]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - kernel/patches/grsecurity-3.0-3.13.2-201402091134.patch
iproute2: Update to 3.14.0.
[people/ms/ipfire-3.x.git] / kernel / patches / grsecurity-3.0-3.13.2-201402091134.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..e289b9b 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -92,32 +101,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -125,12 +142,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -145,14 +165,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -162,14 +182,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -185,6 +206,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -203,7 +227,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -213,8 +242,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -224,6 +257,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -235,13 +269,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -249,9 +287,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238 index b9e9bd8..bf49b92 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1033,6 +1033,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246 + ignore grsecurity's /proc restrictions
247 +
248 +
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252 @@ -2018,6 +2022,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256 + nopcid [X86-64]
257 + Disable PCID (Process-Context IDentifier) even if it
258 + is supported by the processor.
259 +
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263 @@ -2285,6 +2293,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268 + virtualization environments that don't cope well with the
269 + expand down segment used by UDEREF on X86-32 or the frequent
270 + page table updates on X86-64.
271 +
272 + pax_sanitize_slab=
273 + 0/1 to disable/enable slab object sanitization (enabled by
274 + default).
275 +
276 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277 +
278 + pax_extra_latent_entropy
279 + Enable a very simple form of latent entropy extraction
280 + from the first 4GB of memory as the bootmem allocator
281 + passes the memory pages to the buddy allocator.
282 +
283 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284 + when the processor supports PCID.
285 +
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289 diff --git a/Makefile b/Makefile
290 index a7fd5d9..dc8e4db 100644
291 --- a/Makefile
292 +++ b/Makefile
293 @@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298 -HOSTCXXFLAGS = -O2
299 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305 @@ -311,9 +312,15 @@ endif
306 # If the user is running make -s (silent mode), suppress echoing of
307 # commands
308
309 +ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
310 +ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
311 + quiet=silent_
312 +endif
313 +else # make-3.8x
314 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
315 quiet=silent_
316 endif
317 +endif
318
319 export quiet Q KBUILD_VERBOSE
320
321 @@ -417,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
322 # Rules shared between *config targets and build targets
323
324 # Basic helpers built in scripts/
325 -PHONY += scripts_basic
326 -scripts_basic:
327 +PHONY += scripts_basic gcc-plugins
328 +scripts_basic: gcc-plugins
329 $(Q)$(MAKE) $(build)=scripts/basic
330 $(Q)rm -f .tmp_quiet_recordmcount
331
332 @@ -579,6 +586,72 @@ else
333 KBUILD_CFLAGS += -O2
334 endif
335
336 +ifndef DISABLE_PAX_PLUGINS
337 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
338 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
339 +else
340 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
341 +endif
342 +ifneq ($(PLUGINCC),)
343 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
344 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
345 +endif
346 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
347 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
348 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
349 +endif
350 +ifdef CONFIG_KALLOCSTAT_PLUGIN
351 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
352 +endif
353 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
354 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
355 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
356 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
357 +endif
358 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
359 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
360 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
361 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
362 +endif
363 +endif
364 +ifdef CONFIG_CHECKER_PLUGIN
365 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
366 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
367 +endif
368 +endif
369 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
370 +ifdef CONFIG_PAX_SIZE_OVERFLOW
371 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
372 +endif
373 +ifdef CONFIG_PAX_LATENT_ENTROPY
374 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
375 +endif
376 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
377 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
378 +endif
379 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
380 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
381 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
382 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
383 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
384 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
385 +ifeq ($(KBUILD_EXTMOD),)
386 +gcc-plugins:
387 + $(Q)$(MAKE) $(build)=tools/gcc
388 +else
389 +gcc-plugins: ;
390 +endif
391 +else
392 +gcc-plugins:
393 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
394 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
395 +else
396 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
397 +endif
398 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
399 +endif
400 +endif
401 +
402 include $(srctree)/arch/$(SRCARCH)/Makefile
403
404 ifdef CONFIG_READABLE_ASM
405 @@ -619,7 +692,7 @@ endif
406
407 ifdef CONFIG_DEBUG_INFO
408 KBUILD_CFLAGS += -g
409 -KBUILD_AFLAGS += -gdwarf-2
410 +KBUILD_AFLAGS += -Wa,--gdwarf-2
411 endif
412
413 ifdef CONFIG_DEBUG_INFO_REDUCED
414 @@ -754,7 +827,7 @@ export mod_sign_cmd
415
416
417 ifeq ($(KBUILD_EXTMOD),)
418 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
419 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
420
421 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
422 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
423 @@ -803,6 +876,8 @@ endif
424
425 # The actual objects are generated when descending,
426 # make sure no implicit rule kicks in
427 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
428 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
429 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
430
431 # Handle descending into subdirectories listed in $(vmlinux-dirs)
432 @@ -812,7 +887,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
433 # Error messages still appears in the original language
434
435 PHONY += $(vmlinux-dirs)
436 -$(vmlinux-dirs): prepare scripts
437 +$(vmlinux-dirs): gcc-plugins prepare scripts
438 $(Q)$(MAKE) $(build)=$@
439
440 define filechk_kernel.release
441 @@ -855,10 +930,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
442
443 archprepare: archheaders archscripts prepare1 scripts_basic
444
445 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
446 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
447 prepare0: archprepare FORCE
448 $(Q)$(MAKE) $(build)=.
449
450 # All the preparing..
451 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
452 prepare: prepare0
453
454 # Generate some files
455 @@ -966,6 +1044,8 @@ all: modules
456 # using awk while concatenating to the final file.
457
458 PHONY += modules
459 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
460 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
461 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
462 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
463 @$(kecho) ' Building modules, stage 2.';
464 @@ -981,7 +1061,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
465
466 # Target to prepare building external modules
467 PHONY += modules_prepare
468 -modules_prepare: prepare scripts
469 +modules_prepare: gcc-plugins prepare scripts
470
471 # Target to install modules
472 PHONY += modules_install
473 @@ -1047,7 +1127,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
474 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
475 signing_key.priv signing_key.x509 x509.genkey \
476 extra_certificates signing_key.x509.keyid \
477 - signing_key.x509.signer
478 + signing_key.x509.signer tools/gcc/size_overflow_hash.h \
479 + tools/gcc/randomize_layout_seed.h
480
481 # clean - Delete most, but leave enough to build external modules
482 #
483 @@ -1087,6 +1168,7 @@ distclean: mrproper
484 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
485 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
486 -o -name '.*.rej' \
487 + -o -name '.*.rej' -o -name '*.so' \
488 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
489 -type f -print | xargs rm -f
490
491 @@ -1248,6 +1330,8 @@ PHONY += $(module-dirs) modules
492 $(module-dirs): crmodverdir $(objtree)/Module.symvers
493 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
494
495 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
496 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
497 modules: $(module-dirs)
498 @$(kecho) ' Building modules, stage 2.';
499 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
500 @@ -1387,17 +1471,21 @@ else
501 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
502 endif
503
504 -%.s: %.c prepare scripts FORCE
505 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
506 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
507 +%.s: %.c gcc-plugins prepare scripts FORCE
508 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
509 %.i: %.c prepare scripts FORCE
510 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
511 -%.o: %.c prepare scripts FORCE
512 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 +%.o: %.c gcc-plugins prepare scripts FORCE
515 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
516 %.lst: %.c prepare scripts FORCE
517 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
518 -%.s: %.S prepare scripts FORCE
519 +%.s: %.S gcc-plugins prepare scripts FORCE
520 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
521 -%.o: %.S prepare scripts FORCE
522 +%.o: %.S gcc-plugins prepare scripts FORCE
523 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
524 %.symtypes: %.c prepare scripts FORCE
525 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
526 @@ -1407,11 +1495,15 @@ endif
527 $(cmd_crmodverdir)
528 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
529 $(build)=$(build-dir)
530 -%/: prepare scripts FORCE
531 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
532 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
533 +%/: gcc-plugins prepare scripts FORCE
534 $(cmd_crmodverdir)
535 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
536 $(build)=$(build-dir)
537 -%.ko: prepare scripts FORCE
538 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
539 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
540 +%.ko: gcc-plugins prepare scripts FORCE
541 $(cmd_crmodverdir)
542 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
543 $(build)=$(build-dir) $(@:.ko=.o)
544 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
545 index 78b03ef..da28a51 100644
546 --- a/arch/alpha/include/asm/atomic.h
547 +++ b/arch/alpha/include/asm/atomic.h
548 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
549 #define atomic_dec(v) atomic_sub(1,(v))
550 #define atomic64_dec(v) atomic64_sub(1,(v))
551
552 +#define atomic64_read_unchecked(v) atomic64_read(v)
553 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
554 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
555 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
556 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
557 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
558 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
559 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
560 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
561 +
562 #define smp_mb__before_atomic_dec() smp_mb()
563 #define smp_mb__after_atomic_dec() smp_mb()
564 #define smp_mb__before_atomic_inc() smp_mb()
565 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
566 index ad368a9..fbe0f25 100644
567 --- a/arch/alpha/include/asm/cache.h
568 +++ b/arch/alpha/include/asm/cache.h
569 @@ -4,19 +4,19 @@
570 #ifndef __ARCH_ALPHA_CACHE_H
571 #define __ARCH_ALPHA_CACHE_H
572
573 +#include <linux/const.h>
574
575 /* Bytes per L1 (data) cache line. */
576 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
577 -# define L1_CACHE_BYTES 64
578 # define L1_CACHE_SHIFT 6
579 #else
580 /* Both EV4 and EV5 are write-through, read-allocate,
581 direct-mapped, physical.
582 */
583 -# define L1_CACHE_BYTES 32
584 # define L1_CACHE_SHIFT 5
585 #endif
586
587 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
588 #define SMP_CACHE_BYTES L1_CACHE_BYTES
589
590 #endif
591 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
592 index 968d999..d36b2df 100644
593 --- a/arch/alpha/include/asm/elf.h
594 +++ b/arch/alpha/include/asm/elf.h
595 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
596
597 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
598
599 +#ifdef CONFIG_PAX_ASLR
600 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
601 +
602 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
603 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
604 +#endif
605 +
606 /* $0 is set by ld.so to a pointer to a function which might be
607 registered using atexit. This provides a mean for the dynamic
608 linker to call DT_FINI functions for shared libraries that have
609 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
610 index aab14a0..b4fa3e7 100644
611 --- a/arch/alpha/include/asm/pgalloc.h
612 +++ b/arch/alpha/include/asm/pgalloc.h
613 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
614 pgd_set(pgd, pmd);
615 }
616
617 +static inline void
618 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
619 +{
620 + pgd_populate(mm, pgd, pmd);
621 +}
622 +
623 extern pgd_t *pgd_alloc(struct mm_struct *mm);
624
625 static inline void
626 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
627 index d8f9b7e..f6222fa 100644
628 --- a/arch/alpha/include/asm/pgtable.h
629 +++ b/arch/alpha/include/asm/pgtable.h
630 @@ -102,6 +102,17 @@ struct vm_area_struct;
631 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
632 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
633 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
634 +
635 +#ifdef CONFIG_PAX_PAGEEXEC
636 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
637 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
638 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
639 +#else
640 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
641 +# define PAGE_COPY_NOEXEC PAGE_COPY
642 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
643 +#endif
644 +
645 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
646
647 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
648 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
649 index 2fd00b7..cfd5069 100644
650 --- a/arch/alpha/kernel/module.c
651 +++ b/arch/alpha/kernel/module.c
652 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
653
654 /* The small sections were sorted to the end of the segment.
655 The following should definitely cover them. */
656 - gp = (u64)me->module_core + me->core_size - 0x8000;
657 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
658 got = sechdrs[me->arch.gotsecindex].sh_addr;
659
660 for (i = 0; i < n; i++) {
661 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
662 index 1402fcc..0b1abd2 100644
663 --- a/arch/alpha/kernel/osf_sys.c
664 +++ b/arch/alpha/kernel/osf_sys.c
665 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
666 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
667
668 static unsigned long
669 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
670 - unsigned long limit)
671 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
672 + unsigned long limit, unsigned long flags)
673 {
674 struct vm_unmapped_area_info info;
675 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
676
677 info.flags = 0;
678 info.length = len;
679 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
680 info.high_limit = limit;
681 info.align_mask = 0;
682 info.align_offset = 0;
683 + info.threadstack_offset = offset;
684 return vm_unmapped_area(&info);
685 }
686
687 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
688 merely specific addresses, but regions of memory -- perhaps
689 this feature should be incorporated into all ports? */
690
691 +#ifdef CONFIG_PAX_RANDMMAP
692 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
693 +#endif
694 +
695 if (addr) {
696 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
697 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
698 if (addr != (unsigned long) -ENOMEM)
699 return addr;
700 }
701
702 /* Next, try allocating at TASK_UNMAPPED_BASE. */
703 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
704 - len, limit);
705 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
706 +
707 if (addr != (unsigned long) -ENOMEM)
708 return addr;
709
710 /* Finally, try allocating in low memory. */
711 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
712 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
713
714 return addr;
715 }
716 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
717 index 98838a0..b304fb4 100644
718 --- a/arch/alpha/mm/fault.c
719 +++ b/arch/alpha/mm/fault.c
720 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
721 __reload_thread(pcb);
722 }
723
724 +#ifdef CONFIG_PAX_PAGEEXEC
725 +/*
726 + * PaX: decide what to do with offenders (regs->pc = fault address)
727 + *
728 + * returns 1 when task should be killed
729 + * 2 when patched PLT trampoline was detected
730 + * 3 when unpatched PLT trampoline was detected
731 + */
732 +static int pax_handle_fetch_fault(struct pt_regs *regs)
733 +{
734 +
735 +#ifdef CONFIG_PAX_EMUPLT
736 + int err;
737 +
738 + do { /* PaX: patched PLT emulation #1 */
739 + unsigned int ldah, ldq, jmp;
740 +
741 + err = get_user(ldah, (unsigned int *)regs->pc);
742 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
743 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
744 +
745 + if (err)
746 + break;
747 +
748 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
749 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
750 + jmp == 0x6BFB0000U)
751 + {
752 + unsigned long r27, addr;
753 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
754 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
755 +
756 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
757 + err = get_user(r27, (unsigned long *)addr);
758 + if (err)
759 + break;
760 +
761 + regs->r27 = r27;
762 + regs->pc = r27;
763 + return 2;
764 + }
765 + } while (0);
766 +
767 + do { /* PaX: patched PLT emulation #2 */
768 + unsigned int ldah, lda, br;
769 +
770 + err = get_user(ldah, (unsigned int *)regs->pc);
771 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
772 + err |= get_user(br, (unsigned int *)(regs->pc+8));
773 +
774 + if (err)
775 + break;
776 +
777 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
778 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
779 + (br & 0xFFE00000U) == 0xC3E00000U)
780 + {
781 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
782 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
783 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
784 +
785 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
786 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
787 + return 2;
788 + }
789 + } while (0);
790 +
791 + do { /* PaX: unpatched PLT emulation */
792 + unsigned int br;
793 +
794 + err = get_user(br, (unsigned int *)regs->pc);
795 +
796 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
797 + unsigned int br2, ldq, nop, jmp;
798 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
799 +
800 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
801 + err = get_user(br2, (unsigned int *)addr);
802 + err |= get_user(ldq, (unsigned int *)(addr+4));
803 + err |= get_user(nop, (unsigned int *)(addr+8));
804 + err |= get_user(jmp, (unsigned int *)(addr+12));
805 + err |= get_user(resolver, (unsigned long *)(addr+16));
806 +
807 + if (err)
808 + break;
809 +
810 + if (br2 == 0xC3600000U &&
811 + ldq == 0xA77B000CU &&
812 + nop == 0x47FF041FU &&
813 + jmp == 0x6B7B0000U)
814 + {
815 + regs->r28 = regs->pc+4;
816 + regs->r27 = addr+16;
817 + regs->pc = resolver;
818 + return 3;
819 + }
820 + }
821 + } while (0);
822 +#endif
823 +
824 + return 1;
825 +}
826 +
827 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
828 +{
829 + unsigned long i;
830 +
831 + printk(KERN_ERR "PAX: bytes at PC: ");
832 + for (i = 0; i < 5; i++) {
833 + unsigned int c;
834 + if (get_user(c, (unsigned int *)pc+i))
835 + printk(KERN_CONT "???????? ");
836 + else
837 + printk(KERN_CONT "%08x ", c);
838 + }
839 + printk("\n");
840 +}
841 +#endif
842
843 /*
844 * This routine handles page faults. It determines the address,
845 @@ -133,8 +251,29 @@ retry:
846 good_area:
847 si_code = SEGV_ACCERR;
848 if (cause < 0) {
849 - if (!(vma->vm_flags & VM_EXEC))
850 + if (!(vma->vm_flags & VM_EXEC)) {
851 +
852 +#ifdef CONFIG_PAX_PAGEEXEC
853 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
854 + goto bad_area;
855 +
856 + up_read(&mm->mmap_sem);
857 + switch (pax_handle_fetch_fault(regs)) {
858 +
859 +#ifdef CONFIG_PAX_EMUPLT
860 + case 2:
861 + case 3:
862 + return;
863 +#endif
864 +
865 + }
866 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
867 + do_group_exit(SIGKILL);
868 +#else
869 goto bad_area;
870 +#endif
871 +
872 + }
873 } else if (!cause) {
874 /* Allow reads even for write-only mappings */
875 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
876 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
877 index c1f1a7e..554b0cd 100644
878 --- a/arch/arm/Kconfig
879 +++ b/arch/arm/Kconfig
880 @@ -1828,7 +1828,7 @@ config ALIGNMENT_TRAP
881
882 config UACCESS_WITH_MEMCPY
883 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
884 - depends on MMU
885 + depends on MMU && !PAX_MEMORY_UDEREF
886 default y if CPU_FEROCEON
887 help
888 Implement faster copy_to_user and clear_user methods for CPU
889 @@ -2100,6 +2100,7 @@ config XIP_PHYS_ADDR
890 config KEXEC
891 bool "Kexec system call (EXPERIMENTAL)"
892 depends on (!SMP || PM_SLEEP_SMP)
893 + depends on !GRKERNSEC_KMEM
894 help
895 kexec is a system call that implements the ability to shutdown your
896 current kernel, and to start another kernel. It is like a reboot
897 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
898 index 62d2cb5..7a13651 100644
899 --- a/arch/arm/include/asm/atomic.h
900 +++ b/arch/arm/include/asm/atomic.h
901 @@ -18,17 +18,35 @@
902 #include <asm/barrier.h>
903 #include <asm/cmpxchg.h>
904
905 +#ifdef CONFIG_GENERIC_ATOMIC64
906 +#include <asm-generic/atomic64.h>
907 +#endif
908 +
909 #define ATOMIC_INIT(i) { (i) }
910
911 #ifdef __KERNEL__
912
913 +#define _ASM_EXTABLE(from, to) \
914 +" .pushsection __ex_table,\"a\"\n"\
915 +" .align 3\n" \
916 +" .long " #from ", " #to"\n" \
917 +" .popsection"
918 +
919 /*
920 * On ARM, ordinary assignment (str instruction) doesn't clear the local
921 * strex/ldrex monitor on some implementations. The reason we can use it for
922 * atomic_set() is the clrex or dummy strex done on every exception return.
923 */
924 #define atomic_read(v) (*(volatile int *)&(v)->counter)
925 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
926 +{
927 + return v->counter;
928 +}
929 #define atomic_set(v,i) (((v)->counter) = (i))
930 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
931 +{
932 + v->counter = i;
933 +}
934
935 #if __LINUX_ARM_ARCH__ >= 6
936
937 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
938
939 prefetchw(&v->counter);
940 __asm__ __volatile__("@ atomic_add\n"
941 +"1: ldrex %1, [%3]\n"
942 +" adds %0, %1, %4\n"
943 +
944 +#ifdef CONFIG_PAX_REFCOUNT
945 +" bvc 3f\n"
946 +"2: bkpt 0xf103\n"
947 +"3:\n"
948 +#endif
949 +
950 +" strex %1, %0, [%3]\n"
951 +" teq %1, #0\n"
952 +" bne 1b"
953 +
954 +#ifdef CONFIG_PAX_REFCOUNT
955 +"\n4:\n"
956 + _ASM_EXTABLE(2b, 4b)
957 +#endif
958 +
959 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
960 + : "r" (&v->counter), "Ir" (i)
961 + : "cc");
962 +}
963 +
964 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
965 +{
966 + unsigned long tmp;
967 + int result;
968 +
969 + prefetchw(&v->counter);
970 + __asm__ __volatile__("@ atomic_add_unchecked\n"
971 "1: ldrex %0, [%3]\n"
972 " add %0, %0, %4\n"
973 " strex %1, %0, [%3]\n"
974 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
975 smp_mb();
976
977 __asm__ __volatile__("@ atomic_add_return\n"
978 +"1: ldrex %1, [%3]\n"
979 +" adds %0, %1, %4\n"
980 +
981 +#ifdef CONFIG_PAX_REFCOUNT
982 +" bvc 3f\n"
983 +" mov %0, %1\n"
984 +"2: bkpt 0xf103\n"
985 +"3:\n"
986 +#endif
987 +
988 +" strex %1, %0, [%3]\n"
989 +" teq %1, #0\n"
990 +" bne 1b"
991 +
992 +#ifdef CONFIG_PAX_REFCOUNT
993 +"\n4:\n"
994 + _ASM_EXTABLE(2b, 4b)
995 +#endif
996 +
997 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
998 + : "r" (&v->counter), "Ir" (i)
999 + : "cc");
1000 +
1001 + smp_mb();
1002 +
1003 + return result;
1004 +}
1005 +
1006 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1007 +{
1008 + unsigned long tmp;
1009 + int result;
1010 +
1011 + smp_mb();
1012 +
1013 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1014 "1: ldrex %0, [%3]\n"
1015 " add %0, %0, %4\n"
1016 " strex %1, %0, [%3]\n"
1017 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1018
1019 prefetchw(&v->counter);
1020 __asm__ __volatile__("@ atomic_sub\n"
1021 +"1: ldrex %1, [%3]\n"
1022 +" subs %0, %1, %4\n"
1023 +
1024 +#ifdef CONFIG_PAX_REFCOUNT
1025 +" bvc 3f\n"
1026 +"2: bkpt 0xf103\n"
1027 +"3:\n"
1028 +#endif
1029 +
1030 +" strex %1, %0, [%3]\n"
1031 +" teq %1, #0\n"
1032 +" bne 1b"
1033 +
1034 +#ifdef CONFIG_PAX_REFCOUNT
1035 +"\n4:\n"
1036 + _ASM_EXTABLE(2b, 4b)
1037 +#endif
1038 +
1039 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1040 + : "r" (&v->counter), "Ir" (i)
1041 + : "cc");
1042 +}
1043 +
1044 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1045 +{
1046 + unsigned long tmp;
1047 + int result;
1048 +
1049 + prefetchw(&v->counter);
1050 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1051 "1: ldrex %0, [%3]\n"
1052 " sub %0, %0, %4\n"
1053 " strex %1, %0, [%3]\n"
1054 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1055 smp_mb();
1056
1057 __asm__ __volatile__("@ atomic_sub_return\n"
1058 -"1: ldrex %0, [%3]\n"
1059 -" sub %0, %0, %4\n"
1060 +"1: ldrex %1, [%3]\n"
1061 +" subs %0, %1, %4\n"
1062 +
1063 +#ifdef CONFIG_PAX_REFCOUNT
1064 +" bvc 3f\n"
1065 +" mov %0, %1\n"
1066 +"2: bkpt 0xf103\n"
1067 +"3:\n"
1068 +#endif
1069 +
1070 " strex %1, %0, [%3]\n"
1071 " teq %1, #0\n"
1072 " bne 1b"
1073 +
1074 +#ifdef CONFIG_PAX_REFCOUNT
1075 +"\n4:\n"
1076 + _ASM_EXTABLE(2b, 4b)
1077 +#endif
1078 +
1079 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1080 : "r" (&v->counter), "Ir" (i)
1081 : "cc");
1082 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1083 return oldval;
1084 }
1085
1086 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1087 +{
1088 + unsigned long oldval, res;
1089 +
1090 + smp_mb();
1091 +
1092 + do {
1093 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1094 + "ldrex %1, [%3]\n"
1095 + "mov %0, #0\n"
1096 + "teq %1, %4\n"
1097 + "strexeq %0, %5, [%3]\n"
1098 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1099 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1100 + : "cc");
1101 + } while (res);
1102 +
1103 + smp_mb();
1104 +
1105 + return oldval;
1106 +}
1107 +
1108 #else /* ARM_ARCH_6 */
1109
1110 #ifdef CONFIG_SMP
1111 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1112
1113 return val;
1114 }
1115 +
1116 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1117 +{
1118 + return atomic_add_return(i, v);
1119 +}
1120 +
1121 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1122 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1123 +{
1124 + (void) atomic_add_return(i, v);
1125 +}
1126
1127 static inline int atomic_sub_return(int i, atomic_t *v)
1128 {
1129 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1130 return val;
1131 }
1132 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1133 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1134 +{
1135 + (void) atomic_sub_return(i, v);
1136 +}
1137
1138 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1139 {
1140 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1141 return ret;
1142 }
1143
1144 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1145 +{
1146 + return atomic_cmpxchg(v, old, new);
1147 +}
1148 +
1149 #endif /* __LINUX_ARM_ARCH__ */
1150
1151 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1152 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1153 +{
1154 + return xchg(&v->counter, new);
1155 +}
1156
1157 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1158 {
1159 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 }
1161
1162 #define atomic_inc(v) atomic_add(1, v)
1163 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1164 +{
1165 + atomic_add_unchecked(1, v);
1166 +}
1167 #define atomic_dec(v) atomic_sub(1, v)
1168 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1169 +{
1170 + atomic_sub_unchecked(1, v);
1171 +}
1172
1173 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1174 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1175 +{
1176 + return atomic_add_return_unchecked(1, v) == 0;
1177 +}
1178 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1179 #define atomic_inc_return(v) (atomic_add_return(1, v))
1180 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1181 +{
1182 + return atomic_add_return_unchecked(1, v);
1183 +}
1184 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1185 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1186
1187 @@ -221,6 +410,14 @@ typedef struct {
1188 long long counter;
1189 } atomic64_t;
1190
1191 +#ifdef CONFIG_PAX_REFCOUNT
1192 +typedef struct {
1193 + long long counter;
1194 +} atomic64_unchecked_t;
1195 +#else
1196 +typedef atomic64_t atomic64_unchecked_t;
1197 +#endif
1198 +
1199 #define ATOMIC64_INIT(i) { (i) }
1200
1201 #ifdef CONFIG_ARM_LPAE
1202 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1203 return result;
1204 }
1205
1206 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1207 +{
1208 + long long result;
1209 +
1210 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1211 +" ldrd %0, %H0, [%1]"
1212 + : "=&r" (result)
1213 + : "r" (&v->counter), "Qo" (v->counter)
1214 + );
1215 +
1216 + return result;
1217 +}
1218 +
1219 static inline void atomic64_set(atomic64_t *v, long long i)
1220 {
1221 __asm__ __volatile__("@ atomic64_set\n"
1222 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1223 : "r" (&v->counter), "r" (i)
1224 );
1225 }
1226 +
1227 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1228 +{
1229 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1230 +" strd %2, %H2, [%1]"
1231 + : "=Qo" (v->counter)
1232 + : "r" (&v->counter), "r" (i)
1233 + );
1234 +}
1235 #else
1236 static inline long long atomic64_read(const atomic64_t *v)
1237 {
1238 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1239 return result;
1240 }
1241
1242 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1243 +{
1244 + long long result;
1245 +
1246 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1247 +" ldrexd %0, %H0, [%1]"
1248 + : "=&r" (result)
1249 + : "r" (&v->counter), "Qo" (v->counter)
1250 + );
1251 +
1252 + return result;
1253 +}
1254 +
1255 static inline void atomic64_set(atomic64_t *v, long long i)
1256 {
1257 long long tmp;
1258 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1259 : "r" (&v->counter), "r" (i)
1260 : "cc");
1261 }
1262 +
1263 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1264 +{
1265 + long long tmp;
1266 +
1267 + prefetchw(&v->counter);
1268 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1269 +"1: ldrexd %0, %H0, [%2]\n"
1270 +" strexd %0, %3, %H3, [%2]\n"
1271 +" teq %0, #0\n"
1272 +" bne 1b"
1273 + : "=&r" (tmp), "=Qo" (v->counter)
1274 + : "r" (&v->counter), "r" (i)
1275 + : "cc");
1276 +}
1277 #endif
1278
1279 static inline void atomic64_add(long long i, atomic64_t *v)
1280 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1281 __asm__ __volatile__("@ atomic64_add\n"
1282 "1: ldrexd %0, %H0, [%3]\n"
1283 " adds %Q0, %Q0, %Q4\n"
1284 +" adcs %R0, %R0, %R4\n"
1285 +
1286 +#ifdef CONFIG_PAX_REFCOUNT
1287 +" bvc 3f\n"
1288 +"2: bkpt 0xf103\n"
1289 +"3:\n"
1290 +#endif
1291 +
1292 +" strexd %1, %0, %H0, [%3]\n"
1293 +" teq %1, #0\n"
1294 +" bne 1b"
1295 +
1296 +#ifdef CONFIG_PAX_REFCOUNT
1297 +"\n4:\n"
1298 + _ASM_EXTABLE(2b, 4b)
1299 +#endif
1300 +
1301 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1302 + : "r" (&v->counter), "r" (i)
1303 + : "cc");
1304 +}
1305 +
1306 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1307 +{
1308 + long long result;
1309 + unsigned long tmp;
1310 +
1311 + prefetchw(&v->counter);
1312 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1313 +"1: ldrexd %0, %H0, [%3]\n"
1314 +" adds %Q0, %Q0, %Q4\n"
1315 " adc %R0, %R0, %R4\n"
1316 " strexd %1, %0, %H0, [%3]\n"
1317 " teq %1, #0\n"
1318 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_add_return\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " adds %Q0, %Q0, %Q4\n"
1322 +" adcs %R0, %R0, %R4\n"
1323 +
1324 +#ifdef CONFIG_PAX_REFCOUNT
1325 +" bvc 3f\n"
1326 +" mov %0, %1\n"
1327 +" mov %H0, %H1\n"
1328 +"2: bkpt 0xf103\n"
1329 +"3:\n"
1330 +#endif
1331 +
1332 +" strexd %1, %0, %H0, [%3]\n"
1333 +" teq %1, #0\n"
1334 +" bne 1b"
1335 +
1336 +#ifdef CONFIG_PAX_REFCOUNT
1337 +"\n4:\n"
1338 + _ASM_EXTABLE(2b, 4b)
1339 +#endif
1340 +
1341 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1342 + : "r" (&v->counter), "r" (i)
1343 + : "cc");
1344 +
1345 + smp_mb();
1346 +
1347 + return result;
1348 +}
1349 +
1350 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1351 +{
1352 + long long result;
1353 + unsigned long tmp;
1354 +
1355 + smp_mb();
1356 +
1357 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1358 +"1: ldrexd %0, %H0, [%3]\n"
1359 +" adds %Q0, %Q0, %Q4\n"
1360 " adc %R0, %R0, %R4\n"
1361 " strexd %1, %0, %H0, [%3]\n"
1362 " teq %1, #0\n"
1363 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1364 __asm__ __volatile__("@ atomic64_sub\n"
1365 "1: ldrexd %0, %H0, [%3]\n"
1366 " subs %Q0, %Q0, %Q4\n"
1367 +" sbcs %R0, %R0, %R4\n"
1368 +
1369 +#ifdef CONFIG_PAX_REFCOUNT
1370 +" bvc 3f\n"
1371 +"2: bkpt 0xf103\n"
1372 +"3:\n"
1373 +#endif
1374 +
1375 +" strexd %1, %0, %H0, [%3]\n"
1376 +" teq %1, #0\n"
1377 +" bne 1b"
1378 +
1379 +#ifdef CONFIG_PAX_REFCOUNT
1380 +"\n4:\n"
1381 + _ASM_EXTABLE(2b, 4b)
1382 +#endif
1383 +
1384 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1385 + : "r" (&v->counter), "r" (i)
1386 + : "cc");
1387 +}
1388 +
1389 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1390 +{
1391 + long long result;
1392 + unsigned long tmp;
1393 +
1394 + prefetchw(&v->counter);
1395 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1396 +"1: ldrexd %0, %H0, [%3]\n"
1397 +" subs %Q0, %Q0, %Q4\n"
1398 " sbc %R0, %R0, %R4\n"
1399 " strexd %1, %0, %H0, [%3]\n"
1400 " teq %1, #0\n"
1401 @@ -344,17 +691,28 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1402 __asm__ __volatile__("@ atomic64_sub_return\n"
1403 "1: ldrexd %0, %H0, [%3]\n"
1404 " subs %Q0, %Q0, %Q4\n"
1405 -" sbc %R0, %R0, %R4\n"
1406 +" sbcs %R0, %R0, %R4\n"
1407 +
1408 +#ifdef CONFIG_PAX_REFCOUNT
1409 +" bvc 3f\n"
1410 +" mov %0, %1\n"
1411 +" mov %H0, %H1\n"
1412 +"2: bkpt 0xf103\n"
1413 +"3:\n"
1414 +#endif
1415 +
1416 " strexd %1, %0, %H0, [%3]\n"
1417 " teq %1, #0\n"
1418 " bne 1b"
1419 +
1420 +#ifdef CONFIG_PAX_REFCOUNT
1421 +"\n4:\n"
1422 + _ASM_EXTABLE(2b, 4b)
1423 +#endif
1424 +
1425 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1426 : "r" (&v->counter), "r" (i)
1427 : "cc");
1428 -
1429 - smp_mb();
1430 -
1431 - return result;
1432 }
1433
1434 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1435 @@ -382,6 +740,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1436 return oldval;
1437 }
1438
1439 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1440 + long long new)
1441 +{
1442 + long long oldval;
1443 + unsigned long res;
1444 +
1445 + smp_mb();
1446 +
1447 + do {
1448 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1449 + "ldrexd %1, %H1, [%3]\n"
1450 + "mov %0, #0\n"
1451 + "teq %1, %4\n"
1452 + "teqeq %H1, %H4\n"
1453 + "strexdeq %0, %5, %H5, [%3]"
1454 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1455 + : "r" (&ptr->counter), "r" (old), "r" (new)
1456 + : "cc");
1457 + } while (res);
1458 +
1459 + smp_mb();
1460 +
1461 + return oldval;
1462 +}
1463 +
1464 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1465 {
1466 long long result;
1467 @@ -406,20 +789,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1468 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1469 {
1470 long long result;
1471 - unsigned long tmp;
1472 + u64 tmp;
1473
1474 smp_mb();
1475
1476 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1477 -"1: ldrexd %0, %H0, [%3]\n"
1478 -" subs %Q0, %Q0, #1\n"
1479 -" sbc %R0, %R0, #0\n"
1480 +"1: ldrexd %1, %H1, [%3]\n"
1481 +" subs %Q0, %Q1, #1\n"
1482 +" sbcs %R0, %R1, #0\n"
1483 +
1484 +#ifdef CONFIG_PAX_REFCOUNT
1485 +" bvc 3f\n"
1486 +" mov %Q0, %Q1\n"
1487 +" mov %R0, %R1\n"
1488 +"2: bkpt 0xf103\n"
1489 +"3:\n"
1490 +#endif
1491 +
1492 " teq %R0, #0\n"
1493 -" bmi 2f\n"
1494 +" bmi 4f\n"
1495 " strexd %1, %0, %H0, [%3]\n"
1496 " teq %1, #0\n"
1497 " bne 1b\n"
1498 -"2:"
1499 +"4:\n"
1500 +
1501 +#ifdef CONFIG_PAX_REFCOUNT
1502 + _ASM_EXTABLE(2b, 4b)
1503 +#endif
1504 +
1505 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1506 : "r" (&v->counter)
1507 : "cc");
1508 @@ -442,13 +839,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1509 " teq %0, %5\n"
1510 " teqeq %H0, %H5\n"
1511 " moveq %1, #0\n"
1512 -" beq 2f\n"
1513 +" beq 4f\n"
1514 " adds %Q0, %Q0, %Q6\n"
1515 -" adc %R0, %R0, %R6\n"
1516 +" adcs %R0, %R0, %R6\n"
1517 +
1518 +#ifdef CONFIG_PAX_REFCOUNT
1519 +" bvc 3f\n"
1520 +"2: bkpt 0xf103\n"
1521 +"3:\n"
1522 +#endif
1523 +
1524 " strexd %2, %0, %H0, [%4]\n"
1525 " teq %2, #0\n"
1526 " bne 1b\n"
1527 -"2:"
1528 +"4:\n"
1529 +
1530 +#ifdef CONFIG_PAX_REFCOUNT
1531 + _ASM_EXTABLE(2b, 4b)
1532 +#endif
1533 +
1534 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1535 : "r" (&v->counter), "r" (u), "r" (a)
1536 : "cc");
1537 @@ -461,10 +870,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1538
1539 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1540 #define atomic64_inc(v) atomic64_add(1LL, (v))
1541 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1542 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1543 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1544 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1545 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1546 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1547 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1548 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1549 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1550 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1551 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1552 index 75fe66b..ba3dee4 100644
1553 --- a/arch/arm/include/asm/cache.h
1554 +++ b/arch/arm/include/asm/cache.h
1555 @@ -4,8 +4,10 @@
1556 #ifndef __ASMARM_CACHE_H
1557 #define __ASMARM_CACHE_H
1558
1559 +#include <linux/const.h>
1560 +
1561 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1562 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1563 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1564
1565 /*
1566 * Memory returned by kmalloc() may be used for DMA, so we must make
1567 @@ -24,5 +26,6 @@
1568 #endif
1569
1570 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1571 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1572
1573 #endif
1574 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1575 index ee753f1..c9c30a5 100644
1576 --- a/arch/arm/include/asm/cacheflush.h
1577 +++ b/arch/arm/include/asm/cacheflush.h
1578 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1579 void (*dma_unmap_area)(const void *, size_t, int);
1580
1581 void (*dma_flush_range)(const void *, const void *);
1582 -};
1583 +} __no_const;
1584
1585 /*
1586 * Select the calling method
1587 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1588 index 6dcc164..b14d917 100644
1589 --- a/arch/arm/include/asm/checksum.h
1590 +++ b/arch/arm/include/asm/checksum.h
1591 @@ -37,7 +37,19 @@ __wsum
1592 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1593
1594 __wsum
1595 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1596 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1597 +
1598 +static inline __wsum
1599 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1600 +{
1601 + __wsum ret;
1602 + pax_open_userland();
1603 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1604 + pax_close_userland();
1605 + return ret;
1606 +}
1607 +
1608 +
1609
1610 /*
1611 * Fold a partial checksum without adding pseudo headers
1612 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1613 index df2fbba..63fe3e1 100644
1614 --- a/arch/arm/include/asm/cmpxchg.h
1615 +++ b/arch/arm/include/asm/cmpxchg.h
1616 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1617
1618 #define xchg(ptr,x) \
1619 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1620 +#define xchg_unchecked(ptr,x) \
1621 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1622
1623 #include <asm-generic/cmpxchg-local.h>
1624
1625 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1626 index 6ddbe44..b5e38b1 100644
1627 --- a/arch/arm/include/asm/domain.h
1628 +++ b/arch/arm/include/asm/domain.h
1629 @@ -48,18 +48,37 @@
1630 * Domain types
1631 */
1632 #define DOMAIN_NOACCESS 0
1633 -#define DOMAIN_CLIENT 1
1634 #ifdef CONFIG_CPU_USE_DOMAINS
1635 +#define DOMAIN_USERCLIENT 1
1636 +#define DOMAIN_KERNELCLIENT 1
1637 #define DOMAIN_MANAGER 3
1638 +#define DOMAIN_VECTORS DOMAIN_USER
1639 #else
1640 +
1641 +#ifdef CONFIG_PAX_KERNEXEC
1642 #define DOMAIN_MANAGER 1
1643 +#define DOMAIN_KERNEXEC 3
1644 +#else
1645 +#define DOMAIN_MANAGER 1
1646 +#endif
1647 +
1648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1649 +#define DOMAIN_USERCLIENT 0
1650 +#define DOMAIN_UDEREF 1
1651 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1652 +#else
1653 +#define DOMAIN_USERCLIENT 1
1654 +#define DOMAIN_VECTORS DOMAIN_USER
1655 +#endif
1656 +#define DOMAIN_KERNELCLIENT 1
1657 +
1658 #endif
1659
1660 #define domain_val(dom,type) ((type) << (2*(dom)))
1661
1662 #ifndef __ASSEMBLY__
1663
1664 -#ifdef CONFIG_CPU_USE_DOMAINS
1665 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1666 static inline void set_domain(unsigned val)
1667 {
1668 asm volatile(
1669 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1670 isb();
1671 }
1672
1673 -#define modify_domain(dom,type) \
1674 - do { \
1675 - struct thread_info *thread = current_thread_info(); \
1676 - unsigned int domain = thread->cpu_domain; \
1677 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1678 - thread->cpu_domain = domain | domain_val(dom, type); \
1679 - set_domain(thread->cpu_domain); \
1680 - } while (0)
1681 -
1682 +extern void modify_domain(unsigned int dom, unsigned int type);
1683 #else
1684 static inline void set_domain(unsigned val) { }
1685 static inline void modify_domain(unsigned dom, unsigned type) { }
1686 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1687 index f4b46d3..abc9b2b 100644
1688 --- a/arch/arm/include/asm/elf.h
1689 +++ b/arch/arm/include/asm/elf.h
1690 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1691 the loader. We need to make sure that it is out of the way of the program
1692 that it will "exec", and that there is sufficient room for the brk. */
1693
1694 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1695 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1696 +
1697 +#ifdef CONFIG_PAX_ASLR
1698 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1699 +
1700 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1701 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1702 +#endif
1703
1704 /* When the program starts, a1 contains a pointer to a function to be
1705 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1706 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1707 extern void elf_set_personality(const struct elf32_hdr *);
1708 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1709
1710 -struct mm_struct;
1711 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1712 -#define arch_randomize_brk arch_randomize_brk
1713 -
1714 #ifdef CONFIG_MMU
1715 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1716 struct linux_binprm;
1717 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1718 index de53547..52b9a28 100644
1719 --- a/arch/arm/include/asm/fncpy.h
1720 +++ b/arch/arm/include/asm/fncpy.h
1721 @@ -81,7 +81,9 @@
1722 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1723 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1724 \
1725 + pax_open_kernel(); \
1726 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1727 + pax_close_kernel(); \
1728 flush_icache_range((unsigned long)(dest_buf), \
1729 (unsigned long)(dest_buf) + (size)); \
1730 \
1731 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1732 index e42cf59..7b94b8f 100644
1733 --- a/arch/arm/include/asm/futex.h
1734 +++ b/arch/arm/include/asm/futex.h
1735 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1737 return -EFAULT;
1738
1739 + pax_open_userland();
1740 +
1741 smp_mb();
1742 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1743 "1: ldrex %1, [%4]\n"
1744 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 : "cc", "memory");
1746 smp_mb();
1747
1748 + pax_close_userland();
1749 +
1750 *uval = val;
1751 return ret;
1752 }
1753 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1755 return -EFAULT;
1756
1757 + pax_open_userland();
1758 +
1759 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1760 "1: " TUSER(ldr) " %1, [%4]\n"
1761 " teq %1, %2\n"
1762 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1763 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1764 : "cc", "memory");
1765
1766 + pax_close_userland();
1767 +
1768 *uval = val;
1769 return ret;
1770 }
1771 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1772 return -EFAULT;
1773
1774 pagefault_disable(); /* implies preempt_disable() */
1775 + pax_open_userland();
1776
1777 switch (op) {
1778 case FUTEX_OP_SET:
1779 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1780 ret = -ENOSYS;
1781 }
1782
1783 + pax_close_userland();
1784 pagefault_enable(); /* subsumes preempt_enable() */
1785
1786 if (!ret) {
1787 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1788 index 83eb2f7..ed77159 100644
1789 --- a/arch/arm/include/asm/kmap_types.h
1790 +++ b/arch/arm/include/asm/kmap_types.h
1791 @@ -4,6 +4,6 @@
1792 /*
1793 * This is the "bare minimum". AIO seems to require this.
1794 */
1795 -#define KM_TYPE_NR 16
1796 +#define KM_TYPE_NR 17
1797
1798 #endif
1799 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1800 index 9e614a1..3302cca 100644
1801 --- a/arch/arm/include/asm/mach/dma.h
1802 +++ b/arch/arm/include/asm/mach/dma.h
1803 @@ -22,7 +22,7 @@ struct dma_ops {
1804 int (*residue)(unsigned int, dma_t *); /* optional */
1805 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1806 const char *type;
1807 -};
1808 +} __do_const;
1809
1810 struct dma_struct {
1811 void *addr; /* single DMA address */
1812 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1813 index 2fe141f..192dc01 100644
1814 --- a/arch/arm/include/asm/mach/map.h
1815 +++ b/arch/arm/include/asm/mach/map.h
1816 @@ -27,13 +27,16 @@ struct map_desc {
1817 #define MT_MINICLEAN 6
1818 #define MT_LOW_VECTORS 7
1819 #define MT_HIGH_VECTORS 8
1820 -#define MT_MEMORY 9
1821 +#define MT_MEMORY_RWX 9
1822 #define MT_ROM 10
1823 -#define MT_MEMORY_NONCACHED 11
1824 +#define MT_MEMORY_NONCACHED_RX 11
1825 #define MT_MEMORY_DTCM 12
1826 #define MT_MEMORY_ITCM 13
1827 #define MT_MEMORY_SO 14
1828 #define MT_MEMORY_DMA_READY 15
1829 +#define MT_MEMORY_RW 16
1830 +#define MT_MEMORY_RX 17
1831 +#define MT_MEMORY_NONCACHED_RW 18
1832
1833 #ifdef CONFIG_MMU
1834 extern void iotable_init(struct map_desc *, int);
1835 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1836 index f94784f..9a09a4a 100644
1837 --- a/arch/arm/include/asm/outercache.h
1838 +++ b/arch/arm/include/asm/outercache.h
1839 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1840 #endif
1841 void (*set_debug)(unsigned long);
1842 void (*resume)(void);
1843 -};
1844 +} __no_const;
1845
1846 extern struct outer_cache_fns outer_cache;
1847
1848 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1849 index 4355f0e..c229913 100644
1850 --- a/arch/arm/include/asm/page.h
1851 +++ b/arch/arm/include/asm/page.h
1852 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1853 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1854 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1855 unsigned long vaddr, struct vm_area_struct *vma);
1856 -};
1857 +} __no_const;
1858
1859 #ifdef MULTI_USER
1860 extern struct cpu_user_fns cpu_user;
1861 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1862 index 78a7793..e3dc06c 100644
1863 --- a/arch/arm/include/asm/pgalloc.h
1864 +++ b/arch/arm/include/asm/pgalloc.h
1865 @@ -17,6 +17,7 @@
1866 #include <asm/processor.h>
1867 #include <asm/cacheflush.h>
1868 #include <asm/tlbflush.h>
1869 +#include <asm/system_info.h>
1870
1871 #define check_pgt_cache() do { } while (0)
1872
1873 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1874 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1875 }
1876
1877 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1878 +{
1879 + pud_populate(mm, pud, pmd);
1880 +}
1881 +
1882 #else /* !CONFIG_ARM_LPAE */
1883
1884 /*
1885 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1886 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1887 #define pmd_free(mm, pmd) do { } while (0)
1888 #define pud_populate(mm,pmd,pte) BUG()
1889 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1890
1891 #endif /* CONFIG_ARM_LPAE */
1892
1893 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1894 __free_page(pte);
1895 }
1896
1897 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1898 +{
1899 +#ifdef CONFIG_ARM_LPAE
1900 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1901 +#else
1902 + if (addr & SECTION_SIZE)
1903 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1904 + else
1905 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1906 +#endif
1907 + flush_pmd_entry(pmdp);
1908 +}
1909 +
1910 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1911 pmdval_t prot)
1912 {
1913 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1914 static inline void
1915 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1916 {
1917 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1918 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1919 }
1920 #define pmd_pgtable(pmd) pmd_page(pmd)
1921
1922 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1923 index 5cfba15..f415e1a 100644
1924 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1925 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1926 @@ -20,12 +20,15 @@
1927 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1928 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1929 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1930 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1931 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1932 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1933 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1934 +
1935 /*
1936 * - section
1937 */
1938 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1939 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1940 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1941 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1942 @@ -37,6 +40,7 @@
1943 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1944 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1945 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1946 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1947
1948 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1949 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1950 @@ -66,6 +70,7 @@
1951 * - extended small page/tiny page
1952 */
1953 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1954 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1955 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1956 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1957 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1958 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1959 index 86a659a..70e0120 100644
1960 --- a/arch/arm/include/asm/pgtable-2level.h
1961 +++ b/arch/arm/include/asm/pgtable-2level.h
1962 @@ -126,6 +126,9 @@
1963 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1964 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1965
1966 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1967 +#define L_PTE_PXN (_AT(pteval_t, 0))
1968 +
1969 /*
1970 * These are the memory types, defined to be compatible with
1971 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1972 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1973 index 626989f..9d67a33 100644
1974 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1975 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1976 @@ -75,6 +75,7 @@
1977 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1978 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1979 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1980 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1981 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1982
1983 /*
1984 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1985 index 4f95039..b2dd513 100644
1986 --- a/arch/arm/include/asm/pgtable-3level.h
1987 +++ b/arch/arm/include/asm/pgtable-3level.h
1988 @@ -82,6 +82,7 @@
1989 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1990 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1991 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1992 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1993 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1994 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1995 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1996 @@ -95,6 +96,7 @@
1997 /*
1998 * To be used in assembly code with the upper page attributes.
1999 */
2000 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2001 #define L_PTE_XN_HIGH (1 << (54 - 32))
2002 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2003
2004 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2005 index 1571d12..b8a9b43 100644
2006 --- a/arch/arm/include/asm/pgtable.h
2007 +++ b/arch/arm/include/asm/pgtable.h
2008 @@ -33,6 +33,9 @@
2009 #include <asm/pgtable-2level.h>
2010 #endif
2011
2012 +#define ktla_ktva(addr) (addr)
2013 +#define ktva_ktla(addr) (addr)
2014 +
2015 /*
2016 * Just any arbitrary offset to the start of the vmalloc VM area: the
2017 * current 8MB value just means that there will be a 8MB "hole" after the
2018 @@ -48,6 +51,9 @@
2019 #define LIBRARY_TEXT_START 0x0c000000
2020
2021 #ifndef __ASSEMBLY__
2022 +extern pteval_t __supported_pte_mask;
2023 +extern pmdval_t __supported_pmd_mask;
2024 +
2025 extern void __pte_error(const char *file, int line, pte_t);
2026 extern void __pmd_error(const char *file, int line, pmd_t);
2027 extern void __pgd_error(const char *file, int line, pgd_t);
2028 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2029 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2030 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2031
2032 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2033 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2034 +
2035 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2036 +#include <asm/domain.h>
2037 +#include <linux/thread_info.h>
2038 +#include <linux/preempt.h>
2039 +
2040 +static inline int test_domain(int domain, int domaintype)
2041 +{
2042 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2043 +}
2044 +#endif
2045 +
2046 +#ifdef CONFIG_PAX_KERNEXEC
2047 +static inline unsigned long pax_open_kernel(void) {
2048 +#ifdef CONFIG_ARM_LPAE
2049 + /* TODO */
2050 +#else
2051 + preempt_disable();
2052 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2053 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2054 +#endif
2055 + return 0;
2056 +}
2057 +
2058 +static inline unsigned long pax_close_kernel(void) {
2059 +#ifdef CONFIG_ARM_LPAE
2060 + /* TODO */
2061 +#else
2062 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2063 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2064 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2065 + preempt_enable_no_resched();
2066 +#endif
2067 + return 0;
2068 +}
2069 +#else
2070 +static inline unsigned long pax_open_kernel(void) { return 0; }
2071 +static inline unsigned long pax_close_kernel(void) { return 0; }
2072 +#endif
2073 +
2074 /*
2075 * This is the lowest virtual address we can permit any user space
2076 * mapping to be mapped at. This is particularly important for
2077 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2078 /*
2079 * The pgprot_* and protection_map entries will be fixed up in runtime
2080 * to include the cachable and bufferable bits based on memory policy,
2081 - * as well as any architecture dependent bits like global/ASID and SMP
2082 - * shared mapping bits.
2083 + * as well as any architecture dependent bits like global/ASID, PXN,
2084 + * and SMP shared mapping bits.
2085 */
2086 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2087
2088 @@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2089 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2090 {
2091 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2092 - L_PTE_NONE | L_PTE_VALID;
2093 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2094 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2095 return pte;
2096 }
2097 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2098 index 5324c11..bcae5f0 100644
2099 --- a/arch/arm/include/asm/proc-fns.h
2100 +++ b/arch/arm/include/asm/proc-fns.h
2101 @@ -75,7 +75,7 @@ extern struct processor {
2102 unsigned int suspend_size;
2103 void (*do_suspend)(void *);
2104 void (*do_resume)(void *);
2105 -} processor;
2106 +} __do_const processor;
2107
2108 #ifndef MULTI_CPU
2109 extern void cpu_proc_init(void);
2110 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2111 index c4ae171..ea0c0c2 100644
2112 --- a/arch/arm/include/asm/psci.h
2113 +++ b/arch/arm/include/asm/psci.h
2114 @@ -29,7 +29,7 @@ struct psci_operations {
2115 int (*cpu_off)(struct psci_power_state state);
2116 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2117 int (*migrate)(unsigned long cpuid);
2118 -};
2119 +} __no_const;
2120
2121 extern struct psci_operations psci_ops;
2122 extern struct smp_operations psci_smp_ops;
2123 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2124 index 22a3b9b..7f214ee 100644
2125 --- a/arch/arm/include/asm/smp.h
2126 +++ b/arch/arm/include/asm/smp.h
2127 @@ -112,7 +112,7 @@ struct smp_operations {
2128 int (*cpu_disable)(unsigned int cpu);
2129 #endif
2130 #endif
2131 -};
2132 +} __no_const;
2133
2134 /*
2135 * set platform specific SMP operations
2136 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2137 index 71a06b2..8bb9ae1 100644
2138 --- a/arch/arm/include/asm/thread_info.h
2139 +++ b/arch/arm/include/asm/thread_info.h
2140 @@ -88,9 +88,9 @@ struct thread_info {
2141 .flags = 0, \
2142 .preempt_count = INIT_PREEMPT_COUNT, \
2143 .addr_limit = KERNEL_DS, \
2144 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2145 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2146 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2147 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2148 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2149 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2150 .restart_block = { \
2151 .fn = do_no_restart_syscall, \
2152 }, \
2153 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2154 #define TIF_SYSCALL_AUDIT 9
2155 #define TIF_SYSCALL_TRACEPOINT 10
2156 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2157 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2158 +/* within 8 bits of TIF_SYSCALL_TRACE
2159 + * to meet flexible second operand requirements
2160 + */
2161 +#define TIF_GRSEC_SETXID 12
2162 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2163 #define TIF_USING_IWMMXT 17
2164 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2165 #define TIF_RESTORE_SIGMASK 20
2166 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2167 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2168 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2169 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2170 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2171
2172 /* Checks for any syscall work in entry-common.S */
2173 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2174 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2175 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2176
2177 /*
2178 * Change these and you break ASM code in entry-common.S
2179 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2180 index 72abdc5..9eba222 100644
2181 --- a/arch/arm/include/asm/uaccess.h
2182 +++ b/arch/arm/include/asm/uaccess.h
2183 @@ -18,6 +18,7 @@
2184 #include <asm/domain.h>
2185 #include <asm/unified.h>
2186 #include <asm/compiler.h>
2187 +#include <asm/pgtable.h>
2188
2189 #if __LINUX_ARM_ARCH__ < 6
2190 #include <asm-generic/uaccess-unaligned.h>
2191 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2192 static inline void set_fs(mm_segment_t fs)
2193 {
2194 current_thread_info()->addr_limit = fs;
2195 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2196 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2197 }
2198
2199 #define segment_eq(a,b) ((a) == (b))
2200
2201 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2202 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2203 +
2204 +static inline void pax_open_userland(void)
2205 +{
2206 +
2207 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2208 + if (segment_eq(get_fs(), USER_DS)) {
2209 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2210 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2211 + }
2212 +#endif
2213 +
2214 +}
2215 +
2216 +static inline void pax_close_userland(void)
2217 +{
2218 +
2219 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2220 + if (segment_eq(get_fs(), USER_DS)) {
2221 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2222 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2223 + }
2224 +#endif
2225 +
2226 +}
2227 +
2228 #define __addr_ok(addr) ({ \
2229 unsigned long flag; \
2230 __asm__("cmp %2, %0; movlo %0, #0" \
2231 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2232
2233 #define get_user(x,p) \
2234 ({ \
2235 + int __e; \
2236 might_fault(); \
2237 - __get_user_check(x,p); \
2238 + pax_open_userland(); \
2239 + __e = __get_user_check(x,p); \
2240 + pax_close_userland(); \
2241 + __e; \
2242 })
2243
2244 extern int __put_user_1(void *, unsigned int);
2245 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2246
2247 #define put_user(x,p) \
2248 ({ \
2249 + int __e; \
2250 might_fault(); \
2251 - __put_user_check(x,p); \
2252 + pax_open_userland(); \
2253 + __e = __put_user_check(x,p); \
2254 + pax_close_userland(); \
2255 + __e; \
2256 })
2257
2258 #else /* CONFIG_MMU */
2259 @@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2260 #define __get_user(x,ptr) \
2261 ({ \
2262 long __gu_err = 0; \
2263 + pax_open_userland(); \
2264 __get_user_err((x),(ptr),__gu_err); \
2265 + pax_close_userland(); \
2266 __gu_err; \
2267 })
2268
2269 #define __get_user_error(x,ptr,err) \
2270 ({ \
2271 + pax_open_userland(); \
2272 __get_user_err((x),(ptr),err); \
2273 + pax_close_userland(); \
2274 (void) 0; \
2275 })
2276
2277 @@ -319,13 +359,17 @@ do { \
2278 #define __put_user(x,ptr) \
2279 ({ \
2280 long __pu_err = 0; \
2281 + pax_open_userland(); \
2282 __put_user_err((x),(ptr),__pu_err); \
2283 + pax_close_userland(); \
2284 __pu_err; \
2285 })
2286
2287 #define __put_user_error(x,ptr,err) \
2288 ({ \
2289 + pax_open_userland(); \
2290 __put_user_err((x),(ptr),err); \
2291 + pax_close_userland(); \
2292 (void) 0; \
2293 })
2294
2295 @@ -425,11 +469,44 @@ do { \
2296
2297
2298 #ifdef CONFIG_MMU
2299 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2300 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2301 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2302 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2303 +
2304 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2305 +{
2306 + unsigned long ret;
2307 +
2308 + check_object_size(to, n, false);
2309 + pax_open_userland();
2310 + ret = ___copy_from_user(to, from, n);
2311 + pax_close_userland();
2312 + return ret;
2313 +}
2314 +
2315 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2316 +{
2317 + unsigned long ret;
2318 +
2319 + check_object_size(from, n, true);
2320 + pax_open_userland();
2321 + ret = ___copy_to_user(to, from, n);
2322 + pax_close_userland();
2323 + return ret;
2324 +}
2325 +
2326 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2327 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2328 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2329 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2330 +
2331 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2332 +{
2333 + unsigned long ret;
2334 + pax_open_userland();
2335 + ret = ___clear_user(addr, n);
2336 + pax_close_userland();
2337 + return ret;
2338 +}
2339 +
2340 #else
2341 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2342 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2343 @@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2344
2345 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2346 {
2347 + if ((long)n < 0)
2348 + return n;
2349 +
2350 if (access_ok(VERIFY_READ, from, n))
2351 n = __copy_from_user(to, from, n);
2352 else /* security hole - plug it */
2353 @@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2354
2355 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2356 {
2357 + if ((long)n < 0)
2358 + return n;
2359 +
2360 if (access_ok(VERIFY_WRITE, to, n))
2361 n = __copy_to_user(to, from, n);
2362 return n;
2363 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2364 index 5af0ed1..cea83883 100644
2365 --- a/arch/arm/include/uapi/asm/ptrace.h
2366 +++ b/arch/arm/include/uapi/asm/ptrace.h
2367 @@ -92,7 +92,7 @@
2368 * ARMv7 groups of PSR bits
2369 */
2370 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2371 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2372 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2373 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2374 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2375
2376 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2377 index 1f031dd..d9b5e4a 100644
2378 --- a/arch/arm/kernel/armksyms.c
2379 +++ b/arch/arm/kernel/armksyms.c
2380 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2381
2382 /* networking */
2383 EXPORT_SYMBOL(csum_partial);
2384 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2385 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2386 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2387 EXPORT_SYMBOL(__csum_ipv6_magic);
2388
2389 @@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2390 #ifdef CONFIG_MMU
2391 EXPORT_SYMBOL(copy_page);
2392
2393 -EXPORT_SYMBOL(__copy_from_user);
2394 -EXPORT_SYMBOL(__copy_to_user);
2395 -EXPORT_SYMBOL(__clear_user);
2396 +EXPORT_SYMBOL(___copy_from_user);
2397 +EXPORT_SYMBOL(___copy_to_user);
2398 +EXPORT_SYMBOL(___clear_user);
2399
2400 EXPORT_SYMBOL(__get_user_1);
2401 EXPORT_SYMBOL(__get_user_2);
2402 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2403 index b3fb8c9..59cfab2 100644
2404 --- a/arch/arm/kernel/entry-armv.S
2405 +++ b/arch/arm/kernel/entry-armv.S
2406 @@ -47,6 +47,87 @@
2407 9997:
2408 .endm
2409
2410 + .macro pax_enter_kernel
2411 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2412 + @ make aligned space for saved DACR
2413 + sub sp, sp, #8
2414 + @ save regs
2415 + stmdb sp!, {r1, r2}
2416 + @ read DACR from cpu_domain into r1
2417 + mov r2, sp
2418 + @ assume 8K pages, since we have to split the immediate in two
2419 + bic r2, r2, #(0x1fc0)
2420 + bic r2, r2, #(0x3f)
2421 + ldr r1, [r2, #TI_CPU_DOMAIN]
2422 + @ store old DACR on stack
2423 + str r1, [sp, #8]
2424 +#ifdef CONFIG_PAX_KERNEXEC
2425 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2426 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2427 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2428 +#endif
2429 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2430 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2431 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2432 +#endif
2433 + @ write r1 to current_thread_info()->cpu_domain
2434 + str r1, [r2, #TI_CPU_DOMAIN]
2435 + @ write r1 to DACR
2436 + mcr p15, 0, r1, c3, c0, 0
2437 + @ instruction sync
2438 + instr_sync
2439 + @ restore regs
2440 + ldmia sp!, {r1, r2}
2441 +#endif
2442 + .endm
2443 +
2444 + .macro pax_open_userland
2445 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2446 + @ save regs
2447 + stmdb sp!, {r0, r1}
2448 + @ read DACR from cpu_domain into r1
2449 + mov r0, sp
2450 + @ assume 8K pages, since we have to split the immediate in two
2451 + bic r0, r0, #(0x1fc0)
2452 + bic r0, r0, #(0x3f)
2453 + ldr r1, [r0, #TI_CPU_DOMAIN]
2454 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2455 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2456 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2457 + @ write r1 to current_thread_info()->cpu_domain
2458 + str r1, [r0, #TI_CPU_DOMAIN]
2459 + @ write r1 to DACR
2460 + mcr p15, 0, r1, c3, c0, 0
2461 + @ instruction sync
2462 + instr_sync
2463 + @ restore regs
2464 + ldmia sp!, {r0, r1}
2465 +#endif
2466 + .endm
2467 +
2468 + .macro pax_close_userland
2469 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2470 + @ save regs
2471 + stmdb sp!, {r0, r1}
2472 + @ read DACR from cpu_domain into r1
2473 + mov r0, sp
2474 + @ assume 8K pages, since we have to split the immediate in two
2475 + bic r0, r0, #(0x1fc0)
2476 + bic r0, r0, #(0x3f)
2477 + ldr r1, [r0, #TI_CPU_DOMAIN]
2478 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2479 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2480 + @ write r1 to current_thread_info()->cpu_domain
2481 + str r1, [r0, #TI_CPU_DOMAIN]
2482 + @ write r1 to DACR
2483 + mcr p15, 0, r1, c3, c0, 0
2484 + @ instruction sync
2485 + instr_sync
2486 + @ restore regs
2487 + ldmia sp!, {r0, r1}
2488 +#endif
2489 + .endm
2490 +
2491 .macro pabt_helper
2492 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2493 #ifdef MULTI_PABORT
2494 @@ -89,11 +170,15 @@
2495 * Invalid mode handlers
2496 */
2497 .macro inv_entry, reason
2498 +
2499 + pax_enter_kernel
2500 +
2501 sub sp, sp, #S_FRAME_SIZE
2502 ARM( stmib sp, {r1 - lr} )
2503 THUMB( stmia sp, {r0 - r12} )
2504 THUMB( str sp, [sp, #S_SP] )
2505 THUMB( str lr, [sp, #S_LR] )
2506 +
2507 mov r1, #\reason
2508 .endm
2509
2510 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2511 .macro svc_entry, stack_hole=0
2512 UNWIND(.fnstart )
2513 UNWIND(.save {r0 - pc} )
2514 +
2515 + pax_enter_kernel
2516 +
2517 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2518 +
2519 #ifdef CONFIG_THUMB2_KERNEL
2520 SPFIX( str r0, [sp] ) @ temporarily saved
2521 SPFIX( mov r0, sp )
2522 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2523 ldmia r0, {r3 - r5}
2524 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2525 mov r6, #-1 @ "" "" "" ""
2526 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2527 + @ offset sp by 8 as done in pax_enter_kernel
2528 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2529 +#else
2530 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2531 +#endif
2532 SPFIX( addeq r2, r2, #4 )
2533 str r3, [sp, #-4]! @ save the "real" r0 copied
2534 @ from the exception stack
2535 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2536 .macro usr_entry
2537 UNWIND(.fnstart )
2538 UNWIND(.cantunwind ) @ don't unwind the user space
2539 +
2540 + pax_enter_kernel_user
2541 +
2542 sub sp, sp, #S_FRAME_SIZE
2543 ARM( stmib sp, {r1 - r12} )
2544 THUMB( stmia sp, {r0 - r12} )
2545 @@ -416,7 +513,9 @@ __und_usr:
2546 tst r3, #PSR_T_BIT @ Thumb mode?
2547 bne __und_usr_thumb
2548 sub r4, r2, #4 @ ARM instr at LR - 4
2549 + pax_open_userland
2550 1: ldrt r0, [r4]
2551 + pax_close_userland
2552 ARM_BE8(rev r0, r0) @ little endian instruction
2553
2554 @ r0 = 32-bit ARM instruction which caused the exception
2555 @@ -450,10 +549,14 @@ __und_usr_thumb:
2556 */
2557 .arch armv6t2
2558 #endif
2559 + pax_open_userland
2560 2: ldrht r5, [r4]
2561 + pax_close_userland
2562 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2563 blo __und_usr_fault_16 @ 16bit undefined instruction
2564 + pax_open_userland
2565 3: ldrht r0, [r2]
2566 + pax_close_userland
2567 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2568 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2569 orr r0, r0, r5, lsl #16
2570 @@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2571 */
2572 .pushsection .fixup, "ax"
2573 .align 2
2574 -4: mov pc, r9
2575 +4: pax_close_userland
2576 + mov pc, r9
2577 .popsection
2578 .pushsection __ex_table,"a"
2579 .long 1b, 4b
2580 @@ -692,7 +796,7 @@ ENTRY(__switch_to)
2581 THUMB( str lr, [ip], #4 )
2582 ldr r4, [r2, #TI_TP_VALUE]
2583 ldr r5, [r2, #TI_TP_VALUE + 4]
2584 -#ifdef CONFIG_CPU_USE_DOMAINS
2585 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2586 ldr r6, [r2, #TI_CPU_DOMAIN]
2587 #endif
2588 switch_tls r1, r4, r5, r3, r7
2589 @@ -701,7 +805,7 @@ ENTRY(__switch_to)
2590 ldr r8, =__stack_chk_guard
2591 ldr r7, [r7, #TSK_STACK_CANARY]
2592 #endif
2593 -#ifdef CONFIG_CPU_USE_DOMAINS
2594 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2596 #endif
2597 mov r5, r0
2598 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2599 index a2dcafd..1048b5a 100644
2600 --- a/arch/arm/kernel/entry-common.S
2601 +++ b/arch/arm/kernel/entry-common.S
2602 @@ -10,18 +10,46 @@
2603
2604 #include <asm/unistd.h>
2605 #include <asm/ftrace.h>
2606 +#include <asm/domain.h>
2607 #include <asm/unwind.h>
2608
2609 +#include "entry-header.S"
2610 +
2611 #ifdef CONFIG_NEED_RET_TO_USER
2612 #include <mach/entry-macro.S>
2613 #else
2614 .macro arch_ret_to_user, tmp1, tmp2
2615 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 + @ save regs
2617 + stmdb sp!, {r1, r2}
2618 + @ read DACR from cpu_domain into r1
2619 + mov r2, sp
2620 + @ assume 8K pages, since we have to split the immediate in two
2621 + bic r2, r2, #(0x1fc0)
2622 + bic r2, r2, #(0x3f)
2623 + ldr r1, [r2, #TI_CPU_DOMAIN]
2624 +#ifdef CONFIG_PAX_KERNEXEC
2625 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2626 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2627 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2628 +#endif
2629 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2630 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2631 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2632 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2633 +#endif
2634 + @ write r1 to current_thread_info()->cpu_domain
2635 + str r1, [r2, #TI_CPU_DOMAIN]
2636 + @ write r1 to DACR
2637 + mcr p15, 0, r1, c3, c0, 0
2638 + @ instruction sync
2639 + instr_sync
2640 + @ restore regs
2641 + ldmia sp!, {r1, r2}
2642 +#endif
2643 .endm
2644 #endif
2645
2646 -#include "entry-header.S"
2647 -
2648 -
2649 .align 5
2650 /*
2651 * This is the fast syscall return path. We do as little as
2652 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2653 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2654 #endif
2655
2656 + /*
2657 + * do this here to avoid a performance hit of wrapping the code above
2658 + * that directly dereferences userland to parse the SWI instruction
2659 + */
2660 + pax_enter_kernel_user
2661 +
2662 adr tbl, sys_call_table @ load syscall table pointer
2663
2664 #if defined(CONFIG_OABI_COMPAT)
2665 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2666 index 39f89fb..d612bd9 100644
2667 --- a/arch/arm/kernel/entry-header.S
2668 +++ b/arch/arm/kernel/entry-header.S
2669 @@ -184,6 +184,60 @@
2670 msr cpsr_c, \rtemp @ switch back to the SVC mode
2671 .endm
2672
2673 + .macro pax_enter_kernel_user
2674 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2675 + @ save regs
2676 + stmdb sp!, {r0, r1}
2677 + @ read DACR from cpu_domain into r1
2678 + mov r0, sp
2679 + @ assume 8K pages, since we have to split the immediate in two
2680 + bic r0, r0, #(0x1fc0)
2681 + bic r0, r0, #(0x3f)
2682 + ldr r1, [r0, #TI_CPU_DOMAIN]
2683 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2684 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2685 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2686 +#endif
2687 +#ifdef CONFIG_PAX_KERNEXEC
2688 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2689 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2690 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2691 +#endif
2692 + @ write r1 to current_thread_info()->cpu_domain
2693 + str r1, [r0, #TI_CPU_DOMAIN]
2694 + @ write r1 to DACR
2695 + mcr p15, 0, r1, c3, c0, 0
2696 + @ instruction sync
2697 + instr_sync
2698 + @ restore regs
2699 + ldmia sp!, {r0, r1}
2700 +#endif
2701 + .endm
2702 +
2703 + .macro pax_exit_kernel
2704 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705 + @ save regs
2706 + stmdb sp!, {r0, r1}
2707 + @ read old DACR from stack into r1
2708 + ldr r1, [sp, #(8 + S_SP)]
2709 + sub r1, r1, #8
2710 + ldr r1, [r1]
2711 +
2712 + @ write r1 to current_thread_info()->cpu_domain
2713 + mov r0, sp
2714 + @ assume 8K pages, since we have to split the immediate in two
2715 + bic r0, r0, #(0x1fc0)
2716 + bic r0, r0, #(0x3f)
2717 + str r1, [r0, #TI_CPU_DOMAIN]
2718 + @ write r1 to DACR
2719 + mcr p15, 0, r1, c3, c0, 0
2720 + @ instruction sync
2721 + instr_sync
2722 + @ restore regs
2723 + ldmia sp!, {r0, r1}
2724 +#endif
2725 + .endm
2726 +
2727 #ifndef CONFIG_THUMB2_KERNEL
2728 .macro svc_exit, rpsr, irq = 0
2729 .if \irq != 0
2730 @@ -203,6 +257,9 @@
2731 blne trace_hardirqs_off
2732 #endif
2733 .endif
2734 +
2735 + pax_exit_kernel
2736 +
2737 msr spsr_cxsf, \rpsr
2738 #if defined(CONFIG_CPU_V6)
2739 ldr r0, [sp]
2740 @@ -266,6 +323,9 @@
2741 blne trace_hardirqs_off
2742 #endif
2743 .endif
2744 +
2745 + pax_exit_kernel
2746 +
2747 ldr lr, [sp, #S_SP] @ top of the stack
2748 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2749 clrex @ clear the exclusive monitor
2750 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2751 index 918875d..cd5fa27 100644
2752 --- a/arch/arm/kernel/fiq.c
2753 +++ b/arch/arm/kernel/fiq.c
2754 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2755 void *base = vectors_page;
2756 unsigned offset = FIQ_OFFSET;
2757
2758 + pax_open_kernel();
2759 memcpy(base + offset, start, length);
2760 + pax_close_kernel();
2761 +
2762 if (!cache_is_vipt_nonaliasing())
2763 flush_icache_range((unsigned long)base + offset, offset +
2764 length);
2765 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2766 index 32f317e..710ae07 100644
2767 --- a/arch/arm/kernel/head.S
2768 +++ b/arch/arm/kernel/head.S
2769 @@ -52,7 +52,9 @@
2770 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2771
2772 .macro pgtbl, rd, phys
2773 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2774 + mov \rd, #TEXT_OFFSET
2775 + sub \rd, #PG_DIR_SIZE
2776 + add \rd, \rd, \phys
2777 .endm
2778
2779 /*
2780 @@ -436,7 +438,7 @@ __enable_mmu:
2781 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2782 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2783 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2784 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2785 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2786 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2787 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2788 #endif
2789 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2790 index 45e4781..8eac93d 100644
2791 --- a/arch/arm/kernel/module.c
2792 +++ b/arch/arm/kernel/module.c
2793 @@ -38,12 +38,39 @@
2794 #endif
2795
2796 #ifdef CONFIG_MMU
2797 -void *module_alloc(unsigned long size)
2798 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2799 {
2800 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2801 + return NULL;
2802 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2803 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2804 + GFP_KERNEL, prot, NUMA_NO_NODE,
2805 __builtin_return_address(0));
2806 }
2807 +
2808 +void *module_alloc(unsigned long size)
2809 +{
2810 +
2811 +#ifdef CONFIG_PAX_KERNEXEC
2812 + return __module_alloc(size, PAGE_KERNEL);
2813 +#else
2814 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2815 +#endif
2816 +
2817 +}
2818 +
2819 +#ifdef CONFIG_PAX_KERNEXEC
2820 +void module_free_exec(struct module *mod, void *module_region)
2821 +{
2822 + module_free(mod, module_region);
2823 +}
2824 +EXPORT_SYMBOL(module_free_exec);
2825 +
2826 +void *module_alloc_exec(unsigned long size)
2827 +{
2828 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2829 +}
2830 +EXPORT_SYMBOL(module_alloc_exec);
2831 +#endif
2832 #endif
2833
2834 int
2835 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2836 index 07314af..c46655c 100644
2837 --- a/arch/arm/kernel/patch.c
2838 +++ b/arch/arm/kernel/patch.c
2839 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2840 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2841 int size;
2842
2843 + pax_open_kernel();
2844 if (thumb2 && __opcode_is_thumb16(insn)) {
2845 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2846 size = sizeof(u16);
2847 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2848 *(u32 *)addr = insn;
2849 size = sizeof(u32);
2850 }
2851 + pax_close_kernel();
2852
2853 flush_icache_range((uintptr_t)(addr),
2854 (uintptr_t)(addr) + size);
2855 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2856 index 92f7b15..7048500 100644
2857 --- a/arch/arm/kernel/process.c
2858 +++ b/arch/arm/kernel/process.c
2859 @@ -217,6 +217,7 @@ void machine_power_off(void)
2860
2861 if (pm_power_off)
2862 pm_power_off();
2863 + BUG();
2864 }
2865
2866 /*
2867 @@ -230,7 +231,7 @@ void machine_power_off(void)
2868 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2869 * to use. Implementing such co-ordination would be essentially impossible.
2870 */
2871 -void machine_restart(char *cmd)
2872 +__noreturn void machine_restart(char *cmd)
2873 {
2874 local_irq_disable();
2875 smp_send_stop();
2876 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2877
2878 show_regs_print_info(KERN_DEFAULT);
2879
2880 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2881 - print_symbol("LR is at %s\n", regs->ARM_lr);
2882 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2883 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2884 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2885 "sp : %08lx ip : %08lx fp : %08lx\n",
2886 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2887 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2888 return 0;
2889 }
2890
2891 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2892 -{
2893 - unsigned long range_end = mm->brk + 0x02000000;
2894 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2895 -}
2896 -
2897 #ifdef CONFIG_MMU
2898 #ifdef CONFIG_KUSER_HELPERS
2899 /*
2900 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2901
2902 static int __init gate_vma_init(void)
2903 {
2904 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2905 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2906 return 0;
2907 }
2908 arch_initcall(gate_vma_init);
2909 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2910
2911 const char *arch_vma_name(struct vm_area_struct *vma)
2912 {
2913 - return is_gate_vma(vma) ? "[vectors]" :
2914 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2915 - "[sigpage]" : NULL;
2916 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2917 }
2918
2919 -static struct page *signal_page;
2920 -extern struct page *get_signal_page(void);
2921 -
2922 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2923 {
2924 struct mm_struct *mm = current->mm;
2925 - unsigned long addr;
2926 - int ret;
2927 -
2928 - if (!signal_page)
2929 - signal_page = get_signal_page();
2930 - if (!signal_page)
2931 - return -ENOMEM;
2932
2933 down_write(&mm->mmap_sem);
2934 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2935 - if (IS_ERR_VALUE(addr)) {
2936 - ret = addr;
2937 - goto up_fail;
2938 - }
2939 -
2940 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2941 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2942 - &signal_page);
2943 -
2944 - if (ret == 0)
2945 - mm->context.sigpage = addr;
2946 -
2947 - up_fail:
2948 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2949 up_write(&mm->mmap_sem);
2950 - return ret;
2951 + return 0;
2952 }
2953 #endif
2954 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2955 index 4693188..4596c5e 100644
2956 --- a/arch/arm/kernel/psci.c
2957 +++ b/arch/arm/kernel/psci.c
2958 @@ -24,7 +24,7 @@
2959 #include <asm/opcodes-virt.h>
2960 #include <asm/psci.h>
2961
2962 -struct psci_operations psci_ops;
2963 +struct psci_operations psci_ops __read_only;
2964
2965 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2966
2967 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2968 index 0dd3b79..e018f64 100644
2969 --- a/arch/arm/kernel/ptrace.c
2970 +++ b/arch/arm/kernel/ptrace.c
2971 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2972 return current_thread_info()->syscall;
2973 }
2974
2975 +#ifdef CONFIG_GRKERNSEC_SETXID
2976 +extern void gr_delayed_cred_worker(void);
2977 +#endif
2978 +
2979 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2980 {
2981 current_thread_info()->syscall = scno;
2982
2983 +#ifdef CONFIG_GRKERNSEC_SETXID
2984 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2985 + gr_delayed_cred_worker();
2986 +#endif
2987 +
2988 /* Do the secure computing check first; failures should be fast. */
2989 if (secure_computing(scno) == -1)
2990 return -1;
2991 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2992 index 987a7f5..d9d6071 100644
2993 --- a/arch/arm/kernel/setup.c
2994 +++ b/arch/arm/kernel/setup.c
2995 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2996 unsigned int elf_hwcap __read_mostly;
2997 EXPORT_SYMBOL(elf_hwcap);
2998
2999 +pteval_t __supported_pte_mask __read_only;
3000 +pmdval_t __supported_pmd_mask __read_only;
3001
3002 #ifdef MULTI_CPU
3003 -struct processor processor __read_mostly;
3004 +struct processor processor;
3005 #endif
3006 #ifdef MULTI_TLB
3007 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3008 +struct cpu_tlb_fns cpu_tlb __read_only;
3009 #endif
3010 #ifdef MULTI_USER
3011 -struct cpu_user_fns cpu_user __read_mostly;
3012 +struct cpu_user_fns cpu_user __read_only;
3013 #endif
3014 #ifdef MULTI_CACHE
3015 -struct cpu_cache_fns cpu_cache __read_mostly;
3016 +struct cpu_cache_fns cpu_cache __read_only;
3017 #endif
3018 #ifdef CONFIG_OUTER_CACHE
3019 -struct outer_cache_fns outer_cache __read_mostly;
3020 +struct outer_cache_fns outer_cache __read_only;
3021 EXPORT_SYMBOL(outer_cache);
3022 #endif
3023
3024 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3025 asm("mrc p15, 0, %0, c0, c1, 4"
3026 : "=r" (mmfr0));
3027 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3028 - (mmfr0 & 0x000000f0) >= 0x00000030)
3029 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3030 cpu_arch = CPU_ARCH_ARMv7;
3031 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3032 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3033 + __supported_pte_mask |= L_PTE_PXN;
3034 + __supported_pmd_mask |= PMD_PXNTABLE;
3035 + }
3036 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3037 (mmfr0 & 0x000000f0) == 0x00000020)
3038 cpu_arch = CPU_ARCH_ARMv6;
3039 else
3040 @@ -573,7 +579,7 @@ static void __init setup_processor(void)
3041 __cpu_architecture = __get_cpu_architecture();
3042
3043 #ifdef MULTI_CPU
3044 - processor = *list->proc;
3045 + memcpy((void *)&processor, list->proc, sizeof processor);
3046 #endif
3047 #ifdef MULTI_TLB
3048 cpu_tlb = *list->tlb;
3049 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3050 index 04d6388..5115238 100644
3051 --- a/arch/arm/kernel/signal.c
3052 +++ b/arch/arm/kernel/signal.c
3053 @@ -23,8 +23,6 @@
3054
3055 extern const unsigned long sigreturn_codes[7];
3056
3057 -static unsigned long signal_return_offset;
3058 -
3059 #ifdef CONFIG_CRUNCH
3060 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3061 {
3062 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3063 * except when the MPU has protected the vectors
3064 * page from PL0
3065 */
3066 - retcode = mm->context.sigpage + signal_return_offset +
3067 - (idx << 2) + thumb;
3068 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3069 } else
3070 #endif
3071 {
3072 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3073 } while (thread_flags & _TIF_WORK_MASK);
3074 return 0;
3075 }
3076 -
3077 -struct page *get_signal_page(void)
3078 -{
3079 - unsigned long ptr;
3080 - unsigned offset;
3081 - struct page *page;
3082 - void *addr;
3083 -
3084 - page = alloc_pages(GFP_KERNEL, 0);
3085 -
3086 - if (!page)
3087 - return NULL;
3088 -
3089 - addr = page_address(page);
3090 -
3091 - /* Give the signal return code some randomness */
3092 - offset = 0x200 + (get_random_int() & 0x7fc);
3093 - signal_return_offset = offset;
3094 -
3095 - /*
3096 - * Copy signal return handlers into the vector page, and
3097 - * set sigreturn to be a pointer to these.
3098 - */
3099 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3100 -
3101 - ptr = (unsigned long)addr + offset;
3102 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3103 -
3104 - return page;
3105 -}
3106 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3107 index dc894ab..f929a0d 100644
3108 --- a/arch/arm/kernel/smp.c
3109 +++ b/arch/arm/kernel/smp.c
3110 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3111
3112 static DECLARE_COMPLETION(cpu_running);
3113
3114 -static struct smp_operations smp_ops;
3115 +static struct smp_operations smp_ops __read_only;
3116
3117 void __init smp_set_ops(struct smp_operations *ops)
3118 {
3119 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3120 index 4636d56..ce4ec3d 100644
3121 --- a/arch/arm/kernel/traps.c
3122 +++ b/arch/arm/kernel/traps.c
3123 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3124 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3125 {
3126 #ifdef CONFIG_KALLSYMS
3127 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3128 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3129 #else
3130 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3131 #endif
3132 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3133 static int die_owner = -1;
3134 static unsigned int die_nest_count;
3135
3136 +extern void gr_handle_kernel_exploit(void);
3137 +
3138 static unsigned long oops_begin(void)
3139 {
3140 int cpu;
3141 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3142 panic("Fatal exception in interrupt");
3143 if (panic_on_oops)
3144 panic("Fatal exception");
3145 +
3146 + gr_handle_kernel_exploit();
3147 +
3148 if (signr)
3149 do_exit(signr);
3150 }
3151 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3152 * The user helper at 0xffff0fe0 must be used instead.
3153 * (see entry-armv.S for details)
3154 */
3155 + pax_open_kernel();
3156 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3157 + pax_close_kernel();
3158 }
3159 return 0;
3160
3161 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3162 kuser_init(vectors_base);
3163
3164 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3165 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3166 +
3167 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3168 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3169 +#endif
3170 +
3171 #else /* ifndef CONFIG_CPU_V7M */
3172 /*
3173 * on V7-M there is no need to copy the vector table to a dedicated
3174 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3175 index 7bcee5c..e2f3249 100644
3176 --- a/arch/arm/kernel/vmlinux.lds.S
3177 +++ b/arch/arm/kernel/vmlinux.lds.S
3178 @@ -8,7 +8,11 @@
3179 #include <asm/thread_info.h>
3180 #include <asm/memory.h>
3181 #include <asm/page.h>
3182 -
3183 +
3184 +#ifdef CONFIG_PAX_KERNEXEC
3185 +#include <asm/pgtable.h>
3186 +#endif
3187 +
3188 #define PROC_INFO \
3189 . = ALIGN(4); \
3190 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3191 @@ -34,7 +38,7 @@
3192 #endif
3193
3194 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3195 - defined(CONFIG_GENERIC_BUG)
3196 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3197 #define ARM_EXIT_KEEP(x) x
3198 #define ARM_EXIT_DISCARD(x)
3199 #else
3200 @@ -90,6 +94,11 @@ SECTIONS
3201 _text = .;
3202 HEAD_TEXT
3203 }
3204 +
3205 +#ifdef CONFIG_PAX_KERNEXEC
3206 + . = ALIGN(1<<SECTION_SHIFT);
3207 +#endif
3208 +
3209 .text : { /* Real text segment */
3210 _stext = .; /* Text and read-only data */
3211 __exception_text_start = .;
3212 @@ -112,6 +121,8 @@ SECTIONS
3213 ARM_CPU_KEEP(PROC_INFO)
3214 }
3215
3216 + _etext = .; /* End of text section */
3217 +
3218 RO_DATA(PAGE_SIZE)
3219
3220 . = ALIGN(4);
3221 @@ -142,7 +153,9 @@ SECTIONS
3222
3223 NOTES
3224
3225 - _etext = .; /* End of text and rodata section */
3226 +#ifdef CONFIG_PAX_KERNEXEC
3227 + . = ALIGN(1<<SECTION_SHIFT);
3228 +#endif
3229
3230 #ifndef CONFIG_XIP_KERNEL
3231 . = ALIGN(PAGE_SIZE);
3232 @@ -220,6 +233,11 @@ SECTIONS
3233 . = PAGE_OFFSET + TEXT_OFFSET;
3234 #else
3235 __init_end = .;
3236 +
3237 +#ifdef CONFIG_PAX_KERNEXEC
3238 + . = ALIGN(1<<SECTION_SHIFT);
3239 +#endif
3240 +
3241 . = ALIGN(THREAD_SIZE);
3242 __data_loc = .;
3243 #endif
3244 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3245 index 2a700e0..745b980 100644
3246 --- a/arch/arm/kvm/arm.c
3247 +++ b/arch/arm/kvm/arm.c
3248 @@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3249 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3250
3251 /* The VMID used in the VTTBR */
3252 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3253 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3254 static u8 kvm_next_vmid;
3255 static DEFINE_SPINLOCK(kvm_vmid_lock);
3256
3257 @@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3258 */
3259 static bool need_new_vmid_gen(struct kvm *kvm)
3260 {
3261 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3262 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3263 }
3264
3265 /**
3266 @@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3267
3268 /* First user of a new VMID generation? */
3269 if (unlikely(kvm_next_vmid == 0)) {
3270 - atomic64_inc(&kvm_vmid_gen);
3271 + atomic64_inc_unchecked(&kvm_vmid_gen);
3272 kvm_next_vmid = 1;
3273
3274 /*
3275 @@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3276 kvm_call_hyp(__kvm_flush_vm_context);
3277 }
3278
3279 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3280 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3281 kvm->arch.vmid = kvm_next_vmid;
3282 kvm_next_vmid++;
3283
3284 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3285 index 14a0d98..7771a7d 100644
3286 --- a/arch/arm/lib/clear_user.S
3287 +++ b/arch/arm/lib/clear_user.S
3288 @@ -12,14 +12,14 @@
3289
3290 .text
3291
3292 -/* Prototype: int __clear_user(void *addr, size_t sz)
3293 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3294 * Purpose : clear some user memory
3295 * Params : addr - user memory address to clear
3296 * : sz - number of bytes to clear
3297 * Returns : number of bytes NOT cleared
3298 */
3299 ENTRY(__clear_user_std)
3300 -WEAK(__clear_user)
3301 +WEAK(___clear_user)
3302 stmfd sp!, {r1, lr}
3303 mov r2, #0
3304 cmp r1, #4
3305 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3306 USER( strnebt r2, [r0])
3307 mov r0, #0
3308 ldmfd sp!, {r1, pc}
3309 -ENDPROC(__clear_user)
3310 +ENDPROC(___clear_user)
3311 ENDPROC(__clear_user_std)
3312
3313 .pushsection .fixup,"ax"
3314 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3315 index 66a477a..bee61d3 100644
3316 --- a/arch/arm/lib/copy_from_user.S
3317 +++ b/arch/arm/lib/copy_from_user.S
3318 @@ -16,7 +16,7 @@
3319 /*
3320 * Prototype:
3321 *
3322 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3323 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3324 *
3325 * Purpose:
3326 *
3327 @@ -84,11 +84,11 @@
3328
3329 .text
3330
3331 -ENTRY(__copy_from_user)
3332 +ENTRY(___copy_from_user)
3333
3334 #include "copy_template.S"
3335
3336 -ENDPROC(__copy_from_user)
3337 +ENDPROC(___copy_from_user)
3338
3339 .pushsection .fixup,"ax"
3340 .align 0
3341 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3342 index 6ee2f67..d1cce76 100644
3343 --- a/arch/arm/lib/copy_page.S
3344 +++ b/arch/arm/lib/copy_page.S
3345 @@ -10,6 +10,7 @@
3346 * ASM optimised string functions
3347 */
3348 #include <linux/linkage.h>
3349 +#include <linux/const.h>
3350 #include <asm/assembler.h>
3351 #include <asm/asm-offsets.h>
3352 #include <asm/cache.h>
3353 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3354 index d066df6..df28194 100644
3355 --- a/arch/arm/lib/copy_to_user.S
3356 +++ b/arch/arm/lib/copy_to_user.S
3357 @@ -16,7 +16,7 @@
3358 /*
3359 * Prototype:
3360 *
3361 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3362 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3363 *
3364 * Purpose:
3365 *
3366 @@ -88,11 +88,11 @@
3367 .text
3368
3369 ENTRY(__copy_to_user_std)
3370 -WEAK(__copy_to_user)
3371 +WEAK(___copy_to_user)
3372
3373 #include "copy_template.S"
3374
3375 -ENDPROC(__copy_to_user)
3376 +ENDPROC(___copy_to_user)
3377 ENDPROC(__copy_to_user_std)
3378
3379 .pushsection .fixup,"ax"
3380 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3381 index 7d08b43..f7ca7ea 100644
3382 --- a/arch/arm/lib/csumpartialcopyuser.S
3383 +++ b/arch/arm/lib/csumpartialcopyuser.S
3384 @@ -57,8 +57,8 @@
3385 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3386 */
3387
3388 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3389 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3390 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3391 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3392
3393 #include "csumpartialcopygeneric.S"
3394
3395 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3396 index 5306de3..aed6d03 100644
3397 --- a/arch/arm/lib/delay.c
3398 +++ b/arch/arm/lib/delay.c
3399 @@ -28,7 +28,7 @@
3400 /*
3401 * Default to the loop-based delay implementation.
3402 */
3403 -struct arm_delay_ops arm_delay_ops = {
3404 +struct arm_delay_ops arm_delay_ops __read_only = {
3405 .delay = __loop_delay,
3406 .const_udelay = __loop_const_udelay,
3407 .udelay = __loop_udelay,
3408 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3409 index 3e58d71..029817c 100644
3410 --- a/arch/arm/lib/uaccess_with_memcpy.c
3411 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3412 @@ -136,7 +136,7 @@ out:
3413 }
3414
3415 unsigned long
3416 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3417 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3418 {
3419 /*
3420 * This test is stubbed out of the main function above to keep
3421 @@ -190,7 +190,7 @@ out:
3422 return n;
3423 }
3424
3425 -unsigned long __clear_user(void __user *addr, unsigned long n)
3426 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3427 {
3428 /* See rational for this in __copy_to_user() above. */
3429 if (n < 64)
3430 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3431 index f3407a5..bd4256f 100644
3432 --- a/arch/arm/mach-kirkwood/common.c
3433 +++ b/arch/arm/mach-kirkwood/common.c
3434 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3435 clk_gate_ops.disable(hw);
3436 }
3437
3438 -static struct clk_ops clk_gate_fn_ops;
3439 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3440 +{
3441 + return clk_gate_ops.is_enabled(hw);
3442 +}
3443 +
3444 +static struct clk_ops clk_gate_fn_ops = {
3445 + .enable = clk_gate_fn_enable,
3446 + .disable = clk_gate_fn_disable,
3447 + .is_enabled = clk_gate_fn_is_enabled,
3448 +};
3449
3450 static struct clk __init *clk_register_gate_fn(struct device *dev,
3451 const char *name,
3452 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3453 gate_fn->fn_en = fn_en;
3454 gate_fn->fn_dis = fn_dis;
3455
3456 - /* ops is the gate ops, but with our enable/disable functions */
3457 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3458 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3459 - clk_gate_fn_ops = clk_gate_ops;
3460 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3461 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3462 - }
3463 -
3464 clk = clk_register(dev, &gate_fn->gate.hw);
3465
3466 if (IS_ERR(clk))
3467 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3468 index 827d1500..2885dc6 100644
3469 --- a/arch/arm/mach-omap2/board-n8x0.c
3470 +++ b/arch/arm/mach-omap2/board-n8x0.c
3471 @@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3472 }
3473 #endif
3474
3475 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3476 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3477 .late_init = n8x0_menelaus_late_init,
3478 };
3479
3480 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3481 index d24926e..a7645a6 100644
3482 --- a/arch/arm/mach-omap2/gpmc.c
3483 +++ b/arch/arm/mach-omap2/gpmc.c
3484 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3485 };
3486
3487 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3488 -static struct irq_chip gpmc_irq_chip;
3489 static int gpmc_irq_start;
3490
3491 static struct resource gpmc_mem_root;
3492 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3493
3494 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3495
3496 +static struct irq_chip gpmc_irq_chip = {
3497 + .name = "gpmc",
3498 + .irq_startup = gpmc_irq_noop_ret,
3499 + .irq_enable = gpmc_irq_enable,
3500 + .irq_disable = gpmc_irq_disable,
3501 + .irq_shutdown = gpmc_irq_noop,
3502 + .irq_ack = gpmc_irq_noop,
3503 + .irq_mask = gpmc_irq_noop,
3504 + .irq_unmask = gpmc_irq_noop,
3505 +
3506 +};
3507 +
3508 static int gpmc_setup_irq(void)
3509 {
3510 int i;
3511 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3512 return gpmc_irq_start;
3513 }
3514
3515 - gpmc_irq_chip.name = "gpmc";
3516 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3517 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3518 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3519 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3520 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3521 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3522 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3523 -
3524 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3525 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3526
3527 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3528 index f991016..145ebeb 100644
3529 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3531 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3532 int (*finish_suspend)(unsigned long cpu_state);
3533 void (*resume)(void);
3534 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3535 -};
3536 +} __no_const;
3537
3538 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3539 static struct powerdomain *mpuss_pd;
3540 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3541 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3542 {}
3543
3544 -struct cpu_pm_ops omap_pm_ops = {
3545 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3546 .finish_suspend = default_finish_suspend,
3547 .resume = dummy_cpu_resume,
3548 .scu_prepare = dummy_scu_prepare,
3549 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3550 index 3664562..72f85c6 100644
3551 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3552 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3553 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3554 return NOTIFY_OK;
3555 }
3556
3557 -static struct notifier_block __refdata irq_hotplug_notifier = {
3558 +static struct notifier_block irq_hotplug_notifier = {
3559 .notifier_call = irq_cpu_hotplug_notify,
3560 };
3561
3562 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3563 index e0a398c..a470fa5 100644
3564 --- a/arch/arm/mach-omap2/omap_device.c
3565 +++ b/arch/arm/mach-omap2/omap_device.c
3566 @@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3567 struct platform_device __init *omap_device_build(const char *pdev_name,
3568 int pdev_id,
3569 struct omap_hwmod *oh,
3570 - void *pdata, int pdata_len)
3571 + const void *pdata, int pdata_len)
3572 {
3573 struct omap_hwmod *ohs[] = { oh };
3574
3575 @@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3576 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3577 int pdev_id,
3578 struct omap_hwmod **ohs,
3579 - int oh_cnt, void *pdata,
3580 + int oh_cnt, const void *pdata,
3581 int pdata_len)
3582 {
3583 int ret = -ENOMEM;
3584 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3585 index 78c02b3..c94109a 100644
3586 --- a/arch/arm/mach-omap2/omap_device.h
3587 +++ b/arch/arm/mach-omap2/omap_device.h
3588 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3589 /* Core code interface */
3590
3591 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3592 - struct omap_hwmod *oh, void *pdata,
3593 + struct omap_hwmod *oh, const void *pdata,
3594 int pdata_len);
3595
3596 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3597 struct omap_hwmod **oh, int oh_cnt,
3598 - void *pdata, int pdata_len);
3599 + const void *pdata, int pdata_len);
3600
3601 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3602 struct omap_hwmod **ohs, int oh_cnt);
3603 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3604 index 8a1b5e0..5f30074 100644
3605 --- a/arch/arm/mach-omap2/omap_hwmod.c
3606 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3607 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3608 int (*init_clkdm)(struct omap_hwmod *oh);
3609 void (*update_context_lost)(struct omap_hwmod *oh);
3610 int (*get_context_lost)(struct omap_hwmod *oh);
3611 -};
3612 +} __no_const;
3613
3614 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3615 -static struct omap_hwmod_soc_ops soc_ops;
3616 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3617
3618 /* omap_hwmod_list contains all registered struct omap_hwmods */
3619 static LIST_HEAD(omap_hwmod_list);
3620 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3621 index 95fee54..cfa9cf1 100644
3622 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3623 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3624 @@ -10,6 +10,7 @@
3625
3626 #include <linux/kernel.h>
3627 #include <linux/init.h>
3628 +#include <asm/pgtable.h>
3629
3630 #include "powerdomain.h"
3631
3632 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3633
3634 void __init am43xx_powerdomains_init(void)
3635 {
3636 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3637 + pax_open_kernel();
3638 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3639 + pax_close_kernel();
3640 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3641 pwrdm_register_pwrdms(powerdomains_am43xx);
3642 pwrdm_complete_init();
3643 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3644 index d15c7bb..b2d1f0c 100644
3645 --- a/arch/arm/mach-omap2/wd_timer.c
3646 +++ b/arch/arm/mach-omap2/wd_timer.c
3647 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3648 struct omap_hwmod *oh;
3649 char *oh_name = "wd_timer2";
3650 char *dev_name = "omap_wdt";
3651 - struct omap_wd_timer_platform_data pdata;
3652 + static struct omap_wd_timer_platform_data pdata = {
3653 + .read_reset_sources = prm_read_reset_sources
3654 + };
3655
3656 if (!cpu_class_is_omap2() || of_have_populated_dt())
3657 return 0;
3658 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3659 return -EINVAL;
3660 }
3661
3662 - pdata.read_reset_sources = prm_read_reset_sources;
3663 -
3664 pdev = omap_device_build(dev_name, id, oh, &pdata,
3665 sizeof(struct omap_wd_timer_platform_data));
3666 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3667 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3668 index b82dcae..44ee5b6 100644
3669 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3670 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3671 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3672 bool entered_lp2 = false;
3673
3674 if (tegra_pending_sgi())
3675 - ACCESS_ONCE(abort_flag) = true;
3676 + ACCESS_ONCE_RW(abort_flag) = true;
3677
3678 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3679
3680 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3681 index bdb3564..cebb96f 100644
3682 --- a/arch/arm/mach-ux500/setup.h
3683 +++ b/arch/arm/mach-ux500/setup.h
3684 @@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3685 .type = MT_DEVICE, \
3686 }
3687
3688 -#define __MEM_DEV_DESC(x, sz) { \
3689 - .virtual = IO_ADDRESS(x), \
3690 - .pfn = __phys_to_pfn(x), \
3691 - .length = sz, \
3692 - .type = MT_MEMORY, \
3693 -}
3694 -
3695 extern struct smp_operations ux500_smp_ops;
3696 extern void ux500_cpu_die(unsigned int cpu);
3697
3698 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3699 index 1f8fed9..14d7823 100644
3700 --- a/arch/arm/mm/Kconfig
3701 +++ b/arch/arm/mm/Kconfig
3702 @@ -446,7 +446,7 @@ config CPU_32v5
3703
3704 config CPU_32v6
3705 bool
3706 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3707 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3708 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3709
3710 config CPU_32v6K
3711 @@ -601,6 +601,7 @@ config CPU_CP15_MPU
3712
3713 config CPU_USE_DOMAINS
3714 bool
3715 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3716 help
3717 This option enables or disables the use of domain switching
3718 via the set_fs() function.
3719 @@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3720 config KUSER_HELPERS
3721 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3722 default y
3723 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3724 help
3725 Warning: disabling this option may break user programs.
3726
3727 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3728 See Documentation/arm/kernel_user_helpers.txt for details.
3729
3730 However, the fixed address nature of these helpers can be used
3731 - by ROP (return orientated programming) authors when creating
3732 + by ROP (Return Oriented Programming) authors when creating
3733 exploits.
3734
3735 If all of the binaries and libraries which run on your platform
3736 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3737 index 9240364..a2b8cf3 100644
3738 --- a/arch/arm/mm/alignment.c
3739 +++ b/arch/arm/mm/alignment.c
3740 @@ -212,10 +212,12 @@ union offset_union {
3741 #define __get16_unaligned_check(ins,val,addr) \
3742 do { \
3743 unsigned int err = 0, v, a = addr; \
3744 + pax_open_userland(); \
3745 __get8_unaligned_check(ins,v,a,err); \
3746 val = v << ((BE) ? 8 : 0); \
3747 __get8_unaligned_check(ins,v,a,err); \
3748 val |= v << ((BE) ? 0 : 8); \
3749 + pax_close_userland(); \
3750 if (err) \
3751 goto fault; \
3752 } while (0)
3753 @@ -229,6 +231,7 @@ union offset_union {
3754 #define __get32_unaligned_check(ins,val,addr) \
3755 do { \
3756 unsigned int err = 0, v, a = addr; \
3757 + pax_open_userland(); \
3758 __get8_unaligned_check(ins,v,a,err); \
3759 val = v << ((BE) ? 24 : 0); \
3760 __get8_unaligned_check(ins,v,a,err); \
3761 @@ -237,6 +240,7 @@ union offset_union {
3762 val |= v << ((BE) ? 8 : 16); \
3763 __get8_unaligned_check(ins,v,a,err); \
3764 val |= v << ((BE) ? 0 : 24); \
3765 + pax_close_userland(); \
3766 if (err) \
3767 goto fault; \
3768 } while (0)
3769 @@ -250,6 +254,7 @@ union offset_union {
3770 #define __put16_unaligned_check(ins,val,addr) \
3771 do { \
3772 unsigned int err = 0, v = val, a = addr; \
3773 + pax_open_userland(); \
3774 __asm__( FIRST_BYTE_16 \
3775 ARM( "1: "ins" %1, [%2], #1\n" ) \
3776 THUMB( "1: "ins" %1, [%2]\n" ) \
3777 @@ -269,6 +274,7 @@ union offset_union {
3778 " .popsection\n" \
3779 : "=r" (err), "=&r" (v), "=&r" (a) \
3780 : "0" (err), "1" (v), "2" (a)); \
3781 + pax_close_userland(); \
3782 if (err) \
3783 goto fault; \
3784 } while (0)
3785 @@ -282,6 +288,7 @@ union offset_union {
3786 #define __put32_unaligned_check(ins,val,addr) \
3787 do { \
3788 unsigned int err = 0, v = val, a = addr; \
3789 + pax_open_userland(); \
3790 __asm__( FIRST_BYTE_32 \
3791 ARM( "1: "ins" %1, [%2], #1\n" ) \
3792 THUMB( "1: "ins" %1, [%2]\n" ) \
3793 @@ -311,6 +318,7 @@ union offset_union {
3794 " .popsection\n" \
3795 : "=r" (err), "=&r" (v), "=&r" (a) \
3796 : "0" (err), "1" (v), "2" (a)); \
3797 + pax_close_userland(); \
3798 if (err) \
3799 goto fault; \
3800 } while (0)
3801 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3802 index 447da6f..77a5057 100644
3803 --- a/arch/arm/mm/cache-l2x0.c
3804 +++ b/arch/arm/mm/cache-l2x0.c
3805 @@ -45,7 +45,7 @@ struct l2x0_of_data {
3806 void (*setup)(const struct device_node *, u32 *, u32 *);
3807 void (*save)(void);
3808 struct outer_cache_fns outer_cache;
3809 -};
3810 +} __do_const;
3811
3812 static bool of_init = false;
3813
3814 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3815 index 84e6f77..0b52f31 100644
3816 --- a/arch/arm/mm/context.c
3817 +++ b/arch/arm/mm/context.c
3818 @@ -43,7 +43,7 @@
3819 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3820
3821 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3822 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3823 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3824 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3825
3826 static DEFINE_PER_CPU(atomic64_t, active_asids);
3827 @@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3828 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3829 {
3830 u64 asid = atomic64_read(&mm->context.id);
3831 - u64 generation = atomic64_read(&asid_generation);
3832 + u64 generation = atomic64_read_unchecked(&asid_generation);
3833
3834 if (asid != 0 && is_reserved_asid(asid)) {
3835 /*
3836 @@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3837 */
3838 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3839 if (asid == NUM_USER_ASIDS) {
3840 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3841 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3842 &asid_generation);
3843 flush_context(cpu);
3844 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3845 @@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3846 cpu_set_reserved_ttbr0();
3847
3848 asid = atomic64_read(&mm->context.id);
3849 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3850 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3851 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3852 goto switch_mm_fastpath;
3853
3854 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3855 /* Check that our ASID belongs to the current generation. */
3856 asid = atomic64_read(&mm->context.id);
3857 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3858 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3859 asid = new_context(mm, cpu);
3860 atomic64_set(&mm->context.id, asid);
3861 }
3862 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3863 index eb8830a..5360ce7 100644
3864 --- a/arch/arm/mm/fault.c
3865 +++ b/arch/arm/mm/fault.c
3866 @@ -25,6 +25,7 @@
3867 #include <asm/system_misc.h>
3868 #include <asm/system_info.h>
3869 #include <asm/tlbflush.h>
3870 +#include <asm/sections.h>
3871
3872 #include "fault.h"
3873
3874 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3875 if (fixup_exception(regs))
3876 return;
3877
3878 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3879 + if (addr < TASK_SIZE) {
3880 + if (current->signal->curr_ip)
3881 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3882 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3883 + else
3884 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3885 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3886 + }
3887 +#endif
3888 +
3889 +#ifdef CONFIG_PAX_KERNEXEC
3890 + if ((fsr & FSR_WRITE) &&
3891 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3892 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3893 + {
3894 + if (current->signal->curr_ip)
3895 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3896 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3897 + else
3898 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3899 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3900 + }
3901 +#endif
3902 +
3903 /*
3904 * No handler, we'll have to terminate things with extreme prejudice.
3905 */
3906 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3907 }
3908 #endif
3909
3910 +#ifdef CONFIG_PAX_PAGEEXEC
3911 + if (fsr & FSR_LNX_PF) {
3912 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3913 + do_group_exit(SIGKILL);
3914 + }
3915 +#endif
3916 +
3917 tsk->thread.address = addr;
3918 tsk->thread.error_code = fsr;
3919 tsk->thread.trap_no = 14;
3920 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3921 }
3922 #endif /* CONFIG_MMU */
3923
3924 +#ifdef CONFIG_PAX_PAGEEXEC
3925 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3926 +{
3927 + long i;
3928 +
3929 + printk(KERN_ERR "PAX: bytes at PC: ");
3930 + for (i = 0; i < 20; i++) {
3931 + unsigned char c;
3932 + if (get_user(c, (__force unsigned char __user *)pc+i))
3933 + printk(KERN_CONT "?? ");
3934 + else
3935 + printk(KERN_CONT "%02x ", c);
3936 + }
3937 + printk("\n");
3938 +
3939 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3940 + for (i = -1; i < 20; i++) {
3941 + unsigned long c;
3942 + if (get_user(c, (__force unsigned long __user *)sp+i))
3943 + printk(KERN_CONT "???????? ");
3944 + else
3945 + printk(KERN_CONT "%08lx ", c);
3946 + }
3947 + printk("\n");
3948 +}
3949 +#endif
3950 +
3951 /*
3952 * First Level Translation Fault Handler
3953 *
3954 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3955 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3956 struct siginfo info;
3957
3958 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3959 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3960 + if (current->signal->curr_ip)
3961 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3962 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3963 + else
3964 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3965 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3966 + goto die;
3967 + }
3968 +#endif
3969 +
3970 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3971 return;
3972
3973 +die:
3974 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3975 inf->name, fsr, addr);
3976
3977 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3978 ifsr_info[nr].name = name;
3979 }
3980
3981 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3982 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3983 +
3984 asmlinkage void __exception
3985 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3986 {
3987 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3988 struct siginfo info;
3989 + unsigned long pc = instruction_pointer(regs);
3990 +
3991 + if (user_mode(regs)) {
3992 + unsigned long sigpage = current->mm->context.sigpage;
3993 +
3994 + if (sigpage <= pc && pc < sigpage + 7*4) {
3995 + if (pc < sigpage + 3*4)
3996 + sys_sigreturn(regs);
3997 + else
3998 + sys_rt_sigreturn(regs);
3999 + return;
4000 + }
4001 + if (pc == 0xffff0f60UL) {
4002 + /*
4003 + * PaX: __kuser_cmpxchg64 emulation
4004 + */
4005 + // TODO
4006 + //regs->ARM_pc = regs->ARM_lr;
4007 + //return;
4008 + }
4009 + if (pc == 0xffff0fa0UL) {
4010 + /*
4011 + * PaX: __kuser_memory_barrier emulation
4012 + */
4013 + // dmb(); implied by the exception
4014 + regs->ARM_pc = regs->ARM_lr;
4015 + return;
4016 + }
4017 + if (pc == 0xffff0fc0UL) {
4018 + /*
4019 + * PaX: __kuser_cmpxchg emulation
4020 + */
4021 + // TODO
4022 + //long new;
4023 + //int op;
4024 +
4025 + //op = FUTEX_OP_SET << 28;
4026 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4027 + //regs->ARM_r0 = old != new;
4028 + //regs->ARM_pc = regs->ARM_lr;
4029 + //return;
4030 + }
4031 + if (pc == 0xffff0fe0UL) {
4032 + /*
4033 + * PaX: __kuser_get_tls emulation
4034 + */
4035 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4036 + regs->ARM_pc = regs->ARM_lr;
4037 + return;
4038 + }
4039 + }
4040 +
4041 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4042 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4043 + if (current->signal->curr_ip)
4044 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4045 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4046 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4047 + else
4048 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4049 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4050 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4051 + goto die;
4052 + }
4053 +#endif
4054 +
4055 +#ifdef CONFIG_PAX_REFCOUNT
4056 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4057 + unsigned int bkpt;
4058 +
4059 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4060 + current->thread.error_code = ifsr;
4061 + current->thread.trap_no = 0;
4062 + pax_report_refcount_overflow(regs);
4063 + fixup_exception(regs);
4064 + return;
4065 + }
4066 + }
4067 +#endif
4068
4069 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4070 return;
4071
4072 +die:
4073 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4074 inf->name, ifsr, addr);
4075
4076 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4077 index cf08bdf..772656c 100644
4078 --- a/arch/arm/mm/fault.h
4079 +++ b/arch/arm/mm/fault.h
4080 @@ -3,6 +3,7 @@
4081
4082 /*
4083 * Fault status register encodings. We steal bit 31 for our own purposes.
4084 + * Set when the FSR value is from an instruction fault.
4085 */
4086 #define FSR_LNX_PF (1 << 31)
4087 #define FSR_WRITE (1 << 11)
4088 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4089 }
4090 #endif
4091
4092 +/* valid for LPAE and !LPAE */
4093 +static inline int is_xn_fault(unsigned int fsr)
4094 +{
4095 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4096 +}
4097 +
4098 +static inline int is_domain_fault(unsigned int fsr)
4099 +{
4100 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4101 +}
4102 +
4103 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4104 unsigned long search_exception_table(unsigned long addr);
4105
4106 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4107 index 3e8f106..a0a1fe4 100644
4108 --- a/arch/arm/mm/init.c
4109 +++ b/arch/arm/mm/init.c
4110 @@ -30,6 +30,8 @@
4111 #include <asm/setup.h>
4112 #include <asm/tlb.h>
4113 #include <asm/fixmap.h>
4114 +#include <asm/system_info.h>
4115 +#include <asm/cp15.h>
4116
4117 #include <asm/mach/arch.h>
4118 #include <asm/mach/map.h>
4119 @@ -681,7 +683,46 @@ void free_initmem(void)
4120 {
4121 #ifdef CONFIG_HAVE_TCM
4122 extern char __tcm_start, __tcm_end;
4123 +#endif
4124
4125 +#ifdef CONFIG_PAX_KERNEXEC
4126 + unsigned long addr;
4127 + pgd_t *pgd;
4128 + pud_t *pud;
4129 + pmd_t *pmd;
4130 + int cpu_arch = cpu_architecture();
4131 + unsigned int cr = get_cr();
4132 +
4133 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4134 + /* make pages tables, etc before .text NX */
4135 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4136 + pgd = pgd_offset_k(addr);
4137 + pud = pud_offset(pgd, addr);
4138 + pmd = pmd_offset(pud, addr);
4139 + __section_update(pmd, addr, PMD_SECT_XN);
4140 + }
4141 + /* make init NX */
4142 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4143 + pgd = pgd_offset_k(addr);
4144 + pud = pud_offset(pgd, addr);
4145 + pmd = pmd_offset(pud, addr);
4146 + __section_update(pmd, addr, PMD_SECT_XN);
4147 + }
4148 + /* make kernel code/rodata RX */
4149 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4150 + pgd = pgd_offset_k(addr);
4151 + pud = pud_offset(pgd, addr);
4152 + pmd = pmd_offset(pud, addr);
4153 +#ifdef CONFIG_ARM_LPAE
4154 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4155 +#else
4156 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4157 +#endif
4158 + }
4159 + }
4160 +#endif
4161 +
4162 +#ifdef CONFIG_HAVE_TCM
4163 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4164 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4165 #endif
4166 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4167 index f123d6e..04bf569 100644
4168 --- a/arch/arm/mm/ioremap.c
4169 +++ b/arch/arm/mm/ioremap.c
4170 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4171 unsigned int mtype;
4172
4173 if (cached)
4174 - mtype = MT_MEMORY;
4175 + mtype = MT_MEMORY_RX;
4176 else
4177 - mtype = MT_MEMORY_NONCACHED;
4178 + mtype = MT_MEMORY_NONCACHED_RX;
4179
4180 return __arm_ioremap_caller(phys_addr, size, mtype,
4181 __builtin_return_address(0));
4182 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4183 index 5e85ed3..b10a7ed 100644
4184 --- a/arch/arm/mm/mmap.c
4185 +++ b/arch/arm/mm/mmap.c
4186 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4187 struct vm_area_struct *vma;
4188 int do_align = 0;
4189 int aliasing = cache_is_vipt_aliasing();
4190 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4191 struct vm_unmapped_area_info info;
4192
4193 /*
4194 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4195 if (len > TASK_SIZE)
4196 return -ENOMEM;
4197
4198 +#ifdef CONFIG_PAX_RANDMMAP
4199 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4200 +#endif
4201 +
4202 if (addr) {
4203 if (do_align)
4204 addr = COLOUR_ALIGN(addr, pgoff);
4205 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4206 addr = PAGE_ALIGN(addr);
4207
4208 vma = find_vma(mm, addr);
4209 - if (TASK_SIZE - len >= addr &&
4210 - (!vma || addr + len <= vma->vm_start))
4211 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4212 return addr;
4213 }
4214
4215 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4216 info.high_limit = TASK_SIZE;
4217 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4218 info.align_offset = pgoff << PAGE_SHIFT;
4219 + info.threadstack_offset = offset;
4220 return vm_unmapped_area(&info);
4221 }
4222
4223 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4224 unsigned long addr = addr0;
4225 int do_align = 0;
4226 int aliasing = cache_is_vipt_aliasing();
4227 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4228 struct vm_unmapped_area_info info;
4229
4230 /*
4231 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4232 return addr;
4233 }
4234
4235 +#ifdef CONFIG_PAX_RANDMMAP
4236 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4237 +#endif
4238 +
4239 /* requesting a specific address */
4240 if (addr) {
4241 if (do_align)
4242 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4243 else
4244 addr = PAGE_ALIGN(addr);
4245 vma = find_vma(mm, addr);
4246 - if (TASK_SIZE - len >= addr &&
4247 - (!vma || addr + len <= vma->vm_start))
4248 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4249 return addr;
4250 }
4251
4252 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4253 info.high_limit = mm->mmap_base;
4254 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4255 info.align_offset = pgoff << PAGE_SHIFT;
4256 + info.threadstack_offset = offset;
4257 addr = vm_unmapped_area(&info);
4258
4259 /*
4260 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4261 {
4262 unsigned long random_factor = 0UL;
4263
4264 +#ifdef CONFIG_PAX_RANDMMAP
4265 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4266 +#endif
4267 +
4268 /* 8 bits of randomness in 20 address space bits */
4269 if ((current->flags & PF_RANDOMIZE) &&
4270 !(current->personality & ADDR_NO_RANDOMIZE))
4271 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4272
4273 if (mmap_is_legacy()) {
4274 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4275 +
4276 +#ifdef CONFIG_PAX_RANDMMAP
4277 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4278 + mm->mmap_base += mm->delta_mmap;
4279 +#endif
4280 +
4281 mm->get_unmapped_area = arch_get_unmapped_area;
4282 } else {
4283 mm->mmap_base = mmap_base(random_factor);
4284 +
4285 +#ifdef CONFIG_PAX_RANDMMAP
4286 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4287 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4288 +#endif
4289 +
4290 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4291 }
4292 }
4293 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4294 index 580ef2d..2da06ca 100644
4295 --- a/arch/arm/mm/mmu.c
4296 +++ b/arch/arm/mm/mmu.c
4297 @@ -38,6 +38,22 @@
4298 #include "mm.h"
4299 #include "tcm.h"
4300
4301 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4302 +void modify_domain(unsigned int dom, unsigned int type)
4303 +{
4304 + struct thread_info *thread = current_thread_info();
4305 + unsigned int domain = thread->cpu_domain;
4306 + /*
4307 + * DOMAIN_MANAGER might be defined to some other value,
4308 + * use the arch-defined constant
4309 + */
4310 + domain &= ~domain_val(dom, 3);
4311 + thread->cpu_domain = domain | domain_val(dom, type);
4312 + set_domain(thread->cpu_domain);
4313 +}
4314 +EXPORT_SYMBOL(modify_domain);
4315 +#endif
4316 +
4317 /*
4318 * empty_zero_page is a special page that is used for
4319 * zero-initialized data and COW.
4320 @@ -230,10 +246,18 @@ __setup("noalign", noalign_setup);
4321
4322 #endif /* ifdef CONFIG_CPU_CP15 / else */
4323
4324 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4325 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4326 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4327
4328 -static struct mem_type mem_types[] = {
4329 +#ifdef CONFIG_PAX_KERNEXEC
4330 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4331 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4332 +#else
4333 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4334 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4335 +#endif
4336 +
4337 +static struct mem_type mem_types[] __read_only = {
4338 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4339 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4340 L_PTE_SHARED,
4341 @@ -262,16 +286,16 @@ static struct mem_type mem_types[] = {
4342 [MT_UNCACHED] = {
4343 .prot_pte = PROT_PTE_DEVICE,
4344 .prot_l1 = PMD_TYPE_TABLE,
4345 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4346 + .prot_sect = PROT_SECT_DEVICE,
4347 .domain = DOMAIN_IO,
4348 },
4349 [MT_CACHECLEAN] = {
4350 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4351 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4352 .domain = DOMAIN_KERNEL,
4353 },
4354 #ifndef CONFIG_ARM_LPAE
4355 [MT_MINICLEAN] = {
4356 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4357 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4358 .domain = DOMAIN_KERNEL,
4359 },
4360 #endif
4361 @@ -279,36 +303,54 @@ static struct mem_type mem_types[] = {
4362 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4363 L_PTE_RDONLY,
4364 .prot_l1 = PMD_TYPE_TABLE,
4365 - .domain = DOMAIN_USER,
4366 + .domain = DOMAIN_VECTORS,
4367 },
4368 [MT_HIGH_VECTORS] = {
4369 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4370 L_PTE_USER | L_PTE_RDONLY,
4371 .prot_l1 = PMD_TYPE_TABLE,
4372 - .domain = DOMAIN_USER,
4373 + .domain = DOMAIN_VECTORS,
4374 },
4375 - [MT_MEMORY] = {
4376 + [MT_MEMORY_RWX] = {
4377 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4378 .prot_l1 = PMD_TYPE_TABLE,
4379 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4380 .domain = DOMAIN_KERNEL,
4381 },
4382 + [MT_MEMORY_RW] = {
4383 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4384 + .prot_l1 = PMD_TYPE_TABLE,
4385 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4386 + .domain = DOMAIN_KERNEL,
4387 + },
4388 + [MT_MEMORY_RX] = {
4389 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4390 + .prot_l1 = PMD_TYPE_TABLE,
4391 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4392 + .domain = DOMAIN_KERNEL,
4393 + },
4394 [MT_ROM] = {
4395 - .prot_sect = PMD_TYPE_SECT,
4396 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4397 .domain = DOMAIN_KERNEL,
4398 },
4399 - [MT_MEMORY_NONCACHED] = {
4400 + [MT_MEMORY_NONCACHED_RW] = {
4401 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4402 L_PTE_MT_BUFFERABLE,
4403 .prot_l1 = PMD_TYPE_TABLE,
4404 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4405 .domain = DOMAIN_KERNEL,
4406 },
4407 + [MT_MEMORY_NONCACHED_RX] = {
4408 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4409 + L_PTE_MT_BUFFERABLE,
4410 + .prot_l1 = PMD_TYPE_TABLE,
4411 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4412 + .domain = DOMAIN_KERNEL,
4413 + },
4414 [MT_MEMORY_DTCM] = {
4415 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4416 - L_PTE_XN,
4417 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4418 .prot_l1 = PMD_TYPE_TABLE,
4419 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4420 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4421 .domain = DOMAIN_KERNEL,
4422 },
4423 [MT_MEMORY_ITCM] = {
4424 @@ -318,10 +360,10 @@ static struct mem_type mem_types[] = {
4425 },
4426 [MT_MEMORY_SO] = {
4427 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4428 - L_PTE_MT_UNCACHED | L_PTE_XN,
4429 + L_PTE_MT_UNCACHED,
4430 .prot_l1 = PMD_TYPE_TABLE,
4431 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4432 - PMD_SECT_UNCACHED | PMD_SECT_XN,
4433 + PMD_SECT_UNCACHED,
4434 .domain = DOMAIN_KERNEL,
4435 },
4436 [MT_MEMORY_DMA_READY] = {
4437 @@ -407,9 +449,35 @@ static void __init build_mem_type_table(void)
4438 * to prevent speculative instruction fetches.
4439 */
4440 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4441 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4442 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4443 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4444 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4445 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4446 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4447 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4448 +
4449 + /* Mark other regions on ARMv6+ as execute-never */
4450 +
4451 +#ifdef CONFIG_PAX_KERNEXEC
4452 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4453 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4454 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4455 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4456 +#ifndef CONFIG_ARM_LPAE
4457 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4458 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4459 +#endif
4460 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4461 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4462 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4463 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4464 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4465 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4466 +#endif
4467 +
4468 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4469 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4470 }
4471 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4472 /*
4473 @@ -470,6 +538,9 @@ static void __init build_mem_type_table(void)
4474 * from SVC mode and no access from userspace.
4475 */
4476 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4477 +#ifdef CONFIG_PAX_KERNEXEC
4478 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4479 +#endif
4480 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4481 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4482 #endif
4483 @@ -487,11 +558,17 @@ static void __init build_mem_type_table(void)
4484 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4485 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4486 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4487 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4488 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4489 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4490 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4491 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4492 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4493 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4494 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4495 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4496 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4497 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4498 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4499 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4500 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4501 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4502 }
4503 }
4504
4505 @@ -502,15 +579,20 @@ static void __init build_mem_type_table(void)
4506 if (cpu_arch >= CPU_ARCH_ARMv6) {
4507 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4508 /* Non-cacheable Normal is XCB = 001 */
4509 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4510 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4511 + PMD_SECT_BUFFERED;
4512 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4513 PMD_SECT_BUFFERED;
4514 } else {
4515 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4516 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4517 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4518 + PMD_SECT_TEX(1);
4519 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4520 PMD_SECT_TEX(1);
4521 }
4522 } else {
4523 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4524 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4525 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4526 }
4527
4528 #ifdef CONFIG_ARM_LPAE
4529 @@ -526,6 +608,8 @@ static void __init build_mem_type_table(void)
4530 vecs_pgprot |= PTE_EXT_AF;
4531 #endif
4532
4533 + user_pgprot |= __supported_pte_mask;
4534 +
4535 for (i = 0; i < 16; i++) {
4536 pteval_t v = pgprot_val(protection_map[i]);
4537 protection_map[i] = __pgprot(v | user_pgprot);
4538 @@ -543,10 +627,15 @@ static void __init build_mem_type_table(void)
4539
4540 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4541 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4542 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4543 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4544 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4545 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4546 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4547 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4548 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4549 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4550 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4551 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4552 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4553 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4554 mem_types[MT_ROM].prot_sect |= cp->pmd;
4555
4556 switch (cp->pmd) {
4557 @@ -1188,18 +1277,15 @@ void __init arm_mm_memblock_reserve(void)
4558 * called function. This means you can't use any function or debugging
4559 * method which may touch any device, otherwise the kernel _will_ crash.
4560 */
4561 +
4562 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4563 +
4564 static void __init devicemaps_init(const struct machine_desc *mdesc)
4565 {
4566 struct map_desc map;
4567 unsigned long addr;
4568 - void *vectors;
4569
4570 - /*
4571 - * Allocate the vector page early.
4572 - */
4573 - vectors = early_alloc(PAGE_SIZE * 2);
4574 -
4575 - early_trap_init(vectors);
4576 + early_trap_init(&vectors);
4577
4578 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4579 pmd_clear(pmd_off_k(addr));
4580 @@ -1239,7 +1325,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4581 * location (0xffff0000). If we aren't using high-vectors, also
4582 * create a mapping at the low-vectors virtual address.
4583 */
4584 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4585 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4586 map.virtual = 0xffff0000;
4587 map.length = PAGE_SIZE;
4588 #ifdef CONFIG_KUSER_HELPERS
4589 @@ -1311,8 +1397,39 @@ static void __init map_lowmem(void)
4590 map.pfn = __phys_to_pfn(start);
4591 map.virtual = __phys_to_virt(start);
4592 map.length = end - start;
4593 - map.type = MT_MEMORY;
4594
4595 +#ifdef CONFIG_PAX_KERNEXEC
4596 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4597 + struct map_desc kernel;
4598 + struct map_desc initmap;
4599 +
4600 + /* when freeing initmem we will make this RW */
4601 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4602 + initmap.virtual = (unsigned long)__init_begin;
4603 + initmap.length = _sdata - __init_begin;
4604 + initmap.type = MT_MEMORY_RWX;
4605 + create_mapping(&initmap);
4606 +
4607 + /* when freeing initmem we will make this RX */
4608 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4609 + kernel.virtual = (unsigned long)_stext;
4610 + kernel.length = __init_begin - _stext;
4611 + kernel.type = MT_MEMORY_RWX;
4612 + create_mapping(&kernel);
4613 +
4614 + if (map.virtual < (unsigned long)_stext) {
4615 + map.length = (unsigned long)_stext - map.virtual;
4616 + map.type = MT_MEMORY_RWX;
4617 + create_mapping(&map);
4618 + }
4619 +
4620 + map.pfn = __phys_to_pfn(__pa(_sdata));
4621 + map.virtual = (unsigned long)_sdata;
4622 + map.length = end - __pa(_sdata);
4623 + }
4624 +#endif
4625 +
4626 + map.type = MT_MEMORY_RW;
4627 create_mapping(&map);
4628 }
4629 }
4630 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4631 index a5bc92d..0bb4730 100644
4632 --- a/arch/arm/plat-omap/sram.c
4633 +++ b/arch/arm/plat-omap/sram.c
4634 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4635 * Looks like we need to preserve some bootloader code at the
4636 * beginning of SRAM for jumping to flash for reboot to work...
4637 */
4638 + pax_open_kernel();
4639 memset_io(omap_sram_base + omap_sram_skip, 0,
4640 omap_sram_size - omap_sram_skip);
4641 + pax_close_kernel();
4642 }
4643 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4644 index ce6d763..cfea917 100644
4645 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4646 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4647 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4648 int (*started)(unsigned ch);
4649 int (*flush)(unsigned ch);
4650 int (*stop)(unsigned ch);
4651 -};
4652 +} __no_const;
4653
4654 extern void *samsung_dmadev_get_ops(void);
4655 extern void *s3c_dma_get_ops(void);
4656 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4657 index c3a58a1..78fbf54 100644
4658 --- a/arch/avr32/include/asm/cache.h
4659 +++ b/arch/avr32/include/asm/cache.h
4660 @@ -1,8 +1,10 @@
4661 #ifndef __ASM_AVR32_CACHE_H
4662 #define __ASM_AVR32_CACHE_H
4663
4664 +#include <linux/const.h>
4665 +
4666 #define L1_CACHE_SHIFT 5
4667 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4668 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4669
4670 /*
4671 * Memory returned by kmalloc() may be used for DMA, so we must make
4672 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4673 index d232888..87c8df1 100644
4674 --- a/arch/avr32/include/asm/elf.h
4675 +++ b/arch/avr32/include/asm/elf.h
4676 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4677 the loader. We need to make sure that it is out of the way of the program
4678 that it will "exec", and that there is sufficient room for the brk. */
4679
4680 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4681 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4682
4683 +#ifdef CONFIG_PAX_ASLR
4684 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4685 +
4686 +#define PAX_DELTA_MMAP_LEN 15
4687 +#define PAX_DELTA_STACK_LEN 15
4688 +#endif
4689
4690 /* This yields a mask that user programs can use to figure out what
4691 instruction set this CPU supports. This could be done in user space,
4692 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4693 index 479330b..53717a8 100644
4694 --- a/arch/avr32/include/asm/kmap_types.h
4695 +++ b/arch/avr32/include/asm/kmap_types.h
4696 @@ -2,9 +2,9 @@
4697 #define __ASM_AVR32_KMAP_TYPES_H
4698
4699 #ifdef CONFIG_DEBUG_HIGHMEM
4700 -# define KM_TYPE_NR 29
4701 +# define KM_TYPE_NR 30
4702 #else
4703 -# define KM_TYPE_NR 14
4704 +# define KM_TYPE_NR 15
4705 #endif
4706
4707 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4708 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4709 index 0eca933..eb78c7b 100644
4710 --- a/arch/avr32/mm/fault.c
4711 +++ b/arch/avr32/mm/fault.c
4712 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4713
4714 int exception_trace = 1;
4715
4716 +#ifdef CONFIG_PAX_PAGEEXEC
4717 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4718 +{
4719 + unsigned long i;
4720 +
4721 + printk(KERN_ERR "PAX: bytes at PC: ");
4722 + for (i = 0; i < 20; i++) {
4723 + unsigned char c;
4724 + if (get_user(c, (unsigned char *)pc+i))
4725 + printk(KERN_CONT "???????? ");
4726 + else
4727 + printk(KERN_CONT "%02x ", c);
4728 + }
4729 + printk("\n");
4730 +}
4731 +#endif
4732 +
4733 /*
4734 * This routine handles page faults. It determines the address and the
4735 * problem, and then passes it off to one of the appropriate routines.
4736 @@ -176,6 +193,16 @@ bad_area:
4737 up_read(&mm->mmap_sem);
4738
4739 if (user_mode(regs)) {
4740 +
4741 +#ifdef CONFIG_PAX_PAGEEXEC
4742 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4743 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4744 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4745 + do_group_exit(SIGKILL);
4746 + }
4747 + }
4748 +#endif
4749 +
4750 if (exception_trace && printk_ratelimit())
4751 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4752 "sp %08lx ecr %lu\n",
4753 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4754 index 568885a..f8008df 100644
4755 --- a/arch/blackfin/include/asm/cache.h
4756 +++ b/arch/blackfin/include/asm/cache.h
4757 @@ -7,6 +7,7 @@
4758 #ifndef __ARCH_BLACKFIN_CACHE_H
4759 #define __ARCH_BLACKFIN_CACHE_H
4760
4761 +#include <linux/const.h>
4762 #include <linux/linkage.h> /* for asmlinkage */
4763
4764 /*
4765 @@ -14,7 +15,7 @@
4766 * Blackfin loads 32 bytes for cache
4767 */
4768 #define L1_CACHE_SHIFT 5
4769 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4770 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4771 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4772
4773 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4774 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4775 index aea2718..3639a60 100644
4776 --- a/arch/cris/include/arch-v10/arch/cache.h
4777 +++ b/arch/cris/include/arch-v10/arch/cache.h
4778 @@ -1,8 +1,9 @@
4779 #ifndef _ASM_ARCH_CACHE_H
4780 #define _ASM_ARCH_CACHE_H
4781
4782 +#include <linux/const.h>
4783 /* Etrax 100LX have 32-byte cache-lines. */
4784 -#define L1_CACHE_BYTES 32
4785 #define L1_CACHE_SHIFT 5
4786 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4787
4788 #endif /* _ASM_ARCH_CACHE_H */
4789 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4790 index 7caf25d..ee65ac5 100644
4791 --- a/arch/cris/include/arch-v32/arch/cache.h
4792 +++ b/arch/cris/include/arch-v32/arch/cache.h
4793 @@ -1,11 +1,12 @@
4794 #ifndef _ASM_CRIS_ARCH_CACHE_H
4795 #define _ASM_CRIS_ARCH_CACHE_H
4796
4797 +#include <linux/const.h>
4798 #include <arch/hwregs/dma.h>
4799
4800 /* A cache-line is 32 bytes. */
4801 -#define L1_CACHE_BYTES 32
4802 #define L1_CACHE_SHIFT 5
4803 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4804
4805 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4806
4807 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4808 index b86329d..6709906 100644
4809 --- a/arch/frv/include/asm/atomic.h
4810 +++ b/arch/frv/include/asm/atomic.h
4811 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4812 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4813 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4814
4815 +#define atomic64_read_unchecked(v) atomic64_read(v)
4816 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4817 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4818 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4819 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4820 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4821 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4822 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4823 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4824 +
4825 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4826 {
4827 int c, old;
4828 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4829 index 2797163..c2a401d 100644
4830 --- a/arch/frv/include/asm/cache.h
4831 +++ b/arch/frv/include/asm/cache.h
4832 @@ -12,10 +12,11 @@
4833 #ifndef __ASM_CACHE_H
4834 #define __ASM_CACHE_H
4835
4836 +#include <linux/const.h>
4837
4838 /* bytes per L1 cache line */
4839 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4840 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4841 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4842
4843 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4844 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4845 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4846 index 43901f2..0d8b865 100644
4847 --- a/arch/frv/include/asm/kmap_types.h
4848 +++ b/arch/frv/include/asm/kmap_types.h
4849 @@ -2,6 +2,6 @@
4850 #ifndef _ASM_KMAP_TYPES_H
4851 #define _ASM_KMAP_TYPES_H
4852
4853 -#define KM_TYPE_NR 17
4854 +#define KM_TYPE_NR 18
4855
4856 #endif
4857 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4858 index 836f147..4cf23f5 100644
4859 --- a/arch/frv/mm/elf-fdpic.c
4860 +++ b/arch/frv/mm/elf-fdpic.c
4861 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4862 {
4863 struct vm_area_struct *vma;
4864 struct vm_unmapped_area_info info;
4865 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4866
4867 if (len > TASK_SIZE)
4868 return -ENOMEM;
4869 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4870 if (addr) {
4871 addr = PAGE_ALIGN(addr);
4872 vma = find_vma(current->mm, addr);
4873 - if (TASK_SIZE - len >= addr &&
4874 - (!vma || addr + len <= vma->vm_start))
4875 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4876 goto success;
4877 }
4878
4879 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4880 info.high_limit = (current->mm->start_stack - 0x00200000);
4881 info.align_mask = 0;
4882 info.align_offset = 0;
4883 + info.threadstack_offset = offset;
4884 addr = vm_unmapped_area(&info);
4885 if (!(addr & ~PAGE_MASK))
4886 goto success;
4887 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4888 index f4ca594..adc72fd6 100644
4889 --- a/arch/hexagon/include/asm/cache.h
4890 +++ b/arch/hexagon/include/asm/cache.h
4891 @@ -21,9 +21,11 @@
4892 #ifndef __ASM_CACHE_H
4893 #define __ASM_CACHE_H
4894
4895 +#include <linux/const.h>
4896 +
4897 /* Bytes per L1 cache line */
4898 -#define L1_CACHE_SHIFT (5)
4899 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4900 +#define L1_CACHE_SHIFT 5
4901 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4902
4903 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4904 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4905 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4906 index 4e4119b..dd7de0a 100644
4907 --- a/arch/ia64/Kconfig
4908 +++ b/arch/ia64/Kconfig
4909 @@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4910 config KEXEC
4911 bool "kexec system call"
4912 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4913 + depends on !GRKERNSEC_KMEM
4914 help
4915 kexec is a system call that implements the ability to shutdown your
4916 current kernel, and to start another kernel. It is like a reboot
4917 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4918 index 6e6fe18..a6ae668 100644
4919 --- a/arch/ia64/include/asm/atomic.h
4920 +++ b/arch/ia64/include/asm/atomic.h
4921 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4922 #define atomic64_inc(v) atomic64_add(1, (v))
4923 #define atomic64_dec(v) atomic64_sub(1, (v))
4924
4925 +#define atomic64_read_unchecked(v) atomic64_read(v)
4926 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4927 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4928 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4929 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4930 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4931 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4932 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4933 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4934 +
4935 /* Atomic operations are already serializing */
4936 #define smp_mb__before_atomic_dec() barrier()
4937 #define smp_mb__after_atomic_dec() barrier()
4938 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4939 index 988254a..e1ee885 100644
4940 --- a/arch/ia64/include/asm/cache.h
4941 +++ b/arch/ia64/include/asm/cache.h
4942 @@ -1,6 +1,7 @@
4943 #ifndef _ASM_IA64_CACHE_H
4944 #define _ASM_IA64_CACHE_H
4945
4946 +#include <linux/const.h>
4947
4948 /*
4949 * Copyright (C) 1998-2000 Hewlett-Packard Co
4950 @@ -9,7 +10,7 @@
4951
4952 /* Bytes per L1 (data) cache line. */
4953 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4954 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4955 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4956
4957 #ifdef CONFIG_SMP
4958 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4959 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4960 index 5a83c5c..4d7f553 100644
4961 --- a/arch/ia64/include/asm/elf.h
4962 +++ b/arch/ia64/include/asm/elf.h
4963 @@ -42,6 +42,13 @@
4964 */
4965 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4966
4967 +#ifdef CONFIG_PAX_ASLR
4968 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4969 +
4970 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4971 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4972 +#endif
4973 +
4974 #define PT_IA_64_UNWIND 0x70000001
4975
4976 /* IA-64 relocations: */
4977 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4978 index 5767cdf..7462574 100644
4979 --- a/arch/ia64/include/asm/pgalloc.h
4980 +++ b/arch/ia64/include/asm/pgalloc.h
4981 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4982 pgd_val(*pgd_entry) = __pa(pud);
4983 }
4984
4985 +static inline void
4986 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4987 +{
4988 + pgd_populate(mm, pgd_entry, pud);
4989 +}
4990 +
4991 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4992 {
4993 return quicklist_alloc(0, GFP_KERNEL, NULL);
4994 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4995 pud_val(*pud_entry) = __pa(pmd);
4996 }
4997
4998 +static inline void
4999 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5000 +{
5001 + pud_populate(mm, pud_entry, pmd);
5002 +}
5003 +
5004 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5005 {
5006 return quicklist_alloc(0, GFP_KERNEL, NULL);
5007 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5008 index 7935115..c0eca6a 100644
5009 --- a/arch/ia64/include/asm/pgtable.h
5010 +++ b/arch/ia64/include/asm/pgtable.h
5011 @@ -12,7 +12,7 @@
5012 * David Mosberger-Tang <davidm@hpl.hp.com>
5013 */
5014
5015 -
5016 +#include <linux/const.h>
5017 #include <asm/mman.h>
5018 #include <asm/page.h>
5019 #include <asm/processor.h>
5020 @@ -142,6 +142,17 @@
5021 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5022 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5023 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5024 +
5025 +#ifdef CONFIG_PAX_PAGEEXEC
5026 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5027 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5028 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5029 +#else
5030 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5031 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5032 +# define PAGE_COPY_NOEXEC PAGE_COPY
5033 +#endif
5034 +
5035 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5036 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5037 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5038 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5039 index 45698cd..e8e2dbc 100644
5040 --- a/arch/ia64/include/asm/spinlock.h
5041 +++ b/arch/ia64/include/asm/spinlock.h
5042 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5043 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5044
5045 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5046 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5047 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5048 }
5049
5050 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5051 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5052 index 449c8c0..18965fb 100644
5053 --- a/arch/ia64/include/asm/uaccess.h
5054 +++ b/arch/ia64/include/asm/uaccess.h
5055 @@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5056 static inline unsigned long
5057 __copy_to_user (void __user *to, const void *from, unsigned long count)
5058 {
5059 + if (count > INT_MAX)
5060 + return count;
5061 +
5062 + if (!__builtin_constant_p(count))
5063 + check_object_size(from, count, true);
5064 +
5065 return __copy_user(to, (__force void __user *) from, count);
5066 }
5067
5068 static inline unsigned long
5069 __copy_from_user (void *to, const void __user *from, unsigned long count)
5070 {
5071 + if (count > INT_MAX)
5072 + return count;
5073 +
5074 + if (!__builtin_constant_p(count))
5075 + check_object_size(to, count, false);
5076 +
5077 return __copy_user((__force void __user *) to, from, count);
5078 }
5079
5080 @@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5081 ({ \
5082 void __user *__cu_to = (to); \
5083 const void *__cu_from = (from); \
5084 - long __cu_len = (n); \
5085 + unsigned long __cu_len = (n); \
5086 \
5087 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5088 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5089 + if (!__builtin_constant_p(n)) \
5090 + check_object_size(__cu_from, __cu_len, true); \
5091 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5092 + } \
5093 __cu_len; \
5094 })
5095
5096 @@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5097 ({ \
5098 void *__cu_to = (to); \
5099 const void __user *__cu_from = (from); \
5100 - long __cu_len = (n); \
5101 + unsigned long __cu_len = (n); \
5102 \
5103 __chk_user_ptr(__cu_from); \
5104 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5105 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5106 + if (!__builtin_constant_p(n)) \
5107 + check_object_size(__cu_to, __cu_len, false); \
5108 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5109 + } \
5110 __cu_len; \
5111 })
5112
5113 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5114 index 24603be..948052d 100644
5115 --- a/arch/ia64/kernel/module.c
5116 +++ b/arch/ia64/kernel/module.c
5117 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5118 void
5119 module_free (struct module *mod, void *module_region)
5120 {
5121 - if (mod && mod->arch.init_unw_table &&
5122 - module_region == mod->module_init) {
5123 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5124 unw_remove_unwind_table(mod->arch.init_unw_table);
5125 mod->arch.init_unw_table = NULL;
5126 }
5127 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5128 }
5129
5130 static inline int
5131 +in_init_rx (const struct module *mod, uint64_t addr)
5132 +{
5133 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5134 +}
5135 +
5136 +static inline int
5137 +in_init_rw (const struct module *mod, uint64_t addr)
5138 +{
5139 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5140 +}
5141 +
5142 +static inline int
5143 in_init (const struct module *mod, uint64_t addr)
5144 {
5145 - return addr - (uint64_t) mod->module_init < mod->init_size;
5146 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5147 +}
5148 +
5149 +static inline int
5150 +in_core_rx (const struct module *mod, uint64_t addr)
5151 +{
5152 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5153 +}
5154 +
5155 +static inline int
5156 +in_core_rw (const struct module *mod, uint64_t addr)
5157 +{
5158 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5159 }
5160
5161 static inline int
5162 in_core (const struct module *mod, uint64_t addr)
5163 {
5164 - return addr - (uint64_t) mod->module_core < mod->core_size;
5165 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5166 }
5167
5168 static inline int
5169 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5170 break;
5171
5172 case RV_BDREL:
5173 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5174 + if (in_init_rx(mod, val))
5175 + val -= (uint64_t) mod->module_init_rx;
5176 + else if (in_init_rw(mod, val))
5177 + val -= (uint64_t) mod->module_init_rw;
5178 + else if (in_core_rx(mod, val))
5179 + val -= (uint64_t) mod->module_core_rx;
5180 + else if (in_core_rw(mod, val))
5181 + val -= (uint64_t) mod->module_core_rw;
5182 break;
5183
5184 case RV_LTV:
5185 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5186 * addresses have been selected...
5187 */
5188 uint64_t gp;
5189 - if (mod->core_size > MAX_LTOFF)
5190 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5191 /*
5192 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5193 * at the end of the module.
5194 */
5195 - gp = mod->core_size - MAX_LTOFF / 2;
5196 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5197 else
5198 - gp = mod->core_size / 2;
5199 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5200 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5201 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5202 mod->arch.gp = gp;
5203 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5204 }
5205 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5206 index ab33328..f39506c 100644
5207 --- a/arch/ia64/kernel/palinfo.c
5208 +++ b/arch/ia64/kernel/palinfo.c
5209 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5210 return NOTIFY_OK;
5211 }
5212
5213 -static struct notifier_block __refdata palinfo_cpu_notifier =
5214 +static struct notifier_block palinfo_cpu_notifier =
5215 {
5216 .notifier_call = palinfo_cpu_callback,
5217 .priority = 0,
5218 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5219 index 41e33f8..65180b2a 100644
5220 --- a/arch/ia64/kernel/sys_ia64.c
5221 +++ b/arch/ia64/kernel/sys_ia64.c
5222 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5223 unsigned long align_mask = 0;
5224 struct mm_struct *mm = current->mm;
5225 struct vm_unmapped_area_info info;
5226 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5227
5228 if (len > RGN_MAP_LIMIT)
5229 return -ENOMEM;
5230 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5231 if (REGION_NUMBER(addr) == RGN_HPAGE)
5232 addr = 0;
5233 #endif
5234 +
5235 +#ifdef CONFIG_PAX_RANDMMAP
5236 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5237 + addr = mm->free_area_cache;
5238 + else
5239 +#endif
5240 +
5241 if (!addr)
5242 addr = TASK_UNMAPPED_BASE;
5243
5244 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5245 info.high_limit = TASK_SIZE;
5246 info.align_mask = align_mask;
5247 info.align_offset = 0;
5248 + info.threadstack_offset = offset;
5249 return vm_unmapped_area(&info);
5250 }
5251
5252 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5253 index 0ccb28f..8992469 100644
5254 --- a/arch/ia64/kernel/vmlinux.lds.S
5255 +++ b/arch/ia64/kernel/vmlinux.lds.S
5256 @@ -198,7 +198,7 @@ SECTIONS {
5257 /* Per-cpu data: */
5258 . = ALIGN(PERCPU_PAGE_SIZE);
5259 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5260 - __phys_per_cpu_start = __per_cpu_load;
5261 + __phys_per_cpu_start = per_cpu_load;
5262 /*
5263 * ensure percpu data fits
5264 * into percpu page size
5265 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5266 index 7225dad..2a7c8256 100644
5267 --- a/arch/ia64/mm/fault.c
5268 +++ b/arch/ia64/mm/fault.c
5269 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5270 return pte_present(pte);
5271 }
5272
5273 +#ifdef CONFIG_PAX_PAGEEXEC
5274 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5275 +{
5276 + unsigned long i;
5277 +
5278 + printk(KERN_ERR "PAX: bytes at PC: ");
5279 + for (i = 0; i < 8; i++) {
5280 + unsigned int c;
5281 + if (get_user(c, (unsigned int *)pc+i))
5282 + printk(KERN_CONT "???????? ");
5283 + else
5284 + printk(KERN_CONT "%08x ", c);
5285 + }
5286 + printk("\n");
5287 +}
5288 +#endif
5289 +
5290 # define VM_READ_BIT 0
5291 # define VM_WRITE_BIT 1
5292 # define VM_EXEC_BIT 2
5293 @@ -151,8 +168,21 @@ retry:
5294 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5295 goto bad_area;
5296
5297 - if ((vma->vm_flags & mask) != mask)
5298 + if ((vma->vm_flags & mask) != mask) {
5299 +
5300 +#ifdef CONFIG_PAX_PAGEEXEC
5301 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5302 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5303 + goto bad_area;
5304 +
5305 + up_read(&mm->mmap_sem);
5306 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5307 + do_group_exit(SIGKILL);
5308 + }
5309 +#endif
5310 +
5311 goto bad_area;
5312 + }
5313
5314 /*
5315 * If for any reason at all we couldn't handle the fault, make
5316 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5317 index 68232db..6ca80af 100644
5318 --- a/arch/ia64/mm/hugetlbpage.c
5319 +++ b/arch/ia64/mm/hugetlbpage.c
5320 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5321 unsigned long pgoff, unsigned long flags)
5322 {
5323 struct vm_unmapped_area_info info;
5324 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5325
5326 if (len > RGN_MAP_LIMIT)
5327 return -ENOMEM;
5328 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5329 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5330 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5331 info.align_offset = 0;
5332 + info.threadstack_offset = offset;
5333 return vm_unmapped_area(&info);
5334 }
5335
5336 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5337 index 88504ab..cbb6c9f 100644
5338 --- a/arch/ia64/mm/init.c
5339 +++ b/arch/ia64/mm/init.c
5340 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5341 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5342 vma->vm_end = vma->vm_start + PAGE_SIZE;
5343 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5344 +
5345 +#ifdef CONFIG_PAX_PAGEEXEC
5346 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5347 + vma->vm_flags &= ~VM_EXEC;
5348 +
5349 +#ifdef CONFIG_PAX_MPROTECT
5350 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5351 + vma->vm_flags &= ~VM_MAYEXEC;
5352 +#endif
5353 +
5354 + }
5355 +#endif
5356 +
5357 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5358 down_write(&current->mm->mmap_sem);
5359 if (insert_vm_struct(current->mm, vma)) {
5360 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5361 index 40b3ee9..8c2c112 100644
5362 --- a/arch/m32r/include/asm/cache.h
5363 +++ b/arch/m32r/include/asm/cache.h
5364 @@ -1,8 +1,10 @@
5365 #ifndef _ASM_M32R_CACHE_H
5366 #define _ASM_M32R_CACHE_H
5367
5368 +#include <linux/const.h>
5369 +
5370 /* L1 cache line size */
5371 #define L1_CACHE_SHIFT 4
5372 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5373 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5374
5375 #endif /* _ASM_M32R_CACHE_H */
5376 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5377 index 82abd15..d95ae5d 100644
5378 --- a/arch/m32r/lib/usercopy.c
5379 +++ b/arch/m32r/lib/usercopy.c
5380 @@ -14,6 +14,9 @@
5381 unsigned long
5382 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5383 {
5384 + if ((long)n < 0)
5385 + return n;
5386 +
5387 prefetch(from);
5388 if (access_ok(VERIFY_WRITE, to, n))
5389 __copy_user(to,from,n);
5390 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5391 unsigned long
5392 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5393 {
5394 + if ((long)n < 0)
5395 + return n;
5396 +
5397 prefetchw(to);
5398 if (access_ok(VERIFY_READ, from, n))
5399 __copy_user_zeroing(to,from,n);
5400 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5401 index 0395c51..5f26031 100644
5402 --- a/arch/m68k/include/asm/cache.h
5403 +++ b/arch/m68k/include/asm/cache.h
5404 @@ -4,9 +4,11 @@
5405 #ifndef __ARCH_M68K_CACHE_H
5406 #define __ARCH_M68K_CACHE_H
5407
5408 +#include <linux/const.h>
5409 +
5410 /* bytes per L1 cache line */
5411 #define L1_CACHE_SHIFT 4
5412 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5413 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5414
5415 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5416
5417 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5418 index 0424315..defcca9 100644
5419 --- a/arch/metag/mm/hugetlbpage.c
5420 +++ b/arch/metag/mm/hugetlbpage.c
5421 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5422 info.high_limit = TASK_SIZE;
5423 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5424 info.align_offset = 0;
5425 + info.threadstack_offset = 0;
5426 return vm_unmapped_area(&info);
5427 }
5428
5429 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5430 index 4efe96a..60e8699 100644
5431 --- a/arch/microblaze/include/asm/cache.h
5432 +++ b/arch/microblaze/include/asm/cache.h
5433 @@ -13,11 +13,12 @@
5434 #ifndef _ASM_MICROBLAZE_CACHE_H
5435 #define _ASM_MICROBLAZE_CACHE_H
5436
5437 +#include <linux/const.h>
5438 #include <asm/registers.h>
5439
5440 #define L1_CACHE_SHIFT 5
5441 /* word-granular cache in microblaze */
5442 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5443 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5444
5445 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5446
5447 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5448 index 650de39..6982b02 100644
5449 --- a/arch/mips/Kconfig
5450 +++ b/arch/mips/Kconfig
5451 @@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5452
5453 config KEXEC
5454 bool "Kexec system call"
5455 + depends on !GRKERNSEC_KMEM
5456 help
5457 kexec is a system call that implements the ability to shutdown your
5458 current kernel, and to start another kernel. It is like a reboot
5459 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5460 index 7eed2f2..c4e385d 100644
5461 --- a/arch/mips/include/asm/atomic.h
5462 +++ b/arch/mips/include/asm/atomic.h
5463 @@ -21,15 +21,39 @@
5464 #include <asm/cmpxchg.h>
5465 #include <asm/war.h>
5466
5467 +#ifdef CONFIG_GENERIC_ATOMIC64
5468 +#include <asm-generic/atomic64.h>
5469 +#endif
5470 +
5471 #define ATOMIC_INIT(i) { (i) }
5472
5473 +#ifdef CONFIG_64BIT
5474 +#define _ASM_EXTABLE(from, to) \
5475 +" .section __ex_table,\"a\"\n" \
5476 +" .dword " #from ", " #to"\n" \
5477 +" .previous\n"
5478 +#else
5479 +#define _ASM_EXTABLE(from, to) \
5480 +" .section __ex_table,\"a\"\n" \
5481 +" .word " #from ", " #to"\n" \
5482 +" .previous\n"
5483 +#endif
5484 +
5485 /*
5486 * atomic_read - read atomic variable
5487 * @v: pointer of type atomic_t
5488 *
5489 * Atomically reads the value of @v.
5490 */
5491 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5492 +static inline int atomic_read(const atomic_t *v)
5493 +{
5494 + return (*(volatile const int *) &v->counter);
5495 +}
5496 +
5497 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5498 +{
5499 + return (*(volatile const int *) &v->counter);
5500 +}
5501
5502 /*
5503 * atomic_set - set atomic variable
5504 @@ -38,7 +62,15 @@
5505 *
5506 * Atomically sets the value of @v to @i.
5507 */
5508 -#define atomic_set(v, i) ((v)->counter = (i))
5509 +static inline void atomic_set(atomic_t *v, int i)
5510 +{
5511 + v->counter = i;
5512 +}
5513 +
5514 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5515 +{
5516 + v->counter = i;
5517 +}
5518
5519 /*
5520 * atomic_add - add integer to atomic variable
5521 @@ -47,7 +79,67 @@
5522 *
5523 * Atomically adds @i to @v.
5524 */
5525 -static __inline__ void atomic_add(int i, atomic_t * v)
5526 +static __inline__ void atomic_add(int i, atomic_t *v)
5527 +{
5528 + int temp;
5529 +
5530 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5531 + __asm__ __volatile__(
5532 + " .set mips3 \n"
5533 + "1: ll %0, %1 # atomic_add \n"
5534 +#ifdef CONFIG_PAX_REFCOUNT
5535 + /* Exception on overflow. */
5536 + "2: add %0, %2 \n"
5537 +#else
5538 + " addu %0, %2 \n"
5539 +#endif
5540 + " sc %0, %1 \n"
5541 + " beqzl %0, 1b \n"
5542 +#ifdef CONFIG_PAX_REFCOUNT
5543 + "3: \n"
5544 + _ASM_EXTABLE(2b, 3b)
5545 +#endif
5546 + " .set mips0 \n"
5547 + : "=&r" (temp), "+m" (v->counter)
5548 + : "Ir" (i));
5549 + } else if (kernel_uses_llsc) {
5550 + __asm__ __volatile__(
5551 + " .set mips3 \n"
5552 + "1: ll %0, %1 # atomic_add \n"
5553 +#ifdef CONFIG_PAX_REFCOUNT
5554 + /* Exception on overflow. */
5555 + "2: add %0, %2 \n"
5556 +#else
5557 + " addu %0, %2 \n"
5558 +#endif
5559 + " sc %0, %1 \n"
5560 + " beqz %0, 1b \n"
5561 +#ifdef CONFIG_PAX_REFCOUNT
5562 + "3: \n"
5563 + _ASM_EXTABLE(2b, 3b)
5564 +#endif
5565 + " .set mips0 \n"
5566 + : "=&r" (temp), "+m" (v->counter)
5567 + : "Ir" (i));
5568 + } else {
5569 + unsigned long flags;
5570 +
5571 + raw_local_irq_save(flags);
5572 + __asm__ __volatile__(
5573 +#ifdef CONFIG_PAX_REFCOUNT
5574 + /* Exception on overflow. */
5575 + "1: add %0, %1 \n"
5576 + "2: \n"
5577 + _ASM_EXTABLE(1b, 2b)
5578 +#else
5579 + " addu %0, %1 \n"
5580 +#endif
5581 + : "+r" (v->counter) : "Ir" (i));
5582 + raw_local_irq_restore(flags);
5583 + }
5584 +}
5585 +
5586 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5587 {
5588 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5589 int temp;
5590 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5591 *
5592 * Atomically subtracts @i from @v.
5593 */
5594 -static __inline__ void atomic_sub(int i, atomic_t * v)
5595 +static __inline__ void atomic_sub(int i, atomic_t *v)
5596 +{
5597 + int temp;
5598 +
5599 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5600 + __asm__ __volatile__(
5601 + " .set mips3 \n"
5602 + "1: ll %0, %1 # atomic64_sub \n"
5603 +#ifdef CONFIG_PAX_REFCOUNT
5604 + /* Exception on overflow. */
5605 + "2: sub %0, %2 \n"
5606 +#else
5607 + " subu %0, %2 \n"
5608 +#endif
5609 + " sc %0, %1 \n"
5610 + " beqzl %0, 1b \n"
5611 +#ifdef CONFIG_PAX_REFCOUNT
5612 + "3: \n"
5613 + _ASM_EXTABLE(2b, 3b)
5614 +#endif
5615 + " .set mips0 \n"
5616 + : "=&r" (temp), "+m" (v->counter)
5617 + : "Ir" (i));
5618 + } else if (kernel_uses_llsc) {
5619 + __asm__ __volatile__(
5620 + " .set mips3 \n"
5621 + "1: ll %0, %1 # atomic64_sub \n"
5622 +#ifdef CONFIG_PAX_REFCOUNT
5623 + /* Exception on overflow. */
5624 + "2: sub %0, %2 \n"
5625 +#else
5626 + " subu %0, %2 \n"
5627 +#endif
5628 + " sc %0, %1 \n"
5629 + " beqz %0, 1b \n"
5630 +#ifdef CONFIG_PAX_REFCOUNT
5631 + "3: \n"
5632 + _ASM_EXTABLE(2b, 3b)
5633 +#endif
5634 + " .set mips0 \n"
5635 + : "=&r" (temp), "+m" (v->counter)
5636 + : "Ir" (i));
5637 + } else {
5638 + unsigned long flags;
5639 +
5640 + raw_local_irq_save(flags);
5641 + __asm__ __volatile__(
5642 +#ifdef CONFIG_PAX_REFCOUNT
5643 + /* Exception on overflow. */
5644 + "1: sub %0, %1 \n"
5645 + "2: \n"
5646 + _ASM_EXTABLE(1b, 2b)
5647 +#else
5648 + " subu %0, %1 \n"
5649 +#endif
5650 + : "+r" (v->counter) : "Ir" (i));
5651 + raw_local_irq_restore(flags);
5652 + }
5653 +}
5654 +
5655 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5656 {
5657 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5658 int temp;
5659 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5660 /*
5661 * Same as above, but return the result value
5662 */
5663 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5664 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5665 +{
5666 + int result;
5667 + int temp;
5668 +
5669 + smp_mb__before_llsc();
5670 +
5671 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5672 + __asm__ __volatile__(
5673 + " .set mips3 \n"
5674 + "1: ll %1, %2 # atomic_add_return \n"
5675 +#ifdef CONFIG_PAX_REFCOUNT
5676 + "2: add %0, %1, %3 \n"
5677 +#else
5678 + " addu %0, %1, %3 \n"
5679 +#endif
5680 + " sc %0, %2 \n"
5681 + " beqzl %0, 1b \n"
5682 +#ifdef CONFIG_PAX_REFCOUNT
5683 + " b 4f \n"
5684 + " .set noreorder \n"
5685 + "3: b 5f \n"
5686 + " move %0, %1 \n"
5687 + " .set reorder \n"
5688 + _ASM_EXTABLE(2b, 3b)
5689 +#endif
5690 + "4: addu %0, %1, %3 \n"
5691 +#ifdef CONFIG_PAX_REFCOUNT
5692 + "5: \n"
5693 +#endif
5694 + " .set mips0 \n"
5695 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5696 + : "Ir" (i));
5697 + } else if (kernel_uses_llsc) {
5698 + __asm__ __volatile__(
5699 + " .set mips3 \n"
5700 + "1: ll %1, %2 # atomic_add_return \n"
5701 +#ifdef CONFIG_PAX_REFCOUNT
5702 + "2: add %0, %1, %3 \n"
5703 +#else
5704 + " addu %0, %1, %3 \n"
5705 +#endif
5706 + " sc %0, %2 \n"
5707 + " bnez %0, 4f \n"
5708 + " b 1b \n"
5709 +#ifdef CONFIG_PAX_REFCOUNT
5710 + " .set noreorder \n"
5711 + "3: b 5f \n"
5712 + " move %0, %1 \n"
5713 + " .set reorder \n"
5714 + _ASM_EXTABLE(2b, 3b)
5715 +#endif
5716 + "4: addu %0, %1, %3 \n"
5717 +#ifdef CONFIG_PAX_REFCOUNT
5718 + "5: \n"
5719 +#endif
5720 + " .set mips0 \n"
5721 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5722 + : "Ir" (i));
5723 + } else {
5724 + unsigned long flags;
5725 +
5726 + raw_local_irq_save(flags);
5727 + __asm__ __volatile__(
5728 + " lw %0, %1 \n"
5729 +#ifdef CONFIG_PAX_REFCOUNT
5730 + /* Exception on overflow. */
5731 + "1: add %0, %2 \n"
5732 +#else
5733 + " addu %0, %2 \n"
5734 +#endif
5735 + " sw %0, %1 \n"
5736 +#ifdef CONFIG_PAX_REFCOUNT
5737 + /* Note: Dest reg is not modified on overflow */
5738 + "2: \n"
5739 + _ASM_EXTABLE(1b, 2b)
5740 +#endif
5741 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5742 + raw_local_irq_restore(flags);
5743 + }
5744 +
5745 + smp_llsc_mb();
5746 +
5747 + return result;
5748 +}
5749 +
5750 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5751 {
5752 int result;
5753
5754 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5755 return result;
5756 }
5757
5758 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5759 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5760 +{
5761 + int result;
5762 + int temp;
5763 +
5764 + smp_mb__before_llsc();
5765 +
5766 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5767 + __asm__ __volatile__(
5768 + " .set mips3 \n"
5769 + "1: ll %1, %2 # atomic_sub_return \n"
5770 +#ifdef CONFIG_PAX_REFCOUNT
5771 + "2: sub %0, %1, %3 \n"
5772 +#else
5773 + " subu %0, %1, %3 \n"
5774 +#endif
5775 + " sc %0, %2 \n"
5776 + " beqzl %0, 1b \n"
5777 +#ifdef CONFIG_PAX_REFCOUNT
5778 + " b 4f \n"
5779 + " .set noreorder \n"
5780 + "3: b 5f \n"
5781 + " move %0, %1 \n"
5782 + " .set reorder \n"
5783 + _ASM_EXTABLE(2b, 3b)
5784 +#endif
5785 + "4: subu %0, %1, %3 \n"
5786 +#ifdef CONFIG_PAX_REFCOUNT
5787 + "5: \n"
5788 +#endif
5789 + " .set mips0 \n"
5790 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5791 + : "Ir" (i), "m" (v->counter)
5792 + : "memory");
5793 + } else if (kernel_uses_llsc) {
5794 + __asm__ __volatile__(
5795 + " .set mips3 \n"
5796 + "1: ll %1, %2 # atomic_sub_return \n"
5797 +#ifdef CONFIG_PAX_REFCOUNT
5798 + "2: sub %0, %1, %3 \n"
5799 +#else
5800 + " subu %0, %1, %3 \n"
5801 +#endif
5802 + " sc %0, %2 \n"
5803 + " bnez %0, 4f \n"
5804 + " b 1b \n"
5805 +#ifdef CONFIG_PAX_REFCOUNT
5806 + " .set noreorder \n"
5807 + "3: b 5f \n"
5808 + " move %0, %1 \n"
5809 + " .set reorder \n"
5810 + _ASM_EXTABLE(2b, 3b)
5811 +#endif
5812 + "4: subu %0, %1, %3 \n"
5813 +#ifdef CONFIG_PAX_REFCOUNT
5814 + "5: \n"
5815 +#endif
5816 + " .set mips0 \n"
5817 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5818 + : "Ir" (i));
5819 + } else {
5820 + unsigned long flags;
5821 +
5822 + raw_local_irq_save(flags);
5823 + __asm__ __volatile__(
5824 + " lw %0, %1 \n"
5825 +#ifdef CONFIG_PAX_REFCOUNT
5826 + /* Exception on overflow. */
5827 + "1: sub %0, %2 \n"
5828 +#else
5829 + " subu %0, %2 \n"
5830 +#endif
5831 + " sw %0, %1 \n"
5832 +#ifdef CONFIG_PAX_REFCOUNT
5833 + /* Note: Dest reg is not modified on overflow */
5834 + "2: \n"
5835 + _ASM_EXTABLE(1b, 2b)
5836 +#endif
5837 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5838 + raw_local_irq_restore(flags);
5839 + }
5840 +
5841 + smp_llsc_mb();
5842 +
5843 + return result;
5844 +}
5845 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5846 {
5847 int result;
5848
5849 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5850 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5851 * The function returns the old value of @v minus @i.
5852 */
5853 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5854 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5855 {
5856 int result;
5857
5858 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5859 return result;
5860 }
5861
5862 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5863 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5864 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5865 +{
5866 + return cmpxchg(&v->counter, old, new);
5867 +}
5868 +
5869 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5870 + int new)
5871 +{
5872 + return cmpxchg(&(v->counter), old, new);
5873 +}
5874 +
5875 +static inline int atomic_xchg(atomic_t *v, int new)
5876 +{
5877 + return xchg(&v->counter, new);
5878 +}
5879 +
5880 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5881 +{
5882 + return xchg(&(v->counter), new);
5883 +}
5884
5885 /**
5886 * __atomic_add_unless - add unless the number is a given value
5887 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5888
5889 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5890 #define atomic_inc_return(v) atomic_add_return(1, (v))
5891 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5892 +{
5893 + return atomic_add_return_unchecked(1, v);
5894 +}
5895
5896 /*
5897 * atomic_sub_and_test - subtract value from variable and test result
5898 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5899 * other cases.
5900 */
5901 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5902 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5903 +{
5904 + return atomic_add_return_unchecked(1, v) == 0;
5905 +}
5906
5907 /*
5908 * atomic_dec_and_test - decrement by 1 and test
5909 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5910 * Atomically increments @v by 1.
5911 */
5912 #define atomic_inc(v) atomic_add(1, (v))
5913 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5914 +{
5915 + atomic_add_unchecked(1, v);
5916 +}
5917
5918 /*
5919 * atomic_dec - decrement and test
5920 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5921 * Atomically decrements @v by 1.
5922 */
5923 #define atomic_dec(v) atomic_sub(1, (v))
5924 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5925 +{
5926 + atomic_sub_unchecked(1, v);
5927 +}
5928
5929 /*
5930 * atomic_add_negative - add and test if negative
5931 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5932 * @v: pointer of type atomic64_t
5933 *
5934 */
5935 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5936 +static inline long atomic64_read(const atomic64_t *v)
5937 +{
5938 + return (*(volatile const long *) &v->counter);
5939 +}
5940 +
5941 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5942 +{
5943 + return (*(volatile const long *) &v->counter);
5944 +}
5945
5946 /*
5947 * atomic64_set - set atomic variable
5948 * @v: pointer of type atomic64_t
5949 * @i: required value
5950 */
5951 -#define atomic64_set(v, i) ((v)->counter = (i))
5952 +static inline void atomic64_set(atomic64_t *v, long i)
5953 +{
5954 + v->counter = i;
5955 +}
5956 +
5957 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5958 +{
5959 + v->counter = i;
5960 +}
5961
5962 /*
5963 * atomic64_add - add integer to atomic variable
5964 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5965 *
5966 * Atomically adds @i to @v.
5967 */
5968 -static __inline__ void atomic64_add(long i, atomic64_t * v)
5969 +static __inline__ void atomic64_add(long i, atomic64_t *v)
5970 +{
5971 + long temp;
5972 +
5973 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5974 + __asm__ __volatile__(
5975 + " .set mips3 \n"
5976 + "1: lld %0, %1 # atomic64_add \n"
5977 +#ifdef CONFIG_PAX_REFCOUNT
5978 + /* Exception on overflow. */
5979 + "2: dadd %0, %2 \n"
5980 +#else
5981 + " daddu %0, %2 \n"
5982 +#endif
5983 + " scd %0, %1 \n"
5984 + " beqzl %0, 1b \n"
5985 +#ifdef CONFIG_PAX_REFCOUNT
5986 + "3: \n"
5987 + _ASM_EXTABLE(2b, 3b)
5988 +#endif
5989 + " .set mips0 \n"
5990 + : "=&r" (temp), "+m" (v->counter)
5991 + : "Ir" (i));
5992 + } else if (kernel_uses_llsc) {
5993 + __asm__ __volatile__(
5994 + " .set mips3 \n"
5995 + "1: lld %0, %1 # atomic64_add \n"
5996 +#ifdef CONFIG_PAX_REFCOUNT
5997 + /* Exception on overflow. */
5998 + "2: dadd %0, %2 \n"
5999 +#else
6000 + " daddu %0, %2 \n"
6001 +#endif
6002 + " scd %0, %1 \n"
6003 + " beqz %0, 1b \n"
6004 +#ifdef CONFIG_PAX_REFCOUNT
6005 + "3: \n"
6006 + _ASM_EXTABLE(2b, 3b)
6007 +#endif
6008 + " .set mips0 \n"
6009 + : "=&r" (temp), "+m" (v->counter)
6010 + : "Ir" (i));
6011 + } else {
6012 + unsigned long flags;
6013 +
6014 + raw_local_irq_save(flags);
6015 + __asm__ __volatile__(
6016 +#ifdef CONFIG_PAX_REFCOUNT
6017 + /* Exception on overflow. */
6018 + "1: dadd %0, %1 \n"
6019 + "2: \n"
6020 + _ASM_EXTABLE(1b, 2b)
6021 +#else
6022 + " daddu %0, %1 \n"
6023 +#endif
6024 + : "+r" (v->counter) : "Ir" (i));
6025 + raw_local_irq_restore(flags);
6026 + }
6027 +}
6028 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6029 {
6030 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6031 long temp;
6032 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6033 *
6034 * Atomically subtracts @i from @v.
6035 */
6036 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6037 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6038 +{
6039 + long temp;
6040 +
6041 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6042 + __asm__ __volatile__(
6043 + " .set mips3 \n"
6044 + "1: lld %0, %1 # atomic64_sub \n"
6045 +#ifdef CONFIG_PAX_REFCOUNT
6046 + /* Exception on overflow. */
6047 + "2: dsub %0, %2 \n"
6048 +#else
6049 + " dsubu %0, %2 \n"
6050 +#endif
6051 + " scd %0, %1 \n"
6052 + " beqzl %0, 1b \n"
6053 +#ifdef CONFIG_PAX_REFCOUNT
6054 + "3: \n"
6055 + _ASM_EXTABLE(2b, 3b)
6056 +#endif
6057 + " .set mips0 \n"
6058 + : "=&r" (temp), "+m" (v->counter)
6059 + : "Ir" (i));
6060 + } else if (kernel_uses_llsc) {
6061 + __asm__ __volatile__(
6062 + " .set mips3 \n"
6063 + "1: lld %0, %1 # atomic64_sub \n"
6064 +#ifdef CONFIG_PAX_REFCOUNT
6065 + /* Exception on overflow. */
6066 + "2: dsub %0, %2 \n"
6067 +#else
6068 + " dsubu %0, %2 \n"
6069 +#endif
6070 + " scd %0, %1 \n"
6071 + " beqz %0, 1b \n"
6072 +#ifdef CONFIG_PAX_REFCOUNT
6073 + "3: \n"
6074 + _ASM_EXTABLE(2b, 3b)
6075 +#endif
6076 + " .set mips0 \n"
6077 + : "=&r" (temp), "+m" (v->counter)
6078 + : "Ir" (i));
6079 + } else {
6080 + unsigned long flags;
6081 +
6082 + raw_local_irq_save(flags);
6083 + __asm__ __volatile__(
6084 +#ifdef CONFIG_PAX_REFCOUNT
6085 + /* Exception on overflow. */
6086 + "1: dsub %0, %1 \n"
6087 + "2: \n"
6088 + _ASM_EXTABLE(1b, 2b)
6089 +#else
6090 + " dsubu %0, %1 \n"
6091 +#endif
6092 + : "+r" (v->counter) : "Ir" (i));
6093 + raw_local_irq_restore(flags);
6094 + }
6095 +}
6096 +
6097 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6098 {
6099 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6100 long temp;
6101 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6102 /*
6103 * Same as above, but return the result value
6104 */
6105 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6106 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6107 +{
6108 + long result;
6109 + long temp;
6110 +
6111 + smp_mb__before_llsc();
6112 +
6113 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6114 + __asm__ __volatile__(
6115 + " .set mips3 \n"
6116 + "1: lld %1, %2 # atomic64_add_return \n"
6117 +#ifdef CONFIG_PAX_REFCOUNT
6118 + "2: dadd %0, %1, %3 \n"
6119 +#else
6120 + " daddu %0, %1, %3 \n"
6121 +#endif
6122 + " scd %0, %2 \n"
6123 + " beqzl %0, 1b \n"
6124 +#ifdef CONFIG_PAX_REFCOUNT
6125 + " b 4f \n"
6126 + " .set noreorder \n"
6127 + "3: b 5f \n"
6128 + " move %0, %1 \n"
6129 + " .set reorder \n"
6130 + _ASM_EXTABLE(2b, 3b)
6131 +#endif
6132 + "4: daddu %0, %1, %3 \n"
6133 +#ifdef CONFIG_PAX_REFCOUNT
6134 + "5: \n"
6135 +#endif
6136 + " .set mips0 \n"
6137 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6138 + : "Ir" (i));
6139 + } else if (kernel_uses_llsc) {
6140 + __asm__ __volatile__(
6141 + " .set mips3 \n"
6142 + "1: lld %1, %2 # atomic64_add_return \n"
6143 +#ifdef CONFIG_PAX_REFCOUNT
6144 + "2: dadd %0, %1, %3 \n"
6145 +#else
6146 + " daddu %0, %1, %3 \n"
6147 +#endif
6148 + " scd %0, %2 \n"
6149 + " bnez %0, 4f \n"
6150 + " b 1b \n"
6151 +#ifdef CONFIG_PAX_REFCOUNT
6152 + " .set noreorder \n"
6153 + "3: b 5f \n"
6154 + " move %0, %1 \n"
6155 + " .set reorder \n"
6156 + _ASM_EXTABLE(2b, 3b)
6157 +#endif
6158 + "4: daddu %0, %1, %3 \n"
6159 +#ifdef CONFIG_PAX_REFCOUNT
6160 + "5: \n"
6161 +#endif
6162 + " .set mips0 \n"
6163 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6164 + : "Ir" (i), "m" (v->counter)
6165 + : "memory");
6166 + } else {
6167 + unsigned long flags;
6168 +
6169 + raw_local_irq_save(flags);
6170 + __asm__ __volatile__(
6171 + " ld %0, %1 \n"
6172 +#ifdef CONFIG_PAX_REFCOUNT
6173 + /* Exception on overflow. */
6174 + "1: dadd %0, %2 \n"
6175 +#else
6176 + " daddu %0, %2 \n"
6177 +#endif
6178 + " sd %0, %1 \n"
6179 +#ifdef CONFIG_PAX_REFCOUNT
6180 + /* Note: Dest reg is not modified on overflow */
6181 + "2: \n"
6182 + _ASM_EXTABLE(1b, 2b)
6183 +#endif
6184 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6185 + raw_local_irq_restore(flags);
6186 + }
6187 +
6188 + smp_llsc_mb();
6189 +
6190 + return result;
6191 +}
6192 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6193 {
6194 long result;
6195
6196 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6197 return result;
6198 }
6199
6200 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6201 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6202 +{
6203 + long result;
6204 + long temp;
6205 +
6206 + smp_mb__before_llsc();
6207 +
6208 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6209 + long temp;
6210 +
6211 + __asm__ __volatile__(
6212 + " .set mips3 \n"
6213 + "1: lld %1, %2 # atomic64_sub_return \n"
6214 +#ifdef CONFIG_PAX_REFCOUNT
6215 + "2: dsub %0, %1, %3 \n"
6216 +#else
6217 + " dsubu %0, %1, %3 \n"
6218 +#endif
6219 + " scd %0, %2 \n"
6220 + " beqzl %0, 1b \n"
6221 +#ifdef CONFIG_PAX_REFCOUNT
6222 + " b 4f \n"
6223 + " .set noreorder \n"
6224 + "3: b 5f \n"
6225 + " move %0, %1 \n"
6226 + " .set reorder \n"
6227 + _ASM_EXTABLE(2b, 3b)
6228 +#endif
6229 + "4: dsubu %0, %1, %3 \n"
6230 +#ifdef CONFIG_PAX_REFCOUNT
6231 + "5: \n"
6232 +#endif
6233 + " .set mips0 \n"
6234 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6235 + : "Ir" (i), "m" (v->counter)
6236 + : "memory");
6237 + } else if (kernel_uses_llsc) {
6238 + __asm__ __volatile__(
6239 + " .set mips3 \n"
6240 + "1: lld %1, %2 # atomic64_sub_return \n"
6241 +#ifdef CONFIG_PAX_REFCOUNT
6242 + "2: dsub %0, %1, %3 \n"
6243 +#else
6244 + " dsubu %0, %1, %3 \n"
6245 +#endif
6246 + " scd %0, %2 \n"
6247 + " bnez %0, 4f \n"
6248 + " b 1b \n"
6249 +#ifdef CONFIG_PAX_REFCOUNT
6250 + " .set noreorder \n"
6251 + "3: b 5f \n"
6252 + " move %0, %1 \n"
6253 + " .set reorder \n"
6254 + _ASM_EXTABLE(2b, 3b)
6255 +#endif
6256 + "4: dsubu %0, %1, %3 \n"
6257 +#ifdef CONFIG_PAX_REFCOUNT
6258 + "5: \n"
6259 +#endif
6260 + " .set mips0 \n"
6261 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6262 + : "Ir" (i), "m" (v->counter)
6263 + : "memory");
6264 + } else {
6265 + unsigned long flags;
6266 +
6267 + raw_local_irq_save(flags);
6268 + __asm__ __volatile__(
6269 + " ld %0, %1 \n"
6270 +#ifdef CONFIG_PAX_REFCOUNT
6271 + /* Exception on overflow. */
6272 + "1: dsub %0, %2 \n"
6273 +#else
6274 + " dsubu %0, %2 \n"
6275 +#endif
6276 + " sd %0, %1 \n"
6277 +#ifdef CONFIG_PAX_REFCOUNT
6278 + /* Note: Dest reg is not modified on overflow */
6279 + "2: \n"
6280 + _ASM_EXTABLE(1b, 2b)
6281 +#endif
6282 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6283 + raw_local_irq_restore(flags);
6284 + }
6285 +
6286 + smp_llsc_mb();
6287 +
6288 + return result;
6289 +}
6290 +
6291 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6292 {
6293 long result;
6294
6295 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6296 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6297 * The function returns the old value of @v minus @i.
6298 */
6299 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6300 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6301 {
6302 long result;
6303
6304 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6305 return result;
6306 }
6307
6308 -#define atomic64_cmpxchg(v, o, n) \
6309 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6310 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6311 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6312 +{
6313 + return cmpxchg(&v->counter, old, new);
6314 +}
6315 +
6316 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6317 + long new)
6318 +{
6319 + return cmpxchg(&(v->counter), old, new);
6320 +}
6321 +
6322 +static inline long atomic64_xchg(atomic64_t *v, long new)
6323 +{
6324 + return xchg(&v->counter, new);
6325 +}
6326 +
6327 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6328 +{
6329 + return xchg(&(v->counter), new);
6330 +}
6331
6332 /**
6333 * atomic64_add_unless - add unless the number is a given value
6334 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6335
6336 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6337 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6338 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6339
6340 /*
6341 * atomic64_sub_and_test - subtract value from variable and test result
6342 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6343 * other cases.
6344 */
6345 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6346 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6347
6348 /*
6349 * atomic64_dec_and_test - decrement by 1 and test
6350 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6351 * Atomically increments @v by 1.
6352 */
6353 #define atomic64_inc(v) atomic64_add(1, (v))
6354 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6355
6356 /*
6357 * atomic64_dec - decrement and test
6358 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6359 * Atomically decrements @v by 1.
6360 */
6361 #define atomic64_dec(v) atomic64_sub(1, (v))
6362 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6363
6364 /*
6365 * atomic64_add_negative - add and test if negative
6366 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6367 index b4db69f..8f3b093 100644
6368 --- a/arch/mips/include/asm/cache.h
6369 +++ b/arch/mips/include/asm/cache.h
6370 @@ -9,10 +9,11 @@
6371 #ifndef _ASM_CACHE_H
6372 #define _ASM_CACHE_H
6373
6374 +#include <linux/const.h>
6375 #include <kmalloc.h>
6376
6377 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6378 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6379 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6380
6381 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6382 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6383 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6384 index a66359e..d3d474a 100644
6385 --- a/arch/mips/include/asm/elf.h
6386 +++ b/arch/mips/include/asm/elf.h
6387 @@ -373,13 +373,16 @@ extern const char *__elf_platform;
6388 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6389 #endif
6390
6391 +#ifdef CONFIG_PAX_ASLR
6392 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6393 +
6394 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6395 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6396 +#endif
6397 +
6398 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6399 struct linux_binprm;
6400 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6401 int uses_interp);
6402
6403 -struct mm_struct;
6404 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6405 -#define arch_randomize_brk arch_randomize_brk
6406 -
6407 #endif /* _ASM_ELF_H */
6408 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6409 index c1f6afa..38cc6e9 100644
6410 --- a/arch/mips/include/asm/exec.h
6411 +++ b/arch/mips/include/asm/exec.h
6412 @@ -12,6 +12,6 @@
6413 #ifndef _ASM_EXEC_H
6414 #define _ASM_EXEC_H
6415
6416 -extern unsigned long arch_align_stack(unsigned long sp);
6417 +#define arch_align_stack(x) ((x) & ~0xfUL)
6418
6419 #endif /* _ASM_EXEC_H */
6420 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6421 index d44622c..64990d2 100644
6422 --- a/arch/mips/include/asm/local.h
6423 +++ b/arch/mips/include/asm/local.h
6424 @@ -12,15 +12,25 @@ typedef struct
6425 atomic_long_t a;
6426 } local_t;
6427
6428 +typedef struct {
6429 + atomic_long_unchecked_t a;
6430 +} local_unchecked_t;
6431 +
6432 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6433
6434 #define local_read(l) atomic_long_read(&(l)->a)
6435 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6436 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6437 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6438
6439 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6440 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6441 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6442 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6443 #define local_inc(l) atomic_long_inc(&(l)->a)
6444 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6445 #define local_dec(l) atomic_long_dec(&(l)->a)
6446 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6447
6448 /*
6449 * Same as above, but return the result value
6450 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6451 return result;
6452 }
6453
6454 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6455 +{
6456 + unsigned long result;
6457 +
6458 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6459 + unsigned long temp;
6460 +
6461 + __asm__ __volatile__(
6462 + " .set mips3 \n"
6463 + "1:" __LL "%1, %2 # local_add_return \n"
6464 + " addu %0, %1, %3 \n"
6465 + __SC "%0, %2 \n"
6466 + " beqzl %0, 1b \n"
6467 + " addu %0, %1, %3 \n"
6468 + " .set mips0 \n"
6469 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6470 + : "Ir" (i), "m" (l->a.counter)
6471 + : "memory");
6472 + } else if (kernel_uses_llsc) {
6473 + unsigned long temp;
6474 +
6475 + __asm__ __volatile__(
6476 + " .set mips3 \n"
6477 + "1:" __LL "%1, %2 # local_add_return \n"
6478 + " addu %0, %1, %3 \n"
6479 + __SC "%0, %2 \n"
6480 + " beqz %0, 1b \n"
6481 + " addu %0, %1, %3 \n"
6482 + " .set mips0 \n"
6483 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6484 + : "Ir" (i), "m" (l->a.counter)
6485 + : "memory");
6486 + } else {
6487 + unsigned long flags;
6488 +
6489 + local_irq_save(flags);
6490 + result = l->a.counter;
6491 + result += i;
6492 + l->a.counter = result;
6493 + local_irq_restore(flags);
6494 + }
6495 +
6496 + return result;
6497 +}
6498 +
6499 static __inline__ long local_sub_return(long i, local_t * l)
6500 {
6501 unsigned long result;
6502 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6503
6504 #define local_cmpxchg(l, o, n) \
6505 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6506 +#define local_cmpxchg_unchecked(l, o, n) \
6507 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6508 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6509
6510 /**
6511 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6512 index f6be474..12ad554 100644
6513 --- a/arch/mips/include/asm/page.h
6514 +++ b/arch/mips/include/asm/page.h
6515 @@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6516 #ifdef CONFIG_CPU_MIPS32
6517 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6518 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6519 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6520 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6521 #else
6522 typedef struct { unsigned long long pte; } pte_t;
6523 #define pte_val(x) ((x).pte)
6524 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6525 index b336037..5b874cc 100644
6526 --- a/arch/mips/include/asm/pgalloc.h
6527 +++ b/arch/mips/include/asm/pgalloc.h
6528 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6529 {
6530 set_pud(pud, __pud((unsigned long)pmd));
6531 }
6532 +
6533 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6534 +{
6535 + pud_populate(mm, pud, pmd);
6536 +}
6537 #endif
6538
6539 /*
6540 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6541 index 25da651..ae2a259 100644
6542 --- a/arch/mips/include/asm/smtc_proc.h
6543 +++ b/arch/mips/include/asm/smtc_proc.h
6544 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6545
6546 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6547
6548 -extern atomic_t smtc_fpu_recoveries;
6549 +extern atomic_unchecked_t smtc_fpu_recoveries;
6550
6551 #endif /* __ASM_SMTC_PROC_H */
6552 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6553 index 4f58ef6..5e7081b 100644
6554 --- a/arch/mips/include/asm/thread_info.h
6555 +++ b/arch/mips/include/asm/thread_info.h
6556 @@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6557 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6558 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6559 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6560 +/* li takes a 32bit immediate */
6561 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6562 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6563
6564 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6565 @@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6566 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6567 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6568 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6569 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6570
6571 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6572 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6573 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6574
6575 /* work to do in syscall_trace_leave() */
6576 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6577 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6578 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6579
6580 /* work to do on interrupt/exception return */
6581 #define _TIF_WORK_MASK \
6582 @@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6583 /* work to do on any return to u-space */
6584 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6585 _TIF_WORK_SYSCALL_EXIT | \
6586 - _TIF_SYSCALL_TRACEPOINT)
6587 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6588
6589 /*
6590 * We stash processor id into a COP0 register to retrieve it fast
6591 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6592 index 1188e00..41cf144 100644
6593 --- a/arch/mips/kernel/binfmt_elfn32.c
6594 +++ b/arch/mips/kernel/binfmt_elfn32.c
6595 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6596 #undef ELF_ET_DYN_BASE
6597 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6598
6599 +#ifdef CONFIG_PAX_ASLR
6600 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6601 +
6602 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6603 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6604 +#endif
6605 +
6606 #include <asm/processor.h>
6607 #include <linux/module.h>
6608 #include <linux/elfcore.h>
6609 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6610 index 202e581..689ca79 100644
6611 --- a/arch/mips/kernel/binfmt_elfo32.c
6612 +++ b/arch/mips/kernel/binfmt_elfo32.c
6613 @@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6614 #undef ELF_ET_DYN_BASE
6615 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6616
6617 +#ifdef CONFIG_PAX_ASLR
6618 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6619 +
6620 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6621 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6622 +#endif
6623 +
6624 #include <asm/processor.h>
6625
6626 /*
6627 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6628 index d1fea7a..45602ea 100644
6629 --- a/arch/mips/kernel/irq.c
6630 +++ b/arch/mips/kernel/irq.c
6631 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6632 printk("unexpected IRQ # %d\n", irq);
6633 }
6634
6635 -atomic_t irq_err_count;
6636 +atomic_unchecked_t irq_err_count;
6637
6638 int arch_show_interrupts(struct seq_file *p, int prec)
6639 {
6640 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6641 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6642 return 0;
6643 }
6644
6645 asmlinkage void spurious_interrupt(void)
6646 {
6647 - atomic_inc(&irq_err_count);
6648 + atomic_inc_unchecked(&irq_err_count);
6649 }
6650
6651 void __init init_IRQ(void)
6652 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6653 index ddc7610..8c58f17 100644
6654 --- a/arch/mips/kernel/process.c
6655 +++ b/arch/mips/kernel/process.c
6656 @@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6657 out:
6658 return pc;
6659 }
6660 -
6661 -/*
6662 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6663 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6664 - */
6665 -unsigned long arch_align_stack(unsigned long sp)
6666 -{
6667 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6668 - sp -= get_random_int() & ~PAGE_MASK;
6669 -
6670 - return sp & ALMASK;
6671 -}
6672 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6673 index b52e1d2..1a3ca09 100644
6674 --- a/arch/mips/kernel/ptrace.c
6675 +++ b/arch/mips/kernel/ptrace.c
6676 @@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6677 return ret;
6678 }
6679
6680 +#ifdef CONFIG_GRKERNSEC_SETXID
6681 +extern void gr_delayed_cred_worker(void);
6682 +#endif
6683 +
6684 /*
6685 * Notification of system call entry/exit
6686 * - triggered by current->work.syscall_trace
6687 @@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6688 tracehook_report_syscall_entry(regs))
6689 ret = -1;
6690
6691 +#ifdef CONFIG_GRKERNSEC_SETXID
6692 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6693 + gr_delayed_cred_worker();
6694 +#endif
6695 +
6696 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6697 trace_sys_enter(regs, regs->regs[2]);
6698
6699 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6700 index c10aa84..9ec2e60 100644
6701 --- a/arch/mips/kernel/smtc-proc.c
6702 +++ b/arch/mips/kernel/smtc-proc.c
6703 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6704
6705 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6706
6707 -atomic_t smtc_fpu_recoveries;
6708 +atomic_unchecked_t smtc_fpu_recoveries;
6709
6710 static int smtc_proc_show(struct seq_file *m, void *v)
6711 {
6712 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6713 for(i = 0; i < NR_CPUS; i++)
6714 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6715 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6716 - atomic_read(&smtc_fpu_recoveries));
6717 + atomic_read_unchecked(&smtc_fpu_recoveries));
6718 return 0;
6719 }
6720
6721 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6722 smtc_cpu_stats[i].selfipis = 0;
6723 }
6724
6725 - atomic_set(&smtc_fpu_recoveries, 0);
6726 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6727
6728 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6729 }
6730 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6731 index dfc1b91..11a2c07 100644
6732 --- a/arch/mips/kernel/smtc.c
6733 +++ b/arch/mips/kernel/smtc.c
6734 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6735 }
6736 smtc_ipi_qdump();
6737 printk("%d Recoveries of \"stolen\" FPU\n",
6738 - atomic_read(&smtc_fpu_recoveries));
6739 + atomic_read_unchecked(&smtc_fpu_recoveries));
6740 }
6741
6742
6743 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6744 index 84536bf..79caa4d 100644
6745 --- a/arch/mips/kernel/sync-r4k.c
6746 +++ b/arch/mips/kernel/sync-r4k.c
6747 @@ -21,8 +21,8 @@
6748 #include <asm/mipsregs.h>
6749
6750 static atomic_t count_start_flag = ATOMIC_INIT(0);
6751 -static atomic_t count_count_start = ATOMIC_INIT(0);
6752 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6753 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6754 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6755 static atomic_t count_reference = ATOMIC_INIT(0);
6756
6757 #define COUNTON 100
6758 @@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6759
6760 for (i = 0; i < NR_LOOPS; i++) {
6761 /* slaves loop on '!= 2' */
6762 - while (atomic_read(&count_count_start) != 1)
6763 + while (atomic_read_unchecked(&count_count_start) != 1)
6764 mb();
6765 - atomic_set(&count_count_stop, 0);
6766 + atomic_set_unchecked(&count_count_stop, 0);
6767 smp_wmb();
6768
6769 /* this lets the slaves write their count register */
6770 - atomic_inc(&count_count_start);
6771 + atomic_inc_unchecked(&count_count_start);
6772
6773 /*
6774 * Everyone initialises count in the last loop:
6775 @@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6776 /*
6777 * Wait for all slaves to leave the synchronization point:
6778 */
6779 - while (atomic_read(&count_count_stop) != 1)
6780 + while (atomic_read_unchecked(&count_count_stop) != 1)
6781 mb();
6782 - atomic_set(&count_count_start, 0);
6783 + atomic_set_unchecked(&count_count_start, 0);
6784 smp_wmb();
6785 - atomic_inc(&count_count_stop);
6786 + atomic_inc_unchecked(&count_count_stop);
6787 }
6788 /* Arrange for an interrupt in a short while */
6789 write_c0_compare(read_c0_count() + COUNTON);
6790 @@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6791 initcount = atomic_read(&count_reference);
6792
6793 for (i = 0; i < NR_LOOPS; i++) {
6794 - atomic_inc(&count_count_start);
6795 - while (atomic_read(&count_count_start) != 2)
6796 + atomic_inc_unchecked(&count_count_start);
6797 + while (atomic_read_unchecked(&count_count_start) != 2)
6798 mb();
6799
6800 /*
6801 @@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6802 if (i == NR_LOOPS-1)
6803 write_c0_count(initcount);
6804
6805 - atomic_inc(&count_count_stop);
6806 - while (atomic_read(&count_count_stop) != 2)
6807 + atomic_inc_unchecked(&count_count_stop);
6808 + while (atomic_read_unchecked(&count_count_stop) != 2)
6809 mb();
6810 }
6811 /* Arrange for an interrupt in a short while */
6812 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6813 index f9c8746..78b64e3 100644
6814 --- a/arch/mips/kernel/traps.c
6815 +++ b/arch/mips/kernel/traps.c
6816 @@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6817 siginfo_t info;
6818
6819 prev_state = exception_enter();
6820 - die_if_kernel("Integer overflow", regs);
6821 + if (unlikely(!user_mode(regs))) {
6822 +
6823 +#ifdef CONFIG_PAX_REFCOUNT
6824 + if (fixup_exception(regs)) {
6825 + pax_report_refcount_overflow(regs);
6826 + exception_exit(prev_state);
6827 + return;
6828 + }
6829 +#endif
6830 +
6831 + die("Integer overflow", regs);
6832 + }
6833
6834 info.si_code = FPE_INTOVF;
6835 info.si_signo = SIGFPE;
6836 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6837 index becc42b..9e43d4b 100644
6838 --- a/arch/mips/mm/fault.c
6839 +++ b/arch/mips/mm/fault.c
6840 @@ -28,6 +28,23 @@
6841 #include <asm/highmem.h> /* For VMALLOC_END */
6842 #include <linux/kdebug.h>
6843
6844 +#ifdef CONFIG_PAX_PAGEEXEC
6845 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6846 +{
6847 + unsigned long i;
6848 +
6849 + printk(KERN_ERR "PAX: bytes at PC: ");
6850 + for (i = 0; i < 5; i++) {
6851 + unsigned int c;
6852 + if (get_user(c, (unsigned int *)pc+i))
6853 + printk(KERN_CONT "???????? ");
6854 + else
6855 + printk(KERN_CONT "%08x ", c);
6856 + }
6857 + printk("\n");
6858 +}
6859 +#endif
6860 +
6861 /*
6862 * This routine handles page faults. It determines the address,
6863 * and the problem, and then passes it off to one of the appropriate
6864 @@ -199,6 +216,14 @@ bad_area:
6865 bad_area_nosemaphore:
6866 /* User mode accesses just cause a SIGSEGV */
6867 if (user_mode(regs)) {
6868 +
6869 +#ifdef CONFIG_PAX_PAGEEXEC
6870 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6871 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6872 + do_group_exit(SIGKILL);
6873 + }
6874 +#endif
6875 +
6876 tsk->thread.cp0_badvaddr = address;
6877 tsk->thread.error_code = write;
6878 #if 0
6879 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6880 index f1baadd..8537544 100644
6881 --- a/arch/mips/mm/mmap.c
6882 +++ b/arch/mips/mm/mmap.c
6883 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6884 struct vm_area_struct *vma;
6885 unsigned long addr = addr0;
6886 int do_color_align;
6887 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6888 struct vm_unmapped_area_info info;
6889
6890 if (unlikely(len > TASK_SIZE))
6891 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6892 do_color_align = 1;
6893
6894 /* requesting a specific address */
6895 +
6896 +#ifdef CONFIG_PAX_RANDMMAP
6897 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6898 +#endif
6899 +
6900 if (addr) {
6901 if (do_color_align)
6902 addr = COLOUR_ALIGN(addr, pgoff);
6903 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6904 addr = PAGE_ALIGN(addr);
6905
6906 vma = find_vma(mm, addr);
6907 - if (TASK_SIZE - len >= addr &&
6908 - (!vma || addr + len <= vma->vm_start))
6909 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6910 return addr;
6911 }
6912
6913 info.length = len;
6914 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6915 info.align_offset = pgoff << PAGE_SHIFT;
6916 + info.threadstack_offset = offset;
6917
6918 if (dir == DOWN) {
6919 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6920 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6921 {
6922 unsigned long random_factor = 0UL;
6923
6924 +#ifdef CONFIG_PAX_RANDMMAP
6925 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6926 +#endif
6927 +
6928 if (current->flags & PF_RANDOMIZE) {
6929 random_factor = get_random_int();
6930 random_factor = random_factor << PAGE_SHIFT;
6931 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6932
6933 if (mmap_is_legacy()) {
6934 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6935 +
6936 +#ifdef CONFIG_PAX_RANDMMAP
6937 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6938 + mm->mmap_base += mm->delta_mmap;
6939 +#endif
6940 +
6941 mm->get_unmapped_area = arch_get_unmapped_area;
6942 } else {
6943 mm->mmap_base = mmap_base(random_factor);
6944 +
6945 +#ifdef CONFIG_PAX_RANDMMAP
6946 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6947 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6948 +#endif
6949 +
6950 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6951 }
6952 }
6953
6954 -static inline unsigned long brk_rnd(void)
6955 -{
6956 - unsigned long rnd = get_random_int();
6957 -
6958 - rnd = rnd << PAGE_SHIFT;
6959 - /* 8MB for 32bit, 256MB for 64bit */
6960 - if (TASK_IS_32BIT_ADDR)
6961 - rnd = rnd & 0x7ffffful;
6962 - else
6963 - rnd = rnd & 0xffffffful;
6964 -
6965 - return rnd;
6966 -}
6967 -
6968 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6969 -{
6970 - unsigned long base = mm->brk;
6971 - unsigned long ret;
6972 -
6973 - ret = PAGE_ALIGN(base + brk_rnd());
6974 -
6975 - if (ret < mm->brk)
6976 - return mm->brk;
6977 -
6978 - return ret;
6979 -}
6980 -
6981 int __virt_addr_valid(const volatile void *kaddr)
6982 {
6983 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6984 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6985 index a2358b4..7cead4f 100644
6986 --- a/arch/mips/sgi-ip27/ip27-nmi.c
6987 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
6988 @@ -187,9 +187,9 @@ void
6989 cont_nmi_dump(void)
6990 {
6991 #ifndef REAL_NMI_SIGNAL
6992 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
6993 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6994
6995 - atomic_inc(&nmied_cpus);
6996 + atomic_inc_unchecked(&nmied_cpus);
6997 #endif
6998 /*
6999 * Only allow 1 cpu to proceed
7000 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7001 udelay(10000);
7002 }
7003 #else
7004 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7005 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7006 #endif
7007
7008 /*
7009 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7010 index 967d144..db12197 100644
7011 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7012 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7013 @@ -11,12 +11,14 @@
7014 #ifndef _ASM_PROC_CACHE_H
7015 #define _ASM_PROC_CACHE_H
7016
7017 +#include <linux/const.h>
7018 +
7019 /* L1 cache */
7020
7021 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7022 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7023 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7024 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7025 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7026 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7027
7028 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7029 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7030 index bcb5df2..84fabd2 100644
7031 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7032 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7033 @@ -16,13 +16,15 @@
7034 #ifndef _ASM_PROC_CACHE_H
7035 #define _ASM_PROC_CACHE_H
7036
7037 +#include <linux/const.h>
7038 +
7039 /*
7040 * L1 cache
7041 */
7042 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7043 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7044 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7045 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7046 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7047 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7048
7049 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7050 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7051 index 4ce7a01..449202a 100644
7052 --- a/arch/openrisc/include/asm/cache.h
7053 +++ b/arch/openrisc/include/asm/cache.h
7054 @@ -19,11 +19,13 @@
7055 #ifndef __ASM_OPENRISC_CACHE_H
7056 #define __ASM_OPENRISC_CACHE_H
7057
7058 +#include <linux/const.h>
7059 +
7060 /* FIXME: How can we replace these with values from the CPU...
7061 * they shouldn't be hard-coded!
7062 */
7063
7064 -#define L1_CACHE_BYTES 16
7065 #define L1_CACHE_SHIFT 4
7066 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7067
7068 #endif /* __ASM_OPENRISC_CACHE_H */
7069 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7070 index 472886c..00e7df9 100644
7071 --- a/arch/parisc/include/asm/atomic.h
7072 +++ b/arch/parisc/include/asm/atomic.h
7073 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7074 return dec;
7075 }
7076
7077 +#define atomic64_read_unchecked(v) atomic64_read(v)
7078 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7079 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7080 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7081 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7082 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7083 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7084 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7085 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7086 +
7087 #endif /* !CONFIG_64BIT */
7088
7089
7090 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7091 index 47f11c7..3420df2 100644
7092 --- a/arch/parisc/include/asm/cache.h
7093 +++ b/arch/parisc/include/asm/cache.h
7094 @@ -5,6 +5,7 @@
7095 #ifndef __ARCH_PARISC_CACHE_H
7096 #define __ARCH_PARISC_CACHE_H
7097
7098 +#include <linux/const.h>
7099
7100 /*
7101 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7102 @@ -15,13 +16,13 @@
7103 * just ruin performance.
7104 */
7105 #ifdef CONFIG_PA20
7106 -#define L1_CACHE_BYTES 64
7107 #define L1_CACHE_SHIFT 6
7108 #else
7109 -#define L1_CACHE_BYTES 32
7110 #define L1_CACHE_SHIFT 5
7111 #endif
7112
7113 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7114 +
7115 #ifndef __ASSEMBLY__
7116
7117 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7118 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7119 index ad2b503..bdf1651 100644
7120 --- a/arch/parisc/include/asm/elf.h
7121 +++ b/arch/parisc/include/asm/elf.h
7122 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7123
7124 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7125
7126 +#ifdef CONFIG_PAX_ASLR
7127 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7128 +
7129 +#define PAX_DELTA_MMAP_LEN 16
7130 +#define PAX_DELTA_STACK_LEN 16
7131 +#endif
7132 +
7133 /* This yields a mask that user programs can use to figure out what
7134 instruction set this CPU supports. This could be done in user space,
7135 but it's not easy, and we've already done it here. */
7136 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7137 index f213f5b..0af3e8e 100644
7138 --- a/arch/parisc/include/asm/pgalloc.h
7139 +++ b/arch/parisc/include/asm/pgalloc.h
7140 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7141 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7142 }
7143
7144 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7145 +{
7146 + pgd_populate(mm, pgd, pmd);
7147 +}
7148 +
7149 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7150 {
7151 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7152 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7153 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7154 #define pmd_free(mm, x) do { } while (0)
7155 #define pgd_populate(mm, pmd, pte) BUG()
7156 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7157
7158 #endif
7159
7160 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7161 index 34899b5..02dd060 100644
7162 --- a/arch/parisc/include/asm/pgtable.h
7163 +++ b/arch/parisc/include/asm/pgtable.h
7164 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7165 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7166 #define PAGE_COPY PAGE_EXECREAD
7167 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7168 +
7169 +#ifdef CONFIG_PAX_PAGEEXEC
7170 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7171 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7172 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7173 +#else
7174 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7175 +# define PAGE_COPY_NOEXEC PAGE_COPY
7176 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7177 +#endif
7178 +
7179 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7180 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7181 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7182 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7183 index 4006964..fcb3cc2 100644
7184 --- a/arch/parisc/include/asm/uaccess.h
7185 +++ b/arch/parisc/include/asm/uaccess.h
7186 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7187 const void __user *from,
7188 unsigned long n)
7189 {
7190 - int sz = __compiletime_object_size(to);
7191 + size_t sz = __compiletime_object_size(to);
7192 int ret = -EFAULT;
7193
7194 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7195 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7196 ret = __copy_from_user(to, from, n);
7197 else
7198 copy_from_user_overflow();
7199 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7200 index 50dfafc..b9fc230 100644
7201 --- a/arch/parisc/kernel/module.c
7202 +++ b/arch/parisc/kernel/module.c
7203 @@ -98,16 +98,38 @@
7204
7205 /* three functions to determine where in the module core
7206 * or init pieces the location is */
7207 +static inline int in_init_rx(struct module *me, void *loc)
7208 +{
7209 + return (loc >= me->module_init_rx &&
7210 + loc < (me->module_init_rx + me->init_size_rx));
7211 +}
7212 +
7213 +static inline int in_init_rw(struct module *me, void *loc)
7214 +{
7215 + return (loc >= me->module_init_rw &&
7216 + loc < (me->module_init_rw + me->init_size_rw));
7217 +}
7218 +
7219 static inline int in_init(struct module *me, void *loc)
7220 {
7221 - return (loc >= me->module_init &&
7222 - loc <= (me->module_init + me->init_size));
7223 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7224 +}
7225 +
7226 +static inline int in_core_rx(struct module *me, void *loc)
7227 +{
7228 + return (loc >= me->module_core_rx &&
7229 + loc < (me->module_core_rx + me->core_size_rx));
7230 +}
7231 +
7232 +static inline int in_core_rw(struct module *me, void *loc)
7233 +{
7234 + return (loc >= me->module_core_rw &&
7235 + loc < (me->module_core_rw + me->core_size_rw));
7236 }
7237
7238 static inline int in_core(struct module *me, void *loc)
7239 {
7240 - return (loc >= me->module_core &&
7241 - loc <= (me->module_core + me->core_size));
7242 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7243 }
7244
7245 static inline int in_local(struct module *me, void *loc)
7246 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7247 }
7248
7249 /* align things a bit */
7250 - me->core_size = ALIGN(me->core_size, 16);
7251 - me->arch.got_offset = me->core_size;
7252 - me->core_size += gots * sizeof(struct got_entry);
7253 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7254 + me->arch.got_offset = me->core_size_rw;
7255 + me->core_size_rw += gots * sizeof(struct got_entry);
7256
7257 - me->core_size = ALIGN(me->core_size, 16);
7258 - me->arch.fdesc_offset = me->core_size;
7259 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7260 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7261 + me->arch.fdesc_offset = me->core_size_rw;
7262 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7263
7264 me->arch.got_max = gots;
7265 me->arch.fdesc_max = fdescs;
7266 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7267
7268 BUG_ON(value == 0);
7269
7270 - got = me->module_core + me->arch.got_offset;
7271 + got = me->module_core_rw + me->arch.got_offset;
7272 for (i = 0; got[i].addr; i++)
7273 if (got[i].addr == value)
7274 goto out;
7275 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7276 #ifdef CONFIG_64BIT
7277 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7278 {
7279 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7280 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7281
7282 if (!value) {
7283 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7284 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7285
7286 /* Create new one */
7287 fdesc->addr = value;
7288 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7289 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7290 return (Elf_Addr)fdesc;
7291 }
7292 #endif /* CONFIG_64BIT */
7293 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7294
7295 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7296 end = table + sechdrs[me->arch.unwind_section].sh_size;
7297 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7298 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7299
7300 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7301 me->arch.unwind_section, table, end, gp);
7302 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7303 index 0d3a9d4..20a99b0 100644
7304 --- a/arch/parisc/kernel/sys_parisc.c
7305 +++ b/arch/parisc/kernel/sys_parisc.c
7306 @@ -33,9 +33,11 @@
7307 #include <linux/utsname.h>
7308 #include <linux/personality.h>
7309
7310 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7311 +static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7312 + unsigned long flags)
7313 {
7314 struct vm_unmapped_area_info info;
7315 + unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7316
7317 info.flags = 0;
7318 info.length = len;
7319 @@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7320 info.high_limit = TASK_SIZE;
7321 info.align_mask = 0;
7322 info.align_offset = 0;
7323 + info.threadstack_offset = offset;
7324 return vm_unmapped_area(&info);
7325 }
7326
7327 @@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7328 }
7329
7330 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7331 - unsigned long len, unsigned long pgoff)
7332 + unsigned long len, unsigned long pgoff, unsigned long flags)
7333 {
7334 struct vm_unmapped_area_info info;
7335 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7336
7337 info.flags = 0;
7338 info.length = len;
7339 @@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7340 info.high_limit = TASK_SIZE;
7341 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7342 info.align_offset = shared_align_offset(filp, pgoff);
7343 + info.threadstack_offset = offset;
7344 return vm_unmapped_area(&info);
7345 }
7346
7347 @@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7348 return -EINVAL;
7349 return addr;
7350 }
7351 - if (!addr)
7352 + if (!addr) {
7353 addr = TASK_UNMAPPED_BASE;
7354
7355 +#ifdef CONFIG_PAX_RANDMMAP
7356 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7357 + addr += current->mm->delta_mmap;
7358 +#endif
7359 +
7360 + }
7361 +
7362 if (filp || (flags & MAP_SHARED))
7363 - addr = get_shared_area(filp, addr, len, pgoff);
7364 + addr = get_shared_area(filp, addr, len, pgoff, flags);
7365 else
7366 - addr = get_unshared_area(addr, len);
7367 + addr = get_unshared_area(addr, len, flags);
7368
7369 return addr;
7370 }
7371 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7372 index 1cd1d0c..44ec918 100644
7373 --- a/arch/parisc/kernel/traps.c
7374 +++ b/arch/parisc/kernel/traps.c
7375 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7376
7377 down_read(&current->mm->mmap_sem);
7378 vma = find_vma(current->mm,regs->iaoq[0]);
7379 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7380 - && (vma->vm_flags & VM_EXEC)) {
7381 -
7382 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7383 fault_address = regs->iaoq[0];
7384 fault_space = regs->iasq[0];
7385
7386 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7387 index 9d08c71..e2b4d20 100644
7388 --- a/arch/parisc/mm/fault.c
7389 +++ b/arch/parisc/mm/fault.c
7390 @@ -15,6 +15,7 @@
7391 #include <linux/sched.h>
7392 #include <linux/interrupt.h>
7393 #include <linux/module.h>
7394 +#include <linux/unistd.h>
7395
7396 #include <asm/uaccess.h>
7397 #include <asm/traps.h>
7398 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7399 static unsigned long
7400 parisc_acctyp(unsigned long code, unsigned int inst)
7401 {
7402 - if (code == 6 || code == 16)
7403 + if (code == 6 || code == 7 || code == 16)
7404 return VM_EXEC;
7405
7406 switch (inst & 0xf0000000) {
7407 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7408 }
7409 #endif
7410
7411 +#ifdef CONFIG_PAX_PAGEEXEC
7412 +/*
7413 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7414 + *
7415 + * returns 1 when task should be killed
7416 + * 2 when rt_sigreturn trampoline was detected
7417 + * 3 when unpatched PLT trampoline was detected
7418 + */
7419 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7420 +{
7421 +
7422 +#ifdef CONFIG_PAX_EMUPLT
7423 + int err;
7424 +
7425 + do { /* PaX: unpatched PLT emulation */
7426 + unsigned int bl, depwi;
7427 +
7428 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7429 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7430 +
7431 + if (err)
7432 + break;
7433 +
7434 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7435 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7436 +
7437 + err = get_user(ldw, (unsigned int *)addr);
7438 + err |= get_user(bv, (unsigned int *)(addr+4));
7439 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7440 +
7441 + if (err)
7442 + break;
7443 +
7444 + if (ldw == 0x0E801096U &&
7445 + bv == 0xEAC0C000U &&
7446 + ldw2 == 0x0E881095U)
7447 + {
7448 + unsigned int resolver, map;
7449 +
7450 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7451 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7452 + if (err)
7453 + break;
7454 +
7455 + regs->gr[20] = instruction_pointer(regs)+8;
7456 + regs->gr[21] = map;
7457 + regs->gr[22] = resolver;
7458 + regs->iaoq[0] = resolver | 3UL;
7459 + regs->iaoq[1] = regs->iaoq[0] + 4;
7460 + return 3;
7461 + }
7462 + }
7463 + } while (0);
7464 +#endif
7465 +
7466 +#ifdef CONFIG_PAX_EMUTRAMP
7467 +
7468 +#ifndef CONFIG_PAX_EMUSIGRT
7469 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7470 + return 1;
7471 +#endif
7472 +
7473 + do { /* PaX: rt_sigreturn emulation */
7474 + unsigned int ldi1, ldi2, bel, nop;
7475 +
7476 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7477 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7478 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7479 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7480 +
7481 + if (err)
7482 + break;
7483 +
7484 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7485 + ldi2 == 0x3414015AU &&
7486 + bel == 0xE4008200U &&
7487 + nop == 0x08000240U)
7488 + {
7489 + regs->gr[25] = (ldi1 & 2) >> 1;
7490 + regs->gr[20] = __NR_rt_sigreturn;
7491 + regs->gr[31] = regs->iaoq[1] + 16;
7492 + regs->sr[0] = regs->iasq[1];
7493 + regs->iaoq[0] = 0x100UL;
7494 + regs->iaoq[1] = regs->iaoq[0] + 4;
7495 + regs->iasq[0] = regs->sr[2];
7496 + regs->iasq[1] = regs->sr[2];
7497 + return 2;
7498 + }
7499 + } while (0);
7500 +#endif
7501 +
7502 + return 1;
7503 +}
7504 +
7505 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7506 +{
7507 + unsigned long i;
7508 +
7509 + printk(KERN_ERR "PAX: bytes at PC: ");
7510 + for (i = 0; i < 5; i++) {
7511 + unsigned int c;
7512 + if (get_user(c, (unsigned int *)pc+i))
7513 + printk(KERN_CONT "???????? ");
7514 + else
7515 + printk(KERN_CONT "%08x ", c);
7516 + }
7517 + printk("\n");
7518 +}
7519 +#endif
7520 +
7521 int fixup_exception(struct pt_regs *regs)
7522 {
7523 const struct exception_table_entry *fix;
7524 @@ -210,8 +321,33 @@ retry:
7525
7526 good_area:
7527
7528 - if ((vma->vm_flags & acc_type) != acc_type)
7529 + if ((vma->vm_flags & acc_type) != acc_type) {
7530 +
7531 +#ifdef CONFIG_PAX_PAGEEXEC
7532 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7533 + (address & ~3UL) == instruction_pointer(regs))
7534 + {
7535 + up_read(&mm->mmap_sem);
7536 + switch (pax_handle_fetch_fault(regs)) {
7537 +
7538 +#ifdef CONFIG_PAX_EMUPLT
7539 + case 3:
7540 + return;
7541 +#endif
7542 +
7543 +#ifdef CONFIG_PAX_EMUTRAMP
7544 + case 2:
7545 + return;
7546 +#endif
7547 +
7548 + }
7549 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7550 + do_group_exit(SIGKILL);
7551 + }
7552 +#endif
7553 +
7554 goto bad_area;
7555 + }
7556
7557 /*
7558 * If for any reason at all we couldn't handle the fault, make
7559 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7560 index b44b52c..4cd253c 100644
7561 --- a/arch/powerpc/Kconfig
7562 +++ b/arch/powerpc/Kconfig
7563 @@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7564 config KEXEC
7565 bool "kexec system call"
7566 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7567 + depends on !GRKERNSEC_KMEM
7568 help
7569 kexec is a system call that implements the ability to shutdown your
7570 current kernel, and to start another kernel. It is like a reboot
7571 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7572 index e3b1d41..8e81edf 100644
7573 --- a/arch/powerpc/include/asm/atomic.h
7574 +++ b/arch/powerpc/include/asm/atomic.h
7575 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7576 return t1;
7577 }
7578
7579 +#define atomic64_read_unchecked(v) atomic64_read(v)
7580 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7581 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7582 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7583 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7584 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7585 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7586 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7587 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7588 +
7589 #endif /* __powerpc64__ */
7590
7591 #endif /* __KERNEL__ */
7592 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7593 index 9e495c9..b6878e5 100644
7594 --- a/arch/powerpc/include/asm/cache.h
7595 +++ b/arch/powerpc/include/asm/cache.h
7596 @@ -3,6 +3,7 @@
7597
7598 #ifdef __KERNEL__
7599
7600 +#include <linux/const.h>
7601
7602 /* bytes per L1 cache line */
7603 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7604 @@ -22,7 +23,7 @@
7605 #define L1_CACHE_SHIFT 7
7606 #endif
7607
7608 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7609 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7610
7611 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7612
7613 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7614 index 935b5e7..7001d2d 100644
7615 --- a/arch/powerpc/include/asm/elf.h
7616 +++ b/arch/powerpc/include/asm/elf.h
7617 @@ -28,8 +28,19 @@
7618 the loader. We need to make sure that it is out of the way of the program
7619 that it will "exec", and that there is sufficient room for the brk. */
7620
7621 -extern unsigned long randomize_et_dyn(unsigned long base);
7622 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7623 +#define ELF_ET_DYN_BASE (0x20000000)
7624 +
7625 +#ifdef CONFIG_PAX_ASLR
7626 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7627 +
7628 +#ifdef __powerpc64__
7629 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7630 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7631 +#else
7632 +#define PAX_DELTA_MMAP_LEN 15
7633 +#define PAX_DELTA_STACK_LEN 15
7634 +#endif
7635 +#endif
7636
7637 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7638
7639 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7640 (0x7ff >> (PAGE_SHIFT - 12)) : \
7641 (0x3ffff >> (PAGE_SHIFT - 12)))
7642
7643 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7644 -#define arch_randomize_brk arch_randomize_brk
7645 -
7646 -
7647 #ifdef CONFIG_SPU_BASE
7648 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7649 #define NT_SPU 1
7650 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7651 index 8196e9c..d83a9f3 100644
7652 --- a/arch/powerpc/include/asm/exec.h
7653 +++ b/arch/powerpc/include/asm/exec.h
7654 @@ -4,6 +4,6 @@
7655 #ifndef _ASM_POWERPC_EXEC_H
7656 #define _ASM_POWERPC_EXEC_H
7657
7658 -extern unsigned long arch_align_stack(unsigned long sp);
7659 +#define arch_align_stack(x) ((x) & ~0xfUL)
7660
7661 #endif /* _ASM_POWERPC_EXEC_H */
7662 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7663 index 5acabbd..7ea14fa 100644
7664 --- a/arch/powerpc/include/asm/kmap_types.h
7665 +++ b/arch/powerpc/include/asm/kmap_types.h
7666 @@ -10,7 +10,7 @@
7667 * 2 of the License, or (at your option) any later version.
7668 */
7669
7670 -#define KM_TYPE_NR 16
7671 +#define KM_TYPE_NR 17
7672
7673 #endif /* __KERNEL__ */
7674 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7675 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7676 index 8565c25..2865190 100644
7677 --- a/arch/powerpc/include/asm/mman.h
7678 +++ b/arch/powerpc/include/asm/mman.h
7679 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7680 }
7681 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7682
7683 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7684 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7685 {
7686 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7687 }
7688 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7689 index 32e4e21..62afb12 100644
7690 --- a/arch/powerpc/include/asm/page.h
7691 +++ b/arch/powerpc/include/asm/page.h
7692 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7693 * and needs to be executable. This means the whole heap ends
7694 * up being executable.
7695 */
7696 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7697 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7698 +#define VM_DATA_DEFAULT_FLAGS32 \
7699 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7700 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7701
7702 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7703 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7704 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7705 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7706 #endif
7707
7708 +#define ktla_ktva(addr) (addr)
7709 +#define ktva_ktla(addr) (addr)
7710 +
7711 #ifndef CONFIG_PPC_BOOK3S_64
7712 /*
7713 * Use the top bit of the higher-level page table entries to indicate whether
7714 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7715 index 88693ce..ac6f9ab 100644
7716 --- a/arch/powerpc/include/asm/page_64.h
7717 +++ b/arch/powerpc/include/asm/page_64.h
7718 @@ -153,15 +153,18 @@ do { \
7719 * stack by default, so in the absence of a PT_GNU_STACK program header
7720 * we turn execute permission off.
7721 */
7722 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7723 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7724 +#define VM_STACK_DEFAULT_FLAGS32 \
7725 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7726 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7727
7728 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7729 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7730
7731 +#ifndef CONFIG_PAX_PAGEEXEC
7732 #define VM_STACK_DEFAULT_FLAGS \
7733 (is_32bit_task() ? \
7734 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7735 +#endif
7736
7737 #include <asm-generic/getorder.h>
7738
7739 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7740 index 4b0be20..c15a27d 100644
7741 --- a/arch/powerpc/include/asm/pgalloc-64.h
7742 +++ b/arch/powerpc/include/asm/pgalloc-64.h
7743 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7744 #ifndef CONFIG_PPC_64K_PAGES
7745
7746 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7747 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7748
7749 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7750 {
7751 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7752 pud_set(pud, (unsigned long)pmd);
7753 }
7754
7755 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7756 +{
7757 + pud_populate(mm, pud, pmd);
7758 +}
7759 +
7760 #define pmd_populate(mm, pmd, pte_page) \
7761 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7762 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7763 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
7764 #endif
7765
7766 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7767 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7768
7769 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7770 pte_t *pte)
7771 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7772 index 7d6eacf..14c0240 100644
7773 --- a/arch/powerpc/include/asm/pgtable.h
7774 +++ b/arch/powerpc/include/asm/pgtable.h
7775 @@ -2,6 +2,7 @@
7776 #define _ASM_POWERPC_PGTABLE_H
7777 #ifdef __KERNEL__
7778
7779 +#include <linux/const.h>
7780 #ifndef __ASSEMBLY__
7781 #include <asm/processor.h> /* For TASK_SIZE */
7782 #include <asm/mmu.h>
7783 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7784 index 4aad413..85d86bf 100644
7785 --- a/arch/powerpc/include/asm/pte-hash32.h
7786 +++ b/arch/powerpc/include/asm/pte-hash32.h
7787 @@ -21,6 +21,7 @@
7788 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7789 #define _PAGE_USER 0x004 /* usermode access allowed */
7790 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7791 +#define _PAGE_EXEC _PAGE_GUARDED
7792 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7793 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7794 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7795 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7796 index fa8388e..f985549 100644
7797 --- a/arch/powerpc/include/asm/reg.h
7798 +++ b/arch/powerpc/include/asm/reg.h
7799 @@ -239,6 +239,7 @@
7800 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7801 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7802 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7803 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7804 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7805 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7806 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7807 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7808 index 084e080..9415a3d 100644
7809 --- a/arch/powerpc/include/asm/smp.h
7810 +++ b/arch/powerpc/include/asm/smp.h
7811 @@ -51,7 +51,7 @@ struct smp_ops_t {
7812 int (*cpu_disable)(void);
7813 void (*cpu_die)(unsigned int nr);
7814 int (*cpu_bootable)(unsigned int nr);
7815 -};
7816 +} __no_const;
7817
7818 extern void smp_send_debugger_break(void);
7819 extern void start_secondary_resume(void);
7820 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7821 index 9854c56..7517190 100644
7822 --- a/arch/powerpc/include/asm/thread_info.h
7823 +++ b/arch/powerpc/include/asm/thread_info.h
7824 @@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
7825 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7826 TIF_NEED_RESCHED */
7827 #define TIF_32BIT 4 /* 32 bit binary */
7828 -#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7829 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7830 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7831 #define TIF_SINGLESTEP 8 /* singlestepping active */
7832 @@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
7833 #if defined(CONFIG_PPC64)
7834 #define TIF_ELF2ABI 18 /* function descriptors must die! */
7835 #endif
7836 +#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
7837 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7838 +#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7839
7840 /* as above, but as bit values */
7841 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7842 @@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
7843 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7844 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7845 #define _TIF_NOHZ (1<<TIF_NOHZ)
7846 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7847 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7848 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7849 - _TIF_NOHZ)
7850 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
7851
7852 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7853 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7854 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7855 index 9485b43..4718d50 100644
7856 --- a/arch/powerpc/include/asm/uaccess.h
7857 +++ b/arch/powerpc/include/asm/uaccess.h
7858 @@ -318,52 +318,6 @@ do { \
7859 extern unsigned long __copy_tofrom_user(void __user *to,
7860 const void __user *from, unsigned long size);
7861
7862 -#ifndef __powerpc64__
7863 -
7864 -static inline unsigned long copy_from_user(void *to,
7865 - const void __user *from, unsigned long n)
7866 -{
7867 - unsigned long over;
7868 -
7869 - if (access_ok(VERIFY_READ, from, n))
7870 - return __copy_tofrom_user((__force void __user *)to, from, n);
7871 - if ((unsigned long)from < TASK_SIZE) {
7872 - over = (unsigned long)from + n - TASK_SIZE;
7873 - return __copy_tofrom_user((__force void __user *)to, from,
7874 - n - over) + over;
7875 - }
7876 - return n;
7877 -}
7878 -
7879 -static inline unsigned long copy_to_user(void __user *to,
7880 - const void *from, unsigned long n)
7881 -{
7882 - unsigned long over;
7883 -
7884 - if (access_ok(VERIFY_WRITE, to, n))
7885 - return __copy_tofrom_user(to, (__force void __user *)from, n);
7886 - if ((unsigned long)to < TASK_SIZE) {
7887 - over = (unsigned long)to + n - TASK_SIZE;
7888 - return __copy_tofrom_user(to, (__force void __user *)from,
7889 - n - over) + over;
7890 - }
7891 - return n;
7892 -}
7893 -
7894 -#else /* __powerpc64__ */
7895 -
7896 -#define __copy_in_user(to, from, size) \
7897 - __copy_tofrom_user((to), (from), (size))
7898 -
7899 -extern unsigned long copy_from_user(void *to, const void __user *from,
7900 - unsigned long n);
7901 -extern unsigned long copy_to_user(void __user *to, const void *from,
7902 - unsigned long n);
7903 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
7904 - unsigned long n);
7905 -
7906 -#endif /* __powerpc64__ */
7907 -
7908 static inline unsigned long __copy_from_user_inatomic(void *to,
7909 const void __user *from, unsigned long n)
7910 {
7911 @@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7912 if (ret == 0)
7913 return 0;
7914 }
7915 +
7916 + if (!__builtin_constant_p(n))
7917 + check_object_size(to, n, false);
7918 +
7919 return __copy_tofrom_user((__force void __user *)to, from, n);
7920 }
7921
7922 @@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7923 if (ret == 0)
7924 return 0;
7925 }
7926 +
7927 + if (!__builtin_constant_p(n))
7928 + check_object_size(from, n, true);
7929 +
7930 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7931 }
7932
7933 @@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7934 return __copy_to_user_inatomic(to, from, size);
7935 }
7936
7937 +#ifndef __powerpc64__
7938 +
7939 +static inline unsigned long __must_check copy_from_user(void *to,
7940 + const void __user *from, unsigned long n)
7941 +{
7942 + unsigned long over;
7943 +
7944 + if ((long)n < 0)
7945 + return n;
7946 +
7947 + if (access_ok(VERIFY_READ, from, n)) {
7948 + if (!__builtin_constant_p(n))
7949 + check_object_size(to, n, false);
7950 + return __copy_tofrom_user((__force void __user *)to, from, n);
7951 + }
7952 + if ((unsigned long)from < TASK_SIZE) {
7953 + over = (unsigned long)from + n - TASK_SIZE;
7954 + if (!__builtin_constant_p(n - over))
7955 + check_object_size(to, n - over, false);
7956 + return __copy_tofrom_user((__force void __user *)to, from,
7957 + n - over) + over;
7958 + }
7959 + return n;
7960 +}
7961 +
7962 +static inline unsigned long __must_check copy_to_user(void __user *to,
7963 + const void *from, unsigned long n)
7964 +{
7965 + unsigned long over;
7966 +
7967 + if ((long)n < 0)
7968 + return n;
7969 +
7970 + if (access_ok(VERIFY_WRITE, to, n)) {
7971 + if (!__builtin_constant_p(n))
7972 + check_object_size(from, n, true);
7973 + return __copy_tofrom_user(to, (__force void __user *)from, n);
7974 + }
7975 + if ((unsigned long)to < TASK_SIZE) {
7976 + over = (unsigned long)to + n - TASK_SIZE;
7977 + if (!__builtin_constant_p(n))
7978 + check_object_size(from, n - over, true);
7979 + return __copy_tofrom_user(to, (__force void __user *)from,
7980 + n - over) + over;
7981 + }
7982 + return n;
7983 +}
7984 +
7985 +#else /* __powerpc64__ */
7986 +
7987 +#define __copy_in_user(to, from, size) \
7988 + __copy_tofrom_user((to), (from), (size))
7989 +
7990 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7991 +{
7992 + if ((long)n < 0 || n > INT_MAX)
7993 + return n;
7994 +
7995 + if (!__builtin_constant_p(n))
7996 + check_object_size(to, n, false);
7997 +
7998 + if (likely(access_ok(VERIFY_READ, from, n)))
7999 + n = __copy_from_user(to, from, n);
8000 + else
8001 + memset(to, 0, n);
8002 + return n;
8003 +}
8004 +
8005 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8006 +{
8007 + if ((long)n < 0 || n > INT_MAX)
8008 + return n;
8009 +
8010 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8011 + if (!__builtin_constant_p(n))
8012 + check_object_size(from, n, true);
8013 + n = __copy_to_user(to, from, n);
8014 + }
8015 + return n;
8016 +}
8017 +
8018 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8019 + unsigned long n);
8020 +
8021 +#endif /* __powerpc64__ */
8022 +
8023 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8024
8025 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8026 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8027 index e775156..af2d1c0 100644
8028 --- a/arch/powerpc/kernel/exceptions-64e.S
8029 +++ b/arch/powerpc/kernel/exceptions-64e.S
8030 @@ -759,6 +759,7 @@ storage_fault_common:
8031 std r14,_DAR(r1)
8032 std r15,_DSISR(r1)
8033 addi r3,r1,STACK_FRAME_OVERHEAD
8034 + bl .save_nvgprs
8035 mr r4,r14
8036 mr r5,r15
8037 ld r14,PACA_EXGEN+EX_R14(r13)
8038 @@ -767,8 +768,7 @@ storage_fault_common:
8039 cmpdi r3,0
8040 bne- 1f
8041 b .ret_from_except_lite
8042 -1: bl .save_nvgprs
8043 - mr r5,r3
8044 +1: mr r5,r3
8045 addi r3,r1,STACK_FRAME_OVERHEAD
8046 ld r4,_DAR(r1)
8047 bl .bad_page_fault
8048 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8049 index 9f905e4..1d6b3d2 100644
8050 --- a/arch/powerpc/kernel/exceptions-64s.S
8051 +++ b/arch/powerpc/kernel/exceptions-64s.S
8052 @@ -1390,10 +1390,10 @@ handle_page_fault:
8053 11: ld r4,_DAR(r1)
8054 ld r5,_DSISR(r1)
8055 addi r3,r1,STACK_FRAME_OVERHEAD
8056 + bl .save_nvgprs
8057 bl .do_page_fault
8058 cmpdi r3,0
8059 beq+ 12f
8060 - bl .save_nvgprs
8061 mr r5,r3
8062 addi r3,r1,STACK_FRAME_OVERHEAD
8063 lwz r4,_DAR(r1)
8064 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8065 index 6cff040..74ac5d1 100644
8066 --- a/arch/powerpc/kernel/module_32.c
8067 +++ b/arch/powerpc/kernel/module_32.c
8068 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8069 me->arch.core_plt_section = i;
8070 }
8071 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8072 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8073 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8074 return -ENOEXEC;
8075 }
8076
8077 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8078
8079 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8080 /* Init, or core PLT? */
8081 - if (location >= mod->module_core
8082 - && location < mod->module_core + mod->core_size)
8083 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8084 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8085 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8086 - else
8087 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8088 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8089 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8090 + else {
8091 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8092 + return ~0UL;
8093 + }
8094
8095 /* Find this entry, or if that fails, the next avail. entry */
8096 while (entry->jump[0]) {
8097 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8098 }
8099 #ifdef CONFIG_DYNAMIC_FTRACE
8100 module->arch.tramp =
8101 - do_plt_call(module->module_core,
8102 + do_plt_call(module->module_core_rx,
8103 (unsigned long)ftrace_caller,
8104 sechdrs, module);
8105 #endif
8106 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8107 index 4a96556..dd95f6c 100644
8108 --- a/arch/powerpc/kernel/process.c
8109 +++ b/arch/powerpc/kernel/process.c
8110 @@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8111 * Lookup NIP late so we have the best change of getting the
8112 * above info out without failing
8113 */
8114 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8115 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8116 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8117 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8118 #endif
8119 show_stack(current, (unsigned long *) regs->gpr[1]);
8120 if (!user_mode(regs))
8121 @@ -1376,10 +1376,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8122 newsp = stack[0];
8123 ip = stack[STACK_FRAME_LR_SAVE];
8124 if (!firstframe || ip != lr) {
8125 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8126 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8127 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8128 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8129 - printk(" (%pS)",
8130 + printk(" (%pA)",
8131 (void *)current->ret_stack[curr_frame].ret);
8132 curr_frame--;
8133 }
8134 @@ -1399,7 +1399,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8135 struct pt_regs *regs = (struct pt_regs *)
8136 (sp + STACK_FRAME_OVERHEAD);
8137 lr = regs->link;
8138 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8139 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8140 regs->trap, (void *)regs->nip, (void *)lr);
8141 firstframe = 1;
8142 }
8143 @@ -1435,58 +1435,3 @@ void notrace __ppc64_runlatch_off(void)
8144 mtspr(SPRN_CTRLT, ctrl);
8145 }
8146 #endif /* CONFIG_PPC64 */
8147 -
8148 -unsigned long arch_align_stack(unsigned long sp)
8149 -{
8150 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8151 - sp -= get_random_int() & ~PAGE_MASK;
8152 - return sp & ~0xf;
8153 -}
8154 -
8155 -static inline unsigned long brk_rnd(void)
8156 -{
8157 - unsigned long rnd = 0;
8158 -
8159 - /* 8MB for 32bit, 1GB for 64bit */
8160 - if (is_32bit_task())
8161 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8162 - else
8163 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8164 -
8165 - return rnd << PAGE_SHIFT;
8166 -}
8167 -
8168 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8169 -{
8170 - unsigned long base = mm->brk;
8171 - unsigned long ret;
8172 -
8173 -#ifdef CONFIG_PPC_STD_MMU_64
8174 - /*
8175 - * If we are using 1TB segments and we are allowed to randomise
8176 - * the heap, we can put it above 1TB so it is backed by a 1TB
8177 - * segment. Otherwise the heap will be in the bottom 1TB
8178 - * which always uses 256MB segments and this may result in a
8179 - * performance penalty.
8180 - */
8181 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8182 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8183 -#endif
8184 -
8185 - ret = PAGE_ALIGN(base + brk_rnd());
8186 -
8187 - if (ret < mm->brk)
8188 - return mm->brk;
8189 -
8190 - return ret;
8191 -}
8192 -
8193 -unsigned long randomize_et_dyn(unsigned long base)
8194 -{
8195 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8196 -
8197 - if (ret < base)
8198 - return base;
8199 -
8200 - return ret;
8201 -}
8202 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8203 index 2e3d2bf..35df241 100644
8204 --- a/arch/powerpc/kernel/ptrace.c
8205 +++ b/arch/powerpc/kernel/ptrace.c
8206 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8207 return ret;
8208 }
8209
8210 +#ifdef CONFIG_GRKERNSEC_SETXID
8211 +extern void gr_delayed_cred_worker(void);
8212 +#endif
8213 +
8214 /*
8215 * We must return the syscall number to actually look up in the table.
8216 * This can be -1L to skip running any syscall at all.
8217 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8218
8219 secure_computing_strict(regs->gpr[0]);
8220
8221 +#ifdef CONFIG_GRKERNSEC_SETXID
8222 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8223 + gr_delayed_cred_worker();
8224 +#endif
8225 +
8226 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8227 tracehook_report_syscall_entry(regs))
8228 /*
8229 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8230 {
8231 int step;
8232
8233 +#ifdef CONFIG_GRKERNSEC_SETXID
8234 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8235 + gr_delayed_cred_worker();
8236 +#endif
8237 +
8238 audit_syscall_exit(regs);
8239
8240 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8241 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8242 index 68027bf..b26fd31 100644
8243 --- a/arch/powerpc/kernel/signal_32.c
8244 +++ b/arch/powerpc/kernel/signal_32.c
8245 @@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8246 /* Save user registers on the stack */
8247 frame = &rt_sf->uc.uc_mcontext;
8248 addr = frame;
8249 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8250 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8251 sigret = 0;
8252 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8253 } else {
8254 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8255 index 4299104..29e2c51 100644
8256 --- a/arch/powerpc/kernel/signal_64.c
8257 +++ b/arch/powerpc/kernel/signal_64.c
8258 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8259 #endif
8260
8261 /* Set up to return from userspace. */
8262 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8263 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8264 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8265 } else {
8266 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8267 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8268 index 907a472..4ba206f 100644
8269 --- a/arch/powerpc/kernel/traps.c
8270 +++ b/arch/powerpc/kernel/traps.c
8271 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8272 return flags;
8273 }
8274
8275 +extern void gr_handle_kernel_exploit(void);
8276 +
8277 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8278 int signr)
8279 {
8280 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8281 panic("Fatal exception in interrupt");
8282 if (panic_on_oops)
8283 panic("Fatal exception");
8284 +
8285 + gr_handle_kernel_exploit();
8286 +
8287 do_exit(signr);
8288 }
8289
8290 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8291 index 094e45c..d82b848 100644
8292 --- a/arch/powerpc/kernel/vdso.c
8293 +++ b/arch/powerpc/kernel/vdso.c
8294 @@ -35,6 +35,7 @@
8295 #include <asm/vdso.h>
8296 #include <asm/vdso_datapage.h>
8297 #include <asm/setup.h>
8298 +#include <asm/mman.h>
8299
8300 #undef DEBUG
8301
8302 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8303 vdso_base = VDSO32_MBASE;
8304 #endif
8305
8306 - current->mm->context.vdso_base = 0;
8307 + current->mm->context.vdso_base = ~0UL;
8308
8309 /* vDSO has a problem and was disabled, just don't "enable" it for the
8310 * process
8311 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8312 vdso_base = get_unmapped_area(NULL, vdso_base,
8313 (vdso_pages << PAGE_SHIFT) +
8314 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8315 - 0, 0);
8316 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8317 if (IS_ERR_VALUE(vdso_base)) {
8318 rc = vdso_base;
8319 goto fail_mmapsem;
8320 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8321 index 5eea6f3..5d10396 100644
8322 --- a/arch/powerpc/lib/usercopy_64.c
8323 +++ b/arch/powerpc/lib/usercopy_64.c
8324 @@ -9,22 +9,6 @@
8325 #include <linux/module.h>
8326 #include <asm/uaccess.h>
8327
8328 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8329 -{
8330 - if (likely(access_ok(VERIFY_READ, from, n)))
8331 - n = __copy_from_user(to, from, n);
8332 - else
8333 - memset(to, 0, n);
8334 - return n;
8335 -}
8336 -
8337 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8338 -{
8339 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8340 - n = __copy_to_user(to, from, n);
8341 - return n;
8342 -}
8343 -
8344 unsigned long copy_in_user(void __user *to, const void __user *from,
8345 unsigned long n)
8346 {
8347 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8348 return n;
8349 }
8350
8351 -EXPORT_SYMBOL(copy_from_user);
8352 -EXPORT_SYMBOL(copy_to_user);
8353 EXPORT_SYMBOL(copy_in_user);
8354
8355 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8356 index 51ab9e7..7d3c78b 100644
8357 --- a/arch/powerpc/mm/fault.c
8358 +++ b/arch/powerpc/mm/fault.c
8359 @@ -33,6 +33,10 @@
8360 #include <linux/magic.h>
8361 #include <linux/ratelimit.h>
8362 #include <linux/context_tracking.h>
8363 +#include <linux/slab.h>
8364 +#include <linux/pagemap.h>
8365 +#include <linux/compiler.h>
8366 +#include <linux/unistd.h>
8367
8368 #include <asm/firmware.h>
8369 #include <asm/page.h>
8370 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8371 }
8372 #endif
8373
8374 +#ifdef CONFIG_PAX_PAGEEXEC
8375 +/*
8376 + * PaX: decide what to do with offenders (regs->nip = fault address)
8377 + *
8378 + * returns 1 when task should be killed
8379 + */
8380 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8381 +{
8382 + return 1;
8383 +}
8384 +
8385 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8386 +{
8387 + unsigned long i;
8388 +
8389 + printk(KERN_ERR "PAX: bytes at PC: ");
8390 + for (i = 0; i < 5; i++) {
8391 + unsigned int c;
8392 + if (get_user(c, (unsigned int __user *)pc+i))
8393 + printk(KERN_CONT "???????? ");
8394 + else
8395 + printk(KERN_CONT "%08x ", c);
8396 + }
8397 + printk("\n");
8398 +}
8399 +#endif
8400 +
8401 /*
8402 * Check whether the instruction at regs->nip is a store using
8403 * an update addressing form which will update r1.
8404 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8405 * indicate errors in DSISR but can validly be set in SRR1.
8406 */
8407 if (trap == 0x400)
8408 - error_code &= 0x48200000;
8409 + error_code &= 0x58200000;
8410 else
8411 is_write = error_code & DSISR_ISSTORE;
8412 #else
8413 @@ -378,7 +409,7 @@ good_area:
8414 * "undefined". Of those that can be set, this is the only
8415 * one which seems bad.
8416 */
8417 - if (error_code & 0x10000000)
8418 + if (error_code & DSISR_GUARDED)
8419 /* Guarded storage error. */
8420 goto bad_area;
8421 #endif /* CONFIG_8xx */
8422 @@ -393,7 +424,7 @@ good_area:
8423 * processors use the same I/D cache coherency mechanism
8424 * as embedded.
8425 */
8426 - if (error_code & DSISR_PROTFAULT)
8427 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8428 goto bad_area;
8429 #endif /* CONFIG_PPC_STD_MMU */
8430
8431 @@ -483,6 +514,23 @@ bad_area:
8432 bad_area_nosemaphore:
8433 /* User mode accesses cause a SIGSEGV */
8434 if (user_mode(regs)) {
8435 +
8436 +#ifdef CONFIG_PAX_PAGEEXEC
8437 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8438 +#ifdef CONFIG_PPC_STD_MMU
8439 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8440 +#else
8441 + if (is_exec && regs->nip == address) {
8442 +#endif
8443 + switch (pax_handle_fetch_fault(regs)) {
8444 + }
8445 +
8446 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8447 + do_group_exit(SIGKILL);
8448 + }
8449 + }
8450 +#endif
8451 +
8452 _exception(SIGSEGV, regs, code, address);
8453 goto bail;
8454 }
8455 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8456 index cb8bdbe..d770680 100644
8457 --- a/arch/powerpc/mm/mmap.c
8458 +++ b/arch/powerpc/mm/mmap.c
8459 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8460 {
8461 unsigned long rnd = 0;
8462
8463 +#ifdef CONFIG_PAX_RANDMMAP
8464 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8465 +#endif
8466 +
8467 if (current->flags & PF_RANDOMIZE) {
8468 /* 8MB for 32bit, 1GB for 64bit */
8469 if (is_32bit_task())
8470 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8471 */
8472 if (mmap_is_legacy()) {
8473 mm->mmap_base = TASK_UNMAPPED_BASE;
8474 +
8475 +#ifdef CONFIG_PAX_RANDMMAP
8476 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8477 + mm->mmap_base += mm->delta_mmap;
8478 +#endif
8479 +
8480 mm->get_unmapped_area = arch_get_unmapped_area;
8481 } else {
8482 mm->mmap_base = mmap_base();
8483 +
8484 +#ifdef CONFIG_PAX_RANDMMAP
8485 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8486 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8487 +#endif
8488 +
8489 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8490 }
8491 }
8492 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8493 index 7ce9cf3..a964087 100644
8494 --- a/arch/powerpc/mm/slice.c
8495 +++ b/arch/powerpc/mm/slice.c
8496 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8497 if ((mm->task_size - len) < addr)
8498 return 0;
8499 vma = find_vma(mm, addr);
8500 - return (!vma || (addr + len) <= vma->vm_start);
8501 + return check_heap_stack_gap(vma, addr, len, 0);
8502 }
8503
8504 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8505 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8506 info.align_offset = 0;
8507
8508 addr = TASK_UNMAPPED_BASE;
8509 +
8510 +#ifdef CONFIG_PAX_RANDMMAP
8511 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8512 + addr += mm->delta_mmap;
8513 +#endif
8514 +
8515 while (addr < TASK_SIZE) {
8516 info.low_limit = addr;
8517 if (!slice_scan_available(addr, available, 1, &addr))
8518 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8519 if (fixed && addr > (mm->task_size - len))
8520 return -EINVAL;
8521
8522 +#ifdef CONFIG_PAX_RANDMMAP
8523 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8524 + addr = 0;
8525 +#endif
8526 +
8527 /* If hint, make sure it matches our alignment restrictions */
8528 if (!fixed && addr) {
8529 addr = _ALIGN_UP(addr, 1ul << pshift);
8530 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8531 index 9098692..3d54cd1 100644
8532 --- a/arch/powerpc/platforms/cell/spufs/file.c
8533 +++ b/arch/powerpc/platforms/cell/spufs/file.c
8534 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8535 return VM_FAULT_NOPAGE;
8536 }
8537
8538 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8539 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8540 unsigned long address,
8541 - void *buf, int len, int write)
8542 + void *buf, size_t len, int write)
8543 {
8544 struct spu_context *ctx = vma->vm_file->private_data;
8545 unsigned long offset = address - vma->vm_start;
8546 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8547 index fa9aaf7..3f5d836 100644
8548 --- a/arch/s390/include/asm/atomic.h
8549 +++ b/arch/s390/include/asm/atomic.h
8550 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8551 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8552 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8553
8554 +#define atomic64_read_unchecked(v) atomic64_read(v)
8555 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8556 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8557 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8558 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8559 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8560 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8561 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8562 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8563 +
8564 #define smp_mb__before_atomic_dec() smp_mb()
8565 #define smp_mb__after_atomic_dec() smp_mb()
8566 #define smp_mb__before_atomic_inc() smp_mb()
8567 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8568 index 4d7ccac..d03d0ad 100644
8569 --- a/arch/s390/include/asm/cache.h
8570 +++ b/arch/s390/include/asm/cache.h
8571 @@ -9,8 +9,10 @@
8572 #ifndef __ARCH_S390_CACHE_H
8573 #define __ARCH_S390_CACHE_H
8574
8575 -#define L1_CACHE_BYTES 256
8576 +#include <linux/const.h>
8577 +
8578 #define L1_CACHE_SHIFT 8
8579 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8580 #define NET_SKB_PAD 32
8581
8582 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8583 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8584 index 78f4f87..598ce39 100644
8585 --- a/arch/s390/include/asm/elf.h
8586 +++ b/arch/s390/include/asm/elf.h
8587 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8588 the loader. We need to make sure that it is out of the way of the program
8589 that it will "exec", and that there is sufficient room for the brk. */
8590
8591 -extern unsigned long randomize_et_dyn(unsigned long base);
8592 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8593 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8594 +
8595 +#ifdef CONFIG_PAX_ASLR
8596 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8597 +
8598 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8599 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8600 +#endif
8601
8602 /* This yields a mask that user programs can use to figure out what
8603 instruction set this CPU supports. */
8604 @@ -222,9 +228,6 @@ struct linux_binprm;
8605 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8606 int arch_setup_additional_pages(struct linux_binprm *, int);
8607
8608 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8609 -#define arch_randomize_brk arch_randomize_brk
8610 -
8611 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8612
8613 #endif
8614 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8615 index c4a93d6..4d2a9b4 100644
8616 --- a/arch/s390/include/asm/exec.h
8617 +++ b/arch/s390/include/asm/exec.h
8618 @@ -7,6 +7,6 @@
8619 #ifndef __ASM_EXEC_H
8620 #define __ASM_EXEC_H
8621
8622 -extern unsigned long arch_align_stack(unsigned long sp);
8623 +#define arch_align_stack(x) ((x) & ~0xfUL)
8624
8625 #endif /* __ASM_EXEC_H */
8626 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8627 index 79330af..a3a7b06 100644
8628 --- a/arch/s390/include/asm/uaccess.h
8629 +++ b/arch/s390/include/asm/uaccess.h
8630 @@ -245,6 +245,10 @@ static inline unsigned long __must_check
8631 copy_to_user(void __user *to, const void *from, unsigned long n)
8632 {
8633 might_fault();
8634 +
8635 + if ((long)n < 0)
8636 + return n;
8637 +
8638 return __copy_to_user(to, from, n);
8639 }
8640
8641 @@ -268,6 +272,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8642 static inline unsigned long __must_check
8643 __copy_from_user(void *to, const void __user *from, unsigned long n)
8644 {
8645 + if ((long)n < 0)
8646 + return n;
8647 +
8648 return uaccess.copy_from_user(n, from, to);
8649 }
8650
8651 @@ -296,10 +303,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8652 static inline unsigned long __must_check
8653 copy_from_user(void *to, const void __user *from, unsigned long n)
8654 {
8655 - unsigned int sz = __compiletime_object_size(to);
8656 + size_t sz = __compiletime_object_size(to);
8657
8658 might_fault();
8659 - if (unlikely(sz != -1 && sz < n)) {
8660 +
8661 + if ((long)n < 0)
8662 + return n;
8663 +
8664 + if (unlikely(sz != (size_t)-1 && sz < n)) {
8665 copy_from_user_overflow();
8666 return n;
8667 }
8668 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8669 index b89b591..fd9609d 100644
8670 --- a/arch/s390/kernel/module.c
8671 +++ b/arch/s390/kernel/module.c
8672 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8673
8674 /* Increase core size by size of got & plt and set start
8675 offsets for got and plt. */
8676 - me->core_size = ALIGN(me->core_size, 4);
8677 - me->arch.got_offset = me->core_size;
8678 - me->core_size += me->arch.got_size;
8679 - me->arch.plt_offset = me->core_size;
8680 - me->core_size += me->arch.plt_size;
8681 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
8682 + me->arch.got_offset = me->core_size_rw;
8683 + me->core_size_rw += me->arch.got_size;
8684 + me->arch.plt_offset = me->core_size_rx;
8685 + me->core_size_rx += me->arch.plt_size;
8686 return 0;
8687 }
8688
8689 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8690 if (info->got_initialized == 0) {
8691 Elf_Addr *gotent;
8692
8693 - gotent = me->module_core + me->arch.got_offset +
8694 + gotent = me->module_core_rw + me->arch.got_offset +
8695 info->got_offset;
8696 *gotent = val;
8697 info->got_initialized = 1;
8698 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8699 rc = apply_rela_bits(loc, val, 0, 64, 0);
8700 else if (r_type == R_390_GOTENT ||
8701 r_type == R_390_GOTPLTENT) {
8702 - val += (Elf_Addr) me->module_core - loc;
8703 + val += (Elf_Addr) me->module_core_rw - loc;
8704 rc = apply_rela_bits(loc, val, 1, 32, 1);
8705 }
8706 break;
8707 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8708 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8709 if (info->plt_initialized == 0) {
8710 unsigned int *ip;
8711 - ip = me->module_core + me->arch.plt_offset +
8712 + ip = me->module_core_rx + me->arch.plt_offset +
8713 info->plt_offset;
8714 #ifndef CONFIG_64BIT
8715 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8716 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8717 val - loc + 0xffffUL < 0x1ffffeUL) ||
8718 (r_type == R_390_PLT32DBL &&
8719 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8720 - val = (Elf_Addr) me->module_core +
8721 + val = (Elf_Addr) me->module_core_rx +
8722 me->arch.plt_offset +
8723 info->plt_offset;
8724 val += rela->r_addend - loc;
8725 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8726 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8727 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8728 val = val + rela->r_addend -
8729 - ((Elf_Addr) me->module_core + me->arch.got_offset);
8730 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8731 if (r_type == R_390_GOTOFF16)
8732 rc = apply_rela_bits(loc, val, 0, 16, 0);
8733 else if (r_type == R_390_GOTOFF32)
8734 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8735 break;
8736 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8737 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8738 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
8739 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8740 rela->r_addend - loc;
8741 if (r_type == R_390_GOTPC)
8742 rc = apply_rela_bits(loc, val, 1, 32, 0);
8743 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8744 index 7ed0d4e..1dfc145 100644
8745 --- a/arch/s390/kernel/process.c
8746 +++ b/arch/s390/kernel/process.c
8747 @@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
8748 }
8749 return 0;
8750 }
8751 -
8752 -unsigned long arch_align_stack(unsigned long sp)
8753 -{
8754 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8755 - sp -= get_random_int() & ~PAGE_MASK;
8756 - return sp & ~0xf;
8757 -}
8758 -
8759 -static inline unsigned long brk_rnd(void)
8760 -{
8761 - /* 8MB for 32bit, 1GB for 64bit */
8762 - if (is_32bit_task())
8763 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8764 - else
8765 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8766 -}
8767 -
8768 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8769 -{
8770 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8771 -
8772 - if (ret < mm->brk)
8773 - return mm->brk;
8774 - return ret;
8775 -}
8776 -
8777 -unsigned long randomize_et_dyn(unsigned long base)
8778 -{
8779 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8780 -
8781 - if (!(current->flags & PF_RANDOMIZE))
8782 - return base;
8783 - if (ret < base)
8784 - return base;
8785 - return ret;
8786 -}
8787 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8788 index 9b436c2..54fbf0a 100644
8789 --- a/arch/s390/mm/mmap.c
8790 +++ b/arch/s390/mm/mmap.c
8791 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8792 */
8793 if (mmap_is_legacy()) {
8794 mm->mmap_base = mmap_base_legacy();
8795 +
8796 +#ifdef CONFIG_PAX_RANDMMAP
8797 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8798 + mm->mmap_base += mm->delta_mmap;
8799 +#endif
8800 +
8801 mm->get_unmapped_area = arch_get_unmapped_area;
8802 } else {
8803 mm->mmap_base = mmap_base();
8804 +
8805 +#ifdef CONFIG_PAX_RANDMMAP
8806 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8807 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8808 +#endif
8809 +
8810 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8811 }
8812 }
8813 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8814 */
8815 if (mmap_is_legacy()) {
8816 mm->mmap_base = mmap_base_legacy();
8817 +
8818 +#ifdef CONFIG_PAX_RANDMMAP
8819 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8820 + mm->mmap_base += mm->delta_mmap;
8821 +#endif
8822 +
8823 mm->get_unmapped_area = s390_get_unmapped_area;
8824 } else {
8825 mm->mmap_base = mmap_base();
8826 +
8827 +#ifdef CONFIG_PAX_RANDMMAP
8828 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8829 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8830 +#endif
8831 +
8832 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8833 }
8834 }
8835 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8836 index ae3d59f..f65f075 100644
8837 --- a/arch/score/include/asm/cache.h
8838 +++ b/arch/score/include/asm/cache.h
8839 @@ -1,7 +1,9 @@
8840 #ifndef _ASM_SCORE_CACHE_H
8841 #define _ASM_SCORE_CACHE_H
8842
8843 +#include <linux/const.h>
8844 +
8845 #define L1_CACHE_SHIFT 4
8846 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8847 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8848
8849 #endif /* _ASM_SCORE_CACHE_H */
8850 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8851 index f9f3cd5..58ff438 100644
8852 --- a/arch/score/include/asm/exec.h
8853 +++ b/arch/score/include/asm/exec.h
8854 @@ -1,6 +1,6 @@
8855 #ifndef _ASM_SCORE_EXEC_H
8856 #define _ASM_SCORE_EXEC_H
8857
8858 -extern unsigned long arch_align_stack(unsigned long sp);
8859 +#define arch_align_stack(x) (x)
8860
8861 #endif /* _ASM_SCORE_EXEC_H */
8862 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8863 index a1519ad3..e8ac1ff 100644
8864 --- a/arch/score/kernel/process.c
8865 +++ b/arch/score/kernel/process.c
8866 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8867
8868 return task_pt_regs(task)->cp0_epc;
8869 }
8870 -
8871 -unsigned long arch_align_stack(unsigned long sp)
8872 -{
8873 - return sp;
8874 -}
8875 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8876 index ef9e555..331bd29 100644
8877 --- a/arch/sh/include/asm/cache.h
8878 +++ b/arch/sh/include/asm/cache.h
8879 @@ -9,10 +9,11 @@
8880 #define __ASM_SH_CACHE_H
8881 #ifdef __KERNEL__
8882
8883 +#include <linux/const.h>
8884 #include <linux/init.h>
8885 #include <cpu/cache.h>
8886
8887 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8888 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8889
8890 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8891
8892 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8893 index 6777177..cb5e44f 100644
8894 --- a/arch/sh/mm/mmap.c
8895 +++ b/arch/sh/mm/mmap.c
8896 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8897 struct mm_struct *mm = current->mm;
8898 struct vm_area_struct *vma;
8899 int do_colour_align;
8900 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8901 struct vm_unmapped_area_info info;
8902
8903 if (flags & MAP_FIXED) {
8904 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8905 if (filp || (flags & MAP_SHARED))
8906 do_colour_align = 1;
8907
8908 +#ifdef CONFIG_PAX_RANDMMAP
8909 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8910 +#endif
8911 +
8912 if (addr) {
8913 if (do_colour_align)
8914 addr = COLOUR_ALIGN(addr, pgoff);
8915 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8916 addr = PAGE_ALIGN(addr);
8917
8918 vma = find_vma(mm, addr);
8919 - if (TASK_SIZE - len >= addr &&
8920 - (!vma || addr + len <= vma->vm_start))
8921 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8922 return addr;
8923 }
8924
8925 info.flags = 0;
8926 info.length = len;
8927 - info.low_limit = TASK_UNMAPPED_BASE;
8928 + info.low_limit = mm->mmap_base;
8929 info.high_limit = TASK_SIZE;
8930 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8931 info.align_offset = pgoff << PAGE_SHIFT;
8932 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8933 struct mm_struct *mm = current->mm;
8934 unsigned long addr = addr0;
8935 int do_colour_align;
8936 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8937 struct vm_unmapped_area_info info;
8938
8939 if (flags & MAP_FIXED) {
8940 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8941 if (filp || (flags & MAP_SHARED))
8942 do_colour_align = 1;
8943
8944 +#ifdef CONFIG_PAX_RANDMMAP
8945 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8946 +#endif
8947 +
8948 /* requesting a specific address */
8949 if (addr) {
8950 if (do_colour_align)
8951 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8952 addr = PAGE_ALIGN(addr);
8953
8954 vma = find_vma(mm, addr);
8955 - if (TASK_SIZE - len >= addr &&
8956 - (!vma || addr + len <= vma->vm_start))
8957 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8958 return addr;
8959 }
8960
8961 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8962 VM_BUG_ON(addr != -ENOMEM);
8963 info.flags = 0;
8964 info.low_limit = TASK_UNMAPPED_BASE;
8965 +
8966 +#ifdef CONFIG_PAX_RANDMMAP
8967 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8968 + info.low_limit += mm->delta_mmap;
8969 +#endif
8970 +
8971 info.high_limit = TASK_SIZE;
8972 addr = vm_unmapped_area(&info);
8973 }
8974 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8975 index be56a24..443328f 100644
8976 --- a/arch/sparc/include/asm/atomic_64.h
8977 +++ b/arch/sparc/include/asm/atomic_64.h
8978 @@ -14,18 +14,40 @@
8979 #define ATOMIC64_INIT(i) { (i) }
8980
8981 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8982 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8983 +{
8984 + return v->counter;
8985 +}
8986 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8987 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8988 +{
8989 + return v->counter;
8990 +}
8991
8992 #define atomic_set(v, i) (((v)->counter) = i)
8993 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8994 +{
8995 + v->counter = i;
8996 +}
8997 #define atomic64_set(v, i) (((v)->counter) = i)
8998 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8999 +{
9000 + v->counter = i;
9001 +}
9002
9003 extern void atomic_add(int, atomic_t *);
9004 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9005 extern void atomic64_add(long, atomic64_t *);
9006 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9007 extern void atomic_sub(int, atomic_t *);
9008 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9009 extern void atomic64_sub(long, atomic64_t *);
9010 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9011
9012 extern int atomic_add_ret(int, atomic_t *);
9013 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9014 extern long atomic64_add_ret(long, atomic64_t *);
9015 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9016 extern int atomic_sub_ret(int, atomic_t *);
9017 extern long atomic64_sub_ret(long, atomic64_t *);
9018
9019 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9020 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9021
9022 #define atomic_inc_return(v) atomic_add_ret(1, v)
9023 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9024 +{
9025 + return atomic_add_ret_unchecked(1, v);
9026 +}
9027 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9028 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9029 +{
9030 + return atomic64_add_ret_unchecked(1, v);
9031 +}
9032
9033 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9034 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9035
9036 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9037 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9038 +{
9039 + return atomic_add_ret_unchecked(i, v);
9040 +}
9041 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9042 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9043 +{
9044 + return atomic64_add_ret_unchecked(i, v);
9045 +}
9046
9047 /*
9048 * atomic_inc_and_test - increment and test
9049 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9050 * other cases.
9051 */
9052 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9053 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9054 +{
9055 + return atomic_inc_return_unchecked(v) == 0;
9056 +}
9057 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9058
9059 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9060 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9061 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9062
9063 #define atomic_inc(v) atomic_add(1, v)
9064 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9065 +{
9066 + atomic_add_unchecked(1, v);
9067 +}
9068 #define atomic64_inc(v) atomic64_add(1, v)
9069 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9070 +{
9071 + atomic64_add_unchecked(1, v);
9072 +}
9073
9074 #define atomic_dec(v) atomic_sub(1, v)
9075 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9076 +{
9077 + atomic_sub_unchecked(1, v);
9078 +}
9079 #define atomic64_dec(v) atomic64_sub(1, v)
9080 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9081 +{
9082 + atomic64_sub_unchecked(1, v);
9083 +}
9084
9085 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9086 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9087
9088 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9089 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9090 +{
9091 + return cmpxchg(&v->counter, old, new);
9092 +}
9093 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9094 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9095 +{
9096 + return xchg(&v->counter, new);
9097 +}
9098
9099 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9100 {
9101 - int c, old;
9102 + int c, old, new;
9103 c = atomic_read(v);
9104 for (;;) {
9105 - if (unlikely(c == (u)))
9106 + if (unlikely(c == u))
9107 break;
9108 - old = atomic_cmpxchg((v), c, c + (a));
9109 +
9110 + asm volatile("addcc %2, %0, %0\n"
9111 +
9112 +#ifdef CONFIG_PAX_REFCOUNT
9113 + "tvs %%icc, 6\n"
9114 +#endif
9115 +
9116 + : "=r" (new)
9117 + : "0" (c), "ir" (a)
9118 + : "cc");
9119 +
9120 + old = atomic_cmpxchg(v, c, new);
9121 if (likely(old == c))
9122 break;
9123 c = old;
9124 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9125 #define atomic64_cmpxchg(v, o, n) \
9126 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9127 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9128 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9129 +{
9130 + return xchg(&v->counter, new);
9131 +}
9132
9133 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9134 {
9135 - long c, old;
9136 + long c, old, new;
9137 c = atomic64_read(v);
9138 for (;;) {
9139 - if (unlikely(c == (u)))
9140 + if (unlikely(c == u))
9141 break;
9142 - old = atomic64_cmpxchg((v), c, c + (a));
9143 +
9144 + asm volatile("addcc %2, %0, %0\n"
9145 +
9146 +#ifdef CONFIG_PAX_REFCOUNT
9147 + "tvs %%xcc, 6\n"
9148 +#endif
9149 +
9150 + : "=r" (new)
9151 + : "0" (c), "ir" (a)
9152 + : "cc");
9153 +
9154 + old = atomic64_cmpxchg(v, c, new);
9155 if (likely(old == c))
9156 break;
9157 c = old;
9158 }
9159 - return c != (u);
9160 + return c != u;
9161 }
9162
9163 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9164 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9165 index 5bb6991..5c2132e 100644
9166 --- a/arch/sparc/include/asm/cache.h
9167 +++ b/arch/sparc/include/asm/cache.h
9168 @@ -7,10 +7,12 @@
9169 #ifndef _SPARC_CACHE_H
9170 #define _SPARC_CACHE_H
9171
9172 +#include <linux/const.h>
9173 +
9174 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9175
9176 #define L1_CACHE_SHIFT 5
9177 -#define L1_CACHE_BYTES 32
9178 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9179
9180 #ifdef CONFIG_SPARC32
9181 #define SMP_CACHE_BYTES_SHIFT 5
9182 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9183 index a24e41f..47677ff 100644
9184 --- a/arch/sparc/include/asm/elf_32.h
9185 +++ b/arch/sparc/include/asm/elf_32.h
9186 @@ -114,6 +114,13 @@ typedef struct {
9187
9188 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9189
9190 +#ifdef CONFIG_PAX_ASLR
9191 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9192 +
9193 +#define PAX_DELTA_MMAP_LEN 16
9194 +#define PAX_DELTA_STACK_LEN 16
9195 +#endif
9196 +
9197 /* This yields a mask that user programs can use to figure out what
9198 instruction set this cpu supports. This can NOT be done in userspace
9199 on Sparc. */
9200 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9201 index 370ca1e..d4f4a98 100644
9202 --- a/arch/sparc/include/asm/elf_64.h
9203 +++ b/arch/sparc/include/asm/elf_64.h
9204 @@ -189,6 +189,13 @@ typedef struct {
9205 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9206 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9207
9208 +#ifdef CONFIG_PAX_ASLR
9209 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9210 +
9211 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9212 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9213 +#endif
9214 +
9215 extern unsigned long sparc64_elf_hwcap;
9216 #define ELF_HWCAP sparc64_elf_hwcap
9217
9218 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9219 index 9b1c36d..209298b 100644
9220 --- a/arch/sparc/include/asm/pgalloc_32.h
9221 +++ b/arch/sparc/include/asm/pgalloc_32.h
9222 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9223 }
9224
9225 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9226 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9227
9228 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9229 unsigned long address)
9230 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9231 index bcfe063..b333142 100644
9232 --- a/arch/sparc/include/asm/pgalloc_64.h
9233 +++ b/arch/sparc/include/asm/pgalloc_64.h
9234 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9235 }
9236
9237 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9238 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9239
9240 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9241 {
9242 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9243 index 502f632..da1917f 100644
9244 --- a/arch/sparc/include/asm/pgtable_32.h
9245 +++ b/arch/sparc/include/asm/pgtable_32.h
9246 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9247 #define PAGE_SHARED SRMMU_PAGE_SHARED
9248 #define PAGE_COPY SRMMU_PAGE_COPY
9249 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9250 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9251 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9252 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9253 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9254
9255 /* Top-level page directory - dummy used by init-mm.
9256 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9257
9258 /* xwr */
9259 #define __P000 PAGE_NONE
9260 -#define __P001 PAGE_READONLY
9261 -#define __P010 PAGE_COPY
9262 -#define __P011 PAGE_COPY
9263 +#define __P001 PAGE_READONLY_NOEXEC
9264 +#define __P010 PAGE_COPY_NOEXEC
9265 +#define __P011 PAGE_COPY_NOEXEC
9266 #define __P100 PAGE_READONLY
9267 #define __P101 PAGE_READONLY
9268 #define __P110 PAGE_COPY
9269 #define __P111 PAGE_COPY
9270
9271 #define __S000 PAGE_NONE
9272 -#define __S001 PAGE_READONLY
9273 -#define __S010 PAGE_SHARED
9274 -#define __S011 PAGE_SHARED
9275 +#define __S001 PAGE_READONLY_NOEXEC
9276 +#define __S010 PAGE_SHARED_NOEXEC
9277 +#define __S011 PAGE_SHARED_NOEXEC
9278 #define __S100 PAGE_READONLY
9279 #define __S101 PAGE_READONLY
9280 #define __S110 PAGE_SHARED
9281 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9282 index 79da178..c2eede8 100644
9283 --- a/arch/sparc/include/asm/pgtsrmmu.h
9284 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9285 @@ -115,6 +115,11 @@
9286 SRMMU_EXEC | SRMMU_REF)
9287 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9288 SRMMU_EXEC | SRMMU_REF)
9289 +
9290 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9291 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9292 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9293 +
9294 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9295 SRMMU_DIRTY | SRMMU_REF)
9296
9297 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9298 index 9689176..63c18ea 100644
9299 --- a/arch/sparc/include/asm/spinlock_64.h
9300 +++ b/arch/sparc/include/asm/spinlock_64.h
9301 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9302
9303 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9304
9305 -static void inline arch_read_lock(arch_rwlock_t *lock)
9306 +static inline void arch_read_lock(arch_rwlock_t *lock)
9307 {
9308 unsigned long tmp1, tmp2;
9309
9310 __asm__ __volatile__ (
9311 "1: ldsw [%2], %0\n"
9312 " brlz,pn %0, 2f\n"
9313 -"4: add %0, 1, %1\n"
9314 +"4: addcc %0, 1, %1\n"
9315 +
9316 +#ifdef CONFIG_PAX_REFCOUNT
9317 +" tvs %%icc, 6\n"
9318 +#endif
9319 +
9320 " cas [%2], %0, %1\n"
9321 " cmp %0, %1\n"
9322 " bne,pn %%icc, 1b\n"
9323 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9324 " .previous"
9325 : "=&r" (tmp1), "=&r" (tmp2)
9326 : "r" (lock)
9327 - : "memory");
9328 + : "memory", "cc");
9329 }
9330
9331 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9332 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9333 {
9334 int tmp1, tmp2;
9335
9336 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9337 "1: ldsw [%2], %0\n"
9338 " brlz,a,pn %0, 2f\n"
9339 " mov 0, %0\n"
9340 -" add %0, 1, %1\n"
9341 +" addcc %0, 1, %1\n"
9342 +
9343 +#ifdef CONFIG_PAX_REFCOUNT
9344 +" tvs %%icc, 6\n"
9345 +#endif
9346 +
9347 " cas [%2], %0, %1\n"
9348 " cmp %0, %1\n"
9349 " bne,pn %%icc, 1b\n"
9350 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9351 return tmp1;
9352 }
9353
9354 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9355 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9356 {
9357 unsigned long tmp1, tmp2;
9358
9359 __asm__ __volatile__(
9360 "1: lduw [%2], %0\n"
9361 -" sub %0, 1, %1\n"
9362 +" subcc %0, 1, %1\n"
9363 +
9364 +#ifdef CONFIG_PAX_REFCOUNT
9365 +" tvs %%icc, 6\n"
9366 +#endif
9367 +
9368 " cas [%2], %0, %1\n"
9369 " cmp %0, %1\n"
9370 " bne,pn %%xcc, 1b\n"
9371 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9372 : "memory");
9373 }
9374
9375 -static void inline arch_write_lock(arch_rwlock_t *lock)
9376 +static inline void arch_write_lock(arch_rwlock_t *lock)
9377 {
9378 unsigned long mask, tmp1, tmp2;
9379
9380 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9381 : "memory");
9382 }
9383
9384 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9385 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9386 {
9387 __asm__ __volatile__(
9388 " stw %%g0, [%0]"
9389 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9390 : "memory");
9391 }
9392
9393 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9394 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9395 {
9396 unsigned long mask, tmp1, tmp2, result;
9397
9398 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9399 index 96efa7a..16858bf 100644
9400 --- a/arch/sparc/include/asm/thread_info_32.h
9401 +++ b/arch/sparc/include/asm/thread_info_32.h
9402 @@ -49,6 +49,8 @@ struct thread_info {
9403 unsigned long w_saved;
9404
9405 struct restart_block restart_block;
9406 +
9407 + unsigned long lowest_stack;
9408 };
9409
9410 /*
9411 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9412 index a5f01ac..703b554 100644
9413 --- a/arch/sparc/include/asm/thread_info_64.h
9414 +++ b/arch/sparc/include/asm/thread_info_64.h
9415 @@ -63,6 +63,8 @@ struct thread_info {
9416 struct pt_regs *kern_una_regs;
9417 unsigned int kern_una_insn;
9418
9419 + unsigned long lowest_stack;
9420 +
9421 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9422 };
9423
9424 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9425 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9426 /* flag bit 4 is available */
9427 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9428 -/* flag bit 6 is available */
9429 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9430 #define TIF_32BIT 7 /* 32-bit binary */
9431 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9432 #define TIF_SECCOMP 9 /* secure computing */
9433 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9434 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9435 +
9436 /* NOTE: Thread flags >= 12 should be ones we have no interest
9437 * in using in assembly, else we can't use the mask as
9438 * an immediate value in instructions such as andcc.
9439 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9440 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9441 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9442 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9443 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9444
9445 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9446 _TIF_DO_NOTIFY_RESUME_MASK | \
9447 _TIF_NEED_RESCHED)
9448 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9449
9450 +#define _TIF_WORK_SYSCALL \
9451 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9452 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9453 +
9454 +
9455 /*
9456 * Thread-synchronous status.
9457 *
9458 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9459 index 0167d26..767bb0c 100644
9460 --- a/arch/sparc/include/asm/uaccess.h
9461 +++ b/arch/sparc/include/asm/uaccess.h
9462 @@ -1,5 +1,6 @@
9463 #ifndef ___ASM_SPARC_UACCESS_H
9464 #define ___ASM_SPARC_UACCESS_H
9465 +
9466 #if defined(__sparc__) && defined(__arch64__)
9467 #include <asm/uaccess_64.h>
9468 #else
9469 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9470 index 53a28dd..50c38c3 100644
9471 --- a/arch/sparc/include/asm/uaccess_32.h
9472 +++ b/arch/sparc/include/asm/uaccess_32.h
9473 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9474
9475 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9476 {
9477 - if (n && __access_ok((unsigned long) to, n))
9478 + if ((long)n < 0)
9479 + return n;
9480 +
9481 + if (n && __access_ok((unsigned long) to, n)) {
9482 + if (!__builtin_constant_p(n))
9483 + check_object_size(from, n, true);
9484 return __copy_user(to, (__force void __user *) from, n);
9485 - else
9486 + } else
9487 return n;
9488 }
9489
9490 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9491 {
9492 + if ((long)n < 0)
9493 + return n;
9494 +
9495 + if (!__builtin_constant_p(n))
9496 + check_object_size(from, n, true);
9497 +
9498 return __copy_user(to, (__force void __user *) from, n);
9499 }
9500
9501 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9502 {
9503 - if (n && __access_ok((unsigned long) from, n))
9504 + if ((long)n < 0)
9505 + return n;
9506 +
9507 + if (n && __access_ok((unsigned long) from, n)) {
9508 + if (!__builtin_constant_p(n))
9509 + check_object_size(to, n, false);
9510 return __copy_user((__force void __user *) to, from, n);
9511 - else
9512 + } else
9513 return n;
9514 }
9515
9516 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9517 {
9518 + if ((long)n < 0)
9519 + return n;
9520 +
9521 return __copy_user((__force void __user *) to, from, n);
9522 }
9523
9524 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9525 index ad7e178..c9e7423 100644
9526 --- a/arch/sparc/include/asm/uaccess_64.h
9527 +++ b/arch/sparc/include/asm/uaccess_64.h
9528 @@ -10,6 +10,7 @@
9529 #include <linux/compiler.h>
9530 #include <linux/string.h>
9531 #include <linux/thread_info.h>
9532 +#include <linux/kernel.h>
9533 #include <asm/asi.h>
9534 #include <asm/spitfire.h>
9535 #include <asm-generic/uaccess-unaligned.h>
9536 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9537 static inline unsigned long __must_check
9538 copy_from_user(void *to, const void __user *from, unsigned long size)
9539 {
9540 - unsigned long ret = ___copy_from_user(to, from, size);
9541 + unsigned long ret;
9542
9543 + if ((long)size < 0 || size > INT_MAX)
9544 + return size;
9545 +
9546 + if (!__builtin_constant_p(size))
9547 + check_object_size(to, size, false);
9548 +
9549 + ret = ___copy_from_user(to, from, size);
9550 if (unlikely(ret))
9551 ret = copy_from_user_fixup(to, from, size);
9552
9553 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9554 static inline unsigned long __must_check
9555 copy_to_user(void __user *to, const void *from, unsigned long size)
9556 {
9557 - unsigned long ret = ___copy_to_user(to, from, size);
9558 + unsigned long ret;
9559
9560 + if ((long)size < 0 || size > INT_MAX)
9561 + return size;
9562 +
9563 + if (!__builtin_constant_p(size))
9564 + check_object_size(from, size, true);
9565 +
9566 + ret = ___copy_to_user(to, from, size);
9567 if (unlikely(ret))
9568 ret = copy_to_user_fixup(to, from, size);
9569 return ret;
9570 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9571 index d15cc17..d0ae796 100644
9572 --- a/arch/sparc/kernel/Makefile
9573 +++ b/arch/sparc/kernel/Makefile
9574 @@ -4,7 +4,7 @@
9575 #
9576
9577 asflags-y := -ansi
9578 -ccflags-y := -Werror
9579 +#ccflags-y := -Werror
9580
9581 extra-y := head_$(BITS).o
9582
9583 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9584 index fdd819d..5af08c8 100644
9585 --- a/arch/sparc/kernel/process_32.c
9586 +++ b/arch/sparc/kernel/process_32.c
9587 @@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9588
9589 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9590 r->psr, r->pc, r->npc, r->y, print_tainted());
9591 - printk("PC: <%pS>\n", (void *) r->pc);
9592 + printk("PC: <%pA>\n", (void *) r->pc);
9593 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9594 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9595 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9596 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9597 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9598 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9599 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9600 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9601
9602 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9603 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9604 @@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9605 rw = (struct reg_window32 *) fp;
9606 pc = rw->ins[7];
9607 printk("[%08lx : ", pc);
9608 - printk("%pS ] ", (void *) pc);
9609 + printk("%pA ] ", (void *) pc);
9610 fp = rw->ins[6];
9611 } while (++count < 16);
9612 printk("\n");
9613 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9614 index 32a280e..84fc6a9 100644
9615 --- a/arch/sparc/kernel/process_64.c
9616 +++ b/arch/sparc/kernel/process_64.c
9617 @@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
9618 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9619 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9620 if (regs->tstate & TSTATE_PRIV)
9621 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9622 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9623 }
9624
9625 void show_regs(struct pt_regs *regs)
9626 @@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
9627
9628 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9629 regs->tpc, regs->tnpc, regs->y, print_tainted());
9630 - printk("TPC: <%pS>\n", (void *) regs->tpc);
9631 + printk("TPC: <%pA>\n", (void *) regs->tpc);
9632 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9633 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9634 regs->u_regs[3]);
9635 @@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
9636 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9637 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9638 regs->u_regs[15]);
9639 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9640 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9641 show_regwindow(regs);
9642 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9643 }
9644 @@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
9645 ((tp && tp->task) ? tp->task->pid : -1));
9646
9647 if (gp->tstate & TSTATE_PRIV) {
9648 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9649 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9650 (void *) gp->tpc,
9651 (void *) gp->o7,
9652 (void *) gp->i7,
9653 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9654 index 79cc0d1..ec62734 100644
9655 --- a/arch/sparc/kernel/prom_common.c
9656 +++ b/arch/sparc/kernel/prom_common.c
9657 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9658
9659 unsigned int prom_early_allocated __initdata;
9660
9661 -static struct of_pdt_ops prom_sparc_ops __initdata = {
9662 +static struct of_pdt_ops prom_sparc_ops __initconst = {
9663 .nextprop = prom_common_nextprop,
9664 .getproplen = prom_getproplen,
9665 .getproperty = prom_getproperty,
9666 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9667 index c13c9f2..d572c34 100644
9668 --- a/arch/sparc/kernel/ptrace_64.c
9669 +++ b/arch/sparc/kernel/ptrace_64.c
9670 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
9671 return ret;
9672 }
9673
9674 +#ifdef CONFIG_GRKERNSEC_SETXID
9675 +extern void gr_delayed_cred_worker(void);
9676 +#endif
9677 +
9678 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9679 {
9680 int ret = 0;
9681 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9682 if (test_thread_flag(TIF_NOHZ))
9683 user_exit();
9684
9685 +#ifdef CONFIG_GRKERNSEC_SETXID
9686 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9687 + gr_delayed_cred_worker();
9688 +#endif
9689 +
9690 if (test_thread_flag(TIF_SYSCALL_TRACE))
9691 ret = tracehook_report_syscall_entry(regs);
9692
9693 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9694 if (test_thread_flag(TIF_NOHZ))
9695 user_exit();
9696
9697 +#ifdef CONFIG_GRKERNSEC_SETXID
9698 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9699 + gr_delayed_cred_worker();
9700 +#endif
9701 +
9702 audit_syscall_exit(regs);
9703
9704 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9705 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9706 index b085311..6f885f7 100644
9707 --- a/arch/sparc/kernel/smp_64.c
9708 +++ b/arch/sparc/kernel/smp_64.c
9709 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9710 extern unsigned long xcall_flush_dcache_page_spitfire;
9711
9712 #ifdef CONFIG_DEBUG_DCFLUSH
9713 -extern atomic_t dcpage_flushes;
9714 -extern atomic_t dcpage_flushes_xcall;
9715 +extern atomic_unchecked_t dcpage_flushes;
9716 +extern atomic_unchecked_t dcpage_flushes_xcall;
9717 #endif
9718
9719 static inline void __local_flush_dcache_page(struct page *page)
9720 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9721 return;
9722
9723 #ifdef CONFIG_DEBUG_DCFLUSH
9724 - atomic_inc(&dcpage_flushes);
9725 + atomic_inc_unchecked(&dcpage_flushes);
9726 #endif
9727
9728 this_cpu = get_cpu();
9729 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9730 xcall_deliver(data0, __pa(pg_addr),
9731 (u64) pg_addr, cpumask_of(cpu));
9732 #ifdef CONFIG_DEBUG_DCFLUSH
9733 - atomic_inc(&dcpage_flushes_xcall);
9734 + atomic_inc_unchecked(&dcpage_flushes_xcall);
9735 #endif
9736 }
9737 }
9738 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9739 preempt_disable();
9740
9741 #ifdef CONFIG_DEBUG_DCFLUSH
9742 - atomic_inc(&dcpage_flushes);
9743 + atomic_inc_unchecked(&dcpage_flushes);
9744 #endif
9745 data0 = 0;
9746 pg_addr = page_address(page);
9747 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9748 xcall_deliver(data0, __pa(pg_addr),
9749 (u64) pg_addr, cpu_online_mask);
9750 #ifdef CONFIG_DEBUG_DCFLUSH
9751 - atomic_inc(&dcpage_flushes_xcall);
9752 + atomic_inc_unchecked(&dcpage_flushes_xcall);
9753 #endif
9754 }
9755 __local_flush_dcache_page(page);
9756 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9757 index 3a8d184..49498a8 100644
9758 --- a/arch/sparc/kernel/sys_sparc_32.c
9759 +++ b/arch/sparc/kernel/sys_sparc_32.c
9760 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9761 if (len > TASK_SIZE - PAGE_SIZE)
9762 return -ENOMEM;
9763 if (!addr)
9764 - addr = TASK_UNMAPPED_BASE;
9765 + addr = current->mm->mmap_base;
9766
9767 info.flags = 0;
9768 info.length = len;
9769 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9770 index beb0b5a..5a153f7 100644
9771 --- a/arch/sparc/kernel/sys_sparc_64.c
9772 +++ b/arch/sparc/kernel/sys_sparc_64.c
9773 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9774 struct vm_area_struct * vma;
9775 unsigned long task_size = TASK_SIZE;
9776 int do_color_align;
9777 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9778 struct vm_unmapped_area_info info;
9779
9780 if (flags & MAP_FIXED) {
9781 /* We do not accept a shared mapping if it would violate
9782 * cache aliasing constraints.
9783 */
9784 - if ((flags & MAP_SHARED) &&
9785 + if ((filp || (flags & MAP_SHARED)) &&
9786 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9787 return -EINVAL;
9788 return addr;
9789 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9790 if (filp || (flags & MAP_SHARED))
9791 do_color_align = 1;
9792
9793 +#ifdef CONFIG_PAX_RANDMMAP
9794 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9795 +#endif
9796 +
9797 if (addr) {
9798 if (do_color_align)
9799 addr = COLOR_ALIGN(addr, pgoff);
9800 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9801 addr = PAGE_ALIGN(addr);
9802
9803 vma = find_vma(mm, addr);
9804 - if (task_size - len >= addr &&
9805 - (!vma || addr + len <= vma->vm_start))
9806 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9807 return addr;
9808 }
9809
9810 info.flags = 0;
9811 info.length = len;
9812 - info.low_limit = TASK_UNMAPPED_BASE;
9813 + info.low_limit = mm->mmap_base;
9814 info.high_limit = min(task_size, VA_EXCLUDE_START);
9815 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9816 info.align_offset = pgoff << PAGE_SHIFT;
9817 + info.threadstack_offset = offset;
9818 addr = vm_unmapped_area(&info);
9819
9820 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9821 VM_BUG_ON(addr != -ENOMEM);
9822 info.low_limit = VA_EXCLUDE_END;
9823 +
9824 +#ifdef CONFIG_PAX_RANDMMAP
9825 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9826 + info.low_limit += mm->delta_mmap;
9827 +#endif
9828 +
9829 info.high_limit = task_size;
9830 addr = vm_unmapped_area(&info);
9831 }
9832 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9833 unsigned long task_size = STACK_TOP32;
9834 unsigned long addr = addr0;
9835 int do_color_align;
9836 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9837 struct vm_unmapped_area_info info;
9838
9839 /* This should only ever run for 32-bit processes. */
9840 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9841 /* We do not accept a shared mapping if it would violate
9842 * cache aliasing constraints.
9843 */
9844 - if ((flags & MAP_SHARED) &&
9845 + if ((filp || (flags & MAP_SHARED)) &&
9846 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9847 return -EINVAL;
9848 return addr;
9849 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9850 if (filp || (flags & MAP_SHARED))
9851 do_color_align = 1;
9852
9853 +#ifdef CONFIG_PAX_RANDMMAP
9854 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9855 +#endif
9856 +
9857 /* requesting a specific address */
9858 if (addr) {
9859 if (do_color_align)
9860 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9861 addr = PAGE_ALIGN(addr);
9862
9863 vma = find_vma(mm, addr);
9864 - if (task_size - len >= addr &&
9865 - (!vma || addr + len <= vma->vm_start))
9866 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9867 return addr;
9868 }
9869
9870 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9871 info.high_limit = mm->mmap_base;
9872 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9873 info.align_offset = pgoff << PAGE_SHIFT;
9874 + info.threadstack_offset = offset;
9875 addr = vm_unmapped_area(&info);
9876
9877 /*
9878 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9879 VM_BUG_ON(addr != -ENOMEM);
9880 info.flags = 0;
9881 info.low_limit = TASK_UNMAPPED_BASE;
9882 +
9883 +#ifdef CONFIG_PAX_RANDMMAP
9884 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9885 + info.low_limit += mm->delta_mmap;
9886 +#endif
9887 +
9888 info.high_limit = STACK_TOP32;
9889 addr = vm_unmapped_area(&info);
9890 }
9891 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9892 EXPORT_SYMBOL(get_fb_unmapped_area);
9893
9894 /* Essentially the same as PowerPC. */
9895 -static unsigned long mmap_rnd(void)
9896 +static unsigned long mmap_rnd(struct mm_struct *mm)
9897 {
9898 unsigned long rnd = 0UL;
9899
9900 +#ifdef CONFIG_PAX_RANDMMAP
9901 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9902 +#endif
9903 +
9904 if (current->flags & PF_RANDOMIZE) {
9905 unsigned long val = get_random_int();
9906 if (test_thread_flag(TIF_32BIT))
9907 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
9908
9909 void arch_pick_mmap_layout(struct mm_struct *mm)
9910 {
9911 - unsigned long random_factor = mmap_rnd();
9912 + unsigned long random_factor = mmap_rnd(mm);
9913 unsigned long gap;
9914
9915 /*
9916 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9917 gap == RLIM_INFINITY ||
9918 sysctl_legacy_va_layout) {
9919 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9920 +
9921 +#ifdef CONFIG_PAX_RANDMMAP
9922 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9923 + mm->mmap_base += mm->delta_mmap;
9924 +#endif
9925 +
9926 mm->get_unmapped_area = arch_get_unmapped_area;
9927 } else {
9928 /* We know it's 32-bit */
9929 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9930 gap = (task_size / 6 * 5);
9931
9932 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9933 +
9934 +#ifdef CONFIG_PAX_RANDMMAP
9935 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9936 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9937 +#endif
9938 +
9939 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9940 }
9941 }
9942 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9943 index 87729ff..192f9d8 100644
9944 --- a/arch/sparc/kernel/syscalls.S
9945 +++ b/arch/sparc/kernel/syscalls.S
9946 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9947 #endif
9948 .align 32
9949 1: ldx [%g6 + TI_FLAGS], %l5
9950 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9951 + andcc %l5, _TIF_WORK_SYSCALL, %g0
9952 be,pt %icc, rtrap
9953 nop
9954 call syscall_trace_leave
9955 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
9956
9957 srl %i3, 0, %o3 ! IEU0
9958 srl %i2, 0, %o2 ! IEU0 Group
9959 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9960 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9961 bne,pn %icc, linux_syscall_trace32 ! CTI
9962 mov %i0, %l5 ! IEU1
9963 5: call %l7 ! CTI Group brk forced
9964 @@ -207,7 +207,7 @@ linux_sparc_syscall:
9965
9966 mov %i3, %o3 ! IEU1
9967 mov %i4, %o4 ! IEU0 Group
9968 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9969 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9970 bne,pn %icc, linux_syscall_trace ! CTI Group
9971 mov %i0, %l5 ! IEU0
9972 2: call %l7 ! CTI Group brk forced
9973 @@ -223,7 +223,7 @@ ret_sys_call:
9974
9975 cmp %o0, -ERESTART_RESTARTBLOCK
9976 bgeu,pn %xcc, 1f
9977 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9978 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9979 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9980
9981 2:
9982 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9983 index 6629829..036032d 100644
9984 --- a/arch/sparc/kernel/traps_32.c
9985 +++ b/arch/sparc/kernel/traps_32.c
9986 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9987 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9988 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9989
9990 +extern void gr_handle_kernel_exploit(void);
9991 +
9992 void die_if_kernel(char *str, struct pt_regs *regs)
9993 {
9994 static int die_counter;
9995 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9996 count++ < 30 &&
9997 (((unsigned long) rw) >= PAGE_OFFSET) &&
9998 !(((unsigned long) rw) & 0x7)) {
9999 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10000 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10001 (void *) rw->ins[7]);
10002 rw = (struct reg_window32 *)rw->ins[6];
10003 }
10004 }
10005 printk("Instruction DUMP:");
10006 instruction_dump ((unsigned long *) regs->pc);
10007 - if(regs->psr & PSR_PS)
10008 + if(regs->psr & PSR_PS) {
10009 + gr_handle_kernel_exploit();
10010 do_exit(SIGKILL);
10011 + }
10012 do_exit(SIGSEGV);
10013 }
10014
10015 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10016 index 4ced92f..965eeed 100644
10017 --- a/arch/sparc/kernel/traps_64.c
10018 +++ b/arch/sparc/kernel/traps_64.c
10019 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10020 i + 1,
10021 p->trapstack[i].tstate, p->trapstack[i].tpc,
10022 p->trapstack[i].tnpc, p->trapstack[i].tt);
10023 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10024 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10025 }
10026 }
10027
10028 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10029
10030 lvl -= 0x100;
10031 if (regs->tstate & TSTATE_PRIV) {
10032 +
10033 +#ifdef CONFIG_PAX_REFCOUNT
10034 + if (lvl == 6)
10035 + pax_report_refcount_overflow(regs);
10036 +#endif
10037 +
10038 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10039 die_if_kernel(buffer, regs);
10040 }
10041 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10042 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10043 {
10044 char buffer[32];
10045 -
10046 +
10047 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10048 0, lvl, SIGTRAP) == NOTIFY_STOP)
10049 return;
10050
10051 +#ifdef CONFIG_PAX_REFCOUNT
10052 + if (lvl == 6)
10053 + pax_report_refcount_overflow(regs);
10054 +#endif
10055 +
10056 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10057
10058 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10059 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10060 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10061 printk("%s" "ERROR(%d): ",
10062 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10063 - printk("TPC<%pS>\n", (void *) regs->tpc);
10064 + printk("TPC<%pA>\n", (void *) regs->tpc);
10065 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10066 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10067 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10068 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10069 smp_processor_id(),
10070 (type & 0x1) ? 'I' : 'D',
10071 regs->tpc);
10072 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10073 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10074 panic("Irrecoverable Cheetah+ parity error.");
10075 }
10076
10077 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10078 smp_processor_id(),
10079 (type & 0x1) ? 'I' : 'D',
10080 regs->tpc);
10081 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10082 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10083 }
10084
10085 struct sun4v_error_entry {
10086 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10087 /*0x38*/u64 reserved_5;
10088 };
10089
10090 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10091 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10092 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10093 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10094
10095 static const char *sun4v_err_type_to_str(u8 type)
10096 {
10097 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10098 }
10099
10100 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10101 - int cpu, const char *pfx, atomic_t *ocnt)
10102 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10103 {
10104 u64 *raw_ptr = (u64 *) ent;
10105 u32 attrs;
10106 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10107
10108 show_regs(regs);
10109
10110 - if ((cnt = atomic_read(ocnt)) != 0) {
10111 - atomic_set(ocnt, 0);
10112 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10113 + atomic_set_unchecked(ocnt, 0);
10114 wmb();
10115 printk("%s: Queue overflowed %d times.\n",
10116 pfx, cnt);
10117 @@ -2046,7 +2057,7 @@ out:
10118 */
10119 void sun4v_resum_overflow(struct pt_regs *regs)
10120 {
10121 - atomic_inc(&sun4v_resum_oflow_cnt);
10122 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10123 }
10124
10125 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10126 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10127 /* XXX Actually even this can make not that much sense. Perhaps
10128 * XXX we should just pull the plug and panic directly from here?
10129 */
10130 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10131 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10132 }
10133
10134 unsigned long sun4v_err_itlb_vaddr;
10135 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10136
10137 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10138 regs->tpc, tl);
10139 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10140 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10141 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10142 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10143 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10144 (void *) regs->u_regs[UREG_I7]);
10145 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10146 "pte[%lx] error[%lx]\n",
10147 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10148
10149 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10150 regs->tpc, tl);
10151 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10152 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10153 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10154 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10155 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10156 (void *) regs->u_regs[UREG_I7]);
10157 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10158 "pte[%lx] error[%lx]\n",
10159 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10160 fp = (unsigned long)sf->fp + STACK_BIAS;
10161 }
10162
10163 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10164 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10165 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10166 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10167 int index = tsk->curr_ret_stack;
10168 if (tsk->ret_stack && index >= graph) {
10169 pc = tsk->ret_stack[index - graph].ret;
10170 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10171 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10172 graph++;
10173 }
10174 }
10175 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10176 return (struct reg_window *) (fp + STACK_BIAS);
10177 }
10178
10179 +extern void gr_handle_kernel_exploit(void);
10180 +
10181 void die_if_kernel(char *str, struct pt_regs *regs)
10182 {
10183 static int die_counter;
10184 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10185 while (rw &&
10186 count++ < 30 &&
10187 kstack_valid(tp, (unsigned long) rw)) {
10188 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10189 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10190 (void *) rw->ins[7]);
10191
10192 rw = kernel_stack_up(rw);
10193 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10194 }
10195 user_instruction_dump ((unsigned int __user *) regs->tpc);
10196 }
10197 - if (regs->tstate & TSTATE_PRIV)
10198 + if (regs->tstate & TSTATE_PRIV) {
10199 + gr_handle_kernel_exploit();
10200 do_exit(SIGKILL);
10201 + }
10202 do_exit(SIGSEGV);
10203 }
10204 EXPORT_SYMBOL(die_if_kernel);
10205 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10206 index 3c1a7cb..73e1923 100644
10207 --- a/arch/sparc/kernel/unaligned_64.c
10208 +++ b/arch/sparc/kernel/unaligned_64.c
10209 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10210 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10211
10212 if (__ratelimit(&ratelimit)) {
10213 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10214 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10215 regs->tpc, (void *) regs->tpc);
10216 }
10217 }
10218 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10219 index dbe119b..089c7c1 100644
10220 --- a/arch/sparc/lib/Makefile
10221 +++ b/arch/sparc/lib/Makefile
10222 @@ -2,7 +2,7 @@
10223 #
10224
10225 asflags-y := -ansi -DST_DIV0=0x02
10226 -ccflags-y := -Werror
10227 +#ccflags-y := -Werror
10228
10229 lib-$(CONFIG_SPARC32) += ashrdi3.o
10230 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10231 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10232 index 85c233d..68500e0 100644
10233 --- a/arch/sparc/lib/atomic_64.S
10234 +++ b/arch/sparc/lib/atomic_64.S
10235 @@ -17,7 +17,12 @@
10236 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10237 BACKOFF_SETUP(%o2)
10238 1: lduw [%o1], %g1
10239 - add %g1, %o0, %g7
10240 + addcc %g1, %o0, %g7
10241 +
10242 +#ifdef CONFIG_PAX_REFCOUNT
10243 + tvs %icc, 6
10244 +#endif
10245 +
10246 cas [%o1], %g1, %g7
10247 cmp %g1, %g7
10248 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10249 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10250 2: BACKOFF_SPIN(%o2, %o3, 1b)
10251 ENDPROC(atomic_add)
10252
10253 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10254 + BACKOFF_SETUP(%o2)
10255 +1: lduw [%o1], %g1
10256 + add %g1, %o0, %g7
10257 + cas [%o1], %g1, %g7
10258 + cmp %g1, %g7
10259 + bne,pn %icc, 2f
10260 + nop
10261 + retl
10262 + nop
10263 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10264 +ENDPROC(atomic_add_unchecked)
10265 +
10266 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10267 BACKOFF_SETUP(%o2)
10268 1: lduw [%o1], %g1
10269 - sub %g1, %o0, %g7
10270 + subcc %g1, %o0, %g7
10271 +
10272 +#ifdef CONFIG_PAX_REFCOUNT
10273 + tvs %icc, 6
10274 +#endif
10275 +
10276 cas [%o1], %g1, %g7
10277 cmp %g1, %g7
10278 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10279 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10280 2: BACKOFF_SPIN(%o2, %o3, 1b)
10281 ENDPROC(atomic_sub)
10282
10283 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10284 + BACKOFF_SETUP(%o2)
10285 +1: lduw [%o1], %g1
10286 + sub %g1, %o0, %g7
10287 + cas [%o1], %g1, %g7
10288 + cmp %g1, %g7
10289 + bne,pn %icc, 2f
10290 + nop
10291 + retl
10292 + nop
10293 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10294 +ENDPROC(atomic_sub_unchecked)
10295 +
10296 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10297 BACKOFF_SETUP(%o2)
10298 1: lduw [%o1], %g1
10299 - add %g1, %o0, %g7
10300 + addcc %g1, %o0, %g7
10301 +
10302 +#ifdef CONFIG_PAX_REFCOUNT
10303 + tvs %icc, 6
10304 +#endif
10305 +
10306 cas [%o1], %g1, %g7
10307 cmp %g1, %g7
10308 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10309 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10310 2: BACKOFF_SPIN(%o2, %o3, 1b)
10311 ENDPROC(atomic_add_ret)
10312
10313 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10314 + BACKOFF_SETUP(%o2)
10315 +1: lduw [%o1], %g1
10316 + addcc %g1, %o0, %g7
10317 + cas [%o1], %g1, %g7
10318 + cmp %g1, %g7
10319 + bne,pn %icc, 2f
10320 + add %g7, %o0, %g7
10321 + sra %g7, 0, %o0
10322 + retl
10323 + nop
10324 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10325 +ENDPROC(atomic_add_ret_unchecked)
10326 +
10327 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10328 BACKOFF_SETUP(%o2)
10329 1: lduw [%o1], %g1
10330 - sub %g1, %o0, %g7
10331 + subcc %g1, %o0, %g7
10332 +
10333 +#ifdef CONFIG_PAX_REFCOUNT
10334 + tvs %icc, 6
10335 +#endif
10336 +
10337 cas [%o1], %g1, %g7
10338 cmp %g1, %g7
10339 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10340 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10341 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10342 BACKOFF_SETUP(%o2)
10343 1: ldx [%o1], %g1
10344 - add %g1, %o0, %g7
10345 + addcc %g1, %o0, %g7
10346 +
10347 +#ifdef CONFIG_PAX_REFCOUNT
10348 + tvs %xcc, 6
10349 +#endif
10350 +
10351 casx [%o1], %g1, %g7
10352 cmp %g1, %g7
10353 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10354 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10355 2: BACKOFF_SPIN(%o2, %o3, 1b)
10356 ENDPROC(atomic64_add)
10357
10358 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10359 + BACKOFF_SETUP(%o2)
10360 +1: ldx [%o1], %g1
10361 + addcc %g1, %o0, %g7
10362 + casx [%o1], %g1, %g7
10363 + cmp %g1, %g7
10364 + bne,pn %xcc, 2f
10365 + nop
10366 + retl
10367 + nop
10368 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10369 +ENDPROC(atomic64_add_unchecked)
10370 +
10371 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10372 BACKOFF_SETUP(%o2)
10373 1: ldx [%o1], %g1
10374 - sub %g1, %o0, %g7
10375 + subcc %g1, %o0, %g7
10376 +
10377 +#ifdef CONFIG_PAX_REFCOUNT
10378 + tvs %xcc, 6
10379 +#endif
10380 +
10381 casx [%o1], %g1, %g7
10382 cmp %g1, %g7
10383 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10384 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10385 2: BACKOFF_SPIN(%o2, %o3, 1b)
10386 ENDPROC(atomic64_sub)
10387
10388 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10389 + BACKOFF_SETUP(%o2)
10390 +1: ldx [%o1], %g1
10391 + subcc %g1, %o0, %g7
10392 + casx [%o1], %g1, %g7
10393 + cmp %g1, %g7
10394 + bne,pn %xcc, 2f
10395 + nop
10396 + retl
10397 + nop
10398 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10399 +ENDPROC(atomic64_sub_unchecked)
10400 +
10401 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10402 BACKOFF_SETUP(%o2)
10403 1: ldx [%o1], %g1
10404 - add %g1, %o0, %g7
10405 + addcc %g1, %o0, %g7
10406 +
10407 +#ifdef CONFIG_PAX_REFCOUNT
10408 + tvs %xcc, 6
10409 +#endif
10410 +
10411 casx [%o1], %g1, %g7
10412 cmp %g1, %g7
10413 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10414 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10415 2: BACKOFF_SPIN(%o2, %o3, 1b)
10416 ENDPROC(atomic64_add_ret)
10417
10418 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10419 + BACKOFF_SETUP(%o2)
10420 +1: ldx [%o1], %g1
10421 + addcc %g1, %o0, %g7
10422 + casx [%o1], %g1, %g7
10423 + cmp %g1, %g7
10424 + bne,pn %xcc, 2f
10425 + add %g7, %o0, %g7
10426 + mov %g7, %o0
10427 + retl
10428 + nop
10429 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10430 +ENDPROC(atomic64_add_ret_unchecked)
10431 +
10432 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10433 BACKOFF_SETUP(%o2)
10434 1: ldx [%o1], %g1
10435 - sub %g1, %o0, %g7
10436 + subcc %g1, %o0, %g7
10437 +
10438 +#ifdef CONFIG_PAX_REFCOUNT
10439 + tvs %xcc, 6
10440 +#endif
10441 +
10442 casx [%o1], %g1, %g7
10443 cmp %g1, %g7
10444 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10445 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10446 index 323335b..ed85ea2 100644
10447 --- a/arch/sparc/lib/ksyms.c
10448 +++ b/arch/sparc/lib/ksyms.c
10449 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10450
10451 /* Atomic counter implementation. */
10452 EXPORT_SYMBOL(atomic_add);
10453 +EXPORT_SYMBOL(atomic_add_unchecked);
10454 EXPORT_SYMBOL(atomic_add_ret);
10455 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10456 EXPORT_SYMBOL(atomic_sub);
10457 +EXPORT_SYMBOL(atomic_sub_unchecked);
10458 EXPORT_SYMBOL(atomic_sub_ret);
10459 EXPORT_SYMBOL(atomic64_add);
10460 +EXPORT_SYMBOL(atomic64_add_unchecked);
10461 EXPORT_SYMBOL(atomic64_add_ret);
10462 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10463 EXPORT_SYMBOL(atomic64_sub);
10464 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10465 EXPORT_SYMBOL(atomic64_sub_ret);
10466 EXPORT_SYMBOL(atomic64_dec_if_positive);
10467
10468 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10469 index 30c3ecc..736f015 100644
10470 --- a/arch/sparc/mm/Makefile
10471 +++ b/arch/sparc/mm/Makefile
10472 @@ -2,7 +2,7 @@
10473 #
10474
10475 asflags-y := -ansi
10476 -ccflags-y := -Werror
10477 +#ccflags-y := -Werror
10478
10479 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10480 obj-y += fault_$(BITS).o
10481 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10482 index 59dbd46..1dd7f5e 100644
10483 --- a/arch/sparc/mm/fault_32.c
10484 +++ b/arch/sparc/mm/fault_32.c
10485 @@ -21,6 +21,9 @@
10486 #include <linux/perf_event.h>
10487 #include <linux/interrupt.h>
10488 #include <linux/kdebug.h>
10489 +#include <linux/slab.h>
10490 +#include <linux/pagemap.h>
10491 +#include <linux/compiler.h>
10492
10493 #include <asm/page.h>
10494 #include <asm/pgtable.h>
10495 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10496 return safe_compute_effective_address(regs, insn);
10497 }
10498
10499 +#ifdef CONFIG_PAX_PAGEEXEC
10500 +#ifdef CONFIG_PAX_DLRESOLVE
10501 +static void pax_emuplt_close(struct vm_area_struct *vma)
10502 +{
10503 + vma->vm_mm->call_dl_resolve = 0UL;
10504 +}
10505 +
10506 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10507 +{
10508 + unsigned int *kaddr;
10509 +
10510 + vmf->page = alloc_page(GFP_HIGHUSER);
10511 + if (!vmf->page)
10512 + return VM_FAULT_OOM;
10513 +
10514 + kaddr = kmap(vmf->page);
10515 + memset(kaddr, 0, PAGE_SIZE);
10516 + kaddr[0] = 0x9DE3BFA8U; /* save */
10517 + flush_dcache_page(vmf->page);
10518 + kunmap(vmf->page);
10519 + return VM_FAULT_MAJOR;
10520 +}
10521 +
10522 +static const struct vm_operations_struct pax_vm_ops = {
10523 + .close = pax_emuplt_close,
10524 + .fault = pax_emuplt_fault
10525 +};
10526 +
10527 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10528 +{
10529 + int ret;
10530 +
10531 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10532 + vma->vm_mm = current->mm;
10533 + vma->vm_start = addr;
10534 + vma->vm_end = addr + PAGE_SIZE;
10535 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10536 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10537 + vma->vm_ops = &pax_vm_ops;
10538 +
10539 + ret = insert_vm_struct(current->mm, vma);
10540 + if (ret)
10541 + return ret;
10542 +
10543 + ++current->mm->total_vm;
10544 + return 0;
10545 +}
10546 +#endif
10547 +
10548 +/*
10549 + * PaX: decide what to do with offenders (regs->pc = fault address)
10550 + *
10551 + * returns 1 when task should be killed
10552 + * 2 when patched PLT trampoline was detected
10553 + * 3 when unpatched PLT trampoline was detected
10554 + */
10555 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10556 +{
10557 +
10558 +#ifdef CONFIG_PAX_EMUPLT
10559 + int err;
10560 +
10561 + do { /* PaX: patched PLT emulation #1 */
10562 + unsigned int sethi1, sethi2, jmpl;
10563 +
10564 + err = get_user(sethi1, (unsigned int *)regs->pc);
10565 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10566 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10567 +
10568 + if (err)
10569 + break;
10570 +
10571 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10572 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
10573 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
10574 + {
10575 + unsigned int addr;
10576 +
10577 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10578 + addr = regs->u_regs[UREG_G1];
10579 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10580 + regs->pc = addr;
10581 + regs->npc = addr+4;
10582 + return 2;
10583 + }
10584 + } while (0);
10585 +
10586 + do { /* PaX: patched PLT emulation #2 */
10587 + unsigned int ba;
10588 +
10589 + err = get_user(ba, (unsigned int *)regs->pc);
10590 +
10591 + if (err)
10592 + break;
10593 +
10594 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10595 + unsigned int addr;
10596 +
10597 + if ((ba & 0xFFC00000U) == 0x30800000U)
10598 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10599 + else
10600 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10601 + regs->pc = addr;
10602 + regs->npc = addr+4;
10603 + return 2;
10604 + }
10605 + } while (0);
10606 +
10607 + do { /* PaX: patched PLT emulation #3 */
10608 + unsigned int sethi, bajmpl, nop;
10609 +
10610 + err = get_user(sethi, (unsigned int *)regs->pc);
10611 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10612 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
10613 +
10614 + if (err)
10615 + break;
10616 +
10617 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10618 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10619 + nop == 0x01000000U)
10620 + {
10621 + unsigned int addr;
10622 +
10623 + addr = (sethi & 0x003FFFFFU) << 10;
10624 + regs->u_regs[UREG_G1] = addr;
10625 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10626 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10627 + else
10628 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10629 + regs->pc = addr;
10630 + regs->npc = addr+4;
10631 + return 2;
10632 + }
10633 + } while (0);
10634 +
10635 + do { /* PaX: unpatched PLT emulation step 1 */
10636 + unsigned int sethi, ba, nop;
10637 +
10638 + err = get_user(sethi, (unsigned int *)regs->pc);
10639 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
10640 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
10641 +
10642 + if (err)
10643 + break;
10644 +
10645 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10646 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10647 + nop == 0x01000000U)
10648 + {
10649 + unsigned int addr, save, call;
10650 +
10651 + if ((ba & 0xFFC00000U) == 0x30800000U)
10652 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10653 + else
10654 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10655 +
10656 + err = get_user(save, (unsigned int *)addr);
10657 + err |= get_user(call, (unsigned int *)(addr+4));
10658 + err |= get_user(nop, (unsigned int *)(addr+8));
10659 + if (err)
10660 + break;
10661 +
10662 +#ifdef CONFIG_PAX_DLRESOLVE
10663 + if (save == 0x9DE3BFA8U &&
10664 + (call & 0xC0000000U) == 0x40000000U &&
10665 + nop == 0x01000000U)
10666 + {
10667 + struct vm_area_struct *vma;
10668 + unsigned long call_dl_resolve;
10669 +
10670 + down_read(&current->mm->mmap_sem);
10671 + call_dl_resolve = current->mm->call_dl_resolve;
10672 + up_read(&current->mm->mmap_sem);
10673 + if (likely(call_dl_resolve))
10674 + goto emulate;
10675 +
10676 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10677 +
10678 + down_write(&current->mm->mmap_sem);
10679 + if (current->mm->call_dl_resolve) {
10680 + call_dl_resolve = current->mm->call_dl_resolve;
10681 + up_write(&current->mm->mmap_sem);
10682 + if (vma)
10683 + kmem_cache_free(vm_area_cachep, vma);
10684 + goto emulate;
10685 + }
10686 +
10687 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10688 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10689 + up_write(&current->mm->mmap_sem);
10690 + if (vma)
10691 + kmem_cache_free(vm_area_cachep, vma);
10692 + return 1;
10693 + }
10694 +
10695 + if (pax_insert_vma(vma, call_dl_resolve)) {
10696 + up_write(&current->mm->mmap_sem);
10697 + kmem_cache_free(vm_area_cachep, vma);
10698 + return 1;
10699 + }
10700 +
10701 + current->mm->call_dl_resolve = call_dl_resolve;
10702 + up_write(&current->mm->mmap_sem);
10703 +
10704 +emulate:
10705 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10706 + regs->pc = call_dl_resolve;
10707 + regs->npc = addr+4;
10708 + return 3;
10709 + }
10710 +#endif
10711 +
10712 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10713 + if ((save & 0xFFC00000U) == 0x05000000U &&
10714 + (call & 0xFFFFE000U) == 0x85C0A000U &&
10715 + nop == 0x01000000U)
10716 + {
10717 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10718 + regs->u_regs[UREG_G2] = addr + 4;
10719 + addr = (save & 0x003FFFFFU) << 10;
10720 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10721 + regs->pc = addr;
10722 + regs->npc = addr+4;
10723 + return 3;
10724 + }
10725 + }
10726 + } while (0);
10727 +
10728 + do { /* PaX: unpatched PLT emulation step 2 */
10729 + unsigned int save, call, nop;
10730 +
10731 + err = get_user(save, (unsigned int *)(regs->pc-4));
10732 + err |= get_user(call, (unsigned int *)regs->pc);
10733 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
10734 + if (err)
10735 + break;
10736 +
10737 + if (save == 0x9DE3BFA8U &&
10738 + (call & 0xC0000000U) == 0x40000000U &&
10739 + nop == 0x01000000U)
10740 + {
10741 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10742 +
10743 + regs->u_regs[UREG_RETPC] = regs->pc;
10744 + regs->pc = dl_resolve;
10745 + regs->npc = dl_resolve+4;
10746 + return 3;
10747 + }
10748 + } while (0);
10749 +#endif
10750 +
10751 + return 1;
10752 +}
10753 +
10754 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10755 +{
10756 + unsigned long i;
10757 +
10758 + printk(KERN_ERR "PAX: bytes at PC: ");
10759 + for (i = 0; i < 8; i++) {
10760 + unsigned int c;
10761 + if (get_user(c, (unsigned int *)pc+i))
10762 + printk(KERN_CONT "???????? ");
10763 + else
10764 + printk(KERN_CONT "%08x ", c);
10765 + }
10766 + printk("\n");
10767 +}
10768 +#endif
10769 +
10770 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10771 int text_fault)
10772 {
10773 @@ -229,6 +503,24 @@ good_area:
10774 if (!(vma->vm_flags & VM_WRITE))
10775 goto bad_area;
10776 } else {
10777 +
10778 +#ifdef CONFIG_PAX_PAGEEXEC
10779 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10780 + up_read(&mm->mmap_sem);
10781 + switch (pax_handle_fetch_fault(regs)) {
10782 +
10783 +#ifdef CONFIG_PAX_EMUPLT
10784 + case 2:
10785 + case 3:
10786 + return;
10787 +#endif
10788 +
10789 + }
10790 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10791 + do_group_exit(SIGKILL);
10792 + }
10793 +#endif
10794 +
10795 /* Allow reads even for write-only mappings */
10796 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10797 goto bad_area;
10798 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10799 index 69bb818..6ca35c8 100644
10800 --- a/arch/sparc/mm/fault_64.c
10801 +++ b/arch/sparc/mm/fault_64.c
10802 @@ -22,6 +22,9 @@
10803 #include <linux/kdebug.h>
10804 #include <linux/percpu.h>
10805 #include <linux/context_tracking.h>
10806 +#include <linux/slab.h>
10807 +#include <linux/pagemap.h>
10808 +#include <linux/compiler.h>
10809
10810 #include <asm/page.h>
10811 #include <asm/pgtable.h>
10812 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10813 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10814 regs->tpc);
10815 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10816 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10817 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10818 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10819 dump_stack();
10820 unhandled_fault(regs->tpc, current, regs);
10821 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10822 show_regs(regs);
10823 }
10824
10825 +#ifdef CONFIG_PAX_PAGEEXEC
10826 +#ifdef CONFIG_PAX_DLRESOLVE
10827 +static void pax_emuplt_close(struct vm_area_struct *vma)
10828 +{
10829 + vma->vm_mm->call_dl_resolve = 0UL;
10830 +}
10831 +
10832 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10833 +{
10834 + unsigned int *kaddr;
10835 +
10836 + vmf->page = alloc_page(GFP_HIGHUSER);
10837 + if (!vmf->page)
10838 + return VM_FAULT_OOM;
10839 +
10840 + kaddr = kmap(vmf->page);
10841 + memset(kaddr, 0, PAGE_SIZE);
10842 + kaddr[0] = 0x9DE3BFA8U; /* save */
10843 + flush_dcache_page(vmf->page);
10844 + kunmap(vmf->page);
10845 + return VM_FAULT_MAJOR;
10846 +}
10847 +
10848 +static const struct vm_operations_struct pax_vm_ops = {
10849 + .close = pax_emuplt_close,
10850 + .fault = pax_emuplt_fault
10851 +};
10852 +
10853 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10854 +{
10855 + int ret;
10856 +
10857 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10858 + vma->vm_mm = current->mm;
10859 + vma->vm_start = addr;
10860 + vma->vm_end = addr + PAGE_SIZE;
10861 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10862 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10863 + vma->vm_ops = &pax_vm_ops;
10864 +
10865 + ret = insert_vm_struct(current->mm, vma);
10866 + if (ret)
10867 + return ret;
10868 +
10869 + ++current->mm->total_vm;
10870 + return 0;
10871 +}
10872 +#endif
10873 +
10874 +/*
10875 + * PaX: decide what to do with offenders (regs->tpc = fault address)
10876 + *
10877 + * returns 1 when task should be killed
10878 + * 2 when patched PLT trampoline was detected
10879 + * 3 when unpatched PLT trampoline was detected
10880 + */
10881 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10882 +{
10883 +
10884 +#ifdef CONFIG_PAX_EMUPLT
10885 + int err;
10886 +
10887 + do { /* PaX: patched PLT emulation #1 */
10888 + unsigned int sethi1, sethi2, jmpl;
10889 +
10890 + err = get_user(sethi1, (unsigned int *)regs->tpc);
10891 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10892 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10893 +
10894 + if (err)
10895 + break;
10896 +
10897 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10898 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
10899 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
10900 + {
10901 + unsigned long addr;
10902 +
10903 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10904 + addr = regs->u_regs[UREG_G1];
10905 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10906 +
10907 + if (test_thread_flag(TIF_32BIT))
10908 + addr &= 0xFFFFFFFFUL;
10909 +
10910 + regs->tpc = addr;
10911 + regs->tnpc = addr+4;
10912 + return 2;
10913 + }
10914 + } while (0);
10915 +
10916 + do { /* PaX: patched PLT emulation #2 */
10917 + unsigned int ba;
10918 +
10919 + err = get_user(ba, (unsigned int *)regs->tpc);
10920 +
10921 + if (err)
10922 + break;
10923 +
10924 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10925 + unsigned long addr;
10926 +
10927 + if ((ba & 0xFFC00000U) == 0x30800000U)
10928 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10929 + else
10930 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10931 +
10932 + if (test_thread_flag(TIF_32BIT))
10933 + addr &= 0xFFFFFFFFUL;
10934 +
10935 + regs->tpc = addr;
10936 + regs->tnpc = addr+4;
10937 + return 2;
10938 + }
10939 + } while (0);
10940 +
10941 + do { /* PaX: patched PLT emulation #3 */
10942 + unsigned int sethi, bajmpl, nop;
10943 +
10944 + err = get_user(sethi, (unsigned int *)regs->tpc);
10945 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10946 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10947 +
10948 + if (err)
10949 + break;
10950 +
10951 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10952 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10953 + nop == 0x01000000U)
10954 + {
10955 + unsigned long addr;
10956 +
10957 + addr = (sethi & 0x003FFFFFU) << 10;
10958 + regs->u_regs[UREG_G1] = addr;
10959 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10960 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10961 + else
10962 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10963 +
10964 + if (test_thread_flag(TIF_32BIT))
10965 + addr &= 0xFFFFFFFFUL;
10966 +
10967 + regs->tpc = addr;
10968 + regs->tnpc = addr+4;
10969 + return 2;
10970 + }
10971 + } while (0);
10972 +
10973 + do { /* PaX: patched PLT emulation #4 */
10974 + unsigned int sethi, mov1, call, mov2;
10975 +
10976 + err = get_user(sethi, (unsigned int *)regs->tpc);
10977 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10978 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
10979 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10980 +
10981 + if (err)
10982 + break;
10983 +
10984 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10985 + mov1 == 0x8210000FU &&
10986 + (call & 0xC0000000U) == 0x40000000U &&
10987 + mov2 == 0x9E100001U)
10988 + {
10989 + unsigned long addr;
10990 +
10991 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10992 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10993 +
10994 + if (test_thread_flag(TIF_32BIT))
10995 + addr &= 0xFFFFFFFFUL;
10996 +
10997 + regs->tpc = addr;
10998 + regs->tnpc = addr+4;
10999 + return 2;
11000 + }
11001 + } while (0);
11002 +
11003 + do { /* PaX: patched PLT emulation #5 */
11004 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11005 +
11006 + err = get_user(sethi, (unsigned int *)regs->tpc);
11007 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11008 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11009 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11010 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11011 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11012 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11013 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11014 +
11015 + if (err)
11016 + break;
11017 +
11018 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11019 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11020 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11021 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11022 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11023 + sllx == 0x83287020U &&
11024 + jmpl == 0x81C04005U &&
11025 + nop == 0x01000000U)
11026 + {
11027 + unsigned long addr;
11028 +
11029 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11030 + regs->u_regs[UREG_G1] <<= 32;
11031 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11032 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11033 + regs->tpc = addr;
11034 + regs->tnpc = addr+4;
11035 + return 2;
11036 + }
11037 + } while (0);
11038 +
11039 + do { /* PaX: patched PLT emulation #6 */
11040 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11041 +
11042 + err = get_user(sethi, (unsigned int *)regs->tpc);
11043 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11044 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11045 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11046 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11047 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11048 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11049 +
11050 + if (err)
11051 + break;
11052 +
11053 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11054 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11055 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11056 + sllx == 0x83287020U &&
11057 + (or & 0xFFFFE000U) == 0x8A116000U &&
11058 + jmpl == 0x81C04005U &&
11059 + nop == 0x01000000U)
11060 + {
11061 + unsigned long addr;
11062 +
11063 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11064 + regs->u_regs[UREG_G1] <<= 32;
11065 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11066 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11067 + regs->tpc = addr;
11068 + regs->tnpc = addr+4;
11069 + return 2;
11070 + }
11071 + } while (0);
11072 +
11073 + do { /* PaX: unpatched PLT emulation step 1 */
11074 + unsigned int sethi, ba, nop;
11075 +
11076 + err = get_user(sethi, (unsigned int *)regs->tpc);
11077 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11078 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11079 +
11080 + if (err)
11081 + break;
11082 +
11083 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11084 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11085 + nop == 0x01000000U)
11086 + {
11087 + unsigned long addr;
11088 + unsigned int save, call;
11089 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11090 +
11091 + if ((ba & 0xFFC00000U) == 0x30800000U)
11092 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11093 + else
11094 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11095 +
11096 + if (test_thread_flag(TIF_32BIT))
11097 + addr &= 0xFFFFFFFFUL;
11098 +
11099 + err = get_user(save, (unsigned int *)addr);
11100 + err |= get_user(call, (unsigned int *)(addr+4));
11101 + err |= get_user(nop, (unsigned int *)(addr+8));
11102 + if (err)
11103 + break;
11104 +
11105 +#ifdef CONFIG_PAX_DLRESOLVE
11106 + if (save == 0x9DE3BFA8U &&
11107 + (call & 0xC0000000U) == 0x40000000U &&
11108 + nop == 0x01000000U)
11109 + {
11110 + struct vm_area_struct *vma;
11111 + unsigned long call_dl_resolve;
11112 +
11113 + down_read(&current->mm->mmap_sem);
11114 + call_dl_resolve = current->mm->call_dl_resolve;
11115 + up_read(&current->mm->mmap_sem);
11116 + if (likely(call_dl_resolve))
11117 + goto emulate;
11118 +
11119 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11120 +
11121 + down_write(&current->mm->mmap_sem);
11122 + if (current->mm->call_dl_resolve) {
11123 + call_dl_resolve = current->mm->call_dl_resolve;
11124 + up_write(&current->mm->mmap_sem);
11125 + if (vma)
11126 + kmem_cache_free(vm_area_cachep, vma);
11127 + goto emulate;
11128 + }
11129 +
11130 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11131 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11132 + up_write(&current->mm->mmap_sem);
11133 + if (vma)
11134 + kmem_cache_free(vm_area_cachep, vma);
11135 + return 1;
11136 + }
11137 +
11138 + if (pax_insert_vma(vma, call_dl_resolve)) {
11139 + up_write(&current->mm->mmap_sem);
11140 + kmem_cache_free(vm_area_cachep, vma);
11141 + return 1;
11142 + }
11143 +
11144 + current->mm->call_dl_resolve = call_dl_resolve;
11145 + up_write(&current->mm->mmap_sem);
11146 +
11147 +emulate:
11148 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11149 + regs->tpc = call_dl_resolve;
11150 + regs->tnpc = addr+4;
11151 + return 3;
11152 + }
11153 +#endif
11154 +
11155 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11156 + if ((save & 0xFFC00000U) == 0x05000000U &&
11157 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11158 + nop == 0x01000000U)
11159 + {
11160 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11161 + regs->u_regs[UREG_G2] = addr + 4;
11162 + addr = (save & 0x003FFFFFU) << 10;
11163 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11164 +
11165 + if (test_thread_flag(TIF_32BIT))
11166 + addr &= 0xFFFFFFFFUL;
11167 +
11168 + regs->tpc = addr;
11169 + regs->tnpc = addr+4;
11170 + return 3;
11171 + }
11172 +
11173 + /* PaX: 64-bit PLT stub */
11174 + err = get_user(sethi1, (unsigned int *)addr);
11175 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11176 + err |= get_user(or1, (unsigned int *)(addr+8));
11177 + err |= get_user(or2, (unsigned int *)(addr+12));
11178 + err |= get_user(sllx, (unsigned int *)(addr+16));
11179 + err |= get_user(add, (unsigned int *)(addr+20));
11180 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11181 + err |= get_user(nop, (unsigned int *)(addr+28));
11182 + if (err)
11183 + break;
11184 +
11185 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11186 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11187 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11188 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11189 + sllx == 0x89293020U &&
11190 + add == 0x8A010005U &&
11191 + jmpl == 0x89C14000U &&
11192 + nop == 0x01000000U)
11193 + {
11194 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11195 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11196 + regs->u_regs[UREG_G4] <<= 32;
11197 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11198 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11199 + regs->u_regs[UREG_G4] = addr + 24;
11200 + addr = regs->u_regs[UREG_G5];
11201 + regs->tpc = addr;
11202 + regs->tnpc = addr+4;
11203 + return 3;
11204 + }
11205 + }
11206 + } while (0);
11207 +
11208 +#ifdef CONFIG_PAX_DLRESOLVE
11209 + do { /* PaX: unpatched PLT emulation step 2 */
11210 + unsigned int save, call, nop;
11211 +
11212 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11213 + err |= get_user(call, (unsigned int *)regs->tpc);
11214 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11215 + if (err)
11216 + break;
11217 +
11218 + if (save == 0x9DE3BFA8U &&
11219 + (call & 0xC0000000U) == 0x40000000U &&
11220 + nop == 0x01000000U)
11221 + {
11222 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11223 +
11224 + if (test_thread_flag(TIF_32BIT))
11225 + dl_resolve &= 0xFFFFFFFFUL;
11226 +
11227 + regs->u_regs[UREG_RETPC] = regs->tpc;
11228 + regs->tpc = dl_resolve;
11229 + regs->tnpc = dl_resolve+4;
11230 + return 3;
11231 + }
11232 + } while (0);
11233 +#endif
11234 +
11235 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11236 + unsigned int sethi, ba, nop;
11237 +
11238 + err = get_user(sethi, (unsigned int *)regs->tpc);
11239 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11240 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11241 +
11242 + if (err)
11243 + break;
11244 +
11245 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11246 + (ba & 0xFFF00000U) == 0x30600000U &&
11247 + nop == 0x01000000U)
11248 + {
11249 + unsigned long addr;
11250 +
11251 + addr = (sethi & 0x003FFFFFU) << 10;
11252 + regs->u_regs[UREG_G1] = addr;
11253 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11254 +
11255 + if (test_thread_flag(TIF_32BIT))
11256 + addr &= 0xFFFFFFFFUL;
11257 +
11258 + regs->tpc = addr;
11259 + regs->tnpc = addr+4;
11260 + return 2;
11261 + }
11262 + } while (0);
11263 +
11264 +#endif
11265 +
11266 + return 1;
11267 +}
11268 +
11269 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11270 +{
11271 + unsigned long i;
11272 +
11273 + printk(KERN_ERR "PAX: bytes at PC: ");
11274 + for (i = 0; i < 8; i++) {
11275 + unsigned int c;
11276 + if (get_user(c, (unsigned int *)pc+i))
11277 + printk(KERN_CONT "???????? ");
11278 + else
11279 + printk(KERN_CONT "%08x ", c);
11280 + }
11281 + printk("\n");
11282 +}
11283 +#endif
11284 +
11285 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11286 {
11287 enum ctx_state prev_state = exception_enter();
11288 @@ -344,6 +807,29 @@ retry:
11289 if (!vma)
11290 goto bad_area;
11291
11292 +#ifdef CONFIG_PAX_PAGEEXEC
11293 + /* PaX: detect ITLB misses on non-exec pages */
11294 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11295 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11296 + {
11297 + if (address != regs->tpc)
11298 + goto good_area;
11299 +
11300 + up_read(&mm->mmap_sem);
11301 + switch (pax_handle_fetch_fault(regs)) {
11302 +
11303 +#ifdef CONFIG_PAX_EMUPLT
11304 + case 2:
11305 + case 3:
11306 + return;
11307 +#endif
11308 +
11309 + }
11310 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11311 + do_group_exit(SIGKILL);
11312 + }
11313 +#endif
11314 +
11315 /* Pure DTLB misses do not tell us whether the fault causing
11316 * load/store/atomic was a write or not, it only says that there
11317 * was no match. So in such a case we (carefully) read the
11318 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11319 index 3096317..a7b7654 100644
11320 --- a/arch/sparc/mm/hugetlbpage.c
11321 +++ b/arch/sparc/mm/hugetlbpage.c
11322 @@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11323 unsigned long addr,
11324 unsigned long len,
11325 unsigned long pgoff,
11326 - unsigned long flags)
11327 + unsigned long flags,
11328 + unsigned long offset)
11329 {
11330 unsigned long task_size = TASK_SIZE;
11331 struct vm_unmapped_area_info info;
11332 @@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11333
11334 info.flags = 0;
11335 info.length = len;
11336 - info.low_limit = TASK_UNMAPPED_BASE;
11337 + info.low_limit = mm->mmap_base;
11338 info.high_limit = min(task_size, VA_EXCLUDE_START);
11339 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11340 info.align_offset = 0;
11341 + info.threadstack_offset = offset;
11342 addr = vm_unmapped_area(&info);
11343
11344 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11345 VM_BUG_ON(addr != -ENOMEM);
11346 info.low_limit = VA_EXCLUDE_END;
11347 +
11348 +#ifdef CONFIG_PAX_RANDMMAP
11349 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11350 + info.low_limit += mm->delta_mmap;
11351 +#endif
11352 +
11353 info.high_limit = task_size;
11354 addr = vm_unmapped_area(&info);
11355 }
11356 @@ -56,7 +64,8 @@ static unsigned long
11357 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11358 const unsigned long len,
11359 const unsigned long pgoff,
11360 - const unsigned long flags)
11361 + const unsigned long flags,
11362 + const unsigned long offset)
11363 {
11364 struct mm_struct *mm = current->mm;
11365 unsigned long addr = addr0;
11366 @@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11367 info.high_limit = mm->mmap_base;
11368 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11369 info.align_offset = 0;
11370 + info.threadstack_offset = offset;
11371 addr = vm_unmapped_area(&info);
11372
11373 /*
11374 @@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11375 VM_BUG_ON(addr != -ENOMEM);
11376 info.flags = 0;
11377 info.low_limit = TASK_UNMAPPED_BASE;
11378 +
11379 +#ifdef CONFIG_PAX_RANDMMAP
11380 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11381 + info.low_limit += mm->delta_mmap;
11382 +#endif
11383 +
11384 info.high_limit = STACK_TOP32;
11385 addr = vm_unmapped_area(&info);
11386 }
11387 @@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11388 struct mm_struct *mm = current->mm;
11389 struct vm_area_struct *vma;
11390 unsigned long task_size = TASK_SIZE;
11391 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11392
11393 if (test_thread_flag(TIF_32BIT))
11394 task_size = STACK_TOP32;
11395 @@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11396 return addr;
11397 }
11398
11399 +#ifdef CONFIG_PAX_RANDMMAP
11400 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11401 +#endif
11402 +
11403 if (addr) {
11404 addr = ALIGN(addr, HPAGE_SIZE);
11405 vma = find_vma(mm, addr);
11406 - if (task_size - len >= addr &&
11407 - (!vma || addr + len <= vma->vm_start))
11408 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11409 return addr;
11410 }
11411 if (mm->get_unmapped_area == arch_get_unmapped_area)
11412 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11413 - pgoff, flags);
11414 + pgoff, flags, offset);
11415 else
11416 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11417 - pgoff, flags);
11418 + pgoff, flags, offset);
11419 }
11420
11421 pte_t *huge_pte_alloc(struct mm_struct *mm,
11422 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11423 index 5322e53..f820c5e 100644
11424 --- a/arch/sparc/mm/init_64.c
11425 +++ b/arch/sparc/mm/init_64.c
11426 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11427 int num_kernel_image_mappings;
11428
11429 #ifdef CONFIG_DEBUG_DCFLUSH
11430 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11431 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11432 #ifdef CONFIG_SMP
11433 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11434 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11435 #endif
11436 #endif
11437
11438 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11439 {
11440 BUG_ON(tlb_type == hypervisor);
11441 #ifdef CONFIG_DEBUG_DCFLUSH
11442 - atomic_inc(&dcpage_flushes);
11443 + atomic_inc_unchecked(&dcpage_flushes);
11444 #endif
11445
11446 #ifdef DCACHE_ALIASING_POSSIBLE
11447 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11448
11449 #ifdef CONFIG_DEBUG_DCFLUSH
11450 seq_printf(m, "DCPageFlushes\t: %d\n",
11451 - atomic_read(&dcpage_flushes));
11452 + atomic_read_unchecked(&dcpage_flushes));
11453 #ifdef CONFIG_SMP
11454 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11455 - atomic_read(&dcpage_flushes_xcall));
11456 + atomic_read_unchecked(&dcpage_flushes_xcall));
11457 #endif /* CONFIG_SMP */
11458 #endif /* CONFIG_DEBUG_DCFLUSH */
11459 }
11460 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11461 index b3692ce..e4517c9 100644
11462 --- a/arch/tile/Kconfig
11463 +++ b/arch/tile/Kconfig
11464 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11465
11466 config KEXEC
11467 bool "kexec system call"
11468 + depends on !GRKERNSEC_KMEM
11469 ---help---
11470 kexec is a system call that implements the ability to shutdown your
11471 current kernel, and to start another kernel. It is like a reboot
11472 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11473 index ad220ee..2f537b3 100644
11474 --- a/arch/tile/include/asm/atomic_64.h
11475 +++ b/arch/tile/include/asm/atomic_64.h
11476 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11477
11478 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11479
11480 +#define atomic64_read_unchecked(v) atomic64_read(v)
11481 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11482 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11483 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11484 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11485 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11486 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11487 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11488 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11489 +
11490 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11491 #define smp_mb__before_atomic_dec() smp_mb()
11492 #define smp_mb__after_atomic_dec() smp_mb()
11493 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11494 index 6160761..00cac88 100644
11495 --- a/arch/tile/include/asm/cache.h
11496 +++ b/arch/tile/include/asm/cache.h
11497 @@ -15,11 +15,12 @@
11498 #ifndef _ASM_TILE_CACHE_H
11499 #define _ASM_TILE_CACHE_H
11500
11501 +#include <linux/const.h>
11502 #include <arch/chip.h>
11503
11504 /* bytes per L1 data cache line */
11505 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11506 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11508
11509 /* bytes per L2 cache line */
11510 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11511 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11512 index b6cde32..c0cb736 100644
11513 --- a/arch/tile/include/asm/uaccess.h
11514 +++ b/arch/tile/include/asm/uaccess.h
11515 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11516 const void __user *from,
11517 unsigned long n)
11518 {
11519 - int sz = __compiletime_object_size(to);
11520 + size_t sz = __compiletime_object_size(to);
11521
11522 - if (likely(sz == -1 || sz >= n))
11523 + if (likely(sz == (size_t)-1 || sz >= n))
11524 n = _copy_from_user(to, from, n);
11525 else
11526 copy_from_user_overflow();
11527 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11528 index 0cb3bba..7338b2d 100644
11529 --- a/arch/tile/mm/hugetlbpage.c
11530 +++ b/arch/tile/mm/hugetlbpage.c
11531 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11532 info.high_limit = TASK_SIZE;
11533 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11534 info.align_offset = 0;
11535 + info.threadstack_offset = 0;
11536 return vm_unmapped_area(&info);
11537 }
11538
11539 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11540 info.high_limit = current->mm->mmap_base;
11541 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11542 info.align_offset = 0;
11543 + info.threadstack_offset = 0;
11544 addr = vm_unmapped_area(&info);
11545
11546 /*
11547 diff --git a/arch/um/Makefile b/arch/um/Makefile
11548 index 36e658a..71a5c5a 100644
11549 --- a/arch/um/Makefile
11550 +++ b/arch/um/Makefile
11551 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11552 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11553 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11554
11555 +ifdef CONSTIFY_PLUGIN
11556 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11557 +endif
11558 +
11559 #This will adjust *FLAGS accordingly to the platform.
11560 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11561
11562 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11563 index 19e1bdd..3665b77 100644
11564 --- a/arch/um/include/asm/cache.h
11565 +++ b/arch/um/include/asm/cache.h
11566 @@ -1,6 +1,7 @@
11567 #ifndef __UM_CACHE_H
11568 #define __UM_CACHE_H
11569
11570 +#include <linux/const.h>
11571
11572 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11573 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11574 @@ -12,6 +13,6 @@
11575 # define L1_CACHE_SHIFT 5
11576 #endif
11577
11578 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11579 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11580
11581 #endif
11582 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11583 index 2e0a6b1..a64d0f5 100644
11584 --- a/arch/um/include/asm/kmap_types.h
11585 +++ b/arch/um/include/asm/kmap_types.h
11586 @@ -8,6 +8,6 @@
11587
11588 /* No more #include "asm/arch/kmap_types.h" ! */
11589
11590 -#define KM_TYPE_NR 14
11591 +#define KM_TYPE_NR 15
11592
11593 #endif
11594 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11595 index 5ff53d9..5850cdf 100644
11596 --- a/arch/um/include/asm/page.h
11597 +++ b/arch/um/include/asm/page.h
11598 @@ -14,6 +14,9 @@
11599 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11600 #define PAGE_MASK (~(PAGE_SIZE-1))
11601
11602 +#define ktla_ktva(addr) (addr)
11603 +#define ktva_ktla(addr) (addr)
11604 +
11605 #ifndef __ASSEMBLY__
11606
11607 struct page;
11608 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11609 index 0032f92..cd151e0 100644
11610 --- a/arch/um/include/asm/pgtable-3level.h
11611 +++ b/arch/um/include/asm/pgtable-3level.h
11612 @@ -58,6 +58,7 @@
11613 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11614 #define pud_populate(mm, pud, pmd) \
11615 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11616 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11617
11618 #ifdef CONFIG_64BIT
11619 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11620 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11621 index eecc414..48adb87 100644
11622 --- a/arch/um/kernel/process.c
11623 +++ b/arch/um/kernel/process.c
11624 @@ -356,22 +356,6 @@ int singlestepping(void * t)
11625 return 2;
11626 }
11627
11628 -/*
11629 - * Only x86 and x86_64 have an arch_align_stack().
11630 - * All other arches have "#define arch_align_stack(x) (x)"
11631 - * in their asm/system.h
11632 - * As this is included in UML from asm-um/system-generic.h,
11633 - * we can use it to behave as the subarch does.
11634 - */
11635 -#ifndef arch_align_stack
11636 -unsigned long arch_align_stack(unsigned long sp)
11637 -{
11638 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11639 - sp -= get_random_int() % 8192;
11640 - return sp & ~0xf;
11641 -}
11642 -#endif
11643 -
11644 unsigned long get_wchan(struct task_struct *p)
11645 {
11646 unsigned long stack_page, sp, ip;
11647 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11648 index ad8f795..2c7eec6 100644
11649 --- a/arch/unicore32/include/asm/cache.h
11650 +++ b/arch/unicore32/include/asm/cache.h
11651 @@ -12,8 +12,10 @@
11652 #ifndef __UNICORE_CACHE_H__
11653 #define __UNICORE_CACHE_H__
11654
11655 -#define L1_CACHE_SHIFT (5)
11656 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11657 +#include <linux/const.h>
11658 +
11659 +#define L1_CACHE_SHIFT 5
11660 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11661
11662 /*
11663 * Memory returned by kmalloc() may be used for DMA, so we must make
11664 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11665 index 0952ecd..75e0e8a 100644
11666 --- a/arch/x86/Kconfig
11667 +++ b/arch/x86/Kconfig
11668 @@ -249,7 +249,7 @@ config X86_HT
11669
11670 config X86_32_LAZY_GS
11671 def_bool y
11672 - depends on X86_32 && !CC_STACKPROTECTOR
11673 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11674
11675 config ARCH_HWEIGHT_CFLAGS
11676 string
11677 @@ -1104,6 +1104,7 @@ config MICROCODE_EARLY
11678
11679 config X86_MSR
11680 tristate "/dev/cpu/*/msr - Model-specific register support"
11681 + depends on !GRKERNSEC_KMEM
11682 ---help---
11683 This device gives privileged processes access to the x86
11684 Model-Specific Registers (MSRs). It is a character device with
11685 @@ -1127,7 +1128,7 @@ choice
11686
11687 config NOHIGHMEM
11688 bool "off"
11689 - depends on !X86_NUMAQ
11690 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11691 ---help---
11692 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11693 However, the address space of 32-bit x86 processors is only 4
11694 @@ -1164,7 +1165,7 @@ config NOHIGHMEM
11695
11696 config HIGHMEM4G
11697 bool "4GB"
11698 - depends on !X86_NUMAQ
11699 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11700 ---help---
11701 Select this if you have a 32-bit processor and between 1 and 4
11702 gigabytes of physical RAM.
11703 @@ -1217,7 +1218,7 @@ config PAGE_OFFSET
11704 hex
11705 default 0xB0000000 if VMSPLIT_3G_OPT
11706 default 0x80000000 if VMSPLIT_2G
11707 - default 0x78000000 if VMSPLIT_2G_OPT
11708 + default 0x70000000 if VMSPLIT_2G_OPT
11709 default 0x40000000 if VMSPLIT_1G
11710 default 0xC0000000
11711 depends on X86_32
11712 @@ -1619,6 +1620,7 @@ config SECCOMP
11713
11714 config CC_STACKPROTECTOR
11715 bool "Enable -fstack-protector buffer overflow detection"
11716 + depends on X86_64 || !PAX_MEMORY_UDEREF
11717 ---help---
11718 This option turns on the -fstack-protector GCC feature. This
11719 feature puts, at the beginning of functions, a canary value on
11720 @@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
11721
11722 config KEXEC
11723 bool "kexec system call"
11724 + depends on !GRKERNSEC_KMEM
11725 ---help---
11726 kexec is a system call that implements the ability to shutdown your
11727 current kernel, and to start another kernel. It is like a reboot
11728 @@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
11729 config PHYSICAL_ALIGN
11730 hex "Alignment value to which kernel should be aligned"
11731 default "0x1000000"
11732 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11733 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11734 range 0x2000 0x1000000 if X86_32
11735 range 0x200000 0x1000000 if X86_64
11736 ---help---
11737 @@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
11738 If unsure, say N.
11739
11740 config COMPAT_VDSO
11741 - def_bool y
11742 + def_bool n
11743 prompt "Compat VDSO support"
11744 depends on X86_32 || IA32_EMULATION
11745 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11746 ---help---
11747 Map the 32-bit VDSO to the predictable old-style address too.
11748
11749 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11750 index c026cca..14657ae 100644
11751 --- a/arch/x86/Kconfig.cpu
11752 +++ b/arch/x86/Kconfig.cpu
11753 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11754
11755 config X86_F00F_BUG
11756 def_bool y
11757 - depends on M586MMX || M586TSC || M586 || M486
11758 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11759
11760 config X86_INVD_BUG
11761 def_bool y
11762 @@ -327,7 +327,7 @@ config X86_INVD_BUG
11763
11764 config X86_ALIGNMENT_16
11765 def_bool y
11766 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11767 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11768
11769 config X86_INTEL_USERCOPY
11770 def_bool y
11771 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
11772 # generates cmov.
11773 config X86_CMOV
11774 def_bool y
11775 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11776 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11777
11778 config X86_MINIMUM_CPU_FAMILY
11779 int
11780 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11781 index 0f3621e..282f24b 100644
11782 --- a/arch/x86/Kconfig.debug
11783 +++ b/arch/x86/Kconfig.debug
11784 @@ -84,7 +84,7 @@ config X86_PTDUMP
11785 config DEBUG_RODATA
11786 bool "Write protect kernel read-only data structures"
11787 default y
11788 - depends on DEBUG_KERNEL
11789 + depends on DEBUG_KERNEL && BROKEN
11790 ---help---
11791 Mark the kernel read-only data as write-protected in the pagetables,
11792 in order to catch accidental (and incorrect) writes to such const
11793 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
11794
11795 config DEBUG_SET_MODULE_RONX
11796 bool "Set loadable kernel module data as NX and text as RO"
11797 - depends on MODULES
11798 + depends on MODULES && BROKEN
11799 ---help---
11800 This option helps catch unintended modifications to loadable
11801 kernel module's text and read-only data. It also prevents execution
11802 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11803 index 57d0215..b4373fb 100644
11804 --- a/arch/x86/Makefile
11805 +++ b/arch/x86/Makefile
11806 @@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
11807 # CPU-specific tuning. Anything which can be shared with UML should go here.
11808 include $(srctree)/arch/x86/Makefile_32.cpu
11809 KBUILD_CFLAGS += $(cflags-y)
11810 -
11811 - # temporary until string.h is fixed
11812 - KBUILD_CFLAGS += -ffreestanding
11813 else
11814 BITS := 64
11815 UTS_MACHINE := x86_64
11816 CHECKFLAGS += -D__x86_64__ -m64
11817
11818 + biarch := $(call cc-option,-m64)
11819 KBUILD_AFLAGS += -m64
11820 KBUILD_CFLAGS += -m64
11821
11822 @@ -89,6 +87,9 @@ else
11823 KBUILD_CFLAGS += -maccumulate-outgoing-args
11824 endif
11825
11826 +# temporary until string.h is fixed
11827 +KBUILD_CFLAGS += -ffreestanding
11828 +
11829 ifdef CONFIG_CC_STACKPROTECTOR
11830 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11831 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11832 @@ -247,3 +248,12 @@ define archhelp
11833 echo ' FDINITRD=file initrd for the booted kernel'
11834 echo ' kvmconfig - Enable additional options for guest kernel support'
11835 endef
11836 +
11837 +define OLD_LD
11838 +
11839 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11840 +*** Please upgrade your binutils to 2.18 or newer
11841 +endef
11842 +
11843 +archprepare:
11844 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11845 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11846 index d9c1195..a26ca0d 100644
11847 --- a/arch/x86/boot/Makefile
11848 +++ b/arch/x86/boot/Makefile
11849 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
11850 $(call cc-option, -fno-unit-at-a-time)) \
11851 $(call cc-option, -fno-stack-protector) \
11852 $(call cc-option, -mpreferred-stack-boundary=2)
11853 +ifdef CONSTIFY_PLUGIN
11854 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11855 +endif
11856 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11857 GCOV_PROFILE := n
11858
11859 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11860 index 878e4b9..20537ab 100644
11861 --- a/arch/x86/boot/bitops.h
11862 +++ b/arch/x86/boot/bitops.h
11863 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11864 u8 v;
11865 const u32 *p = (const u32 *)addr;
11866
11867 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11868 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11869 return v;
11870 }
11871
11872 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11873
11874 static inline void set_bit(int nr, void *addr)
11875 {
11876 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11877 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11878 }
11879
11880 #endif /* BOOT_BITOPS_H */
11881 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11882 index ef72bae..353a184 100644
11883 --- a/arch/x86/boot/boot.h
11884 +++ b/arch/x86/boot/boot.h
11885 @@ -85,7 +85,7 @@ static inline void io_delay(void)
11886 static inline u16 ds(void)
11887 {
11888 u16 seg;
11889 - asm("movw %%ds,%0" : "=rm" (seg));
11890 + asm volatile("movw %%ds,%0" : "=rm" (seg));
11891 return seg;
11892 }
11893
11894 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11895 static inline int memcmp(const void *s1, const void *s2, size_t len)
11896 {
11897 u8 diff;
11898 - asm("repe; cmpsb; setnz %0"
11899 + asm volatile("repe; cmpsb; setnz %0"
11900 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11901 return diff;
11902 }
11903 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11904 index c8a6792..2402765 100644
11905 --- a/arch/x86/boot/compressed/Makefile
11906 +++ b/arch/x86/boot/compressed/Makefile
11907 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
11908 KBUILD_CFLAGS += -mno-mmx -mno-sse
11909 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11910 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11911 +ifdef CONSTIFY_PLUGIN
11912 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11913 +endif
11914
11915 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11916 GCOV_PROFILE := n
11917 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11918 index a53440e..c3dbf1e 100644
11919 --- a/arch/x86/boot/compressed/efi_stub_32.S
11920 +++ b/arch/x86/boot/compressed/efi_stub_32.S
11921 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11922 * parameter 2, ..., param n. To make things easy, we save the return
11923 * address of efi_call_phys in a global variable.
11924 */
11925 - popl %ecx
11926 - movl %ecx, saved_return_addr(%edx)
11927 - /* get the function pointer into ECX*/
11928 - popl %ecx
11929 - movl %ecx, efi_rt_function_ptr(%edx)
11930 + popl saved_return_addr(%edx)
11931 + popl efi_rt_function_ptr(%edx)
11932
11933 /*
11934 * 3. Call the physical function.
11935 */
11936 - call *%ecx
11937 + call *efi_rt_function_ptr(%edx)
11938
11939 /*
11940 * 4. Balance the stack. And because EAX contain the return value,
11941 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11942 1: popl %edx
11943 subl $1b, %edx
11944
11945 - movl efi_rt_function_ptr(%edx), %ecx
11946 - pushl %ecx
11947 + pushl efi_rt_function_ptr(%edx)
11948
11949 /*
11950 * 10. Push the saved return address onto the stack and return.
11951 */
11952 - movl saved_return_addr(%edx), %ecx
11953 - pushl %ecx
11954 - ret
11955 + jmpl *saved_return_addr(%edx)
11956 ENDPROC(efi_call_phys)
11957 .previous
11958
11959 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11960 index 5d6f689..9d06730 100644
11961 --- a/arch/x86/boot/compressed/head_32.S
11962 +++ b/arch/x86/boot/compressed/head_32.S
11963 @@ -118,7 +118,7 @@ preferred_addr:
11964 notl %eax
11965 andl %eax, %ebx
11966 #else
11967 - movl $LOAD_PHYSICAL_ADDR, %ebx
11968 + movl $____LOAD_PHYSICAL_ADDR, %ebx
11969 #endif
11970
11971 /* Target address to relocate to for decompression */
11972 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11973 index c337422..2c5be72 100644
11974 --- a/arch/x86/boot/compressed/head_64.S
11975 +++ b/arch/x86/boot/compressed/head_64.S
11976 @@ -95,7 +95,7 @@ ENTRY(startup_32)
11977 notl %eax
11978 andl %eax, %ebx
11979 #else
11980 - movl $LOAD_PHYSICAL_ADDR, %ebx
11981 + movl $____LOAD_PHYSICAL_ADDR, %ebx
11982 #endif
11983
11984 /* Target address to relocate to for decompression */
11985 @@ -270,7 +270,7 @@ preferred_addr:
11986 notq %rax
11987 andq %rax, %rbp
11988 #else
11989 - movq $LOAD_PHYSICAL_ADDR, %rbp
11990 + movq $____LOAD_PHYSICAL_ADDR, %rbp
11991 #endif
11992
11993 /* Target address to relocate to for decompression */
11994 @@ -362,8 +362,8 @@ gdt:
11995 .long gdt
11996 .word 0
11997 .quad 0x0000000000000000 /* NULL descriptor */
11998 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
11999 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12000 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12001 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12002 .quad 0x0080890000000000 /* TS descriptor */
12003 .quad 0x0000000000000000 /* TS continued */
12004 gdt_end:
12005 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12006 index 434f077..b6b4b38 100644
12007 --- a/arch/x86/boot/compressed/misc.c
12008 +++ b/arch/x86/boot/compressed/misc.c
12009 @@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12010 * Calculate the delta between where vmlinux was linked to load
12011 * and where it was actually loaded.
12012 */
12013 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12014 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12015 if (!delta) {
12016 debug_putstr("No relocation needed... ");
12017 return;
12018 @@ -380,7 +380,7 @@ static void parse_elf(void *output)
12019 case PT_LOAD:
12020 #ifdef CONFIG_RELOCATABLE
12021 dest = output;
12022 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12023 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12024 #else
12025 dest = (void *)(phdr->p_paddr);
12026 #endif
12027 @@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12028 error("Destination address too large");
12029 #endif
12030 #ifndef CONFIG_RELOCATABLE
12031 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12032 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12033 error("Wrong destination address");
12034 #endif
12035
12036 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12037 index 4d3ff03..e4972ff 100644
12038 --- a/arch/x86/boot/cpucheck.c
12039 +++ b/arch/x86/boot/cpucheck.c
12040 @@ -74,7 +74,7 @@ static int has_fpu(void)
12041 u16 fcw = -1, fsw = -1;
12042 u32 cr0;
12043
12044 - asm("movl %%cr0,%0" : "=r" (cr0));
12045 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
12046 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12047 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12048 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12049 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12050 {
12051 u32 f0, f1;
12052
12053 - asm("pushfl ; "
12054 + asm volatile("pushfl ; "
12055 "pushfl ; "
12056 "popl %0 ; "
12057 "movl %0,%1 ; "
12058 @@ -115,7 +115,7 @@ static void get_flags(void)
12059 set_bit(X86_FEATURE_FPU, cpu.flags);
12060
12061 if (has_eflag(X86_EFLAGS_ID)) {
12062 - asm("cpuid"
12063 + asm volatile("cpuid"
12064 : "=a" (max_intel_level),
12065 "=b" (cpu_vendor[0]),
12066 "=d" (cpu_vendor[1]),
12067 @@ -124,7 +124,7 @@ static void get_flags(void)
12068
12069 if (max_intel_level >= 0x00000001 &&
12070 max_intel_level <= 0x0000ffff) {
12071 - asm("cpuid"
12072 + asm volatile("cpuid"
12073 : "=a" (tfms),
12074 "=c" (cpu.flags[4]),
12075 "=d" (cpu.flags[0])
12076 @@ -136,7 +136,7 @@ static void get_flags(void)
12077 cpu.model += ((tfms >> 16) & 0xf) << 4;
12078 }
12079
12080 - asm("cpuid"
12081 + asm volatile("cpuid"
12082 : "=a" (max_amd_level)
12083 : "a" (0x80000000)
12084 : "ebx", "ecx", "edx");
12085 @@ -144,7 +144,7 @@ static void get_flags(void)
12086 if (max_amd_level >= 0x80000001 &&
12087 max_amd_level <= 0x8000ffff) {
12088 u32 eax = 0x80000001;
12089 - asm("cpuid"
12090 + asm volatile("cpuid"
12091 : "+a" (eax),
12092 "=c" (cpu.flags[6]),
12093 "=d" (cpu.flags[1])
12094 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12095 u32 ecx = MSR_K7_HWCR;
12096 u32 eax, edx;
12097
12098 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12099 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12100 eax &= ~(1 << 15);
12101 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12102 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12103
12104 get_flags(); /* Make sure it really did something */
12105 err = check_flags();
12106 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12107 u32 ecx = MSR_VIA_FCR;
12108 u32 eax, edx;
12109
12110 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12111 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12112 eax |= (1<<1)|(1<<7);
12113 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12114 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12115
12116 set_bit(X86_FEATURE_CX8, cpu.flags);
12117 err = check_flags();
12118 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12119 u32 eax, edx;
12120 u32 level = 1;
12121
12122 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12123 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12124 - asm("cpuid"
12125 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12126 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12127 + asm volatile("cpuid"
12128 : "+a" (level), "=d" (cpu.flags[0])
12129 : : "ecx", "ebx");
12130 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12131 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12132
12133 err = check_flags();
12134 }
12135 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12136 index 9ec06a1..2c25e79 100644
12137 --- a/arch/x86/boot/header.S
12138 +++ b/arch/x86/boot/header.S
12139 @@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12140 # single linked list of
12141 # struct setup_data
12142
12143 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12144 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12145
12146 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12147 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12148 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12149 +#else
12150 #define VO_INIT_SIZE (VO__end - VO__text)
12151 +#endif
12152 #if ZO_INIT_SIZE > VO_INIT_SIZE
12153 #define INIT_SIZE ZO_INIT_SIZE
12154 #else
12155 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12156 index db75d07..8e6d0af 100644
12157 --- a/arch/x86/boot/memory.c
12158 +++ b/arch/x86/boot/memory.c
12159 @@ -19,7 +19,7 @@
12160
12161 static int detect_memory_e820(void)
12162 {
12163 - int count = 0;
12164 + unsigned int count = 0;
12165 struct biosregs ireg, oreg;
12166 struct e820entry *desc = boot_params.e820_map;
12167 static struct e820entry buf; /* static so it is zeroed */
12168 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12169 index 11e8c6e..fdbb1ed 100644
12170 --- a/arch/x86/boot/video-vesa.c
12171 +++ b/arch/x86/boot/video-vesa.c
12172 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12173
12174 boot_params.screen_info.vesapm_seg = oreg.es;
12175 boot_params.screen_info.vesapm_off = oreg.di;
12176 + boot_params.screen_info.vesapm_size = oreg.cx;
12177 }
12178
12179 /*
12180 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12181 index 43eda28..5ab5fdb 100644
12182 --- a/arch/x86/boot/video.c
12183 +++ b/arch/x86/boot/video.c
12184 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12185 static unsigned int get_entry(void)
12186 {
12187 char entry_buf[4];
12188 - int i, len = 0;
12189 + unsigned int i, len = 0;
12190 int key;
12191 unsigned int v;
12192
12193 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12194 index 9105655..41779c1 100644
12195 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12196 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12197 @@ -8,6 +8,8 @@
12198 * including this sentence is retained in full.
12199 */
12200
12201 +#include <asm/alternative-asm.h>
12202 +
12203 .extern crypto_ft_tab
12204 .extern crypto_it_tab
12205 .extern crypto_fl_tab
12206 @@ -70,6 +72,8 @@
12207 je B192; \
12208 leaq 32(r9),r9;
12209
12210 +#define ret pax_force_retaddr; ret
12211 +
12212 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12213 movq r1,r2; \
12214 movq r3,r4; \
12215 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12216 index 477e9d7..c92c7d8 100644
12217 --- a/arch/x86/crypto/aesni-intel_asm.S
12218 +++ b/arch/x86/crypto/aesni-intel_asm.S
12219 @@ -31,6 +31,7 @@
12220
12221 #include <linux/linkage.h>
12222 #include <asm/inst.h>
12223 +#include <asm/alternative-asm.h>
12224
12225 #ifdef __x86_64__
12226 .data
12227 @@ -205,7 +206,7 @@ enc: .octa 0x2
12228 * num_initial_blocks = b mod 4
12229 * encrypt the initial num_initial_blocks blocks and apply ghash on
12230 * the ciphertext
12231 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12232 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12233 * are clobbered
12234 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12235 */
12236 @@ -214,8 +215,8 @@ enc: .octa 0x2
12237 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12238 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12239 mov arg7, %r10 # %r10 = AAD
12240 - mov arg8, %r12 # %r12 = aadLen
12241 - mov %r12, %r11
12242 + mov arg8, %r15 # %r15 = aadLen
12243 + mov %r15, %r11
12244 pxor %xmm\i, %xmm\i
12245 _get_AAD_loop\num_initial_blocks\operation:
12246 movd (%r10), \TMP1
12247 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12248 psrldq $4, %xmm\i
12249 pxor \TMP1, %xmm\i
12250 add $4, %r10
12251 - sub $4, %r12
12252 + sub $4, %r15
12253 jne _get_AAD_loop\num_initial_blocks\operation
12254 cmp $16, %r11
12255 je _get_AAD_loop2_done\num_initial_blocks\operation
12256 - mov $16, %r12
12257 + mov $16, %r15
12258 _get_AAD_loop2\num_initial_blocks\operation:
12259 psrldq $4, %xmm\i
12260 - sub $4, %r12
12261 - cmp %r11, %r12
12262 + sub $4, %r15
12263 + cmp %r11, %r15
12264 jne _get_AAD_loop2\num_initial_blocks\operation
12265 _get_AAD_loop2_done\num_initial_blocks\operation:
12266 movdqa SHUF_MASK(%rip), %xmm14
12267 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12268 * num_initial_blocks = b mod 4
12269 * encrypt the initial num_initial_blocks blocks and apply ghash on
12270 * the ciphertext
12271 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12272 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12273 * are clobbered
12274 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12275 */
12276 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12277 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12278 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12279 mov arg7, %r10 # %r10 = AAD
12280 - mov arg8, %r12 # %r12 = aadLen
12281 - mov %r12, %r11
12282 + mov arg8, %r15 # %r15 = aadLen
12283 + mov %r15, %r11
12284 pxor %xmm\i, %xmm\i
12285 _get_AAD_loop\num_initial_blocks\operation:
12286 movd (%r10), \TMP1
12287 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12288 psrldq $4, %xmm\i
12289 pxor \TMP1, %xmm\i
12290 add $4, %r10
12291 - sub $4, %r12
12292 + sub $4, %r15
12293 jne _get_AAD_loop\num_initial_blocks\operation
12294 cmp $16, %r11
12295 je _get_AAD_loop2_done\num_initial_blocks\operation
12296 - mov $16, %r12
12297 + mov $16, %r15
12298 _get_AAD_loop2\num_initial_blocks\operation:
12299 psrldq $4, %xmm\i
12300 - sub $4, %r12
12301 - cmp %r11, %r12
12302 + sub $4, %r15
12303 + cmp %r11, %r15
12304 jne _get_AAD_loop2\num_initial_blocks\operation
12305 _get_AAD_loop2_done\num_initial_blocks\operation:
12306 movdqa SHUF_MASK(%rip), %xmm14
12307 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12308 *
12309 *****************************************************************************/
12310 ENTRY(aesni_gcm_dec)
12311 - push %r12
12312 + push %r15
12313 push %r13
12314 push %r14
12315 mov %rsp, %r14
12316 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12317 */
12318 sub $VARIABLE_OFFSET, %rsp
12319 and $~63, %rsp # align rsp to 64 bytes
12320 - mov %arg6, %r12
12321 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12322 + mov %arg6, %r15
12323 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12324 movdqa SHUF_MASK(%rip), %xmm2
12325 PSHUFB_XMM %xmm2, %xmm13
12326
12327 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12328 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12329 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12330 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12331 - mov %r13, %r12
12332 - and $(3<<4), %r12
12333 + mov %r13, %r15
12334 + and $(3<<4), %r15
12335 jz _initial_num_blocks_is_0_decrypt
12336 - cmp $(2<<4), %r12
12337 + cmp $(2<<4), %r15
12338 jb _initial_num_blocks_is_1_decrypt
12339 je _initial_num_blocks_is_2_decrypt
12340 _initial_num_blocks_is_3_decrypt:
12341 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12342 sub $16, %r11
12343 add %r13, %r11
12344 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12345 - lea SHIFT_MASK+16(%rip), %r12
12346 - sub %r13, %r12
12347 + lea SHIFT_MASK+16(%rip), %r15
12348 + sub %r13, %r15
12349 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12350 # (%r13 is the number of bytes in plaintext mod 16)
12351 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12352 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12353 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12354
12355 movdqa %xmm1, %xmm2
12356 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12357 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12358 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12359 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12360 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12361 pand %xmm1, %xmm2
12362 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12363 sub $1, %r13
12364 jne _less_than_8_bytes_left_decrypt
12365 _multiple_of_16_bytes_decrypt:
12366 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12367 - shl $3, %r12 # convert into number of bits
12368 - movd %r12d, %xmm15 # len(A) in %xmm15
12369 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12370 + shl $3, %r15 # convert into number of bits
12371 + movd %r15d, %xmm15 # len(A) in %xmm15
12372 shl $3, %arg4 # len(C) in bits (*128)
12373 MOVQ_R64_XMM %arg4, %xmm1
12374 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12375 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12376 mov %r14, %rsp
12377 pop %r14
12378 pop %r13
12379 - pop %r12
12380 + pop %r15
12381 + pax_force_retaddr
12382 ret
12383 ENDPROC(aesni_gcm_dec)
12384
12385 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12386 * poly = x^128 + x^127 + x^126 + x^121 + 1
12387 ***************************************************************************/
12388 ENTRY(aesni_gcm_enc)
12389 - push %r12
12390 + push %r15
12391 push %r13
12392 push %r14
12393 mov %rsp, %r14
12394 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12395 #
12396 sub $VARIABLE_OFFSET, %rsp
12397 and $~63, %rsp
12398 - mov %arg6, %r12
12399 - movdqu (%r12), %xmm13
12400 + mov %arg6, %r15
12401 + movdqu (%r15), %xmm13
12402 movdqa SHUF_MASK(%rip), %xmm2
12403 PSHUFB_XMM %xmm2, %xmm13
12404
12405 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12406 movdqa %xmm13, HashKey(%rsp)
12407 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12408 and $-16, %r13
12409 - mov %r13, %r12
12410 + mov %r13, %r15
12411
12412 # Encrypt first few blocks
12413
12414 - and $(3<<4), %r12
12415 + and $(3<<4), %r15
12416 jz _initial_num_blocks_is_0_encrypt
12417 - cmp $(2<<4), %r12
12418 + cmp $(2<<4), %r15
12419 jb _initial_num_blocks_is_1_encrypt
12420 je _initial_num_blocks_is_2_encrypt
12421 _initial_num_blocks_is_3_encrypt:
12422 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12423 sub $16, %r11
12424 add %r13, %r11
12425 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12426 - lea SHIFT_MASK+16(%rip), %r12
12427 - sub %r13, %r12
12428 + lea SHIFT_MASK+16(%rip), %r15
12429 + sub %r13, %r15
12430 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12431 # (%r13 is the number of bytes in plaintext mod 16)
12432 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12433 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12434 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12435 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12436 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12437 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12438 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12439 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12440 movdqa SHUF_MASK(%rip), %xmm10
12441 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12442 sub $1, %r13
12443 jne _less_than_8_bytes_left_encrypt
12444 _multiple_of_16_bytes_encrypt:
12445 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12446 - shl $3, %r12
12447 - movd %r12d, %xmm15 # len(A) in %xmm15
12448 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12449 + shl $3, %r15
12450 + movd %r15d, %xmm15 # len(A) in %xmm15
12451 shl $3, %arg4 # len(C) in bits (*128)
12452 MOVQ_R64_XMM %arg4, %xmm1
12453 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12454 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12455 mov %r14, %rsp
12456 pop %r14
12457 pop %r13
12458 - pop %r12
12459 + pop %r15
12460 + pax_force_retaddr
12461 ret
12462 ENDPROC(aesni_gcm_enc)
12463
12464 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12465 pxor %xmm1, %xmm0
12466 movaps %xmm0, (TKEYP)
12467 add $0x10, TKEYP
12468 + pax_force_retaddr
12469 ret
12470 ENDPROC(_key_expansion_128)
12471 ENDPROC(_key_expansion_256a)
12472 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12473 shufps $0b01001110, %xmm2, %xmm1
12474 movaps %xmm1, 0x10(TKEYP)
12475 add $0x20, TKEYP
12476 + pax_force_retaddr
12477 ret
12478 ENDPROC(_key_expansion_192a)
12479
12480 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
12481
12482 movaps %xmm0, (TKEYP)
12483 add $0x10, TKEYP
12484 + pax_force_retaddr
12485 ret
12486 ENDPROC(_key_expansion_192b)
12487
12488 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
12489 pxor %xmm1, %xmm2
12490 movaps %xmm2, (TKEYP)
12491 add $0x10, TKEYP
12492 + pax_force_retaddr
12493 ret
12494 ENDPROC(_key_expansion_256b)
12495
12496 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12497 #ifndef __x86_64__
12498 popl KEYP
12499 #endif
12500 + pax_force_retaddr
12501 ret
12502 ENDPROC(aesni_set_key)
12503
12504 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12505 popl KLEN
12506 popl KEYP
12507 #endif
12508 + pax_force_retaddr
12509 ret
12510 ENDPROC(aesni_enc)
12511
12512 @@ -1974,6 +1983,7 @@ _aesni_enc1:
12513 AESENC KEY STATE
12514 movaps 0x70(TKEYP), KEY
12515 AESENCLAST KEY STATE
12516 + pax_force_retaddr
12517 ret
12518 ENDPROC(_aesni_enc1)
12519
12520 @@ -2083,6 +2093,7 @@ _aesni_enc4:
12521 AESENCLAST KEY STATE2
12522 AESENCLAST KEY STATE3
12523 AESENCLAST KEY STATE4
12524 + pax_force_retaddr
12525 ret
12526 ENDPROC(_aesni_enc4)
12527
12528 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12529 popl KLEN
12530 popl KEYP
12531 #endif
12532 + pax_force_retaddr
12533 ret
12534 ENDPROC(aesni_dec)
12535
12536 @@ -2164,6 +2176,7 @@ _aesni_dec1:
12537 AESDEC KEY STATE
12538 movaps 0x70(TKEYP), KEY
12539 AESDECLAST KEY STATE
12540 + pax_force_retaddr
12541 ret
12542 ENDPROC(_aesni_dec1)
12543
12544 @@ -2273,6 +2286,7 @@ _aesni_dec4:
12545 AESDECLAST KEY STATE2
12546 AESDECLAST KEY STATE3
12547 AESDECLAST KEY STATE4
12548 + pax_force_retaddr
12549 ret
12550 ENDPROC(_aesni_dec4)
12551
12552 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12553 popl KEYP
12554 popl LEN
12555 #endif
12556 + pax_force_retaddr
12557 ret
12558 ENDPROC(aesni_ecb_enc)
12559
12560 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12561 popl KEYP
12562 popl LEN
12563 #endif
12564 + pax_force_retaddr
12565 ret
12566 ENDPROC(aesni_ecb_dec)
12567
12568 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12569 popl LEN
12570 popl IVP
12571 #endif
12572 + pax_force_retaddr
12573 ret
12574 ENDPROC(aesni_cbc_enc)
12575
12576 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12577 popl LEN
12578 popl IVP
12579 #endif
12580 + pax_force_retaddr
12581 ret
12582 ENDPROC(aesni_cbc_dec)
12583
12584 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
12585 mov $1, TCTR_LOW
12586 MOVQ_R64_XMM TCTR_LOW INC
12587 MOVQ_R64_XMM CTR TCTR_LOW
12588 + pax_force_retaddr
12589 ret
12590 ENDPROC(_aesni_inc_init)
12591
12592 @@ -2579,6 +2598,7 @@ _aesni_inc:
12593 .Linc_low:
12594 movaps CTR, IV
12595 PSHUFB_XMM BSWAP_MASK IV
12596 + pax_force_retaddr
12597 ret
12598 ENDPROC(_aesni_inc)
12599
12600 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12601 .Lctr_enc_ret:
12602 movups IV, (IVP)
12603 .Lctr_enc_just_ret:
12604 + pax_force_retaddr
12605 ret
12606 ENDPROC(aesni_ctr_enc)
12607
12608 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12609 pxor INC, STATE4
12610 movdqu STATE4, 0x70(OUTP)
12611
12612 + pax_force_retaddr
12613 ret
12614 ENDPROC(aesni_xts_crypt8)
12615
12616 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12617 index 246c670..466e2d6 100644
12618 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12619 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12620 @@ -21,6 +21,7 @@
12621 */
12622
12623 #include <linux/linkage.h>
12624 +#include <asm/alternative-asm.h>
12625
12626 .file "blowfish-x86_64-asm.S"
12627 .text
12628 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12629 jnz .L__enc_xor;
12630
12631 write_block();
12632 + pax_force_retaddr
12633 ret;
12634 .L__enc_xor:
12635 xor_block();
12636 + pax_force_retaddr
12637 ret;
12638 ENDPROC(__blowfish_enc_blk)
12639
12640 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12641
12642 movq %r11, %rbp;
12643
12644 + pax_force_retaddr
12645 ret;
12646 ENDPROC(blowfish_dec_blk)
12647
12648 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12649
12650 popq %rbx;
12651 popq %rbp;
12652 + pax_force_retaddr
12653 ret;
12654
12655 .L__enc_xor4:
12656 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12657
12658 popq %rbx;
12659 popq %rbp;
12660 + pax_force_retaddr
12661 ret;
12662 ENDPROC(__blowfish_enc_blk_4way)
12663
12664 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12665 popq %rbx;
12666 popq %rbp;
12667
12668 + pax_force_retaddr
12669 ret;
12670 ENDPROC(blowfish_dec_blk_4way)
12671 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12672 index ce71f92..1dce7ec 100644
12673 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12674 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12675 @@ -16,6 +16,7 @@
12676 */
12677
12678 #include <linux/linkage.h>
12679 +#include <asm/alternative-asm.h>
12680
12681 #define CAMELLIA_TABLE_BYTE_LEN 272
12682
12683 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12684 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12685 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12686 %rcx, (%r9));
12687 + pax_force_retaddr
12688 ret;
12689 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12690
12691 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12692 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12693 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12694 %rax, (%r9));
12695 + pax_force_retaddr
12696 ret;
12697 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12698
12699 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
12700 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12701 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12702
12703 + pax_force_retaddr
12704 ret;
12705
12706 .align 8
12707 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
12708 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12709 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12710
12711 + pax_force_retaddr
12712 ret;
12713
12714 .align 8
12715 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12716 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12717 %xmm8, %rsi);
12718
12719 + pax_force_retaddr
12720 ret;
12721 ENDPROC(camellia_ecb_enc_16way)
12722
12723 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12724 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12725 %xmm8, %rsi);
12726
12727 + pax_force_retaddr
12728 ret;
12729 ENDPROC(camellia_ecb_dec_16way)
12730
12731 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12732 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12733 %xmm8, %rsi);
12734
12735 + pax_force_retaddr
12736 ret;
12737 ENDPROC(camellia_cbc_dec_16way)
12738
12739 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12740 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12741 %xmm8, %rsi);
12742
12743 + pax_force_retaddr
12744 ret;
12745 ENDPROC(camellia_ctr_16way)
12746
12747 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12748 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12749 %xmm8, %rsi);
12750
12751 + pax_force_retaddr
12752 ret;
12753 ENDPROC(camellia_xts_crypt_16way)
12754
12755 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12756 index 0e0b886..5a3123c 100644
12757 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12758 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12759 @@ -11,6 +11,7 @@
12760 */
12761
12762 #include <linux/linkage.h>
12763 +#include <asm/alternative-asm.h>
12764
12765 #define CAMELLIA_TABLE_BYTE_LEN 272
12766
12767 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12768 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12769 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12770 %rcx, (%r9));
12771 + pax_force_retaddr
12772 ret;
12773 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12774
12775 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12776 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12777 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12778 %rax, (%r9));
12779 + pax_force_retaddr
12780 ret;
12781 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12782
12783 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
12784 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12785 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12786
12787 + pax_force_retaddr
12788 ret;
12789
12790 .align 8
12791 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
12792 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12793 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12794
12795 + pax_force_retaddr
12796 ret;
12797
12798 .align 8
12799 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12800
12801 vzeroupper;
12802
12803 + pax_force_retaddr
12804 ret;
12805 ENDPROC(camellia_ecb_enc_32way)
12806
12807 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12808
12809 vzeroupper;
12810
12811 + pax_force_retaddr
12812 ret;
12813 ENDPROC(camellia_ecb_dec_32way)
12814
12815 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12816
12817 vzeroupper;
12818
12819 + pax_force_retaddr
12820 ret;
12821 ENDPROC(camellia_cbc_dec_32way)
12822
12823 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12824
12825 vzeroupper;
12826
12827 + pax_force_retaddr
12828 ret;
12829 ENDPROC(camellia_ctr_32way)
12830
12831 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12832
12833 vzeroupper;
12834
12835 + pax_force_retaddr
12836 ret;
12837 ENDPROC(camellia_xts_crypt_32way)
12838
12839 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12840 index 310319c..db3d7b5 100644
12841 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12842 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12843 @@ -21,6 +21,7 @@
12844 */
12845
12846 #include <linux/linkage.h>
12847 +#include <asm/alternative-asm.h>
12848
12849 .file "camellia-x86_64-asm_64.S"
12850 .text
12851 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12852 enc_outunpack(mov, RT1);
12853
12854 movq RRBP, %rbp;
12855 + pax_force_retaddr
12856 ret;
12857
12858 .L__enc_xor:
12859 enc_outunpack(xor, RT1);
12860
12861 movq RRBP, %rbp;
12862 + pax_force_retaddr
12863 ret;
12864 ENDPROC(__camellia_enc_blk)
12865
12866 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12867 dec_outunpack();
12868
12869 movq RRBP, %rbp;
12870 + pax_force_retaddr
12871 ret;
12872 ENDPROC(camellia_dec_blk)
12873
12874 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12875
12876 movq RRBP, %rbp;
12877 popq %rbx;
12878 + pax_force_retaddr
12879 ret;
12880
12881 .L__enc2_xor:
12882 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12883
12884 movq RRBP, %rbp;
12885 popq %rbx;
12886 + pax_force_retaddr
12887 ret;
12888 ENDPROC(__camellia_enc_blk_2way)
12889
12890 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12891
12892 movq RRBP, %rbp;
12893 movq RXOR, %rbx;
12894 + pax_force_retaddr
12895 ret;
12896 ENDPROC(camellia_dec_blk_2way)
12897 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12898 index c35fd5d..2d8c7db 100644
12899 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12900 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12901 @@ -24,6 +24,7 @@
12902 */
12903
12904 #include <linux/linkage.h>
12905 +#include <asm/alternative-asm.h>
12906
12907 .file "cast5-avx-x86_64-asm_64.S"
12908
12909 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
12910 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12911 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12912
12913 + pax_force_retaddr
12914 ret;
12915 ENDPROC(__cast5_enc_blk16)
12916
12917 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
12918 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12919 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12920
12921 + pax_force_retaddr
12922 ret;
12923
12924 .L__skip_dec:
12925 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12926 vmovdqu RR4, (6*4*4)(%r11);
12927 vmovdqu RL4, (7*4*4)(%r11);
12928
12929 + pax_force_retaddr
12930 ret;
12931 ENDPROC(cast5_ecb_enc_16way)
12932
12933 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12934 vmovdqu RR4, (6*4*4)(%r11);
12935 vmovdqu RL4, (7*4*4)(%r11);
12936
12937 + pax_force_retaddr
12938 ret;
12939 ENDPROC(cast5_ecb_dec_16way)
12940
12941 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
12942 * %rdx: src
12943 */
12944
12945 - pushq %r12;
12946 + pushq %r14;
12947
12948 movq %rsi, %r11;
12949 - movq %rdx, %r12;
12950 + movq %rdx, %r14;
12951
12952 vmovdqu (0*16)(%rdx), RL1;
12953 vmovdqu (1*16)(%rdx), RR1;
12954 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
12955 call __cast5_dec_blk16;
12956
12957 /* xor with src */
12958 - vmovq (%r12), RX;
12959 + vmovq (%r14), RX;
12960 vpshufd $0x4f, RX, RX;
12961 vpxor RX, RR1, RR1;
12962 - vpxor 0*16+8(%r12), RL1, RL1;
12963 - vpxor 1*16+8(%r12), RR2, RR2;
12964 - vpxor 2*16+8(%r12), RL2, RL2;
12965 - vpxor 3*16+8(%r12), RR3, RR3;
12966 - vpxor 4*16+8(%r12), RL3, RL3;
12967 - vpxor 5*16+8(%r12), RR4, RR4;
12968 - vpxor 6*16+8(%r12), RL4, RL4;
12969 + vpxor 0*16+8(%r14), RL1, RL1;
12970 + vpxor 1*16+8(%r14), RR2, RR2;
12971 + vpxor 2*16+8(%r14), RL2, RL2;
12972 + vpxor 3*16+8(%r14), RR3, RR3;
12973 + vpxor 4*16+8(%r14), RL3, RL3;
12974 + vpxor 5*16+8(%r14), RR4, RR4;
12975 + vpxor 6*16+8(%r14), RL4, RL4;
12976
12977 vmovdqu RR1, (0*16)(%r11);
12978 vmovdqu RL1, (1*16)(%r11);
12979 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
12980 vmovdqu RR4, (6*16)(%r11);
12981 vmovdqu RL4, (7*16)(%r11);
12982
12983 - popq %r12;
12984 + popq %r14;
12985
12986 + pax_force_retaddr
12987 ret;
12988 ENDPROC(cast5_cbc_dec_16way)
12989
12990 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
12991 * %rcx: iv (big endian, 64bit)
12992 */
12993
12994 - pushq %r12;
12995 + pushq %r14;
12996
12997 movq %rsi, %r11;
12998 - movq %rdx, %r12;
12999 + movq %rdx, %r14;
13000
13001 vpcmpeqd RTMP, RTMP, RTMP;
13002 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13003 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13004 call __cast5_enc_blk16;
13005
13006 /* dst = src ^ iv */
13007 - vpxor (0*16)(%r12), RR1, RR1;
13008 - vpxor (1*16)(%r12), RL1, RL1;
13009 - vpxor (2*16)(%r12), RR2, RR2;
13010 - vpxor (3*16)(%r12), RL2, RL2;
13011 - vpxor (4*16)(%r12), RR3, RR3;
13012 - vpxor (5*16)(%r12), RL3, RL3;
13013 - vpxor (6*16)(%r12), RR4, RR4;
13014 - vpxor (7*16)(%r12), RL4, RL4;
13015 + vpxor (0*16)(%r14), RR1, RR1;
13016 + vpxor (1*16)(%r14), RL1, RL1;
13017 + vpxor (2*16)(%r14), RR2, RR2;
13018 + vpxor (3*16)(%r14), RL2, RL2;
13019 + vpxor (4*16)(%r14), RR3, RR3;
13020 + vpxor (5*16)(%r14), RL3, RL3;
13021 + vpxor (6*16)(%r14), RR4, RR4;
13022 + vpxor (7*16)(%r14), RL4, RL4;
13023 vmovdqu RR1, (0*16)(%r11);
13024 vmovdqu RL1, (1*16)(%r11);
13025 vmovdqu RR2, (2*16)(%r11);
13026 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13027 vmovdqu RR4, (6*16)(%r11);
13028 vmovdqu RL4, (7*16)(%r11);
13029
13030 - popq %r12;
13031 + popq %r14;
13032
13033 + pax_force_retaddr
13034 ret;
13035 ENDPROC(cast5_ctr_16way)
13036 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13037 index e3531f8..e123f35 100644
13038 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13039 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13040 @@ -24,6 +24,7 @@
13041 */
13042
13043 #include <linux/linkage.h>
13044 +#include <asm/alternative-asm.h>
13045 #include "glue_helper-asm-avx.S"
13046
13047 .file "cast6-avx-x86_64-asm_64.S"
13048 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13049 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13050 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13051
13052 + pax_force_retaddr
13053 ret;
13054 ENDPROC(__cast6_enc_blk8)
13055
13056 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13057 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13058 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13059
13060 + pax_force_retaddr
13061 ret;
13062 ENDPROC(__cast6_dec_blk8)
13063
13064 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13065
13066 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13067
13068 + pax_force_retaddr
13069 ret;
13070 ENDPROC(cast6_ecb_enc_8way)
13071
13072 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13073
13074 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13075
13076 + pax_force_retaddr
13077 ret;
13078 ENDPROC(cast6_ecb_dec_8way)
13079
13080 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13081 * %rdx: src
13082 */
13083
13084 - pushq %r12;
13085 + pushq %r14;
13086
13087 movq %rsi, %r11;
13088 - movq %rdx, %r12;
13089 + movq %rdx, %r14;
13090
13091 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13092
13093 call __cast6_dec_blk8;
13094
13095 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13096 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13097
13098 - popq %r12;
13099 + popq %r14;
13100
13101 + pax_force_retaddr
13102 ret;
13103 ENDPROC(cast6_cbc_dec_8way)
13104
13105 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13106 * %rcx: iv (little endian, 128bit)
13107 */
13108
13109 - pushq %r12;
13110 + pushq %r14;
13111
13112 movq %rsi, %r11;
13113 - movq %rdx, %r12;
13114 + movq %rdx, %r14;
13115
13116 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13117 RD2, RX, RKR, RKM);
13118
13119 call __cast6_enc_blk8;
13120
13121 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13122 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13123
13124 - popq %r12;
13125 + popq %r14;
13126
13127 + pax_force_retaddr
13128 ret;
13129 ENDPROC(cast6_ctr_8way)
13130
13131 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13132 /* dst <= regs xor IVs(in dst) */
13133 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13134
13135 + pax_force_retaddr
13136 ret;
13137 ENDPROC(cast6_xts_enc_8way)
13138
13139 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13140 /* dst <= regs xor IVs(in dst) */
13141 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13142
13143 + pax_force_retaddr
13144 ret;
13145 ENDPROC(cast6_xts_dec_8way)
13146 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13147 index dbc4339..de6e120 100644
13148 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13149 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13150 @@ -45,6 +45,7 @@
13151
13152 #include <asm/inst.h>
13153 #include <linux/linkage.h>
13154 +#include <asm/alternative-asm.h>
13155
13156 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13157
13158 @@ -312,6 +313,7 @@ do_return:
13159 popq %rsi
13160 popq %rdi
13161 popq %rbx
13162 + pax_force_retaddr
13163 ret
13164
13165 ################################################################
13166 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13167 index 586f41a..d02851e 100644
13168 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13169 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13170 @@ -18,6 +18,7 @@
13171
13172 #include <linux/linkage.h>
13173 #include <asm/inst.h>
13174 +#include <asm/alternative-asm.h>
13175
13176 .data
13177
13178 @@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13179 psrlq $1, T2
13180 pxor T2, T1
13181 pxor T1, DATA
13182 + pax_force_retaddr
13183 ret
13184 ENDPROC(__clmul_gf128mul_ble)
13185
13186 @@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13187 call __clmul_gf128mul_ble
13188 PSHUFB_XMM BSWAP DATA
13189 movups DATA, (%rdi)
13190 + pax_force_retaddr
13191 ret
13192 ENDPROC(clmul_ghash_mul)
13193
13194 @@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13195 PSHUFB_XMM BSWAP DATA
13196 movups DATA, (%rdi)
13197 .Lupdate_just_ret:
13198 + pax_force_retaddr
13199 ret
13200 ENDPROC(clmul_ghash_update)
13201
13202 @@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13203 pand .Lpoly, %xmm1
13204 pxor %xmm1, %xmm0
13205 movups %xmm0, (%rdi)
13206 + pax_force_retaddr
13207 ret
13208 ENDPROC(clmul_ghash_setkey)
13209 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13210 index 9279e0b..c4b3d2c 100644
13211 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13212 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13213 @@ -1,4 +1,5 @@
13214 #include <linux/linkage.h>
13215 +#include <asm/alternative-asm.h>
13216
13217 # enter salsa20_encrypt_bytes
13218 ENTRY(salsa20_encrypt_bytes)
13219 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13220 add %r11,%rsp
13221 mov %rdi,%rax
13222 mov %rsi,%rdx
13223 + pax_force_retaddr
13224 ret
13225 # bytesatleast65:
13226 ._bytesatleast65:
13227 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13228 add %r11,%rsp
13229 mov %rdi,%rax
13230 mov %rsi,%rdx
13231 + pax_force_retaddr
13232 ret
13233 ENDPROC(salsa20_keysetup)
13234
13235 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13236 add %r11,%rsp
13237 mov %rdi,%rax
13238 mov %rsi,%rdx
13239 + pax_force_retaddr
13240 ret
13241 ENDPROC(salsa20_ivsetup)
13242 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13243 index 2f202f4..d9164d6 100644
13244 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13245 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13246 @@ -24,6 +24,7 @@
13247 */
13248
13249 #include <linux/linkage.h>
13250 +#include <asm/alternative-asm.h>
13251 #include "glue_helper-asm-avx.S"
13252
13253 .file "serpent-avx-x86_64-asm_64.S"
13254 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13255 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13256 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13257
13258 + pax_force_retaddr
13259 ret;
13260 ENDPROC(__serpent_enc_blk8_avx)
13261
13262 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13263 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13264 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13265
13266 + pax_force_retaddr
13267 ret;
13268 ENDPROC(__serpent_dec_blk8_avx)
13269
13270 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13271
13272 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13273
13274 + pax_force_retaddr
13275 ret;
13276 ENDPROC(serpent_ecb_enc_8way_avx)
13277
13278 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13279
13280 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13281
13282 + pax_force_retaddr
13283 ret;
13284 ENDPROC(serpent_ecb_dec_8way_avx)
13285
13286 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13287
13288 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13289
13290 + pax_force_retaddr
13291 ret;
13292 ENDPROC(serpent_cbc_dec_8way_avx)
13293
13294 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13295
13296 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13297
13298 + pax_force_retaddr
13299 ret;
13300 ENDPROC(serpent_ctr_8way_avx)
13301
13302 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13303 /* dst <= regs xor IVs(in dst) */
13304 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13305
13306 + pax_force_retaddr
13307 ret;
13308 ENDPROC(serpent_xts_enc_8way_avx)
13309
13310 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13311 /* dst <= regs xor IVs(in dst) */
13312 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13313
13314 + pax_force_retaddr
13315 ret;
13316 ENDPROC(serpent_xts_dec_8way_avx)
13317 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13318 index b222085..abd483c 100644
13319 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13320 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13321 @@ -15,6 +15,7 @@
13322 */
13323
13324 #include <linux/linkage.h>
13325 +#include <asm/alternative-asm.h>
13326 #include "glue_helper-asm-avx2.S"
13327
13328 .file "serpent-avx2-asm_64.S"
13329 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13330 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13331 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13332
13333 + pax_force_retaddr
13334 ret;
13335 ENDPROC(__serpent_enc_blk16)
13336
13337 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13338 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13339 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13340
13341 + pax_force_retaddr
13342 ret;
13343 ENDPROC(__serpent_dec_blk16)
13344
13345 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13346
13347 vzeroupper;
13348
13349 + pax_force_retaddr
13350 ret;
13351 ENDPROC(serpent_ecb_enc_16way)
13352
13353 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13354
13355 vzeroupper;
13356
13357 + pax_force_retaddr
13358 ret;
13359 ENDPROC(serpent_ecb_dec_16way)
13360
13361 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13362
13363 vzeroupper;
13364
13365 + pax_force_retaddr
13366 ret;
13367 ENDPROC(serpent_cbc_dec_16way)
13368
13369 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13370
13371 vzeroupper;
13372
13373 + pax_force_retaddr
13374 ret;
13375 ENDPROC(serpent_ctr_16way)
13376
13377 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13378
13379 vzeroupper;
13380
13381 + pax_force_retaddr
13382 ret;
13383 ENDPROC(serpent_xts_enc_16way)
13384
13385 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13386
13387 vzeroupper;
13388
13389 + pax_force_retaddr
13390 ret;
13391 ENDPROC(serpent_xts_dec_16way)
13392 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13393 index acc066c..1559cc4 100644
13394 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13395 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13396 @@ -25,6 +25,7 @@
13397 */
13398
13399 #include <linux/linkage.h>
13400 +#include <asm/alternative-asm.h>
13401
13402 .file "serpent-sse2-x86_64-asm_64.S"
13403 .text
13404 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13405 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13406 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13407
13408 + pax_force_retaddr
13409 ret;
13410
13411 .L__enc_xor8:
13412 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13413 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13414
13415 + pax_force_retaddr
13416 ret;
13417 ENDPROC(__serpent_enc_blk_8way)
13418
13419 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13420 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13421 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13422
13423 + pax_force_retaddr
13424 ret;
13425 ENDPROC(serpent_dec_blk_8way)
13426 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13427 index a410950..9dfe7ad 100644
13428 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13429 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13430 @@ -29,6 +29,7 @@
13431 */
13432
13433 #include <linux/linkage.h>
13434 +#include <asm/alternative-asm.h>
13435
13436 #define CTX %rdi // arg1
13437 #define BUF %rsi // arg2
13438 @@ -75,9 +76,9 @@
13439
13440 push %rbx
13441 push %rbp
13442 - push %r12
13443 + push %r14
13444
13445 - mov %rsp, %r12
13446 + mov %rsp, %r14
13447 sub $64, %rsp # allocate workspace
13448 and $~15, %rsp # align stack
13449
13450 @@ -99,11 +100,12 @@
13451 xor %rax, %rax
13452 rep stosq
13453
13454 - mov %r12, %rsp # deallocate workspace
13455 + mov %r14, %rsp # deallocate workspace
13456
13457 - pop %r12
13458 + pop %r14
13459 pop %rbp
13460 pop %rbx
13461 + pax_force_retaddr
13462 ret
13463
13464 ENDPROC(\name)
13465 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13466 index 642f156..51a513c 100644
13467 --- a/arch/x86/crypto/sha256-avx-asm.S
13468 +++ b/arch/x86/crypto/sha256-avx-asm.S
13469 @@ -49,6 +49,7 @@
13470
13471 #ifdef CONFIG_AS_AVX
13472 #include <linux/linkage.h>
13473 +#include <asm/alternative-asm.h>
13474
13475 ## assume buffers not aligned
13476 #define VMOVDQ vmovdqu
13477 @@ -460,6 +461,7 @@ done_hash:
13478 popq %r13
13479 popq %rbp
13480 popq %rbx
13481 + pax_force_retaddr
13482 ret
13483 ENDPROC(sha256_transform_avx)
13484
13485 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13486 index 9e86944..3795e6a 100644
13487 --- a/arch/x86/crypto/sha256-avx2-asm.S
13488 +++ b/arch/x86/crypto/sha256-avx2-asm.S
13489 @@ -50,6 +50,7 @@
13490
13491 #ifdef CONFIG_AS_AVX2
13492 #include <linux/linkage.h>
13493 +#include <asm/alternative-asm.h>
13494
13495 ## assume buffers not aligned
13496 #define VMOVDQ vmovdqu
13497 @@ -720,6 +721,7 @@ done_hash:
13498 popq %r12
13499 popq %rbp
13500 popq %rbx
13501 + pax_force_retaddr
13502 ret
13503 ENDPROC(sha256_transform_rorx)
13504
13505 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13506 index f833b74..8c62a9e 100644
13507 --- a/arch/x86/crypto/sha256-ssse3-asm.S
13508 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
13509 @@ -47,6 +47,7 @@
13510 ########################################################################
13511
13512 #include <linux/linkage.h>
13513 +#include <asm/alternative-asm.h>
13514
13515 ## assume buffers not aligned
13516 #define MOVDQ movdqu
13517 @@ -471,6 +472,7 @@ done_hash:
13518 popq %rbp
13519 popq %rbx
13520
13521 + pax_force_retaddr
13522 ret
13523 ENDPROC(sha256_transform_ssse3)
13524
13525 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13526 index 974dde9..a823ff9 100644
13527 --- a/arch/x86/crypto/sha512-avx-asm.S
13528 +++ b/arch/x86/crypto/sha512-avx-asm.S
13529 @@ -49,6 +49,7 @@
13530
13531 #ifdef CONFIG_AS_AVX
13532 #include <linux/linkage.h>
13533 +#include <asm/alternative-asm.h>
13534
13535 .text
13536
13537 @@ -364,6 +365,7 @@ updateblock:
13538 mov frame_RSPSAVE(%rsp), %rsp
13539
13540 nowork:
13541 + pax_force_retaddr
13542 ret
13543 ENDPROC(sha512_transform_avx)
13544
13545 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13546 index 568b961..ed20c37 100644
13547 --- a/arch/x86/crypto/sha512-avx2-asm.S
13548 +++ b/arch/x86/crypto/sha512-avx2-asm.S
13549 @@ -51,6 +51,7 @@
13550
13551 #ifdef CONFIG_AS_AVX2
13552 #include <linux/linkage.h>
13553 +#include <asm/alternative-asm.h>
13554
13555 .text
13556
13557 @@ -678,6 +679,7 @@ done_hash:
13558
13559 # Restore Stack Pointer
13560 mov frame_RSPSAVE(%rsp), %rsp
13561 + pax_force_retaddr
13562 ret
13563 ENDPROC(sha512_transform_rorx)
13564
13565 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13566 index fb56855..6edd768 100644
13567 --- a/arch/x86/crypto/sha512-ssse3-asm.S
13568 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
13569 @@ -48,6 +48,7 @@
13570 ########################################################################
13571
13572 #include <linux/linkage.h>
13573 +#include <asm/alternative-asm.h>
13574
13575 .text
13576
13577 @@ -363,6 +364,7 @@ updateblock:
13578 mov frame_RSPSAVE(%rsp), %rsp
13579
13580 nowork:
13581 + pax_force_retaddr
13582 ret
13583 ENDPROC(sha512_transform_ssse3)
13584
13585 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13586 index 0505813..b067311 100644
13587 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13588 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13589 @@ -24,6 +24,7 @@
13590 */
13591
13592 #include <linux/linkage.h>
13593 +#include <asm/alternative-asm.h>
13594 #include "glue_helper-asm-avx.S"
13595
13596 .file "twofish-avx-x86_64-asm_64.S"
13597 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
13598 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13599 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13600
13601 + pax_force_retaddr
13602 ret;
13603 ENDPROC(__twofish_enc_blk8)
13604
13605 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
13606 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13607 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13608
13609 + pax_force_retaddr
13610 ret;
13611 ENDPROC(__twofish_dec_blk8)
13612
13613 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13614
13615 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13616
13617 + pax_force_retaddr
13618 ret;
13619 ENDPROC(twofish_ecb_enc_8way)
13620
13621 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13622
13623 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13624
13625 + pax_force_retaddr
13626 ret;
13627 ENDPROC(twofish_ecb_dec_8way)
13628
13629 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
13630 * %rdx: src
13631 */
13632
13633 - pushq %r12;
13634 + pushq %r14;
13635
13636 movq %rsi, %r11;
13637 - movq %rdx, %r12;
13638 + movq %rdx, %r14;
13639
13640 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13641
13642 call __twofish_dec_blk8;
13643
13644 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13645 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13646
13647 - popq %r12;
13648 + popq %r14;
13649
13650 + pax_force_retaddr
13651 ret;
13652 ENDPROC(twofish_cbc_dec_8way)
13653
13654 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
13655 * %rcx: iv (little endian, 128bit)
13656 */
13657
13658 - pushq %r12;
13659 + pushq %r14;
13660
13661 movq %rsi, %r11;
13662 - movq %rdx, %r12;
13663 + movq %rdx, %r14;
13664
13665 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13666 RD2, RX0, RX1, RY0);
13667
13668 call __twofish_enc_blk8;
13669
13670 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13671 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13672
13673 - popq %r12;
13674 + popq %r14;
13675
13676 + pax_force_retaddr
13677 ret;
13678 ENDPROC(twofish_ctr_8way)
13679
13680 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13681 /* dst <= regs xor IVs(in dst) */
13682 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13683
13684 + pax_force_retaddr
13685 ret;
13686 ENDPROC(twofish_xts_enc_8way)
13687
13688 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13689 /* dst <= regs xor IVs(in dst) */
13690 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13691
13692 + pax_force_retaddr
13693 ret;
13694 ENDPROC(twofish_xts_dec_8way)
13695 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13696 index 1c3b7ce..02f578d 100644
13697 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13698 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13699 @@ -21,6 +21,7 @@
13700 */
13701
13702 #include <linux/linkage.h>
13703 +#include <asm/alternative-asm.h>
13704
13705 .file "twofish-x86_64-asm-3way.S"
13706 .text
13707 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13708 popq %r13;
13709 popq %r14;
13710 popq %r15;
13711 + pax_force_retaddr
13712 ret;
13713
13714 .L__enc_xor3:
13715 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13716 popq %r13;
13717 popq %r14;
13718 popq %r15;
13719 + pax_force_retaddr
13720 ret;
13721 ENDPROC(__twofish_enc_blk_3way)
13722
13723 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13724 popq %r13;
13725 popq %r14;
13726 popq %r15;
13727 + pax_force_retaddr
13728 ret;
13729 ENDPROC(twofish_dec_blk_3way)
13730 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13731 index a039d21..524b8b2 100644
13732 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13733 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13734 @@ -22,6 +22,7 @@
13735
13736 #include <linux/linkage.h>
13737 #include <asm/asm-offsets.h>
13738 +#include <asm/alternative-asm.h>
13739
13740 #define a_offset 0
13741 #define b_offset 4
13742 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13743
13744 popq R1
13745 movq $1,%rax
13746 + pax_force_retaddr
13747 ret
13748 ENDPROC(twofish_enc_blk)
13749
13750 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13751
13752 popq R1
13753 movq $1,%rax
13754 + pax_force_retaddr
13755 ret
13756 ENDPROC(twofish_dec_blk)
13757 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13758 index d21ff89..6da8e6e 100644
13759 --- a/arch/x86/ia32/ia32_aout.c
13760 +++ b/arch/x86/ia32/ia32_aout.c
13761 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
13762 unsigned long dump_start, dump_size;
13763 struct user32 dump;
13764
13765 + memset(&dump, 0, sizeof(dump));
13766 +
13767 fs = get_fs();
13768 set_fs(KERNEL_DS);
13769 has_dumped = 1;
13770 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13771 index 2206757..85cbcfa 100644
13772 --- a/arch/x86/ia32/ia32_signal.c
13773 +++ b/arch/x86/ia32/ia32_signal.c
13774 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
13775 if (__get_user(set.sig[0], &frame->sc.oldmask)
13776 || (_COMPAT_NSIG_WORDS > 1
13777 && __copy_from_user((((char *) &set.sig) + 4),
13778 - &frame->extramask,
13779 + frame->extramask,
13780 sizeof(frame->extramask))))
13781 goto badframe;
13782
13783 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13784 sp -= frame_size;
13785 /* Align the stack pointer according to the i386 ABI,
13786 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13787 - sp = ((sp + 4) & -16ul) - 4;
13788 + sp = ((sp - 12) & -16ul) - 4;
13789 return (void __user *) sp;
13790 }
13791
13792 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13793 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13794 sigreturn);
13795 else
13796 - restorer = &frame->retcode;
13797 + restorer = frame->retcode;
13798 }
13799
13800 put_user_try {
13801 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13802 * These are actually not used anymore, but left because some
13803 * gdb versions depend on them as a marker.
13804 */
13805 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13806 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13807 } put_user_catch(err);
13808
13809 if (err)
13810 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13811 0xb8,
13812 __NR_ia32_rt_sigreturn,
13813 0x80cd,
13814 - 0,
13815 + 0
13816 };
13817
13818 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13819 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13820
13821 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13822 restorer = ksig->ka.sa.sa_restorer;
13823 + else if (current->mm->context.vdso)
13824 + /* Return stub is in 32bit vsyscall page */
13825 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13826 else
13827 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13828 - rt_sigreturn);
13829 + restorer = frame->retcode;
13830 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13831
13832 /*
13833 * Not actually used anymore, but left because some gdb
13834 * versions need it.
13835 */
13836 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13837 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13838 } put_user_catch(err);
13839
13840 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13841 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13842 index 4299eb0..c0687a7 100644
13843 --- a/arch/x86/ia32/ia32entry.S
13844 +++ b/arch/x86/ia32/ia32entry.S
13845 @@ -15,8 +15,10 @@
13846 #include <asm/irqflags.h>
13847 #include <asm/asm.h>
13848 #include <asm/smap.h>
13849 +#include <asm/pgtable.h>
13850 #include <linux/linkage.h>
13851 #include <linux/err.h>
13852 +#include <asm/alternative-asm.h>
13853
13854 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13855 #include <linux/elf-em.h>
13856 @@ -62,12 +64,12 @@
13857 */
13858 .macro LOAD_ARGS32 offset, _r9=0
13859 .if \_r9
13860 - movl \offset+16(%rsp),%r9d
13861 + movl \offset+R9(%rsp),%r9d
13862 .endif
13863 - movl \offset+40(%rsp),%ecx
13864 - movl \offset+48(%rsp),%edx
13865 - movl \offset+56(%rsp),%esi
13866 - movl \offset+64(%rsp),%edi
13867 + movl \offset+RCX(%rsp),%ecx
13868 + movl \offset+RDX(%rsp),%edx
13869 + movl \offset+RSI(%rsp),%esi
13870 + movl \offset+RDI(%rsp),%edi
13871 movl %eax,%eax /* zero extension */
13872 .endm
13873
13874 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13875 ENDPROC(native_irq_enable_sysexit)
13876 #endif
13877
13878 + .macro pax_enter_kernel_user
13879 + pax_set_fptr_mask
13880 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13881 + call pax_enter_kernel_user
13882 +#endif
13883 + .endm
13884 +
13885 + .macro pax_exit_kernel_user
13886 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13887 + call pax_exit_kernel_user
13888 +#endif
13889 +#ifdef CONFIG_PAX_RANDKSTACK
13890 + pushq %rax
13891 + pushq %r11
13892 + call pax_randomize_kstack
13893 + popq %r11
13894 + popq %rax
13895 +#endif
13896 + .endm
13897 +
13898 + .macro pax_erase_kstack
13899 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13900 + call pax_erase_kstack
13901 +#endif
13902 + .endm
13903 +
13904 /*
13905 * 32bit SYSENTER instruction entry.
13906 *
13907 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13908 CFI_REGISTER rsp,rbp
13909 SWAPGS_UNSAFE_STACK
13910 movq PER_CPU_VAR(kernel_stack), %rsp
13911 - addq $(KERNEL_STACK_OFFSET),%rsp
13912 - /*
13913 - * No need to follow this irqs on/off section: the syscall
13914 - * disabled irqs, here we enable it straight after entry:
13915 - */
13916 - ENABLE_INTERRUPTS(CLBR_NONE)
13917 movl %ebp,%ebp /* zero extension */
13918 pushq_cfi $__USER32_DS
13919 /*CFI_REL_OFFSET ss,0*/
13920 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13921 CFI_REL_OFFSET rsp,0
13922 pushfq_cfi
13923 /*CFI_REL_OFFSET rflags,0*/
13924 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13925 - CFI_REGISTER rip,r10
13926 + orl $X86_EFLAGS_IF,(%rsp)
13927 + GET_THREAD_INFO(%r11)
13928 + movl TI_sysenter_return(%r11), %r11d
13929 + CFI_REGISTER rip,r11
13930 pushq_cfi $__USER32_CS
13931 /*CFI_REL_OFFSET cs,0*/
13932 movl %eax, %eax
13933 - pushq_cfi %r10
13934 + pushq_cfi %r11
13935 CFI_REL_OFFSET rip,0
13936 pushq_cfi %rax
13937 cld
13938 SAVE_ARGS 0,1,0
13939 + pax_enter_kernel_user
13940 +
13941 +#ifdef CONFIG_PAX_RANDKSTACK
13942 + pax_erase_kstack
13943 +#endif
13944 +
13945 + /*
13946 + * No need to follow this irqs on/off section: the syscall
13947 + * disabled irqs, here we enable it straight after entry:
13948 + */
13949 + ENABLE_INTERRUPTS(CLBR_NONE)
13950 /* no need to do an access_ok check here because rbp has been
13951 32bit zero extended */
13952 +
13953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13954 + addq pax_user_shadow_base,%rbp
13955 + ASM_PAX_OPEN_USERLAND
13956 +#endif
13957 +
13958 ASM_STAC
13959 1: movl (%rbp),%ebp
13960 _ASM_EXTABLE(1b,ia32_badarg)
13961 ASM_CLAC
13962 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13963 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13964 +
13965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13966 + ASM_PAX_CLOSE_USERLAND
13967 +#endif
13968 +
13969 + GET_THREAD_INFO(%r11)
13970 + orl $TS_COMPAT,TI_status(%r11)
13971 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13972 CFI_REMEMBER_STATE
13973 jnz sysenter_tracesys
13974 cmpq $(IA32_NR_syscalls-1),%rax
13975 @@ -162,15 +209,18 @@ sysenter_do_call:
13976 sysenter_dispatch:
13977 call *ia32_sys_call_table(,%rax,8)
13978 movq %rax,RAX-ARGOFFSET(%rsp)
13979 + GET_THREAD_INFO(%r11)
13980 DISABLE_INTERRUPTS(CLBR_NONE)
13981 TRACE_IRQS_OFF
13982 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13983 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13984 jnz sysexit_audit
13985 sysexit_from_sys_call:
13986 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13987 + pax_exit_kernel_user
13988 + pax_erase_kstack
13989 + andl $~TS_COMPAT,TI_status(%r11)
13990 /* clear IF, that popfq doesn't enable interrupts early */
13991 - andl $~0x200,EFLAGS-R11(%rsp)
13992 - movl RIP-R11(%rsp),%edx /* User %eip */
13993 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
13994 + movl RIP(%rsp),%edx /* User %eip */
13995 CFI_REGISTER rip,rdx
13996 RESTORE_ARGS 0,24,0,0,0,0
13997 xorq %r8,%r8
13998 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
13999 movl %eax,%esi /* 2nd arg: syscall number */
14000 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14001 call __audit_syscall_entry
14002 +
14003 + pax_erase_kstack
14004 +
14005 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14006 cmpq $(IA32_NR_syscalls-1),%rax
14007 ja ia32_badsys
14008 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14009 .endm
14010
14011 .macro auditsys_exit exit
14012 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14013 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14014 jnz ia32_ret_from_sys_call
14015 TRACE_IRQS_ON
14016 ENABLE_INTERRUPTS(CLBR_NONE)
14017 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14018 1: setbe %al /* 1 if error, 0 if not */
14019 movzbl %al,%edi /* zero-extend that into %edi */
14020 call __audit_syscall_exit
14021 + GET_THREAD_INFO(%r11)
14022 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14023 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14024 DISABLE_INTERRUPTS(CLBR_NONE)
14025 TRACE_IRQS_OFF
14026 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14027 + testl %edi,TI_flags(%r11)
14028 jz \exit
14029 CLEAR_RREGS -ARGOFFSET
14030 jmp int_with_check
14031 @@ -237,7 +291,7 @@ sysexit_audit:
14032
14033 sysenter_tracesys:
14034 #ifdef CONFIG_AUDITSYSCALL
14035 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14036 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14037 jz sysenter_auditsys
14038 #endif
14039 SAVE_REST
14040 @@ -249,6 +303,9 @@ sysenter_tracesys:
14041 RESTORE_REST
14042 cmpq $(IA32_NR_syscalls-1),%rax
14043 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14044 +
14045 + pax_erase_kstack
14046 +
14047 jmp sysenter_do_call
14048 CFI_ENDPROC
14049 ENDPROC(ia32_sysenter_target)
14050 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14051 ENTRY(ia32_cstar_target)
14052 CFI_STARTPROC32 simple
14053 CFI_SIGNAL_FRAME
14054 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14055 + CFI_DEF_CFA rsp,0
14056 CFI_REGISTER rip,rcx
14057 /*CFI_REGISTER rflags,r11*/
14058 SWAPGS_UNSAFE_STACK
14059 movl %esp,%r8d
14060 CFI_REGISTER rsp,r8
14061 movq PER_CPU_VAR(kernel_stack),%rsp
14062 + SAVE_ARGS 8*6,0,0
14063 + pax_enter_kernel_user
14064 +
14065 +#ifdef CONFIG_PAX_RANDKSTACK
14066 + pax_erase_kstack
14067 +#endif
14068 +
14069 /*
14070 * No need to follow this irqs on/off section: the syscall
14071 * disabled irqs and here we enable it straight after entry:
14072 */
14073 ENABLE_INTERRUPTS(CLBR_NONE)
14074 - SAVE_ARGS 8,0,0
14075 movl %eax,%eax /* zero extension */
14076 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14077 movq %rcx,RIP-ARGOFFSET(%rsp)
14078 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14079 /* no need to do an access_ok check here because r8 has been
14080 32bit zero extended */
14081 /* hardware stack frame is complete now */
14082 +
14083 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14084 + ASM_PAX_OPEN_USERLAND
14085 + movq pax_user_shadow_base,%r8
14086 + addq RSP-ARGOFFSET(%rsp),%r8
14087 +#endif
14088 +
14089 ASM_STAC
14090 1: movl (%r8),%r9d
14091 _ASM_EXTABLE(1b,ia32_badarg)
14092 ASM_CLAC
14093 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14094 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14095 +
14096 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14097 + ASM_PAX_CLOSE_USERLAND
14098 +#endif
14099 +
14100 + GET_THREAD_INFO(%r11)
14101 + orl $TS_COMPAT,TI_status(%r11)
14102 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14103 CFI_REMEMBER_STATE
14104 jnz cstar_tracesys
14105 cmpq $IA32_NR_syscalls-1,%rax
14106 @@ -319,13 +395,16 @@ cstar_do_call:
14107 cstar_dispatch:
14108 call *ia32_sys_call_table(,%rax,8)
14109 movq %rax,RAX-ARGOFFSET(%rsp)
14110 + GET_THREAD_INFO(%r11)
14111 DISABLE_INTERRUPTS(CLBR_NONE)
14112 TRACE_IRQS_OFF
14113 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14114 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14115 jnz sysretl_audit
14116 sysretl_from_sys_call:
14117 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14118 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14119 + pax_exit_kernel_user
14120 + pax_erase_kstack
14121 + andl $~TS_COMPAT,TI_status(%r11)
14122 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14123 movl RIP-ARGOFFSET(%rsp),%ecx
14124 CFI_REGISTER rip,rcx
14125 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14126 @@ -352,7 +431,7 @@ sysretl_audit:
14127
14128 cstar_tracesys:
14129 #ifdef CONFIG_AUDITSYSCALL
14130 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14131 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14132 jz cstar_auditsys
14133 #endif
14134 xchgl %r9d,%ebp
14135 @@ -366,11 +445,19 @@ cstar_tracesys:
14136 xchgl %ebp,%r9d
14137 cmpq $(IA32_NR_syscalls-1),%rax
14138 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14139 +
14140 + pax_erase_kstack
14141 +
14142 jmp cstar_do_call
14143 END(ia32_cstar_target)
14144
14145 ia32_badarg:
14146 ASM_CLAC
14147 +
14148 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14149 + ASM_PAX_CLOSE_USERLAND
14150 +#endif
14151 +
14152 movq $-EFAULT,%rax
14153 jmp ia32_sysret
14154 CFI_ENDPROC
14155 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14156 CFI_REL_OFFSET rip,RIP-RIP
14157 PARAVIRT_ADJUST_EXCEPTION_FRAME
14158 SWAPGS
14159 - /*
14160 - * No need to follow this irqs on/off section: the syscall
14161 - * disabled irqs and here we enable it straight after entry:
14162 - */
14163 - ENABLE_INTERRUPTS(CLBR_NONE)
14164 movl %eax,%eax
14165 pushq_cfi %rax
14166 cld
14167 /* note the registers are not zero extended to the sf.
14168 this could be a problem. */
14169 SAVE_ARGS 0,1,0
14170 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14171 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14172 + pax_enter_kernel_user
14173 +
14174 +#ifdef CONFIG_PAX_RANDKSTACK
14175 + pax_erase_kstack
14176 +#endif
14177 +
14178 + /*
14179 + * No need to follow this irqs on/off section: the syscall
14180 + * disabled irqs and here we enable it straight after entry:
14181 + */
14182 + ENABLE_INTERRUPTS(CLBR_NONE)
14183 + GET_THREAD_INFO(%r11)
14184 + orl $TS_COMPAT,TI_status(%r11)
14185 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14186 jnz ia32_tracesys
14187 cmpq $(IA32_NR_syscalls-1),%rax
14188 ja ia32_badsys
14189 @@ -442,6 +536,9 @@ ia32_tracesys:
14190 RESTORE_REST
14191 cmpq $(IA32_NR_syscalls-1),%rax
14192 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14193 +
14194 + pax_erase_kstack
14195 +
14196 jmp ia32_do_call
14197 END(ia32_syscall)
14198
14199 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14200 index 8e0ceec..af13504 100644
14201 --- a/arch/x86/ia32/sys_ia32.c
14202 +++ b/arch/x86/ia32/sys_ia32.c
14203 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14204 */
14205 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14206 {
14207 - typeof(ubuf->st_uid) uid = 0;
14208 - typeof(ubuf->st_gid) gid = 0;
14209 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14210 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14211 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14212 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14213 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14214 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14215 index 372231c..51b537d 100644
14216 --- a/arch/x86/include/asm/alternative-asm.h
14217 +++ b/arch/x86/include/asm/alternative-asm.h
14218 @@ -18,6 +18,45 @@
14219 .endm
14220 #endif
14221
14222 +#ifdef KERNEXEC_PLUGIN
14223 + .macro pax_force_retaddr_bts rip=0
14224 + btsq $63,\rip(%rsp)
14225 + .endm
14226 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14227 + .macro pax_force_retaddr rip=0, reload=0
14228 + btsq $63,\rip(%rsp)
14229 + .endm
14230 + .macro pax_force_fptr ptr
14231 + btsq $63,\ptr
14232 + .endm
14233 + .macro pax_set_fptr_mask
14234 + .endm
14235 +#endif
14236 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14237 + .macro pax_force_retaddr rip=0, reload=0
14238 + .if \reload
14239 + pax_set_fptr_mask
14240 + .endif
14241 + orq %r12,\rip(%rsp)
14242 + .endm
14243 + .macro pax_force_fptr ptr
14244 + orq %r12,\ptr
14245 + .endm
14246 + .macro pax_set_fptr_mask
14247 + movabs $0x8000000000000000,%r12
14248 + .endm
14249 +#endif
14250 +#else
14251 + .macro pax_force_retaddr rip=0, reload=0
14252 + .endm
14253 + .macro pax_force_fptr ptr
14254 + .endm
14255 + .macro pax_force_retaddr_bts rip=0
14256 + .endm
14257 + .macro pax_set_fptr_mask
14258 + .endm
14259 +#endif
14260 +
14261 .macro altinstruction_entry orig alt feature orig_len alt_len
14262 .long \orig - .
14263 .long \alt - .
14264 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14265 index 0a3f9c9..c9d081d 100644
14266 --- a/arch/x86/include/asm/alternative.h
14267 +++ b/arch/x86/include/asm/alternative.h
14268 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14269 ".pushsection .discard,\"aw\",@progbits\n" \
14270 DISCARD_ENTRY(1) \
14271 ".popsection\n" \
14272 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14273 + ".pushsection .altinstr_replacement, \"a\"\n" \
14274 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14275 ".popsection"
14276
14277 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14278 DISCARD_ENTRY(1) \
14279 DISCARD_ENTRY(2) \
14280 ".popsection\n" \
14281 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14282 + ".pushsection .altinstr_replacement, \"a\"\n" \
14283 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14284 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14285 ".popsection"
14286 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14287 index 1d2091a..f5074c1 100644
14288 --- a/arch/x86/include/asm/apic.h
14289 +++ b/arch/x86/include/asm/apic.h
14290 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14291
14292 #ifdef CONFIG_X86_LOCAL_APIC
14293
14294 -extern unsigned int apic_verbosity;
14295 +extern int apic_verbosity;
14296 extern int local_apic_timer_c2_ok;
14297
14298 extern int disable_apic;
14299 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14300 index 20370c6..a2eb9b0 100644
14301 --- a/arch/x86/include/asm/apm.h
14302 +++ b/arch/x86/include/asm/apm.h
14303 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14304 __asm__ __volatile__(APM_DO_ZERO_SEGS
14305 "pushl %%edi\n\t"
14306 "pushl %%ebp\n\t"
14307 - "lcall *%%cs:apm_bios_entry\n\t"
14308 + "lcall *%%ss:apm_bios_entry\n\t"
14309 "setc %%al\n\t"
14310 "popl %%ebp\n\t"
14311 "popl %%edi\n\t"
14312 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14313 __asm__ __volatile__(APM_DO_ZERO_SEGS
14314 "pushl %%edi\n\t"
14315 "pushl %%ebp\n\t"
14316 - "lcall *%%cs:apm_bios_entry\n\t"
14317 + "lcall *%%ss:apm_bios_entry\n\t"
14318 "setc %%bl\n\t"
14319 "popl %%ebp\n\t"
14320 "popl %%edi\n\t"
14321 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14322 index b17f4f4..9620151 100644
14323 --- a/arch/x86/include/asm/atomic.h
14324 +++ b/arch/x86/include/asm/atomic.h
14325 @@ -23,7 +23,18 @@
14326 */
14327 static inline int atomic_read(const atomic_t *v)
14328 {
14329 - return (*(volatile int *)&(v)->counter);
14330 + return (*(volatile const int *)&(v)->counter);
14331 +}
14332 +
14333 +/**
14334 + * atomic_read_unchecked - read atomic variable
14335 + * @v: pointer of type atomic_unchecked_t
14336 + *
14337 + * Atomically reads the value of @v.
14338 + */
14339 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14340 +{
14341 + return (*(volatile const int *)&(v)->counter);
14342 }
14343
14344 /**
14345 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14346 }
14347
14348 /**
14349 + * atomic_set_unchecked - set atomic variable
14350 + * @v: pointer of type atomic_unchecked_t
14351 + * @i: required value
14352 + *
14353 + * Atomically sets the value of @v to @i.
14354 + */
14355 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14356 +{
14357 + v->counter = i;
14358 +}
14359 +
14360 +/**
14361 * atomic_add - add integer to atomic variable
14362 * @i: integer value to add
14363 * @v: pointer of type atomic_t
14364 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14365 */
14366 static inline void atomic_add(int i, atomic_t *v)
14367 {
14368 - asm volatile(LOCK_PREFIX "addl %1,%0"
14369 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14370 +
14371 +#ifdef CONFIG_PAX_REFCOUNT
14372 + "jno 0f\n"
14373 + LOCK_PREFIX "subl %1,%0\n"
14374 + "int $4\n0:\n"
14375 + _ASM_EXTABLE(0b, 0b)
14376 +#endif
14377 +
14378 + : "+m" (v->counter)
14379 + : "ir" (i));
14380 +}
14381 +
14382 +/**
14383 + * atomic_add_unchecked - add integer to atomic variable
14384 + * @i: integer value to add
14385 + * @v: pointer of type atomic_unchecked_t
14386 + *
14387 + * Atomically adds @i to @v.
14388 + */
14389 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14390 +{
14391 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14392 : "+m" (v->counter)
14393 : "ir" (i));
14394 }
14395 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14396 */
14397 static inline void atomic_sub(int i, atomic_t *v)
14398 {
14399 - asm volatile(LOCK_PREFIX "subl %1,%0"
14400 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14401 +
14402 +#ifdef CONFIG_PAX_REFCOUNT
14403 + "jno 0f\n"
14404 + LOCK_PREFIX "addl %1,%0\n"
14405 + "int $4\n0:\n"
14406 + _ASM_EXTABLE(0b, 0b)
14407 +#endif
14408 +
14409 + : "+m" (v->counter)
14410 + : "ir" (i));
14411 +}
14412 +
14413 +/**
14414 + * atomic_sub_unchecked - subtract integer from atomic variable
14415 + * @i: integer value to subtract
14416 + * @v: pointer of type atomic_unchecked_t
14417 + *
14418 + * Atomically subtracts @i from @v.
14419 + */
14420 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14421 +{
14422 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14423 : "+m" (v->counter)
14424 : "ir" (i));
14425 }
14426 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14427 */
14428 static inline int atomic_sub_and_test(int i, atomic_t *v)
14429 {
14430 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14431 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14432 }
14433
14434 /**
14435 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14436 */
14437 static inline void atomic_inc(atomic_t *v)
14438 {
14439 - asm volatile(LOCK_PREFIX "incl %0"
14440 + asm volatile(LOCK_PREFIX "incl %0\n"
14441 +
14442 +#ifdef CONFIG_PAX_REFCOUNT
14443 + "jno 0f\n"
14444 + LOCK_PREFIX "decl %0\n"
14445 + "int $4\n0:\n"
14446 + _ASM_EXTABLE(0b, 0b)
14447 +#endif
14448 +
14449 + : "+m" (v->counter));
14450 +}
14451 +
14452 +/**
14453 + * atomic_inc_unchecked - increment atomic variable
14454 + * @v: pointer of type atomic_unchecked_t
14455 + *
14456 + * Atomically increments @v by 1.
14457 + */
14458 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14459 +{
14460 + asm volatile(LOCK_PREFIX "incl %0\n"
14461 : "+m" (v->counter));
14462 }
14463
14464 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14465 */
14466 static inline void atomic_dec(atomic_t *v)
14467 {
14468 - asm volatile(LOCK_PREFIX "decl %0"
14469 + asm volatile(LOCK_PREFIX "decl %0\n"
14470 +
14471 +#ifdef CONFIG_PAX_REFCOUNT
14472 + "jno 0f\n"
14473 + LOCK_PREFIX "incl %0\n"
14474 + "int $4\n0:\n"
14475 + _ASM_EXTABLE(0b, 0b)
14476 +#endif
14477 +
14478 + : "+m" (v->counter));
14479 +}
14480 +
14481 +/**
14482 + * atomic_dec_unchecked - decrement atomic variable
14483 + * @v: pointer of type atomic_unchecked_t
14484 + *
14485 + * Atomically decrements @v by 1.
14486 + */
14487 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14488 +{
14489 + asm volatile(LOCK_PREFIX "decl %0\n"
14490 : "+m" (v->counter));
14491 }
14492
14493 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14494 */
14495 static inline int atomic_dec_and_test(atomic_t *v)
14496 {
14497 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14498 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14499 }
14500
14501 /**
14502 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14503 */
14504 static inline int atomic_inc_and_test(atomic_t *v)
14505 {
14506 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14507 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14508 +}
14509 +
14510 +/**
14511 + * atomic_inc_and_test_unchecked - increment and test
14512 + * @v: pointer of type atomic_unchecked_t
14513 + *
14514 + * Atomically increments @v by 1
14515 + * and returns true if the result is zero, or false for all
14516 + * other cases.
14517 + */
14518 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14519 +{
14520 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14521 }
14522
14523 /**
14524 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14525 */
14526 static inline int atomic_add_negative(int i, atomic_t *v)
14527 {
14528 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14529 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14530 }
14531
14532 /**
14533 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14534 */
14535 static inline int atomic_add_return(int i, atomic_t *v)
14536 {
14537 + return i + xadd_check_overflow(&v->counter, i);
14538 +}
14539 +
14540 +/**
14541 + * atomic_add_return_unchecked - add integer and return
14542 + * @i: integer value to add
14543 + * @v: pointer of type atomic_unchecked_t
14544 + *
14545 + * Atomically adds @i to @v and returns @i + @v
14546 + */
14547 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14548 +{
14549 return i + xadd(&v->counter, i);
14550 }
14551
14552 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14553 }
14554
14555 #define atomic_inc_return(v) (atomic_add_return(1, v))
14556 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14557 +{
14558 + return atomic_add_return_unchecked(1, v);
14559 +}
14560 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14561
14562 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14563 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14564 +{
14565 + return cmpxchg(&v->counter, old, new);
14566 +}
14567 +
14568 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14569 {
14570 return cmpxchg(&v->counter, old, new);
14571 }
14572 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14573 return xchg(&v->counter, new);
14574 }
14575
14576 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14577 +{
14578 + return xchg(&v->counter, new);
14579 +}
14580 +
14581 /**
14582 * __atomic_add_unless - add unless the number is already a given value
14583 * @v: pointer of type atomic_t
14584 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
14585 * Atomically adds @a to @v, so long as @v was not already @u.
14586 * Returns the old value of @v.
14587 */
14588 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14589 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
14590 {
14591 - int c, old;
14592 + int c, old, new;
14593 c = atomic_read(v);
14594 for (;;) {
14595 - if (unlikely(c == (u)))
14596 + if (unlikely(c == u))
14597 break;
14598 - old = atomic_cmpxchg((v), c, c + (a));
14599 +
14600 + asm volatile("addl %2,%0\n"
14601 +
14602 +#ifdef CONFIG_PAX_REFCOUNT
14603 + "jno 0f\n"
14604 + "subl %2,%0\n"
14605 + "int $4\n0:\n"
14606 + _ASM_EXTABLE(0b, 0b)
14607 +#endif
14608 +
14609 + : "=r" (new)
14610 + : "0" (c), "ir" (a));
14611 +
14612 + old = atomic_cmpxchg(v, c, new);
14613 if (likely(old == c))
14614 break;
14615 c = old;
14616 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14617 }
14618
14619 /**
14620 + * atomic_inc_not_zero_hint - increment if not null
14621 + * @v: pointer of type atomic_t
14622 + * @hint: probable value of the atomic before the increment
14623 + *
14624 + * This version of atomic_inc_not_zero() gives a hint of probable
14625 + * value of the atomic. This helps processor to not read the memory
14626 + * before doing the atomic read/modify/write cycle, lowering
14627 + * number of bus transactions on some arches.
14628 + *
14629 + * Returns: 0 if increment was not done, 1 otherwise.
14630 + */
14631 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14632 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14633 +{
14634 + int val, c = hint, new;
14635 +
14636 + /* sanity test, should be removed by compiler if hint is a constant */
14637 + if (!hint)
14638 + return __atomic_add_unless(v, 1, 0);
14639 +
14640 + do {
14641 + asm volatile("incl %0\n"
14642 +
14643 +#ifdef CONFIG_PAX_REFCOUNT
14644 + "jno 0f\n"
14645 + "decl %0\n"
14646 + "int $4\n0:\n"
14647 + _ASM_EXTABLE(0b, 0b)
14648 +#endif
14649 +
14650 + : "=r" (new)
14651 + : "0" (c));
14652 +
14653 + val = atomic_cmpxchg(v, c, new);
14654 + if (val == c)
14655 + return 1;
14656 + c = val;
14657 + } while (c);
14658 +
14659 + return 0;
14660 +}
14661 +
14662 +/**
14663 * atomic_inc_short - increment of a short integer
14664 * @v: pointer to type int
14665 *
14666 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14667 #endif
14668
14669 /* These are x86-specific, used by some header files */
14670 -#define atomic_clear_mask(mask, addr) \
14671 - asm volatile(LOCK_PREFIX "andl %0,%1" \
14672 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
14673 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14674 +{
14675 + asm volatile(LOCK_PREFIX "andl %1,%0"
14676 + : "+m" (v->counter)
14677 + : "r" (~(mask))
14678 + : "memory");
14679 +}
14680
14681 -#define atomic_set_mask(mask, addr) \
14682 - asm volatile(LOCK_PREFIX "orl %0,%1" \
14683 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14684 - : "memory")
14685 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14686 +{
14687 + asm volatile(LOCK_PREFIX "andl %1,%0"
14688 + : "+m" (v->counter)
14689 + : "r" (~(mask))
14690 + : "memory");
14691 +}
14692 +
14693 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14694 +{
14695 + asm volatile(LOCK_PREFIX "orl %1,%0"
14696 + : "+m" (v->counter)
14697 + : "r" (mask)
14698 + : "memory");
14699 +}
14700 +
14701 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14702 +{
14703 + asm volatile(LOCK_PREFIX "orl %1,%0"
14704 + : "+m" (v->counter)
14705 + : "r" (mask)
14706 + : "memory");
14707 +}
14708
14709 /* Atomic operations are already serializing on x86 */
14710 #define smp_mb__before_atomic_dec() barrier()
14711 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14712 index b154de7..bf18a5a 100644
14713 --- a/arch/x86/include/asm/atomic64_32.h
14714 +++ b/arch/x86/include/asm/atomic64_32.h
14715 @@ -12,6 +12,14 @@ typedef struct {
14716 u64 __aligned(8) counter;
14717 } atomic64_t;
14718
14719 +#ifdef CONFIG_PAX_REFCOUNT
14720 +typedef struct {
14721 + u64 __aligned(8) counter;
14722 +} atomic64_unchecked_t;
14723 +#else
14724 +typedef atomic64_t atomic64_unchecked_t;
14725 +#endif
14726 +
14727 #define ATOMIC64_INIT(val) { (val) }
14728
14729 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14730 @@ -37,21 +45,31 @@ typedef struct {
14731 ATOMIC64_DECL_ONE(sym##_386)
14732
14733 ATOMIC64_DECL_ONE(add_386);
14734 +ATOMIC64_DECL_ONE(add_unchecked_386);
14735 ATOMIC64_DECL_ONE(sub_386);
14736 +ATOMIC64_DECL_ONE(sub_unchecked_386);
14737 ATOMIC64_DECL_ONE(inc_386);
14738 +ATOMIC64_DECL_ONE(inc_unchecked_386);
14739 ATOMIC64_DECL_ONE(dec_386);
14740 +ATOMIC64_DECL_ONE(dec_unchecked_386);
14741 #endif
14742
14743 #define alternative_atomic64(f, out, in...) \
14744 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14745
14746 ATOMIC64_DECL(read);
14747 +ATOMIC64_DECL(read_unchecked);
14748 ATOMIC64_DECL(set);
14749 +ATOMIC64_DECL(set_unchecked);
14750 ATOMIC64_DECL(xchg);
14751 ATOMIC64_DECL(add_return);
14752 +ATOMIC64_DECL(add_return_unchecked);
14753 ATOMIC64_DECL(sub_return);
14754 +ATOMIC64_DECL(sub_return_unchecked);
14755 ATOMIC64_DECL(inc_return);
14756 +ATOMIC64_DECL(inc_return_unchecked);
14757 ATOMIC64_DECL(dec_return);
14758 +ATOMIC64_DECL(dec_return_unchecked);
14759 ATOMIC64_DECL(dec_if_positive);
14760 ATOMIC64_DECL(inc_not_zero);
14761 ATOMIC64_DECL(add_unless);
14762 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14763 }
14764
14765 /**
14766 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14767 + * @p: pointer to type atomic64_unchecked_t
14768 + * @o: expected value
14769 + * @n: new value
14770 + *
14771 + * Atomically sets @v to @n if it was equal to @o and returns
14772 + * the old value.
14773 + */
14774 +
14775 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14776 +{
14777 + return cmpxchg64(&v->counter, o, n);
14778 +}
14779 +
14780 +/**
14781 * atomic64_xchg - xchg atomic64 variable
14782 * @v: pointer to type atomic64_t
14783 * @n: value to assign
14784 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14785 }
14786
14787 /**
14788 + * atomic64_set_unchecked - set atomic64 variable
14789 + * @v: pointer to type atomic64_unchecked_t
14790 + * @n: value to assign
14791 + *
14792 + * Atomically sets the value of @v to @n.
14793 + */
14794 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14795 +{
14796 + unsigned high = (unsigned)(i >> 32);
14797 + unsigned low = (unsigned)i;
14798 + alternative_atomic64(set, /* no output */,
14799 + "S" (v), "b" (low), "c" (high)
14800 + : "eax", "edx", "memory");
14801 +}
14802 +
14803 +/**
14804 * atomic64_read - read atomic64 variable
14805 * @v: pointer to type atomic64_t
14806 *
14807 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14808 }
14809
14810 /**
14811 + * atomic64_read_unchecked - read atomic64 variable
14812 + * @v: pointer to type atomic64_unchecked_t
14813 + *
14814 + * Atomically reads the value of @v and returns it.
14815 + */
14816 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
14817 +{
14818 + long long r;
14819 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14820 + return r;
14821 + }
14822 +
14823 +/**
14824 * atomic64_add_return - add and return
14825 * @i: integer value to add
14826 * @v: pointer to type atomic64_t
14827 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14828 return i;
14829 }
14830
14831 +/**
14832 + * atomic64_add_return_unchecked - add and return
14833 + * @i: integer value to add
14834 + * @v: pointer to type atomic64_unchecked_t
14835 + *
14836 + * Atomically adds @i to @v and returns @i + *@v
14837 + */
14838 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14839 +{
14840 + alternative_atomic64(add_return_unchecked,
14841 + ASM_OUTPUT2("+A" (i), "+c" (v)),
14842 + ASM_NO_INPUT_CLOBBER("memory"));
14843 + return i;
14844 +}
14845 +
14846 /*
14847 * Other variants with different arithmetic operators:
14848 */
14849 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14850 return a;
14851 }
14852
14853 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14854 +{
14855 + long long a;
14856 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
14857 + "S" (v) : "memory", "ecx");
14858 + return a;
14859 +}
14860 +
14861 static inline long long atomic64_dec_return(atomic64_t *v)
14862 {
14863 long long a;
14864 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14865 }
14866
14867 /**
14868 + * atomic64_add_unchecked - add integer to atomic64 variable
14869 + * @i: integer value to add
14870 + * @v: pointer to type atomic64_unchecked_t
14871 + *
14872 + * Atomically adds @i to @v.
14873 + */
14874 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14875 +{
14876 + __alternative_atomic64(add_unchecked, add_return_unchecked,
14877 + ASM_OUTPUT2("+A" (i), "+c" (v)),
14878 + ASM_NO_INPUT_CLOBBER("memory"));
14879 + return i;
14880 +}
14881 +
14882 +/**
14883 * atomic64_sub - subtract the atomic64 variable
14884 * @i: integer value to subtract
14885 * @v: pointer to type atomic64_t
14886 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14887 index 46e9052..ae45136 100644
14888 --- a/arch/x86/include/asm/atomic64_64.h
14889 +++ b/arch/x86/include/asm/atomic64_64.h
14890 @@ -18,7 +18,19 @@
14891 */
14892 static inline long atomic64_read(const atomic64_t *v)
14893 {
14894 - return (*(volatile long *)&(v)->counter);
14895 + return (*(volatile const long *)&(v)->counter);
14896 +}
14897 +
14898 +/**
14899 + * atomic64_read_unchecked - read atomic64 variable
14900 + * @v: pointer of type atomic64_unchecked_t
14901 + *
14902 + * Atomically reads the value of @v.
14903 + * Doesn't imply a read memory barrier.
14904 + */
14905 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
14906 +{
14907 + return (*(volatile const long *)&(v)->counter);
14908 }
14909
14910 /**
14911 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14912 }
14913
14914 /**
14915 + * atomic64_set_unchecked - set atomic64 variable
14916 + * @v: pointer to type atomic64_unchecked_t
14917 + * @i: required value
14918 + *
14919 + * Atomically sets the value of @v to @i.
14920 + */
14921 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14922 +{
14923 + v->counter = i;
14924 +}
14925 +
14926 +/**
14927 * atomic64_add - add integer to atomic64 variable
14928 * @i: integer value to add
14929 * @v: pointer to type atomic64_t
14930 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14931 */
14932 static inline void atomic64_add(long i, atomic64_t *v)
14933 {
14934 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
14935 +
14936 +#ifdef CONFIG_PAX_REFCOUNT
14937 + "jno 0f\n"
14938 + LOCK_PREFIX "subq %1,%0\n"
14939 + "int $4\n0:\n"
14940 + _ASM_EXTABLE(0b, 0b)
14941 +#endif
14942 +
14943 + : "=m" (v->counter)
14944 + : "er" (i), "m" (v->counter));
14945 +}
14946 +
14947 +/**
14948 + * atomic64_add_unchecked - add integer to atomic64 variable
14949 + * @i: integer value to add
14950 + * @v: pointer to type atomic64_unchecked_t
14951 + *
14952 + * Atomically adds @i to @v.
14953 + */
14954 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14955 +{
14956 asm volatile(LOCK_PREFIX "addq %1,%0"
14957 : "=m" (v->counter)
14958 : "er" (i), "m" (v->counter));
14959 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14960 */
14961 static inline void atomic64_sub(long i, atomic64_t *v)
14962 {
14963 - asm volatile(LOCK_PREFIX "subq %1,%0"
14964 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
14965 +
14966 +#ifdef CONFIG_PAX_REFCOUNT
14967 + "jno 0f\n"
14968 + LOCK_PREFIX "addq %1,%0\n"
14969 + "int $4\n0:\n"
14970 + _ASM_EXTABLE(0b, 0b)
14971 +#endif
14972 +
14973 + : "=m" (v->counter)
14974 + : "er" (i), "m" (v->counter));
14975 +}
14976 +
14977 +/**
14978 + * atomic64_sub_unchecked - subtract the atomic64 variable
14979 + * @i: integer value to subtract
14980 + * @v: pointer to type atomic64_unchecked_t
14981 + *
14982 + * Atomically subtracts @i from @v.
14983 + */
14984 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14985 +{
14986 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
14987 : "=m" (v->counter)
14988 : "er" (i), "m" (v->counter));
14989 }
14990 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
14991 */
14992 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14993 {
14994 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
14995 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
14996 }
14997
14998 /**
14999 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15000 */
15001 static inline void atomic64_inc(atomic64_t *v)
15002 {
15003 + asm volatile(LOCK_PREFIX "incq %0\n"
15004 +
15005 +#ifdef CONFIG_PAX_REFCOUNT
15006 + "jno 0f\n"
15007 + LOCK_PREFIX "decq %0\n"
15008 + "int $4\n0:\n"
15009 + _ASM_EXTABLE(0b, 0b)
15010 +#endif
15011 +
15012 + : "=m" (v->counter)
15013 + : "m" (v->counter));
15014 +}
15015 +
15016 +/**
15017 + * atomic64_inc_unchecked - increment atomic64 variable
15018 + * @v: pointer to type atomic64_unchecked_t
15019 + *
15020 + * Atomically increments @v by 1.
15021 + */
15022 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15023 +{
15024 asm volatile(LOCK_PREFIX "incq %0"
15025 : "=m" (v->counter)
15026 : "m" (v->counter));
15027 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15028 */
15029 static inline void atomic64_dec(atomic64_t *v)
15030 {
15031 - asm volatile(LOCK_PREFIX "decq %0"
15032 + asm volatile(LOCK_PREFIX "decq %0\n"
15033 +
15034 +#ifdef CONFIG_PAX_REFCOUNT
15035 + "jno 0f\n"
15036 + LOCK_PREFIX "incq %0\n"
15037 + "int $4\n0:\n"
15038 + _ASM_EXTABLE(0b, 0b)
15039 +#endif
15040 +
15041 + : "=m" (v->counter)
15042 + : "m" (v->counter));
15043 +}
15044 +
15045 +/**
15046 + * atomic64_dec_unchecked - decrement atomic64 variable
15047 + * @v: pointer to type atomic64_t
15048 + *
15049 + * Atomically decrements @v by 1.
15050 + */
15051 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15052 +{
15053 + asm volatile(LOCK_PREFIX "decq %0\n"
15054 : "=m" (v->counter)
15055 : "m" (v->counter));
15056 }
15057 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15058 */
15059 static inline int atomic64_dec_and_test(atomic64_t *v)
15060 {
15061 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15062 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15063 }
15064
15065 /**
15066 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15067 */
15068 static inline int atomic64_inc_and_test(atomic64_t *v)
15069 {
15070 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15071 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15072 }
15073
15074 /**
15075 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15076 */
15077 static inline int atomic64_add_negative(long i, atomic64_t *v)
15078 {
15079 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15080 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15081 }
15082
15083 /**
15084 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15085 */
15086 static inline long atomic64_add_return(long i, atomic64_t *v)
15087 {
15088 + return i + xadd_check_overflow(&v->counter, i);
15089 +}
15090 +
15091 +/**
15092 + * atomic64_add_return_unchecked - add and return
15093 + * @i: integer value to add
15094 + * @v: pointer to type atomic64_unchecked_t
15095 + *
15096 + * Atomically adds @i to @v and returns @i + @v
15097 + */
15098 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15099 +{
15100 return i + xadd(&v->counter, i);
15101 }
15102
15103 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15104 }
15105
15106 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15107 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15108 +{
15109 + return atomic64_add_return_unchecked(1, v);
15110 +}
15111 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15112
15113 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15114 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15115 return cmpxchg(&v->counter, old, new);
15116 }
15117
15118 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15119 +{
15120 + return cmpxchg(&v->counter, old, new);
15121 +}
15122 +
15123 static inline long atomic64_xchg(atomic64_t *v, long new)
15124 {
15125 return xchg(&v->counter, new);
15126 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15127 */
15128 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15129 {
15130 - long c, old;
15131 + long c, old, new;
15132 c = atomic64_read(v);
15133 for (;;) {
15134 - if (unlikely(c == (u)))
15135 + if (unlikely(c == u))
15136 break;
15137 - old = atomic64_cmpxchg((v), c, c + (a));
15138 +
15139 + asm volatile("add %2,%0\n"
15140 +
15141 +#ifdef CONFIG_PAX_REFCOUNT
15142 + "jno 0f\n"
15143 + "sub %2,%0\n"
15144 + "int $4\n0:\n"
15145 + _ASM_EXTABLE(0b, 0b)
15146 +#endif
15147 +
15148 + : "=r" (new)
15149 + : "0" (c), "ir" (a));
15150 +
15151 + old = atomic64_cmpxchg(v, c, new);
15152 if (likely(old == c))
15153 break;
15154 c = old;
15155 }
15156 - return c != (u);
15157 + return c != u;
15158 }
15159
15160 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15161 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15162 index 9fc1af7..fc71228 100644
15163 --- a/arch/x86/include/asm/bitops.h
15164 +++ b/arch/x86/include/asm/bitops.h
15165 @@ -49,7 +49,7 @@
15166 * a mask operation on a byte.
15167 */
15168 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15169 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15170 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15171 #define CONST_MASK(nr) (1 << ((nr) & 7))
15172
15173 /**
15174 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15175 */
15176 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15177 {
15178 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15179 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15180 }
15181
15182 /**
15183 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15184 */
15185 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15186 {
15187 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15188 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15189 }
15190
15191 /**
15192 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15193 */
15194 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15195 {
15196 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15197 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15198 }
15199
15200 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15201 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15202 *
15203 * Undefined if no bit exists, so code should check against 0 first.
15204 */
15205 -static inline unsigned long __ffs(unsigned long word)
15206 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15207 {
15208 asm("rep; bsf %1,%0"
15209 : "=r" (word)
15210 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15211 *
15212 * Undefined if no zero exists, so code should check against ~0UL first.
15213 */
15214 -static inline unsigned long ffz(unsigned long word)
15215 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15216 {
15217 asm("rep; bsf %1,%0"
15218 : "=r" (word)
15219 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15220 *
15221 * Undefined if no set bit exists, so code should check against 0 first.
15222 */
15223 -static inline unsigned long __fls(unsigned long word)
15224 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15225 {
15226 asm("bsr %1,%0"
15227 : "=r" (word)
15228 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15229 * set bit if value is nonzero. The last (most significant) bit is
15230 * at position 32.
15231 */
15232 -static inline int fls(int x)
15233 +static inline int __intentional_overflow(-1) fls(int x)
15234 {
15235 int r;
15236
15237 @@ -478,7 +478,7 @@ static inline int fls(int x)
15238 * at position 64.
15239 */
15240 #ifdef CONFIG_X86_64
15241 -static __always_inline int fls64(__u64 x)
15242 +static __always_inline long fls64(__u64 x)
15243 {
15244 int bitpos = -1;
15245 /*
15246 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15247 index 4fa687a..60f2d39 100644
15248 --- a/arch/x86/include/asm/boot.h
15249 +++ b/arch/x86/include/asm/boot.h
15250 @@ -6,10 +6,15 @@
15251 #include <uapi/asm/boot.h>
15252
15253 /* Physical address where kernel should be loaded. */
15254 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15255 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15256 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15257 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15258
15259 +#ifndef __ASSEMBLY__
15260 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15261 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15262 +#endif
15263 +
15264 /* Minimum kernel alignment, as a power of two */
15265 #ifdef CONFIG_X86_64
15266 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15267 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15268 index 48f99f1..d78ebf9 100644
15269 --- a/arch/x86/include/asm/cache.h
15270 +++ b/arch/x86/include/asm/cache.h
15271 @@ -5,12 +5,13 @@
15272
15273 /* L1 cache line size */
15274 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15275 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15276 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15277
15278 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15279 +#define __read_only __attribute__((__section__(".data..read_only")))
15280
15281 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15282 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15283 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15284
15285 #ifdef CONFIG_X86_VSMP
15286 #ifdef CONFIG_SMP
15287 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15288 index 9863ee3..4a1f8e1 100644
15289 --- a/arch/x86/include/asm/cacheflush.h
15290 +++ b/arch/x86/include/asm/cacheflush.h
15291 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15292 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15293
15294 if (pg_flags == _PGMT_DEFAULT)
15295 - return -1;
15296 + return ~0UL;
15297 else if (pg_flags == _PGMT_WC)
15298 return _PAGE_CACHE_WC;
15299 else if (pg_flags == _PGMT_UC_MINUS)
15300 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15301 index cb4c73b..c473c29 100644
15302 --- a/arch/x86/include/asm/calling.h
15303 +++ b/arch/x86/include/asm/calling.h
15304 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15305 #define RSP 152
15306 #define SS 160
15307
15308 -#define ARGOFFSET R11
15309 -#define SWFRAME ORIG_RAX
15310 +#define ARGOFFSET R15
15311
15312 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15313 - subq $9*8+\addskip, %rsp
15314 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15315 - movq_cfi rdi, 8*8
15316 - movq_cfi rsi, 7*8
15317 - movq_cfi rdx, 6*8
15318 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15319 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15320 + movq_cfi rdi, RDI
15321 + movq_cfi rsi, RSI
15322 + movq_cfi rdx, RDX
15323
15324 .if \save_rcx
15325 - movq_cfi rcx, 5*8
15326 + movq_cfi rcx, RCX
15327 .endif
15328
15329 - movq_cfi rax, 4*8
15330 + movq_cfi rax, RAX
15331
15332 .if \save_r891011
15333 - movq_cfi r8, 3*8
15334 - movq_cfi r9, 2*8
15335 - movq_cfi r10, 1*8
15336 - movq_cfi r11, 0*8
15337 + movq_cfi r8, R8
15338 + movq_cfi r9, R9
15339 + movq_cfi r10, R10
15340 + movq_cfi r11, R11
15341 .endif
15342
15343 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15344 + movq_cfi r12, R12
15345 +#endif
15346 +
15347 .endm
15348
15349 -#define ARG_SKIP (9*8)
15350 +#define ARG_SKIP ORIG_RAX
15351
15352 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15353 rstor_r8910=1, rstor_rdx=1
15354 +
15355 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15356 + movq_cfi_restore R12, r12
15357 +#endif
15358 +
15359 .if \rstor_r11
15360 - movq_cfi_restore 0*8, r11
15361 + movq_cfi_restore R11, r11
15362 .endif
15363
15364 .if \rstor_r8910
15365 - movq_cfi_restore 1*8, r10
15366 - movq_cfi_restore 2*8, r9
15367 - movq_cfi_restore 3*8, r8
15368 + movq_cfi_restore R10, r10
15369 + movq_cfi_restore R9, r9
15370 + movq_cfi_restore R8, r8
15371 .endif
15372
15373 .if \rstor_rax
15374 - movq_cfi_restore 4*8, rax
15375 + movq_cfi_restore RAX, rax
15376 .endif
15377
15378 .if \rstor_rcx
15379 - movq_cfi_restore 5*8, rcx
15380 + movq_cfi_restore RCX, rcx
15381 .endif
15382
15383 .if \rstor_rdx
15384 - movq_cfi_restore 6*8, rdx
15385 + movq_cfi_restore RDX, rdx
15386 .endif
15387
15388 - movq_cfi_restore 7*8, rsi
15389 - movq_cfi_restore 8*8, rdi
15390 + movq_cfi_restore RSI, rsi
15391 + movq_cfi_restore RDI, rdi
15392
15393 - .if ARG_SKIP+\addskip > 0
15394 - addq $ARG_SKIP+\addskip, %rsp
15395 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15396 + .if ORIG_RAX+\addskip > 0
15397 + addq $ORIG_RAX+\addskip, %rsp
15398 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15399 .endif
15400 .endm
15401
15402 - .macro LOAD_ARGS offset, skiprax=0
15403 - movq \offset(%rsp), %r11
15404 - movq \offset+8(%rsp), %r10
15405 - movq \offset+16(%rsp), %r9
15406 - movq \offset+24(%rsp), %r8
15407 - movq \offset+40(%rsp), %rcx
15408 - movq \offset+48(%rsp), %rdx
15409 - movq \offset+56(%rsp), %rsi
15410 - movq \offset+64(%rsp), %rdi
15411 + .macro LOAD_ARGS skiprax=0
15412 + movq R11(%rsp), %r11
15413 + movq R10(%rsp), %r10
15414 + movq R9(%rsp), %r9
15415 + movq R8(%rsp), %r8
15416 + movq RCX(%rsp), %rcx
15417 + movq RDX(%rsp), %rdx
15418 + movq RSI(%rsp), %rsi
15419 + movq RDI(%rsp), %rdi
15420 .if \skiprax
15421 .else
15422 - movq \offset+72(%rsp), %rax
15423 + movq RAX(%rsp), %rax
15424 .endif
15425 .endm
15426
15427 -#define REST_SKIP (6*8)
15428 -
15429 .macro SAVE_REST
15430 - subq $REST_SKIP, %rsp
15431 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15432 - movq_cfi rbx, 5*8
15433 - movq_cfi rbp, 4*8
15434 - movq_cfi r12, 3*8
15435 - movq_cfi r13, 2*8
15436 - movq_cfi r14, 1*8
15437 - movq_cfi r15, 0*8
15438 + movq_cfi rbx, RBX
15439 + movq_cfi rbp, RBP
15440 +
15441 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15442 + movq_cfi r12, R12
15443 +#endif
15444 +
15445 + movq_cfi r13, R13
15446 + movq_cfi r14, R14
15447 + movq_cfi r15, R15
15448 .endm
15449
15450 .macro RESTORE_REST
15451 - movq_cfi_restore 0*8, r15
15452 - movq_cfi_restore 1*8, r14
15453 - movq_cfi_restore 2*8, r13
15454 - movq_cfi_restore 3*8, r12
15455 - movq_cfi_restore 4*8, rbp
15456 - movq_cfi_restore 5*8, rbx
15457 - addq $REST_SKIP, %rsp
15458 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15459 + movq_cfi_restore R15, r15
15460 + movq_cfi_restore R14, r14
15461 + movq_cfi_restore R13, r13
15462 +
15463 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15464 + movq_cfi_restore R12, r12
15465 +#endif
15466 +
15467 + movq_cfi_restore RBP, rbp
15468 + movq_cfi_restore RBX, rbx
15469 .endm
15470
15471 .macro SAVE_ALL
15472 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15473 index f50de69..2b0a458 100644
15474 --- a/arch/x86/include/asm/checksum_32.h
15475 +++ b/arch/x86/include/asm/checksum_32.h
15476 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15477 int len, __wsum sum,
15478 int *src_err_ptr, int *dst_err_ptr);
15479
15480 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15481 + int len, __wsum sum,
15482 + int *src_err_ptr, int *dst_err_ptr);
15483 +
15484 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15485 + int len, __wsum sum,
15486 + int *src_err_ptr, int *dst_err_ptr);
15487 +
15488 /*
15489 * Note: when you get a NULL pointer exception here this means someone
15490 * passed in an incorrect kernel address to one of these functions.
15491 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15492
15493 might_sleep();
15494 stac();
15495 - ret = csum_partial_copy_generic((__force void *)src, dst,
15496 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15497 len, sum, err_ptr, NULL);
15498 clac();
15499
15500 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15501 might_sleep();
15502 if (access_ok(VERIFY_WRITE, dst, len)) {
15503 stac();
15504 - ret = csum_partial_copy_generic(src, (__force void *)dst,
15505 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15506 len, sum, NULL, err_ptr);
15507 clac();
15508 return ret;
15509 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15510 index d47786a..ce1b05d 100644
15511 --- a/arch/x86/include/asm/cmpxchg.h
15512 +++ b/arch/x86/include/asm/cmpxchg.h
15513 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15514 __compiletime_error("Bad argument size for cmpxchg");
15515 extern void __xadd_wrong_size(void)
15516 __compiletime_error("Bad argument size for xadd");
15517 +extern void __xadd_check_overflow_wrong_size(void)
15518 + __compiletime_error("Bad argument size for xadd_check_overflow");
15519 extern void __add_wrong_size(void)
15520 __compiletime_error("Bad argument size for add");
15521 +extern void __add_check_overflow_wrong_size(void)
15522 + __compiletime_error("Bad argument size for add_check_overflow");
15523
15524 /*
15525 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15526 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15527 __ret; \
15528 })
15529
15530 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15531 + ({ \
15532 + __typeof__ (*(ptr)) __ret = (arg); \
15533 + switch (sizeof(*(ptr))) { \
15534 + case __X86_CASE_L: \
15535 + asm volatile (lock #op "l %0, %1\n" \
15536 + "jno 0f\n" \
15537 + "mov %0,%1\n" \
15538 + "int $4\n0:\n" \
15539 + _ASM_EXTABLE(0b, 0b) \
15540 + : "+r" (__ret), "+m" (*(ptr)) \
15541 + : : "memory", "cc"); \
15542 + break; \
15543 + case __X86_CASE_Q: \
15544 + asm volatile (lock #op "q %q0, %1\n" \
15545 + "jno 0f\n" \
15546 + "mov %0,%1\n" \
15547 + "int $4\n0:\n" \
15548 + _ASM_EXTABLE(0b, 0b) \
15549 + : "+r" (__ret), "+m" (*(ptr)) \
15550 + : : "memory", "cc"); \
15551 + break; \
15552 + default: \
15553 + __ ## op ## _check_overflow_wrong_size(); \
15554 + } \
15555 + __ret; \
15556 + })
15557 +
15558 /*
15559 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15560 * Since this is generally used to protect other memory information, we
15561 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15562 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15563 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15564
15565 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15566 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15567 +
15568 #define __add(ptr, inc, lock) \
15569 ({ \
15570 __typeof__ (*(ptr)) __ret = (inc); \
15571 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15572 index 59c6c40..5e0b22c 100644
15573 --- a/arch/x86/include/asm/compat.h
15574 +++ b/arch/x86/include/asm/compat.h
15575 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15576 typedef u32 compat_uint_t;
15577 typedef u32 compat_ulong_t;
15578 typedef u64 __attribute__((aligned(4))) compat_u64;
15579 -typedef u32 compat_uptr_t;
15580 +typedef u32 __user compat_uptr_t;
15581
15582 struct compat_timespec {
15583 compat_time_t tv_sec;
15584 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15585 index 89270b4..f0abf8e 100644
15586 --- a/arch/x86/include/asm/cpufeature.h
15587 +++ b/arch/x86/include/asm/cpufeature.h
15588 @@ -203,7 +203,7 @@
15589 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15590 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15591 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15592 -
15593 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15594
15595 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15596 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15597 @@ -211,7 +211,7 @@
15598 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15599 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15600 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15601 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15602 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15603 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15604 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15605 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15606 @@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15607 #undef cpu_has_centaur_mcr
15608 #define cpu_has_centaur_mcr 0
15609
15610 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15611 #endif /* CONFIG_X86_64 */
15612
15613 #if __GNUC__ >= 4
15614 @@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15615
15616 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15617 t_warn:
15618 - warn_pre_alternatives();
15619 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15620 + warn_pre_alternatives();
15621 return false;
15622 #endif
15623
15624 @@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15625 ".section .discard,\"aw\",@progbits\n"
15626 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15627 ".previous\n"
15628 - ".section .altinstr_replacement,\"ax\"\n"
15629 + ".section .altinstr_replacement,\"a\"\n"
15630 "3: movb $1,%0\n"
15631 "4:\n"
15632 ".previous\n"
15633 @@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15634 " .byte 2b - 1b\n" /* src len */
15635 " .byte 4f - 3f\n" /* repl len */
15636 ".previous\n"
15637 - ".section .altinstr_replacement,\"ax\"\n"
15638 + ".section .altinstr_replacement,\"a\"\n"
15639 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15640 "4:\n"
15641 ".previous\n"
15642 @@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15643 ".section .discard,\"aw\",@progbits\n"
15644 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15645 ".previous\n"
15646 - ".section .altinstr_replacement,\"ax\"\n"
15647 + ".section .altinstr_replacement,\"a\"\n"
15648 "3: movb $0,%0\n"
15649 "4:\n"
15650 ".previous\n"
15651 @@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15652 ".section .discard,\"aw\",@progbits\n"
15653 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15654 ".previous\n"
15655 - ".section .altinstr_replacement,\"ax\"\n"
15656 + ".section .altinstr_replacement,\"a\"\n"
15657 "5: movb $1,%0\n"
15658 "6:\n"
15659 ".previous\n"
15660 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15661 index 50d033a..37deb26 100644
15662 --- a/arch/x86/include/asm/desc.h
15663 +++ b/arch/x86/include/asm/desc.h
15664 @@ -4,6 +4,7 @@
15665 #include <asm/desc_defs.h>
15666 #include <asm/ldt.h>
15667 #include <asm/mmu.h>
15668 +#include <asm/pgtable.h>
15669
15670 #include <linux/smp.h>
15671 #include <linux/percpu.h>
15672 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15673
15674 desc->type = (info->read_exec_only ^ 1) << 1;
15675 desc->type |= info->contents << 2;
15676 + desc->type |= info->seg_not_present ^ 1;
15677
15678 desc->s = 1;
15679 desc->dpl = 0x3;
15680 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15681 }
15682
15683 extern struct desc_ptr idt_descr;
15684 -extern gate_desc idt_table[];
15685 -extern struct desc_ptr debug_idt_descr;
15686 -extern gate_desc debug_idt_table[];
15687 -
15688 -struct gdt_page {
15689 - struct desc_struct gdt[GDT_ENTRIES];
15690 -} __attribute__((aligned(PAGE_SIZE)));
15691 -
15692 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15693 +extern gate_desc idt_table[IDT_ENTRIES];
15694 +extern const struct desc_ptr debug_idt_descr;
15695 +extern gate_desc debug_idt_table[IDT_ENTRIES];
15696
15697 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15698 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15699 {
15700 - return per_cpu(gdt_page, cpu).gdt;
15701 + return cpu_gdt_table[cpu];
15702 }
15703
15704 #ifdef CONFIG_X86_64
15705 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15706 unsigned long base, unsigned dpl, unsigned flags,
15707 unsigned short seg)
15708 {
15709 - gate->a = (seg << 16) | (base & 0xffff);
15710 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15711 + gate->gate.offset_low = base;
15712 + gate->gate.seg = seg;
15713 + gate->gate.reserved = 0;
15714 + gate->gate.type = type;
15715 + gate->gate.s = 0;
15716 + gate->gate.dpl = dpl;
15717 + gate->gate.p = 1;
15718 + gate->gate.offset_high = base >> 16;
15719 }
15720
15721 #endif
15722 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15723
15724 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15725 {
15726 + pax_open_kernel();
15727 memcpy(&idt[entry], gate, sizeof(*gate));
15728 + pax_close_kernel();
15729 }
15730
15731 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15732 {
15733 + pax_open_kernel();
15734 memcpy(&ldt[entry], desc, 8);
15735 + pax_close_kernel();
15736 }
15737
15738 static inline void
15739 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15740 default: size = sizeof(*gdt); break;
15741 }
15742
15743 + pax_open_kernel();
15744 memcpy(&gdt[entry], desc, size);
15745 + pax_close_kernel();
15746 }
15747
15748 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15749 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15750
15751 static inline void native_load_tr_desc(void)
15752 {
15753 + pax_open_kernel();
15754 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15755 + pax_close_kernel();
15756 }
15757
15758 static inline void native_load_gdt(const struct desc_ptr *dtr)
15759 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15760 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15761 unsigned int i;
15762
15763 + pax_open_kernel();
15764 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15765 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15766 + pax_close_kernel();
15767 }
15768
15769 #define _LDT_empty(info) \
15770 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15771 preempt_enable();
15772 }
15773
15774 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
15775 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15776 {
15777 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15778 }
15779 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15780 }
15781
15782 #ifdef CONFIG_X86_64
15783 -static inline void set_nmi_gate(int gate, void *addr)
15784 +static inline void set_nmi_gate(int gate, const void *addr)
15785 {
15786 gate_desc s;
15787
15788 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
15789 #endif
15790
15791 #ifdef CONFIG_TRACING
15792 -extern struct desc_ptr trace_idt_descr;
15793 -extern gate_desc trace_idt_table[];
15794 +extern const struct desc_ptr trace_idt_descr;
15795 +extern gate_desc trace_idt_table[IDT_ENTRIES];
15796 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15797 {
15798 write_idt_entry(trace_idt_table, entry, gate);
15799 }
15800
15801 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
15802 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
15803 unsigned dpl, unsigned ist, unsigned seg)
15804 {
15805 gate_desc s;
15806 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15807 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
15808 #endif
15809
15810 -static inline void _set_gate(int gate, unsigned type, void *addr,
15811 +static inline void _set_gate(int gate, unsigned type, const void *addr,
15812 unsigned dpl, unsigned ist, unsigned seg)
15813 {
15814 gate_desc s;
15815 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15816 #define set_intr_gate(n, addr) \
15817 do { \
15818 BUG_ON((unsigned)n > 0xFF); \
15819 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
15820 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
15821 __KERNEL_CS); \
15822 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
15823 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
15824 0, 0, __KERNEL_CS); \
15825 } while (0)
15826
15827 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
15828 /*
15829 * This routine sets up an interrupt gate at directory privilege level 3.
15830 */
15831 -static inline void set_system_intr_gate(unsigned int n, void *addr)
15832 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
15833 {
15834 BUG_ON((unsigned)n > 0xFF);
15835 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15836 }
15837
15838 -static inline void set_system_trap_gate(unsigned int n, void *addr)
15839 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
15840 {
15841 BUG_ON((unsigned)n > 0xFF);
15842 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15843 }
15844
15845 -static inline void set_trap_gate(unsigned int n, void *addr)
15846 +static inline void set_trap_gate(unsigned int n, const void *addr)
15847 {
15848 BUG_ON((unsigned)n > 0xFF);
15849 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15850 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15851 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15852 {
15853 BUG_ON((unsigned)n > 0xFF);
15854 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15855 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15856 }
15857
15858 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15859 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15860 {
15861 BUG_ON((unsigned)n > 0xFF);
15862 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15863 }
15864
15865 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15866 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15867 {
15868 BUG_ON((unsigned)n > 0xFF);
15869 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15870 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
15871 else
15872 load_idt((const struct desc_ptr *)&idt_descr);
15873 }
15874 +
15875 +#ifdef CONFIG_X86_32
15876 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15877 +{
15878 + struct desc_struct d;
15879 +
15880 + if (likely(limit))
15881 + limit = (limit - 1UL) >> PAGE_SHIFT;
15882 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
15883 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15884 +}
15885 +#endif
15886 +
15887 #endif /* _ASM_X86_DESC_H */
15888 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15889 index 278441f..b95a174 100644
15890 --- a/arch/x86/include/asm/desc_defs.h
15891 +++ b/arch/x86/include/asm/desc_defs.h
15892 @@ -31,6 +31,12 @@ struct desc_struct {
15893 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15894 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15895 };
15896 + struct {
15897 + u16 offset_low;
15898 + u16 seg;
15899 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15900 + unsigned offset_high: 16;
15901 + } gate;
15902 };
15903 } __attribute__((packed));
15904
15905 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15906 index ced283a..ffe04cc 100644
15907 --- a/arch/x86/include/asm/div64.h
15908 +++ b/arch/x86/include/asm/div64.h
15909 @@ -39,7 +39,7 @@
15910 __mod; \
15911 })
15912
15913 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15914 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15915 {
15916 union {
15917 u64 v64;
15918 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15919 index 9c999c1..3860cb8 100644
15920 --- a/arch/x86/include/asm/elf.h
15921 +++ b/arch/x86/include/asm/elf.h
15922 @@ -243,7 +243,25 @@ extern int force_personality32;
15923 the loader. We need to make sure that it is out of the way of the program
15924 that it will "exec", and that there is sufficient room for the brk. */
15925
15926 +#ifdef CONFIG_PAX_SEGMEXEC
15927 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15928 +#else
15929 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15930 +#endif
15931 +
15932 +#ifdef CONFIG_PAX_ASLR
15933 +#ifdef CONFIG_X86_32
15934 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15935 +
15936 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15937 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15938 +#else
15939 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
15940 +
15941 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15942 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15943 +#endif
15944 +#endif
15945
15946 /* This yields a mask that user programs can use to figure out what
15947 instruction set this CPU supports. This could be done in user space,
15948 @@ -296,16 +314,12 @@ do { \
15949
15950 #define ARCH_DLINFO \
15951 do { \
15952 - if (vdso_enabled) \
15953 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15954 - (unsigned long)current->mm->context.vdso); \
15955 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15956 } while (0)
15957
15958 #define ARCH_DLINFO_X32 \
15959 do { \
15960 - if (vdso_enabled) \
15961 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15962 - (unsigned long)current->mm->context.vdso); \
15963 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15964 } while (0)
15965
15966 #define AT_SYSINFO 32
15967 @@ -320,7 +334,7 @@ else \
15968
15969 #endif /* !CONFIG_X86_32 */
15970
15971 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15972 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15973
15974 #define VDSO_ENTRY \
15975 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15976 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15977 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15978 #define compat_arch_setup_additional_pages syscall32_setup_pages
15979
15980 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15981 -#define arch_randomize_brk arch_randomize_brk
15982 -
15983 /*
15984 * True on X86_32 or when emulating IA32 on X86_64
15985 */
15986 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15987 index 77a99ac..39ff7f5 100644
15988 --- a/arch/x86/include/asm/emergency-restart.h
15989 +++ b/arch/x86/include/asm/emergency-restart.h
15990 @@ -1,6 +1,6 @@
15991 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15992 #define _ASM_X86_EMERGENCY_RESTART_H
15993
15994 -extern void machine_emergency_restart(void);
15995 +extern void machine_emergency_restart(void) __noreturn;
15996
15997 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15998 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
15999 index d3d7469..677ef72 100644
16000 --- a/arch/x86/include/asm/floppy.h
16001 +++ b/arch/x86/include/asm/floppy.h
16002 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16003 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16004 } fd_routine[] = {
16005 {
16006 - request_dma,
16007 - free_dma,
16008 - get_dma_residue,
16009 - dma_mem_alloc,
16010 - hard_dma_setup
16011 + ._request_dma = request_dma,
16012 + ._free_dma = free_dma,
16013 + ._get_dma_residue = get_dma_residue,
16014 + ._dma_mem_alloc = dma_mem_alloc,
16015 + ._dma_setup = hard_dma_setup
16016 },
16017 {
16018 - vdma_request_dma,
16019 - vdma_nop,
16020 - vdma_get_dma_residue,
16021 - vdma_mem_alloc,
16022 - vdma_dma_setup
16023 + ._request_dma = vdma_request_dma,
16024 + ._free_dma = vdma_nop,
16025 + ._get_dma_residue = vdma_get_dma_residue,
16026 + ._dma_mem_alloc = vdma_mem_alloc,
16027 + ._dma_setup = vdma_dma_setup
16028 }
16029 };
16030
16031 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16032 index cea1c76..6c0d79b 100644
16033 --- a/arch/x86/include/asm/fpu-internal.h
16034 +++ b/arch/x86/include/asm/fpu-internal.h
16035 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16036 #define user_insn(insn, output, input...) \
16037 ({ \
16038 int err; \
16039 + pax_open_userland(); \
16040 asm volatile(ASM_STAC "\n" \
16041 - "1:" #insn "\n\t" \
16042 + "1:" \
16043 + __copyuser_seg \
16044 + #insn "\n\t" \
16045 "2: " ASM_CLAC "\n" \
16046 ".section .fixup,\"ax\"\n" \
16047 "3: movl $-1,%[err]\n" \
16048 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16049 _ASM_EXTABLE(1b, 3b) \
16050 : [err] "=r" (err), output \
16051 : "0"(0), input); \
16052 + pax_close_userland(); \
16053 err; \
16054 })
16055
16056 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16057 "fnclex\n\t"
16058 "emms\n\t"
16059 "fildl %P[addr]" /* set F?P to defined value */
16060 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16061 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16062 }
16063
16064 return fpu_restore_checking(&tsk->thread.fpu);
16065 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16066 index be27ba1..04a8801 100644
16067 --- a/arch/x86/include/asm/futex.h
16068 +++ b/arch/x86/include/asm/futex.h
16069 @@ -12,6 +12,7 @@
16070 #include <asm/smap.h>
16071
16072 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16073 + typecheck(u32 __user *, uaddr); \
16074 asm volatile("\t" ASM_STAC "\n" \
16075 "1:\t" insn "\n" \
16076 "2:\t" ASM_CLAC "\n" \
16077 @@ -20,15 +21,16 @@
16078 "\tjmp\t2b\n" \
16079 "\t.previous\n" \
16080 _ASM_EXTABLE(1b, 3b) \
16081 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16082 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16083 : "i" (-EFAULT), "0" (oparg), "1" (0))
16084
16085 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16086 + typecheck(u32 __user *, uaddr); \
16087 asm volatile("\t" ASM_STAC "\n" \
16088 "1:\tmovl %2, %0\n" \
16089 "\tmovl\t%0, %3\n" \
16090 "\t" insn "\n" \
16091 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16092 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16093 "\tjnz\t1b\n" \
16094 "3:\t" ASM_CLAC "\n" \
16095 "\t.section .fixup,\"ax\"\n" \
16096 @@ -38,7 +40,7 @@
16097 _ASM_EXTABLE(1b, 4b) \
16098 _ASM_EXTABLE(2b, 4b) \
16099 : "=&a" (oldval), "=&r" (ret), \
16100 - "+m" (*uaddr), "=&r" (tem) \
16101 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16102 : "r" (oparg), "i" (-EFAULT), "1" (0))
16103
16104 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16105 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16106
16107 pagefault_disable();
16108
16109 + pax_open_userland();
16110 switch (op) {
16111 case FUTEX_OP_SET:
16112 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16113 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16114 break;
16115 case FUTEX_OP_ADD:
16116 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16117 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16118 uaddr, oparg);
16119 break;
16120 case FUTEX_OP_OR:
16121 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16122 default:
16123 ret = -ENOSYS;
16124 }
16125 + pax_close_userland();
16126
16127 pagefault_enable();
16128
16129 @@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16130 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16131 return -EFAULT;
16132
16133 + pax_open_userland();
16134 asm volatile("\t" ASM_STAC "\n"
16135 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16136 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16137 "2:\t" ASM_CLAC "\n"
16138 "\t.section .fixup, \"ax\"\n"
16139 "3:\tmov %3, %0\n"
16140 "\tjmp 2b\n"
16141 "\t.previous\n"
16142 _ASM_EXTABLE(1b, 3b)
16143 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16144 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16145 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16146 : "memory"
16147 );
16148 + pax_close_userland();
16149
16150 *uval = oldval;
16151 return ret;
16152 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16153 index cba45d9..86344ba 100644
16154 --- a/arch/x86/include/asm/hw_irq.h
16155 +++ b/arch/x86/include/asm/hw_irq.h
16156 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16157 extern void enable_IO_APIC(void);
16158
16159 /* Statistics */
16160 -extern atomic_t irq_err_count;
16161 -extern atomic_t irq_mis_count;
16162 +extern atomic_unchecked_t irq_err_count;
16163 +extern atomic_unchecked_t irq_mis_count;
16164
16165 /* EISA */
16166 extern void eisa_set_level_irq(unsigned int irq);
16167 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16168 index a203659..9889f1c 100644
16169 --- a/arch/x86/include/asm/i8259.h
16170 +++ b/arch/x86/include/asm/i8259.h
16171 @@ -62,7 +62,7 @@ struct legacy_pic {
16172 void (*init)(int auto_eoi);
16173 int (*irq_pending)(unsigned int irq);
16174 void (*make_irq)(unsigned int irq);
16175 -};
16176 +} __do_const;
16177
16178 extern struct legacy_pic *legacy_pic;
16179 extern struct legacy_pic null_legacy_pic;
16180 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16181 index 34f69cb..6d95446 100644
16182 --- a/arch/x86/include/asm/io.h
16183 +++ b/arch/x86/include/asm/io.h
16184 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16185 "m" (*(volatile type __force *)addr) barrier); }
16186
16187 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16188 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16189 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16190 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16191 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16192
16193 build_mmio_read(__readb, "b", unsigned char, "=q", )
16194 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16195 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16196 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16197 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16198
16199 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16200 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16201 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16202 return ioremap_nocache(offset, size);
16203 }
16204
16205 -extern void iounmap(volatile void __iomem *addr);
16206 +extern void iounmap(const volatile void __iomem *addr);
16207
16208 extern void set_iounmap_nonlazy(void);
16209
16210 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16211
16212 #include <linux/vmalloc.h>
16213
16214 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16215 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16216 +{
16217 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16218 +}
16219 +
16220 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16221 +{
16222 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16223 +}
16224 +
16225 /*
16226 * Convert a virtual cached pointer to an uncached pointer
16227 */
16228 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16229 index bba3cf8..06bc8da 100644
16230 --- a/arch/x86/include/asm/irqflags.h
16231 +++ b/arch/x86/include/asm/irqflags.h
16232 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16233 sti; \
16234 sysexit
16235
16236 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16237 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16238 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16239 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16240 +
16241 #else
16242 #define INTERRUPT_RETURN iret
16243 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16244 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16245 index 9454c16..e4100e3 100644
16246 --- a/arch/x86/include/asm/kprobes.h
16247 +++ b/arch/x86/include/asm/kprobes.h
16248 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16249 #define RELATIVEJUMP_SIZE 5
16250 #define RELATIVECALL_OPCODE 0xe8
16251 #define RELATIVE_ADDR_SIZE 4
16252 -#define MAX_STACK_SIZE 64
16253 -#define MIN_STACK_SIZE(ADDR) \
16254 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16255 - THREAD_SIZE - (unsigned long)(ADDR))) \
16256 - ? (MAX_STACK_SIZE) \
16257 - : (((unsigned long)current_thread_info()) + \
16258 - THREAD_SIZE - (unsigned long)(ADDR)))
16259 +#define MAX_STACK_SIZE 64UL
16260 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16261
16262 #define flush_insn_slot(p) do { } while (0)
16263
16264 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16265 index 4ad6560..75c7bdd 100644
16266 --- a/arch/x86/include/asm/local.h
16267 +++ b/arch/x86/include/asm/local.h
16268 @@ -10,33 +10,97 @@ typedef struct {
16269 atomic_long_t a;
16270 } local_t;
16271
16272 +typedef struct {
16273 + atomic_long_unchecked_t a;
16274 +} local_unchecked_t;
16275 +
16276 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16277
16278 #define local_read(l) atomic_long_read(&(l)->a)
16279 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16280 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16281 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16282
16283 static inline void local_inc(local_t *l)
16284 {
16285 - asm volatile(_ASM_INC "%0"
16286 + asm volatile(_ASM_INC "%0\n"
16287 +
16288 +#ifdef CONFIG_PAX_REFCOUNT
16289 + "jno 0f\n"
16290 + _ASM_DEC "%0\n"
16291 + "int $4\n0:\n"
16292 + _ASM_EXTABLE(0b, 0b)
16293 +#endif
16294 +
16295 + : "+m" (l->a.counter));
16296 +}
16297 +
16298 +static inline void local_inc_unchecked(local_unchecked_t *l)
16299 +{
16300 + asm volatile(_ASM_INC "%0\n"
16301 : "+m" (l->a.counter));
16302 }
16303
16304 static inline void local_dec(local_t *l)
16305 {
16306 - asm volatile(_ASM_DEC "%0"
16307 + asm volatile(_ASM_DEC "%0\n"
16308 +
16309 +#ifdef CONFIG_PAX_REFCOUNT
16310 + "jno 0f\n"
16311 + _ASM_INC "%0\n"
16312 + "int $4\n0:\n"
16313 + _ASM_EXTABLE(0b, 0b)
16314 +#endif
16315 +
16316 + : "+m" (l->a.counter));
16317 +}
16318 +
16319 +static inline void local_dec_unchecked(local_unchecked_t *l)
16320 +{
16321 + asm volatile(_ASM_DEC "%0\n"
16322 : "+m" (l->a.counter));
16323 }
16324
16325 static inline void local_add(long i, local_t *l)
16326 {
16327 - asm volatile(_ASM_ADD "%1,%0"
16328 + asm volatile(_ASM_ADD "%1,%0\n"
16329 +
16330 +#ifdef CONFIG_PAX_REFCOUNT
16331 + "jno 0f\n"
16332 + _ASM_SUB "%1,%0\n"
16333 + "int $4\n0:\n"
16334 + _ASM_EXTABLE(0b, 0b)
16335 +#endif
16336 +
16337 + : "+m" (l->a.counter)
16338 + : "ir" (i));
16339 +}
16340 +
16341 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16342 +{
16343 + asm volatile(_ASM_ADD "%1,%0\n"
16344 : "+m" (l->a.counter)
16345 : "ir" (i));
16346 }
16347
16348 static inline void local_sub(long i, local_t *l)
16349 {
16350 - asm volatile(_ASM_SUB "%1,%0"
16351 + asm volatile(_ASM_SUB "%1,%0\n"
16352 +
16353 +#ifdef CONFIG_PAX_REFCOUNT
16354 + "jno 0f\n"
16355 + _ASM_ADD "%1,%0\n"
16356 + "int $4\n0:\n"
16357 + _ASM_EXTABLE(0b, 0b)
16358 +#endif
16359 +
16360 + : "+m" (l->a.counter)
16361 + : "ir" (i));
16362 +}
16363 +
16364 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16365 +{
16366 + asm volatile(_ASM_SUB "%1,%0\n"
16367 : "+m" (l->a.counter)
16368 : "ir" (i));
16369 }
16370 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16371 */
16372 static inline int local_sub_and_test(long i, local_t *l)
16373 {
16374 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16375 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16376 }
16377
16378 /**
16379 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16380 */
16381 static inline int local_dec_and_test(local_t *l)
16382 {
16383 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16384 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16385 }
16386
16387 /**
16388 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16389 */
16390 static inline int local_inc_and_test(local_t *l)
16391 {
16392 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16393 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16394 }
16395
16396 /**
16397 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16398 */
16399 static inline int local_add_negative(long i, local_t *l)
16400 {
16401 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16402 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16403 }
16404
16405 /**
16406 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16407 static inline long local_add_return(long i, local_t *l)
16408 {
16409 long __i = i;
16410 + asm volatile(_ASM_XADD "%0, %1\n"
16411 +
16412 +#ifdef CONFIG_PAX_REFCOUNT
16413 + "jno 0f\n"
16414 + _ASM_MOV "%0,%1\n"
16415 + "int $4\n0:\n"
16416 + _ASM_EXTABLE(0b, 0b)
16417 +#endif
16418 +
16419 + : "+r" (i), "+m" (l->a.counter)
16420 + : : "memory");
16421 + return i + __i;
16422 +}
16423 +
16424 +/**
16425 + * local_add_return_unchecked - add and return
16426 + * @i: integer value to add
16427 + * @l: pointer to type local_unchecked_t
16428 + *
16429 + * Atomically adds @i to @l and returns @i + @l
16430 + */
16431 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16432 +{
16433 + long __i = i;
16434 asm volatile(_ASM_XADD "%0, %1;"
16435 : "+r" (i), "+m" (l->a.counter)
16436 : : "memory");
16437 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16438
16439 #define local_cmpxchg(l, o, n) \
16440 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16441 +#define local_cmpxchg_unchecked(l, o, n) \
16442 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16443 /* Always has a lock prefix */
16444 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16445
16446 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16447 new file mode 100644
16448 index 0000000..2bfd3ba
16449 --- /dev/null
16450 +++ b/arch/x86/include/asm/mman.h
16451 @@ -0,0 +1,15 @@
16452 +#ifndef _X86_MMAN_H
16453 +#define _X86_MMAN_H
16454 +
16455 +#include <uapi/asm/mman.h>
16456 +
16457 +#ifdef __KERNEL__
16458 +#ifndef __ASSEMBLY__
16459 +#ifdef CONFIG_X86_32
16460 +#define arch_mmap_check i386_mmap_check
16461 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16462 +#endif
16463 +#endif
16464 +#endif
16465 +
16466 +#endif /* X86_MMAN_H */
16467 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16468 index 5f55e69..e20bfb1 100644
16469 --- a/arch/x86/include/asm/mmu.h
16470 +++ b/arch/x86/include/asm/mmu.h
16471 @@ -9,7 +9,7 @@
16472 * we put the segment information here.
16473 */
16474 typedef struct {
16475 - void *ldt;
16476 + struct desc_struct *ldt;
16477 int size;
16478
16479 #ifdef CONFIG_X86_64
16480 @@ -18,7 +18,19 @@ typedef struct {
16481 #endif
16482
16483 struct mutex lock;
16484 - void *vdso;
16485 + unsigned long vdso;
16486 +
16487 +#ifdef CONFIG_X86_32
16488 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16489 + unsigned long user_cs_base;
16490 + unsigned long user_cs_limit;
16491 +
16492 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16493 + cpumask_t cpu_user_cs_mask;
16494 +#endif
16495 +
16496 +#endif
16497 +#endif
16498 } mm_context_t;
16499
16500 #ifdef CONFIG_SMP
16501 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16502 index be12c53..4d24039 100644
16503 --- a/arch/x86/include/asm/mmu_context.h
16504 +++ b/arch/x86/include/asm/mmu_context.h
16505 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16506
16507 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16508 {
16509 +
16510 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16511 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
16512 + unsigned int i;
16513 + pgd_t *pgd;
16514 +
16515 + pax_open_kernel();
16516 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
16517 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16518 + set_pgd_batched(pgd+i, native_make_pgd(0));
16519 + pax_close_kernel();
16520 + }
16521 +#endif
16522 +
16523 #ifdef CONFIG_SMP
16524 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16525 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16526 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16527 struct task_struct *tsk)
16528 {
16529 unsigned cpu = smp_processor_id();
16530 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16531 + int tlbstate = TLBSTATE_OK;
16532 +#endif
16533
16534 if (likely(prev != next)) {
16535 #ifdef CONFIG_SMP
16536 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16537 + tlbstate = this_cpu_read(cpu_tlbstate.state);
16538 +#endif
16539 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16540 this_cpu_write(cpu_tlbstate.active_mm, next);
16541 #endif
16542 cpumask_set_cpu(cpu, mm_cpumask(next));
16543
16544 /* Re-load page tables */
16545 +#ifdef CONFIG_PAX_PER_CPU_PGD
16546 + pax_open_kernel();
16547 +
16548 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16549 + if (static_cpu_has(X86_FEATURE_PCID))
16550 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16551 + else
16552 +#endif
16553 +
16554 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16555 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16556 + pax_close_kernel();
16557 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
16558 +
16559 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16560 + if (static_cpu_has(X86_FEATURE_PCID)) {
16561 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16562 + u64 descriptor[2];
16563 + descriptor[0] = PCID_USER;
16564 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16565 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16566 + descriptor[0] = PCID_KERNEL;
16567 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16568 + }
16569 + } else {
16570 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16571 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16572 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16573 + else
16574 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16575 + }
16576 + } else
16577 +#endif
16578 +
16579 + load_cr3(get_cpu_pgd(cpu, kernel));
16580 +#else
16581 load_cr3(next->pgd);
16582 +#endif
16583
16584 /* Stop flush ipis for the previous mm */
16585 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16586 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16587 /* Load the LDT, if the LDT is different: */
16588 if (unlikely(prev->context.ldt != next->context.ldt))
16589 load_LDT_nolock(&next->context);
16590 +
16591 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16592 + if (!(__supported_pte_mask & _PAGE_NX)) {
16593 + smp_mb__before_clear_bit();
16594 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16595 + smp_mb__after_clear_bit();
16596 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16597 + }
16598 +#endif
16599 +
16600 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16601 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16602 + prev->context.user_cs_limit != next->context.user_cs_limit))
16603 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16604 +#ifdef CONFIG_SMP
16605 + else if (unlikely(tlbstate != TLBSTATE_OK))
16606 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16607 +#endif
16608 +#endif
16609 +
16610 }
16611 + else {
16612 +
16613 +#ifdef CONFIG_PAX_PER_CPU_PGD
16614 + pax_open_kernel();
16615 +
16616 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16617 + if (static_cpu_has(X86_FEATURE_PCID))
16618 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16619 + else
16620 +#endif
16621 +
16622 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16623 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16624 + pax_close_kernel();
16625 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
16626 +
16627 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16628 + if (static_cpu_has(X86_FEATURE_PCID)) {
16629 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16630 + u64 descriptor[2];
16631 + descriptor[0] = PCID_USER;
16632 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16633 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16634 + descriptor[0] = PCID_KERNEL;
16635 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16636 + }
16637 + } else {
16638 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16639 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16640 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16641 + else
16642 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16643 + }
16644 + } else
16645 +#endif
16646 +
16647 + load_cr3(get_cpu_pgd(cpu, kernel));
16648 +#endif
16649 +
16650 #ifdef CONFIG_SMP
16651 - else {
16652 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16653 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16654
16655 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16656 * tlb flush IPI delivery. We must reload CR3
16657 * to make sure to use no freed page tables.
16658 */
16659 +
16660 +#ifndef CONFIG_PAX_PER_CPU_PGD
16661 load_cr3(next->pgd);
16662 +#endif
16663 +
16664 load_LDT_nolock(&next->context);
16665 +
16666 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16667 + if (!(__supported_pte_mask & _PAGE_NX))
16668 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16669 +#endif
16670 +
16671 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16672 +#ifdef CONFIG_PAX_PAGEEXEC
16673 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16674 +#endif
16675 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16676 +#endif
16677 +
16678 }
16679 +#endif
16680 }
16681 -#endif
16682 }
16683
16684 #define activate_mm(prev, next) \
16685 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16686 index e3b7819..b257c64 100644
16687 --- a/arch/x86/include/asm/module.h
16688 +++ b/arch/x86/include/asm/module.h
16689 @@ -5,6 +5,7 @@
16690
16691 #ifdef CONFIG_X86_64
16692 /* X86_64 does not define MODULE_PROC_FAMILY */
16693 +#define MODULE_PROC_FAMILY ""
16694 #elif defined CONFIG_M486
16695 #define MODULE_PROC_FAMILY "486 "
16696 #elif defined CONFIG_M586
16697 @@ -57,8 +58,20 @@
16698 #error unknown processor family
16699 #endif
16700
16701 -#ifdef CONFIG_X86_32
16702 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16703 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16704 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16705 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16706 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16707 +#else
16708 +#define MODULE_PAX_KERNEXEC ""
16709 #endif
16710
16711 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16712 +#define MODULE_PAX_UDEREF "UDEREF "
16713 +#else
16714 +#define MODULE_PAX_UDEREF ""
16715 +#endif
16716 +
16717 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16718 +
16719 #endif /* _ASM_X86_MODULE_H */
16720 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16721 index 86f9301..b365cda 100644
16722 --- a/arch/x86/include/asm/nmi.h
16723 +++ b/arch/x86/include/asm/nmi.h
16724 @@ -40,11 +40,11 @@ struct nmiaction {
16725 nmi_handler_t handler;
16726 unsigned long flags;
16727 const char *name;
16728 -};
16729 +} __do_const;
16730
16731 #define register_nmi_handler(t, fn, fg, n, init...) \
16732 ({ \
16733 - static struct nmiaction init fn##_na = { \
16734 + static const struct nmiaction init fn##_na = { \
16735 .handler = (fn), \
16736 .name = (n), \
16737 .flags = (fg), \
16738 @@ -52,7 +52,7 @@ struct nmiaction {
16739 __register_nmi_handler((t), &fn##_na); \
16740 })
16741
16742 -int __register_nmi_handler(unsigned int, struct nmiaction *);
16743 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
16744
16745 void unregister_nmi_handler(unsigned int, const char *);
16746
16747 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16748 index c878924..21f4889 100644
16749 --- a/arch/x86/include/asm/page.h
16750 +++ b/arch/x86/include/asm/page.h
16751 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16752 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16753
16754 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16755 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16756
16757 #define __boot_va(x) __va(x)
16758 #define __boot_pa(x) __pa(x)
16759 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16760 index 0f1ddee..e2fc3d1 100644
16761 --- a/arch/x86/include/asm/page_64.h
16762 +++ b/arch/x86/include/asm/page_64.h
16763 @@ -7,9 +7,9 @@
16764
16765 /* duplicated to the one in bootmem.h */
16766 extern unsigned long max_pfn;
16767 -extern unsigned long phys_base;
16768 +extern const unsigned long phys_base;
16769
16770 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
16771 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16772 {
16773 unsigned long y = x - __START_KERNEL_map;
16774
16775 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16776 index 401f350..dee5d13 100644
16777 --- a/arch/x86/include/asm/paravirt.h
16778 +++ b/arch/x86/include/asm/paravirt.h
16779 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16780 return (pmd_t) { ret };
16781 }
16782
16783 -static inline pmdval_t pmd_val(pmd_t pmd)
16784 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16785 {
16786 pmdval_t ret;
16787
16788 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16789 val);
16790 }
16791
16792 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16793 +{
16794 + pgdval_t val = native_pgd_val(pgd);
16795 +
16796 + if (sizeof(pgdval_t) > sizeof(long))
16797 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16798 + val, (u64)val >> 32);
16799 + else
16800 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16801 + val);
16802 +}
16803 +
16804 static inline void pgd_clear(pgd_t *pgdp)
16805 {
16806 set_pgd(pgdp, __pgd(0));
16807 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16808 pv_mmu_ops.set_fixmap(idx, phys, flags);
16809 }
16810
16811 +#ifdef CONFIG_PAX_KERNEXEC
16812 +static inline unsigned long pax_open_kernel(void)
16813 +{
16814 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16815 +}
16816 +
16817 +static inline unsigned long pax_close_kernel(void)
16818 +{
16819 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16820 +}
16821 +#else
16822 +static inline unsigned long pax_open_kernel(void) { return 0; }
16823 +static inline unsigned long pax_close_kernel(void) { return 0; }
16824 +#endif
16825 +
16826 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16827
16828 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16829 @@ -906,7 +933,7 @@ extern void default_banner(void);
16830
16831 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16832 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16833 -#define PARA_INDIRECT(addr) *%cs:addr
16834 +#define PARA_INDIRECT(addr) *%ss:addr
16835 #endif
16836
16837 #define INTERRUPT_RETURN \
16838 @@ -981,6 +1008,21 @@ extern void default_banner(void);
16839 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16840 CLBR_NONE, \
16841 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16842 +
16843 +#define GET_CR0_INTO_RDI \
16844 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16845 + mov %rax,%rdi
16846 +
16847 +#define SET_RDI_INTO_CR0 \
16848 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16849 +
16850 +#define GET_CR3_INTO_RDI \
16851 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16852 + mov %rax,%rdi
16853 +
16854 +#define SET_RDI_INTO_CR3 \
16855 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16856 +
16857 #endif /* CONFIG_X86_32 */
16858
16859 #endif /* __ASSEMBLY__ */
16860 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16861 index aab8f67..0fb0ee4 100644
16862 --- a/arch/x86/include/asm/paravirt_types.h
16863 +++ b/arch/x86/include/asm/paravirt_types.h
16864 @@ -84,7 +84,7 @@ struct pv_init_ops {
16865 */
16866 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16867 unsigned long addr, unsigned len);
16868 -};
16869 +} __no_const __no_randomize_layout;
16870
16871
16872 struct pv_lazy_ops {
16873 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
16874 void (*enter)(void);
16875 void (*leave)(void);
16876 void (*flush)(void);
16877 -};
16878 +} __no_randomize_layout;
16879
16880 struct pv_time_ops {
16881 unsigned long long (*sched_clock)(void);
16882 unsigned long long (*steal_clock)(int cpu);
16883 unsigned long (*get_tsc_khz)(void);
16884 -};
16885 +} __no_const __no_randomize_layout;
16886
16887 struct pv_cpu_ops {
16888 /* hooks for various privileged instructions */
16889 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
16890
16891 void (*start_context_switch)(struct task_struct *prev);
16892 void (*end_context_switch)(struct task_struct *next);
16893 -};
16894 +} __no_const __no_randomize_layout;
16895
16896 struct pv_irq_ops {
16897 /*
16898 @@ -215,7 +215,7 @@ struct pv_irq_ops {
16899 #ifdef CONFIG_X86_64
16900 void (*adjust_exception_frame)(void);
16901 #endif
16902 -};
16903 +} __no_randomize_layout;
16904
16905 struct pv_apic_ops {
16906 #ifdef CONFIG_X86_LOCAL_APIC
16907 @@ -223,7 +223,7 @@ struct pv_apic_ops {
16908 unsigned long start_eip,
16909 unsigned long start_esp);
16910 #endif
16911 -};
16912 +} __no_const __no_randomize_layout;
16913
16914 struct pv_mmu_ops {
16915 unsigned long (*read_cr2)(void);
16916 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
16917 struct paravirt_callee_save make_pud;
16918
16919 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16920 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16921 #endif /* PAGETABLE_LEVELS == 4 */
16922 #endif /* PAGETABLE_LEVELS >= 3 */
16923
16924 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
16925 an mfn. We can tell which is which from the index. */
16926 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16927 phys_addr_t phys, pgprot_t flags);
16928 -};
16929 +
16930 +#ifdef CONFIG_PAX_KERNEXEC
16931 + unsigned long (*pax_open_kernel)(void);
16932 + unsigned long (*pax_close_kernel)(void);
16933 +#endif
16934 +
16935 +} __no_randomize_layout;
16936
16937 struct arch_spinlock;
16938 #ifdef CONFIG_SMP
16939 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
16940 struct pv_lock_ops {
16941 struct paravirt_callee_save lock_spinning;
16942 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
16943 -};
16944 +} __no_randomize_layout;
16945
16946 /* This contains all the paravirt structures: we get a convenient
16947 * number for each function using the offset which we use to indicate
16948 - * what to patch. */
16949 + * what to patch.
16950 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
16951 + */
16952 +
16953 struct paravirt_patch_template {
16954 struct pv_init_ops pv_init_ops;
16955 struct pv_time_ops pv_time_ops;
16956 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
16957 struct pv_apic_ops pv_apic_ops;
16958 struct pv_mmu_ops pv_mmu_ops;
16959 struct pv_lock_ops pv_lock_ops;
16960 -};
16961 +} __no_randomize_layout;
16962
16963 extern struct pv_info pv_info;
16964 extern struct pv_init_ops pv_init_ops;
16965 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16966 index c4412e9..90e88c5 100644
16967 --- a/arch/x86/include/asm/pgalloc.h
16968 +++ b/arch/x86/include/asm/pgalloc.h
16969 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16970 pmd_t *pmd, pte_t *pte)
16971 {
16972 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16973 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16974 +}
16975 +
16976 +static inline void pmd_populate_user(struct mm_struct *mm,
16977 + pmd_t *pmd, pte_t *pte)
16978 +{
16979 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16980 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16981 }
16982
16983 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16984
16985 #ifdef CONFIG_X86_PAE
16986 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16987 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16988 +{
16989 + pud_populate(mm, pudp, pmd);
16990 +}
16991 #else /* !CONFIG_X86_PAE */
16992 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16993 {
16994 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16995 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16996 }
16997 +
16998 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16999 +{
17000 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17001 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17002 +}
17003 #endif /* CONFIG_X86_PAE */
17004
17005 #if PAGETABLE_LEVELS > 3
17006 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17007 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17008 }
17009
17010 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17011 +{
17012 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17013 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17014 +}
17015 +
17016 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17017 {
17018 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17019 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17020 index 3bf2dd0..23d2a9f 100644
17021 --- a/arch/x86/include/asm/pgtable-2level.h
17022 +++ b/arch/x86/include/asm/pgtable-2level.h
17023 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17024
17025 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17026 {
17027 + pax_open_kernel();
17028 *pmdp = pmd;
17029 + pax_close_kernel();
17030 }
17031
17032 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17033 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17034 index 81bb91b..9392125 100644
17035 --- a/arch/x86/include/asm/pgtable-3level.h
17036 +++ b/arch/x86/include/asm/pgtable-3level.h
17037 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17038
17039 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17040 {
17041 + pax_open_kernel();
17042 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17043 + pax_close_kernel();
17044 }
17045
17046 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17047 {
17048 + pax_open_kernel();
17049 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17050 + pax_close_kernel();
17051 }
17052
17053 /*
17054 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17055 index bbc8b12..f228861 100644
17056 --- a/arch/x86/include/asm/pgtable.h
17057 +++ b/arch/x86/include/asm/pgtable.h
17058 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17059
17060 #ifndef __PAGETABLE_PUD_FOLDED
17061 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17062 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17063 #define pgd_clear(pgd) native_pgd_clear(pgd)
17064 #endif
17065
17066 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17067
17068 #define arch_end_context_switch(prev) do {} while(0)
17069
17070 +#define pax_open_kernel() native_pax_open_kernel()
17071 +#define pax_close_kernel() native_pax_close_kernel()
17072 #endif /* CONFIG_PARAVIRT */
17073
17074 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17075 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17076 +
17077 +#ifdef CONFIG_PAX_KERNEXEC
17078 +static inline unsigned long native_pax_open_kernel(void)
17079 +{
17080 + unsigned long cr0;
17081 +
17082 + preempt_disable();
17083 + barrier();
17084 + cr0 = read_cr0() ^ X86_CR0_WP;
17085 + BUG_ON(cr0 & X86_CR0_WP);
17086 + write_cr0(cr0);
17087 + return cr0 ^ X86_CR0_WP;
17088 +}
17089 +
17090 +static inline unsigned long native_pax_close_kernel(void)
17091 +{
17092 + unsigned long cr0;
17093 +
17094 + cr0 = read_cr0() ^ X86_CR0_WP;
17095 + BUG_ON(!(cr0 & X86_CR0_WP));
17096 + write_cr0(cr0);
17097 + barrier();
17098 + preempt_enable_no_resched();
17099 + return cr0 ^ X86_CR0_WP;
17100 +}
17101 +#else
17102 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17103 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17104 +#endif
17105 +
17106 /*
17107 * The following only work if pte_present() is true.
17108 * Undefined behaviour if not..
17109 */
17110 +static inline int pte_user(pte_t pte)
17111 +{
17112 + return pte_val(pte) & _PAGE_USER;
17113 +}
17114 +
17115 static inline int pte_dirty(pte_t pte)
17116 {
17117 return pte_flags(pte) & _PAGE_DIRTY;
17118 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17119 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17120 }
17121
17122 +static inline unsigned long pgd_pfn(pgd_t pgd)
17123 +{
17124 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17125 +}
17126 +
17127 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17128
17129 static inline int pmd_large(pmd_t pte)
17130 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17131 return pte_clear_flags(pte, _PAGE_RW);
17132 }
17133
17134 +static inline pte_t pte_mkread(pte_t pte)
17135 +{
17136 + return __pte(pte_val(pte) | _PAGE_USER);
17137 +}
17138 +
17139 static inline pte_t pte_mkexec(pte_t pte)
17140 {
17141 - return pte_clear_flags(pte, _PAGE_NX);
17142 +#ifdef CONFIG_X86_PAE
17143 + if (__supported_pte_mask & _PAGE_NX)
17144 + return pte_clear_flags(pte, _PAGE_NX);
17145 + else
17146 +#endif
17147 + return pte_set_flags(pte, _PAGE_USER);
17148 +}
17149 +
17150 +static inline pte_t pte_exprotect(pte_t pte)
17151 +{
17152 +#ifdef CONFIG_X86_PAE
17153 + if (__supported_pte_mask & _PAGE_NX)
17154 + return pte_set_flags(pte, _PAGE_NX);
17155 + else
17156 +#endif
17157 + return pte_clear_flags(pte, _PAGE_USER);
17158 }
17159
17160 static inline pte_t pte_mkdirty(pte_t pte)
17161 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17162 #endif
17163
17164 #ifndef __ASSEMBLY__
17165 +
17166 +#ifdef CONFIG_PAX_PER_CPU_PGD
17167 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17168 +enum cpu_pgd_type {kernel = 0, user = 1};
17169 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17170 +{
17171 + return cpu_pgd[cpu][type];
17172 +}
17173 +#endif
17174 +
17175 #include <linux/mm_types.h>
17176 #include <linux/mmdebug.h>
17177 #include <linux/log2.h>
17178 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17179 * Currently stuck as a macro due to indirect forward reference to
17180 * linux/mmzone.h's __section_mem_map_addr() definition:
17181 */
17182 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17183 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17184
17185 /* Find an entry in the second-level page table.. */
17186 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17187 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17188 * Currently stuck as a macro due to indirect forward reference to
17189 * linux/mmzone.h's __section_mem_map_addr() definition:
17190 */
17191 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17192 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17193
17194 /* to find an entry in a page-table-directory. */
17195 static inline unsigned long pud_index(unsigned long address)
17196 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17197
17198 static inline int pgd_bad(pgd_t pgd)
17199 {
17200 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17201 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17202 }
17203
17204 static inline int pgd_none(pgd_t pgd)
17205 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17206 * pgd_offset() returns a (pgd_t *)
17207 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17208 */
17209 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17210 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17211 +
17212 +#ifdef CONFIG_PAX_PER_CPU_PGD
17213 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17214 +#endif
17215 +
17216 /*
17217 * a shortcut which implies the use of the kernel's pgd, instead
17218 * of a process's
17219 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17220 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17221 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17222
17223 +#ifdef CONFIG_X86_32
17224 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17225 +#else
17226 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17227 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17228 +
17229 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17230 +#ifdef __ASSEMBLY__
17231 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17232 +#else
17233 +extern unsigned long pax_user_shadow_base;
17234 +extern pgdval_t clone_pgd_mask;
17235 +#endif
17236 +#endif
17237 +
17238 +#endif
17239 +
17240 #ifndef __ASSEMBLY__
17241
17242 extern int direct_gbpages;
17243 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17244 * dst and src can be on the same page, but the range must not overlap,
17245 * and must not cross a page boundary.
17246 */
17247 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17248 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17249 {
17250 - memcpy(dst, src, count * sizeof(pgd_t));
17251 + pax_open_kernel();
17252 + while (count--)
17253 + *dst++ = *src++;
17254 + pax_close_kernel();
17255 }
17256
17257 +#ifdef CONFIG_PAX_PER_CPU_PGD
17258 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17259 +#endif
17260 +
17261 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17262 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17263 +#else
17264 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17265 +#endif
17266 +
17267 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17268 static inline int page_level_shift(enum pg_level level)
17269 {
17270 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17271 index 9ee3221..b979c6b 100644
17272 --- a/arch/x86/include/asm/pgtable_32.h
17273 +++ b/arch/x86/include/asm/pgtable_32.h
17274 @@ -25,9 +25,6 @@
17275 struct mm_struct;
17276 struct vm_area_struct;
17277
17278 -extern pgd_t swapper_pg_dir[1024];
17279 -extern pgd_t initial_page_table[1024];
17280 -
17281 static inline void pgtable_cache_init(void) { }
17282 static inline void check_pgt_cache(void) { }
17283 void paging_init(void);
17284 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17285 # include <asm/pgtable-2level.h>
17286 #endif
17287
17288 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17289 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17290 +#ifdef CONFIG_X86_PAE
17291 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17292 +#endif
17293 +
17294 #if defined(CONFIG_HIGHPTE)
17295 #define pte_offset_map(dir, address) \
17296 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17297 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17298 /* Clear a kernel PTE and flush it from the TLB */
17299 #define kpte_clear_flush(ptep, vaddr) \
17300 do { \
17301 + pax_open_kernel(); \
17302 pte_clear(&init_mm, (vaddr), (ptep)); \
17303 + pax_close_kernel(); \
17304 __flush_tlb_one((vaddr)); \
17305 } while (0)
17306
17307 #endif /* !__ASSEMBLY__ */
17308
17309 +#define HAVE_ARCH_UNMAPPED_AREA
17310 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17311 +
17312 /*
17313 * kern_addr_valid() is (1) for FLATMEM and (0) for
17314 * SPARSEMEM and DISCONTIGMEM
17315 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17316 index ed5903b..c7fe163 100644
17317 --- a/arch/x86/include/asm/pgtable_32_types.h
17318 +++ b/arch/x86/include/asm/pgtable_32_types.h
17319 @@ -8,7 +8,7 @@
17320 */
17321 #ifdef CONFIG_X86_PAE
17322 # include <asm/pgtable-3level_types.h>
17323 -# define PMD_SIZE (1UL << PMD_SHIFT)
17324 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17325 # define PMD_MASK (~(PMD_SIZE - 1))
17326 #else
17327 # include <asm/pgtable-2level_types.h>
17328 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17329 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17330 #endif
17331
17332 +#ifdef CONFIG_PAX_KERNEXEC
17333 +#ifndef __ASSEMBLY__
17334 +extern unsigned char MODULES_EXEC_VADDR[];
17335 +extern unsigned char MODULES_EXEC_END[];
17336 +#endif
17337 +#include <asm/boot.h>
17338 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17339 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17340 +#else
17341 +#define ktla_ktva(addr) (addr)
17342 +#define ktva_ktla(addr) (addr)
17343 +#endif
17344 +
17345 #define MODULES_VADDR VMALLOC_START
17346 #define MODULES_END VMALLOC_END
17347 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17348 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17349 index e22c1db..23a625a 100644
17350 --- a/arch/x86/include/asm/pgtable_64.h
17351 +++ b/arch/x86/include/asm/pgtable_64.h
17352 @@ -16,10 +16,14 @@
17353
17354 extern pud_t level3_kernel_pgt[512];
17355 extern pud_t level3_ident_pgt[512];
17356 +extern pud_t level3_vmalloc_start_pgt[512];
17357 +extern pud_t level3_vmalloc_end_pgt[512];
17358 +extern pud_t level3_vmemmap_pgt[512];
17359 +extern pud_t level2_vmemmap_pgt[512];
17360 extern pmd_t level2_kernel_pgt[512];
17361 extern pmd_t level2_fixmap_pgt[512];
17362 -extern pmd_t level2_ident_pgt[512];
17363 -extern pgd_t init_level4_pgt[];
17364 +extern pmd_t level2_ident_pgt[512*2];
17365 +extern pgd_t init_level4_pgt[512];
17366
17367 #define swapper_pg_dir init_level4_pgt
17368
17369 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17370
17371 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17372 {
17373 + pax_open_kernel();
17374 *pmdp = pmd;
17375 + pax_close_kernel();
17376 }
17377
17378 static inline void native_pmd_clear(pmd_t *pmd)
17379 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17380
17381 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17382 {
17383 + pax_open_kernel();
17384 *pudp = pud;
17385 + pax_close_kernel();
17386 }
17387
17388 static inline void native_pud_clear(pud_t *pud)
17389 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17390
17391 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17392 {
17393 + pax_open_kernel();
17394 + *pgdp = pgd;
17395 + pax_close_kernel();
17396 +}
17397 +
17398 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17399 +{
17400 *pgdp = pgd;
17401 }
17402
17403 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17404 index 2d88344..4679fc3 100644
17405 --- a/arch/x86/include/asm/pgtable_64_types.h
17406 +++ b/arch/x86/include/asm/pgtable_64_types.h
17407 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17408 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17409 #define MODULES_END _AC(0xffffffffff000000, UL)
17410 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17411 +#define MODULES_EXEC_VADDR MODULES_VADDR
17412 +#define MODULES_EXEC_END MODULES_END
17413 +
17414 +#define ktla_ktva(addr) (addr)
17415 +#define ktva_ktla(addr) (addr)
17416
17417 #define EARLY_DYNAMIC_PAGE_TABLES 64
17418
17419 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17420 index 0ecac25..7a15e09 100644
17421 --- a/arch/x86/include/asm/pgtable_types.h
17422 +++ b/arch/x86/include/asm/pgtable_types.h
17423 @@ -16,13 +16,12 @@
17424 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17425 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17426 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17427 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17428 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17429 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17430 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17431 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17432 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17433 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17434 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17435 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17436 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17437 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17438
17439 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17440 @@ -40,7 +39,6 @@
17441 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17442 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17443 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17444 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17445 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17446 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17447 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17448 @@ -87,8 +85,10 @@
17449
17450 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17451 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17452 -#else
17453 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17454 #define _PAGE_NX (_AT(pteval_t, 0))
17455 +#else
17456 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17457 #endif
17458
17459 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17460 @@ -146,6 +146,9 @@
17461 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17462 _PAGE_ACCESSED)
17463
17464 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17465 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17466 +
17467 #define __PAGE_KERNEL_EXEC \
17468 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17469 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17470 @@ -156,7 +159,7 @@
17471 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17472 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17473 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17474 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17475 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17476 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17477 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17478 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17479 @@ -218,8 +221,8 @@
17480 * bits are combined, this will alow user to access the high address mapped
17481 * VDSO in the presence of CONFIG_COMPAT_VDSO
17482 */
17483 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17484 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17485 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17486 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17487 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17488 #endif
17489
17490 @@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17491 {
17492 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17493 }
17494 +#endif
17495
17496 +#if PAGETABLE_LEVELS == 3
17497 +#include <asm-generic/pgtable-nopud.h>
17498 +#endif
17499 +
17500 +#if PAGETABLE_LEVELS == 2
17501 +#include <asm-generic/pgtable-nopmd.h>
17502 +#endif
17503 +
17504 +#ifndef __ASSEMBLY__
17505 #if PAGETABLE_LEVELS > 3
17506 typedef struct { pudval_t pud; } pud_t;
17507
17508 @@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17509 return pud.pud;
17510 }
17511 #else
17512 -#include <asm-generic/pgtable-nopud.h>
17513 -
17514 static inline pudval_t native_pud_val(pud_t pud)
17515 {
17516 return native_pgd_val(pud.pgd);
17517 @@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17518 return pmd.pmd;
17519 }
17520 #else
17521 -#include <asm-generic/pgtable-nopmd.h>
17522 -
17523 static inline pmdval_t native_pmd_val(pmd_t pmd)
17524 {
17525 return native_pgd_val(pmd.pud.pgd);
17526 @@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
17527
17528 extern pteval_t __supported_pte_mask;
17529 extern void set_nx(void);
17530 -extern int nx_enabled;
17531
17532 #define pgprot_writecombine pgprot_writecombine
17533 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17534 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17535 index c8b0519..fd29e73 100644
17536 --- a/arch/x86/include/asm/preempt.h
17537 +++ b/arch/x86/include/asm/preempt.h
17538 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17539 */
17540 static __always_inline bool __preempt_count_dec_and_test(void)
17541 {
17542 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17543 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17544 }
17545
17546 /*
17547 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17548 index 7b034a4..4fe3e3f 100644
17549 --- a/arch/x86/include/asm/processor.h
17550 +++ b/arch/x86/include/asm/processor.h
17551 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17552 /* Index into per_cpu list: */
17553 u16 cpu_index;
17554 u32 microcode;
17555 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17556 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17557
17558 #define X86_VENDOR_INTEL 0
17559 #define X86_VENDOR_CYRIX 1
17560 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17561 : "memory");
17562 }
17563
17564 +/* invpcid (%rdx),%rax */
17565 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17566 +
17567 +#define INVPCID_SINGLE_ADDRESS 0UL
17568 +#define INVPCID_SINGLE_CONTEXT 1UL
17569 +#define INVPCID_ALL_GLOBAL 2UL
17570 +#define INVPCID_ALL_MONGLOBAL 3UL
17571 +
17572 +#define PCID_KERNEL 0UL
17573 +#define PCID_USER 1UL
17574 +#define PCID_NOFLUSH (1UL << 63)
17575 +
17576 static inline void load_cr3(pgd_t *pgdir)
17577 {
17578 - write_cr3(__pa(pgdir));
17579 + write_cr3(__pa(pgdir) | PCID_KERNEL);
17580 }
17581
17582 #ifdef CONFIG_X86_32
17583 @@ -283,7 +295,7 @@ struct tss_struct {
17584
17585 } ____cacheline_aligned;
17586
17587 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17588 +extern struct tss_struct init_tss[NR_CPUS];
17589
17590 /*
17591 * Save the original ist values for checking stack pointers during debugging
17592 @@ -453,6 +465,7 @@ struct thread_struct {
17593 unsigned short ds;
17594 unsigned short fsindex;
17595 unsigned short gsindex;
17596 + unsigned short ss;
17597 #endif
17598 #ifdef CONFIG_X86_32
17599 unsigned long ip;
17600 @@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
17601 extern unsigned long mmu_cr4_features;
17602 extern u32 *trampoline_cr4_features;
17603
17604 -static inline void set_in_cr4(unsigned long mask)
17605 -{
17606 - unsigned long cr4;
17607 -
17608 - mmu_cr4_features |= mask;
17609 - if (trampoline_cr4_features)
17610 - *trampoline_cr4_features = mmu_cr4_features;
17611 - cr4 = read_cr4();
17612 - cr4 |= mask;
17613 - write_cr4(cr4);
17614 -}
17615 -
17616 -static inline void clear_in_cr4(unsigned long mask)
17617 -{
17618 - unsigned long cr4;
17619 -
17620 - mmu_cr4_features &= ~mask;
17621 - if (trampoline_cr4_features)
17622 - *trampoline_cr4_features = mmu_cr4_features;
17623 - cr4 = read_cr4();
17624 - cr4 &= ~mask;
17625 - write_cr4(cr4);
17626 -}
17627 +extern void set_in_cr4(unsigned long mask);
17628 +extern void clear_in_cr4(unsigned long mask);
17629
17630 typedef struct {
17631 unsigned long seg;
17632 @@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
17633 */
17634 #define TASK_SIZE PAGE_OFFSET
17635 #define TASK_SIZE_MAX TASK_SIZE
17636 +
17637 +#ifdef CONFIG_PAX_SEGMEXEC
17638 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17639 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17640 +#else
17641 #define STACK_TOP TASK_SIZE
17642 -#define STACK_TOP_MAX STACK_TOP
17643 +#endif
17644 +
17645 +#define STACK_TOP_MAX TASK_SIZE
17646
17647 #define INIT_THREAD { \
17648 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
17649 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17650 .vm86_info = NULL, \
17651 .sysenter_cs = __KERNEL_CS, \
17652 .io_bitmap_ptr = NULL, \
17653 @@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
17654 */
17655 #define INIT_TSS { \
17656 .x86_tss = { \
17657 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
17658 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17659 .ss0 = __KERNEL_DS, \
17660 .ss1 = __KERNEL_CS, \
17661 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17662 @@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
17663 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17664
17665 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17666 -#define KSTK_TOP(info) \
17667 -({ \
17668 - unsigned long *__ptr = (unsigned long *)(info); \
17669 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17670 -})
17671 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17672
17673 /*
17674 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17675 @@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17676 #define task_pt_regs(task) \
17677 ({ \
17678 struct pt_regs *__regs__; \
17679 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17680 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17681 __regs__ - 1; \
17682 })
17683
17684 @@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17685 /*
17686 * User space process size. 47bits minus one guard page.
17687 */
17688 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17689 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17690
17691 /* This decides where the kernel will search for a free chunk of vm
17692 * space during mmap's.
17693 */
17694 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17695 - 0xc0000000 : 0xFFFFe000)
17696 + 0xc0000000 : 0xFFFFf000)
17697
17698 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17699 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17700 @@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17701 #define STACK_TOP_MAX TASK_SIZE_MAX
17702
17703 #define INIT_THREAD { \
17704 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17705 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17706 }
17707
17708 #define INIT_TSS { \
17709 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17710 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17711 }
17712
17713 /*
17714 @@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17715 */
17716 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17717
17718 +#ifdef CONFIG_PAX_SEGMEXEC
17719 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17720 +#endif
17721 +
17722 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17723
17724 /* Get/set a process' ability to use the timestamp counter instruction */
17725 @@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17726 return 0;
17727 }
17728
17729 -extern unsigned long arch_align_stack(unsigned long sp);
17730 +#define arch_align_stack(x) ((x) & ~0xfUL)
17731 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17732
17733 void default_idle(void);
17734 @@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
17735 #define xen_set_default_idle 0
17736 #endif
17737
17738 -void stop_this_cpu(void *dummy);
17739 +void stop_this_cpu(void *dummy) __noreturn;
17740 void df_debug(struct pt_regs *regs, long error_code);
17741 #endif /* _ASM_X86_PROCESSOR_H */
17742 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17743 index 942a086..6c26446 100644
17744 --- a/arch/x86/include/asm/ptrace.h
17745 +++ b/arch/x86/include/asm/ptrace.h
17746 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17747 }
17748
17749 /*
17750 - * user_mode_vm(regs) determines whether a register set came from user mode.
17751 + * user_mode(regs) determines whether a register set came from user mode.
17752 * This is true if V8086 mode was enabled OR if the register set was from
17753 * protected mode with RPL-3 CS value. This tricky test checks that with
17754 * one comparison. Many places in the kernel can bypass this full check
17755 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17756 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17757 + * be used.
17758 */
17759 -static inline int user_mode(struct pt_regs *regs)
17760 +static inline int user_mode_novm(struct pt_regs *regs)
17761 {
17762 #ifdef CONFIG_X86_32
17763 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17764 #else
17765 - return !!(regs->cs & 3);
17766 + return !!(regs->cs & SEGMENT_RPL_MASK);
17767 #endif
17768 }
17769
17770 -static inline int user_mode_vm(struct pt_regs *regs)
17771 +static inline int user_mode(struct pt_regs *regs)
17772 {
17773 #ifdef CONFIG_X86_32
17774 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17775 USER_RPL;
17776 #else
17777 - return user_mode(regs);
17778 + return user_mode_novm(regs);
17779 #endif
17780 }
17781
17782 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17783 #ifdef CONFIG_X86_64
17784 static inline bool user_64bit_mode(struct pt_regs *regs)
17785 {
17786 + unsigned long cs = regs->cs & 0xffff;
17787 #ifndef CONFIG_PARAVIRT
17788 /*
17789 * On non-paravirt systems, this is the only long mode CPL 3
17790 * selector. We do not allow long mode selectors in the LDT.
17791 */
17792 - return regs->cs == __USER_CS;
17793 + return cs == __USER_CS;
17794 #else
17795 /* Headers are too twisted for this to go in paravirt.h. */
17796 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17797 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17798 #endif
17799 }
17800
17801 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17802 * Traps from the kernel do not save sp and ss.
17803 * Use the helper function to retrieve sp.
17804 */
17805 - if (offset == offsetof(struct pt_regs, sp) &&
17806 - regs->cs == __KERNEL_CS)
17807 - return kernel_stack_pointer(regs);
17808 + if (offset == offsetof(struct pt_regs, sp)) {
17809 + unsigned long cs = regs->cs & 0xffff;
17810 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17811 + return kernel_stack_pointer(regs);
17812 + }
17813 #endif
17814 return *(unsigned long *)((unsigned long)regs + offset);
17815 }
17816 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17817 index 9c6b890..5305f53 100644
17818 --- a/arch/x86/include/asm/realmode.h
17819 +++ b/arch/x86/include/asm/realmode.h
17820 @@ -22,16 +22,14 @@ struct real_mode_header {
17821 #endif
17822 /* APM/BIOS reboot */
17823 u32 machine_real_restart_asm;
17824 -#ifdef CONFIG_X86_64
17825 u32 machine_real_restart_seg;
17826 -#endif
17827 };
17828
17829 /* This must match data at trampoline_32/64.S */
17830 struct trampoline_header {
17831 #ifdef CONFIG_X86_32
17832 u32 start;
17833 - u16 gdt_pad;
17834 + u16 boot_cs;
17835 u16 gdt_limit;
17836 u32 gdt_base;
17837 #else
17838 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17839 index a82c4f1..ac45053 100644
17840 --- a/arch/x86/include/asm/reboot.h
17841 +++ b/arch/x86/include/asm/reboot.h
17842 @@ -6,13 +6,13 @@
17843 struct pt_regs;
17844
17845 struct machine_ops {
17846 - void (*restart)(char *cmd);
17847 - void (*halt)(void);
17848 - void (*power_off)(void);
17849 + void (* __noreturn restart)(char *cmd);
17850 + void (* __noreturn halt)(void);
17851 + void (* __noreturn power_off)(void);
17852 void (*shutdown)(void);
17853 void (*crash_shutdown)(struct pt_regs *);
17854 - void (*emergency_restart)(void);
17855 -};
17856 + void (* __noreturn emergency_restart)(void);
17857 +} __no_const;
17858
17859 extern struct machine_ops machine_ops;
17860
17861 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
17862 index 8f7866a..e442f20 100644
17863 --- a/arch/x86/include/asm/rmwcc.h
17864 +++ b/arch/x86/include/asm/rmwcc.h
17865 @@ -3,7 +3,34 @@
17866
17867 #ifdef CC_HAVE_ASM_GOTO
17868
17869 -#define __GEN_RMWcc(fullop, var, cc, ...) \
17870 +#ifdef CONFIG_PAX_REFCOUNT
17871 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17872 +do { \
17873 + asm_volatile_goto (fullop \
17874 + ";jno 0f\n" \
17875 + fullantiop \
17876 + ";int $4\n0:\n" \
17877 + _ASM_EXTABLE(0b, 0b) \
17878 + ";j" cc " %l[cc_label]" \
17879 + : : "m" (var), ## __VA_ARGS__ \
17880 + : "memory" : cc_label); \
17881 + return 0; \
17882 +cc_label: \
17883 + return 1; \
17884 +} while (0)
17885 +#else
17886 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17887 +do { \
17888 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
17889 + : : "m" (var), ## __VA_ARGS__ \
17890 + : "memory" : cc_label); \
17891 + return 0; \
17892 +cc_label: \
17893 + return 1; \
17894 +} while (0)
17895 +#endif
17896 +
17897 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17898 do { \
17899 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
17900 : : "m" (var), ## __VA_ARGS__ \
17901 @@ -13,15 +40,46 @@ cc_label: \
17902 return 1; \
17903 } while (0)
17904
17905 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17906 - __GEN_RMWcc(op " " arg0, var, cc)
17907 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17908 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17909
17910 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17911 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
17912 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17913 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17914 +
17915 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17916 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
17917 +
17918 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17919 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
17920
17921 #else /* !CC_HAVE_ASM_GOTO */
17922
17923 -#define __GEN_RMWcc(fullop, var, cc, ...) \
17924 +#ifdef CONFIG_PAX_REFCOUNT
17925 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17926 +do { \
17927 + char c; \
17928 + asm volatile (fullop \
17929 + ";jno 0f\n" \
17930 + fullantiop \
17931 + ";int $4\n0:\n" \
17932 + _ASM_EXTABLE(0b, 0b) \
17933 + "; set" cc " %1" \
17934 + : "+m" (var), "=qm" (c) \
17935 + : __VA_ARGS__ : "memory"); \
17936 + return c != 0; \
17937 +} while (0)
17938 +#else
17939 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17940 +do { \
17941 + char c; \
17942 + asm volatile (fullop "; set" cc " %1" \
17943 + : "+m" (var), "=qm" (c) \
17944 + : __VA_ARGS__ : "memory"); \
17945 + return c != 0; \
17946 +} while (0)
17947 +#endif
17948 +
17949 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17950 do { \
17951 char c; \
17952 asm volatile (fullop "; set" cc " %1" \
17953 @@ -30,11 +88,17 @@ do { \
17954 return c != 0; \
17955 } while (0)
17956
17957 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17958 - __GEN_RMWcc(op " " arg0, var, cc)
17959 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17960 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17961 +
17962 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17963 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17964 +
17965 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17966 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
17967
17968 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17969 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
17970 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17971 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
17972
17973 #endif /* CC_HAVE_ASM_GOTO */
17974
17975 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17976 index cad82c9..2e5c5c1 100644
17977 --- a/arch/x86/include/asm/rwsem.h
17978 +++ b/arch/x86/include/asm/rwsem.h
17979 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17980 {
17981 asm volatile("# beginning down_read\n\t"
17982 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17983 +
17984 +#ifdef CONFIG_PAX_REFCOUNT
17985 + "jno 0f\n"
17986 + LOCK_PREFIX _ASM_DEC "(%1)\n"
17987 + "int $4\n0:\n"
17988 + _ASM_EXTABLE(0b, 0b)
17989 +#endif
17990 +
17991 /* adds 0x00000001 */
17992 " jns 1f\n"
17993 " call call_rwsem_down_read_failed\n"
17994 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17995 "1:\n\t"
17996 " mov %1,%2\n\t"
17997 " add %3,%2\n\t"
17998 +
17999 +#ifdef CONFIG_PAX_REFCOUNT
18000 + "jno 0f\n"
18001 + "sub %3,%2\n"
18002 + "int $4\n0:\n"
18003 + _ASM_EXTABLE(0b, 0b)
18004 +#endif
18005 +
18006 " jle 2f\n\t"
18007 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18008 " jnz 1b\n\t"
18009 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18010 long tmp;
18011 asm volatile("# beginning down_write\n\t"
18012 LOCK_PREFIX " xadd %1,(%2)\n\t"
18013 +
18014 +#ifdef CONFIG_PAX_REFCOUNT
18015 + "jno 0f\n"
18016 + "mov %1,(%2)\n"
18017 + "int $4\n0:\n"
18018 + _ASM_EXTABLE(0b, 0b)
18019 +#endif
18020 +
18021 /* adds 0xffff0001, returns the old value */
18022 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18023 /* was the active mask 0 before? */
18024 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18025 long tmp;
18026 asm volatile("# beginning __up_read\n\t"
18027 LOCK_PREFIX " xadd %1,(%2)\n\t"
18028 +
18029 +#ifdef CONFIG_PAX_REFCOUNT
18030 + "jno 0f\n"
18031 + "mov %1,(%2)\n"
18032 + "int $4\n0:\n"
18033 + _ASM_EXTABLE(0b, 0b)
18034 +#endif
18035 +
18036 /* subtracts 1, returns the old value */
18037 " jns 1f\n\t"
18038 " call call_rwsem_wake\n" /* expects old value in %edx */
18039 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18040 long tmp;
18041 asm volatile("# beginning __up_write\n\t"
18042 LOCK_PREFIX " xadd %1,(%2)\n\t"
18043 +
18044 +#ifdef CONFIG_PAX_REFCOUNT
18045 + "jno 0f\n"
18046 + "mov %1,(%2)\n"
18047 + "int $4\n0:\n"
18048 + _ASM_EXTABLE(0b, 0b)
18049 +#endif
18050 +
18051 /* subtracts 0xffff0001, returns the old value */
18052 " jns 1f\n\t"
18053 " call call_rwsem_wake\n" /* expects old value in %edx */
18054 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18055 {
18056 asm volatile("# beginning __downgrade_write\n\t"
18057 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18058 +
18059 +#ifdef CONFIG_PAX_REFCOUNT
18060 + "jno 0f\n"
18061 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18062 + "int $4\n0:\n"
18063 + _ASM_EXTABLE(0b, 0b)
18064 +#endif
18065 +
18066 /*
18067 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18068 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18069 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18070 */
18071 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18072 {
18073 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18074 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18075 +
18076 +#ifdef CONFIG_PAX_REFCOUNT
18077 + "jno 0f\n"
18078 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18079 + "int $4\n0:\n"
18080 + _ASM_EXTABLE(0b, 0b)
18081 +#endif
18082 +
18083 : "+m" (sem->count)
18084 : "er" (delta));
18085 }
18086 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18087 */
18088 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18089 {
18090 - return delta + xadd(&sem->count, delta);
18091 + return delta + xadd_check_overflow(&sem->count, delta);
18092 }
18093
18094 #endif /* __KERNEL__ */
18095 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18096 index 6f1c3a8..7744f19 100644
18097 --- a/arch/x86/include/asm/segment.h
18098 +++ b/arch/x86/include/asm/segment.h
18099 @@ -64,10 +64,15 @@
18100 * 26 - ESPFIX small SS
18101 * 27 - per-cpu [ offset to per-cpu data area ]
18102 * 28 - stack_canary-20 [ for stack protector ]
18103 - * 29 - unused
18104 - * 30 - unused
18105 + * 29 - PCI BIOS CS
18106 + * 30 - PCI BIOS DS
18107 * 31 - TSS for double fault handler
18108 */
18109 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18110 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18111 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18112 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18113 +
18114 #define GDT_ENTRY_TLS_MIN 6
18115 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18116
18117 @@ -79,6 +84,8 @@
18118
18119 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18120
18121 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18122 +
18123 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18124
18125 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18126 @@ -104,6 +111,12 @@
18127 #define __KERNEL_STACK_CANARY 0
18128 #endif
18129
18130 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18131 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18132 +
18133 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18134 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18135 +
18136 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18137
18138 /*
18139 @@ -141,7 +154,7 @@
18140 */
18141
18142 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18143 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18144 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18145
18146
18147 #else
18148 @@ -165,6 +178,8 @@
18149 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18150 #define __USER32_DS __USER_DS
18151
18152 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18153 +
18154 #define GDT_ENTRY_TSS 8 /* needs two entries */
18155 #define GDT_ENTRY_LDT 10 /* needs two entries */
18156 #define GDT_ENTRY_TLS_MIN 12
18157 @@ -173,6 +188,8 @@
18158 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18159 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18160
18161 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18162 +
18163 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18164 #define FS_TLS 0
18165 #define GS_TLS 1
18166 @@ -180,12 +197,14 @@
18167 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18168 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18169
18170 -#define GDT_ENTRIES 16
18171 +#define GDT_ENTRIES 17
18172
18173 #endif
18174
18175 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18176 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18177 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18178 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18179 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18180 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18181 #ifndef CONFIG_PARAVIRT
18182 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18183 {
18184 unsigned long __limit;
18185 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18186 - return __limit + 1;
18187 + return __limit;
18188 }
18189
18190 #endif /* !__ASSEMBLY__ */
18191 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18192 index 8d3120f..352b440 100644
18193 --- a/arch/x86/include/asm/smap.h
18194 +++ b/arch/x86/include/asm/smap.h
18195 @@ -25,11 +25,40 @@
18196
18197 #include <asm/alternative-asm.h>
18198
18199 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18200 +#define ASM_PAX_OPEN_USERLAND \
18201 + 661: jmp 663f; \
18202 + .pushsection .altinstr_replacement, "a" ; \
18203 + 662: pushq %rax; nop; \
18204 + .popsection ; \
18205 + .pushsection .altinstructions, "a" ; \
18206 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18207 + .popsection ; \
18208 + call __pax_open_userland; \
18209 + popq %rax; \
18210 + 663:
18211 +
18212 +#define ASM_PAX_CLOSE_USERLAND \
18213 + 661: jmp 663f; \
18214 + .pushsection .altinstr_replacement, "a" ; \
18215 + 662: pushq %rax; nop; \
18216 + .popsection; \
18217 + .pushsection .altinstructions, "a" ; \
18218 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18219 + .popsection; \
18220 + call __pax_close_userland; \
18221 + popq %rax; \
18222 + 663:
18223 +#else
18224 +#define ASM_PAX_OPEN_USERLAND
18225 +#define ASM_PAX_CLOSE_USERLAND
18226 +#endif
18227 +
18228 #ifdef CONFIG_X86_SMAP
18229
18230 #define ASM_CLAC \
18231 661: ASM_NOP3 ; \
18232 - .pushsection .altinstr_replacement, "ax" ; \
18233 + .pushsection .altinstr_replacement, "a" ; \
18234 662: __ASM_CLAC ; \
18235 .popsection ; \
18236 .pushsection .altinstructions, "a" ; \
18237 @@ -38,7 +67,7 @@
18238
18239 #define ASM_STAC \
18240 661: ASM_NOP3 ; \
18241 - .pushsection .altinstr_replacement, "ax" ; \
18242 + .pushsection .altinstr_replacement, "a" ; \
18243 662: __ASM_STAC ; \
18244 .popsection ; \
18245 .pushsection .altinstructions, "a" ; \
18246 @@ -56,6 +85,37 @@
18247
18248 #include <asm/alternative.h>
18249
18250 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18251 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18252 +
18253 +extern void __pax_open_userland(void);
18254 +static __always_inline unsigned long pax_open_userland(void)
18255 +{
18256 +
18257 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18258 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18259 + :
18260 + : [open] "i" (__pax_open_userland)
18261 + : "memory", "rax");
18262 +#endif
18263 +
18264 + return 0;
18265 +}
18266 +
18267 +extern void __pax_close_userland(void);
18268 +static __always_inline unsigned long pax_close_userland(void)
18269 +{
18270 +
18271 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18272 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18273 + :
18274 + : [close] "i" (__pax_close_userland)
18275 + : "memory", "rax");
18276 +#endif
18277 +
18278 + return 0;
18279 +}
18280 +
18281 #ifdef CONFIG_X86_SMAP
18282
18283 static __always_inline void clac(void)
18284 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18285 index 4137890..03fa172 100644
18286 --- a/arch/x86/include/asm/smp.h
18287 +++ b/arch/x86/include/asm/smp.h
18288 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18289 /* cpus sharing the last level cache: */
18290 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18291 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18292 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18293 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18294
18295 static inline struct cpumask *cpu_sibling_mask(int cpu)
18296 {
18297 @@ -79,7 +79,7 @@ struct smp_ops {
18298
18299 void (*send_call_func_ipi)(const struct cpumask *mask);
18300 void (*send_call_func_single_ipi)(int cpu);
18301 -};
18302 +} __no_const;
18303
18304 /* Globals due to paravirt */
18305 extern void set_cpu_sibling_map(int cpu);
18306 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18307 extern int safe_smp_processor_id(void);
18308
18309 #elif defined(CONFIG_X86_64_SMP)
18310 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18311 -
18312 -#define stack_smp_processor_id() \
18313 -({ \
18314 - struct thread_info *ti; \
18315 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18316 - ti->cpu; \
18317 -})
18318 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18319 +#define stack_smp_processor_id() raw_smp_processor_id()
18320 #define safe_smp_processor_id() smp_processor_id()
18321
18322 #endif
18323 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18324 index bf156de..1a782ab 100644
18325 --- a/arch/x86/include/asm/spinlock.h
18326 +++ b/arch/x86/include/asm/spinlock.h
18327 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18328 static inline void arch_read_lock(arch_rwlock_t *rw)
18329 {
18330 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18331 +
18332 +#ifdef CONFIG_PAX_REFCOUNT
18333 + "jno 0f\n"
18334 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18335 + "int $4\n0:\n"
18336 + _ASM_EXTABLE(0b, 0b)
18337 +#endif
18338 +
18339 "jns 1f\n"
18340 "call __read_lock_failed\n\t"
18341 "1:\n"
18342 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18343 static inline void arch_write_lock(arch_rwlock_t *rw)
18344 {
18345 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18346 +
18347 +#ifdef CONFIG_PAX_REFCOUNT
18348 + "jno 0f\n"
18349 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18350 + "int $4\n0:\n"
18351 + _ASM_EXTABLE(0b, 0b)
18352 +#endif
18353 +
18354 "jz 1f\n"
18355 "call __write_lock_failed\n\t"
18356 "1:\n"
18357 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18358
18359 static inline void arch_read_unlock(arch_rwlock_t *rw)
18360 {
18361 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18362 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18363 +
18364 +#ifdef CONFIG_PAX_REFCOUNT
18365 + "jno 0f\n"
18366 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18367 + "int $4\n0:\n"
18368 + _ASM_EXTABLE(0b, 0b)
18369 +#endif
18370 +
18371 :"+m" (rw->lock) : : "memory");
18372 }
18373
18374 static inline void arch_write_unlock(arch_rwlock_t *rw)
18375 {
18376 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18377 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18378 +
18379 +#ifdef CONFIG_PAX_REFCOUNT
18380 + "jno 0f\n"
18381 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18382 + "int $4\n0:\n"
18383 + _ASM_EXTABLE(0b, 0b)
18384 +#endif
18385 +
18386 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18387 }
18388
18389 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18390 index 6a99859..03cb807 100644
18391 --- a/arch/x86/include/asm/stackprotector.h
18392 +++ b/arch/x86/include/asm/stackprotector.h
18393 @@ -47,7 +47,7 @@
18394 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18395 */
18396 #define GDT_STACK_CANARY_INIT \
18397 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18398 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18399
18400 /*
18401 * Initialize the stackprotector canary value.
18402 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18403
18404 static inline void load_stack_canary_segment(void)
18405 {
18406 -#ifdef CONFIG_X86_32
18407 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18408 asm volatile ("mov %0, %%gs" : : "r" (0));
18409 #endif
18410 }
18411 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18412 index 70bbe39..4ae2bd4 100644
18413 --- a/arch/x86/include/asm/stacktrace.h
18414 +++ b/arch/x86/include/asm/stacktrace.h
18415 @@ -11,28 +11,20 @@
18416
18417 extern int kstack_depth_to_print;
18418
18419 -struct thread_info;
18420 +struct task_struct;
18421 struct stacktrace_ops;
18422
18423 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18424 - unsigned long *stack,
18425 - unsigned long bp,
18426 - const struct stacktrace_ops *ops,
18427 - void *data,
18428 - unsigned long *end,
18429 - int *graph);
18430 +typedef unsigned long walk_stack_t(struct task_struct *task,
18431 + void *stack_start,
18432 + unsigned long *stack,
18433 + unsigned long bp,
18434 + const struct stacktrace_ops *ops,
18435 + void *data,
18436 + unsigned long *end,
18437 + int *graph);
18438
18439 -extern unsigned long
18440 -print_context_stack(struct thread_info *tinfo,
18441 - unsigned long *stack, unsigned long bp,
18442 - const struct stacktrace_ops *ops, void *data,
18443 - unsigned long *end, int *graph);
18444 -
18445 -extern unsigned long
18446 -print_context_stack_bp(struct thread_info *tinfo,
18447 - unsigned long *stack, unsigned long bp,
18448 - const struct stacktrace_ops *ops, void *data,
18449 - unsigned long *end, int *graph);
18450 +extern walk_stack_t print_context_stack;
18451 +extern walk_stack_t print_context_stack_bp;
18452
18453 /* Generic stack tracer with callbacks */
18454
18455 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18456 void (*address)(void *data, unsigned long address, int reliable);
18457 /* On negative return stop dumping */
18458 int (*stack)(void *data, char *name);
18459 - walk_stack_t walk_stack;
18460 + walk_stack_t *walk_stack;
18461 };
18462
18463 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18464 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18465 index d7f3b3b..3cc39f1 100644
18466 --- a/arch/x86/include/asm/switch_to.h
18467 +++ b/arch/x86/include/asm/switch_to.h
18468 @@ -108,7 +108,7 @@ do { \
18469 "call __switch_to\n\t" \
18470 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18471 __switch_canary \
18472 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18473 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18474 "movq %%rax,%%rdi\n\t" \
18475 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18476 "jnz ret_from_fork\n\t" \
18477 @@ -119,7 +119,7 @@ do { \
18478 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18479 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18480 [_tif_fork] "i" (_TIF_FORK), \
18481 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
18482 + [thread_info] "m" (current_tinfo), \
18483 [current_task] "m" (current_task) \
18484 __switch_canary_iparam \
18485 : "memory", "cc" __EXTRA_CLOBBER)
18486 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18487 index 3ba3de4..6c113b2 100644
18488 --- a/arch/x86/include/asm/thread_info.h
18489 +++ b/arch/x86/include/asm/thread_info.h
18490 @@ -10,6 +10,7 @@
18491 #include <linux/compiler.h>
18492 #include <asm/page.h>
18493 #include <asm/types.h>
18494 +#include <asm/percpu.h>
18495
18496 /*
18497 * low level task data that entry.S needs immediate access to
18498 @@ -23,7 +24,6 @@ struct exec_domain;
18499 #include <linux/atomic.h>
18500
18501 struct thread_info {
18502 - struct task_struct *task; /* main task structure */
18503 struct exec_domain *exec_domain; /* execution domain */
18504 __u32 flags; /* low level flags */
18505 __u32 status; /* thread synchronous flags */
18506 @@ -32,19 +32,13 @@ struct thread_info {
18507 mm_segment_t addr_limit;
18508 struct restart_block restart_block;
18509 void __user *sysenter_return;
18510 -#ifdef CONFIG_X86_32
18511 - unsigned long previous_esp; /* ESP of the previous stack in
18512 - case of nested (IRQ) stacks
18513 - */
18514 - __u8 supervisor_stack[0];
18515 -#endif
18516 + unsigned long lowest_stack;
18517 unsigned int sig_on_uaccess_error:1;
18518 unsigned int uaccess_err:1; /* uaccess failed */
18519 };
18520
18521 -#define INIT_THREAD_INFO(tsk) \
18522 +#define INIT_THREAD_INFO \
18523 { \
18524 - .task = &tsk, \
18525 .exec_domain = &default_exec_domain, \
18526 .flags = 0, \
18527 .cpu = 0, \
18528 @@ -55,7 +49,7 @@ struct thread_info {
18529 }, \
18530 }
18531
18532 -#define init_thread_info (init_thread_union.thread_info)
18533 +#define init_thread_info (init_thread_union.stack)
18534 #define init_stack (init_thread_union.stack)
18535
18536 #else /* !__ASSEMBLY__ */
18537 @@ -95,6 +89,7 @@ struct thread_info {
18538 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18539 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18540 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18541 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18542
18543 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18544 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18545 @@ -118,17 +113,18 @@ struct thread_info {
18546 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18547 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18548 #define _TIF_X32 (1 << TIF_X32)
18549 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18550
18551 /* work to do in syscall_trace_enter() */
18552 #define _TIF_WORK_SYSCALL_ENTRY \
18553 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18554 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18555 - _TIF_NOHZ)
18556 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18557
18558 /* work to do in syscall_trace_leave() */
18559 #define _TIF_WORK_SYSCALL_EXIT \
18560 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18561 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18562 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18563
18564 /* work to do on interrupt/exception return */
18565 #define _TIF_WORK_MASK \
18566 @@ -139,7 +135,7 @@ struct thread_info {
18567 /* work to do on any return to user space */
18568 #define _TIF_ALLWORK_MASK \
18569 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18570 - _TIF_NOHZ)
18571 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18572
18573 /* Only used for 64 bit */
18574 #define _TIF_DO_NOTIFY_MASK \
18575 @@ -153,45 +149,40 @@ struct thread_info {
18576 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18577 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18578
18579 -#ifdef CONFIG_X86_32
18580 -
18581 -#define STACK_WARN (THREAD_SIZE/8)
18582 -/*
18583 - * macros/functions for gaining access to the thread information structure
18584 - *
18585 - * preempt_count needs to be 1 initially, until the scheduler is functional.
18586 - */
18587 -#ifndef __ASSEMBLY__
18588 -
18589 -
18590 -/* how to get the current stack pointer from C */
18591 -register unsigned long current_stack_pointer asm("esp") __used;
18592 -
18593 -/* how to get the thread information struct from C */
18594 -static inline struct thread_info *current_thread_info(void)
18595 -{
18596 - return (struct thread_info *)
18597 - (current_stack_pointer & ~(THREAD_SIZE - 1));
18598 -}
18599 -
18600 -#else /* !__ASSEMBLY__ */
18601 -
18602 +#ifdef __ASSEMBLY__
18603 /* how to get the thread information struct from ASM */
18604 #define GET_THREAD_INFO(reg) \
18605 - movl $-THREAD_SIZE, reg; \
18606 - andl %esp, reg
18607 + mov PER_CPU_VAR(current_tinfo), reg
18608
18609 /* use this one if reg already contains %esp */
18610 -#define GET_THREAD_INFO_WITH_ESP(reg) \
18611 - andl $-THREAD_SIZE, reg
18612 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18613 +#else
18614 +/* how to get the thread information struct from C */
18615 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18616 +
18617 +static __always_inline struct thread_info *current_thread_info(void)
18618 +{
18619 + return this_cpu_read_stable(current_tinfo);
18620 +}
18621 +#endif
18622 +
18623 +#ifdef CONFIG_X86_32
18624 +
18625 +#define STACK_WARN (THREAD_SIZE/8)
18626 +/*
18627 + * macros/functions for gaining access to the thread information structure
18628 + *
18629 + * preempt_count needs to be 1 initially, until the scheduler is functional.
18630 + */
18631 +#ifndef __ASSEMBLY__
18632 +
18633 +/* how to get the current stack pointer from C */
18634 +register unsigned long current_stack_pointer asm("esp") __used;
18635
18636 #endif
18637
18638 #else /* X86_32 */
18639
18640 -#include <asm/percpu.h>
18641 -#define KERNEL_STACK_OFFSET (5*8)
18642 -
18643 /*
18644 * macros/functions for gaining access to the thread information structure
18645 * preempt_count needs to be 1 initially, until the scheduler is functional.
18646 @@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
18647 #ifndef __ASSEMBLY__
18648 DECLARE_PER_CPU(unsigned long, kernel_stack);
18649
18650 -static inline struct thread_info *current_thread_info(void)
18651 -{
18652 - struct thread_info *ti;
18653 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
18654 - KERNEL_STACK_OFFSET - THREAD_SIZE);
18655 - return ti;
18656 -}
18657 -
18658 -#else /* !__ASSEMBLY__ */
18659 -
18660 -/* how to get the thread information struct from ASM */
18661 -#define GET_THREAD_INFO(reg) \
18662 - movq PER_CPU_VAR(kernel_stack),reg ; \
18663 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18664 -
18665 -/*
18666 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18667 - * a certain register (to be used in assembler memory operands).
18668 - */
18669 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18670 -
18671 +/* how to get the current stack pointer from C */
18672 +register unsigned long current_stack_pointer asm("rsp") __used;
18673 #endif
18674
18675 #endif /* !X86_32 */
18676 @@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
18677 extern void arch_task_cache_init(void);
18678 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18679 extern void arch_release_task_struct(struct task_struct *tsk);
18680 +
18681 +#define __HAVE_THREAD_FUNCTIONS
18682 +#define task_thread_info(task) (&(task)->tinfo)
18683 +#define task_stack_page(task) ((task)->stack)
18684 +#define setup_thread_stack(p, org) do {} while (0)
18685 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18686 +
18687 #endif
18688 #endif /* _ASM_X86_THREAD_INFO_H */
18689 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18690 index e6d90ba..f81f114 100644
18691 --- a/arch/x86/include/asm/tlbflush.h
18692 +++ b/arch/x86/include/asm/tlbflush.h
18693 @@ -17,18 +17,44 @@
18694
18695 static inline void __native_flush_tlb(void)
18696 {
18697 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18698 + u64 descriptor[2];
18699 +
18700 + descriptor[0] = PCID_KERNEL;
18701 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18702 + return;
18703 + }
18704 +
18705 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18706 + if (static_cpu_has(X86_FEATURE_PCID)) {
18707 + unsigned int cpu = raw_get_cpu();
18708 +
18709 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18710 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18711 + raw_put_cpu_no_resched();
18712 + return;
18713 + }
18714 +#endif
18715 +
18716 native_write_cr3(native_read_cr3());
18717 }
18718
18719 static inline void __native_flush_tlb_global_irq_disabled(void)
18720 {
18721 - unsigned long cr4;
18722 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18723 + u64 descriptor[2];
18724
18725 - cr4 = native_read_cr4();
18726 - /* clear PGE */
18727 - native_write_cr4(cr4 & ~X86_CR4_PGE);
18728 - /* write old PGE again and flush TLBs */
18729 - native_write_cr4(cr4);
18730 + descriptor[0] = PCID_KERNEL;
18731 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18732 + } else {
18733 + unsigned long cr4;
18734 +
18735 + cr4 = native_read_cr4();
18736 + /* clear PGE */
18737 + native_write_cr4(cr4 & ~X86_CR4_PGE);
18738 + /* write old PGE again and flush TLBs */
18739 + native_write_cr4(cr4);
18740 + }
18741 }
18742
18743 static inline void __native_flush_tlb_global(void)
18744 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
18745
18746 static inline void __native_flush_tlb_single(unsigned long addr)
18747 {
18748 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18749 + u64 descriptor[2];
18750 +
18751 + descriptor[0] = PCID_KERNEL;
18752 + descriptor[1] = addr;
18753 +
18754 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18755 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18756 + if (addr < TASK_SIZE_MAX)
18757 + descriptor[1] += pax_user_shadow_base;
18758 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18759 + }
18760 +
18761 + descriptor[0] = PCID_USER;
18762 + descriptor[1] = addr;
18763 +#endif
18764 +
18765 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18766 + return;
18767 + }
18768 +
18769 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18770 + if (static_cpu_has(X86_FEATURE_PCID)) {
18771 + unsigned int cpu = raw_get_cpu();
18772 +
18773 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18774 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18775 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18776 + raw_put_cpu_no_resched();
18777 +
18778 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18779 + addr += pax_user_shadow_base;
18780 + }
18781 +#endif
18782 +
18783 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18784 }
18785
18786 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18787 index 8ec57c0..3ee58c9 100644
18788 --- a/arch/x86/include/asm/uaccess.h
18789 +++ b/arch/x86/include/asm/uaccess.h
18790 @@ -7,6 +7,7 @@
18791 #include <linux/compiler.h>
18792 #include <linux/thread_info.h>
18793 #include <linux/string.h>
18794 +#include <linux/spinlock.h>
18795 #include <asm/asm.h>
18796 #include <asm/page.h>
18797 #include <asm/smap.h>
18798 @@ -29,7 +30,12 @@
18799
18800 #define get_ds() (KERNEL_DS)
18801 #define get_fs() (current_thread_info()->addr_limit)
18802 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18803 +void __set_fs(mm_segment_t x);
18804 +void set_fs(mm_segment_t x);
18805 +#else
18806 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18807 +#endif
18808
18809 #define segment_eq(a, b) ((a).seg == (b).seg)
18810
18811 @@ -77,8 +83,34 @@
18812 * checks that the pointer is in the user space range - after calling
18813 * this function, memory access functions may still return -EFAULT.
18814 */
18815 -#define access_ok(type, addr, size) \
18816 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18817 +extern int _cond_resched(void);
18818 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18819 +#define access_ok(type, addr, size) \
18820 +({ \
18821 + long __size = size; \
18822 + unsigned long __addr = (unsigned long)addr; \
18823 + unsigned long __addr_ao = __addr & PAGE_MASK; \
18824 + unsigned long __end_ao = __addr + __size - 1; \
18825 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18826 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18827 + while(__addr_ao <= __end_ao) { \
18828 + char __c_ao; \
18829 + __addr_ao += PAGE_SIZE; \
18830 + if (__size > PAGE_SIZE) \
18831 + _cond_resched(); \
18832 + if (__get_user(__c_ao, (char __user *)__addr)) \
18833 + break; \
18834 + if (type != VERIFY_WRITE) { \
18835 + __addr = __addr_ao; \
18836 + continue; \
18837 + } \
18838 + if (__put_user(__c_ao, (char __user *)__addr)) \
18839 + break; \
18840 + __addr = __addr_ao; \
18841 + } \
18842 + } \
18843 + __ret_ao; \
18844 +})
18845
18846 /*
18847 * The exception table consists of pairs of addresses relative to the
18848 @@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18849 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18850 __chk_user_ptr(ptr); \
18851 might_fault(); \
18852 + pax_open_userland(); \
18853 asm volatile("call __get_user_%P3" \
18854 : "=a" (__ret_gu), "=r" (__val_gu) \
18855 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18856 (x) = (__typeof__(*(ptr))) __val_gu; \
18857 + pax_close_userland(); \
18858 __ret_gu; \
18859 })
18860
18861 @@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18862 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18863 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18864
18865 -
18866 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18867 +#define __copyuser_seg "gs;"
18868 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18869 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18870 +#else
18871 +#define __copyuser_seg
18872 +#define __COPYUSER_SET_ES
18873 +#define __COPYUSER_RESTORE_ES
18874 +#endif
18875
18876 #ifdef CONFIG_X86_32
18877 #define __put_user_asm_u64(x, addr, err, errret) \
18878 asm volatile(ASM_STAC "\n" \
18879 - "1: movl %%eax,0(%2)\n" \
18880 - "2: movl %%edx,4(%2)\n" \
18881 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18882 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18883 "3: " ASM_CLAC "\n" \
18884 ".section .fixup,\"ax\"\n" \
18885 "4: movl %3,%0\n" \
18886 @@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18887
18888 #define __put_user_asm_ex_u64(x, addr) \
18889 asm volatile(ASM_STAC "\n" \
18890 - "1: movl %%eax,0(%1)\n" \
18891 - "2: movl %%edx,4(%1)\n" \
18892 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18893 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18894 "3: " ASM_CLAC "\n" \
18895 _ASM_EXTABLE_EX(1b, 2b) \
18896 _ASM_EXTABLE_EX(2b, 3b) \
18897 @@ -249,7 +291,8 @@ extern void __put_user_8(void);
18898 __typeof__(*(ptr)) __pu_val; \
18899 __chk_user_ptr(ptr); \
18900 might_fault(); \
18901 - __pu_val = x; \
18902 + __pu_val = (x); \
18903 + pax_open_userland(); \
18904 switch (sizeof(*(ptr))) { \
18905 case 1: \
18906 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18907 @@ -267,6 +310,7 @@ extern void __put_user_8(void);
18908 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18909 break; \
18910 } \
18911 + pax_close_userland(); \
18912 __ret_pu; \
18913 })
18914
18915 @@ -347,8 +391,10 @@ do { \
18916 } while (0)
18917
18918 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18919 +do { \
18920 + pax_open_userland(); \
18921 asm volatile(ASM_STAC "\n" \
18922 - "1: mov"itype" %2,%"rtype"1\n" \
18923 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18924 "2: " ASM_CLAC "\n" \
18925 ".section .fixup,\"ax\"\n" \
18926 "3: mov %3,%0\n" \
18927 @@ -356,8 +402,10 @@ do { \
18928 " jmp 2b\n" \
18929 ".previous\n" \
18930 _ASM_EXTABLE(1b, 3b) \
18931 - : "=r" (err), ltype(x) \
18932 - : "m" (__m(addr)), "i" (errret), "0" (err))
18933 + : "=r" (err), ltype (x) \
18934 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
18935 + pax_close_userland(); \
18936 +} while (0)
18937
18938 #define __get_user_size_ex(x, ptr, size) \
18939 do { \
18940 @@ -381,7 +429,7 @@ do { \
18941 } while (0)
18942
18943 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18944 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18945 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18946 "2:\n" \
18947 _ASM_EXTABLE_EX(1b, 2b) \
18948 : ltype(x) : "m" (__m(addr)))
18949 @@ -398,13 +446,24 @@ do { \
18950 int __gu_err; \
18951 unsigned long __gu_val; \
18952 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18953 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
18954 + (x) = (__typeof__(*(ptr)))__gu_val; \
18955 __gu_err; \
18956 })
18957
18958 /* FIXME: this hack is definitely wrong -AK */
18959 struct __large_struct { unsigned long buf[100]; };
18960 -#define __m(x) (*(struct __large_struct __user *)(x))
18961 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18962 +#define ____m(x) \
18963 +({ \
18964 + unsigned long ____x = (unsigned long)(x); \
18965 + if (____x < pax_user_shadow_base) \
18966 + ____x += pax_user_shadow_base; \
18967 + (typeof(x))____x; \
18968 +})
18969 +#else
18970 +#define ____m(x) (x)
18971 +#endif
18972 +#define __m(x) (*(struct __large_struct __user *)____m(x))
18973
18974 /*
18975 * Tell gcc we read from memory instead of writing: this is because
18976 @@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
18977 * aliasing issues.
18978 */
18979 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18980 +do { \
18981 + pax_open_userland(); \
18982 asm volatile(ASM_STAC "\n" \
18983 - "1: mov"itype" %"rtype"1,%2\n" \
18984 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18985 "2: " ASM_CLAC "\n" \
18986 ".section .fixup,\"ax\"\n" \
18987 "3: mov %3,%0\n" \
18988 @@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
18989 ".previous\n" \
18990 _ASM_EXTABLE(1b, 3b) \
18991 : "=r"(err) \
18992 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18993 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18994 + pax_close_userland(); \
18995 +} while (0)
18996
18997 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18998 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18999 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19000 "2:\n" \
19001 _ASM_EXTABLE_EX(1b, 2b) \
19002 : : ltype(x), "m" (__m(addr)))
19003 @@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19004 */
19005 #define uaccess_try do { \
19006 current_thread_info()->uaccess_err = 0; \
19007 + pax_open_userland(); \
19008 stac(); \
19009 barrier();
19010
19011 #define uaccess_catch(err) \
19012 clac(); \
19013 + pax_close_userland(); \
19014 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19015 } while (0)
19016
19017 @@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19018 * On error, the variable @x is set to zero.
19019 */
19020
19021 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19022 +#define __get_user(x, ptr) get_user((x), (ptr))
19023 +#else
19024 #define __get_user(x, ptr) \
19025 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19026 +#endif
19027
19028 /**
19029 * __put_user: - Write a simple value into user space, with less checking.
19030 @@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19031 * Returns zero on success, or -EFAULT on error.
19032 */
19033
19034 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19035 +#define __put_user(x, ptr) put_user((x), (ptr))
19036 +#else
19037 #define __put_user(x, ptr) \
19038 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19039 +#endif
19040
19041 #define __get_user_unaligned __get_user
19042 #define __put_user_unaligned __put_user
19043 @@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19044 #define get_user_ex(x, ptr) do { \
19045 unsigned long __gue_val; \
19046 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19047 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19048 + (x) = (__typeof__(*(ptr)))__gue_val; \
19049 } while (0)
19050
19051 #define put_user_try uaccess_try
19052 @@ -536,17 +609,6 @@ extern struct movsl_mask {
19053
19054 #define ARCH_HAS_NOCACHE_UACCESS 1
19055
19056 -#ifdef CONFIG_X86_32
19057 -# include <asm/uaccess_32.h>
19058 -#else
19059 -# include <asm/uaccess_64.h>
19060 -#endif
19061 -
19062 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19063 - unsigned n);
19064 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19065 - unsigned n);
19066 -
19067 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19068 # define copy_user_diag __compiletime_error
19069 #else
19070 @@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19071 extern void copy_user_diag("copy_from_user() buffer size is too small")
19072 copy_from_user_overflow(void);
19073 extern void copy_user_diag("copy_to_user() buffer size is too small")
19074 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19075 +copy_to_user_overflow(void);
19076
19077 #undef copy_user_diag
19078
19079 @@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19080
19081 extern void
19082 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19083 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19084 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19085 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19086
19087 #else
19088 @@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19089
19090 #endif
19091
19092 +#ifdef CONFIG_X86_32
19093 +# include <asm/uaccess_32.h>
19094 +#else
19095 +# include <asm/uaccess_64.h>
19096 +#endif
19097 +
19098 static inline unsigned long __must_check
19099 copy_from_user(void *to, const void __user *from, unsigned long n)
19100 {
19101 - int sz = __compiletime_object_size(to);
19102 + size_t sz = __compiletime_object_size(to);
19103
19104 might_fault();
19105
19106 @@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19107 * case, and do only runtime checking for non-constant sizes.
19108 */
19109
19110 - if (likely(sz < 0 || sz >= n))
19111 - n = _copy_from_user(to, from, n);
19112 - else if(__builtin_constant_p(n))
19113 - copy_from_user_overflow();
19114 - else
19115 - __copy_from_user_overflow(sz, n);
19116 + if (likely(sz != (size_t)-1 && sz < n)) {
19117 + if(__builtin_constant_p(n))
19118 + copy_from_user_overflow();
19119 + else
19120 + __copy_from_user_overflow(sz, n);
19121 + } if (access_ok(VERIFY_READ, from, n))
19122 + n = __copy_from_user(to, from, n);
19123 + else if ((long)n > 0)
19124 + memset(to, 0, n);
19125
19126 return n;
19127 }
19128 @@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19129 static inline unsigned long __must_check
19130 copy_to_user(void __user *to, const void *from, unsigned long n)
19131 {
19132 - int sz = __compiletime_object_size(from);
19133 + size_t sz = __compiletime_object_size(from);
19134
19135 might_fault();
19136
19137 /* See the comment in copy_from_user() above. */
19138 - if (likely(sz < 0 || sz >= n))
19139 - n = _copy_to_user(to, from, n);
19140 - else if(__builtin_constant_p(n))
19141 - copy_to_user_overflow();
19142 - else
19143 - __copy_to_user_overflow(sz, n);
19144 + if (likely(sz != (size_t)-1 && sz < n)) {
19145 + if(__builtin_constant_p(n))
19146 + copy_to_user_overflow();
19147 + else
19148 + __copy_to_user_overflow(sz, n);
19149 + } else if (access_ok(VERIFY_WRITE, to, n))
19150 + n = __copy_to_user(to, from, n);
19151
19152 return n;
19153 }
19154 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19155 index 3c03a5d..1071638 100644
19156 --- a/arch/x86/include/asm/uaccess_32.h
19157 +++ b/arch/x86/include/asm/uaccess_32.h
19158 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19159 static __always_inline unsigned long __must_check
19160 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19161 {
19162 + if ((long)n < 0)
19163 + return n;
19164 +
19165 + check_object_size(from, n, true);
19166 +
19167 if (__builtin_constant_p(n)) {
19168 unsigned long ret;
19169
19170 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19171 __copy_to_user(void __user *to, const void *from, unsigned long n)
19172 {
19173 might_fault();
19174 +
19175 return __copy_to_user_inatomic(to, from, n);
19176 }
19177
19178 static __always_inline unsigned long
19179 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19180 {
19181 + if ((long)n < 0)
19182 + return n;
19183 +
19184 /* Avoid zeroing the tail if the copy fails..
19185 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19186 * but as the zeroing behaviour is only significant when n is not
19187 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19188 __copy_from_user(void *to, const void __user *from, unsigned long n)
19189 {
19190 might_fault();
19191 +
19192 + if ((long)n < 0)
19193 + return n;
19194 +
19195 + check_object_size(to, n, false);
19196 +
19197 if (__builtin_constant_p(n)) {
19198 unsigned long ret;
19199
19200 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19201 const void __user *from, unsigned long n)
19202 {
19203 might_fault();
19204 +
19205 + if ((long)n < 0)
19206 + return n;
19207 +
19208 if (__builtin_constant_p(n)) {
19209 unsigned long ret;
19210
19211 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19212 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19213 unsigned long n)
19214 {
19215 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19216 + if ((long)n < 0)
19217 + return n;
19218 +
19219 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19220 }
19221
19222 #endif /* _ASM_X86_UACCESS_32_H */
19223 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19224 index 190413d..8a80c2a 100644
19225 --- a/arch/x86/include/asm/uaccess_64.h
19226 +++ b/arch/x86/include/asm/uaccess_64.h
19227 @@ -10,6 +10,9 @@
19228 #include <asm/alternative.h>
19229 #include <asm/cpufeature.h>
19230 #include <asm/page.h>
19231 +#include <asm/pgtable.h>
19232 +
19233 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19234
19235 /*
19236 * Copy To/From Userspace
19237 @@ -17,14 +20,14 @@
19238
19239 /* Handles exceptions in both to and from, but doesn't do access_ok */
19240 __must_check unsigned long
19241 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19242 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19243 __must_check unsigned long
19244 -copy_user_generic_string(void *to, const void *from, unsigned len);
19245 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19246 __must_check unsigned long
19247 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19248 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19249
19250 static __always_inline __must_check unsigned long
19251 -copy_user_generic(void *to, const void *from, unsigned len)
19252 +copy_user_generic(void *to, const void *from, unsigned long len)
19253 {
19254 unsigned ret;
19255
19256 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19257 }
19258
19259 __must_check unsigned long
19260 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19261 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19262
19263 static __always_inline __must_check
19264 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19265 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19266 {
19267 - int ret = 0;
19268 + size_t sz = __compiletime_object_size(dst);
19269 + unsigned ret = 0;
19270 +
19271 + if (size > INT_MAX)
19272 + return size;
19273 +
19274 + check_object_size(dst, size, false);
19275 +
19276 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19277 + if (!__access_ok(VERIFY_READ, src, size))
19278 + return size;
19279 +#endif
19280 +
19281 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19282 + if(__builtin_constant_p(size))
19283 + copy_from_user_overflow();
19284 + else
19285 + __copy_from_user_overflow(sz, size);
19286 + return size;
19287 + }
19288
19289 if (!__builtin_constant_p(size))
19290 - return copy_user_generic(dst, (__force void *)src, size);
19291 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19292 switch (size) {
19293 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19294 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19295 ret, "b", "b", "=q", 1);
19296 return ret;
19297 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19298 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19299 ret, "w", "w", "=r", 2);
19300 return ret;
19301 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19302 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19303 ret, "l", "k", "=r", 4);
19304 return ret;
19305 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19306 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19307 ret, "q", "", "=r", 8);
19308 return ret;
19309 case 10:
19310 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19311 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19312 ret, "q", "", "=r", 10);
19313 if (unlikely(ret))
19314 return ret;
19315 __get_user_asm(*(u16 *)(8 + (char *)dst),
19316 - (u16 __user *)(8 + (char __user *)src),
19317 + (const u16 __user *)(8 + (const char __user *)src),
19318 ret, "w", "w", "=r", 2);
19319 return ret;
19320 case 16:
19321 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19322 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19323 ret, "q", "", "=r", 16);
19324 if (unlikely(ret))
19325 return ret;
19326 __get_user_asm(*(u64 *)(8 + (char *)dst),
19327 - (u64 __user *)(8 + (char __user *)src),
19328 + (const u64 __user *)(8 + (const char __user *)src),
19329 ret, "q", "", "=r", 8);
19330 return ret;
19331 default:
19332 - return copy_user_generic(dst, (__force void *)src, size);
19333 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19334 }
19335 }
19336
19337 static __always_inline __must_check
19338 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19339 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19340 {
19341 might_fault();
19342 return __copy_from_user_nocheck(dst, src, size);
19343 }
19344
19345 static __always_inline __must_check
19346 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19347 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19348 {
19349 - int ret = 0;
19350 + size_t sz = __compiletime_object_size(src);
19351 + unsigned ret = 0;
19352 +
19353 + if (size > INT_MAX)
19354 + return size;
19355 +
19356 + check_object_size(src, size, true);
19357 +
19358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19359 + if (!__access_ok(VERIFY_WRITE, dst, size))
19360 + return size;
19361 +#endif
19362 +
19363 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19364 + if(__builtin_constant_p(size))
19365 + copy_to_user_overflow();
19366 + else
19367 + __copy_to_user_overflow(sz, size);
19368 + return size;
19369 + }
19370
19371 if (!__builtin_constant_p(size))
19372 - return copy_user_generic((__force void *)dst, src, size);
19373 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19374 switch (size) {
19375 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19376 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19377 ret, "b", "b", "iq", 1);
19378 return ret;
19379 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19380 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19381 ret, "w", "w", "ir", 2);
19382 return ret;
19383 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19384 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19385 ret, "l", "k", "ir", 4);
19386 return ret;
19387 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19388 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19389 ret, "q", "", "er", 8);
19390 return ret;
19391 case 10:
19392 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19393 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19394 ret, "q", "", "er", 10);
19395 if (unlikely(ret))
19396 return ret;
19397 asm("":::"memory");
19398 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19399 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19400 ret, "w", "w", "ir", 2);
19401 return ret;
19402 case 16:
19403 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19404 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19405 ret, "q", "", "er", 16);
19406 if (unlikely(ret))
19407 return ret;
19408 asm("":::"memory");
19409 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19410 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19411 ret, "q", "", "er", 8);
19412 return ret;
19413 default:
19414 - return copy_user_generic((__force void *)dst, src, size);
19415 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19416 }
19417 }
19418
19419 static __always_inline __must_check
19420 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19421 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19422 {
19423 might_fault();
19424 return __copy_to_user_nocheck(dst, src, size);
19425 }
19426
19427 static __always_inline __must_check
19428 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19429 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19430 {
19431 - int ret = 0;
19432 + unsigned ret = 0;
19433
19434 might_fault();
19435 +
19436 + if (size > INT_MAX)
19437 + return size;
19438 +
19439 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19440 + if (!__access_ok(VERIFY_READ, src, size))
19441 + return size;
19442 + if (!__access_ok(VERIFY_WRITE, dst, size))
19443 + return size;
19444 +#endif
19445 +
19446 if (!__builtin_constant_p(size))
19447 - return copy_user_generic((__force void *)dst,
19448 - (__force void *)src, size);
19449 + return copy_user_generic((__force_kernel void *)____m(dst),
19450 + (__force_kernel const void *)____m(src), size);
19451 switch (size) {
19452 case 1: {
19453 u8 tmp;
19454 - __get_user_asm(tmp, (u8 __user *)src,
19455 + __get_user_asm(tmp, (const u8 __user *)src,
19456 ret, "b", "b", "=q", 1);
19457 if (likely(!ret))
19458 __put_user_asm(tmp, (u8 __user *)dst,
19459 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19460 }
19461 case 2: {
19462 u16 tmp;
19463 - __get_user_asm(tmp, (u16 __user *)src,
19464 + __get_user_asm(tmp, (const u16 __user *)src,
19465 ret, "w", "w", "=r", 2);
19466 if (likely(!ret))
19467 __put_user_asm(tmp, (u16 __user *)dst,
19468 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19469
19470 case 4: {
19471 u32 tmp;
19472 - __get_user_asm(tmp, (u32 __user *)src,
19473 + __get_user_asm(tmp, (const u32 __user *)src,
19474 ret, "l", "k", "=r", 4);
19475 if (likely(!ret))
19476 __put_user_asm(tmp, (u32 __user *)dst,
19477 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19478 }
19479 case 8: {
19480 u64 tmp;
19481 - __get_user_asm(tmp, (u64 __user *)src,
19482 + __get_user_asm(tmp, (const u64 __user *)src,
19483 ret, "q", "", "=r", 8);
19484 if (likely(!ret))
19485 __put_user_asm(tmp, (u64 __user *)dst,
19486 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19487 return ret;
19488 }
19489 default:
19490 - return copy_user_generic((__force void *)dst,
19491 - (__force void *)src, size);
19492 + return copy_user_generic((__force_kernel void *)____m(dst),
19493 + (__force_kernel const void *)____m(src), size);
19494 }
19495 }
19496
19497 -static __must_check __always_inline int
19498 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19499 +static __must_check __always_inline unsigned long
19500 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19501 {
19502 - return __copy_from_user_nocheck(dst, (__force const void *)src, size);
19503 + return __copy_from_user_nocheck(dst, src, size);
19504 }
19505
19506 -static __must_check __always_inline int
19507 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19508 +static __must_check __always_inline unsigned long
19509 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19510 {
19511 - return __copy_to_user_nocheck((__force void *)dst, src, size);
19512 + return __copy_to_user_nocheck(dst, src, size);
19513 }
19514
19515 -extern long __copy_user_nocache(void *dst, const void __user *src,
19516 - unsigned size, int zerorest);
19517 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19518 + unsigned long size, int zerorest);
19519
19520 -static inline int
19521 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19522 +static inline unsigned long
19523 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19524 {
19525 might_fault();
19526 +
19527 + if (size > INT_MAX)
19528 + return size;
19529 +
19530 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19531 + if (!__access_ok(VERIFY_READ, src, size))
19532 + return size;
19533 +#endif
19534 +
19535 return __copy_user_nocache(dst, src, size, 1);
19536 }
19537
19538 -static inline int
19539 +static inline unsigned long
19540 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19541 - unsigned size)
19542 + unsigned long size)
19543 {
19544 + if (size > INT_MAX)
19545 + return size;
19546 +
19547 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19548 + if (!__access_ok(VERIFY_READ, src, size))
19549 + return size;
19550 +#endif
19551 +
19552 return __copy_user_nocache(dst, src, size, 0);
19553 }
19554
19555 unsigned long
19556 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19557 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19558
19559 #endif /* _ASM_X86_UACCESS_64_H */
19560 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19561 index 5b238981..77fdd78 100644
19562 --- a/arch/x86/include/asm/word-at-a-time.h
19563 +++ b/arch/x86/include/asm/word-at-a-time.h
19564 @@ -11,7 +11,7 @@
19565 * and shift, for example.
19566 */
19567 struct word_at_a_time {
19568 - const unsigned long one_bits, high_bits;
19569 + unsigned long one_bits, high_bits;
19570 };
19571
19572 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19573 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19574 index 0f1be11..f7542bf 100644
19575 --- a/arch/x86/include/asm/x86_init.h
19576 +++ b/arch/x86/include/asm/x86_init.h
19577 @@ -129,7 +129,7 @@ struct x86_init_ops {
19578 struct x86_init_timers timers;
19579 struct x86_init_iommu iommu;
19580 struct x86_init_pci pci;
19581 -};
19582 +} __no_const;
19583
19584 /**
19585 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19586 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19587 void (*setup_percpu_clockev)(void);
19588 void (*early_percpu_clock_init)(void);
19589 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19590 -};
19591 +} __no_const;
19592
19593 struct timespec;
19594
19595 @@ -168,7 +168,7 @@ struct x86_platform_ops {
19596 void (*save_sched_clock_state)(void);
19597 void (*restore_sched_clock_state)(void);
19598 void (*apic_post_init)(void);
19599 -};
19600 +} __no_const;
19601
19602 struct pci_dev;
19603 struct msi_msg;
19604 @@ -185,7 +185,7 @@ struct x86_msi_ops {
19605 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19606 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
19607 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
19608 -};
19609 +} __no_const;
19610
19611 struct IO_APIC_route_entry;
19612 struct io_apic_irq_attr;
19613 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
19614 unsigned int destination, int vector,
19615 struct io_apic_irq_attr *attr);
19616 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19617 -};
19618 +} __no_const;
19619
19620 extern struct x86_init_ops x86_init;
19621 extern struct x86_cpuinit_ops x86_cpuinit;
19622 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
19623 index b913915..4f5a581 100644
19624 --- a/arch/x86/include/asm/xen/page.h
19625 +++ b/arch/x86/include/asm/xen/page.h
19626 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
19627 extern struct page *m2p_find_override(unsigned long mfn);
19628 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
19629
19630 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
19631 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
19632 {
19633 unsigned long mfn;
19634
19635 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19636 index 0415cda..3b22adc 100644
19637 --- a/arch/x86/include/asm/xsave.h
19638 +++ b/arch/x86/include/asm/xsave.h
19639 @@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19640 if (unlikely(err))
19641 return -EFAULT;
19642
19643 + pax_open_userland();
19644 __asm__ __volatile__(ASM_STAC "\n"
19645 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19646 + "1:"
19647 + __copyuser_seg
19648 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19649 "2: " ASM_CLAC "\n"
19650 ".section .fixup,\"ax\"\n"
19651 "3: movl $-1,%[err]\n"
19652 @@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19653 : [err] "=r" (err)
19654 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19655 : "memory");
19656 + pax_close_userland();
19657 return err;
19658 }
19659
19660 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19661 {
19662 int err;
19663 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19664 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19665 u32 lmask = mask;
19666 u32 hmask = mask >> 32;
19667
19668 + pax_open_userland();
19669 __asm__ __volatile__(ASM_STAC "\n"
19670 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19671 + "1:"
19672 + __copyuser_seg
19673 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19674 "2: " ASM_CLAC "\n"
19675 ".section .fixup,\"ax\"\n"
19676 "3: movl $-1,%[err]\n"
19677 @@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19678 : [err] "=r" (err)
19679 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19680 : "memory"); /* memory required? */
19681 + pax_close_userland();
19682 return err;
19683 }
19684
19685 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19686 index bbae024..e1528f9 100644
19687 --- a/arch/x86/include/uapi/asm/e820.h
19688 +++ b/arch/x86/include/uapi/asm/e820.h
19689 @@ -63,7 +63,7 @@ struct e820map {
19690 #define ISA_START_ADDRESS 0xa0000
19691 #define ISA_END_ADDRESS 0x100000
19692
19693 -#define BIOS_BEGIN 0x000a0000
19694 +#define BIOS_BEGIN 0x000c0000
19695 #define BIOS_END 0x00100000
19696
19697 #define BIOS_ROM_BASE 0xffe00000
19698 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
19699 index 7b0a55a..ad115bf 100644
19700 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
19701 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
19702 @@ -49,7 +49,6 @@
19703 #define EFLAGS 144
19704 #define RSP 152
19705 #define SS 160
19706 -#define ARGOFFSET R11
19707 #endif /* __ASSEMBLY__ */
19708
19709 /* top of stack page */
19710 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19711 index 9b0a34e..fc7e553 100644
19712 --- a/arch/x86/kernel/Makefile
19713 +++ b/arch/x86/kernel/Makefile
19714 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19715 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19716 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19717 obj-y += probe_roms.o
19718 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19719 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19720 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19721 obj-y += syscall_$(BITS).o
19722 obj-$(CONFIG_X86_64) += vsyscall_64.o
19723 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19724 index 6c0b43b..e67bb31 100644
19725 --- a/arch/x86/kernel/acpi/boot.c
19726 +++ b/arch/x86/kernel/acpi/boot.c
19727 @@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19728 * If your system is blacklisted here, but you find that acpi=force
19729 * works for you, please contact linux-acpi@vger.kernel.org
19730 */
19731 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
19732 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19733 /*
19734 * Boxes that need ACPI disabled
19735 */
19736 @@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19737 };
19738
19739 /* second table for DMI checks that should run after early-quirks */
19740 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19741 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19742 /*
19743 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19744 * which includes some code which overrides all temperature
19745 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19746 index 3a2ae4c..9db31d6 100644
19747 --- a/arch/x86/kernel/acpi/sleep.c
19748 +++ b/arch/x86/kernel/acpi/sleep.c
19749 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
19750 #else /* CONFIG_64BIT */
19751 #ifdef CONFIG_SMP
19752 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19753 +
19754 + pax_open_kernel();
19755 early_gdt_descr.address =
19756 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19757 + pax_close_kernel();
19758 +
19759 initial_gs = per_cpu_offset(smp_processor_id());
19760 #endif
19761 initial_code = (unsigned long)wakeup_long64;
19762 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19763 index 665c6b7..eae4d56 100644
19764 --- a/arch/x86/kernel/acpi/wakeup_32.S
19765 +++ b/arch/x86/kernel/acpi/wakeup_32.S
19766 @@ -29,13 +29,11 @@ wakeup_pmode_return:
19767 # and restore the stack ... but you need gdt for this to work
19768 movl saved_context_esp, %esp
19769
19770 - movl %cs:saved_magic, %eax
19771 - cmpl $0x12345678, %eax
19772 + cmpl $0x12345678, saved_magic
19773 jne bogus_magic
19774
19775 # jump to place where we left off
19776 - movl saved_eip, %eax
19777 - jmp *%eax
19778 + jmp *(saved_eip)
19779
19780 bogus_magic:
19781 jmp bogus_magic
19782 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19783 index df94598..f3b29bf 100644
19784 --- a/arch/x86/kernel/alternative.c
19785 +++ b/arch/x86/kernel/alternative.c
19786 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19787 */
19788 for (a = start; a < end; a++) {
19789 instr = (u8 *)&a->instr_offset + a->instr_offset;
19790 +
19791 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19792 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19793 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19794 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19795 +#endif
19796 +
19797 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19798 BUG_ON(a->replacementlen > a->instrlen);
19799 BUG_ON(a->instrlen > sizeof(insnbuf));
19800 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19801 for (poff = start; poff < end; poff++) {
19802 u8 *ptr = (u8 *)poff + *poff;
19803
19804 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19805 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19806 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19807 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19808 +#endif
19809 +
19810 if (!*poff || ptr < text || ptr >= text_end)
19811 continue;
19812 /* turn DS segment override prefix into lock prefix */
19813 - if (*ptr == 0x3e)
19814 + if (*ktla_ktva(ptr) == 0x3e)
19815 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19816 }
19817 mutex_unlock(&text_mutex);
19818 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19819 for (poff = start; poff < end; poff++) {
19820 u8 *ptr = (u8 *)poff + *poff;
19821
19822 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19823 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19824 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19825 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19826 +#endif
19827 +
19828 if (!*poff || ptr < text || ptr >= text_end)
19829 continue;
19830 /* turn lock prefix into DS segment override prefix */
19831 - if (*ptr == 0xf0)
19832 + if (*ktla_ktva(ptr) == 0xf0)
19833 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19834 }
19835 mutex_unlock(&text_mutex);
19836 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19837
19838 BUG_ON(p->len > MAX_PATCH_LEN);
19839 /* prep the buffer with the original instructions */
19840 - memcpy(insnbuf, p->instr, p->len);
19841 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19842 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19843 (unsigned long)p->instr, p->len);
19844
19845 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
19846 if (!uniproc_patched || num_possible_cpus() == 1)
19847 free_init_pages("SMP alternatives",
19848 (unsigned long)__smp_locks,
19849 - (unsigned long)__smp_locks_end);
19850 + PAGE_ALIGN((unsigned long)__smp_locks_end));
19851 #endif
19852
19853 apply_paravirt(__parainstructions, __parainstructions_end);
19854 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
19855 * instructions. And on the local CPU you need to be protected again NMI or MCE
19856 * handlers seeing an inconsistent instruction while you patch.
19857 */
19858 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
19859 +void *__kprobes text_poke_early(void *addr, const void *opcode,
19860 size_t len)
19861 {
19862 unsigned long flags;
19863 local_irq_save(flags);
19864 - memcpy(addr, opcode, len);
19865 +
19866 + pax_open_kernel();
19867 + memcpy(ktla_ktva(addr), opcode, len);
19868 sync_core();
19869 + pax_close_kernel();
19870 +
19871 local_irq_restore(flags);
19872 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19873 that causes hangs on some VIA CPUs. */
19874 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19875 */
19876 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19877 {
19878 - unsigned long flags;
19879 - char *vaddr;
19880 + unsigned char *vaddr = ktla_ktva(addr);
19881 struct page *pages[2];
19882 - int i;
19883 + size_t i;
19884
19885 if (!core_kernel_text((unsigned long)addr)) {
19886 - pages[0] = vmalloc_to_page(addr);
19887 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19888 + pages[0] = vmalloc_to_page(vaddr);
19889 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19890 } else {
19891 - pages[0] = virt_to_page(addr);
19892 + pages[0] = virt_to_page(vaddr);
19893 WARN_ON(!PageReserved(pages[0]));
19894 - pages[1] = virt_to_page(addr + PAGE_SIZE);
19895 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19896 }
19897 BUG_ON(!pages[0]);
19898 - local_irq_save(flags);
19899 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19900 - if (pages[1])
19901 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19902 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19903 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19904 - clear_fixmap(FIX_TEXT_POKE0);
19905 - if (pages[1])
19906 - clear_fixmap(FIX_TEXT_POKE1);
19907 - local_flush_tlb();
19908 - sync_core();
19909 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
19910 - that causes hangs on some VIA CPUs. */
19911 + text_poke_early(addr, opcode, len);
19912 for (i = 0; i < len; i++)
19913 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19914 - local_irq_restore(flags);
19915 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19916 return addr;
19917 }
19918
19919 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
19920 if (likely(!bp_patching_in_progress))
19921 return 0;
19922
19923 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19924 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19925 return 0;
19926
19927 /* set up the specified breakpoint handler */
19928 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
19929 */
19930 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19931 {
19932 - unsigned char int3 = 0xcc;
19933 + const unsigned char int3 = 0xcc;
19934
19935 bp_int3_handler = handler;
19936 bp_int3_addr = (u8 *)addr + sizeof(int3);
19937 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19938 index d278736..0b4af9a8 100644
19939 --- a/arch/x86/kernel/apic/apic.c
19940 +++ b/arch/x86/kernel/apic/apic.c
19941 @@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
19942 /*
19943 * Debug level, exported for io_apic.c
19944 */
19945 -unsigned int apic_verbosity;
19946 +int apic_verbosity;
19947
19948 int pic_mode;
19949
19950 @@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19951 apic_write(APIC_ESR, 0);
19952 v1 = apic_read(APIC_ESR);
19953 ack_APIC_irq();
19954 - atomic_inc(&irq_err_count);
19955 + atomic_inc_unchecked(&irq_err_count);
19956
19957 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19958 smp_processor_id(), v0 , v1);
19959 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19960 index 00c77cf..2dc6a2d 100644
19961 --- a/arch/x86/kernel/apic/apic_flat_64.c
19962 +++ b/arch/x86/kernel/apic/apic_flat_64.c
19963 @@ -157,7 +157,7 @@ static int flat_probe(void)
19964 return 1;
19965 }
19966
19967 -static struct apic apic_flat = {
19968 +static struct apic apic_flat __read_only = {
19969 .name = "flat",
19970 .probe = flat_probe,
19971 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19972 @@ -271,7 +271,7 @@ static int physflat_probe(void)
19973 return 0;
19974 }
19975
19976 -static struct apic apic_physflat = {
19977 +static struct apic apic_physflat __read_only = {
19978
19979 .name = "physical flat",
19980 .probe = physflat_probe,
19981 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19982 index e145f28..2752888 100644
19983 --- a/arch/x86/kernel/apic/apic_noop.c
19984 +++ b/arch/x86/kernel/apic/apic_noop.c
19985 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19986 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19987 }
19988
19989 -struct apic apic_noop = {
19990 +struct apic apic_noop __read_only = {
19991 .name = "noop",
19992 .probe = noop_probe,
19993 .acpi_madt_oem_check = NULL,
19994 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19995 index d50e364..543bee3 100644
19996 --- a/arch/x86/kernel/apic/bigsmp_32.c
19997 +++ b/arch/x86/kernel/apic/bigsmp_32.c
19998 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19999 return dmi_bigsmp;
20000 }
20001
20002 -static struct apic apic_bigsmp = {
20003 +static struct apic apic_bigsmp __read_only = {
20004
20005 .name = "bigsmp",
20006 .probe = probe_bigsmp,
20007 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20008 index c552247..587a316 100644
20009 --- a/arch/x86/kernel/apic/es7000_32.c
20010 +++ b/arch/x86/kernel/apic/es7000_32.c
20011 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20012 return ret && es7000_apic_is_cluster();
20013 }
20014
20015 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20016 -static struct apic __refdata apic_es7000_cluster = {
20017 +static struct apic apic_es7000_cluster __read_only = {
20018
20019 .name = "es7000",
20020 .probe = probe_es7000,
20021 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20022 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20023 };
20024
20025 -static struct apic __refdata apic_es7000 = {
20026 +static struct apic apic_es7000 __read_only = {
20027
20028 .name = "es7000",
20029 .probe = probe_es7000,
20030 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20031 index e63a5bd..c0babf8 100644
20032 --- a/arch/x86/kernel/apic/io_apic.c
20033 +++ b/arch/x86/kernel/apic/io_apic.c
20034 @@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20035 }
20036 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20037
20038 -void lock_vector_lock(void)
20039 +void lock_vector_lock(void) __acquires(vector_lock)
20040 {
20041 /* Used to the online set of cpus does not change
20042 * during assign_irq_vector.
20043 @@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20044 raw_spin_lock(&vector_lock);
20045 }
20046
20047 -void unlock_vector_lock(void)
20048 +void unlock_vector_lock(void) __releases(vector_lock)
20049 {
20050 raw_spin_unlock(&vector_lock);
20051 }
20052 @@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20053 ack_APIC_irq();
20054 }
20055
20056 -atomic_t irq_mis_count;
20057 +atomic_unchecked_t irq_mis_count;
20058
20059 #ifdef CONFIG_GENERIC_PENDING_IRQ
20060 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20061 @@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20062 * at the cpu.
20063 */
20064 if (!(v & (1 << (i & 0x1f)))) {
20065 - atomic_inc(&irq_mis_count);
20066 + atomic_inc_unchecked(&irq_mis_count);
20067
20068 eoi_ioapic_irq(irq, cfg);
20069 }
20070 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20071 index 1e42e8f..daacf44 100644
20072 --- a/arch/x86/kernel/apic/numaq_32.c
20073 +++ b/arch/x86/kernel/apic/numaq_32.c
20074 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20075 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20076 }
20077
20078 -/* Use __refdata to keep false positive warning calm. */
20079 -static struct apic __refdata apic_numaq = {
20080 +static struct apic apic_numaq __read_only = {
20081
20082 .name = "NUMAQ",
20083 .probe = probe_numaq,
20084 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20085 index eb35ef9..f184a21 100644
20086 --- a/arch/x86/kernel/apic/probe_32.c
20087 +++ b/arch/x86/kernel/apic/probe_32.c
20088 @@ -72,7 +72,7 @@ static int probe_default(void)
20089 return 1;
20090 }
20091
20092 -static struct apic apic_default = {
20093 +static struct apic apic_default __read_only = {
20094
20095 .name = "default",
20096 .probe = probe_default,
20097 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20098 index 77c95c0..434f8a4 100644
20099 --- a/arch/x86/kernel/apic/summit_32.c
20100 +++ b/arch/x86/kernel/apic/summit_32.c
20101 @@ -486,7 +486,7 @@ void setup_summit(void)
20102 }
20103 #endif
20104
20105 -static struct apic apic_summit = {
20106 +static struct apic apic_summit __read_only = {
20107
20108 .name = "summit",
20109 .probe = probe_summit,
20110 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20111 index 140e29d..d88bc95 100644
20112 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20113 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20114 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20115 return notifier_from_errno(err);
20116 }
20117
20118 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20119 +static struct notifier_block x2apic_cpu_notifier = {
20120 .notifier_call = update_clusterinfo,
20121 };
20122
20123 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20124 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20125 }
20126
20127 -static struct apic apic_x2apic_cluster = {
20128 +static struct apic apic_x2apic_cluster __read_only = {
20129
20130 .name = "cluster x2apic",
20131 .probe = x2apic_cluster_probe,
20132 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20133 index 562a76d..a003c0f 100644
20134 --- a/arch/x86/kernel/apic/x2apic_phys.c
20135 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20136 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20137 return apic == &apic_x2apic_phys;
20138 }
20139
20140 -static struct apic apic_x2apic_phys = {
20141 +static struct apic apic_x2apic_phys __read_only = {
20142
20143 .name = "physical x2apic",
20144 .probe = x2apic_phys_probe,
20145 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20146 index ad0dc04..0d9cc56 100644
20147 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20148 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20149 @@ -350,7 +350,7 @@ static int uv_probe(void)
20150 return apic == &apic_x2apic_uv_x;
20151 }
20152
20153 -static struct apic __refdata apic_x2apic_uv_x = {
20154 +static struct apic apic_x2apic_uv_x __read_only = {
20155
20156 .name = "UV large system",
20157 .probe = uv_probe,
20158 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20159 index 3ab0343..814c4787 100644
20160 --- a/arch/x86/kernel/apm_32.c
20161 +++ b/arch/x86/kernel/apm_32.c
20162 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20163 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20164 * even though they are called in protected mode.
20165 */
20166 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20167 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20168 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20169
20170 static const char driver_version[] = "1.16ac"; /* no spaces */
20171 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20172 BUG_ON(cpu != 0);
20173 gdt = get_cpu_gdt_table(cpu);
20174 save_desc_40 = gdt[0x40 / 8];
20175 +
20176 + pax_open_kernel();
20177 gdt[0x40 / 8] = bad_bios_desc;
20178 + pax_close_kernel();
20179
20180 apm_irq_save(flags);
20181 APM_DO_SAVE_SEGS;
20182 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20183 &call->esi);
20184 APM_DO_RESTORE_SEGS;
20185 apm_irq_restore(flags);
20186 +
20187 + pax_open_kernel();
20188 gdt[0x40 / 8] = save_desc_40;
20189 + pax_close_kernel();
20190 +
20191 put_cpu();
20192
20193 return call->eax & 0xff;
20194 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20195 BUG_ON(cpu != 0);
20196 gdt = get_cpu_gdt_table(cpu);
20197 save_desc_40 = gdt[0x40 / 8];
20198 +
20199 + pax_open_kernel();
20200 gdt[0x40 / 8] = bad_bios_desc;
20201 + pax_close_kernel();
20202
20203 apm_irq_save(flags);
20204 APM_DO_SAVE_SEGS;
20205 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20206 &call->eax);
20207 APM_DO_RESTORE_SEGS;
20208 apm_irq_restore(flags);
20209 +
20210 + pax_open_kernel();
20211 gdt[0x40 / 8] = save_desc_40;
20212 + pax_close_kernel();
20213 +
20214 put_cpu();
20215 return error;
20216 }
20217 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20218 * code to that CPU.
20219 */
20220 gdt = get_cpu_gdt_table(0);
20221 +
20222 + pax_open_kernel();
20223 set_desc_base(&gdt[APM_CS >> 3],
20224 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20225 set_desc_base(&gdt[APM_CS_16 >> 3],
20226 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20227 set_desc_base(&gdt[APM_DS >> 3],
20228 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20229 + pax_close_kernel();
20230
20231 proc_create("apm", 0, NULL, &apm_file_ops);
20232
20233 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20234 index 9f6b934..cf5ffb3 100644
20235 --- a/arch/x86/kernel/asm-offsets.c
20236 +++ b/arch/x86/kernel/asm-offsets.c
20237 @@ -32,6 +32,8 @@ void common(void) {
20238 OFFSET(TI_flags, thread_info, flags);
20239 OFFSET(TI_status, thread_info, status);
20240 OFFSET(TI_addr_limit, thread_info, addr_limit);
20241 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20242 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20243
20244 BLANK();
20245 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20246 @@ -52,8 +54,26 @@ void common(void) {
20247 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20248 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20249 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20250 +
20251 +#ifdef CONFIG_PAX_KERNEXEC
20252 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20253 #endif
20254
20255 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20256 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20257 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20258 +#ifdef CONFIG_X86_64
20259 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20260 +#endif
20261 +#endif
20262 +
20263 +#endif
20264 +
20265 + BLANK();
20266 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20267 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20268 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20269 +
20270 #ifdef CONFIG_XEN
20271 BLANK();
20272 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20273 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20274 index e7c798b..2b2019b 100644
20275 --- a/arch/x86/kernel/asm-offsets_64.c
20276 +++ b/arch/x86/kernel/asm-offsets_64.c
20277 @@ -77,6 +77,7 @@ int main(void)
20278 BLANK();
20279 #undef ENTRY
20280
20281 + DEFINE(TSS_size, sizeof(struct tss_struct));
20282 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20283 BLANK();
20284
20285 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20286 index 47b56a7..efc2bc6 100644
20287 --- a/arch/x86/kernel/cpu/Makefile
20288 +++ b/arch/x86/kernel/cpu/Makefile
20289 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20290 CFLAGS_REMOVE_perf_event.o = -pg
20291 endif
20292
20293 -# Make sure load_percpu_segment has no stackprotector
20294 -nostackp := $(call cc-option, -fno-stack-protector)
20295 -CFLAGS_common.o := $(nostackp)
20296 -
20297 obj-y := intel_cacheinfo.o scattered.o topology.o
20298 obj-y += proc.o capflags.o powerflags.o common.o
20299 obj-y += rdrand.o
20300 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20301 index 59bfebc..d8f27bd 100644
20302 --- a/arch/x86/kernel/cpu/amd.c
20303 +++ b/arch/x86/kernel/cpu/amd.c
20304 @@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20305 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20306 {
20307 /* AMD errata T13 (order #21922) */
20308 - if ((c->x86 == 6)) {
20309 + if (c->x86 == 6) {
20310 /* Duron Rev A0 */
20311 if (c->x86_model == 3 && c->x86_mask == 0)
20312 size = 64;
20313 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20314 index 6abc172..3b0df94 100644
20315 --- a/arch/x86/kernel/cpu/common.c
20316 +++ b/arch/x86/kernel/cpu/common.c
20317 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20318
20319 static const struct cpu_dev *this_cpu = &default_cpu;
20320
20321 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20322 -#ifdef CONFIG_X86_64
20323 - /*
20324 - * We need valid kernel segments for data and code in long mode too
20325 - * IRET will check the segment types kkeil 2000/10/28
20326 - * Also sysret mandates a special GDT layout
20327 - *
20328 - * TLS descriptors are currently at a different place compared to i386.
20329 - * Hopefully nobody expects them at a fixed place (Wine?)
20330 - */
20331 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20332 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20333 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20334 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20335 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20336 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20337 -#else
20338 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20339 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20340 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20341 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20342 - /*
20343 - * Segments used for calling PnP BIOS have byte granularity.
20344 - * They code segments and data segments have fixed 64k limits,
20345 - * the transfer segment sizes are set at run time.
20346 - */
20347 - /* 32-bit code */
20348 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20349 - /* 16-bit code */
20350 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20351 - /* 16-bit data */
20352 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20353 - /* 16-bit data */
20354 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20355 - /* 16-bit data */
20356 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20357 - /*
20358 - * The APM segments have byte granularity and their bases
20359 - * are set at run time. All have 64k limits.
20360 - */
20361 - /* 32-bit code */
20362 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20363 - /* 16-bit code */
20364 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20365 - /* data */
20366 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20367 -
20368 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20369 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20370 - GDT_STACK_CANARY_INIT
20371 -#endif
20372 -} };
20373 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20374 -
20375 static int __init x86_xsave_setup(char *s)
20376 {
20377 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20378 @@ -288,6 +234,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20379 set_in_cr4(X86_CR4_SMAP);
20380 }
20381
20382 +#ifdef CONFIG_X86_64
20383 +static __init int setup_disable_pcid(char *arg)
20384 +{
20385 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20386 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20387 +
20388 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20389 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20390 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20391 +#endif
20392 +
20393 + return 1;
20394 +}
20395 +__setup("nopcid", setup_disable_pcid);
20396 +
20397 +static void setup_pcid(struct cpuinfo_x86 *c)
20398 +{
20399 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20400 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20401 +
20402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20403 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20404 + pax_open_kernel();
20405 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20406 + pax_close_kernel();
20407 + printk("PAX: slow and weak UDEREF enabled\n");
20408 + } else
20409 + printk("PAX: UDEREF disabled\n");
20410 +#endif
20411 +
20412 + return;
20413 + }
20414 +
20415 + printk("PAX: PCID detected\n");
20416 + set_in_cr4(X86_CR4_PCIDE);
20417 +
20418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20419 + pax_open_kernel();
20420 + clone_pgd_mask = ~(pgdval_t)0UL;
20421 + pax_close_kernel();
20422 + if (pax_user_shadow_base)
20423 + printk("PAX: weak UDEREF enabled\n");
20424 + else {
20425 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20426 + printk("PAX: strong UDEREF enabled\n");
20427 + }
20428 +#endif
20429 +
20430 + if (cpu_has(c, X86_FEATURE_INVPCID))
20431 + printk("PAX: INVPCID detected\n");
20432 +}
20433 +#endif
20434 +
20435 /*
20436 * Some CPU features depend on higher CPUID levels, which may not always
20437 * be available due to CPUID level capping or broken virtualization
20438 @@ -388,7 +387,7 @@ void switch_to_new_gdt(int cpu)
20439 {
20440 struct desc_ptr gdt_descr;
20441
20442 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20443 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20444 gdt_descr.size = GDT_SIZE - 1;
20445 load_gdt(&gdt_descr);
20446 /* Reload the per-cpu base */
20447 @@ -877,6 +876,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20448 setup_smep(c);
20449 setup_smap(c);
20450
20451 +#ifdef CONFIG_X86_64
20452 + setup_pcid(c);
20453 +#endif
20454 +
20455 /*
20456 * The vendor-specific functions might have changed features.
20457 * Now we do "generic changes."
20458 @@ -885,6 +888,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20459 /* Filter out anything that depends on CPUID levels we don't have */
20460 filter_cpuid_features(c, true);
20461
20462 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20463 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20464 +#endif
20465 +
20466 /* If the model name is still unset, do table lookup. */
20467 if (!c->x86_model_id[0]) {
20468 const char *p;
20469 @@ -1072,10 +1079,12 @@ static __init int setup_disablecpuid(char *arg)
20470 }
20471 __setup("clearcpuid=", setup_disablecpuid);
20472
20473 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20474 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20475 +
20476 #ifdef CONFIG_X86_64
20477 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20478 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20479 - (unsigned long) debug_idt_table };
20480 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20481 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20482
20483 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20484 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20485 @@ -1089,7 +1098,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20486 EXPORT_PER_CPU_SYMBOL(current_task);
20487
20488 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20489 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20490 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20491 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20492
20493 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20494 @@ -1239,7 +1248,7 @@ void cpu_init(void)
20495 load_ucode_ap();
20496
20497 cpu = stack_smp_processor_id();
20498 - t = &per_cpu(init_tss, cpu);
20499 + t = init_tss + cpu;
20500 oist = &per_cpu(orig_ist, cpu);
20501
20502 #ifdef CONFIG_NUMA
20503 @@ -1274,7 +1283,6 @@ void cpu_init(void)
20504 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20505 barrier();
20506
20507 - x86_configure_nx();
20508 enable_x2apic();
20509
20510 /*
20511 @@ -1326,7 +1334,7 @@ void cpu_init(void)
20512 {
20513 int cpu = smp_processor_id();
20514 struct task_struct *curr = current;
20515 - struct tss_struct *t = &per_cpu(init_tss, cpu);
20516 + struct tss_struct *t = init_tss + cpu;
20517 struct thread_struct *thread = &curr->thread;
20518
20519 show_ucode_info_early();
20520 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20521 index 0641113..06f5ba4 100644
20522 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20523 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20524 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20525 };
20526
20527 #ifdef CONFIG_AMD_NB
20528 +static struct attribute *default_attrs_amd_nb[] = {
20529 + &type.attr,
20530 + &level.attr,
20531 + &coherency_line_size.attr,
20532 + &physical_line_partition.attr,
20533 + &ways_of_associativity.attr,
20534 + &number_of_sets.attr,
20535 + &size.attr,
20536 + &shared_cpu_map.attr,
20537 + &shared_cpu_list.attr,
20538 + NULL,
20539 + NULL,
20540 + NULL,
20541 + NULL
20542 +};
20543 +
20544 static struct attribute **amd_l3_attrs(void)
20545 {
20546 static struct attribute **attrs;
20547 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20548
20549 n = ARRAY_SIZE(default_attrs);
20550
20551 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20552 - n += 2;
20553 -
20554 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20555 - n += 1;
20556 -
20557 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20558 - if (attrs == NULL)
20559 - return attrs = default_attrs;
20560 -
20561 - for (n = 0; default_attrs[n]; n++)
20562 - attrs[n] = default_attrs[n];
20563 + attrs = default_attrs_amd_nb;
20564
20565 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20566 attrs[n++] = &cache_disable_0.attr;
20567 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20568 .default_attrs = default_attrs,
20569 };
20570
20571 +#ifdef CONFIG_AMD_NB
20572 +static struct kobj_type ktype_cache_amd_nb = {
20573 + .sysfs_ops = &sysfs_ops,
20574 + .default_attrs = default_attrs_amd_nb,
20575 +};
20576 +#endif
20577 +
20578 static struct kobj_type ktype_percpu_entry = {
20579 .sysfs_ops = &sysfs_ops,
20580 };
20581 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
20582 return retval;
20583 }
20584
20585 +#ifdef CONFIG_AMD_NB
20586 + amd_l3_attrs();
20587 +#endif
20588 +
20589 for (i = 0; i < num_cache_leaves; i++) {
20590 + struct kobj_type *ktype;
20591 +
20592 this_object = INDEX_KOBJECT_PTR(cpu, i);
20593 this_object->cpu = cpu;
20594 this_object->index = i;
20595
20596 this_leaf = CPUID4_INFO_IDX(cpu, i);
20597
20598 - ktype_cache.default_attrs = default_attrs;
20599 + ktype = &ktype_cache;
20600 #ifdef CONFIG_AMD_NB
20601 if (this_leaf->base.nb)
20602 - ktype_cache.default_attrs = amd_l3_attrs();
20603 + ktype = &ktype_cache_amd_nb;
20604 #endif
20605 retval = kobject_init_and_add(&(this_object->kobj),
20606 - &ktype_cache,
20607 + ktype,
20608 per_cpu(ici_cache_kobject, cpu),
20609 "index%1lu", i);
20610 if (unlikely(retval)) {
20611 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20612 index b3218cd..99a75de 100644
20613 --- a/arch/x86/kernel/cpu/mcheck/mce.c
20614 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
20615 @@ -45,6 +45,7 @@
20616 #include <asm/processor.h>
20617 #include <asm/mce.h>
20618 #include <asm/msr.h>
20619 +#include <asm/local.h>
20620
20621 #include "mce-internal.h"
20622
20623 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
20624 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20625 m->cs, m->ip);
20626
20627 - if (m->cs == __KERNEL_CS)
20628 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20629 print_symbol("{%s}", m->ip);
20630 pr_cont("\n");
20631 }
20632 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
20633
20634 #define PANIC_TIMEOUT 5 /* 5 seconds */
20635
20636 -static atomic_t mce_paniced;
20637 +static atomic_unchecked_t mce_paniced;
20638
20639 static int fake_panic;
20640 -static atomic_t mce_fake_paniced;
20641 +static atomic_unchecked_t mce_fake_paniced;
20642
20643 /* Panic in progress. Enable interrupts and wait for final IPI */
20644 static void wait_for_panic(void)
20645 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20646 /*
20647 * Make sure only one CPU runs in machine check panic
20648 */
20649 - if (atomic_inc_return(&mce_paniced) > 1)
20650 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20651 wait_for_panic();
20652 barrier();
20653
20654 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20655 console_verbose();
20656 } else {
20657 /* Don't log too much for fake panic */
20658 - if (atomic_inc_return(&mce_fake_paniced) > 1)
20659 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20660 return;
20661 }
20662 /* First print corrected ones that are still unlogged */
20663 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20664 if (!fake_panic) {
20665 if (panic_timeout == 0)
20666 panic_timeout = mca_cfg.panic_timeout;
20667 - panic(msg);
20668 + panic("%s", msg);
20669 } else
20670 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20671 }
20672 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
20673 * might have been modified by someone else.
20674 */
20675 rmb();
20676 - if (atomic_read(&mce_paniced))
20677 + if (atomic_read_unchecked(&mce_paniced))
20678 wait_for_panic();
20679 if (!mca_cfg.monarch_timeout)
20680 goto out;
20681 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20682 }
20683
20684 /* Call the installed machine check handler for this CPU setup. */
20685 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
20686 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20687 unexpected_machine_check;
20688
20689 /*
20690 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20691 return;
20692 }
20693
20694 + pax_open_kernel();
20695 machine_check_vector = do_machine_check;
20696 + pax_close_kernel();
20697
20698 __mcheck_cpu_init_generic();
20699 __mcheck_cpu_init_vendor(c);
20700 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20701 */
20702
20703 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20704 -static int mce_chrdev_open_count; /* #times opened */
20705 +static local_t mce_chrdev_open_count; /* #times opened */
20706 static int mce_chrdev_open_exclu; /* already open exclusive? */
20707
20708 static int mce_chrdev_open(struct inode *inode, struct file *file)
20709 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20710 spin_lock(&mce_chrdev_state_lock);
20711
20712 if (mce_chrdev_open_exclu ||
20713 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20714 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20715 spin_unlock(&mce_chrdev_state_lock);
20716
20717 return -EBUSY;
20718 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20719
20720 if (file->f_flags & O_EXCL)
20721 mce_chrdev_open_exclu = 1;
20722 - mce_chrdev_open_count++;
20723 + local_inc(&mce_chrdev_open_count);
20724
20725 spin_unlock(&mce_chrdev_state_lock);
20726
20727 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20728 {
20729 spin_lock(&mce_chrdev_state_lock);
20730
20731 - mce_chrdev_open_count--;
20732 + local_dec(&mce_chrdev_open_count);
20733 mce_chrdev_open_exclu = 0;
20734
20735 spin_unlock(&mce_chrdev_state_lock);
20736 @@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
20737
20738 for (i = 0; i < mca_cfg.banks; i++) {
20739 struct mce_bank *b = &mce_banks[i];
20740 - struct device_attribute *a = &b->attr;
20741 + device_attribute_no_const *a = &b->attr;
20742
20743 sysfs_attr_init(&a->attr);
20744 a->attr.name = b->attrname;
20745 @@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
20746 static void mce_reset(void)
20747 {
20748 cpu_missing = 0;
20749 - atomic_set(&mce_fake_paniced, 0);
20750 + atomic_set_unchecked(&mce_fake_paniced, 0);
20751 atomic_set(&mce_executing, 0);
20752 atomic_set(&mce_callin, 0);
20753 atomic_set(&global_nwo, 0);
20754 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20755 index 1c044b1..37a2a43 100644
20756 --- a/arch/x86/kernel/cpu/mcheck/p5.c
20757 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
20758 @@ -11,6 +11,7 @@
20759 #include <asm/processor.h>
20760 #include <asm/mce.h>
20761 #include <asm/msr.h>
20762 +#include <asm/pgtable.h>
20763
20764 /* By default disabled */
20765 int mce_p5_enabled __read_mostly;
20766 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20767 if (!cpu_has(c, X86_FEATURE_MCE))
20768 return;
20769
20770 + pax_open_kernel();
20771 machine_check_vector = pentium_machine_check;
20772 + pax_close_kernel();
20773 /* Make sure the vector pointer is visible before we enable MCEs: */
20774 wmb();
20775
20776 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20777 index e9a701a..35317d6 100644
20778 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
20779 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20780 @@ -10,6 +10,7 @@
20781 #include <asm/processor.h>
20782 #include <asm/mce.h>
20783 #include <asm/msr.h>
20784 +#include <asm/pgtable.h>
20785
20786 /* Machine check handler for WinChip C6: */
20787 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20788 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20789 {
20790 u32 lo, hi;
20791
20792 + pax_open_kernel();
20793 machine_check_vector = winchip_machine_check;
20794 + pax_close_kernel();
20795 /* Make sure the vector pointer is visible before we enable MCEs: */
20796 wmb();
20797
20798 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20799 index f961de9..8a9d332 100644
20800 --- a/arch/x86/kernel/cpu/mtrr/main.c
20801 +++ b/arch/x86/kernel/cpu/mtrr/main.c
20802 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20803 u64 size_or_mask, size_and_mask;
20804 static bool mtrr_aps_delayed_init;
20805
20806 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20807 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20808
20809 const struct mtrr_ops *mtrr_if;
20810
20811 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20812 index df5e41f..816c719 100644
20813 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20814 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20815 @@ -25,7 +25,7 @@ struct mtrr_ops {
20816 int (*validate_add_page)(unsigned long base, unsigned long size,
20817 unsigned int type);
20818 int (*have_wrcomb)(void);
20819 -};
20820 +} __do_const;
20821
20822 extern int generic_get_free_region(unsigned long base, unsigned long size,
20823 int replace_reg);
20824 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20825 index 8e13293..9bfd68c 100644
20826 --- a/arch/x86/kernel/cpu/perf_event.c
20827 +++ b/arch/x86/kernel/cpu/perf_event.c
20828 @@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20829 pr_info("no hardware sampling interrupt available.\n");
20830 }
20831
20832 -static struct attribute_group x86_pmu_format_group = {
20833 +static attribute_group_no_const x86_pmu_format_group = {
20834 .name = "format",
20835 .attrs = NULL,
20836 };
20837 @@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20838 NULL,
20839 };
20840
20841 -static struct attribute_group x86_pmu_events_group = {
20842 +static attribute_group_no_const x86_pmu_events_group = {
20843 .name = "events",
20844 .attrs = events_attr,
20845 };
20846 @@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20847 if (idx > GDT_ENTRIES)
20848 return 0;
20849
20850 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20851 + desc = get_cpu_gdt_table(smp_processor_id());
20852 }
20853
20854 return get_desc_base(desc + idx);
20855 @@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20856 break;
20857
20858 perf_callchain_store(entry, frame.return_address);
20859 - fp = frame.next_frame;
20860 + fp = (const void __force_user *)frame.next_frame;
20861 }
20862 }
20863
20864 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20865 index 639d128..e92d7e5 100644
20866 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20867 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20868 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20869 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20870 {
20871 struct attribute **attrs;
20872 - struct attribute_group *attr_group;
20873 + attribute_group_no_const *attr_group;
20874 int i = 0, j;
20875
20876 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20877 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20878 index 0fa4f24..17990ed 100644
20879 --- a/arch/x86/kernel/cpu/perf_event_intel.c
20880 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
20881 @@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
20882 * v2 and above have a perf capabilities MSR
20883 */
20884 if (version > 1) {
20885 - u64 capabilities;
20886 + u64 capabilities = x86_pmu.intel_cap.capabilities;
20887
20888 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20889 - x86_pmu.intel_cap.capabilities = capabilities;
20890 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20891 + x86_pmu.intel_cap.capabilities = capabilities;
20892 }
20893
20894 intel_ds_init();
20895 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20896 index 29c2487..a5606fa 100644
20897 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20898 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20899 @@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20900 static int __init uncore_type_init(struct intel_uncore_type *type)
20901 {
20902 struct intel_uncore_pmu *pmus;
20903 - struct attribute_group *attr_group;
20904 + attribute_group_no_const *attr_group;
20905 struct attribute **attrs;
20906 int i, j;
20907
20908 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20909 index a80ab71..4089da5 100644
20910 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20911 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20912 @@ -498,7 +498,7 @@ struct intel_uncore_box {
20913 struct uncore_event_desc {
20914 struct kobj_attribute attr;
20915 const char *config;
20916 -};
20917 +} __do_const;
20918
20919 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20920 { \
20921 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20922 index 7d9481c..99c7e4b 100644
20923 --- a/arch/x86/kernel/cpuid.c
20924 +++ b/arch/x86/kernel/cpuid.c
20925 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20926 return notifier_from_errno(err);
20927 }
20928
20929 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
20930 +static struct notifier_block cpuid_class_cpu_notifier =
20931 {
20932 .notifier_call = cpuid_class_cpu_callback,
20933 };
20934 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20935 index 18677a9..f67c45b 100644
20936 --- a/arch/x86/kernel/crash.c
20937 +++ b/arch/x86/kernel/crash.c
20938 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20939 {
20940 #ifdef CONFIG_X86_32
20941 struct pt_regs fixed_regs;
20942 -#endif
20943
20944 -#ifdef CONFIG_X86_32
20945 - if (!user_mode_vm(regs)) {
20946 + if (!user_mode(regs)) {
20947 crash_fixup_ss_esp(&fixed_regs, regs);
20948 regs = &fixed_regs;
20949 }
20950 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20951 index afa64ad..dce67dd 100644
20952 --- a/arch/x86/kernel/crash_dump_64.c
20953 +++ b/arch/x86/kernel/crash_dump_64.c
20954 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20955 return -ENOMEM;
20956
20957 if (userbuf) {
20958 - if (copy_to_user(buf, vaddr + offset, csize)) {
20959 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20960 iounmap(vaddr);
20961 return -EFAULT;
20962 }
20963 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20964 index 5d3fe8d..02e1429 100644
20965 --- a/arch/x86/kernel/doublefault.c
20966 +++ b/arch/x86/kernel/doublefault.c
20967 @@ -13,7 +13,7 @@
20968
20969 #define DOUBLEFAULT_STACKSIZE (1024)
20970 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20971 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20972 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20973
20974 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20975
20976 @@ -23,7 +23,7 @@ static void doublefault_fn(void)
20977 unsigned long gdt, tss;
20978
20979 native_store_gdt(&gdt_desc);
20980 - gdt = gdt_desc.address;
20981 + gdt = (unsigned long)gdt_desc.address;
20982
20983 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20984
20985 @@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20986 /* 0x2 bit is always set */
20987 .flags = X86_EFLAGS_SF | 0x2,
20988 .sp = STACK_START,
20989 - .es = __USER_DS,
20990 + .es = __KERNEL_DS,
20991 .cs = __KERNEL_CS,
20992 .ss = __KERNEL_DS,
20993 - .ds = __USER_DS,
20994 + .ds = __KERNEL_DS,
20995 .fs = __KERNEL_PERCPU,
20996
20997 .__cr3 = __pa_nodebug(swapper_pg_dir),
20998 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20999 index d9c12d3..7858b62 100644
21000 --- a/arch/x86/kernel/dumpstack.c
21001 +++ b/arch/x86/kernel/dumpstack.c
21002 @@ -2,6 +2,9 @@
21003 * Copyright (C) 1991, 1992 Linus Torvalds
21004 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21005 */
21006 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21007 +#define __INCLUDED_BY_HIDESYM 1
21008 +#endif
21009 #include <linux/kallsyms.h>
21010 #include <linux/kprobes.h>
21011 #include <linux/uaccess.h>
21012 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21013 static void
21014 print_ftrace_graph_addr(unsigned long addr, void *data,
21015 const struct stacktrace_ops *ops,
21016 - struct thread_info *tinfo, int *graph)
21017 + struct task_struct *task, int *graph)
21018 {
21019 - struct task_struct *task;
21020 unsigned long ret_addr;
21021 int index;
21022
21023 if (addr != (unsigned long)return_to_handler)
21024 return;
21025
21026 - task = tinfo->task;
21027 index = task->curr_ret_stack;
21028
21029 if (!task->ret_stack || index < *graph)
21030 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21031 static inline void
21032 print_ftrace_graph_addr(unsigned long addr, void *data,
21033 const struct stacktrace_ops *ops,
21034 - struct thread_info *tinfo, int *graph)
21035 + struct task_struct *task, int *graph)
21036 { }
21037 #endif
21038
21039 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21040 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21041 */
21042
21043 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21044 - void *p, unsigned int size, void *end)
21045 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21046 {
21047 - void *t = tinfo;
21048 if (end) {
21049 if (p < end && p >= (end-THREAD_SIZE))
21050 return 1;
21051 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21052 }
21053
21054 unsigned long
21055 -print_context_stack(struct thread_info *tinfo,
21056 +print_context_stack(struct task_struct *task, void *stack_start,
21057 unsigned long *stack, unsigned long bp,
21058 const struct stacktrace_ops *ops, void *data,
21059 unsigned long *end, int *graph)
21060 {
21061 struct stack_frame *frame = (struct stack_frame *)bp;
21062
21063 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21064 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21065 unsigned long addr;
21066
21067 addr = *stack;
21068 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21069 } else {
21070 ops->address(data, addr, 0);
21071 }
21072 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21073 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21074 }
21075 stack++;
21076 }
21077 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21078 EXPORT_SYMBOL_GPL(print_context_stack);
21079
21080 unsigned long
21081 -print_context_stack_bp(struct thread_info *tinfo,
21082 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21083 unsigned long *stack, unsigned long bp,
21084 const struct stacktrace_ops *ops, void *data,
21085 unsigned long *end, int *graph)
21086 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21087 struct stack_frame *frame = (struct stack_frame *)bp;
21088 unsigned long *ret_addr = &frame->return_address;
21089
21090 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21091 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21092 unsigned long addr = *ret_addr;
21093
21094 if (!__kernel_text_address(addr))
21095 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21096 ops->address(data, addr, 1);
21097 frame = frame->next_frame;
21098 ret_addr = &frame->return_address;
21099 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21100 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21101 }
21102
21103 return (unsigned long)frame;
21104 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21105 static void print_trace_address(void *data, unsigned long addr, int reliable)
21106 {
21107 touch_nmi_watchdog();
21108 - printk(data);
21109 + printk("%s", (char *)data);
21110 printk_stack_address(addr, reliable);
21111 }
21112
21113 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21114 }
21115 EXPORT_SYMBOL_GPL(oops_begin);
21116
21117 +extern void gr_handle_kernel_exploit(void);
21118 +
21119 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21120 {
21121 if (regs && kexec_should_crash(current))
21122 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21123 panic("Fatal exception in interrupt");
21124 if (panic_on_oops)
21125 panic("Fatal exception");
21126 - do_exit(signr);
21127 +
21128 + gr_handle_kernel_exploit();
21129 +
21130 + do_group_exit(signr);
21131 }
21132
21133 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21134 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21135 print_modules();
21136 show_regs(regs);
21137 #ifdef CONFIG_X86_32
21138 - if (user_mode_vm(regs)) {
21139 + if (user_mode(regs)) {
21140 sp = regs->sp;
21141 ss = regs->ss & 0xffff;
21142 } else {
21143 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21144 unsigned long flags = oops_begin();
21145 int sig = SIGSEGV;
21146
21147 - if (!user_mode_vm(regs))
21148 + if (!user_mode(regs))
21149 report_bug(regs->ip, regs);
21150
21151 if (__die(str, regs, err))
21152 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21153 index f2a1770..540657f 100644
21154 --- a/arch/x86/kernel/dumpstack_32.c
21155 +++ b/arch/x86/kernel/dumpstack_32.c
21156 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21157 bp = stack_frame(task, regs);
21158
21159 for (;;) {
21160 - struct thread_info *context;
21161 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21162
21163 - context = (struct thread_info *)
21164 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21165 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21166 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21167
21168 - stack = (unsigned long *)context->previous_esp;
21169 - if (!stack)
21170 + if (stack_start == task_stack_page(task))
21171 break;
21172 + stack = *(unsigned long **)stack_start;
21173 if (ops->stack(data, "IRQ") < 0)
21174 break;
21175 touch_nmi_watchdog();
21176 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21177 int i;
21178
21179 show_regs_print_info(KERN_EMERG);
21180 - __show_regs(regs, !user_mode_vm(regs));
21181 + __show_regs(regs, !user_mode(regs));
21182
21183 /*
21184 * When in-kernel, we also print out the stack and code at the
21185 * time of the fault..
21186 */
21187 - if (!user_mode_vm(regs)) {
21188 + if (!user_mode(regs)) {
21189 unsigned int code_prologue = code_bytes * 43 / 64;
21190 unsigned int code_len = code_bytes;
21191 unsigned char c;
21192 u8 *ip;
21193 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21194
21195 pr_emerg("Stack:\n");
21196 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21197
21198 pr_emerg("Code:");
21199
21200 - ip = (u8 *)regs->ip - code_prologue;
21201 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21202 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21203 /* try starting at IP */
21204 - ip = (u8 *)regs->ip;
21205 + ip = (u8 *)regs->ip + cs_base;
21206 code_len = code_len - code_prologue + 1;
21207 }
21208 for (i = 0; i < code_len; i++, ip++) {
21209 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21210 pr_cont(" Bad EIP value.");
21211 break;
21212 }
21213 - if (ip == (u8 *)regs->ip)
21214 + if (ip == (u8 *)regs->ip + cs_base)
21215 pr_cont(" <%02x>", c);
21216 else
21217 pr_cont(" %02x", c);
21218 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21219 {
21220 unsigned short ud2;
21221
21222 + ip = ktla_ktva(ip);
21223 if (ip < PAGE_OFFSET)
21224 return 0;
21225 if (probe_kernel_address((unsigned short *)ip, ud2))
21226 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21227
21228 return ud2 == 0x0b0f;
21229 }
21230 +
21231 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21232 +void pax_check_alloca(unsigned long size)
21233 +{
21234 + unsigned long sp = (unsigned long)&sp, stack_left;
21235 +
21236 + /* all kernel stacks are of the same size */
21237 + stack_left = sp & (THREAD_SIZE - 1);
21238 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21239 +}
21240 +EXPORT_SYMBOL(pax_check_alloca);
21241 +#endif
21242 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21243 index addb207..99635fa 100644
21244 --- a/arch/x86/kernel/dumpstack_64.c
21245 +++ b/arch/x86/kernel/dumpstack_64.c
21246 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21247 unsigned long *irq_stack_end =
21248 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21249 unsigned used = 0;
21250 - struct thread_info *tinfo;
21251 int graph = 0;
21252 unsigned long dummy;
21253 + void *stack_start;
21254
21255 if (!task)
21256 task = current;
21257 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21258 * current stack address. If the stacks consist of nested
21259 * exceptions
21260 */
21261 - tinfo = task_thread_info(task);
21262 for (;;) {
21263 char *id;
21264 unsigned long *estack_end;
21265 +
21266 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21267 &used, &id);
21268
21269 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21270 if (ops->stack(data, id) < 0)
21271 break;
21272
21273 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21274 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21275 data, estack_end, &graph);
21276 ops->stack(data, "<EOE>");
21277 /*
21278 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21279 * second-to-last pointer (index -2 to end) in the
21280 * exception stack:
21281 */
21282 + if ((u16)estack_end[-1] != __KERNEL_DS)
21283 + goto out;
21284 stack = (unsigned long *) estack_end[-2];
21285 continue;
21286 }
21287 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21288 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21289 if (ops->stack(data, "IRQ") < 0)
21290 break;
21291 - bp = ops->walk_stack(tinfo, stack, bp,
21292 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21293 ops, data, irq_stack_end, &graph);
21294 /*
21295 * We link to the next stack (which would be
21296 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21297 /*
21298 * This handles the process stack:
21299 */
21300 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21301 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21302 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21303 +out:
21304 put_cpu();
21305 }
21306 EXPORT_SYMBOL(dump_trace);
21307 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21308
21309 return ud2 == 0x0b0f;
21310 }
21311 +
21312 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21313 +void pax_check_alloca(unsigned long size)
21314 +{
21315 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21316 + unsigned cpu, used;
21317 + char *id;
21318 +
21319 + /* check the process stack first */
21320 + stack_start = (unsigned long)task_stack_page(current);
21321 + stack_end = stack_start + THREAD_SIZE;
21322 + if (likely(stack_start <= sp && sp < stack_end)) {
21323 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21324 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21325 + return;
21326 + }
21327 +
21328 + cpu = get_cpu();
21329 +
21330 + /* check the irq stacks */
21331 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21332 + stack_start = stack_end - IRQ_STACK_SIZE;
21333 + if (stack_start <= sp && sp < stack_end) {
21334 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21335 + put_cpu();
21336 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21337 + return;
21338 + }
21339 +
21340 + /* check the exception stacks */
21341 + used = 0;
21342 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21343 + stack_start = stack_end - EXCEPTION_STKSZ;
21344 + if (stack_end && stack_start <= sp && sp < stack_end) {
21345 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21346 + put_cpu();
21347 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21348 + return;
21349 + }
21350 +
21351 + put_cpu();
21352 +
21353 + /* unknown stack */
21354 + BUG();
21355 +}
21356 +EXPORT_SYMBOL(pax_check_alloca);
21357 +#endif
21358 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21359 index 174da5f..5e55606 100644
21360 --- a/arch/x86/kernel/e820.c
21361 +++ b/arch/x86/kernel/e820.c
21362 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21363
21364 static void early_panic(char *msg)
21365 {
21366 - early_printk(msg);
21367 - panic(msg);
21368 + early_printk("%s", msg);
21369 + panic("%s", msg);
21370 }
21371
21372 static int userdef __initdata;
21373 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21374 index 01d1c18..8073693 100644
21375 --- a/arch/x86/kernel/early_printk.c
21376 +++ b/arch/x86/kernel/early_printk.c
21377 @@ -7,6 +7,7 @@
21378 #include <linux/pci_regs.h>
21379 #include <linux/pci_ids.h>
21380 #include <linux/errno.h>
21381 +#include <linux/sched.h>
21382 #include <asm/io.h>
21383 #include <asm/processor.h>
21384 #include <asm/fcntl.h>
21385 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21386 index a2a4f46..6cab058 100644
21387 --- a/arch/x86/kernel/entry_32.S
21388 +++ b/arch/x86/kernel/entry_32.S
21389 @@ -177,13 +177,153 @@
21390 /*CFI_REL_OFFSET gs, PT_GS*/
21391 .endm
21392 .macro SET_KERNEL_GS reg
21393 +
21394 +#ifdef CONFIG_CC_STACKPROTECTOR
21395 movl $(__KERNEL_STACK_CANARY), \reg
21396 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21397 + movl $(__USER_DS), \reg
21398 +#else
21399 + xorl \reg, \reg
21400 +#endif
21401 +
21402 movl \reg, %gs
21403 .endm
21404
21405 #endif /* CONFIG_X86_32_LAZY_GS */
21406
21407 -.macro SAVE_ALL
21408 +.macro pax_enter_kernel
21409 +#ifdef CONFIG_PAX_KERNEXEC
21410 + call pax_enter_kernel
21411 +#endif
21412 +.endm
21413 +
21414 +.macro pax_exit_kernel
21415 +#ifdef CONFIG_PAX_KERNEXEC
21416 + call pax_exit_kernel
21417 +#endif
21418 +.endm
21419 +
21420 +#ifdef CONFIG_PAX_KERNEXEC
21421 +ENTRY(pax_enter_kernel)
21422 +#ifdef CONFIG_PARAVIRT
21423 + pushl %eax
21424 + pushl %ecx
21425 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21426 + mov %eax, %esi
21427 +#else
21428 + mov %cr0, %esi
21429 +#endif
21430 + bts $16, %esi
21431 + jnc 1f
21432 + mov %cs, %esi
21433 + cmp $__KERNEL_CS, %esi
21434 + jz 3f
21435 + ljmp $__KERNEL_CS, $3f
21436 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21437 +2:
21438 +#ifdef CONFIG_PARAVIRT
21439 + mov %esi, %eax
21440 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21441 +#else
21442 + mov %esi, %cr0
21443 +#endif
21444 +3:
21445 +#ifdef CONFIG_PARAVIRT
21446 + popl %ecx
21447 + popl %eax
21448 +#endif
21449 + ret
21450 +ENDPROC(pax_enter_kernel)
21451 +
21452 +ENTRY(pax_exit_kernel)
21453 +#ifdef CONFIG_PARAVIRT
21454 + pushl %eax
21455 + pushl %ecx
21456 +#endif
21457 + mov %cs, %esi
21458 + cmp $__KERNEXEC_KERNEL_CS, %esi
21459 + jnz 2f
21460 +#ifdef CONFIG_PARAVIRT
21461 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21462 + mov %eax, %esi
21463 +#else
21464 + mov %cr0, %esi
21465 +#endif
21466 + btr $16, %esi
21467 + ljmp $__KERNEL_CS, $1f
21468 +1:
21469 +#ifdef CONFIG_PARAVIRT
21470 + mov %esi, %eax
21471 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21472 +#else
21473 + mov %esi, %cr0
21474 +#endif
21475 +2:
21476 +#ifdef CONFIG_PARAVIRT
21477 + popl %ecx
21478 + popl %eax
21479 +#endif
21480 + ret
21481 +ENDPROC(pax_exit_kernel)
21482 +#endif
21483 +
21484 + .macro pax_erase_kstack
21485 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21486 + call pax_erase_kstack
21487 +#endif
21488 + .endm
21489 +
21490 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21491 +/*
21492 + * ebp: thread_info
21493 + */
21494 +ENTRY(pax_erase_kstack)
21495 + pushl %edi
21496 + pushl %ecx
21497 + pushl %eax
21498 +
21499 + mov TI_lowest_stack(%ebp), %edi
21500 + mov $-0xBEEF, %eax
21501 + std
21502 +
21503 +1: mov %edi, %ecx
21504 + and $THREAD_SIZE_asm - 1, %ecx
21505 + shr $2, %ecx
21506 + repne scasl
21507 + jecxz 2f
21508 +
21509 + cmp $2*16, %ecx
21510 + jc 2f
21511 +
21512 + mov $2*16, %ecx
21513 + repe scasl
21514 + jecxz 2f
21515 + jne 1b
21516 +
21517 +2: cld
21518 + mov %esp, %ecx
21519 + sub %edi, %ecx
21520 +
21521 + cmp $THREAD_SIZE_asm, %ecx
21522 + jb 3f
21523 + ud2
21524 +3:
21525 +
21526 + shr $2, %ecx
21527 + rep stosl
21528 +
21529 + mov TI_task_thread_sp0(%ebp), %edi
21530 + sub $128, %edi
21531 + mov %edi, TI_lowest_stack(%ebp)
21532 +
21533 + popl %eax
21534 + popl %ecx
21535 + popl %edi
21536 + ret
21537 +ENDPROC(pax_erase_kstack)
21538 +#endif
21539 +
21540 +.macro __SAVE_ALL _DS
21541 cld
21542 PUSH_GS
21543 pushl_cfi %fs
21544 @@ -206,7 +346,7 @@
21545 CFI_REL_OFFSET ecx, 0
21546 pushl_cfi %ebx
21547 CFI_REL_OFFSET ebx, 0
21548 - movl $(__USER_DS), %edx
21549 + movl $\_DS, %edx
21550 movl %edx, %ds
21551 movl %edx, %es
21552 movl $(__KERNEL_PERCPU), %edx
21553 @@ -214,6 +354,15 @@
21554 SET_KERNEL_GS %edx
21555 .endm
21556
21557 +.macro SAVE_ALL
21558 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21559 + __SAVE_ALL __KERNEL_DS
21560 + pax_enter_kernel
21561 +#else
21562 + __SAVE_ALL __USER_DS
21563 +#endif
21564 +.endm
21565 +
21566 .macro RESTORE_INT_REGS
21567 popl_cfi %ebx
21568 CFI_RESTORE ebx
21569 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
21570 popfl_cfi
21571 jmp syscall_exit
21572 CFI_ENDPROC
21573 -END(ret_from_fork)
21574 +ENDPROC(ret_from_fork)
21575
21576 ENTRY(ret_from_kernel_thread)
21577 CFI_STARTPROC
21578 @@ -344,7 +493,15 @@ ret_from_intr:
21579 andl $SEGMENT_RPL_MASK, %eax
21580 #endif
21581 cmpl $USER_RPL, %eax
21582 +
21583 +#ifdef CONFIG_PAX_KERNEXEC
21584 + jae resume_userspace
21585 +
21586 + pax_exit_kernel
21587 + jmp resume_kernel
21588 +#else
21589 jb resume_kernel # not returning to v8086 or userspace
21590 +#endif
21591
21592 ENTRY(resume_userspace)
21593 LOCKDEP_SYS_EXIT
21594 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21595 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21596 # int/exception return?
21597 jne work_pending
21598 - jmp restore_all
21599 -END(ret_from_exception)
21600 + jmp restore_all_pax
21601 +ENDPROC(ret_from_exception)
21602
21603 #ifdef CONFIG_PREEMPT
21604 ENTRY(resume_kernel)
21605 @@ -369,7 +526,7 @@ need_resched:
21606 jz restore_all
21607 call preempt_schedule_irq
21608 jmp need_resched
21609 -END(resume_kernel)
21610 +ENDPROC(resume_kernel)
21611 #endif
21612 CFI_ENDPROC
21613 /*
21614 @@ -403,30 +560,45 @@ sysenter_past_esp:
21615 /*CFI_REL_OFFSET cs, 0*/
21616 /*
21617 * Push current_thread_info()->sysenter_return to the stack.
21618 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21619 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
21620 */
21621 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21622 + pushl_cfi $0
21623 CFI_REL_OFFSET eip, 0
21624
21625 pushl_cfi %eax
21626 SAVE_ALL
21627 + GET_THREAD_INFO(%ebp)
21628 + movl TI_sysenter_return(%ebp),%ebp
21629 + movl %ebp,PT_EIP(%esp)
21630 ENABLE_INTERRUPTS(CLBR_NONE)
21631
21632 /*
21633 * Load the potential sixth argument from user stack.
21634 * Careful about security.
21635 */
21636 + movl PT_OLDESP(%esp),%ebp
21637 +
21638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21639 + mov PT_OLDSS(%esp),%ds
21640 +1: movl %ds:(%ebp),%ebp
21641 + push %ss
21642 + pop %ds
21643 +#else
21644 cmpl $__PAGE_OFFSET-3,%ebp
21645 jae syscall_fault
21646 ASM_STAC
21647 1: movl (%ebp),%ebp
21648 ASM_CLAC
21649 +#endif
21650 +
21651 movl %ebp,PT_EBP(%esp)
21652 _ASM_EXTABLE(1b,syscall_fault)
21653
21654 GET_THREAD_INFO(%ebp)
21655
21656 +#ifdef CONFIG_PAX_RANDKSTACK
21657 + pax_erase_kstack
21658 +#endif
21659 +
21660 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21661 jnz sysenter_audit
21662 sysenter_do_call:
21663 @@ -441,12 +613,24 @@ sysenter_do_call:
21664 testl $_TIF_ALLWORK_MASK, %ecx
21665 jne sysexit_audit
21666 sysenter_exit:
21667 +
21668 +#ifdef CONFIG_PAX_RANDKSTACK
21669 + pushl_cfi %eax
21670 + movl %esp, %eax
21671 + call pax_randomize_kstack
21672 + popl_cfi %eax
21673 +#endif
21674 +
21675 + pax_erase_kstack
21676 +
21677 /* if something modifies registers it must also disable sysexit */
21678 movl PT_EIP(%esp), %edx
21679 movl PT_OLDESP(%esp), %ecx
21680 xorl %ebp,%ebp
21681 TRACE_IRQS_ON
21682 1: mov PT_FS(%esp), %fs
21683 +2: mov PT_DS(%esp), %ds
21684 +3: mov PT_ES(%esp), %es
21685 PTGS_TO_GS
21686 ENABLE_INTERRUPTS_SYSEXIT
21687
21688 @@ -463,6 +647,9 @@ sysenter_audit:
21689 movl %eax,%edx /* 2nd arg: syscall number */
21690 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21691 call __audit_syscall_entry
21692 +
21693 + pax_erase_kstack
21694 +
21695 pushl_cfi %ebx
21696 movl PT_EAX(%esp),%eax /* reload syscall number */
21697 jmp sysenter_do_call
21698 @@ -488,10 +675,16 @@ sysexit_audit:
21699
21700 CFI_ENDPROC
21701 .pushsection .fixup,"ax"
21702 -2: movl $0,PT_FS(%esp)
21703 +4: movl $0,PT_FS(%esp)
21704 + jmp 1b
21705 +5: movl $0,PT_DS(%esp)
21706 + jmp 1b
21707 +6: movl $0,PT_ES(%esp)
21708 jmp 1b
21709 .popsection
21710 - _ASM_EXTABLE(1b,2b)
21711 + _ASM_EXTABLE(1b,4b)
21712 + _ASM_EXTABLE(2b,5b)
21713 + _ASM_EXTABLE(3b,6b)
21714 PTGS_TO_GS_EX
21715 ENDPROC(ia32_sysenter_target)
21716
21717 @@ -506,6 +699,11 @@ ENTRY(system_call)
21718 pushl_cfi %eax # save orig_eax
21719 SAVE_ALL
21720 GET_THREAD_INFO(%ebp)
21721 +
21722 +#ifdef CONFIG_PAX_RANDKSTACK
21723 + pax_erase_kstack
21724 +#endif
21725 +
21726 # system call tracing in operation / emulation
21727 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21728 jnz syscall_trace_entry
21729 @@ -524,6 +722,15 @@ syscall_exit:
21730 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21731 jne syscall_exit_work
21732
21733 +restore_all_pax:
21734 +
21735 +#ifdef CONFIG_PAX_RANDKSTACK
21736 + movl %esp, %eax
21737 + call pax_randomize_kstack
21738 +#endif
21739 +
21740 + pax_erase_kstack
21741 +
21742 restore_all:
21743 TRACE_IRQS_IRET
21744 restore_all_notrace:
21745 @@ -580,14 +787,34 @@ ldt_ss:
21746 * compensating for the offset by changing to the ESPFIX segment with
21747 * a base address that matches for the difference.
21748 */
21749 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21750 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21751 mov %esp, %edx /* load kernel esp */
21752 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21753 mov %dx, %ax /* eax: new kernel esp */
21754 sub %eax, %edx /* offset (low word is 0) */
21755 +#ifdef CONFIG_SMP
21756 + movl PER_CPU_VAR(cpu_number), %ebx
21757 + shll $PAGE_SHIFT_asm, %ebx
21758 + addl $cpu_gdt_table, %ebx
21759 +#else
21760 + movl $cpu_gdt_table, %ebx
21761 +#endif
21762 shr $16, %edx
21763 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21764 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21765 +
21766 +#ifdef CONFIG_PAX_KERNEXEC
21767 + mov %cr0, %esi
21768 + btr $16, %esi
21769 + mov %esi, %cr0
21770 +#endif
21771 +
21772 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21773 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21774 +
21775 +#ifdef CONFIG_PAX_KERNEXEC
21776 + bts $16, %esi
21777 + mov %esi, %cr0
21778 +#endif
21779 +
21780 pushl_cfi $__ESPFIX_SS
21781 pushl_cfi %eax /* new kernel esp */
21782 /* Disable interrupts, but do not irqtrace this section: we
21783 @@ -616,20 +843,18 @@ work_resched:
21784 movl TI_flags(%ebp), %ecx
21785 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21786 # than syscall tracing?
21787 - jz restore_all
21788 + jz restore_all_pax
21789 testb $_TIF_NEED_RESCHED, %cl
21790 jnz work_resched
21791
21792 work_notifysig: # deal with pending signals and
21793 # notify-resume requests
21794 + movl %esp, %eax
21795 #ifdef CONFIG_VM86
21796 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21797 - movl %esp, %eax
21798 jne work_notifysig_v86 # returning to kernel-space or
21799 # vm86-space
21800 1:
21801 -#else
21802 - movl %esp, %eax
21803 #endif
21804 TRACE_IRQS_ON
21805 ENABLE_INTERRUPTS(CLBR_NONE)
21806 @@ -650,7 +875,7 @@ work_notifysig_v86:
21807 movl %eax, %esp
21808 jmp 1b
21809 #endif
21810 -END(work_pending)
21811 +ENDPROC(work_pending)
21812
21813 # perform syscall exit tracing
21814 ALIGN
21815 @@ -658,11 +883,14 @@ syscall_trace_entry:
21816 movl $-ENOSYS,PT_EAX(%esp)
21817 movl %esp, %eax
21818 call syscall_trace_enter
21819 +
21820 + pax_erase_kstack
21821 +
21822 /* What it returned is what we'll actually use. */
21823 cmpl $(NR_syscalls), %eax
21824 jnae syscall_call
21825 jmp syscall_exit
21826 -END(syscall_trace_entry)
21827 +ENDPROC(syscall_trace_entry)
21828
21829 # perform syscall exit tracing
21830 ALIGN
21831 @@ -675,21 +903,25 @@ syscall_exit_work:
21832 movl %esp, %eax
21833 call syscall_trace_leave
21834 jmp resume_userspace
21835 -END(syscall_exit_work)
21836 +ENDPROC(syscall_exit_work)
21837 CFI_ENDPROC
21838
21839 RING0_INT_FRAME # can't unwind into user space anyway
21840 syscall_fault:
21841 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21842 + push %ss
21843 + pop %ds
21844 +#endif
21845 ASM_CLAC
21846 GET_THREAD_INFO(%ebp)
21847 movl $-EFAULT,PT_EAX(%esp)
21848 jmp resume_userspace
21849 -END(syscall_fault)
21850 +ENDPROC(syscall_fault)
21851
21852 syscall_badsys:
21853 movl $-ENOSYS,PT_EAX(%esp)
21854 jmp resume_userspace
21855 -END(syscall_badsys)
21856 +ENDPROC(syscall_badsys)
21857 CFI_ENDPROC
21858 /*
21859 * End of kprobes section
21860 @@ -705,8 +937,15 @@ END(syscall_badsys)
21861 * normal stack and adjusts ESP with the matching offset.
21862 */
21863 /* fixup the stack */
21864 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21865 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21866 +#ifdef CONFIG_SMP
21867 + movl PER_CPU_VAR(cpu_number), %ebx
21868 + shll $PAGE_SHIFT_asm, %ebx
21869 + addl $cpu_gdt_table, %ebx
21870 +#else
21871 + movl $cpu_gdt_table, %ebx
21872 +#endif
21873 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21874 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21875 shl $16, %eax
21876 addl %esp, %eax /* the adjusted stack pointer */
21877 pushl_cfi $__KERNEL_DS
21878 @@ -759,7 +998,7 @@ vector=vector+1
21879 .endr
21880 2: jmp common_interrupt
21881 .endr
21882 -END(irq_entries_start)
21883 +ENDPROC(irq_entries_start)
21884
21885 .previous
21886 END(interrupt)
21887 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
21888 pushl_cfi $do_coprocessor_error
21889 jmp error_code
21890 CFI_ENDPROC
21891 -END(coprocessor_error)
21892 +ENDPROC(coprocessor_error)
21893
21894 ENTRY(simd_coprocessor_error)
21895 RING0_INT_FRAME
21896 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
21897 .section .altinstructions,"a"
21898 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21899 .previous
21900 -.section .altinstr_replacement,"ax"
21901 +.section .altinstr_replacement,"a"
21902 663: pushl $do_simd_coprocessor_error
21903 664:
21904 .previous
21905 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
21906 #endif
21907 jmp error_code
21908 CFI_ENDPROC
21909 -END(simd_coprocessor_error)
21910 +ENDPROC(simd_coprocessor_error)
21911
21912 ENTRY(device_not_available)
21913 RING0_INT_FRAME
21914 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
21915 pushl_cfi $do_device_not_available
21916 jmp error_code
21917 CFI_ENDPROC
21918 -END(device_not_available)
21919 +ENDPROC(device_not_available)
21920
21921 #ifdef CONFIG_PARAVIRT
21922 ENTRY(native_iret)
21923 iret
21924 _ASM_EXTABLE(native_iret, iret_exc)
21925 -END(native_iret)
21926 +ENDPROC(native_iret)
21927
21928 ENTRY(native_irq_enable_sysexit)
21929 sti
21930 sysexit
21931 -END(native_irq_enable_sysexit)
21932 +ENDPROC(native_irq_enable_sysexit)
21933 #endif
21934
21935 ENTRY(overflow)
21936 @@ -872,7 +1111,7 @@ ENTRY(overflow)
21937 pushl_cfi $do_overflow
21938 jmp error_code
21939 CFI_ENDPROC
21940 -END(overflow)
21941 +ENDPROC(overflow)
21942
21943 ENTRY(bounds)
21944 RING0_INT_FRAME
21945 @@ -881,7 +1120,7 @@ ENTRY(bounds)
21946 pushl_cfi $do_bounds
21947 jmp error_code
21948 CFI_ENDPROC
21949 -END(bounds)
21950 +ENDPROC(bounds)
21951
21952 ENTRY(invalid_op)
21953 RING0_INT_FRAME
21954 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
21955 pushl_cfi $do_invalid_op
21956 jmp error_code
21957 CFI_ENDPROC
21958 -END(invalid_op)
21959 +ENDPROC(invalid_op)
21960
21961 ENTRY(coprocessor_segment_overrun)
21962 RING0_INT_FRAME
21963 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
21964 pushl_cfi $do_coprocessor_segment_overrun
21965 jmp error_code
21966 CFI_ENDPROC
21967 -END(coprocessor_segment_overrun)
21968 +ENDPROC(coprocessor_segment_overrun)
21969
21970 ENTRY(invalid_TSS)
21971 RING0_EC_FRAME
21972 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
21973 pushl_cfi $do_invalid_TSS
21974 jmp error_code
21975 CFI_ENDPROC
21976 -END(invalid_TSS)
21977 +ENDPROC(invalid_TSS)
21978
21979 ENTRY(segment_not_present)
21980 RING0_EC_FRAME
21981 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
21982 pushl_cfi $do_segment_not_present
21983 jmp error_code
21984 CFI_ENDPROC
21985 -END(segment_not_present)
21986 +ENDPROC(segment_not_present)
21987
21988 ENTRY(stack_segment)
21989 RING0_EC_FRAME
21990 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
21991 pushl_cfi $do_stack_segment
21992 jmp error_code
21993 CFI_ENDPROC
21994 -END(stack_segment)
21995 +ENDPROC(stack_segment)
21996
21997 ENTRY(alignment_check)
21998 RING0_EC_FRAME
21999 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22000 pushl_cfi $do_alignment_check
22001 jmp error_code
22002 CFI_ENDPROC
22003 -END(alignment_check)
22004 +ENDPROC(alignment_check)
22005
22006 ENTRY(divide_error)
22007 RING0_INT_FRAME
22008 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22009 pushl_cfi $do_divide_error
22010 jmp error_code
22011 CFI_ENDPROC
22012 -END(divide_error)
22013 +ENDPROC(divide_error)
22014
22015 #ifdef CONFIG_X86_MCE
22016 ENTRY(machine_check)
22017 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22018 pushl_cfi machine_check_vector
22019 jmp error_code
22020 CFI_ENDPROC
22021 -END(machine_check)
22022 +ENDPROC(machine_check)
22023 #endif
22024
22025 ENTRY(spurious_interrupt_bug)
22026 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22027 pushl_cfi $do_spurious_interrupt_bug
22028 jmp error_code
22029 CFI_ENDPROC
22030 -END(spurious_interrupt_bug)
22031 +ENDPROC(spurious_interrupt_bug)
22032 /*
22033 * End of kprobes section
22034 */
22035 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22036
22037 ENTRY(mcount)
22038 ret
22039 -END(mcount)
22040 +ENDPROC(mcount)
22041
22042 ENTRY(ftrace_caller)
22043 cmpl $0, function_trace_stop
22044 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22045 .globl ftrace_stub
22046 ftrace_stub:
22047 ret
22048 -END(ftrace_caller)
22049 +ENDPROC(ftrace_caller)
22050
22051 ENTRY(ftrace_regs_caller)
22052 pushf /* push flags before compare (in cs location) */
22053 @@ -1207,7 +1446,7 @@ trace:
22054 popl %ecx
22055 popl %eax
22056 jmp ftrace_stub
22057 -END(mcount)
22058 +ENDPROC(mcount)
22059 #endif /* CONFIG_DYNAMIC_FTRACE */
22060 #endif /* CONFIG_FUNCTION_TRACER */
22061
22062 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22063 popl %ecx
22064 popl %eax
22065 ret
22066 -END(ftrace_graph_caller)
22067 +ENDPROC(ftrace_graph_caller)
22068
22069 .globl return_to_handler
22070 return_to_handler:
22071 @@ -1291,15 +1530,18 @@ error_code:
22072 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22073 REG_TO_PTGS %ecx
22074 SET_KERNEL_GS %ecx
22075 - movl $(__USER_DS), %ecx
22076 + movl $(__KERNEL_DS), %ecx
22077 movl %ecx, %ds
22078 movl %ecx, %es
22079 +
22080 + pax_enter_kernel
22081 +
22082 TRACE_IRQS_OFF
22083 movl %esp,%eax # pt_regs pointer
22084 call *%edi
22085 jmp ret_from_exception
22086 CFI_ENDPROC
22087 -END(page_fault)
22088 +ENDPROC(page_fault)
22089
22090 /*
22091 * Debug traps and NMI can happen at the one SYSENTER instruction
22092 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22093 call do_debug
22094 jmp ret_from_exception
22095 CFI_ENDPROC
22096 -END(debug)
22097 +ENDPROC(debug)
22098
22099 /*
22100 * NMI is doubly nasty. It can happen _while_ we're handling
22101 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22102 xorl %edx,%edx # zero error code
22103 movl %esp,%eax # pt_regs pointer
22104 call do_nmi
22105 +
22106 + pax_exit_kernel
22107 +
22108 jmp restore_all_notrace
22109 CFI_ENDPROC
22110
22111 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22112 FIXUP_ESPFIX_STACK # %eax == %esp
22113 xorl %edx,%edx # zero error code
22114 call do_nmi
22115 +
22116 + pax_exit_kernel
22117 +
22118 RESTORE_REGS
22119 lss 12+4(%esp), %esp # back to espfix stack
22120 CFI_ADJUST_CFA_OFFSET -24
22121 jmp irq_return
22122 CFI_ENDPROC
22123 -END(nmi)
22124 +ENDPROC(nmi)
22125
22126 ENTRY(int3)
22127 RING0_INT_FRAME
22128 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22129 call do_int3
22130 jmp ret_from_exception
22131 CFI_ENDPROC
22132 -END(int3)
22133 +ENDPROC(int3)
22134
22135 ENTRY(general_protection)
22136 RING0_EC_FRAME
22137 pushl_cfi $do_general_protection
22138 jmp error_code
22139 CFI_ENDPROC
22140 -END(general_protection)
22141 +ENDPROC(general_protection)
22142
22143 #ifdef CONFIG_KVM_GUEST
22144 ENTRY(async_page_fault)
22145 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22146 pushl_cfi $do_async_page_fault
22147 jmp error_code
22148 CFI_ENDPROC
22149 -END(async_page_fault)
22150 +ENDPROC(async_page_fault)
22151 #endif
22152
22153 /*
22154 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22155 index 1e96c36..3ff710a 100644
22156 --- a/arch/x86/kernel/entry_64.S
22157 +++ b/arch/x86/kernel/entry_64.S
22158 @@ -59,6 +59,8 @@
22159 #include <asm/context_tracking.h>
22160 #include <asm/smap.h>
22161 #include <linux/err.h>
22162 +#include <asm/pgtable.h>
22163 +#include <asm/alternative-asm.h>
22164
22165 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22166 #include <linux/elf-em.h>
22167 @@ -80,8 +82,9 @@
22168 #ifdef CONFIG_DYNAMIC_FTRACE
22169
22170 ENTRY(function_hook)
22171 + pax_force_retaddr
22172 retq
22173 -END(function_hook)
22174 +ENDPROC(function_hook)
22175
22176 /* skip is set if stack has been adjusted */
22177 .macro ftrace_caller_setup skip=0
22178 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22179 #endif
22180
22181 GLOBAL(ftrace_stub)
22182 + pax_force_retaddr
22183 retq
22184 -END(ftrace_caller)
22185 +ENDPROC(ftrace_caller)
22186
22187 ENTRY(ftrace_regs_caller)
22188 /* Save the current flags before compare (in SS location)*/
22189 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22190 popfq
22191 jmp ftrace_stub
22192
22193 -END(ftrace_regs_caller)
22194 +ENDPROC(ftrace_regs_caller)
22195
22196
22197 #else /* ! CONFIG_DYNAMIC_FTRACE */
22198 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22199 #endif
22200
22201 GLOBAL(ftrace_stub)
22202 + pax_force_retaddr
22203 retq
22204
22205 trace:
22206 @@ -225,12 +230,13 @@ trace:
22207 #endif
22208 subq $MCOUNT_INSN_SIZE, %rdi
22209
22210 + pax_force_fptr ftrace_trace_function
22211 call *ftrace_trace_function
22212
22213 MCOUNT_RESTORE_FRAME
22214
22215 jmp ftrace_stub
22216 -END(function_hook)
22217 +ENDPROC(function_hook)
22218 #endif /* CONFIG_DYNAMIC_FTRACE */
22219 #endif /* CONFIG_FUNCTION_TRACER */
22220
22221 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22222
22223 MCOUNT_RESTORE_FRAME
22224
22225 + pax_force_retaddr
22226 retq
22227 -END(ftrace_graph_caller)
22228 +ENDPROC(ftrace_graph_caller)
22229
22230 GLOBAL(return_to_handler)
22231 subq $24, %rsp
22232 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22233 movq 8(%rsp), %rdx
22234 movq (%rsp), %rax
22235 addq $24, %rsp
22236 + pax_force_fptr %rdi
22237 jmp *%rdi
22238 +ENDPROC(return_to_handler)
22239 #endif
22240
22241
22242 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22243 ENDPROC(native_usergs_sysret64)
22244 #endif /* CONFIG_PARAVIRT */
22245
22246 + .macro ljmpq sel, off
22247 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22248 + .byte 0x48; ljmp *1234f(%rip)
22249 + .pushsection .rodata
22250 + .align 16
22251 + 1234: .quad \off; .word \sel
22252 + .popsection
22253 +#else
22254 + pushq $\sel
22255 + pushq $\off
22256 + lretq
22257 +#endif
22258 + .endm
22259 +
22260 + .macro pax_enter_kernel
22261 + pax_set_fptr_mask
22262 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22263 + call pax_enter_kernel
22264 +#endif
22265 + .endm
22266 +
22267 + .macro pax_exit_kernel
22268 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22269 + call pax_exit_kernel
22270 +#endif
22271 +
22272 + .endm
22273 +
22274 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22275 +ENTRY(pax_enter_kernel)
22276 + pushq %rdi
22277 +
22278 +#ifdef CONFIG_PARAVIRT
22279 + PV_SAVE_REGS(CLBR_RDI)
22280 +#endif
22281 +
22282 +#ifdef CONFIG_PAX_KERNEXEC
22283 + GET_CR0_INTO_RDI
22284 + bts $16,%rdi
22285 + jnc 3f
22286 + mov %cs,%edi
22287 + cmp $__KERNEL_CS,%edi
22288 + jnz 2f
22289 +1:
22290 +#endif
22291 +
22292 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22293 + 661: jmp 111f
22294 + .pushsection .altinstr_replacement, "a"
22295 + 662: ASM_NOP2
22296 + .popsection
22297 + .pushsection .altinstructions, "a"
22298 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22299 + .popsection
22300 + GET_CR3_INTO_RDI
22301 + cmp $0,%dil
22302 + jnz 112f
22303 + mov $__KERNEL_DS,%edi
22304 + mov %edi,%ss
22305 + jmp 111f
22306 +112: cmp $1,%dil
22307 + jz 113f
22308 + ud2
22309 +113: sub $4097,%rdi
22310 + bts $63,%rdi
22311 + SET_RDI_INTO_CR3
22312 + mov $__UDEREF_KERNEL_DS,%edi
22313 + mov %edi,%ss
22314 +111:
22315 +#endif
22316 +
22317 +#ifdef CONFIG_PARAVIRT
22318 + PV_RESTORE_REGS(CLBR_RDI)
22319 +#endif
22320 +
22321 + popq %rdi
22322 + pax_force_retaddr
22323 + retq
22324 +
22325 +#ifdef CONFIG_PAX_KERNEXEC
22326 +2: ljmpq __KERNEL_CS,1b
22327 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22328 +4: SET_RDI_INTO_CR0
22329 + jmp 1b
22330 +#endif
22331 +ENDPROC(pax_enter_kernel)
22332 +
22333 +ENTRY(pax_exit_kernel)
22334 + pushq %rdi
22335 +
22336 +#ifdef CONFIG_PARAVIRT
22337 + PV_SAVE_REGS(CLBR_RDI)
22338 +#endif
22339 +
22340 +#ifdef CONFIG_PAX_KERNEXEC
22341 + mov %cs,%rdi
22342 + cmp $__KERNEXEC_KERNEL_CS,%edi
22343 + jz 2f
22344 + GET_CR0_INTO_RDI
22345 + bts $16,%rdi
22346 + jnc 4f
22347 +1:
22348 +#endif
22349 +
22350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22351 + 661: jmp 111f
22352 + .pushsection .altinstr_replacement, "a"
22353 + 662: ASM_NOP2
22354 + .popsection
22355 + .pushsection .altinstructions, "a"
22356 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22357 + .popsection
22358 + mov %ss,%edi
22359 + cmp $__UDEREF_KERNEL_DS,%edi
22360 + jnz 111f
22361 + GET_CR3_INTO_RDI
22362 + cmp $0,%dil
22363 + jz 112f
22364 + ud2
22365 +112: add $4097,%rdi
22366 + bts $63,%rdi
22367 + SET_RDI_INTO_CR3
22368 + mov $__KERNEL_DS,%edi
22369 + mov %edi,%ss
22370 +111:
22371 +#endif
22372 +
22373 +#ifdef CONFIG_PARAVIRT
22374 + PV_RESTORE_REGS(CLBR_RDI);
22375 +#endif
22376 +
22377 + popq %rdi
22378 + pax_force_retaddr
22379 + retq
22380 +
22381 +#ifdef CONFIG_PAX_KERNEXEC
22382 +2: GET_CR0_INTO_RDI
22383 + btr $16,%rdi
22384 + jnc 4f
22385 + ljmpq __KERNEL_CS,3f
22386 +3: SET_RDI_INTO_CR0
22387 + jmp 1b
22388 +4: ud2
22389 + jmp 4b
22390 +#endif
22391 +ENDPROC(pax_exit_kernel)
22392 +#endif
22393 +
22394 + .macro pax_enter_kernel_user
22395 + pax_set_fptr_mask
22396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22397 + call pax_enter_kernel_user
22398 +#endif
22399 + .endm
22400 +
22401 + .macro pax_exit_kernel_user
22402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22403 + call pax_exit_kernel_user
22404 +#endif
22405 +#ifdef CONFIG_PAX_RANDKSTACK
22406 + pushq %rax
22407 + pushq %r11
22408 + call pax_randomize_kstack
22409 + popq %r11
22410 + popq %rax
22411 +#endif
22412 + .endm
22413 +
22414 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22415 +ENTRY(pax_enter_kernel_user)
22416 + pushq %rdi
22417 + pushq %rbx
22418 +
22419 +#ifdef CONFIG_PARAVIRT
22420 + PV_SAVE_REGS(CLBR_RDI)
22421 +#endif
22422 +
22423 + 661: jmp 111f
22424 + .pushsection .altinstr_replacement, "a"
22425 + 662: ASM_NOP2
22426 + .popsection
22427 + .pushsection .altinstructions, "a"
22428 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22429 + .popsection
22430 + GET_CR3_INTO_RDI
22431 + cmp $1,%dil
22432 + jnz 4f
22433 + sub $4097,%rdi
22434 + bts $63,%rdi
22435 + SET_RDI_INTO_CR3
22436 + jmp 3f
22437 +111:
22438 +
22439 + GET_CR3_INTO_RDI
22440 + mov %rdi,%rbx
22441 + add $__START_KERNEL_map,%rbx
22442 + sub phys_base(%rip),%rbx
22443 +
22444 +#ifdef CONFIG_PARAVIRT
22445 + cmpl $0, pv_info+PARAVIRT_enabled
22446 + jz 1f
22447 + pushq %rdi
22448 + i = 0
22449 + .rept USER_PGD_PTRS
22450 + mov i*8(%rbx),%rsi
22451 + mov $0,%sil
22452 + lea i*8(%rbx),%rdi
22453 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22454 + i = i + 1
22455 + .endr
22456 + popq %rdi
22457 + jmp 2f
22458 +1:
22459 +#endif
22460 +
22461 + i = 0
22462 + .rept USER_PGD_PTRS
22463 + movb $0,i*8(%rbx)
22464 + i = i + 1
22465 + .endr
22466 +
22467 +2: SET_RDI_INTO_CR3
22468 +
22469 +#ifdef CONFIG_PAX_KERNEXEC
22470 + GET_CR0_INTO_RDI
22471 + bts $16,%rdi
22472 + SET_RDI_INTO_CR0
22473 +#endif
22474 +
22475 +3:
22476 +
22477 +#ifdef CONFIG_PARAVIRT
22478 + PV_RESTORE_REGS(CLBR_RDI)
22479 +#endif
22480 +
22481 + popq %rbx
22482 + popq %rdi
22483 + pax_force_retaddr
22484 + retq
22485 +4: ud2
22486 +ENDPROC(pax_enter_kernel_user)
22487 +
22488 +ENTRY(pax_exit_kernel_user)
22489 + pushq %rdi
22490 + pushq %rbx
22491 +
22492 +#ifdef CONFIG_PARAVIRT
22493 + PV_SAVE_REGS(CLBR_RDI)
22494 +#endif
22495 +
22496 + GET_CR3_INTO_RDI
22497 + 661: jmp 1f
22498 + .pushsection .altinstr_replacement, "a"
22499 + 662: ASM_NOP2
22500 + .popsection
22501 + .pushsection .altinstructions, "a"
22502 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22503 + .popsection
22504 + cmp $0,%dil
22505 + jnz 3f
22506 + add $4097,%rdi
22507 + bts $63,%rdi
22508 + SET_RDI_INTO_CR3
22509 + jmp 2f
22510 +1:
22511 +
22512 + mov %rdi,%rbx
22513 +
22514 +#ifdef CONFIG_PAX_KERNEXEC
22515 + GET_CR0_INTO_RDI
22516 + btr $16,%rdi
22517 + jnc 3f
22518 + SET_RDI_INTO_CR0
22519 +#endif
22520 +
22521 + add $__START_KERNEL_map,%rbx
22522 + sub phys_base(%rip),%rbx
22523 +
22524 +#ifdef CONFIG_PARAVIRT
22525 + cmpl $0, pv_info+PARAVIRT_enabled
22526 + jz 1f
22527 + i = 0
22528 + .rept USER_PGD_PTRS
22529 + mov i*8(%rbx),%rsi
22530 + mov $0x67,%sil
22531 + lea i*8(%rbx),%rdi
22532 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22533 + i = i + 1
22534 + .endr
22535 + jmp 2f
22536 +1:
22537 +#endif
22538 +
22539 + i = 0
22540 + .rept USER_PGD_PTRS
22541 + movb $0x67,i*8(%rbx)
22542 + i = i + 1
22543 + .endr
22544 +2:
22545 +
22546 +#ifdef CONFIG_PARAVIRT
22547 + PV_RESTORE_REGS(CLBR_RDI)
22548 +#endif
22549 +
22550 + popq %rbx
22551 + popq %rdi
22552 + pax_force_retaddr
22553 + retq
22554 +3: ud2
22555 +ENDPROC(pax_exit_kernel_user)
22556 +#endif
22557 +
22558 + .macro pax_enter_kernel_nmi
22559 + pax_set_fptr_mask
22560 +
22561 +#ifdef CONFIG_PAX_KERNEXEC
22562 + GET_CR0_INTO_RDI
22563 + bts $16,%rdi
22564 + jc 110f
22565 + SET_RDI_INTO_CR0
22566 + or $2,%ebx
22567 +110:
22568 +#endif
22569 +
22570 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22571 + 661: jmp 111f
22572 + .pushsection .altinstr_replacement, "a"
22573 + 662: ASM_NOP2
22574 + .popsection
22575 + .pushsection .altinstructions, "a"
22576 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22577 + .popsection
22578 + GET_CR3_INTO_RDI
22579 + cmp $0,%dil
22580 + jz 111f
22581 + sub $4097,%rdi
22582 + or $4,%ebx
22583 + bts $63,%rdi
22584 + SET_RDI_INTO_CR3
22585 + mov $__UDEREF_KERNEL_DS,%edi
22586 + mov %edi,%ss
22587 +111:
22588 +#endif
22589 + .endm
22590 +
22591 + .macro pax_exit_kernel_nmi
22592 +#ifdef CONFIG_PAX_KERNEXEC
22593 + btr $1,%ebx
22594 + jnc 110f
22595 + GET_CR0_INTO_RDI
22596 + btr $16,%rdi
22597 + SET_RDI_INTO_CR0
22598 +110:
22599 +#endif
22600 +
22601 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22602 + btr $2,%ebx
22603 + jnc 111f
22604 + GET_CR3_INTO_RDI
22605 + add $4097,%rdi
22606 + bts $63,%rdi
22607 + SET_RDI_INTO_CR3
22608 + mov $__KERNEL_DS,%edi
22609 + mov %edi,%ss
22610 +111:
22611 +#endif
22612 + .endm
22613 +
22614 + .macro pax_erase_kstack
22615 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22616 + call pax_erase_kstack
22617 +#endif
22618 + .endm
22619 +
22620 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22621 +ENTRY(pax_erase_kstack)
22622 + pushq %rdi
22623 + pushq %rcx
22624 + pushq %rax
22625 + pushq %r11
22626 +
22627 + GET_THREAD_INFO(%r11)
22628 + mov TI_lowest_stack(%r11), %rdi
22629 + mov $-0xBEEF, %rax
22630 + std
22631 +
22632 +1: mov %edi, %ecx
22633 + and $THREAD_SIZE_asm - 1, %ecx
22634 + shr $3, %ecx
22635 + repne scasq
22636 + jecxz 2f
22637 +
22638 + cmp $2*8, %ecx
22639 + jc 2f
22640 +
22641 + mov $2*8, %ecx
22642 + repe scasq
22643 + jecxz 2f
22644 + jne 1b
22645 +
22646 +2: cld
22647 + mov %esp, %ecx
22648 + sub %edi, %ecx
22649 +
22650 + cmp $THREAD_SIZE_asm, %rcx
22651 + jb 3f
22652 + ud2
22653 +3:
22654 +
22655 + shr $3, %ecx
22656 + rep stosq
22657 +
22658 + mov TI_task_thread_sp0(%r11), %rdi
22659 + sub $256, %rdi
22660 + mov %rdi, TI_lowest_stack(%r11)
22661 +
22662 + popq %r11
22663 + popq %rax
22664 + popq %rcx
22665 + popq %rdi
22666 + pax_force_retaddr
22667 + ret
22668 +ENDPROC(pax_erase_kstack)
22669 +#endif
22670
22671 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22672 #ifdef CONFIG_TRACE_IRQFLAGS
22673 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
22674 .endm
22675
22676 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
22677 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
22678 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
22679 jnc 1f
22680 TRACE_IRQS_ON_DEBUG
22681 1:
22682 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
22683 movq \tmp,R11+\offset(%rsp)
22684 .endm
22685
22686 - .macro FAKE_STACK_FRAME child_rip
22687 - /* push in order ss, rsp, eflags, cs, rip */
22688 - xorl %eax, %eax
22689 - pushq_cfi $__KERNEL_DS /* ss */
22690 - /*CFI_REL_OFFSET ss,0*/
22691 - pushq_cfi %rax /* rsp */
22692 - CFI_REL_OFFSET rsp,0
22693 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
22694 - /*CFI_REL_OFFSET rflags,0*/
22695 - pushq_cfi $__KERNEL_CS /* cs */
22696 - /*CFI_REL_OFFSET cs,0*/
22697 - pushq_cfi \child_rip /* rip */
22698 - CFI_REL_OFFSET rip,0
22699 - pushq_cfi %rax /* orig rax */
22700 - .endm
22701 -
22702 - .macro UNFAKE_STACK_FRAME
22703 - addq $8*6, %rsp
22704 - CFI_ADJUST_CFA_OFFSET -(6*8)
22705 - .endm
22706 -
22707 /*
22708 * initial frame state for interrupts (and exceptions without error code)
22709 */
22710 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
22711 /* save partial stack frame */
22712 .macro SAVE_ARGS_IRQ
22713 cld
22714 - /* start from rbp in pt_regs and jump over */
22715 - movq_cfi rdi, (RDI-RBP)
22716 - movq_cfi rsi, (RSI-RBP)
22717 - movq_cfi rdx, (RDX-RBP)
22718 - movq_cfi rcx, (RCX-RBP)
22719 - movq_cfi rax, (RAX-RBP)
22720 - movq_cfi r8, (R8-RBP)
22721 - movq_cfi r9, (R9-RBP)
22722 - movq_cfi r10, (R10-RBP)
22723 - movq_cfi r11, (R11-RBP)
22724 + /* start from r15 in pt_regs and jump over */
22725 + movq_cfi rdi, RDI
22726 + movq_cfi rsi, RSI
22727 + movq_cfi rdx, RDX
22728 + movq_cfi rcx, RCX
22729 + movq_cfi rax, RAX
22730 + movq_cfi r8, R8
22731 + movq_cfi r9, R9
22732 + movq_cfi r10, R10
22733 + movq_cfi r11, R11
22734 + movq_cfi r12, R12
22735
22736 /* Save rbp so that we can unwind from get_irq_regs() */
22737 - movq_cfi rbp, 0
22738 + movq_cfi rbp, RBP
22739
22740 /* Save previous stack value */
22741 movq %rsp, %rsi
22742
22743 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
22744 - testl $3, CS-RBP(%rsi)
22745 + movq %rsp,%rdi /* arg1 for handler */
22746 + testb $3, CS(%rsi)
22747 je 1f
22748 SWAPGS
22749 /*
22750 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
22751 0x06 /* DW_OP_deref */, \
22752 0x08 /* DW_OP_const1u */, SS+8-RBP, \
22753 0x22 /* DW_OP_plus */
22754 +
22755 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22756 + testb $3, CS(%rdi)
22757 + jnz 1f
22758 + pax_enter_kernel
22759 + jmp 2f
22760 +1: pax_enter_kernel_user
22761 +2:
22762 +#else
22763 + pax_enter_kernel
22764 +#endif
22765 +
22766 /* We entered an interrupt context - irqs are off: */
22767 TRACE_IRQS_OFF
22768 .endm
22769 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
22770 js 1f /* negative -> in kernel */
22771 SWAPGS
22772 xorl %ebx,%ebx
22773 -1: ret
22774 +1:
22775 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22776 + testb $3, CS+8(%rsp)
22777 + jnz 1f
22778 + pax_enter_kernel
22779 + jmp 2f
22780 +1: pax_enter_kernel_user
22781 +2:
22782 +#else
22783 + pax_enter_kernel
22784 +#endif
22785 + pax_force_retaddr
22786 + ret
22787 CFI_ENDPROC
22788 -END(save_paranoid)
22789 +ENDPROC(save_paranoid)
22790 +
22791 +ENTRY(save_paranoid_nmi)
22792 + XCPT_FRAME 1 RDI+8
22793 + cld
22794 + movq_cfi rdi, RDI+8
22795 + movq_cfi rsi, RSI+8
22796 + movq_cfi rdx, RDX+8
22797 + movq_cfi rcx, RCX+8
22798 + movq_cfi rax, RAX+8
22799 + movq_cfi r8, R8+8
22800 + movq_cfi r9, R9+8
22801 + movq_cfi r10, R10+8
22802 + movq_cfi r11, R11+8
22803 + movq_cfi rbx, RBX+8
22804 + movq_cfi rbp, RBP+8
22805 + movq_cfi r12, R12+8
22806 + movq_cfi r13, R13+8
22807 + movq_cfi r14, R14+8
22808 + movq_cfi r15, R15+8
22809 + movl $1,%ebx
22810 + movl $MSR_GS_BASE,%ecx
22811 + rdmsr
22812 + testl %edx,%edx
22813 + js 1f /* negative -> in kernel */
22814 + SWAPGS
22815 + xorl %ebx,%ebx
22816 +1: pax_enter_kernel_nmi
22817 + pax_force_retaddr
22818 + ret
22819 + CFI_ENDPROC
22820 +ENDPROC(save_paranoid_nmi)
22821 .popsection
22822
22823 /*
22824 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
22825
22826 RESTORE_REST
22827
22828 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22829 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22830 jz 1f
22831
22832 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22833 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
22834 jmp ret_from_sys_call # go to the SYSRET fastpath
22835
22836 1:
22837 - subq $REST_SKIP, %rsp # leave space for volatiles
22838 - CFI_ADJUST_CFA_OFFSET REST_SKIP
22839 movq %rbp, %rdi
22840 call *%rbx
22841 movl $0, RAX(%rsp)
22842 RESTORE_REST
22843 jmp int_ret_from_sys_call
22844 CFI_ENDPROC
22845 -END(ret_from_fork)
22846 +ENDPROC(ret_from_fork)
22847
22848 /*
22849 * System call entry. Up to 6 arguments in registers are supported.
22850 @@ -593,7 +1059,7 @@ END(ret_from_fork)
22851 ENTRY(system_call)
22852 CFI_STARTPROC simple
22853 CFI_SIGNAL_FRAME
22854 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22855 + CFI_DEF_CFA rsp,0
22856 CFI_REGISTER rip,rcx
22857 /*CFI_REGISTER rflags,r11*/
22858 SWAPGS_UNSAFE_STACK
22859 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
22860
22861 movq %rsp,PER_CPU_VAR(old_rsp)
22862 movq PER_CPU_VAR(kernel_stack),%rsp
22863 + SAVE_ARGS 8*6,0
22864 + pax_enter_kernel_user
22865 +
22866 +#ifdef CONFIG_PAX_RANDKSTACK
22867 + pax_erase_kstack
22868 +#endif
22869 +
22870 /*
22871 * No need to follow this irqs off/on section - it's straight
22872 * and short:
22873 */
22874 ENABLE_INTERRUPTS(CLBR_NONE)
22875 - SAVE_ARGS 8,0
22876 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22877 movq %rcx,RIP-ARGOFFSET(%rsp)
22878 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22879 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22880 + GET_THREAD_INFO(%rcx)
22881 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22882 jnz tracesys
22883 system_call_fastpath:
22884 #if __SYSCALL_MASK == ~0
22885 @@ -639,10 +1112,13 @@ sysret_check:
22886 LOCKDEP_SYS_EXIT
22887 DISABLE_INTERRUPTS(CLBR_NONE)
22888 TRACE_IRQS_OFF
22889 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22890 + GET_THREAD_INFO(%rcx)
22891 + movl TI_flags(%rcx),%edx
22892 andl %edi,%edx
22893 jnz sysret_careful
22894 CFI_REMEMBER_STATE
22895 + pax_exit_kernel_user
22896 + pax_erase_kstack
22897 /*
22898 * sysretq will re-enable interrupts:
22899 */
22900 @@ -701,6 +1177,9 @@ auditsys:
22901 movq %rax,%rsi /* 2nd arg: syscall number */
22902 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22903 call __audit_syscall_entry
22904 +
22905 + pax_erase_kstack
22906 +
22907 LOAD_ARGS 0 /* reload call-clobbered registers */
22908 jmp system_call_fastpath
22909
22910 @@ -722,7 +1201,7 @@ sysret_audit:
22911 /* Do syscall tracing */
22912 tracesys:
22913 #ifdef CONFIG_AUDITSYSCALL
22914 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22915 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22916 jz auditsys
22917 #endif
22918 SAVE_REST
22919 @@ -730,12 +1209,15 @@ tracesys:
22920 FIXUP_TOP_OF_STACK %rdi
22921 movq %rsp,%rdi
22922 call syscall_trace_enter
22923 +
22924 + pax_erase_kstack
22925 +
22926 /*
22927 * Reload arg registers from stack in case ptrace changed them.
22928 * We don't reload %rax because syscall_trace_enter() returned
22929 * the value it wants us to use in the table lookup.
22930 */
22931 - LOAD_ARGS ARGOFFSET, 1
22932 + LOAD_ARGS 1
22933 RESTORE_REST
22934 #if __SYSCALL_MASK == ~0
22935 cmpq $__NR_syscall_max,%rax
22936 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
22937 andl %edi,%edx
22938 jnz int_careful
22939 andl $~TS_COMPAT,TI_status(%rcx)
22940 - jmp retint_swapgs
22941 + pax_exit_kernel_user
22942 + pax_erase_kstack
22943 + jmp retint_swapgs_pax
22944
22945 /* Either reschedule or signal or syscall exit tracking needed. */
22946 /* First do a reschedule test. */
22947 @@ -811,7 +1295,7 @@ int_restore_rest:
22948 TRACE_IRQS_OFF
22949 jmp int_with_check
22950 CFI_ENDPROC
22951 -END(system_call)
22952 +ENDPROC(system_call)
22953
22954 .macro FORK_LIKE func
22955 ENTRY(stub_\func)
22956 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
22957 DEFAULT_FRAME 0 8 /* offset 8: return address */
22958 call sys_\func
22959 RESTORE_TOP_OF_STACK %r11, 8
22960 - ret $REST_SKIP /* pop extended registers */
22961 + pax_force_retaddr
22962 + ret
22963 CFI_ENDPROC
22964 -END(stub_\func)
22965 +ENDPROC(stub_\func)
22966 .endm
22967
22968 .macro FIXED_FRAME label,func
22969 @@ -836,9 +1321,10 @@ ENTRY(\label)
22970 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22971 call \func
22972 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22973 + pax_force_retaddr
22974 ret
22975 CFI_ENDPROC
22976 -END(\label)
22977 +ENDPROC(\label)
22978 .endm
22979
22980 FORK_LIKE clone
22981 @@ -846,19 +1332,6 @@ END(\label)
22982 FORK_LIKE vfork
22983 FIXED_FRAME stub_iopl, sys_iopl
22984
22985 -ENTRY(ptregscall_common)
22986 - DEFAULT_FRAME 1 8 /* offset 8: return address */
22987 - RESTORE_TOP_OF_STACK %r11, 8
22988 - movq_cfi_restore R15+8, r15
22989 - movq_cfi_restore R14+8, r14
22990 - movq_cfi_restore R13+8, r13
22991 - movq_cfi_restore R12+8, r12
22992 - movq_cfi_restore RBP+8, rbp
22993 - movq_cfi_restore RBX+8, rbx
22994 - ret $REST_SKIP /* pop extended registers */
22995 - CFI_ENDPROC
22996 -END(ptregscall_common)
22997 -
22998 ENTRY(stub_execve)
22999 CFI_STARTPROC
23000 addq $8, %rsp
23001 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23002 RESTORE_REST
23003 jmp int_ret_from_sys_call
23004 CFI_ENDPROC
23005 -END(stub_execve)
23006 +ENDPROC(stub_execve)
23007
23008 /*
23009 * sigreturn is special because it needs to restore all registers on return.
23010 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23011 RESTORE_REST
23012 jmp int_ret_from_sys_call
23013 CFI_ENDPROC
23014 -END(stub_rt_sigreturn)
23015 +ENDPROC(stub_rt_sigreturn)
23016
23017 #ifdef CONFIG_X86_X32_ABI
23018 ENTRY(stub_x32_rt_sigreturn)
23019 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23020 RESTORE_REST
23021 jmp int_ret_from_sys_call
23022 CFI_ENDPROC
23023 -END(stub_x32_rt_sigreturn)
23024 +ENDPROC(stub_x32_rt_sigreturn)
23025
23026 ENTRY(stub_x32_execve)
23027 CFI_STARTPROC
23028 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23029 RESTORE_REST
23030 jmp int_ret_from_sys_call
23031 CFI_ENDPROC
23032 -END(stub_x32_execve)
23033 +ENDPROC(stub_x32_execve)
23034
23035 #endif
23036
23037 @@ -952,7 +1425,7 @@ vector=vector+1
23038 2: jmp common_interrupt
23039 .endr
23040 CFI_ENDPROC
23041 -END(irq_entries_start)
23042 +ENDPROC(irq_entries_start)
23043
23044 .previous
23045 END(interrupt)
23046 @@ -969,8 +1442,8 @@ END(interrupt)
23047 /* 0(%rsp): ~(interrupt number) */
23048 .macro interrupt func
23049 /* reserve pt_regs for scratch regs and rbp */
23050 - subq $ORIG_RAX-RBP, %rsp
23051 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23052 + subq $ORIG_RAX, %rsp
23053 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23054 SAVE_ARGS_IRQ
23055 call \func
23056 .endm
23057 @@ -997,14 +1470,14 @@ ret_from_intr:
23058
23059 /* Restore saved previous stack */
23060 popq %rsi
23061 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23062 - leaq ARGOFFSET-RBP(%rsi), %rsp
23063 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23064 + movq %rsi, %rsp
23065 CFI_DEF_CFA_REGISTER rsp
23066 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23067 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23068
23069 exit_intr:
23070 GET_THREAD_INFO(%rcx)
23071 - testl $3,CS-ARGOFFSET(%rsp)
23072 + testb $3,CS-ARGOFFSET(%rsp)
23073 je retint_kernel
23074
23075 /* Interrupt came from user space */
23076 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23077 * The iretq could re-enable interrupts:
23078 */
23079 DISABLE_INTERRUPTS(CLBR_ANY)
23080 + pax_exit_kernel_user
23081 +retint_swapgs_pax:
23082 TRACE_IRQS_IRETQ
23083 SWAPGS
23084 jmp restore_args
23085
23086 retint_restore_args: /* return to kernel space */
23087 DISABLE_INTERRUPTS(CLBR_ANY)
23088 + pax_exit_kernel
23089 + pax_force_retaddr (RIP-ARGOFFSET)
23090 /*
23091 * The iretq could re-enable interrupts:
23092 */
23093 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23094 #endif
23095
23096 CFI_ENDPROC
23097 -END(common_interrupt)
23098 +ENDPROC(common_interrupt)
23099 /*
23100 * End of kprobes section
23101 */
23102 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23103 interrupt \do_sym
23104 jmp ret_from_intr
23105 CFI_ENDPROC
23106 -END(\sym)
23107 +ENDPROC(\sym)
23108 .endm
23109
23110 #ifdef CONFIG_TRACING
23111 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23112 call \do_sym
23113 jmp error_exit /* %ebx: no swapgs flag */
23114 CFI_ENDPROC
23115 -END(\sym)
23116 +ENDPROC(\sym)
23117 .endm
23118
23119 .macro paranoidzeroentry sym do_sym
23120 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23121 call \do_sym
23122 jmp paranoid_exit /* %ebx: no swapgs flag */
23123 CFI_ENDPROC
23124 -END(\sym)
23125 +ENDPROC(\sym)
23126 .endm
23127
23128 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23129 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23130 .macro paranoidzeroentry_ist sym do_sym ist
23131 ENTRY(\sym)
23132 INTR_FRAME
23133 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23134 TRACE_IRQS_OFF_DEBUG
23135 movq %rsp,%rdi /* pt_regs pointer */
23136 xorl %esi,%esi /* no error code */
23137 +#ifdef CONFIG_SMP
23138 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23139 + lea init_tss(%r13), %r13
23140 +#else
23141 + lea init_tss(%rip), %r13
23142 +#endif
23143 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23144 call \do_sym
23145 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23146 jmp paranoid_exit /* %ebx: no swapgs flag */
23147 CFI_ENDPROC
23148 -END(\sym)
23149 +ENDPROC(\sym)
23150 .endm
23151
23152 .macro errorentry sym do_sym
23153 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23154 call \do_sym
23155 jmp error_exit /* %ebx: no swapgs flag */
23156 CFI_ENDPROC
23157 -END(\sym)
23158 +ENDPROC(\sym)
23159 .endm
23160
23161 #ifdef CONFIG_TRACING
23162 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23163 call \do_sym
23164 jmp paranoid_exit /* %ebx: no swapgs flag */
23165 CFI_ENDPROC
23166 -END(\sym)
23167 +ENDPROC(\sym)
23168 .endm
23169
23170 zeroentry divide_error do_divide_error
23171 @@ -1336,9 +1819,10 @@ gs_change:
23172 2: mfence /* workaround */
23173 SWAPGS
23174 popfq_cfi
23175 + pax_force_retaddr
23176 ret
23177 CFI_ENDPROC
23178 -END(native_load_gs_index)
23179 +ENDPROC(native_load_gs_index)
23180
23181 _ASM_EXTABLE(gs_change,bad_gs)
23182 .section .fixup,"ax"
23183 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23184 CFI_DEF_CFA_REGISTER rsp
23185 CFI_ADJUST_CFA_OFFSET -8
23186 decl PER_CPU_VAR(irq_count)
23187 + pax_force_retaddr
23188 ret
23189 CFI_ENDPROC
23190 -END(do_softirq_own_stack)
23191 +ENDPROC(do_softirq_own_stack)
23192
23193 #ifdef CONFIG_XEN
23194 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23195 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23196 decl PER_CPU_VAR(irq_count)
23197 jmp error_exit
23198 CFI_ENDPROC
23199 -END(xen_do_hypervisor_callback)
23200 +ENDPROC(xen_do_hypervisor_callback)
23201
23202 /*
23203 * Hypervisor uses this for application faults while it executes.
23204 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23205 SAVE_ALL
23206 jmp error_exit
23207 CFI_ENDPROC
23208 -END(xen_failsafe_callback)
23209 +ENDPROC(xen_failsafe_callback)
23210
23211 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23212 xen_hvm_callback_vector xen_evtchn_do_upcall
23213 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23214 DEFAULT_FRAME
23215 DISABLE_INTERRUPTS(CLBR_NONE)
23216 TRACE_IRQS_OFF_DEBUG
23217 - testl %ebx,%ebx /* swapgs needed? */
23218 + testl $1,%ebx /* swapgs needed? */
23219 jnz paranoid_restore
23220 - testl $3,CS(%rsp)
23221 + testb $3,CS(%rsp)
23222 jnz paranoid_userspace
23223 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23224 + pax_exit_kernel
23225 + TRACE_IRQS_IRETQ 0
23226 + SWAPGS_UNSAFE_STACK
23227 + RESTORE_ALL 8
23228 + pax_force_retaddr_bts
23229 + jmp irq_return
23230 +#endif
23231 paranoid_swapgs:
23232 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23233 + pax_exit_kernel_user
23234 +#else
23235 + pax_exit_kernel
23236 +#endif
23237 TRACE_IRQS_IRETQ 0
23238 SWAPGS_UNSAFE_STACK
23239 RESTORE_ALL 8
23240 jmp irq_return
23241 paranoid_restore:
23242 + pax_exit_kernel
23243 TRACE_IRQS_IRETQ_DEBUG 0
23244 RESTORE_ALL 8
23245 + pax_force_retaddr_bts
23246 jmp irq_return
23247 paranoid_userspace:
23248 GET_THREAD_INFO(%rcx)
23249 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23250 TRACE_IRQS_OFF
23251 jmp paranoid_userspace
23252 CFI_ENDPROC
23253 -END(paranoid_exit)
23254 +ENDPROC(paranoid_exit)
23255
23256 /*
23257 * Exception entry point. This expects an error code/orig_rax on the stack.
23258 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23259 movq_cfi r14, R14+8
23260 movq_cfi r15, R15+8
23261 xorl %ebx,%ebx
23262 - testl $3,CS+8(%rsp)
23263 + testb $3,CS+8(%rsp)
23264 je error_kernelspace
23265 error_swapgs:
23266 SWAPGS
23267 error_sti:
23268 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23269 + testb $3, CS+8(%rsp)
23270 + jnz 1f
23271 + pax_enter_kernel
23272 + jmp 2f
23273 +1: pax_enter_kernel_user
23274 +2:
23275 +#else
23276 + pax_enter_kernel
23277 +#endif
23278 TRACE_IRQS_OFF
23279 + pax_force_retaddr
23280 ret
23281
23282 /*
23283 @@ -1616,7 +2127,7 @@ bstep_iret:
23284 movq %rcx,RIP+8(%rsp)
23285 jmp error_swapgs
23286 CFI_ENDPROC
23287 -END(error_entry)
23288 +ENDPROC(error_entry)
23289
23290
23291 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23292 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23293 DISABLE_INTERRUPTS(CLBR_NONE)
23294 TRACE_IRQS_OFF
23295 GET_THREAD_INFO(%rcx)
23296 - testl %eax,%eax
23297 + testl $1,%eax
23298 jne retint_kernel
23299 LOCKDEP_SYS_EXIT_IRQ
23300 movl TI_flags(%rcx),%edx
23301 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23302 jnz retint_careful
23303 jmp retint_swapgs
23304 CFI_ENDPROC
23305 -END(error_exit)
23306 +ENDPROC(error_exit)
23307
23308 /*
23309 * Test if a given stack is an NMI stack or not.
23310 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23311 * If %cs was not the kernel segment, then the NMI triggered in user
23312 * space, which means it is definitely not nested.
23313 */
23314 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23315 + je 1f
23316 cmpl $__KERNEL_CS, 16(%rsp)
23317 jne first_nmi
23318 -
23319 +1:
23320 /*
23321 * Check the special variable on the stack to see if NMIs are
23322 * executing.
23323 @@ -1730,8 +2243,7 @@ nested_nmi:
23324
23325 1:
23326 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23327 - leaq -1*8(%rsp), %rdx
23328 - movq %rdx, %rsp
23329 + subq $8, %rsp
23330 CFI_ADJUST_CFA_OFFSET 1*8
23331 leaq -10*8(%rsp), %rdx
23332 pushq_cfi $__KERNEL_DS
23333 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23334 CFI_RESTORE rdx
23335
23336 /* No need to check faults here */
23337 +# pax_force_retaddr_bts
23338 INTERRUPT_RETURN
23339
23340 CFI_RESTORE_STATE
23341 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23342 subq $ORIG_RAX-R15, %rsp
23343 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23344 /*
23345 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23346 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23347 * as we should not be calling schedule in NMI context.
23348 * Even with normal interrupts enabled. An NMI should not be
23349 * setting NEED_RESCHED or anything that normal interrupts and
23350 * exceptions might do.
23351 */
23352 - call save_paranoid
23353 + call save_paranoid_nmi
23354 DEFAULT_FRAME 0
23355
23356 /*
23357 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23358 * NMI itself takes a page fault, the page fault that was preempted
23359 * will read the information from the NMI page fault and not the
23360 * origin fault. Save it off and restore it if it changes.
23361 - * Use the r12 callee-saved register.
23362 + * Use the r13 callee-saved register.
23363 */
23364 - movq %cr2, %r12
23365 + movq %cr2, %r13
23366
23367 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23368 movq %rsp,%rdi
23369 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23370
23371 /* Did the NMI take a page fault? Restore cr2 if it did */
23372 movq %cr2, %rcx
23373 - cmpq %rcx, %r12
23374 + cmpq %rcx, %r13
23375 je 1f
23376 - movq %r12, %cr2
23377 + movq %r13, %cr2
23378 1:
23379
23380 - testl %ebx,%ebx /* swapgs needed? */
23381 + testl $1,%ebx /* swapgs needed? */
23382 jnz nmi_restore
23383 nmi_swapgs:
23384 SWAPGS_UNSAFE_STACK
23385 nmi_restore:
23386 + pax_exit_kernel_nmi
23387 /* Pop the extra iret frame at once */
23388 RESTORE_ALL 6*8
23389 + testb $3, 8(%rsp)
23390 + jnz 1f
23391 + pax_force_retaddr_bts
23392 +1:
23393
23394 /* Clear the NMI executing stack variable */
23395 movq $0, 5*8(%rsp)
23396 jmp irq_return
23397 CFI_ENDPROC
23398 -END(nmi)
23399 +ENDPROC(nmi)
23400
23401 ENTRY(ignore_sysret)
23402 CFI_STARTPROC
23403 mov $-ENOSYS,%eax
23404 sysret
23405 CFI_ENDPROC
23406 -END(ignore_sysret)
23407 +ENDPROC(ignore_sysret)
23408
23409 /*
23410 * End of kprobes section
23411 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23412 index d4bdd25..912664c 100644
23413 --- a/arch/x86/kernel/ftrace.c
23414 +++ b/arch/x86/kernel/ftrace.c
23415 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23416 {
23417 unsigned char replaced[MCOUNT_INSN_SIZE];
23418
23419 + ip = ktla_ktva(ip);
23420 +
23421 /*
23422 * Note: Due to modules and __init, code can
23423 * disappear and change, we need to protect against faulting
23424 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23425 unsigned char old[MCOUNT_INSN_SIZE], *new;
23426 int ret;
23427
23428 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
23429 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
23430 new = ftrace_call_replace(ip, (unsigned long)func);
23431
23432 /* See comment above by declaration of modifying_ftrace_code */
23433 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23434 /* Also update the regs callback function */
23435 if (!ret) {
23436 ip = (unsigned long)(&ftrace_regs_call);
23437 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
23438 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
23439 new = ftrace_call_replace(ip, (unsigned long)func);
23440 ret = ftrace_modify_code(ip, old, new);
23441 }
23442 @@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23443 * kernel identity mapping to modify code.
23444 */
23445 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23446 - ip = (unsigned long)__va(__pa_symbol(ip));
23447 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23448
23449 return probe_kernel_write((void *)ip, val, size);
23450 }
23451 @@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
23452 unsigned char replaced[MCOUNT_INSN_SIZE];
23453 unsigned char brk = BREAKPOINT_INSTRUCTION;
23454
23455 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23456 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23457 return -EFAULT;
23458
23459 /* Make sure it is what we expect it to be */
23460 @@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23461 return ret;
23462
23463 fail_update:
23464 - probe_kernel_write((void *)ip, &old_code[0], 1);
23465 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23466 goto out;
23467 }
23468
23469 @@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
23470 {
23471 unsigned char code[MCOUNT_INSN_SIZE];
23472
23473 + ip = ktla_ktva(ip);
23474 +
23475 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
23476 return -EFAULT;
23477
23478 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23479 index 85126cc..1bbce17 100644
23480 --- a/arch/x86/kernel/head64.c
23481 +++ b/arch/x86/kernel/head64.c
23482 @@ -67,12 +67,12 @@ again:
23483 pgd = *pgd_p;
23484
23485 /*
23486 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23487 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23488 + * The use of __early_va rather than __va here is critical:
23489 + * __va would point us back into the dynamic
23490 * range and we might end up looping forever...
23491 */
23492 if (pgd)
23493 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23494 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23495 else {
23496 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23497 reset_early_page_tables();
23498 @@ -82,13 +82,13 @@ again:
23499 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23500 for (i = 0; i < PTRS_PER_PUD; i++)
23501 pud_p[i] = 0;
23502 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23503 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23504 }
23505 pud_p += pud_index(address);
23506 pud = *pud_p;
23507
23508 if (pud)
23509 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23510 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23511 else {
23512 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23513 reset_early_page_tables();
23514 @@ -98,7 +98,7 @@ again:
23515 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23516 for (i = 0; i < PTRS_PER_PMD; i++)
23517 pmd_p[i] = 0;
23518 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23519 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23520 }
23521 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23522 pmd_p[pmd_index(address)] = pmd;
23523 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23524 if (console_loglevel == 10)
23525 early_printk("Kernel alive\n");
23526
23527 - clear_page(init_level4_pgt);
23528 /* set init_level4_pgt kernel high mapping*/
23529 init_level4_pgt[511] = early_level4_pgt[511];
23530
23531 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23532 index 81ba276..30c5411 100644
23533 --- a/arch/x86/kernel/head_32.S
23534 +++ b/arch/x86/kernel/head_32.S
23535 @@ -26,6 +26,12 @@
23536 /* Physical address */
23537 #define pa(X) ((X) - __PAGE_OFFSET)
23538
23539 +#ifdef CONFIG_PAX_KERNEXEC
23540 +#define ta(X) (X)
23541 +#else
23542 +#define ta(X) ((X) - __PAGE_OFFSET)
23543 +#endif
23544 +
23545 /*
23546 * References to members of the new_cpu_data structure.
23547 */
23548 @@ -55,11 +61,7 @@
23549 * and small than max_low_pfn, otherwise will waste some page table entries
23550 */
23551
23552 -#if PTRS_PER_PMD > 1
23553 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
23554 -#else
23555 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
23556 -#endif
23557 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
23558
23559 /* Number of possible pages in the lowmem region */
23560 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
23561 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
23562 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23563
23564 /*
23565 + * Real beginning of normal "text" segment
23566 + */
23567 +ENTRY(stext)
23568 +ENTRY(_stext)
23569 +
23570 +/*
23571 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
23572 * %esi points to the real-mode code as a 32-bit pointer.
23573 * CS and DS must be 4 GB flat segments, but we don't depend on
23574 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23575 * can.
23576 */
23577 __HEAD
23578 +
23579 +#ifdef CONFIG_PAX_KERNEXEC
23580 + jmp startup_32
23581 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
23582 +.fill PAGE_SIZE-5,1,0xcc
23583 +#endif
23584 +
23585 ENTRY(startup_32)
23586 movl pa(stack_start),%ecx
23587
23588 @@ -106,6 +121,59 @@ ENTRY(startup_32)
23589 2:
23590 leal -__PAGE_OFFSET(%ecx),%esp
23591
23592 +#ifdef CONFIG_SMP
23593 + movl $pa(cpu_gdt_table),%edi
23594 + movl $__per_cpu_load,%eax
23595 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
23596 + rorl $16,%eax
23597 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
23598 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
23599 + movl $__per_cpu_end - 1,%eax
23600 + subl $__per_cpu_start,%eax
23601 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
23602 +#endif
23603 +
23604 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23605 + movl $NR_CPUS,%ecx
23606 + movl $pa(cpu_gdt_table),%edi
23607 +1:
23608 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
23609 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
23610 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
23611 + addl $PAGE_SIZE_asm,%edi
23612 + loop 1b
23613 +#endif
23614 +
23615 +#ifdef CONFIG_PAX_KERNEXEC
23616 + movl $pa(boot_gdt),%edi
23617 + movl $__LOAD_PHYSICAL_ADDR,%eax
23618 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
23619 + rorl $16,%eax
23620 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
23621 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
23622 + rorl $16,%eax
23623 +
23624 + ljmp $(__BOOT_CS),$1f
23625 +1:
23626 +
23627 + movl $NR_CPUS,%ecx
23628 + movl $pa(cpu_gdt_table),%edi
23629 + addl $__PAGE_OFFSET,%eax
23630 +1:
23631 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
23632 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
23633 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23634 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23635 + rorl $16,%eax
23636 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23637 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23638 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23639 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23640 + rorl $16,%eax
23641 + addl $PAGE_SIZE_asm,%edi
23642 + loop 1b
23643 +#endif
23644 +
23645 /*
23646 * Clear BSS first so that there are no surprises...
23647 */
23648 @@ -201,8 +269,11 @@ ENTRY(startup_32)
23649 movl %eax, pa(max_pfn_mapped)
23650
23651 /* Do early initialization of the fixmap area */
23652 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23653 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23654 +#ifdef CONFIG_COMPAT_VDSO
23655 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23656 +#else
23657 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23658 +#endif
23659 #else /* Not PAE */
23660
23661 page_pde_offset = (__PAGE_OFFSET >> 20);
23662 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23663 movl %eax, pa(max_pfn_mapped)
23664
23665 /* Do early initialization of the fixmap area */
23666 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23667 - movl %eax,pa(initial_page_table+0xffc)
23668 +#ifdef CONFIG_COMPAT_VDSO
23669 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23670 +#else
23671 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23672 +#endif
23673 #endif
23674
23675 #ifdef CONFIG_PARAVIRT
23676 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23677 cmpl $num_subarch_entries, %eax
23678 jae bad_subarch
23679
23680 - movl pa(subarch_entries)(,%eax,4), %eax
23681 - subl $__PAGE_OFFSET, %eax
23682 - jmp *%eax
23683 + jmp *pa(subarch_entries)(,%eax,4)
23684
23685 bad_subarch:
23686 WEAK(lguest_entry)
23687 @@ -261,10 +333,10 @@ WEAK(xen_entry)
23688 __INITDATA
23689
23690 subarch_entries:
23691 - .long default_entry /* normal x86/PC */
23692 - .long lguest_entry /* lguest hypervisor */
23693 - .long xen_entry /* Xen hypervisor */
23694 - .long default_entry /* Moorestown MID */
23695 + .long ta(default_entry) /* normal x86/PC */
23696 + .long ta(lguest_entry) /* lguest hypervisor */
23697 + .long ta(xen_entry) /* Xen hypervisor */
23698 + .long ta(default_entry) /* Moorestown MID */
23699 num_subarch_entries = (. - subarch_entries) / 4
23700 .previous
23701 #else
23702 @@ -354,6 +426,7 @@ default_entry:
23703 movl pa(mmu_cr4_features),%eax
23704 movl %eax,%cr4
23705
23706 +#ifdef CONFIG_X86_PAE
23707 testb $X86_CR4_PAE, %al # check if PAE is enabled
23708 jz enable_paging
23709
23710 @@ -382,6 +455,9 @@ default_entry:
23711 /* Make changes effective */
23712 wrmsr
23713
23714 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23715 +#endif
23716 +
23717 enable_paging:
23718
23719 /*
23720 @@ -449,14 +525,20 @@ is486:
23721 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23722 movl %eax,%ss # after changing gdt.
23723
23724 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
23725 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23726 movl %eax,%ds
23727 movl %eax,%es
23728
23729 movl $(__KERNEL_PERCPU), %eax
23730 movl %eax,%fs # set this cpu's percpu
23731
23732 +#ifdef CONFIG_CC_STACKPROTECTOR
23733 movl $(__KERNEL_STACK_CANARY),%eax
23734 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23735 + movl $(__USER_DS),%eax
23736 +#else
23737 + xorl %eax,%eax
23738 +#endif
23739 movl %eax,%gs
23740
23741 xorl %eax,%eax # Clear LDT
23742 @@ -512,8 +594,11 @@ setup_once:
23743 * relocation. Manually set base address in stack canary
23744 * segment descriptor.
23745 */
23746 - movl $gdt_page,%eax
23747 + movl $cpu_gdt_table,%eax
23748 movl $stack_canary,%ecx
23749 +#ifdef CONFIG_SMP
23750 + addl $__per_cpu_load,%ecx
23751 +#endif
23752 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23753 shrl $16, %ecx
23754 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23755 @@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
23756 /* This is global to keep gas from relaxing the jumps */
23757 ENTRY(early_idt_handler)
23758 cld
23759 - cmpl $2,%ss:early_recursion_flag
23760 + cmpl $1,%ss:early_recursion_flag
23761 je hlt_loop
23762 incl %ss:early_recursion_flag
23763
23764 @@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
23765 pushl (20+6*4)(%esp) /* trapno */
23766 pushl $fault_msg
23767 call printk
23768 -#endif
23769 call dump_stack
23770 +#endif
23771 hlt_loop:
23772 hlt
23773 jmp hlt_loop
23774 @@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
23775 /* This is the default interrupt "handler" :-) */
23776 ALIGN
23777 ignore_int:
23778 - cld
23779 #ifdef CONFIG_PRINTK
23780 + cmpl $2,%ss:early_recursion_flag
23781 + je hlt_loop
23782 + incl %ss:early_recursion_flag
23783 + cld
23784 pushl %eax
23785 pushl %ecx
23786 pushl %edx
23787 @@ -612,9 +700,6 @@ ignore_int:
23788 movl $(__KERNEL_DS),%eax
23789 movl %eax,%ds
23790 movl %eax,%es
23791 - cmpl $2,early_recursion_flag
23792 - je hlt_loop
23793 - incl early_recursion_flag
23794 pushl 16(%esp)
23795 pushl 24(%esp)
23796 pushl 32(%esp)
23797 @@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
23798 /*
23799 * BSS section
23800 */
23801 -__PAGE_ALIGNED_BSS
23802 - .align PAGE_SIZE
23803 #ifdef CONFIG_X86_PAE
23804 +.section .initial_pg_pmd,"a",@progbits
23805 initial_pg_pmd:
23806 .fill 1024*KPMDS,4,0
23807 #else
23808 +.section .initial_page_table,"a",@progbits
23809 ENTRY(initial_page_table)
23810 .fill 1024,4,0
23811 #endif
23812 +.section .initial_pg_fixmap,"a",@progbits
23813 initial_pg_fixmap:
23814 .fill 1024,4,0
23815 +.section .empty_zero_page,"a",@progbits
23816 ENTRY(empty_zero_page)
23817 .fill 4096,1,0
23818 +.section .swapper_pg_dir,"a",@progbits
23819 ENTRY(swapper_pg_dir)
23820 +#ifdef CONFIG_X86_PAE
23821 + .fill 4,8,0
23822 +#else
23823 .fill 1024,4,0
23824 +#endif
23825
23826 /*
23827 * This starts the data section.
23828 */
23829 #ifdef CONFIG_X86_PAE
23830 -__PAGE_ALIGNED_DATA
23831 - /* Page-aligned for the benefit of paravirt? */
23832 - .align PAGE_SIZE
23833 +.section .initial_page_table,"a",@progbits
23834 ENTRY(initial_page_table)
23835 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23836 # if KPMDS == 3
23837 @@ -689,12 +779,20 @@ ENTRY(initial_page_table)
23838 # error "Kernel PMDs should be 1, 2 or 3"
23839 # endif
23840 .align PAGE_SIZE /* needs to be page-sized too */
23841 +
23842 +#ifdef CONFIG_PAX_PER_CPU_PGD
23843 +ENTRY(cpu_pgd)
23844 + .rept 2*NR_CPUS
23845 + .fill 4,8,0
23846 + .endr
23847 +#endif
23848 +
23849 #endif
23850
23851 .data
23852 .balign 4
23853 ENTRY(stack_start)
23854 - .long init_thread_union+THREAD_SIZE
23855 + .long init_thread_union+THREAD_SIZE-8
23856
23857 __INITRODATA
23858 int_msg:
23859 @@ -722,7 +820,7 @@ fault_msg:
23860 * segment size, and 32-bit linear address value:
23861 */
23862
23863 - .data
23864 +.section .rodata,"a",@progbits
23865 .globl boot_gdt_descr
23866 .globl idt_descr
23867
23868 @@ -731,7 +829,7 @@ fault_msg:
23869 .word 0 # 32 bit align gdt_desc.address
23870 boot_gdt_descr:
23871 .word __BOOT_DS+7
23872 - .long boot_gdt - __PAGE_OFFSET
23873 + .long pa(boot_gdt)
23874
23875 .word 0 # 32-bit align idt_desc.address
23876 idt_descr:
23877 @@ -742,7 +840,7 @@ idt_descr:
23878 .word 0 # 32 bit align gdt_desc.address
23879 ENTRY(early_gdt_descr)
23880 .word GDT_ENTRIES*8-1
23881 - .long gdt_page /* Overwritten for secondary CPUs */
23882 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
23883
23884 /*
23885 * The boot_gdt must mirror the equivalent in setup.S and is
23886 @@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23887 .align L1_CACHE_BYTES
23888 ENTRY(boot_gdt)
23889 .fill GDT_ENTRY_BOOT_CS,8,0
23890 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23891 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23892 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23893 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23894 +
23895 + .align PAGE_SIZE_asm
23896 +ENTRY(cpu_gdt_table)
23897 + .rept NR_CPUS
23898 + .quad 0x0000000000000000 /* NULL descriptor */
23899 + .quad 0x0000000000000000 /* 0x0b reserved */
23900 + .quad 0x0000000000000000 /* 0x13 reserved */
23901 + .quad 0x0000000000000000 /* 0x1b reserved */
23902 +
23903 +#ifdef CONFIG_PAX_KERNEXEC
23904 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23905 +#else
23906 + .quad 0x0000000000000000 /* 0x20 unused */
23907 +#endif
23908 +
23909 + .quad 0x0000000000000000 /* 0x28 unused */
23910 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23911 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23912 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23913 + .quad 0x0000000000000000 /* 0x4b reserved */
23914 + .quad 0x0000000000000000 /* 0x53 reserved */
23915 + .quad 0x0000000000000000 /* 0x5b reserved */
23916 +
23917 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23918 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23919 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23920 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23921 +
23922 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23923 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23924 +
23925 + /*
23926 + * Segments used for calling PnP BIOS have byte granularity.
23927 + * The code segments and data segments have fixed 64k limits,
23928 + * the transfer segment sizes are set at run time.
23929 + */
23930 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
23931 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
23932 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
23933 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
23934 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
23935 +
23936 + /*
23937 + * The APM segments have byte granularity and their bases
23938 + * are set at run time. All have 64k limits.
23939 + */
23940 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23941 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23942 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
23943 +
23944 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23945 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23946 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23947 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23948 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23949 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23950 +
23951 + /* Be sure this is zeroed to avoid false validations in Xen */
23952 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23953 + .endr
23954 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23955 index e1aabdb..fee4fee 100644
23956 --- a/arch/x86/kernel/head_64.S
23957 +++ b/arch/x86/kernel/head_64.S
23958 @@ -20,6 +20,8 @@
23959 #include <asm/processor-flags.h>
23960 #include <asm/percpu.h>
23961 #include <asm/nops.h>
23962 +#include <asm/cpufeature.h>
23963 +#include <asm/alternative-asm.h>
23964
23965 #ifdef CONFIG_PARAVIRT
23966 #include <asm/asm-offsets.h>
23967 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23968 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23969 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23970 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23971 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
23972 +L3_VMALLOC_START = pud_index(VMALLOC_START)
23973 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
23974 +L3_VMALLOC_END = pud_index(VMALLOC_END)
23975 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23976 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23977
23978 .text
23979 __HEAD
23980 @@ -89,11 +97,24 @@ startup_64:
23981 * Fixup the physical addresses in the page table
23982 */
23983 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23984 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23985 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23986 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23987 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23988 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23989
23990 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23991 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23992 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
23993 +#ifndef CONFIG_XEN
23994 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
23995 +#endif
23996 +
23997 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23998 +
23999 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24000 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24001
24002 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24003 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24004
24005 /*
24006 * Set up the identity mapping for the switchover. These
24007 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24008 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24009 1:
24010
24011 - /* Enable PAE mode and PGE */
24012 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24013 + /* Enable PAE mode and PSE/PGE */
24014 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24015 movq %rcx, %cr4
24016
24017 /* Setup early boot stage 4 level pagetables. */
24018 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24019 movl $MSR_EFER, %ecx
24020 rdmsr
24021 btsl $_EFER_SCE, %eax /* Enable System Call */
24022 - btl $20,%edi /* No Execute supported? */
24023 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24024 jnc 1f
24025 btsl $_EFER_NX, %eax
24026 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24027 +#ifndef CONFIG_EFI
24028 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24029 +#endif
24030 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24031 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24032 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24033 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24034 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24035 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24036 1: wrmsr /* Make changes effective */
24037
24038 /* Setup cr0 */
24039 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24040 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24041 * address given in m16:64.
24042 */
24043 + pax_set_fptr_mask
24044 movq initial_code(%rip),%rax
24045 pushq $0 # fake return address to stop unwinder
24046 pushq $__KERNEL_CS # set correct cs
24047 @@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
24048 call dump_stack
24049 #ifdef CONFIG_KALLSYMS
24050 leaq early_idt_ripmsg(%rip),%rdi
24051 - movq 40(%rsp),%rsi # %rip again
24052 + movq 88(%rsp),%rsi # %rip again
24053 call __print_symbol
24054 #endif
24055 #endif /* EARLY_PRINTK */
24056 @@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
24057 early_recursion_flag:
24058 .long 0
24059
24060 + .section .rodata,"a",@progbits
24061 #ifdef CONFIG_EARLY_PRINTK
24062 early_idt_msg:
24063 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24064 @@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
24065 NEXT_PAGE(early_dynamic_pgts)
24066 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24067
24068 - .data
24069 + .section .rodata,"a",@progbits
24070
24071 -#ifndef CONFIG_XEN
24072 NEXT_PAGE(init_level4_pgt)
24073 - .fill 512,8,0
24074 -#else
24075 -NEXT_PAGE(init_level4_pgt)
24076 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24077 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24078 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24079 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24080 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24081 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24082 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24083 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24084 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24085 .org init_level4_pgt + L4_START_KERNEL*8, 0
24086 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24087 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24088
24089 +#ifdef CONFIG_PAX_PER_CPU_PGD
24090 +NEXT_PAGE(cpu_pgd)
24091 + .rept 2*NR_CPUS
24092 + .fill 512,8,0
24093 + .endr
24094 +#endif
24095 +
24096 NEXT_PAGE(level3_ident_pgt)
24097 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24098 +#ifdef CONFIG_XEN
24099 .fill 511, 8, 0
24100 +#else
24101 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24102 + .fill 510,8,0
24103 +#endif
24104 +
24105 +NEXT_PAGE(level3_vmalloc_start_pgt)
24106 + .fill 512,8,0
24107 +
24108 +NEXT_PAGE(level3_vmalloc_end_pgt)
24109 + .fill 512,8,0
24110 +
24111 +NEXT_PAGE(level3_vmemmap_pgt)
24112 + .fill L3_VMEMMAP_START,8,0
24113 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24114 +
24115 NEXT_PAGE(level2_ident_pgt)
24116 - /* Since I easily can, map the first 1G.
24117 + /* Since I easily can, map the first 2G.
24118 * Don't set NX because code runs from these pages.
24119 */
24120 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24121 -#endif
24122 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24123
24124 NEXT_PAGE(level3_kernel_pgt)
24125 .fill L3_START_KERNEL,8,0
24126 @@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
24127 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24128 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24129
24130 +NEXT_PAGE(level2_vmemmap_pgt)
24131 + .fill 512,8,0
24132 +
24133 NEXT_PAGE(level2_kernel_pgt)
24134 /*
24135 * 512 MB kernel mapping. We spend a full page on this pagetable
24136 @@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
24137 NEXT_PAGE(level2_fixmap_pgt)
24138 .fill 506,8,0
24139 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24140 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24141 - .fill 5,8,0
24142 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24143 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24144 + .fill 4,8,0
24145
24146 NEXT_PAGE(level1_fixmap_pgt)
24147 .fill 512,8,0
24148
24149 +NEXT_PAGE(level1_vsyscall_pgt)
24150 + .fill 512,8,0
24151 +
24152 #undef PMDS
24153
24154 - .data
24155 + .align PAGE_SIZE
24156 +ENTRY(cpu_gdt_table)
24157 + .rept NR_CPUS
24158 + .quad 0x0000000000000000 /* NULL descriptor */
24159 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24160 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24161 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24162 + .quad 0x00cffb000000ffff /* __USER32_CS */
24163 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24164 + .quad 0x00affb000000ffff /* __USER_CS */
24165 +
24166 +#ifdef CONFIG_PAX_KERNEXEC
24167 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24168 +#else
24169 + .quad 0x0 /* unused */
24170 +#endif
24171 +
24172 + .quad 0,0 /* TSS */
24173 + .quad 0,0 /* LDT */
24174 + .quad 0,0,0 /* three TLS descriptors */
24175 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24176 + /* asm/segment.h:GDT_ENTRIES must match this */
24177 +
24178 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24179 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24180 +#else
24181 + .quad 0x0 /* unused */
24182 +#endif
24183 +
24184 + /* zero the remaining page */
24185 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24186 + .endr
24187 +
24188 .align 16
24189 .globl early_gdt_descr
24190 early_gdt_descr:
24191 .word GDT_ENTRIES*8-1
24192 early_gdt_descr_base:
24193 - .quad INIT_PER_CPU_VAR(gdt_page)
24194 + .quad cpu_gdt_table
24195
24196 ENTRY(phys_base)
24197 /* This must match the first entry in level2_kernel_pgt */
24198 .quad 0x0000000000000000
24199
24200 #include "../../x86/xen/xen-head.S"
24201 -
24202 - __PAGE_ALIGNED_BSS
24203 +
24204 + .section .rodata,"a",@progbits
24205 NEXT_PAGE(empty_zero_page)
24206 .skip PAGE_SIZE
24207 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24208 index 05fd74f..c3548b1 100644
24209 --- a/arch/x86/kernel/i386_ksyms_32.c
24210 +++ b/arch/x86/kernel/i386_ksyms_32.c
24211 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24212 EXPORT_SYMBOL(cmpxchg8b_emu);
24213 #endif
24214
24215 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24216 +
24217 /* Networking helper routines. */
24218 EXPORT_SYMBOL(csum_partial_copy_generic);
24219 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24220 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24221
24222 EXPORT_SYMBOL(__get_user_1);
24223 EXPORT_SYMBOL(__get_user_2);
24224 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24225 EXPORT_SYMBOL(___preempt_schedule_context);
24226 #endif
24227 #endif
24228 +
24229 +#ifdef CONFIG_PAX_KERNEXEC
24230 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24231 +#endif
24232 +
24233 +#ifdef CONFIG_PAX_PER_CPU_PGD
24234 +EXPORT_SYMBOL(cpu_pgd);
24235 +#endif
24236 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24237 index e8368c6..9c1a712 100644
24238 --- a/arch/x86/kernel/i387.c
24239 +++ b/arch/x86/kernel/i387.c
24240 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24241 static inline bool interrupted_user_mode(void)
24242 {
24243 struct pt_regs *regs = get_irq_regs();
24244 - return regs && user_mode_vm(regs);
24245 + return regs && user_mode(regs);
24246 }
24247
24248 /*
24249 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24250 index 2e977b5..5f2c273 100644
24251 --- a/arch/x86/kernel/i8259.c
24252 +++ b/arch/x86/kernel/i8259.c
24253 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24254 static void make_8259A_irq(unsigned int irq)
24255 {
24256 disable_irq_nosync(irq);
24257 - io_apic_irqs &= ~(1<<irq);
24258 + io_apic_irqs &= ~(1UL<<irq);
24259 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24260 i8259A_chip.name);
24261 enable_irq(irq);
24262 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24263 "spurious 8259A interrupt: IRQ%d.\n", irq);
24264 spurious_irq_mask |= irqmask;
24265 }
24266 - atomic_inc(&irq_err_count);
24267 + atomic_inc_unchecked(&irq_err_count);
24268 /*
24269 * Theoretically we do not have to handle this IRQ,
24270 * but in Linux this does not cause problems and is
24271 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24272 /* (slave's support for AEOI in flat mode is to be investigated) */
24273 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24274
24275 + pax_open_kernel();
24276 if (auto_eoi)
24277 /*
24278 * In AEOI mode we just have to mask the interrupt
24279 * when acking.
24280 */
24281 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24282 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24283 else
24284 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24285 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24286 + pax_close_kernel();
24287
24288 udelay(100); /* wait for 8259A to initialize */
24289
24290 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24291 index a979b5b..1d6db75 100644
24292 --- a/arch/x86/kernel/io_delay.c
24293 +++ b/arch/x86/kernel/io_delay.c
24294 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24295 * Quirk table for systems that misbehave (lock up, etc.) if port
24296 * 0x80 is used:
24297 */
24298 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24299 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24300 {
24301 .callback = dmi_io_delay_0xed_port,
24302 .ident = "Compaq Presario V6000",
24303 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24304 index 4ddaf66..49d5c18 100644
24305 --- a/arch/x86/kernel/ioport.c
24306 +++ b/arch/x86/kernel/ioport.c
24307 @@ -6,6 +6,7 @@
24308 #include <linux/sched.h>
24309 #include <linux/kernel.h>
24310 #include <linux/capability.h>
24311 +#include <linux/security.h>
24312 #include <linux/errno.h>
24313 #include <linux/types.h>
24314 #include <linux/ioport.h>
24315 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24316 return -EINVAL;
24317 if (turn_on && !capable(CAP_SYS_RAWIO))
24318 return -EPERM;
24319 +#ifdef CONFIG_GRKERNSEC_IO
24320 + if (turn_on && grsec_disable_privio) {
24321 + gr_handle_ioperm();
24322 + return -ENODEV;
24323 + }
24324 +#endif
24325
24326 /*
24327 * If it's the first ioperm() call in this thread's lifetime, set the
24328 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24329 * because the ->io_bitmap_max value must match the bitmap
24330 * contents:
24331 */
24332 - tss = &per_cpu(init_tss, get_cpu());
24333 + tss = init_tss + get_cpu();
24334
24335 if (turn_on)
24336 bitmap_clear(t->io_bitmap_ptr, from, num);
24337 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24338 if (level > old) {
24339 if (!capable(CAP_SYS_RAWIO))
24340 return -EPERM;
24341 +#ifdef CONFIG_GRKERNSEC_IO
24342 + if (grsec_disable_privio) {
24343 + gr_handle_iopl();
24344 + return -ENODEV;
24345 + }
24346 +#endif
24347 }
24348 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24349 t->iopl = level << 12;
24350 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24351 index 22d0687..e07b2a5 100644
24352 --- a/arch/x86/kernel/irq.c
24353 +++ b/arch/x86/kernel/irq.c
24354 @@ -21,7 +21,7 @@
24355 #define CREATE_TRACE_POINTS
24356 #include <asm/trace/irq_vectors.h>
24357
24358 -atomic_t irq_err_count;
24359 +atomic_unchecked_t irq_err_count;
24360
24361 /* Function pointer for generic interrupt vector handling */
24362 void (*x86_platform_ipi_callback)(void) = NULL;
24363 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24364 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24365 seq_printf(p, " Machine check polls\n");
24366 #endif
24367 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24368 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24369 #if defined(CONFIG_X86_IO_APIC)
24370 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24371 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24372 #endif
24373 return 0;
24374 }
24375 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24376
24377 u64 arch_irq_stat(void)
24378 {
24379 - u64 sum = atomic_read(&irq_err_count);
24380 + u64 sum = atomic_read_unchecked(&irq_err_count);
24381 return sum;
24382 }
24383
24384 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24385 index d7fcbed..1f747f7 100644
24386 --- a/arch/x86/kernel/irq_32.c
24387 +++ b/arch/x86/kernel/irq_32.c
24388 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24389 __asm__ __volatile__("andl %%esp,%0" :
24390 "=r" (sp) : "0" (THREAD_SIZE - 1));
24391
24392 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24393 + return sp < STACK_WARN;
24394 }
24395
24396 static void print_stack_overflow(void)
24397 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24398 * per-CPU IRQ handling contexts (thread information and stack)
24399 */
24400 union irq_ctx {
24401 - struct thread_info tinfo;
24402 - u32 stack[THREAD_SIZE/sizeof(u32)];
24403 + unsigned long previous_esp;
24404 + u32 stack[THREAD_SIZE/sizeof(u32)];
24405 } __attribute__((aligned(THREAD_SIZE)));
24406
24407 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24408 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24409 static inline int
24410 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24411 {
24412 - union irq_ctx *curctx, *irqctx;
24413 + union irq_ctx *irqctx;
24414 u32 *isp, arg1, arg2;
24415
24416 - curctx = (union irq_ctx *) current_thread_info();
24417 irqctx = __this_cpu_read(hardirq_ctx);
24418
24419 /*
24420 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24421 * handler) we can't do that and just have to keep using the
24422 * current stack (which is the irq stack already after all)
24423 */
24424 - if (unlikely(curctx == irqctx))
24425 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24426 return 0;
24427
24428 /* build the stack frame on the IRQ stack */
24429 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24430 - irqctx->tinfo.task = curctx->tinfo.task;
24431 - irqctx->tinfo.previous_esp = current_stack_pointer;
24432 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24433 + irqctx->previous_esp = current_stack_pointer;
24434 +
24435 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24436 + __set_fs(MAKE_MM_SEG(0));
24437 +#endif
24438
24439 if (unlikely(overflow))
24440 call_on_stack(print_stack_overflow, isp);
24441 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24442 : "0" (irq), "1" (desc), "2" (isp),
24443 "D" (desc->handle_irq)
24444 : "memory", "cc", "ecx");
24445 +
24446 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24447 + __set_fs(current_thread_info()->addr_limit);
24448 +#endif
24449 +
24450 return 1;
24451 }
24452
24453 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24454 */
24455 void irq_ctx_init(int cpu)
24456 {
24457 - union irq_ctx *irqctx;
24458 -
24459 if (per_cpu(hardirq_ctx, cpu))
24460 return;
24461
24462 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24463 - THREADINFO_GFP,
24464 - THREAD_SIZE_ORDER));
24465 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24466 - irqctx->tinfo.cpu = cpu;
24467 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24468 -
24469 - per_cpu(hardirq_ctx, cpu) = irqctx;
24470 -
24471 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24472 - THREADINFO_GFP,
24473 - THREAD_SIZE_ORDER));
24474 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24475 - irqctx->tinfo.cpu = cpu;
24476 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24477 -
24478 - per_cpu(softirq_ctx, cpu) = irqctx;
24479 -
24480 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24481 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24482 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24483 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24484 }
24485
24486 void do_softirq_own_stack(void)
24487 {
24488 - struct thread_info *curctx;
24489 union irq_ctx *irqctx;
24490 u32 *isp;
24491
24492 - curctx = current_thread_info();
24493 irqctx = __this_cpu_read(softirq_ctx);
24494 - irqctx->tinfo.task = curctx->task;
24495 - irqctx->tinfo.previous_esp = current_stack_pointer;
24496 + irqctx->previous_esp = current_stack_pointer;
24497
24498 /* build the stack frame on the softirq stack */
24499 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24500 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24501 +
24502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24503 + __set_fs(MAKE_MM_SEG(0));
24504 +#endif
24505
24506 call_on_stack(__do_softirq, isp);
24507 +
24508 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24509 + __set_fs(current_thread_info()->addr_limit);
24510 +#endif
24511 +
24512 }
24513
24514 bool handle_irq(unsigned irq, struct pt_regs *regs)
24515 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24516 if (unlikely(!desc))
24517 return false;
24518
24519 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24520 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24521 if (unlikely(overflow))
24522 print_stack_overflow();
24523 desc->handle_irq(irq, desc);
24524 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24525 index 4d1c746..232961d 100644
24526 --- a/arch/x86/kernel/irq_64.c
24527 +++ b/arch/x86/kernel/irq_64.c
24528 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24529 u64 estack_top, estack_bottom;
24530 u64 curbase = (u64)task_stack_page(current);
24531
24532 - if (user_mode_vm(regs))
24533 + if (user_mode(regs))
24534 return;
24535
24536 if (regs->sp >= curbase + sizeof(struct thread_info) +
24537 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24538 index 26d5a55..a01160a 100644
24539 --- a/arch/x86/kernel/jump_label.c
24540 +++ b/arch/x86/kernel/jump_label.c
24541 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24542 * Jump label is enabled for the first time.
24543 * So we expect a default_nop...
24544 */
24545 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
24546 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
24547 != 0))
24548 bug_at((void *)entry->code, __LINE__);
24549 } else {
24550 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24551 * ...otherwise expect an ideal_nop. Otherwise
24552 * something went horribly wrong.
24553 */
24554 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
24555 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
24556 != 0))
24557 bug_at((void *)entry->code, __LINE__);
24558 }
24559 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
24560 * are converting the default nop to the ideal nop.
24561 */
24562 if (init) {
24563 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
24564 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
24565 bug_at((void *)entry->code, __LINE__);
24566 } else {
24567 code.jump = 0xe9;
24568 code.offset = entry->target -
24569 (entry->code + JUMP_LABEL_NOP_SIZE);
24570 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
24571 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
24572 bug_at((void *)entry->code, __LINE__);
24573 }
24574 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
24575 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
24576 index 836f832..a8bda67 100644
24577 --- a/arch/x86/kernel/kgdb.c
24578 +++ b/arch/x86/kernel/kgdb.c
24579 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
24580 #ifdef CONFIG_X86_32
24581 switch (regno) {
24582 case GDB_SS:
24583 - if (!user_mode_vm(regs))
24584 + if (!user_mode(regs))
24585 *(unsigned long *)mem = __KERNEL_DS;
24586 break;
24587 case GDB_SP:
24588 - if (!user_mode_vm(regs))
24589 + if (!user_mode(regs))
24590 *(unsigned long *)mem = kernel_stack_pointer(regs);
24591 break;
24592 case GDB_GS:
24593 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
24594 bp->attr.bp_addr = breakinfo[breakno].addr;
24595 bp->attr.bp_len = breakinfo[breakno].len;
24596 bp->attr.bp_type = breakinfo[breakno].type;
24597 - info->address = breakinfo[breakno].addr;
24598 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
24599 + info->address = ktla_ktva(breakinfo[breakno].addr);
24600 + else
24601 + info->address = breakinfo[breakno].addr;
24602 info->len = breakinfo[breakno].len;
24603 info->type = breakinfo[breakno].type;
24604 val = arch_install_hw_breakpoint(bp);
24605 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
24606 case 'k':
24607 /* clear the trace bit */
24608 linux_regs->flags &= ~X86_EFLAGS_TF;
24609 - atomic_set(&kgdb_cpu_doing_single_step, -1);
24610 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
24611
24612 /* set the trace bit if we're stepping */
24613 if (remcomInBuffer[0] == 's') {
24614 linux_regs->flags |= X86_EFLAGS_TF;
24615 - atomic_set(&kgdb_cpu_doing_single_step,
24616 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
24617 raw_smp_processor_id());
24618 }
24619
24620 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
24621
24622 switch (cmd) {
24623 case DIE_DEBUG:
24624 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
24625 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24626 if (user_mode(regs))
24627 return single_step_cont(regs, args);
24628 break;
24629 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24630 #endif /* CONFIG_DEBUG_RODATA */
24631
24632 bpt->type = BP_BREAKPOINT;
24633 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24634 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24635 BREAK_INSTR_SIZE);
24636 if (err)
24637 return err;
24638 - err = probe_kernel_write((char *)bpt->bpt_addr,
24639 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24640 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24641 #ifdef CONFIG_DEBUG_RODATA
24642 if (!err)
24643 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24644 return -EBUSY;
24645 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24646 BREAK_INSTR_SIZE);
24647 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24648 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24649 if (err)
24650 return err;
24651 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24652 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24653 if (mutex_is_locked(&text_mutex))
24654 goto knl_write;
24655 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24656 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24657 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24658 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24659 goto knl_write;
24660 return err;
24661 knl_write:
24662 #endif /* CONFIG_DEBUG_RODATA */
24663 - return probe_kernel_write((char *)bpt->bpt_addr,
24664 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24665 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24666 }
24667
24668 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24669 index 79a3f96..6ba030a 100644
24670 --- a/arch/x86/kernel/kprobes/core.c
24671 +++ b/arch/x86/kernel/kprobes/core.c
24672 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24673 s32 raddr;
24674 } __packed *insn;
24675
24676 - insn = (struct __arch_relative_insn *)from;
24677 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
24678 +
24679 + pax_open_kernel();
24680 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24681 insn->op = op;
24682 + pax_close_kernel();
24683 }
24684
24685 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24686 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24687 kprobe_opcode_t opcode;
24688 kprobe_opcode_t *orig_opcodes = opcodes;
24689
24690 - if (search_exception_tables((unsigned long)opcodes))
24691 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24692 return 0; /* Page fault may occur on this address. */
24693
24694 retry:
24695 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24696 * for the first byte, we can recover the original instruction
24697 * from it and kp->opcode.
24698 */
24699 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24700 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24701 buf[0] = kp->opcode;
24702 - return (unsigned long)buf;
24703 + return ktva_ktla((unsigned long)buf);
24704 }
24705
24706 /*
24707 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24708 /* Another subsystem puts a breakpoint, failed to recover */
24709 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24710 return 0;
24711 + pax_open_kernel();
24712 memcpy(dest, insn.kaddr, insn.length);
24713 + pax_close_kernel();
24714
24715 #ifdef CONFIG_X86_64
24716 if (insn_rip_relative(&insn)) {
24717 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24718 return 0;
24719 }
24720 disp = (u8 *) dest + insn_offset_displacement(&insn);
24721 + pax_open_kernel();
24722 *(s32 *) disp = (s32) newdisp;
24723 + pax_close_kernel();
24724 }
24725 #endif
24726 return insn.length;
24727 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24728 * nor set current_kprobe, because it doesn't use single
24729 * stepping.
24730 */
24731 - regs->ip = (unsigned long)p->ainsn.insn;
24732 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24733 preempt_enable_no_resched();
24734 return;
24735 }
24736 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24737 regs->flags &= ~X86_EFLAGS_IF;
24738 /* single step inline if the instruction is an int3 */
24739 if (p->opcode == BREAKPOINT_INSTRUCTION)
24740 - regs->ip = (unsigned long)p->addr;
24741 + regs->ip = ktla_ktva((unsigned long)p->addr);
24742 else
24743 - regs->ip = (unsigned long)p->ainsn.insn;
24744 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24745 }
24746
24747 /*
24748 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24749 setup_singlestep(p, regs, kcb, 0);
24750 return 1;
24751 }
24752 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
24753 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24754 /*
24755 * The breakpoint instruction was removed right
24756 * after we hit it. Another cpu has removed
24757 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24758 " movq %rax, 152(%rsp)\n"
24759 RESTORE_REGS_STRING
24760 " popfq\n"
24761 +#ifdef KERNEXEC_PLUGIN
24762 + " btsq $63,(%rsp)\n"
24763 +#endif
24764 #else
24765 " pushf\n"
24766 SAVE_REGS_STRING
24767 @@ -779,7 +789,7 @@ static void __kprobes
24768 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24769 {
24770 unsigned long *tos = stack_addr(regs);
24771 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24772 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24773 unsigned long orig_ip = (unsigned long)p->addr;
24774 kprobe_opcode_t *insn = p->ainsn.insn;
24775
24776 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24777 struct die_args *args = data;
24778 int ret = NOTIFY_DONE;
24779
24780 - if (args->regs && user_mode_vm(args->regs))
24781 + if (args->regs && user_mode(args->regs))
24782 return ret;
24783
24784 switch (val) {
24785 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24786 index 898160b..758cde8 100644
24787 --- a/arch/x86/kernel/kprobes/opt.c
24788 +++ b/arch/x86/kernel/kprobes/opt.c
24789 @@ -79,6 +79,7 @@ found:
24790 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24791 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24792 {
24793 + pax_open_kernel();
24794 #ifdef CONFIG_X86_64
24795 *addr++ = 0x48;
24796 *addr++ = 0xbf;
24797 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24798 *addr++ = 0xb8;
24799 #endif
24800 *(unsigned long *)addr = val;
24801 + pax_close_kernel();
24802 }
24803
24804 asm (
24805 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24806 * Verify if the address gap is in 2GB range, because this uses
24807 * a relative jump.
24808 */
24809 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24810 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24811 if (abs(rel) > 0x7fffffff)
24812 return -ERANGE;
24813
24814 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24815 op->optinsn.size = ret;
24816
24817 /* Copy arch-dep-instance from template */
24818 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24819 + pax_open_kernel();
24820 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24821 + pax_close_kernel();
24822
24823 /* Set probe information */
24824 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24825
24826 /* Set probe function call */
24827 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24828 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24829
24830 /* Set returning jmp instruction at the tail of out-of-line buffer */
24831 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24832 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24833 (u8 *)op->kp.addr + op->optinsn.size);
24834
24835 flush_icache_range((unsigned long) buf,
24836 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
24837 WARN_ON(kprobe_disabled(&op->kp));
24838
24839 /* Backup instructions which will be replaced by jump address */
24840 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24841 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24842 RELATIVE_ADDR_SIZE);
24843
24844 insn_buf[0] = RELATIVEJUMP_OPCODE;
24845 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24846 /* This kprobe is really able to run optimized path. */
24847 op = container_of(p, struct optimized_kprobe, kp);
24848 /* Detour through copied instructions */
24849 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24850 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24851 if (!reenter)
24852 reset_current_kprobe();
24853 preempt_enable_no_resched();
24854 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24855 index ebc9873..1b9724b 100644
24856 --- a/arch/x86/kernel/ldt.c
24857 +++ b/arch/x86/kernel/ldt.c
24858 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24859 if (reload) {
24860 #ifdef CONFIG_SMP
24861 preempt_disable();
24862 - load_LDT(pc);
24863 + load_LDT_nolock(pc);
24864 if (!cpumask_equal(mm_cpumask(current->mm),
24865 cpumask_of(smp_processor_id())))
24866 smp_call_function(flush_ldt, current->mm, 1);
24867 preempt_enable();
24868 #else
24869 - load_LDT(pc);
24870 + load_LDT_nolock(pc);
24871 #endif
24872 }
24873 if (oldsize) {
24874 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24875 return err;
24876
24877 for (i = 0; i < old->size; i++)
24878 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24879 + write_ldt_entry(new->ldt, i, old->ldt + i);
24880 return 0;
24881 }
24882
24883 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24884 retval = copy_ldt(&mm->context, &old_mm->context);
24885 mutex_unlock(&old_mm->context.lock);
24886 }
24887 +
24888 + if (tsk == current) {
24889 + mm->context.vdso = 0;
24890 +
24891 +#ifdef CONFIG_X86_32
24892 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24893 + mm->context.user_cs_base = 0UL;
24894 + mm->context.user_cs_limit = ~0UL;
24895 +
24896 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24897 + cpus_clear(mm->context.cpu_user_cs_mask);
24898 +#endif
24899 +
24900 +#endif
24901 +#endif
24902 +
24903 + }
24904 +
24905 return retval;
24906 }
24907
24908 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24909 }
24910 }
24911
24912 +#ifdef CONFIG_PAX_SEGMEXEC
24913 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24914 + error = -EINVAL;
24915 + goto out_unlock;
24916 + }
24917 +#endif
24918 +
24919 fill_ldt(&ldt, &ldt_info);
24920 if (oldmode)
24921 ldt.avl = 0;
24922 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24923 index 5b19e4d..6476a76 100644
24924 --- a/arch/x86/kernel/machine_kexec_32.c
24925 +++ b/arch/x86/kernel/machine_kexec_32.c
24926 @@ -26,7 +26,7 @@
24927 #include <asm/cacheflush.h>
24928 #include <asm/debugreg.h>
24929
24930 -static void set_idt(void *newidt, __u16 limit)
24931 +static void set_idt(struct desc_struct *newidt, __u16 limit)
24932 {
24933 struct desc_ptr curidt;
24934
24935 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24936 }
24937
24938
24939 -static void set_gdt(void *newgdt, __u16 limit)
24940 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24941 {
24942 struct desc_ptr curgdt;
24943
24944 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24945 }
24946
24947 control_page = page_address(image->control_code_page);
24948 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24949 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24950
24951 relocate_kernel_ptr = control_page;
24952 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24953 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24954 index 15c9876..0a43909 100644
24955 --- a/arch/x86/kernel/microcode_core.c
24956 +++ b/arch/x86/kernel/microcode_core.c
24957 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24958 return NOTIFY_OK;
24959 }
24960
24961 -static struct notifier_block __refdata mc_cpu_notifier = {
24962 +static struct notifier_block mc_cpu_notifier = {
24963 .notifier_call = mc_cpu_callback,
24964 };
24965
24966 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24967 index 5fb2ceb..3ae90bb 100644
24968 --- a/arch/x86/kernel/microcode_intel.c
24969 +++ b/arch/x86/kernel/microcode_intel.c
24970 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24971
24972 static int get_ucode_user(void *to, const void *from, size_t n)
24973 {
24974 - return copy_from_user(to, from, n);
24975 + return copy_from_user(to, (const void __force_user *)from, n);
24976 }
24977
24978 static enum ucode_state
24979 request_microcode_user(int cpu, const void __user *buf, size_t size)
24980 {
24981 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24982 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24983 }
24984
24985 static void microcode_fini_cpu(int cpu)
24986 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24987 index 18be189..4a9fe40 100644
24988 --- a/arch/x86/kernel/module.c
24989 +++ b/arch/x86/kernel/module.c
24990 @@ -43,15 +43,60 @@ do { \
24991 } while (0)
24992 #endif
24993
24994 -void *module_alloc(unsigned long size)
24995 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24996 {
24997 - if (PAGE_ALIGN(size) > MODULES_LEN)
24998 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24999 return NULL;
25000 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25001 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25002 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25003 NUMA_NO_NODE, __builtin_return_address(0));
25004 }
25005
25006 +void *module_alloc(unsigned long size)
25007 +{
25008 +
25009 +#ifdef CONFIG_PAX_KERNEXEC
25010 + return __module_alloc(size, PAGE_KERNEL);
25011 +#else
25012 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25013 +#endif
25014 +
25015 +}
25016 +
25017 +#ifdef CONFIG_PAX_KERNEXEC
25018 +#ifdef CONFIG_X86_32
25019 +void *module_alloc_exec(unsigned long size)
25020 +{
25021 + struct vm_struct *area;
25022 +
25023 + if (size == 0)
25024 + return NULL;
25025 +
25026 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25027 + return area ? area->addr : NULL;
25028 +}
25029 +EXPORT_SYMBOL(module_alloc_exec);
25030 +
25031 +void module_free_exec(struct module *mod, void *module_region)
25032 +{
25033 + vunmap(module_region);
25034 +}
25035 +EXPORT_SYMBOL(module_free_exec);
25036 +#else
25037 +void module_free_exec(struct module *mod, void *module_region)
25038 +{
25039 + module_free(mod, module_region);
25040 +}
25041 +EXPORT_SYMBOL(module_free_exec);
25042 +
25043 +void *module_alloc_exec(unsigned long size)
25044 +{
25045 + return __module_alloc(size, PAGE_KERNEL_RX);
25046 +}
25047 +EXPORT_SYMBOL(module_alloc_exec);
25048 +#endif
25049 +#endif
25050 +
25051 #ifdef CONFIG_X86_32
25052 int apply_relocate(Elf32_Shdr *sechdrs,
25053 const char *strtab,
25054 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25055 unsigned int i;
25056 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25057 Elf32_Sym *sym;
25058 - uint32_t *location;
25059 + uint32_t *plocation, location;
25060
25061 DEBUGP("Applying relocate section %u to %u\n",
25062 relsec, sechdrs[relsec].sh_info);
25063 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25064 /* This is where to make the change */
25065 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25066 - + rel[i].r_offset;
25067 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25068 + location = (uint32_t)plocation;
25069 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25070 + plocation = ktla_ktva((void *)plocation);
25071 /* This is the symbol it is referring to. Note that all
25072 undefined symbols have been resolved. */
25073 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25074 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25075 switch (ELF32_R_TYPE(rel[i].r_info)) {
25076 case R_386_32:
25077 /* We add the value into the location given */
25078 - *location += sym->st_value;
25079 + pax_open_kernel();
25080 + *plocation += sym->st_value;
25081 + pax_close_kernel();
25082 break;
25083 case R_386_PC32:
25084 /* Add the value, subtract its position */
25085 - *location += sym->st_value - (uint32_t)location;
25086 + pax_open_kernel();
25087 + *plocation += sym->st_value - location;
25088 + pax_close_kernel();
25089 break;
25090 default:
25091 pr_err("%s: Unknown relocation: %u\n",
25092 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25093 case R_X86_64_NONE:
25094 break;
25095 case R_X86_64_64:
25096 + pax_open_kernel();
25097 *(u64 *)loc = val;
25098 + pax_close_kernel();
25099 break;
25100 case R_X86_64_32:
25101 + pax_open_kernel();
25102 *(u32 *)loc = val;
25103 + pax_close_kernel();
25104 if (val != *(u32 *)loc)
25105 goto overflow;
25106 break;
25107 case R_X86_64_32S:
25108 + pax_open_kernel();
25109 *(s32 *)loc = val;
25110 + pax_close_kernel();
25111 if ((s64)val != *(s32 *)loc)
25112 goto overflow;
25113 break;
25114 case R_X86_64_PC32:
25115 val -= (u64)loc;
25116 + pax_open_kernel();
25117 *(u32 *)loc = val;
25118 + pax_close_kernel();
25119 +
25120 #if 0
25121 if ((s64)val != *(s32 *)loc)
25122 goto overflow;
25123 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25124 index 05266b5..1577fde 100644
25125 --- a/arch/x86/kernel/msr.c
25126 +++ b/arch/x86/kernel/msr.c
25127 @@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25128 return notifier_from_errno(err);
25129 }
25130
25131 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25132 +static struct notifier_block msr_class_cpu_notifier = {
25133 .notifier_call = msr_class_cpu_callback,
25134 };
25135
25136 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25137 index 6fcb49c..5b3f4ff 100644
25138 --- a/arch/x86/kernel/nmi.c
25139 +++ b/arch/x86/kernel/nmi.c
25140 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25141 return handled;
25142 }
25143
25144 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25145 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25146 {
25147 struct nmi_desc *desc = nmi_to_desc(type);
25148 unsigned long flags;
25149 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25150 * event confuses some handlers (kdump uses this flag)
25151 */
25152 if (action->flags & NMI_FLAG_FIRST)
25153 - list_add_rcu(&action->list, &desc->head);
25154 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25155 else
25156 - list_add_tail_rcu(&action->list, &desc->head);
25157 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25158
25159 spin_unlock_irqrestore(&desc->lock, flags);
25160 return 0;
25161 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25162 if (!strcmp(n->name, name)) {
25163 WARN(in_nmi(),
25164 "Trying to free NMI (%s) from NMI context!\n", n->name);
25165 - list_del_rcu(&n->list);
25166 + pax_list_del_rcu((struct list_head *)&n->list);
25167 break;
25168 }
25169 }
25170 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25171 dotraplinkage notrace __kprobes void
25172 do_nmi(struct pt_regs *regs, long error_code)
25173 {
25174 +
25175 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25176 + if (!user_mode(regs)) {
25177 + unsigned long cs = regs->cs & 0xFFFF;
25178 + unsigned long ip = ktva_ktla(regs->ip);
25179 +
25180 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25181 + regs->ip = ip;
25182 + }
25183 +#endif
25184 +
25185 nmi_nesting_preprocess(regs);
25186
25187 nmi_enter();
25188 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25189 index 6d9582e..f746287 100644
25190 --- a/arch/x86/kernel/nmi_selftest.c
25191 +++ b/arch/x86/kernel/nmi_selftest.c
25192 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25193 {
25194 /* trap all the unknown NMIs we may generate */
25195 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25196 - __initdata);
25197 + __initconst);
25198 }
25199
25200 static void __init cleanup_nmi_testsuite(void)
25201 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25202 unsigned long timeout;
25203
25204 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25205 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25206 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25207 nmi_fail = FAILURE;
25208 return;
25209 }
25210 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25211 index bbb6c73..24a58ef 100644
25212 --- a/arch/x86/kernel/paravirt-spinlocks.c
25213 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25214 @@ -8,7 +8,7 @@
25215
25216 #include <asm/paravirt.h>
25217
25218 -struct pv_lock_ops pv_lock_ops = {
25219 +struct pv_lock_ops pv_lock_ops __read_only = {
25220 #ifdef CONFIG_SMP
25221 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25222 .unlock_kick = paravirt_nop,
25223 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25224 index 1b10af8..0b58cbc 100644
25225 --- a/arch/x86/kernel/paravirt.c
25226 +++ b/arch/x86/kernel/paravirt.c
25227 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25228 {
25229 return x;
25230 }
25231 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25232 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25233 +#endif
25234
25235 void __init default_banner(void)
25236 {
25237 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25238 if (opfunc == NULL)
25239 /* If there's no function, patch it with a ud2a (BUG) */
25240 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25241 - else if (opfunc == _paravirt_nop)
25242 + else if (opfunc == (void *)_paravirt_nop)
25243 /* If the operation is a nop, then nop the callsite */
25244 ret = paravirt_patch_nop();
25245
25246 /* identity functions just return their single argument */
25247 - else if (opfunc == _paravirt_ident_32)
25248 + else if (opfunc == (void *)_paravirt_ident_32)
25249 ret = paravirt_patch_ident_32(insnbuf, len);
25250 - else if (opfunc == _paravirt_ident_64)
25251 + else if (opfunc == (void *)_paravirt_ident_64)
25252 ret = paravirt_patch_ident_64(insnbuf, len);
25253 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25254 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25255 + ret = paravirt_patch_ident_64(insnbuf, len);
25256 +#endif
25257
25258 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25259 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25260 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25261 if (insn_len > len || start == NULL)
25262 insn_len = len;
25263 else
25264 - memcpy(insnbuf, start, insn_len);
25265 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25266
25267 return insn_len;
25268 }
25269 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25270 return this_cpu_read(paravirt_lazy_mode);
25271 }
25272
25273 -struct pv_info pv_info = {
25274 +struct pv_info pv_info __read_only = {
25275 .name = "bare hardware",
25276 .paravirt_enabled = 0,
25277 .kernel_rpl = 0,
25278 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25279 #endif
25280 };
25281
25282 -struct pv_init_ops pv_init_ops = {
25283 +struct pv_init_ops pv_init_ops __read_only = {
25284 .patch = native_patch,
25285 };
25286
25287 -struct pv_time_ops pv_time_ops = {
25288 +struct pv_time_ops pv_time_ops __read_only = {
25289 .sched_clock = native_sched_clock,
25290 .steal_clock = native_steal_clock,
25291 };
25292
25293 -__visible struct pv_irq_ops pv_irq_ops = {
25294 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25295 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25296 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25297 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25298 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25299 #endif
25300 };
25301
25302 -__visible struct pv_cpu_ops pv_cpu_ops = {
25303 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25304 .cpuid = native_cpuid,
25305 .get_debugreg = native_get_debugreg,
25306 .set_debugreg = native_set_debugreg,
25307 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25308 .end_context_switch = paravirt_nop,
25309 };
25310
25311 -struct pv_apic_ops pv_apic_ops = {
25312 +struct pv_apic_ops pv_apic_ops __read_only= {
25313 #ifdef CONFIG_X86_LOCAL_APIC
25314 .startup_ipi_hook = paravirt_nop,
25315 #endif
25316 };
25317
25318 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25319 +#ifdef CONFIG_X86_32
25320 +#ifdef CONFIG_X86_PAE
25321 +/* 64-bit pagetable entries */
25322 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25323 +#else
25324 /* 32-bit pagetable entries */
25325 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25326 +#endif
25327 #else
25328 /* 64-bit pagetable entries */
25329 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25330 #endif
25331
25332 -struct pv_mmu_ops pv_mmu_ops = {
25333 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25334
25335 .read_cr2 = native_read_cr2,
25336 .write_cr2 = native_write_cr2,
25337 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25338 .make_pud = PTE_IDENT,
25339
25340 .set_pgd = native_set_pgd,
25341 + .set_pgd_batched = native_set_pgd_batched,
25342 #endif
25343 #endif /* PAGETABLE_LEVELS >= 3 */
25344
25345 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25346 },
25347
25348 .set_fixmap = native_set_fixmap,
25349 +
25350 +#ifdef CONFIG_PAX_KERNEXEC
25351 + .pax_open_kernel = native_pax_open_kernel,
25352 + .pax_close_kernel = native_pax_close_kernel,
25353 +#endif
25354 +
25355 };
25356
25357 EXPORT_SYMBOL_GPL(pv_time_ops);
25358 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25359 index 299d493..2ccb0ee 100644
25360 --- a/arch/x86/kernel/pci-calgary_64.c
25361 +++ b/arch/x86/kernel/pci-calgary_64.c
25362 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25363 tce_space = be64_to_cpu(readq(target));
25364 tce_space = tce_space & TAR_SW_BITS;
25365
25366 - tce_space = tce_space & (~specified_table_size);
25367 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25368 info->tce_space = (u64 *)__va(tce_space);
25369 }
25370 }
25371 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25372 index 35ccf75..7a15747 100644
25373 --- a/arch/x86/kernel/pci-iommu_table.c
25374 +++ b/arch/x86/kernel/pci-iommu_table.c
25375 @@ -2,7 +2,7 @@
25376 #include <asm/iommu_table.h>
25377 #include <linux/string.h>
25378 #include <linux/kallsyms.h>
25379 -
25380 +#include <linux/sched.h>
25381
25382 #define DEBUG 1
25383
25384 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25385 index 6c483ba..d10ce2f 100644
25386 --- a/arch/x86/kernel/pci-swiotlb.c
25387 +++ b/arch/x86/kernel/pci-swiotlb.c
25388 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25389 void *vaddr, dma_addr_t dma_addr,
25390 struct dma_attrs *attrs)
25391 {
25392 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25393 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25394 }
25395
25396 static struct dma_map_ops swiotlb_dma_ops = {
25397 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25398 index ca7f0d5..8996469 100644
25399 --- a/arch/x86/kernel/preempt.S
25400 +++ b/arch/x86/kernel/preempt.S
25401 @@ -3,12 +3,14 @@
25402 #include <asm/dwarf2.h>
25403 #include <asm/asm.h>
25404 #include <asm/calling.h>
25405 +#include <asm/alternative-asm.h>
25406
25407 ENTRY(___preempt_schedule)
25408 CFI_STARTPROC
25409 SAVE_ALL
25410 call preempt_schedule
25411 RESTORE_ALL
25412 + pax_force_retaddr
25413 ret
25414 CFI_ENDPROC
25415
25416 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25417 SAVE_ALL
25418 call preempt_schedule_context
25419 RESTORE_ALL
25420 + pax_force_retaddr
25421 ret
25422 CFI_ENDPROC
25423
25424 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25425 index 3fb8d95..254dc51 100644
25426 --- a/arch/x86/kernel/process.c
25427 +++ b/arch/x86/kernel/process.c
25428 @@ -36,7 +36,8 @@
25429 * section. Since TSS's are completely CPU-local, we want them
25430 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25431 */
25432 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25433 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25434 +EXPORT_SYMBOL(init_tss);
25435
25436 #ifdef CONFIG_X86_64
25437 static DEFINE_PER_CPU(unsigned char, is_idle);
25438 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25439 task_xstate_cachep =
25440 kmem_cache_create("task_xstate", xstate_size,
25441 __alignof__(union thread_xstate),
25442 - SLAB_PANIC | SLAB_NOTRACK, NULL);
25443 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25444 }
25445
25446 /*
25447 @@ -105,7 +106,7 @@ void exit_thread(void)
25448 unsigned long *bp = t->io_bitmap_ptr;
25449
25450 if (bp) {
25451 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25452 + struct tss_struct *tss = init_tss + get_cpu();
25453
25454 t->io_bitmap_ptr = NULL;
25455 clear_thread_flag(TIF_IO_BITMAP);
25456 @@ -125,6 +126,9 @@ void flush_thread(void)
25457 {
25458 struct task_struct *tsk = current;
25459
25460 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25461 + loadsegment(gs, 0);
25462 +#endif
25463 flush_ptrace_hw_breakpoint(tsk);
25464 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25465 drop_init_fpu(tsk);
25466 @@ -271,7 +275,7 @@ static void __exit_idle(void)
25467 void exit_idle(void)
25468 {
25469 /* idle loop has pid 0 */
25470 - if (current->pid)
25471 + if (task_pid_nr(current))
25472 return;
25473 __exit_idle();
25474 }
25475 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25476 return ret;
25477 }
25478 #endif
25479 -void stop_this_cpu(void *dummy)
25480 +__noreturn void stop_this_cpu(void *dummy)
25481 {
25482 local_irq_disable();
25483 /*
25484 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25485 }
25486 early_param("idle", idle_setup);
25487
25488 -unsigned long arch_align_stack(unsigned long sp)
25489 +#ifdef CONFIG_PAX_RANDKSTACK
25490 +void pax_randomize_kstack(struct pt_regs *regs)
25491 {
25492 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25493 - sp -= get_random_int() % 8192;
25494 - return sp & ~0xf;
25495 -}
25496 + struct thread_struct *thread = &current->thread;
25497 + unsigned long time;
25498
25499 -unsigned long arch_randomize_brk(struct mm_struct *mm)
25500 -{
25501 - unsigned long range_end = mm->brk + 0x02000000;
25502 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25503 -}
25504 + if (!randomize_va_space)
25505 + return;
25506 +
25507 + if (v8086_mode(regs))
25508 + return;
25509
25510 + rdtscl(time);
25511 +
25512 + /* P4 seems to return a 0 LSB, ignore it */
25513 +#ifdef CONFIG_MPENTIUM4
25514 + time &= 0x3EUL;
25515 + time <<= 2;
25516 +#elif defined(CONFIG_X86_64)
25517 + time &= 0xFUL;
25518 + time <<= 4;
25519 +#else
25520 + time &= 0x1FUL;
25521 + time <<= 3;
25522 +#endif
25523 +
25524 + thread->sp0 ^= time;
25525 + load_sp0(init_tss + smp_processor_id(), thread);
25526 +
25527 +#ifdef CONFIG_X86_64
25528 + this_cpu_write(kernel_stack, thread->sp0);
25529 +#endif
25530 +}
25531 +#endif
25532 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
25533 index 6f1236c..fd448d4 100644
25534 --- a/arch/x86/kernel/process_32.c
25535 +++ b/arch/x86/kernel/process_32.c
25536 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
25537 unsigned long thread_saved_pc(struct task_struct *tsk)
25538 {
25539 return ((unsigned long *)tsk->thread.sp)[3];
25540 +//XXX return tsk->thread.eip;
25541 }
25542
25543 void __show_regs(struct pt_regs *regs, int all)
25544 @@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
25545 unsigned long sp;
25546 unsigned short ss, gs;
25547
25548 - if (user_mode_vm(regs)) {
25549 + if (user_mode(regs)) {
25550 sp = regs->sp;
25551 ss = regs->ss & 0xffff;
25552 - gs = get_user_gs(regs);
25553 } else {
25554 sp = kernel_stack_pointer(regs);
25555 savesegment(ss, ss);
25556 - savesegment(gs, gs);
25557 }
25558 + gs = get_user_gs(regs);
25559
25560 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
25561 (u16)regs->cs, regs->ip, regs->flags,
25562 - smp_processor_id());
25563 + raw_smp_processor_id());
25564 print_symbol("EIP is at %s\n", regs->ip);
25565
25566 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
25567 @@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
25568 int copy_thread(unsigned long clone_flags, unsigned long sp,
25569 unsigned long arg, struct task_struct *p)
25570 {
25571 - struct pt_regs *childregs = task_pt_regs(p);
25572 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
25573 struct task_struct *tsk;
25574 int err;
25575
25576 p->thread.sp = (unsigned long) childregs;
25577 p->thread.sp0 = (unsigned long) (childregs+1);
25578 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25579
25580 if (unlikely(p->flags & PF_KTHREAD)) {
25581 /* kernel thread */
25582 memset(childregs, 0, sizeof(struct pt_regs));
25583 p->thread.ip = (unsigned long) ret_from_kernel_thread;
25584 - task_user_gs(p) = __KERNEL_STACK_CANARY;
25585 - childregs->ds = __USER_DS;
25586 - childregs->es = __USER_DS;
25587 + savesegment(gs, childregs->gs);
25588 + childregs->ds = __KERNEL_DS;
25589 + childregs->es = __KERNEL_DS;
25590 childregs->fs = __KERNEL_PERCPU;
25591 childregs->bx = sp; /* function */
25592 childregs->bp = arg;
25593 @@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25594 struct thread_struct *prev = &prev_p->thread,
25595 *next = &next_p->thread;
25596 int cpu = smp_processor_id();
25597 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
25598 + struct tss_struct *tss = init_tss + cpu;
25599 fpu_switch_t fpu;
25600
25601 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
25602 @@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25603 */
25604 lazy_save_gs(prev->gs);
25605
25606 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25607 + __set_fs(task_thread_info(next_p)->addr_limit);
25608 +#endif
25609 +
25610 /*
25611 * Load the per-thread Thread-Local Storage descriptor.
25612 */
25613 @@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25614 */
25615 arch_end_context_switch(next_p);
25616
25617 + this_cpu_write(current_task, next_p);
25618 + this_cpu_write(current_tinfo, &next_p->tinfo);
25619 +
25620 /*
25621 * Restore %gs if needed (which is common)
25622 */
25623 @@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25624
25625 switch_fpu_finish(next_p, fpu);
25626
25627 - this_cpu_write(current_task, next_p);
25628 -
25629 return prev_p;
25630 }
25631
25632 @@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
25633 } while (count++ < 16);
25634 return 0;
25635 }
25636 -
25637 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
25638 index 9c0280f..5bbb1c0 100644
25639 --- a/arch/x86/kernel/process_64.c
25640 +++ b/arch/x86/kernel/process_64.c
25641 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25642 struct pt_regs *childregs;
25643 struct task_struct *me = current;
25644
25645 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25646 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25647 childregs = task_pt_regs(p);
25648 p->thread.sp = (unsigned long) childregs;
25649 p->thread.usersp = me->thread.usersp;
25650 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25651 set_tsk_thread_flag(p, TIF_FORK);
25652 p->thread.fpu_counter = 0;
25653 p->thread.io_bitmap_ptr = NULL;
25654 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25655 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25656 savesegment(es, p->thread.es);
25657 savesegment(ds, p->thread.ds);
25658 + savesegment(ss, p->thread.ss);
25659 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25660 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25661
25662 if (unlikely(p->flags & PF_KTHREAD)) {
25663 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25664 struct thread_struct *prev = &prev_p->thread;
25665 struct thread_struct *next = &next_p->thread;
25666 int cpu = smp_processor_id();
25667 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
25668 + struct tss_struct *tss = init_tss + cpu;
25669 unsigned fsindex, gsindex;
25670 fpu_switch_t fpu;
25671
25672 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25673 if (unlikely(next->ds | prev->ds))
25674 loadsegment(ds, next->ds);
25675
25676 + savesegment(ss, prev->ss);
25677 + if (unlikely(next->ss != prev->ss))
25678 + loadsegment(ss, next->ss);
25679
25680 /* We must save %fs and %gs before load_TLS() because
25681 * %fs and %gs may be cleared by load_TLS().
25682 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25683 prev->usersp = this_cpu_read(old_rsp);
25684 this_cpu_write(old_rsp, next->usersp);
25685 this_cpu_write(current_task, next_p);
25686 + this_cpu_write(current_tinfo, &next_p->tinfo);
25687
25688 /*
25689 * If it were not for PREEMPT_ACTIVE we could guarantee that the
25690 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25691 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
25692 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
25693
25694 - this_cpu_write(kernel_stack,
25695 - (unsigned long)task_stack_page(next_p) +
25696 - THREAD_SIZE - KERNEL_STACK_OFFSET);
25697 + this_cpu_write(kernel_stack, next->sp0);
25698
25699 /*
25700 * Now maybe reload the debug registers and handle I/O bitmaps
25701 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
25702 if (!p || p == current || p->state == TASK_RUNNING)
25703 return 0;
25704 stack = (unsigned long)task_stack_page(p);
25705 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25706 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25707 return 0;
25708 fp = *(u64 *)(p->thread.sp);
25709 do {
25710 - if (fp < (unsigned long)stack ||
25711 - fp >= (unsigned long)stack+THREAD_SIZE)
25712 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25713 return 0;
25714 ip = *(u64 *)(fp+8);
25715 if (!in_sched_functions(ip))
25716 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25717 index 7461f50..1334029 100644
25718 --- a/arch/x86/kernel/ptrace.c
25719 +++ b/arch/x86/kernel/ptrace.c
25720 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25721 {
25722 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25723 unsigned long sp = (unsigned long)&regs->sp;
25724 - struct thread_info *tinfo;
25725
25726 - if (context == (sp & ~(THREAD_SIZE - 1)))
25727 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25728 return sp;
25729
25730 - tinfo = (struct thread_info *)context;
25731 - if (tinfo->previous_esp)
25732 - return tinfo->previous_esp;
25733 + sp = *(unsigned long *)context;
25734 + if (sp)
25735 + return sp;
25736
25737 return (unsigned long)regs;
25738 }
25739 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25740 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25741 {
25742 int i;
25743 - int dr7 = 0;
25744 + unsigned long dr7 = 0;
25745 struct arch_hw_breakpoint *info;
25746
25747 for (i = 0; i < HBP_NUM; i++) {
25748 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
25749 unsigned long addr, unsigned long data)
25750 {
25751 int ret;
25752 - unsigned long __user *datap = (unsigned long __user *)data;
25753 + unsigned long __user *datap = (__force unsigned long __user *)data;
25754
25755 switch (request) {
25756 /* read the word at location addr in the USER area. */
25757 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
25758 if ((int) addr < 0)
25759 return -EIO;
25760 ret = do_get_thread_area(child, addr,
25761 - (struct user_desc __user *)data);
25762 + (__force struct user_desc __user *) data);
25763 break;
25764
25765 case PTRACE_SET_THREAD_AREA:
25766 if ((int) addr < 0)
25767 return -EIO;
25768 ret = do_set_thread_area(child, addr,
25769 - (struct user_desc __user *)data, 0);
25770 + (__force struct user_desc __user *) data, 0);
25771 break;
25772 #endif
25773
25774 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25775
25776 #ifdef CONFIG_X86_64
25777
25778 -static struct user_regset x86_64_regsets[] __read_mostly = {
25779 +static user_regset_no_const x86_64_regsets[] __read_only = {
25780 [REGSET_GENERAL] = {
25781 .core_note_type = NT_PRSTATUS,
25782 .n = sizeof(struct user_regs_struct) / sizeof(long),
25783 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
25784 #endif /* CONFIG_X86_64 */
25785
25786 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25787 -static struct user_regset x86_32_regsets[] __read_mostly = {
25788 +static user_regset_no_const x86_32_regsets[] __read_only = {
25789 [REGSET_GENERAL] = {
25790 .core_note_type = NT_PRSTATUS,
25791 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25792 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
25793 */
25794 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25795
25796 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25797 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25798 {
25799 #ifdef CONFIG_X86_64
25800 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25801 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25802 memset(info, 0, sizeof(*info));
25803 info->si_signo = SIGTRAP;
25804 info->si_code = si_code;
25805 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25806 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25807 }
25808
25809 void user_single_step_siginfo(struct task_struct *tsk,
25810 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25811 # define IS_IA32 0
25812 #endif
25813
25814 +#ifdef CONFIG_GRKERNSEC_SETXID
25815 +extern void gr_delayed_cred_worker(void);
25816 +#endif
25817 +
25818 /*
25819 * We must return the syscall number to actually look up in the table.
25820 * This can be -1L to skip running any syscall at all.
25821 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25822
25823 user_exit();
25824
25825 +#ifdef CONFIG_GRKERNSEC_SETXID
25826 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25827 + gr_delayed_cred_worker();
25828 +#endif
25829 +
25830 /*
25831 * If we stepped into a sysenter/syscall insn, it trapped in
25832 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25833 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25834 */
25835 user_exit();
25836
25837 +#ifdef CONFIG_GRKERNSEC_SETXID
25838 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25839 + gr_delayed_cred_worker();
25840 +#endif
25841 +
25842 audit_syscall_exit(regs);
25843
25844 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25845 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25846 index 2f355d2..e75ed0a 100644
25847 --- a/arch/x86/kernel/pvclock.c
25848 +++ b/arch/x86/kernel/pvclock.c
25849 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
25850 reset_hung_task_detector();
25851 }
25852
25853 -static atomic64_t last_value = ATOMIC64_INIT(0);
25854 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25855
25856 void pvclock_resume(void)
25857 {
25858 - atomic64_set(&last_value, 0);
25859 + atomic64_set_unchecked(&last_value, 0);
25860 }
25861
25862 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25863 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25864 * updating at the same time, and one of them could be slightly behind,
25865 * making the assumption that last_value always go forward fail to hold.
25866 */
25867 - last = atomic64_read(&last_value);
25868 + last = atomic64_read_unchecked(&last_value);
25869 do {
25870 if (ret < last)
25871 return last;
25872 - last = atomic64_cmpxchg(&last_value, last, ret);
25873 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25874 } while (unlikely(last != ret));
25875
25876 return ret;
25877 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25878 index c752cb4..866c432 100644
25879 --- a/arch/x86/kernel/reboot.c
25880 +++ b/arch/x86/kernel/reboot.c
25881 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25882
25883 void __noreturn machine_real_restart(unsigned int type)
25884 {
25885 +
25886 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25887 + struct desc_struct *gdt;
25888 +#endif
25889 +
25890 local_irq_disable();
25891
25892 /*
25893 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25894
25895 /* Jump to the identity-mapped low memory code */
25896 #ifdef CONFIG_X86_32
25897 - asm volatile("jmpl *%0" : :
25898 +
25899 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25900 + gdt = get_cpu_gdt_table(smp_processor_id());
25901 + pax_open_kernel();
25902 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25903 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25904 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25905 + loadsegment(ds, __KERNEL_DS);
25906 + loadsegment(es, __KERNEL_DS);
25907 + loadsegment(ss, __KERNEL_DS);
25908 +#endif
25909 +#ifdef CONFIG_PAX_KERNEXEC
25910 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25911 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25912 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25913 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25914 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25915 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25916 +#endif
25917 + pax_close_kernel();
25918 +#endif
25919 +
25920 + asm volatile("ljmpl *%0" : :
25921 "rm" (real_mode_header->machine_real_restart_asm),
25922 "a" (type));
25923 #else
25924 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25925 * try to force a triple fault and then cycle between hitting the keyboard
25926 * controller and doing that
25927 */
25928 -static void native_machine_emergency_restart(void)
25929 +static void __noreturn native_machine_emergency_restart(void)
25930 {
25931 int i;
25932 int attempt = 0;
25933 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
25934 #endif
25935 }
25936
25937 -static void __machine_emergency_restart(int emergency)
25938 +static void __noreturn __machine_emergency_restart(int emergency)
25939 {
25940 reboot_emergency = emergency;
25941 machine_ops.emergency_restart();
25942 }
25943
25944 -static void native_machine_restart(char *__unused)
25945 +static void __noreturn native_machine_restart(char *__unused)
25946 {
25947 pr_notice("machine restart\n");
25948
25949 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
25950 __machine_emergency_restart(0);
25951 }
25952
25953 -static void native_machine_halt(void)
25954 +static void __noreturn native_machine_halt(void)
25955 {
25956 /* Stop other cpus and apics */
25957 machine_shutdown();
25958 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
25959 stop_this_cpu(NULL);
25960 }
25961
25962 -static void native_machine_power_off(void)
25963 +static void __noreturn native_machine_power_off(void)
25964 {
25965 if (pm_power_off) {
25966 if (!reboot_force)
25967 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
25968 }
25969 /* A fallback in case there is no PM info available */
25970 tboot_shutdown(TB_SHUTDOWN_HALT);
25971 + unreachable();
25972 }
25973
25974 -struct machine_ops machine_ops = {
25975 +struct machine_ops machine_ops __read_only = {
25976 .power_off = native_machine_power_off,
25977 .shutdown = native_machine_shutdown,
25978 .emergency_restart = native_machine_emergency_restart,
25979 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25980 index c8e41e9..64049ef 100644
25981 --- a/arch/x86/kernel/reboot_fixups_32.c
25982 +++ b/arch/x86/kernel/reboot_fixups_32.c
25983 @@ -57,7 +57,7 @@ struct device_fixup {
25984 unsigned int vendor;
25985 unsigned int device;
25986 void (*reboot_fixup)(struct pci_dev *);
25987 -};
25988 +} __do_const;
25989
25990 /*
25991 * PCI ids solely used for fixups_table go here
25992 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25993 index 3fd2c69..16ef367 100644
25994 --- a/arch/x86/kernel/relocate_kernel_64.S
25995 +++ b/arch/x86/kernel/relocate_kernel_64.S
25996 @@ -11,6 +11,7 @@
25997 #include <asm/kexec.h>
25998 #include <asm/processor-flags.h>
25999 #include <asm/pgtable_types.h>
26000 +#include <asm/alternative-asm.h>
26001
26002 /*
26003 * Must be relocatable PIC code callable as a C function
26004 @@ -96,8 +97,7 @@ relocate_kernel:
26005
26006 /* jump to identity mapped page */
26007 addq $(identity_mapped - relocate_kernel), %r8
26008 - pushq %r8
26009 - ret
26010 + jmp *%r8
26011
26012 identity_mapped:
26013 /* set return address to 0 if not preserving context */
26014 @@ -167,6 +167,7 @@ identity_mapped:
26015 xorl %r14d, %r14d
26016 xorl %r15d, %r15d
26017
26018 + pax_force_retaddr 0, 1
26019 ret
26020
26021 1:
26022 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26023 index cb233bc..23b4879 100644
26024 --- a/arch/x86/kernel/setup.c
26025 +++ b/arch/x86/kernel/setup.c
26026 @@ -110,6 +110,7 @@
26027 #include <asm/mce.h>
26028 #include <asm/alternative.h>
26029 #include <asm/prom.h>
26030 +#include <asm/boot.h>
26031
26032 /*
26033 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26034 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26035 #endif
26036
26037
26038 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26039 -__visible unsigned long mmu_cr4_features;
26040 +#ifdef CONFIG_X86_64
26041 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26042 +#elif defined(CONFIG_X86_PAE)
26043 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26044 #else
26045 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26046 +__visible unsigned long mmu_cr4_features __read_only;
26047 #endif
26048
26049 +void set_in_cr4(unsigned long mask)
26050 +{
26051 + unsigned long cr4 = read_cr4();
26052 +
26053 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26054 + return;
26055 +
26056 + pax_open_kernel();
26057 + mmu_cr4_features |= mask;
26058 + pax_close_kernel();
26059 +
26060 + if (trampoline_cr4_features)
26061 + *trampoline_cr4_features = mmu_cr4_features;
26062 + cr4 |= mask;
26063 + write_cr4(cr4);
26064 +}
26065 +EXPORT_SYMBOL(set_in_cr4);
26066 +
26067 +void clear_in_cr4(unsigned long mask)
26068 +{
26069 + unsigned long cr4 = read_cr4();
26070 +
26071 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26072 + return;
26073 +
26074 + pax_open_kernel();
26075 + mmu_cr4_features &= ~mask;
26076 + pax_close_kernel();
26077 +
26078 + if (trampoline_cr4_features)
26079 + *trampoline_cr4_features = mmu_cr4_features;
26080 + cr4 &= ~mask;
26081 + write_cr4(cr4);
26082 +}
26083 +EXPORT_SYMBOL(clear_in_cr4);
26084 +
26085 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26086 int bootloader_type, bootloader_version;
26087
26088 @@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26089 * area (640->1Mb) as ram even though it is not.
26090 * take them out.
26091 */
26092 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26093 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26094
26095 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26096 }
26097 @@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26098 /* called before trim_bios_range() to spare extra sanitize */
26099 static void __init e820_add_kernel_range(void)
26100 {
26101 - u64 start = __pa_symbol(_text);
26102 + u64 start = __pa_symbol(ktla_ktva(_text));
26103 u64 size = __pa_symbol(_end) - start;
26104
26105 /*
26106 @@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26107
26108 void __init setup_arch(char **cmdline_p)
26109 {
26110 +#ifdef CONFIG_X86_32
26111 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26112 +#else
26113 memblock_reserve(__pa_symbol(_text),
26114 (unsigned long)__bss_stop - (unsigned long)_text);
26115 +#endif
26116
26117 early_reserve_initrd();
26118
26119 @@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26120
26121 if (!boot_params.hdr.root_flags)
26122 root_mountflags &= ~MS_RDONLY;
26123 - init_mm.start_code = (unsigned long) _text;
26124 - init_mm.end_code = (unsigned long) _etext;
26125 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26126 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26127 init_mm.end_data = (unsigned long) _edata;
26128 init_mm.brk = _brk_end;
26129
26130 - code_resource.start = __pa_symbol(_text);
26131 - code_resource.end = __pa_symbol(_etext)-1;
26132 - data_resource.start = __pa_symbol(_etext);
26133 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26134 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26135 + data_resource.start = __pa_symbol(_sdata);
26136 data_resource.end = __pa_symbol(_edata)-1;
26137 bss_resource.start = __pa_symbol(__bss_start);
26138 bss_resource.end = __pa_symbol(__bss_stop)-1;
26139 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26140 index 5cdff03..80fa283 100644
26141 --- a/arch/x86/kernel/setup_percpu.c
26142 +++ b/arch/x86/kernel/setup_percpu.c
26143 @@ -21,19 +21,17 @@
26144 #include <asm/cpu.h>
26145 #include <asm/stackprotector.h>
26146
26147 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26148 +#ifdef CONFIG_SMP
26149 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26150 EXPORT_PER_CPU_SYMBOL(cpu_number);
26151 +#endif
26152
26153 -#ifdef CONFIG_X86_64
26154 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26155 -#else
26156 -#define BOOT_PERCPU_OFFSET 0
26157 -#endif
26158
26159 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26160 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26161
26162 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26163 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26164 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26165 };
26166 EXPORT_SYMBOL(__per_cpu_offset);
26167 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26168 {
26169 #ifdef CONFIG_NEED_MULTIPLE_NODES
26170 pg_data_t *last = NULL;
26171 - unsigned int cpu;
26172 + int cpu;
26173
26174 for_each_possible_cpu(cpu) {
26175 int node = early_cpu_to_node(cpu);
26176 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26177 {
26178 #ifdef CONFIG_X86_32
26179 struct desc_struct gdt;
26180 + unsigned long base = per_cpu_offset(cpu);
26181
26182 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26183 - 0x2 | DESCTYPE_S, 0x8);
26184 - gdt.s = 1;
26185 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26186 + 0x83 | DESCTYPE_S, 0xC);
26187 write_gdt_entry(get_cpu_gdt_table(cpu),
26188 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26189 #endif
26190 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26191 /* alrighty, percpu areas up and running */
26192 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26193 for_each_possible_cpu(cpu) {
26194 +#ifdef CONFIG_CC_STACKPROTECTOR
26195 +#ifdef CONFIG_X86_32
26196 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26197 +#endif
26198 +#endif
26199 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26200 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26201 per_cpu(cpu_number, cpu) = cpu;
26202 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26203 */
26204 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26205 #endif
26206 +#ifdef CONFIG_CC_STACKPROTECTOR
26207 +#ifdef CONFIG_X86_32
26208 + if (!cpu)
26209 + per_cpu(stack_canary.canary, cpu) = canary;
26210 +#endif
26211 +#endif
26212 /*
26213 * Up to this point, the boot CPU has been using .init.data
26214 * area. Reload any changed state for the boot CPU.
26215 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26216 index 9e5de68..16c53cb 100644
26217 --- a/arch/x86/kernel/signal.c
26218 +++ b/arch/x86/kernel/signal.c
26219 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26220 * Align the stack pointer according to the i386 ABI,
26221 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26222 */
26223 - sp = ((sp + 4) & -16ul) - 4;
26224 + sp = ((sp - 12) & -16ul) - 4;
26225 #else /* !CONFIG_X86_32 */
26226 sp = round_down(sp, 16) - 8;
26227 #endif
26228 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26229 }
26230
26231 if (current->mm->context.vdso)
26232 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26233 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26234 else
26235 - restorer = &frame->retcode;
26236 + restorer = (void __user *)&frame->retcode;
26237 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26238 restorer = ksig->ka.sa.sa_restorer;
26239
26240 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26241 * reasons and because gdb uses it as a signature to notice
26242 * signal handler stack frames.
26243 */
26244 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26245 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26246
26247 if (err)
26248 return -EFAULT;
26249 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26250 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26251
26252 /* Set up to return from userspace. */
26253 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26254 + if (current->mm->context.vdso)
26255 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26256 + else
26257 + restorer = (void __user *)&frame->retcode;
26258 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26259 restorer = ksig->ka.sa.sa_restorer;
26260 put_user_ex(restorer, &frame->pretcode);
26261 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26262 * reasons and because gdb uses it as a signature to notice
26263 * signal handler stack frames.
26264 */
26265 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26266 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26267 } put_user_catch(err);
26268
26269 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26270 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26271 {
26272 int usig = signr_convert(ksig->sig);
26273 sigset_t *set = sigmask_to_save();
26274 - compat_sigset_t *cset = (compat_sigset_t *) set;
26275 + sigset_t sigcopy;
26276 + compat_sigset_t *cset;
26277 +
26278 + sigcopy = *set;
26279 +
26280 + cset = (compat_sigset_t *) &sigcopy;
26281
26282 /* Set up the stack frame */
26283 if (is_ia32_frame()) {
26284 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26285 } else if (is_x32_frame()) {
26286 return x32_setup_rt_frame(ksig, cset, regs);
26287 } else {
26288 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26289 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26290 }
26291 }
26292
26293 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26294 index 7c3a5a6..f0a8961 100644
26295 --- a/arch/x86/kernel/smp.c
26296 +++ b/arch/x86/kernel/smp.c
26297 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26298
26299 __setup("nonmi_ipi", nonmi_ipi_setup);
26300
26301 -struct smp_ops smp_ops = {
26302 +struct smp_ops smp_ops __read_only = {
26303 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26304 .smp_prepare_cpus = native_smp_prepare_cpus,
26305 .smp_cpus_done = native_smp_cpus_done,
26306 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26307 index 85dc05a..1241266 100644
26308 --- a/arch/x86/kernel/smpboot.c
26309 +++ b/arch/x86/kernel/smpboot.c
26310 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26311
26312 enable_start_cpu0 = 0;
26313
26314 -#ifdef CONFIG_X86_32
26315 - /* switch away from the initial page table */
26316 - load_cr3(swapper_pg_dir);
26317 - __flush_tlb_all();
26318 -#endif
26319 -
26320 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26321 barrier();
26322 +
26323 + /* switch away from the initial page table */
26324 +#ifdef CONFIG_PAX_PER_CPU_PGD
26325 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26326 + __flush_tlb_all();
26327 +#elif defined(CONFIG_X86_32)
26328 + load_cr3(swapper_pg_dir);
26329 + __flush_tlb_all();
26330 +#endif
26331 +
26332 /*
26333 * Check TSC synchronization with the BP:
26334 */
26335 @@ -751,6 +755,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26336 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26337 (THREAD_SIZE + task_stack_page(idle))) - 1);
26338 per_cpu(current_task, cpu) = idle;
26339 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26340
26341 #ifdef CONFIG_X86_32
26342 /* Stack for startup_32 can be just as for start_secondary onwards */
26343 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26344 #else
26345 clear_tsk_thread_flag(idle, TIF_FORK);
26346 initial_gs = per_cpu_offset(cpu);
26347 - per_cpu(kernel_stack, cpu) =
26348 - (unsigned long)task_stack_page(idle) -
26349 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26350 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26351 #endif
26352 +
26353 + pax_open_kernel();
26354 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26355 + pax_close_kernel();
26356 +
26357 initial_code = (unsigned long)start_secondary;
26358 stack_start = idle->thread.sp;
26359
26360 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26361 /* the FPU context is blank, nobody can own it */
26362 __cpu_disable_lazy_restore(cpu);
26363
26364 +#ifdef CONFIG_PAX_PER_CPU_PGD
26365 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26366 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26367 + KERNEL_PGD_PTRS);
26368 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26369 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26370 + KERNEL_PGD_PTRS);
26371 +#endif
26372 +
26373 err = do_boot_cpu(apicid, cpu, tidle);
26374 if (err) {
26375 pr_debug("do_boot_cpu failed %d\n", err);
26376 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26377 index 9b4d51d..5d28b58 100644
26378 --- a/arch/x86/kernel/step.c
26379 +++ b/arch/x86/kernel/step.c
26380 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26381 struct desc_struct *desc;
26382 unsigned long base;
26383
26384 - seg &= ~7UL;
26385 + seg >>= 3;
26386
26387 mutex_lock(&child->mm->context.lock);
26388 - if (unlikely((seg >> 3) >= child->mm->context.size))
26389 + if (unlikely(seg >= child->mm->context.size))
26390 addr = -1L; /* bogus selector, access would fault */
26391 else {
26392 desc = child->mm->context.ldt + seg;
26393 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26394 addr += base;
26395 }
26396 mutex_unlock(&child->mm->context.lock);
26397 - }
26398 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26399 + addr = ktla_ktva(addr);
26400
26401 return addr;
26402 }
26403 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26404 unsigned char opcode[15];
26405 unsigned long addr = convert_ip_to_linear(child, regs);
26406
26407 + if (addr == -EINVAL)
26408 + return 0;
26409 +
26410 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26411 for (i = 0; i < copied; i++) {
26412 switch (opcode[i]) {
26413 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26414 new file mode 100644
26415 index 0000000..5877189
26416 --- /dev/null
26417 +++ b/arch/x86/kernel/sys_i386_32.c
26418 @@ -0,0 +1,189 @@
26419 +/*
26420 + * This file contains various random system calls that
26421 + * have a non-standard calling sequence on the Linux/i386
26422 + * platform.
26423 + */
26424 +
26425 +#include <linux/errno.h>
26426 +#include <linux/sched.h>
26427 +#include <linux/mm.h>
26428 +#include <linux/fs.h>
26429 +#include <linux/smp.h>
26430 +#include <linux/sem.h>
26431 +#include <linux/msg.h>
26432 +#include <linux/shm.h>
26433 +#include <linux/stat.h>
26434 +#include <linux/syscalls.h>
26435 +#include <linux/mman.h>
26436 +#include <linux/file.h>
26437 +#include <linux/utsname.h>
26438 +#include <linux/ipc.h>
26439 +#include <linux/elf.h>
26440 +
26441 +#include <linux/uaccess.h>
26442 +#include <linux/unistd.h>
26443 +
26444 +#include <asm/syscalls.h>
26445 +
26446 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26447 +{
26448 + unsigned long pax_task_size = TASK_SIZE;
26449 +
26450 +#ifdef CONFIG_PAX_SEGMEXEC
26451 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26452 + pax_task_size = SEGMEXEC_TASK_SIZE;
26453 +#endif
26454 +
26455 + if (flags & MAP_FIXED)
26456 + if (len > pax_task_size || addr > pax_task_size - len)
26457 + return -EINVAL;
26458 +
26459 + return 0;
26460 +}
26461 +
26462 +/*
26463 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26464 + */
26465 +static unsigned long get_align_mask(void)
26466 +{
26467 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26468 + return 0;
26469 +
26470 + if (!(current->flags & PF_RANDOMIZE))
26471 + return 0;
26472 +
26473 + return va_align.mask;
26474 +}
26475 +
26476 +unsigned long
26477 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
26478 + unsigned long len, unsigned long pgoff, unsigned long flags)
26479 +{
26480 + struct mm_struct *mm = current->mm;
26481 + struct vm_area_struct *vma;
26482 + unsigned long pax_task_size = TASK_SIZE;
26483 + struct vm_unmapped_area_info info;
26484 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26485 +
26486 +#ifdef CONFIG_PAX_SEGMEXEC
26487 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26488 + pax_task_size = SEGMEXEC_TASK_SIZE;
26489 +#endif
26490 +
26491 + pax_task_size -= PAGE_SIZE;
26492 +
26493 + if (len > pax_task_size)
26494 + return -ENOMEM;
26495 +
26496 + if (flags & MAP_FIXED)
26497 + return addr;
26498 +
26499 +#ifdef CONFIG_PAX_RANDMMAP
26500 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26501 +#endif
26502 +
26503 + if (addr) {
26504 + addr = PAGE_ALIGN(addr);
26505 + if (pax_task_size - len >= addr) {
26506 + vma = find_vma(mm, addr);
26507 + if (check_heap_stack_gap(vma, addr, len, offset))
26508 + return addr;
26509 + }
26510 + }
26511 +
26512 + info.flags = 0;
26513 + info.length = len;
26514 + info.align_mask = filp ? get_align_mask() : 0;
26515 + info.align_offset = pgoff << PAGE_SHIFT;
26516 + info.threadstack_offset = offset;
26517 +
26518 +#ifdef CONFIG_PAX_PAGEEXEC
26519 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26520 + info.low_limit = 0x00110000UL;
26521 + info.high_limit = mm->start_code;
26522 +
26523 +#ifdef CONFIG_PAX_RANDMMAP
26524 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26525 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26526 +#endif
26527 +
26528 + if (info.low_limit < info.high_limit) {
26529 + addr = vm_unmapped_area(&info);
26530 + if (!IS_ERR_VALUE(addr))
26531 + return addr;
26532 + }
26533 + } else
26534 +#endif
26535 +
26536 + info.low_limit = mm->mmap_base;
26537 + info.high_limit = pax_task_size;
26538 +
26539 + return vm_unmapped_area(&info);
26540 +}
26541 +
26542 +unsigned long
26543 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26544 + const unsigned long len, const unsigned long pgoff,
26545 + const unsigned long flags)
26546 +{
26547 + struct vm_area_struct *vma;
26548 + struct mm_struct *mm = current->mm;
26549 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
26550 + struct vm_unmapped_area_info info;
26551 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26552 +
26553 +#ifdef CONFIG_PAX_SEGMEXEC
26554 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26555 + pax_task_size = SEGMEXEC_TASK_SIZE;
26556 +#endif
26557 +
26558 + pax_task_size -= PAGE_SIZE;
26559 +
26560 + /* requested length too big for entire address space */
26561 + if (len > pax_task_size)
26562 + return -ENOMEM;
26563 +
26564 + if (flags & MAP_FIXED)
26565 + return addr;
26566 +
26567 +#ifdef CONFIG_PAX_PAGEEXEC
26568 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
26569 + goto bottomup;
26570 +#endif
26571 +
26572 +#ifdef CONFIG_PAX_RANDMMAP
26573 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26574 +#endif
26575 +
26576 + /* requesting a specific address */
26577 + if (addr) {
26578 + addr = PAGE_ALIGN(addr);
26579 + if (pax_task_size - len >= addr) {
26580 + vma = find_vma(mm, addr);
26581 + if (check_heap_stack_gap(vma, addr, len, offset))
26582 + return addr;
26583 + }
26584 + }
26585 +
26586 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
26587 + info.length = len;
26588 + info.low_limit = PAGE_SIZE;
26589 + info.high_limit = mm->mmap_base;
26590 + info.align_mask = filp ? get_align_mask() : 0;
26591 + info.align_offset = pgoff << PAGE_SHIFT;
26592 + info.threadstack_offset = offset;
26593 +
26594 + addr = vm_unmapped_area(&info);
26595 + if (!(addr & ~PAGE_MASK))
26596 + return addr;
26597 + VM_BUG_ON(addr != -ENOMEM);
26598 +
26599 +bottomup:
26600 + /*
26601 + * A failed mmap() very likely causes application failure,
26602 + * so fall back to the bottom-up function here. This scenario
26603 + * can happen with large stack limits and large mmap()
26604 + * allocations.
26605 + */
26606 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
26607 +}
26608 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
26609 index 30277e2..5664a29 100644
26610 --- a/arch/x86/kernel/sys_x86_64.c
26611 +++ b/arch/x86/kernel/sys_x86_64.c
26612 @@ -81,8 +81,8 @@ out:
26613 return error;
26614 }
26615
26616 -static void find_start_end(unsigned long flags, unsigned long *begin,
26617 - unsigned long *end)
26618 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
26619 + unsigned long *begin, unsigned long *end)
26620 {
26621 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
26622 unsigned long new_begin;
26623 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
26624 *begin = new_begin;
26625 }
26626 } else {
26627 - *begin = current->mm->mmap_legacy_base;
26628 + *begin = mm->mmap_legacy_base;
26629 *end = TASK_SIZE;
26630 }
26631 }
26632 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26633 struct vm_area_struct *vma;
26634 struct vm_unmapped_area_info info;
26635 unsigned long begin, end;
26636 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26637
26638 if (flags & MAP_FIXED)
26639 return addr;
26640
26641 - find_start_end(flags, &begin, &end);
26642 + find_start_end(mm, flags, &begin, &end);
26643
26644 if (len > end)
26645 return -ENOMEM;
26646
26647 +#ifdef CONFIG_PAX_RANDMMAP
26648 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26649 +#endif
26650 +
26651 if (addr) {
26652 addr = PAGE_ALIGN(addr);
26653 vma = find_vma(mm, addr);
26654 - if (end - len >= addr &&
26655 - (!vma || addr + len <= vma->vm_start))
26656 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26657 return addr;
26658 }
26659
26660 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26661 info.high_limit = end;
26662 info.align_mask = filp ? get_align_mask() : 0;
26663 info.align_offset = pgoff << PAGE_SHIFT;
26664 + info.threadstack_offset = offset;
26665 return vm_unmapped_area(&info);
26666 }
26667
26668 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26669 struct mm_struct *mm = current->mm;
26670 unsigned long addr = addr0;
26671 struct vm_unmapped_area_info info;
26672 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26673
26674 /* requested length too big for entire address space */
26675 if (len > TASK_SIZE)
26676 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26677 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26678 goto bottomup;
26679
26680 +#ifdef CONFIG_PAX_RANDMMAP
26681 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26682 +#endif
26683 +
26684 /* requesting a specific address */
26685 if (addr) {
26686 addr = PAGE_ALIGN(addr);
26687 vma = find_vma(mm, addr);
26688 - if (TASK_SIZE - len >= addr &&
26689 - (!vma || addr + len <= vma->vm_start))
26690 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26691 return addr;
26692 }
26693
26694 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26695 info.high_limit = mm->mmap_base;
26696 info.align_mask = filp ? get_align_mask() : 0;
26697 info.align_offset = pgoff << PAGE_SHIFT;
26698 + info.threadstack_offset = offset;
26699 addr = vm_unmapped_area(&info);
26700 if (!(addr & ~PAGE_MASK))
26701 return addr;
26702 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26703 index 91a4496..bb87552 100644
26704 --- a/arch/x86/kernel/tboot.c
26705 +++ b/arch/x86/kernel/tboot.c
26706 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
26707
26708 void tboot_shutdown(u32 shutdown_type)
26709 {
26710 - void (*shutdown)(void);
26711 + void (* __noreturn shutdown)(void);
26712
26713 if (!tboot_enabled())
26714 return;
26715 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
26716
26717 switch_to_tboot_pt();
26718
26719 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26720 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
26721 shutdown();
26722
26723 /* should not reach here */
26724 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
26725 return -ENODEV;
26726 }
26727
26728 -static atomic_t ap_wfs_count;
26729 +static atomic_unchecked_t ap_wfs_count;
26730
26731 static int tboot_wait_for_aps(int num_aps)
26732 {
26733 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
26734 {
26735 switch (action) {
26736 case CPU_DYING:
26737 - atomic_inc(&ap_wfs_count);
26738 + atomic_inc_unchecked(&ap_wfs_count);
26739 if (num_online_cpus() == 1)
26740 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26741 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26742 return NOTIFY_BAD;
26743 break;
26744 }
26745 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
26746
26747 tboot_create_trampoline();
26748
26749 - atomic_set(&ap_wfs_count, 0);
26750 + atomic_set_unchecked(&ap_wfs_count, 0);
26751 register_hotcpu_notifier(&tboot_cpu_notifier);
26752
26753 #ifdef CONFIG_DEBUG_FS
26754 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26755 index 24d3c91..d06b473 100644
26756 --- a/arch/x86/kernel/time.c
26757 +++ b/arch/x86/kernel/time.c
26758 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26759 {
26760 unsigned long pc = instruction_pointer(regs);
26761
26762 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26763 + if (!user_mode(regs) && in_lock_functions(pc)) {
26764 #ifdef CONFIG_FRAME_POINTER
26765 - return *(unsigned long *)(regs->bp + sizeof(long));
26766 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26767 #else
26768 unsigned long *sp =
26769 (unsigned long *)kernel_stack_pointer(regs);
26770 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26771 * or above a saved flags. Eflags has bits 22-31 zero,
26772 * kernel addresses don't.
26773 */
26774 +
26775 +#ifdef CONFIG_PAX_KERNEXEC
26776 + return ktla_ktva(sp[0]);
26777 +#else
26778 if (sp[0] >> 22)
26779 return sp[0];
26780 if (sp[1] >> 22)
26781 return sp[1];
26782 #endif
26783 +
26784 +#endif
26785 }
26786 return pc;
26787 }
26788 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26789 index f7fec09..9991981 100644
26790 --- a/arch/x86/kernel/tls.c
26791 +++ b/arch/x86/kernel/tls.c
26792 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26793 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26794 return -EINVAL;
26795
26796 +#ifdef CONFIG_PAX_SEGMEXEC
26797 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26798 + return -EINVAL;
26799 +#endif
26800 +
26801 set_tls_desc(p, idx, &info, 1);
26802
26803 return 0;
26804 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26805
26806 if (kbuf)
26807 info = kbuf;
26808 - else if (__copy_from_user(infobuf, ubuf, count))
26809 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26810 return -EFAULT;
26811 else
26812 info = infobuf;
26813 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
26814 index 1c113db..287b42e 100644
26815 --- a/arch/x86/kernel/tracepoint.c
26816 +++ b/arch/x86/kernel/tracepoint.c
26817 @@ -9,11 +9,11 @@
26818 #include <linux/atomic.h>
26819
26820 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
26821 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26822 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26823 (unsigned long) trace_idt_table };
26824
26825 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26826 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
26827 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
26828
26829 static int trace_irq_vector_refcount;
26830 static DEFINE_MUTEX(irq_vector_mutex);
26831 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26832 index b857ed8..51ae4cb 100644
26833 --- a/arch/x86/kernel/traps.c
26834 +++ b/arch/x86/kernel/traps.c
26835 @@ -66,7 +66,7 @@
26836 #include <asm/proto.h>
26837
26838 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26839 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
26840 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
26841 #else
26842 #include <asm/processor-flags.h>
26843 #include <asm/setup.h>
26844 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
26845 #endif
26846
26847 /* Must be page-aligned because the real IDT is used in a fixmap. */
26848 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
26849 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
26850
26851 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26852 EXPORT_SYMBOL_GPL(used_vectors);
26853 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26854 }
26855
26856 static int __kprobes
26857 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26858 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26859 struct pt_regs *regs, long error_code)
26860 {
26861 #ifdef CONFIG_X86_32
26862 - if (regs->flags & X86_VM_MASK) {
26863 + if (v8086_mode(regs)) {
26864 /*
26865 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26866 * On nmi (interrupt 2), do_trap should not be called.
26867 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26868 return -1;
26869 }
26870 #endif
26871 - if (!user_mode(regs)) {
26872 + if (!user_mode_novm(regs)) {
26873 if (!fixup_exception(regs)) {
26874 tsk->thread.error_code = error_code;
26875 tsk->thread.trap_nr = trapnr;
26876 +
26877 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26878 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26879 + str = "PAX: suspicious stack segment fault";
26880 +#endif
26881 +
26882 die(str, regs, error_code);
26883 }
26884 +
26885 +#ifdef CONFIG_PAX_REFCOUNT
26886 + if (trapnr == 4)
26887 + pax_report_refcount_overflow(regs);
26888 +#endif
26889 +
26890 return 0;
26891 }
26892
26893 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26894 }
26895
26896 static void __kprobes
26897 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26898 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26899 long error_code, siginfo_t *info)
26900 {
26901 struct task_struct *tsk = current;
26902 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26903 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26904 printk_ratelimit()) {
26905 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26906 - tsk->comm, tsk->pid, str,
26907 + tsk->comm, task_pid_nr(tsk), str,
26908 regs->ip, regs->sp, error_code);
26909 print_vma_addr(" in ", regs->ip);
26910 pr_cont("\n");
26911 @@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26912 conditional_sti(regs);
26913
26914 #ifdef CONFIG_X86_32
26915 - if (regs->flags & X86_VM_MASK) {
26916 + if (v8086_mode(regs)) {
26917 local_irq_enable();
26918 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26919 goto exit;
26920 @@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26921 #endif
26922
26923 tsk = current;
26924 - if (!user_mode(regs)) {
26925 + if (!user_mode_novm(regs)) {
26926 if (fixup_exception(regs))
26927 goto exit;
26928
26929 tsk->thread.error_code = error_code;
26930 tsk->thread.trap_nr = X86_TRAP_GP;
26931 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26932 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26933 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26934 +
26935 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26936 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26937 + die("PAX: suspicious general protection fault", regs, error_code);
26938 + else
26939 +#endif
26940 +
26941 die("general protection fault", regs, error_code);
26942 + }
26943 goto exit;
26944 }
26945
26946 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26947 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26948 + struct mm_struct *mm = tsk->mm;
26949 + unsigned long limit;
26950 +
26951 + down_write(&mm->mmap_sem);
26952 + limit = mm->context.user_cs_limit;
26953 + if (limit < TASK_SIZE) {
26954 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26955 + up_write(&mm->mmap_sem);
26956 + return;
26957 + }
26958 + up_write(&mm->mmap_sem);
26959 + }
26960 +#endif
26961 +
26962 tsk->thread.error_code = error_code;
26963 tsk->thread.trap_nr = X86_TRAP_GP;
26964
26965 @@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26966 /* It's safe to allow irq's after DR6 has been saved */
26967 preempt_conditional_sti(regs);
26968
26969 - if (regs->flags & X86_VM_MASK) {
26970 + if (v8086_mode(regs)) {
26971 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26972 X86_TRAP_DB);
26973 preempt_conditional_cli(regs);
26974 @@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26975 * We already checked v86 mode above, so we can check for kernel mode
26976 * by just checking the CPL of CS.
26977 */
26978 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
26979 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26980 tsk->thread.debugreg6 &= ~DR_STEP;
26981 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26982 regs->flags &= ~X86_EFLAGS_TF;
26983 @@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26984 return;
26985 conditional_sti(regs);
26986
26987 - if (!user_mode_vm(regs))
26988 + if (!user_mode(regs))
26989 {
26990 if (!fixup_exception(regs)) {
26991 task->thread.error_code = error_code;
26992 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26993 index 2ed8459..7cf329f 100644
26994 --- a/arch/x86/kernel/uprobes.c
26995 +++ b/arch/x86/kernel/uprobes.c
26996 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26997 int ret = NOTIFY_DONE;
26998
26999 /* We are only interested in userspace traps */
27000 - if (regs && !user_mode_vm(regs))
27001 + if (regs && !user_mode(regs))
27002 return NOTIFY_DONE;
27003
27004 switch (val) {
27005 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27006
27007 if (ncopied != rasize) {
27008 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27009 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27010 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27011
27012 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27013 }
27014 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27015 index b9242ba..50c5edd 100644
27016 --- a/arch/x86/kernel/verify_cpu.S
27017 +++ b/arch/x86/kernel/verify_cpu.S
27018 @@ -20,6 +20,7 @@
27019 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27020 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27021 * arch/x86/kernel/head_32.S: processor startup
27022 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27023 *
27024 * verify_cpu, returns the status of longmode and SSE in register %eax.
27025 * 0: Success 1: Failure
27026 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27027 index e8edcf5..27f9344 100644
27028 --- a/arch/x86/kernel/vm86_32.c
27029 +++ b/arch/x86/kernel/vm86_32.c
27030 @@ -44,6 +44,7 @@
27031 #include <linux/ptrace.h>
27032 #include <linux/audit.h>
27033 #include <linux/stddef.h>
27034 +#include <linux/grsecurity.h>
27035
27036 #include <asm/uaccess.h>
27037 #include <asm/io.h>
27038 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27039 do_exit(SIGSEGV);
27040 }
27041
27042 - tss = &per_cpu(init_tss, get_cpu());
27043 + tss = init_tss + get_cpu();
27044 current->thread.sp0 = current->thread.saved_sp0;
27045 current->thread.sysenter_cs = __KERNEL_CS;
27046 load_sp0(tss, &current->thread);
27047 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27048
27049 if (tsk->thread.saved_sp0)
27050 return -EPERM;
27051 +
27052 +#ifdef CONFIG_GRKERNSEC_VM86
27053 + if (!capable(CAP_SYS_RAWIO)) {
27054 + gr_handle_vm86();
27055 + return -EPERM;
27056 + }
27057 +#endif
27058 +
27059 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27060 offsetof(struct kernel_vm86_struct, vm86plus) -
27061 sizeof(info.regs));
27062 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27063 int tmp;
27064 struct vm86plus_struct __user *v86;
27065
27066 +#ifdef CONFIG_GRKERNSEC_VM86
27067 + if (!capable(CAP_SYS_RAWIO)) {
27068 + gr_handle_vm86();
27069 + return -EPERM;
27070 + }
27071 +#endif
27072 +
27073 tsk = current;
27074 switch (cmd) {
27075 case VM86_REQUEST_IRQ:
27076 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27077 tsk->thread.saved_fs = info->regs32->fs;
27078 tsk->thread.saved_gs = get_user_gs(info->regs32);
27079
27080 - tss = &per_cpu(init_tss, get_cpu());
27081 + tss = init_tss + get_cpu();
27082 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27083 if (cpu_has_sep)
27084 tsk->thread.sysenter_cs = 0;
27085 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27086 goto cannot_handle;
27087 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27088 goto cannot_handle;
27089 - intr_ptr = (unsigned long __user *) (i << 2);
27090 + intr_ptr = (__force unsigned long __user *) (i << 2);
27091 if (get_user(segoffs, intr_ptr))
27092 goto cannot_handle;
27093 if ((segoffs >> 16) == BIOSSEG)
27094 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27095 index da6b35a..977e9cf 100644
27096 --- a/arch/x86/kernel/vmlinux.lds.S
27097 +++ b/arch/x86/kernel/vmlinux.lds.S
27098 @@ -26,6 +26,13 @@
27099 #include <asm/page_types.h>
27100 #include <asm/cache.h>
27101 #include <asm/boot.h>
27102 +#include <asm/segment.h>
27103 +
27104 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27105 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27106 +#else
27107 +#define __KERNEL_TEXT_OFFSET 0
27108 +#endif
27109
27110 #undef i386 /* in case the preprocessor is a 32bit one */
27111
27112 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27113
27114 PHDRS {
27115 text PT_LOAD FLAGS(5); /* R_E */
27116 +#ifdef CONFIG_X86_32
27117 + module PT_LOAD FLAGS(5); /* R_E */
27118 +#endif
27119 +#ifdef CONFIG_XEN
27120 + rodata PT_LOAD FLAGS(5); /* R_E */
27121 +#else
27122 + rodata PT_LOAD FLAGS(4); /* R__ */
27123 +#endif
27124 data PT_LOAD FLAGS(6); /* RW_ */
27125 -#ifdef CONFIG_X86_64
27126 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27127 #ifdef CONFIG_SMP
27128 percpu PT_LOAD FLAGS(6); /* RW_ */
27129 #endif
27130 + text.init PT_LOAD FLAGS(5); /* R_E */
27131 + text.exit PT_LOAD FLAGS(5); /* R_E */
27132 init PT_LOAD FLAGS(7); /* RWE */
27133 -#endif
27134 note PT_NOTE FLAGS(0); /* ___ */
27135 }
27136
27137 SECTIONS
27138 {
27139 #ifdef CONFIG_X86_32
27140 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27141 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27142 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27143 #else
27144 - . = __START_KERNEL;
27145 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27146 + . = __START_KERNEL;
27147 #endif
27148
27149 /* Text and read-only data */
27150 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27151 - _text = .;
27152 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27153 /* bootstrapping code */
27154 +#ifdef CONFIG_X86_32
27155 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27156 +#else
27157 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27158 +#endif
27159 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27160 + _text = .;
27161 HEAD_TEXT
27162 . = ALIGN(8);
27163 _stext = .;
27164 @@ -104,13 +124,47 @@ SECTIONS
27165 IRQENTRY_TEXT
27166 *(.fixup)
27167 *(.gnu.warning)
27168 - /* End of text section */
27169 - _etext = .;
27170 } :text = 0x9090
27171
27172 - NOTES :text :note
27173 + . += __KERNEL_TEXT_OFFSET;
27174
27175 - EXCEPTION_TABLE(16) :text = 0x9090
27176 +#ifdef CONFIG_X86_32
27177 + . = ALIGN(PAGE_SIZE);
27178 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27179 +
27180 +#ifdef CONFIG_PAX_KERNEXEC
27181 + MODULES_EXEC_VADDR = .;
27182 + BYTE(0)
27183 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27184 + . = ALIGN(HPAGE_SIZE) - 1;
27185 + MODULES_EXEC_END = .;
27186 +#endif
27187 +
27188 + } :module
27189 +#endif
27190 +
27191 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27192 + /* End of text section */
27193 + BYTE(0)
27194 + _etext = . - __KERNEL_TEXT_OFFSET;
27195 + }
27196 +
27197 +#ifdef CONFIG_X86_32
27198 + . = ALIGN(PAGE_SIZE);
27199 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27200 + . = ALIGN(PAGE_SIZE);
27201 + *(.empty_zero_page)
27202 + *(.initial_pg_fixmap)
27203 + *(.initial_pg_pmd)
27204 + *(.initial_page_table)
27205 + *(.swapper_pg_dir)
27206 + } :rodata
27207 +#endif
27208 +
27209 + . = ALIGN(PAGE_SIZE);
27210 + NOTES :rodata :note
27211 +
27212 + EXCEPTION_TABLE(16) :rodata
27213
27214 #if defined(CONFIG_DEBUG_RODATA)
27215 /* .text should occupy whole number of pages */
27216 @@ -122,16 +176,20 @@ SECTIONS
27217
27218 /* Data */
27219 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27220 +
27221 +#ifdef CONFIG_PAX_KERNEXEC
27222 + . = ALIGN(HPAGE_SIZE);
27223 +#else
27224 + . = ALIGN(PAGE_SIZE);
27225 +#endif
27226 +
27227 /* Start of data section */
27228 _sdata = .;
27229
27230 /* init_task */
27231 INIT_TASK_DATA(THREAD_SIZE)
27232
27233 -#ifdef CONFIG_X86_32
27234 - /* 32 bit has nosave before _edata */
27235 NOSAVE_DATA
27236 -#endif
27237
27238 PAGE_ALIGNED_DATA(PAGE_SIZE)
27239
27240 @@ -172,12 +230,19 @@ SECTIONS
27241 #endif /* CONFIG_X86_64 */
27242
27243 /* Init code and data - will be freed after init */
27244 - . = ALIGN(PAGE_SIZE);
27245 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27246 + BYTE(0)
27247 +
27248 +#ifdef CONFIG_PAX_KERNEXEC
27249 + . = ALIGN(HPAGE_SIZE);
27250 +#else
27251 + . = ALIGN(PAGE_SIZE);
27252 +#endif
27253 +
27254 __init_begin = .; /* paired with __init_end */
27255 - }
27256 + } :init.begin
27257
27258 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27259 +#ifdef CONFIG_SMP
27260 /*
27261 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27262 * output PHDR, so the next output section - .init.text - should
27263 @@ -186,12 +251,27 @@ SECTIONS
27264 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27265 #endif
27266
27267 - INIT_TEXT_SECTION(PAGE_SIZE)
27268 -#ifdef CONFIG_X86_64
27269 - :init
27270 -#endif
27271 + . = ALIGN(PAGE_SIZE);
27272 + init_begin = .;
27273 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27274 + VMLINUX_SYMBOL(_sinittext) = .;
27275 + INIT_TEXT
27276 + VMLINUX_SYMBOL(_einittext) = .;
27277 + . = ALIGN(PAGE_SIZE);
27278 + } :text.init
27279
27280 - INIT_DATA_SECTION(16)
27281 + /*
27282 + * .exit.text is discard at runtime, not link time, to deal with
27283 + * references from .altinstructions and .eh_frame
27284 + */
27285 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27286 + EXIT_TEXT
27287 + . = ALIGN(16);
27288 + } :text.exit
27289 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27290 +
27291 + . = ALIGN(PAGE_SIZE);
27292 + INIT_DATA_SECTION(16) :init
27293
27294 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27295 __x86_cpu_dev_start = .;
27296 @@ -262,19 +342,12 @@ SECTIONS
27297 }
27298
27299 . = ALIGN(8);
27300 - /*
27301 - * .exit.text is discard at runtime, not link time, to deal with
27302 - * references from .altinstructions and .eh_frame
27303 - */
27304 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27305 - EXIT_TEXT
27306 - }
27307
27308 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27309 EXIT_DATA
27310 }
27311
27312 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27313 +#ifndef CONFIG_SMP
27314 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27315 #endif
27316
27317 @@ -293,16 +366,10 @@ SECTIONS
27318 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27319 __smp_locks = .;
27320 *(.smp_locks)
27321 - . = ALIGN(PAGE_SIZE);
27322 __smp_locks_end = .;
27323 + . = ALIGN(PAGE_SIZE);
27324 }
27325
27326 -#ifdef CONFIG_X86_64
27327 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27328 - NOSAVE_DATA
27329 - }
27330 -#endif
27331 -
27332 /* BSS */
27333 . = ALIGN(PAGE_SIZE);
27334 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27335 @@ -318,6 +385,7 @@ SECTIONS
27336 __brk_base = .;
27337 . += 64 * 1024; /* 64k alignment slop space */
27338 *(.brk_reservation) /* areas brk users have reserved */
27339 + . = ALIGN(HPAGE_SIZE);
27340 __brk_limit = .;
27341 }
27342
27343 @@ -344,13 +412,12 @@ SECTIONS
27344 * for the boot processor.
27345 */
27346 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27347 -INIT_PER_CPU(gdt_page);
27348 INIT_PER_CPU(irq_stack_union);
27349
27350 /*
27351 * Build-time check on the image size:
27352 */
27353 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27354 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27355 "kernel image bigger than KERNEL_IMAGE_SIZE");
27356
27357 #ifdef CONFIG_SMP
27358 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27359 index 1f96f93..d5c8f7a 100644
27360 --- a/arch/x86/kernel/vsyscall_64.c
27361 +++ b/arch/x86/kernel/vsyscall_64.c
27362 @@ -56,15 +56,13 @@
27363 DEFINE_VVAR(int, vgetcpu_mode);
27364 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27365
27366 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27367 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27368
27369 static int __init vsyscall_setup(char *str)
27370 {
27371 if (str) {
27372 if (!strcmp("emulate", str))
27373 vsyscall_mode = EMULATE;
27374 - else if (!strcmp("native", str))
27375 - vsyscall_mode = NATIVE;
27376 else if (!strcmp("none", str))
27377 vsyscall_mode = NONE;
27378 else
27379 @@ -323,8 +321,7 @@ do_ret:
27380 return true;
27381
27382 sigsegv:
27383 - force_sig(SIGSEGV, current);
27384 - return true;
27385 + do_group_exit(SIGKILL);
27386 }
27387
27388 /*
27389 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27390 extern char __vvar_page;
27391 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27392
27393 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27394 - vsyscall_mode == NATIVE
27395 - ? PAGE_KERNEL_VSYSCALL
27396 - : PAGE_KERNEL_VVAR);
27397 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27398 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27399 (unsigned long)VSYSCALL_START);
27400
27401 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27402 index 04068192..4d75aa6 100644
27403 --- a/arch/x86/kernel/x8664_ksyms_64.c
27404 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27405 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27406 EXPORT_SYMBOL(copy_user_generic_unrolled);
27407 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27408 EXPORT_SYMBOL(__copy_user_nocache);
27409 -EXPORT_SYMBOL(_copy_from_user);
27410 -EXPORT_SYMBOL(_copy_to_user);
27411
27412 EXPORT_SYMBOL(copy_page);
27413 EXPORT_SYMBOL(clear_page);
27414 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27415 EXPORT_SYMBOL(___preempt_schedule_context);
27416 #endif
27417 #endif
27418 +
27419 +#ifdef CONFIG_PAX_PER_CPU_PGD
27420 +EXPORT_SYMBOL(cpu_pgd);
27421 +#endif
27422 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27423 index 021783b..6511282 100644
27424 --- a/arch/x86/kernel/x86_init.c
27425 +++ b/arch/x86/kernel/x86_init.c
27426 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27427 static void default_nmi_init(void) { };
27428 static int default_i8042_detect(void) { return 1; };
27429
27430 -struct x86_platform_ops x86_platform = {
27431 +struct x86_platform_ops x86_platform __read_only = {
27432 .calibrate_tsc = native_calibrate_tsc,
27433 .get_wallclock = mach_get_cmos_time,
27434 .set_wallclock = mach_set_rtc_mmss,
27435 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27436 EXPORT_SYMBOL_GPL(x86_platform);
27437
27438 #if defined(CONFIG_PCI_MSI)
27439 -struct x86_msi_ops x86_msi = {
27440 +struct x86_msi_ops x86_msi __read_only = {
27441 .setup_msi_irqs = native_setup_msi_irqs,
27442 .compose_msi_msg = native_compose_msi_msg,
27443 .teardown_msi_irq = native_teardown_msi_irq,
27444 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27445 }
27446 #endif
27447
27448 -struct x86_io_apic_ops x86_io_apic_ops = {
27449 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27450 .init = native_io_apic_init_mappings,
27451 .read = native_io_apic_read,
27452 .write = native_io_apic_write,
27453 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27454 index 422fd82..b2d262e 100644
27455 --- a/arch/x86/kernel/xsave.c
27456 +++ b/arch/x86/kernel/xsave.c
27457 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27458
27459 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27460 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27461 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27462 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27463
27464 if (!use_xsave())
27465 return err;
27466
27467 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27468 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27469
27470 /*
27471 * Read the xstate_bv which we copied (directly from the cpu or
27472 * from the state in task struct) to the user buffers.
27473 */
27474 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27475 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27476
27477 /*
27478 * For legacy compatible, we always set FP/SSE bits in the bit
27479 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27480 */
27481 xstate_bv |= XSTATE_FPSSE;
27482
27483 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27484 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27485
27486 return err;
27487 }
27488 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27489 {
27490 int err;
27491
27492 + buf = (struct xsave_struct __user *)____m(buf);
27493 if (use_xsave())
27494 err = xsave_user(buf);
27495 else if (use_fxsr())
27496 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27497 */
27498 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27499 {
27500 + buf = (void __user *)____m(buf);
27501 if (use_xsave()) {
27502 if ((unsigned long)buf % 64 || fx_only) {
27503 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27504 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27505 index c697625..a032162 100644
27506 --- a/arch/x86/kvm/cpuid.c
27507 +++ b/arch/x86/kvm/cpuid.c
27508 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27509 struct kvm_cpuid2 *cpuid,
27510 struct kvm_cpuid_entry2 __user *entries)
27511 {
27512 - int r;
27513 + int r, i;
27514
27515 r = -E2BIG;
27516 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27517 goto out;
27518 r = -EFAULT;
27519 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27520 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27521 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27522 goto out;
27523 + for (i = 0; i < cpuid->nent; ++i) {
27524 + struct kvm_cpuid_entry2 cpuid_entry;
27525 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
27526 + goto out;
27527 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
27528 + }
27529 vcpu->arch.cpuid_nent = cpuid->nent;
27530 kvm_apic_set_version(vcpu);
27531 kvm_x86_ops->cpuid_update(vcpu);
27532 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
27533 struct kvm_cpuid2 *cpuid,
27534 struct kvm_cpuid_entry2 __user *entries)
27535 {
27536 - int r;
27537 + int r, i;
27538
27539 r = -E2BIG;
27540 if (cpuid->nent < vcpu->arch.cpuid_nent)
27541 goto out;
27542 r = -EFAULT;
27543 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
27544 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27545 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27546 goto out;
27547 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
27548 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
27549 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
27550 + goto out;
27551 + }
27552 return 0;
27553
27554 out:
27555 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
27556 index d86ff15..e77b023 100644
27557 --- a/arch/x86/kvm/lapic.c
27558 +++ b/arch/x86/kvm/lapic.c
27559 @@ -55,7 +55,7 @@
27560 #define APIC_BUS_CYCLE_NS 1
27561
27562 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
27563 -#define apic_debug(fmt, arg...)
27564 +#define apic_debug(fmt, arg...) do {} while (0)
27565
27566 #define APIC_LVT_NUM 6
27567 /* 14 is the version for Xeon and Pentium 8.4.8*/
27568 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
27569 index ad75d77..a679d32 100644
27570 --- a/arch/x86/kvm/paging_tmpl.h
27571 +++ b/arch/x86/kvm/paging_tmpl.h
27572 @@ -331,7 +331,7 @@ retry_walk:
27573 if (unlikely(kvm_is_error_hva(host_addr)))
27574 goto error;
27575
27576 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
27577 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
27578 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
27579 goto error;
27580 walker->ptep_user[walker->level - 1] = ptep_user;
27581 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
27582 index c7168a5..09070fc 100644
27583 --- a/arch/x86/kvm/svm.c
27584 +++ b/arch/x86/kvm/svm.c
27585 @@ -3497,7 +3497,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
27586 int cpu = raw_smp_processor_id();
27587
27588 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
27589 +
27590 + pax_open_kernel();
27591 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
27592 + pax_close_kernel();
27593 +
27594 load_TR_desc();
27595 }
27596
27597 @@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
27598 #endif
27599 #endif
27600
27601 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27602 + __set_fs(current_thread_info()->addr_limit);
27603 +#endif
27604 +
27605 reload_tss(vcpu);
27606
27607 local_irq_disable();
27608 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
27609 index da7837e..86c6ebf 100644
27610 --- a/arch/x86/kvm/vmx.c
27611 +++ b/arch/x86/kvm/vmx.c
27612 @@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
27613 #endif
27614 }
27615
27616 -static void vmcs_clear_bits(unsigned long field, u32 mask)
27617 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
27618 {
27619 vmcs_writel(field, vmcs_readl(field) & ~mask);
27620 }
27621
27622 -static void vmcs_set_bits(unsigned long field, u32 mask)
27623 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
27624 {
27625 vmcs_writel(field, vmcs_readl(field) | mask);
27626 }
27627 @@ -1522,7 +1522,11 @@ static void reload_tss(void)
27628 struct desc_struct *descs;
27629
27630 descs = (void *)gdt->address;
27631 +
27632 + pax_open_kernel();
27633 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27634 + pax_close_kernel();
27635 +
27636 load_TR_desc();
27637 }
27638
27639 @@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27640 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27641 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27642
27643 +#ifdef CONFIG_PAX_PER_CPU_PGD
27644 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27645 +#endif
27646 +
27647 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27648 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27649 vmx->loaded_vmcs->cpu = cpu;
27650 @@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
27651 * reads and returns guest's timestamp counter "register"
27652 * guest_tsc = host_tsc + tsc_offset -- 21.3
27653 */
27654 -static u64 guest_read_tsc(void)
27655 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
27656 {
27657 u64 host_tsc, tsc_offset;
27658
27659 @@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
27660 if (!cpu_has_vmx_flexpriority())
27661 flexpriority_enabled = 0;
27662
27663 - if (!cpu_has_vmx_tpr_shadow())
27664 - kvm_x86_ops->update_cr8_intercept = NULL;
27665 + if (!cpu_has_vmx_tpr_shadow()) {
27666 + pax_open_kernel();
27667 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27668 + pax_close_kernel();
27669 + }
27670
27671 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27672 kvm_disable_largepages();
27673 @@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
27674 if (!cpu_has_vmx_apicv())
27675 enable_apicv = 0;
27676
27677 + pax_open_kernel();
27678 if (enable_apicv)
27679 - kvm_x86_ops->update_cr8_intercept = NULL;
27680 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27681 else {
27682 - kvm_x86_ops->hwapic_irr_update = NULL;
27683 - kvm_x86_ops->deliver_posted_interrupt = NULL;
27684 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27685 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27686 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27687 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27688 }
27689 + pax_close_kernel();
27690
27691 if (nested)
27692 nested_vmx_setup_ctls_msrs();
27693 @@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27694
27695 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27696 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27697 +
27698 +#ifndef CONFIG_PAX_PER_CPU_PGD
27699 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27700 +#endif
27701
27702 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27703 #ifdef CONFIG_X86_64
27704 @@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27705 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27706 vmx->host_idt_base = dt.address;
27707
27708 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27709 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27710
27711 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27712 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27713 @@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27714 "jmp 2f \n\t"
27715 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27716 "2: "
27717 +
27718 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27719 + "ljmp %[cs],$3f\n\t"
27720 + "3: "
27721 +#endif
27722 +
27723 /* Save guest registers, load host registers, keep flags */
27724 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27725 "pop %0 \n\t"
27726 @@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27727 #endif
27728 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27729 [wordsize]"i"(sizeof(ulong))
27730 +
27731 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27732 + ,[cs]"i"(__KERNEL_CS)
27733 +#endif
27734 +
27735 : "cc", "memory"
27736 #ifdef CONFIG_X86_64
27737 , "rax", "rbx", "rdi", "rsi"
27738 @@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27739 if (debugctlmsr)
27740 update_debugctlmsr(debugctlmsr);
27741
27742 -#ifndef CONFIG_X86_64
27743 +#ifdef CONFIG_X86_32
27744 /*
27745 * The sysexit path does not restore ds/es, so we must set them to
27746 * a reasonable value ourselves.
27747 @@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27748 * may be executed in interrupt context, which saves and restore segments
27749 * around it, nullifying its effect.
27750 */
27751 - loadsegment(ds, __USER_DS);
27752 - loadsegment(es, __USER_DS);
27753 + loadsegment(ds, __KERNEL_DS);
27754 + loadsegment(es, __KERNEL_DS);
27755 + loadsegment(ss, __KERNEL_DS);
27756 +
27757 +#ifdef CONFIG_PAX_KERNEXEC
27758 + loadsegment(fs, __KERNEL_PERCPU);
27759 +#endif
27760 +
27761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27762 + __set_fs(current_thread_info()->addr_limit);
27763 +#endif
27764 +
27765 #endif
27766
27767 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27768 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27769 index d89d51b..f3c612a 100644
27770 --- a/arch/x86/kvm/x86.c
27771 +++ b/arch/x86/kvm/x86.c
27772 @@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27773 {
27774 struct kvm *kvm = vcpu->kvm;
27775 int lm = is_long_mode(vcpu);
27776 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27777 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27778 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27779 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27780 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27781 : kvm->arch.xen_hvm_config.blob_size_32;
27782 u32 page_num = data & ~PAGE_MASK;
27783 @@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27784 if (n < msr_list.nmsrs)
27785 goto out;
27786 r = -EFAULT;
27787 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27788 + goto out;
27789 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27790 num_msrs_to_save * sizeof(u32)))
27791 goto out;
27792 @@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27793 };
27794 #endif
27795
27796 -int kvm_arch_init(void *opaque)
27797 +int kvm_arch_init(const void *opaque)
27798 {
27799 int r;
27800 struct kvm_x86_ops *ops = opaque;
27801 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27802 index bdf8532..f63c587 100644
27803 --- a/arch/x86/lguest/boot.c
27804 +++ b/arch/x86/lguest/boot.c
27805 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27806 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27807 * Launcher to reboot us.
27808 */
27809 -static void lguest_restart(char *reason)
27810 +static __noreturn void lguest_restart(char *reason)
27811 {
27812 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27813 + BUG();
27814 }
27815
27816 /*G:050
27817 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27818 index 00933d5..3a64af9 100644
27819 --- a/arch/x86/lib/atomic64_386_32.S
27820 +++ b/arch/x86/lib/atomic64_386_32.S
27821 @@ -48,6 +48,10 @@ BEGIN(read)
27822 movl (v), %eax
27823 movl 4(v), %edx
27824 RET_ENDP
27825 +BEGIN(read_unchecked)
27826 + movl (v), %eax
27827 + movl 4(v), %edx
27828 +RET_ENDP
27829 #undef v
27830
27831 #define v %esi
27832 @@ -55,6 +59,10 @@ BEGIN(set)
27833 movl %ebx, (v)
27834 movl %ecx, 4(v)
27835 RET_ENDP
27836 +BEGIN(set_unchecked)
27837 + movl %ebx, (v)
27838 + movl %ecx, 4(v)
27839 +RET_ENDP
27840 #undef v
27841
27842 #define v %esi
27843 @@ -70,6 +78,20 @@ RET_ENDP
27844 BEGIN(add)
27845 addl %eax, (v)
27846 adcl %edx, 4(v)
27847 +
27848 +#ifdef CONFIG_PAX_REFCOUNT
27849 + jno 0f
27850 + subl %eax, (v)
27851 + sbbl %edx, 4(v)
27852 + int $4
27853 +0:
27854 + _ASM_EXTABLE(0b, 0b)
27855 +#endif
27856 +
27857 +RET_ENDP
27858 +BEGIN(add_unchecked)
27859 + addl %eax, (v)
27860 + adcl %edx, 4(v)
27861 RET_ENDP
27862 #undef v
27863
27864 @@ -77,6 +99,24 @@ RET_ENDP
27865 BEGIN(add_return)
27866 addl (v), %eax
27867 adcl 4(v), %edx
27868 +
27869 +#ifdef CONFIG_PAX_REFCOUNT
27870 + into
27871 +1234:
27872 + _ASM_EXTABLE(1234b, 2f)
27873 +#endif
27874 +
27875 + movl %eax, (v)
27876 + movl %edx, 4(v)
27877 +
27878 +#ifdef CONFIG_PAX_REFCOUNT
27879 +2:
27880 +#endif
27881 +
27882 +RET_ENDP
27883 +BEGIN(add_return_unchecked)
27884 + addl (v), %eax
27885 + adcl 4(v), %edx
27886 movl %eax, (v)
27887 movl %edx, 4(v)
27888 RET_ENDP
27889 @@ -86,6 +126,20 @@ RET_ENDP
27890 BEGIN(sub)
27891 subl %eax, (v)
27892 sbbl %edx, 4(v)
27893 +
27894 +#ifdef CONFIG_PAX_REFCOUNT
27895 + jno 0f
27896 + addl %eax, (v)
27897 + adcl %edx, 4(v)
27898 + int $4
27899 +0:
27900 + _ASM_EXTABLE(0b, 0b)
27901 +#endif
27902 +
27903 +RET_ENDP
27904 +BEGIN(sub_unchecked)
27905 + subl %eax, (v)
27906 + sbbl %edx, 4(v)
27907 RET_ENDP
27908 #undef v
27909
27910 @@ -96,6 +150,27 @@ BEGIN(sub_return)
27911 sbbl $0, %edx
27912 addl (v), %eax
27913 adcl 4(v), %edx
27914 +
27915 +#ifdef CONFIG_PAX_REFCOUNT
27916 + into
27917 +1234:
27918 + _ASM_EXTABLE(1234b, 2f)
27919 +#endif
27920 +
27921 + movl %eax, (v)
27922 + movl %edx, 4(v)
27923 +
27924 +#ifdef CONFIG_PAX_REFCOUNT
27925 +2:
27926 +#endif
27927 +
27928 +RET_ENDP
27929 +BEGIN(sub_return_unchecked)
27930 + negl %edx
27931 + negl %eax
27932 + sbbl $0, %edx
27933 + addl (v), %eax
27934 + adcl 4(v), %edx
27935 movl %eax, (v)
27936 movl %edx, 4(v)
27937 RET_ENDP
27938 @@ -105,6 +180,20 @@ RET_ENDP
27939 BEGIN(inc)
27940 addl $1, (v)
27941 adcl $0, 4(v)
27942 +
27943 +#ifdef CONFIG_PAX_REFCOUNT
27944 + jno 0f
27945 + subl $1, (v)
27946 + sbbl $0, 4(v)
27947 + int $4
27948 +0:
27949 + _ASM_EXTABLE(0b, 0b)
27950 +#endif
27951 +
27952 +RET_ENDP
27953 +BEGIN(inc_unchecked)
27954 + addl $1, (v)
27955 + adcl $0, 4(v)
27956 RET_ENDP
27957 #undef v
27958
27959 @@ -114,6 +203,26 @@ BEGIN(inc_return)
27960 movl 4(v), %edx
27961 addl $1, %eax
27962 adcl $0, %edx
27963 +
27964 +#ifdef CONFIG_PAX_REFCOUNT
27965 + into
27966 +1234:
27967 + _ASM_EXTABLE(1234b, 2f)
27968 +#endif
27969 +
27970 + movl %eax, (v)
27971 + movl %edx, 4(v)
27972 +
27973 +#ifdef CONFIG_PAX_REFCOUNT
27974 +2:
27975 +#endif
27976 +
27977 +RET_ENDP
27978 +BEGIN(inc_return_unchecked)
27979 + movl (v), %eax
27980 + movl 4(v), %edx
27981 + addl $1, %eax
27982 + adcl $0, %edx
27983 movl %eax, (v)
27984 movl %edx, 4(v)
27985 RET_ENDP
27986 @@ -123,6 +232,20 @@ RET_ENDP
27987 BEGIN(dec)
27988 subl $1, (v)
27989 sbbl $0, 4(v)
27990 +
27991 +#ifdef CONFIG_PAX_REFCOUNT
27992 + jno 0f
27993 + addl $1, (v)
27994 + adcl $0, 4(v)
27995 + int $4
27996 +0:
27997 + _ASM_EXTABLE(0b, 0b)
27998 +#endif
27999 +
28000 +RET_ENDP
28001 +BEGIN(dec_unchecked)
28002 + subl $1, (v)
28003 + sbbl $0, 4(v)
28004 RET_ENDP
28005 #undef v
28006
28007 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28008 movl 4(v), %edx
28009 subl $1, %eax
28010 sbbl $0, %edx
28011 +
28012 +#ifdef CONFIG_PAX_REFCOUNT
28013 + into
28014 +1234:
28015 + _ASM_EXTABLE(1234b, 2f)
28016 +#endif
28017 +
28018 + movl %eax, (v)
28019 + movl %edx, 4(v)
28020 +
28021 +#ifdef CONFIG_PAX_REFCOUNT
28022 +2:
28023 +#endif
28024 +
28025 +RET_ENDP
28026 +BEGIN(dec_return_unchecked)
28027 + movl (v), %eax
28028 + movl 4(v), %edx
28029 + subl $1, %eax
28030 + sbbl $0, %edx
28031 movl %eax, (v)
28032 movl %edx, 4(v)
28033 RET_ENDP
28034 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28035 adcl %edx, %edi
28036 addl (v), %eax
28037 adcl 4(v), %edx
28038 +
28039 +#ifdef CONFIG_PAX_REFCOUNT
28040 + into
28041 +1234:
28042 + _ASM_EXTABLE(1234b, 2f)
28043 +#endif
28044 +
28045 cmpl %eax, %ecx
28046 je 3f
28047 1:
28048 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28049 1:
28050 addl $1, %eax
28051 adcl $0, %edx
28052 +
28053 +#ifdef CONFIG_PAX_REFCOUNT
28054 + into
28055 +1234:
28056 + _ASM_EXTABLE(1234b, 2f)
28057 +#endif
28058 +
28059 movl %eax, (v)
28060 movl %edx, 4(v)
28061 movl $1, %eax
28062 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28063 movl 4(v), %edx
28064 subl $1, %eax
28065 sbbl $0, %edx
28066 +
28067 +#ifdef CONFIG_PAX_REFCOUNT
28068 + into
28069 +1234:
28070 + _ASM_EXTABLE(1234b, 1f)
28071 +#endif
28072 +
28073 js 1f
28074 movl %eax, (v)
28075 movl %edx, 4(v)
28076 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28077 index f5cc9eb..51fa319 100644
28078 --- a/arch/x86/lib/atomic64_cx8_32.S
28079 +++ b/arch/x86/lib/atomic64_cx8_32.S
28080 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28081 CFI_STARTPROC
28082
28083 read64 %ecx
28084 + pax_force_retaddr
28085 ret
28086 CFI_ENDPROC
28087 ENDPROC(atomic64_read_cx8)
28088
28089 +ENTRY(atomic64_read_unchecked_cx8)
28090 + CFI_STARTPROC
28091 +
28092 + read64 %ecx
28093 + pax_force_retaddr
28094 + ret
28095 + CFI_ENDPROC
28096 +ENDPROC(atomic64_read_unchecked_cx8)
28097 +
28098 ENTRY(atomic64_set_cx8)
28099 CFI_STARTPROC
28100
28101 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28102 cmpxchg8b (%esi)
28103 jne 1b
28104
28105 + pax_force_retaddr
28106 ret
28107 CFI_ENDPROC
28108 ENDPROC(atomic64_set_cx8)
28109
28110 +ENTRY(atomic64_set_unchecked_cx8)
28111 + CFI_STARTPROC
28112 +
28113 +1:
28114 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28115 + * are atomic on 586 and newer */
28116 + cmpxchg8b (%esi)
28117 + jne 1b
28118 +
28119 + pax_force_retaddr
28120 + ret
28121 + CFI_ENDPROC
28122 +ENDPROC(atomic64_set_unchecked_cx8)
28123 +
28124 ENTRY(atomic64_xchg_cx8)
28125 CFI_STARTPROC
28126
28127 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28128 cmpxchg8b (%esi)
28129 jne 1b
28130
28131 + pax_force_retaddr
28132 ret
28133 CFI_ENDPROC
28134 ENDPROC(atomic64_xchg_cx8)
28135
28136 -.macro addsub_return func ins insc
28137 -ENTRY(atomic64_\func\()_return_cx8)
28138 +.macro addsub_return func ins insc unchecked=""
28139 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28140 CFI_STARTPROC
28141 SAVE ebp
28142 SAVE ebx
28143 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28144 movl %edx, %ecx
28145 \ins\()l %esi, %ebx
28146 \insc\()l %edi, %ecx
28147 +
28148 +.ifb \unchecked
28149 +#ifdef CONFIG_PAX_REFCOUNT
28150 + into
28151 +2:
28152 + _ASM_EXTABLE(2b, 3f)
28153 +#endif
28154 +.endif
28155 +
28156 LOCK_PREFIX
28157 cmpxchg8b (%ebp)
28158 jne 1b
28159 -
28160 -10:
28161 movl %ebx, %eax
28162 movl %ecx, %edx
28163 +
28164 +.ifb \unchecked
28165 +#ifdef CONFIG_PAX_REFCOUNT
28166 +3:
28167 +#endif
28168 +.endif
28169 +
28170 RESTORE edi
28171 RESTORE esi
28172 RESTORE ebx
28173 RESTORE ebp
28174 + pax_force_retaddr
28175 ret
28176 CFI_ENDPROC
28177 -ENDPROC(atomic64_\func\()_return_cx8)
28178 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28179 .endm
28180
28181 addsub_return add add adc
28182 addsub_return sub sub sbb
28183 +addsub_return add add adc _unchecked
28184 +addsub_return sub sub sbb _unchecked
28185
28186 -.macro incdec_return func ins insc
28187 -ENTRY(atomic64_\func\()_return_cx8)
28188 +.macro incdec_return func ins insc unchecked=""
28189 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28190 CFI_STARTPROC
28191 SAVE ebx
28192
28193 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28194 movl %edx, %ecx
28195 \ins\()l $1, %ebx
28196 \insc\()l $0, %ecx
28197 +
28198 +.ifb \unchecked
28199 +#ifdef CONFIG_PAX_REFCOUNT
28200 + into
28201 +2:
28202 + _ASM_EXTABLE(2b, 3f)
28203 +#endif
28204 +.endif
28205 +
28206 LOCK_PREFIX
28207 cmpxchg8b (%esi)
28208 jne 1b
28209
28210 -10:
28211 movl %ebx, %eax
28212 movl %ecx, %edx
28213 +
28214 +.ifb \unchecked
28215 +#ifdef CONFIG_PAX_REFCOUNT
28216 +3:
28217 +#endif
28218 +.endif
28219 +
28220 RESTORE ebx
28221 + pax_force_retaddr
28222 ret
28223 CFI_ENDPROC
28224 -ENDPROC(atomic64_\func\()_return_cx8)
28225 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28226 .endm
28227
28228 incdec_return inc add adc
28229 incdec_return dec sub sbb
28230 +incdec_return inc add adc _unchecked
28231 +incdec_return dec sub sbb _unchecked
28232
28233 ENTRY(atomic64_dec_if_positive_cx8)
28234 CFI_STARTPROC
28235 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28236 movl %edx, %ecx
28237 subl $1, %ebx
28238 sbb $0, %ecx
28239 +
28240 +#ifdef CONFIG_PAX_REFCOUNT
28241 + into
28242 +1234:
28243 + _ASM_EXTABLE(1234b, 2f)
28244 +#endif
28245 +
28246 js 2f
28247 LOCK_PREFIX
28248 cmpxchg8b (%esi)
28249 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28250 movl %ebx, %eax
28251 movl %ecx, %edx
28252 RESTORE ebx
28253 + pax_force_retaddr
28254 ret
28255 CFI_ENDPROC
28256 ENDPROC(atomic64_dec_if_positive_cx8)
28257 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28258 movl %edx, %ecx
28259 addl %ebp, %ebx
28260 adcl %edi, %ecx
28261 +
28262 +#ifdef CONFIG_PAX_REFCOUNT
28263 + into
28264 +1234:
28265 + _ASM_EXTABLE(1234b, 3f)
28266 +#endif
28267 +
28268 LOCK_PREFIX
28269 cmpxchg8b (%esi)
28270 jne 1b
28271 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28272 CFI_ADJUST_CFA_OFFSET -8
28273 RESTORE ebx
28274 RESTORE ebp
28275 + pax_force_retaddr
28276 ret
28277 4:
28278 cmpl %edx, 4(%esp)
28279 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28280 xorl %ecx, %ecx
28281 addl $1, %ebx
28282 adcl %edx, %ecx
28283 +
28284 +#ifdef CONFIG_PAX_REFCOUNT
28285 + into
28286 +1234:
28287 + _ASM_EXTABLE(1234b, 3f)
28288 +#endif
28289 +
28290 LOCK_PREFIX
28291 cmpxchg8b (%esi)
28292 jne 1b
28293 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28294 movl $1, %eax
28295 3:
28296 RESTORE ebx
28297 + pax_force_retaddr
28298 ret
28299 CFI_ENDPROC
28300 ENDPROC(atomic64_inc_not_zero_cx8)
28301 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28302 index e78b8ee..7e173a8 100644
28303 --- a/arch/x86/lib/checksum_32.S
28304 +++ b/arch/x86/lib/checksum_32.S
28305 @@ -29,7 +29,8 @@
28306 #include <asm/dwarf2.h>
28307 #include <asm/errno.h>
28308 #include <asm/asm.h>
28309 -
28310 +#include <asm/segment.h>
28311 +
28312 /*
28313 * computes a partial checksum, e.g. for TCP/UDP fragments
28314 */
28315 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28316
28317 #define ARGBASE 16
28318 #define FP 12
28319 -
28320 -ENTRY(csum_partial_copy_generic)
28321 +
28322 +ENTRY(csum_partial_copy_generic_to_user)
28323 CFI_STARTPROC
28324 +
28325 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28326 + pushl_cfi %gs
28327 + popl_cfi %es
28328 + jmp csum_partial_copy_generic
28329 +#endif
28330 +
28331 +ENTRY(csum_partial_copy_generic_from_user)
28332 +
28333 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28334 + pushl_cfi %gs
28335 + popl_cfi %ds
28336 +#endif
28337 +
28338 +ENTRY(csum_partial_copy_generic)
28339 subl $4,%esp
28340 CFI_ADJUST_CFA_OFFSET 4
28341 pushl_cfi %edi
28342 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28343 jmp 4f
28344 SRC(1: movw (%esi), %bx )
28345 addl $2, %esi
28346 -DST( movw %bx, (%edi) )
28347 +DST( movw %bx, %es:(%edi) )
28348 addl $2, %edi
28349 addw %bx, %ax
28350 adcl $0, %eax
28351 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28352 SRC(1: movl (%esi), %ebx )
28353 SRC( movl 4(%esi), %edx )
28354 adcl %ebx, %eax
28355 -DST( movl %ebx, (%edi) )
28356 +DST( movl %ebx, %es:(%edi) )
28357 adcl %edx, %eax
28358 -DST( movl %edx, 4(%edi) )
28359 +DST( movl %edx, %es:4(%edi) )
28360
28361 SRC( movl 8(%esi), %ebx )
28362 SRC( movl 12(%esi), %edx )
28363 adcl %ebx, %eax
28364 -DST( movl %ebx, 8(%edi) )
28365 +DST( movl %ebx, %es:8(%edi) )
28366 adcl %edx, %eax
28367 -DST( movl %edx, 12(%edi) )
28368 +DST( movl %edx, %es:12(%edi) )
28369
28370 SRC( movl 16(%esi), %ebx )
28371 SRC( movl 20(%esi), %edx )
28372 adcl %ebx, %eax
28373 -DST( movl %ebx, 16(%edi) )
28374 +DST( movl %ebx, %es:16(%edi) )
28375 adcl %edx, %eax
28376 -DST( movl %edx, 20(%edi) )
28377 +DST( movl %edx, %es:20(%edi) )
28378
28379 SRC( movl 24(%esi), %ebx )
28380 SRC( movl 28(%esi), %edx )
28381 adcl %ebx, %eax
28382 -DST( movl %ebx, 24(%edi) )
28383 +DST( movl %ebx, %es:24(%edi) )
28384 adcl %edx, %eax
28385 -DST( movl %edx, 28(%edi) )
28386 +DST( movl %edx, %es:28(%edi) )
28387
28388 lea 32(%esi), %esi
28389 lea 32(%edi), %edi
28390 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28391 shrl $2, %edx # This clears CF
28392 SRC(3: movl (%esi), %ebx )
28393 adcl %ebx, %eax
28394 -DST( movl %ebx, (%edi) )
28395 +DST( movl %ebx, %es:(%edi) )
28396 lea 4(%esi), %esi
28397 lea 4(%edi), %edi
28398 dec %edx
28399 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28400 jb 5f
28401 SRC( movw (%esi), %cx )
28402 leal 2(%esi), %esi
28403 -DST( movw %cx, (%edi) )
28404 +DST( movw %cx, %es:(%edi) )
28405 leal 2(%edi), %edi
28406 je 6f
28407 shll $16,%ecx
28408 SRC(5: movb (%esi), %cl )
28409 -DST( movb %cl, (%edi) )
28410 +DST( movb %cl, %es:(%edi) )
28411 6: addl %ecx, %eax
28412 adcl $0, %eax
28413 7:
28414 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28415
28416 6001:
28417 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28418 - movl $-EFAULT, (%ebx)
28419 + movl $-EFAULT, %ss:(%ebx)
28420
28421 # zero the complete destination - computing the rest
28422 # is too much work
28423 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28424
28425 6002:
28426 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28427 - movl $-EFAULT,(%ebx)
28428 + movl $-EFAULT,%ss:(%ebx)
28429 jmp 5000b
28430
28431 .previous
28432
28433 + pushl_cfi %ss
28434 + popl_cfi %ds
28435 + pushl_cfi %ss
28436 + popl_cfi %es
28437 popl_cfi %ebx
28438 CFI_RESTORE ebx
28439 popl_cfi %esi
28440 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28441 popl_cfi %ecx # equivalent to addl $4,%esp
28442 ret
28443 CFI_ENDPROC
28444 -ENDPROC(csum_partial_copy_generic)
28445 +ENDPROC(csum_partial_copy_generic_to_user)
28446
28447 #else
28448
28449 /* Version for PentiumII/PPro */
28450
28451 #define ROUND1(x) \
28452 + nop; nop; nop; \
28453 SRC(movl x(%esi), %ebx ) ; \
28454 addl %ebx, %eax ; \
28455 - DST(movl %ebx, x(%edi) ) ;
28456 + DST(movl %ebx, %es:x(%edi)) ;
28457
28458 #define ROUND(x) \
28459 + nop; nop; nop; \
28460 SRC(movl x(%esi), %ebx ) ; \
28461 adcl %ebx, %eax ; \
28462 - DST(movl %ebx, x(%edi) ) ;
28463 + DST(movl %ebx, %es:x(%edi)) ;
28464
28465 #define ARGBASE 12
28466 -
28467 -ENTRY(csum_partial_copy_generic)
28468 +
28469 +ENTRY(csum_partial_copy_generic_to_user)
28470 CFI_STARTPROC
28471 +
28472 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28473 + pushl_cfi %gs
28474 + popl_cfi %es
28475 + jmp csum_partial_copy_generic
28476 +#endif
28477 +
28478 +ENTRY(csum_partial_copy_generic_from_user)
28479 +
28480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28481 + pushl_cfi %gs
28482 + popl_cfi %ds
28483 +#endif
28484 +
28485 +ENTRY(csum_partial_copy_generic)
28486 pushl_cfi %ebx
28487 CFI_REL_OFFSET ebx, 0
28488 pushl_cfi %edi
28489 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28490 subl %ebx, %edi
28491 lea -1(%esi),%edx
28492 andl $-32,%edx
28493 - lea 3f(%ebx,%ebx), %ebx
28494 + lea 3f(%ebx,%ebx,2), %ebx
28495 testl %esi, %esi
28496 jmp *%ebx
28497 1: addl $64,%esi
28498 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28499 jb 5f
28500 SRC( movw (%esi), %dx )
28501 leal 2(%esi), %esi
28502 -DST( movw %dx, (%edi) )
28503 +DST( movw %dx, %es:(%edi) )
28504 leal 2(%edi), %edi
28505 je 6f
28506 shll $16,%edx
28507 5:
28508 SRC( movb (%esi), %dl )
28509 -DST( movb %dl, (%edi) )
28510 +DST( movb %dl, %es:(%edi) )
28511 6: addl %edx, %eax
28512 adcl $0, %eax
28513 7:
28514 .section .fixup, "ax"
28515 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28516 - movl $-EFAULT, (%ebx)
28517 + movl $-EFAULT, %ss:(%ebx)
28518 # zero the complete destination (computing the rest is too much work)
28519 movl ARGBASE+8(%esp),%edi # dst
28520 movl ARGBASE+12(%esp),%ecx # len
28521 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
28522 rep; stosb
28523 jmp 7b
28524 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28525 - movl $-EFAULT, (%ebx)
28526 + movl $-EFAULT, %ss:(%ebx)
28527 jmp 7b
28528 .previous
28529
28530 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28531 + pushl_cfi %ss
28532 + popl_cfi %ds
28533 + pushl_cfi %ss
28534 + popl_cfi %es
28535 +#endif
28536 +
28537 popl_cfi %esi
28538 CFI_RESTORE esi
28539 popl_cfi %edi
28540 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
28541 CFI_RESTORE ebx
28542 ret
28543 CFI_ENDPROC
28544 -ENDPROC(csum_partial_copy_generic)
28545 +ENDPROC(csum_partial_copy_generic_to_user)
28546
28547 #undef ROUND
28548 #undef ROUND1
28549 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
28550 index f2145cf..cea889d 100644
28551 --- a/arch/x86/lib/clear_page_64.S
28552 +++ b/arch/x86/lib/clear_page_64.S
28553 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
28554 movl $4096/8,%ecx
28555 xorl %eax,%eax
28556 rep stosq
28557 + pax_force_retaddr
28558 ret
28559 CFI_ENDPROC
28560 ENDPROC(clear_page_c)
28561 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
28562 movl $4096,%ecx
28563 xorl %eax,%eax
28564 rep stosb
28565 + pax_force_retaddr
28566 ret
28567 CFI_ENDPROC
28568 ENDPROC(clear_page_c_e)
28569 @@ -43,6 +45,7 @@ ENTRY(clear_page)
28570 leaq 64(%rdi),%rdi
28571 jnz .Lloop
28572 nop
28573 + pax_force_retaddr
28574 ret
28575 CFI_ENDPROC
28576 .Lclear_page_end:
28577 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
28578
28579 #include <asm/cpufeature.h>
28580
28581 - .section .altinstr_replacement,"ax"
28582 + .section .altinstr_replacement,"a"
28583 1: .byte 0xeb /* jmp <disp8> */
28584 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
28585 2: .byte 0xeb /* jmp <disp8> */
28586 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
28587 index 1e572c5..2a162cd 100644
28588 --- a/arch/x86/lib/cmpxchg16b_emu.S
28589 +++ b/arch/x86/lib/cmpxchg16b_emu.S
28590 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
28591
28592 popf
28593 mov $1, %al
28594 + pax_force_retaddr
28595 ret
28596
28597 not_same:
28598 popf
28599 xor %al,%al
28600 + pax_force_retaddr
28601 ret
28602
28603 CFI_ENDPROC
28604 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
28605 index 176cca6..e0d658e 100644
28606 --- a/arch/x86/lib/copy_page_64.S
28607 +++ b/arch/x86/lib/copy_page_64.S
28608 @@ -9,6 +9,7 @@ copy_page_rep:
28609 CFI_STARTPROC
28610 movl $4096/8, %ecx
28611 rep movsq
28612 + pax_force_retaddr
28613 ret
28614 CFI_ENDPROC
28615 ENDPROC(copy_page_rep)
28616 @@ -24,8 +25,8 @@ ENTRY(copy_page)
28617 CFI_ADJUST_CFA_OFFSET 2*8
28618 movq %rbx, (%rsp)
28619 CFI_REL_OFFSET rbx, 0
28620 - movq %r12, 1*8(%rsp)
28621 - CFI_REL_OFFSET r12, 1*8
28622 + movq %r13, 1*8(%rsp)
28623 + CFI_REL_OFFSET r13, 1*8
28624
28625 movl $(4096/64)-5, %ecx
28626 .p2align 4
28627 @@ -38,7 +39,7 @@ ENTRY(copy_page)
28628 movq 0x8*4(%rsi), %r9
28629 movq 0x8*5(%rsi), %r10
28630 movq 0x8*6(%rsi), %r11
28631 - movq 0x8*7(%rsi), %r12
28632 + movq 0x8*7(%rsi), %r13
28633
28634 prefetcht0 5*64(%rsi)
28635
28636 @@ -49,7 +50,7 @@ ENTRY(copy_page)
28637 movq %r9, 0x8*4(%rdi)
28638 movq %r10, 0x8*5(%rdi)
28639 movq %r11, 0x8*6(%rdi)
28640 - movq %r12, 0x8*7(%rdi)
28641 + movq %r13, 0x8*7(%rdi)
28642
28643 leaq 64 (%rsi), %rsi
28644 leaq 64 (%rdi), %rdi
28645 @@ -68,7 +69,7 @@ ENTRY(copy_page)
28646 movq 0x8*4(%rsi), %r9
28647 movq 0x8*5(%rsi), %r10
28648 movq 0x8*6(%rsi), %r11
28649 - movq 0x8*7(%rsi), %r12
28650 + movq 0x8*7(%rsi), %r13
28651
28652 movq %rax, 0x8*0(%rdi)
28653 movq %rbx, 0x8*1(%rdi)
28654 @@ -77,7 +78,7 @@ ENTRY(copy_page)
28655 movq %r9, 0x8*4(%rdi)
28656 movq %r10, 0x8*5(%rdi)
28657 movq %r11, 0x8*6(%rdi)
28658 - movq %r12, 0x8*7(%rdi)
28659 + movq %r13, 0x8*7(%rdi)
28660
28661 leaq 64(%rdi), %rdi
28662 leaq 64(%rsi), %rsi
28663 @@ -85,10 +86,11 @@ ENTRY(copy_page)
28664
28665 movq (%rsp), %rbx
28666 CFI_RESTORE rbx
28667 - movq 1*8(%rsp), %r12
28668 - CFI_RESTORE r12
28669 + movq 1*8(%rsp), %r13
28670 + CFI_RESTORE r13
28671 addq $2*8, %rsp
28672 CFI_ADJUST_CFA_OFFSET -2*8
28673 + pax_force_retaddr
28674 ret
28675 .Lcopy_page_end:
28676 CFI_ENDPROC
28677 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
28678
28679 #include <asm/cpufeature.h>
28680
28681 - .section .altinstr_replacement,"ax"
28682 + .section .altinstr_replacement,"a"
28683 1: .byte 0xeb /* jmp <disp8> */
28684 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28685 2:
28686 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28687 index a30ca15..407412b 100644
28688 --- a/arch/x86/lib/copy_user_64.S
28689 +++ b/arch/x86/lib/copy_user_64.S
28690 @@ -18,31 +18,7 @@
28691 #include <asm/alternative-asm.h>
28692 #include <asm/asm.h>
28693 #include <asm/smap.h>
28694 -
28695 -/*
28696 - * By placing feature2 after feature1 in altinstructions section, we logically
28697 - * implement:
28698 - * If CPU has feature2, jmp to alt2 is used
28699 - * else if CPU has feature1, jmp to alt1 is used
28700 - * else jmp to orig is used.
28701 - */
28702 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28703 -0:
28704 - .byte 0xe9 /* 32bit jump */
28705 - .long \orig-1f /* by default jump to orig */
28706 -1:
28707 - .section .altinstr_replacement,"ax"
28708 -2: .byte 0xe9 /* near jump with 32bit immediate */
28709 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28710 -3: .byte 0xe9 /* near jump with 32bit immediate */
28711 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28712 - .previous
28713 -
28714 - .section .altinstructions,"a"
28715 - altinstruction_entry 0b,2b,\feature1,5,5
28716 - altinstruction_entry 0b,3b,\feature2,5,5
28717 - .previous
28718 - .endm
28719 +#include <asm/pgtable.h>
28720
28721 .macro ALIGN_DESTINATION
28722 #ifdef FIX_ALIGNMENT
28723 @@ -70,52 +46,6 @@
28724 #endif
28725 .endm
28726
28727 -/* Standard copy_to_user with segment limit checking */
28728 -ENTRY(_copy_to_user)
28729 - CFI_STARTPROC
28730 - GET_THREAD_INFO(%rax)
28731 - movq %rdi,%rcx
28732 - addq %rdx,%rcx
28733 - jc bad_to_user
28734 - cmpq TI_addr_limit(%rax),%rcx
28735 - ja bad_to_user
28736 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28737 - copy_user_generic_unrolled,copy_user_generic_string, \
28738 - copy_user_enhanced_fast_string
28739 - CFI_ENDPROC
28740 -ENDPROC(_copy_to_user)
28741 -
28742 -/* Standard copy_from_user with segment limit checking */
28743 -ENTRY(_copy_from_user)
28744 - CFI_STARTPROC
28745 - GET_THREAD_INFO(%rax)
28746 - movq %rsi,%rcx
28747 - addq %rdx,%rcx
28748 - jc bad_from_user
28749 - cmpq TI_addr_limit(%rax),%rcx
28750 - ja bad_from_user
28751 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28752 - copy_user_generic_unrolled,copy_user_generic_string, \
28753 - copy_user_enhanced_fast_string
28754 - CFI_ENDPROC
28755 -ENDPROC(_copy_from_user)
28756 -
28757 - .section .fixup,"ax"
28758 - /* must zero dest */
28759 -ENTRY(bad_from_user)
28760 -bad_from_user:
28761 - CFI_STARTPROC
28762 - movl %edx,%ecx
28763 - xorl %eax,%eax
28764 - rep
28765 - stosb
28766 -bad_to_user:
28767 - movl %edx,%eax
28768 - ret
28769 - CFI_ENDPROC
28770 -ENDPROC(bad_from_user)
28771 - .previous
28772 -
28773 /*
28774 * copy_user_generic_unrolled - memory copy with exception handling.
28775 * This version is for CPUs like P4 that don't have efficient micro
28776 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28777 */
28778 ENTRY(copy_user_generic_unrolled)
28779 CFI_STARTPROC
28780 + ASM_PAX_OPEN_USERLAND
28781 ASM_STAC
28782 cmpl $8,%edx
28783 jb 20f /* less then 8 bytes, go to byte copy loop */
28784 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28785 jnz 21b
28786 23: xor %eax,%eax
28787 ASM_CLAC
28788 + ASM_PAX_CLOSE_USERLAND
28789 + pax_force_retaddr
28790 ret
28791
28792 .section .fixup,"ax"
28793 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28794 */
28795 ENTRY(copy_user_generic_string)
28796 CFI_STARTPROC
28797 + ASM_PAX_OPEN_USERLAND
28798 ASM_STAC
28799 andl %edx,%edx
28800 jz 4f
28801 @@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28802 movsb
28803 4: xorl %eax,%eax
28804 ASM_CLAC
28805 + ASM_PAX_CLOSE_USERLAND
28806 + pax_force_retaddr
28807 ret
28808
28809 .section .fixup,"ax"
28810 @@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28811 */
28812 ENTRY(copy_user_enhanced_fast_string)
28813 CFI_STARTPROC
28814 + ASM_PAX_OPEN_USERLAND
28815 ASM_STAC
28816 andl %edx,%edx
28817 jz 2f
28818 @@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28819 movsb
28820 2: xorl %eax,%eax
28821 ASM_CLAC
28822 + ASM_PAX_CLOSE_USERLAND
28823 + pax_force_retaddr
28824 ret
28825
28826 .section .fixup,"ax"
28827 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28828 index 6a4f43c..c70fb52 100644
28829 --- a/arch/x86/lib/copy_user_nocache_64.S
28830 +++ b/arch/x86/lib/copy_user_nocache_64.S
28831 @@ -8,6 +8,7 @@
28832
28833 #include <linux/linkage.h>
28834 #include <asm/dwarf2.h>
28835 +#include <asm/alternative-asm.h>
28836
28837 #define FIX_ALIGNMENT 1
28838
28839 @@ -16,6 +17,7 @@
28840 #include <asm/thread_info.h>
28841 #include <asm/asm.h>
28842 #include <asm/smap.h>
28843 +#include <asm/pgtable.h>
28844
28845 .macro ALIGN_DESTINATION
28846 #ifdef FIX_ALIGNMENT
28847 @@ -49,6 +51,16 @@
28848 */
28849 ENTRY(__copy_user_nocache)
28850 CFI_STARTPROC
28851 +
28852 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28853 + mov pax_user_shadow_base,%rcx
28854 + cmp %rcx,%rsi
28855 + jae 1f
28856 + add %rcx,%rsi
28857 +1:
28858 +#endif
28859 +
28860 + ASM_PAX_OPEN_USERLAND
28861 ASM_STAC
28862 cmpl $8,%edx
28863 jb 20f /* less then 8 bytes, go to byte copy loop */
28864 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28865 jnz 21b
28866 23: xorl %eax,%eax
28867 ASM_CLAC
28868 + ASM_PAX_CLOSE_USERLAND
28869 sfence
28870 + pax_force_retaddr
28871 ret
28872
28873 .section .fixup,"ax"
28874 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28875 index 2419d5f..fe52d0e 100644
28876 --- a/arch/x86/lib/csum-copy_64.S
28877 +++ b/arch/x86/lib/csum-copy_64.S
28878 @@ -9,6 +9,7 @@
28879 #include <asm/dwarf2.h>
28880 #include <asm/errno.h>
28881 #include <asm/asm.h>
28882 +#include <asm/alternative-asm.h>
28883
28884 /*
28885 * Checksum copy with exception handling.
28886 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
28887 CFI_ADJUST_CFA_OFFSET 7*8
28888 movq %rbx, 2*8(%rsp)
28889 CFI_REL_OFFSET rbx, 2*8
28890 - movq %r12, 3*8(%rsp)
28891 - CFI_REL_OFFSET r12, 3*8
28892 + movq %r15, 3*8(%rsp)
28893 + CFI_REL_OFFSET r15, 3*8
28894 movq %r14, 4*8(%rsp)
28895 CFI_REL_OFFSET r14, 4*8
28896 movq %r13, 5*8(%rsp)
28897 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
28898 movl %edx, %ecx
28899
28900 xorl %r9d, %r9d
28901 - movq %rcx, %r12
28902 + movq %rcx, %r15
28903
28904 - shrq $6, %r12
28905 + shrq $6, %r15
28906 jz .Lhandle_tail /* < 64 */
28907
28908 clc
28909
28910 /* main loop. clear in 64 byte blocks */
28911 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
28912 - /* r11: temp3, rdx: temp4, r12 loopcnt */
28913 + /* r11: temp3, rdx: temp4, r15 loopcnt */
28914 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
28915 .p2align 4
28916 .Lloop:
28917 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
28918 adcq %r14, %rax
28919 adcq %r13, %rax
28920
28921 - decl %r12d
28922 + decl %r15d
28923
28924 dest
28925 movq %rbx, (%rsi)
28926 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
28927 .Lende:
28928 movq 2*8(%rsp), %rbx
28929 CFI_RESTORE rbx
28930 - movq 3*8(%rsp), %r12
28931 - CFI_RESTORE r12
28932 + movq 3*8(%rsp), %r15
28933 + CFI_RESTORE r15
28934 movq 4*8(%rsp), %r14
28935 CFI_RESTORE r14
28936 movq 5*8(%rsp), %r13
28937 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28938 CFI_RESTORE rbp
28939 addq $7*8, %rsp
28940 CFI_ADJUST_CFA_OFFSET -7*8
28941 + pax_force_retaddr
28942 ret
28943 CFI_RESTORE_STATE
28944
28945 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28946 index 7609e0e..b449b98 100644
28947 --- a/arch/x86/lib/csum-wrappers_64.c
28948 +++ b/arch/x86/lib/csum-wrappers_64.c
28949 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28950 len -= 2;
28951 }
28952 }
28953 + pax_open_userland();
28954 stac();
28955 - isum = csum_partial_copy_generic((__force const void *)src,
28956 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28957 dst, len, isum, errp, NULL);
28958 clac();
28959 + pax_close_userland();
28960 if (unlikely(*errp))
28961 goto out_err;
28962
28963 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28964 }
28965
28966 *errp = 0;
28967 + pax_open_userland();
28968 stac();
28969 - ret = csum_partial_copy_generic(src, (void __force *)dst,
28970 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28971 len, isum, NULL, errp);
28972 clac();
28973 + pax_close_userland();
28974 return ret;
28975 }
28976 EXPORT_SYMBOL(csum_partial_copy_to_user);
28977 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28978 index a451235..1daa956 100644
28979 --- a/arch/x86/lib/getuser.S
28980 +++ b/arch/x86/lib/getuser.S
28981 @@ -33,17 +33,40 @@
28982 #include <asm/thread_info.h>
28983 #include <asm/asm.h>
28984 #include <asm/smap.h>
28985 +#include <asm/segment.h>
28986 +#include <asm/pgtable.h>
28987 +#include <asm/alternative-asm.h>
28988 +
28989 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28990 +#define __copyuser_seg gs;
28991 +#else
28992 +#define __copyuser_seg
28993 +#endif
28994
28995 .text
28996 ENTRY(__get_user_1)
28997 CFI_STARTPROC
28998 +
28999 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29000 GET_THREAD_INFO(%_ASM_DX)
29001 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29002 jae bad_get_user
29003 ASM_STAC
29004 -1: movzbl (%_ASM_AX),%edx
29005 +
29006 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29007 + mov pax_user_shadow_base,%_ASM_DX
29008 + cmp %_ASM_DX,%_ASM_AX
29009 + jae 1234f
29010 + add %_ASM_DX,%_ASM_AX
29011 +1234:
29012 +#endif
29013 +
29014 +#endif
29015 +
29016 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29017 xor %eax,%eax
29018 ASM_CLAC
29019 + pax_force_retaddr
29020 ret
29021 CFI_ENDPROC
29022 ENDPROC(__get_user_1)
29023 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29024 ENTRY(__get_user_2)
29025 CFI_STARTPROC
29026 add $1,%_ASM_AX
29027 +
29028 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29029 jc bad_get_user
29030 GET_THREAD_INFO(%_ASM_DX)
29031 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29032 jae bad_get_user
29033 ASM_STAC
29034 -2: movzwl -1(%_ASM_AX),%edx
29035 +
29036 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29037 + mov pax_user_shadow_base,%_ASM_DX
29038 + cmp %_ASM_DX,%_ASM_AX
29039 + jae 1234f
29040 + add %_ASM_DX,%_ASM_AX
29041 +1234:
29042 +#endif
29043 +
29044 +#endif
29045 +
29046 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29047 xor %eax,%eax
29048 ASM_CLAC
29049 + pax_force_retaddr
29050 ret
29051 CFI_ENDPROC
29052 ENDPROC(__get_user_2)
29053 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29054 ENTRY(__get_user_4)
29055 CFI_STARTPROC
29056 add $3,%_ASM_AX
29057 +
29058 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29059 jc bad_get_user
29060 GET_THREAD_INFO(%_ASM_DX)
29061 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29062 jae bad_get_user
29063 ASM_STAC
29064 -3: movl -3(%_ASM_AX),%edx
29065 +
29066 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29067 + mov pax_user_shadow_base,%_ASM_DX
29068 + cmp %_ASM_DX,%_ASM_AX
29069 + jae 1234f
29070 + add %_ASM_DX,%_ASM_AX
29071 +1234:
29072 +#endif
29073 +
29074 +#endif
29075 +
29076 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29077 xor %eax,%eax
29078 ASM_CLAC
29079 + pax_force_retaddr
29080 ret
29081 CFI_ENDPROC
29082 ENDPROC(__get_user_4)
29083 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29084 GET_THREAD_INFO(%_ASM_DX)
29085 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29086 jae bad_get_user
29087 +
29088 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29089 + mov pax_user_shadow_base,%_ASM_DX
29090 + cmp %_ASM_DX,%_ASM_AX
29091 + jae 1234f
29092 + add %_ASM_DX,%_ASM_AX
29093 +1234:
29094 +#endif
29095 +
29096 ASM_STAC
29097 4: movq -7(%_ASM_AX),%rdx
29098 xor %eax,%eax
29099 ASM_CLAC
29100 + pax_force_retaddr
29101 ret
29102 #else
29103 add $7,%_ASM_AX
29104 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29105 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29106 jae bad_get_user_8
29107 ASM_STAC
29108 -4: movl -7(%_ASM_AX),%edx
29109 -5: movl -3(%_ASM_AX),%ecx
29110 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29111 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29112 xor %eax,%eax
29113 ASM_CLAC
29114 + pax_force_retaddr
29115 ret
29116 #endif
29117 CFI_ENDPROC
29118 @@ -113,6 +175,7 @@ bad_get_user:
29119 xor %edx,%edx
29120 mov $(-EFAULT),%_ASM_AX
29121 ASM_CLAC
29122 + pax_force_retaddr
29123 ret
29124 CFI_ENDPROC
29125 END(bad_get_user)
29126 @@ -124,6 +187,7 @@ bad_get_user_8:
29127 xor %ecx,%ecx
29128 mov $(-EFAULT),%_ASM_AX
29129 ASM_CLAC
29130 + pax_force_retaddr
29131 ret
29132 CFI_ENDPROC
29133 END(bad_get_user_8)
29134 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29135 index 54fcffe..7be149e 100644
29136 --- a/arch/x86/lib/insn.c
29137 +++ b/arch/x86/lib/insn.c
29138 @@ -20,8 +20,10 @@
29139
29140 #ifdef __KERNEL__
29141 #include <linux/string.h>
29142 +#include <asm/pgtable_types.h>
29143 #else
29144 #include <string.h>
29145 +#define ktla_ktva(addr) addr
29146 #endif
29147 #include <asm/inat.h>
29148 #include <asm/insn.h>
29149 @@ -53,8 +55,8 @@
29150 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29151 {
29152 memset(insn, 0, sizeof(*insn));
29153 - insn->kaddr = kaddr;
29154 - insn->next_byte = kaddr;
29155 + insn->kaddr = ktla_ktva(kaddr);
29156 + insn->next_byte = ktla_ktva(kaddr);
29157 insn->x86_64 = x86_64 ? 1 : 0;
29158 insn->opnd_bytes = 4;
29159 if (x86_64)
29160 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29161 index 05a95e7..326f2fa 100644
29162 --- a/arch/x86/lib/iomap_copy_64.S
29163 +++ b/arch/x86/lib/iomap_copy_64.S
29164 @@ -17,6 +17,7 @@
29165
29166 #include <linux/linkage.h>
29167 #include <asm/dwarf2.h>
29168 +#include <asm/alternative-asm.h>
29169
29170 /*
29171 * override generic version in lib/iomap_copy.c
29172 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29173 CFI_STARTPROC
29174 movl %edx,%ecx
29175 rep movsd
29176 + pax_force_retaddr
29177 ret
29178 CFI_ENDPROC
29179 ENDPROC(__iowrite32_copy)
29180 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29181 index 56313a3..0db417e 100644
29182 --- a/arch/x86/lib/memcpy_64.S
29183 +++ b/arch/x86/lib/memcpy_64.S
29184 @@ -24,7 +24,7 @@
29185 * This gets patched over the unrolled variant (below) via the
29186 * alternative instructions framework:
29187 */
29188 - .section .altinstr_replacement, "ax", @progbits
29189 + .section .altinstr_replacement, "a", @progbits
29190 .Lmemcpy_c:
29191 movq %rdi, %rax
29192 movq %rdx, %rcx
29193 @@ -33,6 +33,7 @@
29194 rep movsq
29195 movl %edx, %ecx
29196 rep movsb
29197 + pax_force_retaddr
29198 ret
29199 .Lmemcpy_e:
29200 .previous
29201 @@ -44,11 +45,12 @@
29202 * This gets patched over the unrolled variant (below) via the
29203 * alternative instructions framework:
29204 */
29205 - .section .altinstr_replacement, "ax", @progbits
29206 + .section .altinstr_replacement, "a", @progbits
29207 .Lmemcpy_c_e:
29208 movq %rdi, %rax
29209 movq %rdx, %rcx
29210 rep movsb
29211 + pax_force_retaddr
29212 ret
29213 .Lmemcpy_e_e:
29214 .previous
29215 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29216 movq %r9, 1*8(%rdi)
29217 movq %r10, -2*8(%rdi, %rdx)
29218 movq %r11, -1*8(%rdi, %rdx)
29219 + pax_force_retaddr
29220 retq
29221 .p2align 4
29222 .Lless_16bytes:
29223 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29224 movq -1*8(%rsi, %rdx), %r9
29225 movq %r8, 0*8(%rdi)
29226 movq %r9, -1*8(%rdi, %rdx)
29227 + pax_force_retaddr
29228 retq
29229 .p2align 4
29230 .Lless_8bytes:
29231 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29232 movl -4(%rsi, %rdx), %r8d
29233 movl %ecx, (%rdi)
29234 movl %r8d, -4(%rdi, %rdx)
29235 + pax_force_retaddr
29236 retq
29237 .p2align 4
29238 .Lless_3bytes:
29239 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29240 movb %cl, (%rdi)
29241
29242 .Lend:
29243 + pax_force_retaddr
29244 retq
29245 CFI_ENDPROC
29246 ENDPROC(memcpy)
29247 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29248 index 65268a6..dd1de11 100644
29249 --- a/arch/x86/lib/memmove_64.S
29250 +++ b/arch/x86/lib/memmove_64.S
29251 @@ -202,14 +202,16 @@ ENTRY(memmove)
29252 movb (%rsi), %r11b
29253 movb %r11b, (%rdi)
29254 13:
29255 + pax_force_retaddr
29256 retq
29257 CFI_ENDPROC
29258
29259 - .section .altinstr_replacement,"ax"
29260 + .section .altinstr_replacement,"a"
29261 .Lmemmove_begin_forward_efs:
29262 /* Forward moving data. */
29263 movq %rdx, %rcx
29264 rep movsb
29265 + pax_force_retaddr
29266 retq
29267 .Lmemmove_end_forward_efs:
29268 .previous
29269 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29270 index 2dcb380..2eb79fe 100644
29271 --- a/arch/x86/lib/memset_64.S
29272 +++ b/arch/x86/lib/memset_64.S
29273 @@ -16,7 +16,7 @@
29274 *
29275 * rax original destination
29276 */
29277 - .section .altinstr_replacement, "ax", @progbits
29278 + .section .altinstr_replacement, "a", @progbits
29279 .Lmemset_c:
29280 movq %rdi,%r9
29281 movq %rdx,%rcx
29282 @@ -30,6 +30,7 @@
29283 movl %edx,%ecx
29284 rep stosb
29285 movq %r9,%rax
29286 + pax_force_retaddr
29287 ret
29288 .Lmemset_e:
29289 .previous
29290 @@ -45,13 +46,14 @@
29291 *
29292 * rax original destination
29293 */
29294 - .section .altinstr_replacement, "ax", @progbits
29295 + .section .altinstr_replacement, "a", @progbits
29296 .Lmemset_c_e:
29297 movq %rdi,%r9
29298 movb %sil,%al
29299 movq %rdx,%rcx
29300 rep stosb
29301 movq %r9,%rax
29302 + pax_force_retaddr
29303 ret
29304 .Lmemset_e_e:
29305 .previous
29306 @@ -118,6 +120,7 @@ ENTRY(__memset)
29307
29308 .Lende:
29309 movq %r10,%rax
29310 + pax_force_retaddr
29311 ret
29312
29313 CFI_RESTORE_STATE
29314 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29315 index c9f2d9b..e7fd2c0 100644
29316 --- a/arch/x86/lib/mmx_32.c
29317 +++ b/arch/x86/lib/mmx_32.c
29318 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29319 {
29320 void *p;
29321 int i;
29322 + unsigned long cr0;
29323
29324 if (unlikely(in_interrupt()))
29325 return __memcpy(to, from, len);
29326 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29327 kernel_fpu_begin();
29328
29329 __asm__ __volatile__ (
29330 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29331 - " prefetch 64(%0)\n"
29332 - " prefetch 128(%0)\n"
29333 - " prefetch 192(%0)\n"
29334 - " prefetch 256(%0)\n"
29335 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29336 + " prefetch 64(%1)\n"
29337 + " prefetch 128(%1)\n"
29338 + " prefetch 192(%1)\n"
29339 + " prefetch 256(%1)\n"
29340 "2: \n"
29341 ".section .fixup, \"ax\"\n"
29342 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29343 + "3: \n"
29344 +
29345 +#ifdef CONFIG_PAX_KERNEXEC
29346 + " movl %%cr0, %0\n"
29347 + " movl %0, %%eax\n"
29348 + " andl $0xFFFEFFFF, %%eax\n"
29349 + " movl %%eax, %%cr0\n"
29350 +#endif
29351 +
29352 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29353 +
29354 +#ifdef CONFIG_PAX_KERNEXEC
29355 + " movl %0, %%cr0\n"
29356 +#endif
29357 +
29358 " jmp 2b\n"
29359 ".previous\n"
29360 _ASM_EXTABLE(1b, 3b)
29361 - : : "r" (from));
29362 + : "=&r" (cr0) : "r" (from) : "ax");
29363
29364 for ( ; i > 5; i--) {
29365 __asm__ __volatile__ (
29366 - "1: prefetch 320(%0)\n"
29367 - "2: movq (%0), %%mm0\n"
29368 - " movq 8(%0), %%mm1\n"
29369 - " movq 16(%0), %%mm2\n"
29370 - " movq 24(%0), %%mm3\n"
29371 - " movq %%mm0, (%1)\n"
29372 - " movq %%mm1, 8(%1)\n"
29373 - " movq %%mm2, 16(%1)\n"
29374 - " movq %%mm3, 24(%1)\n"
29375 - " movq 32(%0), %%mm0\n"
29376 - " movq 40(%0), %%mm1\n"
29377 - " movq 48(%0), %%mm2\n"
29378 - " movq 56(%0), %%mm3\n"
29379 - " movq %%mm0, 32(%1)\n"
29380 - " movq %%mm1, 40(%1)\n"
29381 - " movq %%mm2, 48(%1)\n"
29382 - " movq %%mm3, 56(%1)\n"
29383 + "1: prefetch 320(%1)\n"
29384 + "2: movq (%1), %%mm0\n"
29385 + " movq 8(%1), %%mm1\n"
29386 + " movq 16(%1), %%mm2\n"
29387 + " movq 24(%1), %%mm3\n"
29388 + " movq %%mm0, (%2)\n"
29389 + " movq %%mm1, 8(%2)\n"
29390 + " movq %%mm2, 16(%2)\n"
29391 + " movq %%mm3, 24(%2)\n"
29392 + " movq 32(%1), %%mm0\n"
29393 + " movq 40(%1), %%mm1\n"
29394 + " movq 48(%1), %%mm2\n"
29395 + " movq 56(%1), %%mm3\n"
29396 + " movq %%mm0, 32(%2)\n"
29397 + " movq %%mm1, 40(%2)\n"
29398 + " movq %%mm2, 48(%2)\n"
29399 + " movq %%mm3, 56(%2)\n"
29400 ".section .fixup, \"ax\"\n"
29401 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29402 + "3:\n"
29403 +
29404 +#ifdef CONFIG_PAX_KERNEXEC
29405 + " movl %%cr0, %0\n"
29406 + " movl %0, %%eax\n"
29407 + " andl $0xFFFEFFFF, %%eax\n"
29408 + " movl %%eax, %%cr0\n"
29409 +#endif
29410 +
29411 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29412 +
29413 +#ifdef CONFIG_PAX_KERNEXEC
29414 + " movl %0, %%cr0\n"
29415 +#endif
29416 +
29417 " jmp 2b\n"
29418 ".previous\n"
29419 _ASM_EXTABLE(1b, 3b)
29420 - : : "r" (from), "r" (to) : "memory");
29421 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29422
29423 from += 64;
29424 to += 64;
29425 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29426 static void fast_copy_page(void *to, void *from)
29427 {
29428 int i;
29429 + unsigned long cr0;
29430
29431 kernel_fpu_begin();
29432
29433 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29434 * but that is for later. -AV
29435 */
29436 __asm__ __volatile__(
29437 - "1: prefetch (%0)\n"
29438 - " prefetch 64(%0)\n"
29439 - " prefetch 128(%0)\n"
29440 - " prefetch 192(%0)\n"
29441 - " prefetch 256(%0)\n"
29442 + "1: prefetch (%1)\n"
29443 + " prefetch 64(%1)\n"
29444 + " prefetch 128(%1)\n"
29445 + " prefetch 192(%1)\n"
29446 + " prefetch 256(%1)\n"
29447 "2: \n"
29448 ".section .fixup, \"ax\"\n"
29449 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29450 + "3: \n"
29451 +
29452 +#ifdef CONFIG_PAX_KERNEXEC
29453 + " movl %%cr0, %0\n"
29454 + " movl %0, %%eax\n"
29455 + " andl $0xFFFEFFFF, %%eax\n"
29456 + " movl %%eax, %%cr0\n"
29457 +#endif
29458 +
29459 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29460 +
29461 +#ifdef CONFIG_PAX_KERNEXEC
29462 + " movl %0, %%cr0\n"
29463 +#endif
29464 +
29465 " jmp 2b\n"
29466 ".previous\n"
29467 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29468 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29469
29470 for (i = 0; i < (4096-320)/64; i++) {
29471 __asm__ __volatile__ (
29472 - "1: prefetch 320(%0)\n"
29473 - "2: movq (%0), %%mm0\n"
29474 - " movntq %%mm0, (%1)\n"
29475 - " movq 8(%0), %%mm1\n"
29476 - " movntq %%mm1, 8(%1)\n"
29477 - " movq 16(%0), %%mm2\n"
29478 - " movntq %%mm2, 16(%1)\n"
29479 - " movq 24(%0), %%mm3\n"
29480 - " movntq %%mm3, 24(%1)\n"
29481 - " movq 32(%0), %%mm4\n"
29482 - " movntq %%mm4, 32(%1)\n"
29483 - " movq 40(%0), %%mm5\n"
29484 - " movntq %%mm5, 40(%1)\n"
29485 - " movq 48(%0), %%mm6\n"
29486 - " movntq %%mm6, 48(%1)\n"
29487 - " movq 56(%0), %%mm7\n"
29488 - " movntq %%mm7, 56(%1)\n"
29489 + "1: prefetch 320(%1)\n"
29490 + "2: movq (%1), %%mm0\n"
29491 + " movntq %%mm0, (%2)\n"
29492 + " movq 8(%1), %%mm1\n"
29493 + " movntq %%mm1, 8(%2)\n"
29494 + " movq 16(%1), %%mm2\n"
29495 + " movntq %%mm2, 16(%2)\n"
29496 + " movq 24(%1), %%mm3\n"
29497 + " movntq %%mm3, 24(%2)\n"
29498 + " movq 32(%1), %%mm4\n"
29499 + " movntq %%mm4, 32(%2)\n"
29500 + " movq 40(%1), %%mm5\n"
29501 + " movntq %%mm5, 40(%2)\n"
29502 + " movq 48(%1), %%mm6\n"
29503 + " movntq %%mm6, 48(%2)\n"
29504 + " movq 56(%1), %%mm7\n"
29505 + " movntq %%mm7, 56(%2)\n"
29506 ".section .fixup, \"ax\"\n"
29507 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29508 + "3:\n"
29509 +
29510 +#ifdef CONFIG_PAX_KERNEXEC
29511 + " movl %%cr0, %0\n"
29512 + " movl %0, %%eax\n"
29513 + " andl $0xFFFEFFFF, %%eax\n"
29514 + " movl %%eax, %%cr0\n"
29515 +#endif
29516 +
29517 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29518 +
29519 +#ifdef CONFIG_PAX_KERNEXEC
29520 + " movl %0, %%cr0\n"
29521 +#endif
29522 +
29523 " jmp 2b\n"
29524 ".previous\n"
29525 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29526 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29527
29528 from += 64;
29529 to += 64;
29530 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29531 static void fast_copy_page(void *to, void *from)
29532 {
29533 int i;
29534 + unsigned long cr0;
29535
29536 kernel_fpu_begin();
29537
29538 __asm__ __volatile__ (
29539 - "1: prefetch (%0)\n"
29540 - " prefetch 64(%0)\n"
29541 - " prefetch 128(%0)\n"
29542 - " prefetch 192(%0)\n"
29543 - " prefetch 256(%0)\n"
29544 + "1: prefetch (%1)\n"
29545 + " prefetch 64(%1)\n"
29546 + " prefetch 128(%1)\n"
29547 + " prefetch 192(%1)\n"
29548 + " prefetch 256(%1)\n"
29549 "2: \n"
29550 ".section .fixup, \"ax\"\n"
29551 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29552 + "3: \n"
29553 +
29554 +#ifdef CONFIG_PAX_KERNEXEC
29555 + " movl %%cr0, %0\n"
29556 + " movl %0, %%eax\n"
29557 + " andl $0xFFFEFFFF, %%eax\n"
29558 + " movl %%eax, %%cr0\n"
29559 +#endif
29560 +
29561 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29562 +
29563 +#ifdef CONFIG_PAX_KERNEXEC
29564 + " movl %0, %%cr0\n"
29565 +#endif
29566 +
29567 " jmp 2b\n"
29568 ".previous\n"
29569 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29570 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29571
29572 for (i = 0; i < 4096/64; i++) {
29573 __asm__ __volatile__ (
29574 - "1: prefetch 320(%0)\n"
29575 - "2: movq (%0), %%mm0\n"
29576 - " movq 8(%0), %%mm1\n"
29577 - " movq 16(%0), %%mm2\n"
29578 - " movq 24(%0), %%mm3\n"
29579 - " movq %%mm0, (%1)\n"
29580 - " movq %%mm1, 8(%1)\n"
29581 - " movq %%mm2, 16(%1)\n"
29582 - " movq %%mm3, 24(%1)\n"
29583 - " movq 32(%0), %%mm0\n"
29584 - " movq 40(%0), %%mm1\n"
29585 - " movq 48(%0), %%mm2\n"
29586 - " movq 56(%0), %%mm3\n"
29587 - " movq %%mm0, 32(%1)\n"
29588 - " movq %%mm1, 40(%1)\n"
29589 - " movq %%mm2, 48(%1)\n"
29590 - " movq %%mm3, 56(%1)\n"
29591 + "1: prefetch 320(%1)\n"
29592 + "2: movq (%1), %%mm0\n"
29593 + " movq 8(%1), %%mm1\n"
29594 + " movq 16(%1), %%mm2\n"
29595 + " movq 24(%1), %%mm3\n"
29596 + " movq %%mm0, (%2)\n"
29597 + " movq %%mm1, 8(%2)\n"
29598 + " movq %%mm2, 16(%2)\n"
29599 + " movq %%mm3, 24(%2)\n"
29600 + " movq 32(%1), %%mm0\n"
29601 + " movq 40(%1), %%mm1\n"
29602 + " movq 48(%1), %%mm2\n"
29603 + " movq 56(%1), %%mm3\n"
29604 + " movq %%mm0, 32(%2)\n"
29605 + " movq %%mm1, 40(%2)\n"
29606 + " movq %%mm2, 48(%2)\n"
29607 + " movq %%mm3, 56(%2)\n"
29608 ".section .fixup, \"ax\"\n"
29609 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29610 + "3:\n"
29611 +
29612 +#ifdef CONFIG_PAX_KERNEXEC
29613 + " movl %%cr0, %0\n"
29614 + " movl %0, %%eax\n"
29615 + " andl $0xFFFEFFFF, %%eax\n"
29616 + " movl %%eax, %%cr0\n"
29617 +#endif
29618 +
29619 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29620 +
29621 +#ifdef CONFIG_PAX_KERNEXEC
29622 + " movl %0, %%cr0\n"
29623 +#endif
29624 +
29625 " jmp 2b\n"
29626 ".previous\n"
29627 _ASM_EXTABLE(1b, 3b)
29628 - : : "r" (from), "r" (to) : "memory");
29629 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29630
29631 from += 64;
29632 to += 64;
29633 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29634 index f6d13ee..d789440 100644
29635 --- a/arch/x86/lib/msr-reg.S
29636 +++ b/arch/x86/lib/msr-reg.S
29637 @@ -3,6 +3,7 @@
29638 #include <asm/dwarf2.h>
29639 #include <asm/asm.h>
29640 #include <asm/msr.h>
29641 +#include <asm/alternative-asm.h>
29642
29643 #ifdef CONFIG_X86_64
29644 /*
29645 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
29646 movl %edi, 28(%r10)
29647 popq_cfi %rbp
29648 popq_cfi %rbx
29649 + pax_force_retaddr
29650 ret
29651 3:
29652 CFI_RESTORE_STATE
29653 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29654 index fc6ba17..d4d989d 100644
29655 --- a/arch/x86/lib/putuser.S
29656 +++ b/arch/x86/lib/putuser.S
29657 @@ -16,7 +16,9 @@
29658 #include <asm/errno.h>
29659 #include <asm/asm.h>
29660 #include <asm/smap.h>
29661 -
29662 +#include <asm/segment.h>
29663 +#include <asm/pgtable.h>
29664 +#include <asm/alternative-asm.h>
29665
29666 /*
29667 * __put_user_X
29668 @@ -30,57 +32,125 @@
29669 * as they get called from within inline assembly.
29670 */
29671
29672 -#define ENTER CFI_STARTPROC ; \
29673 - GET_THREAD_INFO(%_ASM_BX)
29674 -#define EXIT ASM_CLAC ; \
29675 - ret ; \
29676 +#define ENTER CFI_STARTPROC
29677 +#define EXIT ASM_CLAC ; \
29678 + pax_force_retaddr ; \
29679 + ret ; \
29680 CFI_ENDPROC
29681
29682 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29683 +#define _DEST %_ASM_CX,%_ASM_BX
29684 +#else
29685 +#define _DEST %_ASM_CX
29686 +#endif
29687 +
29688 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29689 +#define __copyuser_seg gs;
29690 +#else
29691 +#define __copyuser_seg
29692 +#endif
29693 +
29694 .text
29695 ENTRY(__put_user_1)
29696 ENTER
29697 +
29698 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29699 + GET_THREAD_INFO(%_ASM_BX)
29700 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29701 jae bad_put_user
29702 ASM_STAC
29703 -1: movb %al,(%_ASM_CX)
29704 +
29705 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29706 + mov pax_user_shadow_base,%_ASM_BX
29707 + cmp %_ASM_BX,%_ASM_CX
29708 + jb 1234f
29709 + xor %ebx,%ebx
29710 +1234:
29711 +#endif
29712 +
29713 +#endif
29714 +
29715 +1: __copyuser_seg movb %al,(_DEST)
29716 xor %eax,%eax
29717 EXIT
29718 ENDPROC(__put_user_1)
29719
29720 ENTRY(__put_user_2)
29721 ENTER
29722 +
29723 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29724 + GET_THREAD_INFO(%_ASM_BX)
29725 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29726 sub $1,%_ASM_BX
29727 cmp %_ASM_BX,%_ASM_CX
29728 jae bad_put_user
29729 ASM_STAC
29730 -2: movw %ax,(%_ASM_CX)
29731 +
29732 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29733 + mov pax_user_shadow_base,%_ASM_BX
29734 + cmp %_ASM_BX,%_ASM_CX
29735 + jb 1234f
29736 + xor %ebx,%ebx
29737 +1234:
29738 +#endif
29739 +
29740 +#endif
29741 +
29742 +2: __copyuser_seg movw %ax,(_DEST)
29743 xor %eax,%eax
29744 EXIT
29745 ENDPROC(__put_user_2)
29746
29747 ENTRY(__put_user_4)
29748 ENTER
29749 +
29750 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29751 + GET_THREAD_INFO(%_ASM_BX)
29752 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29753 sub $3,%_ASM_BX
29754 cmp %_ASM_BX,%_ASM_CX
29755 jae bad_put_user
29756 ASM_STAC
29757 -3: movl %eax,(%_ASM_CX)
29758 +
29759 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29760 + mov pax_user_shadow_base,%_ASM_BX
29761 + cmp %_ASM_BX,%_ASM_CX
29762 + jb 1234f
29763 + xor %ebx,%ebx
29764 +1234:
29765 +#endif
29766 +
29767 +#endif
29768 +
29769 +3: __copyuser_seg movl %eax,(_DEST)
29770 xor %eax,%eax
29771 EXIT
29772 ENDPROC(__put_user_4)
29773
29774 ENTRY(__put_user_8)
29775 ENTER
29776 +
29777 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29778 + GET_THREAD_INFO(%_ASM_BX)
29779 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29780 sub $7,%_ASM_BX
29781 cmp %_ASM_BX,%_ASM_CX
29782 jae bad_put_user
29783 ASM_STAC
29784 -4: mov %_ASM_AX,(%_ASM_CX)
29785 +
29786 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29787 + mov pax_user_shadow_base,%_ASM_BX
29788 + cmp %_ASM_BX,%_ASM_CX
29789 + jb 1234f
29790 + xor %ebx,%ebx
29791 +1234:
29792 +#endif
29793 +
29794 +#endif
29795 +
29796 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
29797 #ifdef CONFIG_X86_32
29798 -5: movl %edx,4(%_ASM_CX)
29799 +5: __copyuser_seg movl %edx,4(_DEST)
29800 #endif
29801 xor %eax,%eax
29802 EXIT
29803 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29804 index 1cad221..de671ee 100644
29805 --- a/arch/x86/lib/rwlock.S
29806 +++ b/arch/x86/lib/rwlock.S
29807 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29808 FRAME
29809 0: LOCK_PREFIX
29810 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29811 +
29812 +#ifdef CONFIG_PAX_REFCOUNT
29813 + jno 1234f
29814 + LOCK_PREFIX
29815 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29816 + int $4
29817 +1234:
29818 + _ASM_EXTABLE(1234b, 1234b)
29819 +#endif
29820 +
29821 1: rep; nop
29822 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29823 jne 1b
29824 LOCK_PREFIX
29825 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29826 +
29827 +#ifdef CONFIG_PAX_REFCOUNT
29828 + jno 1234f
29829 + LOCK_PREFIX
29830 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29831 + int $4
29832 +1234:
29833 + _ASM_EXTABLE(1234b, 1234b)
29834 +#endif
29835 +
29836 jnz 0b
29837 ENDFRAME
29838 + pax_force_retaddr
29839 ret
29840 CFI_ENDPROC
29841 END(__write_lock_failed)
29842 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29843 FRAME
29844 0: LOCK_PREFIX
29845 READ_LOCK_SIZE(inc) (%__lock_ptr)
29846 +
29847 +#ifdef CONFIG_PAX_REFCOUNT
29848 + jno 1234f
29849 + LOCK_PREFIX
29850 + READ_LOCK_SIZE(dec) (%__lock_ptr)
29851 + int $4
29852 +1234:
29853 + _ASM_EXTABLE(1234b, 1234b)
29854 +#endif
29855 +
29856 1: rep; nop
29857 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29858 js 1b
29859 LOCK_PREFIX
29860 READ_LOCK_SIZE(dec) (%__lock_ptr)
29861 +
29862 +#ifdef CONFIG_PAX_REFCOUNT
29863 + jno 1234f
29864 + LOCK_PREFIX
29865 + READ_LOCK_SIZE(inc) (%__lock_ptr)
29866 + int $4
29867 +1234:
29868 + _ASM_EXTABLE(1234b, 1234b)
29869 +#endif
29870 +
29871 js 0b
29872 ENDFRAME
29873 + pax_force_retaddr
29874 ret
29875 CFI_ENDPROC
29876 END(__read_lock_failed)
29877 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29878 index 5dff5f0..cadebf4 100644
29879 --- a/arch/x86/lib/rwsem.S
29880 +++ b/arch/x86/lib/rwsem.S
29881 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29882 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29883 CFI_RESTORE __ASM_REG(dx)
29884 restore_common_regs
29885 + pax_force_retaddr
29886 ret
29887 CFI_ENDPROC
29888 ENDPROC(call_rwsem_down_read_failed)
29889 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29890 movq %rax,%rdi
29891 call rwsem_down_write_failed
29892 restore_common_regs
29893 + pax_force_retaddr
29894 ret
29895 CFI_ENDPROC
29896 ENDPROC(call_rwsem_down_write_failed)
29897 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29898 movq %rax,%rdi
29899 call rwsem_wake
29900 restore_common_regs
29901 -1: ret
29902 +1: pax_force_retaddr
29903 + ret
29904 CFI_ENDPROC
29905 ENDPROC(call_rwsem_wake)
29906
29907 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29908 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29909 CFI_RESTORE __ASM_REG(dx)
29910 restore_common_regs
29911 + pax_force_retaddr
29912 ret
29913 CFI_ENDPROC
29914 ENDPROC(call_rwsem_downgrade_wake)
29915 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29916 index a63efd6..8149fbe 100644
29917 --- a/arch/x86/lib/thunk_64.S
29918 +++ b/arch/x86/lib/thunk_64.S
29919 @@ -8,6 +8,7 @@
29920 #include <linux/linkage.h>
29921 #include <asm/dwarf2.h>
29922 #include <asm/calling.h>
29923 +#include <asm/alternative-asm.h>
29924
29925 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29926 .macro THUNK name, func, put_ret_addr_in_rdi=0
29927 @@ -15,11 +16,11 @@
29928 \name:
29929 CFI_STARTPROC
29930
29931 - /* this one pushes 9 elems, the next one would be %rIP */
29932 - SAVE_ARGS
29933 + /* this one pushes 15+1 elems, the next one would be %rIP */
29934 + SAVE_ARGS 8
29935
29936 .if \put_ret_addr_in_rdi
29937 - movq_cfi_restore 9*8, rdi
29938 + movq_cfi_restore RIP, rdi
29939 .endif
29940
29941 call \func
29942 @@ -38,8 +39,9 @@
29943
29944 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
29945 CFI_STARTPROC
29946 - SAVE_ARGS
29947 + SAVE_ARGS 8
29948 restore:
29949 - RESTORE_ARGS
29950 + RESTORE_ARGS 1,8
29951 + pax_force_retaddr
29952 ret
29953 CFI_ENDPROC
29954 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29955 index e2f5e21..4b22130 100644
29956 --- a/arch/x86/lib/usercopy_32.c
29957 +++ b/arch/x86/lib/usercopy_32.c
29958 @@ -42,11 +42,13 @@ do { \
29959 int __d0; \
29960 might_fault(); \
29961 __asm__ __volatile__( \
29962 + __COPYUSER_SET_ES \
29963 ASM_STAC "\n" \
29964 "0: rep; stosl\n" \
29965 " movl %2,%0\n" \
29966 "1: rep; stosb\n" \
29967 "2: " ASM_CLAC "\n" \
29968 + __COPYUSER_RESTORE_ES \
29969 ".section .fixup,\"ax\"\n" \
29970 "3: lea 0(%2,%0,4),%0\n" \
29971 " jmp 2b\n" \
29972 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29973
29974 #ifdef CONFIG_X86_INTEL_USERCOPY
29975 static unsigned long
29976 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
29977 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29978 {
29979 int d0, d1;
29980 __asm__ __volatile__(
29981 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29982 " .align 2,0x90\n"
29983 "3: movl 0(%4), %%eax\n"
29984 "4: movl 4(%4), %%edx\n"
29985 - "5: movl %%eax, 0(%3)\n"
29986 - "6: movl %%edx, 4(%3)\n"
29987 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29988 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29989 "7: movl 8(%4), %%eax\n"
29990 "8: movl 12(%4),%%edx\n"
29991 - "9: movl %%eax, 8(%3)\n"
29992 - "10: movl %%edx, 12(%3)\n"
29993 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29994 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29995 "11: movl 16(%4), %%eax\n"
29996 "12: movl 20(%4), %%edx\n"
29997 - "13: movl %%eax, 16(%3)\n"
29998 - "14: movl %%edx, 20(%3)\n"
29999 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30000 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30001 "15: movl 24(%4), %%eax\n"
30002 "16: movl 28(%4), %%edx\n"
30003 - "17: movl %%eax, 24(%3)\n"
30004 - "18: movl %%edx, 28(%3)\n"
30005 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30006 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30007 "19: movl 32(%4), %%eax\n"
30008 "20: movl 36(%4), %%edx\n"
30009 - "21: movl %%eax, 32(%3)\n"
30010 - "22: movl %%edx, 36(%3)\n"
30011 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30012 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30013 "23: movl 40(%4), %%eax\n"
30014 "24: movl 44(%4), %%edx\n"
30015 - "25: movl %%eax, 40(%3)\n"
30016 - "26: movl %%edx, 44(%3)\n"
30017 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30018 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30019 "27: movl 48(%4), %%eax\n"
30020 "28: movl 52(%4), %%edx\n"
30021 - "29: movl %%eax, 48(%3)\n"
30022 - "30: movl %%edx, 52(%3)\n"
30023 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30024 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30025 "31: movl 56(%4), %%eax\n"
30026 "32: movl 60(%4), %%edx\n"
30027 - "33: movl %%eax, 56(%3)\n"
30028 - "34: movl %%edx, 60(%3)\n"
30029 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30030 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30031 " addl $-64, %0\n"
30032 " addl $64, %4\n"
30033 " addl $64, %3\n"
30034 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30035 " shrl $2, %0\n"
30036 " andl $3, %%eax\n"
30037 " cld\n"
30038 + __COPYUSER_SET_ES
30039 "99: rep; movsl\n"
30040 "36: movl %%eax, %0\n"
30041 "37: rep; movsb\n"
30042 "100:\n"
30043 + __COPYUSER_RESTORE_ES
30044 + ".section .fixup,\"ax\"\n"
30045 + "101: lea 0(%%eax,%0,4),%0\n"
30046 + " jmp 100b\n"
30047 + ".previous\n"
30048 + _ASM_EXTABLE(1b,100b)
30049 + _ASM_EXTABLE(2b,100b)
30050 + _ASM_EXTABLE(3b,100b)
30051 + _ASM_EXTABLE(4b,100b)
30052 + _ASM_EXTABLE(5b,100b)
30053 + _ASM_EXTABLE(6b,100b)
30054 + _ASM_EXTABLE(7b,100b)
30055 + _ASM_EXTABLE(8b,100b)
30056 + _ASM_EXTABLE(9b,100b)
30057 + _ASM_EXTABLE(10b,100b)
30058 + _ASM_EXTABLE(11b,100b)
30059 + _ASM_EXTABLE(12b,100b)
30060 + _ASM_EXTABLE(13b,100b)
30061 + _ASM_EXTABLE(14b,100b)
30062 + _ASM_EXTABLE(15b,100b)
30063 + _ASM_EXTABLE(16b,100b)
30064 + _ASM_EXTABLE(17b,100b)
30065 + _ASM_EXTABLE(18b,100b)
30066 + _ASM_EXTABLE(19b,100b)
30067 + _ASM_EXTABLE(20b,100b)
30068 + _ASM_EXTABLE(21b,100b)
30069 + _ASM_EXTABLE(22b,100b)
30070 + _ASM_EXTABLE(23b,100b)
30071 + _ASM_EXTABLE(24b,100b)
30072 + _ASM_EXTABLE(25b,100b)
30073 + _ASM_EXTABLE(26b,100b)
30074 + _ASM_EXTABLE(27b,100b)
30075 + _ASM_EXTABLE(28b,100b)
30076 + _ASM_EXTABLE(29b,100b)
30077 + _ASM_EXTABLE(30b,100b)
30078 + _ASM_EXTABLE(31b,100b)
30079 + _ASM_EXTABLE(32b,100b)
30080 + _ASM_EXTABLE(33b,100b)
30081 + _ASM_EXTABLE(34b,100b)
30082 + _ASM_EXTABLE(35b,100b)
30083 + _ASM_EXTABLE(36b,100b)
30084 + _ASM_EXTABLE(37b,100b)
30085 + _ASM_EXTABLE(99b,101b)
30086 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30087 + : "1"(to), "2"(from), "0"(size)
30088 + : "eax", "edx", "memory");
30089 + return size;
30090 +}
30091 +
30092 +static unsigned long
30093 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30094 +{
30095 + int d0, d1;
30096 + __asm__ __volatile__(
30097 + " .align 2,0x90\n"
30098 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30099 + " cmpl $67, %0\n"
30100 + " jbe 3f\n"
30101 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30102 + " .align 2,0x90\n"
30103 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30104 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30105 + "5: movl %%eax, 0(%3)\n"
30106 + "6: movl %%edx, 4(%3)\n"
30107 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30108 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30109 + "9: movl %%eax, 8(%3)\n"
30110 + "10: movl %%edx, 12(%3)\n"
30111 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30112 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30113 + "13: movl %%eax, 16(%3)\n"
30114 + "14: movl %%edx, 20(%3)\n"
30115 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30116 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30117 + "17: movl %%eax, 24(%3)\n"
30118 + "18: movl %%edx, 28(%3)\n"
30119 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30120 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30121 + "21: movl %%eax, 32(%3)\n"
30122 + "22: movl %%edx, 36(%3)\n"
30123 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30124 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30125 + "25: movl %%eax, 40(%3)\n"
30126 + "26: movl %%edx, 44(%3)\n"
30127 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30128 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30129 + "29: movl %%eax, 48(%3)\n"
30130 + "30: movl %%edx, 52(%3)\n"
30131 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30132 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30133 + "33: movl %%eax, 56(%3)\n"
30134 + "34: movl %%edx, 60(%3)\n"
30135 + " addl $-64, %0\n"
30136 + " addl $64, %4\n"
30137 + " addl $64, %3\n"
30138 + " cmpl $63, %0\n"
30139 + " ja 1b\n"
30140 + "35: movl %0, %%eax\n"
30141 + " shrl $2, %0\n"
30142 + " andl $3, %%eax\n"
30143 + " cld\n"
30144 + "99: rep; "__copyuser_seg" movsl\n"
30145 + "36: movl %%eax, %0\n"
30146 + "37: rep; "__copyuser_seg" movsb\n"
30147 + "100:\n"
30148 ".section .fixup,\"ax\"\n"
30149 "101: lea 0(%%eax,%0,4),%0\n"
30150 " jmp 100b\n"
30151 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30152 int d0, d1;
30153 __asm__ __volatile__(
30154 " .align 2,0x90\n"
30155 - "0: movl 32(%4), %%eax\n"
30156 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30157 " cmpl $67, %0\n"
30158 " jbe 2f\n"
30159 - "1: movl 64(%4), %%eax\n"
30160 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30161 " .align 2,0x90\n"
30162 - "2: movl 0(%4), %%eax\n"
30163 - "21: movl 4(%4), %%edx\n"
30164 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30165 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30166 " movl %%eax, 0(%3)\n"
30167 " movl %%edx, 4(%3)\n"
30168 - "3: movl 8(%4), %%eax\n"
30169 - "31: movl 12(%4),%%edx\n"
30170 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30171 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30172 " movl %%eax, 8(%3)\n"
30173 " movl %%edx, 12(%3)\n"
30174 - "4: movl 16(%4), %%eax\n"
30175 - "41: movl 20(%4), %%edx\n"
30176 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30177 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30178 " movl %%eax, 16(%3)\n"
30179 " movl %%edx, 20(%3)\n"
30180 - "10: movl 24(%4), %%eax\n"
30181 - "51: movl 28(%4), %%edx\n"
30182 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30183 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30184 " movl %%eax, 24(%3)\n"
30185 " movl %%edx, 28(%3)\n"
30186 - "11: movl 32(%4), %%eax\n"
30187 - "61: movl 36(%4), %%edx\n"
30188 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30189 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30190 " movl %%eax, 32(%3)\n"
30191 " movl %%edx, 36(%3)\n"
30192 - "12: movl 40(%4), %%eax\n"
30193 - "71: movl 44(%4), %%edx\n"
30194 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30195 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30196 " movl %%eax, 40(%3)\n"
30197 " movl %%edx, 44(%3)\n"
30198 - "13: movl 48(%4), %%eax\n"
30199 - "81: movl 52(%4), %%edx\n"
30200 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30201 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30202 " movl %%eax, 48(%3)\n"
30203 " movl %%edx, 52(%3)\n"
30204 - "14: movl 56(%4), %%eax\n"
30205 - "91: movl 60(%4), %%edx\n"
30206 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30207 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30208 " movl %%eax, 56(%3)\n"
30209 " movl %%edx, 60(%3)\n"
30210 " addl $-64, %0\n"
30211 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30212 " shrl $2, %0\n"
30213 " andl $3, %%eax\n"
30214 " cld\n"
30215 - "6: rep; movsl\n"
30216 + "6: rep; "__copyuser_seg" movsl\n"
30217 " movl %%eax,%0\n"
30218 - "7: rep; movsb\n"
30219 + "7: rep; "__copyuser_seg" movsb\n"
30220 "8:\n"
30221 ".section .fixup,\"ax\"\n"
30222 "9: lea 0(%%eax,%0,4),%0\n"
30223 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30224
30225 __asm__ __volatile__(
30226 " .align 2,0x90\n"
30227 - "0: movl 32(%4), %%eax\n"
30228 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30229 " cmpl $67, %0\n"
30230 " jbe 2f\n"
30231 - "1: movl 64(%4), %%eax\n"
30232 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30233 " .align 2,0x90\n"
30234 - "2: movl 0(%4), %%eax\n"
30235 - "21: movl 4(%4), %%edx\n"
30236 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30237 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30238 " movnti %%eax, 0(%3)\n"
30239 " movnti %%edx, 4(%3)\n"
30240 - "3: movl 8(%4), %%eax\n"
30241 - "31: movl 12(%4),%%edx\n"
30242 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30243 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30244 " movnti %%eax, 8(%3)\n"
30245 " movnti %%edx, 12(%3)\n"
30246 - "4: movl 16(%4), %%eax\n"
30247 - "41: movl 20(%4), %%edx\n"
30248 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30249 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30250 " movnti %%eax, 16(%3)\n"
30251 " movnti %%edx, 20(%3)\n"
30252 - "10: movl 24(%4), %%eax\n"
30253 - "51: movl 28(%4), %%edx\n"
30254 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30255 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30256 " movnti %%eax, 24(%3)\n"
30257 " movnti %%edx, 28(%3)\n"
30258 - "11: movl 32(%4), %%eax\n"
30259 - "61: movl 36(%4), %%edx\n"
30260 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30261 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30262 " movnti %%eax, 32(%3)\n"
30263 " movnti %%edx, 36(%3)\n"
30264 - "12: movl 40(%4), %%eax\n"
30265 - "71: movl 44(%4), %%edx\n"
30266 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30267 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30268 " movnti %%eax, 40(%3)\n"
30269 " movnti %%edx, 44(%3)\n"
30270 - "13: movl 48(%4), %%eax\n"
30271 - "81: movl 52(%4), %%edx\n"
30272 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30273 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30274 " movnti %%eax, 48(%3)\n"
30275 " movnti %%edx, 52(%3)\n"
30276 - "14: movl 56(%4), %%eax\n"
30277 - "91: movl 60(%4), %%edx\n"
30278 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30279 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30280 " movnti %%eax, 56(%3)\n"
30281 " movnti %%edx, 60(%3)\n"
30282 " addl $-64, %0\n"
30283 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30284 " shrl $2, %0\n"
30285 " andl $3, %%eax\n"
30286 " cld\n"
30287 - "6: rep; movsl\n"
30288 + "6: rep; "__copyuser_seg" movsl\n"
30289 " movl %%eax,%0\n"
30290 - "7: rep; movsb\n"
30291 + "7: rep; "__copyuser_seg" movsb\n"
30292 "8:\n"
30293 ".section .fixup,\"ax\"\n"
30294 "9: lea 0(%%eax,%0,4),%0\n"
30295 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30296
30297 __asm__ __volatile__(
30298 " .align 2,0x90\n"
30299 - "0: movl 32(%4), %%eax\n"
30300 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30301 " cmpl $67, %0\n"
30302 " jbe 2f\n"
30303 - "1: movl 64(%4), %%eax\n"
30304 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30305 " .align 2,0x90\n"
30306 - "2: movl 0(%4), %%eax\n"
30307 - "21: movl 4(%4), %%edx\n"
30308 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30309 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30310 " movnti %%eax, 0(%3)\n"
30311 " movnti %%edx, 4(%3)\n"
30312 - "3: movl 8(%4), %%eax\n"
30313 - "31: movl 12(%4),%%edx\n"
30314 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30315 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30316 " movnti %%eax, 8(%3)\n"
30317 " movnti %%edx, 12(%3)\n"
30318 - "4: movl 16(%4), %%eax\n"
30319 - "41: movl 20(%4), %%edx\n"
30320 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30321 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30322 " movnti %%eax, 16(%3)\n"
30323 " movnti %%edx, 20(%3)\n"
30324 - "10: movl 24(%4), %%eax\n"
30325 - "51: movl 28(%4), %%edx\n"
30326 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30327 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30328 " movnti %%eax, 24(%3)\n"
30329 " movnti %%edx, 28(%3)\n"
30330 - "11: movl 32(%4), %%eax\n"
30331 - "61: movl 36(%4), %%edx\n"
30332 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30333 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30334 " movnti %%eax, 32(%3)\n"
30335 " movnti %%edx, 36(%3)\n"
30336 - "12: movl 40(%4), %%eax\n"
30337 - "71: movl 44(%4), %%edx\n"
30338 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30339 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30340 " movnti %%eax, 40(%3)\n"
30341 " movnti %%edx, 44(%3)\n"
30342 - "13: movl 48(%4), %%eax\n"
30343 - "81: movl 52(%4), %%edx\n"
30344 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30345 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30346 " movnti %%eax, 48(%3)\n"
30347 " movnti %%edx, 52(%3)\n"
30348 - "14: movl 56(%4), %%eax\n"
30349 - "91: movl 60(%4), %%edx\n"
30350 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30351 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30352 " movnti %%eax, 56(%3)\n"
30353 " movnti %%edx, 60(%3)\n"
30354 " addl $-64, %0\n"
30355 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30356 " shrl $2, %0\n"
30357 " andl $3, %%eax\n"
30358 " cld\n"
30359 - "6: rep; movsl\n"
30360 + "6: rep; "__copyuser_seg" movsl\n"
30361 " movl %%eax,%0\n"
30362 - "7: rep; movsb\n"
30363 + "7: rep; "__copyuser_seg" movsb\n"
30364 "8:\n"
30365 ".section .fixup,\"ax\"\n"
30366 "9: lea 0(%%eax,%0,4),%0\n"
30367 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30368 */
30369 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30370 unsigned long size);
30371 -unsigned long __copy_user_intel(void __user *to, const void *from,
30372 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30373 + unsigned long size);
30374 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30375 unsigned long size);
30376 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30377 const void __user *from, unsigned long size);
30378 #endif /* CONFIG_X86_INTEL_USERCOPY */
30379
30380 /* Generic arbitrary sized copy. */
30381 -#define __copy_user(to, from, size) \
30382 +#define __copy_user(to, from, size, prefix, set, restore) \
30383 do { \
30384 int __d0, __d1, __d2; \
30385 __asm__ __volatile__( \
30386 + set \
30387 " cmp $7,%0\n" \
30388 " jbe 1f\n" \
30389 " movl %1,%0\n" \
30390 " negl %0\n" \
30391 " andl $7,%0\n" \
30392 " subl %0,%3\n" \
30393 - "4: rep; movsb\n" \
30394 + "4: rep; "prefix"movsb\n" \
30395 " movl %3,%0\n" \
30396 " shrl $2,%0\n" \
30397 " andl $3,%3\n" \
30398 " .align 2,0x90\n" \
30399 - "0: rep; movsl\n" \
30400 + "0: rep; "prefix"movsl\n" \
30401 " movl %3,%0\n" \
30402 - "1: rep; movsb\n" \
30403 + "1: rep; "prefix"movsb\n" \
30404 "2:\n" \
30405 + restore \
30406 ".section .fixup,\"ax\"\n" \
30407 "5: addl %3,%0\n" \
30408 " jmp 2b\n" \
30409 @@ -538,14 +650,14 @@ do { \
30410 " negl %0\n" \
30411 " andl $7,%0\n" \
30412 " subl %0,%3\n" \
30413 - "4: rep; movsb\n" \
30414 + "4: rep; "__copyuser_seg"movsb\n" \
30415 " movl %3,%0\n" \
30416 " shrl $2,%0\n" \
30417 " andl $3,%3\n" \
30418 " .align 2,0x90\n" \
30419 - "0: rep; movsl\n" \
30420 + "0: rep; "__copyuser_seg"movsl\n" \
30421 " movl %3,%0\n" \
30422 - "1: rep; movsb\n" \
30423 + "1: rep; "__copyuser_seg"movsb\n" \
30424 "2:\n" \
30425 ".section .fixup,\"ax\"\n" \
30426 "5: addl %3,%0\n" \
30427 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30428 {
30429 stac();
30430 if (movsl_is_ok(to, from, n))
30431 - __copy_user(to, from, n);
30432 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30433 else
30434 - n = __copy_user_intel(to, from, n);
30435 + n = __generic_copy_to_user_intel(to, from, n);
30436 clac();
30437 return n;
30438 }
30439 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30440 {
30441 stac();
30442 if (movsl_is_ok(to, from, n))
30443 - __copy_user(to, from, n);
30444 + __copy_user(to, from, n, __copyuser_seg, "", "");
30445 else
30446 - n = __copy_user_intel((void __user *)to,
30447 - (const void *)from, n);
30448 + n = __generic_copy_from_user_intel(to, from, n);
30449 clac();
30450 return n;
30451 }
30452 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30453 if (n > 64 && cpu_has_xmm2)
30454 n = __copy_user_intel_nocache(to, from, n);
30455 else
30456 - __copy_user(to, from, n);
30457 + __copy_user(to, from, n, __copyuser_seg, "", "");
30458 #else
30459 - __copy_user(to, from, n);
30460 + __copy_user(to, from, n, __copyuser_seg, "", "");
30461 #endif
30462 clac();
30463 return n;
30464 }
30465 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30466
30467 -/**
30468 - * copy_to_user: - Copy a block of data into user space.
30469 - * @to: Destination address, in user space.
30470 - * @from: Source address, in kernel space.
30471 - * @n: Number of bytes to copy.
30472 - *
30473 - * Context: User context only. This function may sleep.
30474 - *
30475 - * Copy data from kernel space to user space.
30476 - *
30477 - * Returns number of bytes that could not be copied.
30478 - * On success, this will be zero.
30479 - */
30480 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30481 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30482 +void __set_fs(mm_segment_t x)
30483 {
30484 - if (access_ok(VERIFY_WRITE, to, n))
30485 - n = __copy_to_user(to, from, n);
30486 - return n;
30487 + switch (x.seg) {
30488 + case 0:
30489 + loadsegment(gs, 0);
30490 + break;
30491 + case TASK_SIZE_MAX:
30492 + loadsegment(gs, __USER_DS);
30493 + break;
30494 + case -1UL:
30495 + loadsegment(gs, __KERNEL_DS);
30496 + break;
30497 + default:
30498 + BUG();
30499 + }
30500 }
30501 -EXPORT_SYMBOL(_copy_to_user);
30502 +EXPORT_SYMBOL(__set_fs);
30503
30504 -/**
30505 - * copy_from_user: - Copy a block of data from user space.
30506 - * @to: Destination address, in kernel space.
30507 - * @from: Source address, in user space.
30508 - * @n: Number of bytes to copy.
30509 - *
30510 - * Context: User context only. This function may sleep.
30511 - *
30512 - * Copy data from user space to kernel space.
30513 - *
30514 - * Returns number of bytes that could not be copied.
30515 - * On success, this will be zero.
30516 - *
30517 - * If some data could not be copied, this function will pad the copied
30518 - * data to the requested size using zero bytes.
30519 - */
30520 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
30521 +void set_fs(mm_segment_t x)
30522 {
30523 - if (access_ok(VERIFY_READ, from, n))
30524 - n = __copy_from_user(to, from, n);
30525 - else
30526 - memset(to, 0, n);
30527 - return n;
30528 + current_thread_info()->addr_limit = x;
30529 + __set_fs(x);
30530 }
30531 -EXPORT_SYMBOL(_copy_from_user);
30532 +EXPORT_SYMBOL(set_fs);
30533 +#endif
30534 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30535 index c905e89..01ab928 100644
30536 --- a/arch/x86/lib/usercopy_64.c
30537 +++ b/arch/x86/lib/usercopy_64.c
30538 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30539 might_fault();
30540 /* no memory constraint because it doesn't change any memory gcc knows
30541 about */
30542 + pax_open_userland();
30543 stac();
30544 asm volatile(
30545 " testq %[size8],%[size8]\n"
30546 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30547 _ASM_EXTABLE(0b,3b)
30548 _ASM_EXTABLE(1b,2b)
30549 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30550 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30551 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30552 [zero] "r" (0UL), [eight] "r" (8UL));
30553 clac();
30554 + pax_close_userland();
30555 return size;
30556 }
30557 EXPORT_SYMBOL(__clear_user);
30558 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30559 }
30560 EXPORT_SYMBOL(clear_user);
30561
30562 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30563 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30564 {
30565 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30566 - return copy_user_generic((__force void *)to, (__force void *)from, len);
30567 - }
30568 - return len;
30569 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30570 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30571 + return len;
30572 }
30573 EXPORT_SYMBOL(copy_in_user);
30574
30575 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30576 * it is not necessary to optimize tail handling.
30577 */
30578 __visible unsigned long
30579 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30580 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30581 {
30582 char c;
30583 unsigned zero_len;
30584
30585 + clac();
30586 + pax_close_userland();
30587 for (; len; --len, to++) {
30588 if (__get_user_nocheck(c, from++, sizeof(char)))
30589 break;
30590 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30591 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30592 if (__put_user_nocheck(c, to++, sizeof(char)))
30593 break;
30594 - clac();
30595 return len;
30596 }
30597 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30598 index 6a19ad9..1c48f9a 100644
30599 --- a/arch/x86/mm/Makefile
30600 +++ b/arch/x86/mm/Makefile
30601 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30602 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30603
30604 obj-$(CONFIG_MEMTEST) += memtest.o
30605 +
30606 +quote:="
30607 +obj-$(CONFIG_X86_64) += uderef_64.o
30608 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30609 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30610 index 903ec1e..c4166b2 100644
30611 --- a/arch/x86/mm/extable.c
30612 +++ b/arch/x86/mm/extable.c
30613 @@ -6,12 +6,24 @@
30614 static inline unsigned long
30615 ex_insn_addr(const struct exception_table_entry *x)
30616 {
30617 - return (unsigned long)&x->insn + x->insn;
30618 + unsigned long reloc = 0;
30619 +
30620 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30621 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30622 +#endif
30623 +
30624 + return (unsigned long)&x->insn + x->insn + reloc;
30625 }
30626 static inline unsigned long
30627 ex_fixup_addr(const struct exception_table_entry *x)
30628 {
30629 - return (unsigned long)&x->fixup + x->fixup;
30630 + unsigned long reloc = 0;
30631 +
30632 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30633 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30634 +#endif
30635 +
30636 + return (unsigned long)&x->fixup + x->fixup + reloc;
30637 }
30638
30639 int fixup_exception(struct pt_regs *regs)
30640 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30641 unsigned long new_ip;
30642
30643 #ifdef CONFIG_PNPBIOS
30644 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30645 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30646 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30647 extern u32 pnp_bios_is_utter_crap;
30648 pnp_bios_is_utter_crap = 1;
30649 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30650 i += 4;
30651 p->fixup -= i;
30652 i += 4;
30653 +
30654 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30655 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30656 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30657 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30658 +#endif
30659 +
30660 }
30661 }
30662
30663 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30664 index 9d591c8..2e61790 100644
30665 --- a/arch/x86/mm/fault.c
30666 +++ b/arch/x86/mm/fault.c
30667 @@ -14,11 +14,18 @@
30668 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30669 #include <linux/prefetch.h> /* prefetchw */
30670 #include <linux/context_tracking.h> /* exception_enter(), ... */
30671 +#include <linux/unistd.h>
30672 +#include <linux/compiler.h>
30673
30674 #include <asm/traps.h> /* dotraplinkage, ... */
30675 #include <asm/pgalloc.h> /* pgd_*(), ... */
30676 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30677 #include <asm/fixmap.h> /* VSYSCALL_START */
30678 +#include <asm/tlbflush.h>
30679 +
30680 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30681 +#include <asm/stacktrace.h>
30682 +#endif
30683
30684 #define CREATE_TRACE_POINTS
30685 #include <asm/trace/exceptions.h>
30686 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
30687 int ret = 0;
30688
30689 /* kprobe_running() needs smp_processor_id() */
30690 - if (kprobes_built_in() && !user_mode_vm(regs)) {
30691 + if (kprobes_built_in() && !user_mode(regs)) {
30692 preempt_disable();
30693 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30694 ret = 1;
30695 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30696 return !instr_lo || (instr_lo>>1) == 1;
30697 case 0x00:
30698 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30699 - if (probe_kernel_address(instr, opcode))
30700 + if (user_mode(regs)) {
30701 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30702 + return 0;
30703 + } else if (probe_kernel_address(instr, opcode))
30704 return 0;
30705
30706 *prefetch = (instr_lo == 0xF) &&
30707 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30708 while (instr < max_instr) {
30709 unsigned char opcode;
30710
30711 - if (probe_kernel_address(instr, opcode))
30712 + if (user_mode(regs)) {
30713 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30714 + break;
30715 + } else if (probe_kernel_address(instr, opcode))
30716 break;
30717
30718 instr++;
30719 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30720 force_sig_info(si_signo, &info, tsk);
30721 }
30722
30723 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30724 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30725 +#endif
30726 +
30727 +#ifdef CONFIG_PAX_EMUTRAMP
30728 +static int pax_handle_fetch_fault(struct pt_regs *regs);
30729 +#endif
30730 +
30731 +#ifdef CONFIG_PAX_PAGEEXEC
30732 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30733 +{
30734 + pgd_t *pgd;
30735 + pud_t *pud;
30736 + pmd_t *pmd;
30737 +
30738 + pgd = pgd_offset(mm, address);
30739 + if (!pgd_present(*pgd))
30740 + return NULL;
30741 + pud = pud_offset(pgd, address);
30742 + if (!pud_present(*pud))
30743 + return NULL;
30744 + pmd = pmd_offset(pud, address);
30745 + if (!pmd_present(*pmd))
30746 + return NULL;
30747 + return pmd;
30748 +}
30749 +#endif
30750 +
30751 DEFINE_SPINLOCK(pgd_lock);
30752 LIST_HEAD(pgd_list);
30753
30754 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
30755 for (address = VMALLOC_START & PMD_MASK;
30756 address >= TASK_SIZE && address < FIXADDR_TOP;
30757 address += PMD_SIZE) {
30758 +
30759 +#ifdef CONFIG_PAX_PER_CPU_PGD
30760 + unsigned long cpu;
30761 +#else
30762 struct page *page;
30763 +#endif
30764
30765 spin_lock(&pgd_lock);
30766 +
30767 +#ifdef CONFIG_PAX_PER_CPU_PGD
30768 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30769 + pgd_t *pgd = get_cpu_pgd(cpu, user);
30770 + pmd_t *ret;
30771 +
30772 + ret = vmalloc_sync_one(pgd, address);
30773 + if (!ret)
30774 + break;
30775 + pgd = get_cpu_pgd(cpu, kernel);
30776 +#else
30777 list_for_each_entry(page, &pgd_list, lru) {
30778 + pgd_t *pgd;
30779 spinlock_t *pgt_lock;
30780 pmd_t *ret;
30781
30782 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
30783 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30784
30785 spin_lock(pgt_lock);
30786 - ret = vmalloc_sync_one(page_address(page), address);
30787 + pgd = page_address(page);
30788 +#endif
30789 +
30790 + ret = vmalloc_sync_one(pgd, address);
30791 +
30792 +#ifndef CONFIG_PAX_PER_CPU_PGD
30793 spin_unlock(pgt_lock);
30794 +#endif
30795
30796 if (!ret)
30797 break;
30798 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30799 * an interrupt in the middle of a task switch..
30800 */
30801 pgd_paddr = read_cr3();
30802 +
30803 +#ifdef CONFIG_PAX_PER_CPU_PGD
30804 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30805 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30806 +#endif
30807 +
30808 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30809 if (!pmd_k)
30810 return -1;
30811 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30812 * happen within a race in page table update. In the later
30813 * case just flush:
30814 */
30815 - pgd = pgd_offset(current->active_mm, address);
30816 +
30817 pgd_ref = pgd_offset_k(address);
30818 if (pgd_none(*pgd_ref))
30819 return -1;
30820
30821 +#ifdef CONFIG_PAX_PER_CPU_PGD
30822 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30823 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30824 + if (pgd_none(*pgd)) {
30825 + set_pgd(pgd, *pgd_ref);
30826 + arch_flush_lazy_mmu_mode();
30827 + } else {
30828 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30829 + }
30830 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30831 +#else
30832 + pgd = pgd_offset(current->active_mm, address);
30833 +#endif
30834 +
30835 if (pgd_none(*pgd)) {
30836 set_pgd(pgd, *pgd_ref);
30837 arch_flush_lazy_mmu_mode();
30838 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30839 static int is_errata100(struct pt_regs *regs, unsigned long address)
30840 {
30841 #ifdef CONFIG_X86_64
30842 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30843 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30844 return 1;
30845 #endif
30846 return 0;
30847 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30848 }
30849
30850 static const char nx_warning[] = KERN_CRIT
30851 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30852 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30853
30854 static void
30855 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30856 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30857 if (!oops_may_print())
30858 return;
30859
30860 - if (error_code & PF_INSTR) {
30861 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30862 unsigned int level;
30863
30864 pte_t *pte = lookup_address(address, &level);
30865
30866 if (pte && pte_present(*pte) && !pte_exec(*pte))
30867 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30868 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30869 }
30870
30871 +#ifdef CONFIG_PAX_KERNEXEC
30872 + if (init_mm.start_code <= address && address < init_mm.end_code) {
30873 + if (current->signal->curr_ip)
30874 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30875 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
30876 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30877 + else
30878 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30879 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30880 + }
30881 +#endif
30882 +
30883 printk(KERN_ALERT "BUG: unable to handle kernel ");
30884 if (address < PAGE_SIZE)
30885 printk(KERN_CONT "NULL pointer dereference");
30886 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30887 return;
30888 }
30889 #endif
30890 +
30891 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30892 + if (pax_is_fetch_fault(regs, error_code, address)) {
30893 +
30894 +#ifdef CONFIG_PAX_EMUTRAMP
30895 + switch (pax_handle_fetch_fault(regs)) {
30896 + case 2:
30897 + return;
30898 + }
30899 +#endif
30900 +
30901 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30902 + do_group_exit(SIGKILL);
30903 + }
30904 +#endif
30905 +
30906 /* Kernel addresses are always protection faults: */
30907 if (address >= TASK_SIZE)
30908 error_code |= PF_PROT;
30909 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30910 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30911 printk(KERN_ERR
30912 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30913 - tsk->comm, tsk->pid, address);
30914 + tsk->comm, task_pid_nr(tsk), address);
30915 code = BUS_MCEERR_AR;
30916 }
30917 #endif
30918 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30919 return 1;
30920 }
30921
30922 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30923 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30924 +{
30925 + pte_t *pte;
30926 + pmd_t *pmd;
30927 + spinlock_t *ptl;
30928 + unsigned char pte_mask;
30929 +
30930 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30931 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
30932 + return 0;
30933 +
30934 + /* PaX: it's our fault, let's handle it if we can */
30935 +
30936 + /* PaX: take a look at read faults before acquiring any locks */
30937 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30938 + /* instruction fetch attempt from a protected page in user mode */
30939 + up_read(&mm->mmap_sem);
30940 +
30941 +#ifdef CONFIG_PAX_EMUTRAMP
30942 + switch (pax_handle_fetch_fault(regs)) {
30943 + case 2:
30944 + return 1;
30945 + }
30946 +#endif
30947 +
30948 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30949 + do_group_exit(SIGKILL);
30950 + }
30951 +
30952 + pmd = pax_get_pmd(mm, address);
30953 + if (unlikely(!pmd))
30954 + return 0;
30955 +
30956 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30957 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30958 + pte_unmap_unlock(pte, ptl);
30959 + return 0;
30960 + }
30961 +
30962 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30963 + /* write attempt to a protected page in user mode */
30964 + pte_unmap_unlock(pte, ptl);
30965 + return 0;
30966 + }
30967 +
30968 +#ifdef CONFIG_SMP
30969 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30970 +#else
30971 + if (likely(address > get_limit(regs->cs)))
30972 +#endif
30973 + {
30974 + set_pte(pte, pte_mkread(*pte));
30975 + __flush_tlb_one(address);
30976 + pte_unmap_unlock(pte, ptl);
30977 + up_read(&mm->mmap_sem);
30978 + return 1;
30979 + }
30980 +
30981 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30982 +
30983 + /*
30984 + * PaX: fill DTLB with user rights and retry
30985 + */
30986 + __asm__ __volatile__ (
30987 + "orb %2,(%1)\n"
30988 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30989 +/*
30990 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30991 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30992 + * page fault when examined during a TLB load attempt. this is true not only
30993 + * for PTEs holding a non-present entry but also present entries that will
30994 + * raise a page fault (such as those set up by PaX, or the copy-on-write
30995 + * mechanism). in effect it means that we do *not* need to flush the TLBs
30996 + * for our target pages since their PTEs are simply not in the TLBs at all.
30997 +
30998 + * the best thing in omitting it is that we gain around 15-20% speed in the
30999 + * fast path of the page fault handler and can get rid of tracing since we
31000 + * can no longer flush unintended entries.
31001 + */
31002 + "invlpg (%0)\n"
31003 +#endif
31004 + __copyuser_seg"testb $0,(%0)\n"
31005 + "xorb %3,(%1)\n"
31006 + :
31007 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31008 + : "memory", "cc");
31009 + pte_unmap_unlock(pte, ptl);
31010 + up_read(&mm->mmap_sem);
31011 + return 1;
31012 +}
31013 +#endif
31014 +
31015 /*
31016 * Handle a spurious fault caused by a stale TLB entry.
31017 *
31018 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31019 static inline int
31020 access_error(unsigned long error_code, struct vm_area_struct *vma)
31021 {
31022 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31023 + return 1;
31024 +
31025 if (error_code & PF_WRITE) {
31026 /* write, present and write, not present: */
31027 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31028 @@ -1004,7 +1212,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31029 if (error_code & PF_USER)
31030 return false;
31031
31032 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31033 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31034 return false;
31035
31036 return true;
31037 @@ -1031,6 +1239,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31038 /* Get the faulting address: */
31039 address = read_cr2();
31040
31041 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31042 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31043 + if (!search_exception_tables(regs->ip)) {
31044 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31045 + bad_area_nosemaphore(regs, error_code, address);
31046 + return;
31047 + }
31048 + if (address < pax_user_shadow_base) {
31049 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31050 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31051 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31052 + } else
31053 + address -= pax_user_shadow_base;
31054 + }
31055 +#endif
31056 +
31057 /*
31058 * Detect and handle instructions that would cause a page fault for
31059 * both a tracked kernel page and a userspace page.
31060 @@ -1110,7 +1334,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31061 * User-mode registers count as a user access even for any
31062 * potential system fault or CPU buglet:
31063 */
31064 - if (user_mode_vm(regs)) {
31065 + if (user_mode(regs)) {
31066 local_irq_enable();
31067 error_code |= PF_USER;
31068 flags |= FAULT_FLAG_USER;
31069 @@ -1157,6 +1381,11 @@ retry:
31070 might_sleep();
31071 }
31072
31073 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31074 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31075 + return;
31076 +#endif
31077 +
31078 vma = find_vma(mm, address);
31079 if (unlikely(!vma)) {
31080 bad_area(regs, error_code, address);
31081 @@ -1168,18 +1397,24 @@ retry:
31082 bad_area(regs, error_code, address);
31083 return;
31084 }
31085 - if (error_code & PF_USER) {
31086 - /*
31087 - * Accessing the stack below %sp is always a bug.
31088 - * The large cushion allows instructions like enter
31089 - * and pusha to work. ("enter $65535, $31" pushes
31090 - * 32 pointers and then decrements %sp by 65535.)
31091 - */
31092 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31093 - bad_area(regs, error_code, address);
31094 - return;
31095 - }
31096 + /*
31097 + * Accessing the stack below %sp is always a bug.
31098 + * The large cushion allows instructions like enter
31099 + * and pusha to work. ("enter $65535, $31" pushes
31100 + * 32 pointers and then decrements %sp by 65535.)
31101 + */
31102 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31103 + bad_area(regs, error_code, address);
31104 + return;
31105 }
31106 +
31107 +#ifdef CONFIG_PAX_SEGMEXEC
31108 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31109 + bad_area(regs, error_code, address);
31110 + return;
31111 + }
31112 +#endif
31113 +
31114 if (unlikely(expand_stack(vma, address))) {
31115 bad_area(regs, error_code, address);
31116 return;
31117 @@ -1273,3 +1508,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31118 __do_page_fault(regs, error_code);
31119 exception_exit(prev_state);
31120 }
31121 +
31122 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31123 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31124 +{
31125 + struct mm_struct *mm = current->mm;
31126 + unsigned long ip = regs->ip;
31127 +
31128 + if (v8086_mode(regs))
31129 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31130 +
31131 +#ifdef CONFIG_PAX_PAGEEXEC
31132 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31133 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31134 + return true;
31135 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31136 + return true;
31137 + return false;
31138 + }
31139 +#endif
31140 +
31141 +#ifdef CONFIG_PAX_SEGMEXEC
31142 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31143 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31144 + return true;
31145 + return false;
31146 + }
31147 +#endif
31148 +
31149 + return false;
31150 +}
31151 +#endif
31152 +
31153 +#ifdef CONFIG_PAX_EMUTRAMP
31154 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31155 +{
31156 + int err;
31157 +
31158 + do { /* PaX: libffi trampoline emulation */
31159 + unsigned char mov, jmp;
31160 + unsigned int addr1, addr2;
31161 +
31162 +#ifdef CONFIG_X86_64
31163 + if ((regs->ip + 9) >> 32)
31164 + break;
31165 +#endif
31166 +
31167 + err = get_user(mov, (unsigned char __user *)regs->ip);
31168 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31169 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31170 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31171 +
31172 + if (err)
31173 + break;
31174 +
31175 + if (mov == 0xB8 && jmp == 0xE9) {
31176 + regs->ax = addr1;
31177 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31178 + return 2;
31179 + }
31180 + } while (0);
31181 +
31182 + do { /* PaX: gcc trampoline emulation #1 */
31183 + unsigned char mov1, mov2;
31184 + unsigned short jmp;
31185 + unsigned int addr1, addr2;
31186 +
31187 +#ifdef CONFIG_X86_64
31188 + if ((regs->ip + 11) >> 32)
31189 + break;
31190 +#endif
31191 +
31192 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31193 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31194 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31195 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31196 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31197 +
31198 + if (err)
31199 + break;
31200 +
31201 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31202 + regs->cx = addr1;
31203 + regs->ax = addr2;
31204 + regs->ip = addr2;
31205 + return 2;
31206 + }
31207 + } while (0);
31208 +
31209 + do { /* PaX: gcc trampoline emulation #2 */
31210 + unsigned char mov, jmp;
31211 + unsigned int addr1, addr2;
31212 +
31213 +#ifdef CONFIG_X86_64
31214 + if ((regs->ip + 9) >> 32)
31215 + break;
31216 +#endif
31217 +
31218 + err = get_user(mov, (unsigned char __user *)regs->ip);
31219 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31220 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31221 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31222 +
31223 + if (err)
31224 + break;
31225 +
31226 + if (mov == 0xB9 && jmp == 0xE9) {
31227 + regs->cx = addr1;
31228 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31229 + return 2;
31230 + }
31231 + } while (0);
31232 +
31233 + return 1; /* PaX in action */
31234 +}
31235 +
31236 +#ifdef CONFIG_X86_64
31237 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31238 +{
31239 + int err;
31240 +
31241 + do { /* PaX: libffi trampoline emulation */
31242 + unsigned short mov1, mov2, jmp1;
31243 + unsigned char stcclc, jmp2;
31244 + unsigned long addr1, addr2;
31245 +
31246 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31247 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31248 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31249 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31250 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31251 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31252 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31253 +
31254 + if (err)
31255 + break;
31256 +
31257 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31258 + regs->r11 = addr1;
31259 + regs->r10 = addr2;
31260 + if (stcclc == 0xF8)
31261 + regs->flags &= ~X86_EFLAGS_CF;
31262 + else
31263 + regs->flags |= X86_EFLAGS_CF;
31264 + regs->ip = addr1;
31265 + return 2;
31266 + }
31267 + } while (0);
31268 +
31269 + do { /* PaX: gcc trampoline emulation #1 */
31270 + unsigned short mov1, mov2, jmp1;
31271 + unsigned char jmp2;
31272 + unsigned int addr1;
31273 + unsigned long addr2;
31274 +
31275 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31276 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31277 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31278 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31279 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31280 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31281 +
31282 + if (err)
31283 + break;
31284 +
31285 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31286 + regs->r11 = addr1;
31287 + regs->r10 = addr2;
31288 + regs->ip = addr1;
31289 + return 2;
31290 + }
31291 + } while (0);
31292 +
31293 + do { /* PaX: gcc trampoline emulation #2 */
31294 + unsigned short mov1, mov2, jmp1;
31295 + unsigned char jmp2;
31296 + unsigned long addr1, addr2;
31297 +
31298 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31299 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31300 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31301 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31302 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31303 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31304 +
31305 + if (err)
31306 + break;
31307 +
31308 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31309 + regs->r11 = addr1;
31310 + regs->r10 = addr2;
31311 + regs->ip = addr1;
31312 + return 2;
31313 + }
31314 + } while (0);
31315 +
31316 + return 1; /* PaX in action */
31317 +}
31318 +#endif
31319 +
31320 +/*
31321 + * PaX: decide what to do with offenders (regs->ip = fault address)
31322 + *
31323 + * returns 1 when task should be killed
31324 + * 2 when gcc trampoline was detected
31325 + */
31326 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31327 +{
31328 + if (v8086_mode(regs))
31329 + return 1;
31330 +
31331 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31332 + return 1;
31333 +
31334 +#ifdef CONFIG_X86_32
31335 + return pax_handle_fetch_fault_32(regs);
31336 +#else
31337 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31338 + return pax_handle_fetch_fault_32(regs);
31339 + else
31340 + return pax_handle_fetch_fault_64(regs);
31341 +#endif
31342 +}
31343 +#endif
31344 +
31345 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31346 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31347 +{
31348 + long i;
31349 +
31350 + printk(KERN_ERR "PAX: bytes at PC: ");
31351 + for (i = 0; i < 20; i++) {
31352 + unsigned char c;
31353 + if (get_user(c, (unsigned char __force_user *)pc+i))
31354 + printk(KERN_CONT "?? ");
31355 + else
31356 + printk(KERN_CONT "%02x ", c);
31357 + }
31358 + printk("\n");
31359 +
31360 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31361 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31362 + unsigned long c;
31363 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31364 +#ifdef CONFIG_X86_32
31365 + printk(KERN_CONT "???????? ");
31366 +#else
31367 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31368 + printk(KERN_CONT "???????? ???????? ");
31369 + else
31370 + printk(KERN_CONT "???????????????? ");
31371 +#endif
31372 + } else {
31373 +#ifdef CONFIG_X86_64
31374 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31375 + printk(KERN_CONT "%08x ", (unsigned int)c);
31376 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31377 + } else
31378 +#endif
31379 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31380 + }
31381 + }
31382 + printk("\n");
31383 +}
31384 +#endif
31385 +
31386 +/**
31387 + * probe_kernel_write(): safely attempt to write to a location
31388 + * @dst: address to write to
31389 + * @src: pointer to the data that shall be written
31390 + * @size: size of the data chunk
31391 + *
31392 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31393 + * happens, handle that and return -EFAULT.
31394 + */
31395 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31396 +{
31397 + long ret;
31398 + mm_segment_t old_fs = get_fs();
31399 +
31400 + set_fs(KERNEL_DS);
31401 + pagefault_disable();
31402 + pax_open_kernel();
31403 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31404 + pax_close_kernel();
31405 + pagefault_enable();
31406 + set_fs(old_fs);
31407 +
31408 + return ret ? -EFAULT : 0;
31409 +}
31410 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31411 index 0596e8e..9de0b1c 100644
31412 --- a/arch/x86/mm/gup.c
31413 +++ b/arch/x86/mm/gup.c
31414 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31415 addr = start;
31416 len = (unsigned long) nr_pages << PAGE_SHIFT;
31417 end = start + len;
31418 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31419 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31420 (void __user *)start, len)))
31421 return 0;
31422
31423 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31424 goto slow_irqon;
31425 #endif
31426
31427 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31428 + (void __user *)start, len)))
31429 + return 0;
31430 +
31431 /*
31432 * XXX: batch / limit 'nr', to avoid large irq off latency
31433 * needs some instrumenting to determine the common sizes used by
31434 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31435 index 4500142..53a363c 100644
31436 --- a/arch/x86/mm/highmem_32.c
31437 +++ b/arch/x86/mm/highmem_32.c
31438 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31439 idx = type + KM_TYPE_NR*smp_processor_id();
31440 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31441 BUG_ON(!pte_none(*(kmap_pte-idx)));
31442 +
31443 + pax_open_kernel();
31444 set_pte(kmap_pte-idx, mk_pte(page, prot));
31445 + pax_close_kernel();
31446 +
31447 arch_flush_lazy_mmu_mode();
31448
31449 return (void *)vaddr;
31450 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31451 index 9d980d8..6bbfacb 100644
31452 --- a/arch/x86/mm/hugetlbpage.c
31453 +++ b/arch/x86/mm/hugetlbpage.c
31454 @@ -92,23 +92,30 @@ int pmd_huge_support(void)
31455 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31456 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31457 unsigned long addr, unsigned long len,
31458 - unsigned long pgoff, unsigned long flags)
31459 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31460 {
31461 struct hstate *h = hstate_file(file);
31462 struct vm_unmapped_area_info info;
31463 -
31464 +
31465 info.flags = 0;
31466 info.length = len;
31467 info.low_limit = TASK_UNMAPPED_BASE;
31468 +
31469 +#ifdef CONFIG_PAX_RANDMMAP
31470 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31471 + info.low_limit += current->mm->delta_mmap;
31472 +#endif
31473 +
31474 info.high_limit = TASK_SIZE;
31475 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31476 info.align_offset = 0;
31477 + info.threadstack_offset = offset;
31478 return vm_unmapped_area(&info);
31479 }
31480
31481 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31482 unsigned long addr0, unsigned long len,
31483 - unsigned long pgoff, unsigned long flags)
31484 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31485 {
31486 struct hstate *h = hstate_file(file);
31487 struct vm_unmapped_area_info info;
31488 @@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31489 info.high_limit = current->mm->mmap_base;
31490 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31491 info.align_offset = 0;
31492 + info.threadstack_offset = offset;
31493 addr = vm_unmapped_area(&info);
31494
31495 /*
31496 @@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31497 VM_BUG_ON(addr != -ENOMEM);
31498 info.flags = 0;
31499 info.low_limit = TASK_UNMAPPED_BASE;
31500 +
31501 +#ifdef CONFIG_PAX_RANDMMAP
31502 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31503 + info.low_limit += current->mm->delta_mmap;
31504 +#endif
31505 +
31506 info.high_limit = TASK_SIZE;
31507 addr = vm_unmapped_area(&info);
31508 }
31509 @@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31510 struct hstate *h = hstate_file(file);
31511 struct mm_struct *mm = current->mm;
31512 struct vm_area_struct *vma;
31513 + unsigned long pax_task_size = TASK_SIZE;
31514 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31515
31516 if (len & ~huge_page_mask(h))
31517 return -EINVAL;
31518 - if (len > TASK_SIZE)
31519 +
31520 +#ifdef CONFIG_PAX_SEGMEXEC
31521 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
31522 + pax_task_size = SEGMEXEC_TASK_SIZE;
31523 +#endif
31524 +
31525 + pax_task_size -= PAGE_SIZE;
31526 +
31527 + if (len > pax_task_size)
31528 return -ENOMEM;
31529
31530 if (flags & MAP_FIXED) {
31531 @@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31532 return addr;
31533 }
31534
31535 +#ifdef CONFIG_PAX_RANDMMAP
31536 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31537 +#endif
31538 +
31539 if (addr) {
31540 addr = ALIGN(addr, huge_page_size(h));
31541 vma = find_vma(mm, addr);
31542 - if (TASK_SIZE - len >= addr &&
31543 - (!vma || addr + len <= vma->vm_start))
31544 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31545 return addr;
31546 }
31547 if (mm->get_unmapped_area == arch_get_unmapped_area)
31548 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31549 - pgoff, flags);
31550 + pgoff, flags, offset);
31551 else
31552 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31553 - pgoff, flags);
31554 + pgoff, flags, offset);
31555 }
31556
31557 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31558 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31559 index f971306..e83e0f6 100644
31560 --- a/arch/x86/mm/init.c
31561 +++ b/arch/x86/mm/init.c
31562 @@ -4,6 +4,7 @@
31563 #include <linux/swap.h>
31564 #include <linux/memblock.h>
31565 #include <linux/bootmem.h> /* for max_low_pfn */
31566 +#include <linux/tboot.h>
31567
31568 #include <asm/cacheflush.h>
31569 #include <asm/e820.h>
31570 @@ -17,6 +18,8 @@
31571 #include <asm/proto.h>
31572 #include <asm/dma.h> /* for MAX_DMA_PFN */
31573 #include <asm/microcode.h>
31574 +#include <asm/desc.h>
31575 +#include <asm/bios_ebda.h>
31576
31577 #include "mm_internal.h"
31578
31579 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
31580 early_ioremap_page_table_range_init();
31581 #endif
31582
31583 +#ifdef CONFIG_PAX_PER_CPU_PGD
31584 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31585 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31586 + KERNEL_PGD_PTRS);
31587 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31588 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31589 + KERNEL_PGD_PTRS);
31590 + load_cr3(get_cpu_pgd(0, kernel));
31591 +#else
31592 load_cr3(swapper_pg_dir);
31593 +#endif
31594 +
31595 __flush_tlb_all();
31596
31597 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31598 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
31599 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31600 * mmio resources as well as potential bios/acpi data regions.
31601 */
31602 +
31603 +#ifdef CONFIG_GRKERNSEC_KMEM
31604 +static unsigned int ebda_start __read_only;
31605 +static unsigned int ebda_end __read_only;
31606 +#endif
31607 +
31608 int devmem_is_allowed(unsigned long pagenr)
31609 {
31610 - if (pagenr < 256)
31611 +#ifdef CONFIG_GRKERNSEC_KMEM
31612 + /* allow BDA */
31613 + if (!pagenr)
31614 return 1;
31615 + /* allow EBDA */
31616 + if (pagenr >= ebda_start && pagenr < ebda_end)
31617 + return 1;
31618 + /* if tboot is in use, allow access to its hardcoded serial log range */
31619 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31620 + return 1;
31621 +#else
31622 + if (!pagenr)
31623 + return 1;
31624 +#ifdef CONFIG_VM86
31625 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31626 + return 1;
31627 +#endif
31628 +#endif
31629 +
31630 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31631 + return 1;
31632 +#ifdef CONFIG_GRKERNSEC_KMEM
31633 + /* throw out everything else below 1MB */
31634 + if (pagenr <= 256)
31635 + return 0;
31636 +#endif
31637 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31638 return 0;
31639 if (!page_is_ram(pagenr))
31640 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31641 #endif
31642 }
31643
31644 +#ifdef CONFIG_GRKERNSEC_KMEM
31645 +static inline void gr_init_ebda(void)
31646 +{
31647 + unsigned int ebda_addr;
31648 + unsigned int ebda_size = 0;
31649 +
31650 + ebda_addr = get_bios_ebda();
31651 + if (ebda_addr) {
31652 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31653 + ebda_size <<= 10;
31654 + }
31655 + if (ebda_addr && ebda_size) {
31656 + ebda_start = ebda_addr >> PAGE_SHIFT;
31657 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31658 + } else {
31659 + ebda_start = 0x9f000 >> PAGE_SHIFT;
31660 + ebda_end = 0xa0000 >> PAGE_SHIFT;
31661 + }
31662 +}
31663 +#else
31664 +static inline void gr_init_ebda(void) { }
31665 +#endif
31666 +
31667 void free_initmem(void)
31668 {
31669 +#ifdef CONFIG_PAX_KERNEXEC
31670 +#ifdef CONFIG_X86_32
31671 + /* PaX: limit KERNEL_CS to actual size */
31672 + unsigned long addr, limit;
31673 + struct desc_struct d;
31674 + int cpu;
31675 +#else
31676 + pgd_t *pgd;
31677 + pud_t *pud;
31678 + pmd_t *pmd;
31679 + unsigned long addr, end;
31680 +#endif
31681 +#endif
31682 +
31683 + gr_init_ebda();
31684 +
31685 +#ifdef CONFIG_PAX_KERNEXEC
31686 +#ifdef CONFIG_X86_32
31687 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31688 + limit = (limit - 1UL) >> PAGE_SHIFT;
31689 +
31690 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31691 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31692 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31693 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31694 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31695 + }
31696 +
31697 + /* PaX: make KERNEL_CS read-only */
31698 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31699 + if (!paravirt_enabled())
31700 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31701 +/*
31702 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31703 + pgd = pgd_offset_k(addr);
31704 + pud = pud_offset(pgd, addr);
31705 + pmd = pmd_offset(pud, addr);
31706 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31707 + }
31708 +*/
31709 +#ifdef CONFIG_X86_PAE
31710 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31711 +/*
31712 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31713 + pgd = pgd_offset_k(addr);
31714 + pud = pud_offset(pgd, addr);
31715 + pmd = pmd_offset(pud, addr);
31716 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31717 + }
31718 +*/
31719 +#endif
31720 +
31721 +#ifdef CONFIG_MODULES
31722 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31723 +#endif
31724 +
31725 +#else
31726 + /* PaX: make kernel code/rodata read-only, rest non-executable */
31727 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31728 + pgd = pgd_offset_k(addr);
31729 + pud = pud_offset(pgd, addr);
31730 + pmd = pmd_offset(pud, addr);
31731 + if (!pmd_present(*pmd))
31732 + continue;
31733 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31734 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31735 + else
31736 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31737 + }
31738 +
31739 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31740 + end = addr + KERNEL_IMAGE_SIZE;
31741 + for (; addr < end; addr += PMD_SIZE) {
31742 + pgd = pgd_offset_k(addr);
31743 + pud = pud_offset(pgd, addr);
31744 + pmd = pmd_offset(pud, addr);
31745 + if (!pmd_present(*pmd))
31746 + continue;
31747 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31748 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31749 + }
31750 +#endif
31751 +
31752 + flush_tlb_all();
31753 +#endif
31754 +
31755 free_init_pages("unused kernel",
31756 (unsigned long)(&__init_begin),
31757 (unsigned long)(&__init_end));
31758 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31759 index 4287f1f..3b99c71 100644
31760 --- a/arch/x86/mm/init_32.c
31761 +++ b/arch/x86/mm/init_32.c
31762 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31763 bool __read_mostly __vmalloc_start_set = false;
31764
31765 /*
31766 - * Creates a middle page table and puts a pointer to it in the
31767 - * given global directory entry. This only returns the gd entry
31768 - * in non-PAE compilation mode, since the middle layer is folded.
31769 - */
31770 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
31771 -{
31772 - pud_t *pud;
31773 - pmd_t *pmd_table;
31774 -
31775 -#ifdef CONFIG_X86_PAE
31776 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31777 - pmd_table = (pmd_t *)alloc_low_page();
31778 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31779 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31780 - pud = pud_offset(pgd, 0);
31781 - BUG_ON(pmd_table != pmd_offset(pud, 0));
31782 -
31783 - return pmd_table;
31784 - }
31785 -#endif
31786 - pud = pud_offset(pgd, 0);
31787 - pmd_table = pmd_offset(pud, 0);
31788 -
31789 - return pmd_table;
31790 -}
31791 -
31792 -/*
31793 * Create a page table and place a pointer to it in a middle page
31794 * directory entry:
31795 */
31796 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31797 pte_t *page_table = (pte_t *)alloc_low_page();
31798
31799 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31800 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31801 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31802 +#else
31803 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31804 +#endif
31805 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31806 }
31807
31808 return pte_offset_kernel(pmd, 0);
31809 }
31810
31811 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
31812 +{
31813 + pud_t *pud;
31814 + pmd_t *pmd_table;
31815 +
31816 + pud = pud_offset(pgd, 0);
31817 + pmd_table = pmd_offset(pud, 0);
31818 +
31819 + return pmd_table;
31820 +}
31821 +
31822 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31823 {
31824 int pgd_idx = pgd_index(vaddr);
31825 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31826 int pgd_idx, pmd_idx;
31827 unsigned long vaddr;
31828 pgd_t *pgd;
31829 + pud_t *pud;
31830 pmd_t *pmd;
31831 pte_t *pte = NULL;
31832 unsigned long count = page_table_range_init_count(start, end);
31833 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31834 pgd = pgd_base + pgd_idx;
31835
31836 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31837 - pmd = one_md_table_init(pgd);
31838 - pmd = pmd + pmd_index(vaddr);
31839 + pud = pud_offset(pgd, vaddr);
31840 + pmd = pmd_offset(pud, vaddr);
31841 +
31842 +#ifdef CONFIG_X86_PAE
31843 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31844 +#endif
31845 +
31846 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31847 pmd++, pmd_idx++) {
31848 pte = page_table_kmap_check(one_page_table_init(pmd),
31849 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31850 }
31851 }
31852
31853 -static inline int is_kernel_text(unsigned long addr)
31854 +static inline int is_kernel_text(unsigned long start, unsigned long end)
31855 {
31856 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31857 - return 1;
31858 - return 0;
31859 + if ((start > ktla_ktva((unsigned long)_etext) ||
31860 + end <= ktla_ktva((unsigned long)_stext)) &&
31861 + (start > ktla_ktva((unsigned long)_einittext) ||
31862 + end <= ktla_ktva((unsigned long)_sinittext)) &&
31863 +
31864 +#ifdef CONFIG_ACPI_SLEEP
31865 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31866 +#endif
31867 +
31868 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31869 + return 0;
31870 + return 1;
31871 }
31872
31873 /*
31874 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31875 unsigned long last_map_addr = end;
31876 unsigned long start_pfn, end_pfn;
31877 pgd_t *pgd_base = swapper_pg_dir;
31878 - int pgd_idx, pmd_idx, pte_ofs;
31879 + unsigned int pgd_idx, pmd_idx, pte_ofs;
31880 unsigned long pfn;
31881 pgd_t *pgd;
31882 + pud_t *pud;
31883 pmd_t *pmd;
31884 pte_t *pte;
31885 unsigned pages_2m, pages_4k;
31886 @@ -291,8 +295,13 @@ repeat:
31887 pfn = start_pfn;
31888 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31889 pgd = pgd_base + pgd_idx;
31890 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31891 - pmd = one_md_table_init(pgd);
31892 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31893 + pud = pud_offset(pgd, 0);
31894 + pmd = pmd_offset(pud, 0);
31895 +
31896 +#ifdef CONFIG_X86_PAE
31897 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31898 +#endif
31899
31900 if (pfn >= end_pfn)
31901 continue;
31902 @@ -304,14 +313,13 @@ repeat:
31903 #endif
31904 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31905 pmd++, pmd_idx++) {
31906 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31907 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31908
31909 /*
31910 * Map with big pages if possible, otherwise
31911 * create normal page tables:
31912 */
31913 if (use_pse) {
31914 - unsigned int addr2;
31915 pgprot_t prot = PAGE_KERNEL_LARGE;
31916 /*
31917 * first pass will use the same initial
31918 @@ -322,11 +330,7 @@ repeat:
31919 _PAGE_PSE);
31920
31921 pfn &= PMD_MASK >> PAGE_SHIFT;
31922 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31923 - PAGE_OFFSET + PAGE_SIZE-1;
31924 -
31925 - if (is_kernel_text(addr) ||
31926 - is_kernel_text(addr2))
31927 + if (is_kernel_text(address, address + PMD_SIZE))
31928 prot = PAGE_KERNEL_LARGE_EXEC;
31929
31930 pages_2m++;
31931 @@ -343,7 +347,7 @@ repeat:
31932 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31933 pte += pte_ofs;
31934 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31935 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31936 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31937 pgprot_t prot = PAGE_KERNEL;
31938 /*
31939 * first pass will use the same initial
31940 @@ -351,7 +355,7 @@ repeat:
31941 */
31942 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31943
31944 - if (is_kernel_text(addr))
31945 + if (is_kernel_text(address, address + PAGE_SIZE))
31946 prot = PAGE_KERNEL_EXEC;
31947
31948 pages_4k++;
31949 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31950
31951 pud = pud_offset(pgd, va);
31952 pmd = pmd_offset(pud, va);
31953 - if (!pmd_present(*pmd))
31954 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31955 break;
31956
31957 /* should not be large page here */
31958 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31959
31960 static void __init pagetable_init(void)
31961 {
31962 - pgd_t *pgd_base = swapper_pg_dir;
31963 -
31964 - permanent_kmaps_init(pgd_base);
31965 + permanent_kmaps_init(swapper_pg_dir);
31966 }
31967
31968 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31969 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31970 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31971
31972 /* user-defined highmem size */
31973 @@ -787,10 +789,10 @@ void __init mem_init(void)
31974 ((unsigned long)&__init_end -
31975 (unsigned long)&__init_begin) >> 10,
31976
31977 - (unsigned long)&_etext, (unsigned long)&_edata,
31978 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31979 + (unsigned long)&_sdata, (unsigned long)&_edata,
31980 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31981
31982 - (unsigned long)&_text, (unsigned long)&_etext,
31983 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31984 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31985
31986 /*
31987 @@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31988 if (!kernel_set_to_readonly)
31989 return;
31990
31991 + start = ktla_ktva(start);
31992 pr_debug("Set kernel text: %lx - %lx for read write\n",
31993 start, start+size);
31994
31995 @@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31996 if (!kernel_set_to_readonly)
31997 return;
31998
31999 + start = ktla_ktva(start);
32000 pr_debug("Set kernel text: %lx - %lx for read only\n",
32001 start, start+size);
32002
32003 @@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32004 unsigned long start = PFN_ALIGN(_text);
32005 unsigned long size = PFN_ALIGN(_etext) - start;
32006
32007 + start = ktla_ktva(start);
32008 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32009 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32010 size >> 10);
32011 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32012 index 104d56a..62ba13f1 100644
32013 --- a/arch/x86/mm/init_64.c
32014 +++ b/arch/x86/mm/init_64.c
32015 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32016 * around without checking the pgd every time.
32017 */
32018
32019 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32020 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32021 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32022
32023 int force_personality32;
32024 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32025
32026 for (address = start; address <= end; address += PGDIR_SIZE) {
32027 const pgd_t *pgd_ref = pgd_offset_k(address);
32028 +
32029 +#ifdef CONFIG_PAX_PER_CPU_PGD
32030 + unsigned long cpu;
32031 +#else
32032 struct page *page;
32033 +#endif
32034
32035 if (pgd_none(*pgd_ref))
32036 continue;
32037
32038 spin_lock(&pgd_lock);
32039 +
32040 +#ifdef CONFIG_PAX_PER_CPU_PGD
32041 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32042 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32043 +
32044 + if (pgd_none(*pgd))
32045 + set_pgd(pgd, *pgd_ref);
32046 + else
32047 + BUG_ON(pgd_page_vaddr(*pgd)
32048 + != pgd_page_vaddr(*pgd_ref));
32049 + pgd = pgd_offset_cpu(cpu, kernel, address);
32050 +#else
32051 list_for_each_entry(page, &pgd_list, lru) {
32052 pgd_t *pgd;
32053 spinlock_t *pgt_lock;
32054 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32055 /* the pgt_lock only for Xen */
32056 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32057 spin_lock(pgt_lock);
32058 +#endif
32059
32060 if (pgd_none(*pgd))
32061 set_pgd(pgd, *pgd_ref);
32062 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32063 BUG_ON(pgd_page_vaddr(*pgd)
32064 != pgd_page_vaddr(*pgd_ref));
32065
32066 +#ifndef CONFIG_PAX_PER_CPU_PGD
32067 spin_unlock(pgt_lock);
32068 +#endif
32069 +
32070 }
32071 spin_unlock(&pgd_lock);
32072 }
32073 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32074 {
32075 if (pgd_none(*pgd)) {
32076 pud_t *pud = (pud_t *)spp_getpage();
32077 - pgd_populate(&init_mm, pgd, pud);
32078 + pgd_populate_kernel(&init_mm, pgd, pud);
32079 if (pud != pud_offset(pgd, 0))
32080 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32081 pud, pud_offset(pgd, 0));
32082 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32083 {
32084 if (pud_none(*pud)) {
32085 pmd_t *pmd = (pmd_t *) spp_getpage();
32086 - pud_populate(&init_mm, pud, pmd);
32087 + pud_populate_kernel(&init_mm, pud, pmd);
32088 if (pmd != pmd_offset(pud, 0))
32089 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32090 pmd, pmd_offset(pud, 0));
32091 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32092 pmd = fill_pmd(pud, vaddr);
32093 pte = fill_pte(pmd, vaddr);
32094
32095 + pax_open_kernel();
32096 set_pte(pte, new_pte);
32097 + pax_close_kernel();
32098
32099 /*
32100 * It's enough to flush this one mapping.
32101 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32102 pgd = pgd_offset_k((unsigned long)__va(phys));
32103 if (pgd_none(*pgd)) {
32104 pud = (pud_t *) spp_getpage();
32105 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32106 - _PAGE_USER));
32107 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32108 }
32109 pud = pud_offset(pgd, (unsigned long)__va(phys));
32110 if (pud_none(*pud)) {
32111 pmd = (pmd_t *) spp_getpage();
32112 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32113 - _PAGE_USER));
32114 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32115 }
32116 pmd = pmd_offset(pud, phys);
32117 BUG_ON(!pmd_none(*pmd));
32118 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32119 prot);
32120
32121 spin_lock(&init_mm.page_table_lock);
32122 - pud_populate(&init_mm, pud, pmd);
32123 + pud_populate_kernel(&init_mm, pud, pmd);
32124 spin_unlock(&init_mm.page_table_lock);
32125 }
32126 __flush_tlb_all();
32127 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32128 page_size_mask);
32129
32130 spin_lock(&init_mm.page_table_lock);
32131 - pgd_populate(&init_mm, pgd, pud);
32132 + pgd_populate_kernel(&init_mm, pgd, pud);
32133 spin_unlock(&init_mm.page_table_lock);
32134 pgd_changed = true;
32135 }
32136 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32137 static struct vm_area_struct gate_vma = {
32138 .vm_start = VSYSCALL_START,
32139 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32140 - .vm_page_prot = PAGE_READONLY_EXEC,
32141 - .vm_flags = VM_READ | VM_EXEC
32142 + .vm_page_prot = PAGE_READONLY,
32143 + .vm_flags = VM_READ
32144 };
32145
32146 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32147 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32148
32149 const char *arch_vma_name(struct vm_area_struct *vma)
32150 {
32151 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32152 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32153 return "[vdso]";
32154 if (vma == &gate_vma)
32155 return "[vsyscall]";
32156 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32157 index 7b179b4..6bd17777 100644
32158 --- a/arch/x86/mm/iomap_32.c
32159 +++ b/arch/x86/mm/iomap_32.c
32160 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32161 type = kmap_atomic_idx_push();
32162 idx = type + KM_TYPE_NR * smp_processor_id();
32163 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32164 +
32165 + pax_open_kernel();
32166 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32167 + pax_close_kernel();
32168 +
32169 arch_flush_lazy_mmu_mode();
32170
32171 return (void *)vaddr;
32172 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32173 index 799580c..72f9fe0 100644
32174 --- a/arch/x86/mm/ioremap.c
32175 +++ b/arch/x86/mm/ioremap.c
32176 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32177 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32178 int is_ram = page_is_ram(pfn);
32179
32180 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32181 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32182 return NULL;
32183 WARN_ON_ONCE(is_ram);
32184 }
32185 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32186 *
32187 * Caller must ensure there is only one unmapping for the same pointer.
32188 */
32189 -void iounmap(volatile void __iomem *addr)
32190 +void iounmap(const volatile void __iomem *addr)
32191 {
32192 struct vm_struct *p, *o;
32193
32194 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32195
32196 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32197 if (page_is_ram(start >> PAGE_SHIFT))
32198 +#ifdef CONFIG_HIGHMEM
32199 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32200 +#endif
32201 return __va(phys);
32202
32203 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32204 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32205 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32206 {
32207 if (page_is_ram(phys >> PAGE_SHIFT))
32208 +#ifdef CONFIG_HIGHMEM
32209 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32210 +#endif
32211 return;
32212
32213 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32214 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32215 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32216
32217 static __initdata int after_paging_init;
32218 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32219 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32220
32221 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32222 {
32223 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32224 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32225
32226 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32227 - memset(bm_pte, 0, sizeof(bm_pte));
32228 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32229 + pmd_populate_user(&init_mm, pmd, bm_pte);
32230
32231 /*
32232 * The boot-ioremap range spans multiple pmds, for which
32233 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32234 index d87dd6d..bf3fa66 100644
32235 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32236 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32237 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32238 * memory (e.g. tracked pages)? For now, we need this to avoid
32239 * invoking kmemcheck for PnP BIOS calls.
32240 */
32241 - if (regs->flags & X86_VM_MASK)
32242 + if (v8086_mode(regs))
32243 return false;
32244 - if (regs->cs != __KERNEL_CS)
32245 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32246 return false;
32247
32248 pte = kmemcheck_pte_lookup(address);
32249 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32250 index 25e7e13..1964579 100644
32251 --- a/arch/x86/mm/mmap.c
32252 +++ b/arch/x86/mm/mmap.c
32253 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32254 * Leave an at least ~128 MB hole with possible stack randomization.
32255 */
32256 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32257 -#define MAX_GAP (TASK_SIZE/6*5)
32258 +#define MAX_GAP (pax_task_size/6*5)
32259
32260 static int mmap_is_legacy(void)
32261 {
32262 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32263 return rnd << PAGE_SHIFT;
32264 }
32265
32266 -static unsigned long mmap_base(void)
32267 +static unsigned long mmap_base(struct mm_struct *mm)
32268 {
32269 unsigned long gap = rlimit(RLIMIT_STACK);
32270 + unsigned long pax_task_size = TASK_SIZE;
32271 +
32272 +#ifdef CONFIG_PAX_SEGMEXEC
32273 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32274 + pax_task_size = SEGMEXEC_TASK_SIZE;
32275 +#endif
32276
32277 if (gap < MIN_GAP)
32278 gap = MIN_GAP;
32279 else if (gap > MAX_GAP)
32280 gap = MAX_GAP;
32281
32282 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32283 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32284 }
32285
32286 /*
32287 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32288 * does, but not when emulating X86_32
32289 */
32290 -static unsigned long mmap_legacy_base(void)
32291 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32292 {
32293 - if (mmap_is_ia32())
32294 + if (mmap_is_ia32()) {
32295 +
32296 +#ifdef CONFIG_PAX_SEGMEXEC
32297 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32298 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32299 + else
32300 +#endif
32301 +
32302 return TASK_UNMAPPED_BASE;
32303 - else
32304 + } else
32305 return TASK_UNMAPPED_BASE + mmap_rnd();
32306 }
32307
32308 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32309 */
32310 void arch_pick_mmap_layout(struct mm_struct *mm)
32311 {
32312 - mm->mmap_legacy_base = mmap_legacy_base();
32313 - mm->mmap_base = mmap_base();
32314 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32315 + mm->mmap_base = mmap_base(mm);
32316 +
32317 +#ifdef CONFIG_PAX_RANDMMAP
32318 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32319 + mm->mmap_legacy_base += mm->delta_mmap;
32320 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32321 + }
32322 +#endif
32323
32324 if (mmap_is_legacy()) {
32325 mm->mmap_base = mm->mmap_legacy_base;
32326 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32327 index 0057a7a..95c7edd 100644
32328 --- a/arch/x86/mm/mmio-mod.c
32329 +++ b/arch/x86/mm/mmio-mod.c
32330 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32331 break;
32332 default:
32333 {
32334 - unsigned char *ip = (unsigned char *)instptr;
32335 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32336 my_trace->opcode = MMIO_UNKNOWN_OP;
32337 my_trace->width = 0;
32338 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32339 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32340 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32341 void __iomem *addr)
32342 {
32343 - static atomic_t next_id;
32344 + static atomic_unchecked_t next_id;
32345 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32346 /* These are page-unaligned. */
32347 struct mmiotrace_map map = {
32348 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32349 .private = trace
32350 },
32351 .phys = offset,
32352 - .id = atomic_inc_return(&next_id)
32353 + .id = atomic_inc_return_unchecked(&next_id)
32354 };
32355 map.map_id = trace->id;
32356
32357 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32358 ioremap_trace_core(offset, size, addr);
32359 }
32360
32361 -static void iounmap_trace_core(volatile void __iomem *addr)
32362 +static void iounmap_trace_core(const volatile void __iomem *addr)
32363 {
32364 struct mmiotrace_map map = {
32365 .phys = 0,
32366 @@ -328,7 +328,7 @@ not_enabled:
32367 }
32368 }
32369
32370 -void mmiotrace_iounmap(volatile void __iomem *addr)
32371 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32372 {
32373 might_sleep();
32374 if (is_enabled()) /* recheck and proper locking in *_core() */
32375 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32376 index 24aec58..c39fe8b 100644
32377 --- a/arch/x86/mm/numa.c
32378 +++ b/arch/x86/mm/numa.c
32379 @@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32380 return true;
32381 }
32382
32383 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32384 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32385 {
32386 unsigned long uninitialized_var(pfn_align);
32387 int i, nid;
32388 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32389 index d0b1773..4c3327c 100644
32390 --- a/arch/x86/mm/pageattr-test.c
32391 +++ b/arch/x86/mm/pageattr-test.c
32392 @@ -36,7 +36,7 @@ enum {
32393
32394 static int pte_testbit(pte_t pte)
32395 {
32396 - return pte_flags(pte) & _PAGE_UNUSED1;
32397 + return pte_flags(pte) & _PAGE_CPA_TEST;
32398 }
32399
32400 struct split_state {
32401 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32402 index bb32480..75f2f5e 100644
32403 --- a/arch/x86/mm/pageattr.c
32404 +++ b/arch/x86/mm/pageattr.c
32405 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32406 */
32407 #ifdef CONFIG_PCI_BIOS
32408 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32409 - pgprot_val(forbidden) |= _PAGE_NX;
32410 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32411 #endif
32412
32413 /*
32414 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32415 * Does not cover __inittext since that is gone later on. On
32416 * 64bit we do not enforce !NX on the low mapping
32417 */
32418 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32419 - pgprot_val(forbidden) |= _PAGE_NX;
32420 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32421 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32422
32423 +#ifdef CONFIG_DEBUG_RODATA
32424 /*
32425 * The .rodata section needs to be read-only. Using the pfn
32426 * catches all aliases.
32427 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32428 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32429 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32430 pgprot_val(forbidden) |= _PAGE_RW;
32431 +#endif
32432
32433 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32434 /*
32435 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32436 }
32437 #endif
32438
32439 +#ifdef CONFIG_PAX_KERNEXEC
32440 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32441 + pgprot_val(forbidden) |= _PAGE_RW;
32442 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32443 + }
32444 +#endif
32445 +
32446 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32447
32448 return prot;
32449 @@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32450 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32451 {
32452 /* change init_mm */
32453 + pax_open_kernel();
32454 set_pte_atomic(kpte, pte);
32455 +
32456 #ifdef CONFIG_X86_32
32457 if (!SHARED_KERNEL_PMD) {
32458 +
32459 +#ifdef CONFIG_PAX_PER_CPU_PGD
32460 + unsigned long cpu;
32461 +#else
32462 struct page *page;
32463 +#endif
32464
32465 +#ifdef CONFIG_PAX_PER_CPU_PGD
32466 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32467 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32468 +#else
32469 list_for_each_entry(page, &pgd_list, lru) {
32470 - pgd_t *pgd;
32471 + pgd_t *pgd = (pgd_t *)page_address(page);
32472 +#endif
32473 +
32474 pud_t *pud;
32475 pmd_t *pmd;
32476
32477 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
32478 + pgd += pgd_index(address);
32479 pud = pud_offset(pgd, address);
32480 pmd = pmd_offset(pud, address);
32481 set_pte_atomic((pte_t *)pmd, pte);
32482 }
32483 }
32484 #endif
32485 + pax_close_kernel();
32486 }
32487
32488 static int
32489 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32490 index 6574388..87e9bef 100644
32491 --- a/arch/x86/mm/pat.c
32492 +++ b/arch/x86/mm/pat.c
32493 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32494
32495 if (!entry) {
32496 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32497 - current->comm, current->pid, start, end - 1);
32498 + current->comm, task_pid_nr(current), start, end - 1);
32499 return -EINVAL;
32500 }
32501
32502 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32503
32504 while (cursor < to) {
32505 if (!devmem_is_allowed(pfn)) {
32506 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32507 - current->comm, from, to - 1);
32508 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32509 + current->comm, from, to - 1, cursor);
32510 return 0;
32511 }
32512 cursor += PAGE_SIZE;
32513 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32514 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32515 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32516 "for [mem %#010Lx-%#010Lx]\n",
32517 - current->comm, current->pid,
32518 + current->comm, task_pid_nr(current),
32519 cattr_name(flags),
32520 base, (unsigned long long)(base + size-1));
32521 return -EINVAL;
32522 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32523 flags = lookup_memtype(paddr);
32524 if (want_flags != flags) {
32525 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32526 - current->comm, current->pid,
32527 + current->comm, task_pid_nr(current),
32528 cattr_name(want_flags),
32529 (unsigned long long)paddr,
32530 (unsigned long long)(paddr + size - 1),
32531 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32532 free_memtype(paddr, paddr + size);
32533 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32534 " for [mem %#010Lx-%#010Lx], got %s\n",
32535 - current->comm, current->pid,
32536 + current->comm, task_pid_nr(current),
32537 cattr_name(want_flags),
32538 (unsigned long long)paddr,
32539 (unsigned long long)(paddr + size - 1),
32540 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32541 index 415f6c4..d319983 100644
32542 --- a/arch/x86/mm/pat_rbtree.c
32543 +++ b/arch/x86/mm/pat_rbtree.c
32544 @@ -160,7 +160,7 @@ success:
32545
32546 failure:
32547 printk(KERN_INFO "%s:%d conflicting memory types "
32548 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32549 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32550 end, cattr_name(found_type), cattr_name(match->type));
32551 return -EBUSY;
32552 }
32553 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32554 index 9f0614d..92ae64a 100644
32555 --- a/arch/x86/mm/pf_in.c
32556 +++ b/arch/x86/mm/pf_in.c
32557 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32558 int i;
32559 enum reason_type rv = OTHERS;
32560
32561 - p = (unsigned char *)ins_addr;
32562 + p = (unsigned char *)ktla_ktva(ins_addr);
32563 p += skip_prefix(p, &prf);
32564 p += get_opcode(p, &opcode);
32565
32566 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32567 struct prefix_bits prf;
32568 int i;
32569
32570 - p = (unsigned char *)ins_addr;
32571 + p = (unsigned char *)ktla_ktva(ins_addr);
32572 p += skip_prefix(p, &prf);
32573 p += get_opcode(p, &opcode);
32574
32575 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32576 struct prefix_bits prf;
32577 int i;
32578
32579 - p = (unsigned char *)ins_addr;
32580 + p = (unsigned char *)ktla_ktva(ins_addr);
32581 p += skip_prefix(p, &prf);
32582 p += get_opcode(p, &opcode);
32583
32584 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32585 struct prefix_bits prf;
32586 int i;
32587
32588 - p = (unsigned char *)ins_addr;
32589 + p = (unsigned char *)ktla_ktva(ins_addr);
32590 p += skip_prefix(p, &prf);
32591 p += get_opcode(p, &opcode);
32592 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32593 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32594 struct prefix_bits prf;
32595 int i;
32596
32597 - p = (unsigned char *)ins_addr;
32598 + p = (unsigned char *)ktla_ktva(ins_addr);
32599 p += skip_prefix(p, &prf);
32600 p += get_opcode(p, &opcode);
32601 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32602 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32603 index c96314a..433b127 100644
32604 --- a/arch/x86/mm/pgtable.c
32605 +++ b/arch/x86/mm/pgtable.c
32606 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
32607 list_del(&page->lru);
32608 }
32609
32610 -#define UNSHARED_PTRS_PER_PGD \
32611 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32612 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32613 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32614
32615 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32616 +{
32617 + unsigned int count = USER_PGD_PTRS;
32618
32619 + if (!pax_user_shadow_base)
32620 + return;
32621 +
32622 + while (count--)
32623 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32624 +}
32625 +#endif
32626 +
32627 +#ifdef CONFIG_PAX_PER_CPU_PGD
32628 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32629 +{
32630 + unsigned int count = USER_PGD_PTRS;
32631 +
32632 + while (count--) {
32633 + pgd_t pgd;
32634 +
32635 +#ifdef CONFIG_X86_64
32636 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32637 +#else
32638 + pgd = *src++;
32639 +#endif
32640 +
32641 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32642 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32643 +#endif
32644 +
32645 + *dst++ = pgd;
32646 + }
32647 +
32648 +}
32649 +#endif
32650 +
32651 +#ifdef CONFIG_X86_64
32652 +#define pxd_t pud_t
32653 +#define pyd_t pgd_t
32654 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32655 +#define pgtable_pxd_page_ctor(page) true
32656 +#define pgtable_pxd_page_dtor(page)
32657 +#define pxd_free(mm, pud) pud_free((mm), (pud))
32658 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32659 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
32660 +#define PYD_SIZE PGDIR_SIZE
32661 +#else
32662 +#define pxd_t pmd_t
32663 +#define pyd_t pud_t
32664 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32665 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
32666 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
32667 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
32668 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32669 +#define pyd_offset(mm, address) pud_offset((mm), (address))
32670 +#define PYD_SIZE PUD_SIZE
32671 +#endif
32672 +
32673 +#ifdef CONFIG_PAX_PER_CPU_PGD
32674 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32675 +static inline void pgd_dtor(pgd_t *pgd) {}
32676 +#else
32677 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32678 {
32679 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32680 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
32681 pgd_list_del(pgd);
32682 spin_unlock(&pgd_lock);
32683 }
32684 +#endif
32685
32686 /*
32687 * List of all pgd's needed for non-PAE so it can invalidate entries
32688 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
32689 * -- nyc
32690 */
32691
32692 -#ifdef CONFIG_X86_PAE
32693 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32694 /*
32695 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32696 * updating the top-level pagetable entries to guarantee the
32697 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
32698 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32699 * and initialize the kernel pmds here.
32700 */
32701 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32702 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32703
32704 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32705 {
32706 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32707 */
32708 flush_tlb_mm(mm);
32709 }
32710 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32711 +#define PREALLOCATED_PXDS USER_PGD_PTRS
32712 #else /* !CONFIG_X86_PAE */
32713
32714 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32715 -#define PREALLOCATED_PMDS 0
32716 +#define PREALLOCATED_PXDS 0
32717
32718 #endif /* CONFIG_X86_PAE */
32719
32720 -static void free_pmds(pmd_t *pmds[])
32721 +static void free_pxds(pxd_t *pxds[])
32722 {
32723 int i;
32724
32725 - for(i = 0; i < PREALLOCATED_PMDS; i++)
32726 - if (pmds[i]) {
32727 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
32728 - free_page((unsigned long)pmds[i]);
32729 + for(i = 0; i < PREALLOCATED_PXDS; i++)
32730 + if (pxds[i]) {
32731 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
32732 + free_page((unsigned long)pxds[i]);
32733 }
32734 }
32735
32736 -static int preallocate_pmds(pmd_t *pmds[])
32737 +static int preallocate_pxds(pxd_t *pxds[])
32738 {
32739 int i;
32740 bool failed = false;
32741
32742 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
32743 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32744 - if (!pmd)
32745 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
32746 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32747 + if (!pxd)
32748 failed = true;
32749 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
32750 - free_page((unsigned long)pmd);
32751 - pmd = NULL;
32752 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
32753 + free_page((unsigned long)pxd);
32754 + pxd = NULL;
32755 failed = true;
32756 }
32757 - pmds[i] = pmd;
32758 + pxds[i] = pxd;
32759 }
32760
32761 if (failed) {
32762 - free_pmds(pmds);
32763 + free_pxds(pxds);
32764 return -ENOMEM;
32765 }
32766
32767 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32768 * preallocate which never got a corresponding vma will need to be
32769 * freed manually.
32770 */
32771 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32772 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32773 {
32774 int i;
32775
32776 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
32777 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
32778 pgd_t pgd = pgdp[i];
32779
32780 if (pgd_val(pgd) != 0) {
32781 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32782 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32783
32784 - pgdp[i] = native_make_pgd(0);
32785 + set_pgd(pgdp + i, native_make_pgd(0));
32786
32787 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32788 - pmd_free(mm, pmd);
32789 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32790 + pxd_free(mm, pxd);
32791 }
32792 }
32793 }
32794
32795 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32796 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32797 {
32798 - pud_t *pud;
32799 + pyd_t *pyd;
32800 int i;
32801
32802 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32803 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32804 return;
32805
32806 - pud = pud_offset(pgd, 0);
32807 -
32808 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32809 - pmd_t *pmd = pmds[i];
32810 +#ifdef CONFIG_X86_64
32811 + pyd = pyd_offset(mm, 0L);
32812 +#else
32813 + pyd = pyd_offset(pgd, 0L);
32814 +#endif
32815
32816 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32817 + pxd_t *pxd = pxds[i];
32818 if (i >= KERNEL_PGD_BOUNDARY)
32819 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32820 - sizeof(pmd_t) * PTRS_PER_PMD);
32821 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32822 + sizeof(pxd_t) * PTRS_PER_PMD);
32823
32824 - pud_populate(mm, pud, pmd);
32825 + pyd_populate(mm, pyd, pxd);
32826 }
32827 }
32828
32829 pgd_t *pgd_alloc(struct mm_struct *mm)
32830 {
32831 pgd_t *pgd;
32832 - pmd_t *pmds[PREALLOCATED_PMDS];
32833 + pxd_t *pxds[PREALLOCATED_PXDS];
32834
32835 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32836
32837 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32838
32839 mm->pgd = pgd;
32840
32841 - if (preallocate_pmds(pmds) != 0)
32842 + if (preallocate_pxds(pxds) != 0)
32843 goto out_free_pgd;
32844
32845 if (paravirt_pgd_alloc(mm) != 0)
32846 - goto out_free_pmds;
32847 + goto out_free_pxds;
32848
32849 /*
32850 * Make sure that pre-populating the pmds is atomic with
32851 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32852 spin_lock(&pgd_lock);
32853
32854 pgd_ctor(mm, pgd);
32855 - pgd_prepopulate_pmd(mm, pgd, pmds);
32856 + pgd_prepopulate_pxd(mm, pgd, pxds);
32857
32858 spin_unlock(&pgd_lock);
32859
32860 return pgd;
32861
32862 -out_free_pmds:
32863 - free_pmds(pmds);
32864 +out_free_pxds:
32865 + free_pxds(pxds);
32866 out_free_pgd:
32867 free_page((unsigned long)pgd);
32868 out:
32869 @@ -313,7 +380,7 @@ out:
32870
32871 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32872 {
32873 - pgd_mop_up_pmds(mm, pgd);
32874 + pgd_mop_up_pxds(mm, pgd);
32875 pgd_dtor(pgd);
32876 paravirt_pgd_free(mm, pgd);
32877 free_page((unsigned long)pgd);
32878 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32879 index a69bcb8..19068ab 100644
32880 --- a/arch/x86/mm/pgtable_32.c
32881 +++ b/arch/x86/mm/pgtable_32.c
32882 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32883 return;
32884 }
32885 pte = pte_offset_kernel(pmd, vaddr);
32886 +
32887 + pax_open_kernel();
32888 if (pte_val(pteval))
32889 set_pte_at(&init_mm, vaddr, pte, pteval);
32890 else
32891 pte_clear(&init_mm, vaddr, pte);
32892 + pax_close_kernel();
32893
32894 /*
32895 * It's enough to flush this one mapping.
32896 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32897 index e666cbb..61788c45 100644
32898 --- a/arch/x86/mm/physaddr.c
32899 +++ b/arch/x86/mm/physaddr.c
32900 @@ -10,7 +10,7 @@
32901 #ifdef CONFIG_X86_64
32902
32903 #ifdef CONFIG_DEBUG_VIRTUAL
32904 -unsigned long __phys_addr(unsigned long x)
32905 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32906 {
32907 unsigned long y = x - __START_KERNEL_map;
32908
32909 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32910 #else
32911
32912 #ifdef CONFIG_DEBUG_VIRTUAL
32913 -unsigned long __phys_addr(unsigned long x)
32914 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32915 {
32916 unsigned long phys_addr = x - PAGE_OFFSET;
32917 /* VMALLOC_* aren't constants */
32918 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32919 index 90555bf..f5f1828 100644
32920 --- a/arch/x86/mm/setup_nx.c
32921 +++ b/arch/x86/mm/setup_nx.c
32922 @@ -5,8 +5,10 @@
32923 #include <asm/pgtable.h>
32924 #include <asm/proto.h>
32925
32926 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32927 static int disable_nx;
32928
32929 +#ifndef CONFIG_PAX_PAGEEXEC
32930 /*
32931 * noexec = on|off
32932 *
32933 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32934 return 0;
32935 }
32936 early_param("noexec", noexec_setup);
32937 +#endif
32938 +
32939 +#endif
32940
32941 void x86_configure_nx(void)
32942 {
32943 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32944 if (cpu_has_nx && !disable_nx)
32945 __supported_pte_mask |= _PAGE_NX;
32946 else
32947 +#endif
32948 __supported_pte_mask &= ~_PAGE_NX;
32949 }
32950
32951 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32952 index ae699b3..f1b2ad2 100644
32953 --- a/arch/x86/mm/tlb.c
32954 +++ b/arch/x86/mm/tlb.c
32955 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
32956 BUG();
32957 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32958 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32959 +
32960 +#ifndef CONFIG_PAX_PER_CPU_PGD
32961 load_cr3(swapper_pg_dir);
32962 +#endif
32963 +
32964 }
32965 }
32966 EXPORT_SYMBOL_GPL(leave_mm);
32967 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32968 new file mode 100644
32969 index 0000000..dace51c
32970 --- /dev/null
32971 +++ b/arch/x86/mm/uderef_64.c
32972 @@ -0,0 +1,37 @@
32973 +#include <linux/mm.h>
32974 +#include <asm/pgtable.h>
32975 +#include <asm/uaccess.h>
32976 +
32977 +#ifdef CONFIG_PAX_MEMORY_UDEREF
32978 +/* PaX: due to the special call convention these functions must
32979 + * - remain leaf functions under all configurations,
32980 + * - never be called directly, only dereferenced from the wrappers.
32981 + */
32982 +void __pax_open_userland(void)
32983 +{
32984 + unsigned int cpu;
32985 +
32986 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
32987 + return;
32988 +
32989 + cpu = raw_get_cpu();
32990 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32991 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32992 + raw_put_cpu_no_resched();
32993 +}
32994 +EXPORT_SYMBOL(__pax_open_userland);
32995 +
32996 +void __pax_close_userland(void)
32997 +{
32998 + unsigned int cpu;
32999 +
33000 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33001 + return;
33002 +
33003 + cpu = raw_get_cpu();
33004 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33005 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33006 + raw_put_cpu_no_resched();
33007 +}
33008 +EXPORT_SYMBOL(__pax_close_userland);
33009 +#endif
33010 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33011 index 877b9a1..a8ecf42 100644
33012 --- a/arch/x86/net/bpf_jit.S
33013 +++ b/arch/x86/net/bpf_jit.S
33014 @@ -9,6 +9,7 @@
33015 */
33016 #include <linux/linkage.h>
33017 #include <asm/dwarf2.h>
33018 +#include <asm/alternative-asm.h>
33019
33020 /*
33021 * Calling convention :
33022 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33023 jle bpf_slow_path_word
33024 mov (SKBDATA,%rsi),%eax
33025 bswap %eax /* ntohl() */
33026 + pax_force_retaddr
33027 ret
33028
33029 sk_load_half:
33030 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33031 jle bpf_slow_path_half
33032 movzwl (SKBDATA,%rsi),%eax
33033 rol $8,%ax # ntohs()
33034 + pax_force_retaddr
33035 ret
33036
33037 sk_load_byte:
33038 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33039 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33040 jle bpf_slow_path_byte
33041 movzbl (SKBDATA,%rsi),%eax
33042 + pax_force_retaddr
33043 ret
33044
33045 /**
33046 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33047 movzbl (SKBDATA,%rsi),%ebx
33048 and $15,%bl
33049 shl $2,%bl
33050 + pax_force_retaddr
33051 ret
33052
33053 /* rsi contains offset and can be scratched */
33054 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33055 js bpf_error
33056 mov -12(%rbp),%eax
33057 bswap %eax
33058 + pax_force_retaddr
33059 ret
33060
33061 bpf_slow_path_half:
33062 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33063 mov -12(%rbp),%ax
33064 rol $8,%ax
33065 movzwl %ax,%eax
33066 + pax_force_retaddr
33067 ret
33068
33069 bpf_slow_path_byte:
33070 bpf_slow_path_common(1)
33071 js bpf_error
33072 movzbl -12(%rbp),%eax
33073 + pax_force_retaddr
33074 ret
33075
33076 bpf_slow_path_byte_msh:
33077 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33078 and $15,%al
33079 shl $2,%al
33080 xchg %eax,%ebx
33081 + pax_force_retaddr
33082 ret
33083
33084 #define sk_negative_common(SIZE) \
33085 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33086 sk_negative_common(4)
33087 mov (%rax), %eax
33088 bswap %eax
33089 + pax_force_retaddr
33090 ret
33091
33092 bpf_slow_path_half_neg:
33093 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33094 mov (%rax),%ax
33095 rol $8,%ax
33096 movzwl %ax,%eax
33097 + pax_force_retaddr
33098 ret
33099
33100 bpf_slow_path_byte_neg:
33101 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33102 .globl sk_load_byte_negative_offset
33103 sk_negative_common(1)
33104 movzbl (%rax), %eax
33105 + pax_force_retaddr
33106 ret
33107
33108 bpf_slow_path_byte_msh_neg:
33109 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33110 and $15,%al
33111 shl $2,%al
33112 xchg %eax,%ebx
33113 + pax_force_retaddr
33114 ret
33115
33116 bpf_error:
33117 @@ -197,4 +210,5 @@ bpf_error:
33118 xor %eax,%eax
33119 mov -8(%rbp),%rbx
33120 leaveq
33121 + pax_force_retaddr
33122 ret
33123 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33124 index 4ed75dd..8dfe0d5 100644
33125 --- a/arch/x86/net/bpf_jit_comp.c
33126 +++ b/arch/x86/net/bpf_jit_comp.c
33127 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33128 return ptr + len;
33129 }
33130
33131 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33132 +#define MAX_INSTR_CODE_SIZE 96
33133 +#else
33134 +#define MAX_INSTR_CODE_SIZE 64
33135 +#endif
33136 +
33137 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33138
33139 #define EMIT1(b1) EMIT(b1, 1)
33140 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33141 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33142 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33143 +
33144 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33145 +/* original constant will appear in ecx */
33146 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33147 +do { \
33148 + /* mov ecx, randkey */ \
33149 + EMIT1(0xb9); \
33150 + EMIT(_key, 4); \
33151 + /* xor ecx, randkey ^ off */ \
33152 + EMIT2(0x81, 0xf1); \
33153 + EMIT((_key) ^ (_off), 4); \
33154 +} while (0)
33155 +
33156 +#define EMIT1_off32(b1, _off) \
33157 +do { \
33158 + switch (b1) { \
33159 + case 0x05: /* add eax, imm32 */ \
33160 + case 0x2d: /* sub eax, imm32 */ \
33161 + case 0x25: /* and eax, imm32 */ \
33162 + case 0x0d: /* or eax, imm32 */ \
33163 + case 0xb8: /* mov eax, imm32 */ \
33164 + case 0x35: /* xor eax, imm32 */ \
33165 + case 0x3d: /* cmp eax, imm32 */ \
33166 + case 0xa9: /* test eax, imm32 */ \
33167 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33168 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33169 + break; \
33170 + case 0xbb: /* mov ebx, imm32 */ \
33171 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33172 + /* mov ebx, ecx */ \
33173 + EMIT2(0x89, 0xcb); \
33174 + break; \
33175 + case 0xbe: /* mov esi, imm32 */ \
33176 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33177 + /* mov esi, ecx */ \
33178 + EMIT2(0x89, 0xce); \
33179 + break; \
33180 + case 0xe8: /* call rel imm32, always to known funcs */ \
33181 + EMIT1(b1); \
33182 + EMIT(_off, 4); \
33183 + break; \
33184 + case 0xe9: /* jmp rel imm32 */ \
33185 + EMIT1(b1); \
33186 + EMIT(_off, 4); \
33187 + /* prevent fall-through, we're not called if off = 0 */ \
33188 + EMIT(0xcccccccc, 4); \
33189 + EMIT(0xcccccccc, 4); \
33190 + break; \
33191 + default: \
33192 + BUILD_BUG(); \
33193 + } \
33194 +} while (0)
33195 +
33196 +#define EMIT2_off32(b1, b2, _off) \
33197 +do { \
33198 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33199 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33200 + EMIT(randkey, 4); \
33201 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33202 + EMIT((_off) - randkey, 4); \
33203 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33204 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33205 + /* imul eax, ecx */ \
33206 + EMIT3(0x0f, 0xaf, 0xc1); \
33207 + } else { \
33208 + BUILD_BUG(); \
33209 + } \
33210 +} while (0)
33211 +#else
33212 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33213 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33214 +#endif
33215
33216 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33217 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33218 @@ -91,6 +168,24 @@ do { \
33219 #define X86_JBE 0x76
33220 #define X86_JA 0x77
33221
33222 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33223 +#define APPEND_FLOW_VERIFY() \
33224 +do { \
33225 + /* mov ecx, randkey */ \
33226 + EMIT1(0xb9); \
33227 + EMIT(randkey, 4); \
33228 + /* cmp ecx, randkey */ \
33229 + EMIT2(0x81, 0xf9); \
33230 + EMIT(randkey, 4); \
33231 + /* jz after 8 int 3s */ \
33232 + EMIT2(0x74, 0x08); \
33233 + EMIT(0xcccccccc, 4); \
33234 + EMIT(0xcccccccc, 4); \
33235 +} while (0)
33236 +#else
33237 +#define APPEND_FLOW_VERIFY() do { } while (0)
33238 +#endif
33239 +
33240 #define EMIT_COND_JMP(op, offset) \
33241 do { \
33242 if (is_near(offset)) \
33243 @@ -98,6 +193,7 @@ do { \
33244 else { \
33245 EMIT2(0x0f, op + 0x10); \
33246 EMIT(offset, 4); /* jxx .+off32 */ \
33247 + APPEND_FLOW_VERIFY(); \
33248 } \
33249 } while (0)
33250
33251 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33252 return -1;
33253 }
33254
33255 -struct bpf_binary_header {
33256 - unsigned int pages;
33257 - /* Note : for security reasons, bpf code will follow a randomly
33258 - * sized amount of int3 instructions
33259 - */
33260 - u8 image[];
33261 -};
33262 -
33263 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33264 +/* Note : for security reasons, bpf code will follow a randomly
33265 + * sized amount of int3 instructions
33266 + */
33267 +static u8 *bpf_alloc_binary(unsigned int proglen,
33268 u8 **image_ptr)
33269 {
33270 unsigned int sz, hole;
33271 - struct bpf_binary_header *header;
33272 + u8 *header;
33273
33274 /* Most of BPF filters are really small,
33275 * but if some of them fill a page, allow at least
33276 * 128 extra bytes to insert a random section of int3
33277 */
33278 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33279 - header = module_alloc(sz);
33280 + sz = round_up(proglen + 128, PAGE_SIZE);
33281 + header = module_alloc_exec(sz);
33282 if (!header)
33283 return NULL;
33284
33285 + pax_open_kernel();
33286 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33287 + pax_close_kernel();
33288
33289 - header->pages = sz / PAGE_SIZE;
33290 - hole = sz - (proglen + sizeof(*header));
33291 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33292
33293 /* insert a random number of int3 instructions before BPF code */
33294 - *image_ptr = &header->image[prandom_u32() % hole];
33295 + *image_ptr = &header[prandom_u32() % hole];
33296 return header;
33297 }
33298
33299 void bpf_jit_compile(struct sk_filter *fp)
33300 {
33301 - u8 temp[64];
33302 + u8 temp[MAX_INSTR_CODE_SIZE];
33303 u8 *prog;
33304 unsigned int proglen, oldproglen = 0;
33305 int ilen, i;
33306 int t_offset, f_offset;
33307 u8 t_op, f_op, seen = 0, pass;
33308 u8 *image = NULL;
33309 - struct bpf_binary_header *header = NULL;
33310 + u8 *header = NULL;
33311 u8 *func;
33312 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33313 unsigned int cleanup_addr; /* epilogue code offset */
33314 unsigned int *addrs;
33315 const struct sock_filter *filter = fp->insns;
33316 int flen = fp->len;
33317 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33318 + unsigned int randkey;
33319 +#endif
33320
33321 if (!bpf_jit_enable)
33322 return;
33323 @@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
33324 if (addrs == NULL)
33325 return;
33326
33327 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33328 + randkey = get_random_int();
33329 +#endif
33330 +
33331 /* Before first pass, make a rough estimation of addrs[]
33332 - * each bpf instruction is translated to less than 64 bytes
33333 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33334 */
33335 for (proglen = 0, i = 0; i < flen; i++) {
33336 - proglen += 64;
33337 + proglen += MAX_INSTR_CODE_SIZE;
33338 addrs[i] = proglen;
33339 }
33340 cleanup_addr = proglen; /* epilogue address */
33341 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33342 case BPF_S_ALU_MUL_K: /* A *= K */
33343 if (is_imm8(K))
33344 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33345 - else {
33346 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33347 - EMIT(K, 4);
33348 - }
33349 + else
33350 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33351 break;
33352 case BPF_S_ALU_DIV_X: /* A /= X; */
33353 seen |= SEEN_XREG;
33354 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33355 break;
33356 }
33357 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33358 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33359 + DILUTE_CONST_SEQUENCE(K, randkey);
33360 +#else
33361 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33362 +#endif
33363 EMIT2(0xf7, 0xf1); /* div %ecx */
33364 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33365 break;
33366 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33367 if (K == 1)
33368 break;
33369 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33370 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33371 + DILUTE_CONST_SEQUENCE(K, randkey);
33372 +#else
33373 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33374 +#endif
33375 EMIT2(0xf7, 0xf1); /* div %ecx */
33376 break;
33377 case BPF_S_ALU_AND_X:
33378 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33379 if (is_imm8(K)) {
33380 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33381 } else {
33382 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33383 - EMIT(K, 4);
33384 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33385 }
33386 } else {
33387 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33388 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33389 if (unlikely(proglen + ilen > oldproglen)) {
33390 pr_err("bpb_jit_compile fatal error\n");
33391 kfree(addrs);
33392 - module_free(NULL, header);
33393 + module_free_exec(NULL, image);
33394 return;
33395 }
33396 + pax_open_kernel();
33397 memcpy(image + proglen, temp, ilen);
33398 + pax_close_kernel();
33399 }
33400 proglen += ilen;
33401 addrs[i] = proglen;
33402 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33403
33404 if (image) {
33405 bpf_flush_icache(header, image + proglen);
33406 - set_memory_ro((unsigned long)header, header->pages);
33407 fp->bpf_func = (void *)image;
33408 }
33409 out:
33410 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33411 {
33412 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33413 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33414 - struct bpf_binary_header *header = (void *)addr;
33415
33416 - set_memory_rw(addr, header->pages);
33417 - module_free(NULL, header);
33418 + set_memory_rw(addr, 1);
33419 + module_free_exec(NULL, (void *)addr);
33420 kfree(fp);
33421 }
33422
33423 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33424 index 5d04be5..2beeaa2 100644
33425 --- a/arch/x86/oprofile/backtrace.c
33426 +++ b/arch/x86/oprofile/backtrace.c
33427 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33428 struct stack_frame_ia32 *fp;
33429 unsigned long bytes;
33430
33431 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33432 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33433 if (bytes != 0)
33434 return NULL;
33435
33436 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33437 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33438
33439 oprofile_add_trace(bufhead[0].return_address);
33440
33441 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33442 struct stack_frame bufhead[2];
33443 unsigned long bytes;
33444
33445 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33446 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33447 if (bytes != 0)
33448 return NULL;
33449
33450 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33451 {
33452 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33453
33454 - if (!user_mode_vm(regs)) {
33455 + if (!user_mode(regs)) {
33456 unsigned long stack = kernel_stack_pointer(regs);
33457 if (depth)
33458 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33459 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33460 index 6890d84..1dad1f1 100644
33461 --- a/arch/x86/oprofile/nmi_int.c
33462 +++ b/arch/x86/oprofile/nmi_int.c
33463 @@ -23,6 +23,7 @@
33464 #include <asm/nmi.h>
33465 #include <asm/msr.h>
33466 #include <asm/apic.h>
33467 +#include <asm/pgtable.h>
33468
33469 #include "op_counter.h"
33470 #include "op_x86_model.h"
33471 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33472 if (ret)
33473 return ret;
33474
33475 - if (!model->num_virt_counters)
33476 - model->num_virt_counters = model->num_counters;
33477 + if (!model->num_virt_counters) {
33478 + pax_open_kernel();
33479 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
33480 + pax_close_kernel();
33481 + }
33482
33483 mux_init(ops);
33484
33485 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33486 index 50d86c0..7985318 100644
33487 --- a/arch/x86/oprofile/op_model_amd.c
33488 +++ b/arch/x86/oprofile/op_model_amd.c
33489 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33490 num_counters = AMD64_NUM_COUNTERS;
33491 }
33492
33493 - op_amd_spec.num_counters = num_counters;
33494 - op_amd_spec.num_controls = num_counters;
33495 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33496 + pax_open_kernel();
33497 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33498 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33499 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33500 + pax_close_kernel();
33501
33502 return 0;
33503 }
33504 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33505 index d90528e..0127e2b 100644
33506 --- a/arch/x86/oprofile/op_model_ppro.c
33507 +++ b/arch/x86/oprofile/op_model_ppro.c
33508 @@ -19,6 +19,7 @@
33509 #include <asm/msr.h>
33510 #include <asm/apic.h>
33511 #include <asm/nmi.h>
33512 +#include <asm/pgtable.h>
33513
33514 #include "op_x86_model.h"
33515 #include "op_counter.h"
33516 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33517
33518 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33519
33520 - op_arch_perfmon_spec.num_counters = num_counters;
33521 - op_arch_perfmon_spec.num_controls = num_counters;
33522 + pax_open_kernel();
33523 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33524 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33525 + pax_close_kernel();
33526 }
33527
33528 static int arch_perfmon_init(struct oprofile_operations *ignore)
33529 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33530 index 71e8a67..6a313bb 100644
33531 --- a/arch/x86/oprofile/op_x86_model.h
33532 +++ b/arch/x86/oprofile/op_x86_model.h
33533 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
33534 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33535 struct op_msrs const * const msrs);
33536 #endif
33537 -};
33538 +} __do_const;
33539
33540 struct op_counter_config;
33541
33542 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
33543 index 51384ca..a25f51e 100644
33544 --- a/arch/x86/pci/intel_mid_pci.c
33545 +++ b/arch/x86/pci/intel_mid_pci.c
33546 @@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
33547 pr_info("Intel MID platform detected, using MID PCI ops\n");
33548 pci_mmcfg_late_init();
33549 pcibios_enable_irq = intel_mid_pci_irq_enable;
33550 - pci_root_ops = intel_mid_pci_ops;
33551 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
33552 pci_soc_mode = 1;
33553 /* Continue with standard init */
33554 return 1;
33555 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33556 index 372e9b8..e775a6c 100644
33557 --- a/arch/x86/pci/irq.c
33558 +++ b/arch/x86/pci/irq.c
33559 @@ -50,7 +50,7 @@ struct irq_router {
33560 struct irq_router_handler {
33561 u16 vendor;
33562 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33563 -};
33564 +} __do_const;
33565
33566 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33567 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33568 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33569 return 0;
33570 }
33571
33572 -static __initdata struct irq_router_handler pirq_routers[] = {
33573 +static __initconst const struct irq_router_handler pirq_routers[] = {
33574 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33575 { PCI_VENDOR_ID_AL, ali_router_probe },
33576 { PCI_VENDOR_ID_ITE, ite_router_probe },
33577 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33578 static void __init pirq_find_router(struct irq_router *r)
33579 {
33580 struct irq_routing_table *rt = pirq_table;
33581 - struct irq_router_handler *h;
33582 + const struct irq_router_handler *h;
33583
33584 #ifdef CONFIG_PCI_BIOS
33585 if (!rt->signature) {
33586 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33587 return 0;
33588 }
33589
33590 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33591 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33592 {
33593 .callback = fix_broken_hp_bios_irq9,
33594 .ident = "HP Pavilion N5400 Series Laptop",
33595 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33596 index c77b24a..c979855 100644
33597 --- a/arch/x86/pci/pcbios.c
33598 +++ b/arch/x86/pci/pcbios.c
33599 @@ -79,7 +79,7 @@ union bios32 {
33600 static struct {
33601 unsigned long address;
33602 unsigned short segment;
33603 -} bios32_indirect = { 0, __KERNEL_CS };
33604 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33605
33606 /*
33607 * Returns the entry point for the given service, NULL on error
33608 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33609 unsigned long length; /* %ecx */
33610 unsigned long entry; /* %edx */
33611 unsigned long flags;
33612 + struct desc_struct d, *gdt;
33613
33614 local_irq_save(flags);
33615 - __asm__("lcall *(%%edi); cld"
33616 +
33617 + gdt = get_cpu_gdt_table(smp_processor_id());
33618 +
33619 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33620 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33621 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33622 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33623 +
33624 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33625 : "=a" (return_code),
33626 "=b" (address),
33627 "=c" (length),
33628 "=d" (entry)
33629 : "0" (service),
33630 "1" (0),
33631 - "D" (&bios32_indirect));
33632 + "D" (&bios32_indirect),
33633 + "r"(__PCIBIOS_DS)
33634 + : "memory");
33635 +
33636 + pax_open_kernel();
33637 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33638 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33639 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33640 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33641 + pax_close_kernel();
33642 +
33643 local_irq_restore(flags);
33644
33645 switch (return_code) {
33646 - case 0:
33647 - return address + entry;
33648 - case 0x80: /* Not present */
33649 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33650 - return 0;
33651 - default: /* Shouldn't happen */
33652 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33653 - service, return_code);
33654 + case 0: {
33655 + int cpu;
33656 + unsigned char flags;
33657 +
33658 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33659 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33660 + printk(KERN_WARNING "bios32_service: not valid\n");
33661 return 0;
33662 + }
33663 + address = address + PAGE_OFFSET;
33664 + length += 16UL; /* some BIOSs underreport this... */
33665 + flags = 4;
33666 + if (length >= 64*1024*1024) {
33667 + length >>= PAGE_SHIFT;
33668 + flags |= 8;
33669 + }
33670 +
33671 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33672 + gdt = get_cpu_gdt_table(cpu);
33673 + pack_descriptor(&d, address, length, 0x9b, flags);
33674 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33675 + pack_descriptor(&d, address, length, 0x93, flags);
33676 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33677 + }
33678 + return entry;
33679 + }
33680 + case 0x80: /* Not present */
33681 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33682 + return 0;
33683 + default: /* Shouldn't happen */
33684 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33685 + service, return_code);
33686 + return 0;
33687 }
33688 }
33689
33690 static struct {
33691 unsigned long address;
33692 unsigned short segment;
33693 -} pci_indirect = { 0, __KERNEL_CS };
33694 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33695
33696 -static int pci_bios_present;
33697 +static int pci_bios_present __read_only;
33698
33699 static int check_pcibios(void)
33700 {
33701 @@ -131,11 +174,13 @@ static int check_pcibios(void)
33702 unsigned long flags, pcibios_entry;
33703
33704 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33705 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33706 + pci_indirect.address = pcibios_entry;
33707
33708 local_irq_save(flags);
33709 - __asm__(
33710 - "lcall *(%%edi); cld\n\t"
33711 + __asm__("movw %w6, %%ds\n\t"
33712 + "lcall *%%ss:(%%edi); cld\n\t"
33713 + "push %%ss\n\t"
33714 + "pop %%ds\n\t"
33715 "jc 1f\n\t"
33716 "xor %%ah, %%ah\n"
33717 "1:"
33718 @@ -144,7 +189,8 @@ static int check_pcibios(void)
33719 "=b" (ebx),
33720 "=c" (ecx)
33721 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33722 - "D" (&pci_indirect)
33723 + "D" (&pci_indirect),
33724 + "r" (__PCIBIOS_DS)
33725 : "memory");
33726 local_irq_restore(flags);
33727
33728 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33729
33730 switch (len) {
33731 case 1:
33732 - __asm__("lcall *(%%esi); cld\n\t"
33733 + __asm__("movw %w6, %%ds\n\t"
33734 + "lcall *%%ss:(%%esi); cld\n\t"
33735 + "push %%ss\n\t"
33736 + "pop %%ds\n\t"
33737 "jc 1f\n\t"
33738 "xor %%ah, %%ah\n"
33739 "1:"
33740 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33741 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33742 "b" (bx),
33743 "D" ((long)reg),
33744 - "S" (&pci_indirect));
33745 + "S" (&pci_indirect),
33746 + "r" (__PCIBIOS_DS));
33747 /*
33748 * Zero-extend the result beyond 8 bits, do not trust the
33749 * BIOS having done it:
33750 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33751 *value &= 0xff;
33752 break;
33753 case 2:
33754 - __asm__("lcall *(%%esi); cld\n\t"
33755 + __asm__("movw %w6, %%ds\n\t"
33756 + "lcall *%%ss:(%%esi); cld\n\t"
33757 + "push %%ss\n\t"
33758 + "pop %%ds\n\t"
33759 "jc 1f\n\t"
33760 "xor %%ah, %%ah\n"
33761 "1:"
33762 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33763 : "1" (PCIBIOS_READ_CONFIG_WORD),
33764 "b" (bx),
33765 "D" ((long)reg),
33766 - "S" (&pci_indirect));
33767 + "S" (&pci_indirect),
33768 + "r" (__PCIBIOS_DS));
33769 /*
33770 * Zero-extend the result beyond 16 bits, do not trust the
33771 * BIOS having done it:
33772 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33773 *value &= 0xffff;
33774 break;
33775 case 4:
33776 - __asm__("lcall *(%%esi); cld\n\t"
33777 + __asm__("movw %w6, %%ds\n\t"
33778 + "lcall *%%ss:(%%esi); cld\n\t"
33779 + "push %%ss\n\t"
33780 + "pop %%ds\n\t"
33781 "jc 1f\n\t"
33782 "xor %%ah, %%ah\n"
33783 "1:"
33784 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33785 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33786 "b" (bx),
33787 "D" ((long)reg),
33788 - "S" (&pci_indirect));
33789 + "S" (&pci_indirect),
33790 + "r" (__PCIBIOS_DS));
33791 break;
33792 }
33793
33794 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33795
33796 switch (len) {
33797 case 1:
33798 - __asm__("lcall *(%%esi); cld\n\t"
33799 + __asm__("movw %w6, %%ds\n\t"
33800 + "lcall *%%ss:(%%esi); cld\n\t"
33801 + "push %%ss\n\t"
33802 + "pop %%ds\n\t"
33803 "jc 1f\n\t"
33804 "xor %%ah, %%ah\n"
33805 "1:"
33806 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33807 "c" (value),
33808 "b" (bx),
33809 "D" ((long)reg),
33810 - "S" (&pci_indirect));
33811 + "S" (&pci_indirect),
33812 + "r" (__PCIBIOS_DS));
33813 break;
33814 case 2:
33815 - __asm__("lcall *(%%esi); cld\n\t"
33816 + __asm__("movw %w6, %%ds\n\t"
33817 + "lcall *%%ss:(%%esi); cld\n\t"
33818 + "push %%ss\n\t"
33819 + "pop %%ds\n\t"
33820 "jc 1f\n\t"
33821 "xor %%ah, %%ah\n"
33822 "1:"
33823 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33824 "c" (value),
33825 "b" (bx),
33826 "D" ((long)reg),
33827 - "S" (&pci_indirect));
33828 + "S" (&pci_indirect),
33829 + "r" (__PCIBIOS_DS));
33830 break;
33831 case 4:
33832 - __asm__("lcall *(%%esi); cld\n\t"
33833 + __asm__("movw %w6, %%ds\n\t"
33834 + "lcall *%%ss:(%%esi); cld\n\t"
33835 + "push %%ss\n\t"
33836 + "pop %%ds\n\t"
33837 "jc 1f\n\t"
33838 "xor %%ah, %%ah\n"
33839 "1:"
33840 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33841 "c" (value),
33842 "b" (bx),
33843 "D" ((long)reg),
33844 - "S" (&pci_indirect));
33845 + "S" (&pci_indirect),
33846 + "r" (__PCIBIOS_DS));
33847 break;
33848 }
33849
33850 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33851
33852 DBG("PCI: Fetching IRQ routing table... ");
33853 __asm__("push %%es\n\t"
33854 + "movw %w8, %%ds\n\t"
33855 "push %%ds\n\t"
33856 "pop %%es\n\t"
33857 - "lcall *(%%esi); cld\n\t"
33858 + "lcall *%%ss:(%%esi); cld\n\t"
33859 "pop %%es\n\t"
33860 + "push %%ss\n\t"
33861 + "pop %%ds\n"
33862 "jc 1f\n\t"
33863 "xor %%ah, %%ah\n"
33864 "1:"
33865 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33866 "1" (0),
33867 "D" ((long) &opt),
33868 "S" (&pci_indirect),
33869 - "m" (opt)
33870 + "m" (opt),
33871 + "r" (__PCIBIOS_DS)
33872 : "memory");
33873 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33874 if (ret & 0xff00)
33875 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33876 {
33877 int ret;
33878
33879 - __asm__("lcall *(%%esi); cld\n\t"
33880 + __asm__("movw %w5, %%ds\n\t"
33881 + "lcall *%%ss:(%%esi); cld\n\t"
33882 + "push %%ss\n\t"
33883 + "pop %%ds\n"
33884 "jc 1f\n\t"
33885 "xor %%ah, %%ah\n"
33886 "1:"
33887 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33888 : "0" (PCIBIOS_SET_PCI_HW_INT),
33889 "b" ((dev->bus->number << 8) | dev->devfn),
33890 "c" ((irq << 8) | (pin + 10)),
33891 - "S" (&pci_indirect));
33892 + "S" (&pci_indirect),
33893 + "r" (__PCIBIOS_DS));
33894 return !(ret & 0xff00);
33895 }
33896 EXPORT_SYMBOL(pcibios_set_irq_routing);
33897 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33898 index 40e4469..d915bf9 100644
33899 --- a/arch/x86/platform/efi/efi_32.c
33900 +++ b/arch/x86/platform/efi/efi_32.c
33901 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33902 {
33903 struct desc_ptr gdt_descr;
33904
33905 +#ifdef CONFIG_PAX_KERNEXEC
33906 + struct desc_struct d;
33907 +#endif
33908 +
33909 local_irq_save(efi_rt_eflags);
33910
33911 load_cr3(initial_page_table);
33912 __flush_tlb_all();
33913
33914 +#ifdef CONFIG_PAX_KERNEXEC
33915 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33916 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33917 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33918 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33919 +#endif
33920 +
33921 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33922 gdt_descr.size = GDT_SIZE - 1;
33923 load_gdt(&gdt_descr);
33924 @@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33925 {
33926 struct desc_ptr gdt_descr;
33927
33928 +#ifdef CONFIG_PAX_KERNEXEC
33929 + struct desc_struct d;
33930 +
33931 + memset(&d, 0, sizeof d);
33932 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33933 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33934 +#endif
33935 +
33936 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33937 gdt_descr.size = GDT_SIZE - 1;
33938 load_gdt(&gdt_descr);
33939
33940 +#ifdef CONFIG_PAX_PER_CPU_PGD
33941 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33942 +#else
33943 load_cr3(swapper_pg_dir);
33944 +#endif
33945 +
33946 __flush_tlb_all();
33947
33948 local_irq_restore(efi_rt_eflags);
33949 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33950 index 39a0e7f1..872396e 100644
33951 --- a/arch/x86/platform/efi/efi_64.c
33952 +++ b/arch/x86/platform/efi/efi_64.c
33953 @@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33954 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33955 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33956 }
33957 +
33958 +#ifdef CONFIG_PAX_PER_CPU_PGD
33959 + load_cr3(swapper_pg_dir);
33960 +#endif
33961 +
33962 __flush_tlb_all();
33963 }
33964
33965 @@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33966 for (pgd = 0; pgd < n_pgds; pgd++)
33967 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33968 kfree(save_pgd);
33969 +
33970 +#ifdef CONFIG_PAX_PER_CPU_PGD
33971 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33972 +#endif
33973 +
33974 __flush_tlb_all();
33975 local_irq_restore(efi_flags);
33976 early_code_mapping_set_exec(0);
33977 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33978 index fbe66e6..eae5e38 100644
33979 --- a/arch/x86/platform/efi/efi_stub_32.S
33980 +++ b/arch/x86/platform/efi/efi_stub_32.S
33981 @@ -6,7 +6,9 @@
33982 */
33983
33984 #include <linux/linkage.h>
33985 +#include <linux/init.h>
33986 #include <asm/page_types.h>
33987 +#include <asm/segment.h>
33988
33989 /*
33990 * efi_call_phys(void *, ...) is a function with variable parameters.
33991 @@ -20,7 +22,7 @@
33992 * service functions will comply with gcc calling convention, too.
33993 */
33994
33995 -.text
33996 +__INIT
33997 ENTRY(efi_call_phys)
33998 /*
33999 * 0. The function can only be called in Linux kernel. So CS has been
34000 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34001 * The mapping of lower virtual memory has been created in prelog and
34002 * epilog.
34003 */
34004 - movl $1f, %edx
34005 - subl $__PAGE_OFFSET, %edx
34006 - jmp *%edx
34007 +#ifdef CONFIG_PAX_KERNEXEC
34008 + movl $(__KERNEXEC_EFI_DS), %edx
34009 + mov %edx, %ds
34010 + mov %edx, %es
34011 + mov %edx, %ss
34012 + addl $2f,(1f)
34013 + ljmp *(1f)
34014 +
34015 +__INITDATA
34016 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34017 +.previous
34018 +
34019 +2:
34020 + subl $2b,(1b)
34021 +#else
34022 + jmp 1f-__PAGE_OFFSET
34023 1:
34024 +#endif
34025
34026 /*
34027 * 2. Now on the top of stack is the return
34028 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34029 * parameter 2, ..., param n. To make things easy, we save the return
34030 * address of efi_call_phys in a global variable.
34031 */
34032 - popl %edx
34033 - movl %edx, saved_return_addr
34034 - /* get the function pointer into ECX*/
34035 - popl %ecx
34036 - movl %ecx, efi_rt_function_ptr
34037 - movl $2f, %edx
34038 - subl $__PAGE_OFFSET, %edx
34039 - pushl %edx
34040 + popl (saved_return_addr)
34041 + popl (efi_rt_function_ptr)
34042
34043 /*
34044 * 3. Clear PG bit in %CR0.
34045 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34046 /*
34047 * 5. Call the physical function.
34048 */
34049 - jmp *%ecx
34050 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34051
34052 -2:
34053 /*
34054 * 6. After EFI runtime service returns, control will return to
34055 * following instruction. We'd better readjust stack pointer first.
34056 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34057 movl %cr0, %edx
34058 orl $0x80000000, %edx
34059 movl %edx, %cr0
34060 - jmp 1f
34061 -1:
34062 +
34063 /*
34064 * 8. Now restore the virtual mode from flat mode by
34065 * adding EIP with PAGE_OFFSET.
34066 */
34067 - movl $1f, %edx
34068 - jmp *%edx
34069 +#ifdef CONFIG_PAX_KERNEXEC
34070 + movl $(__KERNEL_DS), %edx
34071 + mov %edx, %ds
34072 + mov %edx, %es
34073 + mov %edx, %ss
34074 + ljmp $(__KERNEL_CS),$1f
34075 +#else
34076 + jmp 1f+__PAGE_OFFSET
34077 +#endif
34078 1:
34079
34080 /*
34081 * 9. Balance the stack. And because EAX contain the return value,
34082 * we'd better not clobber it.
34083 */
34084 - leal efi_rt_function_ptr, %edx
34085 - movl (%edx), %ecx
34086 - pushl %ecx
34087 + pushl (efi_rt_function_ptr)
34088
34089 /*
34090 - * 10. Push the saved return address onto the stack and return.
34091 + * 10. Return to the saved return address.
34092 */
34093 - leal saved_return_addr, %edx
34094 - movl (%edx), %ecx
34095 - pushl %ecx
34096 - ret
34097 + jmpl *(saved_return_addr)
34098 ENDPROC(efi_call_phys)
34099 .previous
34100
34101 -.data
34102 +__INITDATA
34103 saved_return_addr:
34104 .long 0
34105 efi_rt_function_ptr:
34106 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34107 index 4c07cca..2c8427d 100644
34108 --- a/arch/x86/platform/efi/efi_stub_64.S
34109 +++ b/arch/x86/platform/efi/efi_stub_64.S
34110 @@ -7,6 +7,7 @@
34111 */
34112
34113 #include <linux/linkage.h>
34114 +#include <asm/alternative-asm.h>
34115
34116 #define SAVE_XMM \
34117 mov %rsp, %rax; \
34118 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
34119 call *%rdi
34120 addq $32, %rsp
34121 RESTORE_XMM
34122 + pax_force_retaddr 0, 1
34123 ret
34124 ENDPROC(efi_call0)
34125
34126 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
34127 call *%rdi
34128 addq $32, %rsp
34129 RESTORE_XMM
34130 + pax_force_retaddr 0, 1
34131 ret
34132 ENDPROC(efi_call1)
34133
34134 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
34135 call *%rdi
34136 addq $32, %rsp
34137 RESTORE_XMM
34138 + pax_force_retaddr 0, 1
34139 ret
34140 ENDPROC(efi_call2)
34141
34142 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
34143 call *%rdi
34144 addq $32, %rsp
34145 RESTORE_XMM
34146 + pax_force_retaddr 0, 1
34147 ret
34148 ENDPROC(efi_call3)
34149
34150 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
34151 call *%rdi
34152 addq $32, %rsp
34153 RESTORE_XMM
34154 + pax_force_retaddr 0, 1
34155 ret
34156 ENDPROC(efi_call4)
34157
34158 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
34159 call *%rdi
34160 addq $48, %rsp
34161 RESTORE_XMM
34162 + pax_force_retaddr 0, 1
34163 ret
34164 ENDPROC(efi_call5)
34165
34166 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
34167 call *%rdi
34168 addq $48, %rsp
34169 RESTORE_XMM
34170 + pax_force_retaddr 0, 1
34171 ret
34172 ENDPROC(efi_call6)
34173 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34174 index f90e290..435f0dd 100644
34175 --- a/arch/x86/platform/intel-mid/intel-mid.c
34176 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34177 @@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34178 {
34179 }
34180
34181 -static void intel_mid_reboot(void)
34182 +static void __noreturn intel_mid_reboot(void)
34183 {
34184 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34185 + BUG();
34186 }
34187
34188 static unsigned long __init intel_mid_calibrate_tsc(void)
34189 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34190 index d6ee929..3637cb5 100644
34191 --- a/arch/x86/platform/olpc/olpc_dt.c
34192 +++ b/arch/x86/platform/olpc/olpc_dt.c
34193 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34194 return res;
34195 }
34196
34197 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34198 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34199 .nextprop = olpc_dt_nextprop,
34200 .getproplen = olpc_dt_getproplen,
34201 .getproperty = olpc_dt_getproperty,
34202 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34203 index 424f4c9..f2a2988 100644
34204 --- a/arch/x86/power/cpu.c
34205 +++ b/arch/x86/power/cpu.c
34206 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34207 static void fix_processor_context(void)
34208 {
34209 int cpu = smp_processor_id();
34210 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34211 -#ifdef CONFIG_X86_64
34212 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34213 - tss_desc tss;
34214 -#endif
34215 + struct tss_struct *t = init_tss + cpu;
34216 +
34217 set_tss_desc(cpu, t); /*
34218 * This just modifies memory; should not be
34219 * necessary. But... This is necessary, because
34220 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34221 */
34222
34223 #ifdef CONFIG_X86_64
34224 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34225 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34226 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34227 -
34228 syscall_init(); /* This sets MSR_*STAR and related */
34229 #endif
34230 load_TR_desc(); /* This does ltr */
34231 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34232 index a44f457..9140171 100644
34233 --- a/arch/x86/realmode/init.c
34234 +++ b/arch/x86/realmode/init.c
34235 @@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34236 __va(real_mode_header->trampoline_header);
34237
34238 #ifdef CONFIG_X86_32
34239 - trampoline_header->start = __pa_symbol(startup_32_smp);
34240 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34241 +
34242 +#ifdef CONFIG_PAX_KERNEXEC
34243 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34244 +#endif
34245 +
34246 + trampoline_header->boot_cs = __BOOT_CS;
34247 trampoline_header->gdt_limit = __BOOT_DS + 7;
34248 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34249 #else
34250 @@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34251 *trampoline_cr4_features = read_cr4();
34252
34253 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34254 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34255 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34256 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34257 #endif
34258 }
34259 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34260 index 9cac825..4890b25 100644
34261 --- a/arch/x86/realmode/rm/Makefile
34262 +++ b/arch/x86/realmode/rm/Makefile
34263 @@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34264 $(call cc-option, -fno-unit-at-a-time)) \
34265 $(call cc-option, -fno-stack-protector) \
34266 $(call cc-option, -mpreferred-stack-boundary=2)
34267 +ifdef CONSTIFY_PLUGIN
34268 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34269 +endif
34270 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34271 GCOV_PROFILE := n
34272 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34273 index a28221d..93c40f1 100644
34274 --- a/arch/x86/realmode/rm/header.S
34275 +++ b/arch/x86/realmode/rm/header.S
34276 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34277 #endif
34278 /* APM/BIOS reboot */
34279 .long pa_machine_real_restart_asm
34280 -#ifdef CONFIG_X86_64
34281 +#ifdef CONFIG_X86_32
34282 + .long __KERNEL_CS
34283 +#else
34284 .long __KERNEL32_CS
34285 #endif
34286 END(real_mode_header)
34287 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34288 index c1b2791..f9e31c7 100644
34289 --- a/arch/x86/realmode/rm/trampoline_32.S
34290 +++ b/arch/x86/realmode/rm/trampoline_32.S
34291 @@ -25,6 +25,12 @@
34292 #include <asm/page_types.h>
34293 #include "realmode.h"
34294
34295 +#ifdef CONFIG_PAX_KERNEXEC
34296 +#define ta(X) (X)
34297 +#else
34298 +#define ta(X) (pa_ ## X)
34299 +#endif
34300 +
34301 .text
34302 .code16
34303
34304 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34305
34306 cli # We should be safe anyway
34307
34308 - movl tr_start, %eax # where we need to go
34309 -
34310 movl $0xA5A5A5A5, trampoline_status
34311 # write marker for master knows we're running
34312
34313 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34314 movw $1, %dx # protected mode (PE) bit
34315 lmsw %dx # into protected mode
34316
34317 - ljmpl $__BOOT_CS, $pa_startup_32
34318 + ljmpl *(trampoline_header)
34319
34320 .section ".text32","ax"
34321 .code32
34322 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34323 .balign 8
34324 GLOBAL(trampoline_header)
34325 tr_start: .space 4
34326 - tr_gdt_pad: .space 2
34327 + tr_boot_cs: .space 2
34328 tr_gdt: .space 6
34329 END(trampoline_header)
34330
34331 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34332 index bb360dc..d0fd8f8 100644
34333 --- a/arch/x86/realmode/rm/trampoline_64.S
34334 +++ b/arch/x86/realmode/rm/trampoline_64.S
34335 @@ -94,6 +94,7 @@ ENTRY(startup_32)
34336 movl %edx, %gs
34337
34338 movl pa_tr_cr4, %eax
34339 + andl $~X86_CR4_PCIDE, %eax
34340 movl %eax, %cr4 # Enable PAE mode
34341
34342 # Setup trampoline 4 level pagetables
34343 @@ -107,7 +108,7 @@ ENTRY(startup_32)
34344 wrmsr
34345
34346 # Enable paging and in turn activate Long Mode
34347 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34348 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34349 movl %eax, %cr0
34350
34351 /*
34352 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34353 index e812034..c747134 100644
34354 --- a/arch/x86/tools/Makefile
34355 +++ b/arch/x86/tools/Makefile
34356 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34357
34358 $(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
34359
34360 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34361 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34362 hostprogs-y += relocs
34363 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34364 relocs: $(obj)/relocs
34365 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34366 index f7bab68..b6d9886 100644
34367 --- a/arch/x86/tools/relocs.c
34368 +++ b/arch/x86/tools/relocs.c
34369 @@ -1,5 +1,7 @@
34370 /* This is included from relocs_32/64.c */
34371
34372 +#include "../../../include/generated/autoconf.h"
34373 +
34374 #define ElfW(type) _ElfW(ELF_BITS, type)
34375 #define _ElfW(bits, type) __ElfW(bits, type)
34376 #define __ElfW(bits, type) Elf##bits##_##type
34377 @@ -11,6 +13,7 @@
34378 #define Elf_Sym ElfW(Sym)
34379
34380 static Elf_Ehdr ehdr;
34381 +static Elf_Phdr *phdr;
34382
34383 struct relocs {
34384 uint32_t *offset;
34385 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34386 }
34387 }
34388
34389 +static void read_phdrs(FILE *fp)
34390 +{
34391 + unsigned int i;
34392 +
34393 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34394 + if (!phdr) {
34395 + die("Unable to allocate %d program headers\n",
34396 + ehdr.e_phnum);
34397 + }
34398 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34399 + die("Seek to %d failed: %s\n",
34400 + ehdr.e_phoff, strerror(errno));
34401 + }
34402 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34403 + die("Cannot read ELF program headers: %s\n",
34404 + strerror(errno));
34405 + }
34406 + for(i = 0; i < ehdr.e_phnum; i++) {
34407 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34408 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34409 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34410 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34411 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34412 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34413 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34414 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34415 + }
34416 +
34417 +}
34418 +
34419 static void read_shdrs(FILE *fp)
34420 {
34421 - int i;
34422 + unsigned int i;
34423 Elf_Shdr shdr;
34424
34425 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34426 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34427
34428 static void read_strtabs(FILE *fp)
34429 {
34430 - int i;
34431 + unsigned int i;
34432 for (i = 0; i < ehdr.e_shnum; i++) {
34433 struct section *sec = &secs[i];
34434 if (sec->shdr.sh_type != SHT_STRTAB) {
34435 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34436
34437 static void read_symtabs(FILE *fp)
34438 {
34439 - int i,j;
34440 + unsigned int i,j;
34441 for (i = 0; i < ehdr.e_shnum; i++) {
34442 struct section *sec = &secs[i];
34443 if (sec->shdr.sh_type != SHT_SYMTAB) {
34444 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34445 }
34446
34447
34448 -static void read_relocs(FILE *fp)
34449 +static void read_relocs(FILE *fp, int use_real_mode)
34450 {
34451 - int i,j;
34452 + unsigned int i,j;
34453 + uint32_t base;
34454 +
34455 for (i = 0; i < ehdr.e_shnum; i++) {
34456 struct section *sec = &secs[i];
34457 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34458 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34459 die("Cannot read symbol table: %s\n",
34460 strerror(errno));
34461 }
34462 + base = 0;
34463 +
34464 +#ifdef CONFIG_X86_32
34465 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34466 + if (phdr[j].p_type != PT_LOAD )
34467 + continue;
34468 + 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)
34469 + continue;
34470 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34471 + break;
34472 + }
34473 +#endif
34474 +
34475 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34476 Elf_Rel *rel = &sec->reltab[j];
34477 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34478 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34479 rel->r_info = elf_xword_to_cpu(rel->r_info);
34480 #if (SHT_REL_TYPE == SHT_RELA)
34481 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34482 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34483
34484 static void print_absolute_symbols(void)
34485 {
34486 - int i;
34487 + unsigned int i;
34488 const char *format;
34489
34490 if (ELF_BITS == 64)
34491 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34492 for (i = 0; i < ehdr.e_shnum; i++) {
34493 struct section *sec = &secs[i];
34494 char *sym_strtab;
34495 - int j;
34496 + unsigned int j;
34497
34498 if (sec->shdr.sh_type != SHT_SYMTAB) {
34499 continue;
34500 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34501
34502 static void print_absolute_relocs(void)
34503 {
34504 - int i, printed = 0;
34505 + unsigned int i, printed = 0;
34506 const char *format;
34507
34508 if (ELF_BITS == 64)
34509 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34510 struct section *sec_applies, *sec_symtab;
34511 char *sym_strtab;
34512 Elf_Sym *sh_symtab;
34513 - int j;
34514 + unsigned int j;
34515 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34516 continue;
34517 }
34518 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34519 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34520 Elf_Sym *sym, const char *symname))
34521 {
34522 - int i;
34523 + unsigned int i;
34524 /* Walk through the relocations */
34525 for (i = 0; i < ehdr.e_shnum; i++) {
34526 char *sym_strtab;
34527 Elf_Sym *sh_symtab;
34528 struct section *sec_applies, *sec_symtab;
34529 - int j;
34530 + unsigned int j;
34531 struct section *sec = &secs[i];
34532
34533 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34534 @@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34535 {
34536 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34537 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34538 + char *sym_strtab = sec->link->link->strtab;
34539 +
34540 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34541 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34542 + return 0;
34543 +
34544 +#ifdef CONFIG_PAX_KERNEXEC
34545 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34546 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34547 + return 0;
34548 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34549 + return 0;
34550 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34551 + return 0;
34552 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34553 + return 0;
34554 +#endif
34555
34556 switch (r_type) {
34557 case R_386_NONE:
34558 @@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34559
34560 static void emit_relocs(int as_text, int use_real_mode)
34561 {
34562 - int i;
34563 + unsigned int i;
34564 int (*write_reloc)(uint32_t, FILE *) = write32;
34565 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34566 const char *symname);
34567 @@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34568 {
34569 regex_init(use_real_mode);
34570 read_ehdr(fp);
34571 + read_phdrs(fp);
34572 read_shdrs(fp);
34573 read_strtabs(fp);
34574 read_symtabs(fp);
34575 - read_relocs(fp);
34576 + read_relocs(fp, use_real_mode);
34577 if (ELF_BITS == 64)
34578 percpu_init();
34579 if (show_absolute_syms) {
34580 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34581 index 80ffa5b..a33bd15 100644
34582 --- a/arch/x86/um/tls_32.c
34583 +++ b/arch/x86/um/tls_32.c
34584 @@ -260,7 +260,7 @@ out:
34585 if (unlikely(task == current &&
34586 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34587 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34588 - "without flushed TLS.", current->pid);
34589 + "without flushed TLS.", task_pid_nr(current));
34590 }
34591
34592 return 0;
34593 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34594 index fd14be1..e3c79c0 100644
34595 --- a/arch/x86/vdso/Makefile
34596 +++ b/arch/x86/vdso/Makefile
34597 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34598 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34599 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34600
34601 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34602 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34603 GCOV_PROFILE := n
34604
34605 #
34606 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34607 index d6bfb87..876ee18 100644
34608 --- a/arch/x86/vdso/vdso32-setup.c
34609 +++ b/arch/x86/vdso/vdso32-setup.c
34610 @@ -25,6 +25,7 @@
34611 #include <asm/tlbflush.h>
34612 #include <asm/vdso.h>
34613 #include <asm/proto.h>
34614 +#include <asm/mman.h>
34615
34616 enum {
34617 VDSO_DISABLED = 0,
34618 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34619 void enable_sep_cpu(void)
34620 {
34621 int cpu = get_cpu();
34622 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
34623 + struct tss_struct *tss = init_tss + cpu;
34624
34625 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34626 put_cpu();
34627 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34628 gate_vma.vm_start = FIXADDR_USER_START;
34629 gate_vma.vm_end = FIXADDR_USER_END;
34630 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34631 - gate_vma.vm_page_prot = __P101;
34632 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34633
34634 return 0;
34635 }
34636 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34637 if (compat)
34638 addr = VDSO_HIGH_BASE;
34639 else {
34640 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34641 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34642 if (IS_ERR_VALUE(addr)) {
34643 ret = addr;
34644 goto up_fail;
34645 }
34646 }
34647
34648 - current->mm->context.vdso = (void *)addr;
34649 + current->mm->context.vdso = addr;
34650
34651 if (compat_uses_vma || !compat) {
34652 /*
34653 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34654 }
34655
34656 current_thread_info()->sysenter_return =
34657 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34658 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34659
34660 up_fail:
34661 if (ret)
34662 - current->mm->context.vdso = NULL;
34663 + current->mm->context.vdso = 0;
34664
34665 up_write(&mm->mmap_sem);
34666
34667 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34668
34669 const char *arch_vma_name(struct vm_area_struct *vma)
34670 {
34671 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34672 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34673 return "[vdso]";
34674 +
34675 +#ifdef CONFIG_PAX_SEGMEXEC
34676 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34677 + return "[vdso]";
34678 +#endif
34679 +
34680 return NULL;
34681 }
34682
34683 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34684 * Check to see if the corresponding task was created in compat vdso
34685 * mode.
34686 */
34687 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34688 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34689 return &gate_vma;
34690 return NULL;
34691 }
34692 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34693 index 431e875..cbb23f3 100644
34694 --- a/arch/x86/vdso/vma.c
34695 +++ b/arch/x86/vdso/vma.c
34696 @@ -16,8 +16,6 @@
34697 #include <asm/vdso.h>
34698 #include <asm/page.h>
34699
34700 -unsigned int __read_mostly vdso_enabled = 1;
34701 -
34702 extern char vdso_start[], vdso_end[];
34703 extern unsigned short vdso_sync_cpuid;
34704
34705 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34706 * unaligned here as a result of stack start randomization.
34707 */
34708 addr = PAGE_ALIGN(addr);
34709 - addr = align_vdso_addr(addr);
34710
34711 return addr;
34712 }
34713 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34714 unsigned size)
34715 {
34716 struct mm_struct *mm = current->mm;
34717 - unsigned long addr;
34718 + unsigned long addr = 0;
34719 int ret;
34720
34721 - if (!vdso_enabled)
34722 - return 0;
34723 -
34724 down_write(&mm->mmap_sem);
34725 +
34726 +#ifdef CONFIG_PAX_RANDMMAP
34727 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34728 +#endif
34729 +
34730 addr = vdso_addr(mm->start_stack, size);
34731 + addr = align_vdso_addr(addr);
34732 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34733 if (IS_ERR_VALUE(addr)) {
34734 ret = addr;
34735 goto up_fail;
34736 }
34737
34738 - current->mm->context.vdso = (void *)addr;
34739 + mm->context.vdso = addr;
34740
34741 ret = install_special_mapping(mm, addr, size,
34742 VM_READ|VM_EXEC|
34743 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34744 pages);
34745 - if (ret) {
34746 - current->mm->context.vdso = NULL;
34747 - goto up_fail;
34748 - }
34749 + if (ret)
34750 + mm->context.vdso = 0;
34751
34752 up_fail:
34753 up_write(&mm->mmap_sem);
34754 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34755 vdsox32_size);
34756 }
34757 #endif
34758 -
34759 -static __init int vdso_setup(char *s)
34760 -{
34761 - vdso_enabled = simple_strtoul(s, NULL, 0);
34762 - return 0;
34763 -}
34764 -__setup("vdso=", vdso_setup);
34765 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34766 index fa6ade7..73da73a5 100644
34767 --- a/arch/x86/xen/enlighten.c
34768 +++ b/arch/x86/xen/enlighten.c
34769 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34770
34771 struct shared_info xen_dummy_shared_info;
34772
34773 -void *xen_initial_gdt;
34774 -
34775 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34776 __read_mostly int xen_have_vector_callback;
34777 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34778 @@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34779 {
34780 unsigned long va = dtr->address;
34781 unsigned int size = dtr->size + 1;
34782 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34783 - unsigned long frames[pages];
34784 + unsigned long frames[65536 / PAGE_SIZE];
34785 int f;
34786
34787 /*
34788 @@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34789 {
34790 unsigned long va = dtr->address;
34791 unsigned int size = dtr->size + 1;
34792 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34793 - unsigned long frames[pages];
34794 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34795 int f;
34796
34797 /*
34798 @@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34799 * 8-byte entries, or 16 4k pages..
34800 */
34801
34802 - BUG_ON(size > 65536);
34803 + BUG_ON(size > GDT_SIZE);
34804 BUG_ON(va & ~PAGE_MASK);
34805
34806 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34807 @@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34808 return 0;
34809 }
34810
34811 -static void set_xen_basic_apic_ops(void)
34812 +static void __init set_xen_basic_apic_ops(void)
34813 {
34814 apic->read = xen_apic_read;
34815 apic->write = xen_apic_write;
34816 @@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34817 #endif
34818 };
34819
34820 -static void xen_reboot(int reason)
34821 +static __noreturn void xen_reboot(int reason)
34822 {
34823 struct sched_shutdown r = { .reason = reason };
34824
34825 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34826 - BUG();
34827 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34828 + BUG();
34829 }
34830
34831 -static void xen_restart(char *msg)
34832 +static __noreturn void xen_restart(char *msg)
34833 {
34834 xen_reboot(SHUTDOWN_reboot);
34835 }
34836
34837 -static void xen_emergency_restart(void)
34838 +static __noreturn void xen_emergency_restart(void)
34839 {
34840 xen_reboot(SHUTDOWN_reboot);
34841 }
34842
34843 -static void xen_machine_halt(void)
34844 +static __noreturn void xen_machine_halt(void)
34845 {
34846 xen_reboot(SHUTDOWN_poweroff);
34847 }
34848
34849 -static void xen_machine_power_off(void)
34850 +static __noreturn void xen_machine_power_off(void)
34851 {
34852 if (pm_power_off)
34853 pm_power_off();
34854 @@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34855 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34856
34857 /* Work out if we support NX */
34858 - x86_configure_nx();
34859 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34860 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34861 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34862 + unsigned l, h;
34863 +
34864 + __supported_pte_mask |= _PAGE_NX;
34865 + rdmsr(MSR_EFER, l, h);
34866 + l |= EFER_NX;
34867 + wrmsr(MSR_EFER, l, h);
34868 + }
34869 +#endif
34870
34871 xen_setup_features();
34872
34873 @@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34874
34875 machine_ops = xen_machine_ops;
34876
34877 - /*
34878 - * The only reliable way to retain the initial address of the
34879 - * percpu gdt_page is to remember it here, so we can go and
34880 - * mark it RW later, when the initial percpu area is freed.
34881 - */
34882 - xen_initial_gdt = &per_cpu(gdt_page, 0);
34883 -
34884 xen_smp_init();
34885
34886 #ifdef CONFIG_ACPI_NUMA
34887 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34888 index ce563be..7327d91 100644
34889 --- a/arch/x86/xen/mmu.c
34890 +++ b/arch/x86/xen/mmu.c
34891 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34892 return val;
34893 }
34894
34895 -static pteval_t pte_pfn_to_mfn(pteval_t val)
34896 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34897 {
34898 if (val & _PAGE_PRESENT) {
34899 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34900 @@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34901 /* L3_k[510] -> level2_kernel_pgt
34902 * L3_i[511] -> level2_fixmap_pgt */
34903 convert_pfn_mfn(level3_kernel_pgt);
34904 + convert_pfn_mfn(level3_vmalloc_start_pgt);
34905 + convert_pfn_mfn(level3_vmalloc_end_pgt);
34906 + convert_pfn_mfn(level3_vmemmap_pgt);
34907
34908 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34909 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34910 @@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34911 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34912 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34913 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34914 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34915 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34916 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34917 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34918 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34919 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34920 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34921 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34922
34923 @@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34924 pv_mmu_ops.set_pud = xen_set_pud;
34925 #if PAGETABLE_LEVELS == 4
34926 pv_mmu_ops.set_pgd = xen_set_pgd;
34927 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34928 #endif
34929
34930 /* This will work as long as patching hasn't happened yet
34931 @@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34932 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34933 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34934 .set_pgd = xen_set_pgd_hyper,
34935 + .set_pgd_batched = xen_set_pgd_hyper,
34936
34937 .alloc_pud = xen_alloc_pmd_init,
34938 .release_pud = xen_release_pmd_init,
34939 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34940 index c36b325..b0f1518 100644
34941 --- a/arch/x86/xen/smp.c
34942 +++ b/arch/x86/xen/smp.c
34943 @@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34944 native_smp_prepare_boot_cpu();
34945
34946 if (xen_pv_domain()) {
34947 - /* We've switched to the "real" per-cpu gdt, so make sure the
34948 - old memory can be recycled */
34949 - make_lowmem_page_readwrite(xen_initial_gdt);
34950 -
34951 #ifdef CONFIG_X86_32
34952 /*
34953 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34954 * expects __USER_DS
34955 */
34956 - loadsegment(ds, __USER_DS);
34957 - loadsegment(es, __USER_DS);
34958 + loadsegment(ds, __KERNEL_DS);
34959 + loadsegment(es, __KERNEL_DS);
34960 #endif
34961
34962 xen_filter_cpu_maps();
34963 @@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34964 ctxt->user_regs.ss = __KERNEL_DS;
34965 #ifdef CONFIG_X86_32
34966 ctxt->user_regs.fs = __KERNEL_PERCPU;
34967 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34968 + savesegment(gs, ctxt->user_regs.gs);
34969 #else
34970 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34971 #endif
34972 @@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34973
34974 {
34975 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34976 - ctxt->user_regs.ds = __USER_DS;
34977 - ctxt->user_regs.es = __USER_DS;
34978 + ctxt->user_regs.ds = __KERNEL_DS;
34979 + ctxt->user_regs.es = __KERNEL_DS;
34980
34981 xen_copy_trap_info(ctxt->trap_ctxt);
34982
34983 @@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34984 int rc;
34985
34986 per_cpu(current_task, cpu) = idle;
34987 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
34988 #ifdef CONFIG_X86_32
34989 irq_ctx_init(cpu);
34990 #else
34991 clear_tsk_thread_flag(idle, TIF_FORK);
34992 - per_cpu(kernel_stack, cpu) =
34993 - (unsigned long)task_stack_page(idle) -
34994 - KERNEL_STACK_OFFSET + THREAD_SIZE;
34995 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34996 #endif
34997 xen_setup_runstate_info(cpu);
34998 xen_setup_timer(cpu);
34999 @@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35000
35001 void __init xen_smp_init(void)
35002 {
35003 - smp_ops = xen_smp_ops;
35004 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35005 xen_fill_possible_map();
35006 }
35007
35008 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35009 index 33ca6e4..0ded929 100644
35010 --- a/arch/x86/xen/xen-asm_32.S
35011 +++ b/arch/x86/xen/xen-asm_32.S
35012 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
35013 ESP_OFFSET=4 # bytes pushed onto stack
35014
35015 /*
35016 - * Store vcpu_info pointer for easy access. Do it this way to
35017 - * avoid having to reload %fs
35018 + * Store vcpu_info pointer for easy access.
35019 */
35020 #ifdef CONFIG_SMP
35021 - GET_THREAD_INFO(%eax)
35022 - movl %ss:TI_cpu(%eax), %eax
35023 - movl %ss:__per_cpu_offset(,%eax,4), %eax
35024 - mov %ss:xen_vcpu(%eax), %eax
35025 + push %fs
35026 + mov $(__KERNEL_PERCPU), %eax
35027 + mov %eax, %fs
35028 + mov PER_CPU_VAR(xen_vcpu), %eax
35029 + pop %fs
35030 #else
35031 movl %ss:xen_vcpu, %eax
35032 #endif
35033 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35034 index 7faed58..ba4427c 100644
35035 --- a/arch/x86/xen/xen-head.S
35036 +++ b/arch/x86/xen/xen-head.S
35037 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
35038 #ifdef CONFIG_X86_32
35039 mov %esi,xen_start_info
35040 mov $init_thread_union+THREAD_SIZE,%esp
35041 +#ifdef CONFIG_SMP
35042 + movl $cpu_gdt_table,%edi
35043 + movl $__per_cpu_load,%eax
35044 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35045 + rorl $16,%eax
35046 + movb %al,__KERNEL_PERCPU + 4(%edi)
35047 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35048 + movl $__per_cpu_end - 1,%eax
35049 + subl $__per_cpu_start,%eax
35050 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35051 +#endif
35052 #else
35053 mov %rsi,xen_start_info
35054 mov $init_thread_union+THREAD_SIZE,%rsp
35055 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35056 index 95f8c61..611d6e8 100644
35057 --- a/arch/x86/xen/xen-ops.h
35058 +++ b/arch/x86/xen/xen-ops.h
35059 @@ -10,8 +10,6 @@
35060 extern const char xen_hypervisor_callback[];
35061 extern const char xen_failsafe_callback[];
35062
35063 -extern void *xen_initial_gdt;
35064 -
35065 struct trap_info;
35066 void xen_copy_trap_info(struct trap_info *traps);
35067
35068 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35069 index 525bd3d..ef888b1 100644
35070 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35071 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35072 @@ -119,9 +119,9 @@
35073 ----------------------------------------------------------------------*/
35074
35075 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35076 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35077 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35078 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35079 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35080
35081 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35082 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35083 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35084 index 2f33760..835e50a 100644
35085 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35086 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35087 @@ -11,6 +11,7 @@
35088 #ifndef _XTENSA_CORE_H
35089 #define _XTENSA_CORE_H
35090
35091 +#include <linux/const.h>
35092
35093 /****************************************************************************
35094 Parameters Useful for Any Code, USER or PRIVILEGED
35095 @@ -112,9 +113,9 @@
35096 ----------------------------------------------------------------------*/
35097
35098 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35099 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35100 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35101 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35102 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35103
35104 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35105 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35106 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35107 index af00795..2bb8105 100644
35108 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35109 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35110 @@ -11,6 +11,7 @@
35111 #ifndef _XTENSA_CORE_CONFIGURATION_H
35112 #define _XTENSA_CORE_CONFIGURATION_H
35113
35114 +#include <linux/const.h>
35115
35116 /****************************************************************************
35117 Parameters Useful for Any Code, USER or PRIVILEGED
35118 @@ -118,9 +119,9 @@
35119 ----------------------------------------------------------------------*/
35120
35121 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35122 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35123 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35124 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35125 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35126
35127 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35128 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35129 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35130 index 4e491d9..c8e18e4 100644
35131 --- a/block/blk-cgroup.c
35132 +++ b/block/blk-cgroup.c
35133 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35134 static struct cgroup_subsys_state *
35135 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35136 {
35137 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35138 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35139 struct blkcg *blkcg;
35140
35141 if (!parent_css) {
35142 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35143
35144 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35145 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35146 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35147 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35148 done:
35149 spin_lock_init(&blkcg->lock);
35150 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35151 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35152 index 1855bf5..af12b06 100644
35153 --- a/block/blk-iopoll.c
35154 +++ b/block/blk-iopoll.c
35155 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35156 }
35157 EXPORT_SYMBOL(blk_iopoll_complete);
35158
35159 -static void blk_iopoll_softirq(struct softirq_action *h)
35160 +static __latent_entropy void blk_iopoll_softirq(void)
35161 {
35162 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35163 int rearm = 0, budget = blk_iopoll_budget;
35164 diff --git a/block/blk-map.c b/block/blk-map.c
35165 index 623e1cd..ca1e109 100644
35166 --- a/block/blk-map.c
35167 +++ b/block/blk-map.c
35168 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35169 if (!len || !kbuf)
35170 return -EINVAL;
35171
35172 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35173 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35174 if (do_copy)
35175 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35176 else
35177 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35178 index 57790c1..5e988dd 100644
35179 --- a/block/blk-softirq.c
35180 +++ b/block/blk-softirq.c
35181 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35182 * Softirq action handler - move entries to local list and loop over them
35183 * while passing them to the queue registered handler.
35184 */
35185 -static void blk_done_softirq(struct softirq_action *h)
35186 +static __latent_entropy void blk_done_softirq(void)
35187 {
35188 struct list_head *cpu_list, local_list;
35189
35190 diff --git a/block/bsg.c b/block/bsg.c
35191 index 420a5a9..23834aa 100644
35192 --- a/block/bsg.c
35193 +++ b/block/bsg.c
35194 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35195 struct sg_io_v4 *hdr, struct bsg_device *bd,
35196 fmode_t has_write_perm)
35197 {
35198 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35199 + unsigned char *cmdptr;
35200 +
35201 if (hdr->request_len > BLK_MAX_CDB) {
35202 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35203 if (!rq->cmd)
35204 return -ENOMEM;
35205 - }
35206 + cmdptr = rq->cmd;
35207 + } else
35208 + cmdptr = tmpcmd;
35209
35210 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35211 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35212 hdr->request_len))
35213 return -EFAULT;
35214
35215 + if (cmdptr != rq->cmd)
35216 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35217 +
35218 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35219 if (blk_verify_command(rq->cmd, has_write_perm))
35220 return -EPERM;
35221 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35222 index fbd5a67..f24fd95 100644
35223 --- a/block/compat_ioctl.c
35224 +++ b/block/compat_ioctl.c
35225 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35226 cgc = compat_alloc_user_space(sizeof(*cgc));
35227 cgc32 = compat_ptr(arg);
35228
35229 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35230 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35231 get_user(data, &cgc32->buffer) ||
35232 put_user(compat_ptr(data), &cgc->buffer) ||
35233 copy_in_user(&cgc->buflen, &cgc32->buflen,
35234 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35235 err |= __get_user(f->spec1, &uf->spec1);
35236 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35237 err |= __get_user(name, &uf->name);
35238 - f->name = compat_ptr(name);
35239 + f->name = (void __force_kernel *)compat_ptr(name);
35240 if (err) {
35241 err = -EFAULT;
35242 goto out;
35243 diff --git a/block/genhd.c b/block/genhd.c
35244 index 791f419..89f21c4 100644
35245 --- a/block/genhd.c
35246 +++ b/block/genhd.c
35247 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35248
35249 /*
35250 * Register device numbers dev..(dev+range-1)
35251 - * range must be nonzero
35252 + * Noop if @range is zero.
35253 * The hash chain is sorted on range, so that subranges can override.
35254 */
35255 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35256 struct kobject *(*probe)(dev_t, int *, void *),
35257 int (*lock)(dev_t, void *), void *data)
35258 {
35259 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35260 + if (range)
35261 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35262 }
35263
35264 EXPORT_SYMBOL(blk_register_region);
35265
35266 +/* undo blk_register_region(), noop if @range is zero */
35267 void blk_unregister_region(dev_t devt, unsigned long range)
35268 {
35269 - kobj_unmap(bdev_map, devt, range);
35270 + if (range)
35271 + kobj_unmap(bdev_map, devt, range);
35272 }
35273
35274 EXPORT_SYMBOL(blk_unregister_region);
35275 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35276 index dc51f46..d5446a8 100644
35277 --- a/block/partitions/efi.c
35278 +++ b/block/partitions/efi.c
35279 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35280 if (!gpt)
35281 return NULL;
35282
35283 + if (!le32_to_cpu(gpt->num_partition_entries))
35284 + return NULL;
35285 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35286 + if (!pte)
35287 + return NULL;
35288 +
35289 count = le32_to_cpu(gpt->num_partition_entries) *
35290 le32_to_cpu(gpt->sizeof_partition_entry);
35291 - if (!count)
35292 - return NULL;
35293 - pte = kmalloc(count, GFP_KERNEL);
35294 - if (!pte)
35295 - return NULL;
35296 -
35297 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35298 (u8 *) pte, count) < count) {
35299 kfree(pte);
35300 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35301 index 625e3e4..b5339f9 100644
35302 --- a/block/scsi_ioctl.c
35303 +++ b/block/scsi_ioctl.c
35304 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35305 return put_user(0, p);
35306 }
35307
35308 -static int sg_get_timeout(struct request_queue *q)
35309 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35310 {
35311 return jiffies_to_clock_t(q->sg_timeout);
35312 }
35313 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35314 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35315 struct sg_io_hdr *hdr, fmode_t mode)
35316 {
35317 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35318 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35319 + unsigned char *cmdptr;
35320 +
35321 + if (rq->cmd != rq->__cmd)
35322 + cmdptr = rq->cmd;
35323 + else
35324 + cmdptr = tmpcmd;
35325 +
35326 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35327 return -EFAULT;
35328 +
35329 + if (cmdptr != rq->cmd)
35330 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35331 +
35332 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35333 return -EPERM;
35334
35335 @@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35336 int err;
35337 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35338 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35339 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35340 + unsigned char *cmdptr;
35341
35342 if (!sic)
35343 return -EINVAL;
35344 @@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35345 */
35346 err = -EFAULT;
35347 rq->cmd_len = cmdlen;
35348 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35349 +
35350 + if (rq->cmd != rq->__cmd)
35351 + cmdptr = rq->cmd;
35352 + else
35353 + cmdptr = tmpcmd;
35354 +
35355 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35356 goto error;
35357
35358 + if (rq->cmd != cmdptr)
35359 + memcpy(rq->cmd, cmdptr, cmdlen);
35360 +
35361 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35362 goto error;
35363
35364 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35365 index 7bdd61b..afec999 100644
35366 --- a/crypto/cryptd.c
35367 +++ b/crypto/cryptd.c
35368 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35369
35370 struct cryptd_blkcipher_request_ctx {
35371 crypto_completion_t complete;
35372 -};
35373 +} __no_const;
35374
35375 struct cryptd_hash_ctx {
35376 struct crypto_shash *child;
35377 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35378
35379 struct cryptd_aead_request_ctx {
35380 crypto_completion_t complete;
35381 -};
35382 +} __no_const;
35383
35384 static void cryptd_queue_worker(struct work_struct *work);
35385
35386 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35387 index f8c920c..ab2cb5a 100644
35388 --- a/crypto/pcrypt.c
35389 +++ b/crypto/pcrypt.c
35390 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35391 int ret;
35392
35393 pinst->kobj.kset = pcrypt_kset;
35394 - ret = kobject_add(&pinst->kobj, NULL, name);
35395 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35396 if (!ret)
35397 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35398
35399 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35400 index 15dddc1..b61cf0c 100644
35401 --- a/drivers/acpi/acpica/hwxfsleep.c
35402 +++ b/drivers/acpi/acpica/hwxfsleep.c
35403 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35404 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35405
35406 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35407 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35408 - acpi_hw_extended_sleep},
35409 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35410 - acpi_hw_extended_wake_prep},
35411 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35412 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35413 + .extended_function = acpi_hw_extended_sleep},
35414 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35415 + .extended_function = acpi_hw_extended_wake_prep},
35416 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35417 + .extended_function = acpi_hw_extended_wake}
35418 };
35419
35420 /*
35421 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35422 index 21ba34a..cb05966 100644
35423 --- a/drivers/acpi/apei/apei-internal.h
35424 +++ b/drivers/acpi/apei/apei-internal.h
35425 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35426 struct apei_exec_ins_type {
35427 u32 flags;
35428 apei_exec_ins_func_t run;
35429 -};
35430 +} __do_const;
35431
35432 struct apei_exec_context {
35433 u32 ip;
35434 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35435 index a30bc31..b91c4d5 100644
35436 --- a/drivers/acpi/apei/ghes.c
35437 +++ b/drivers/acpi/apei/ghes.c
35438 @@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35439 const struct acpi_hest_generic *generic,
35440 const struct acpi_generic_status *estatus)
35441 {
35442 - static atomic_t seqno;
35443 + static atomic_unchecked_t seqno;
35444 unsigned int curr_seqno;
35445 char pfx_seq[64];
35446
35447 @@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35448 else
35449 pfx = KERN_ERR;
35450 }
35451 - curr_seqno = atomic_inc_return(&seqno);
35452 + curr_seqno = atomic_inc_return_unchecked(&seqno);
35453 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35454 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35455 pfx_seq, generic->header.source_id);
35456 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35457 index a83e3c6..c3d617f 100644
35458 --- a/drivers/acpi/bgrt.c
35459 +++ b/drivers/acpi/bgrt.c
35460 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35461 if (!bgrt_image)
35462 return -ENODEV;
35463
35464 - bin_attr_image.private = bgrt_image;
35465 - bin_attr_image.size = bgrt_image_size;
35466 + pax_open_kernel();
35467 + *(void **)&bin_attr_image.private = bgrt_image;
35468 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
35469 + pax_close_kernel();
35470
35471 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35472 if (!bgrt_kobj)
35473 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35474 index 078c4f7..410e272 100644
35475 --- a/drivers/acpi/blacklist.c
35476 +++ b/drivers/acpi/blacklist.c
35477 @@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35478 u32 is_critical_error;
35479 };
35480
35481 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35482 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35483
35484 /*
35485 * POLICY: If *anything* doesn't work, put it on the blacklist.
35486 @@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35487 return 0;
35488 }
35489
35490 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35491 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35492 {
35493 .callback = dmi_disable_osi_vista,
35494 .ident = "Fujitsu Siemens",
35495 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
35496 index 12b62f2..dc2aac8 100644
35497 --- a/drivers/acpi/custom_method.c
35498 +++ b/drivers/acpi/custom_method.c
35499 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
35500 struct acpi_table_header table;
35501 acpi_status status;
35502
35503 +#ifdef CONFIG_GRKERNSEC_KMEM
35504 + return -EPERM;
35505 +#endif
35506 +
35507 if (!(*ppos)) {
35508 /* parse the table header to get the table length */
35509 if (count <= sizeof(struct acpi_table_header))
35510 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35511 index 644516d..643937e 100644
35512 --- a/drivers/acpi/processor_idle.c
35513 +++ b/drivers/acpi/processor_idle.c
35514 @@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35515 {
35516 int i, count = CPUIDLE_DRIVER_STATE_START;
35517 struct acpi_processor_cx *cx;
35518 - struct cpuidle_state *state;
35519 + cpuidle_state_no_const *state;
35520 struct cpuidle_driver *drv = &acpi_idle_driver;
35521
35522 if (!pr->flags.power_setup_done)
35523 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35524 index 6dbc3ca..b8b59a0 100644
35525 --- a/drivers/acpi/sysfs.c
35526 +++ b/drivers/acpi/sysfs.c
35527 @@ -425,11 +425,11 @@ static u32 num_counters;
35528 static struct attribute **all_attrs;
35529 static u32 acpi_gpe_count;
35530
35531 -static struct attribute_group interrupt_stats_attr_group = {
35532 +static attribute_group_no_const interrupt_stats_attr_group = {
35533 .name = "interrupts",
35534 };
35535
35536 -static struct kobj_attribute *counter_attrs;
35537 +static kobj_attribute_no_const *counter_attrs;
35538
35539 static void delete_gpe_attr_array(void)
35540 {
35541 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35542 index c482f8c..c832240 100644
35543 --- a/drivers/ata/libahci.c
35544 +++ b/drivers/ata/libahci.c
35545 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
35546 }
35547 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35548
35549 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35550 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35551 struct ata_taskfile *tf, int is_cmd, u16 flags,
35552 unsigned long timeout_msec)
35553 {
35554 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35555 index 1a3dbd1..dfc6e5c 100644
35556 --- a/drivers/ata/libata-core.c
35557 +++ b/drivers/ata/libata-core.c
35558 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35559 static void ata_dev_xfermask(struct ata_device *dev);
35560 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35561
35562 -atomic_t ata_print_id = ATOMIC_INIT(0);
35563 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35564
35565 struct ata_force_param {
35566 const char *name;
35567 @@ -4850,7 +4850,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35568 struct ata_port *ap;
35569 unsigned int tag;
35570
35571 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35572 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35573 ap = qc->ap;
35574
35575 qc->flags = 0;
35576 @@ -4866,7 +4866,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35577 struct ata_port *ap;
35578 struct ata_link *link;
35579
35580 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35581 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35582 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35583 ap = qc->ap;
35584 link = qc->dev->link;
35585 @@ -5985,6 +5985,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35586 return;
35587
35588 spin_lock(&lock);
35589 + pax_open_kernel();
35590
35591 for (cur = ops->inherits; cur; cur = cur->inherits) {
35592 void **inherit = (void **)cur;
35593 @@ -5998,8 +5999,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35594 if (IS_ERR(*pp))
35595 *pp = NULL;
35596
35597 - ops->inherits = NULL;
35598 + *(struct ata_port_operations **)&ops->inherits = NULL;
35599
35600 + pax_close_kernel();
35601 spin_unlock(&lock);
35602 }
35603
35604 @@ -6192,7 +6194,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35605
35606 /* give ports names and add SCSI hosts */
35607 for (i = 0; i < host->n_ports; i++) {
35608 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35609 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35610 host->ports[i]->local_port_no = i + 1;
35611 }
35612
35613 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35614 index ef8567d..8bdbd03 100644
35615 --- a/drivers/ata/libata-scsi.c
35616 +++ b/drivers/ata/libata-scsi.c
35617 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
35618
35619 if (rc)
35620 return rc;
35621 - ap->print_id = atomic_inc_return(&ata_print_id);
35622 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35623 return 0;
35624 }
35625 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35626 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35627 index 45b5ab3..98446b8 100644
35628 --- a/drivers/ata/libata.h
35629 +++ b/drivers/ata/libata.h
35630 @@ -53,7 +53,7 @@ enum {
35631 ATA_DNXFER_QUIET = (1 << 31),
35632 };
35633
35634 -extern atomic_t ata_print_id;
35635 +extern atomic_unchecked_t ata_print_id;
35636 extern int atapi_passthru16;
35637 extern int libata_fua;
35638 extern int libata_noacpi;
35639 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35640 index 73492dd..ca2bff5 100644
35641 --- a/drivers/ata/pata_arasan_cf.c
35642 +++ b/drivers/ata/pata_arasan_cf.c
35643 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35644 /* Handle platform specific quirks */
35645 if (quirk) {
35646 if (quirk & CF_BROKEN_PIO) {
35647 - ap->ops->set_piomode = NULL;
35648 + pax_open_kernel();
35649 + *(void **)&ap->ops->set_piomode = NULL;
35650 + pax_close_kernel();
35651 ap->pio_mask = 0;
35652 }
35653 if (quirk & CF_BROKEN_MWDMA)
35654 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35655 index f9b983a..887b9d8 100644
35656 --- a/drivers/atm/adummy.c
35657 +++ b/drivers/atm/adummy.c
35658 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35659 vcc->pop(vcc, skb);
35660 else
35661 dev_kfree_skb_any(skb);
35662 - atomic_inc(&vcc->stats->tx);
35663 + atomic_inc_unchecked(&vcc->stats->tx);
35664
35665 return 0;
35666 }
35667 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35668 index 62a7607..cc4be104 100644
35669 --- a/drivers/atm/ambassador.c
35670 +++ b/drivers/atm/ambassador.c
35671 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35672 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35673
35674 // VC layer stats
35675 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35676 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35677
35678 // free the descriptor
35679 kfree (tx_descr);
35680 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35681 dump_skb ("<<<", vc, skb);
35682
35683 // VC layer stats
35684 - atomic_inc(&atm_vcc->stats->rx);
35685 + atomic_inc_unchecked(&atm_vcc->stats->rx);
35686 __net_timestamp(skb);
35687 // end of our responsibility
35688 atm_vcc->push (atm_vcc, skb);
35689 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35690 } else {
35691 PRINTK (KERN_INFO, "dropped over-size frame");
35692 // should we count this?
35693 - atomic_inc(&atm_vcc->stats->rx_drop);
35694 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35695 }
35696
35697 } else {
35698 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35699 }
35700
35701 if (check_area (skb->data, skb->len)) {
35702 - atomic_inc(&atm_vcc->stats->tx_err);
35703 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35704 return -ENOMEM; // ?
35705 }
35706
35707 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35708 index 0e3f8f9..765a7a5 100644
35709 --- a/drivers/atm/atmtcp.c
35710 +++ b/drivers/atm/atmtcp.c
35711 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35712 if (vcc->pop) vcc->pop(vcc,skb);
35713 else dev_kfree_skb(skb);
35714 if (dev_data) return 0;
35715 - atomic_inc(&vcc->stats->tx_err);
35716 + atomic_inc_unchecked(&vcc->stats->tx_err);
35717 return -ENOLINK;
35718 }
35719 size = skb->len+sizeof(struct atmtcp_hdr);
35720 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35721 if (!new_skb) {
35722 if (vcc->pop) vcc->pop(vcc,skb);
35723 else dev_kfree_skb(skb);
35724 - atomic_inc(&vcc->stats->tx_err);
35725 + atomic_inc_unchecked(&vcc->stats->tx_err);
35726 return -ENOBUFS;
35727 }
35728 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35729 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35730 if (vcc->pop) vcc->pop(vcc,skb);
35731 else dev_kfree_skb(skb);
35732 out_vcc->push(out_vcc,new_skb);
35733 - atomic_inc(&vcc->stats->tx);
35734 - atomic_inc(&out_vcc->stats->rx);
35735 + atomic_inc_unchecked(&vcc->stats->tx);
35736 + atomic_inc_unchecked(&out_vcc->stats->rx);
35737 return 0;
35738 }
35739
35740 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35741 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35742 read_unlock(&vcc_sklist_lock);
35743 if (!out_vcc) {
35744 - atomic_inc(&vcc->stats->tx_err);
35745 + atomic_inc_unchecked(&vcc->stats->tx_err);
35746 goto done;
35747 }
35748 skb_pull(skb,sizeof(struct atmtcp_hdr));
35749 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35750 __net_timestamp(new_skb);
35751 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35752 out_vcc->push(out_vcc,new_skb);
35753 - atomic_inc(&vcc->stats->tx);
35754 - atomic_inc(&out_vcc->stats->rx);
35755 + atomic_inc_unchecked(&vcc->stats->tx);
35756 + atomic_inc_unchecked(&out_vcc->stats->rx);
35757 done:
35758 if (vcc->pop) vcc->pop(vcc,skb);
35759 else dev_kfree_skb(skb);
35760 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35761 index b1955ba..b179940 100644
35762 --- a/drivers/atm/eni.c
35763 +++ b/drivers/atm/eni.c
35764 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35765 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35766 vcc->dev->number);
35767 length = 0;
35768 - atomic_inc(&vcc->stats->rx_err);
35769 + atomic_inc_unchecked(&vcc->stats->rx_err);
35770 }
35771 else {
35772 length = ATM_CELL_SIZE-1; /* no HEC */
35773 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35774 size);
35775 }
35776 eff = length = 0;
35777 - atomic_inc(&vcc->stats->rx_err);
35778 + atomic_inc_unchecked(&vcc->stats->rx_err);
35779 }
35780 else {
35781 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35782 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35783 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35784 vcc->dev->number,vcc->vci,length,size << 2,descr);
35785 length = eff = 0;
35786 - atomic_inc(&vcc->stats->rx_err);
35787 + atomic_inc_unchecked(&vcc->stats->rx_err);
35788 }
35789 }
35790 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35791 @@ -767,7 +767,7 @@ rx_dequeued++;
35792 vcc->push(vcc,skb);
35793 pushed++;
35794 }
35795 - atomic_inc(&vcc->stats->rx);
35796 + atomic_inc_unchecked(&vcc->stats->rx);
35797 }
35798 wake_up(&eni_dev->rx_wait);
35799 }
35800 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35801 PCI_DMA_TODEVICE);
35802 if (vcc->pop) vcc->pop(vcc,skb);
35803 else dev_kfree_skb_irq(skb);
35804 - atomic_inc(&vcc->stats->tx);
35805 + atomic_inc_unchecked(&vcc->stats->tx);
35806 wake_up(&eni_dev->tx_wait);
35807 dma_complete++;
35808 }
35809 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35810 index b41c948..a002b17 100644
35811 --- a/drivers/atm/firestream.c
35812 +++ b/drivers/atm/firestream.c
35813 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35814 }
35815 }
35816
35817 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35818 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35819
35820 fs_dprintk (FS_DEBUG_TXMEM, "i");
35821 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35822 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35823 #endif
35824 skb_put (skb, qe->p1 & 0xffff);
35825 ATM_SKB(skb)->vcc = atm_vcc;
35826 - atomic_inc(&atm_vcc->stats->rx);
35827 + atomic_inc_unchecked(&atm_vcc->stats->rx);
35828 __net_timestamp(skb);
35829 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35830 atm_vcc->push (atm_vcc, skb);
35831 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35832 kfree (pe);
35833 }
35834 if (atm_vcc)
35835 - atomic_inc(&atm_vcc->stats->rx_drop);
35836 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35837 break;
35838 case 0x1f: /* Reassembly abort: no buffers. */
35839 /* Silently increment error counter. */
35840 if (atm_vcc)
35841 - atomic_inc(&atm_vcc->stats->rx_drop);
35842 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35843 break;
35844 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35845 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35846 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35847 index 204814e..cede831 100644
35848 --- a/drivers/atm/fore200e.c
35849 +++ b/drivers/atm/fore200e.c
35850 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35851 #endif
35852 /* check error condition */
35853 if (*entry->status & STATUS_ERROR)
35854 - atomic_inc(&vcc->stats->tx_err);
35855 + atomic_inc_unchecked(&vcc->stats->tx_err);
35856 else
35857 - atomic_inc(&vcc->stats->tx);
35858 + atomic_inc_unchecked(&vcc->stats->tx);
35859 }
35860 }
35861
35862 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35863 if (skb == NULL) {
35864 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35865
35866 - atomic_inc(&vcc->stats->rx_drop);
35867 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35868 return -ENOMEM;
35869 }
35870
35871 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35872
35873 dev_kfree_skb_any(skb);
35874
35875 - atomic_inc(&vcc->stats->rx_drop);
35876 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35877 return -ENOMEM;
35878 }
35879
35880 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35881
35882 vcc->push(vcc, skb);
35883 - atomic_inc(&vcc->stats->rx);
35884 + atomic_inc_unchecked(&vcc->stats->rx);
35885
35886 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35887
35888 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35889 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35890 fore200e->atm_dev->number,
35891 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35892 - atomic_inc(&vcc->stats->rx_err);
35893 + atomic_inc_unchecked(&vcc->stats->rx_err);
35894 }
35895 }
35896
35897 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35898 goto retry_here;
35899 }
35900
35901 - atomic_inc(&vcc->stats->tx_err);
35902 + atomic_inc_unchecked(&vcc->stats->tx_err);
35903
35904 fore200e->tx_sat++;
35905 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35906 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35907 index 8557adc..3fb5d55 100644
35908 --- a/drivers/atm/he.c
35909 +++ b/drivers/atm/he.c
35910 @@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35911
35912 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35913 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35914 - atomic_inc(&vcc->stats->rx_drop);
35915 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35916 goto return_host_buffers;
35917 }
35918
35919 @@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35920 RBRQ_LEN_ERR(he_dev->rbrq_head)
35921 ? "LEN_ERR" : "",
35922 vcc->vpi, vcc->vci);
35923 - atomic_inc(&vcc->stats->rx_err);
35924 + atomic_inc_unchecked(&vcc->stats->rx_err);
35925 goto return_host_buffers;
35926 }
35927
35928 @@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35929 vcc->push(vcc, skb);
35930 spin_lock(&he_dev->global_lock);
35931
35932 - atomic_inc(&vcc->stats->rx);
35933 + atomic_inc_unchecked(&vcc->stats->rx);
35934
35935 return_host_buffers:
35936 ++pdus_assembled;
35937 @@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35938 tpd->vcc->pop(tpd->vcc, tpd->skb);
35939 else
35940 dev_kfree_skb_any(tpd->skb);
35941 - atomic_inc(&tpd->vcc->stats->tx_err);
35942 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35943 }
35944 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35945 return;
35946 @@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35947 vcc->pop(vcc, skb);
35948 else
35949 dev_kfree_skb_any(skb);
35950 - atomic_inc(&vcc->stats->tx_err);
35951 + atomic_inc_unchecked(&vcc->stats->tx_err);
35952 return -EINVAL;
35953 }
35954
35955 @@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35956 vcc->pop(vcc, skb);
35957 else
35958 dev_kfree_skb_any(skb);
35959 - atomic_inc(&vcc->stats->tx_err);
35960 + atomic_inc_unchecked(&vcc->stats->tx_err);
35961 return -EINVAL;
35962 }
35963 #endif
35964 @@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35965 vcc->pop(vcc, skb);
35966 else
35967 dev_kfree_skb_any(skb);
35968 - atomic_inc(&vcc->stats->tx_err);
35969 + atomic_inc_unchecked(&vcc->stats->tx_err);
35970 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35971 return -ENOMEM;
35972 }
35973 @@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35974 vcc->pop(vcc, skb);
35975 else
35976 dev_kfree_skb_any(skb);
35977 - atomic_inc(&vcc->stats->tx_err);
35978 + atomic_inc_unchecked(&vcc->stats->tx_err);
35979 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35980 return -ENOMEM;
35981 }
35982 @@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35983 __enqueue_tpd(he_dev, tpd, cid);
35984 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35985
35986 - atomic_inc(&vcc->stats->tx);
35987 + atomic_inc_unchecked(&vcc->stats->tx);
35988
35989 return 0;
35990 }
35991 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35992 index 1dc0519..1aadaf7 100644
35993 --- a/drivers/atm/horizon.c
35994 +++ b/drivers/atm/horizon.c
35995 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35996 {
35997 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35998 // VC layer stats
35999 - atomic_inc(&vcc->stats->rx);
36000 + atomic_inc_unchecked(&vcc->stats->rx);
36001 __net_timestamp(skb);
36002 // end of our responsibility
36003 vcc->push (vcc, skb);
36004 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36005 dev->tx_iovec = NULL;
36006
36007 // VC layer stats
36008 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36009 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36010
36011 // free the skb
36012 hrz_kfree_skb (skb);
36013 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36014 index 1bdf104..9dc44b1 100644
36015 --- a/drivers/atm/idt77252.c
36016 +++ b/drivers/atm/idt77252.c
36017 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36018 else
36019 dev_kfree_skb(skb);
36020
36021 - atomic_inc(&vcc->stats->tx);
36022 + atomic_inc_unchecked(&vcc->stats->tx);
36023 }
36024
36025 atomic_dec(&scq->used);
36026 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36027 if ((sb = dev_alloc_skb(64)) == NULL) {
36028 printk("%s: Can't allocate buffers for aal0.\n",
36029 card->name);
36030 - atomic_add(i, &vcc->stats->rx_drop);
36031 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36032 break;
36033 }
36034 if (!atm_charge(vcc, sb->truesize)) {
36035 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36036 card->name);
36037 - atomic_add(i - 1, &vcc->stats->rx_drop);
36038 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36039 dev_kfree_skb(sb);
36040 break;
36041 }
36042 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36043 ATM_SKB(sb)->vcc = vcc;
36044 __net_timestamp(sb);
36045 vcc->push(vcc, sb);
36046 - atomic_inc(&vcc->stats->rx);
36047 + atomic_inc_unchecked(&vcc->stats->rx);
36048
36049 cell += ATM_CELL_PAYLOAD;
36050 }
36051 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36052 "(CDC: %08x)\n",
36053 card->name, len, rpp->len, readl(SAR_REG_CDC));
36054 recycle_rx_pool_skb(card, rpp);
36055 - atomic_inc(&vcc->stats->rx_err);
36056 + atomic_inc_unchecked(&vcc->stats->rx_err);
36057 return;
36058 }
36059 if (stat & SAR_RSQE_CRC) {
36060 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36061 recycle_rx_pool_skb(card, rpp);
36062 - atomic_inc(&vcc->stats->rx_err);
36063 + atomic_inc_unchecked(&vcc->stats->rx_err);
36064 return;
36065 }
36066 if (skb_queue_len(&rpp->queue) > 1) {
36067 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36068 RXPRINTK("%s: Can't alloc RX skb.\n",
36069 card->name);
36070 recycle_rx_pool_skb(card, rpp);
36071 - atomic_inc(&vcc->stats->rx_err);
36072 + atomic_inc_unchecked(&vcc->stats->rx_err);
36073 return;
36074 }
36075 if (!atm_charge(vcc, skb->truesize)) {
36076 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36077 __net_timestamp(skb);
36078
36079 vcc->push(vcc, skb);
36080 - atomic_inc(&vcc->stats->rx);
36081 + atomic_inc_unchecked(&vcc->stats->rx);
36082
36083 return;
36084 }
36085 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36086 __net_timestamp(skb);
36087
36088 vcc->push(vcc, skb);
36089 - atomic_inc(&vcc->stats->rx);
36090 + atomic_inc_unchecked(&vcc->stats->rx);
36091
36092 if (skb->truesize > SAR_FB_SIZE_3)
36093 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36094 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36095 if (vcc->qos.aal != ATM_AAL0) {
36096 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36097 card->name, vpi, vci);
36098 - atomic_inc(&vcc->stats->rx_drop);
36099 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36100 goto drop;
36101 }
36102
36103 if ((sb = dev_alloc_skb(64)) == NULL) {
36104 printk("%s: Can't allocate buffers for AAL0.\n",
36105 card->name);
36106 - atomic_inc(&vcc->stats->rx_err);
36107 + atomic_inc_unchecked(&vcc->stats->rx_err);
36108 goto drop;
36109 }
36110
36111 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36112 ATM_SKB(sb)->vcc = vcc;
36113 __net_timestamp(sb);
36114 vcc->push(vcc, sb);
36115 - atomic_inc(&vcc->stats->rx);
36116 + atomic_inc_unchecked(&vcc->stats->rx);
36117
36118 drop:
36119 skb_pull(queue, 64);
36120 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36121
36122 if (vc == NULL) {
36123 printk("%s: NULL connection in send().\n", card->name);
36124 - atomic_inc(&vcc->stats->tx_err);
36125 + atomic_inc_unchecked(&vcc->stats->tx_err);
36126 dev_kfree_skb(skb);
36127 return -EINVAL;
36128 }
36129 if (!test_bit(VCF_TX, &vc->flags)) {
36130 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36131 - atomic_inc(&vcc->stats->tx_err);
36132 + atomic_inc_unchecked(&vcc->stats->tx_err);
36133 dev_kfree_skb(skb);
36134 return -EINVAL;
36135 }
36136 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36137 break;
36138 default:
36139 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36140 - atomic_inc(&vcc->stats->tx_err);
36141 + atomic_inc_unchecked(&vcc->stats->tx_err);
36142 dev_kfree_skb(skb);
36143 return -EINVAL;
36144 }
36145
36146 if (skb_shinfo(skb)->nr_frags != 0) {
36147 printk("%s: No scatter-gather yet.\n", card->name);
36148 - atomic_inc(&vcc->stats->tx_err);
36149 + atomic_inc_unchecked(&vcc->stats->tx_err);
36150 dev_kfree_skb(skb);
36151 return -EINVAL;
36152 }
36153 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36154
36155 err = queue_skb(card, vc, skb, oam);
36156 if (err) {
36157 - atomic_inc(&vcc->stats->tx_err);
36158 + atomic_inc_unchecked(&vcc->stats->tx_err);
36159 dev_kfree_skb(skb);
36160 return err;
36161 }
36162 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36163 skb = dev_alloc_skb(64);
36164 if (!skb) {
36165 printk("%s: Out of memory in send_oam().\n", card->name);
36166 - atomic_inc(&vcc->stats->tx_err);
36167 + atomic_inc_unchecked(&vcc->stats->tx_err);
36168 return -ENOMEM;
36169 }
36170 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36171 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36172 index 4217f29..88f547a 100644
36173 --- a/drivers/atm/iphase.c
36174 +++ b/drivers/atm/iphase.c
36175 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36176 status = (u_short) (buf_desc_ptr->desc_mode);
36177 if (status & (RX_CER | RX_PTE | RX_OFL))
36178 {
36179 - atomic_inc(&vcc->stats->rx_err);
36180 + atomic_inc_unchecked(&vcc->stats->rx_err);
36181 IF_ERR(printk("IA: bad packet, dropping it");)
36182 if (status & RX_CER) {
36183 IF_ERR(printk(" cause: packet CRC error\n");)
36184 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36185 len = dma_addr - buf_addr;
36186 if (len > iadev->rx_buf_sz) {
36187 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36188 - atomic_inc(&vcc->stats->rx_err);
36189 + atomic_inc_unchecked(&vcc->stats->rx_err);
36190 goto out_free_desc;
36191 }
36192
36193 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36194 ia_vcc = INPH_IA_VCC(vcc);
36195 if (ia_vcc == NULL)
36196 {
36197 - atomic_inc(&vcc->stats->rx_err);
36198 + atomic_inc_unchecked(&vcc->stats->rx_err);
36199 atm_return(vcc, skb->truesize);
36200 dev_kfree_skb_any(skb);
36201 goto INCR_DLE;
36202 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36203 if ((length > iadev->rx_buf_sz) || (length >
36204 (skb->len - sizeof(struct cpcs_trailer))))
36205 {
36206 - atomic_inc(&vcc->stats->rx_err);
36207 + atomic_inc_unchecked(&vcc->stats->rx_err);
36208 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36209 length, skb->len);)
36210 atm_return(vcc, skb->truesize);
36211 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36212
36213 IF_RX(printk("rx_dle_intr: skb push");)
36214 vcc->push(vcc,skb);
36215 - atomic_inc(&vcc->stats->rx);
36216 + atomic_inc_unchecked(&vcc->stats->rx);
36217 iadev->rx_pkt_cnt++;
36218 }
36219 INCR_DLE:
36220 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36221 {
36222 struct k_sonet_stats *stats;
36223 stats = &PRIV(_ia_dev[board])->sonet_stats;
36224 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36225 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36226 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36227 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36228 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36229 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36230 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36231 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36232 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36233 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36234 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36235 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36236 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36237 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36238 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36239 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36240 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36241 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36242 }
36243 ia_cmds.status = 0;
36244 break;
36245 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36246 if ((desc == 0) || (desc > iadev->num_tx_desc))
36247 {
36248 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36249 - atomic_inc(&vcc->stats->tx);
36250 + atomic_inc_unchecked(&vcc->stats->tx);
36251 if (vcc->pop)
36252 vcc->pop(vcc, skb);
36253 else
36254 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36255 ATM_DESC(skb) = vcc->vci;
36256 skb_queue_tail(&iadev->tx_dma_q, skb);
36257
36258 - atomic_inc(&vcc->stats->tx);
36259 + atomic_inc_unchecked(&vcc->stats->tx);
36260 iadev->tx_pkt_cnt++;
36261 /* Increment transaction counter */
36262 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36263
36264 #if 0
36265 /* add flow control logic */
36266 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36267 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36268 if (iavcc->vc_desc_cnt > 10) {
36269 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36270 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36271 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36272 index fa7d701..1e404c7 100644
36273 --- a/drivers/atm/lanai.c
36274 +++ b/drivers/atm/lanai.c
36275 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36276 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36277 lanai_endtx(lanai, lvcc);
36278 lanai_free_skb(lvcc->tx.atmvcc, skb);
36279 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36280 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36281 }
36282
36283 /* Try to fill the buffer - don't call unless there is backlog */
36284 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36285 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36286 __net_timestamp(skb);
36287 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36288 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36289 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36290 out:
36291 lvcc->rx.buf.ptr = end;
36292 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36293 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36294 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36295 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36296 lanai->stats.service_rxnotaal5++;
36297 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36298 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36299 return 0;
36300 }
36301 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36302 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36303 int bytes;
36304 read_unlock(&vcc_sklist_lock);
36305 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36306 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36307 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36308 lvcc->stats.x.aal5.service_trash++;
36309 bytes = (SERVICE_GET_END(s) * 16) -
36310 (((unsigned long) lvcc->rx.buf.ptr) -
36311 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36312 }
36313 if (s & SERVICE_STREAM) {
36314 read_unlock(&vcc_sklist_lock);
36315 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36316 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36317 lvcc->stats.x.aal5.service_stream++;
36318 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36319 "PDU on VCI %d!\n", lanai->number, vci);
36320 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36321 return 0;
36322 }
36323 DPRINTK("got rx crc error on vci %d\n", vci);
36324 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36325 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36326 lvcc->stats.x.aal5.service_rxcrc++;
36327 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36328 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36329 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36330 index 5aca5f4..ce3a6b0 100644
36331 --- a/drivers/atm/nicstar.c
36332 +++ b/drivers/atm/nicstar.c
36333 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36334 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36335 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36336 card->index);
36337 - atomic_inc(&vcc->stats->tx_err);
36338 + atomic_inc_unchecked(&vcc->stats->tx_err);
36339 dev_kfree_skb_any(skb);
36340 return -EINVAL;
36341 }
36342 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36343 if (!vc->tx) {
36344 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36345 card->index);
36346 - atomic_inc(&vcc->stats->tx_err);
36347 + atomic_inc_unchecked(&vcc->stats->tx_err);
36348 dev_kfree_skb_any(skb);
36349 return -EINVAL;
36350 }
36351 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36352 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36353 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36354 card->index);
36355 - atomic_inc(&vcc->stats->tx_err);
36356 + atomic_inc_unchecked(&vcc->stats->tx_err);
36357 dev_kfree_skb_any(skb);
36358 return -EINVAL;
36359 }
36360
36361 if (skb_shinfo(skb)->nr_frags != 0) {
36362 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36363 - atomic_inc(&vcc->stats->tx_err);
36364 + atomic_inc_unchecked(&vcc->stats->tx_err);
36365 dev_kfree_skb_any(skb);
36366 return -EINVAL;
36367 }
36368 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36369 }
36370
36371 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36372 - atomic_inc(&vcc->stats->tx_err);
36373 + atomic_inc_unchecked(&vcc->stats->tx_err);
36374 dev_kfree_skb_any(skb);
36375 return -EIO;
36376 }
36377 - atomic_inc(&vcc->stats->tx);
36378 + atomic_inc_unchecked(&vcc->stats->tx);
36379
36380 return 0;
36381 }
36382 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36383 printk
36384 ("nicstar%d: Can't allocate buffers for aal0.\n",
36385 card->index);
36386 - atomic_add(i, &vcc->stats->rx_drop);
36387 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36388 break;
36389 }
36390 if (!atm_charge(vcc, sb->truesize)) {
36391 RXPRINTK
36392 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36393 card->index);
36394 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36395 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36396 dev_kfree_skb_any(sb);
36397 break;
36398 }
36399 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36400 ATM_SKB(sb)->vcc = vcc;
36401 __net_timestamp(sb);
36402 vcc->push(vcc, sb);
36403 - atomic_inc(&vcc->stats->rx);
36404 + atomic_inc_unchecked(&vcc->stats->rx);
36405 cell += ATM_CELL_PAYLOAD;
36406 }
36407
36408 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36409 if (iovb == NULL) {
36410 printk("nicstar%d: Out of iovec buffers.\n",
36411 card->index);
36412 - atomic_inc(&vcc->stats->rx_drop);
36413 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36414 recycle_rx_buf(card, skb);
36415 return;
36416 }
36417 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36418 small or large buffer itself. */
36419 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36420 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36421 - atomic_inc(&vcc->stats->rx_err);
36422 + atomic_inc_unchecked(&vcc->stats->rx_err);
36423 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36424 NS_MAX_IOVECS);
36425 NS_PRV_IOVCNT(iovb) = 0;
36426 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36427 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36428 card->index);
36429 which_list(card, skb);
36430 - atomic_inc(&vcc->stats->rx_err);
36431 + atomic_inc_unchecked(&vcc->stats->rx_err);
36432 recycle_rx_buf(card, skb);
36433 vc->rx_iov = NULL;
36434 recycle_iov_buf(card, iovb);
36435 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36436 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36437 card->index);
36438 which_list(card, skb);
36439 - atomic_inc(&vcc->stats->rx_err);
36440 + atomic_inc_unchecked(&vcc->stats->rx_err);
36441 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36442 NS_PRV_IOVCNT(iovb));
36443 vc->rx_iov = NULL;
36444 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36445 printk(" - PDU size mismatch.\n");
36446 else
36447 printk(".\n");
36448 - atomic_inc(&vcc->stats->rx_err);
36449 + atomic_inc_unchecked(&vcc->stats->rx_err);
36450 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36451 NS_PRV_IOVCNT(iovb));
36452 vc->rx_iov = NULL;
36453 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36454 /* skb points to a small buffer */
36455 if (!atm_charge(vcc, skb->truesize)) {
36456 push_rxbufs(card, skb);
36457 - atomic_inc(&vcc->stats->rx_drop);
36458 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36459 } else {
36460 skb_put(skb, len);
36461 dequeue_sm_buf(card, skb);
36462 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36463 ATM_SKB(skb)->vcc = vcc;
36464 __net_timestamp(skb);
36465 vcc->push(vcc, skb);
36466 - atomic_inc(&vcc->stats->rx);
36467 + atomic_inc_unchecked(&vcc->stats->rx);
36468 }
36469 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36470 struct sk_buff *sb;
36471 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36472 if (len <= NS_SMBUFSIZE) {
36473 if (!atm_charge(vcc, sb->truesize)) {
36474 push_rxbufs(card, sb);
36475 - atomic_inc(&vcc->stats->rx_drop);
36476 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36477 } else {
36478 skb_put(sb, len);
36479 dequeue_sm_buf(card, sb);
36480 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36481 ATM_SKB(sb)->vcc = vcc;
36482 __net_timestamp(sb);
36483 vcc->push(vcc, sb);
36484 - atomic_inc(&vcc->stats->rx);
36485 + atomic_inc_unchecked(&vcc->stats->rx);
36486 }
36487
36488 push_rxbufs(card, skb);
36489 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36490
36491 if (!atm_charge(vcc, skb->truesize)) {
36492 push_rxbufs(card, skb);
36493 - atomic_inc(&vcc->stats->rx_drop);
36494 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36495 } else {
36496 dequeue_lg_buf(card, skb);
36497 #ifdef NS_USE_DESTRUCTORS
36498 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36499 ATM_SKB(skb)->vcc = vcc;
36500 __net_timestamp(skb);
36501 vcc->push(vcc, skb);
36502 - atomic_inc(&vcc->stats->rx);
36503 + atomic_inc_unchecked(&vcc->stats->rx);
36504 }
36505
36506 push_rxbufs(card, sb);
36507 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36508 printk
36509 ("nicstar%d: Out of huge buffers.\n",
36510 card->index);
36511 - atomic_inc(&vcc->stats->rx_drop);
36512 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36513 recycle_iovec_rx_bufs(card,
36514 (struct iovec *)
36515 iovb->data,
36516 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36517 card->hbpool.count++;
36518 } else
36519 dev_kfree_skb_any(hb);
36520 - atomic_inc(&vcc->stats->rx_drop);
36521 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36522 } else {
36523 /* Copy the small buffer to the huge buffer */
36524 sb = (struct sk_buff *)iov->iov_base;
36525 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36526 #endif /* NS_USE_DESTRUCTORS */
36527 __net_timestamp(hb);
36528 vcc->push(vcc, hb);
36529 - atomic_inc(&vcc->stats->rx);
36530 + atomic_inc_unchecked(&vcc->stats->rx);
36531 }
36532 }
36533
36534 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36535 index 32784d1..4a8434a 100644
36536 --- a/drivers/atm/solos-pci.c
36537 +++ b/drivers/atm/solos-pci.c
36538 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36539 }
36540 atm_charge(vcc, skb->truesize);
36541 vcc->push(vcc, skb);
36542 - atomic_inc(&vcc->stats->rx);
36543 + atomic_inc_unchecked(&vcc->stats->rx);
36544 break;
36545
36546 case PKT_STATUS:
36547 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36548 vcc = SKB_CB(oldskb)->vcc;
36549
36550 if (vcc) {
36551 - atomic_inc(&vcc->stats->tx);
36552 + atomic_inc_unchecked(&vcc->stats->tx);
36553 solos_pop(vcc, oldskb);
36554 } else {
36555 dev_kfree_skb_irq(oldskb);
36556 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36557 index 0215934..ce9f5b1 100644
36558 --- a/drivers/atm/suni.c
36559 +++ b/drivers/atm/suni.c
36560 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36561
36562
36563 #define ADD_LIMITED(s,v) \
36564 - atomic_add((v),&stats->s); \
36565 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36566 + atomic_add_unchecked((v),&stats->s); \
36567 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36568
36569
36570 static void suni_hz(unsigned long from_timer)
36571 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36572 index 5120a96..e2572bd 100644
36573 --- a/drivers/atm/uPD98402.c
36574 +++ b/drivers/atm/uPD98402.c
36575 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36576 struct sonet_stats tmp;
36577 int error = 0;
36578
36579 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36580 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36581 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36582 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36583 if (zero && !error) {
36584 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36585
36586
36587 #define ADD_LIMITED(s,v) \
36588 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36589 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36590 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36591 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36592 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36593 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36594
36595
36596 static void stat_event(struct atm_dev *dev)
36597 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36598 if (reason & uPD98402_INT_PFM) stat_event(dev);
36599 if (reason & uPD98402_INT_PCO) {
36600 (void) GET(PCOCR); /* clear interrupt cause */
36601 - atomic_add(GET(HECCT),
36602 + atomic_add_unchecked(GET(HECCT),
36603 &PRIV(dev)->sonet_stats.uncorr_hcs);
36604 }
36605 if ((reason & uPD98402_INT_RFO) &&
36606 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36607 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36608 uPD98402_INT_LOS),PIMR); /* enable them */
36609 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36610 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36611 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36612 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36613 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36614 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36615 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36616 return 0;
36617 }
36618
36619 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36620 index 969c3c2..9b72956 100644
36621 --- a/drivers/atm/zatm.c
36622 +++ b/drivers/atm/zatm.c
36623 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36624 }
36625 if (!size) {
36626 dev_kfree_skb_irq(skb);
36627 - if (vcc) atomic_inc(&vcc->stats->rx_err);
36628 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36629 continue;
36630 }
36631 if (!atm_charge(vcc,skb->truesize)) {
36632 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36633 skb->len = size;
36634 ATM_SKB(skb)->vcc = vcc;
36635 vcc->push(vcc,skb);
36636 - atomic_inc(&vcc->stats->rx);
36637 + atomic_inc_unchecked(&vcc->stats->rx);
36638 }
36639 zout(pos & 0xffff,MTA(mbx));
36640 #if 0 /* probably a stupid idea */
36641 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36642 skb_queue_head(&zatm_vcc->backlog,skb);
36643 break;
36644 }
36645 - atomic_inc(&vcc->stats->tx);
36646 + atomic_inc_unchecked(&vcc->stats->tx);
36647 wake_up(&zatm_vcc->tx_wait);
36648 }
36649
36650 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36651 index 73f6c29..b0c0e13 100644
36652 --- a/drivers/base/bus.c
36653 +++ b/drivers/base/bus.c
36654 @@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36655 return -EINVAL;
36656
36657 mutex_lock(&subsys->p->mutex);
36658 - list_add_tail(&sif->node, &subsys->p->interfaces);
36659 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36660 if (sif->add_dev) {
36661 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36662 while ((dev = subsys_dev_iter_next(&iter)))
36663 @@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36664 subsys = sif->subsys;
36665
36666 mutex_lock(&subsys->p->mutex);
36667 - list_del_init(&sif->node);
36668 + pax_list_del_init((struct list_head *)&sif->node);
36669 if (sif->remove_dev) {
36670 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36671 while ((dev = subsys_dev_iter_next(&iter)))
36672 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36673 index 0f38201..6c2b444 100644
36674 --- a/drivers/base/devtmpfs.c
36675 +++ b/drivers/base/devtmpfs.c
36676 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36677 if (!thread)
36678 return 0;
36679
36680 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36681 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36682 if (err)
36683 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36684 else
36685 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36686 *err = sys_unshare(CLONE_NEWNS);
36687 if (*err)
36688 goto out;
36689 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36690 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36691 if (*err)
36692 goto out;
36693 - sys_chdir("/.."); /* will traverse into overmounted root */
36694 - sys_chroot(".");
36695 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36696 + sys_chroot((char __force_user *)".");
36697 complete(&setup_done);
36698 while (1) {
36699 spin_lock(&req_lock);
36700 diff --git a/drivers/base/node.c b/drivers/base/node.c
36701 index bc9f43b..29703b8 100644
36702 --- a/drivers/base/node.c
36703 +++ b/drivers/base/node.c
36704 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36705 struct node_attr {
36706 struct device_attribute attr;
36707 enum node_states state;
36708 -};
36709 +} __do_const;
36710
36711 static ssize_t show_node_state(struct device *dev,
36712 struct device_attribute *attr, char *buf)
36713 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36714 index bfb8955..42c9b9a 100644
36715 --- a/drivers/base/power/domain.c
36716 +++ b/drivers/base/power/domain.c
36717 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36718 {
36719 struct cpuidle_driver *cpuidle_drv;
36720 struct gpd_cpu_data *cpu_data;
36721 - struct cpuidle_state *idle_state;
36722 + cpuidle_state_no_const *idle_state;
36723 int ret = 0;
36724
36725 if (IS_ERR_OR_NULL(genpd) || state < 0)
36726 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36727 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36728 {
36729 struct gpd_cpu_data *cpu_data;
36730 - struct cpuidle_state *idle_state;
36731 + cpuidle_state_no_const *idle_state;
36732 int ret = 0;
36733
36734 if (IS_ERR_OR_NULL(genpd))
36735 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36736 index 03e089a..0e9560c 100644
36737 --- a/drivers/base/power/sysfs.c
36738 +++ b/drivers/base/power/sysfs.c
36739 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36740 return -EIO;
36741 }
36742 }
36743 - return sprintf(buf, p);
36744 + return sprintf(buf, "%s", p);
36745 }
36746
36747 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36748 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36749 index 2d56f41..8830f19 100644
36750 --- a/drivers/base/power/wakeup.c
36751 +++ b/drivers/base/power/wakeup.c
36752 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36753 * They need to be modified together atomically, so it's better to use one
36754 * atomic variable to hold them both.
36755 */
36756 -static atomic_t combined_event_count = ATOMIC_INIT(0);
36757 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36758
36759 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36760 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36761
36762 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36763 {
36764 - unsigned int comb = atomic_read(&combined_event_count);
36765 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
36766
36767 *cnt = (comb >> IN_PROGRESS_BITS);
36768 *inpr = comb & MAX_IN_PROGRESS;
36769 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36770 ws->start_prevent_time = ws->last_time;
36771
36772 /* Increment the counter of events in progress. */
36773 - cec = atomic_inc_return(&combined_event_count);
36774 + cec = atomic_inc_return_unchecked(&combined_event_count);
36775
36776 trace_wakeup_source_activate(ws->name, cec);
36777 }
36778 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36779 * Increment the counter of registered wakeup events and decrement the
36780 * couter of wakeup events in progress simultaneously.
36781 */
36782 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36783 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36784 trace_wakeup_source_deactivate(ws->name, cec);
36785
36786 split_counters(&cnt, &inpr);
36787 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36788 index e8d11b6..7b1b36f 100644
36789 --- a/drivers/base/syscore.c
36790 +++ b/drivers/base/syscore.c
36791 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36792 void register_syscore_ops(struct syscore_ops *ops)
36793 {
36794 mutex_lock(&syscore_ops_lock);
36795 - list_add_tail(&ops->node, &syscore_ops_list);
36796 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36797 mutex_unlock(&syscore_ops_lock);
36798 }
36799 EXPORT_SYMBOL_GPL(register_syscore_ops);
36800 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36801 void unregister_syscore_ops(struct syscore_ops *ops)
36802 {
36803 mutex_lock(&syscore_ops_lock);
36804 - list_del(&ops->node);
36805 + pax_list_del((struct list_head *)&ops->node);
36806 mutex_unlock(&syscore_ops_lock);
36807 }
36808 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36809 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36810 index b35fc4f..c902870 100644
36811 --- a/drivers/block/cciss.c
36812 +++ b/drivers/block/cciss.c
36813 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36814 while (!list_empty(&h->reqQ)) {
36815 c = list_entry(h->reqQ.next, CommandList_struct, list);
36816 /* can't do anything if fifo is full */
36817 - if ((h->access.fifo_full(h))) {
36818 + if ((h->access->fifo_full(h))) {
36819 dev_warn(&h->pdev->dev, "fifo full\n");
36820 break;
36821 }
36822 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36823 h->Qdepth--;
36824
36825 /* Tell the controller execute command */
36826 - h->access.submit_command(h, c);
36827 + h->access->submit_command(h, c);
36828
36829 /* Put job onto the completed Q */
36830 addQ(&h->cmpQ, c);
36831 @@ -3447,17 +3447,17 @@ startio:
36832
36833 static inline unsigned long get_next_completion(ctlr_info_t *h)
36834 {
36835 - return h->access.command_completed(h);
36836 + return h->access->command_completed(h);
36837 }
36838
36839 static inline int interrupt_pending(ctlr_info_t *h)
36840 {
36841 - return h->access.intr_pending(h);
36842 + return h->access->intr_pending(h);
36843 }
36844
36845 static inline long interrupt_not_for_us(ctlr_info_t *h)
36846 {
36847 - return ((h->access.intr_pending(h) == 0) ||
36848 + return ((h->access->intr_pending(h) == 0) ||
36849 (h->interrupts_enabled == 0));
36850 }
36851
36852 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36853 u32 a;
36854
36855 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36856 - return h->access.command_completed(h);
36857 + return h->access->command_completed(h);
36858
36859 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36860 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36861 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36862 trans_support & CFGTBL_Trans_use_short_tags);
36863
36864 /* Change the access methods to the performant access methods */
36865 - h->access = SA5_performant_access;
36866 + h->access = &SA5_performant_access;
36867 h->transMethod = CFGTBL_Trans_Performant;
36868
36869 return;
36870 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36871 if (prod_index < 0)
36872 return -ENODEV;
36873 h->product_name = products[prod_index].product_name;
36874 - h->access = *(products[prod_index].access);
36875 + h->access = products[prod_index].access;
36876
36877 if (cciss_board_disabled(h)) {
36878 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36879 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36880 }
36881
36882 /* make sure the board interrupts are off */
36883 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36884 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36885 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36886 if (rc)
36887 goto clean2;
36888 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36889 * fake ones to scoop up any residual completions.
36890 */
36891 spin_lock_irqsave(&h->lock, flags);
36892 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36893 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36894 spin_unlock_irqrestore(&h->lock, flags);
36895 free_irq(h->intr[h->intr_mode], h);
36896 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36897 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36898 dev_info(&h->pdev->dev, "Board READY.\n");
36899 dev_info(&h->pdev->dev,
36900 "Waiting for stale completions to drain.\n");
36901 - h->access.set_intr_mask(h, CCISS_INTR_ON);
36902 + h->access->set_intr_mask(h, CCISS_INTR_ON);
36903 msleep(10000);
36904 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36905 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36906
36907 rc = controller_reset_failed(h->cfgtable);
36908 if (rc)
36909 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36910 cciss_scsi_setup(h);
36911
36912 /* Turn the interrupts on so we can service requests */
36913 - h->access.set_intr_mask(h, CCISS_INTR_ON);
36914 + h->access->set_intr_mask(h, CCISS_INTR_ON);
36915
36916 /* Get the firmware version */
36917 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36918 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36919 kfree(flush_buf);
36920 if (return_code != IO_OK)
36921 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36922 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36923 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36924 free_irq(h->intr[h->intr_mode], h);
36925 }
36926
36927 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36928 index 7fda30e..2f27946 100644
36929 --- a/drivers/block/cciss.h
36930 +++ b/drivers/block/cciss.h
36931 @@ -101,7 +101,7 @@ struct ctlr_info
36932 /* information about each logical volume */
36933 drive_info_struct *drv[CISS_MAX_LUN];
36934
36935 - struct access_method access;
36936 + struct access_method *access;
36937
36938 /* queue and queue Info */
36939 struct list_head reqQ;
36940 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
36941 }
36942
36943 static struct access_method SA5_access = {
36944 - SA5_submit_command,
36945 - SA5_intr_mask,
36946 - SA5_fifo_full,
36947 - SA5_intr_pending,
36948 - SA5_completed,
36949 + .submit_command = SA5_submit_command,
36950 + .set_intr_mask = SA5_intr_mask,
36951 + .fifo_full = SA5_fifo_full,
36952 + .intr_pending = SA5_intr_pending,
36953 + .command_completed = SA5_completed,
36954 };
36955
36956 static struct access_method SA5B_access = {
36957 - SA5_submit_command,
36958 - SA5B_intr_mask,
36959 - SA5_fifo_full,
36960 - SA5B_intr_pending,
36961 - SA5_completed,
36962 + .submit_command = SA5_submit_command,
36963 + .set_intr_mask = SA5B_intr_mask,
36964 + .fifo_full = SA5_fifo_full,
36965 + .intr_pending = SA5B_intr_pending,
36966 + .command_completed = SA5_completed,
36967 };
36968
36969 static struct access_method SA5_performant_access = {
36970 - SA5_submit_command,
36971 - SA5_performant_intr_mask,
36972 - SA5_fifo_full,
36973 - SA5_performant_intr_pending,
36974 - SA5_performant_completed,
36975 + .submit_command = SA5_submit_command,
36976 + .set_intr_mask = SA5_performant_intr_mask,
36977 + .fifo_full = SA5_fifo_full,
36978 + .intr_pending = SA5_performant_intr_pending,
36979 + .command_completed = SA5_performant_completed,
36980 };
36981
36982 struct board_type {
36983 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36984 index 2b94403..fd6ad1f 100644
36985 --- a/drivers/block/cpqarray.c
36986 +++ b/drivers/block/cpqarray.c
36987 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36988 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36989 goto Enomem4;
36990 }
36991 - hba[i]->access.set_intr_mask(hba[i], 0);
36992 + hba[i]->access->set_intr_mask(hba[i], 0);
36993 if (request_irq(hba[i]->intr, do_ida_intr,
36994 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36995 {
36996 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36997 add_timer(&hba[i]->timer);
36998
36999 /* Enable IRQ now that spinlock and rate limit timer are set up */
37000 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37001 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37002
37003 for(j=0; j<NWD; j++) {
37004 struct gendisk *disk = ida_gendisk[i][j];
37005 @@ -694,7 +694,7 @@ DBGINFO(
37006 for(i=0; i<NR_PRODUCTS; i++) {
37007 if (board_id == products[i].board_id) {
37008 c->product_name = products[i].product_name;
37009 - c->access = *(products[i].access);
37010 + c->access = products[i].access;
37011 break;
37012 }
37013 }
37014 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37015 hba[ctlr]->intr = intr;
37016 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37017 hba[ctlr]->product_name = products[j].product_name;
37018 - hba[ctlr]->access = *(products[j].access);
37019 + hba[ctlr]->access = products[j].access;
37020 hba[ctlr]->ctlr = ctlr;
37021 hba[ctlr]->board_id = board_id;
37022 hba[ctlr]->pci_dev = NULL; /* not PCI */
37023 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37024
37025 while((c = h->reqQ) != NULL) {
37026 /* Can't do anything if we're busy */
37027 - if (h->access.fifo_full(h) == 0)
37028 + if (h->access->fifo_full(h) == 0)
37029 return;
37030
37031 /* Get the first entry from the request Q */
37032 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37033 h->Qdepth--;
37034
37035 /* Tell the controller to do our bidding */
37036 - h->access.submit_command(h, c);
37037 + h->access->submit_command(h, c);
37038
37039 /* Get onto the completion Q */
37040 addQ(&h->cmpQ, c);
37041 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37042 unsigned long flags;
37043 __u32 a,a1;
37044
37045 - istat = h->access.intr_pending(h);
37046 + istat = h->access->intr_pending(h);
37047 /* Is this interrupt for us? */
37048 if (istat == 0)
37049 return IRQ_NONE;
37050 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37051 */
37052 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37053 if (istat & FIFO_NOT_EMPTY) {
37054 - while((a = h->access.command_completed(h))) {
37055 + while((a = h->access->command_completed(h))) {
37056 a1 = a; a &= ~3;
37057 if ((c = h->cmpQ) == NULL)
37058 {
37059 @@ -1448,11 +1448,11 @@ static int sendcmd(
37060 /*
37061 * Disable interrupt
37062 */
37063 - info_p->access.set_intr_mask(info_p, 0);
37064 + info_p->access->set_intr_mask(info_p, 0);
37065 /* Make sure there is room in the command FIFO */
37066 /* Actually it should be completely empty at this time. */
37067 for (i = 200000; i > 0; i--) {
37068 - temp = info_p->access.fifo_full(info_p);
37069 + temp = info_p->access->fifo_full(info_p);
37070 if (temp != 0) {
37071 break;
37072 }
37073 @@ -1465,7 +1465,7 @@ DBG(
37074 /*
37075 * Send the cmd
37076 */
37077 - info_p->access.submit_command(info_p, c);
37078 + info_p->access->submit_command(info_p, c);
37079 complete = pollcomplete(ctlr);
37080
37081 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37082 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37083 * we check the new geometry. Then turn interrupts back on when
37084 * we're done.
37085 */
37086 - host->access.set_intr_mask(host, 0);
37087 + host->access->set_intr_mask(host, 0);
37088 getgeometry(ctlr);
37089 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37090 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37091
37092 for(i=0; i<NWD; i++) {
37093 struct gendisk *disk = ida_gendisk[ctlr][i];
37094 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37095 /* Wait (up to 2 seconds) for a command to complete */
37096
37097 for (i = 200000; i > 0; i--) {
37098 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37099 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37100 if (done == 0) {
37101 udelay(10); /* a short fixed delay */
37102 } else
37103 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37104 index be73e9d..7fbf140 100644
37105 --- a/drivers/block/cpqarray.h
37106 +++ b/drivers/block/cpqarray.h
37107 @@ -99,7 +99,7 @@ struct ctlr_info {
37108 drv_info_t drv[NWD];
37109 struct proc_dir_entry *proc;
37110
37111 - struct access_method access;
37112 + struct access_method *access;
37113
37114 cmdlist_t *reqQ;
37115 cmdlist_t *cmpQ;
37116 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37117 index 0e06f0c..c47b81d 100644
37118 --- a/drivers/block/drbd/drbd_int.h
37119 +++ b/drivers/block/drbd/drbd_int.h
37120 @@ -582,7 +582,7 @@ struct drbd_epoch {
37121 struct drbd_tconn *tconn;
37122 struct list_head list;
37123 unsigned int barrier_nr;
37124 - atomic_t epoch_size; /* increased on every request added. */
37125 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37126 atomic_t active; /* increased on every req. added, and dec on every finished. */
37127 unsigned long flags;
37128 };
37129 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37130 unsigned int al_tr_number;
37131 int al_tr_cycle;
37132 wait_queue_head_t seq_wait;
37133 - atomic_t packet_seq;
37134 + atomic_unchecked_t packet_seq;
37135 unsigned int peer_seq;
37136 spinlock_t peer_seq_lock;
37137 unsigned int minor;
37138 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37139 char __user *uoptval;
37140 int err;
37141
37142 - uoptval = (char __user __force *)optval;
37143 + uoptval = (char __force_user *)optval;
37144
37145 set_fs(KERNEL_DS);
37146 if (level == SOL_SOCKET)
37147 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37148 index 89c497c..9c736ae 100644
37149 --- a/drivers/block/drbd/drbd_interval.c
37150 +++ b/drivers/block/drbd/drbd_interval.c
37151 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37152 }
37153
37154 static const struct rb_augment_callbacks augment_callbacks = {
37155 - augment_propagate,
37156 - augment_copy,
37157 - augment_rotate,
37158 + .propagate = augment_propagate,
37159 + .copy = augment_copy,
37160 + .rotate = augment_rotate,
37161 };
37162
37163 /**
37164 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37165 index 9e3818b..7b64c92 100644
37166 --- a/drivers/block/drbd/drbd_main.c
37167 +++ b/drivers/block/drbd/drbd_main.c
37168 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37169 p->sector = sector;
37170 p->block_id = block_id;
37171 p->blksize = blksize;
37172 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37173 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37174 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37175 }
37176
37177 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37178 return -EIO;
37179 p->sector = cpu_to_be64(req->i.sector);
37180 p->block_id = (unsigned long)req;
37181 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37182 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37183 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37184 if (mdev->state.conn >= C_SYNC_SOURCE &&
37185 mdev->state.conn <= C_PAUSED_SYNC_T)
37186 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37187 {
37188 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37189
37190 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37191 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37192 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37193 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37194 kfree(tconn->current_epoch);
37195
37196 idr_destroy(&tconn->volumes);
37197 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37198 index c706d50..5e1b472 100644
37199 --- a/drivers/block/drbd/drbd_nl.c
37200 +++ b/drivers/block/drbd/drbd_nl.c
37201 @@ -3440,7 +3440,7 @@ out:
37202
37203 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37204 {
37205 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37206 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37207 struct sk_buff *msg;
37208 struct drbd_genlmsghdr *d_out;
37209 unsigned seq;
37210 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37211 return;
37212 }
37213
37214 - seq = atomic_inc_return(&drbd_genl_seq);
37215 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37216 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37217 if (!msg)
37218 goto failed;
37219 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37220 index 6fa6673..b7f97e9 100644
37221 --- a/drivers/block/drbd/drbd_receiver.c
37222 +++ b/drivers/block/drbd/drbd_receiver.c
37223 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37224 {
37225 int err;
37226
37227 - atomic_set(&mdev->packet_seq, 0);
37228 + atomic_set_unchecked(&mdev->packet_seq, 0);
37229 mdev->peer_seq = 0;
37230
37231 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37232 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37233 do {
37234 next_epoch = NULL;
37235
37236 - epoch_size = atomic_read(&epoch->epoch_size);
37237 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37238
37239 switch (ev & ~EV_CLEANUP) {
37240 case EV_PUT:
37241 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37242 rv = FE_DESTROYED;
37243 } else {
37244 epoch->flags = 0;
37245 - atomic_set(&epoch->epoch_size, 0);
37246 + atomic_set_unchecked(&epoch->epoch_size, 0);
37247 /* atomic_set(&epoch->active, 0); is already zero */
37248 if (rv == FE_STILL_LIVE)
37249 rv = FE_RECYCLED;
37250 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37251 conn_wait_active_ee_empty(tconn);
37252 drbd_flush(tconn);
37253
37254 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37255 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37256 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37257 if (epoch)
37258 break;
37259 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37260 }
37261
37262 epoch->flags = 0;
37263 - atomic_set(&epoch->epoch_size, 0);
37264 + atomic_set_unchecked(&epoch->epoch_size, 0);
37265 atomic_set(&epoch->active, 0);
37266
37267 spin_lock(&tconn->epoch_lock);
37268 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37269 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37270 list_add(&epoch->list, &tconn->current_epoch->list);
37271 tconn->current_epoch = epoch;
37272 tconn->epochs++;
37273 @@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37274
37275 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37276 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37277 - atomic_inc(&tconn->current_epoch->epoch_size);
37278 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37279 err2 = drbd_drain_block(mdev, pi->size);
37280 if (!err)
37281 err = err2;
37282 @@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37283
37284 spin_lock(&tconn->epoch_lock);
37285 peer_req->epoch = tconn->current_epoch;
37286 - atomic_inc(&peer_req->epoch->epoch_size);
37287 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37288 atomic_inc(&peer_req->epoch->active);
37289 spin_unlock(&tconn->epoch_lock);
37290
37291 @@ -4344,7 +4344,7 @@ struct data_cmd {
37292 int expect_payload;
37293 size_t pkt_size;
37294 int (*fn)(struct drbd_tconn *, struct packet_info *);
37295 -};
37296 +} __do_const;
37297
37298 static struct data_cmd drbd_cmd_handler[] = {
37299 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37300 @@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37301 if (!list_empty(&tconn->current_epoch->list))
37302 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37303 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37304 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37305 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37306 tconn->send.seen_any_write_yet = false;
37307
37308 conn_info(tconn, "Connection closed\n");
37309 @@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37310 struct asender_cmd {
37311 size_t pkt_size;
37312 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37313 -};
37314 +} __do_const;
37315
37316 static struct asender_cmd asender_tbl[] = {
37317 [P_PING] = { 0, got_Ping },
37318 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37319 index c8dac73..1800093 100644
37320 --- a/drivers/block/loop.c
37321 +++ b/drivers/block/loop.c
37322 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37323
37324 file_start_write(file);
37325 set_fs(get_ds());
37326 - bw = file->f_op->write(file, buf, len, &pos);
37327 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37328 set_fs(old_fs);
37329 file_end_write(file);
37330 if (likely(bw == len))
37331 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37332 index 83a598e..2de5ce3 100644
37333 --- a/drivers/block/null_blk.c
37334 +++ b/drivers/block/null_blk.c
37335 @@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37336 return 0;
37337 }
37338
37339 -static struct blk_mq_ops null_mq_ops = {
37340 - .queue_rq = null_queue_rq,
37341 - .map_queue = blk_mq_map_queue,
37342 +static struct blk_mq_ops null_mq_single_ops = {
37343 + .queue_rq = null_queue_rq,
37344 + .map_queue = blk_mq_map_queue,
37345 .init_hctx = null_init_hctx,
37346 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37347 + .free_hctx = blk_mq_free_single_hw_queue,
37348 +};
37349 +
37350 +static struct blk_mq_ops null_mq_per_node_ops = {
37351 + .queue_rq = null_queue_rq,
37352 + .map_queue = blk_mq_map_queue,
37353 + .init_hctx = null_init_hctx,
37354 + .alloc_hctx = null_alloc_hctx,
37355 + .free_hctx = null_free_hctx,
37356 };
37357
37358 static struct blk_mq_reg null_mq_reg = {
37359 - .ops = &null_mq_ops,
37360 + .ops = &null_mq_single_ops,
37361 .queue_depth = 64,
37362 .cmd_size = sizeof(struct nullb_cmd),
37363 .flags = BLK_MQ_F_SHOULD_MERGE,
37364 @@ -545,13 +555,8 @@ static int null_add_dev(void)
37365 null_mq_reg.queue_depth = hw_queue_depth;
37366 null_mq_reg.nr_hw_queues = submit_queues;
37367
37368 - if (use_per_node_hctx) {
37369 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37370 - null_mq_reg.ops->free_hctx = null_free_hctx;
37371 - } else {
37372 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37373 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37374 - }
37375 + if (use_per_node_hctx)
37376 + null_mq_reg.ops = &null_mq_per_node_ops;
37377
37378 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37379 } else if (queue_mode == NULL_Q_BIO) {
37380 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37381 index ff8668c..f62167a 100644
37382 --- a/drivers/block/pktcdvd.c
37383 +++ b/drivers/block/pktcdvd.c
37384 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37385
37386 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37387 {
37388 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37389 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37390 }
37391
37392 /*
37393 @@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37394 return -EROFS;
37395 }
37396 pd->settings.fp = ti.fp;
37397 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37398 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37399
37400 if (ti.nwa_v) {
37401 pd->nwa = be32_to_cpu(ti.next_writable);
37402 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37403 index e5565fb..71be10b4 100644
37404 --- a/drivers/block/smart1,2.h
37405 +++ b/drivers/block/smart1,2.h
37406 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37407 }
37408
37409 static struct access_method smart4_access = {
37410 - smart4_submit_command,
37411 - smart4_intr_mask,
37412 - smart4_fifo_full,
37413 - smart4_intr_pending,
37414 - smart4_completed,
37415 + .submit_command = smart4_submit_command,
37416 + .set_intr_mask = smart4_intr_mask,
37417 + .fifo_full = smart4_fifo_full,
37418 + .intr_pending = smart4_intr_pending,
37419 + .command_completed = smart4_completed,
37420 };
37421
37422 /*
37423 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37424 }
37425
37426 static struct access_method smart2_access = {
37427 - smart2_submit_command,
37428 - smart2_intr_mask,
37429 - smart2_fifo_full,
37430 - smart2_intr_pending,
37431 - smart2_completed,
37432 + .submit_command = smart2_submit_command,
37433 + .set_intr_mask = smart2_intr_mask,
37434 + .fifo_full = smart2_fifo_full,
37435 + .intr_pending = smart2_intr_pending,
37436 + .command_completed = smart2_completed,
37437 };
37438
37439 /*
37440 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37441 }
37442
37443 static struct access_method smart2e_access = {
37444 - smart2e_submit_command,
37445 - smart2e_intr_mask,
37446 - smart2e_fifo_full,
37447 - smart2e_intr_pending,
37448 - smart2e_completed,
37449 + .submit_command = smart2e_submit_command,
37450 + .set_intr_mask = smart2e_intr_mask,
37451 + .fifo_full = smart2e_fifo_full,
37452 + .intr_pending = smart2e_intr_pending,
37453 + .command_completed = smart2e_completed,
37454 };
37455
37456 /*
37457 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37458 }
37459
37460 static struct access_method smart1_access = {
37461 - smart1_submit_command,
37462 - smart1_intr_mask,
37463 - smart1_fifo_full,
37464 - smart1_intr_pending,
37465 - smart1_completed,
37466 + .submit_command = smart1_submit_command,
37467 + .set_intr_mask = smart1_intr_mask,
37468 + .fifo_full = smart1_fifo_full,
37469 + .intr_pending = smart1_intr_pending,
37470 + .command_completed = smart1_completed,
37471 };
37472 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37473 index f038dba..bb74c08 100644
37474 --- a/drivers/bluetooth/btwilink.c
37475 +++ b/drivers/bluetooth/btwilink.c
37476 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
37477
37478 static int bt_ti_probe(struct platform_device *pdev)
37479 {
37480 - static struct ti_st *hst;
37481 + struct ti_st *hst;
37482 struct hci_dev *hdev;
37483 int err;
37484
37485 diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
37486 index b6739cb..962fd35 100644
37487 --- a/drivers/bus/arm-cci.c
37488 +++ b/drivers/bus/arm-cci.c
37489 @@ -979,7 +979,7 @@ static int cci_probe(void)
37490
37491 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
37492
37493 - ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
37494 + ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
37495 if (!ports)
37496 return -ENOMEM;
37497
37498 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37499 index 8a3aff7..d7538c2 100644
37500 --- a/drivers/cdrom/cdrom.c
37501 +++ b/drivers/cdrom/cdrom.c
37502 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37503 ENSURE(reset, CDC_RESET);
37504 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37505 cdi->mc_flags = 0;
37506 - cdo->n_minors = 0;
37507 cdi->options = CDO_USE_FFLAGS;
37508
37509 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
37510 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
37511 else
37512 cdi->cdda_method = CDDA_OLD;
37513
37514 - if (!cdo->generic_packet)
37515 - cdo->generic_packet = cdrom_dummy_generic_packet;
37516 + if (!cdo->generic_packet) {
37517 + pax_open_kernel();
37518 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
37519 + pax_close_kernel();
37520 + }
37521
37522 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
37523 mutex_lock(&cdrom_mutex);
37524 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
37525 if (cdi->exit)
37526 cdi->exit(cdi);
37527
37528 - cdi->ops->n_minors--;
37529 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
37530 }
37531
37532 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
37533 */
37534 nr = nframes;
37535 do {
37536 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37537 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37538 if (cgc.buffer)
37539 break;
37540
37541 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
37542 struct cdrom_device_info *cdi;
37543 int ret;
37544
37545 - ret = scnprintf(info + *pos, max_size - *pos, header);
37546 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
37547 if (!ret)
37548 return 1;
37549
37550 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
37551 index 5980cb9..6d7bd7e 100644
37552 --- a/drivers/cdrom/gdrom.c
37553 +++ b/drivers/cdrom/gdrom.c
37554 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
37555 .audio_ioctl = gdrom_audio_ioctl,
37556 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
37557 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37558 - .n_minors = 1,
37559 };
37560
37561 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37562 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37563 index fa3243d..8c98297 100644
37564 --- a/drivers/char/Kconfig
37565 +++ b/drivers/char/Kconfig
37566 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37567
37568 config DEVKMEM
37569 bool "/dev/kmem virtual device support"
37570 - default y
37571 + default n
37572 + depends on !GRKERNSEC_KMEM
37573 help
37574 Say Y here if you want to support the /dev/kmem device. The
37575 /dev/kmem device is rarely used, but can be used for certain
37576 @@ -576,6 +577,7 @@ config DEVPORT
37577 bool
37578 depends on !M68K
37579 depends on ISA || PCI
37580 + depends on !GRKERNSEC_KMEM
37581 default y
37582
37583 source "drivers/s390/char/Kconfig"
37584 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37585 index a48e05b..6bac831 100644
37586 --- a/drivers/char/agp/compat_ioctl.c
37587 +++ b/drivers/char/agp/compat_ioctl.c
37588 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37589 return -ENOMEM;
37590 }
37591
37592 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37593 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37594 sizeof(*usegment) * ureserve.seg_count)) {
37595 kfree(usegment);
37596 kfree(ksegment);
37597 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37598 index 1b19239..b87b143 100644
37599 --- a/drivers/char/agp/frontend.c
37600 +++ b/drivers/char/agp/frontend.c
37601 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37602 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37603 return -EFAULT;
37604
37605 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37606 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37607 return -EFAULT;
37608
37609 client = agp_find_client_by_pid(reserve.pid);
37610 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37611 if (segment == NULL)
37612 return -ENOMEM;
37613
37614 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
37615 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37616 sizeof(struct agp_segment) * reserve.seg_count)) {
37617 kfree(segment);
37618 return -EFAULT;
37619 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37620 index 4f94375..413694e 100644
37621 --- a/drivers/char/genrtc.c
37622 +++ b/drivers/char/genrtc.c
37623 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37624 switch (cmd) {
37625
37626 case RTC_PLL_GET:
37627 + memset(&pll, 0, sizeof(pll));
37628 if (get_rtc_pll(&pll))
37629 return -EINVAL;
37630 else
37631 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37632 index 5d9c31d..c94ccb5 100644
37633 --- a/drivers/char/hpet.c
37634 +++ b/drivers/char/hpet.c
37635 @@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37636 }
37637
37638 static int
37639 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37640 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37641 struct hpet_info *info)
37642 {
37643 struct hpet_timer __iomem *timer;
37644 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37645 index 86fe45c..c0ea948 100644
37646 --- a/drivers/char/hw_random/intel-rng.c
37647 +++ b/drivers/char/hw_random/intel-rng.c
37648 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37649
37650 if (no_fwh_detect)
37651 return -ENODEV;
37652 - printk(warning);
37653 + printk("%s", warning);
37654 return -EBUSY;
37655 }
37656
37657 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37658 index ec4e10f..f2a763b 100644
37659 --- a/drivers/char/ipmi/ipmi_msghandler.c
37660 +++ b/drivers/char/ipmi/ipmi_msghandler.c
37661 @@ -420,7 +420,7 @@ struct ipmi_smi {
37662 struct proc_dir_entry *proc_dir;
37663 char proc_dir_name[10];
37664
37665 - atomic_t stats[IPMI_NUM_STATS];
37666 + atomic_unchecked_t stats[IPMI_NUM_STATS];
37667
37668 /*
37669 * run_to_completion duplicate of smb_info, smi_info
37670 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37671
37672
37673 #define ipmi_inc_stat(intf, stat) \
37674 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37675 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37676 #define ipmi_get_stat(intf, stat) \
37677 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37678 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37679
37680 static int is_lan_addr(struct ipmi_addr *addr)
37681 {
37682 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37683 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37684 init_waitqueue_head(&intf->waitq);
37685 for (i = 0; i < IPMI_NUM_STATS; i++)
37686 - atomic_set(&intf->stats[i], 0);
37687 + atomic_set_unchecked(&intf->stats[i], 0);
37688
37689 intf->proc_dir = NULL;
37690
37691 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37692 index 15e4a60..b046093 100644
37693 --- a/drivers/char/ipmi/ipmi_si_intf.c
37694 +++ b/drivers/char/ipmi/ipmi_si_intf.c
37695 @@ -280,7 +280,7 @@ struct smi_info {
37696 unsigned char slave_addr;
37697
37698 /* Counters and things for the proc filesystem. */
37699 - atomic_t stats[SI_NUM_STATS];
37700 + atomic_unchecked_t stats[SI_NUM_STATS];
37701
37702 struct task_struct *thread;
37703
37704 @@ -289,9 +289,9 @@ struct smi_info {
37705 };
37706
37707 #define smi_inc_stat(smi, stat) \
37708 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37709 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37710 #define smi_get_stat(smi, stat) \
37711 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37712 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37713
37714 #define SI_MAX_PARMS 4
37715
37716 @@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
37717 atomic_set(&new_smi->req_events, 0);
37718 new_smi->run_to_completion = 0;
37719 for (i = 0; i < SI_NUM_STATS; i++)
37720 - atomic_set(&new_smi->stats[i], 0);
37721 + atomic_set_unchecked(&new_smi->stats[i], 0);
37722
37723 new_smi->interrupt_disabled = 1;
37724 atomic_set(&new_smi->stop_operation, 0);
37725 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37726 index f895a8c..2bc9147 100644
37727 --- a/drivers/char/mem.c
37728 +++ b/drivers/char/mem.c
37729 @@ -18,6 +18,7 @@
37730 #include <linux/raw.h>
37731 #include <linux/tty.h>
37732 #include <linux/capability.h>
37733 +#include <linux/security.h>
37734 #include <linux/ptrace.h>
37735 #include <linux/device.h>
37736 #include <linux/highmem.h>
37737 @@ -37,6 +38,10 @@
37738
37739 #define DEVPORT_MINOR 4
37740
37741 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37742 +extern const struct file_operations grsec_fops;
37743 +#endif
37744 +
37745 static inline unsigned long size_inside_page(unsigned long start,
37746 unsigned long size)
37747 {
37748 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37749
37750 while (cursor < to) {
37751 if (!devmem_is_allowed(pfn)) {
37752 +#ifdef CONFIG_GRKERNSEC_KMEM
37753 + gr_handle_mem_readwrite(from, to);
37754 +#else
37755 printk(KERN_INFO
37756 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37757 current->comm, from, to);
37758 +#endif
37759 return 0;
37760 }
37761 cursor += PAGE_SIZE;
37762 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37763 }
37764 return 1;
37765 }
37766 +#elif defined(CONFIG_GRKERNSEC_KMEM)
37767 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37768 +{
37769 + return 0;
37770 +}
37771 #else
37772 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37773 {
37774 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37775
37776 while (count > 0) {
37777 unsigned long remaining;
37778 + char *temp;
37779
37780 sz = size_inside_page(p, count);
37781
37782 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37783 if (!ptr)
37784 return -EFAULT;
37785
37786 - remaining = copy_to_user(buf, ptr, sz);
37787 +#ifdef CONFIG_PAX_USERCOPY
37788 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37789 + if (!temp) {
37790 + unxlate_dev_mem_ptr(p, ptr);
37791 + return -ENOMEM;
37792 + }
37793 + memcpy(temp, ptr, sz);
37794 +#else
37795 + temp = ptr;
37796 +#endif
37797 +
37798 + remaining = copy_to_user(buf, temp, sz);
37799 +
37800 +#ifdef CONFIG_PAX_USERCOPY
37801 + kfree(temp);
37802 +#endif
37803 +
37804 unxlate_dev_mem_ptr(p, ptr);
37805 if (remaining)
37806 return -EFAULT;
37807 @@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37808 size_t count, loff_t *ppos)
37809 {
37810 unsigned long p = *ppos;
37811 - ssize_t low_count, read, sz;
37812 + ssize_t low_count, read, sz, err = 0;
37813 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37814 - int err = 0;
37815
37816 read = 0;
37817 if (p < (unsigned long) high_memory) {
37818 @@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37819 }
37820 #endif
37821 while (low_count > 0) {
37822 + char *temp;
37823 +
37824 sz = size_inside_page(p, low_count);
37825
37826 /*
37827 @@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37828 */
37829 kbuf = xlate_dev_kmem_ptr((char *)p);
37830
37831 - if (copy_to_user(buf, kbuf, sz))
37832 +#ifdef CONFIG_PAX_USERCOPY
37833 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37834 + if (!temp)
37835 + return -ENOMEM;
37836 + memcpy(temp, kbuf, sz);
37837 +#else
37838 + temp = kbuf;
37839 +#endif
37840 +
37841 + err = copy_to_user(buf, temp, sz);
37842 +
37843 +#ifdef CONFIG_PAX_USERCOPY
37844 + kfree(temp);
37845 +#endif
37846 +
37847 + if (err)
37848 return -EFAULT;
37849 buf += sz;
37850 p += sz;
37851 @@ -822,6 +869,9 @@ static const struct memdev {
37852 #ifdef CONFIG_PRINTK
37853 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
37854 #endif
37855 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37856 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37857 +#endif
37858 };
37859
37860 static int memory_open(struct inode *inode, struct file *filp)
37861 @@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
37862 continue;
37863
37864 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37865 - NULL, devlist[minor].name);
37866 + NULL, "%s", devlist[minor].name);
37867 }
37868
37869 return tty_init();
37870 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37871 index 9df78e2..01ba9ae 100644
37872 --- a/drivers/char/nvram.c
37873 +++ b/drivers/char/nvram.c
37874 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37875
37876 spin_unlock_irq(&rtc_lock);
37877
37878 - if (copy_to_user(buf, contents, tmp - contents))
37879 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37880 return -EFAULT;
37881
37882 *ppos = i;
37883 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37884 index d39cca6..8c1e269 100644
37885 --- a/drivers/char/pcmcia/synclink_cs.c
37886 +++ b/drivers/char/pcmcia/synclink_cs.c
37887 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37888
37889 if (debug_level >= DEBUG_LEVEL_INFO)
37890 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37891 - __FILE__, __LINE__, info->device_name, port->count);
37892 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37893
37894 - WARN_ON(!port->count);
37895 + WARN_ON(!atomic_read(&port->count));
37896
37897 if (tty_port_close_start(port, tty, filp) == 0)
37898 goto cleanup;
37899 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37900 cleanup:
37901 if (debug_level >= DEBUG_LEVEL_INFO)
37902 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37903 - tty->driver->name, port->count);
37904 + tty->driver->name, atomic_read(&port->count));
37905 }
37906
37907 /* Wait until the transmitter is empty.
37908 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37909
37910 if (debug_level >= DEBUG_LEVEL_INFO)
37911 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37912 - __FILE__, __LINE__, tty->driver->name, port->count);
37913 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37914
37915 /* If port is closing, signal caller to try again */
37916 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37917 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37918 goto cleanup;
37919 }
37920 spin_lock(&port->lock);
37921 - port->count++;
37922 + atomic_inc(&port->count);
37923 spin_unlock(&port->lock);
37924 spin_unlock_irqrestore(&info->netlock, flags);
37925
37926 - if (port->count == 1) {
37927 + if (atomic_read(&port->count) == 1) {
37928 /* 1st open on this device, init hardware */
37929 retval = startup(info, tty);
37930 if (retval < 0)
37931 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37932 unsigned short new_crctype;
37933
37934 /* return error if TTY interface open */
37935 - if (info->port.count)
37936 + if (atomic_read(&info->port.count))
37937 return -EBUSY;
37938
37939 switch (encoding)
37940 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37941
37942 /* arbitrate between network and tty opens */
37943 spin_lock_irqsave(&info->netlock, flags);
37944 - if (info->port.count != 0 || info->netcount != 0) {
37945 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37946 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37947 spin_unlock_irqrestore(&info->netlock, flags);
37948 return -EBUSY;
37949 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37950 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37951
37952 /* return error if TTY interface open */
37953 - if (info->port.count)
37954 + if (atomic_read(&info->port.count))
37955 return -EBUSY;
37956
37957 if (cmd != SIOCWANDEV)
37958 diff --git a/drivers/char/random.c b/drivers/char/random.c
37959 index 429b75b..03d60db 100644
37960 --- a/drivers/char/random.c
37961 +++ b/drivers/char/random.c
37962 @@ -270,10 +270,17 @@
37963 /*
37964 * Configuration information
37965 */
37966 +#ifdef CONFIG_GRKERNSEC_RANDNET
37967 +#define INPUT_POOL_SHIFT 14
37968 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
37969 +#define OUTPUT_POOL_SHIFT 12
37970 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
37971 +#else
37972 #define INPUT_POOL_SHIFT 12
37973 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
37974 #define OUTPUT_POOL_SHIFT 10
37975 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
37976 +#endif
37977 #define SEC_XFER_SIZE 512
37978 #define EXTRACT_SIZE 10
37979
37980 @@ -361,12 +368,19 @@ static struct poolinfo {
37981 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
37982 int tap1, tap2, tap3, tap4, tap5;
37983 } poolinfo_table[] = {
37984 +#ifdef CONFIG_GRKERNSEC_RANDNET
37985 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37986 + { S(512), 411, 308, 208, 104, 1 },
37987 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37988 + { S(128), 104, 76, 51, 25, 1 },
37989 +#else
37990 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
37991 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
37992 { S(128), 104, 76, 51, 25, 1 },
37993 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
37994 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
37995 { S(32), 26, 19, 14, 7, 1 },
37996 +#endif
37997 #if 0
37998 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
37999 { S(2048), 1638, 1231, 819, 411, 1 },
38000 @@ -524,8 +538,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38001 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38002 }
38003
38004 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38005 - ACCESS_ONCE(r->add_ptr) = i;
38006 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38007 + ACCESS_ONCE_RW(r->add_ptr) = i;
38008 smp_wmb();
38009
38010 if (out)
38011 @@ -1151,7 +1165,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38012
38013 extract_buf(r, tmp);
38014 i = min_t(int, nbytes, EXTRACT_SIZE);
38015 - if (copy_to_user(buf, tmp, i)) {
38016 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38017 ret = -EFAULT;
38018 break;
38019 }
38020 @@ -1507,7 +1521,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38021 #include <linux/sysctl.h>
38022
38023 static int min_read_thresh = 8, min_write_thresh;
38024 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
38025 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38026 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38027 static char sysctl_bootid[16];
38028
38029 @@ -1523,7 +1537,7 @@ static char sysctl_bootid[16];
38030 static int proc_do_uuid(struct ctl_table *table, int write,
38031 void __user *buffer, size_t *lenp, loff_t *ppos)
38032 {
38033 - struct ctl_table fake_table;
38034 + ctl_table_no_const fake_table;
38035 unsigned char buf[64], tmp_uuid[16], *uuid;
38036
38037 uuid = table->data;
38038 @@ -1553,7 +1567,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38039 static int proc_do_entropy(ctl_table *table, int write,
38040 void __user *buffer, size_t *lenp, loff_t *ppos)
38041 {
38042 - ctl_table fake_table;
38043 + ctl_table_no_const fake_table;
38044 int entropy_count;
38045
38046 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38047 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38048 index 7cc1fe22..b602d6b 100644
38049 --- a/drivers/char/sonypi.c
38050 +++ b/drivers/char/sonypi.c
38051 @@ -54,6 +54,7 @@
38052
38053 #include <asm/uaccess.h>
38054 #include <asm/io.h>
38055 +#include <asm/local.h>
38056
38057 #include <linux/sonypi.h>
38058
38059 @@ -490,7 +491,7 @@ static struct sonypi_device {
38060 spinlock_t fifo_lock;
38061 wait_queue_head_t fifo_proc_list;
38062 struct fasync_struct *fifo_async;
38063 - int open_count;
38064 + local_t open_count;
38065 int model;
38066 struct input_dev *input_jog_dev;
38067 struct input_dev *input_key_dev;
38068 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38069 static int sonypi_misc_release(struct inode *inode, struct file *file)
38070 {
38071 mutex_lock(&sonypi_device.lock);
38072 - sonypi_device.open_count--;
38073 + local_dec(&sonypi_device.open_count);
38074 mutex_unlock(&sonypi_device.lock);
38075 return 0;
38076 }
38077 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38078 {
38079 mutex_lock(&sonypi_device.lock);
38080 /* Flush input queue on first open */
38081 - if (!sonypi_device.open_count)
38082 + if (!local_read(&sonypi_device.open_count))
38083 kfifo_reset(&sonypi_device.fifo);
38084 - sonypi_device.open_count++;
38085 + local_inc(&sonypi_device.open_count);
38086 mutex_unlock(&sonypi_device.lock);
38087
38088 return 0;
38089 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38090 index 64420b3..5c40b56 100644
38091 --- a/drivers/char/tpm/tpm_acpi.c
38092 +++ b/drivers/char/tpm/tpm_acpi.c
38093 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38094 virt = acpi_os_map_memory(start, len);
38095 if (!virt) {
38096 kfree(log->bios_event_log);
38097 + log->bios_event_log = NULL;
38098 printk("%s: ERROR - Unable to map memory\n", __func__);
38099 return -EIO;
38100 }
38101
38102 - memcpy_fromio(log->bios_event_log, virt, len);
38103 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38104
38105 acpi_os_unmap_memory(virt, len);
38106 return 0;
38107 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38108 index 59f7cb2..bac8b6d 100644
38109 --- a/drivers/char/tpm/tpm_eventlog.c
38110 +++ b/drivers/char/tpm/tpm_eventlog.c
38111 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38112 event = addr;
38113
38114 if ((event->event_type == 0 && event->event_size == 0) ||
38115 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38116 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38117 return NULL;
38118
38119 return addr;
38120 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38121 return NULL;
38122
38123 if ((event->event_type == 0 && event->event_size == 0) ||
38124 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38125 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38126 return NULL;
38127
38128 (*pos)++;
38129 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38130 int i;
38131
38132 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38133 - seq_putc(m, data[i]);
38134 + if (!seq_putc(m, data[i]))
38135 + return -EFAULT;
38136
38137 return 0;
38138 }
38139 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38140 index feea87c..18aefff 100644
38141 --- a/drivers/char/virtio_console.c
38142 +++ b/drivers/char/virtio_console.c
38143 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38144 if (to_user) {
38145 ssize_t ret;
38146
38147 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38148 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38149 if (ret)
38150 return -EFAULT;
38151 } else {
38152 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38153 if (!port_has_data(port) && !port->host_connected)
38154 return 0;
38155
38156 - return fill_readbuf(port, ubuf, count, true);
38157 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38158 }
38159
38160 static int wait_port_writable(struct port *port, bool nonblock)
38161 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38162 index a33f46f..a720eed 100644
38163 --- a/drivers/clk/clk-composite.c
38164 +++ b/drivers/clk/clk-composite.c
38165 @@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38166 struct clk *clk;
38167 struct clk_init_data init;
38168 struct clk_composite *composite;
38169 - struct clk_ops *clk_composite_ops;
38170 + clk_ops_no_const *clk_composite_ops;
38171
38172 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38173 if (!composite) {
38174 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38175 index 81dd31a..ef5c542 100644
38176 --- a/drivers/clk/socfpga/clk.c
38177 +++ b/drivers/clk/socfpga/clk.c
38178 @@ -22,6 +22,7 @@
38179 #include <linux/clk-provider.h>
38180 #include <linux/io.h>
38181 #include <linux/of.h>
38182 +#include <asm/pgtable.h>
38183
38184 /* Clock Manager offsets */
38185 #define CLKMGR_CTRL 0x0
38186 @@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38187 streq(clk_name, "periph_pll") ||
38188 streq(clk_name, "sdram_pll")) {
38189 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38190 - clk_pll_ops.enable = clk_gate_ops.enable;
38191 - clk_pll_ops.disable = clk_gate_ops.disable;
38192 + pax_open_kernel();
38193 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38194 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38195 + pax_close_kernel();
38196 }
38197
38198 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38199 @@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38200 return parent_rate / div;
38201 }
38202
38203 -static struct clk_ops gateclk_ops = {
38204 +static clk_ops_no_const gateclk_ops __read_only = {
38205 .recalc_rate = socfpga_clk_recalc_rate,
38206 .get_parent = socfpga_clk_get_parent,
38207 .set_parent = socfpga_clk_set_parent,
38208 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38209 index caf41eb..223d27a 100644
38210 --- a/drivers/cpufreq/acpi-cpufreq.c
38211 +++ b/drivers/cpufreq/acpi-cpufreq.c
38212 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38213 return sprintf(buf, "%u\n", boost_enabled);
38214 }
38215
38216 -static struct global_attr global_boost = __ATTR(boost, 0644,
38217 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
38218 show_global_boost,
38219 store_global_boost);
38220
38221 @@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38222 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38223 per_cpu(acfreq_data, cpu) = data;
38224
38225 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38226 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38227 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38228 + pax_open_kernel();
38229 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38230 + pax_close_kernel();
38231 + }
38232
38233 result = acpi_processor_register_performance(data->acpi_data, cpu);
38234 if (result)
38235 @@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38236 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38237 break;
38238 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38239 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38240 + pax_open_kernel();
38241 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38242 + pax_close_kernel();
38243 break;
38244 default:
38245 break;
38246 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38247 index 8d19f7c..6bc2daa 100644
38248 --- a/drivers/cpufreq/cpufreq.c
38249 +++ b/drivers/cpufreq/cpufreq.c
38250 @@ -1885,7 +1885,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38251 #endif
38252
38253 mutex_lock(&cpufreq_governor_mutex);
38254 - list_del(&governor->governor_list);
38255 + pax_list_del(&governor->governor_list);
38256 mutex_unlock(&cpufreq_governor_mutex);
38257 return;
38258 }
38259 @@ -2115,7 +2115,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38260 return NOTIFY_OK;
38261 }
38262
38263 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38264 +static struct notifier_block cpufreq_cpu_notifier = {
38265 .notifier_call = cpufreq_cpu_callback,
38266 };
38267
38268 @@ -2148,8 +2148,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38269
38270 pr_debug("trying to register driver %s\n", driver_data->name);
38271
38272 - if (driver_data->setpolicy)
38273 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38274 + if (driver_data->setpolicy) {
38275 + pax_open_kernel();
38276 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38277 + pax_close_kernel();
38278 + }
38279
38280 write_lock_irqsave(&cpufreq_driver_lock, flags);
38281 if (cpufreq_driver) {
38282 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38283 index e6be635..f8a90dc 100644
38284 --- a/drivers/cpufreq/cpufreq_governor.c
38285 +++ b/drivers/cpufreq/cpufreq_governor.c
38286 @@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38287 struct dbs_data *dbs_data;
38288 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38289 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38290 - struct od_ops *od_ops = NULL;
38291 + const struct od_ops *od_ops = NULL;
38292 struct od_dbs_tuners *od_tuners = NULL;
38293 struct cs_dbs_tuners *cs_tuners = NULL;
38294 struct cpu_dbs_common_info *cpu_cdbs;
38295 @@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38296
38297 if ((cdata->governor == GOV_CONSERVATIVE) &&
38298 (!policy->governor->initialized)) {
38299 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38300 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38301
38302 cpufreq_register_notifier(cs_ops->notifier_block,
38303 CPUFREQ_TRANSITION_NOTIFIER);
38304 @@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38305
38306 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38307 (policy->governor->initialized == 1)) {
38308 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38309 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38310
38311 cpufreq_unregister_notifier(cs_ops->notifier_block,
38312 CPUFREQ_TRANSITION_NOTIFIER);
38313 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38314 index b5f2b86..daa801b 100644
38315 --- a/drivers/cpufreq/cpufreq_governor.h
38316 +++ b/drivers/cpufreq/cpufreq_governor.h
38317 @@ -205,7 +205,7 @@ struct common_dbs_data {
38318 void (*exit)(struct dbs_data *dbs_data);
38319
38320 /* Governor specific ops, see below */
38321 - void *gov_ops;
38322 + const void *gov_ops;
38323 };
38324
38325 /* Governor Per policy data */
38326 @@ -225,7 +225,7 @@ struct od_ops {
38327 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38328 unsigned int freq_next, unsigned int relation);
38329 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38330 -};
38331 +} __no_const;
38332
38333 struct cs_ops {
38334 struct notifier_block *notifier_block;
38335 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38336 index 18d4091..434be15 100644
38337 --- a/drivers/cpufreq/cpufreq_ondemand.c
38338 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38339 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38340
38341 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38342
38343 -static struct od_ops od_ops = {
38344 +static struct od_ops od_ops __read_only = {
38345 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38346 .powersave_bias_target = generic_powersave_bias_target,
38347 .freq_increase = dbs_freq_increase,
38348 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38349 (struct cpufreq_policy *, unsigned int, unsigned int),
38350 unsigned int powersave_bias)
38351 {
38352 - od_ops.powersave_bias_target = f;
38353 + pax_open_kernel();
38354 + *(void **)&od_ops.powersave_bias_target = f;
38355 + pax_close_kernel();
38356 od_set_powersave_bias(powersave_bias);
38357 }
38358 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38359
38360 void od_unregister_powersave_bias_handler(void)
38361 {
38362 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38363 + pax_open_kernel();
38364 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38365 + pax_close_kernel();
38366 od_set_powersave_bias(0);
38367 }
38368 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38369 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38370 index 4cf0d28..5830372 100644
38371 --- a/drivers/cpufreq/cpufreq_stats.c
38372 +++ b/drivers/cpufreq/cpufreq_stats.c
38373 @@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38374 }
38375
38376 /* priority=1 so this will get called before cpufreq_remove_dev */
38377 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38378 +static struct notifier_block cpufreq_stat_cpu_notifier = {
38379 .notifier_call = cpufreq_stat_cpu_callback,
38380 .priority = 1,
38381 };
38382 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38383 index d51f17ed..9f43b15 100644
38384 --- a/drivers/cpufreq/intel_pstate.c
38385 +++ b/drivers/cpufreq/intel_pstate.c
38386 @@ -112,10 +112,10 @@ struct pstate_funcs {
38387 struct cpu_defaults {
38388 struct pstate_adjust_policy pid_policy;
38389 struct pstate_funcs funcs;
38390 -};
38391 +} __do_const;
38392
38393 static struct pstate_adjust_policy pid_params;
38394 -static struct pstate_funcs pstate_funcs;
38395 +static struct pstate_funcs *pstate_funcs;
38396
38397 struct perf_limits {
38398 int no_turbo;
38399 @@ -462,7 +462,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38400
38401 cpu->pstate.current_pstate = pstate;
38402
38403 - pstate_funcs.set(pstate);
38404 + pstate_funcs->set(pstate);
38405 }
38406
38407 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38408 @@ -484,9 +484,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38409 {
38410 sprintf(cpu->name, "Intel 2nd generation core");
38411
38412 - cpu->pstate.min_pstate = pstate_funcs.get_min();
38413 - cpu->pstate.max_pstate = pstate_funcs.get_max();
38414 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
38415 + cpu->pstate.min_pstate = pstate_funcs->get_min();
38416 + cpu->pstate.max_pstate = pstate_funcs->get_max();
38417 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
38418
38419 /*
38420 * goto max pstate so we don't slow up boot if we are built-in if we are
38421 @@ -750,9 +750,9 @@ static int intel_pstate_msrs_not_valid(void)
38422 rdmsrl(MSR_IA32_APERF, aperf);
38423 rdmsrl(MSR_IA32_MPERF, mperf);
38424
38425 - if (!pstate_funcs.get_max() ||
38426 - !pstate_funcs.get_min() ||
38427 - !pstate_funcs.get_turbo())
38428 + if (!pstate_funcs->get_max() ||
38429 + !pstate_funcs->get_min() ||
38430 + !pstate_funcs->get_turbo())
38431 return -ENODEV;
38432
38433 rdmsrl(MSR_IA32_APERF, tmp);
38434 @@ -766,7 +766,7 @@ static int intel_pstate_msrs_not_valid(void)
38435 return 0;
38436 }
38437
38438 -static void copy_pid_params(struct pstate_adjust_policy *policy)
38439 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
38440 {
38441 pid_params.sample_rate_ms = policy->sample_rate_ms;
38442 pid_params.p_gain_pct = policy->p_gain_pct;
38443 @@ -778,10 +778,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
38444
38445 static void copy_cpu_funcs(struct pstate_funcs *funcs)
38446 {
38447 - pstate_funcs.get_max = funcs->get_max;
38448 - pstate_funcs.get_min = funcs->get_min;
38449 - pstate_funcs.get_turbo = funcs->get_turbo;
38450 - pstate_funcs.set = funcs->set;
38451 + pstate_funcs = funcs;
38452 }
38453
38454 #if IS_ENABLED(CONFIG_ACPI)
38455 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
38456 index 3d1cba9..0ab21d2 100644
38457 --- a/drivers/cpufreq/p4-clockmod.c
38458 +++ b/drivers/cpufreq/p4-clockmod.c
38459 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38460 case 0x0F: /* Core Duo */
38461 case 0x16: /* Celeron Core */
38462 case 0x1C: /* Atom */
38463 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38464 + pax_open_kernel();
38465 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38466 + pax_close_kernel();
38467 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
38468 case 0x0D: /* Pentium M (Dothan) */
38469 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38470 + pax_open_kernel();
38471 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38472 + pax_close_kernel();
38473 /* fall through */
38474 case 0x09: /* Pentium M (Banias) */
38475 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
38476 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38477
38478 /* on P-4s, the TSC runs with constant frequency independent whether
38479 * throttling is active or not. */
38480 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38481 + pax_open_kernel();
38482 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38483 + pax_close_kernel();
38484
38485 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
38486 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
38487 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
38488 index 724ffbd..ad83692 100644
38489 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
38490 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
38491 @@ -18,14 +18,12 @@
38492 #include <asm/head.h>
38493 #include <asm/timer.h>
38494
38495 -static struct cpufreq_driver *cpufreq_us3_driver;
38496 -
38497 struct us3_freq_percpu_info {
38498 struct cpufreq_frequency_table table[4];
38499 };
38500
38501 /* Indexed by cpu number. */
38502 -static struct us3_freq_percpu_info *us3_freq_table;
38503 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
38504
38505 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
38506 * in the Safari config register.
38507 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
38508
38509 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
38510 {
38511 - if (cpufreq_us3_driver) {
38512 - cpufreq_frequency_table_put_attr(policy->cpu);
38513 - us3_freq_target(policy, 0);
38514 - }
38515 + cpufreq_frequency_table_put_attr(policy->cpu);
38516 + us3_freq_target(policy, 0);
38517
38518 return 0;
38519 }
38520
38521 +static int __init us3_freq_init(void);
38522 +static void __exit us3_freq_exit(void);
38523 +
38524 +static struct cpufreq_driver cpufreq_us3_driver = {
38525 + .init = us3_freq_cpu_init,
38526 + .verify = cpufreq_generic_frequency_table_verify,
38527 + .target_index = us3_freq_target,
38528 + .get = us3_freq_get,
38529 + .exit = us3_freq_cpu_exit,
38530 + .owner = THIS_MODULE,
38531 + .name = "UltraSPARC-III",
38532 +
38533 +};
38534 +
38535 static int __init us3_freq_init(void)
38536 {
38537 unsigned long manuf, impl, ver;
38538 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
38539 (impl == CHEETAH_IMPL ||
38540 impl == CHEETAH_PLUS_IMPL ||
38541 impl == JAGUAR_IMPL ||
38542 - impl == PANTHER_IMPL)) {
38543 - struct cpufreq_driver *driver;
38544 -
38545 - ret = -ENOMEM;
38546 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
38547 - if (!driver)
38548 - goto err_out;
38549 -
38550 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
38551 - GFP_KERNEL);
38552 - if (!us3_freq_table)
38553 - goto err_out;
38554 -
38555 - driver->init = us3_freq_cpu_init;
38556 - driver->verify = cpufreq_generic_frequency_table_verify;
38557 - driver->target_index = us3_freq_target;
38558 - driver->get = us3_freq_get;
38559 - driver->exit = us3_freq_cpu_exit;
38560 - strcpy(driver->name, "UltraSPARC-III");
38561 -
38562 - cpufreq_us3_driver = driver;
38563 - ret = cpufreq_register_driver(driver);
38564 - if (ret)
38565 - goto err_out;
38566 -
38567 - return 0;
38568 -
38569 -err_out:
38570 - if (driver) {
38571 - kfree(driver);
38572 - cpufreq_us3_driver = NULL;
38573 - }
38574 - kfree(us3_freq_table);
38575 - us3_freq_table = NULL;
38576 - return ret;
38577 - }
38578 + impl == PANTHER_IMPL))
38579 + return cpufreq_register_driver(&cpufreq_us3_driver);
38580
38581 return -ENODEV;
38582 }
38583
38584 static void __exit us3_freq_exit(void)
38585 {
38586 - if (cpufreq_us3_driver) {
38587 - cpufreq_unregister_driver(cpufreq_us3_driver);
38588 - kfree(cpufreq_us3_driver);
38589 - cpufreq_us3_driver = NULL;
38590 - kfree(us3_freq_table);
38591 - us3_freq_table = NULL;
38592 - }
38593 + cpufreq_unregister_driver(&cpufreq_us3_driver);
38594 }
38595
38596 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
38597 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
38598 index 4e1daca..e707b61 100644
38599 --- a/drivers/cpufreq/speedstep-centrino.c
38600 +++ b/drivers/cpufreq/speedstep-centrino.c
38601 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
38602 !cpu_has(cpu, X86_FEATURE_EST))
38603 return -ENODEV;
38604
38605 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
38606 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38607 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
38608 + pax_open_kernel();
38609 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38610 + pax_close_kernel();
38611 + }
38612
38613 if (policy->cpu != 0)
38614 return -ENODEV;
38615 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
38616 index 06dbe7c..c2c8671 100644
38617 --- a/drivers/cpuidle/driver.c
38618 +++ b/drivers/cpuidle/driver.c
38619 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
38620
38621 static void poll_idle_init(struct cpuidle_driver *drv)
38622 {
38623 - struct cpuidle_state *state = &drv->states[0];
38624 + cpuidle_state_no_const *state = &drv->states[0];
38625
38626 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38627 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38628 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38629 index ca89412..a7b9c49 100644
38630 --- a/drivers/cpuidle/governor.c
38631 +++ b/drivers/cpuidle/governor.c
38632 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38633 mutex_lock(&cpuidle_lock);
38634 if (__cpuidle_find_governor(gov->name) == NULL) {
38635 ret = 0;
38636 - list_add_tail(&gov->governor_list, &cpuidle_governors);
38637 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38638 if (!cpuidle_curr_governor ||
38639 cpuidle_curr_governor->rating < gov->rating)
38640 cpuidle_switch_governor(gov);
38641 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38642 index e918b6d..f87ea80 100644
38643 --- a/drivers/cpuidle/sysfs.c
38644 +++ b/drivers/cpuidle/sysfs.c
38645 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38646 NULL
38647 };
38648
38649 -static struct attribute_group cpuidle_attr_group = {
38650 +static attribute_group_no_const cpuidle_attr_group = {
38651 .attrs = cpuidle_default_attrs,
38652 .name = "cpuidle",
38653 };
38654 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38655 index 12fea3e..1e28f47 100644
38656 --- a/drivers/crypto/hifn_795x.c
38657 +++ b/drivers/crypto/hifn_795x.c
38658 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38659 MODULE_PARM_DESC(hifn_pll_ref,
38660 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38661
38662 -static atomic_t hifn_dev_number;
38663 +static atomic_unchecked_t hifn_dev_number;
38664
38665 #define ACRYPTO_OP_DECRYPT 0
38666 #define ACRYPTO_OP_ENCRYPT 1
38667 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38668 goto err_out_disable_pci_device;
38669
38670 snprintf(name, sizeof(name), "hifn%d",
38671 - atomic_inc_return(&hifn_dev_number)-1);
38672 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
38673
38674 err = pci_request_regions(pdev, name);
38675 if (err)
38676 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38677 index a0b2f7e..1b6f028 100644
38678 --- a/drivers/devfreq/devfreq.c
38679 +++ b/drivers/devfreq/devfreq.c
38680 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38681 goto err_out;
38682 }
38683
38684 - list_add(&governor->node, &devfreq_governor_list);
38685 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38686
38687 list_for_each_entry(devfreq, &devfreq_list, node) {
38688 int ret = 0;
38689 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38690 }
38691 }
38692
38693 - list_del(&governor->node);
38694 + pax_list_del((struct list_head *)&governor->node);
38695 err_out:
38696 mutex_unlock(&devfreq_list_lock);
38697
38698 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
38699 index 0d765c0..60b7480 100644
38700 --- a/drivers/dma/sh/shdmac.c
38701 +++ b/drivers/dma/sh/shdmac.c
38702 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38703 return ret;
38704 }
38705
38706 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38707 +static struct notifier_block sh_dmae_nmi_notifier = {
38708 .notifier_call = sh_dmae_nmi_handler,
38709
38710 /* Run before NMI debug handler and KGDB */
38711 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38712 index 1026743..80b081c 100644
38713 --- a/drivers/edac/edac_device.c
38714 +++ b/drivers/edac/edac_device.c
38715 @@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38716 */
38717 int edac_device_alloc_index(void)
38718 {
38719 - static atomic_t device_indexes = ATOMIC_INIT(0);
38720 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38721
38722 - return atomic_inc_return(&device_indexes) - 1;
38723 + return atomic_inc_return_unchecked(&device_indexes) - 1;
38724 }
38725 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38726
38727 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38728 index 9f7e0e60..348c875 100644
38729 --- a/drivers/edac/edac_mc_sysfs.c
38730 +++ b/drivers/edac/edac_mc_sysfs.c
38731 @@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
38732 struct dev_ch_attribute {
38733 struct device_attribute attr;
38734 int channel;
38735 -};
38736 +} __do_const;
38737
38738 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38739 struct dev_ch_attribute dev_attr_legacy_##_name = \
38740 @@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38741 }
38742
38743 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38744 + pax_open_kernel();
38745 if (mci->get_sdram_scrub_rate) {
38746 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38747 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38748 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38749 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38750 }
38751 if (mci->set_sdram_scrub_rate) {
38752 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38753 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38754 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38755 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38756 }
38757 + pax_close_kernel();
38758 err = device_create_file(&mci->dev,
38759 &dev_attr_sdram_scrub_rate);
38760 if (err) {
38761 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38762 index 2cf44b4d..6dd2dc7 100644
38763 --- a/drivers/edac/edac_pci.c
38764 +++ b/drivers/edac/edac_pci.c
38765 @@ -29,7 +29,7 @@
38766
38767 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38768 static LIST_HEAD(edac_pci_list);
38769 -static atomic_t pci_indexes = ATOMIC_INIT(0);
38770 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38771
38772 /*
38773 * edac_pci_alloc_ctl_info
38774 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38775 */
38776 int edac_pci_alloc_index(void)
38777 {
38778 - return atomic_inc_return(&pci_indexes) - 1;
38779 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
38780 }
38781 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38782
38783 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38784 index e8658e4..22746d6 100644
38785 --- a/drivers/edac/edac_pci_sysfs.c
38786 +++ b/drivers/edac/edac_pci_sysfs.c
38787 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38788 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38789 static int edac_pci_poll_msec = 1000; /* one second workq period */
38790
38791 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
38792 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38793 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38794 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38795
38796 static struct kobject *edac_pci_top_main_kobj;
38797 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38798 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38799 void *value;
38800 ssize_t(*show) (void *, char *);
38801 ssize_t(*store) (void *, const char *, size_t);
38802 -};
38803 +} __do_const;
38804
38805 /* Set of show/store abstract level functions for PCI Parity object */
38806 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38807 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38808 edac_printk(KERN_CRIT, EDAC_PCI,
38809 "Signaled System Error on %s\n",
38810 pci_name(dev));
38811 - atomic_inc(&pci_nonparity_count);
38812 + atomic_inc_unchecked(&pci_nonparity_count);
38813 }
38814
38815 if (status & (PCI_STATUS_PARITY)) {
38816 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38817 "Master Data Parity Error on %s\n",
38818 pci_name(dev));
38819
38820 - atomic_inc(&pci_parity_count);
38821 + atomic_inc_unchecked(&pci_parity_count);
38822 }
38823
38824 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38825 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38826 "Detected Parity Error on %s\n",
38827 pci_name(dev));
38828
38829 - atomic_inc(&pci_parity_count);
38830 + atomic_inc_unchecked(&pci_parity_count);
38831 }
38832 }
38833
38834 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38835 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38836 "Signaled System Error on %s\n",
38837 pci_name(dev));
38838 - atomic_inc(&pci_nonparity_count);
38839 + atomic_inc_unchecked(&pci_nonparity_count);
38840 }
38841
38842 if (status & (PCI_STATUS_PARITY)) {
38843 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38844 "Master Data Parity Error on "
38845 "%s\n", pci_name(dev));
38846
38847 - atomic_inc(&pci_parity_count);
38848 + atomic_inc_unchecked(&pci_parity_count);
38849 }
38850
38851 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38852 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38853 "Detected Parity Error on %s\n",
38854 pci_name(dev));
38855
38856 - atomic_inc(&pci_parity_count);
38857 + atomic_inc_unchecked(&pci_parity_count);
38858 }
38859 }
38860 }
38861 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38862 if (!check_pci_errors)
38863 return;
38864
38865 - before_count = atomic_read(&pci_parity_count);
38866 + before_count = atomic_read_unchecked(&pci_parity_count);
38867
38868 /* scan all PCI devices looking for a Parity Error on devices and
38869 * bridges.
38870 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38871 /* Only if operator has selected panic on PCI Error */
38872 if (edac_pci_get_panic_on_pe()) {
38873 /* If the count is different 'after' from 'before' */
38874 - if (before_count != atomic_read(&pci_parity_count))
38875 + if (before_count != atomic_read_unchecked(&pci_parity_count))
38876 panic("EDAC: PCI Parity Error");
38877 }
38878 }
38879 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38880 index 51b7e3a..aa8a3e8 100644
38881 --- a/drivers/edac/mce_amd.h
38882 +++ b/drivers/edac/mce_amd.h
38883 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
38884 bool (*mc0_mce)(u16, u8);
38885 bool (*mc1_mce)(u16, u8);
38886 bool (*mc2_mce)(u16, u8);
38887 -};
38888 +} __no_const;
38889
38890 void amd_report_gart_errors(bool);
38891 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38892 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38893 index 57ea7f4..af06b76 100644
38894 --- a/drivers/firewire/core-card.c
38895 +++ b/drivers/firewire/core-card.c
38896 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38897 const struct fw_card_driver *driver,
38898 struct device *device)
38899 {
38900 - static atomic_t index = ATOMIC_INIT(-1);
38901 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
38902
38903 - card->index = atomic_inc_return(&index);
38904 + card->index = atomic_inc_return_unchecked(&index);
38905 card->driver = driver;
38906 card->device = device;
38907 card->current_tlabel = 0;
38908 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38909
38910 void fw_core_remove_card(struct fw_card *card)
38911 {
38912 - struct fw_card_driver dummy_driver = dummy_driver_template;
38913 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
38914
38915 card->driver->update_phy_reg(card, 4,
38916 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38917 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38918 index de4aa40..49ab1f2 100644
38919 --- a/drivers/firewire/core-device.c
38920 +++ b/drivers/firewire/core-device.c
38921 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38922 struct config_rom_attribute {
38923 struct device_attribute attr;
38924 u32 key;
38925 -};
38926 +} __do_const;
38927
38928 static ssize_t show_immediate(struct device *dev,
38929 struct device_attribute *dattr, char *buf)
38930 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38931 index 0e79951..b180217 100644
38932 --- a/drivers/firewire/core-transaction.c
38933 +++ b/drivers/firewire/core-transaction.c
38934 @@ -38,6 +38,7 @@
38935 #include <linux/timer.h>
38936 #include <linux/types.h>
38937 #include <linux/workqueue.h>
38938 +#include <linux/sched.h>
38939
38940 #include <asm/byteorder.h>
38941
38942 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38943 index 515a42c..5ecf3ba 100644
38944 --- a/drivers/firewire/core.h
38945 +++ b/drivers/firewire/core.h
38946 @@ -111,6 +111,7 @@ struct fw_card_driver {
38947
38948 int (*stop_iso)(struct fw_iso_context *ctx);
38949 };
38950 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38951
38952 void fw_card_initialize(struct fw_card *card,
38953 const struct fw_card_driver *driver, struct device *device);
38954 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38955 index 94a58a0..f5eba42 100644
38956 --- a/drivers/firmware/dmi-id.c
38957 +++ b/drivers/firmware/dmi-id.c
38958 @@ -16,7 +16,7 @@
38959 struct dmi_device_attribute{
38960 struct device_attribute dev_attr;
38961 int field;
38962 -};
38963 +} __do_const;
38964 #define to_dmi_dev_attr(_dev_attr) \
38965 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38966
38967 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38968 index c7e81ff..94a7401 100644
38969 --- a/drivers/firmware/dmi_scan.c
38970 +++ b/drivers/firmware/dmi_scan.c
38971 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38972 if (buf == NULL)
38973 return -1;
38974
38975 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38976 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38977
38978 iounmap(buf);
38979 return 0;
38980 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
38981 index 1491dd4..aa910db 100644
38982 --- a/drivers/firmware/efi/cper.c
38983 +++ b/drivers/firmware/efi/cper.c
38984 @@ -41,12 +41,12 @@
38985 */
38986 u64 cper_next_record_id(void)
38987 {
38988 - static atomic64_t seq;
38989 + static atomic64_unchecked_t seq;
38990
38991 - if (!atomic64_read(&seq))
38992 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
38993 + if (!atomic64_read_unchecked(&seq))
38994 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
38995
38996 - return atomic64_inc_return(&seq);
38997 + return atomic64_inc_return_unchecked(&seq);
38998 }
38999 EXPORT_SYMBOL_GPL(cper_next_record_id);
39000
39001 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39002 index 2e2fbde..7676c8b 100644
39003 --- a/drivers/firmware/efi/efi.c
39004 +++ b/drivers/firmware/efi/efi.c
39005 @@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39006 };
39007
39008 static struct efivars generic_efivars;
39009 -static struct efivar_operations generic_ops;
39010 +static efivar_operations_no_const generic_ops __read_only;
39011
39012 static int generic_ops_register(void)
39013 {
39014 - generic_ops.get_variable = efi.get_variable;
39015 - generic_ops.set_variable = efi.set_variable;
39016 - generic_ops.get_next_variable = efi.get_next_variable;
39017 - generic_ops.query_variable_store = efi_query_variable_store;
39018 + pax_open_kernel();
39019 + *(void **)&generic_ops.get_variable = efi.get_variable;
39020 + *(void **)&generic_ops.set_variable = efi.set_variable;
39021 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39022 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39023 + pax_close_kernel();
39024
39025 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39026 }
39027 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39028 index 3dc2482..7bd2f61 100644
39029 --- a/drivers/firmware/efi/efivars.c
39030 +++ b/drivers/firmware/efi/efivars.c
39031 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39032 static int
39033 create_efivars_bin_attributes(void)
39034 {
39035 - struct bin_attribute *attr;
39036 + bin_attribute_no_const *attr;
39037 int error;
39038
39039 /* new_var */
39040 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39041 index 2a90ba6..07f3733 100644
39042 --- a/drivers/firmware/google/memconsole.c
39043 +++ b/drivers/firmware/google/memconsole.c
39044 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39045 if (!found_memconsole())
39046 return -ENODEV;
39047
39048 - memconsole_bin_attr.size = memconsole_length;
39049 + pax_open_kernel();
39050 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39051 + pax_close_kernel();
39052
39053 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39054
39055 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39056 index 814addb..0937d7f 100644
39057 --- a/drivers/gpio/gpio-ich.c
39058 +++ b/drivers/gpio/gpio-ich.c
39059 @@ -71,7 +71,7 @@ struct ichx_desc {
39060 /* Some chipsets have quirks, let these use their own request/get */
39061 int (*request)(struct gpio_chip *chip, unsigned offset);
39062 int (*get)(struct gpio_chip *chip, unsigned offset);
39063 -};
39064 +} __do_const;
39065
39066 static struct {
39067 spinlock_t lock;
39068 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39069 index 9902732..64b62dd 100644
39070 --- a/drivers/gpio/gpio-vr41xx.c
39071 +++ b/drivers/gpio/gpio-vr41xx.c
39072 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39073 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39074 maskl, pendl, maskh, pendh);
39075
39076 - atomic_inc(&irq_err_count);
39077 + atomic_inc_unchecked(&irq_err_count);
39078
39079 return -EINVAL;
39080 }
39081 diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c
39082 index 62d0ff3..073dbf3 100644
39083 --- a/drivers/gpu/drm/armada/armada_drv.c
39084 +++ b/drivers/gpu/drm/armada/armada_drv.c
39085 @@ -68,15 +68,7 @@ void __armada_drm_queue_unref_work(struct drm_device *dev,
39086 {
39087 struct armada_private *priv = dev->dev_private;
39088
39089 - /*
39090 - * Yes, we really must jump through these hoops just to store a
39091 - * _pointer_ to something into the kfifo. This is utterly insane
39092 - * and idiotic, because it kfifo requires the _data_ pointed to by
39093 - * the pointer const, not the pointer itself. Not only that, but
39094 - * you have to pass a pointer _to_ the pointer you want stored.
39095 - */
39096 - const struct drm_framebuffer *silly_api_alert = fb;
39097 - WARN_ON(!kfifo_put(&priv->fb_unref, &silly_api_alert));
39098 + WARN_ON(!kfifo_put(&priv->fb_unref, fb));
39099 schedule_work(&priv->fb_unref_work);
39100 }
39101
39102 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39103 index d6cf77c..2842146 100644
39104 --- a/drivers/gpu/drm/drm_crtc.c
39105 +++ b/drivers/gpu/drm/drm_crtc.c
39106 @@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39107 goto done;
39108 }
39109
39110 - if (copy_to_user(&enum_ptr[copied].name,
39111 + if (copy_to_user(enum_ptr[copied].name,
39112 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39113 ret = -EFAULT;
39114 goto done;
39115 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39116 index 01361ab..891e821 100644
39117 --- a/drivers/gpu/drm/drm_crtc_helper.c
39118 +++ b/drivers/gpu/drm/drm_crtc_helper.c
39119 @@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39120 struct drm_crtc *tmp;
39121 int crtc_mask = 1;
39122
39123 - WARN(!crtc, "checking null crtc?\n");
39124 + BUG_ON(!crtc);
39125
39126 dev = crtc->dev;
39127
39128 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39129 index d9137e4..69b73a0 100644
39130 --- a/drivers/gpu/drm/drm_drv.c
39131 +++ b/drivers/gpu/drm/drm_drv.c
39132 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39133 /**
39134 * Copy and IOCTL return string to user space
39135 */
39136 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39137 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39138 {
39139 int len;
39140
39141 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39142 struct drm_file *file_priv = filp->private_data;
39143 struct drm_device *dev;
39144 const struct drm_ioctl_desc *ioctl = NULL;
39145 - drm_ioctl_t *func;
39146 + drm_ioctl_no_const_t func;
39147 unsigned int nr = DRM_IOCTL_NR(cmd);
39148 int retcode = -EINVAL;
39149 char stack_kdata[128];
39150 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39151 index c5b929c..8a3b8be 100644
39152 --- a/drivers/gpu/drm/drm_fops.c
39153 +++ b/drivers/gpu/drm/drm_fops.c
39154 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39155 if (drm_device_is_unplugged(dev))
39156 return -ENODEV;
39157
39158 - if (!dev->open_count++)
39159 + if (local_inc_return(&dev->open_count) == 1)
39160 need_setup = 1;
39161 mutex_lock(&dev->struct_mutex);
39162 old_imapping = inode->i_mapping;
39163 @@ -127,7 +127,7 @@ err_undo:
39164 iput(container_of(dev->dev_mapping, struct inode, i_data));
39165 dev->dev_mapping = old_mapping;
39166 mutex_unlock(&dev->struct_mutex);
39167 - dev->open_count--;
39168 + local_dec(&dev->open_count);
39169 return retcode;
39170 }
39171 EXPORT_SYMBOL(drm_open);
39172 @@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39173
39174 mutex_lock(&drm_global_mutex);
39175
39176 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39177 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39178
39179 if (dev->driver->preclose)
39180 dev->driver->preclose(dev, file_priv);
39181 @@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39182 * Begin inline drm_release
39183 */
39184
39185 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39186 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39187 task_pid_nr(current),
39188 (long)old_encode_dev(file_priv->minor->device),
39189 - dev->open_count);
39190 + local_read(&dev->open_count));
39191
39192 /* Release any auth tokens that might point to this file_priv,
39193 (do that under the drm_global_mutex) */
39194 @@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39195 * End inline drm_release
39196 */
39197
39198 - if (!--dev->open_count) {
39199 + if (local_dec_and_test(&dev->open_count)) {
39200 if (atomic_read(&dev->ioctl_count)) {
39201 DRM_ERROR("Device busy: %d\n",
39202 atomic_read(&dev->ioctl_count));
39203 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39204 index 3d2e91c..d31c4c9 100644
39205 --- a/drivers/gpu/drm/drm_global.c
39206 +++ b/drivers/gpu/drm/drm_global.c
39207 @@ -36,7 +36,7 @@
39208 struct drm_global_item {
39209 struct mutex mutex;
39210 void *object;
39211 - int refcount;
39212 + atomic_t refcount;
39213 };
39214
39215 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39216 @@ -49,7 +49,7 @@ void drm_global_init(void)
39217 struct drm_global_item *item = &glob[i];
39218 mutex_init(&item->mutex);
39219 item->object = NULL;
39220 - item->refcount = 0;
39221 + atomic_set(&item->refcount, 0);
39222 }
39223 }
39224
39225 @@ -59,7 +59,7 @@ void drm_global_release(void)
39226 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39227 struct drm_global_item *item = &glob[i];
39228 BUG_ON(item->object != NULL);
39229 - BUG_ON(item->refcount != 0);
39230 + BUG_ON(atomic_read(&item->refcount) != 0);
39231 }
39232 }
39233
39234 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39235 struct drm_global_item *item = &glob[ref->global_type];
39236
39237 mutex_lock(&item->mutex);
39238 - if (item->refcount == 0) {
39239 + if (atomic_read(&item->refcount) == 0) {
39240 item->object = kzalloc(ref->size, GFP_KERNEL);
39241 if (unlikely(item->object == NULL)) {
39242 ret = -ENOMEM;
39243 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39244 goto out_err;
39245
39246 }
39247 - ++item->refcount;
39248 + atomic_inc(&item->refcount);
39249 ref->object = item->object;
39250 mutex_unlock(&item->mutex);
39251 return 0;
39252 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39253 struct drm_global_item *item = &glob[ref->global_type];
39254
39255 mutex_lock(&item->mutex);
39256 - BUG_ON(item->refcount == 0);
39257 + BUG_ON(atomic_read(&item->refcount) == 0);
39258 BUG_ON(ref->object != item->object);
39259 - if (--item->refcount == 0) {
39260 + if (atomic_dec_and_test(&item->refcount)) {
39261 ref->release(ref);
39262 item->object = NULL;
39263 }
39264 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39265 index 7d5a152..d7186da 100644
39266 --- a/drivers/gpu/drm/drm_info.c
39267 +++ b/drivers/gpu/drm/drm_info.c
39268 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39269 struct drm_local_map *map;
39270 struct drm_map_list *r_list;
39271
39272 - /* Hardcoded from _DRM_FRAME_BUFFER,
39273 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39274 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39275 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39276 + static const char * const types[] = {
39277 + [_DRM_FRAME_BUFFER] = "FB",
39278 + [_DRM_REGISTERS] = "REG",
39279 + [_DRM_SHM] = "SHM",
39280 + [_DRM_AGP] = "AGP",
39281 + [_DRM_SCATTER_GATHER] = "SG",
39282 + [_DRM_CONSISTENT] = "PCI",
39283 + [_DRM_GEM] = "GEM" };
39284 const char *type;
39285 int i;
39286
39287 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39288 map = r_list->map;
39289 if (!map)
39290 continue;
39291 - if (map->type < 0 || map->type > 5)
39292 + if (map->type >= ARRAY_SIZE(types))
39293 type = "??";
39294 else
39295 type = types[map->type];
39296 @@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39297 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39298 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39299 vma->vm_flags & VM_IO ? 'i' : '-',
39300 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39301 + 0);
39302 +#else
39303 vma->vm_pgoff);
39304 +#endif
39305
39306 #if defined(__i386__)
39307 pgprot = pgprot_val(vma->vm_page_prot);
39308 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39309 index 2f4c434..dd12cd2 100644
39310 --- a/drivers/gpu/drm/drm_ioc32.c
39311 +++ b/drivers/gpu/drm/drm_ioc32.c
39312 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39313 request = compat_alloc_user_space(nbytes);
39314 if (!access_ok(VERIFY_WRITE, request, nbytes))
39315 return -EFAULT;
39316 - list = (struct drm_buf_desc *) (request + 1);
39317 + list = (struct drm_buf_desc __user *) (request + 1);
39318
39319 if (__put_user(count, &request->count)
39320 || __put_user(list, &request->list))
39321 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39322 request = compat_alloc_user_space(nbytes);
39323 if (!access_ok(VERIFY_WRITE, request, nbytes))
39324 return -EFAULT;
39325 - list = (struct drm_buf_pub *) (request + 1);
39326 + list = (struct drm_buf_pub __user *) (request + 1);
39327
39328 if (__put_user(count, &request->count)
39329 || __put_user(list, &request->list))
39330 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39331 return 0;
39332 }
39333
39334 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39335 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39336 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39337 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39338 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39339 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39340 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39341 {
39342 unsigned int nr = DRM_IOCTL_NR(cmd);
39343 - drm_ioctl_compat_t *fn;
39344 int ret;
39345
39346 /* Assume that ioctls without an explicit compat routine will just
39347 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39348 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39349 return drm_ioctl(filp, cmd, arg);
39350
39351 - fn = drm_compat_ioctls[nr];
39352 -
39353 - if (fn != NULL)
39354 - ret = (*fn) (filp, cmd, arg);
39355 + if (drm_compat_ioctls[nr] != NULL)
39356 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39357 else
39358 ret = drm_ioctl(filp, cmd, arg);
39359
39360 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39361 index 66dd3a0..3bed6c4 100644
39362 --- a/drivers/gpu/drm/drm_stub.c
39363 +++ b/drivers/gpu/drm/drm_stub.c
39364 @@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39365
39366 drm_device_set_unplugged(dev);
39367
39368 - if (dev->open_count == 0) {
39369 + if (local_read(&dev->open_count) == 0) {
39370 drm_put_dev(dev);
39371 }
39372 mutex_unlock(&drm_global_mutex);
39373 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39374 index c22c309..ae758c3 100644
39375 --- a/drivers/gpu/drm/drm_sysfs.c
39376 +++ b/drivers/gpu/drm/drm_sysfs.c
39377 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39378 */
39379 int drm_sysfs_device_add(struct drm_minor *minor)
39380 {
39381 - char *minor_str;
39382 + const char *minor_str;
39383 int r;
39384
39385 if (minor->type == DRM_MINOR_CONTROL)
39386 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39387 index d4d16ed..8fb0b51 100644
39388 --- a/drivers/gpu/drm/i810/i810_drv.h
39389 +++ b/drivers/gpu/drm/i810/i810_drv.h
39390 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39391 int page_flipping;
39392
39393 wait_queue_head_t irq_queue;
39394 - atomic_t irq_received;
39395 - atomic_t irq_emitted;
39396 + atomic_unchecked_t irq_received;
39397 + atomic_unchecked_t irq_emitted;
39398
39399 int front_offset;
39400 } drm_i810_private_t;
39401 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
39402 index 6ed45a9..eb6dc41 100644
39403 --- a/drivers/gpu/drm/i915/i915_debugfs.c
39404 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
39405 @@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
39406 I915_READ(GTIMR));
39407 }
39408 seq_printf(m, "Interrupts received: %d\n",
39409 - atomic_read(&dev_priv->irq_received));
39410 + atomic_read_unchecked(&dev_priv->irq_received));
39411 for_each_ring(ring, dev_priv, i) {
39412 if (INTEL_INFO(dev)->gen >= 6) {
39413 seq_printf(m,
39414 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
39415 index 5c64842..f14bdf8 100644
39416 --- a/drivers/gpu/drm/i915/i915_dma.c
39417 +++ b/drivers/gpu/drm/i915/i915_dma.c
39418 @@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
39419 bool can_switch;
39420
39421 spin_lock(&dev->count_lock);
39422 - can_switch = (dev->open_count == 0);
39423 + can_switch = (local_read(&dev->open_count) == 0);
39424 spin_unlock(&dev->count_lock);
39425 return can_switch;
39426 }
39427 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
39428 index 90fcccb..b8aabc9 100644
39429 --- a/drivers/gpu/drm/i915/i915_drv.h
39430 +++ b/drivers/gpu/drm/i915/i915_drv.h
39431 @@ -1325,7 +1325,7 @@ typedef struct drm_i915_private {
39432 drm_dma_handle_t *status_page_dmah;
39433 struct resource mch_res;
39434
39435 - atomic_t irq_received;
39436 + atomic_unchecked_t irq_received;
39437
39438 /* protects the irq masks */
39439 spinlock_t irq_lock;
39440 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39441 index a3ba9a8..ee52ddd 100644
39442 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39443 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39444 @@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
39445
39446 static int
39447 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
39448 - int count)
39449 + unsigned int count)
39450 {
39451 - int i;
39452 + unsigned int i;
39453 unsigned relocs_total = 0;
39454 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
39455
39456 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
39457 index 3c59584..500f2e9 100644
39458 --- a/drivers/gpu/drm/i915/i915_ioc32.c
39459 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
39460 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
39461 (unsigned long)request);
39462 }
39463
39464 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39465 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
39466 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
39467 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
39468 [DRM_I915_GETPARAM] = compat_i915_getparam,
39469 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39470 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39471 {
39472 unsigned int nr = DRM_IOCTL_NR(cmd);
39473 - drm_ioctl_compat_t *fn = NULL;
39474 int ret;
39475
39476 if (nr < DRM_COMMAND_BASE)
39477 return drm_compat_ioctl(filp, cmd, arg);
39478
39479 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
39480 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39481 -
39482 - if (fn != NULL)
39483 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
39484 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39485 ret = (*fn) (filp, cmd, arg);
39486 - else
39487 + } else
39488 ret = drm_ioctl(filp, cmd, arg);
39489
39490 return ret;
39491 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
39492 index f13d5ed..8e6f36d 100644
39493 --- a/drivers/gpu/drm/i915/i915_irq.c
39494 +++ b/drivers/gpu/drm/i915/i915_irq.c
39495 @@ -1420,7 +1420,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
39496 int pipe;
39497 u32 pipe_stats[I915_MAX_PIPES];
39498
39499 - atomic_inc(&dev_priv->irq_received);
39500 + atomic_inc_unchecked(&dev_priv->irq_received);
39501
39502 while (true) {
39503 iir = I915_READ(VLV_IIR);
39504 @@ -1730,7 +1730,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
39505 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
39506 irqreturn_t ret = IRQ_NONE;
39507
39508 - atomic_inc(&dev_priv->irq_received);
39509 + atomic_inc_unchecked(&dev_priv->irq_received);
39510
39511 /* We get interrupts on unclaimed registers, so check for this before we
39512 * do any I915_{READ,WRITE}. */
39513 @@ -1800,7 +1800,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
39514 uint32_t tmp = 0;
39515 enum pipe pipe;
39516
39517 - atomic_inc(&dev_priv->irq_received);
39518 + atomic_inc_unchecked(&dev_priv->irq_received);
39519
39520 master_ctl = I915_READ(GEN8_MASTER_IRQ);
39521 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
39522 @@ -2624,7 +2624,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
39523 {
39524 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39525
39526 - atomic_set(&dev_priv->irq_received, 0);
39527 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39528
39529 I915_WRITE(HWSTAM, 0xeffe);
39530
39531 @@ -2642,7 +2642,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
39532 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39533 int pipe;
39534
39535 - atomic_set(&dev_priv->irq_received, 0);
39536 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39537
39538 /* VLV magic */
39539 I915_WRITE(VLV_IMR, 0);
39540 @@ -2673,7 +2673,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
39541 struct drm_i915_private *dev_priv = dev->dev_private;
39542 int pipe;
39543
39544 - atomic_set(&dev_priv->irq_received, 0);
39545 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39546
39547 I915_WRITE(GEN8_MASTER_IRQ, 0);
39548 POSTING_READ(GEN8_MASTER_IRQ);
39549 @@ -2999,7 +2999,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
39550 if (!dev_priv)
39551 return;
39552
39553 - atomic_set(&dev_priv->irq_received, 0);
39554 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39555
39556 I915_WRITE(GEN8_MASTER_IRQ, 0);
39557
39558 @@ -3093,7 +3093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39559 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39560 int pipe;
39561
39562 - atomic_set(&dev_priv->irq_received, 0);
39563 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39564
39565 for_each_pipe(pipe)
39566 I915_WRITE(PIPESTAT(pipe), 0);
39567 @@ -3179,7 +3179,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39568 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39569 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39570
39571 - atomic_inc(&dev_priv->irq_received);
39572 + atomic_inc_unchecked(&dev_priv->irq_received);
39573
39574 iir = I915_READ16(IIR);
39575 if (iir == 0)
39576 @@ -3254,7 +3254,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39577 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39578 int pipe;
39579
39580 - atomic_set(&dev_priv->irq_received, 0);
39581 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39582
39583 if (I915_HAS_HOTPLUG(dev)) {
39584 I915_WRITE(PORT_HOTPLUG_EN, 0);
39585 @@ -3361,7 +3361,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39586 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39587 int pipe, ret = IRQ_NONE;
39588
39589 - atomic_inc(&dev_priv->irq_received);
39590 + atomic_inc_unchecked(&dev_priv->irq_received);
39591
39592 iir = I915_READ(IIR);
39593 do {
39594 @@ -3488,7 +3488,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39595 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39596 int pipe;
39597
39598 - atomic_set(&dev_priv->irq_received, 0);
39599 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39600
39601 I915_WRITE(PORT_HOTPLUG_EN, 0);
39602 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39603 @@ -3604,7 +3604,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39604 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39605 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39606
39607 - atomic_inc(&dev_priv->irq_received);
39608 + atomic_inc_unchecked(&dev_priv->irq_received);
39609
39610 iir = I915_READ(IIR);
39611
39612 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39613 index 2bde35d..529646c 100644
39614 --- a/drivers/gpu/drm/i915/intel_display.c
39615 +++ b/drivers/gpu/drm/i915/intel_display.c
39616 @@ -10492,13 +10492,13 @@ struct intel_quirk {
39617 int subsystem_vendor;
39618 int subsystem_device;
39619 void (*hook)(struct drm_device *dev);
39620 -};
39621 +} __do_const;
39622
39623 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39624 struct intel_dmi_quirk {
39625 void (*hook)(struct drm_device *dev);
39626 const struct dmi_system_id (*dmi_id_list)[];
39627 -};
39628 +} __do_const;
39629
39630 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39631 {
39632 @@ -10506,18 +10506,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39633 return 1;
39634 }
39635
39636 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39637 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
39638 {
39639 - .dmi_id_list = &(const struct dmi_system_id[]) {
39640 - {
39641 - .callback = intel_dmi_reverse_brightness,
39642 - .ident = "NCR Corporation",
39643 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39644 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
39645 - },
39646 - },
39647 - { } /* terminating entry */
39648 + .callback = intel_dmi_reverse_brightness,
39649 + .ident = "NCR Corporation",
39650 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39651 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
39652 },
39653 + },
39654 + { } /* terminating entry */
39655 +};
39656 +
39657 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39658 + {
39659 + .dmi_id_list = &intel_dmi_quirks_table,
39660 .hook = quirk_invert_brightness,
39661 },
39662 };
39663 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39664 index ca4bc54..ee598a2 100644
39665 --- a/drivers/gpu/drm/mga/mga_drv.h
39666 +++ b/drivers/gpu/drm/mga/mga_drv.h
39667 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39668 u32 clear_cmd;
39669 u32 maccess;
39670
39671 - atomic_t vbl_received; /**< Number of vblanks received. */
39672 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39673 wait_queue_head_t fence_queue;
39674 - atomic_t last_fence_retired;
39675 + atomic_unchecked_t last_fence_retired;
39676 u32 next_fence_to_post;
39677
39678 unsigned int fb_cpp;
39679 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39680 index 709e90d..89a1c0d 100644
39681 --- a/drivers/gpu/drm/mga/mga_ioc32.c
39682 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
39683 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39684 return 0;
39685 }
39686
39687 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
39688 +drm_ioctl_compat_t mga_compat_ioctls[] = {
39689 [DRM_MGA_INIT] = compat_mga_init,
39690 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39691 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39692 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39693 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39694 {
39695 unsigned int nr = DRM_IOCTL_NR(cmd);
39696 - drm_ioctl_compat_t *fn = NULL;
39697 int ret;
39698
39699 if (nr < DRM_COMMAND_BASE)
39700 return drm_compat_ioctl(filp, cmd, arg);
39701
39702 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39703 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39704 -
39705 - if (fn != NULL)
39706 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39707 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39708 ret = (*fn) (filp, cmd, arg);
39709 - else
39710 + } else
39711 ret = drm_ioctl(filp, cmd, arg);
39712
39713 return ret;
39714 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39715 index 2b0ceb8..517e99e 100644
39716 --- a/drivers/gpu/drm/mga/mga_irq.c
39717 +++ b/drivers/gpu/drm/mga/mga_irq.c
39718 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39719 if (crtc != 0)
39720 return 0;
39721
39722 - return atomic_read(&dev_priv->vbl_received);
39723 + return atomic_read_unchecked(&dev_priv->vbl_received);
39724 }
39725
39726
39727 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39728 /* VBLANK interrupt */
39729 if (status & MGA_VLINEPEN) {
39730 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39731 - atomic_inc(&dev_priv->vbl_received);
39732 + atomic_inc_unchecked(&dev_priv->vbl_received);
39733 drm_handle_vblank(dev, 0);
39734 handled = 1;
39735 }
39736 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39737 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39738 MGA_WRITE(MGA_PRIMEND, prim_end);
39739
39740 - atomic_inc(&dev_priv->last_fence_retired);
39741 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
39742 DRM_WAKEUP(&dev_priv->fence_queue);
39743 handled = 1;
39744 }
39745 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39746 * using fences.
39747 */
39748 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39749 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39750 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39751 - *sequence) <= (1 << 23)));
39752
39753 *sequence = cur_fence;
39754 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39755 index 4c3feaa..26391ce 100644
39756 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39757 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39758 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39759 struct bit_table {
39760 const char id;
39761 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39762 -};
39763 +} __no_const;
39764
39765 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39766
39767 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39768 index 4b0fb6c..67667a9 100644
39769 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39770 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39771 @@ -96,7 +96,6 @@ struct nouveau_drm {
39772 struct drm_global_reference mem_global_ref;
39773 struct ttm_bo_global_ref bo_global_ref;
39774 struct ttm_bo_device bdev;
39775 - atomic_t validate_sequence;
39776 int (*move)(struct nouveau_channel *,
39777 struct ttm_buffer_object *,
39778 struct ttm_mem_reg *, struct ttm_mem_reg *);
39779 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39780 index c1a7e5a..38b8539 100644
39781 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39782 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39783 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39784 unsigned long arg)
39785 {
39786 unsigned int nr = DRM_IOCTL_NR(cmd);
39787 - drm_ioctl_compat_t *fn = NULL;
39788 + drm_ioctl_compat_t fn = NULL;
39789 int ret;
39790
39791 if (nr < DRM_COMMAND_BASE)
39792 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39793 index 19e3757..ad16478 100644
39794 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
39795 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39796 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39797 }
39798
39799 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
39800 - nouveau_vram_manager_init,
39801 - nouveau_vram_manager_fini,
39802 - nouveau_vram_manager_new,
39803 - nouveau_vram_manager_del,
39804 - nouveau_vram_manager_debug
39805 + .init = nouveau_vram_manager_init,
39806 + .takedown = nouveau_vram_manager_fini,
39807 + .get_node = nouveau_vram_manager_new,
39808 + .put_node = nouveau_vram_manager_del,
39809 + .debug = nouveau_vram_manager_debug
39810 };
39811
39812 static int
39813 @@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39814 }
39815
39816 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
39817 - nouveau_gart_manager_init,
39818 - nouveau_gart_manager_fini,
39819 - nouveau_gart_manager_new,
39820 - nouveau_gart_manager_del,
39821 - nouveau_gart_manager_debug
39822 + .init = nouveau_gart_manager_init,
39823 + .takedown = nouveau_gart_manager_fini,
39824 + .get_node = nouveau_gart_manager_new,
39825 + .put_node = nouveau_gart_manager_del,
39826 + .debug = nouveau_gart_manager_debug
39827 };
39828
39829 #include <core/subdev/vm/nv04.h>
39830 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39831 }
39832
39833 const struct ttm_mem_type_manager_func nv04_gart_manager = {
39834 - nv04_gart_manager_init,
39835 - nv04_gart_manager_fini,
39836 - nv04_gart_manager_new,
39837 - nv04_gart_manager_del,
39838 - nv04_gart_manager_debug
39839 + .init = nv04_gart_manager_init,
39840 + .takedown = nv04_gart_manager_fini,
39841 + .get_node = nv04_gart_manager_new,
39842 + .put_node = nv04_gart_manager_del,
39843 + .debug = nv04_gart_manager_debug
39844 };
39845
39846 int
39847 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39848 index 81638d7..2e45854 100644
39849 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39850 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39851 @@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39852 bool can_switch;
39853
39854 spin_lock(&dev->count_lock);
39855 - can_switch = (dev->open_count == 0);
39856 + can_switch = (local_read(&dev->open_count) == 0);
39857 spin_unlock(&dev->count_lock);
39858 return can_switch;
39859 }
39860 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
39861 index eb89653..613cf71 100644
39862 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
39863 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
39864 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
39865 int ret;
39866
39867 mutex_lock(&qdev->async_io_mutex);
39868 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
39869 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39870 if (qdev->last_sent_io_cmd > irq_num) {
39871 if (intr)
39872 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39873 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39874 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39875 else
39876 ret = wait_event_timeout(qdev->io_cmd_event,
39877 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39878 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39879 /* 0 is timeout, just bail the "hw" has gone away */
39880 if (ret <= 0)
39881 goto out;
39882 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
39883 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39884 }
39885 outb(val, addr);
39886 qdev->last_sent_io_cmd = irq_num + 1;
39887 if (intr)
39888 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39889 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39890 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39891 else
39892 ret = wait_event_timeout(qdev->io_cmd_event,
39893 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39894 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39895 out:
39896 if (ret > 0)
39897 ret = 0;
39898 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
39899 index c3c2bbd..bc3c0fb 100644
39900 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
39901 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
39902 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
39903 struct drm_info_node *node = (struct drm_info_node *) m->private;
39904 struct qxl_device *qdev = node->minor->dev->dev_private;
39905
39906 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
39907 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
39908 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
39909 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
39910 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
39911 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
39912 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
39913 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
39914 seq_printf(m, "%d\n", qdev->irq_received_error);
39915 return 0;
39916 }
39917 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
39918 index 7bda32f..dd98fc5 100644
39919 --- a/drivers/gpu/drm/qxl/qxl_drv.h
39920 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
39921 @@ -290,10 +290,10 @@ struct qxl_device {
39922 unsigned int last_sent_io_cmd;
39923
39924 /* interrupt handling */
39925 - atomic_t irq_received;
39926 - atomic_t irq_received_display;
39927 - atomic_t irq_received_cursor;
39928 - atomic_t irq_received_io_cmd;
39929 + atomic_unchecked_t irq_received;
39930 + atomic_unchecked_t irq_received_display;
39931 + atomic_unchecked_t irq_received_cursor;
39932 + atomic_unchecked_t irq_received_io_cmd;
39933 unsigned irq_received_error;
39934 wait_queue_head_t display_event;
39935 wait_queue_head_t cursor_event;
39936 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
39937 index 7b95c75..9cffb4f 100644
39938 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
39939 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
39940 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
39941
39942 /* TODO copy slow path code from i915 */
39943 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
39944 - 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);
39945 + 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);
39946
39947 {
39948 struct qxl_drawable *draw = fb_cmd;
39949 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
39950 struct drm_qxl_reloc reloc;
39951
39952 if (DRM_COPY_FROM_USER(&reloc,
39953 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
39954 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
39955 sizeof(reloc))) {
39956 ret = -EFAULT;
39957 goto out_free_bos;
39958 @@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
39959 struct drm_qxl_command *commands =
39960 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
39961
39962 - if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
39963 + if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
39964 sizeof(user_cmd)))
39965 return -EFAULT;
39966
39967 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
39968 index 21393dc..329f3a9 100644
39969 --- a/drivers/gpu/drm/qxl/qxl_irq.c
39970 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
39971 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
39972
39973 pending = xchg(&qdev->ram_header->int_pending, 0);
39974
39975 - atomic_inc(&qdev->irq_received);
39976 + atomic_inc_unchecked(&qdev->irq_received);
39977
39978 if (pending & QXL_INTERRUPT_DISPLAY) {
39979 - atomic_inc(&qdev->irq_received_display);
39980 + atomic_inc_unchecked(&qdev->irq_received_display);
39981 wake_up_all(&qdev->display_event);
39982 qxl_queue_garbage_collect(qdev, false);
39983 }
39984 if (pending & QXL_INTERRUPT_CURSOR) {
39985 - atomic_inc(&qdev->irq_received_cursor);
39986 + atomic_inc_unchecked(&qdev->irq_received_cursor);
39987 wake_up_all(&qdev->cursor_event);
39988 }
39989 if (pending & QXL_INTERRUPT_IO_CMD) {
39990 - atomic_inc(&qdev->irq_received_io_cmd);
39991 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
39992 wake_up_all(&qdev->io_cmd_event);
39993 }
39994 if (pending & QXL_INTERRUPT_ERROR) {
39995 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
39996 init_waitqueue_head(&qdev->io_cmd_event);
39997 INIT_WORK(&qdev->client_monitors_config_work,
39998 qxl_client_monitors_config_work_func);
39999 - atomic_set(&qdev->irq_received, 0);
40000 - atomic_set(&qdev->irq_received_display, 0);
40001 - atomic_set(&qdev->irq_received_cursor, 0);
40002 - atomic_set(&qdev->irq_received_io_cmd, 0);
40003 + atomic_set_unchecked(&qdev->irq_received, 0);
40004 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40005 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40006 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40007 qdev->irq_received_error = 0;
40008 ret = drm_irq_install(qdev->ddev);
40009 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40010 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40011 index c7e7e65..7dddd4d 100644
40012 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40013 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40014 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40015 }
40016 }
40017
40018 -static struct vm_operations_struct qxl_ttm_vm_ops;
40019 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40020 static const struct vm_operations_struct *ttm_vm_ops;
40021
40022 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40023 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40024 return r;
40025 if (unlikely(ttm_vm_ops == NULL)) {
40026 ttm_vm_ops = vma->vm_ops;
40027 + pax_open_kernel();
40028 qxl_ttm_vm_ops = *ttm_vm_ops;
40029 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40030 + pax_close_kernel();
40031 }
40032 vma->vm_ops = &qxl_ttm_vm_ops;
40033 return 0;
40034 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40035 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40036 {
40037 #if defined(CONFIG_DEBUG_FS)
40038 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40039 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40040 - unsigned i;
40041 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40042 + {
40043 + .name = "qxl_mem_mm",
40044 + .show = &qxl_mm_dump_table,
40045 + },
40046 + {
40047 + .name = "qxl_surf_mm",
40048 + .show = &qxl_mm_dump_table,
40049 + }
40050 + };
40051
40052 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40053 - if (i == 0)
40054 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40055 - else
40056 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40057 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40058 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40059 - qxl_mem_types_list[i].driver_features = 0;
40060 - if (i == 0)
40061 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40062 - else
40063 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40064 + pax_open_kernel();
40065 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40066 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40067 + pax_close_kernel();
40068
40069 - }
40070 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40071 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40072 #else
40073 return 0;
40074 #endif
40075 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40076 index c451257..0ad2134 100644
40077 --- a/drivers/gpu/drm/r128/r128_cce.c
40078 +++ b/drivers/gpu/drm/r128/r128_cce.c
40079 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40080
40081 /* GH: Simple idle check.
40082 */
40083 - atomic_set(&dev_priv->idle_count, 0);
40084 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40085
40086 /* We don't support anything other than bus-mastering ring mode,
40087 * but the ring can be in either AGP or PCI space for the ring
40088 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40089 index 56eb5e3..c4ec43d 100644
40090 --- a/drivers/gpu/drm/r128/r128_drv.h
40091 +++ b/drivers/gpu/drm/r128/r128_drv.h
40092 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40093 int is_pci;
40094 unsigned long cce_buffers_offset;
40095
40096 - atomic_t idle_count;
40097 + atomic_unchecked_t idle_count;
40098
40099 int page_flipping;
40100 int current_page;
40101 u32 crtc_offset;
40102 u32 crtc_offset_cntl;
40103
40104 - atomic_t vbl_received;
40105 + atomic_unchecked_t vbl_received;
40106
40107 u32 color_fmt;
40108 unsigned int front_offset;
40109 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40110 index a954c54..9cc595c 100644
40111 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40112 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40113 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40114 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40115 }
40116
40117 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40118 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40119 [DRM_R128_INIT] = compat_r128_init,
40120 [DRM_R128_DEPTH] = compat_r128_depth,
40121 [DRM_R128_STIPPLE] = compat_r128_stipple,
40122 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40123 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40124 {
40125 unsigned int nr = DRM_IOCTL_NR(cmd);
40126 - drm_ioctl_compat_t *fn = NULL;
40127 int ret;
40128
40129 if (nr < DRM_COMMAND_BASE)
40130 return drm_compat_ioctl(filp, cmd, arg);
40131
40132 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40133 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40134 -
40135 - if (fn != NULL)
40136 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40137 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40138 ret = (*fn) (filp, cmd, arg);
40139 - else
40140 + } else
40141 ret = drm_ioctl(filp, cmd, arg);
40142
40143 return ret;
40144 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40145 index 2ea4f09..d391371 100644
40146 --- a/drivers/gpu/drm/r128/r128_irq.c
40147 +++ b/drivers/gpu/drm/r128/r128_irq.c
40148 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40149 if (crtc != 0)
40150 return 0;
40151
40152 - return atomic_read(&dev_priv->vbl_received);
40153 + return atomic_read_unchecked(&dev_priv->vbl_received);
40154 }
40155
40156 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40157 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40158 /* VBLANK interrupt */
40159 if (status & R128_CRTC_VBLANK_INT) {
40160 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40161 - atomic_inc(&dev_priv->vbl_received);
40162 + atomic_inc_unchecked(&dev_priv->vbl_received);
40163 drm_handle_vblank(dev, 0);
40164 return IRQ_HANDLED;
40165 }
40166 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40167 index 01dd9ae..6352f04 100644
40168 --- a/drivers/gpu/drm/r128/r128_state.c
40169 +++ b/drivers/gpu/drm/r128/r128_state.c
40170 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40171
40172 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40173 {
40174 - if (atomic_read(&dev_priv->idle_count) == 0)
40175 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40176 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40177 else
40178 - atomic_set(&dev_priv->idle_count, 0);
40179 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40180 }
40181
40182 #endif
40183 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40184 index af85299..ed9ac8d 100644
40185 --- a/drivers/gpu/drm/radeon/mkregtable.c
40186 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40187 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40188 regex_t mask_rex;
40189 regmatch_t match[4];
40190 char buf[1024];
40191 - size_t end;
40192 + long end;
40193 int len;
40194 int done = 0;
40195 int r;
40196 unsigned o;
40197 struct offset *offset;
40198 char last_reg_s[10];
40199 - int last_reg;
40200 + unsigned long last_reg;
40201
40202 if (regcomp
40203 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40204 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40205 index 39b033b..6efc056 100644
40206 --- a/drivers/gpu/drm/radeon/radeon_device.c
40207 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40208 @@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40209 bool can_switch;
40210
40211 spin_lock(&dev->count_lock);
40212 - can_switch = (dev->open_count == 0);
40213 + can_switch = (local_read(&dev->open_count) == 0);
40214 spin_unlock(&dev->count_lock);
40215 return can_switch;
40216 }
40217 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40218 index 00e0d44..08381a4 100644
40219 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40220 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40221 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40222
40223 /* SW interrupt */
40224 wait_queue_head_t swi_queue;
40225 - atomic_t swi_emitted;
40226 + atomic_unchecked_t swi_emitted;
40227 int vblank_crtc;
40228 uint32_t irq_enable_reg;
40229 uint32_t r500_disp_irq_reg;
40230 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40231 index bdb0f93..5ff558f 100644
40232 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40233 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40234 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40235 request = compat_alloc_user_space(sizeof(*request));
40236 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40237 || __put_user(req32.param, &request->param)
40238 - || __put_user((void __user *)(unsigned long)req32.value,
40239 + || __put_user((unsigned long)req32.value,
40240 &request->value))
40241 return -EFAULT;
40242
40243 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40244 #define compat_radeon_cp_setparam NULL
40245 #endif /* X86_64 || IA64 */
40246
40247 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40248 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40249 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40250 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40251 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40252 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40253 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40254 {
40255 unsigned int nr = DRM_IOCTL_NR(cmd);
40256 - drm_ioctl_compat_t *fn = NULL;
40257 int ret;
40258
40259 if (nr < DRM_COMMAND_BASE)
40260 return drm_compat_ioctl(filp, cmd, arg);
40261
40262 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40263 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40264 -
40265 - if (fn != NULL)
40266 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40267 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40268 ret = (*fn) (filp, cmd, arg);
40269 - else
40270 + } else
40271 ret = drm_ioctl(filp, cmd, arg);
40272
40273 return ret;
40274 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40275 index 8d68e97..9dcfed8 100644
40276 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40277 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40278 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40279 unsigned int ret;
40280 RING_LOCALS;
40281
40282 - atomic_inc(&dev_priv->swi_emitted);
40283 - ret = atomic_read(&dev_priv->swi_emitted);
40284 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40285 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40286
40287 BEGIN_RING(4);
40288 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40289 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40290 drm_radeon_private_t *dev_priv =
40291 (drm_radeon_private_t *) dev->dev_private;
40292
40293 - atomic_set(&dev_priv->swi_emitted, 0);
40294 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40295 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40296
40297 dev->max_vblank_count = 0x001fffff;
40298 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40299 index 4d20910..6726b6d 100644
40300 --- a/drivers/gpu/drm/radeon/radeon_state.c
40301 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40302 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40303 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40304 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40305
40306 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40307 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40308 sarea_priv->nbox * sizeof(depth_boxes[0])))
40309 return -EFAULT;
40310
40311 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40312 {
40313 drm_radeon_private_t *dev_priv = dev->dev_private;
40314 drm_radeon_getparam_t *param = data;
40315 - int value;
40316 + int value = 0;
40317
40318 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40319
40320 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40321 index 71245d6..94c556d 100644
40322 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40323 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40324 @@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40325 man->size = size >> PAGE_SHIFT;
40326 }
40327
40328 -static struct vm_operations_struct radeon_ttm_vm_ops;
40329 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40330 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40331
40332 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40333 @@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40334 }
40335 if (unlikely(ttm_vm_ops == NULL)) {
40336 ttm_vm_ops = vma->vm_ops;
40337 + pax_open_kernel();
40338 radeon_ttm_vm_ops = *ttm_vm_ops;
40339 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40340 + pax_close_kernel();
40341 }
40342 vma->vm_ops = &radeon_ttm_vm_ops;
40343 return 0;
40344 @@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40345 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40346 {
40347 #if defined(CONFIG_DEBUG_FS)
40348 - static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40349 - static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40350 - unsigned i;
40351 + static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40352 + {
40353 + .name = "radeon_vram_mm",
40354 + .show = &radeon_mm_dump_table,
40355 + },
40356 + {
40357 + .name = "radeon_gtt_mm",
40358 + .show = &radeon_mm_dump_table,
40359 + },
40360 + {
40361 + .name = "ttm_page_pool",
40362 + .show = &ttm_page_alloc_debugfs,
40363 + },
40364 + {
40365 + .name = "ttm_dma_page_pool",
40366 + .show = &ttm_dma_page_alloc_debugfs,
40367 + },
40368 + };
40369 + unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40370
40371 - for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40372 - if (i == 0)
40373 - sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40374 - else
40375 - sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40376 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40377 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40378 - radeon_mem_types_list[i].driver_features = 0;
40379 - if (i == 0)
40380 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40381 - else
40382 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40383 -
40384 - }
40385 - /* Add ttm page pool to debugfs */
40386 - sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40387 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40388 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40389 - radeon_mem_types_list[i].driver_features = 0;
40390 - radeon_mem_types_list[i++].data = NULL;
40391 + pax_open_kernel();
40392 + *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40393 + *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40394 + pax_close_kernel();
40395 #ifdef CONFIG_SWIOTLB
40396 - if (swiotlb_nr_tbl()) {
40397 - sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
40398 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40399 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
40400 - radeon_mem_types_list[i].driver_features = 0;
40401 - radeon_mem_types_list[i++].data = NULL;
40402 - }
40403 + if (swiotlb_nr_tbl())
40404 + i++;
40405 #endif
40406 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
40407
40408 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40409 index ae1cb31..5b5b6b7c 100644
40410 --- a/drivers/gpu/drm/tegra/dc.c
40411 +++ b/drivers/gpu/drm/tegra/dc.c
40412 @@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40413 }
40414
40415 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40416 - dc->debugfs_files[i].data = dc;
40417 + *(void **)&dc->debugfs_files[i].data = dc;
40418
40419 err = drm_debugfs_create_files(dc->debugfs_files,
40420 ARRAY_SIZE(debugfs_files),
40421 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
40422 index 0cd9bc2..9759be4 100644
40423 --- a/drivers/gpu/drm/tegra/hdmi.c
40424 +++ b/drivers/gpu/drm/tegra/hdmi.c
40425 @@ -57,7 +57,7 @@ struct tegra_hdmi {
40426 bool stereo;
40427 bool dvi;
40428
40429 - struct drm_info_list *debugfs_files;
40430 + drm_info_list_no_const *debugfs_files;
40431 struct drm_minor *minor;
40432 struct dentry *debugfs;
40433 };
40434 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40435 index c58eba33..83c2728 100644
40436 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
40437 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40438 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
40439 }
40440
40441 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
40442 - ttm_bo_man_init,
40443 - ttm_bo_man_takedown,
40444 - ttm_bo_man_get_node,
40445 - ttm_bo_man_put_node,
40446 - ttm_bo_man_debug
40447 + .init = ttm_bo_man_init,
40448 + .takedown = ttm_bo_man_takedown,
40449 + .get_node = ttm_bo_man_get_node,
40450 + .put_node = ttm_bo_man_put_node,
40451 + .debug = ttm_bo_man_debug
40452 };
40453 EXPORT_SYMBOL(ttm_bo_manager_func);
40454 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
40455 index dbc2def..0a9f710 100644
40456 --- a/drivers/gpu/drm/ttm/ttm_memory.c
40457 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
40458 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
40459 zone->glob = glob;
40460 glob->zone_kernel = zone;
40461 ret = kobject_init_and_add(
40462 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40463 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40464 if (unlikely(ret != 0)) {
40465 kobject_put(&zone->kobj);
40466 return ret;
40467 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
40468 zone->glob = glob;
40469 glob->zone_dma32 = zone;
40470 ret = kobject_init_and_add(
40471 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40472 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40473 if (unlikely(ret != 0)) {
40474 kobject_put(&zone->kobj);
40475 return ret;
40476 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40477 index 863bef9..cba15cf 100644
40478 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
40479 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40480 @@ -391,9 +391,9 @@ out:
40481 static unsigned long
40482 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
40483 {
40484 - static atomic_t start_pool = ATOMIC_INIT(0);
40485 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
40486 unsigned i;
40487 - unsigned pool_offset = atomic_add_return(1, &start_pool);
40488 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
40489 struct ttm_page_pool *pool;
40490 int shrink_pages = sc->nr_to_scan;
40491 unsigned long freed = 0;
40492 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
40493 index 97e9d61..bf23c461 100644
40494 --- a/drivers/gpu/drm/udl/udl_fb.c
40495 +++ b/drivers/gpu/drm/udl/udl_fb.c
40496 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
40497 fb_deferred_io_cleanup(info);
40498 kfree(info->fbdefio);
40499 info->fbdefio = NULL;
40500 - info->fbops->fb_mmap = udl_fb_mmap;
40501 }
40502
40503 pr_warn("released /dev/fb%d user=%d count=%d\n",
40504 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
40505 index a811ef2..ff99b05 100644
40506 --- a/drivers/gpu/drm/via/via_drv.h
40507 +++ b/drivers/gpu/drm/via/via_drv.h
40508 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
40509 typedef uint32_t maskarray_t[5];
40510
40511 typedef struct drm_via_irq {
40512 - atomic_t irq_received;
40513 + atomic_unchecked_t irq_received;
40514 uint32_t pending_mask;
40515 uint32_t enable_mask;
40516 wait_queue_head_t irq_queue;
40517 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
40518 struct timeval last_vblank;
40519 int last_vblank_valid;
40520 unsigned usec_per_vblank;
40521 - atomic_t vbl_received;
40522 + atomic_unchecked_t vbl_received;
40523 drm_via_state_t hc_state;
40524 char pci_buf[VIA_PCI_BUF_SIZE];
40525 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
40526 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
40527 index ac98964..5dbf512 100644
40528 --- a/drivers/gpu/drm/via/via_irq.c
40529 +++ b/drivers/gpu/drm/via/via_irq.c
40530 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
40531 if (crtc != 0)
40532 return 0;
40533
40534 - return atomic_read(&dev_priv->vbl_received);
40535 + return atomic_read_unchecked(&dev_priv->vbl_received);
40536 }
40537
40538 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40539 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40540
40541 status = VIA_READ(VIA_REG_INTERRUPT);
40542 if (status & VIA_IRQ_VBLANK_PENDING) {
40543 - atomic_inc(&dev_priv->vbl_received);
40544 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
40545 + atomic_inc_unchecked(&dev_priv->vbl_received);
40546 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
40547 do_gettimeofday(&cur_vblank);
40548 if (dev_priv->last_vblank_valid) {
40549 dev_priv->usec_per_vblank =
40550 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40551 dev_priv->last_vblank = cur_vblank;
40552 dev_priv->last_vblank_valid = 1;
40553 }
40554 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
40555 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
40556 DRM_DEBUG("US per vblank is: %u\n",
40557 dev_priv->usec_per_vblank);
40558 }
40559 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40560
40561 for (i = 0; i < dev_priv->num_irqs; ++i) {
40562 if (status & cur_irq->pending_mask) {
40563 - atomic_inc(&cur_irq->irq_received);
40564 + atomic_inc_unchecked(&cur_irq->irq_received);
40565 DRM_WAKEUP(&cur_irq->irq_queue);
40566 handled = 1;
40567 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
40568 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
40569 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40570 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
40571 masks[irq][4]));
40572 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
40573 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
40574 } else {
40575 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40576 (((cur_irq_sequence =
40577 - atomic_read(&cur_irq->irq_received)) -
40578 + atomic_read_unchecked(&cur_irq->irq_received)) -
40579 *sequence) <= (1 << 23)));
40580 }
40581 *sequence = cur_irq_sequence;
40582 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
40583 }
40584
40585 for (i = 0; i < dev_priv->num_irqs; ++i) {
40586 - atomic_set(&cur_irq->irq_received, 0);
40587 + atomic_set_unchecked(&cur_irq->irq_received, 0);
40588 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
40589 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
40590 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
40591 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
40592 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
40593 case VIA_IRQ_RELATIVE:
40594 irqwait->request.sequence +=
40595 - atomic_read(&cur_irq->irq_received);
40596 + atomic_read_unchecked(&cur_irq->irq_received);
40597 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
40598 case VIA_IRQ_ABSOLUTE:
40599 break;
40600 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40601 index 20890ad..699e4f2 100644
40602 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40603 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40604 @@ -342,7 +342,7 @@ struct vmw_private {
40605 * Fencing and IRQs.
40606 */
40607
40608 - atomic_t marker_seq;
40609 + atomic_unchecked_t marker_seq;
40610 wait_queue_head_t fence_queue;
40611 wait_queue_head_t fifo_queue;
40612 int fence_queue_waiters; /* Protected by hw_mutex */
40613 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40614 index 3eb1486..0a47ee9 100644
40615 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40616 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40617 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
40618 (unsigned int) min,
40619 (unsigned int) fifo->capabilities);
40620
40621 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40622 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40623 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
40624 vmw_marker_queue_init(&fifo->marker_queue);
40625 return vmw_fifo_send_fence(dev_priv, &dummy);
40626 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
40627 if (reserveable)
40628 iowrite32(bytes, fifo_mem +
40629 SVGA_FIFO_RESERVED);
40630 - return fifo_mem + (next_cmd >> 2);
40631 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
40632 } else {
40633 need_bounce = true;
40634 }
40635 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40636
40637 fm = vmw_fifo_reserve(dev_priv, bytes);
40638 if (unlikely(fm == NULL)) {
40639 - *seqno = atomic_read(&dev_priv->marker_seq);
40640 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40641 ret = -ENOMEM;
40642 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
40643 false, 3*HZ);
40644 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40645 }
40646
40647 do {
40648 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
40649 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
40650 } while (*seqno == 0);
40651
40652 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
40653 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40654 index c5c054a..46f0548 100644
40655 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40656 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40657 @@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
40658 }
40659
40660 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
40661 - vmw_gmrid_man_init,
40662 - vmw_gmrid_man_takedown,
40663 - vmw_gmrid_man_get_node,
40664 - vmw_gmrid_man_put_node,
40665 - vmw_gmrid_man_debug
40666 + .init = vmw_gmrid_man_init,
40667 + .takedown = vmw_gmrid_man_takedown,
40668 + .get_node = vmw_gmrid_man_get_node,
40669 + .put_node = vmw_gmrid_man_put_node,
40670 + .debug = vmw_gmrid_man_debug
40671 };
40672 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40673 index 45d5b5a..f3f5e4e 100644
40674 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40675 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40676 @@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
40677 int ret;
40678
40679 num_clips = arg->num_clips;
40680 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40681 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40682
40683 if (unlikely(num_clips == 0))
40684 return 0;
40685 @@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
40686 int ret;
40687
40688 num_clips = arg->num_clips;
40689 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40690 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40691
40692 if (unlikely(num_clips == 0))
40693 return 0;
40694 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40695 index 4640adb..e1384ed 100644
40696 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40697 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40698 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
40699 * emitted. Then the fence is stale and signaled.
40700 */
40701
40702 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
40703 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
40704 > VMW_FENCE_WRAP);
40705
40706 return ret;
40707 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
40708
40709 if (fifo_idle)
40710 down_read(&fifo_state->rwsem);
40711 - signal_seq = atomic_read(&dev_priv->marker_seq);
40712 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
40713 ret = 0;
40714
40715 for (;;) {
40716 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40717 index 8a8725c2..afed796 100644
40718 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40719 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40720 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
40721 while (!vmw_lag_lt(queue, us)) {
40722 spin_lock(&queue->lock);
40723 if (list_empty(&queue->head))
40724 - seqno = atomic_read(&dev_priv->marker_seq);
40725 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40726 else {
40727 marker = list_first_entry(&queue->head,
40728 struct vmw_marker, head);
40729 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
40730 index ec0ae2d..dc0780b 100644
40731 --- a/drivers/gpu/vga/vga_switcheroo.c
40732 +++ b/drivers/gpu/vga/vga_switcheroo.c
40733 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
40734
40735 /* this version is for the case where the power switch is separate
40736 to the device being powered down. */
40737 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
40738 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
40739 {
40740 /* copy over all the bus versions */
40741 if (dev->bus && dev->bus->pm) {
40742 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
40743 return ret;
40744 }
40745
40746 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
40747 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
40748 {
40749 /* copy over all the bus versions */
40750 if (dev->bus && dev->bus->pm) {
40751 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
40752 index 253fe23..0dfec5f 100644
40753 --- a/drivers/hid/hid-core.c
40754 +++ b/drivers/hid/hid-core.c
40755 @@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40756
40757 int hid_add_device(struct hid_device *hdev)
40758 {
40759 - static atomic_t id = ATOMIC_INIT(0);
40760 + static atomic_unchecked_t id = ATOMIC_INIT(0);
40761 int ret;
40762
40763 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40764 @@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
40765 /* XXX hack, any other cleaner solution after the driver core
40766 * is converted to allow more than 20 bytes as the device name? */
40767 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40768 - hdev->vendor, hdev->product, atomic_inc_return(&id));
40769 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40770
40771 hid_debug_register(hdev, dev_name(&hdev->dev));
40772 ret = device_add(&hdev->dev);
40773 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40774 index c13fb5b..55a3802 100644
40775 --- a/drivers/hid/hid-wiimote-debug.c
40776 +++ b/drivers/hid/hid-wiimote-debug.c
40777 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40778 else if (size == 0)
40779 return -EIO;
40780
40781 - if (copy_to_user(u, buf, size))
40782 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
40783 return -EFAULT;
40784
40785 *off += size;
40786 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40787 index cedc6da..2c3da2a 100644
40788 --- a/drivers/hid/uhid.c
40789 +++ b/drivers/hid/uhid.c
40790 @@ -47,7 +47,7 @@ struct uhid_device {
40791 struct mutex report_lock;
40792 wait_queue_head_t report_wait;
40793 atomic_t report_done;
40794 - atomic_t report_id;
40795 + atomic_unchecked_t report_id;
40796 struct uhid_event report_buf;
40797 };
40798
40799 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40800
40801 spin_lock_irqsave(&uhid->qlock, flags);
40802 ev->type = UHID_FEATURE;
40803 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40804 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40805 ev->u.feature.rnum = rnum;
40806 ev->u.feature.rtype = report_type;
40807
40808 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40809 spin_lock_irqsave(&uhid->qlock, flags);
40810
40811 /* id for old report; drop it silently */
40812 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40813 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40814 goto unlock;
40815 if (atomic_read(&uhid->report_done))
40816 goto unlock;
40817 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40818 index cea623c..73011b0 100644
40819 --- a/drivers/hv/channel.c
40820 +++ b/drivers/hv/channel.c
40821 @@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40822 int ret = 0;
40823 int t;
40824
40825 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40826 - atomic_inc(&vmbus_connection.next_gpadl_handle);
40827 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40828 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40829
40830 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40831 if (ret)
40832 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40833 index f0c5e07..399256e 100644
40834 --- a/drivers/hv/hv.c
40835 +++ b/drivers/hv/hv.c
40836 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40837 u64 output_address = (output) ? virt_to_phys(output) : 0;
40838 u32 output_address_hi = output_address >> 32;
40839 u32 output_address_lo = output_address & 0xFFFFFFFF;
40840 - void *hypercall_page = hv_context.hypercall_page;
40841 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40842
40843 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40844 "=a"(hv_status_lo) : "d" (control_hi),
40845 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40846 index 7e17a54..a50a33d 100644
40847 --- a/drivers/hv/hv_balloon.c
40848 +++ b/drivers/hv/hv_balloon.c
40849 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40850
40851 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40852 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40853 -static atomic_t trans_id = ATOMIC_INIT(0);
40854 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40855
40856 static int dm_ring_size = (5 * PAGE_SIZE);
40857
40858 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
40859 pr_info("Memory hot add failed\n");
40860
40861 dm->state = DM_INITIALIZED;
40862 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
40863 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40864 vmbus_sendpacket(dm->dev->channel, &resp,
40865 sizeof(struct dm_hot_add_response),
40866 (unsigned long)NULL,
40867 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40868 memset(&status, 0, sizeof(struct dm_status));
40869 status.hdr.type = DM_STATUS_REPORT;
40870 status.hdr.size = sizeof(struct dm_status);
40871 - status.hdr.trans_id = atomic_inc_return(&trans_id);
40872 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40873
40874 /*
40875 * The host expects the guest to report free memory.
40876 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40877 * send the status. This can happen if we were interrupted
40878 * after we picked our transaction ID.
40879 */
40880 - if (status.hdr.trans_id != atomic_read(&trans_id))
40881 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40882 return;
40883
40884 vmbus_sendpacket(dm->dev->channel, &status,
40885 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
40886 */
40887
40888 do {
40889 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40890 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40891 ret = vmbus_sendpacket(dm_device.dev->channel,
40892 bl_resp,
40893 bl_resp->hdr.size,
40894 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40895
40896 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40897 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40898 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
40899 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40900 resp.hdr.size = sizeof(struct dm_unballoon_response);
40901
40902 vmbus_sendpacket(dm_device.dev->channel, &resp,
40903 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40904 memset(&version_req, 0, sizeof(struct dm_version_request));
40905 version_req.hdr.type = DM_VERSION_REQUEST;
40906 version_req.hdr.size = sizeof(struct dm_version_request);
40907 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40908 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40909 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40910 version_req.is_last_attempt = 1;
40911
40912 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40913 memset(&version_req, 0, sizeof(struct dm_version_request));
40914 version_req.hdr.type = DM_VERSION_REQUEST;
40915 version_req.hdr.size = sizeof(struct dm_version_request);
40916 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40917 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40918 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40919 version_req.is_last_attempt = 0;
40920
40921 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40922 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40923 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40924 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40925 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40926 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40927
40928 cap_msg.caps.cap_bits.balloon = 1;
40929 cap_msg.caps.cap_bits.hot_add = 1;
40930 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40931 index e055176..c22ff1f 100644
40932 --- a/drivers/hv/hyperv_vmbus.h
40933 +++ b/drivers/hv/hyperv_vmbus.h
40934 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
40935 struct vmbus_connection {
40936 enum vmbus_connect_state conn_state;
40937
40938 - atomic_t next_gpadl_handle;
40939 + atomic_unchecked_t next_gpadl_handle;
40940
40941 /*
40942 * Represents channel interrupts. Each bit position represents a
40943 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40944 index 48aad4f..c768fb2 100644
40945 --- a/drivers/hv/vmbus_drv.c
40946 +++ b/drivers/hv/vmbus_drv.c
40947 @@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40948 {
40949 int ret = 0;
40950
40951 - static atomic_t device_num = ATOMIC_INIT(0);
40952 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40953
40954 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40955 - atomic_inc_return(&device_num));
40956 + atomic_inc_return_unchecked(&device_num));
40957
40958 child_device_obj->device.bus = &hv_bus;
40959 child_device_obj->device.parent = &hv_acpi_dev->dev;
40960 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40961 index 6a34f7f..aa4c3a6 100644
40962 --- a/drivers/hwmon/acpi_power_meter.c
40963 +++ b/drivers/hwmon/acpi_power_meter.c
40964 @@ -117,7 +117,7 @@ struct sensor_template {
40965 struct device_attribute *devattr,
40966 const char *buf, size_t count);
40967 int index;
40968 -};
40969 +} __do_const;
40970
40971 /* Averaging interval */
40972 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40973 @@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40974 struct sensor_template *attrs)
40975 {
40976 struct device *dev = &resource->acpi_dev->dev;
40977 - struct sensor_device_attribute *sensors =
40978 + sensor_device_attribute_no_const *sensors =
40979 &resource->sensors[resource->num_sensors];
40980 int res = 0;
40981
40982 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40983 index 3288f13..71cfb4e 100644
40984 --- a/drivers/hwmon/applesmc.c
40985 +++ b/drivers/hwmon/applesmc.c
40986 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40987 {
40988 struct applesmc_node_group *grp;
40989 struct applesmc_dev_attr *node;
40990 - struct attribute *attr;
40991 + attribute_no_const *attr;
40992 int ret, i;
40993
40994 for (grp = groups; grp->format; grp++) {
40995 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40996 index dafc63c..4abb96c 100644
40997 --- a/drivers/hwmon/asus_atk0110.c
40998 +++ b/drivers/hwmon/asus_atk0110.c
40999 @@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41000 struct atk_sensor_data {
41001 struct list_head list;
41002 struct atk_data *data;
41003 - struct device_attribute label_attr;
41004 - struct device_attribute input_attr;
41005 - struct device_attribute limit1_attr;
41006 - struct device_attribute limit2_attr;
41007 + device_attribute_no_const label_attr;
41008 + device_attribute_no_const input_attr;
41009 + device_attribute_no_const limit1_attr;
41010 + device_attribute_no_const limit2_attr;
41011 char label_attr_name[ATTR_NAME_SIZE];
41012 char input_attr_name[ATTR_NAME_SIZE];
41013 char limit1_attr_name[ATTR_NAME_SIZE];
41014 @@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41015 static struct device_attribute atk_name_attr =
41016 __ATTR(name, 0444, atk_name_show, NULL);
41017
41018 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41019 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41020 sysfs_show_func show)
41021 {
41022 sysfs_attr_init(&attr->attr);
41023 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41024 index 9425098..7646cc5 100644
41025 --- a/drivers/hwmon/coretemp.c
41026 +++ b/drivers/hwmon/coretemp.c
41027 @@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41028 return NOTIFY_OK;
41029 }
41030
41031 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41032 +static struct notifier_block coretemp_cpu_notifier = {
41033 .notifier_call = coretemp_cpu_callback,
41034 };
41035
41036 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41037 index 632f1dc..57e6a58 100644
41038 --- a/drivers/hwmon/ibmaem.c
41039 +++ b/drivers/hwmon/ibmaem.c
41040 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41041 struct aem_rw_sensor_template *rw)
41042 {
41043 struct device *dev = &data->pdev->dev;
41044 - struct sensor_device_attribute *sensors = data->sensors;
41045 + sensor_device_attribute_no_const *sensors = data->sensors;
41046 int err;
41047
41048 /* Set up read-only sensors */
41049 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41050 index 708081b..fe2d4ab 100644
41051 --- a/drivers/hwmon/iio_hwmon.c
41052 +++ b/drivers/hwmon/iio_hwmon.c
41053 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41054 {
41055 struct device *dev = &pdev->dev;
41056 struct iio_hwmon_state *st;
41057 - struct sensor_device_attribute *a;
41058 + sensor_device_attribute_no_const *a;
41059 int ret, i;
41060 int in_i = 1, temp_i = 1, curr_i = 1;
41061 enum iio_chan_type type;
41062 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41063 index cf811c1..4c17110 100644
41064 --- a/drivers/hwmon/nct6775.c
41065 +++ b/drivers/hwmon/nct6775.c
41066 @@ -944,10 +944,10 @@ static struct attribute_group *
41067 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41068 int repeat)
41069 {
41070 - struct attribute_group *group;
41071 + attribute_group_no_const *group;
41072 struct sensor_device_attr_u *su;
41073 - struct sensor_device_attribute *a;
41074 - struct sensor_device_attribute_2 *a2;
41075 + sensor_device_attribute_no_const *a;
41076 + sensor_device_attribute_2_no_const *a2;
41077 struct attribute **attrs;
41078 struct sensor_device_template **t;
41079 int i, count;
41080 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41081 index 3cbf66e..8c5cc2a 100644
41082 --- a/drivers/hwmon/pmbus/pmbus_core.c
41083 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41084 @@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41085 return 0;
41086 }
41087
41088 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41089 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41090 const char *name,
41091 umode_t mode,
41092 ssize_t (*show)(struct device *dev,
41093 @@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41094 dev_attr->store = store;
41095 }
41096
41097 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41098 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41099 const char *name,
41100 umode_t mode,
41101 ssize_t (*show)(struct device *dev,
41102 @@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41103 u16 reg, u8 mask)
41104 {
41105 struct pmbus_boolean *boolean;
41106 - struct sensor_device_attribute *a;
41107 + sensor_device_attribute_no_const *a;
41108
41109 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41110 if (!boolean)
41111 @@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41112 bool update, bool readonly)
41113 {
41114 struct pmbus_sensor *sensor;
41115 - struct device_attribute *a;
41116 + device_attribute_no_const *a;
41117
41118 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41119 if (!sensor)
41120 @@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41121 const char *lstring, int index)
41122 {
41123 struct pmbus_label *label;
41124 - struct device_attribute *a;
41125 + device_attribute_no_const *a;
41126
41127 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41128 if (!label)
41129 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41130 index 97cd45a..ac54d8b 100644
41131 --- a/drivers/hwmon/sht15.c
41132 +++ b/drivers/hwmon/sht15.c
41133 @@ -169,7 +169,7 @@ struct sht15_data {
41134 int supply_uv;
41135 bool supply_uv_valid;
41136 struct work_struct update_supply_work;
41137 - atomic_t interrupt_handled;
41138 + atomic_unchecked_t interrupt_handled;
41139 };
41140
41141 /**
41142 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41143 ret = gpio_direction_input(data->pdata->gpio_data);
41144 if (ret)
41145 return ret;
41146 - atomic_set(&data->interrupt_handled, 0);
41147 + atomic_set_unchecked(&data->interrupt_handled, 0);
41148
41149 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41150 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41151 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41152 /* Only relevant if the interrupt hasn't occurred. */
41153 - if (!atomic_read(&data->interrupt_handled))
41154 + if (!atomic_read_unchecked(&data->interrupt_handled))
41155 schedule_work(&data->read_work);
41156 }
41157 ret = wait_event_timeout(data->wait_queue,
41158 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41159
41160 /* First disable the interrupt */
41161 disable_irq_nosync(irq);
41162 - atomic_inc(&data->interrupt_handled);
41163 + atomic_inc_unchecked(&data->interrupt_handled);
41164 /* Then schedule a reading work struct */
41165 if (data->state != SHT15_READING_NOTHING)
41166 schedule_work(&data->read_work);
41167 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41168 * If not, then start the interrupt again - care here as could
41169 * have gone low in meantime so verify it hasn't!
41170 */
41171 - atomic_set(&data->interrupt_handled, 0);
41172 + atomic_set_unchecked(&data->interrupt_handled, 0);
41173 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41174 /* If still not occurred or another handler was scheduled */
41175 if (gpio_get_value(data->pdata->gpio_data)
41176 - || atomic_read(&data->interrupt_handled))
41177 + || atomic_read_unchecked(&data->interrupt_handled))
41178 return;
41179 }
41180
41181 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41182 index 38944e9..ae9e5ed 100644
41183 --- a/drivers/hwmon/via-cputemp.c
41184 +++ b/drivers/hwmon/via-cputemp.c
41185 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41186 return NOTIFY_OK;
41187 }
41188
41189 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41190 +static struct notifier_block via_cputemp_cpu_notifier = {
41191 .notifier_call = via_cputemp_cpu_callback,
41192 };
41193
41194 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41195 index 07f01ac..d79ad3d 100644
41196 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41197 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41198 @@ -43,7 +43,7 @@
41199 extern struct i2c_adapter amd756_smbus;
41200
41201 static struct i2c_adapter *s4882_adapter;
41202 -static struct i2c_algorithm *s4882_algo;
41203 +static i2c_algorithm_no_const *s4882_algo;
41204
41205 /* Wrapper access functions for multiplexed SMBus */
41206 static DEFINE_MUTEX(amd756_lock);
41207 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41208 index 721f7eb..0fd2a09 100644
41209 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41210 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41211 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41212 /* usb layer */
41213
41214 /* Send command to device, and get response. */
41215 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41216 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41217 {
41218 int ret = 0;
41219 int actual;
41220 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41221 index 2ca268d..c6acbdf 100644
41222 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41223 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41224 @@ -41,7 +41,7 @@
41225 extern struct i2c_adapter *nforce2_smbus;
41226
41227 static struct i2c_adapter *s4985_adapter;
41228 -static struct i2c_algorithm *s4985_algo;
41229 +static i2c_algorithm_no_const *s4985_algo;
41230
41231 /* Wrapper access functions for multiplexed SMBus */
41232 static DEFINE_MUTEX(nforce2_lock);
41233 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41234 index 80b47e8..1a6040d9 100644
41235 --- a/drivers/i2c/i2c-dev.c
41236 +++ b/drivers/i2c/i2c-dev.c
41237 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41238 break;
41239 }
41240
41241 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41242 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41243 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41244 if (IS_ERR(rdwr_pa[i].buf)) {
41245 res = PTR_ERR(rdwr_pa[i].buf);
41246 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41247 index 0b510ba..4fbb5085 100644
41248 --- a/drivers/ide/ide-cd.c
41249 +++ b/drivers/ide/ide-cd.c
41250 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41251 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41252 if ((unsigned long)buf & alignment
41253 || blk_rq_bytes(rq) & q->dma_pad_mask
41254 - || object_is_on_stack(buf))
41255 + || object_starts_on_stack(buf))
41256 drive->dma = 0;
41257 }
41258 }
41259 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41260 index 18f72e3..3722327 100644
41261 --- a/drivers/iio/industrialio-core.c
41262 +++ b/drivers/iio/industrialio-core.c
41263 @@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41264 }
41265
41266 static
41267 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41268 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41269 const char *postfix,
41270 struct iio_chan_spec const *chan,
41271 ssize_t (*readfunc)(struct device *dev,
41272 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41273 index f2ef7ef..743d02f 100644
41274 --- a/drivers/infiniband/core/cm.c
41275 +++ b/drivers/infiniband/core/cm.c
41276 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41277
41278 struct cm_counter_group {
41279 struct kobject obj;
41280 - atomic_long_t counter[CM_ATTR_COUNT];
41281 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41282 };
41283
41284 struct cm_counter_attribute {
41285 @@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41286 struct ib_mad_send_buf *msg = NULL;
41287 int ret;
41288
41289 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41290 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41291 counter[CM_REQ_COUNTER]);
41292
41293 /* Quick state check to discard duplicate REQs. */
41294 @@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41295 if (!cm_id_priv)
41296 return;
41297
41298 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41299 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41300 counter[CM_REP_COUNTER]);
41301 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41302 if (ret)
41303 @@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41304 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41305 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41306 spin_unlock_irq(&cm_id_priv->lock);
41307 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41308 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41309 counter[CM_RTU_COUNTER]);
41310 goto out;
41311 }
41312 @@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41313 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41314 dreq_msg->local_comm_id);
41315 if (!cm_id_priv) {
41316 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41317 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41318 counter[CM_DREQ_COUNTER]);
41319 cm_issue_drep(work->port, work->mad_recv_wc);
41320 return -EINVAL;
41321 @@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41322 case IB_CM_MRA_REP_RCVD:
41323 break;
41324 case IB_CM_TIMEWAIT:
41325 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41326 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41327 counter[CM_DREQ_COUNTER]);
41328 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41329 goto unlock;
41330 @@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41331 cm_free_msg(msg);
41332 goto deref;
41333 case IB_CM_DREQ_RCVD:
41334 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41335 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41336 counter[CM_DREQ_COUNTER]);
41337 goto unlock;
41338 default:
41339 @@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41340 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41341 cm_id_priv->msg, timeout)) {
41342 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41343 - atomic_long_inc(&work->port->
41344 + atomic_long_inc_unchecked(&work->port->
41345 counter_group[CM_RECV_DUPLICATES].
41346 counter[CM_MRA_COUNTER]);
41347 goto out;
41348 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41349 break;
41350 case IB_CM_MRA_REQ_RCVD:
41351 case IB_CM_MRA_REP_RCVD:
41352 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41353 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41354 counter[CM_MRA_COUNTER]);
41355 /* fall through */
41356 default:
41357 @@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41358 case IB_CM_LAP_IDLE:
41359 break;
41360 case IB_CM_MRA_LAP_SENT:
41361 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41362 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41363 counter[CM_LAP_COUNTER]);
41364 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41365 goto unlock;
41366 @@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41367 cm_free_msg(msg);
41368 goto deref;
41369 case IB_CM_LAP_RCVD:
41370 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41371 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41372 counter[CM_LAP_COUNTER]);
41373 goto unlock;
41374 default:
41375 @@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41376 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41377 if (cur_cm_id_priv) {
41378 spin_unlock_irq(&cm.lock);
41379 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41380 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41381 counter[CM_SIDR_REQ_COUNTER]);
41382 goto out; /* Duplicate message. */
41383 }
41384 @@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41385 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41386 msg->retries = 1;
41387
41388 - atomic_long_add(1 + msg->retries,
41389 + atomic_long_add_unchecked(1 + msg->retries,
41390 &port->counter_group[CM_XMIT].counter[attr_index]);
41391 if (msg->retries)
41392 - atomic_long_add(msg->retries,
41393 + atomic_long_add_unchecked(msg->retries,
41394 &port->counter_group[CM_XMIT_RETRIES].
41395 counter[attr_index]);
41396
41397 @@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41398 }
41399
41400 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41401 - atomic_long_inc(&port->counter_group[CM_RECV].
41402 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41403 counter[attr_id - CM_ATTR_ID_OFFSET]);
41404
41405 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41406 @@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41407 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41408
41409 return sprintf(buf, "%ld\n",
41410 - atomic_long_read(&group->counter[cm_attr->index]));
41411 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41412 }
41413
41414 static const struct sysfs_ops cm_counter_ops = {
41415 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41416 index 9f5ad7c..588cd84 100644
41417 --- a/drivers/infiniband/core/fmr_pool.c
41418 +++ b/drivers/infiniband/core/fmr_pool.c
41419 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
41420
41421 struct task_struct *thread;
41422
41423 - atomic_t req_ser;
41424 - atomic_t flush_ser;
41425 + atomic_unchecked_t req_ser;
41426 + atomic_unchecked_t flush_ser;
41427
41428 wait_queue_head_t force_wait;
41429 };
41430 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41431 struct ib_fmr_pool *pool = pool_ptr;
41432
41433 do {
41434 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41435 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41436 ib_fmr_batch_release(pool);
41437
41438 - atomic_inc(&pool->flush_ser);
41439 + atomic_inc_unchecked(&pool->flush_ser);
41440 wake_up_interruptible(&pool->force_wait);
41441
41442 if (pool->flush_function)
41443 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41444 }
41445
41446 set_current_state(TASK_INTERRUPTIBLE);
41447 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
41448 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
41449 !kthread_should_stop())
41450 schedule();
41451 __set_current_state(TASK_RUNNING);
41452 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
41453 pool->dirty_watermark = params->dirty_watermark;
41454 pool->dirty_len = 0;
41455 spin_lock_init(&pool->pool_lock);
41456 - atomic_set(&pool->req_ser, 0);
41457 - atomic_set(&pool->flush_ser, 0);
41458 + atomic_set_unchecked(&pool->req_ser, 0);
41459 + atomic_set_unchecked(&pool->flush_ser, 0);
41460 init_waitqueue_head(&pool->force_wait);
41461
41462 pool->thread = kthread_run(ib_fmr_cleanup_thread,
41463 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41464 }
41465 spin_unlock_irq(&pool->pool_lock);
41466
41467 - serial = atomic_inc_return(&pool->req_ser);
41468 + serial = atomic_inc_return_unchecked(&pool->req_ser);
41469 wake_up_process(pool->thread);
41470
41471 if (wait_event_interruptible(pool->force_wait,
41472 - atomic_read(&pool->flush_ser) - serial >= 0))
41473 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41474 return -EINTR;
41475
41476 return 0;
41477 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
41478 } else {
41479 list_add_tail(&fmr->list, &pool->dirty_list);
41480 if (++pool->dirty_len >= pool->dirty_watermark) {
41481 - atomic_inc(&pool->req_ser);
41482 + atomic_inc_unchecked(&pool->req_ser);
41483 wake_up_process(pool->thread);
41484 }
41485 }
41486 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
41487 index 84e4500..2c9beeb 100644
41488 --- a/drivers/infiniband/hw/cxgb4/mem.c
41489 +++ b/drivers/infiniband/hw/cxgb4/mem.c
41490 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41491 int err;
41492 struct fw_ri_tpte tpt;
41493 u32 stag_idx;
41494 - static atomic_t key;
41495 + static atomic_unchecked_t key;
41496
41497 if (c4iw_fatal_error(rdev))
41498 return -EIO;
41499 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41500 if (rdev->stats.stag.cur > rdev->stats.stag.max)
41501 rdev->stats.stag.max = rdev->stats.stag.cur;
41502 mutex_unlock(&rdev->stats.lock);
41503 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
41504 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
41505 }
41506 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
41507 __func__, stag_state, type, pdid, stag_idx);
41508 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
41509 index 644c2c7..ecf0879 100644
41510 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
41511 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
41512 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
41513 }
41514
41515 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
41516 - ipath_mapping_error,
41517 - ipath_dma_map_single,
41518 - ipath_dma_unmap_single,
41519 - ipath_dma_map_page,
41520 - ipath_dma_unmap_page,
41521 - ipath_map_sg,
41522 - ipath_unmap_sg,
41523 - ipath_sg_dma_address,
41524 - ipath_sg_dma_len,
41525 - ipath_sync_single_for_cpu,
41526 - ipath_sync_single_for_device,
41527 - ipath_dma_alloc_coherent,
41528 - ipath_dma_free_coherent
41529 + .mapping_error = ipath_mapping_error,
41530 + .map_single = ipath_dma_map_single,
41531 + .unmap_single = ipath_dma_unmap_single,
41532 + .map_page = ipath_dma_map_page,
41533 + .unmap_page = ipath_dma_unmap_page,
41534 + .map_sg = ipath_map_sg,
41535 + .unmap_sg = ipath_unmap_sg,
41536 + .dma_address = ipath_sg_dma_address,
41537 + .dma_len = ipath_sg_dma_len,
41538 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
41539 + .sync_single_for_device = ipath_sync_single_for_device,
41540 + .alloc_coherent = ipath_dma_alloc_coherent,
41541 + .free_coherent = ipath_dma_free_coherent
41542 };
41543 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
41544 index 79b3dbc..96e5fcc 100644
41545 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
41546 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
41547 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41548 struct ib_atomic_eth *ateth;
41549 struct ipath_ack_entry *e;
41550 u64 vaddr;
41551 - atomic64_t *maddr;
41552 + atomic64_unchecked_t *maddr;
41553 u64 sdata;
41554 u32 rkey;
41555 u8 next;
41556 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41557 IB_ACCESS_REMOTE_ATOMIC)))
41558 goto nack_acc_unlck;
41559 /* Perform atomic OP and save result. */
41560 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41561 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41562 sdata = be64_to_cpu(ateth->swap_data);
41563 e = &qp->s_ack_queue[qp->r_head_ack_queue];
41564 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
41565 - (u64) atomic64_add_return(sdata, maddr) - sdata :
41566 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41567 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41568 be64_to_cpu(ateth->compare_data),
41569 sdata);
41570 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
41571 index 1f95bba..9530f87 100644
41572 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
41573 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
41574 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
41575 unsigned long flags;
41576 struct ib_wc wc;
41577 u64 sdata;
41578 - atomic64_t *maddr;
41579 + atomic64_unchecked_t *maddr;
41580 enum ib_wc_status send_status;
41581
41582 /*
41583 @@ -382,11 +382,11 @@ again:
41584 IB_ACCESS_REMOTE_ATOMIC)))
41585 goto acc_err;
41586 /* Perform atomic OP and save result. */
41587 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41588 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41589 sdata = wqe->wr.wr.atomic.compare_add;
41590 *(u64 *) sqp->s_sge.sge.vaddr =
41591 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
41592 - (u64) atomic64_add_return(sdata, maddr) - sdata :
41593 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41594 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41595 sdata, wqe->wr.wr.atomic.swap);
41596 goto send_comp;
41597 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
41598 index f2a3f48..673ec79 100644
41599 --- a/drivers/infiniband/hw/mlx4/mad.c
41600 +++ b/drivers/infiniband/hw/mlx4/mad.c
41601 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
41602
41603 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
41604 {
41605 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
41606 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
41607 cpu_to_be64(0xff00000000000000LL);
41608 }
41609
41610 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
41611 index 25b2cdf..099ff97 100644
41612 --- a/drivers/infiniband/hw/mlx4/mcg.c
41613 +++ b/drivers/infiniband/hw/mlx4/mcg.c
41614 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
41615 {
41616 char name[20];
41617
41618 - atomic_set(&ctx->tid, 0);
41619 + atomic_set_unchecked(&ctx->tid, 0);
41620 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
41621 ctx->mcg_wq = create_singlethread_workqueue(name);
41622 if (!ctx->mcg_wq)
41623 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41624 index 036b663..c9a8c73 100644
41625 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
41626 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41627 @@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
41628 struct list_head mcg_mgid0_list;
41629 struct workqueue_struct *mcg_wq;
41630 struct mlx4_ib_demux_pv_ctx **tun;
41631 - atomic_t tid;
41632 + atomic_unchecked_t tid;
41633 int flushing; /* flushing the work queue */
41634 };
41635
41636 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
41637 index 9d3e5c1..6f166df 100644
41638 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
41639 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
41640 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
41641 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
41642 }
41643
41644 -int mthca_QUERY_FW(struct mthca_dev *dev)
41645 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
41646 {
41647 struct mthca_mailbox *mailbox;
41648 u32 *outbox;
41649 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41650 CMD_TIME_CLASS_B);
41651 }
41652
41653 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41654 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41655 int num_mtt)
41656 {
41657 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
41658 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
41659 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
41660 }
41661
41662 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41663 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41664 int eq_num)
41665 {
41666 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
41667 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
41668 CMD_TIME_CLASS_B);
41669 }
41670
41671 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41672 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41673 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
41674 void *in_mad, void *response_mad)
41675 {
41676 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
41677 index 87897b9..7e79542 100644
41678 --- a/drivers/infiniband/hw/mthca/mthca_main.c
41679 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
41680 @@ -692,7 +692,7 @@ err_close:
41681 return err;
41682 }
41683
41684 -static int mthca_setup_hca(struct mthca_dev *dev)
41685 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
41686 {
41687 int err;
41688
41689 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41690 index ed9a989..6aa5dc2 100644
41691 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
41692 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41693 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
41694 * through the bitmaps)
41695 */
41696
41697 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41698 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41699 {
41700 int o;
41701 int m;
41702 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41703 return key;
41704 }
41705
41706 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41707 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41708 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41709 {
41710 struct mthca_mailbox *mailbox;
41711 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
41712 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
41713 }
41714
41715 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41716 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41717 u64 *buffer_list, int buffer_size_shift,
41718 int list_len, u64 iova, u64 total_size,
41719 u32 access, struct mthca_mr *mr)
41720 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
41721 index 5b71d43..35a9e14 100644
41722 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
41723 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
41724 @@ -763,7 +763,7 @@ unlock:
41725 return 0;
41726 }
41727
41728 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41729 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41730 {
41731 struct mthca_dev *dev = to_mdev(ibcq->device);
41732 struct mthca_cq *cq = to_mcq(ibcq);
41733 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41734 index 4291410..d2ab1fb 100644
41735 --- a/drivers/infiniband/hw/nes/nes.c
41736 +++ b/drivers/infiniband/hw/nes/nes.c
41737 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41738 LIST_HEAD(nes_adapter_list);
41739 static LIST_HEAD(nes_dev_list);
41740
41741 -atomic_t qps_destroyed;
41742 +atomic_unchecked_t qps_destroyed;
41743
41744 static unsigned int ee_flsh_adapter;
41745 static unsigned int sysfs_nonidx_addr;
41746 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41747 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41748 struct nes_adapter *nesadapter = nesdev->nesadapter;
41749
41750 - atomic_inc(&qps_destroyed);
41751 + atomic_inc_unchecked(&qps_destroyed);
41752
41753 /* Free the control structures */
41754
41755 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41756 index 33cc589..3bd6538 100644
41757 --- a/drivers/infiniband/hw/nes/nes.h
41758 +++ b/drivers/infiniband/hw/nes/nes.h
41759 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41760 extern unsigned int wqm_quanta;
41761 extern struct list_head nes_adapter_list;
41762
41763 -extern atomic_t cm_connects;
41764 -extern atomic_t cm_accepts;
41765 -extern atomic_t cm_disconnects;
41766 -extern atomic_t cm_closes;
41767 -extern atomic_t cm_connecteds;
41768 -extern atomic_t cm_connect_reqs;
41769 -extern atomic_t cm_rejects;
41770 -extern atomic_t mod_qp_timouts;
41771 -extern atomic_t qps_created;
41772 -extern atomic_t qps_destroyed;
41773 -extern atomic_t sw_qps_destroyed;
41774 +extern atomic_unchecked_t cm_connects;
41775 +extern atomic_unchecked_t cm_accepts;
41776 +extern atomic_unchecked_t cm_disconnects;
41777 +extern atomic_unchecked_t cm_closes;
41778 +extern atomic_unchecked_t cm_connecteds;
41779 +extern atomic_unchecked_t cm_connect_reqs;
41780 +extern atomic_unchecked_t cm_rejects;
41781 +extern atomic_unchecked_t mod_qp_timouts;
41782 +extern atomic_unchecked_t qps_created;
41783 +extern atomic_unchecked_t qps_destroyed;
41784 +extern atomic_unchecked_t sw_qps_destroyed;
41785 extern u32 mh_detected;
41786 extern u32 mh_pauses_sent;
41787 extern u32 cm_packets_sent;
41788 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41789 extern u32 cm_packets_received;
41790 extern u32 cm_packets_dropped;
41791 extern u32 cm_packets_retrans;
41792 -extern atomic_t cm_listens_created;
41793 -extern atomic_t cm_listens_destroyed;
41794 +extern atomic_unchecked_t cm_listens_created;
41795 +extern atomic_unchecked_t cm_listens_destroyed;
41796 extern u32 cm_backlog_drops;
41797 -extern atomic_t cm_loopbacks;
41798 -extern atomic_t cm_nodes_created;
41799 -extern atomic_t cm_nodes_destroyed;
41800 -extern atomic_t cm_accel_dropped_pkts;
41801 -extern atomic_t cm_resets_recvd;
41802 -extern atomic_t pau_qps_created;
41803 -extern atomic_t pau_qps_destroyed;
41804 +extern atomic_unchecked_t cm_loopbacks;
41805 +extern atomic_unchecked_t cm_nodes_created;
41806 +extern atomic_unchecked_t cm_nodes_destroyed;
41807 +extern atomic_unchecked_t cm_accel_dropped_pkts;
41808 +extern atomic_unchecked_t cm_resets_recvd;
41809 +extern atomic_unchecked_t pau_qps_created;
41810 +extern atomic_unchecked_t pau_qps_destroyed;
41811
41812 extern u32 int_mod_timer_init;
41813 extern u32 int_mod_cq_depth_256;
41814 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41815 index 6b29249..461d143 100644
41816 --- a/drivers/infiniband/hw/nes/nes_cm.c
41817 +++ b/drivers/infiniband/hw/nes/nes_cm.c
41818 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41819 u32 cm_packets_retrans;
41820 u32 cm_packets_created;
41821 u32 cm_packets_received;
41822 -atomic_t cm_listens_created;
41823 -atomic_t cm_listens_destroyed;
41824 +atomic_unchecked_t cm_listens_created;
41825 +atomic_unchecked_t cm_listens_destroyed;
41826 u32 cm_backlog_drops;
41827 -atomic_t cm_loopbacks;
41828 -atomic_t cm_nodes_created;
41829 -atomic_t cm_nodes_destroyed;
41830 -atomic_t cm_accel_dropped_pkts;
41831 -atomic_t cm_resets_recvd;
41832 +atomic_unchecked_t cm_loopbacks;
41833 +atomic_unchecked_t cm_nodes_created;
41834 +atomic_unchecked_t cm_nodes_destroyed;
41835 +atomic_unchecked_t cm_accel_dropped_pkts;
41836 +atomic_unchecked_t cm_resets_recvd;
41837
41838 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41839 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41840 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
41841 /* instance of function pointers for client API */
41842 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
41843 static struct nes_cm_ops nes_cm_api = {
41844 - mini_cm_accelerated,
41845 - mini_cm_listen,
41846 - mini_cm_del_listen,
41847 - mini_cm_connect,
41848 - mini_cm_close,
41849 - mini_cm_accept,
41850 - mini_cm_reject,
41851 - mini_cm_recv_pkt,
41852 - mini_cm_dealloc_core,
41853 - mini_cm_get,
41854 - mini_cm_set
41855 + .accelerated = mini_cm_accelerated,
41856 + .listen = mini_cm_listen,
41857 + .stop_listener = mini_cm_del_listen,
41858 + .connect = mini_cm_connect,
41859 + .close = mini_cm_close,
41860 + .accept = mini_cm_accept,
41861 + .reject = mini_cm_reject,
41862 + .recv_pkt = mini_cm_recv_pkt,
41863 + .destroy_cm_core = mini_cm_dealloc_core,
41864 + .get = mini_cm_get,
41865 + .set = mini_cm_set
41866 };
41867
41868 static struct nes_cm_core *g_cm_core;
41869
41870 -atomic_t cm_connects;
41871 -atomic_t cm_accepts;
41872 -atomic_t cm_disconnects;
41873 -atomic_t cm_closes;
41874 -atomic_t cm_connecteds;
41875 -atomic_t cm_connect_reqs;
41876 -atomic_t cm_rejects;
41877 +atomic_unchecked_t cm_connects;
41878 +atomic_unchecked_t cm_accepts;
41879 +atomic_unchecked_t cm_disconnects;
41880 +atomic_unchecked_t cm_closes;
41881 +atomic_unchecked_t cm_connecteds;
41882 +atomic_unchecked_t cm_connect_reqs;
41883 +atomic_unchecked_t cm_rejects;
41884
41885 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41886 {
41887 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41888 kfree(listener);
41889 listener = NULL;
41890 ret = 0;
41891 - atomic_inc(&cm_listens_destroyed);
41892 + atomic_inc_unchecked(&cm_listens_destroyed);
41893 } else {
41894 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41895 }
41896 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41897 cm_node->rem_mac);
41898
41899 add_hte_node(cm_core, cm_node);
41900 - atomic_inc(&cm_nodes_created);
41901 + atomic_inc_unchecked(&cm_nodes_created);
41902
41903 return cm_node;
41904 }
41905 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41906 }
41907
41908 atomic_dec(&cm_core->node_cnt);
41909 - atomic_inc(&cm_nodes_destroyed);
41910 + atomic_inc_unchecked(&cm_nodes_destroyed);
41911 nesqp = cm_node->nesqp;
41912 if (nesqp) {
41913 nesqp->cm_node = NULL;
41914 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41915
41916 static void drop_packet(struct sk_buff *skb)
41917 {
41918 - atomic_inc(&cm_accel_dropped_pkts);
41919 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
41920 dev_kfree_skb_any(skb);
41921 }
41922
41923 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41924 {
41925
41926 int reset = 0; /* whether to send reset in case of err.. */
41927 - atomic_inc(&cm_resets_recvd);
41928 + atomic_inc_unchecked(&cm_resets_recvd);
41929 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41930 " refcnt=%d\n", cm_node, cm_node->state,
41931 atomic_read(&cm_node->ref_count));
41932 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41933 rem_ref_cm_node(cm_node->cm_core, cm_node);
41934 return NULL;
41935 }
41936 - atomic_inc(&cm_loopbacks);
41937 + atomic_inc_unchecked(&cm_loopbacks);
41938 loopbackremotenode->loopbackpartner = cm_node;
41939 loopbackremotenode->tcp_cntxt.rcv_wscale =
41940 NES_CM_DEFAULT_RCV_WND_SCALE;
41941 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
41942 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
41943 else {
41944 rem_ref_cm_node(cm_core, cm_node);
41945 - atomic_inc(&cm_accel_dropped_pkts);
41946 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
41947 dev_kfree_skb_any(skb);
41948 }
41949 break;
41950 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41951
41952 if ((cm_id) && (cm_id->event_handler)) {
41953 if (issue_disconn) {
41954 - atomic_inc(&cm_disconnects);
41955 + atomic_inc_unchecked(&cm_disconnects);
41956 cm_event.event = IW_CM_EVENT_DISCONNECT;
41957 cm_event.status = disconn_status;
41958 cm_event.local_addr = cm_id->local_addr;
41959 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41960 }
41961
41962 if (issue_close) {
41963 - atomic_inc(&cm_closes);
41964 + atomic_inc_unchecked(&cm_closes);
41965 nes_disconnect(nesqp, 1);
41966
41967 cm_id->provider_data = nesqp;
41968 @@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41969
41970 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
41971 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
41972 - atomic_inc(&cm_accepts);
41973 + atomic_inc_unchecked(&cm_accepts);
41974
41975 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
41976 netdev_refcnt_read(nesvnic->netdev));
41977 @@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
41978 struct nes_cm_core *cm_core;
41979 u8 *start_buff;
41980
41981 - atomic_inc(&cm_rejects);
41982 + atomic_inc_unchecked(&cm_rejects);
41983 cm_node = (struct nes_cm_node *)cm_id->provider_data;
41984 loopback = cm_node->loopbackpartner;
41985 cm_core = cm_node->cm_core;
41986 @@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41987 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
41988 ntohs(laddr->sin_port));
41989
41990 - atomic_inc(&cm_connects);
41991 + atomic_inc_unchecked(&cm_connects);
41992 nesqp->active_conn = 1;
41993
41994 /* cache the cm_id in the qp */
41995 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
41996 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
41997 return err;
41998 }
41999 - atomic_inc(&cm_listens_created);
42000 + atomic_inc_unchecked(&cm_listens_created);
42001 }
42002
42003 cm_id->add_ref(cm_id);
42004 @@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42005
42006 if (nesqp->destroyed)
42007 return;
42008 - atomic_inc(&cm_connecteds);
42009 + atomic_inc_unchecked(&cm_connecteds);
42010 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42011 " local port 0x%04X. jiffies = %lu.\n",
42012 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42013 @@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42014
42015 cm_id->add_ref(cm_id);
42016 ret = cm_id->event_handler(cm_id, &cm_event);
42017 - atomic_inc(&cm_closes);
42018 + atomic_inc_unchecked(&cm_closes);
42019 cm_event.event = IW_CM_EVENT_CLOSE;
42020 cm_event.status = 0;
42021 cm_event.provider_data = cm_id->provider_data;
42022 @@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42023 return;
42024 cm_id = cm_node->cm_id;
42025
42026 - atomic_inc(&cm_connect_reqs);
42027 + atomic_inc_unchecked(&cm_connect_reqs);
42028 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42029 cm_node, cm_id, jiffies);
42030
42031 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42032 return;
42033 cm_id = cm_node->cm_id;
42034
42035 - atomic_inc(&cm_connect_reqs);
42036 + atomic_inc_unchecked(&cm_connect_reqs);
42037 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42038 cm_node, cm_id, jiffies);
42039
42040 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42041 index 4166452..fc952c3 100644
42042 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42043 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42044 @@ -40,8 +40,8 @@
42045 #include "nes.h"
42046 #include "nes_mgt.h"
42047
42048 -atomic_t pau_qps_created;
42049 -atomic_t pau_qps_destroyed;
42050 +atomic_unchecked_t pau_qps_created;
42051 +atomic_unchecked_t pau_qps_destroyed;
42052
42053 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42054 {
42055 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42056 {
42057 struct sk_buff *skb;
42058 unsigned long flags;
42059 - atomic_inc(&pau_qps_destroyed);
42060 + atomic_inc_unchecked(&pau_qps_destroyed);
42061
42062 /* Free packets that have not yet been forwarded */
42063 /* Lock is acquired by skb_dequeue when removing the skb */
42064 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42065 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42066 skb_queue_head_init(&nesqp->pau_list);
42067 spin_lock_init(&nesqp->pau_lock);
42068 - atomic_inc(&pau_qps_created);
42069 + atomic_inc_unchecked(&pau_qps_created);
42070 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42071 }
42072
42073 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42074 index 49eb511..a774366 100644
42075 --- a/drivers/infiniband/hw/nes/nes_nic.c
42076 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42077 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42078 target_stat_values[++index] = mh_detected;
42079 target_stat_values[++index] = mh_pauses_sent;
42080 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42081 - target_stat_values[++index] = atomic_read(&cm_connects);
42082 - target_stat_values[++index] = atomic_read(&cm_accepts);
42083 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42084 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42085 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42086 - target_stat_values[++index] = atomic_read(&cm_rejects);
42087 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42088 - target_stat_values[++index] = atomic_read(&qps_created);
42089 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42090 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42091 - target_stat_values[++index] = atomic_read(&cm_closes);
42092 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42093 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42094 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42095 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42096 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42097 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42098 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42099 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42100 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42101 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42102 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42103 target_stat_values[++index] = cm_packets_sent;
42104 target_stat_values[++index] = cm_packets_bounced;
42105 target_stat_values[++index] = cm_packets_created;
42106 target_stat_values[++index] = cm_packets_received;
42107 target_stat_values[++index] = cm_packets_dropped;
42108 target_stat_values[++index] = cm_packets_retrans;
42109 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42110 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42111 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42112 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42113 target_stat_values[++index] = cm_backlog_drops;
42114 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42115 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42116 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42117 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42118 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42119 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42120 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42121 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42122 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42123 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42124 target_stat_values[++index] = nesadapter->free_4kpbl;
42125 target_stat_values[++index] = nesadapter->free_256pbl;
42126 target_stat_values[++index] = int_mod_timer_init;
42127 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42128 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42129 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42130 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42131 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42132 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42133 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42134 }
42135
42136 /**
42137 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42138 index 8308e36..ae0d3b5 100644
42139 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42140 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42141 @@ -46,9 +46,9 @@
42142
42143 #include <rdma/ib_umem.h>
42144
42145 -atomic_t mod_qp_timouts;
42146 -atomic_t qps_created;
42147 -atomic_t sw_qps_destroyed;
42148 +atomic_unchecked_t mod_qp_timouts;
42149 +atomic_unchecked_t qps_created;
42150 +atomic_unchecked_t sw_qps_destroyed;
42151
42152 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42153
42154 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42155 if (init_attr->create_flags)
42156 return ERR_PTR(-EINVAL);
42157
42158 - atomic_inc(&qps_created);
42159 + atomic_inc_unchecked(&qps_created);
42160 switch (init_attr->qp_type) {
42161 case IB_QPT_RC:
42162 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42163 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42164 struct iw_cm_event cm_event;
42165 int ret = 0;
42166
42167 - atomic_inc(&sw_qps_destroyed);
42168 + atomic_inc_unchecked(&sw_qps_destroyed);
42169 nesqp->destroyed = 1;
42170
42171 /* Blow away the connection if it exists. */
42172 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42173 index 1946101..09766d2 100644
42174 --- a/drivers/infiniband/hw/qib/qib.h
42175 +++ b/drivers/infiniband/hw/qib/qib.h
42176 @@ -52,6 +52,7 @@
42177 #include <linux/kref.h>
42178 #include <linux/sched.h>
42179 #include <linux/kthread.h>
42180 +#include <linux/slab.h>
42181
42182 #include "qib_common.h"
42183 #include "qib_verbs.h"
42184 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42185 index 24c41ba..102d71f 100644
42186 --- a/drivers/input/gameport/gameport.c
42187 +++ b/drivers/input/gameport/gameport.c
42188 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42189 */
42190 static void gameport_init_port(struct gameport *gameport)
42191 {
42192 - static atomic_t gameport_no = ATOMIC_INIT(0);
42193 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42194
42195 __module_get(THIS_MODULE);
42196
42197 mutex_init(&gameport->drv_mutex);
42198 device_initialize(&gameport->dev);
42199 dev_set_name(&gameport->dev, "gameport%lu",
42200 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42201 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42202 gameport->dev.bus = &gameport_bus;
42203 gameport->dev.release = gameport_release_port;
42204 if (gameport->parent)
42205 diff --git a/drivers/input/input.c b/drivers/input/input.c
42206 index d2965e4..f52b7d7 100644
42207 --- a/drivers/input/input.c
42208 +++ b/drivers/input/input.c
42209 @@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42210 */
42211 struct input_dev *input_allocate_device(void)
42212 {
42213 - static atomic_t input_no = ATOMIC_INIT(0);
42214 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42215 struct input_dev *dev;
42216
42217 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42218 @@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42219 INIT_LIST_HEAD(&dev->node);
42220
42221 dev_set_name(&dev->dev, "input%ld",
42222 - (unsigned long) atomic_inc_return(&input_no) - 1);
42223 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42224
42225 __module_get(THIS_MODULE);
42226 }
42227 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42228 index 04c69af..5f92d00 100644
42229 --- a/drivers/input/joystick/sidewinder.c
42230 +++ b/drivers/input/joystick/sidewinder.c
42231 @@ -30,6 +30,7 @@
42232 #include <linux/kernel.h>
42233 #include <linux/module.h>
42234 #include <linux/slab.h>
42235 +#include <linux/sched.h>
42236 #include <linux/init.h>
42237 #include <linux/input.h>
42238 #include <linux/gameport.h>
42239 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42240 index 75e3b10..fb390fd 100644
42241 --- a/drivers/input/joystick/xpad.c
42242 +++ b/drivers/input/joystick/xpad.c
42243 @@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42244
42245 static int xpad_led_probe(struct usb_xpad *xpad)
42246 {
42247 - static atomic_t led_seq = ATOMIC_INIT(0);
42248 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42249 long led_no;
42250 struct xpad_led *led;
42251 struct led_classdev *led_cdev;
42252 @@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42253 if (!led)
42254 return -ENOMEM;
42255
42256 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42257 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42258
42259 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42260 led->xpad = xpad;
42261 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42262 index e204f26..8459f15 100644
42263 --- a/drivers/input/misc/ims-pcu.c
42264 +++ b/drivers/input/misc/ims-pcu.c
42265 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42266
42267 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42268 {
42269 - static atomic_t device_no = ATOMIC_INIT(0);
42270 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42271
42272 const struct ims_pcu_device_info *info;
42273 u8 device_id;
42274 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42275 }
42276
42277 /* Device appears to be operable, complete initialization */
42278 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42279 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42280
42281 error = ims_pcu_setup_backlight(pcu);
42282 if (error)
42283 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42284 index 2f0b39d..7370f13 100644
42285 --- a/drivers/input/mouse/psmouse.h
42286 +++ b/drivers/input/mouse/psmouse.h
42287 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42288 ssize_t (*set)(struct psmouse *psmouse, void *data,
42289 const char *buf, size_t count);
42290 bool protect;
42291 -};
42292 +} __do_const;
42293 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42294
42295 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42296 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42297 index 4c842c3..590b0bf 100644
42298 --- a/drivers/input/mousedev.c
42299 +++ b/drivers/input/mousedev.c
42300 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42301
42302 spin_unlock_irq(&client->packet_lock);
42303
42304 - if (copy_to_user(buffer, data, count))
42305 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42306 return -EFAULT;
42307
42308 return count;
42309 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42310 index 8f4c4ab..5fc8a45 100644
42311 --- a/drivers/input/serio/serio.c
42312 +++ b/drivers/input/serio/serio.c
42313 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42314 */
42315 static void serio_init_port(struct serio *serio)
42316 {
42317 - static atomic_t serio_no = ATOMIC_INIT(0);
42318 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42319
42320 __module_get(THIS_MODULE);
42321
42322 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42323 mutex_init(&serio->drv_mutex);
42324 device_initialize(&serio->dev);
42325 dev_set_name(&serio->dev, "serio%ld",
42326 - (long)atomic_inc_return(&serio_no) - 1);
42327 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42328 serio->dev.bus = &serio_bus;
42329 serio->dev.release = serio_release_port;
42330 serio->dev.groups = serio_device_attr_groups;
42331 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42332 index 59df2e7..8f1cafb 100644
42333 --- a/drivers/input/serio/serio_raw.c
42334 +++ b/drivers/input/serio/serio_raw.c
42335 @@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42336
42337 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42338 {
42339 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42340 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42341 struct serio_raw *serio_raw;
42342 int err;
42343
42344 @@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42345 }
42346
42347 snprintf(serio_raw->name, sizeof(serio_raw->name),
42348 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42349 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42350 kref_init(&serio_raw->kref);
42351 INIT_LIST_HEAD(&serio_raw->client_list);
42352 init_waitqueue_head(&serio_raw->wait);
42353 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42354 index e5555fc..937986d 100644
42355 --- a/drivers/iommu/iommu.c
42356 +++ b/drivers/iommu/iommu.c
42357 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42358 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42359 {
42360 bus_register_notifier(bus, &iommu_bus_nb);
42361 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42362 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42363 }
42364
42365 /**
42366 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42367 index 39f81ae..2660096 100644
42368 --- a/drivers/iommu/irq_remapping.c
42369 +++ b/drivers/iommu/irq_remapping.c
42370 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42371 void panic_if_irq_remap(const char *msg)
42372 {
42373 if (irq_remapping_enabled)
42374 - panic(msg);
42375 + panic("%s", msg);
42376 }
42377
42378 static void ir_ack_apic_edge(struct irq_data *data)
42379 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42380
42381 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42382 {
42383 - chip->irq_print_chip = ir_print_prefix;
42384 - chip->irq_ack = ir_ack_apic_edge;
42385 - chip->irq_eoi = ir_ack_apic_level;
42386 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42387 + pax_open_kernel();
42388 + *(void **)&chip->irq_print_chip = ir_print_prefix;
42389 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
42390 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
42391 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42392 + pax_close_kernel();
42393 }
42394
42395 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42396 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42397 index 341c601..e5f407e 100644
42398 --- a/drivers/irqchip/irq-gic.c
42399 +++ b/drivers/irqchip/irq-gic.c
42400 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42401 * Supported arch specific GIC irq extension.
42402 * Default make them NULL.
42403 */
42404 -struct irq_chip gic_arch_extn = {
42405 +irq_chip_no_const gic_arch_extn = {
42406 .irq_eoi = NULL,
42407 .irq_mask = NULL,
42408 .irq_unmask = NULL,
42409 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42410 chained_irq_exit(chip, desc);
42411 }
42412
42413 -static struct irq_chip gic_chip = {
42414 +static irq_chip_no_const gic_chip __read_only = {
42415 .name = "GIC",
42416 .irq_mask = gic_mask_irq,
42417 .irq_unmask = gic_unmask_irq,
42418 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
42419 index ac6f72b..81150f2 100644
42420 --- a/drivers/isdn/capi/capi.c
42421 +++ b/drivers/isdn/capi/capi.c
42422 @@ -81,8 +81,8 @@ struct capiminor {
42423
42424 struct capi20_appl *ap;
42425 u32 ncci;
42426 - atomic_t datahandle;
42427 - atomic_t msgid;
42428 + atomic_unchecked_t datahandle;
42429 + atomic_unchecked_t msgid;
42430
42431 struct tty_port port;
42432 int ttyinstop;
42433 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
42434 capimsg_setu16(s, 2, mp->ap->applid);
42435 capimsg_setu8 (s, 4, CAPI_DATA_B3);
42436 capimsg_setu8 (s, 5, CAPI_RESP);
42437 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
42438 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
42439 capimsg_setu32(s, 8, mp->ncci);
42440 capimsg_setu16(s, 12, datahandle);
42441 }
42442 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
42443 mp->outbytes -= len;
42444 spin_unlock_bh(&mp->outlock);
42445
42446 - datahandle = atomic_inc_return(&mp->datahandle);
42447 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
42448 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
42449 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42450 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42451 capimsg_setu16(skb->data, 2, mp->ap->applid);
42452 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
42453 capimsg_setu8 (skb->data, 5, CAPI_REQ);
42454 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
42455 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
42456 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
42457 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
42458 capimsg_setu16(skb->data, 16, len); /* Data length */
42459 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
42460 index c44950d..10ac276 100644
42461 --- a/drivers/isdn/gigaset/bas-gigaset.c
42462 +++ b/drivers/isdn/gigaset/bas-gigaset.c
42463 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
42464
42465
42466 static const struct gigaset_ops gigops = {
42467 - gigaset_write_cmd,
42468 - gigaset_write_room,
42469 - gigaset_chars_in_buffer,
42470 - gigaset_brkchars,
42471 - gigaset_init_bchannel,
42472 - gigaset_close_bchannel,
42473 - gigaset_initbcshw,
42474 - gigaset_freebcshw,
42475 - gigaset_reinitbcshw,
42476 - gigaset_initcshw,
42477 - gigaset_freecshw,
42478 - gigaset_set_modem_ctrl,
42479 - gigaset_baud_rate,
42480 - gigaset_set_line_ctrl,
42481 - gigaset_isoc_send_skb,
42482 - gigaset_isoc_input,
42483 + .write_cmd = gigaset_write_cmd,
42484 + .write_room = gigaset_write_room,
42485 + .chars_in_buffer = gigaset_chars_in_buffer,
42486 + .brkchars = gigaset_brkchars,
42487 + .init_bchannel = gigaset_init_bchannel,
42488 + .close_bchannel = gigaset_close_bchannel,
42489 + .initbcshw = gigaset_initbcshw,
42490 + .freebcshw = gigaset_freebcshw,
42491 + .reinitbcshw = gigaset_reinitbcshw,
42492 + .initcshw = gigaset_initcshw,
42493 + .freecshw = gigaset_freecshw,
42494 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42495 + .baud_rate = gigaset_baud_rate,
42496 + .set_line_ctrl = gigaset_set_line_ctrl,
42497 + .send_skb = gigaset_isoc_send_skb,
42498 + .handle_input = gigaset_isoc_input,
42499 };
42500
42501 /* bas_gigaset_init
42502 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
42503 index 600c79b..3752bab 100644
42504 --- a/drivers/isdn/gigaset/interface.c
42505 +++ b/drivers/isdn/gigaset/interface.c
42506 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
42507 }
42508 tty->driver_data = cs;
42509
42510 - ++cs->port.count;
42511 + atomic_inc(&cs->port.count);
42512
42513 - if (cs->port.count == 1) {
42514 + if (atomic_read(&cs->port.count) == 1) {
42515 tty_port_tty_set(&cs->port, tty);
42516 cs->port.low_latency = 1;
42517 }
42518 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
42519
42520 if (!cs->connected)
42521 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
42522 - else if (!cs->port.count)
42523 + else if (!atomic_read(&cs->port.count))
42524 dev_warn(cs->dev, "%s: device not opened\n", __func__);
42525 - else if (!--cs->port.count)
42526 + else if (!atomic_dec_return(&cs->port.count))
42527 tty_port_tty_set(&cs->port, NULL);
42528
42529 mutex_unlock(&cs->mutex);
42530 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
42531 index 8c91fd5..14f13ce 100644
42532 --- a/drivers/isdn/gigaset/ser-gigaset.c
42533 +++ b/drivers/isdn/gigaset/ser-gigaset.c
42534 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
42535 }
42536
42537 static const struct gigaset_ops ops = {
42538 - gigaset_write_cmd,
42539 - gigaset_write_room,
42540 - gigaset_chars_in_buffer,
42541 - gigaset_brkchars,
42542 - gigaset_init_bchannel,
42543 - gigaset_close_bchannel,
42544 - gigaset_initbcshw,
42545 - gigaset_freebcshw,
42546 - gigaset_reinitbcshw,
42547 - gigaset_initcshw,
42548 - gigaset_freecshw,
42549 - gigaset_set_modem_ctrl,
42550 - gigaset_baud_rate,
42551 - gigaset_set_line_ctrl,
42552 - gigaset_m10x_send_skb, /* asyncdata.c */
42553 - gigaset_m10x_input, /* asyncdata.c */
42554 + .write_cmd = gigaset_write_cmd,
42555 + .write_room = gigaset_write_room,
42556 + .chars_in_buffer = gigaset_chars_in_buffer,
42557 + .brkchars = gigaset_brkchars,
42558 + .init_bchannel = gigaset_init_bchannel,
42559 + .close_bchannel = gigaset_close_bchannel,
42560 + .initbcshw = gigaset_initbcshw,
42561 + .freebcshw = gigaset_freebcshw,
42562 + .reinitbcshw = gigaset_reinitbcshw,
42563 + .initcshw = gigaset_initcshw,
42564 + .freecshw = gigaset_freecshw,
42565 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42566 + .baud_rate = gigaset_baud_rate,
42567 + .set_line_ctrl = gigaset_set_line_ctrl,
42568 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
42569 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
42570 };
42571
42572
42573 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
42574 index d0a41cb..b953e50 100644
42575 --- a/drivers/isdn/gigaset/usb-gigaset.c
42576 +++ b/drivers/isdn/gigaset/usb-gigaset.c
42577 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
42578 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
42579 memcpy(cs->hw.usb->bchars, buf, 6);
42580 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
42581 - 0, 0, &buf, 6, 2000);
42582 + 0, 0, buf, 6, 2000);
42583 }
42584
42585 static void gigaset_freebcshw(struct bc_state *bcs)
42586 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
42587 }
42588
42589 static const struct gigaset_ops ops = {
42590 - gigaset_write_cmd,
42591 - gigaset_write_room,
42592 - gigaset_chars_in_buffer,
42593 - gigaset_brkchars,
42594 - gigaset_init_bchannel,
42595 - gigaset_close_bchannel,
42596 - gigaset_initbcshw,
42597 - gigaset_freebcshw,
42598 - gigaset_reinitbcshw,
42599 - gigaset_initcshw,
42600 - gigaset_freecshw,
42601 - gigaset_set_modem_ctrl,
42602 - gigaset_baud_rate,
42603 - gigaset_set_line_ctrl,
42604 - gigaset_m10x_send_skb,
42605 - gigaset_m10x_input,
42606 + .write_cmd = gigaset_write_cmd,
42607 + .write_room = gigaset_write_room,
42608 + .chars_in_buffer = gigaset_chars_in_buffer,
42609 + .brkchars = gigaset_brkchars,
42610 + .init_bchannel = gigaset_init_bchannel,
42611 + .close_bchannel = gigaset_close_bchannel,
42612 + .initbcshw = gigaset_initbcshw,
42613 + .freebcshw = gigaset_freebcshw,
42614 + .reinitbcshw = gigaset_reinitbcshw,
42615 + .initcshw = gigaset_initcshw,
42616 + .freecshw = gigaset_freecshw,
42617 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42618 + .baud_rate = gigaset_baud_rate,
42619 + .set_line_ctrl = gigaset_set_line_ctrl,
42620 + .send_skb = gigaset_m10x_send_skb,
42621 + .handle_input = gigaset_m10x_input,
42622 };
42623
42624 /*
42625 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
42626 index 4d9b195..455075c 100644
42627 --- a/drivers/isdn/hardware/avm/b1.c
42628 +++ b/drivers/isdn/hardware/avm/b1.c
42629 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
42630 }
42631 if (left) {
42632 if (t4file->user) {
42633 - if (copy_from_user(buf, dp, left))
42634 + if (left > sizeof buf || copy_from_user(buf, dp, left))
42635 return -EFAULT;
42636 } else {
42637 memcpy(buf, dp, left);
42638 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
42639 }
42640 if (left) {
42641 if (config->user) {
42642 - if (copy_from_user(buf, dp, left))
42643 + if (left > sizeof buf || copy_from_user(buf, dp, left))
42644 return -EFAULT;
42645 } else {
42646 memcpy(buf, dp, left);
42647 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42648 index 9bb12ba..d4262f7 100644
42649 --- a/drivers/isdn/i4l/isdn_common.c
42650 +++ b/drivers/isdn/i4l/isdn_common.c
42651 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42652 } else
42653 return -EINVAL;
42654 case IIOCDBGVAR:
42655 + if (!capable(CAP_SYS_RAWIO))
42656 + return -EPERM;
42657 if (arg) {
42658 if (copy_to_user(argp, &dev, sizeof(ulong)))
42659 return -EFAULT;
42660 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
42661 index 91d5730..336523e 100644
42662 --- a/drivers/isdn/i4l/isdn_concap.c
42663 +++ b/drivers/isdn/i4l/isdn_concap.c
42664 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
42665 }
42666
42667 struct concap_device_ops isdn_concap_reliable_dl_dops = {
42668 - &isdn_concap_dl_data_req,
42669 - &isdn_concap_dl_connect_req,
42670 - &isdn_concap_dl_disconn_req
42671 + .data_req = &isdn_concap_dl_data_req,
42672 + .connect_req = &isdn_concap_dl_connect_req,
42673 + .disconn_req = &isdn_concap_dl_disconn_req
42674 };
42675
42676 /* The following should better go into a dedicated source file such that
42677 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42678 index 3c5f249..5fac4d0 100644
42679 --- a/drivers/isdn/i4l/isdn_tty.c
42680 +++ b/drivers/isdn/i4l/isdn_tty.c
42681 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42682
42683 #ifdef ISDN_DEBUG_MODEM_OPEN
42684 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42685 - port->count);
42686 + atomic_read(&port->count));
42687 #endif
42688 - port->count++;
42689 + atomic_inc(&port->count);
42690 port->tty = tty;
42691 /*
42692 * Start up serial port
42693 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42694 #endif
42695 return;
42696 }
42697 - if ((tty->count == 1) && (port->count != 1)) {
42698 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42699 /*
42700 * Uh, oh. tty->count is 1, which means that the tty
42701 * structure will be freed. Info->count should always
42702 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42703 * serial port won't be shutdown.
42704 */
42705 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42706 - "info->count is %d\n", port->count);
42707 - port->count = 1;
42708 + "info->count is %d\n", atomic_read(&port->count));
42709 + atomic_set(&port->count, 1);
42710 }
42711 - if (--port->count < 0) {
42712 + if (atomic_dec_return(&port->count) < 0) {
42713 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42714 - info->line, port->count);
42715 - port->count = 0;
42716 + info->line, atomic_read(&port->count));
42717 + atomic_set(&port->count, 0);
42718 }
42719 - if (port->count) {
42720 + if (atomic_read(&port->count)) {
42721 #ifdef ISDN_DEBUG_MODEM_OPEN
42722 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42723 #endif
42724 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42725 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42726 return;
42727 isdn_tty_shutdown(info);
42728 - port->count = 0;
42729 + atomic_set(&port->count, 0);
42730 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42731 port->tty = NULL;
42732 wake_up_interruptible(&port->open_wait);
42733 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42734 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42735 modem_info *info = &dev->mdm.info[i];
42736
42737 - if (info->port.count == 0)
42738 + if (atomic_read(&info->port.count) == 0)
42739 continue;
42740 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42741 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42742 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
42743 index e2d4e58..40cd045 100644
42744 --- a/drivers/isdn/i4l/isdn_x25iface.c
42745 +++ b/drivers/isdn/i4l/isdn_x25iface.c
42746 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
42747
42748
42749 static struct concap_proto_ops ix25_pops = {
42750 - &isdn_x25iface_proto_new,
42751 - &isdn_x25iface_proto_del,
42752 - &isdn_x25iface_proto_restart,
42753 - &isdn_x25iface_proto_close,
42754 - &isdn_x25iface_xmit,
42755 - &isdn_x25iface_receive,
42756 - &isdn_x25iface_connect_ind,
42757 - &isdn_x25iface_disconn_ind
42758 + .proto_new = &isdn_x25iface_proto_new,
42759 + .proto_del = &isdn_x25iface_proto_del,
42760 + .restart = &isdn_x25iface_proto_restart,
42761 + .close = &isdn_x25iface_proto_close,
42762 + .encap_and_xmit = &isdn_x25iface_xmit,
42763 + .data_ind = &isdn_x25iface_receive,
42764 + .connect_ind = &isdn_x25iface_connect_ind,
42765 + .disconn_ind = &isdn_x25iface_disconn_ind
42766 };
42767
42768 /* error message helper function */
42769 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42770 index 53d487f..f020f41 100644
42771 --- a/drivers/isdn/icn/icn.c
42772 +++ b/drivers/isdn/icn/icn.c
42773 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42774 if (count > len)
42775 count = len;
42776 if (user) {
42777 - if (copy_from_user(msg, buf, count))
42778 + if (count > sizeof msg || copy_from_user(msg, buf, count))
42779 return -EFAULT;
42780 } else
42781 memcpy(msg, buf, count);
42782 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
42783 index a4f05c5..1433bc5 100644
42784 --- a/drivers/isdn/mISDN/dsp_cmx.c
42785 +++ b/drivers/isdn/mISDN/dsp_cmx.c
42786 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
42787 static u16 dsp_count; /* last sample count */
42788 static int dsp_count_valid; /* if we have last sample count */
42789
42790 -void
42791 +void __intentional_overflow(-1)
42792 dsp_cmx_send(void *arg)
42793 {
42794 struct dsp_conf *conf;
42795 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42796 index d93e245..e7ece6b 100644
42797 --- a/drivers/leds/leds-clevo-mail.c
42798 +++ b/drivers/leds/leds-clevo-mail.c
42799 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42800 * detected as working, but in reality it is not) as low as
42801 * possible.
42802 */
42803 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
42804 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
42805 {
42806 .callback = clevo_mail_led_dmi_callback,
42807 .ident = "Clevo D410J",
42808 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42809 index 5b8f938..b73d657 100644
42810 --- a/drivers/leds/leds-ss4200.c
42811 +++ b/drivers/leds/leds-ss4200.c
42812 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42813 * detected as working, but in reality it is not) as low as
42814 * possible.
42815 */
42816 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
42817 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
42818 {
42819 .callback = ss4200_led_dmi_callback,
42820 .ident = "Intel SS4200-E",
42821 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42822 index 0bf1e4e..b4bf44e 100644
42823 --- a/drivers/lguest/core.c
42824 +++ b/drivers/lguest/core.c
42825 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
42826 * The end address needs +1 because __get_vm_area allocates an
42827 * extra guard page, so we need space for that.
42828 */
42829 +
42830 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42831 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42832 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42833 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42834 +#else
42835 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42836 VM_ALLOC, switcher_addr, switcher_addr
42837 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42838 +#endif
42839 +
42840 if (!switcher_vma) {
42841 err = -ENOMEM;
42842 printk("lguest: could not map switcher pages high\n");
42843 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
42844 * Now the Switcher is mapped at the right address, we can't fail!
42845 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42846 */
42847 - memcpy(switcher_vma->addr, start_switcher_text,
42848 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42849 end_switcher_text - start_switcher_text);
42850
42851 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42852 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42853 index bfb39bb..08a603b 100644
42854 --- a/drivers/lguest/page_tables.c
42855 +++ b/drivers/lguest/page_tables.c
42856 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42857 /*:*/
42858
42859 #ifdef CONFIG_X86_PAE
42860 -static void release_pmd(pmd_t *spmd)
42861 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42862 {
42863 /* If the entry's not present, there's nothing to release. */
42864 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42865 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42866 index 922a1ac..9dd0c2a 100644
42867 --- a/drivers/lguest/x86/core.c
42868 +++ b/drivers/lguest/x86/core.c
42869 @@ -59,7 +59,7 @@ static struct {
42870 /* Offset from where switcher.S was compiled to where we've copied it */
42871 static unsigned long switcher_offset(void)
42872 {
42873 - return switcher_addr - (unsigned long)start_switcher_text;
42874 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42875 }
42876
42877 /* This cpu's struct lguest_pages (after the Switcher text page) */
42878 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42879 * These copies are pretty cheap, so we do them unconditionally: */
42880 /* Save the current Host top-level page directory.
42881 */
42882 +
42883 +#ifdef CONFIG_PAX_PER_CPU_PGD
42884 + pages->state.host_cr3 = read_cr3();
42885 +#else
42886 pages->state.host_cr3 = __pa(current->mm->pgd);
42887 +#endif
42888 +
42889 /*
42890 * Set up the Guest's page tables to see this CPU's pages (and no
42891 * other CPU's pages).
42892 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
42893 * compiled-in switcher code and the high-mapped copy we just made.
42894 */
42895 for (i = 0; i < IDT_ENTRIES; i++)
42896 - default_idt_entries[i] += switcher_offset();
42897 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42898
42899 /*
42900 * Set up the Switcher's per-cpu areas.
42901 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
42902 * it will be undisturbed when we switch. To change %cs and jump we
42903 * need this structure to feed to Intel's "lcall" instruction.
42904 */
42905 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42906 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42907 lguest_entry.segment = LGUEST_CS;
42908
42909 /*
42910 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42911 index 40634b0..4f5855e 100644
42912 --- a/drivers/lguest/x86/switcher_32.S
42913 +++ b/drivers/lguest/x86/switcher_32.S
42914 @@ -87,6 +87,7 @@
42915 #include <asm/page.h>
42916 #include <asm/segment.h>
42917 #include <asm/lguest.h>
42918 +#include <asm/processor-flags.h>
42919
42920 // We mark the start of the code to copy
42921 // It's placed in .text tho it's never run here
42922 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42923 // Changes type when we load it: damn Intel!
42924 // For after we switch over our page tables
42925 // That entry will be read-only: we'd crash.
42926 +
42927 +#ifdef CONFIG_PAX_KERNEXEC
42928 + mov %cr0, %edx
42929 + xor $X86_CR0_WP, %edx
42930 + mov %edx, %cr0
42931 +#endif
42932 +
42933 movl $(GDT_ENTRY_TSS*8), %edx
42934 ltr %dx
42935
42936 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42937 // Let's clear it again for our return.
42938 // The GDT descriptor of the Host
42939 // Points to the table after two "size" bytes
42940 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42941 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42942 // Clear "used" from type field (byte 5, bit 2)
42943 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42944 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42945 +
42946 +#ifdef CONFIG_PAX_KERNEXEC
42947 + mov %cr0, %eax
42948 + xor $X86_CR0_WP, %eax
42949 + mov %eax, %cr0
42950 +#endif
42951
42952 // Once our page table's switched, the Guest is live!
42953 // The Host fades as we run this final step.
42954 @@ -295,13 +309,12 @@ deliver_to_host:
42955 // I consulted gcc, and it gave
42956 // These instructions, which I gladly credit:
42957 leal (%edx,%ebx,8), %eax
42958 - movzwl (%eax),%edx
42959 - movl 4(%eax), %eax
42960 - xorw %ax, %ax
42961 - orl %eax, %edx
42962 + movl 4(%eax), %edx
42963 + movw (%eax), %dx
42964 // Now the address of the handler's in %edx
42965 // We call it now: its "iret" drops us home.
42966 - jmp *%edx
42967 + ljmp $__KERNEL_CS, $1f
42968 +1: jmp *%edx
42969
42970 // Every interrupt can come to us here
42971 // But we must truly tell each apart.
42972 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42973 index 9762f1b..3e79734 100644
42974 --- a/drivers/md/bcache/closure.h
42975 +++ b/drivers/md/bcache/closure.h
42976 @@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
42977 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42978 struct workqueue_struct *wq)
42979 {
42980 - BUG_ON(object_is_on_stack(cl));
42981 + BUG_ON(object_starts_on_stack(cl));
42982 closure_set_ip(cl);
42983 cl->fn = fn;
42984 cl->wq = wq;
42985 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42986 index 12dc29b..1596277 100644
42987 --- a/drivers/md/bitmap.c
42988 +++ b/drivers/md/bitmap.c
42989 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42990 chunk_kb ? "KB" : "B");
42991 if (bitmap->storage.file) {
42992 seq_printf(seq, ", file: ");
42993 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42994 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42995 }
42996
42997 seq_printf(seq, "\n");
42998 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42999 index 5152142..623d141 100644
43000 --- a/drivers/md/dm-ioctl.c
43001 +++ b/drivers/md/dm-ioctl.c
43002 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43003 cmd == DM_LIST_VERSIONS_CMD)
43004 return 0;
43005
43006 - if ((cmd == DM_DEV_CREATE_CMD)) {
43007 + if (cmd == DM_DEV_CREATE_CMD) {
43008 if (!*param->name) {
43009 DMWARN("name not supplied when creating device");
43010 return -EINVAL;
43011 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43012 index 9584443..9fc9ac9 100644
43013 --- a/drivers/md/dm-raid1.c
43014 +++ b/drivers/md/dm-raid1.c
43015 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43016
43017 struct mirror {
43018 struct mirror_set *ms;
43019 - atomic_t error_count;
43020 + atomic_unchecked_t error_count;
43021 unsigned long error_type;
43022 struct dm_dev *dev;
43023 sector_t offset;
43024 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43025 struct mirror *m;
43026
43027 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43028 - if (!atomic_read(&m->error_count))
43029 + if (!atomic_read_unchecked(&m->error_count))
43030 return m;
43031
43032 return NULL;
43033 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43034 * simple way to tell if a device has encountered
43035 * errors.
43036 */
43037 - atomic_inc(&m->error_count);
43038 + atomic_inc_unchecked(&m->error_count);
43039
43040 if (test_and_set_bit(error_type, &m->error_type))
43041 return;
43042 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43043 struct mirror *m = get_default_mirror(ms);
43044
43045 do {
43046 - if (likely(!atomic_read(&m->error_count)))
43047 + if (likely(!atomic_read_unchecked(&m->error_count)))
43048 return m;
43049
43050 if (m-- == ms->mirror)
43051 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43052 {
43053 struct mirror *default_mirror = get_default_mirror(m->ms);
43054
43055 - return !atomic_read(&default_mirror->error_count);
43056 + return !atomic_read_unchecked(&default_mirror->error_count);
43057 }
43058
43059 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43060 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43061 */
43062 if (likely(region_in_sync(ms, region, 1)))
43063 m = choose_mirror(ms, bio->bi_sector);
43064 - else if (m && atomic_read(&m->error_count))
43065 + else if (m && atomic_read_unchecked(&m->error_count))
43066 m = NULL;
43067
43068 if (likely(m))
43069 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43070 }
43071
43072 ms->mirror[mirror].ms = ms;
43073 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43074 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43075 ms->mirror[mirror].error_type = 0;
43076 ms->mirror[mirror].offset = offset;
43077
43078 @@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43079 */
43080 static char device_status_char(struct mirror *m)
43081 {
43082 - if (!atomic_read(&(m->error_count)))
43083 + if (!atomic_read_unchecked(&(m->error_count)))
43084 return 'A';
43085
43086 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43087 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43088 index 28a9012..9c0f6a5 100644
43089 --- a/drivers/md/dm-stats.c
43090 +++ b/drivers/md/dm-stats.c
43091 @@ -382,7 +382,7 @@ do_sync_free:
43092 synchronize_rcu_expedited();
43093 dm_stat_free(&s->rcu_head);
43094 } else {
43095 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43096 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43097 call_rcu(&s->rcu_head, dm_stat_free);
43098 }
43099 return 0;
43100 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43101 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43102 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43103 ));
43104 - ACCESS_ONCE(last->last_sector) = end_sector;
43105 - ACCESS_ONCE(last->last_rw) = bi_rw;
43106 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43107 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43108 }
43109
43110 rcu_read_lock();
43111 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43112 index 73c1712..7347292 100644
43113 --- a/drivers/md/dm-stripe.c
43114 +++ b/drivers/md/dm-stripe.c
43115 @@ -21,7 +21,7 @@ struct stripe {
43116 struct dm_dev *dev;
43117 sector_t physical_start;
43118
43119 - atomic_t error_count;
43120 + atomic_unchecked_t error_count;
43121 };
43122
43123 struct stripe_c {
43124 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43125 kfree(sc);
43126 return r;
43127 }
43128 - atomic_set(&(sc->stripe[i].error_count), 0);
43129 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43130 }
43131
43132 ti->private = sc;
43133 @@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43134 DMEMIT("%d ", sc->stripes);
43135 for (i = 0; i < sc->stripes; i++) {
43136 DMEMIT("%s ", sc->stripe[i].dev->name);
43137 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43138 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43139 'D' : 'A';
43140 }
43141 buffer[i] = '\0';
43142 @@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43143 */
43144 for (i = 0; i < sc->stripes; i++)
43145 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43146 - atomic_inc(&(sc->stripe[i].error_count));
43147 - if (atomic_read(&(sc->stripe[i].error_count)) <
43148 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43149 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43150 DM_IO_ERROR_THRESHOLD)
43151 schedule_work(&sc->trigger_event);
43152 }
43153 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43154 index 3ba6a38..b0fa9b0 100644
43155 --- a/drivers/md/dm-table.c
43156 +++ b/drivers/md/dm-table.c
43157 @@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43158 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43159 struct mapped_device *md)
43160 {
43161 - static char *_claim_ptr = "I belong to device-mapper";
43162 + static char _claim_ptr[] = "I belong to device-mapper";
43163 struct block_device *bdev;
43164
43165 int r;
43166 @@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43167 if (!dev_size)
43168 return 0;
43169
43170 - if ((start >= dev_size) || (start + len > dev_size)) {
43171 + if ((start >= dev_size) || (len > dev_size - start)) {
43172 DMWARN("%s: %s too small for target: "
43173 "start=%llu, len=%llu, dev_size=%llu",
43174 dm_device_name(ti->table->md), bdevname(bdev, b),
43175 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43176 index 8a30ad5..72792d3 100644
43177 --- a/drivers/md/dm-thin-metadata.c
43178 +++ b/drivers/md/dm-thin-metadata.c
43179 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43180 {
43181 pmd->info.tm = pmd->tm;
43182 pmd->info.levels = 2;
43183 - pmd->info.value_type.context = pmd->data_sm;
43184 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43185 pmd->info.value_type.size = sizeof(__le64);
43186 pmd->info.value_type.inc = data_block_inc;
43187 pmd->info.value_type.dec = data_block_dec;
43188 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43189
43190 pmd->bl_info.tm = pmd->tm;
43191 pmd->bl_info.levels = 1;
43192 - pmd->bl_info.value_type.context = pmd->data_sm;
43193 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43194 pmd->bl_info.value_type.size = sizeof(__le64);
43195 pmd->bl_info.value_type.inc = data_block_inc;
43196 pmd->bl_info.value_type.dec = data_block_dec;
43197 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43198 index 0704c52..0a33d61 100644
43199 --- a/drivers/md/dm.c
43200 +++ b/drivers/md/dm.c
43201 @@ -185,9 +185,9 @@ struct mapped_device {
43202 /*
43203 * Event handling.
43204 */
43205 - atomic_t event_nr;
43206 + atomic_unchecked_t event_nr;
43207 wait_queue_head_t eventq;
43208 - atomic_t uevent_seq;
43209 + atomic_unchecked_t uevent_seq;
43210 struct list_head uevent_list;
43211 spinlock_t uevent_lock; /* Protect access to uevent_list */
43212
43213 @@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43214 spin_lock_init(&md->deferred_lock);
43215 atomic_set(&md->holders, 1);
43216 atomic_set(&md->open_count, 0);
43217 - atomic_set(&md->event_nr, 0);
43218 - atomic_set(&md->uevent_seq, 0);
43219 + atomic_set_unchecked(&md->event_nr, 0);
43220 + atomic_set_unchecked(&md->uevent_seq, 0);
43221 INIT_LIST_HEAD(&md->uevent_list);
43222 spin_lock_init(&md->uevent_lock);
43223
43224 @@ -2175,7 +2175,7 @@ static void event_callback(void *context)
43225
43226 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43227
43228 - atomic_inc(&md->event_nr);
43229 + atomic_inc_unchecked(&md->event_nr);
43230 wake_up(&md->eventq);
43231 }
43232
43233 @@ -2868,18 +2868,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43234
43235 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43236 {
43237 - return atomic_add_return(1, &md->uevent_seq);
43238 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43239 }
43240
43241 uint32_t dm_get_event_nr(struct mapped_device *md)
43242 {
43243 - return atomic_read(&md->event_nr);
43244 + return atomic_read_unchecked(&md->event_nr);
43245 }
43246
43247 int dm_wait_event(struct mapped_device *md, int event_nr)
43248 {
43249 return wait_event_interruptible(md->eventq,
43250 - (event_nr != atomic_read(&md->event_nr)));
43251 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43252 }
43253
43254 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43255 diff --git a/drivers/md/md.c b/drivers/md/md.c
43256 index 369d919..ba7049c 100644
43257 --- a/drivers/md/md.c
43258 +++ b/drivers/md/md.c
43259 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43260 * start build, activate spare
43261 */
43262 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43263 -static atomic_t md_event_count;
43264 +static atomic_unchecked_t md_event_count;
43265 void md_new_event(struct mddev *mddev)
43266 {
43267 - atomic_inc(&md_event_count);
43268 + atomic_inc_unchecked(&md_event_count);
43269 wake_up(&md_event_waiters);
43270 }
43271 EXPORT_SYMBOL_GPL(md_new_event);
43272 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43273 */
43274 static void md_new_event_inintr(struct mddev *mddev)
43275 {
43276 - atomic_inc(&md_event_count);
43277 + atomic_inc_unchecked(&md_event_count);
43278 wake_up(&md_event_waiters);
43279 }
43280
43281 @@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43282 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43283 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43284 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43285 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43286 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43287
43288 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43289 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43290 @@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43291 else
43292 sb->resync_offset = cpu_to_le64(0);
43293
43294 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43295 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43296
43297 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43298 sb->size = cpu_to_le64(mddev->dev_sectors);
43299 @@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43300 static ssize_t
43301 errors_show(struct md_rdev *rdev, char *page)
43302 {
43303 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43304 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43305 }
43306
43307 static ssize_t
43308 @@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43309 char *e;
43310 unsigned long n = simple_strtoul(buf, &e, 10);
43311 if (*buf && (*e == 0 || *e == '\n')) {
43312 - atomic_set(&rdev->corrected_errors, n);
43313 + atomic_set_unchecked(&rdev->corrected_errors, n);
43314 return len;
43315 }
43316 return -EINVAL;
43317 @@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43318 rdev->sb_loaded = 0;
43319 rdev->bb_page = NULL;
43320 atomic_set(&rdev->nr_pending, 0);
43321 - atomic_set(&rdev->read_errors, 0);
43322 - atomic_set(&rdev->corrected_errors, 0);
43323 + atomic_set_unchecked(&rdev->read_errors, 0);
43324 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43325
43326 INIT_LIST_HEAD(&rdev->same_set);
43327 init_waitqueue_head(&rdev->blocked_wait);
43328 @@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43329
43330 spin_unlock(&pers_lock);
43331 seq_printf(seq, "\n");
43332 - seq->poll_event = atomic_read(&md_event_count);
43333 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43334 return 0;
43335 }
43336 if (v == (void*)2) {
43337 @@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43338 return error;
43339
43340 seq = file->private_data;
43341 - seq->poll_event = atomic_read(&md_event_count);
43342 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43343 return error;
43344 }
43345
43346 @@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43347 /* always allow read */
43348 mask = POLLIN | POLLRDNORM;
43349
43350 - if (seq->poll_event != atomic_read(&md_event_count))
43351 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43352 mask |= POLLERR | POLLPRI;
43353 return mask;
43354 }
43355 @@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43356 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43357 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43358 (int)part_stat_read(&disk->part0, sectors[1]) -
43359 - atomic_read(&disk->sync_io);
43360 + atomic_read_unchecked(&disk->sync_io);
43361 /* sync IO will cause sync_io to increase before the disk_stats
43362 * as sync_io is counted when a request starts, and
43363 * disk_stats is counted when it completes.
43364 diff --git a/drivers/md/md.h b/drivers/md/md.h
43365 index 0095ec8..c89277a 100644
43366 --- a/drivers/md/md.h
43367 +++ b/drivers/md/md.h
43368 @@ -94,13 +94,13 @@ struct md_rdev {
43369 * only maintained for arrays that
43370 * support hot removal
43371 */
43372 - atomic_t read_errors; /* number of consecutive read errors that
43373 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
43374 * we have tried to ignore.
43375 */
43376 struct timespec last_read_error; /* monotonic time since our
43377 * last read error
43378 */
43379 - atomic_t corrected_errors; /* number of corrected read errors,
43380 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43381 * for reporting to userspace and storing
43382 * in superblock.
43383 */
43384 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43385
43386 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43387 {
43388 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43389 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43390 }
43391
43392 struct md_personality
43393 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43394 index 3e6d115..ffecdeb 100644
43395 --- a/drivers/md/persistent-data/dm-space-map.h
43396 +++ b/drivers/md/persistent-data/dm-space-map.h
43397 @@ -71,6 +71,7 @@ struct dm_space_map {
43398 dm_sm_threshold_fn fn,
43399 void *context);
43400 };
43401 +typedef struct dm_space_map __no_const dm_space_map_no_const;
43402
43403 /*----------------------------------------------------------------*/
43404
43405 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
43406 index a49cfcc..20b9a65 100644
43407 --- a/drivers/md/raid1.c
43408 +++ b/drivers/md/raid1.c
43409 @@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
43410 if (r1_sync_page_io(rdev, sect, s,
43411 bio->bi_io_vec[idx].bv_page,
43412 READ) != 0)
43413 - atomic_add(s, &rdev->corrected_errors);
43414 + atomic_add_unchecked(s, &rdev->corrected_errors);
43415 }
43416 sectors -= s;
43417 sect += s;
43418 @@ -2148,7 +2148,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
43419 test_bit(In_sync, &rdev->flags)) {
43420 if (r1_sync_page_io(rdev, sect, s,
43421 conf->tmppage, READ)) {
43422 - atomic_add(s, &rdev->corrected_errors);
43423 + atomic_add_unchecked(s, &rdev->corrected_errors);
43424 printk(KERN_INFO
43425 "md/raid1:%s: read error corrected "
43426 "(%d sectors at %llu on %s)\n",
43427 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
43428 index 06eeb99..770613e 100644
43429 --- a/drivers/md/raid10.c
43430 +++ b/drivers/md/raid10.c
43431 @@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
43432 /* The write handler will notice the lack of
43433 * R10BIO_Uptodate and record any errors etc
43434 */
43435 - atomic_add(r10_bio->sectors,
43436 + atomic_add_unchecked(r10_bio->sectors,
43437 &conf->mirrors[d].rdev->corrected_errors);
43438
43439 /* for reconstruct, we always reschedule after a read.
43440 @@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43441 {
43442 struct timespec cur_time_mon;
43443 unsigned long hours_since_last;
43444 - unsigned int read_errors = atomic_read(&rdev->read_errors);
43445 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
43446
43447 ktime_get_ts(&cur_time_mon);
43448
43449 @@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43450 * overflowing the shift of read_errors by hours_since_last.
43451 */
43452 if (hours_since_last >= 8 * sizeof(read_errors))
43453 - atomic_set(&rdev->read_errors, 0);
43454 + atomic_set_unchecked(&rdev->read_errors, 0);
43455 else
43456 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
43457 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
43458 }
43459
43460 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
43461 @@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43462 return;
43463
43464 check_decay_read_errors(mddev, rdev);
43465 - atomic_inc(&rdev->read_errors);
43466 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
43467 + atomic_inc_unchecked(&rdev->read_errors);
43468 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
43469 char b[BDEVNAME_SIZE];
43470 bdevname(rdev->bdev, b);
43471
43472 @@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43473 "md/raid10:%s: %s: Raid device exceeded "
43474 "read_error threshold [cur %d:max %d]\n",
43475 mdname(mddev), b,
43476 - atomic_read(&rdev->read_errors), max_read_errors);
43477 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
43478 printk(KERN_NOTICE
43479 "md/raid10:%s: %s: Failing raid device\n",
43480 mdname(mddev), b);
43481 @@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43482 sect +
43483 choose_data_offset(r10_bio, rdev)),
43484 bdevname(rdev->bdev, b));
43485 - atomic_add(s, &rdev->corrected_errors);
43486 + atomic_add_unchecked(s, &rdev->corrected_errors);
43487 }
43488
43489 rdev_dec_pending(rdev, mddev);
43490 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
43491 index 03f82ab..374bb38 100644
43492 --- a/drivers/md/raid5.c
43493 +++ b/drivers/md/raid5.c
43494 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
43495 mdname(conf->mddev), STRIPE_SECTORS,
43496 (unsigned long long)s,
43497 bdevname(rdev->bdev, b));
43498 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
43499 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
43500 clear_bit(R5_ReadError, &sh->dev[i].flags);
43501 clear_bit(R5_ReWrite, &sh->dev[i].flags);
43502 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
43503 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
43504
43505 - if (atomic_read(&rdev->read_errors))
43506 - atomic_set(&rdev->read_errors, 0);
43507 + if (atomic_read_unchecked(&rdev->read_errors))
43508 + atomic_set_unchecked(&rdev->read_errors, 0);
43509 } else {
43510 const char *bdn = bdevname(rdev->bdev, b);
43511 int retry = 0;
43512 int set_bad = 0;
43513
43514 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
43515 - atomic_inc(&rdev->read_errors);
43516 + atomic_inc_unchecked(&rdev->read_errors);
43517 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
43518 printk_ratelimited(
43519 KERN_WARNING
43520 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
43521 mdname(conf->mddev),
43522 (unsigned long long)s,
43523 bdn);
43524 - } else if (atomic_read(&rdev->read_errors)
43525 + } else if (atomic_read_unchecked(&rdev->read_errors)
43526 > conf->max_nr_stripes)
43527 printk(KERN_WARNING
43528 "md/raid:%s: Too many read errors, failing device %s.\n",
43529 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
43530 index 983db75..ef9248c 100644
43531 --- a/drivers/media/dvb-core/dvbdev.c
43532 +++ b/drivers/media/dvb-core/dvbdev.c
43533 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
43534 const struct dvb_device *template, void *priv, int type)
43535 {
43536 struct dvb_device *dvbdev;
43537 - struct file_operations *dvbdevfops;
43538 + file_operations_no_const *dvbdevfops;
43539 struct device *clsdev;
43540 int minor;
43541 int id;
43542 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
43543 index 9b6c3bb..baeb5c7 100644
43544 --- a/drivers/media/dvb-frontends/dib3000.h
43545 +++ b/drivers/media/dvb-frontends/dib3000.h
43546 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
43547 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
43548 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
43549 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
43550 -};
43551 +} __no_const;
43552
43553 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
43554 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
43555 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
43556 index ed8cb90..5ef7f79 100644
43557 --- a/drivers/media/pci/cx88/cx88-video.c
43558 +++ b/drivers/media/pci/cx88/cx88-video.c
43559 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
43560
43561 /* ------------------------------------------------------------------ */
43562
43563 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43564 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43565 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43566 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43567 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43568 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43569
43570 module_param_array(video_nr, int, NULL, 0444);
43571 module_param_array(vbi_nr, int, NULL, 0444);
43572 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
43573 index 802642d..5534900 100644
43574 --- a/drivers/media/pci/ivtv/ivtv-driver.c
43575 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
43576 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
43577 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
43578
43579 /* ivtv instance counter */
43580 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
43581 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
43582
43583 /* Parameter declarations */
43584 static int cardtype[IVTV_MAX_CARDS];
43585 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
43586 index dfd0a21..6bbb465 100644
43587 --- a/drivers/media/platform/omap/omap_vout.c
43588 +++ b/drivers/media/platform/omap/omap_vout.c
43589 @@ -63,7 +63,6 @@ enum omap_vout_channels {
43590 OMAP_VIDEO2,
43591 };
43592
43593 -static struct videobuf_queue_ops video_vbq_ops;
43594 /* Variables configurable through module params*/
43595 static u32 video1_numbuffers = 3;
43596 static u32 video2_numbuffers = 3;
43597 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
43598 {
43599 struct videobuf_queue *q;
43600 struct omap_vout_device *vout = NULL;
43601 + static struct videobuf_queue_ops video_vbq_ops = {
43602 + .buf_setup = omap_vout_buffer_setup,
43603 + .buf_prepare = omap_vout_buffer_prepare,
43604 + .buf_release = omap_vout_buffer_release,
43605 + .buf_queue = omap_vout_buffer_queue,
43606 + };
43607
43608 vout = video_drvdata(file);
43609 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
43610 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
43611 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
43612
43613 q = &vout->vbq;
43614 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
43615 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
43616 - video_vbq_ops.buf_release = omap_vout_buffer_release;
43617 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
43618 spin_lock_init(&vout->vbq_lock);
43619
43620 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
43621 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
43622 index fb2acc5..a2fcbdc4 100644
43623 --- a/drivers/media/platform/s5p-tv/mixer.h
43624 +++ b/drivers/media/platform/s5p-tv/mixer.h
43625 @@ -156,7 +156,7 @@ struct mxr_layer {
43626 /** layer index (unique identifier) */
43627 int idx;
43628 /** callbacks for layer methods */
43629 - struct mxr_layer_ops ops;
43630 + struct mxr_layer_ops *ops;
43631 /** format array */
43632 const struct mxr_format **fmt_array;
43633 /** size of format array */
43634 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43635 index 74344c7..a39e70e 100644
43636 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43637 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43638 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
43639 {
43640 struct mxr_layer *layer;
43641 int ret;
43642 - struct mxr_layer_ops ops = {
43643 + static struct mxr_layer_ops ops = {
43644 .release = mxr_graph_layer_release,
43645 .buffer_set = mxr_graph_buffer_set,
43646 .stream_set = mxr_graph_stream_set,
43647 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
43648 index b713403..53cb5ad 100644
43649 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
43650 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
43651 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
43652 layer->update_buf = next;
43653 }
43654
43655 - layer->ops.buffer_set(layer, layer->update_buf);
43656 + layer->ops->buffer_set(layer, layer->update_buf);
43657
43658 if (done && done != layer->shadow_buf)
43659 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
43660 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
43661 index 81b97db..b089ccd 100644
43662 --- a/drivers/media/platform/s5p-tv/mixer_video.c
43663 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
43664 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
43665 layer->geo.src.height = layer->geo.src.full_height;
43666
43667 mxr_geometry_dump(mdev, &layer->geo);
43668 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43669 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43670 mxr_geometry_dump(mdev, &layer->geo);
43671 }
43672
43673 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43674 layer->geo.dst.full_width = mbus_fmt.width;
43675 layer->geo.dst.full_height = mbus_fmt.height;
43676 layer->geo.dst.field = mbus_fmt.field;
43677 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43678 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43679
43680 mxr_geometry_dump(mdev, &layer->geo);
43681 }
43682 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43683 /* set source size to highest accepted value */
43684 geo->src.full_width = max(geo->dst.full_width, pix->width);
43685 geo->src.full_height = max(geo->dst.full_height, pix->height);
43686 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43687 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43688 mxr_geometry_dump(mdev, &layer->geo);
43689 /* set cropping to total visible screen */
43690 geo->src.width = pix->width;
43691 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43692 geo->src.x_offset = 0;
43693 geo->src.y_offset = 0;
43694 /* assure consistency of geometry */
43695 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43696 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43697 mxr_geometry_dump(mdev, &layer->geo);
43698 /* set full size to lowest possible value */
43699 geo->src.full_width = 0;
43700 geo->src.full_height = 0;
43701 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43702 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43703 mxr_geometry_dump(mdev, &layer->geo);
43704
43705 /* returning results */
43706 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43707 target->width = s->r.width;
43708 target->height = s->r.height;
43709
43710 - layer->ops.fix_geometry(layer, stage, s->flags);
43711 + layer->ops->fix_geometry(layer, stage, s->flags);
43712
43713 /* retrieve update selection rectangle */
43714 res.left = target->x_offset;
43715 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43716 mxr_output_get(mdev);
43717
43718 mxr_layer_update_output(layer);
43719 - layer->ops.format_set(layer);
43720 + layer->ops->format_set(layer);
43721 /* enabling layer in hardware */
43722 spin_lock_irqsave(&layer->enq_slock, flags);
43723 layer->state = MXR_LAYER_STREAMING;
43724 spin_unlock_irqrestore(&layer->enq_slock, flags);
43725
43726 - layer->ops.stream_set(layer, MXR_ENABLE);
43727 + layer->ops->stream_set(layer, MXR_ENABLE);
43728 mxr_streamer_get(mdev);
43729
43730 return 0;
43731 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43732 spin_unlock_irqrestore(&layer->enq_slock, flags);
43733
43734 /* disabling layer in hardware */
43735 - layer->ops.stream_set(layer, MXR_DISABLE);
43736 + layer->ops->stream_set(layer, MXR_DISABLE);
43737 /* remove one streamer */
43738 mxr_streamer_put(mdev);
43739 /* allow changes in output configuration */
43740 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43741
43742 void mxr_layer_release(struct mxr_layer *layer)
43743 {
43744 - if (layer->ops.release)
43745 - layer->ops.release(layer);
43746 + if (layer->ops->release)
43747 + layer->ops->release(layer);
43748 }
43749
43750 void mxr_base_layer_release(struct mxr_layer *layer)
43751 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43752
43753 layer->mdev = mdev;
43754 layer->idx = idx;
43755 - layer->ops = *ops;
43756 + layer->ops = ops;
43757
43758 spin_lock_init(&layer->enq_slock);
43759 INIT_LIST_HEAD(&layer->enq_list);
43760 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43761 index c9388c4..ce71ece 100644
43762 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43763 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43764 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43765 {
43766 struct mxr_layer *layer;
43767 int ret;
43768 - struct mxr_layer_ops ops = {
43769 + static struct mxr_layer_ops ops = {
43770 .release = mxr_vp_layer_release,
43771 .buffer_set = mxr_vp_buffer_set,
43772 .stream_set = mxr_vp_stream_set,
43773 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
43774 index 2d4e73b..8b4d5b6 100644
43775 --- a/drivers/media/platform/vivi.c
43776 +++ b/drivers/media/platform/vivi.c
43777 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
43778 MODULE_LICENSE("Dual BSD/GPL");
43779 MODULE_VERSION(VIVI_VERSION);
43780
43781 -static unsigned video_nr = -1;
43782 -module_param(video_nr, uint, 0644);
43783 +static int video_nr = -1;
43784 +module_param(video_nr, int, 0644);
43785 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
43786
43787 static unsigned n_devs = 1;
43788 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43789 index 545c04c..a14bded 100644
43790 --- a/drivers/media/radio/radio-cadet.c
43791 +++ b/drivers/media/radio/radio-cadet.c
43792 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43793 unsigned char readbuf[RDS_BUFFER];
43794 int i = 0;
43795
43796 + if (count > RDS_BUFFER)
43797 + return -EFAULT;
43798 mutex_lock(&dev->lock);
43799 if (dev->rdsstat == 0)
43800 cadet_start_rds(dev);
43801 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43802 while (i < count && dev->rdsin != dev->rdsout)
43803 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43804
43805 - if (i && copy_to_user(data, readbuf, i))
43806 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43807 i = -EFAULT;
43808 unlock:
43809 mutex_unlock(&dev->lock);
43810 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43811 index 5236035..c622c74 100644
43812 --- a/drivers/media/radio/radio-maxiradio.c
43813 +++ b/drivers/media/radio/radio-maxiradio.c
43814 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43815 /* TEA5757 pin mappings */
43816 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43817
43818 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43819 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43820
43821 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43822 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43823 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43824 index 050b3bb..79f62b9 100644
43825 --- a/drivers/media/radio/radio-shark.c
43826 +++ b/drivers/media/radio/radio-shark.c
43827 @@ -79,7 +79,7 @@ struct shark_device {
43828 u32 last_val;
43829 };
43830
43831 -static atomic_t shark_instance = ATOMIC_INIT(0);
43832 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43833
43834 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43835 {
43836 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43837 index 8654e0d..0608a64 100644
43838 --- a/drivers/media/radio/radio-shark2.c
43839 +++ b/drivers/media/radio/radio-shark2.c
43840 @@ -74,7 +74,7 @@ struct shark_device {
43841 u8 *transfer_buffer;
43842 };
43843
43844 -static atomic_t shark_instance = ATOMIC_INIT(0);
43845 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43846
43847 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43848 {
43849 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43850 index 2fd9009..278cc1e 100644
43851 --- a/drivers/media/radio/radio-si476x.c
43852 +++ b/drivers/media/radio/radio-si476x.c
43853 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43854 struct si476x_radio *radio;
43855 struct v4l2_ctrl *ctrl;
43856
43857 - static atomic_t instance = ATOMIC_INIT(0);
43858 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
43859
43860 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43861 if (!radio)
43862 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43863 index 46da365..3ba4206 100644
43864 --- a/drivers/media/rc/rc-main.c
43865 +++ b/drivers/media/rc/rc-main.c
43866 @@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43867 int rc_register_device(struct rc_dev *dev)
43868 {
43869 static bool raw_init = false; /* raw decoders loaded? */
43870 - static atomic_t devno = ATOMIC_INIT(0);
43871 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
43872 struct rc_map *rc_map;
43873 const char *path;
43874 int rc;
43875 @@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
43876 */
43877 mutex_lock(&dev->lock);
43878
43879 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43880 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43881 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43882 dev_set_drvdata(&dev->dev, dev);
43883 rc = device_add(&dev->dev);
43884 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43885 index 20e345d..da56fe4 100644
43886 --- a/drivers/media/usb/dvb-usb/cxusb.c
43887 +++ b/drivers/media/usb/dvb-usb/cxusb.c
43888 @@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43889
43890 struct dib0700_adapter_state {
43891 int (*set_param_save) (struct dvb_frontend *);
43892 -};
43893 +} __no_const;
43894
43895 static int dib7070_set_param_override(struct dvb_frontend *fe)
43896 {
43897 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43898 index c1a63b2..dbcbfb6 100644
43899 --- a/drivers/media/usb/dvb-usb/dw2102.c
43900 +++ b/drivers/media/usb/dvb-usb/dw2102.c
43901 @@ -121,7 +121,7 @@ struct su3000_state {
43902
43903 struct s6x0_state {
43904 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43905 -};
43906 +} __no_const;
43907
43908 /* debug */
43909 static int dvb_usb_dw2102_debug;
43910 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43911 index 8f7a6a4..eb0e1d4 100644
43912 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43913 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43914 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43915 __u32 reserved;
43916 };
43917
43918 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43919 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43920 enum v4l2_memory memory)
43921 {
43922 void __user *up_pln;
43923 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43924 return 0;
43925 }
43926
43927 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43928 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43929 enum v4l2_memory memory)
43930 {
43931 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43932 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43933 * by passing a very big num_planes value */
43934 uplane = compat_alloc_user_space(num_planes *
43935 sizeof(struct v4l2_plane));
43936 - kp->m.planes = uplane;
43937 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
43938
43939 while (--num_planes >= 0) {
43940 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
43941 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43942 if (num_planes == 0)
43943 return 0;
43944
43945 - uplane = kp->m.planes;
43946 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
43947 if (get_user(p, &up->m.planes))
43948 return -EFAULT;
43949 uplane32 = compat_ptr(p);
43950 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
43951 get_user(kp->capability, &up->capability) ||
43952 get_user(kp->flags, &up->flags))
43953 return -EFAULT;
43954 - kp->base = compat_ptr(tmp);
43955 + kp->base = (void __force_kernel *)compat_ptr(tmp);
43956 get_v4l2_pix_format(&kp->fmt, &up->fmt);
43957 return 0;
43958 }
43959 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
43960 n * sizeof(struct v4l2_ext_control32)))
43961 return -EFAULT;
43962 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
43963 - kp->controls = kcontrols;
43964 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
43965 while (--n >= 0) {
43966 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
43967 return -EFAULT;
43968 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
43969 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
43970 {
43971 struct v4l2_ext_control32 __user *ucontrols;
43972 - struct v4l2_ext_control __user *kcontrols = kp->controls;
43973 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
43974 int n = kp->count;
43975 compat_caddr_t p;
43976
43977 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43978 put_user(kp->start_block, &up->start_block) ||
43979 put_user(kp->blocks, &up->blocks) ||
43980 put_user(tmp, &up->edid) ||
43981 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43982 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43983 return -EFAULT;
43984 return 0;
43985 }
43986 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
43987 index fb46790..ae1f8fa 100644
43988 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
43989 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
43990 @@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
43991 return 0;
43992
43993 case V4L2_CTRL_TYPE_STRING:
43994 - len = strlen(c->string);
43995 - if (len < ctrl->minimum)
43996 + len = strlen_user(c->string);
43997 + if (!len || len < ctrl->minimum)
43998 return -ERANGE;
43999 if ((len - ctrl->minimum) % ctrl->step)
44000 return -ERANGE;
44001 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44002 index 02d1b63..5fd6b16 100644
44003 --- a/drivers/media/v4l2-core/v4l2-device.c
44004 +++ b/drivers/media/v4l2-core/v4l2-device.c
44005 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44006 EXPORT_SYMBOL_GPL(v4l2_device_put);
44007
44008 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44009 - atomic_t *instance)
44010 + atomic_unchecked_t *instance)
44011 {
44012 - int num = atomic_inc_return(instance) - 1;
44013 + int num = atomic_inc_return_unchecked(instance) - 1;
44014 int len = strlen(basename);
44015
44016 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44017 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44018 index 68e6b5e..8eb2aec 100644
44019 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44020 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44021 @@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44022 struct file *file, void *fh, void *p);
44023 } u;
44024 void (*debug)(const void *arg, bool write_only);
44025 -};
44026 +} __do_const;
44027 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44028
44029 /* This control needs a priority check */
44030 #define INFO_FL_PRIO (1 << 0)
44031 @@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44032 struct video_device *vfd = video_devdata(file);
44033 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44034 bool write_only = false;
44035 - struct v4l2_ioctl_info default_info;
44036 + v4l2_ioctl_info_no_const default_info;
44037 const struct v4l2_ioctl_info *info;
44038 void *fh = file->private_data;
44039 struct v4l2_fh *vfh = NULL;
44040 @@ -2194,7 +2195,7 @@ done:
44041 }
44042
44043 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44044 - void * __user *user_ptr, void ***kernel_ptr)
44045 + void __user **user_ptr, void ***kernel_ptr)
44046 {
44047 int ret = 0;
44048
44049 @@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44050 ret = -EINVAL;
44051 break;
44052 }
44053 - *user_ptr = (void __user *)buf->m.planes;
44054 + *user_ptr = (void __force_user *)buf->m.planes;
44055 *kernel_ptr = (void *)&buf->m.planes;
44056 *array_size = sizeof(struct v4l2_plane) * buf->length;
44057 ret = 1;
44058 @@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44059 ret = -EINVAL;
44060 break;
44061 }
44062 - *user_ptr = (void __user *)ctrls->controls;
44063 + *user_ptr = (void __force_user *)ctrls->controls;
44064 *kernel_ptr = (void *)&ctrls->controls;
44065 *array_size = sizeof(struct v4l2_ext_control)
44066 * ctrls->count;
44067 @@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44068 err = -ENOTTY;
44069
44070 if (has_array_args) {
44071 - *kernel_ptr = user_ptr;
44072 + *kernel_ptr = (void __force_kernel *)user_ptr;
44073 if (copy_to_user(user_ptr, mbuf, array_size))
44074 err = -EFAULT;
44075 goto out_array_args;
44076 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44077 index 767ff4d..c69d259 100644
44078 --- a/drivers/message/fusion/mptbase.c
44079 +++ b/drivers/message/fusion/mptbase.c
44080 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44081 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44082 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44083
44084 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44085 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44086 +#else
44087 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44088 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44089 +#endif
44090 +
44091 /*
44092 * Rounding UP to nearest 4-kB boundary here...
44093 */
44094 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44095 ioc->facts.GlobalCredits);
44096
44097 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44098 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44099 + NULL, NULL);
44100 +#else
44101 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44102 +#endif
44103 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44104 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44105 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44106 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44107 index dd239bd..689c4f7 100644
44108 --- a/drivers/message/fusion/mptsas.c
44109 +++ b/drivers/message/fusion/mptsas.c
44110 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44111 return 0;
44112 }
44113
44114 +static inline void
44115 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44116 +{
44117 + if (phy_info->port_details) {
44118 + phy_info->port_details->rphy = rphy;
44119 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44120 + ioc->name, rphy));
44121 + }
44122 +
44123 + if (rphy) {
44124 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44125 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44126 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44127 + ioc->name, rphy, rphy->dev.release));
44128 + }
44129 +}
44130 +
44131 /* no mutex */
44132 static void
44133 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44134 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44135 return NULL;
44136 }
44137
44138 -static inline void
44139 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44140 -{
44141 - if (phy_info->port_details) {
44142 - phy_info->port_details->rphy = rphy;
44143 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44144 - ioc->name, rphy));
44145 - }
44146 -
44147 - if (rphy) {
44148 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44149 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44150 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44151 - ioc->name, rphy, rphy->dev.release));
44152 - }
44153 -}
44154 -
44155 static inline struct sas_port *
44156 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44157 {
44158 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44159 index 727819c..ad74694 100644
44160 --- a/drivers/message/fusion/mptscsih.c
44161 +++ b/drivers/message/fusion/mptscsih.c
44162 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44163
44164 h = shost_priv(SChost);
44165
44166 - if (h) {
44167 - if (h->info_kbuf == NULL)
44168 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44169 - return h->info_kbuf;
44170 - h->info_kbuf[0] = '\0';
44171 + if (!h)
44172 + return NULL;
44173
44174 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44175 - h->info_kbuf[size-1] = '\0';
44176 - }
44177 + if (h->info_kbuf == NULL)
44178 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44179 + return h->info_kbuf;
44180 + h->info_kbuf[0] = '\0';
44181 +
44182 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44183 + h->info_kbuf[size-1] = '\0';
44184
44185 return h->info_kbuf;
44186 }
44187 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44188 index b7d87cd..3fb36da 100644
44189 --- a/drivers/message/i2o/i2o_proc.c
44190 +++ b/drivers/message/i2o/i2o_proc.c
44191 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44192 "Array Controller Device"
44193 };
44194
44195 -static char *chtostr(char *tmp, u8 *chars, int n)
44196 -{
44197 - tmp[0] = 0;
44198 - return strncat(tmp, (char *)chars, n);
44199 -}
44200 -
44201 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44202 char *group)
44203 {
44204 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44205 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44206 {
44207 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44208 - static u32 work32[5];
44209 - static u8 *work8 = (u8 *) work32;
44210 - static u16 *work16 = (u16 *) work32;
44211 + u32 work32[5];
44212 + u8 *work8 = (u8 *) work32;
44213 + u16 *work16 = (u16 *) work32;
44214 int token;
44215 u32 hwcap;
44216
44217 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44218 } *result;
44219
44220 i2o_exec_execute_ddm_table ddm_table;
44221 - char tmp[28 + 1];
44222
44223 result = kmalloc(sizeof(*result), GFP_KERNEL);
44224 if (!result)
44225 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44226
44227 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44228 seq_printf(seq, "%-#8x", ddm_table.module_id);
44229 - seq_printf(seq, "%-29s",
44230 - chtostr(tmp, ddm_table.module_name_version, 28));
44231 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44232 seq_printf(seq, "%9d ", ddm_table.data_size);
44233 seq_printf(seq, "%8d", ddm_table.code_size);
44234
44235 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44236
44237 i2o_driver_result_table *result;
44238 i2o_driver_store_table *dst;
44239 - char tmp[28 + 1];
44240
44241 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44242 if (result == NULL)
44243 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44244
44245 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44246 seq_printf(seq, "%-#8x", dst->module_id);
44247 - seq_printf(seq, "%-29s",
44248 - chtostr(tmp, dst->module_name_version, 28));
44249 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44250 + seq_printf(seq, "%-.28s", dst->module_name_version);
44251 + seq_printf(seq, "%-.8s", dst->date);
44252 seq_printf(seq, "%8d ", dst->module_size);
44253 seq_printf(seq, "%8d ", dst->mpb_size);
44254 seq_printf(seq, "0x%04x", dst->module_flags);
44255 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44256 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44257 {
44258 struct i2o_device *d = (struct i2o_device *)seq->private;
44259 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44260 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44261 // == (allow) 512d bytes (max)
44262 - static u16 *work16 = (u16 *) work32;
44263 + u16 *work16 = (u16 *) work32;
44264 int token;
44265 - char tmp[16 + 1];
44266
44267 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44268
44269 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44270 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44271 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44272 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44273 - seq_printf(seq, "Vendor info : %s\n",
44274 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44275 - seq_printf(seq, "Product info : %s\n",
44276 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44277 - seq_printf(seq, "Description : %s\n",
44278 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44279 - seq_printf(seq, "Product rev. : %s\n",
44280 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44281 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44282 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44283 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44284 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44285
44286 seq_printf(seq, "Serial number : ");
44287 print_serial_number(seq, (u8 *) (work32 + 16),
44288 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44289 u8 pad[256]; // allow up to 256 byte (max) serial number
44290 } result;
44291
44292 - char tmp[24 + 1];
44293 -
44294 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44295
44296 if (token < 0) {
44297 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44298 }
44299
44300 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44301 - seq_printf(seq, "Module name : %s\n",
44302 - chtostr(tmp, result.module_name, 24));
44303 - seq_printf(seq, "Module revision : %s\n",
44304 - chtostr(tmp, result.module_rev, 8));
44305 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44306 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44307
44308 seq_printf(seq, "Serial number : ");
44309 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44310 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44311 u8 instance_number[4];
44312 } result;
44313
44314 - char tmp[64 + 1];
44315 -
44316 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44317
44318 if (token < 0) {
44319 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44320 return 0;
44321 }
44322
44323 - seq_printf(seq, "Device name : %s\n",
44324 - chtostr(tmp, result.device_name, 64));
44325 - seq_printf(seq, "Service name : %s\n",
44326 - chtostr(tmp, result.service_name, 64));
44327 - seq_printf(seq, "Physical name : %s\n",
44328 - chtostr(tmp, result.physical_location, 64));
44329 - seq_printf(seq, "Instance number : %s\n",
44330 - chtostr(tmp, result.instance_number, 4));
44331 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
44332 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
44333 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44334 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44335
44336 return 0;
44337 }
44338 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44339 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44340 {
44341 struct i2o_device *d = (struct i2o_device *)seq->private;
44342 - static u32 work32[12];
44343 - static u16 *work16 = (u16 *) work32;
44344 - static u8 *work8 = (u8 *) work32;
44345 + u32 work32[12];
44346 + u16 *work16 = (u16 *) work32;
44347 + u8 *work8 = (u8 *) work32;
44348 int token;
44349
44350 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44351 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44352 index a8c08f3..155fe3d 100644
44353 --- a/drivers/message/i2o/iop.c
44354 +++ b/drivers/message/i2o/iop.c
44355 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44356
44357 spin_lock_irqsave(&c->context_list_lock, flags);
44358
44359 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44360 - atomic_inc(&c->context_list_counter);
44361 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44362 + atomic_inc_unchecked(&c->context_list_counter);
44363
44364 - entry->context = atomic_read(&c->context_list_counter);
44365 + entry->context = atomic_read_unchecked(&c->context_list_counter);
44366
44367 list_add(&entry->list, &c->context_list);
44368
44369 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44370
44371 #if BITS_PER_LONG == 64
44372 spin_lock_init(&c->context_list_lock);
44373 - atomic_set(&c->context_list_counter, 0);
44374 + atomic_set_unchecked(&c->context_list_counter, 0);
44375 INIT_LIST_HEAD(&c->context_list);
44376 #endif
44377
44378 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44379 index fcbb2e9..2635e11 100644
44380 --- a/drivers/mfd/janz-cmodio.c
44381 +++ b/drivers/mfd/janz-cmodio.c
44382 @@ -13,6 +13,7 @@
44383
44384 #include <linux/kernel.h>
44385 #include <linux/module.h>
44386 +#include <linux/slab.h>
44387 #include <linux/init.h>
44388 #include <linux/pci.h>
44389 #include <linux/interrupt.h>
44390 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
44391 index 176aa26..27811b2 100644
44392 --- a/drivers/mfd/max8925-i2c.c
44393 +++ b/drivers/mfd/max8925-i2c.c
44394 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
44395 const struct i2c_device_id *id)
44396 {
44397 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
44398 - static struct max8925_chip *chip;
44399 + struct max8925_chip *chip;
44400 struct device_node *node = client->dev.of_node;
44401
44402 if (node && !pdata) {
44403 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
44404 index c0f608e..286f8ec 100644
44405 --- a/drivers/mfd/tps65910.c
44406 +++ b/drivers/mfd/tps65910.c
44407 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
44408 struct tps65910_platform_data *pdata)
44409 {
44410 int ret = 0;
44411 - static struct regmap_irq_chip *tps6591x_irqs_chip;
44412 + struct regmap_irq_chip *tps6591x_irqs_chip;
44413
44414 if (!irq) {
44415 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
44416 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
44417 index 9aa6d1e..1631bfc 100644
44418 --- a/drivers/mfd/twl4030-irq.c
44419 +++ b/drivers/mfd/twl4030-irq.c
44420 @@ -35,6 +35,7 @@
44421 #include <linux/of.h>
44422 #include <linux/irqdomain.h>
44423 #include <linux/i2c/twl.h>
44424 +#include <asm/pgtable.h>
44425
44426 #include "twl-core.h"
44427
44428 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
44429 * Install an irq handler for each of the SIH modules;
44430 * clone dummy irq_chip since PIH can't *do* anything
44431 */
44432 - twl4030_irq_chip = dummy_irq_chip;
44433 - twl4030_irq_chip.name = "twl4030";
44434 + pax_open_kernel();
44435 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
44436 + *(const char **)&twl4030_irq_chip.name = "twl4030";
44437
44438 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44439 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44440 + pax_close_kernel();
44441
44442 for (i = irq_base; i < irq_end; i++) {
44443 irq_set_chip_and_handler(i, &twl4030_irq_chip,
44444 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
44445 index 464419b..64bae8d 100644
44446 --- a/drivers/misc/c2port/core.c
44447 +++ b/drivers/misc/c2port/core.c
44448 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
44449 goto error_idr_alloc;
44450 c2dev->id = ret;
44451
44452 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44453 + pax_open_kernel();
44454 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44455 + pax_close_kernel();
44456
44457 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
44458 "c2port%d", c2dev->id);
44459 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
44460 index 9c34e57..b981cda 100644
44461 --- a/drivers/misc/eeprom/sunxi_sid.c
44462 +++ b/drivers/misc/eeprom/sunxi_sid.c
44463 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
44464
44465 platform_set_drvdata(pdev, sid_data);
44466
44467 - sid_bin_attr.size = sid_data->keysize;
44468 + pax_open_kernel();
44469 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
44470 + pax_close_kernel();
44471 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
44472 return -ENODEV;
44473
44474 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
44475 index 36f5d52..32311c3 100644
44476 --- a/drivers/misc/kgdbts.c
44477 +++ b/drivers/misc/kgdbts.c
44478 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
44479 char before[BREAK_INSTR_SIZE];
44480 char after[BREAK_INSTR_SIZE];
44481
44482 - probe_kernel_read(before, (char *)kgdbts_break_test,
44483 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
44484 BREAK_INSTR_SIZE);
44485 init_simple_test();
44486 ts.tst = plant_and_detach_test;
44487 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
44488 /* Activate test with initial breakpoint */
44489 if (!is_early)
44490 kgdb_breakpoint();
44491 - probe_kernel_read(after, (char *)kgdbts_break_test,
44492 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
44493 BREAK_INSTR_SIZE);
44494 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
44495 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
44496 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
44497 index 036effe..b3a6336 100644
44498 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
44499 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
44500 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
44501 * the lid is closed. This leads to interrupts as soon as a little move
44502 * is done.
44503 */
44504 - atomic_inc(&lis3->count);
44505 + atomic_inc_unchecked(&lis3->count);
44506
44507 wake_up_interruptible(&lis3->misc_wait);
44508 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
44509 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
44510 if (lis3->pm_dev)
44511 pm_runtime_get_sync(lis3->pm_dev);
44512
44513 - atomic_set(&lis3->count, 0);
44514 + atomic_set_unchecked(&lis3->count, 0);
44515 return 0;
44516 }
44517
44518 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
44519 add_wait_queue(&lis3->misc_wait, &wait);
44520 while (true) {
44521 set_current_state(TASK_INTERRUPTIBLE);
44522 - data = atomic_xchg(&lis3->count, 0);
44523 + data = atomic_xchg_unchecked(&lis3->count, 0);
44524 if (data)
44525 break;
44526
44527 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
44528 struct lis3lv02d, miscdev);
44529
44530 poll_wait(file, &lis3->misc_wait, wait);
44531 - if (atomic_read(&lis3->count))
44532 + if (atomic_read_unchecked(&lis3->count))
44533 return POLLIN | POLLRDNORM;
44534 return 0;
44535 }
44536 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
44537 index c439c82..1f20f57 100644
44538 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
44539 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
44540 @@ -297,7 +297,7 @@ struct lis3lv02d {
44541 struct input_polled_dev *idev; /* input device */
44542 struct platform_device *pdev; /* platform device */
44543 struct regulator_bulk_data regulators[2];
44544 - atomic_t count; /* interrupt count after last read */
44545 + atomic_unchecked_t count; /* interrupt count after last read */
44546 union axis_conversion ac; /* hw -> logical axis */
44547 int mapped_btns[3];
44548
44549 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
44550 index 2f30bad..c4c13d0 100644
44551 --- a/drivers/misc/sgi-gru/gruhandles.c
44552 +++ b/drivers/misc/sgi-gru/gruhandles.c
44553 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
44554 unsigned long nsec;
44555
44556 nsec = CLKS2NSEC(clks);
44557 - atomic_long_inc(&mcs_op_statistics[op].count);
44558 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
44559 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
44560 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
44561 if (mcs_op_statistics[op].max < nsec)
44562 mcs_op_statistics[op].max = nsec;
44563 }
44564 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
44565 index 4f76359..cdfcb2e 100644
44566 --- a/drivers/misc/sgi-gru/gruprocfs.c
44567 +++ b/drivers/misc/sgi-gru/gruprocfs.c
44568 @@ -32,9 +32,9 @@
44569
44570 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
44571
44572 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
44573 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
44574 {
44575 - unsigned long val = atomic_long_read(v);
44576 + unsigned long val = atomic_long_read_unchecked(v);
44577
44578 seq_printf(s, "%16lu %s\n", val, id);
44579 }
44580 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
44581
44582 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
44583 for (op = 0; op < mcsop_last; op++) {
44584 - count = atomic_long_read(&mcs_op_statistics[op].count);
44585 - total = atomic_long_read(&mcs_op_statistics[op].total);
44586 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
44587 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
44588 max = mcs_op_statistics[op].max;
44589 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
44590 count ? total / count : 0, max);
44591 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
44592 index 5c3ce24..4915ccb 100644
44593 --- a/drivers/misc/sgi-gru/grutables.h
44594 +++ b/drivers/misc/sgi-gru/grutables.h
44595 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
44596 * GRU statistics.
44597 */
44598 struct gru_stats_s {
44599 - atomic_long_t vdata_alloc;
44600 - atomic_long_t vdata_free;
44601 - atomic_long_t gts_alloc;
44602 - atomic_long_t gts_free;
44603 - atomic_long_t gms_alloc;
44604 - atomic_long_t gms_free;
44605 - atomic_long_t gts_double_allocate;
44606 - atomic_long_t assign_context;
44607 - atomic_long_t assign_context_failed;
44608 - atomic_long_t free_context;
44609 - atomic_long_t load_user_context;
44610 - atomic_long_t load_kernel_context;
44611 - atomic_long_t lock_kernel_context;
44612 - atomic_long_t unlock_kernel_context;
44613 - atomic_long_t steal_user_context;
44614 - atomic_long_t steal_kernel_context;
44615 - atomic_long_t steal_context_failed;
44616 - atomic_long_t nopfn;
44617 - atomic_long_t asid_new;
44618 - atomic_long_t asid_next;
44619 - atomic_long_t asid_wrap;
44620 - atomic_long_t asid_reuse;
44621 - atomic_long_t intr;
44622 - atomic_long_t intr_cbr;
44623 - atomic_long_t intr_tfh;
44624 - atomic_long_t intr_spurious;
44625 - atomic_long_t intr_mm_lock_failed;
44626 - atomic_long_t call_os;
44627 - atomic_long_t call_os_wait_queue;
44628 - atomic_long_t user_flush_tlb;
44629 - atomic_long_t user_unload_context;
44630 - atomic_long_t user_exception;
44631 - atomic_long_t set_context_option;
44632 - atomic_long_t check_context_retarget_intr;
44633 - atomic_long_t check_context_unload;
44634 - atomic_long_t tlb_dropin;
44635 - atomic_long_t tlb_preload_page;
44636 - atomic_long_t tlb_dropin_fail_no_asid;
44637 - atomic_long_t tlb_dropin_fail_upm;
44638 - atomic_long_t tlb_dropin_fail_invalid;
44639 - atomic_long_t tlb_dropin_fail_range_active;
44640 - atomic_long_t tlb_dropin_fail_idle;
44641 - atomic_long_t tlb_dropin_fail_fmm;
44642 - atomic_long_t tlb_dropin_fail_no_exception;
44643 - atomic_long_t tfh_stale_on_fault;
44644 - atomic_long_t mmu_invalidate_range;
44645 - atomic_long_t mmu_invalidate_page;
44646 - atomic_long_t flush_tlb;
44647 - atomic_long_t flush_tlb_gru;
44648 - atomic_long_t flush_tlb_gru_tgh;
44649 - atomic_long_t flush_tlb_gru_zero_asid;
44650 + atomic_long_unchecked_t vdata_alloc;
44651 + atomic_long_unchecked_t vdata_free;
44652 + atomic_long_unchecked_t gts_alloc;
44653 + atomic_long_unchecked_t gts_free;
44654 + atomic_long_unchecked_t gms_alloc;
44655 + atomic_long_unchecked_t gms_free;
44656 + atomic_long_unchecked_t gts_double_allocate;
44657 + atomic_long_unchecked_t assign_context;
44658 + atomic_long_unchecked_t assign_context_failed;
44659 + atomic_long_unchecked_t free_context;
44660 + atomic_long_unchecked_t load_user_context;
44661 + atomic_long_unchecked_t load_kernel_context;
44662 + atomic_long_unchecked_t lock_kernel_context;
44663 + atomic_long_unchecked_t unlock_kernel_context;
44664 + atomic_long_unchecked_t steal_user_context;
44665 + atomic_long_unchecked_t steal_kernel_context;
44666 + atomic_long_unchecked_t steal_context_failed;
44667 + atomic_long_unchecked_t nopfn;
44668 + atomic_long_unchecked_t asid_new;
44669 + atomic_long_unchecked_t asid_next;
44670 + atomic_long_unchecked_t asid_wrap;
44671 + atomic_long_unchecked_t asid_reuse;
44672 + atomic_long_unchecked_t intr;
44673 + atomic_long_unchecked_t intr_cbr;
44674 + atomic_long_unchecked_t intr_tfh;
44675 + atomic_long_unchecked_t intr_spurious;
44676 + atomic_long_unchecked_t intr_mm_lock_failed;
44677 + atomic_long_unchecked_t call_os;
44678 + atomic_long_unchecked_t call_os_wait_queue;
44679 + atomic_long_unchecked_t user_flush_tlb;
44680 + atomic_long_unchecked_t user_unload_context;
44681 + atomic_long_unchecked_t user_exception;
44682 + atomic_long_unchecked_t set_context_option;
44683 + atomic_long_unchecked_t check_context_retarget_intr;
44684 + atomic_long_unchecked_t check_context_unload;
44685 + atomic_long_unchecked_t tlb_dropin;
44686 + atomic_long_unchecked_t tlb_preload_page;
44687 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
44688 + atomic_long_unchecked_t tlb_dropin_fail_upm;
44689 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
44690 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
44691 + atomic_long_unchecked_t tlb_dropin_fail_idle;
44692 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
44693 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
44694 + atomic_long_unchecked_t tfh_stale_on_fault;
44695 + atomic_long_unchecked_t mmu_invalidate_range;
44696 + atomic_long_unchecked_t mmu_invalidate_page;
44697 + atomic_long_unchecked_t flush_tlb;
44698 + atomic_long_unchecked_t flush_tlb_gru;
44699 + atomic_long_unchecked_t flush_tlb_gru_tgh;
44700 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
44701
44702 - atomic_long_t copy_gpa;
44703 - atomic_long_t read_gpa;
44704 + atomic_long_unchecked_t copy_gpa;
44705 + atomic_long_unchecked_t read_gpa;
44706
44707 - atomic_long_t mesq_receive;
44708 - atomic_long_t mesq_receive_none;
44709 - atomic_long_t mesq_send;
44710 - atomic_long_t mesq_send_failed;
44711 - atomic_long_t mesq_noop;
44712 - atomic_long_t mesq_send_unexpected_error;
44713 - atomic_long_t mesq_send_lb_overflow;
44714 - atomic_long_t mesq_send_qlimit_reached;
44715 - atomic_long_t mesq_send_amo_nacked;
44716 - atomic_long_t mesq_send_put_nacked;
44717 - atomic_long_t mesq_page_overflow;
44718 - atomic_long_t mesq_qf_locked;
44719 - atomic_long_t mesq_qf_noop_not_full;
44720 - atomic_long_t mesq_qf_switch_head_failed;
44721 - atomic_long_t mesq_qf_unexpected_error;
44722 - atomic_long_t mesq_noop_unexpected_error;
44723 - atomic_long_t mesq_noop_lb_overflow;
44724 - atomic_long_t mesq_noop_qlimit_reached;
44725 - atomic_long_t mesq_noop_amo_nacked;
44726 - atomic_long_t mesq_noop_put_nacked;
44727 - atomic_long_t mesq_noop_page_overflow;
44728 + atomic_long_unchecked_t mesq_receive;
44729 + atomic_long_unchecked_t mesq_receive_none;
44730 + atomic_long_unchecked_t mesq_send;
44731 + atomic_long_unchecked_t mesq_send_failed;
44732 + atomic_long_unchecked_t mesq_noop;
44733 + atomic_long_unchecked_t mesq_send_unexpected_error;
44734 + atomic_long_unchecked_t mesq_send_lb_overflow;
44735 + atomic_long_unchecked_t mesq_send_qlimit_reached;
44736 + atomic_long_unchecked_t mesq_send_amo_nacked;
44737 + atomic_long_unchecked_t mesq_send_put_nacked;
44738 + atomic_long_unchecked_t mesq_page_overflow;
44739 + atomic_long_unchecked_t mesq_qf_locked;
44740 + atomic_long_unchecked_t mesq_qf_noop_not_full;
44741 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
44742 + atomic_long_unchecked_t mesq_qf_unexpected_error;
44743 + atomic_long_unchecked_t mesq_noop_unexpected_error;
44744 + atomic_long_unchecked_t mesq_noop_lb_overflow;
44745 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
44746 + atomic_long_unchecked_t mesq_noop_amo_nacked;
44747 + atomic_long_unchecked_t mesq_noop_put_nacked;
44748 + atomic_long_unchecked_t mesq_noop_page_overflow;
44749
44750 };
44751
44752 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
44753 tghop_invalidate, mcsop_last};
44754
44755 struct mcs_op_statistic {
44756 - atomic_long_t count;
44757 - atomic_long_t total;
44758 + atomic_long_unchecked_t count;
44759 + atomic_long_unchecked_t total;
44760 unsigned long max;
44761 };
44762
44763 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
44764
44765 #define STAT(id) do { \
44766 if (gru_options & OPT_STATS) \
44767 - atomic_long_inc(&gru_stats.id); \
44768 + atomic_long_inc_unchecked(&gru_stats.id); \
44769 } while (0)
44770
44771 #ifdef CONFIG_SGI_GRU_DEBUG
44772 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
44773 index c862cd4..0d176fe 100644
44774 --- a/drivers/misc/sgi-xp/xp.h
44775 +++ b/drivers/misc/sgi-xp/xp.h
44776 @@ -288,7 +288,7 @@ struct xpc_interface {
44777 xpc_notify_func, void *);
44778 void (*received) (short, int, void *);
44779 enum xp_retval (*partid_to_nasids) (short, void *);
44780 -};
44781 +} __no_const;
44782
44783 extern struct xpc_interface xpc_interface;
44784
44785 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
44786 index 01be66d..e3a0c7e 100644
44787 --- a/drivers/misc/sgi-xp/xp_main.c
44788 +++ b/drivers/misc/sgi-xp/xp_main.c
44789 @@ -78,13 +78,13 @@ xpc_notloaded(void)
44790 }
44791
44792 struct xpc_interface xpc_interface = {
44793 - (void (*)(int))xpc_notloaded,
44794 - (void (*)(int))xpc_notloaded,
44795 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44796 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44797 + .connect = (void (*)(int))xpc_notloaded,
44798 + .disconnect = (void (*)(int))xpc_notloaded,
44799 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44800 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44801 void *))xpc_notloaded,
44802 - (void (*)(short, int, void *))xpc_notloaded,
44803 - (enum xp_retval(*)(short, void *))xpc_notloaded
44804 + .received = (void (*)(short, int, void *))xpc_notloaded,
44805 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
44806 };
44807 EXPORT_SYMBOL_GPL(xpc_interface);
44808
44809 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44810 index b94d5f7..7f494c5 100644
44811 --- a/drivers/misc/sgi-xp/xpc.h
44812 +++ b/drivers/misc/sgi-xp/xpc.h
44813 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
44814 void (*received_payload) (struct xpc_channel *, void *);
44815 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44816 };
44817 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44818
44819 /* struct xpc_partition act_state values (for XPC HB) */
44820
44821 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44822 /* found in xpc_main.c */
44823 extern struct device *xpc_part;
44824 extern struct device *xpc_chan;
44825 -extern struct xpc_arch_operations xpc_arch_ops;
44826 +extern xpc_arch_operations_no_const xpc_arch_ops;
44827 extern int xpc_disengage_timelimit;
44828 extern int xpc_disengage_timedout;
44829 extern int xpc_activate_IRQ_rcvd;
44830 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44831 index 82dc574..8539ab2 100644
44832 --- a/drivers/misc/sgi-xp/xpc_main.c
44833 +++ b/drivers/misc/sgi-xp/xpc_main.c
44834 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44835 .notifier_call = xpc_system_die,
44836 };
44837
44838 -struct xpc_arch_operations xpc_arch_ops;
44839 +xpc_arch_operations_no_const xpc_arch_ops;
44840
44841 /*
44842 * Timer function to enforce the timelimit on the partition disengage.
44843 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44844
44845 if (((die_args->trapnr == X86_TRAP_MF) ||
44846 (die_args->trapnr == X86_TRAP_XF)) &&
44847 - !user_mode_vm(die_args->regs))
44848 + !user_mode(die_args->regs))
44849 xpc_die_deactivate();
44850
44851 break;
44852 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
44853 index 29d5d98..fea356f 100644
44854 --- a/drivers/mmc/card/block.c
44855 +++ b/drivers/mmc/card/block.c
44856 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
44857 if (idata->ic.postsleep_min_us)
44858 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
44859
44860 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
44861 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
44862 err = -EFAULT;
44863 goto cmd_rel_host;
44864 }
44865 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44866 index e5b5eeb..7bf2212 100644
44867 --- a/drivers/mmc/core/mmc_ops.c
44868 +++ b/drivers/mmc/core/mmc_ops.c
44869 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44870 void *data_buf;
44871 int is_on_stack;
44872
44873 - is_on_stack = object_is_on_stack(buf);
44874 + is_on_stack = object_starts_on_stack(buf);
44875 if (is_on_stack) {
44876 /*
44877 * dma onto stack is unsafe/nonportable, but callers to this
44878 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44879 index 6bf24ab..13d0293b 100644
44880 --- a/drivers/mmc/host/dw_mmc.h
44881 +++ b/drivers/mmc/host/dw_mmc.h
44882 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
44883 int (*parse_dt)(struct dw_mci *host);
44884 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
44885 struct dw_mci_tuning_data *tuning_data);
44886 -};
44887 +} __do_const;
44888 #endif /* _DW_MMC_H_ */
44889 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44890 index f320579..7b7ebac 100644
44891 --- a/drivers/mmc/host/mmci.c
44892 +++ b/drivers/mmc/host/mmci.c
44893 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
44894 }
44895
44896 if (variant->busy_detect) {
44897 - mmci_ops.card_busy = mmci_card_busy;
44898 + pax_open_kernel();
44899 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
44900 + pax_close_kernel();
44901 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44902 }
44903
44904 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
44905 index 1dcaf8a..025af25 100644
44906 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
44907 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
44908 @@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
44909 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
44910 }
44911
44912 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
44913 - sdhci_esdhc_ops.platform_execute_tuning =
44914 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
44915 + pax_open_kernel();
44916 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
44917 esdhc_executing_tuning;
44918 + pax_close_kernel();
44919 + }
44920 boarddata = &imx_data->boarddata;
44921 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
44922 if (!host->mmc->parent->platform_data) {
44923 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44924 index 6debda9..2ba7427 100644
44925 --- a/drivers/mmc/host/sdhci-s3c.c
44926 +++ b/drivers/mmc/host/sdhci-s3c.c
44927 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44928 * we can use overriding functions instead of default.
44929 */
44930 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44931 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44932 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44933 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44934 + pax_open_kernel();
44935 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44936 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44937 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44938 + pax_close_kernel();
44939 }
44940
44941 /* It supports additional host capabilities if needed */
44942 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
44943 index 096993f..f02c23b 100644
44944 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
44945 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
44946 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
44947 size_t totlen = 0, thislen;
44948 int ret = 0;
44949 size_t buflen = 0;
44950 - static char *buffer;
44951 + char *buffer;
44952
44953 if (!ECCBUF_SIZE) {
44954 /* We should fall back to a general writev implementation.
44955 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44956 index 370b9dd..1a1176b 100644
44957 --- a/drivers/mtd/nand/denali.c
44958 +++ b/drivers/mtd/nand/denali.c
44959 @@ -24,6 +24,7 @@
44960 #include <linux/slab.h>
44961 #include <linux/mtd/mtd.h>
44962 #include <linux/module.h>
44963 +#include <linux/slab.h>
44964
44965 #include "denali.h"
44966
44967 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44968 index 51b9d6a..52af9a7 100644
44969 --- a/drivers/mtd/nftlmount.c
44970 +++ b/drivers/mtd/nftlmount.c
44971 @@ -24,6 +24,7 @@
44972 #include <asm/errno.h>
44973 #include <linux/delay.h>
44974 #include <linux/slab.h>
44975 +#include <linux/sched.h>
44976 #include <linux/mtd/mtd.h>
44977 #include <linux/mtd/nand.h>
44978 #include <linux/mtd/nftl.h>
44979 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44980 index 4b8e895..6b3c498 100644
44981 --- a/drivers/mtd/sm_ftl.c
44982 +++ b/drivers/mtd/sm_ftl.c
44983 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44984 #define SM_CIS_VENDOR_OFFSET 0x59
44985 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44986 {
44987 - struct attribute_group *attr_group;
44988 + attribute_group_no_const *attr_group;
44989 struct attribute **attributes;
44990 struct sm_sysfs_attribute *vendor_attribute;
44991
44992 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44993 index 4b8c58b..a200546 100644
44994 --- a/drivers/net/bonding/bond_main.c
44995 +++ b/drivers/net/bonding/bond_main.c
44996 @@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
44997
44998 bond_netlink_fini();
44999 unregister_pernet_subsys(&bond_net_ops);
45000 + rtnl_link_unregister(&bond_link_ops);
45001
45002 #ifdef CONFIG_NET_POLL_CONTROLLER
45003 /*
45004 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45005 index 40e7b1c..6a70fff 100644
45006 --- a/drivers/net/bonding/bond_netlink.c
45007 +++ b/drivers/net/bonding/bond_netlink.c
45008 @@ -102,7 +102,7 @@ nla_put_failure:
45009 return -EMSGSIZE;
45010 }
45011
45012 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45013 +struct rtnl_link_ops bond_link_ops = {
45014 .kind = "bond",
45015 .priv_size = sizeof(struct bonding),
45016 .setup = bond_setup,
45017 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45018 index 36fa577..a158806 100644
45019 --- a/drivers/net/ethernet/8390/ax88796.c
45020 +++ b/drivers/net/ethernet/8390/ax88796.c
45021 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45022 if (ax->plat->reg_offsets)
45023 ei_local->reg_offset = ax->plat->reg_offsets;
45024 else {
45025 + resource_size_t _mem_size = mem_size;
45026 + do_div(_mem_size, 0x18);
45027 ei_local->reg_offset = ax->reg_offsets;
45028 for (ret = 0; ret < 0x18; ret++)
45029 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45030 + ax->reg_offsets[ret] = _mem_size * ret;
45031 }
45032
45033 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45034 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45035 index 41f3ca5a..1ee5364 100644
45036 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45037 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45038 @@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45039 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45040 {
45041 /* RX_MODE controlling object */
45042 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45043 + bnx2x_init_rx_mode_obj(bp);
45044
45045 /* multicast configuration controlling object */
45046 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45047 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45048 index 18438a5..c923b8e 100644
45049 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45050 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45051 @@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45052 return rc;
45053 }
45054
45055 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45056 - struct bnx2x_rx_mode_obj *o)
45057 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45058 {
45059 if (CHIP_IS_E1x(bp)) {
45060 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45061 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45062 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45063 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45064 } else {
45065 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45066 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45067 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45068 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45069 }
45070 }
45071
45072 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45073 index 6a53c15..6e7d1e7 100644
45074 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45075 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45076 @@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45077
45078 /********************* RX MODE ****************/
45079
45080 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45081 - struct bnx2x_rx_mode_obj *o);
45082 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45083
45084 /**
45085 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45086 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45087 index 5c3835a..d18b952 100644
45088 --- a/drivers/net/ethernet/broadcom/tg3.h
45089 +++ b/drivers/net/ethernet/broadcom/tg3.h
45090 @@ -150,6 +150,7 @@
45091 #define CHIPREV_ID_5750_A0 0x4000
45092 #define CHIPREV_ID_5750_A1 0x4001
45093 #define CHIPREV_ID_5750_A3 0x4003
45094 +#define CHIPREV_ID_5750_C1 0x4201
45095 #define CHIPREV_ID_5750_C2 0x4202
45096 #define CHIPREV_ID_5752_A0_HW 0x5000
45097 #define CHIPREV_ID_5752_A0 0x6000
45098 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45099 index 3ca77fa..fcc015f 100644
45100 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45101 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45102 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45103 }
45104
45105 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45106 - bna_cb_ioceth_enable,
45107 - bna_cb_ioceth_disable,
45108 - bna_cb_ioceth_hbfail,
45109 - bna_cb_ioceth_reset
45110 + .enable_cbfn = bna_cb_ioceth_enable,
45111 + .disable_cbfn = bna_cb_ioceth_disable,
45112 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45113 + .reset_cbfn = bna_cb_ioceth_reset
45114 };
45115
45116 static void bna_attr_init(struct bna_ioceth *ioceth)
45117 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45118 index 8cffcdf..aadf043 100644
45119 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45120 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45121 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45122 */
45123 struct l2t_skb_cb {
45124 arp_failure_handler_func arp_failure_handler;
45125 -};
45126 +} __no_const;
45127
45128 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45129
45130 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45131 index fff02ed..d421412 100644
45132 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45133 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45134 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45135
45136 int i;
45137 struct adapter *ap = netdev2adap(dev);
45138 - static const unsigned int *reg_ranges;
45139 + const unsigned int *reg_ranges;
45140 int arr_size = 0, buf_size = 0;
45141
45142 if (is_t4(ap->params.chip)) {
45143 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45144 index c05b66d..ed69872 100644
45145 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45146 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45147 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45148 for (i=0; i<ETH_ALEN; i++) {
45149 tmp.addr[i] = dev->dev_addr[i];
45150 }
45151 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45152 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45153 break;
45154
45155 case DE4X5_SET_HWADDR: /* Set the hardware address */
45156 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45157 spin_lock_irqsave(&lp->lock, flags);
45158 memcpy(&statbuf, &lp->pktStats, ioc->len);
45159 spin_unlock_irqrestore(&lp->lock, flags);
45160 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45161 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45162 return -EFAULT;
45163 break;
45164 }
45165 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45166 index a37039d..a51d7e8 100644
45167 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45168 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45169 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45170
45171 if (wrapped)
45172 newacc += 65536;
45173 - ACCESS_ONCE(*acc) = newacc;
45174 + ACCESS_ONCE_RW(*acc) = newacc;
45175 }
45176
45177 static void populate_erx_stats(struct be_adapter *adapter,
45178 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45179 index 212f44b..fb69959 100644
45180 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45181 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45182 @@ -31,6 +31,8 @@
45183 #include <linux/netdevice.h>
45184 #include <linux/phy.h>
45185 #include <linux/platform_device.h>
45186 +#include <linux/interrupt.h>
45187 +#include <linux/irqreturn.h>
45188 #include <net/ip.h>
45189
45190 #include "ftgmac100.h"
45191 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45192 index 8be5b40..081bc1b 100644
45193 --- a/drivers/net/ethernet/faraday/ftmac100.c
45194 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45195 @@ -31,6 +31,8 @@
45196 #include <linux/module.h>
45197 #include <linux/netdevice.h>
45198 #include <linux/platform_device.h>
45199 +#include <linux/interrupt.h>
45200 +#include <linux/irqreturn.h>
45201
45202 #include "ftmac100.h"
45203
45204 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45205 index 5184e2a..acb28c3 100644
45206 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45207 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45208 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45209 }
45210
45211 /* update the base incval used to calculate frequency adjustment */
45212 - ACCESS_ONCE(adapter->base_incval) = incval;
45213 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45214 smp_mb();
45215
45216 /* need lock to prevent incorrect read while modifying cyclecounter */
45217 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45218 index fbe5363..266b4e3 100644
45219 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45220 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45221 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45222 struct __vxge_hw_fifo *fifo;
45223 struct vxge_hw_fifo_config *config;
45224 u32 txdl_size, txdl_per_memblock;
45225 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45226 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45227 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45228 + };
45229 +
45230 struct __vxge_hw_virtualpath *vpath;
45231
45232 if ((vp == NULL) || (attr == NULL)) {
45233 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45234 goto exit;
45235 }
45236
45237 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45238 -
45239 fifo->mempool =
45240 __vxge_hw_mempool_create(vpath->hldev,
45241 fifo->config->memblock_size,
45242 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45243 index 918e18d..4ca3650 100644
45244 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45245 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45246 @@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45247 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45248 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45249 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45250 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45251 + pax_open_kernel();
45252 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45253 + pax_close_kernel();
45254 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45255 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45256 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45257 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45258 index 734d286..b017bf5 100644
45259 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45260 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45261 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45262 case QLCNIC_NON_PRIV_FUNC:
45263 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45264 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45265 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45266 + pax_open_kernel();
45267 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45268 + pax_close_kernel();
45269 break;
45270 case QLCNIC_PRIV_FUNC:
45271 ahw->op_mode = QLCNIC_PRIV_FUNC;
45272 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45273 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45274 + pax_open_kernel();
45275 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45276 + pax_close_kernel();
45277 break;
45278 case QLCNIC_MGMT_FUNC:
45279 ahw->op_mode = QLCNIC_MGMT_FUNC;
45280 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45281 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45282 + pax_open_kernel();
45283 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45284 + pax_close_kernel();
45285 break;
45286 default:
45287 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45288 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45289 index 7763962..c3499a7 100644
45290 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45291 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45292 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45293 struct qlcnic_dump_entry *entry;
45294 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45295 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45296 - static const struct qlcnic_dump_operations *fw_dump_ops;
45297 + const struct qlcnic_dump_operations *fw_dump_ops;
45298 struct device *dev = &adapter->pdev->dev;
45299 struct qlcnic_hardware_context *ahw;
45300 void *temp_buffer;
45301 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45302 index c737f0e..32b8682 100644
45303 --- a/drivers/net/ethernet/realtek/r8169.c
45304 +++ b/drivers/net/ethernet/realtek/r8169.c
45305 @@ -759,22 +759,22 @@ struct rtl8169_private {
45306 struct mdio_ops {
45307 void (*write)(struct rtl8169_private *, int, int);
45308 int (*read)(struct rtl8169_private *, int);
45309 - } mdio_ops;
45310 + } __no_const mdio_ops;
45311
45312 struct pll_power_ops {
45313 void (*down)(struct rtl8169_private *);
45314 void (*up)(struct rtl8169_private *);
45315 - } pll_power_ops;
45316 + } __no_const pll_power_ops;
45317
45318 struct jumbo_ops {
45319 void (*enable)(struct rtl8169_private *);
45320 void (*disable)(struct rtl8169_private *);
45321 - } jumbo_ops;
45322 + } __no_const jumbo_ops;
45323
45324 struct csi_ops {
45325 void (*write)(struct rtl8169_private *, int, int);
45326 u32 (*read)(struct rtl8169_private *, int);
45327 - } csi_ops;
45328 + } __no_const csi_ops;
45329
45330 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45331 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45332 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45333 index 3dd39dc..85efa46 100644
45334 --- a/drivers/net/ethernet/sfc/ptp.c
45335 +++ b/drivers/net/ethernet/sfc/ptp.c
45336 @@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45337 ptp->start.dma_addr);
45338
45339 /* Clear flag that signals MC ready */
45340 - ACCESS_ONCE(*start) = 0;
45341 + ACCESS_ONCE_RW(*start) = 0;
45342 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45343 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45344 EFX_BUG_ON_PARANOID(rc);
45345 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45346 index 50617c5..b13724c 100644
45347 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45348 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45349 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45350
45351 writel(value, ioaddr + MMC_CNTRL);
45352
45353 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45354 - MMC_CNTRL, value);
45355 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45356 +// MMC_CNTRL, value);
45357 }
45358
45359 /* To mask all all interrupts.*/
45360 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
45361 index e6fe0d8..2b7d752 100644
45362 --- a/drivers/net/hyperv/hyperv_net.h
45363 +++ b/drivers/net/hyperv/hyperv_net.h
45364 @@ -101,7 +101,7 @@ struct rndis_device {
45365
45366 enum rndis_device_state state;
45367 bool link_state;
45368 - atomic_t new_req_id;
45369 + atomic_unchecked_t new_req_id;
45370
45371 spinlock_t request_lock;
45372 struct list_head req_list;
45373 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
45374 index 0775f0a..d4fb316 100644
45375 --- a/drivers/net/hyperv/rndis_filter.c
45376 +++ b/drivers/net/hyperv/rndis_filter.c
45377 @@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
45378 * template
45379 */
45380 set = &rndis_msg->msg.set_req;
45381 - set->req_id = atomic_inc_return(&dev->new_req_id);
45382 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45383
45384 /* Add to the request list */
45385 spin_lock_irqsave(&dev->request_lock, flags);
45386 @@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
45387
45388 /* Setup the rndis set */
45389 halt = &request->request_msg.msg.halt_req;
45390 - halt->req_id = atomic_inc_return(&dev->new_req_id);
45391 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45392
45393 /* Ignore return since this msg is optional. */
45394 rndis_filter_send_request(dev, request);
45395 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
45396 index bf0d55e..82bcfbd1 100644
45397 --- a/drivers/net/ieee802154/fakehard.c
45398 +++ b/drivers/net/ieee802154/fakehard.c
45399 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
45400 phy->transmit_power = 0xbf;
45401
45402 dev->netdev_ops = &fake_ops;
45403 - dev->ml_priv = &fake_mlme;
45404 + dev->ml_priv = (void *)&fake_mlme;
45405
45406 priv = netdev_priv(dev);
45407 priv->phy = phy;
45408 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
45409 index bc8faae..e51e25d 100644
45410 --- a/drivers/net/macvlan.c
45411 +++ b/drivers/net/macvlan.c
45412 @@ -990,13 +990,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
45413 int macvlan_link_register(struct rtnl_link_ops *ops)
45414 {
45415 /* common fields */
45416 - ops->priv_size = sizeof(struct macvlan_dev);
45417 - ops->validate = macvlan_validate;
45418 - ops->maxtype = IFLA_MACVLAN_MAX;
45419 - ops->policy = macvlan_policy;
45420 - ops->changelink = macvlan_changelink;
45421 - ops->get_size = macvlan_get_size;
45422 - ops->fill_info = macvlan_fill_info;
45423 + pax_open_kernel();
45424 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
45425 + *(void **)&ops->validate = macvlan_validate;
45426 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
45427 + *(const void **)&ops->policy = macvlan_policy;
45428 + *(void **)&ops->changelink = macvlan_changelink;
45429 + *(void **)&ops->get_size = macvlan_get_size;
45430 + *(void **)&ops->fill_info = macvlan_fill_info;
45431 + pax_close_kernel();
45432
45433 return rtnl_link_register(ops);
45434 };
45435 @@ -1051,7 +1053,7 @@ static int macvlan_device_event(struct notifier_block *unused,
45436 return NOTIFY_DONE;
45437 }
45438
45439 -static struct notifier_block macvlan_notifier_block __read_mostly = {
45440 +static struct notifier_block macvlan_notifier_block = {
45441 .notifier_call = macvlan_device_event,
45442 };
45443
45444 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
45445 index 2a89da0..c17fe1d 100644
45446 --- a/drivers/net/macvtap.c
45447 +++ b/drivers/net/macvtap.c
45448 @@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
45449 }
45450
45451 ret = 0;
45452 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45453 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45454 put_user(q->flags, &ifr->ifr_flags))
45455 ret = -EFAULT;
45456 macvtap_put_vlan(vlan);
45457 @@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
45458 return NOTIFY_DONE;
45459 }
45460
45461 -static struct notifier_block macvtap_notifier_block __read_mostly = {
45462 +static struct notifier_block macvtap_notifier_block = {
45463 .notifier_call = macvtap_device_event,
45464 };
45465
45466 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
45467 index daec9b0..6428fcb 100644
45468 --- a/drivers/net/phy/mdio-bitbang.c
45469 +++ b/drivers/net/phy/mdio-bitbang.c
45470 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
45471 struct mdiobb_ctrl *ctrl = bus->priv;
45472
45473 module_put(ctrl->ops->owner);
45474 + mdiobus_unregister(bus);
45475 mdiobus_free(bus);
45476 }
45477 EXPORT_SYMBOL(free_mdio_bitbang);
45478 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
45479 index 72ff14b..11d442d 100644
45480 --- a/drivers/net/ppp/ppp_generic.c
45481 +++ b/drivers/net/ppp/ppp_generic.c
45482 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45483 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
45484 struct ppp_stats stats;
45485 struct ppp_comp_stats cstats;
45486 - char *vers;
45487
45488 switch (cmd) {
45489 case SIOCGPPPSTATS:
45490 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45491 break;
45492
45493 case SIOCGPPPVER:
45494 - vers = PPP_VERSION;
45495 - if (copy_to_user(addr, vers, strlen(vers) + 1))
45496 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
45497 break;
45498 err = 0;
45499 break;
45500 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
45501 index 1252d9c..80e660b 100644
45502 --- a/drivers/net/slip/slhc.c
45503 +++ b/drivers/net/slip/slhc.c
45504 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
45505 register struct tcphdr *thp;
45506 register struct iphdr *ip;
45507 register struct cstate *cs;
45508 - int len, hdrlen;
45509 + long len, hdrlen;
45510 unsigned char *cp = icp;
45511
45512 /* We've got a compressed packet; read the change byte */
45513 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
45514 index b75ae5b..953c157 100644
45515 --- a/drivers/net/team/team.c
45516 +++ b/drivers/net/team/team.c
45517 @@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
45518 return NOTIFY_DONE;
45519 }
45520
45521 -static struct notifier_block team_notifier_block __read_mostly = {
45522 +static struct notifier_block team_notifier_block = {
45523 .notifier_call = team_device_event,
45524 };
45525
45526 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
45527 index ecec802..614f08f 100644
45528 --- a/drivers/net/tun.c
45529 +++ b/drivers/net/tun.c
45530 @@ -1839,7 +1839,7 @@ unlock:
45531 }
45532
45533 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45534 - unsigned long arg, int ifreq_len)
45535 + unsigned long arg, size_t ifreq_len)
45536 {
45537 struct tun_file *tfile = file->private_data;
45538 struct tun_struct *tun;
45539 @@ -1852,6 +1852,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45540 unsigned int ifindex;
45541 int ret;
45542
45543 + if (ifreq_len > sizeof ifr)
45544 + return -EFAULT;
45545 +
45546 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
45547 if (copy_from_user(&ifr, argp, ifreq_len))
45548 return -EFAULT;
45549 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
45550 index 1a48234..a555339 100644
45551 --- a/drivers/net/usb/hso.c
45552 +++ b/drivers/net/usb/hso.c
45553 @@ -71,7 +71,7 @@
45554 #include <asm/byteorder.h>
45555 #include <linux/serial_core.h>
45556 #include <linux/serial.h>
45557 -
45558 +#include <asm/local.h>
45559
45560 #define MOD_AUTHOR "Option Wireless"
45561 #define MOD_DESCRIPTION "USB High Speed Option driver"
45562 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
45563 struct urb *urb;
45564
45565 urb = serial->rx_urb[0];
45566 - if (serial->port.count > 0) {
45567 + if (atomic_read(&serial->port.count) > 0) {
45568 count = put_rxbuf_data(urb, serial);
45569 if (count == -1)
45570 return;
45571 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
45572 DUMP1(urb->transfer_buffer, urb->actual_length);
45573
45574 /* Anyone listening? */
45575 - if (serial->port.count == 0)
45576 + if (atomic_read(&serial->port.count) == 0)
45577 return;
45578
45579 if (status == 0) {
45580 @@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45581 tty_port_tty_set(&serial->port, tty);
45582
45583 /* check for port already opened, if not set the termios */
45584 - serial->port.count++;
45585 - if (serial->port.count == 1) {
45586 + if (atomic_inc_return(&serial->port.count) == 1) {
45587 serial->rx_state = RX_IDLE;
45588 /* Force default termio settings */
45589 _hso_serial_set_termios(tty, NULL);
45590 @@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45591 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
45592 if (result) {
45593 hso_stop_serial_device(serial->parent);
45594 - serial->port.count--;
45595 + atomic_dec(&serial->port.count);
45596 kref_put(&serial->parent->ref, hso_serial_ref_free);
45597 }
45598 } else {
45599 @@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
45600
45601 /* reset the rts and dtr */
45602 /* do the actual close */
45603 - serial->port.count--;
45604 + atomic_dec(&serial->port.count);
45605
45606 - if (serial->port.count <= 0) {
45607 - serial->port.count = 0;
45608 + if (atomic_read(&serial->port.count) <= 0) {
45609 + atomic_set(&serial->port.count, 0);
45610 tty_port_tty_set(&serial->port, NULL);
45611 if (!usb_gone)
45612 hso_stop_serial_device(serial->parent);
45613 @@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
45614
45615 /* the actual setup */
45616 spin_lock_irqsave(&serial->serial_lock, flags);
45617 - if (serial->port.count)
45618 + if (atomic_read(&serial->port.count))
45619 _hso_serial_set_termios(tty, old);
45620 else
45621 tty->termios = *old;
45622 @@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
45623 D1("Pending read interrupt on port %d\n", i);
45624 spin_lock(&serial->serial_lock);
45625 if (serial->rx_state == RX_IDLE &&
45626 - serial->port.count > 0) {
45627 + atomic_read(&serial->port.count) > 0) {
45628 /* Setup and send a ctrl req read on
45629 * port i */
45630 if (!serial->rx_urb_filled[0]) {
45631 @@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
45632 /* Start all serial ports */
45633 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
45634 if (serial_table[i] && (serial_table[i]->interface == iface)) {
45635 - if (dev2ser(serial_table[i])->port.count) {
45636 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
45637 result =
45638 hso_start_serial_device(serial_table[i], GFP_NOIO);
45639 hso_kick_transmit(dev2ser(serial_table[i]));
45640 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
45641 index a79e9d3..78cd4fa 100644
45642 --- a/drivers/net/usb/sierra_net.c
45643 +++ b/drivers/net/usb/sierra_net.c
45644 @@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
45645 /* atomic counter partially included in MAC address to make sure 2 devices
45646 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
45647 */
45648 -static atomic_t iface_counter = ATOMIC_INIT(0);
45649 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
45650
45651 /*
45652 * SYNC Timer Delay definition used to set the expiry time
45653 @@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
45654 dev->net->netdev_ops = &sierra_net_device_ops;
45655
45656 /* change MAC addr to include, ifacenum, and to be unique */
45657 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
45658 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
45659 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
45660
45661 /* we will have to manufacture ethernet headers, prepare template */
45662 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
45663 index 0247973..088193a 100644
45664 --- a/drivers/net/vxlan.c
45665 +++ b/drivers/net/vxlan.c
45666 @@ -2615,7 +2615,7 @@ nla_put_failure:
45667 return -EMSGSIZE;
45668 }
45669
45670 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
45671 +static struct rtnl_link_ops vxlan_link_ops = {
45672 .kind = "vxlan",
45673 .maxtype = IFLA_VXLAN_MAX,
45674 .policy = vxlan_policy,
45675 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
45676 index 5920c99..ff2e4a5 100644
45677 --- a/drivers/net/wan/lmc/lmc_media.c
45678 +++ b/drivers/net/wan/lmc/lmc_media.c
45679 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
45680 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
45681
45682 lmc_media_t lmc_ds3_media = {
45683 - lmc_ds3_init, /* special media init stuff */
45684 - lmc_ds3_default, /* reset to default state */
45685 - lmc_ds3_set_status, /* reset status to state provided */
45686 - lmc_dummy_set_1, /* set clock source */
45687 - lmc_dummy_set2_1, /* set line speed */
45688 - lmc_ds3_set_100ft, /* set cable length */
45689 - lmc_ds3_set_scram, /* set scrambler */
45690 - lmc_ds3_get_link_status, /* get link status */
45691 - lmc_dummy_set_1, /* set link status */
45692 - lmc_ds3_set_crc_length, /* set CRC length */
45693 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45694 - lmc_ds3_watchdog
45695 + .init = lmc_ds3_init, /* special media init stuff */
45696 + .defaults = lmc_ds3_default, /* reset to default state */
45697 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
45698 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
45699 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45700 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
45701 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
45702 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
45703 + .set_link_status = lmc_dummy_set_1, /* set link status */
45704 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
45705 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45706 + .watchdog = lmc_ds3_watchdog
45707 };
45708
45709 lmc_media_t lmc_hssi_media = {
45710 - lmc_hssi_init, /* special media init stuff */
45711 - lmc_hssi_default, /* reset to default state */
45712 - lmc_hssi_set_status, /* reset status to state provided */
45713 - lmc_hssi_set_clock, /* set clock source */
45714 - lmc_dummy_set2_1, /* set line speed */
45715 - lmc_dummy_set_1, /* set cable length */
45716 - lmc_dummy_set_1, /* set scrambler */
45717 - lmc_hssi_get_link_status, /* get link status */
45718 - lmc_hssi_set_link_status, /* set link status */
45719 - lmc_hssi_set_crc_length, /* set CRC length */
45720 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45721 - lmc_hssi_watchdog
45722 + .init = lmc_hssi_init, /* special media init stuff */
45723 + .defaults = lmc_hssi_default, /* reset to default state */
45724 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
45725 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
45726 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45727 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45728 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45729 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
45730 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
45731 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
45732 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45733 + .watchdog = lmc_hssi_watchdog
45734 };
45735
45736 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
45737 - lmc_ssi_default, /* reset to default state */
45738 - lmc_ssi_set_status, /* reset status to state provided */
45739 - lmc_ssi_set_clock, /* set clock source */
45740 - lmc_ssi_set_speed, /* set line speed */
45741 - lmc_dummy_set_1, /* set cable length */
45742 - lmc_dummy_set_1, /* set scrambler */
45743 - lmc_ssi_get_link_status, /* get link status */
45744 - lmc_ssi_set_link_status, /* set link status */
45745 - lmc_ssi_set_crc_length, /* set CRC length */
45746 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45747 - lmc_ssi_watchdog
45748 +lmc_media_t lmc_ssi_media = {
45749 + .init = lmc_ssi_init, /* special media init stuff */
45750 + .defaults = lmc_ssi_default, /* reset to default state */
45751 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
45752 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
45753 + .set_speed = lmc_ssi_set_speed, /* set line speed */
45754 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45755 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45756 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
45757 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
45758 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
45759 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45760 + .watchdog = lmc_ssi_watchdog
45761 };
45762
45763 lmc_media_t lmc_t1_media = {
45764 - lmc_t1_init, /* special media init stuff */
45765 - lmc_t1_default, /* reset to default state */
45766 - lmc_t1_set_status, /* reset status to state provided */
45767 - lmc_t1_set_clock, /* set clock source */
45768 - lmc_dummy_set2_1, /* set line speed */
45769 - lmc_dummy_set_1, /* set cable length */
45770 - lmc_dummy_set_1, /* set scrambler */
45771 - lmc_t1_get_link_status, /* get link status */
45772 - lmc_dummy_set_1, /* set link status */
45773 - lmc_t1_set_crc_length, /* set CRC length */
45774 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45775 - lmc_t1_watchdog
45776 + .init = lmc_t1_init, /* special media init stuff */
45777 + .defaults = lmc_t1_default, /* reset to default state */
45778 + .set_status = lmc_t1_set_status, /* reset status to state provided */
45779 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
45780 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45781 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45782 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45783 + .get_link_status = lmc_t1_get_link_status, /* get link status */
45784 + .set_link_status = lmc_dummy_set_1, /* set link status */
45785 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
45786 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45787 + .watchdog = lmc_t1_watchdog
45788 };
45789
45790 static void
45791 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
45792 index feacc3b..5bac0de 100644
45793 --- a/drivers/net/wan/z85230.c
45794 +++ b/drivers/net/wan/z85230.c
45795 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
45796
45797 struct z8530_irqhandler z8530_sync =
45798 {
45799 - z8530_rx,
45800 - z8530_tx,
45801 - z8530_status
45802 + .rx = z8530_rx,
45803 + .tx = z8530_tx,
45804 + .status = z8530_status
45805 };
45806
45807 EXPORT_SYMBOL(z8530_sync);
45808 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
45809 }
45810
45811 static struct z8530_irqhandler z8530_dma_sync = {
45812 - z8530_dma_rx,
45813 - z8530_dma_tx,
45814 - z8530_dma_status
45815 + .rx = z8530_dma_rx,
45816 + .tx = z8530_dma_tx,
45817 + .status = z8530_dma_status
45818 };
45819
45820 static struct z8530_irqhandler z8530_txdma_sync = {
45821 - z8530_rx,
45822 - z8530_dma_tx,
45823 - z8530_dma_status
45824 + .rx = z8530_rx,
45825 + .tx = z8530_dma_tx,
45826 + .status = z8530_dma_status
45827 };
45828
45829 /**
45830 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
45831
45832 struct z8530_irqhandler z8530_nop=
45833 {
45834 - z8530_rx_clear,
45835 - z8530_tx_clear,
45836 - z8530_status_clear
45837 + .rx = z8530_rx_clear,
45838 + .tx = z8530_tx_clear,
45839 + .status = z8530_status_clear
45840 };
45841
45842
45843 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
45844 index 0b60295..b8bfa5b 100644
45845 --- a/drivers/net/wimax/i2400m/rx.c
45846 +++ b/drivers/net/wimax/i2400m/rx.c
45847 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
45848 if (i2400m->rx_roq == NULL)
45849 goto error_roq_alloc;
45850
45851 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
45852 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
45853 GFP_KERNEL);
45854 if (rd == NULL) {
45855 result = -ENOMEM;
45856 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
45857 index edf4b57..68b51c0 100644
45858 --- a/drivers/net/wireless/airo.c
45859 +++ b/drivers/net/wireless/airo.c
45860 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
45861 struct airo_info *ai = dev->ml_priv;
45862 int ridcode;
45863 int enabled;
45864 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45865 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45866 unsigned char *iobuf;
45867
45868 /* Only super-user can write RIDs */
45869 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
45870 index 34c8a33..3261fdc 100644
45871 --- a/drivers/net/wireless/at76c50x-usb.c
45872 +++ b/drivers/net/wireless/at76c50x-usb.c
45873 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
45874 }
45875
45876 /* Convert timeout from the DFU status to jiffies */
45877 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
45878 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
45879 {
45880 return msecs_to_jiffies((s->poll_timeout[2] << 16)
45881 | (s->poll_timeout[1] << 8)
45882 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
45883 index edae50b..b24278c 100644
45884 --- a/drivers/net/wireless/ath/ath10k/htc.c
45885 +++ b/drivers/net/wireless/ath/ath10k/htc.c
45886 @@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
45887 /* registered target arrival callback from the HIF layer */
45888 int ath10k_htc_init(struct ath10k *ar)
45889 {
45890 - struct ath10k_hif_cb htc_callbacks;
45891 + static struct ath10k_hif_cb htc_callbacks = {
45892 + .rx_completion = ath10k_htc_rx_completion_handler,
45893 + .tx_completion = ath10k_htc_tx_completion_handler,
45894 + };
45895 struct ath10k_htc_ep *ep = NULL;
45896 struct ath10k_htc *htc = &ar->htc;
45897
45898 @@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
45899 ath10k_htc_reset_endpoint_states(htc);
45900
45901 /* setup HIF layer callbacks */
45902 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
45903 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
45904 htc->ar = ar;
45905
45906 /* Get HIF default pipe for HTC message exchange */
45907 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
45908 index 4716d33..a688310 100644
45909 --- a/drivers/net/wireless/ath/ath10k/htc.h
45910 +++ b/drivers/net/wireless/ath/ath10k/htc.h
45911 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
45912
45913 struct ath10k_htc_ops {
45914 void (*target_send_suspend_complete)(struct ath10k *ar);
45915 -};
45916 +} __no_const;
45917
45918 struct ath10k_htc_ep_ops {
45919 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
45920 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
45921 void (*ep_tx_credits)(struct ath10k *);
45922 -};
45923 +} __no_const;
45924
45925 /* service connection information */
45926 struct ath10k_htc_svc_conn_req {
45927 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45928 index a366d6b..b6f28f8 100644
45929 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45930 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45931 @@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45932 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
45933 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
45934
45935 - ACCESS_ONCE(ads->ds_link) = i->link;
45936 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
45937 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
45938 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
45939
45940 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
45941 ctl6 = SM(i->keytype, AR_EncrType);
45942 @@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45943
45944 if ((i->is_first || i->is_last) &&
45945 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
45946 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
45947 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
45948 | set11nTries(i->rates, 1)
45949 | set11nTries(i->rates, 2)
45950 | set11nTries(i->rates, 3)
45951 | (i->dur_update ? AR_DurUpdateEna : 0)
45952 | SM(0, AR_BurstDur);
45953
45954 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
45955 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
45956 | set11nRate(i->rates, 1)
45957 | set11nRate(i->rates, 2)
45958 | set11nRate(i->rates, 3);
45959 } else {
45960 - ACCESS_ONCE(ads->ds_ctl2) = 0;
45961 - ACCESS_ONCE(ads->ds_ctl3) = 0;
45962 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
45963 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
45964 }
45965
45966 if (!i->is_first) {
45967 - ACCESS_ONCE(ads->ds_ctl0) = 0;
45968 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45969 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45970 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
45971 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45972 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45973 return;
45974 }
45975
45976 @@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45977 break;
45978 }
45979
45980 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
45981 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
45982 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45983 | SM(i->txpower, AR_XmitPower)
45984 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45985 @@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45986 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
45987 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
45988
45989 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45990 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45991 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45992 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45993
45994 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
45995 return;
45996
45997 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45998 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45999 | set11nPktDurRTSCTS(i->rates, 1);
46000
46001 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46002 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46003 | set11nPktDurRTSCTS(i->rates, 3);
46004
46005 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46006 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46007 | set11nRateFlags(i->rates, 1)
46008 | set11nRateFlags(i->rates, 2)
46009 | set11nRateFlags(i->rates, 3)
46010 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46011 index f6c5c1b..6058354 100644
46012 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46013 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46014 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46015 (i->qcu << AR_TxQcuNum_S) | desc_len;
46016
46017 checksum += val;
46018 - ACCESS_ONCE(ads->info) = val;
46019 + ACCESS_ONCE_RW(ads->info) = val;
46020
46021 checksum += i->link;
46022 - ACCESS_ONCE(ads->link) = i->link;
46023 + ACCESS_ONCE_RW(ads->link) = i->link;
46024
46025 checksum += i->buf_addr[0];
46026 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46027 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46028 checksum += i->buf_addr[1];
46029 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46030 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46031 checksum += i->buf_addr[2];
46032 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46033 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46034 checksum += i->buf_addr[3];
46035 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46036 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46037
46038 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46039 - ACCESS_ONCE(ads->ctl3) = val;
46040 + ACCESS_ONCE_RW(ads->ctl3) = val;
46041 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46042 - ACCESS_ONCE(ads->ctl5) = val;
46043 + ACCESS_ONCE_RW(ads->ctl5) = val;
46044 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46045 - ACCESS_ONCE(ads->ctl7) = val;
46046 + ACCESS_ONCE_RW(ads->ctl7) = val;
46047 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46048 - ACCESS_ONCE(ads->ctl9) = val;
46049 + ACCESS_ONCE_RW(ads->ctl9) = val;
46050
46051 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46052 - ACCESS_ONCE(ads->ctl10) = checksum;
46053 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46054
46055 if (i->is_first || i->is_last) {
46056 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46057 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46058 | set11nTries(i->rates, 1)
46059 | set11nTries(i->rates, 2)
46060 | set11nTries(i->rates, 3)
46061 | (i->dur_update ? AR_DurUpdateEna : 0)
46062 | SM(0, AR_BurstDur);
46063
46064 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46065 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46066 | set11nRate(i->rates, 1)
46067 | set11nRate(i->rates, 2)
46068 | set11nRate(i->rates, 3);
46069 } else {
46070 - ACCESS_ONCE(ads->ctl13) = 0;
46071 - ACCESS_ONCE(ads->ctl14) = 0;
46072 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46073 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46074 }
46075
46076 ads->ctl20 = 0;
46077 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46078
46079 ctl17 = SM(i->keytype, AR_EncrType);
46080 if (!i->is_first) {
46081 - ACCESS_ONCE(ads->ctl11) = 0;
46082 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46083 - ACCESS_ONCE(ads->ctl15) = 0;
46084 - ACCESS_ONCE(ads->ctl16) = 0;
46085 - ACCESS_ONCE(ads->ctl17) = ctl17;
46086 - ACCESS_ONCE(ads->ctl18) = 0;
46087 - ACCESS_ONCE(ads->ctl19) = 0;
46088 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46089 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46090 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46091 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46092 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46093 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46094 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46095 return;
46096 }
46097
46098 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46099 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46100 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46101 | SM(i->txpower, AR_XmitPower)
46102 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46103 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46104 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46105 ctl12 |= SM(val, AR_PAPRDChainMask);
46106
46107 - ACCESS_ONCE(ads->ctl12) = ctl12;
46108 - ACCESS_ONCE(ads->ctl17) = ctl17;
46109 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46110 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46111
46112 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46113 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46114 | set11nPktDurRTSCTS(i->rates, 1);
46115
46116 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46117 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46118 | set11nPktDurRTSCTS(i->rates, 3);
46119
46120 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46121 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46122 | set11nRateFlags(i->rates, 1)
46123 | set11nRateFlags(i->rates, 2)
46124 | set11nRateFlags(i->rates, 3)
46125 | SM(i->rtscts_rate, AR_RTSCTSRate);
46126
46127 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46128 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46129 }
46130
46131 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46132 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46133 index a2c9a5d..b52273e 100644
46134 --- a/drivers/net/wireless/ath/ath9k/hw.h
46135 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46136 @@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46137
46138 /* ANI */
46139 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46140 -};
46141 +} __no_const;
46142
46143 /**
46144 * struct ath_spec_scan - parameters for Atheros spectral scan
46145 @@ -711,7 +711,7 @@ struct ath_hw_ops {
46146 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46147 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46148 #endif
46149 -};
46150 +} __no_const;
46151
46152 struct ath_nf_limits {
46153 s16 max;
46154 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46155 index 92190da..f3a4c4c 100644
46156 --- a/drivers/net/wireless/b43/phy_lp.c
46157 +++ b/drivers/net/wireless/b43/phy_lp.c
46158 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46159 {
46160 struct ssb_bus *bus = dev->dev->sdev->bus;
46161
46162 - static const struct b206x_channel *chandata = NULL;
46163 + const struct b206x_channel *chandata = NULL;
46164 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46165 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46166 u16 old_comm15, scale;
46167 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46168 index dea3b50..543db99 100644
46169 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46170 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46171 @@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46172 */
46173 if (il3945_mod_params.disable_hw_scan) {
46174 D_INFO("Disabling hw_scan\n");
46175 - il3945_mac_ops.hw_scan = NULL;
46176 + pax_open_kernel();
46177 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46178 + pax_close_kernel();
46179 }
46180
46181 D_INFO("*** LOAD DRIVER ***\n");
46182 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46183 index d94f8ab..5b568c8 100644
46184 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46185 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46186 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46187 {
46188 struct iwl_priv *priv = file->private_data;
46189 char buf[64];
46190 - int buf_size;
46191 + size_t buf_size;
46192 u32 offset, len;
46193
46194 memset(buf, 0, sizeof(buf));
46195 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46196 struct iwl_priv *priv = file->private_data;
46197
46198 char buf[8];
46199 - int buf_size;
46200 + size_t buf_size;
46201 u32 reset_flag;
46202
46203 memset(buf, 0, sizeof(buf));
46204 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46205 {
46206 struct iwl_priv *priv = file->private_data;
46207 char buf[8];
46208 - int buf_size;
46209 + size_t buf_size;
46210 int ht40;
46211
46212 memset(buf, 0, sizeof(buf));
46213 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46214 {
46215 struct iwl_priv *priv = file->private_data;
46216 char buf[8];
46217 - int buf_size;
46218 + size_t buf_size;
46219 int value;
46220
46221 memset(buf, 0, sizeof(buf));
46222 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46223 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46224 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46225
46226 -static const char *fmt_value = " %-30s %10u\n";
46227 -static const char *fmt_hex = " %-30s 0x%02X\n";
46228 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46229 -static const char *fmt_header =
46230 +static const char fmt_value[] = " %-30s %10u\n";
46231 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46232 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46233 +static const char fmt_header[] =
46234 "%-32s current cumulative delta max\n";
46235
46236 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46237 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46238 {
46239 struct iwl_priv *priv = file->private_data;
46240 char buf[8];
46241 - int buf_size;
46242 + size_t buf_size;
46243 int clear;
46244
46245 memset(buf, 0, sizeof(buf));
46246 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46247 {
46248 struct iwl_priv *priv = file->private_data;
46249 char buf[8];
46250 - int buf_size;
46251 + size_t buf_size;
46252 int trace;
46253
46254 memset(buf, 0, sizeof(buf));
46255 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46256 {
46257 struct iwl_priv *priv = file->private_data;
46258 char buf[8];
46259 - int buf_size;
46260 + size_t buf_size;
46261 int missed;
46262
46263 memset(buf, 0, sizeof(buf));
46264 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46265
46266 struct iwl_priv *priv = file->private_data;
46267 char buf[8];
46268 - int buf_size;
46269 + size_t buf_size;
46270 int plcp;
46271
46272 memset(buf, 0, sizeof(buf));
46273 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46274
46275 struct iwl_priv *priv = file->private_data;
46276 char buf[8];
46277 - int buf_size;
46278 + size_t buf_size;
46279 int flush;
46280
46281 memset(buf, 0, sizeof(buf));
46282 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46283
46284 struct iwl_priv *priv = file->private_data;
46285 char buf[8];
46286 - int buf_size;
46287 + size_t buf_size;
46288 int rts;
46289
46290 if (!priv->cfg->ht_params)
46291 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46292 {
46293 struct iwl_priv *priv = file->private_data;
46294 char buf[8];
46295 - int buf_size;
46296 + size_t buf_size;
46297
46298 memset(buf, 0, sizeof(buf));
46299 buf_size = min(count, sizeof(buf) - 1);
46300 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46301 struct iwl_priv *priv = file->private_data;
46302 u32 event_log_flag;
46303 char buf[8];
46304 - int buf_size;
46305 + size_t buf_size;
46306
46307 /* check that the interface is up */
46308 if (!iwl_is_ready(priv))
46309 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46310 struct iwl_priv *priv = file->private_data;
46311 char buf[8];
46312 u32 calib_disabled;
46313 - int buf_size;
46314 + size_t buf_size;
46315
46316 memset(buf, 0, sizeof(buf));
46317 buf_size = min(count, sizeof(buf) - 1);
46318 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46319 index 7aad766..06addb4 100644
46320 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
46321 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46322 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46323 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46324 {
46325 struct iwl_nvm_data *data = priv->nvm_data;
46326 - char *debug_msg;
46327 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46328
46329 if (data->sku_cap_11n_enable &&
46330 !priv->cfg->ht_params) {
46331 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46332 return -EINVAL;
46333 }
46334
46335 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46336 IWL_DEBUG_INFO(priv, debug_msg,
46337 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46338 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46339 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46340 index f53ef83..5e34bcb 100644
46341 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46342 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46343 @@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46344 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46345
46346 char buf[8];
46347 - int buf_size;
46348 + size_t buf_size;
46349 u32 reset_flag;
46350
46351 memset(buf, 0, sizeof(buf));
46352 @@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46353 {
46354 struct iwl_trans *trans = file->private_data;
46355 char buf[8];
46356 - int buf_size;
46357 + size_t buf_size;
46358 int csr;
46359
46360 memset(buf, 0, sizeof(buf));
46361 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
46362 index a1b32ee..94b3c3d 100644
46363 --- a/drivers/net/wireless/mac80211_hwsim.c
46364 +++ b/drivers/net/wireless/mac80211_hwsim.c
46365 @@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
46366
46367 if (channels > 1) {
46368 hwsim_if_comb.num_different_channels = channels;
46369 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46370 - mac80211_hwsim_ops.cancel_hw_scan =
46371 - mac80211_hwsim_cancel_hw_scan;
46372 - mac80211_hwsim_ops.sw_scan_start = NULL;
46373 - mac80211_hwsim_ops.sw_scan_complete = NULL;
46374 - mac80211_hwsim_ops.remain_on_channel =
46375 - mac80211_hwsim_roc;
46376 - mac80211_hwsim_ops.cancel_remain_on_channel =
46377 - mac80211_hwsim_croc;
46378 - mac80211_hwsim_ops.add_chanctx =
46379 - mac80211_hwsim_add_chanctx;
46380 - mac80211_hwsim_ops.remove_chanctx =
46381 - mac80211_hwsim_remove_chanctx;
46382 - mac80211_hwsim_ops.change_chanctx =
46383 - mac80211_hwsim_change_chanctx;
46384 - mac80211_hwsim_ops.assign_vif_chanctx =
46385 - mac80211_hwsim_assign_vif_chanctx;
46386 - mac80211_hwsim_ops.unassign_vif_chanctx =
46387 - mac80211_hwsim_unassign_vif_chanctx;
46388 + pax_open_kernel();
46389 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46390 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46391 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
46392 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
46393 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
46394 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46395 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46396 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46397 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
46398 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
46399 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
46400 + pax_close_kernel();
46401 }
46402
46403 spin_lock_init(&hwsim_radio_lock);
46404 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
46405 index 8169a85..7fa3b47 100644
46406 --- a/drivers/net/wireless/rndis_wlan.c
46407 +++ b/drivers/net/wireless/rndis_wlan.c
46408 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
46409
46410 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
46411
46412 - if (rts_threshold < 0 || rts_threshold > 2347)
46413 + if (rts_threshold > 2347)
46414 rts_threshold = 2347;
46415
46416 tmp = cpu_to_le32(rts_threshold);
46417 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
46418 index e4ba2ce..63d7417 100644
46419 --- a/drivers/net/wireless/rt2x00/rt2x00.h
46420 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
46421 @@ -377,7 +377,7 @@ struct rt2x00_intf {
46422 * for hardware which doesn't support hardware
46423 * sequence counting.
46424 */
46425 - atomic_t seqno;
46426 + atomic_unchecked_t seqno;
46427 };
46428
46429 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
46430 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
46431 index a5d38e8..d3c24ea 100644
46432 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
46433 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
46434 @@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
46435 * sequence counter given by mac80211.
46436 */
46437 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
46438 - seqno = atomic_add_return(0x10, &intf->seqno);
46439 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
46440 else
46441 - seqno = atomic_read(&intf->seqno);
46442 + seqno = atomic_read_unchecked(&intf->seqno);
46443
46444 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
46445 hdr->seq_ctrl |= cpu_to_le16(seqno);
46446 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
46447 index e2b3d9c..67a5184 100644
46448 --- a/drivers/net/wireless/ti/wl1251/sdio.c
46449 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
46450 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
46451
46452 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
46453
46454 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46455 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46456 + pax_open_kernel();
46457 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46458 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46459 + pax_close_kernel();
46460
46461 wl1251_info("using dedicated interrupt line");
46462 } else {
46463 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46464 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46465 + pax_open_kernel();
46466 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46467 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46468 + pax_close_kernel();
46469
46470 wl1251_info("using SDIO interrupt");
46471 }
46472 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
46473 index be7129b..4161356 100644
46474 --- a/drivers/net/wireless/ti/wl12xx/main.c
46475 +++ b/drivers/net/wireless/ti/wl12xx/main.c
46476 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46477 sizeof(wl->conf.mem));
46478
46479 /* read data preparation is only needed by wl127x */
46480 - wl->ops->prepare_read = wl127x_prepare_read;
46481 + pax_open_kernel();
46482 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46483 + pax_close_kernel();
46484
46485 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46486 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46487 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46488 sizeof(wl->conf.mem));
46489
46490 /* read data preparation is only needed by wl127x */
46491 - wl->ops->prepare_read = wl127x_prepare_read;
46492 + pax_open_kernel();
46493 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46494 + pax_close_kernel();
46495
46496 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46497 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46498 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
46499 index ec37b16..7e34d66 100644
46500 --- a/drivers/net/wireless/ti/wl18xx/main.c
46501 +++ b/drivers/net/wireless/ti/wl18xx/main.c
46502 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
46503 }
46504
46505 if (!checksum_param) {
46506 - wl18xx_ops.set_rx_csum = NULL;
46507 - wl18xx_ops.init_vif = NULL;
46508 + pax_open_kernel();
46509 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
46510 + *(void **)&wl18xx_ops.init_vif = NULL;
46511 + pax_close_kernel();
46512 }
46513
46514 /* Enable 11a Band only if we have 5G antennas */
46515 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
46516 index 84d94f5..bd6c61c 100644
46517 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
46518 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
46519 @@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
46520 {
46521 struct zd_usb *usb = urb->context;
46522 struct zd_usb_interrupt *intr = &usb->intr;
46523 - int len;
46524 + unsigned int len;
46525 u16 int_num;
46526
46527 ZD_ASSERT(in_interrupt());
46528 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
46529 index 7130864..00e64de 100644
46530 --- a/drivers/nfc/nfcwilink.c
46531 +++ b/drivers/nfc/nfcwilink.c
46532 @@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
46533
46534 static int nfcwilink_probe(struct platform_device *pdev)
46535 {
46536 - static struct nfcwilink *drv;
46537 + struct nfcwilink *drv;
46538 int rc;
46539 __u32 protocols;
46540
46541 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
46542 index d93b2b6..ae50401 100644
46543 --- a/drivers/oprofile/buffer_sync.c
46544 +++ b/drivers/oprofile/buffer_sync.c
46545 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
46546 if (cookie == NO_COOKIE)
46547 offset = pc;
46548 if (cookie == INVALID_COOKIE) {
46549 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46550 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46551 offset = pc;
46552 }
46553 if (cookie != last_cookie) {
46554 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
46555 /* add userspace sample */
46556
46557 if (!mm) {
46558 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
46559 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
46560 return 0;
46561 }
46562
46563 cookie = lookup_dcookie(mm, s->eip, &offset);
46564
46565 if (cookie == INVALID_COOKIE) {
46566 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46567 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46568 return 0;
46569 }
46570
46571 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
46572 /* ignore backtraces if failed to add a sample */
46573 if (state == sb_bt_start) {
46574 state = sb_bt_ignore;
46575 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
46576 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
46577 }
46578 }
46579 release_mm(mm);
46580 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
46581 index c0cc4e7..44d4e54 100644
46582 --- a/drivers/oprofile/event_buffer.c
46583 +++ b/drivers/oprofile/event_buffer.c
46584 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
46585 }
46586
46587 if (buffer_pos == buffer_size) {
46588 - atomic_inc(&oprofile_stats.event_lost_overflow);
46589 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
46590 return;
46591 }
46592
46593 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
46594 index ed2c3ec..deda85a 100644
46595 --- a/drivers/oprofile/oprof.c
46596 +++ b/drivers/oprofile/oprof.c
46597 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
46598 if (oprofile_ops.switch_events())
46599 return;
46600
46601 - atomic_inc(&oprofile_stats.multiplex_counter);
46602 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
46603 start_switch_worker();
46604 }
46605
46606 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
46607 index ee2cfce..7f8f699 100644
46608 --- a/drivers/oprofile/oprofile_files.c
46609 +++ b/drivers/oprofile/oprofile_files.c
46610 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
46611
46612 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
46613
46614 -static ssize_t timeout_read(struct file *file, char __user *buf,
46615 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
46616 size_t count, loff_t *offset)
46617 {
46618 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
46619 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
46620 index 59659ce..6c860a0 100644
46621 --- a/drivers/oprofile/oprofile_stats.c
46622 +++ b/drivers/oprofile/oprofile_stats.c
46623 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
46624 cpu_buf->sample_invalid_eip = 0;
46625 }
46626
46627 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
46628 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
46629 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
46630 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
46631 - atomic_set(&oprofile_stats.multiplex_counter, 0);
46632 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
46633 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
46634 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
46635 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
46636 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
46637 }
46638
46639
46640 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
46641 index 1fc622b..8c48fc3 100644
46642 --- a/drivers/oprofile/oprofile_stats.h
46643 +++ b/drivers/oprofile/oprofile_stats.h
46644 @@ -13,11 +13,11 @@
46645 #include <linux/atomic.h>
46646
46647 struct oprofile_stat_struct {
46648 - atomic_t sample_lost_no_mm;
46649 - atomic_t sample_lost_no_mapping;
46650 - atomic_t bt_lost_no_mapping;
46651 - atomic_t event_lost_overflow;
46652 - atomic_t multiplex_counter;
46653 + atomic_unchecked_t sample_lost_no_mm;
46654 + atomic_unchecked_t sample_lost_no_mapping;
46655 + atomic_unchecked_t bt_lost_no_mapping;
46656 + atomic_unchecked_t event_lost_overflow;
46657 + atomic_unchecked_t multiplex_counter;
46658 };
46659
46660 extern struct oprofile_stat_struct oprofile_stats;
46661 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
46662 index 3f49345..c750d0b 100644
46663 --- a/drivers/oprofile/oprofilefs.c
46664 +++ b/drivers/oprofile/oprofilefs.c
46665 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
46666
46667 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
46668 {
46669 - atomic_t *val = file->private_data;
46670 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
46671 + atomic_unchecked_t *val = file->private_data;
46672 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
46673 }
46674
46675
46676 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
46677
46678
46679 int oprofilefs_create_ro_atomic(struct dentry *root,
46680 - char const *name, atomic_t *val)
46681 + char const *name, atomic_unchecked_t *val)
46682 {
46683 return __oprofilefs_create_file(root, name,
46684 &atomic_ro_fops, 0444, val);
46685 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
46686 index 61be1d9..dec05d7 100644
46687 --- a/drivers/oprofile/timer_int.c
46688 +++ b/drivers/oprofile/timer_int.c
46689 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
46690 return NOTIFY_OK;
46691 }
46692
46693 -static struct notifier_block __refdata oprofile_cpu_notifier = {
46694 +static struct notifier_block oprofile_cpu_notifier = {
46695 .notifier_call = oprofile_cpu_notify,
46696 };
46697
46698 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
46699 index 92ed045..62d39bd7 100644
46700 --- a/drivers/parport/procfs.c
46701 +++ b/drivers/parport/procfs.c
46702 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
46703
46704 *ppos += len;
46705
46706 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
46707 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
46708 }
46709
46710 #ifdef CONFIG_PARPORT_1284
46711 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
46712
46713 *ppos += len;
46714
46715 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
46716 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
46717 }
46718 #endif /* IEEE1284.3 support. */
46719
46720 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
46721 index ecfac7e..41be7028 100644
46722 --- a/drivers/pci/hotplug/acpiphp_ibm.c
46723 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
46724 @@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
46725 goto init_cleanup;
46726 }
46727
46728 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46729 + pax_open_kernel();
46730 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46731 + pax_close_kernel();
46732 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
46733
46734 return retval;
46735 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
46736 index 7536eef..52dc8fa 100644
46737 --- a/drivers/pci/hotplug/cpcihp_generic.c
46738 +++ b/drivers/pci/hotplug/cpcihp_generic.c
46739 @@ -73,7 +73,6 @@ static u16 port;
46740 static unsigned int enum_bit;
46741 static u8 enum_mask;
46742
46743 -static struct cpci_hp_controller_ops generic_hpc_ops;
46744 static struct cpci_hp_controller generic_hpc;
46745
46746 static int __init validate_parameters(void)
46747 @@ -139,6 +138,10 @@ static int query_enum(void)
46748 return ((value & enum_mask) == enum_mask);
46749 }
46750
46751 +static struct cpci_hp_controller_ops generic_hpc_ops = {
46752 + .query_enum = query_enum,
46753 +};
46754 +
46755 static int __init cpcihp_generic_init(void)
46756 {
46757 int status;
46758 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
46759 pci_dev_put(dev);
46760
46761 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
46762 - generic_hpc_ops.query_enum = query_enum;
46763 generic_hpc.ops = &generic_hpc_ops;
46764
46765 status = cpci_hp_register_controller(&generic_hpc);
46766 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
46767 index e8c4a7c..7046f5c 100644
46768 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
46769 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
46770 @@ -59,7 +59,6 @@
46771 /* local variables */
46772 static bool debug;
46773 static bool poll;
46774 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
46775 static struct cpci_hp_controller zt5550_hpc;
46776
46777 /* Primary cPCI bus bridge device */
46778 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
46779 return 0;
46780 }
46781
46782 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
46783 + .query_enum = zt5550_hc_query_enum,
46784 +};
46785 +
46786 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
46787 {
46788 int status;
46789 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
46790 dbg("returned from zt5550_hc_config");
46791
46792 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
46793 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
46794 zt5550_hpc.ops = &zt5550_hpc_ops;
46795 if(!poll) {
46796 zt5550_hpc.irq = hc_dev->irq;
46797 zt5550_hpc.irq_flags = IRQF_SHARED;
46798 zt5550_hpc.dev_id = hc_dev;
46799
46800 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46801 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46802 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46803 + pax_open_kernel();
46804 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46805 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46806 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46807 + pax_open_kernel();
46808 } else {
46809 info("using ENUM# polling mode");
46810 }
46811 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
46812 index 76ba8a1..20ca857 100644
46813 --- a/drivers/pci/hotplug/cpqphp_nvram.c
46814 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
46815 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
46816
46817 void compaq_nvram_init (void __iomem *rom_start)
46818 {
46819 +
46820 +#ifndef CONFIG_PAX_KERNEXEC
46821 if (rom_start) {
46822 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
46823 }
46824 +#endif
46825 +
46826 dbg("int15 entry = %p\n", compaq_int15_entry_point);
46827
46828 /* initialize our int15 lock */
46829 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
46830 index cfa92a9..29539c5 100644
46831 --- a/drivers/pci/hotplug/pci_hotplug_core.c
46832 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
46833 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
46834 return -EINVAL;
46835 }
46836
46837 - slot->ops->owner = owner;
46838 - slot->ops->mod_name = mod_name;
46839 + pax_open_kernel();
46840 + *(struct module **)&slot->ops->owner = owner;
46841 + *(const char **)&slot->ops->mod_name = mod_name;
46842 + pax_close_kernel();
46843
46844 mutex_lock(&pci_hp_mutex);
46845 /*
46846 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
46847 index bbd48bb..6907ef4 100644
46848 --- a/drivers/pci/hotplug/pciehp_core.c
46849 +++ b/drivers/pci/hotplug/pciehp_core.c
46850 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
46851 struct slot *slot = ctrl->slot;
46852 struct hotplug_slot *hotplug = NULL;
46853 struct hotplug_slot_info *info = NULL;
46854 - struct hotplug_slot_ops *ops = NULL;
46855 + hotplug_slot_ops_no_const *ops = NULL;
46856 char name[SLOT_NAME_SIZE];
46857 int retval = -ENOMEM;
46858
46859 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
46860 index c91e6c1..5c723ef 100644
46861 --- a/drivers/pci/pci-sysfs.c
46862 +++ b/drivers/pci/pci-sysfs.c
46863 @@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
46864 {
46865 /* allocate attribute structure, piggyback attribute name */
46866 int name_len = write_combine ? 13 : 10;
46867 - struct bin_attribute *res_attr;
46868 + bin_attribute_no_const *res_attr;
46869 int retval;
46870
46871 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
46872 @@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
46873 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
46874 {
46875 int retval;
46876 - struct bin_attribute *attr;
46877 + bin_attribute_no_const *attr;
46878
46879 /* If the device has VPD, try to expose it in sysfs. */
46880 if (dev->vpd) {
46881 @@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
46882 {
46883 int retval;
46884 int rom_size = 0;
46885 - struct bin_attribute *attr;
46886 + bin_attribute_no_const *attr;
46887
46888 if (!sysfs_initialized)
46889 return -EACCES;
46890 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
46891 index 9c91ecc..bda4796 100644
46892 --- a/drivers/pci/pci.h
46893 +++ b/drivers/pci/pci.h
46894 @@ -95,7 +95,7 @@ struct pci_vpd_ops {
46895 struct pci_vpd {
46896 unsigned int len;
46897 const struct pci_vpd_ops *ops;
46898 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
46899 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
46900 };
46901
46902 int pci_vpd_pci22_init(struct pci_dev *dev);
46903 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
46904 index f1272dc..e92a1ac 100644
46905 --- a/drivers/pci/pcie/aspm.c
46906 +++ b/drivers/pci/pcie/aspm.c
46907 @@ -27,9 +27,9 @@
46908 #define MODULE_PARAM_PREFIX "pcie_aspm."
46909
46910 /* Note: those are not register definitions */
46911 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
46912 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
46913 -#define ASPM_STATE_L1 (4) /* L1 state */
46914 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
46915 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
46916 +#define ASPM_STATE_L1 (4U) /* L1 state */
46917 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
46918 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
46919
46920 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
46921 index 38e403d..a2ce55a 100644
46922 --- a/drivers/pci/probe.c
46923 +++ b/drivers/pci/probe.c
46924 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
46925 struct pci_bus_region region, inverted_region;
46926 bool bar_too_big = false, bar_disabled = false;
46927
46928 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
46929 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
46930
46931 /* No printks while decoding is disabled! */
46932 if (!dev->mmio_always_on) {
46933 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
46934 index 46d1378..30e452b 100644
46935 --- a/drivers/pci/proc.c
46936 +++ b/drivers/pci/proc.c
46937 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
46938 static int __init pci_proc_init(void)
46939 {
46940 struct pci_dev *dev = NULL;
46941 +
46942 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46943 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46944 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
46945 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46946 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46947 +#endif
46948 +#else
46949 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
46950 +#endif
46951 proc_create("devices", 0, proc_bus_pci_dir,
46952 &proc_bus_pci_dev_operations);
46953 proc_initialized = 1;
46954 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
46955 index 3e5b4497..dcdfb70 100644
46956 --- a/drivers/platform/chrome/chromeos_laptop.c
46957 +++ b/drivers/platform/chrome/chromeos_laptop.c
46958 @@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
46959 return 0;
46960 }
46961
46962 -static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
46963 +static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
46964 {
46965 .ident = "Samsung Series 5 550 - Touchpad",
46966 .matches = {
46967 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
46968 index 19c313b..ed28b38 100644
46969 --- a/drivers/platform/x86/asus-wmi.c
46970 +++ b/drivers/platform/x86/asus-wmi.c
46971 @@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
46972 int err;
46973 u32 retval = -1;
46974
46975 +#ifdef CONFIG_GRKERNSEC_KMEM
46976 + return -EPERM;
46977 +#endif
46978 +
46979 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
46980
46981 if (err < 0)
46982 @@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
46983 int err;
46984 u32 retval = -1;
46985
46986 +#ifdef CONFIG_GRKERNSEC_KMEM
46987 + return -EPERM;
46988 +#endif
46989 +
46990 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
46991 &retval);
46992
46993 @@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
46994 union acpi_object *obj;
46995 acpi_status status;
46996
46997 +#ifdef CONFIG_GRKERNSEC_KMEM
46998 + return -EPERM;
46999 +#endif
47000 +
47001 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47002 1, asus->debug.method_id,
47003 &input, &output);
47004 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47005 index 62f8030..c7f2a45 100644
47006 --- a/drivers/platform/x86/msi-laptop.c
47007 +++ b/drivers/platform/x86/msi-laptop.c
47008 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47009
47010 if (!quirks->ec_read_only) {
47011 /* allow userland write sysfs file */
47012 - dev_attr_bluetooth.store = store_bluetooth;
47013 - dev_attr_wlan.store = store_wlan;
47014 - dev_attr_threeg.store = store_threeg;
47015 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47016 - dev_attr_wlan.attr.mode |= S_IWUSR;
47017 - dev_attr_threeg.attr.mode |= S_IWUSR;
47018 + pax_open_kernel();
47019 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47020 + *(void **)&dev_attr_wlan.store = store_wlan;
47021 + *(void **)&dev_attr_threeg.store = store_threeg;
47022 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47023 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47024 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47025 + pax_close_kernel();
47026 }
47027
47028 /* disable hardware control by fn key */
47029 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47030 index 70222f2..8c8ce66 100644
47031 --- a/drivers/platform/x86/msi-wmi.c
47032 +++ b/drivers/platform/x86/msi-wmi.c
47033 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47034 static void msi_wmi_notify(u32 value, void *context)
47035 {
47036 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47037 - static struct key_entry *key;
47038 + struct key_entry *key;
47039 union acpi_object *obj;
47040 acpi_status status;
47041
47042 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47043 index fb233ae..23a325c 100644
47044 --- a/drivers/platform/x86/sony-laptop.c
47045 +++ b/drivers/platform/x86/sony-laptop.c
47046 @@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47047 }
47048
47049 /* High speed charging function */
47050 -static struct device_attribute *hsc_handle;
47051 +static device_attribute_no_const *hsc_handle;
47052
47053 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47054 struct device_attribute *attr,
47055 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47056 index 58b0274..6704626 100644
47057 --- a/drivers/platform/x86/thinkpad_acpi.c
47058 +++ b/drivers/platform/x86/thinkpad_acpi.c
47059 @@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47060 return 0;
47061 }
47062
47063 -void static hotkey_mask_warn_incomplete_mask(void)
47064 +static void hotkey_mask_warn_incomplete_mask(void)
47065 {
47066 /* log only what the user can fix... */
47067 const u32 wantedmask = hotkey_driver_mask &
47068 @@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47069 }
47070 }
47071
47072 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47073 - struct tp_nvram_state *newn,
47074 - const u32 event_mask)
47075 -{
47076 -
47077 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47078 do { \
47079 if ((event_mask & (1 << __scancode)) && \
47080 @@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47081 tpacpi_hotkey_send_key(__scancode); \
47082 } while (0)
47083
47084 - void issue_volchange(const unsigned int oldvol,
47085 - const unsigned int newvol)
47086 - {
47087 - unsigned int i = oldvol;
47088 +static void issue_volchange(const unsigned int oldvol,
47089 + const unsigned int newvol,
47090 + const u32 event_mask)
47091 +{
47092 + unsigned int i = oldvol;
47093
47094 - while (i > newvol) {
47095 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47096 - i--;
47097 - }
47098 - while (i < newvol) {
47099 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47100 - i++;
47101 - }
47102 + while (i > newvol) {
47103 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47104 + i--;
47105 }
47106 + while (i < newvol) {
47107 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47108 + i++;
47109 + }
47110 +}
47111
47112 - void issue_brightnesschange(const unsigned int oldbrt,
47113 - const unsigned int newbrt)
47114 - {
47115 - unsigned int i = oldbrt;
47116 +static void issue_brightnesschange(const unsigned int oldbrt,
47117 + const unsigned int newbrt,
47118 + const u32 event_mask)
47119 +{
47120 + unsigned int i = oldbrt;
47121
47122 - while (i > newbrt) {
47123 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47124 - i--;
47125 - }
47126 - while (i < newbrt) {
47127 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47128 - i++;
47129 - }
47130 + while (i > newbrt) {
47131 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47132 + i--;
47133 + }
47134 + while (i < newbrt) {
47135 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47136 + i++;
47137 }
47138 +}
47139
47140 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47141 + struct tp_nvram_state *newn,
47142 + const u32 event_mask)
47143 +{
47144 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47145 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47146 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47147 @@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47148 oldn->volume_level != newn->volume_level) {
47149 /* recently muted, or repeated mute keypress, or
47150 * multiple presses ending in mute */
47151 - issue_volchange(oldn->volume_level, newn->volume_level);
47152 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47153 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47154 }
47155 } else {
47156 @@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47157 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47158 }
47159 if (oldn->volume_level != newn->volume_level) {
47160 - issue_volchange(oldn->volume_level, newn->volume_level);
47161 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47162 } else if (oldn->volume_toggle != newn->volume_toggle) {
47163 /* repeated vol up/down keypress at end of scale ? */
47164 if (newn->volume_level == 0)
47165 @@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47166 /* handle brightness */
47167 if (oldn->brightness_level != newn->brightness_level) {
47168 issue_brightnesschange(oldn->brightness_level,
47169 - newn->brightness_level);
47170 + newn->brightness_level,
47171 + event_mask);
47172 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47173 /* repeated key presses that didn't change state */
47174 if (newn->brightness_level == 0)
47175 @@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47176 && !tp_features.bright_unkfw)
47177 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47178 }
47179 +}
47180
47181 #undef TPACPI_COMPARE_KEY
47182 #undef TPACPI_MAY_SEND_KEY
47183 -}
47184
47185 /*
47186 * Polling driver
47187 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47188 index 769d265..a3a05ca 100644
47189 --- a/drivers/pnp/pnpbios/bioscalls.c
47190 +++ b/drivers/pnp/pnpbios/bioscalls.c
47191 @@ -58,7 +58,7 @@ do { \
47192 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47193 } while(0)
47194
47195 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47196 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47197 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47198
47199 /*
47200 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47201
47202 cpu = get_cpu();
47203 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47204 +
47205 + pax_open_kernel();
47206 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47207 + pax_close_kernel();
47208
47209 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47210 spin_lock_irqsave(&pnp_bios_lock, flags);
47211 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47212 :"memory");
47213 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47214
47215 + pax_open_kernel();
47216 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47217 + pax_close_kernel();
47218 +
47219 put_cpu();
47220
47221 /* If we get here and this is set then the PnP BIOS faulted on us. */
47222 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47223 return status;
47224 }
47225
47226 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47227 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47228 {
47229 int i;
47230
47231 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47232 pnp_bios_callpoint.offset = header->fields.pm16offset;
47233 pnp_bios_callpoint.segment = PNP_CS16;
47234
47235 + pax_open_kernel();
47236 +
47237 for_each_possible_cpu(i) {
47238 struct desc_struct *gdt = get_cpu_gdt_table(i);
47239 if (!gdt)
47240 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47241 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47242 (unsigned long)__va(header->fields.pm16dseg));
47243 }
47244 +
47245 + pax_close_kernel();
47246 }
47247 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47248 index d95e101..67f0c3f 100644
47249 --- a/drivers/pnp/resource.c
47250 +++ b/drivers/pnp/resource.c
47251 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47252 return 1;
47253
47254 /* check if the resource is valid */
47255 - if (*irq < 0 || *irq > 15)
47256 + if (*irq > 15)
47257 return 0;
47258
47259 /* check if the resource is reserved */
47260 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47261 return 1;
47262
47263 /* check if the resource is valid */
47264 - if (*dma < 0 || *dma == 4 || *dma > 7)
47265 + if (*dma == 4 || *dma > 7)
47266 return 0;
47267
47268 /* check if the resource is reserved */
47269 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47270 index 0c52e2a..3421ab7 100644
47271 --- a/drivers/power/pda_power.c
47272 +++ b/drivers/power/pda_power.c
47273 @@ -37,7 +37,11 @@ static int polling;
47274
47275 #if IS_ENABLED(CONFIG_USB_PHY)
47276 static struct usb_phy *transceiver;
47277 -static struct notifier_block otg_nb;
47278 +static int otg_handle_notification(struct notifier_block *nb,
47279 + unsigned long event, void *unused);
47280 +static struct notifier_block otg_nb = {
47281 + .notifier_call = otg_handle_notification
47282 +};
47283 #endif
47284
47285 static struct regulator *ac_draw;
47286 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47287
47288 #if IS_ENABLED(CONFIG_USB_PHY)
47289 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47290 - otg_nb.notifier_call = otg_handle_notification;
47291 ret = usb_register_notifier(transceiver, &otg_nb);
47292 if (ret) {
47293 dev_err(dev, "failure to register otg notifier\n");
47294 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47295 index cc439fd..8fa30df 100644
47296 --- a/drivers/power/power_supply.h
47297 +++ b/drivers/power/power_supply.h
47298 @@ -16,12 +16,12 @@ struct power_supply;
47299
47300 #ifdef CONFIG_SYSFS
47301
47302 -extern void power_supply_init_attrs(struct device_type *dev_type);
47303 +extern void power_supply_init_attrs(void);
47304 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47305
47306 #else
47307
47308 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47309 +static inline void power_supply_init_attrs(void) {}
47310 #define power_supply_uevent NULL
47311
47312 #endif /* CONFIG_SYSFS */
47313 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47314 index 557af94..84dc1fe 100644
47315 --- a/drivers/power/power_supply_core.c
47316 +++ b/drivers/power/power_supply_core.c
47317 @@ -24,7 +24,10 @@
47318 struct class *power_supply_class;
47319 EXPORT_SYMBOL_GPL(power_supply_class);
47320
47321 -static struct device_type power_supply_dev_type;
47322 +extern const struct attribute_group *power_supply_attr_groups[];
47323 +static struct device_type power_supply_dev_type = {
47324 + .groups = power_supply_attr_groups,
47325 +};
47326
47327 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47328 struct power_supply *supply)
47329 @@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47330 return PTR_ERR(power_supply_class);
47331
47332 power_supply_class->dev_uevent = power_supply_uevent;
47333 - power_supply_init_attrs(&power_supply_dev_type);
47334 + power_supply_init_attrs();
47335
47336 return 0;
47337 }
47338 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47339 index 44420d1..967126e 100644
47340 --- a/drivers/power/power_supply_sysfs.c
47341 +++ b/drivers/power/power_supply_sysfs.c
47342 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47343 .is_visible = power_supply_attr_is_visible,
47344 };
47345
47346 -static const struct attribute_group *power_supply_attr_groups[] = {
47347 +const struct attribute_group *power_supply_attr_groups[] = {
47348 &power_supply_attr_group,
47349 NULL,
47350 };
47351
47352 -void power_supply_init_attrs(struct device_type *dev_type)
47353 +void power_supply_init_attrs(void)
47354 {
47355 int i;
47356
47357 - dev_type->groups = power_supply_attr_groups;
47358 -
47359 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
47360 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
47361 }
47362 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
47363 index 84419af..268ede8 100644
47364 --- a/drivers/powercap/powercap_sys.c
47365 +++ b/drivers/powercap/powercap_sys.c
47366 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
47367 struct device_attribute name_attr;
47368 };
47369
47370 +static ssize_t show_constraint_name(struct device *dev,
47371 + struct device_attribute *dev_attr,
47372 + char *buf);
47373 +
47374 static struct powercap_constraint_attr
47375 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
47376 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
47377 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
47378 + .power_limit_attr = {
47379 + .attr = {
47380 + .name = NULL,
47381 + .mode = S_IWUSR | S_IRUGO
47382 + },
47383 + .show = show_constraint_power_limit_uw,
47384 + .store = store_constraint_power_limit_uw
47385 + },
47386 +
47387 + .time_window_attr = {
47388 + .attr = {
47389 + .name = NULL,
47390 + .mode = S_IWUSR | S_IRUGO
47391 + },
47392 + .show = show_constraint_time_window_us,
47393 + .store = store_constraint_time_window_us
47394 + },
47395 +
47396 + .max_power_attr = {
47397 + .attr = {
47398 + .name = NULL,
47399 + .mode = S_IRUGO
47400 + },
47401 + .show = show_constraint_max_power_uw,
47402 + .store = NULL
47403 + },
47404 +
47405 + .min_power_attr = {
47406 + .attr = {
47407 + .name = NULL,
47408 + .mode = S_IRUGO
47409 + },
47410 + .show = show_constraint_min_power_uw,
47411 + .store = NULL
47412 + },
47413 +
47414 + .max_time_window_attr = {
47415 + .attr = {
47416 + .name = NULL,
47417 + .mode = S_IRUGO
47418 + },
47419 + .show = show_constraint_max_time_window_us,
47420 + .store = NULL
47421 + },
47422 +
47423 + .min_time_window_attr = {
47424 + .attr = {
47425 + .name = NULL,
47426 + .mode = S_IRUGO
47427 + },
47428 + .show = show_constraint_min_time_window_us,
47429 + .store = NULL
47430 + },
47431 +
47432 + .name_attr = {
47433 + .attr = {
47434 + .name = NULL,
47435 + .mode = S_IRUGO
47436 + },
47437 + .show = show_constraint_name,
47438 + .store = NULL
47439 + }
47440 + }
47441 +};
47442
47443 /* A list of powercap control_types */
47444 static LIST_HEAD(powercap_cntrl_list);
47445 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
47446 }
47447
47448 static int create_constraint_attribute(int id, const char *name,
47449 - int mode,
47450 - struct device_attribute *dev_attr,
47451 - ssize_t (*show)(struct device *,
47452 - struct device_attribute *, char *),
47453 - ssize_t (*store)(struct device *,
47454 - struct device_attribute *,
47455 - const char *, size_t)
47456 - )
47457 + struct device_attribute *dev_attr)
47458 {
47459 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
47460
47461 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
47462 - id, name);
47463 - if (!dev_attr->attr.name)
47464 + if (!name)
47465 return -ENOMEM;
47466 - dev_attr->attr.mode = mode;
47467 - dev_attr->show = show;
47468 - dev_attr->store = store;
47469 +
47470 + pax_open_kernel();
47471 + *(const char **)&dev_attr->attr.name = name;
47472 + pax_close_kernel();
47473
47474 return 0;
47475 }
47476 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
47477
47478 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
47479 ret = create_constraint_attribute(i, "power_limit_uw",
47480 - S_IWUSR | S_IRUGO,
47481 - &constraint_attrs[i].power_limit_attr,
47482 - show_constraint_power_limit_uw,
47483 - store_constraint_power_limit_uw);
47484 + &constraint_attrs[i].power_limit_attr);
47485 if (ret)
47486 goto err_alloc;
47487 ret = create_constraint_attribute(i, "time_window_us",
47488 - S_IWUSR | S_IRUGO,
47489 - &constraint_attrs[i].time_window_attr,
47490 - show_constraint_time_window_us,
47491 - store_constraint_time_window_us);
47492 + &constraint_attrs[i].time_window_attr);
47493 if (ret)
47494 goto err_alloc;
47495 - ret = create_constraint_attribute(i, "name", S_IRUGO,
47496 - &constraint_attrs[i].name_attr,
47497 - show_constraint_name,
47498 - NULL);
47499 + ret = create_constraint_attribute(i, "name",
47500 + &constraint_attrs[i].name_attr);
47501 if (ret)
47502 goto err_alloc;
47503 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
47504 - &constraint_attrs[i].max_power_attr,
47505 - show_constraint_max_power_uw,
47506 - NULL);
47507 + ret = create_constraint_attribute(i, "max_power_uw",
47508 + &constraint_attrs[i].max_power_attr);
47509 if (ret)
47510 goto err_alloc;
47511 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
47512 - &constraint_attrs[i].min_power_attr,
47513 - show_constraint_min_power_uw,
47514 - NULL);
47515 + ret = create_constraint_attribute(i, "min_power_uw",
47516 + &constraint_attrs[i].min_power_attr);
47517 if (ret)
47518 goto err_alloc;
47519 ret = create_constraint_attribute(i, "max_time_window_us",
47520 - S_IRUGO,
47521 - &constraint_attrs[i].max_time_window_attr,
47522 - show_constraint_max_time_window_us,
47523 - NULL);
47524 + &constraint_attrs[i].max_time_window_attr);
47525 if (ret)
47526 goto err_alloc;
47527 ret = create_constraint_attribute(i, "min_time_window_us",
47528 - S_IRUGO,
47529 - &constraint_attrs[i].min_time_window_attr,
47530 - show_constraint_min_time_window_us,
47531 - NULL);
47532 + &constraint_attrs[i].min_time_window_attr);
47533 if (ret)
47534 goto err_alloc;
47535
47536 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
47537 power_zone->zone_dev_attrs[count++] =
47538 &dev_attr_max_energy_range_uj.attr;
47539 if (power_zone->ops->get_energy_uj) {
47540 + pax_open_kernel();
47541 if (power_zone->ops->reset_energy_uj)
47542 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47543 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47544 else
47545 - dev_attr_energy_uj.attr.mode = S_IRUGO;
47546 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
47547 + pax_close_kernel();
47548 power_zone->zone_dev_attrs[count++] =
47549 &dev_attr_energy_uj.attr;
47550 }
47551 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
47552 index d85f313..ae857d0 100644
47553 --- a/drivers/regulator/core.c
47554 +++ b/drivers/regulator/core.c
47555 @@ -3362,7 +3362,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47556 {
47557 const struct regulation_constraints *constraints = NULL;
47558 const struct regulator_init_data *init_data;
47559 - static atomic_t regulator_no = ATOMIC_INIT(0);
47560 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
47561 struct regulator_dev *rdev;
47562 struct device *dev;
47563 int ret, i;
47564 @@ -3432,7 +3432,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47565 rdev->dev.of_node = config->of_node;
47566 rdev->dev.parent = dev;
47567 dev_set_name(&rdev->dev, "regulator.%d",
47568 - atomic_inc_return(&regulator_no) - 1);
47569 + atomic_inc_return_unchecked(&regulator_no) - 1);
47570 ret = device_register(&rdev->dev);
47571 if (ret != 0) {
47572 put_device(&rdev->dev);
47573 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
47574 index 8d94d3d..653b623 100644
47575 --- a/drivers/regulator/max8660.c
47576 +++ b/drivers/regulator/max8660.c
47577 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
47578 max8660->shadow_regs[MAX8660_OVER1] = 5;
47579 } else {
47580 /* Otherwise devices can be toggled via software */
47581 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
47582 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
47583 + pax_open_kernel();
47584 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
47585 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
47586 + pax_close_kernel();
47587 }
47588
47589 /*
47590 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
47591 index 892aa1e..ebd1b9c 100644
47592 --- a/drivers/regulator/max8973-regulator.c
47593 +++ b/drivers/regulator/max8973-regulator.c
47594 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
47595 if (!pdata || !pdata->enable_ext_control) {
47596 max->desc.enable_reg = MAX8973_VOUT;
47597 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
47598 - max->ops.enable = regulator_enable_regmap;
47599 - max->ops.disable = regulator_disable_regmap;
47600 - max->ops.is_enabled = regulator_is_enabled_regmap;
47601 + pax_open_kernel();
47602 + *(void **)&max->ops.enable = regulator_enable_regmap;
47603 + *(void **)&max->ops.disable = regulator_disable_regmap;
47604 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
47605 + pax_close_kernel();
47606 }
47607
47608 if (pdata) {
47609 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
47610 index 96c9f80..90974ca 100644
47611 --- a/drivers/regulator/mc13892-regulator.c
47612 +++ b/drivers/regulator/mc13892-regulator.c
47613 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
47614 }
47615 mc13xxx_unlock(mc13892);
47616
47617 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47618 + pax_open_kernel();
47619 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47620 = mc13892_vcam_set_mode;
47621 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47622 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47623 = mc13892_vcam_get_mode;
47624 + pax_close_kernel();
47625
47626 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
47627 ARRAY_SIZE(mc13892_regulators));
47628 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
47629 index f148762..5a6d1e5 100644
47630 --- a/drivers/rtc/rtc-cmos.c
47631 +++ b/drivers/rtc/rtc-cmos.c
47632 @@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
47633 hpet_rtc_timer_init();
47634
47635 /* export at least the first block of NVRAM */
47636 - nvram.size = address_space - NVRAM_OFFSET;
47637 + pax_open_kernel();
47638 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
47639 + pax_close_kernel();
47640 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
47641 if (retval < 0) {
47642 dev_dbg(dev, "can't create nvram file? %d\n", retval);
47643 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
47644 index d049393..bb20be0 100644
47645 --- a/drivers/rtc/rtc-dev.c
47646 +++ b/drivers/rtc/rtc-dev.c
47647 @@ -16,6 +16,7 @@
47648 #include <linux/module.h>
47649 #include <linux/rtc.h>
47650 #include <linux/sched.h>
47651 +#include <linux/grsecurity.h>
47652 #include "rtc-core.h"
47653
47654 static dev_t rtc_devt;
47655 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
47656 if (copy_from_user(&tm, uarg, sizeof(tm)))
47657 return -EFAULT;
47658
47659 + gr_log_timechange();
47660 +
47661 return rtc_set_time(rtc, &tm);
47662
47663 case RTC_PIE_ON:
47664 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
47665 index 4e75345..09f8663 100644
47666 --- a/drivers/rtc/rtc-ds1307.c
47667 +++ b/drivers/rtc/rtc-ds1307.c
47668 @@ -107,7 +107,7 @@ struct ds1307 {
47669 u8 offset; /* register's offset */
47670 u8 regs[11];
47671 u16 nvram_offset;
47672 - struct bin_attribute *nvram;
47673 + bin_attribute_no_const *nvram;
47674 enum ds_type type;
47675 unsigned long flags;
47676 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
47677 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
47678 index 11880c1..b823aa4 100644
47679 --- a/drivers/rtc/rtc-m48t59.c
47680 +++ b/drivers/rtc/rtc-m48t59.c
47681 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
47682 if (IS_ERR(m48t59->rtc))
47683 return PTR_ERR(m48t59->rtc);
47684
47685 - m48t59_nvram_attr.size = pdata->offset;
47686 + pax_open_kernel();
47687 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
47688 + pax_close_kernel();
47689
47690 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
47691 if (ret)
47692 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
47693 index 14b5f8d..cc9bd26 100644
47694 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
47695 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
47696 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
47697 for (bit = 0; bit < 8; bit++) {
47698
47699 if ((pci_status[i] & (0x1 << bit)) != 0) {
47700 - static const char *s;
47701 + const char *s;
47702
47703 s = pci_status_strings[bit];
47704 if (i == 7/*TARG*/ && bit == 3)
47705 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
47706
47707 for (bit = 0; bit < 8; bit++) {
47708
47709 - if ((split_status[i] & (0x1 << bit)) != 0) {
47710 - static const char *s;
47711 -
47712 - s = split_status_strings[bit];
47713 - printk(s, ahd_name(ahd),
47714 + if ((split_status[i] & (0x1 << bit)) != 0)
47715 + printk(split_status_strings[bit], ahd_name(ahd),
47716 split_status_source[i]);
47717 - }
47718
47719 if (i > 1)
47720 continue;
47721
47722 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
47723 - static const char *s;
47724 -
47725 - s = split_status_strings[bit];
47726 - printk(s, ahd_name(ahd), "SG");
47727 - }
47728 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
47729 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
47730 }
47731 }
47732 /*
47733 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
47734 index e693af6..2e525b6 100644
47735 --- a/drivers/scsi/bfa/bfa_fcpim.h
47736 +++ b/drivers/scsi/bfa/bfa_fcpim.h
47737 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
47738
47739 struct bfa_itn_s {
47740 bfa_isr_func_t isr;
47741 -};
47742 +} __no_const;
47743
47744 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
47745 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
47746 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
47747 index a3ab5cc..8143622 100644
47748 --- a/drivers/scsi/bfa/bfa_fcs.c
47749 +++ b/drivers/scsi/bfa/bfa_fcs.c
47750 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
47751 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
47752
47753 static struct bfa_fcs_mod_s fcs_modules[] = {
47754 - { bfa_fcs_port_attach, NULL, NULL },
47755 - { bfa_fcs_uf_attach, NULL, NULL },
47756 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
47757 - bfa_fcs_fabric_modexit },
47758 + {
47759 + .attach = bfa_fcs_port_attach,
47760 + .modinit = NULL,
47761 + .modexit = NULL
47762 + },
47763 + {
47764 + .attach = bfa_fcs_uf_attach,
47765 + .modinit = NULL,
47766 + .modexit = NULL
47767 + },
47768 + {
47769 + .attach = bfa_fcs_fabric_attach,
47770 + .modinit = bfa_fcs_fabric_modinit,
47771 + .modexit = bfa_fcs_fabric_modexit
47772 + },
47773 };
47774
47775 /*
47776 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
47777 index f5e4e61..a0acaf6 100644
47778 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
47779 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
47780 @@ -89,15 +89,26 @@ static struct {
47781 void (*offline) (struct bfa_fcs_lport_s *port);
47782 } __port_action[] = {
47783 {
47784 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
47785 - bfa_fcs_lport_unknown_offline}, {
47786 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
47787 - bfa_fcs_lport_fab_offline}, {
47788 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
47789 - bfa_fcs_lport_n2n_offline}, {
47790 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
47791 - bfa_fcs_lport_loop_offline},
47792 - };
47793 + .init = bfa_fcs_lport_unknown_init,
47794 + .online = bfa_fcs_lport_unknown_online,
47795 + .offline = bfa_fcs_lport_unknown_offline
47796 + },
47797 + {
47798 + .init = bfa_fcs_lport_fab_init,
47799 + .online = bfa_fcs_lport_fab_online,
47800 + .offline = bfa_fcs_lport_fab_offline
47801 + },
47802 + {
47803 + .init = bfa_fcs_lport_n2n_init,
47804 + .online = bfa_fcs_lport_n2n_online,
47805 + .offline = bfa_fcs_lport_n2n_offline
47806 + },
47807 + {
47808 + .init = bfa_fcs_lport_loop_init,
47809 + .online = bfa_fcs_lport_loop_online,
47810 + .offline = bfa_fcs_lport_loop_offline
47811 + },
47812 +};
47813
47814 /*
47815 * fcs_port_sm FCS logical port state machine
47816 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
47817 index 90814fe..4384138 100644
47818 --- a/drivers/scsi/bfa/bfa_ioc.h
47819 +++ b/drivers/scsi/bfa/bfa_ioc.h
47820 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
47821 bfa_ioc_disable_cbfn_t disable_cbfn;
47822 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
47823 bfa_ioc_reset_cbfn_t reset_cbfn;
47824 -};
47825 +} __no_const;
47826
47827 /*
47828 * IOC event notification mechanism.
47829 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
47830 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
47831 enum bfi_ioc_state fwstate);
47832 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
47833 -};
47834 +} __no_const;
47835
47836 /*
47837 * Queue element to wait for room in request queue. FIFO order is
47838 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
47839 index a14c784..6de6790 100644
47840 --- a/drivers/scsi/bfa/bfa_modules.h
47841 +++ b/drivers/scsi/bfa/bfa_modules.h
47842 @@ -78,12 +78,12 @@ enum {
47843 \
47844 extern struct bfa_module_s hal_mod_ ## __mod; \
47845 struct bfa_module_s hal_mod_ ## __mod = { \
47846 - bfa_ ## __mod ## _meminfo, \
47847 - bfa_ ## __mod ## _attach, \
47848 - bfa_ ## __mod ## _detach, \
47849 - bfa_ ## __mod ## _start, \
47850 - bfa_ ## __mod ## _stop, \
47851 - bfa_ ## __mod ## _iocdisable, \
47852 + .meminfo = bfa_ ## __mod ## _meminfo, \
47853 + .attach = bfa_ ## __mod ## _attach, \
47854 + .detach = bfa_ ## __mod ## _detach, \
47855 + .start = bfa_ ## __mod ## _start, \
47856 + .stop = bfa_ ## __mod ## _stop, \
47857 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
47858 }
47859
47860 #define BFA_CACHELINE_SZ (256)
47861 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
47862 index 045c4e1..13de803 100644
47863 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
47864 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
47865 @@ -33,8 +33,8 @@
47866 */
47867 #include "libfcoe.h"
47868
47869 -static atomic_t ctlr_num;
47870 -static atomic_t fcf_num;
47871 +static atomic_unchecked_t ctlr_num;
47872 +static atomic_unchecked_t fcf_num;
47873
47874 /*
47875 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
47876 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
47877 if (!ctlr)
47878 goto out;
47879
47880 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
47881 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
47882 ctlr->f = f;
47883 ctlr->mode = FIP_CONN_TYPE_FABRIC;
47884 INIT_LIST_HEAD(&ctlr->fcfs);
47885 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
47886 fcf->dev.parent = &ctlr->dev;
47887 fcf->dev.bus = &fcoe_bus_type;
47888 fcf->dev.type = &fcoe_fcf_device_type;
47889 - fcf->id = atomic_inc_return(&fcf_num) - 1;
47890 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
47891 fcf->state = FCOE_FCF_STATE_UNKNOWN;
47892
47893 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
47894 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
47895 {
47896 int error;
47897
47898 - atomic_set(&ctlr_num, 0);
47899 - atomic_set(&fcf_num, 0);
47900 + atomic_set_unchecked(&ctlr_num, 0);
47901 + atomic_set_unchecked(&fcf_num, 0);
47902
47903 error = bus_register(&fcoe_bus_type);
47904 if (error)
47905 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
47906 index f2c5005..db36c02 100644
47907 --- a/drivers/scsi/hosts.c
47908 +++ b/drivers/scsi/hosts.c
47909 @@ -42,7 +42,7 @@
47910 #include "scsi_logging.h"
47911
47912
47913 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47914 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47915
47916
47917 static void scsi_host_cls_release(struct device *dev)
47918 @@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
47919 * subtract one because we increment first then return, but we need to
47920 * know what the next host number was before increment
47921 */
47922 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
47923 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
47924 shost->dma_channel = 0xff;
47925
47926 /* These three are default values which can be overridden */
47927 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
47928 index 20a5e6e..8b23cea 100644
47929 --- a/drivers/scsi/hpsa.c
47930 +++ b/drivers/scsi/hpsa.c
47931 @@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
47932 unsigned long flags;
47933
47934 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
47935 - return h->access.command_completed(h, q);
47936 + return h->access->command_completed(h, q);
47937
47938 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
47939 a = rq->head[rq->current_entry];
47940 @@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
47941 while (!list_empty(&h->reqQ)) {
47942 c = list_entry(h->reqQ.next, struct CommandList, list);
47943 /* can't do anything if fifo is full */
47944 - if ((h->access.fifo_full(h))) {
47945 + if ((h->access->fifo_full(h))) {
47946 dev_warn(&h->pdev->dev, "fifo full\n");
47947 break;
47948 }
47949 @@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
47950
47951 /* Tell the controller execute command */
47952 spin_unlock_irqrestore(&h->lock, flags);
47953 - h->access.submit_command(h, c);
47954 + h->access->submit_command(h, c);
47955 spin_lock_irqsave(&h->lock, flags);
47956 }
47957 spin_unlock_irqrestore(&h->lock, flags);
47958 @@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
47959
47960 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
47961 {
47962 - return h->access.command_completed(h, q);
47963 + return h->access->command_completed(h, q);
47964 }
47965
47966 static inline bool interrupt_pending(struct ctlr_info *h)
47967 {
47968 - return h->access.intr_pending(h);
47969 + return h->access->intr_pending(h);
47970 }
47971
47972 static inline long interrupt_not_for_us(struct ctlr_info *h)
47973 {
47974 - return (h->access.intr_pending(h) == 0) ||
47975 + return (h->access->intr_pending(h) == 0) ||
47976 (h->interrupts_enabled == 0);
47977 }
47978
47979 @@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
47980 if (prod_index < 0)
47981 return -ENODEV;
47982 h->product_name = products[prod_index].product_name;
47983 - h->access = *(products[prod_index].access);
47984 + h->access = products[prod_index].access;
47985
47986 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
47987 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
47988 @@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
47989
47990 assert_spin_locked(&lockup_detector_lock);
47991 remove_ctlr_from_lockup_detector_list(h);
47992 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
47993 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
47994 spin_lock_irqsave(&h->lock, flags);
47995 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
47996 spin_unlock_irqrestore(&h->lock, flags);
47997 @@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
47998 }
47999
48000 /* make sure the board interrupts are off */
48001 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48002 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48003
48004 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48005 goto clean2;
48006 @@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48007 * fake ones to scoop up any residual completions.
48008 */
48009 spin_lock_irqsave(&h->lock, flags);
48010 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48011 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48012 spin_unlock_irqrestore(&h->lock, flags);
48013 free_irqs(h);
48014 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48015 @@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48016 dev_info(&h->pdev->dev, "Board READY.\n");
48017 dev_info(&h->pdev->dev,
48018 "Waiting for stale completions to drain.\n");
48019 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48020 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48021 msleep(10000);
48022 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48023 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48024
48025 rc = controller_reset_failed(h->cfgtable);
48026 if (rc)
48027 @@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48028 }
48029
48030 /* Turn the interrupts on so we can service requests */
48031 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48032 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48033
48034 hpsa_hba_inquiry(h);
48035 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48036 @@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48037 * To write all data in the battery backed cache to disks
48038 */
48039 hpsa_flush_cache(h);
48040 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48041 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48042 hpsa_free_irqs_and_disable_msix(h);
48043 }
48044
48045 @@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48046 return;
48047 }
48048 /* Change the access methods to the performant access methods */
48049 - h->access = SA5_performant_access;
48050 + h->access = &SA5_performant_access;
48051 h->transMethod = CFGTBL_Trans_Performant;
48052 }
48053
48054 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48055 index bc85e72..d463049 100644
48056 --- a/drivers/scsi/hpsa.h
48057 +++ b/drivers/scsi/hpsa.h
48058 @@ -79,7 +79,7 @@ struct ctlr_info {
48059 unsigned int msix_vector;
48060 unsigned int msi_vector;
48061 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48062 - struct access_method access;
48063 + struct access_method *access;
48064
48065 /* queue and queue Info */
48066 struct list_head reqQ;
48067 @@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48068 }
48069
48070 static struct access_method SA5_access = {
48071 - SA5_submit_command,
48072 - SA5_intr_mask,
48073 - SA5_fifo_full,
48074 - SA5_intr_pending,
48075 - SA5_completed,
48076 + .submit_command = SA5_submit_command,
48077 + .set_intr_mask = SA5_intr_mask,
48078 + .fifo_full = SA5_fifo_full,
48079 + .intr_pending = SA5_intr_pending,
48080 + .command_completed = SA5_completed,
48081 };
48082
48083 static struct access_method SA5_performant_access = {
48084 - SA5_submit_command,
48085 - SA5_performant_intr_mask,
48086 - SA5_fifo_full,
48087 - SA5_performant_intr_pending,
48088 - SA5_performant_completed,
48089 + .submit_command = SA5_submit_command,
48090 + .set_intr_mask = SA5_performant_intr_mask,
48091 + .fifo_full = SA5_fifo_full,
48092 + .intr_pending = SA5_performant_intr_pending,
48093 + .command_completed = SA5_performant_completed,
48094 };
48095
48096 struct board_type {
48097 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48098 index 1b3a094..068e683 100644
48099 --- a/drivers/scsi/libfc/fc_exch.c
48100 +++ b/drivers/scsi/libfc/fc_exch.c
48101 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48102 u16 pool_max_index;
48103
48104 struct {
48105 - atomic_t no_free_exch;
48106 - atomic_t no_free_exch_xid;
48107 - atomic_t xid_not_found;
48108 - atomic_t xid_busy;
48109 - atomic_t seq_not_found;
48110 - atomic_t non_bls_resp;
48111 + atomic_unchecked_t no_free_exch;
48112 + atomic_unchecked_t no_free_exch_xid;
48113 + atomic_unchecked_t xid_not_found;
48114 + atomic_unchecked_t xid_busy;
48115 + atomic_unchecked_t seq_not_found;
48116 + atomic_unchecked_t non_bls_resp;
48117 } stats;
48118 };
48119
48120 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48121 /* allocate memory for exchange */
48122 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48123 if (!ep) {
48124 - atomic_inc(&mp->stats.no_free_exch);
48125 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48126 goto out;
48127 }
48128 memset(ep, 0, sizeof(*ep));
48129 @@ -874,7 +874,7 @@ out:
48130 return ep;
48131 err:
48132 spin_unlock_bh(&pool->lock);
48133 - atomic_inc(&mp->stats.no_free_exch_xid);
48134 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48135 mempool_free(ep, mp->ep_pool);
48136 return NULL;
48137 }
48138 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48139 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48140 ep = fc_exch_find(mp, xid);
48141 if (!ep) {
48142 - atomic_inc(&mp->stats.xid_not_found);
48143 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48144 reject = FC_RJT_OX_ID;
48145 goto out;
48146 }
48147 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48148 ep = fc_exch_find(mp, xid);
48149 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48150 if (ep) {
48151 - atomic_inc(&mp->stats.xid_busy);
48152 + atomic_inc_unchecked(&mp->stats.xid_busy);
48153 reject = FC_RJT_RX_ID;
48154 goto rel;
48155 }
48156 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48157 }
48158 xid = ep->xid; /* get our XID */
48159 } else if (!ep) {
48160 - atomic_inc(&mp->stats.xid_not_found);
48161 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48162 reject = FC_RJT_RX_ID; /* XID not found */
48163 goto out;
48164 }
48165 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48166 } else {
48167 sp = &ep->seq;
48168 if (sp->id != fh->fh_seq_id) {
48169 - atomic_inc(&mp->stats.seq_not_found);
48170 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48171 if (f_ctl & FC_FC_END_SEQ) {
48172 /*
48173 * Update sequence_id based on incoming last
48174 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48175
48176 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48177 if (!ep) {
48178 - atomic_inc(&mp->stats.xid_not_found);
48179 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48180 goto out;
48181 }
48182 if (ep->esb_stat & ESB_ST_COMPLETE) {
48183 - atomic_inc(&mp->stats.xid_not_found);
48184 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48185 goto rel;
48186 }
48187 if (ep->rxid == FC_XID_UNKNOWN)
48188 ep->rxid = ntohs(fh->fh_rx_id);
48189 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48190 - atomic_inc(&mp->stats.xid_not_found);
48191 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48192 goto rel;
48193 }
48194 if (ep->did != ntoh24(fh->fh_s_id) &&
48195 ep->did != FC_FID_FLOGI) {
48196 - atomic_inc(&mp->stats.xid_not_found);
48197 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48198 goto rel;
48199 }
48200 sof = fr_sof(fp);
48201 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48202 sp->ssb_stat |= SSB_ST_RESP;
48203 sp->id = fh->fh_seq_id;
48204 } else if (sp->id != fh->fh_seq_id) {
48205 - atomic_inc(&mp->stats.seq_not_found);
48206 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48207 goto rel;
48208 }
48209
48210 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48211 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48212
48213 if (!sp)
48214 - atomic_inc(&mp->stats.xid_not_found);
48215 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48216 else
48217 - atomic_inc(&mp->stats.non_bls_resp);
48218 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
48219
48220 fc_frame_free(fp);
48221 }
48222 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48223
48224 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48225 mp = ema->mp;
48226 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48227 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48228 st->fc_no_free_exch_xid +=
48229 - atomic_read(&mp->stats.no_free_exch_xid);
48230 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48231 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48232 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48233 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48234 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48235 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48236 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48237 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48238 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48239 }
48240 }
48241 EXPORT_SYMBOL(fc_exch_update_stats);
48242 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48243 index d289583..b745eec 100644
48244 --- a/drivers/scsi/libsas/sas_ata.c
48245 +++ b/drivers/scsi/libsas/sas_ata.c
48246 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48247 .postreset = ata_std_postreset,
48248 .error_handler = ata_std_error_handler,
48249 .post_internal_cmd = sas_ata_post_internal,
48250 - .qc_defer = ata_std_qc_defer,
48251 + .qc_defer = ata_std_qc_defer,
48252 .qc_prep = ata_noop_qc_prep,
48253 .qc_issue = sas_ata_qc_issue,
48254 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48255 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48256 index 4e1b75c..0bbdfa9 100644
48257 --- a/drivers/scsi/lpfc/lpfc.h
48258 +++ b/drivers/scsi/lpfc/lpfc.h
48259 @@ -432,7 +432,7 @@ struct lpfc_vport {
48260 struct dentry *debug_nodelist;
48261 struct dentry *vport_debugfs_root;
48262 struct lpfc_debugfs_trc *disc_trc;
48263 - atomic_t disc_trc_cnt;
48264 + atomic_unchecked_t disc_trc_cnt;
48265 #endif
48266 uint8_t stat_data_enabled;
48267 uint8_t stat_data_blocked;
48268 @@ -865,8 +865,8 @@ struct lpfc_hba {
48269 struct timer_list fabric_block_timer;
48270 unsigned long bit_flags;
48271 #define FABRIC_COMANDS_BLOCKED 0
48272 - atomic_t num_rsrc_err;
48273 - atomic_t num_cmd_success;
48274 + atomic_unchecked_t num_rsrc_err;
48275 + atomic_unchecked_t num_cmd_success;
48276 unsigned long last_rsrc_error_time;
48277 unsigned long last_ramp_down_time;
48278 unsigned long last_ramp_up_time;
48279 @@ -902,7 +902,7 @@ struct lpfc_hba {
48280
48281 struct dentry *debug_slow_ring_trc;
48282 struct lpfc_debugfs_trc *slow_ring_trc;
48283 - atomic_t slow_ring_trc_cnt;
48284 + atomic_unchecked_t slow_ring_trc_cnt;
48285 /* iDiag debugfs sub-directory */
48286 struct dentry *idiag_root;
48287 struct dentry *idiag_pci_cfg;
48288 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48289 index 60084e6..0e2e700 100644
48290 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
48291 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48292 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48293
48294 #include <linux/debugfs.h>
48295
48296 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48297 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48298 static unsigned long lpfc_debugfs_start_time = 0L;
48299
48300 /* iDiag */
48301 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48302 lpfc_debugfs_enable = 0;
48303
48304 len = 0;
48305 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48306 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48307 (lpfc_debugfs_max_disc_trc - 1);
48308 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48309 dtp = vport->disc_trc + i;
48310 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48311 lpfc_debugfs_enable = 0;
48312
48313 len = 0;
48314 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48315 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48316 (lpfc_debugfs_max_slow_ring_trc - 1);
48317 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48318 dtp = phba->slow_ring_trc + i;
48319 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48320 !vport || !vport->disc_trc)
48321 return;
48322
48323 - index = atomic_inc_return(&vport->disc_trc_cnt) &
48324 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48325 (lpfc_debugfs_max_disc_trc - 1);
48326 dtp = vport->disc_trc + index;
48327 dtp->fmt = fmt;
48328 dtp->data1 = data1;
48329 dtp->data2 = data2;
48330 dtp->data3 = data3;
48331 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48332 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48333 dtp->jif = jiffies;
48334 #endif
48335 return;
48336 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48337 !phba || !phba->slow_ring_trc)
48338 return;
48339
48340 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
48341 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
48342 (lpfc_debugfs_max_slow_ring_trc - 1);
48343 dtp = phba->slow_ring_trc + index;
48344 dtp->fmt = fmt;
48345 dtp->data1 = data1;
48346 dtp->data2 = data2;
48347 dtp->data3 = data3;
48348 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48349 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48350 dtp->jif = jiffies;
48351 #endif
48352 return;
48353 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48354 "slow_ring buffer\n");
48355 goto debug_failed;
48356 }
48357 - atomic_set(&phba->slow_ring_trc_cnt, 0);
48358 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
48359 memset(phba->slow_ring_trc, 0,
48360 (sizeof(struct lpfc_debugfs_trc) *
48361 lpfc_debugfs_max_slow_ring_trc));
48362 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48363 "buffer\n");
48364 goto debug_failed;
48365 }
48366 - atomic_set(&vport->disc_trc_cnt, 0);
48367 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
48368
48369 snprintf(name, sizeof(name), "discovery_trace");
48370 vport->debug_disc_trc =
48371 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
48372 index 68c94cc..8c27be5 100644
48373 --- a/drivers/scsi/lpfc/lpfc_init.c
48374 +++ b/drivers/scsi/lpfc/lpfc_init.c
48375 @@ -10949,8 +10949,10 @@ lpfc_init(void)
48376 "misc_register returned with status %d", error);
48377
48378 if (lpfc_enable_npiv) {
48379 - lpfc_transport_functions.vport_create = lpfc_vport_create;
48380 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48381 + pax_open_kernel();
48382 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
48383 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48384 + pax_close_kernel();
48385 }
48386 lpfc_transport_template =
48387 fc_attach_transport(&lpfc_transport_functions);
48388 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
48389 index b2ede05..aaf482ca 100644
48390 --- a/drivers/scsi/lpfc/lpfc_scsi.c
48391 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
48392 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
48393 uint32_t evt_posted;
48394
48395 spin_lock_irqsave(&phba->hbalock, flags);
48396 - atomic_inc(&phba->num_rsrc_err);
48397 + atomic_inc_unchecked(&phba->num_rsrc_err);
48398 phba->last_rsrc_error_time = jiffies;
48399
48400 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
48401 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
48402 unsigned long flags;
48403 struct lpfc_hba *phba = vport->phba;
48404 uint32_t evt_posted;
48405 - atomic_inc(&phba->num_cmd_success);
48406 + atomic_inc_unchecked(&phba->num_cmd_success);
48407
48408 if (vport->cfg_lun_queue_depth <= queue_depth)
48409 return;
48410 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48411 unsigned long num_rsrc_err, num_cmd_success;
48412 int i;
48413
48414 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
48415 - num_cmd_success = atomic_read(&phba->num_cmd_success);
48416 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
48417 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
48418
48419 /*
48420 * The error and success command counters are global per
48421 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48422 }
48423 }
48424 lpfc_destroy_vport_work_array(phba, vports);
48425 - atomic_set(&phba->num_rsrc_err, 0);
48426 - atomic_set(&phba->num_cmd_success, 0);
48427 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
48428 + atomic_set_unchecked(&phba->num_cmd_success, 0);
48429 }
48430
48431 /**
48432 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
48433 }
48434 }
48435 lpfc_destroy_vport_work_array(phba, vports);
48436 - atomic_set(&phba->num_rsrc_err, 0);
48437 - atomic_set(&phba->num_cmd_success, 0);
48438 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
48439 + atomic_set_unchecked(&phba->num_cmd_success, 0);
48440 }
48441
48442 /**
48443 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48444 index 7f0af4f..193ac3e 100644
48445 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48446 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48447 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
48448 {
48449 struct scsi_device *sdev = to_scsi_device(dev);
48450 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48451 - static struct _raid_device *raid_device;
48452 + struct _raid_device *raid_device;
48453 unsigned long flags;
48454 Mpi2RaidVolPage0_t vol_pg0;
48455 Mpi2ConfigReply_t mpi_reply;
48456 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
48457 {
48458 struct scsi_device *sdev = to_scsi_device(dev);
48459 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48460 - static struct _raid_device *raid_device;
48461 + struct _raid_device *raid_device;
48462 unsigned long flags;
48463 Mpi2RaidVolPage0_t vol_pg0;
48464 Mpi2ConfigReply_t mpi_reply;
48465 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
48466 struct fw_event_work *fw_event)
48467 {
48468 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
48469 - static struct _raid_device *raid_device;
48470 + struct _raid_device *raid_device;
48471 unsigned long flags;
48472 u16 handle;
48473
48474 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
48475 u64 sas_address;
48476 struct _sas_device *sas_device;
48477 struct _sas_node *expander_device;
48478 - static struct _raid_device *raid_device;
48479 + struct _raid_device *raid_device;
48480 u8 retry_count;
48481 unsigned long flags;
48482
48483 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
48484 index be8ce54..94ed33a 100644
48485 --- a/drivers/scsi/pmcraid.c
48486 +++ b/drivers/scsi/pmcraid.c
48487 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
48488 res->scsi_dev = scsi_dev;
48489 scsi_dev->hostdata = res;
48490 res->change_detected = 0;
48491 - atomic_set(&res->read_failures, 0);
48492 - atomic_set(&res->write_failures, 0);
48493 + atomic_set_unchecked(&res->read_failures, 0);
48494 + atomic_set_unchecked(&res->write_failures, 0);
48495 rc = 0;
48496 }
48497 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
48498 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
48499
48500 /* If this was a SCSI read/write command keep count of errors */
48501 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
48502 - atomic_inc(&res->read_failures);
48503 + atomic_inc_unchecked(&res->read_failures);
48504 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
48505 - atomic_inc(&res->write_failures);
48506 + atomic_inc_unchecked(&res->write_failures);
48507
48508 if (!RES_IS_GSCSI(res->cfg_entry) &&
48509 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
48510 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
48511 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48512 * hrrq_id assigned here in queuecommand
48513 */
48514 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48515 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48516 pinstance->num_hrrq;
48517 cmd->cmd_done = pmcraid_io_done;
48518
48519 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
48520 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48521 * hrrq_id assigned here in queuecommand
48522 */
48523 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48524 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48525 pinstance->num_hrrq;
48526
48527 if (request_size) {
48528 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
48529
48530 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
48531 /* add resources only after host is added into system */
48532 - if (!atomic_read(&pinstance->expose_resources))
48533 + if (!atomic_read_unchecked(&pinstance->expose_resources))
48534 return;
48535
48536 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
48537 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
48538 init_waitqueue_head(&pinstance->reset_wait_q);
48539
48540 atomic_set(&pinstance->outstanding_cmds, 0);
48541 - atomic_set(&pinstance->last_message_id, 0);
48542 - atomic_set(&pinstance->expose_resources, 0);
48543 + atomic_set_unchecked(&pinstance->last_message_id, 0);
48544 + atomic_set_unchecked(&pinstance->expose_resources, 0);
48545
48546 INIT_LIST_HEAD(&pinstance->free_res_q);
48547 INIT_LIST_HEAD(&pinstance->used_res_q);
48548 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
48549 /* Schedule worker thread to handle CCN and take care of adding and
48550 * removing devices to OS
48551 */
48552 - atomic_set(&pinstance->expose_resources, 1);
48553 + atomic_set_unchecked(&pinstance->expose_resources, 1);
48554 schedule_work(&pinstance->worker_q);
48555 return rc;
48556
48557 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
48558 index e1d150f..6c6df44 100644
48559 --- a/drivers/scsi/pmcraid.h
48560 +++ b/drivers/scsi/pmcraid.h
48561 @@ -748,7 +748,7 @@ struct pmcraid_instance {
48562 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
48563
48564 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
48565 - atomic_t last_message_id;
48566 + atomic_unchecked_t last_message_id;
48567
48568 /* configuration table */
48569 struct pmcraid_config_table *cfg_table;
48570 @@ -777,7 +777,7 @@ struct pmcraid_instance {
48571 atomic_t outstanding_cmds;
48572
48573 /* should add/delete resources to mid-layer now ?*/
48574 - atomic_t expose_resources;
48575 + atomic_unchecked_t expose_resources;
48576
48577
48578
48579 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
48580 struct pmcraid_config_table_entry_ext cfg_entry_ext;
48581 };
48582 struct scsi_device *scsi_dev; /* Link scsi_device structure */
48583 - atomic_t read_failures; /* count of failed READ commands */
48584 - atomic_t write_failures; /* count of failed WRITE commands */
48585 + atomic_unchecked_t read_failures; /* count of failed READ commands */
48586 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
48587
48588 /* To indicate add/delete/modify during CCN */
48589 u8 change_detected;
48590 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
48591 index 5f174b8..98d32b0 100644
48592 --- a/drivers/scsi/qla2xxx/qla_attr.c
48593 +++ b/drivers/scsi/qla2xxx/qla_attr.c
48594 @@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
48595 return 0;
48596 }
48597
48598 -struct fc_function_template qla2xxx_transport_functions = {
48599 +fc_function_template_no_const qla2xxx_transport_functions = {
48600
48601 .show_host_node_name = 1,
48602 .show_host_port_name = 1,
48603 @@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
48604 .bsg_timeout = qla24xx_bsg_timeout,
48605 };
48606
48607 -struct fc_function_template qla2xxx_transport_vport_functions = {
48608 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
48609
48610 .show_host_node_name = 1,
48611 .show_host_port_name = 1,
48612 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
48613 index 4446bf5..9a3574d 100644
48614 --- a/drivers/scsi/qla2xxx/qla_gbl.h
48615 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
48616 @@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
48617 struct device_attribute;
48618 extern struct device_attribute *qla2x00_host_attrs[];
48619 struct fc_function_template;
48620 -extern struct fc_function_template qla2xxx_transport_functions;
48621 -extern struct fc_function_template qla2xxx_transport_vport_functions;
48622 +extern fc_function_template_no_const qla2xxx_transport_functions;
48623 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
48624 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
48625 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
48626 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
48627 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
48628 index 52be35e..b933907 100644
48629 --- a/drivers/scsi/qla2xxx/qla_os.c
48630 +++ b/drivers/scsi/qla2xxx/qla_os.c
48631 @@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
48632 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
48633 /* Ok, a 64bit DMA mask is applicable. */
48634 ha->flags.enable_64bit_addressing = 1;
48635 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48636 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48637 + pax_open_kernel();
48638 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48639 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48640 + pax_close_kernel();
48641 return;
48642 }
48643 }
48644 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
48645 index 084d1fd..9f939eb 100644
48646 --- a/drivers/scsi/qla4xxx/ql4_def.h
48647 +++ b/drivers/scsi/qla4xxx/ql4_def.h
48648 @@ -296,7 +296,7 @@ struct ddb_entry {
48649 * (4000 only) */
48650 atomic_t relogin_timer; /* Max Time to wait for
48651 * relogin to complete */
48652 - atomic_t relogin_retry_count; /* Num of times relogin has been
48653 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
48654 * retried */
48655 uint32_t default_time2wait; /* Default Min time between
48656 * relogins (+aens) */
48657 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
48658 index cf174a4..128a420 100644
48659 --- a/drivers/scsi/qla4xxx/ql4_os.c
48660 +++ b/drivers/scsi/qla4xxx/ql4_os.c
48661 @@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
48662 */
48663 if (!iscsi_is_session_online(cls_sess)) {
48664 /* Reset retry relogin timer */
48665 - atomic_inc(&ddb_entry->relogin_retry_count);
48666 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
48667 DEBUG2(ql4_printk(KERN_INFO, ha,
48668 "%s: index[%d] relogin timed out-retrying"
48669 " relogin (%d), retry (%d)\n", __func__,
48670 ddb_entry->fw_ddb_index,
48671 - atomic_read(&ddb_entry->relogin_retry_count),
48672 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
48673 ddb_entry->default_time2wait + 4));
48674 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
48675 atomic_set(&ddb_entry->retry_relogin_timer,
48676 @@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
48677
48678 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
48679 atomic_set(&ddb_entry->relogin_timer, 0);
48680 - atomic_set(&ddb_entry->relogin_retry_count, 0);
48681 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
48682 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
48683 ddb_entry->default_relogin_timeout =
48684 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
48685 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
48686 index fe0bcb1..c9255be 100644
48687 --- a/drivers/scsi/scsi.c
48688 +++ b/drivers/scsi/scsi.c
48689 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
48690 struct Scsi_Host *host = cmd->device->host;
48691 int rtn = 0;
48692
48693 - atomic_inc(&cmd->device->iorequest_cnt);
48694 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48695
48696 /* check if the device is still usable */
48697 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
48698 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
48699 index 7bd7f0d..44147bf 100644
48700 --- a/drivers/scsi/scsi_lib.c
48701 +++ b/drivers/scsi/scsi_lib.c
48702 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
48703 shost = sdev->host;
48704 scsi_init_cmd_errh(cmd);
48705 cmd->result = DID_NO_CONNECT << 16;
48706 - atomic_inc(&cmd->device->iorequest_cnt);
48707 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48708
48709 /*
48710 * SCSI request completion path will do scsi_device_unbusy(),
48711 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
48712
48713 INIT_LIST_HEAD(&cmd->eh_entry);
48714
48715 - atomic_inc(&cmd->device->iodone_cnt);
48716 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
48717 if (cmd->result)
48718 - atomic_inc(&cmd->device->ioerr_cnt);
48719 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
48720
48721 disposition = scsi_decide_disposition(cmd);
48722 if (disposition != SUCCESS &&
48723 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
48724 index 8ff62c2..693b6f7 100644
48725 --- a/drivers/scsi/scsi_sysfs.c
48726 +++ b/drivers/scsi/scsi_sysfs.c
48727 @@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
48728 char *buf) \
48729 { \
48730 struct scsi_device *sdev = to_scsi_device(dev); \
48731 - unsigned long long count = atomic_read(&sdev->field); \
48732 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
48733 return snprintf(buf, 20, "0x%llx\n", count); \
48734 } \
48735 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
48736 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
48737 index 84a1fdf..693b0d6 100644
48738 --- a/drivers/scsi/scsi_tgt_lib.c
48739 +++ b/drivers/scsi/scsi_tgt_lib.c
48740 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
48741 int err;
48742
48743 dprintk("%lx %u\n", uaddr, len);
48744 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
48745 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
48746 if (err) {
48747 /*
48748 * TODO: need to fixup sg_tablesize, max_segment_size,
48749 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
48750 index 4628fd5..a94a1c2 100644
48751 --- a/drivers/scsi/scsi_transport_fc.c
48752 +++ b/drivers/scsi/scsi_transport_fc.c
48753 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
48754 * Netlink Infrastructure
48755 */
48756
48757 -static atomic_t fc_event_seq;
48758 +static atomic_unchecked_t fc_event_seq;
48759
48760 /**
48761 * fc_get_event_number - Obtain the next sequential FC event number
48762 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
48763 u32
48764 fc_get_event_number(void)
48765 {
48766 - return atomic_add_return(1, &fc_event_seq);
48767 + return atomic_add_return_unchecked(1, &fc_event_seq);
48768 }
48769 EXPORT_SYMBOL(fc_get_event_number);
48770
48771 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
48772 {
48773 int error;
48774
48775 - atomic_set(&fc_event_seq, 0);
48776 + atomic_set_unchecked(&fc_event_seq, 0);
48777
48778 error = transport_class_register(&fc_host_class);
48779 if (error)
48780 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
48781 char *cp;
48782
48783 *val = simple_strtoul(buf, &cp, 0);
48784 - if ((*cp && (*cp != '\n')) || (*val < 0))
48785 + if (*cp && (*cp != '\n'))
48786 return -EINVAL;
48787 /*
48788 * Check for overflow; dev_loss_tmo is u32
48789 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
48790 index 63a6ca4..5d5cadd 100644
48791 --- a/drivers/scsi/scsi_transport_iscsi.c
48792 +++ b/drivers/scsi/scsi_transport_iscsi.c
48793 @@ -79,7 +79,7 @@ struct iscsi_internal {
48794 struct transport_container session_cont;
48795 };
48796
48797 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
48798 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
48799 static struct workqueue_struct *iscsi_eh_timer_workq;
48800
48801 static DEFINE_IDA(iscsi_sess_ida);
48802 @@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
48803 int err;
48804
48805 ihost = shost->shost_data;
48806 - session->sid = atomic_add_return(1, &iscsi_session_nr);
48807 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
48808
48809 if (target_id == ISCSI_MAX_TARGET) {
48810 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
48811 @@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
48812 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
48813 ISCSI_TRANSPORT_VERSION);
48814
48815 - atomic_set(&iscsi_session_nr, 0);
48816 + atomic_set_unchecked(&iscsi_session_nr, 0);
48817
48818 err = class_register(&iscsi_transport_class);
48819 if (err)
48820 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
48821 index 2700a5a..752ec38 100644
48822 --- a/drivers/scsi/scsi_transport_srp.c
48823 +++ b/drivers/scsi/scsi_transport_srp.c
48824 @@ -36,7 +36,7 @@
48825 #include "scsi_transport_srp_internal.h"
48826
48827 struct srp_host_attrs {
48828 - atomic_t next_port_id;
48829 + atomic_unchecked_t next_port_id;
48830 };
48831 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
48832
48833 @@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
48834 struct Scsi_Host *shost = dev_to_shost(dev);
48835 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
48836
48837 - atomic_set(&srp_host->next_port_id, 0);
48838 + atomic_set_unchecked(&srp_host->next_port_id, 0);
48839 return 0;
48840 }
48841
48842 @@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
48843 rport_fast_io_fail_timedout);
48844 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
48845
48846 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
48847 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
48848 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
48849
48850 transport_setup_device(&rport->dev);
48851 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
48852 index 69725f7..03aaee1 100644
48853 --- a/drivers/scsi/sd.c
48854 +++ b/drivers/scsi/sd.c
48855 @@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
48856 sdkp->disk = gd;
48857 sdkp->index = index;
48858 atomic_set(&sdkp->openers, 0);
48859 - atomic_set(&sdkp->device->ioerr_cnt, 0);
48860 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
48861
48862 if (!sdp->request_queue->rq_timeout) {
48863 if (sdp->type != TYPE_MOD)
48864 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
48865 index df5e961..df6b97f 100644
48866 --- a/drivers/scsi/sg.c
48867 +++ b/drivers/scsi/sg.c
48868 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
48869 sdp->disk->disk_name,
48870 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
48871 NULL,
48872 - (char *)arg);
48873 + (char __user *)arg);
48874 case BLKTRACESTART:
48875 return blk_trace_startstop(sdp->device->request_queue, 1);
48876 case BLKTRACESTOP:
48877 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
48878 index 349ebba..ff2a249 100644
48879 --- a/drivers/spi/spi.c
48880 +++ b/drivers/spi/spi.c
48881 @@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
48882 EXPORT_SYMBOL_GPL(spi_bus_unlock);
48883
48884 /* portable code must never pass more than 32 bytes */
48885 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
48886 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
48887
48888 static u8 *buf;
48889
48890 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
48891 index 2c61783..4d49e4e 100644
48892 --- a/drivers/staging/android/timed_output.c
48893 +++ b/drivers/staging/android/timed_output.c
48894 @@ -25,7 +25,7 @@
48895 #include "timed_output.h"
48896
48897 static struct class *timed_output_class;
48898 -static atomic_t device_count;
48899 +static atomic_unchecked_t device_count;
48900
48901 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
48902 char *buf)
48903 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
48904 timed_output_class = class_create(THIS_MODULE, "timed_output");
48905 if (IS_ERR(timed_output_class))
48906 return PTR_ERR(timed_output_class);
48907 - atomic_set(&device_count, 0);
48908 + atomic_set_unchecked(&device_count, 0);
48909 timed_output_class->dev_groups = timed_output_groups;
48910 }
48911
48912 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
48913 if (ret < 0)
48914 return ret;
48915
48916 - tdev->index = atomic_inc_return(&device_count);
48917 + tdev->index = atomic_inc_return_unchecked(&device_count);
48918 tdev->dev = device_create(timed_output_class, NULL,
48919 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
48920 if (IS_ERR(tdev->dev))
48921 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
48922 index c0f7cd7..5424212 100644
48923 --- a/drivers/staging/gdm724x/gdm_tty.c
48924 +++ b/drivers/staging/gdm724x/gdm_tty.c
48925 @@ -45,7 +45,7 @@
48926 #define gdm_tty_send_control(n, r, v, d, l) (\
48927 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
48928
48929 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
48930 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
48931
48932 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
48933 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
48934 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
48935 index b7613c8..c302392 100644
48936 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
48937 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
48938 @@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
48939 return 0;
48940 }
48941
48942 -sfw_test_client_ops_t brw_test_client;
48943 -void brw_init_test_client(void)
48944 -{
48945 - brw_test_client.tso_init = brw_client_init;
48946 - brw_test_client.tso_fini = brw_client_fini;
48947 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
48948 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
48949 +sfw_test_client_ops_t brw_test_client = {
48950 + .tso_init = brw_client_init,
48951 + .tso_fini = brw_client_fini,
48952 + .tso_prep_rpc = brw_client_prep_rpc,
48953 + .tso_done_rpc = brw_client_done_rpc,
48954 };
48955
48956 srpc_service_t brw_test_service;
48957 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
48958 index 483c785..e1a2a7b 100644
48959 --- a/drivers/staging/lustre/lnet/selftest/framework.c
48960 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
48961 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
48962
48963 extern sfw_test_client_ops_t ping_test_client;
48964 extern srpc_service_t ping_test_service;
48965 -extern void ping_init_test_client(void);
48966 extern void ping_init_test_service(void);
48967
48968 extern sfw_test_client_ops_t brw_test_client;
48969 extern srpc_service_t brw_test_service;
48970 -extern void brw_init_test_client(void);
48971 extern void brw_init_test_service(void);
48972
48973
48974 @@ -1684,12 +1682,10 @@ sfw_startup (void)
48975 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
48976 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
48977
48978 - brw_init_test_client();
48979 brw_init_test_service();
48980 rc = sfw_register_test(&brw_test_service, &brw_test_client);
48981 LASSERT (rc == 0);
48982
48983 - ping_init_test_client();
48984 ping_init_test_service();
48985 rc = sfw_register_test(&ping_test_service, &ping_test_client);
48986 LASSERT (rc == 0);
48987 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
48988 index f0f9194..b589047 100644
48989 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
48990 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
48991 @@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
48992 return 0;
48993 }
48994
48995 -sfw_test_client_ops_t ping_test_client;
48996 -void ping_init_test_client(void)
48997 -{
48998 - ping_test_client.tso_init = ping_client_init;
48999 - ping_test_client.tso_fini = ping_client_fini;
49000 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49001 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49002 -}
49003 +sfw_test_client_ops_t ping_test_client = {
49004 + .tso_init = ping_client_init,
49005 + .tso_fini = ping_client_fini,
49006 + .tso_prep_rpc = ping_client_prep_rpc,
49007 + .tso_done_rpc = ping_client_done_rpc,
49008 +};
49009
49010 srpc_service_t ping_test_service;
49011 void ping_init_test_service(void)
49012 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49013 index bc2b82f..67fd598 100644
49014 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49015 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49016 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49017 ldlm_completion_callback lcs_completion;
49018 ldlm_blocking_callback lcs_blocking;
49019 ldlm_glimpse_callback lcs_glimpse;
49020 -};
49021 +} __no_const;
49022
49023 /* ldlm_lockd.c */
49024 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49025 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49026 index d0aea15..7af68e1 100644
49027 --- a/drivers/staging/lustre/lustre/include/obd.h
49028 +++ b/drivers/staging/lustre/lustre/include/obd.h
49029 @@ -1417,7 +1417,7 @@ struct md_ops {
49030 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49031 * wrapper function in include/linux/obd_class.h.
49032 */
49033 -};
49034 +} __no_const;
49035
49036 struct lsm_operations {
49037 void (*lsm_free)(struct lov_stripe_md *);
49038 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49039 index 39fcdac..222780f 100644
49040 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49041 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49042 @@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49043 int added = (mode == LCK_NL);
49044 int overlaps = 0;
49045 int splitted = 0;
49046 - const struct ldlm_callback_suite null_cbs = { NULL };
49047 + const struct ldlm_callback_suite null_cbs = { };
49048 int rc;
49049
49050 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49051 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49052 index fc6c977..df1f956 100644
49053 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49054 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49055 @@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49056 int LL_PROC_PROTO(proc_console_max_delay_cs)
49057 {
49058 int rc, max_delay_cs;
49059 - ctl_table_t dummy = *table;
49060 + ctl_table_no_const dummy = *table;
49061 cfs_duration_t d;
49062
49063 dummy.data = &max_delay_cs;
49064 @@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49065 int LL_PROC_PROTO(proc_console_min_delay_cs)
49066 {
49067 int rc, min_delay_cs;
49068 - ctl_table_t dummy = *table;
49069 + ctl_table_no_const dummy = *table;
49070 cfs_duration_t d;
49071
49072 dummy.data = &min_delay_cs;
49073 @@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49074 int LL_PROC_PROTO(proc_console_backoff)
49075 {
49076 int rc, backoff;
49077 - ctl_table_t dummy = *table;
49078 + ctl_table_no_const dummy = *table;
49079
49080 dummy.data = &backoff;
49081 dummy.proc_handler = &proc_dointvec;
49082 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49083 index f3108c7..cd4f9da 100644
49084 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49085 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49086 @@ -348,11 +348,11 @@ out:
49087
49088
49089 struct cfs_psdev_ops libcfs_psdev_ops = {
49090 - libcfs_psdev_open,
49091 - libcfs_psdev_release,
49092 - NULL,
49093 - NULL,
49094 - libcfs_ioctl
49095 + .p_open = libcfs_psdev_open,
49096 + .p_close = libcfs_psdev_release,
49097 + .p_read = NULL,
49098 + .p_write = NULL,
49099 + .p_ioctl = libcfs_ioctl
49100 };
49101
49102 extern int insert_proc(void);
49103 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49104 index 3675020..e80d92c 100644
49105 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49106 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49107 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49108
49109 static int solo_sysfs_init(struct solo_dev *solo_dev)
49110 {
49111 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49112 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49113 struct device *dev = &solo_dev->dev;
49114 const char *driver;
49115 int i;
49116 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49117 index 1db18c7..35e6afc 100644
49118 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49119 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49120 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49121
49122 int solo_g723_init(struct solo_dev *solo_dev)
49123 {
49124 - static struct snd_device_ops ops = { NULL };
49125 + static struct snd_device_ops ops = { };
49126 struct snd_card *card;
49127 struct snd_kcontrol_new kctl;
49128 char name[32];
49129 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49130 index 7f2f247..d999137 100644
49131 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49132 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49133 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49134
49135 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49136 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49137 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49138 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49139 if (p2m_id < 0)
49140 p2m_id = -p2m_id;
49141 }
49142 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49143 index f1bbb8c..a73eaba 100644
49144 --- a/drivers/staging/media/solo6x10/solo6x10.h
49145 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49146 @@ -237,7 +237,7 @@ struct solo_dev {
49147
49148 /* P2M DMA Engine */
49149 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49150 - atomic_t p2m_count;
49151 + atomic_unchecked_t p2m_count;
49152 int p2m_jiffies;
49153 unsigned int p2m_timeouts;
49154
49155 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49156 index 0315f60..2ecae10 100644
49157 --- a/drivers/staging/octeon/ethernet-rx.c
49158 +++ b/drivers/staging/octeon/ethernet-rx.c
49159 @@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49160 /* Increment RX stats for virtual ports */
49161 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49162 #ifdef CONFIG_64BIT
49163 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49164 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49165 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49166 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49167 #else
49168 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49169 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49170 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49171 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49172 #endif
49173 }
49174 netif_receive_skb(skb);
49175 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49176 dev->name);
49177 */
49178 #ifdef CONFIG_64BIT
49179 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49180 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49181 #else
49182 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49183 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49184 #endif
49185 dev_kfree_skb_irq(skb);
49186 }
49187 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49188 index bd6ca71..8f0961e 100644
49189 --- a/drivers/staging/octeon/ethernet.c
49190 +++ b/drivers/staging/octeon/ethernet.c
49191 @@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49192 * since the RX tasklet also increments it.
49193 */
49194 #ifdef CONFIG_64BIT
49195 - atomic64_add(rx_status.dropped_packets,
49196 - (atomic64_t *)&priv->stats.rx_dropped);
49197 + atomic64_add_unchecked(rx_status.dropped_packets,
49198 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49199 #else
49200 - atomic_add(rx_status.dropped_packets,
49201 - (atomic_t *)&priv->stats.rx_dropped);
49202 + atomic_add_unchecked(rx_status.dropped_packets,
49203 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
49204 #endif
49205 }
49206
49207 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49208 index 439c3c9..2d74293 100644
49209 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
49210 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49211 @@ -271,7 +271,7 @@ struct hal_ops {
49212 s32 (*c2h_handler)(struct adapter *padapter,
49213 struct c2h_evt_hdr *c2h_evt);
49214 c2h_id_filter c2h_id_filter_ccx;
49215 -};
49216 +} __no_const;
49217
49218 enum rt_eeprom_type {
49219 EEPROM_93C46,
49220 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49221 index eb6f0e5..e6a0958 100644
49222 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
49223 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49224 @@ -126,7 +126,7 @@ struct _io_ops {
49225 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49226 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49227 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49228 -};
49229 +} __no_const;
49230
49231 struct io_req {
49232 struct list_head list;
49233 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49234 index dc23395..cf7e9b1 100644
49235 --- a/drivers/staging/rtl8712/rtl871x_io.h
49236 +++ b/drivers/staging/rtl8712/rtl871x_io.h
49237 @@ -108,7 +108,7 @@ struct _io_ops {
49238 u8 *pmem);
49239 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49240 u8 *pmem);
49241 -};
49242 +} __no_const;
49243
49244 struct io_req {
49245 struct list_head list;
49246 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49247 index 1f5088b..0e59820 100644
49248 --- a/drivers/staging/sbe-2t3e3/netdev.c
49249 +++ b/drivers/staging/sbe-2t3e3/netdev.c
49250 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49251 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49252
49253 if (rlen)
49254 - if (copy_to_user(data, &resp, rlen))
49255 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49256 return -EFAULT;
49257
49258 return 0;
49259 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49260 index a863a98..d272795 100644
49261 --- a/drivers/staging/usbip/vhci.h
49262 +++ b/drivers/staging/usbip/vhci.h
49263 @@ -83,7 +83,7 @@ struct vhci_hcd {
49264 unsigned resuming:1;
49265 unsigned long re_timeout;
49266
49267 - atomic_t seqnum;
49268 + atomic_unchecked_t seqnum;
49269
49270 /*
49271 * NOTE:
49272 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49273 index e810ad5..931336f 100644
49274 --- a/drivers/staging/usbip/vhci_hcd.c
49275 +++ b/drivers/staging/usbip/vhci_hcd.c
49276 @@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49277
49278 spin_lock(&vdev->priv_lock);
49279
49280 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49281 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49282 if (priv->seqnum == 0xffff)
49283 dev_info(&urb->dev->dev, "seqnum max\n");
49284
49285 @@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49286 return -ENOMEM;
49287 }
49288
49289 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49290 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49291 if (unlink->seqnum == 0xffff)
49292 pr_info("seqnum max\n");
49293
49294 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
49295 vdev->rhport = rhport;
49296 }
49297
49298 - atomic_set(&vhci->seqnum, 0);
49299 + atomic_set_unchecked(&vhci->seqnum, 0);
49300 spin_lock_init(&vhci->lock);
49301
49302 hcd->power_budget = 0; /* no limit */
49303 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
49304 index d07fcb5..358e1e1 100644
49305 --- a/drivers/staging/usbip/vhci_rx.c
49306 +++ b/drivers/staging/usbip/vhci_rx.c
49307 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
49308 if (!urb) {
49309 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
49310 pr_info("max seqnum %d\n",
49311 - atomic_read(&the_controller->seqnum));
49312 + atomic_read_unchecked(&the_controller->seqnum));
49313 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
49314 return;
49315 }
49316 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
49317 index ab8b2ba..99184aa 100644
49318 --- a/drivers/staging/vt6655/hostap.c
49319 +++ b/drivers/staging/vt6655/hostap.c
49320 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
49321 *
49322 */
49323
49324 +static net_device_ops_no_const apdev_netdev_ops;
49325 +
49326 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49327 {
49328 PSDevice apdev_priv;
49329 struct net_device *dev = pDevice->dev;
49330 int ret;
49331 - const struct net_device_ops apdev_netdev_ops = {
49332 - .ndo_start_xmit = pDevice->tx_80211,
49333 - };
49334
49335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49336
49337 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49338 *apdev_priv = *pDevice;
49339 eth_hw_addr_inherit(pDevice->apdev, dev);
49340
49341 + /* only half broken now */
49342 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49343 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49344
49345 pDevice->apdev->type = ARPHRD_IEEE80211;
49346 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
49347 index 67ba48b..24e602f 100644
49348 --- a/drivers/staging/vt6656/hostap.c
49349 +++ b/drivers/staging/vt6656/hostap.c
49350 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
49351 *
49352 */
49353
49354 +static net_device_ops_no_const apdev_netdev_ops;
49355 +
49356 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49357 {
49358 struct vnt_private *apdev_priv;
49359 struct net_device *dev = pDevice->dev;
49360 int ret;
49361 - const struct net_device_ops apdev_netdev_ops = {
49362 - .ndo_start_xmit = pDevice->tx_80211,
49363 - };
49364
49365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49366
49367 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49368 *apdev_priv = *pDevice;
49369 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
49370
49371 + /* only half broken now */
49372 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49373 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49374
49375 pDevice->apdev->type = ARPHRD_IEEE80211;
49376 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
49377 index 24884ca..26c8220 100644
49378 --- a/drivers/target/sbp/sbp_target.c
49379 +++ b/drivers/target/sbp/sbp_target.c
49380 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
49381
49382 #define SESSION_MAINTENANCE_INTERVAL HZ
49383
49384 -static atomic_t login_id = ATOMIC_INIT(0);
49385 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
49386
49387 static void session_maintenance_work(struct work_struct *);
49388 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
49389 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
49390 login->lun = se_lun;
49391 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
49392 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
49393 - login->login_id = atomic_inc_return(&login_id);
49394 + login->login_id = atomic_inc_return_unchecked(&login_id);
49395
49396 login->tgt_agt = sbp_target_agent_register(login);
49397 if (IS_ERR(login->tgt_agt)) {
49398 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
49399 index d06de84..fd38c9b 100644
49400 --- a/drivers/target/target_core_device.c
49401 +++ b/drivers/target/target_core_device.c
49402 @@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
49403 spin_lock_init(&dev->se_tmr_lock);
49404 spin_lock_init(&dev->qf_cmd_lock);
49405 sema_init(&dev->caw_sem, 1);
49406 - atomic_set(&dev->dev_ordered_id, 0);
49407 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
49408 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
49409 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
49410 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
49411 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
49412 index 91953da..a842b90 100644
49413 --- a/drivers/target/target_core_transport.c
49414 +++ b/drivers/target/target_core_transport.c
49415 @@ -1112,7 +1112,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
49416 * Used to determine when ORDERED commands should go from
49417 * Dormant to Active status.
49418 */
49419 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
49420 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
49421 smp_mb__after_atomic_inc();
49422 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
49423 cmd->se_ordered_id, cmd->sam_task_attr,
49424 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
49425 index 33f83fe..d80f8e1 100644
49426 --- a/drivers/tty/cyclades.c
49427 +++ b/drivers/tty/cyclades.c
49428 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
49429 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
49430 info->port.count);
49431 #endif
49432 - info->port.count++;
49433 + atomic_inc(&info->port.count);
49434 #ifdef CY_DEBUG_COUNT
49435 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
49436 - current->pid, info->port.count);
49437 + current->pid, atomic_read(&info->port.count));
49438 #endif
49439
49440 /*
49441 @@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
49442 for (j = 0; j < cy_card[i].nports; j++) {
49443 info = &cy_card[i].ports[j];
49444
49445 - if (info->port.count) {
49446 + if (atomic_read(&info->port.count)) {
49447 /* XXX is the ldisc num worth this? */
49448 struct tty_struct *tty;
49449 struct tty_ldisc *ld;
49450 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
49451 index 9eba119..5070303 100644
49452 --- a/drivers/tty/hvc/hvc_console.c
49453 +++ b/drivers/tty/hvc/hvc_console.c
49454 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
49455
49456 spin_lock_irqsave(&hp->port.lock, flags);
49457 /* Check and then increment for fast path open. */
49458 - if (hp->port.count++ > 0) {
49459 + if (atomic_inc_return(&hp->port.count) > 1) {
49460 spin_unlock_irqrestore(&hp->port.lock, flags);
49461 hvc_kick();
49462 return 0;
49463 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49464
49465 spin_lock_irqsave(&hp->port.lock, flags);
49466
49467 - if (--hp->port.count == 0) {
49468 + if (atomic_dec_return(&hp->port.count) == 0) {
49469 spin_unlock_irqrestore(&hp->port.lock, flags);
49470 /* We are done with the tty pointer now. */
49471 tty_port_tty_set(&hp->port, NULL);
49472 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49473 */
49474 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
49475 } else {
49476 - if (hp->port.count < 0)
49477 + if (atomic_read(&hp->port.count) < 0)
49478 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
49479 - hp->vtermno, hp->port.count);
49480 + hp->vtermno, atomic_read(&hp->port.count));
49481 spin_unlock_irqrestore(&hp->port.lock, flags);
49482 }
49483 }
49484 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
49485 * open->hangup case this can be called after the final close so prevent
49486 * that from happening for now.
49487 */
49488 - if (hp->port.count <= 0) {
49489 + if (atomic_read(&hp->port.count) <= 0) {
49490 spin_unlock_irqrestore(&hp->port.lock, flags);
49491 return;
49492 }
49493
49494 - hp->port.count = 0;
49495 + atomic_set(&hp->port.count, 0);
49496 spin_unlock_irqrestore(&hp->port.lock, flags);
49497 tty_port_tty_set(&hp->port, NULL);
49498
49499 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
49500 return -EPIPE;
49501
49502 /* FIXME what's this (unprotected) check for? */
49503 - if (hp->port.count <= 0)
49504 + if (atomic_read(&hp->port.count) <= 0)
49505 return -EIO;
49506
49507 spin_lock_irqsave(&hp->lock, flags);
49508 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
49509 index 81e939e..95ead10 100644
49510 --- a/drivers/tty/hvc/hvcs.c
49511 +++ b/drivers/tty/hvc/hvcs.c
49512 @@ -83,6 +83,7 @@
49513 #include <asm/hvcserver.h>
49514 #include <asm/uaccess.h>
49515 #include <asm/vio.h>
49516 +#include <asm/local.h>
49517
49518 /*
49519 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
49520 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
49521
49522 spin_lock_irqsave(&hvcsd->lock, flags);
49523
49524 - if (hvcsd->port.count > 0) {
49525 + if (atomic_read(&hvcsd->port.count) > 0) {
49526 spin_unlock_irqrestore(&hvcsd->lock, flags);
49527 printk(KERN_INFO "HVCS: vterm state unchanged. "
49528 "The hvcs device node is still in use.\n");
49529 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
49530 }
49531 }
49532
49533 - hvcsd->port.count = 0;
49534 + atomic_set(&hvcsd->port.count, 0);
49535 hvcsd->port.tty = tty;
49536 tty->driver_data = hvcsd;
49537
49538 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
49539 unsigned long flags;
49540
49541 spin_lock_irqsave(&hvcsd->lock, flags);
49542 - hvcsd->port.count++;
49543 + atomic_inc(&hvcsd->port.count);
49544 hvcsd->todo_mask |= HVCS_SCHED_READ;
49545 spin_unlock_irqrestore(&hvcsd->lock, flags);
49546
49547 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49548 hvcsd = tty->driver_data;
49549
49550 spin_lock_irqsave(&hvcsd->lock, flags);
49551 - if (--hvcsd->port.count == 0) {
49552 + if (atomic_dec_and_test(&hvcsd->port.count)) {
49553
49554 vio_disable_interrupts(hvcsd->vdev);
49555
49556 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49557
49558 free_irq(irq, hvcsd);
49559 return;
49560 - } else if (hvcsd->port.count < 0) {
49561 + } else if (atomic_read(&hvcsd->port.count) < 0) {
49562 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
49563 " is missmanaged.\n",
49564 - hvcsd->vdev->unit_address, hvcsd->port.count);
49565 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
49566 }
49567
49568 spin_unlock_irqrestore(&hvcsd->lock, flags);
49569 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49570
49571 spin_lock_irqsave(&hvcsd->lock, flags);
49572 /* Preserve this so that we know how many kref refs to put */
49573 - temp_open_count = hvcsd->port.count;
49574 + temp_open_count = atomic_read(&hvcsd->port.count);
49575
49576 /*
49577 * Don't kref put inside the spinlock because the destruction
49578 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49579 tty->driver_data = NULL;
49580 hvcsd->port.tty = NULL;
49581
49582 - hvcsd->port.count = 0;
49583 + atomic_set(&hvcsd->port.count, 0);
49584
49585 /* This will drop any buffered data on the floor which is OK in a hangup
49586 * scenario. */
49587 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
49588 * the middle of a write operation? This is a crummy place to do this
49589 * but we want to keep it all in the spinlock.
49590 */
49591 - if (hvcsd->port.count <= 0) {
49592 + if (atomic_read(&hvcsd->port.count) <= 0) {
49593 spin_unlock_irqrestore(&hvcsd->lock, flags);
49594 return -ENODEV;
49595 }
49596 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
49597 {
49598 struct hvcs_struct *hvcsd = tty->driver_data;
49599
49600 - if (!hvcsd || hvcsd->port.count <= 0)
49601 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
49602 return 0;
49603
49604 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
49605 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
49606 index 4190199..48f2920 100644
49607 --- a/drivers/tty/hvc/hvsi.c
49608 +++ b/drivers/tty/hvc/hvsi.c
49609 @@ -85,7 +85,7 @@ struct hvsi_struct {
49610 int n_outbuf;
49611 uint32_t vtermno;
49612 uint32_t virq;
49613 - atomic_t seqno; /* HVSI packet sequence number */
49614 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
49615 uint16_t mctrl;
49616 uint8_t state; /* HVSI protocol state */
49617 uint8_t flags;
49618 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
49619
49620 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
49621 packet.hdr.len = sizeof(struct hvsi_query_response);
49622 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49623 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49624 packet.verb = VSV_SEND_VERSION_NUMBER;
49625 packet.u.version = HVSI_VERSION;
49626 packet.query_seqno = query_seqno+1;
49627 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
49628
49629 packet.hdr.type = VS_QUERY_PACKET_HEADER;
49630 packet.hdr.len = sizeof(struct hvsi_query);
49631 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49632 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49633 packet.verb = verb;
49634
49635 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
49636 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
49637 int wrote;
49638
49639 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
49640 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49641 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49642 packet.hdr.len = sizeof(struct hvsi_control);
49643 packet.verb = VSV_SET_MODEM_CTL;
49644 packet.mask = HVSI_TSDTR;
49645 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
49646 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
49647
49648 packet.hdr.type = VS_DATA_PACKET_HEADER;
49649 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49650 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49651 packet.hdr.len = count + sizeof(struct hvsi_header);
49652 memcpy(&packet.data, buf, count);
49653
49654 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
49655 struct hvsi_control packet __ALIGNED__;
49656
49657 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
49658 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49659 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49660 packet.hdr.len = 6;
49661 packet.verb = VSV_CLOSE_PROTOCOL;
49662
49663 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
49664 index 347050e..14f8fbf 100644
49665 --- a/drivers/tty/hvc/hvsi_lib.c
49666 +++ b/drivers/tty/hvc/hvsi_lib.c
49667 @@ -9,7 +9,7 @@
49668
49669 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
49670 {
49671 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
49672 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
49673
49674 /* Assumes that always succeeds, works in practice */
49675 return pv->put_chars(pv->termno, (char *)packet, packet->len);
49676 @@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
49677
49678 /* Reset state */
49679 pv->established = 0;
49680 - atomic_set(&pv->seqno, 0);
49681 + atomic_set_unchecked(&pv->seqno, 0);
49682
49683 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
49684
49685 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
49686 index 8fd72ff..34a0bed 100644
49687 --- a/drivers/tty/ipwireless/tty.c
49688 +++ b/drivers/tty/ipwireless/tty.c
49689 @@ -29,6 +29,7 @@
49690 #include <linux/tty_driver.h>
49691 #include <linux/tty_flip.h>
49692 #include <linux/uaccess.h>
49693 +#include <asm/local.h>
49694
49695 #include "tty.h"
49696 #include "network.h"
49697 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49698 mutex_unlock(&tty->ipw_tty_mutex);
49699 return -ENODEV;
49700 }
49701 - if (tty->port.count == 0)
49702 + if (atomic_read(&tty->port.count) == 0)
49703 tty->tx_bytes_queued = 0;
49704
49705 - tty->port.count++;
49706 + atomic_inc(&tty->port.count);
49707
49708 tty->port.tty = linux_tty;
49709 linux_tty->driver_data = tty;
49710 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49711
49712 static void do_ipw_close(struct ipw_tty *tty)
49713 {
49714 - tty->port.count--;
49715 -
49716 - if (tty->port.count == 0) {
49717 + if (atomic_dec_return(&tty->port.count) == 0) {
49718 struct tty_struct *linux_tty = tty->port.tty;
49719
49720 if (linux_tty != NULL) {
49721 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
49722 return;
49723
49724 mutex_lock(&tty->ipw_tty_mutex);
49725 - if (tty->port.count == 0) {
49726 + if (atomic_read(&tty->port.count) == 0) {
49727 mutex_unlock(&tty->ipw_tty_mutex);
49728 return;
49729 }
49730 @@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
49731
49732 mutex_lock(&tty->ipw_tty_mutex);
49733
49734 - if (!tty->port.count) {
49735 + if (!atomic_read(&tty->port.count)) {
49736 mutex_unlock(&tty->ipw_tty_mutex);
49737 return;
49738 }
49739 @@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
49740 return -ENODEV;
49741
49742 mutex_lock(&tty->ipw_tty_mutex);
49743 - if (!tty->port.count) {
49744 + if (!atomic_read(&tty->port.count)) {
49745 mutex_unlock(&tty->ipw_tty_mutex);
49746 return -EINVAL;
49747 }
49748 @@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
49749 if (!tty)
49750 return -ENODEV;
49751
49752 - if (!tty->port.count)
49753 + if (!atomic_read(&tty->port.count))
49754 return -EINVAL;
49755
49756 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
49757 @@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
49758 if (!tty)
49759 return 0;
49760
49761 - if (!tty->port.count)
49762 + if (!atomic_read(&tty->port.count))
49763 return 0;
49764
49765 return tty->tx_bytes_queued;
49766 @@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
49767 if (!tty)
49768 return -ENODEV;
49769
49770 - if (!tty->port.count)
49771 + if (!atomic_read(&tty->port.count))
49772 return -EINVAL;
49773
49774 return get_control_lines(tty);
49775 @@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
49776 if (!tty)
49777 return -ENODEV;
49778
49779 - if (!tty->port.count)
49780 + if (!atomic_read(&tty->port.count))
49781 return -EINVAL;
49782
49783 return set_control_lines(tty, set, clear);
49784 @@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
49785 if (!tty)
49786 return -ENODEV;
49787
49788 - if (!tty->port.count)
49789 + if (!atomic_read(&tty->port.count))
49790 return -EINVAL;
49791
49792 /* FIXME: Exactly how is the tty object locked here .. */
49793 @@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
49794 * are gone */
49795 mutex_lock(&ttyj->ipw_tty_mutex);
49796 }
49797 - while (ttyj->port.count)
49798 + while (atomic_read(&ttyj->port.count))
49799 do_ipw_close(ttyj);
49800 ipwireless_disassociate_network_ttys(network,
49801 ttyj->channel_idx);
49802 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
49803 index 1deaca4..c8582d4 100644
49804 --- a/drivers/tty/moxa.c
49805 +++ b/drivers/tty/moxa.c
49806 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
49807 }
49808
49809 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
49810 - ch->port.count++;
49811 + atomic_inc(&ch->port.count);
49812 tty->driver_data = ch;
49813 tty_port_tty_set(&ch->port, tty);
49814 mutex_lock(&ch->port.mutex);
49815 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
49816 index c0f76da..d974c32 100644
49817 --- a/drivers/tty/n_gsm.c
49818 +++ b/drivers/tty/n_gsm.c
49819 @@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
49820 spin_lock_init(&dlci->lock);
49821 mutex_init(&dlci->mutex);
49822 dlci->fifo = &dlci->_fifo;
49823 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
49824 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
49825 kfree(dlci);
49826 return NULL;
49827 }
49828 @@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
49829 struct gsm_dlci *dlci = tty->driver_data;
49830 struct tty_port *port = &dlci->port;
49831
49832 - port->count++;
49833 + atomic_inc(&port->count);
49834 dlci_get(dlci);
49835 dlci_get(dlci->gsm->dlci[0]);
49836 mux_get(dlci->gsm);
49837 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
49838 index 34aacaa..dad073b 100644
49839 --- a/drivers/tty/n_tty.c
49840 +++ b/drivers/tty/n_tty.c
49841 @@ -114,7 +114,7 @@ struct n_tty_data {
49842 int minimum_to_wake;
49843
49844 /* consumer-published */
49845 - size_t read_tail;
49846 + size_t read_tail __intentional_overflow(-1);
49847 size_t line_start;
49848
49849 /* protected by output lock */
49850 @@ -2502,6 +2502,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
49851 {
49852 *ops = tty_ldisc_N_TTY;
49853 ops->owner = NULL;
49854 - ops->refcount = ops->flags = 0;
49855 + atomic_set(&ops->refcount, 0);
49856 + ops->flags = 0;
49857 }
49858 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
49859 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
49860 index 25c9bc7..24077b7 100644
49861 --- a/drivers/tty/pty.c
49862 +++ b/drivers/tty/pty.c
49863 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
49864 panic("Couldn't register Unix98 pts driver");
49865
49866 /* Now create the /dev/ptmx special device */
49867 + pax_open_kernel();
49868 tty_default_fops(&ptmx_fops);
49869 - ptmx_fops.open = ptmx_open;
49870 + *(void **)&ptmx_fops.open = ptmx_open;
49871 + pax_close_kernel();
49872
49873 cdev_init(&ptmx_cdev, &ptmx_fops);
49874 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
49875 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
49876 index 354564e..fe50d9a 100644
49877 --- a/drivers/tty/rocket.c
49878 +++ b/drivers/tty/rocket.c
49879 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49880 tty->driver_data = info;
49881 tty_port_tty_set(port, tty);
49882
49883 - if (port->count++ == 0) {
49884 + if (atomic_inc_return(&port->count) == 1) {
49885 atomic_inc(&rp_num_ports_open);
49886
49887 #ifdef ROCKET_DEBUG_OPEN
49888 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49889 #endif
49890 }
49891 #ifdef ROCKET_DEBUG_OPEN
49892 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
49893 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
49894 #endif
49895
49896 /*
49897 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
49898 spin_unlock_irqrestore(&info->port.lock, flags);
49899 return;
49900 }
49901 - if (info->port.count)
49902 + if (atomic_read(&info->port.count))
49903 atomic_dec(&rp_num_ports_open);
49904 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
49905 spin_unlock_irqrestore(&info->port.lock, flags);
49906 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
49907 index 1274499..f541382 100644
49908 --- a/drivers/tty/serial/ioc4_serial.c
49909 +++ b/drivers/tty/serial/ioc4_serial.c
49910 @@ -437,7 +437,7 @@ struct ioc4_soft {
49911 } is_intr_info[MAX_IOC4_INTR_ENTS];
49912
49913 /* Number of entries active in the above array */
49914 - atomic_t is_num_intrs;
49915 + atomic_unchecked_t is_num_intrs;
49916 } is_intr_type[IOC4_NUM_INTR_TYPES];
49917
49918 /* is_ir_lock must be held while
49919 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
49920 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
49921 || (type == IOC4_OTHER_INTR_TYPE)));
49922
49923 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
49924 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
49925 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
49926
49927 /* Save off the lower level interrupt handler */
49928 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
49929
49930 soft = arg;
49931 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
49932 - num_intrs = (int)atomic_read(
49933 + num_intrs = (int)atomic_read_unchecked(
49934 &soft->is_intr_type[intr_type].is_num_intrs);
49935
49936 this_mir = this_ir = pending_intrs(soft, intr_type);
49937 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
49938 index a260cde..6b2b5ce 100644
49939 --- a/drivers/tty/serial/kgdboc.c
49940 +++ b/drivers/tty/serial/kgdboc.c
49941 @@ -24,8 +24,9 @@
49942 #define MAX_CONFIG_LEN 40
49943
49944 static struct kgdb_io kgdboc_io_ops;
49945 +static struct kgdb_io kgdboc_io_ops_console;
49946
49947 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
49948 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
49949 static int configured = -1;
49950
49951 static char config[MAX_CONFIG_LEN];
49952 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
49953 kgdboc_unregister_kbd();
49954 if (configured == 1)
49955 kgdb_unregister_io_module(&kgdboc_io_ops);
49956 + else if (configured == 2)
49957 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
49958 }
49959
49960 static int configure_kgdboc(void)
49961 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
49962 int err;
49963 char *cptr = config;
49964 struct console *cons;
49965 + int is_console = 0;
49966
49967 err = kgdboc_option_setup(config);
49968 if (err || !strlen(config) || isspace(config[0]))
49969 goto noconfig;
49970
49971 err = -ENODEV;
49972 - kgdboc_io_ops.is_console = 0;
49973 kgdb_tty_driver = NULL;
49974
49975 kgdboc_use_kms = 0;
49976 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
49977 int idx;
49978 if (cons->device && cons->device(cons, &idx) == p &&
49979 idx == tty_line) {
49980 - kgdboc_io_ops.is_console = 1;
49981 + is_console = 1;
49982 break;
49983 }
49984 cons = cons->next;
49985 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
49986 kgdb_tty_line = tty_line;
49987
49988 do_register:
49989 - err = kgdb_register_io_module(&kgdboc_io_ops);
49990 + if (is_console) {
49991 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
49992 + configured = 2;
49993 + } else {
49994 + err = kgdb_register_io_module(&kgdboc_io_ops);
49995 + configured = 1;
49996 + }
49997 if (err)
49998 goto noconfig;
49999
50000 @@ -205,8 +214,6 @@ do_register:
50001 if (err)
50002 goto nmi_con_failed;
50003
50004 - configured = 1;
50005 -
50006 return 0;
50007
50008 nmi_con_failed:
50009 @@ -223,7 +230,7 @@ noconfig:
50010 static int __init init_kgdboc(void)
50011 {
50012 /* Already configured? */
50013 - if (configured == 1)
50014 + if (configured >= 1)
50015 return 0;
50016
50017 return configure_kgdboc();
50018 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50019 if (config[len - 1] == '\n')
50020 config[len - 1] = '\0';
50021
50022 - if (configured == 1)
50023 + if (configured >= 1)
50024 cleanup_kgdboc();
50025
50026 /* Go and configure with the new params. */
50027 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50028 .post_exception = kgdboc_post_exp_handler,
50029 };
50030
50031 +static struct kgdb_io kgdboc_io_ops_console = {
50032 + .name = "kgdboc",
50033 + .read_char = kgdboc_get_char,
50034 + .write_char = kgdboc_put_char,
50035 + .pre_exception = kgdboc_pre_exp_handler,
50036 + .post_exception = kgdboc_post_exp_handler,
50037 + .is_console = 1
50038 +};
50039 +
50040 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50041 /* This is only available if kgdboc is a built in for early debugging */
50042 static int __init kgdboc_early_init(char *opt)
50043 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50044 index b5d779c..3622cfe 100644
50045 --- a/drivers/tty/serial/msm_serial.c
50046 +++ b/drivers/tty/serial/msm_serial.c
50047 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50048 .cons = MSM_CONSOLE,
50049 };
50050
50051 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50052 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50053
50054 static const struct of_device_id msm_uartdm_table[] = {
50055 { .compatible = "qcom,msm-uartdm" },
50056 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50057 int irq;
50058
50059 if (pdev->id == -1)
50060 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50061 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50062
50063 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50064 return -ENXIO;
50065 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50066 index c1af04d..0815c8a 100644
50067 --- a/drivers/tty/serial/samsung.c
50068 +++ b/drivers/tty/serial/samsung.c
50069 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50070 }
50071 }
50072
50073 +static int s3c64xx_serial_startup(struct uart_port *port);
50074 static int s3c24xx_serial_startup(struct uart_port *port)
50075 {
50076 struct s3c24xx_uart_port *ourport = to_ourport(port);
50077 int ret;
50078
50079 + /* Startup sequence is different for s3c64xx and higher SoC's */
50080 + if (s3c24xx_serial_has_interrupt_mask(port))
50081 + return s3c64xx_serial_startup(port);
50082 +
50083 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50084 port->mapbase, port->membase);
50085
50086 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50087 /* setup info for port */
50088 port->dev = &platdev->dev;
50089
50090 - /* Startup sequence is different for s3c64xx and higher SoC's */
50091 - if (s3c24xx_serial_has_interrupt_mask(port))
50092 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50093 -
50094 port->uartclk = 1;
50095
50096 if (cfg->uart_flags & UPF_CONS_FLOW) {
50097 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50098 index 0f02351..07c59c5 100644
50099 --- a/drivers/tty/serial/serial_core.c
50100 +++ b/drivers/tty/serial/serial_core.c
50101 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50102 uart_flush_buffer(tty);
50103 uart_shutdown(tty, state);
50104 spin_lock_irqsave(&port->lock, flags);
50105 - port->count = 0;
50106 + atomic_set(&port->count, 0);
50107 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50108 spin_unlock_irqrestore(&port->lock, flags);
50109 tty_port_tty_set(port, NULL);
50110 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50111 goto end;
50112 }
50113
50114 - port->count++;
50115 + atomic_inc(&port->count);
50116 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50117 retval = -ENXIO;
50118 goto err_dec_count;
50119 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50120 /*
50121 * Make sure the device is in D0 state.
50122 */
50123 - if (port->count == 1)
50124 + if (atomic_read(&port->count) == 1)
50125 uart_change_pm(state, UART_PM_STATE_ON);
50126
50127 /*
50128 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50129 end:
50130 return retval;
50131 err_dec_count:
50132 - port->count--;
50133 + atomic_inc(&port->count);
50134 mutex_unlock(&port->mutex);
50135 goto end;
50136 }
50137 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50138 index e1ce141..6d4ed80 100644
50139 --- a/drivers/tty/synclink.c
50140 +++ b/drivers/tty/synclink.c
50141 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50142
50143 if (debug_level >= DEBUG_LEVEL_INFO)
50144 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50145 - __FILE__,__LINE__, info->device_name, info->port.count);
50146 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50147
50148 if (tty_port_close_start(&info->port, tty, filp) == 0)
50149 goto cleanup;
50150 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50151 cleanup:
50152 if (debug_level >= DEBUG_LEVEL_INFO)
50153 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50154 - tty->driver->name, info->port.count);
50155 + tty->driver->name, atomic_read(&info->port.count));
50156
50157 } /* end of mgsl_close() */
50158
50159 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50160
50161 mgsl_flush_buffer(tty);
50162 shutdown(info);
50163 -
50164 - info->port.count = 0;
50165 +
50166 + atomic_set(&info->port.count, 0);
50167 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50168 info->port.tty = NULL;
50169
50170 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50171
50172 if (debug_level >= DEBUG_LEVEL_INFO)
50173 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50174 - __FILE__,__LINE__, tty->driver->name, port->count );
50175 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50176
50177 spin_lock_irqsave(&info->irq_spinlock, flags);
50178 if (!tty_hung_up_p(filp)) {
50179 extra_count = true;
50180 - port->count--;
50181 + atomic_dec(&port->count);
50182 }
50183 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50184 port->blocked_open++;
50185 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50186
50187 if (debug_level >= DEBUG_LEVEL_INFO)
50188 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50189 - __FILE__,__LINE__, tty->driver->name, port->count );
50190 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50191
50192 tty_unlock(tty);
50193 schedule();
50194 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50195
50196 /* FIXME: Racy on hangup during close wait */
50197 if (extra_count)
50198 - port->count++;
50199 + atomic_inc(&port->count);
50200 port->blocked_open--;
50201
50202 if (debug_level >= DEBUG_LEVEL_INFO)
50203 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50204 - __FILE__,__LINE__, tty->driver->name, port->count );
50205 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50206
50207 if (!retval)
50208 port->flags |= ASYNC_NORMAL_ACTIVE;
50209 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50210
50211 if (debug_level >= DEBUG_LEVEL_INFO)
50212 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50213 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50214 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50215
50216 /* If port is closing, signal caller to try again */
50217 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50218 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50219 spin_unlock_irqrestore(&info->netlock, flags);
50220 goto cleanup;
50221 }
50222 - info->port.count++;
50223 + atomic_inc(&info->port.count);
50224 spin_unlock_irqrestore(&info->netlock, flags);
50225
50226 - if (info->port.count == 1) {
50227 + if (atomic_read(&info->port.count) == 1) {
50228 /* 1st open on this device, init hardware */
50229 retval = startup(info);
50230 if (retval < 0)
50231 @@ -3446,8 +3446,8 @@ cleanup:
50232 if (retval) {
50233 if (tty->count == 1)
50234 info->port.tty = NULL; /* tty layer will release tty struct */
50235 - if(info->port.count)
50236 - info->port.count--;
50237 + if (atomic_read(&info->port.count))
50238 + atomic_dec(&info->port.count);
50239 }
50240
50241 return retval;
50242 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50243 unsigned short new_crctype;
50244
50245 /* return error if TTY interface open */
50246 - if (info->port.count)
50247 + if (atomic_read(&info->port.count))
50248 return -EBUSY;
50249
50250 switch (encoding)
50251 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50252
50253 /* arbitrate between network and tty opens */
50254 spin_lock_irqsave(&info->netlock, flags);
50255 - if (info->port.count != 0 || info->netcount != 0) {
50256 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50257 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50258 spin_unlock_irqrestore(&info->netlock, flags);
50259 return -EBUSY;
50260 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50261 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50262
50263 /* return error if TTY interface open */
50264 - if (info->port.count)
50265 + if (atomic_read(&info->port.count))
50266 return -EBUSY;
50267
50268 if (cmd != SIOCWANDEV)
50269 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
50270 index 1abf946..1ee34fc 100644
50271 --- a/drivers/tty/synclink_gt.c
50272 +++ b/drivers/tty/synclink_gt.c
50273 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50274 tty->driver_data = info;
50275 info->port.tty = tty;
50276
50277 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
50278 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
50279
50280 /* If port is closing, signal caller to try again */
50281 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50282 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50283 mutex_unlock(&info->port.mutex);
50284 goto cleanup;
50285 }
50286 - info->port.count++;
50287 + atomic_inc(&info->port.count);
50288 spin_unlock_irqrestore(&info->netlock, flags);
50289
50290 - if (info->port.count == 1) {
50291 + if (atomic_read(&info->port.count) == 1) {
50292 /* 1st open on this device, init hardware */
50293 retval = startup(info);
50294 if (retval < 0) {
50295 @@ -715,8 +715,8 @@ cleanup:
50296 if (retval) {
50297 if (tty->count == 1)
50298 info->port.tty = NULL; /* tty layer will release tty struct */
50299 - if(info->port.count)
50300 - info->port.count--;
50301 + if(atomic_read(&info->port.count))
50302 + atomic_dec(&info->port.count);
50303 }
50304
50305 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
50306 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50307
50308 if (sanity_check(info, tty->name, "close"))
50309 return;
50310 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
50311 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
50312
50313 if (tty_port_close_start(&info->port, tty, filp) == 0)
50314 goto cleanup;
50315 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50316 tty_port_close_end(&info->port, tty);
50317 info->port.tty = NULL;
50318 cleanup:
50319 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
50320 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
50321 }
50322
50323 static void hangup(struct tty_struct *tty)
50324 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
50325 shutdown(info);
50326
50327 spin_lock_irqsave(&info->port.lock, flags);
50328 - info->port.count = 0;
50329 + atomic_set(&info->port.count, 0);
50330 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50331 info->port.tty = NULL;
50332 spin_unlock_irqrestore(&info->port.lock, flags);
50333 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50334 unsigned short new_crctype;
50335
50336 /* return error if TTY interface open */
50337 - if (info->port.count)
50338 + if (atomic_read(&info->port.count))
50339 return -EBUSY;
50340
50341 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
50342 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
50343
50344 /* arbitrate between network and tty opens */
50345 spin_lock_irqsave(&info->netlock, flags);
50346 - if (info->port.count != 0 || info->netcount != 0) {
50347 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50348 DBGINFO(("%s hdlc_open busy\n", dev->name));
50349 spin_unlock_irqrestore(&info->netlock, flags);
50350 return -EBUSY;
50351 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50352 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
50353
50354 /* return error if TTY interface open */
50355 - if (info->port.count)
50356 + if (atomic_read(&info->port.count))
50357 return -EBUSY;
50358
50359 if (cmd != SIOCWANDEV)
50360 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
50361 if (port == NULL)
50362 continue;
50363 spin_lock(&port->lock);
50364 - if ((port->port.count || port->netcount) &&
50365 + if ((atomic_read(&port->port.count) || port->netcount) &&
50366 port->pending_bh && !port->bh_running &&
50367 !port->bh_requested) {
50368 DBGISR(("%s bh queued\n", port->device_name));
50369 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50370 spin_lock_irqsave(&info->lock, flags);
50371 if (!tty_hung_up_p(filp)) {
50372 extra_count = true;
50373 - port->count--;
50374 + atomic_dec(&port->count);
50375 }
50376 spin_unlock_irqrestore(&info->lock, flags);
50377 port->blocked_open++;
50378 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50379 remove_wait_queue(&port->open_wait, &wait);
50380
50381 if (extra_count)
50382 - port->count++;
50383 + atomic_inc(&port->count);
50384 port->blocked_open--;
50385
50386 if (!retval)
50387 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
50388 index dc6e969..5dc8786 100644
50389 --- a/drivers/tty/synclinkmp.c
50390 +++ b/drivers/tty/synclinkmp.c
50391 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50392
50393 if (debug_level >= DEBUG_LEVEL_INFO)
50394 printk("%s(%d):%s open(), old ref count = %d\n",
50395 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50396 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50397
50398 /* If port is closing, signal caller to try again */
50399 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50400 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50401 spin_unlock_irqrestore(&info->netlock, flags);
50402 goto cleanup;
50403 }
50404 - info->port.count++;
50405 + atomic_inc(&info->port.count);
50406 spin_unlock_irqrestore(&info->netlock, flags);
50407
50408 - if (info->port.count == 1) {
50409 + if (atomic_read(&info->port.count) == 1) {
50410 /* 1st open on this device, init hardware */
50411 retval = startup(info);
50412 if (retval < 0)
50413 @@ -796,8 +796,8 @@ cleanup:
50414 if (retval) {
50415 if (tty->count == 1)
50416 info->port.tty = NULL; /* tty layer will release tty struct */
50417 - if(info->port.count)
50418 - info->port.count--;
50419 + if(atomic_read(&info->port.count))
50420 + atomic_dec(&info->port.count);
50421 }
50422
50423 return retval;
50424 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50425
50426 if (debug_level >= DEBUG_LEVEL_INFO)
50427 printk("%s(%d):%s close() entry, count=%d\n",
50428 - __FILE__,__LINE__, info->device_name, info->port.count);
50429 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50430
50431 if (tty_port_close_start(&info->port, tty, filp) == 0)
50432 goto cleanup;
50433 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50434 cleanup:
50435 if (debug_level >= DEBUG_LEVEL_INFO)
50436 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
50437 - tty->driver->name, info->port.count);
50438 + tty->driver->name, atomic_read(&info->port.count));
50439 }
50440
50441 /* Called by tty_hangup() when a hangup is signaled.
50442 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
50443 shutdown(info);
50444
50445 spin_lock_irqsave(&info->port.lock, flags);
50446 - info->port.count = 0;
50447 + atomic_set(&info->port.count, 0);
50448 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50449 info->port.tty = NULL;
50450 spin_unlock_irqrestore(&info->port.lock, flags);
50451 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50452 unsigned short new_crctype;
50453
50454 /* return error if TTY interface open */
50455 - if (info->port.count)
50456 + if (atomic_read(&info->port.count))
50457 return -EBUSY;
50458
50459 switch (encoding)
50460 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
50461
50462 /* arbitrate between network and tty opens */
50463 spin_lock_irqsave(&info->netlock, flags);
50464 - if (info->port.count != 0 || info->netcount != 0) {
50465 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50466 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50467 spin_unlock_irqrestore(&info->netlock, flags);
50468 return -EBUSY;
50469 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50470 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50471
50472 /* return error if TTY interface open */
50473 - if (info->port.count)
50474 + if (atomic_read(&info->port.count))
50475 return -EBUSY;
50476
50477 if (cmd != SIOCWANDEV)
50478 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
50479 * do not request bottom half processing if the
50480 * device is not open in a normal mode.
50481 */
50482 - if ( port && (port->port.count || port->netcount) &&
50483 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
50484 port->pending_bh && !port->bh_running &&
50485 !port->bh_requested ) {
50486 if ( debug_level >= DEBUG_LEVEL_ISR )
50487 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50488
50489 if (debug_level >= DEBUG_LEVEL_INFO)
50490 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
50491 - __FILE__,__LINE__, tty->driver->name, port->count );
50492 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50493
50494 spin_lock_irqsave(&info->lock, flags);
50495 if (!tty_hung_up_p(filp)) {
50496 extra_count = true;
50497 - port->count--;
50498 + atomic_dec(&port->count);
50499 }
50500 spin_unlock_irqrestore(&info->lock, flags);
50501 port->blocked_open++;
50502 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50503
50504 if (debug_level >= DEBUG_LEVEL_INFO)
50505 printk("%s(%d):%s block_til_ready() count=%d\n",
50506 - __FILE__,__LINE__, tty->driver->name, port->count );
50507 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50508
50509 tty_unlock(tty);
50510 schedule();
50511 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50512 remove_wait_queue(&port->open_wait, &wait);
50513
50514 if (extra_count)
50515 - port->count++;
50516 + atomic_inc(&port->count);
50517 port->blocked_open--;
50518
50519 if (debug_level >= DEBUG_LEVEL_INFO)
50520 printk("%s(%d):%s block_til_ready() after, count=%d\n",
50521 - __FILE__,__LINE__, tty->driver->name, port->count );
50522 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50523
50524 if (!retval)
50525 port->flags |= ASYNC_NORMAL_ACTIVE;
50526 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
50527 index ce396ec..04a37be 100644
50528 --- a/drivers/tty/sysrq.c
50529 +++ b/drivers/tty/sysrq.c
50530 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
50531 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
50532 size_t count, loff_t *ppos)
50533 {
50534 - if (count) {
50535 + if (count && capable(CAP_SYS_ADMIN)) {
50536 char c;
50537
50538 if (get_user(c, buf))
50539 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
50540 index c74a00a..02cf211a 100644
50541 --- a/drivers/tty/tty_io.c
50542 +++ b/drivers/tty/tty_io.c
50543 @@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
50544
50545 void tty_default_fops(struct file_operations *fops)
50546 {
50547 - *fops = tty_fops;
50548 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
50549 }
50550
50551 /*
50552 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
50553 index 6458e11..6cfc218 100644
50554 --- a/drivers/tty/tty_ldisc.c
50555 +++ b/drivers/tty/tty_ldisc.c
50556 @@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
50557 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50558 tty_ldiscs[disc] = new_ldisc;
50559 new_ldisc->num = disc;
50560 - new_ldisc->refcount = 0;
50561 + atomic_set(&new_ldisc->refcount, 0);
50562 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50563
50564 return ret;
50565 @@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
50566 return -EINVAL;
50567
50568 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50569 - if (tty_ldiscs[disc]->refcount)
50570 + if (atomic_read(&tty_ldiscs[disc]->refcount))
50571 ret = -EBUSY;
50572 else
50573 tty_ldiscs[disc] = NULL;
50574 @@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
50575 if (ldops) {
50576 ret = ERR_PTR(-EAGAIN);
50577 if (try_module_get(ldops->owner)) {
50578 - ldops->refcount++;
50579 + atomic_inc(&ldops->refcount);
50580 ret = ldops;
50581 }
50582 }
50583 @@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
50584 unsigned long flags;
50585
50586 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50587 - ldops->refcount--;
50588 + atomic_dec(&ldops->refcount);
50589 module_put(ldops->owner);
50590 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50591 }
50592 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
50593 index c94d234..8210f2d 100644
50594 --- a/drivers/tty/tty_port.c
50595 +++ b/drivers/tty/tty_port.c
50596 @@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
50597 unsigned long flags;
50598
50599 spin_lock_irqsave(&port->lock, flags);
50600 - port->count = 0;
50601 + atomic_set(&port->count, 0);
50602 port->flags &= ~ASYNC_NORMAL_ACTIVE;
50603 tty = port->tty;
50604 if (tty)
50605 @@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50606 /* The port lock protects the port counts */
50607 spin_lock_irqsave(&port->lock, flags);
50608 if (!tty_hung_up_p(filp))
50609 - port->count--;
50610 + atomic_dec(&port->count);
50611 port->blocked_open++;
50612 spin_unlock_irqrestore(&port->lock, flags);
50613
50614 @@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50615 we must not mess that up further */
50616 spin_lock_irqsave(&port->lock, flags);
50617 if (!tty_hung_up_p(filp))
50618 - port->count++;
50619 + atomic_inc(&port->count);
50620 port->blocked_open--;
50621 if (retval == 0)
50622 port->flags |= ASYNC_NORMAL_ACTIVE;
50623 @@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
50624 return 0;
50625 }
50626
50627 - if (tty->count == 1 && port->count != 1) {
50628 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
50629 printk(KERN_WARNING
50630 "tty_port_close_start: tty->count = 1 port count = %d.\n",
50631 - port->count);
50632 - port->count = 1;
50633 + atomic_read(&port->count));
50634 + atomic_set(&port->count, 1);
50635 }
50636 - if (--port->count < 0) {
50637 + if (atomic_dec_return(&port->count) < 0) {
50638 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
50639 - port->count);
50640 - port->count = 0;
50641 + atomic_read(&port->count));
50642 + atomic_set(&port->count, 0);
50643 }
50644
50645 - if (port->count) {
50646 + if (atomic_read(&port->count)) {
50647 spin_unlock_irqrestore(&port->lock, flags);
50648 return 0;
50649 }
50650 @@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
50651 {
50652 spin_lock_irq(&port->lock);
50653 if (!tty_hung_up_p(filp))
50654 - ++port->count;
50655 + atomic_inc(&port->count);
50656 spin_unlock_irq(&port->lock);
50657 tty_port_tty_set(port, tty);
50658
50659 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
50660 index d0e3a44..5f8b754 100644
50661 --- a/drivers/tty/vt/keyboard.c
50662 +++ b/drivers/tty/vt/keyboard.c
50663 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
50664 kbd->kbdmode == VC_OFF) &&
50665 value != KVAL(K_SAK))
50666 return; /* SAK is allowed even in raw mode */
50667 +
50668 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50669 + {
50670 + void *func = fn_handler[value];
50671 + if (func == fn_show_state || func == fn_show_ptregs ||
50672 + func == fn_show_mem)
50673 + return;
50674 + }
50675 +#endif
50676 +
50677 fn_handler[value](vc);
50678 }
50679
50680 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50681 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
50682 return -EFAULT;
50683
50684 - if (!capable(CAP_SYS_TTY_CONFIG))
50685 - perm = 0;
50686 -
50687 switch (cmd) {
50688 case KDGKBENT:
50689 /* Ensure another thread doesn't free it under us */
50690 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50691 spin_unlock_irqrestore(&kbd_event_lock, flags);
50692 return put_user(val, &user_kbe->kb_value);
50693 case KDSKBENT:
50694 + if (!capable(CAP_SYS_TTY_CONFIG))
50695 + perm = 0;
50696 +
50697 if (!perm)
50698 return -EPERM;
50699 if (!i && v == K_NOSUCHMAP) {
50700 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50701 int i, j, k;
50702 int ret;
50703
50704 - if (!capable(CAP_SYS_TTY_CONFIG))
50705 - perm = 0;
50706 -
50707 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
50708 if (!kbs) {
50709 ret = -ENOMEM;
50710 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50711 kfree(kbs);
50712 return ((p && *p) ? -EOVERFLOW : 0);
50713 case KDSKBSENT:
50714 + if (!capable(CAP_SYS_TTY_CONFIG))
50715 + perm = 0;
50716 +
50717 if (!perm) {
50718 ret = -EPERM;
50719 goto reterr;
50720 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
50721 index a673e5b..36e5d32 100644
50722 --- a/drivers/uio/uio.c
50723 +++ b/drivers/uio/uio.c
50724 @@ -25,6 +25,7 @@
50725 #include <linux/kobject.h>
50726 #include <linux/cdev.h>
50727 #include <linux/uio_driver.h>
50728 +#include <asm/local.h>
50729
50730 #define UIO_MAX_DEVICES (1U << MINORBITS)
50731
50732 @@ -32,7 +33,7 @@ struct uio_device {
50733 struct module *owner;
50734 struct device *dev;
50735 int minor;
50736 - atomic_t event;
50737 + atomic_unchecked_t event;
50738 struct fasync_struct *async_queue;
50739 wait_queue_head_t wait;
50740 struct uio_info *info;
50741 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
50742 struct device_attribute *attr, char *buf)
50743 {
50744 struct uio_device *idev = dev_get_drvdata(dev);
50745 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
50746 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
50747 }
50748 static DEVICE_ATTR_RO(event);
50749
50750 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
50751 {
50752 struct uio_device *idev = info->uio_dev;
50753
50754 - atomic_inc(&idev->event);
50755 + atomic_inc_unchecked(&idev->event);
50756 wake_up_interruptible(&idev->wait);
50757 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
50758 }
50759 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
50760 }
50761
50762 listener->dev = idev;
50763 - listener->event_count = atomic_read(&idev->event);
50764 + listener->event_count = atomic_read_unchecked(&idev->event);
50765 filep->private_data = listener;
50766
50767 if (idev->info->open) {
50768 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
50769 return -EIO;
50770
50771 poll_wait(filep, &idev->wait, wait);
50772 - if (listener->event_count != atomic_read(&idev->event))
50773 + if (listener->event_count != atomic_read_unchecked(&idev->event))
50774 return POLLIN | POLLRDNORM;
50775 return 0;
50776 }
50777 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
50778 do {
50779 set_current_state(TASK_INTERRUPTIBLE);
50780
50781 - event_count = atomic_read(&idev->event);
50782 + event_count = atomic_read_unchecked(&idev->event);
50783 if (event_count != listener->event_count) {
50784 if (copy_to_user(buf, &event_count, count))
50785 retval = -EFAULT;
50786 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
50787 static int uio_find_mem_index(struct vm_area_struct *vma)
50788 {
50789 struct uio_device *idev = vma->vm_private_data;
50790 + unsigned long size;
50791
50792 if (vma->vm_pgoff < MAX_UIO_MAPS) {
50793 - if (idev->info->mem[vma->vm_pgoff].size == 0)
50794 + size = idev->info->mem[vma->vm_pgoff].size;
50795 + if (size == 0)
50796 + return -1;
50797 + if (vma->vm_end - vma->vm_start > size)
50798 return -1;
50799 return (int)vma->vm_pgoff;
50800 }
50801 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
50802 idev->owner = owner;
50803 idev->info = info;
50804 init_waitqueue_head(&idev->wait);
50805 - atomic_set(&idev->event, 0);
50806 + atomic_set_unchecked(&idev->event, 0);
50807
50808 ret = uio_get_minor(idev);
50809 if (ret)
50810 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
50811 index 8a7eb77..c00402f 100644
50812 --- a/drivers/usb/atm/cxacru.c
50813 +++ b/drivers/usb/atm/cxacru.c
50814 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
50815 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
50816 if (ret < 2)
50817 return -EINVAL;
50818 - if (index < 0 || index > 0x7f)
50819 + if (index > 0x7f)
50820 return -EINVAL;
50821 pos += tmp;
50822
50823 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
50824 index 25a7bfc..57f3cf5 100644
50825 --- a/drivers/usb/atm/usbatm.c
50826 +++ b/drivers/usb/atm/usbatm.c
50827 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50828 if (printk_ratelimit())
50829 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
50830 __func__, vpi, vci);
50831 - atomic_inc(&vcc->stats->rx_err);
50832 + atomic_inc_unchecked(&vcc->stats->rx_err);
50833 return;
50834 }
50835
50836 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50837 if (length > ATM_MAX_AAL5_PDU) {
50838 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
50839 __func__, length, vcc);
50840 - atomic_inc(&vcc->stats->rx_err);
50841 + atomic_inc_unchecked(&vcc->stats->rx_err);
50842 goto out;
50843 }
50844
50845 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50846 if (sarb->len < pdu_length) {
50847 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
50848 __func__, pdu_length, sarb->len, vcc);
50849 - atomic_inc(&vcc->stats->rx_err);
50850 + atomic_inc_unchecked(&vcc->stats->rx_err);
50851 goto out;
50852 }
50853
50854 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
50855 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
50856 __func__, vcc);
50857 - atomic_inc(&vcc->stats->rx_err);
50858 + atomic_inc_unchecked(&vcc->stats->rx_err);
50859 goto out;
50860 }
50861
50862 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50863 if (printk_ratelimit())
50864 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
50865 __func__, length);
50866 - atomic_inc(&vcc->stats->rx_drop);
50867 + atomic_inc_unchecked(&vcc->stats->rx_drop);
50868 goto out;
50869 }
50870
50871 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50872
50873 vcc->push(vcc, skb);
50874
50875 - atomic_inc(&vcc->stats->rx);
50876 + atomic_inc_unchecked(&vcc->stats->rx);
50877 out:
50878 skb_trim(sarb, 0);
50879 }
50880 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
50881 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
50882
50883 usbatm_pop(vcc, skb);
50884 - atomic_inc(&vcc->stats->tx);
50885 + atomic_inc_unchecked(&vcc->stats->tx);
50886
50887 skb = skb_dequeue(&instance->sndqueue);
50888 }
50889 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
50890 if (!left--)
50891 return sprintf(page,
50892 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
50893 - atomic_read(&atm_dev->stats.aal5.tx),
50894 - atomic_read(&atm_dev->stats.aal5.tx_err),
50895 - atomic_read(&atm_dev->stats.aal5.rx),
50896 - atomic_read(&atm_dev->stats.aal5.rx_err),
50897 - atomic_read(&atm_dev->stats.aal5.rx_drop));
50898 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
50899 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
50900 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
50901 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
50902 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
50903
50904 if (!left--) {
50905 if (instance->disconnected)
50906 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
50907 index 2a3bbdf..91d72cf 100644
50908 --- a/drivers/usb/core/devices.c
50909 +++ b/drivers/usb/core/devices.c
50910 @@ -126,7 +126,7 @@ static const char format_endpt[] =
50911 * time it gets called.
50912 */
50913 static struct device_connect_event {
50914 - atomic_t count;
50915 + atomic_unchecked_t count;
50916 wait_queue_head_t wait;
50917 } device_event = {
50918 .count = ATOMIC_INIT(1),
50919 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
50920
50921 void usbfs_conn_disc_event(void)
50922 {
50923 - atomic_add(2, &device_event.count);
50924 + atomic_add_unchecked(2, &device_event.count);
50925 wake_up(&device_event.wait);
50926 }
50927
50928 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
50929
50930 poll_wait(file, &device_event.wait, wait);
50931
50932 - event_count = atomic_read(&device_event.count);
50933 + event_count = atomic_read_unchecked(&device_event.count);
50934 if (file->f_version != event_count) {
50935 file->f_version = event_count;
50936 return POLLIN | POLLRDNORM;
50937 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
50938 index 967152a..16fa2e5 100644
50939 --- a/drivers/usb/core/devio.c
50940 +++ b/drivers/usb/core/devio.c
50941 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50942 struct dev_state *ps = file->private_data;
50943 struct usb_device *dev = ps->dev;
50944 ssize_t ret = 0;
50945 - unsigned len;
50946 + size_t len;
50947 loff_t pos;
50948 int i;
50949
50950 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50951 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
50952 struct usb_config_descriptor *config =
50953 (struct usb_config_descriptor *)dev->rawdescriptors[i];
50954 - unsigned int length = le16_to_cpu(config->wTotalLength);
50955 + size_t length = le16_to_cpu(config->wTotalLength);
50956
50957 if (*ppos < pos + length) {
50958
50959 /* The descriptor may claim to be longer than it
50960 * really is. Here is the actual allocated length. */
50961 - unsigned alloclen =
50962 + size_t alloclen =
50963 le16_to_cpu(dev->config[i].desc.wTotalLength);
50964
50965 - len = length - (*ppos - pos);
50966 + len = length + pos - *ppos;
50967 if (len > nbytes)
50968 len = nbytes;
50969
50970 /* Simply don't write (skip over) unallocated parts */
50971 if (alloclen > (*ppos - pos)) {
50972 - alloclen -= (*ppos - pos);
50973 + alloclen = alloclen + pos - *ppos;
50974 if (copy_to_user(buf,
50975 dev->rawdescriptors[i] + (*ppos - pos),
50976 min(len, alloclen))) {
50977 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
50978 index 6bffb8c..b404e8b 100644
50979 --- a/drivers/usb/core/hcd.c
50980 +++ b/drivers/usb/core/hcd.c
50981 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
50982 */
50983 usb_get_urb(urb);
50984 atomic_inc(&urb->use_count);
50985 - atomic_inc(&urb->dev->urbnum);
50986 + atomic_inc_unchecked(&urb->dev->urbnum);
50987 usbmon_urb_submit(&hcd->self, urb);
50988
50989 /* NOTE requirements on root-hub callers (usbfs and the hub
50990 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
50991 urb->hcpriv = NULL;
50992 INIT_LIST_HEAD(&urb->urb_list);
50993 atomic_dec(&urb->use_count);
50994 - atomic_dec(&urb->dev->urbnum);
50995 + atomic_dec_unchecked(&urb->dev->urbnum);
50996 if (atomic_read(&urb->reject))
50997 wake_up(&usb_kill_urb_queue);
50998 usb_put_urb(urb);
50999 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51000 index 07e6654..6420edf 100644
51001 --- a/drivers/usb/core/hub.c
51002 +++ b/drivers/usb/core/hub.c
51003 @@ -27,6 +27,7 @@
51004 #include <linux/freezer.h>
51005 #include <linux/random.h>
51006 #include <linux/pm_qos.h>
51007 +#include <linux/grsecurity.h>
51008
51009 #include <asm/uaccess.h>
51010 #include <asm/byteorder.h>
51011 @@ -4442,6 +4443,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51012 goto done;
51013 return;
51014 }
51015 +
51016 + if (gr_handle_new_usb())
51017 + goto done;
51018 +
51019 if (hub_is_superspeed(hub->hdev))
51020 unit_load = 150;
51021 else
51022 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51023 index bb31597..6c5ef8b 100644
51024 --- a/drivers/usb/core/message.c
51025 +++ b/drivers/usb/core/message.c
51026 @@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51027 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51028 * error number.
51029 */
51030 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51031 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51032 __u8 requesttype, __u16 value, __u16 index, void *data,
51033 __u16 size, int timeout)
51034 {
51035 @@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51036 * If successful, 0. Otherwise a negative error number. The number of actual
51037 * bytes transferred will be stored in the @actual_length paramater.
51038 */
51039 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51040 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51041 void *data, int len, int *actual_length, int timeout)
51042 {
51043 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51044 @@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51045 * bytes transferred will be stored in the @actual_length paramater.
51046 *
51047 */
51048 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51049 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51050 void *data, int len, int *actual_length, int timeout)
51051 {
51052 struct urb *urb;
51053 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51054 index 52a97ad..e73330f 100644
51055 --- a/drivers/usb/core/sysfs.c
51056 +++ b/drivers/usb/core/sysfs.c
51057 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51058 struct usb_device *udev;
51059
51060 udev = to_usb_device(dev);
51061 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51062 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51063 }
51064 static DEVICE_ATTR_RO(urbnum);
51065
51066 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51067 index 4d11449..f4ccabf 100644
51068 --- a/drivers/usb/core/usb.c
51069 +++ b/drivers/usb/core/usb.c
51070 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51071 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51072 dev->state = USB_STATE_ATTACHED;
51073 dev->lpm_disable_count = 1;
51074 - atomic_set(&dev->urbnum, 0);
51075 + atomic_set_unchecked(&dev->urbnum, 0);
51076
51077 INIT_LIST_HEAD(&dev->ep0.urb_list);
51078 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51079 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51080 index 02e44fc..3c4fe64 100644
51081 --- a/drivers/usb/dwc3/gadget.c
51082 +++ b/drivers/usb/dwc3/gadget.c
51083 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51084 if (!usb_endpoint_xfer_isoc(desc))
51085 return 0;
51086
51087 - memset(&trb_link, 0, sizeof(trb_link));
51088 -
51089 /* Link TRB for ISOC. The HWO bit is never reset */
51090 trb_st_hw = &dep->trb_pool[0];
51091
51092 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51093 index 8cfc319..4868255 100644
51094 --- a/drivers/usb/early/ehci-dbgp.c
51095 +++ b/drivers/usb/early/ehci-dbgp.c
51096 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51097
51098 #ifdef CONFIG_KGDB
51099 static struct kgdb_io kgdbdbgp_io_ops;
51100 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51101 +static struct kgdb_io kgdbdbgp_io_ops_console;
51102 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51103 #else
51104 #define dbgp_kgdb_mode (0)
51105 #endif
51106 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51107 .write_char = kgdbdbgp_write_char,
51108 };
51109
51110 +static struct kgdb_io kgdbdbgp_io_ops_console = {
51111 + .name = "kgdbdbgp",
51112 + .read_char = kgdbdbgp_read_char,
51113 + .write_char = kgdbdbgp_write_char,
51114 + .is_console = 1
51115 +};
51116 +
51117 static int kgdbdbgp_wait_time;
51118
51119 static int __init kgdbdbgp_parse_config(char *str)
51120 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51121 ptr++;
51122 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51123 }
51124 - kgdb_register_io_module(&kgdbdbgp_io_ops);
51125 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51126 + if (early_dbgp_console.index != -1)
51127 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51128 + else
51129 + kgdb_register_io_module(&kgdbdbgp_io_ops);
51130
51131 return 0;
51132 }
51133 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51134 index b369292..9f3ba40 100644
51135 --- a/drivers/usb/gadget/u_serial.c
51136 +++ b/drivers/usb/gadget/u_serial.c
51137 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51138 spin_lock_irq(&port->port_lock);
51139
51140 /* already open? Great. */
51141 - if (port->port.count) {
51142 + if (atomic_read(&port->port.count)) {
51143 status = 0;
51144 - port->port.count++;
51145 + atomic_inc(&port->port.count);
51146
51147 /* currently opening/closing? wait ... */
51148 } else if (port->openclose) {
51149 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51150 tty->driver_data = port;
51151 port->port.tty = tty;
51152
51153 - port->port.count = 1;
51154 + atomic_set(&port->port.count, 1);
51155 port->openclose = false;
51156
51157 /* if connected, start the I/O stream */
51158 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51159
51160 spin_lock_irq(&port->port_lock);
51161
51162 - if (port->port.count != 1) {
51163 - if (port->port.count == 0)
51164 + if (atomic_read(&port->port.count) != 1) {
51165 + if (atomic_read(&port->port.count) == 0)
51166 WARN_ON(1);
51167 else
51168 - --port->port.count;
51169 + atomic_dec(&port->port.count);
51170 goto exit;
51171 }
51172
51173 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51174 * and sleep if necessary
51175 */
51176 port->openclose = true;
51177 - port->port.count = 0;
51178 + atomic_set(&port->port.count, 0);
51179
51180 gser = port->port_usb;
51181 if (gser && gser->disconnect)
51182 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51183 int cond;
51184
51185 spin_lock_irq(&port->port_lock);
51186 - cond = (port->port.count == 0) && !port->openclose;
51187 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51188 spin_unlock_irq(&port->port_lock);
51189 return cond;
51190 }
51191 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51192 /* if it's already open, start I/O ... and notify the serial
51193 * protocol about open/close status (connect/disconnect).
51194 */
51195 - if (port->port.count) {
51196 + if (atomic_read(&port->port.count)) {
51197 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51198 gs_start_io(port);
51199 if (gser->connect)
51200 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51201
51202 port->port_usb = NULL;
51203 gser->ioport = NULL;
51204 - if (port->port.count > 0 || port->openclose) {
51205 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
51206 wake_up_interruptible(&port->drain_wait);
51207 if (port->port.tty)
51208 tty_hangup(port->port.tty);
51209 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51210
51211 /* finally, free any unused/unusable I/O buffers */
51212 spin_lock_irqsave(&port->port_lock, flags);
51213 - if (port->port.count == 0 && !port->openclose)
51214 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
51215 gs_buf_free(&port->port_write_buf);
51216 gs_free_requests(gser->out, &port->read_pool, NULL);
51217 gs_free_requests(gser->out, &port->read_queue, NULL);
51218 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51219 index 835fc08..f8b22bf 100644
51220 --- a/drivers/usb/host/ehci-hub.c
51221 +++ b/drivers/usb/host/ehci-hub.c
51222 @@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
51223 urb->transfer_flags = URB_DIR_IN;
51224 usb_get_urb(urb);
51225 atomic_inc(&urb->use_count);
51226 - atomic_inc(&urb->dev->urbnum);
51227 + atomic_inc_unchecked(&urb->dev->urbnum);
51228 urb->setup_dma = dma_map_single(
51229 hcd->self.controller,
51230 urb->setup_packet,
51231 @@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51232 urb->status = -EINPROGRESS;
51233 usb_get_urb(urb);
51234 atomic_inc(&urb->use_count);
51235 - atomic_inc(&urb->dev->urbnum);
51236 + atomic_inc_unchecked(&urb->dev->urbnum);
51237 retval = submit_single_step_set_feature(hcd, urb, 0);
51238 if (!retval && !wait_for_completion_timeout(&done,
51239 msecs_to_jiffies(2000))) {
51240 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51241 index ba6a5d6..f88f7f3 100644
51242 --- a/drivers/usb/misc/appledisplay.c
51243 +++ b/drivers/usb/misc/appledisplay.c
51244 @@ -83,7 +83,7 @@ struct appledisplay {
51245 spinlock_t lock;
51246 };
51247
51248 -static atomic_t count_displays = ATOMIC_INIT(0);
51249 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51250 static struct workqueue_struct *wq;
51251
51252 static void appledisplay_complete(struct urb *urb)
51253 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51254
51255 /* Register backlight device */
51256 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
51257 - atomic_inc_return(&count_displays) - 1);
51258 + atomic_inc_return_unchecked(&count_displays) - 1);
51259 memset(&props, 0, sizeof(struct backlight_properties));
51260 props.type = BACKLIGHT_RAW;
51261 props.max_brightness = 0xff;
51262 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
51263 index c69bb50..215ef37 100644
51264 --- a/drivers/usb/serial/console.c
51265 +++ b/drivers/usb/serial/console.c
51266 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
51267
51268 info->port = port;
51269
51270 - ++port->port.count;
51271 + atomic_inc(&port->port.count);
51272 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
51273 if (serial->type->set_termios) {
51274 /*
51275 @@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
51276 }
51277 /* Now that any required fake tty operations are completed restore
51278 * the tty port count */
51279 - --port->port.count;
51280 + atomic_dec(&port->port.count);
51281 /* The console is special in terms of closing the device so
51282 * indicate this port is now acting as a system console. */
51283 port->port.console = 1;
51284 @@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
51285 free_tty:
51286 kfree(tty);
51287 reset_open_count:
51288 - port->port.count = 0;
51289 + atomic_set(&port->port.count, 0);
51290 usb_autopm_put_interface(serial->interface);
51291 error_get_interface:
51292 usb_serial_put(serial);
51293 @@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
51294 static void usb_console_write(struct console *co,
51295 const char *buf, unsigned count)
51296 {
51297 - static struct usbcons_info *info = &usbcons_info;
51298 + struct usbcons_info *info = &usbcons_info;
51299 struct usb_serial_port *port = info->port;
51300 struct usb_serial *serial;
51301 int retval = -ENODEV;
51302 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
51303 index 75f70f0..d467e1a 100644
51304 --- a/drivers/usb/storage/usb.h
51305 +++ b/drivers/usb/storage/usb.h
51306 @@ -63,7 +63,7 @@ struct us_unusual_dev {
51307 __u8 useProtocol;
51308 __u8 useTransport;
51309 int (*initFunction)(struct us_data *);
51310 -};
51311 +} __do_const;
51312
51313
51314 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
51315 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
51316 index e614f02..3fd60e2 100644
51317 --- a/drivers/usb/wusbcore/wa-hc.h
51318 +++ b/drivers/usb/wusbcore/wa-hc.h
51319 @@ -225,7 +225,7 @@ struct wahc {
51320 spinlock_t xfer_list_lock;
51321 struct work_struct xfer_enqueue_work;
51322 struct work_struct xfer_error_work;
51323 - atomic_t xfer_id_count;
51324 + atomic_unchecked_t xfer_id_count;
51325
51326 kernel_ulong_t quirks;
51327 };
51328 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
51329 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
51330 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
51331 wa->dto_in_use = 0;
51332 - atomic_set(&wa->xfer_id_count, 1);
51333 + atomic_set_unchecked(&wa->xfer_id_count, 1);
51334 }
51335
51336 /**
51337 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
51338 index ed5abe8..7036400 100644
51339 --- a/drivers/usb/wusbcore/wa-xfer.c
51340 +++ b/drivers/usb/wusbcore/wa-xfer.c
51341 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
51342 */
51343 static void wa_xfer_id_init(struct wa_xfer *xfer)
51344 {
51345 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
51346 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
51347 }
51348
51349 /* Return the xfer's ID. */
51350 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
51351 index 1eab4ac..e21efc9 100644
51352 --- a/drivers/vfio/vfio.c
51353 +++ b/drivers/vfio/vfio.c
51354 @@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
51355 return 0;
51356
51357 /* TODO Prevent device auto probing */
51358 - WARN("Device %s added to live group %d!\n", dev_name(dev),
51359 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
51360 iommu_group_id(group->iommu_group));
51361
51362 return 0;
51363 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
51364 index 5174eba..451e6bc 100644
51365 --- a/drivers/vhost/vringh.c
51366 +++ b/drivers/vhost/vringh.c
51367 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
51368 /* Userspace access helpers: in this case, addresses are really userspace. */
51369 static inline int getu16_user(u16 *val, const u16 *p)
51370 {
51371 - return get_user(*val, (__force u16 __user *)p);
51372 + return get_user(*val, (u16 __force_user *)p);
51373 }
51374
51375 static inline int putu16_user(u16 *p, u16 val)
51376 {
51377 - return put_user(val, (__force u16 __user *)p);
51378 + return put_user(val, (u16 __force_user *)p);
51379 }
51380
51381 static inline int copydesc_user(void *dst, const void *src, size_t len)
51382 {
51383 - return copy_from_user(dst, (__force void __user *)src, len) ?
51384 + return copy_from_user(dst, (void __force_user *)src, len) ?
51385 -EFAULT : 0;
51386 }
51387
51388 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
51389 const struct vring_used_elem *src,
51390 unsigned int num)
51391 {
51392 - return copy_to_user((__force void __user *)dst, src,
51393 + return copy_to_user((void __force_user *)dst, src,
51394 sizeof(*dst) * num) ? -EFAULT : 0;
51395 }
51396
51397 static inline int xfer_from_user(void *src, void *dst, size_t len)
51398 {
51399 - return copy_from_user(dst, (__force void __user *)src, len) ?
51400 + return copy_from_user(dst, (void __force_user *)src, len) ?
51401 -EFAULT : 0;
51402 }
51403
51404 static inline int xfer_to_user(void *dst, void *src, size_t len)
51405 {
51406 - return copy_to_user((__force void __user *)dst, src, len) ?
51407 + return copy_to_user((void __force_user *)dst, src, len) ?
51408 -EFAULT : 0;
51409 }
51410
51411 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
51412 vrh->last_used_idx = 0;
51413 vrh->vring.num = num;
51414 /* vring expects kernel addresses, but only used via accessors. */
51415 - vrh->vring.desc = (__force struct vring_desc *)desc;
51416 - vrh->vring.avail = (__force struct vring_avail *)avail;
51417 - vrh->vring.used = (__force struct vring_used *)used;
51418 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
51419 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
51420 + vrh->vring.used = (__force_kernel struct vring_used *)used;
51421 return 0;
51422 }
51423 EXPORT_SYMBOL(vringh_init_user);
51424 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
51425
51426 static inline int putu16_kern(u16 *p, u16 val)
51427 {
51428 - ACCESS_ONCE(*p) = val;
51429 + ACCESS_ONCE_RW(*p) = val;
51430 return 0;
51431 }
51432
51433 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
51434 index 1b0b233..6f34c2c 100644
51435 --- a/drivers/video/arcfb.c
51436 +++ b/drivers/video/arcfb.c
51437 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
51438 return -ENOSPC;
51439
51440 err = 0;
51441 - if ((count + p) > fbmemlength) {
51442 + if (count > (fbmemlength - p)) {
51443 count = fbmemlength - p;
51444 err = -ENOSPC;
51445 }
51446 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
51447 index 12ca031..84a8a74 100644
51448 --- a/drivers/video/aty/aty128fb.c
51449 +++ b/drivers/video/aty/aty128fb.c
51450 @@ -149,7 +149,7 @@ enum {
51451 };
51452
51453 /* Must match above enum */
51454 -static char * const r128_family[] = {
51455 +static const char * const r128_family[] = {
51456 "AGP",
51457 "PCI",
51458 "PRO AGP",
51459 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
51460 index 28fafbf..ae91651 100644
51461 --- a/drivers/video/aty/atyfb_base.c
51462 +++ b/drivers/video/aty/atyfb_base.c
51463 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
51464 par->accel_flags = var->accel_flags; /* hack */
51465
51466 if (var->accel_flags) {
51467 - info->fbops->fb_sync = atyfb_sync;
51468 + pax_open_kernel();
51469 + *(void **)&info->fbops->fb_sync = atyfb_sync;
51470 + pax_close_kernel();
51471 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51472 } else {
51473 - info->fbops->fb_sync = NULL;
51474 + pax_open_kernel();
51475 + *(void **)&info->fbops->fb_sync = NULL;
51476 + pax_close_kernel();
51477 info->flags |= FBINFO_HWACCEL_DISABLED;
51478 }
51479
51480 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
51481 index 95ec042..e6affdd 100644
51482 --- a/drivers/video/aty/mach64_cursor.c
51483 +++ b/drivers/video/aty/mach64_cursor.c
51484 @@ -7,6 +7,7 @@
51485 #include <linux/string.h>
51486
51487 #include <asm/io.h>
51488 +#include <asm/pgtable.h>
51489
51490 #ifdef __sparc__
51491 #include <asm/fbio.h>
51492 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
51493 info->sprite.buf_align = 16; /* and 64 lines tall. */
51494 info->sprite.flags = FB_PIXMAP_IO;
51495
51496 - info->fbops->fb_cursor = atyfb_cursor;
51497 + pax_open_kernel();
51498 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
51499 + pax_close_kernel();
51500
51501 return 0;
51502 }
51503 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
51504 index 7592cc2..92feb56 100644
51505 --- a/drivers/video/backlight/kb3886_bl.c
51506 +++ b/drivers/video/backlight/kb3886_bl.c
51507 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
51508 static unsigned long kb3886bl_flags;
51509 #define KB3886BL_SUSPENDED 0x01
51510
51511 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
51512 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
51513 {
51514 .ident = "Sahara Touch-iT",
51515 .matches = {
51516 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
51517 index 900aa4e..6d49418 100644
51518 --- a/drivers/video/fb_defio.c
51519 +++ b/drivers/video/fb_defio.c
51520 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
51521
51522 BUG_ON(!fbdefio);
51523 mutex_init(&fbdefio->lock);
51524 - info->fbops->fb_mmap = fb_deferred_io_mmap;
51525 + pax_open_kernel();
51526 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
51527 + pax_close_kernel();
51528 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
51529 INIT_LIST_HEAD(&fbdefio->pagelist);
51530 if (fbdefio->delay == 0) /* set a default of 1 s */
51531 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
51532 page->mapping = NULL;
51533 }
51534
51535 - info->fbops->fb_mmap = NULL;
51536 + *(void **)&info->fbops->fb_mmap = NULL;
51537 mutex_destroy(&fbdefio->lock);
51538 }
51539 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
51540 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
51541 index 010d191..7b8235a 100644
51542 --- a/drivers/video/fbmem.c
51543 +++ b/drivers/video/fbmem.c
51544 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51545 image->dx += image->width + 8;
51546 }
51547 } else if (rotate == FB_ROTATE_UD) {
51548 - for (x = 0; x < num && image->dx >= 0; x++) {
51549 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
51550 info->fbops->fb_imageblit(info, image);
51551 image->dx -= image->width + 8;
51552 }
51553 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51554 image->dy += image->height + 8;
51555 }
51556 } else if (rotate == FB_ROTATE_CCW) {
51557 - for (x = 0; x < num && image->dy >= 0; x++) {
51558 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
51559 info->fbops->fb_imageblit(info, image);
51560 image->dy -= image->height + 8;
51561 }
51562 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
51563 return -EFAULT;
51564 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
51565 return -EINVAL;
51566 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
51567 + if (con2fb.framebuffer >= FB_MAX)
51568 return -EINVAL;
51569 if (!registered_fb[con2fb.framebuffer])
51570 request_module("fb%d", con2fb.framebuffer);
51571 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
51572 __u32 data;
51573 int err;
51574
51575 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
51576 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
51577
51578 data = (__u32) (unsigned long) fix->smem_start;
51579 err |= put_user(data, &fix32->smem_start);
51580 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
51581 index 130708f..cdac1a9 100644
51582 --- a/drivers/video/hyperv_fb.c
51583 +++ b/drivers/video/hyperv_fb.c
51584 @@ -233,7 +233,7 @@ static uint screen_fb_size;
51585 static inline int synthvid_send(struct hv_device *hdev,
51586 struct synthvid_msg *msg)
51587 {
51588 - static atomic64_t request_id = ATOMIC64_INIT(0);
51589 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
51590 int ret;
51591
51592 msg->pipe_hdr.type = PIPE_MSG_DATA;
51593 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
51594
51595 ret = vmbus_sendpacket(hdev->channel, msg,
51596 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
51597 - atomic64_inc_return(&request_id),
51598 + atomic64_inc_return_unchecked(&request_id),
51599 VM_PKT_DATA_INBAND, 0);
51600
51601 if (ret)
51602 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
51603 index 7672d2e..b56437f 100644
51604 --- a/drivers/video/i810/i810_accel.c
51605 +++ b/drivers/video/i810/i810_accel.c
51606 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
51607 }
51608 }
51609 printk("ringbuffer lockup!!!\n");
51610 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
51611 i810_report_error(mmio);
51612 par->dev_flags |= LOCKUP;
51613 info->pixmap.scan_align = 1;
51614 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
51615 index 3c14e43..2630570 100644
51616 --- a/drivers/video/logo/logo_linux_clut224.ppm
51617 +++ b/drivers/video/logo/logo_linux_clut224.ppm
51618 @@ -2,1603 +2,1123 @@ P3
51619 # Standard 224-color Linux logo
51620 80 80
51621 255
51622 - 0 0 0 0 0 0 0 0 0 0 0 0
51623 - 0 0 0 0 0 0 0 0 0 0 0 0
51624 - 0 0 0 0 0 0 0 0 0 0 0 0
51625 - 0 0 0 0 0 0 0 0 0 0 0 0
51626 - 0 0 0 0 0 0 0 0 0 0 0 0
51627 - 0 0 0 0 0 0 0 0 0 0 0 0
51628 - 0 0 0 0 0 0 0 0 0 0 0 0
51629 - 0 0 0 0 0 0 0 0 0 0 0 0
51630 - 0 0 0 0 0 0 0 0 0 0 0 0
51631 - 6 6 6 6 6 6 10 10 10 10 10 10
51632 - 10 10 10 6 6 6 6 6 6 6 6 6
51633 - 0 0 0 0 0 0 0 0 0 0 0 0
51634 - 0 0 0 0 0 0 0 0 0 0 0 0
51635 - 0 0 0 0 0 0 0 0 0 0 0 0
51636 - 0 0 0 0 0 0 0 0 0 0 0 0
51637 - 0 0 0 0 0 0 0 0 0 0 0 0
51638 - 0 0 0 0 0 0 0 0 0 0 0 0
51639 - 0 0 0 0 0 0 0 0 0 0 0 0
51640 - 0 0 0 0 0 0 0 0 0 0 0 0
51641 - 0 0 0 0 0 0 0 0 0 0 0 0
51642 - 0 0 0 0 0 0 0 0 0 0 0 0
51643 - 0 0 0 0 0 0 0 0 0 0 0 0
51644 - 0 0 0 0 0 0 0 0 0 0 0 0
51645 - 0 0 0 0 0 0 0 0 0 0 0 0
51646 - 0 0 0 0 0 0 0 0 0 0 0 0
51647 - 0 0 0 0 0 0 0 0 0 0 0 0
51648 - 0 0 0 0 0 0 0 0 0 0 0 0
51649 - 0 0 0 0 0 0 0 0 0 0 0 0
51650 - 0 0 0 6 6 6 10 10 10 14 14 14
51651 - 22 22 22 26 26 26 30 30 30 34 34 34
51652 - 30 30 30 30 30 30 26 26 26 18 18 18
51653 - 14 14 14 10 10 10 6 6 6 0 0 0
51654 - 0 0 0 0 0 0 0 0 0 0 0 0
51655 - 0 0 0 0 0 0 0 0 0 0 0 0
51656 - 0 0 0 0 0 0 0 0 0 0 0 0
51657 - 0 0 0 0 0 0 0 0 0 0 0 0
51658 - 0 0 0 0 0 0 0 0 0 0 0 0
51659 - 0 0 0 0 0 0 0 0 0 0 0 0
51660 - 0 0 0 0 0 0 0 0 0 0 0 0
51661 - 0 0 0 0 0 0 0 0 0 0 0 0
51662 - 0 0 0 0 0 0 0 0 0 0 0 0
51663 - 0 0 0 0 0 1 0 0 1 0 0 0
51664 - 0 0 0 0 0 0 0 0 0 0 0 0
51665 - 0 0 0 0 0 0 0 0 0 0 0 0
51666 - 0 0 0 0 0 0 0 0 0 0 0 0
51667 - 0 0 0 0 0 0 0 0 0 0 0 0
51668 - 0 0 0 0 0 0 0 0 0 0 0 0
51669 - 0 0 0 0 0 0 0 0 0 0 0 0
51670 - 6 6 6 14 14 14 26 26 26 42 42 42
51671 - 54 54 54 66 66 66 78 78 78 78 78 78
51672 - 78 78 78 74 74 74 66 66 66 54 54 54
51673 - 42 42 42 26 26 26 18 18 18 10 10 10
51674 - 6 6 6 0 0 0 0 0 0 0 0 0
51675 - 0 0 0 0 0 0 0 0 0 0 0 0
51676 - 0 0 0 0 0 0 0 0 0 0 0 0
51677 - 0 0 0 0 0 0 0 0 0 0 0 0
51678 - 0 0 0 0 0 0 0 0 0 0 0 0
51679 - 0 0 0 0 0 0 0 0 0 0 0 0
51680 - 0 0 0 0 0 0 0 0 0 0 0 0
51681 - 0 0 0 0 0 0 0 0 0 0 0 0
51682 - 0 0 0 0 0 0 0 0 0 0 0 0
51683 - 0 0 1 0 0 0 0 0 0 0 0 0
51684 - 0 0 0 0 0 0 0 0 0 0 0 0
51685 - 0 0 0 0 0 0 0 0 0 0 0 0
51686 - 0 0 0 0 0 0 0 0 0 0 0 0
51687 - 0 0 0 0 0 0 0 0 0 0 0 0
51688 - 0 0 0 0 0 0 0 0 0 0 0 0
51689 - 0 0 0 0 0 0 0 0 0 10 10 10
51690 - 22 22 22 42 42 42 66 66 66 86 86 86
51691 - 66 66 66 38 38 38 38 38 38 22 22 22
51692 - 26 26 26 34 34 34 54 54 54 66 66 66
51693 - 86 86 86 70 70 70 46 46 46 26 26 26
51694 - 14 14 14 6 6 6 0 0 0 0 0 0
51695 - 0 0 0 0 0 0 0 0 0 0 0 0
51696 - 0 0 0 0 0 0 0 0 0 0 0 0
51697 - 0 0 0 0 0 0 0 0 0 0 0 0
51698 - 0 0 0 0 0 0 0 0 0 0 0 0
51699 - 0 0 0 0 0 0 0 0 0 0 0 0
51700 - 0 0 0 0 0 0 0 0 0 0 0 0
51701 - 0 0 0 0 0 0 0 0 0 0 0 0
51702 - 0 0 0 0 0 0 0 0 0 0 0 0
51703 - 0 0 1 0 0 1 0 0 1 0 0 0
51704 - 0 0 0 0 0 0 0 0 0 0 0 0
51705 - 0 0 0 0 0 0 0 0 0 0 0 0
51706 - 0 0 0 0 0 0 0 0 0 0 0 0
51707 - 0 0 0 0 0 0 0 0 0 0 0 0
51708 - 0 0 0 0 0 0 0 0 0 0 0 0
51709 - 0 0 0 0 0 0 10 10 10 26 26 26
51710 - 50 50 50 82 82 82 58 58 58 6 6 6
51711 - 2 2 6 2 2 6 2 2 6 2 2 6
51712 - 2 2 6 2 2 6 2 2 6 2 2 6
51713 - 6 6 6 54 54 54 86 86 86 66 66 66
51714 - 38 38 38 18 18 18 6 6 6 0 0 0
51715 - 0 0 0 0 0 0 0 0 0 0 0 0
51716 - 0 0 0 0 0 0 0 0 0 0 0 0
51717 - 0 0 0 0 0 0 0 0 0 0 0 0
51718 - 0 0 0 0 0 0 0 0 0 0 0 0
51719 - 0 0 0 0 0 0 0 0 0 0 0 0
51720 - 0 0 0 0 0 0 0 0 0 0 0 0
51721 - 0 0 0 0 0 0 0 0 0 0 0 0
51722 - 0 0 0 0 0 0 0 0 0 0 0 0
51723 - 0 0 0 0 0 0 0 0 0 0 0 0
51724 - 0 0 0 0 0 0 0 0 0 0 0 0
51725 - 0 0 0 0 0 0 0 0 0 0 0 0
51726 - 0 0 0 0 0 0 0 0 0 0 0 0
51727 - 0 0 0 0 0 0 0 0 0 0 0 0
51728 - 0 0 0 0 0 0 0 0 0 0 0 0
51729 - 0 0 0 6 6 6 22 22 22 50 50 50
51730 - 78 78 78 34 34 34 2 2 6 2 2 6
51731 - 2 2 6 2 2 6 2 2 6 2 2 6
51732 - 2 2 6 2 2 6 2 2 6 2 2 6
51733 - 2 2 6 2 2 6 6 6 6 70 70 70
51734 - 78 78 78 46 46 46 22 22 22 6 6 6
51735 - 0 0 0 0 0 0 0 0 0 0 0 0
51736 - 0 0 0 0 0 0 0 0 0 0 0 0
51737 - 0 0 0 0 0 0 0 0 0 0 0 0
51738 - 0 0 0 0 0 0 0 0 0 0 0 0
51739 - 0 0 0 0 0 0 0 0 0 0 0 0
51740 - 0 0 0 0 0 0 0 0 0 0 0 0
51741 - 0 0 0 0 0 0 0 0 0 0 0 0
51742 - 0 0 0 0 0 0 0 0 0 0 0 0
51743 - 0 0 1 0 0 1 0 0 1 0 0 0
51744 - 0 0 0 0 0 0 0 0 0 0 0 0
51745 - 0 0 0 0 0 0 0 0 0 0 0 0
51746 - 0 0 0 0 0 0 0 0 0 0 0 0
51747 - 0 0 0 0 0 0 0 0 0 0 0 0
51748 - 0 0 0 0 0 0 0 0 0 0 0 0
51749 - 6 6 6 18 18 18 42 42 42 82 82 82
51750 - 26 26 26 2 2 6 2 2 6 2 2 6
51751 - 2 2 6 2 2 6 2 2 6 2 2 6
51752 - 2 2 6 2 2 6 2 2 6 14 14 14
51753 - 46 46 46 34 34 34 6 6 6 2 2 6
51754 - 42 42 42 78 78 78 42 42 42 18 18 18
51755 - 6 6 6 0 0 0 0 0 0 0 0 0
51756 - 0 0 0 0 0 0 0 0 0 0 0 0
51757 - 0 0 0 0 0 0 0 0 0 0 0 0
51758 - 0 0 0 0 0 0 0 0 0 0 0 0
51759 - 0 0 0 0 0 0 0 0 0 0 0 0
51760 - 0 0 0 0 0 0 0 0 0 0 0 0
51761 - 0 0 0 0 0 0 0 0 0 0 0 0
51762 - 0 0 0 0 0 0 0 0 0 0 0 0
51763 - 0 0 1 0 0 0 0 0 1 0 0 0
51764 - 0 0 0 0 0 0 0 0 0 0 0 0
51765 - 0 0 0 0 0 0 0 0 0 0 0 0
51766 - 0 0 0 0 0 0 0 0 0 0 0 0
51767 - 0 0 0 0 0 0 0 0 0 0 0 0
51768 - 0 0 0 0 0 0 0 0 0 0 0 0
51769 - 10 10 10 30 30 30 66 66 66 58 58 58
51770 - 2 2 6 2 2 6 2 2 6 2 2 6
51771 - 2 2 6 2 2 6 2 2 6 2 2 6
51772 - 2 2 6 2 2 6 2 2 6 26 26 26
51773 - 86 86 86 101 101 101 46 46 46 10 10 10
51774 - 2 2 6 58 58 58 70 70 70 34 34 34
51775 - 10 10 10 0 0 0 0 0 0 0 0 0
51776 - 0 0 0 0 0 0 0 0 0 0 0 0
51777 - 0 0 0 0 0 0 0 0 0 0 0 0
51778 - 0 0 0 0 0 0 0 0 0 0 0 0
51779 - 0 0 0 0 0 0 0 0 0 0 0 0
51780 - 0 0 0 0 0 0 0 0 0 0 0 0
51781 - 0 0 0 0 0 0 0 0 0 0 0 0
51782 - 0 0 0 0 0 0 0 0 0 0 0 0
51783 - 0 0 1 0 0 1 0 0 1 0 0 0
51784 - 0 0 0 0 0 0 0 0 0 0 0 0
51785 - 0 0 0 0 0 0 0 0 0 0 0 0
51786 - 0 0 0 0 0 0 0 0 0 0 0 0
51787 - 0 0 0 0 0 0 0 0 0 0 0 0
51788 - 0 0 0 0 0 0 0 0 0 0 0 0
51789 - 14 14 14 42 42 42 86 86 86 10 10 10
51790 - 2 2 6 2 2 6 2 2 6 2 2 6
51791 - 2 2 6 2 2 6 2 2 6 2 2 6
51792 - 2 2 6 2 2 6 2 2 6 30 30 30
51793 - 94 94 94 94 94 94 58 58 58 26 26 26
51794 - 2 2 6 6 6 6 78 78 78 54 54 54
51795 - 22 22 22 6 6 6 0 0 0 0 0 0
51796 - 0 0 0 0 0 0 0 0 0 0 0 0
51797 - 0 0 0 0 0 0 0 0 0 0 0 0
51798 - 0 0 0 0 0 0 0 0 0 0 0 0
51799 - 0 0 0 0 0 0 0 0 0 0 0 0
51800 - 0 0 0 0 0 0 0 0 0 0 0 0
51801 - 0 0 0 0 0 0 0 0 0 0 0 0
51802 - 0 0 0 0 0 0 0 0 0 0 0 0
51803 - 0 0 0 0 0 0 0 0 0 0 0 0
51804 - 0 0 0 0 0 0 0 0 0 0 0 0
51805 - 0 0 0 0 0 0 0 0 0 0 0 0
51806 - 0 0 0 0 0 0 0 0 0 0 0 0
51807 - 0 0 0 0 0 0 0 0 0 0 0 0
51808 - 0 0 0 0 0 0 0 0 0 6 6 6
51809 - 22 22 22 62 62 62 62 62 62 2 2 6
51810 - 2 2 6 2 2 6 2 2 6 2 2 6
51811 - 2 2 6 2 2 6 2 2 6 2 2 6
51812 - 2 2 6 2 2 6 2 2 6 26 26 26
51813 - 54 54 54 38 38 38 18 18 18 10 10 10
51814 - 2 2 6 2 2 6 34 34 34 82 82 82
51815 - 38 38 38 14 14 14 0 0 0 0 0 0
51816 - 0 0 0 0 0 0 0 0 0 0 0 0
51817 - 0 0 0 0 0 0 0 0 0 0 0 0
51818 - 0 0 0 0 0 0 0 0 0 0 0 0
51819 - 0 0 0 0 0 0 0 0 0 0 0 0
51820 - 0 0 0 0 0 0 0 0 0 0 0 0
51821 - 0 0 0 0 0 0 0 0 0 0 0 0
51822 - 0 0 0 0 0 0 0 0 0 0 0 0
51823 - 0 0 0 0 0 1 0 0 1 0 0 0
51824 - 0 0 0 0 0 0 0 0 0 0 0 0
51825 - 0 0 0 0 0 0 0 0 0 0 0 0
51826 - 0 0 0 0 0 0 0 0 0 0 0 0
51827 - 0 0 0 0 0 0 0 0 0 0 0 0
51828 - 0 0 0 0 0 0 0 0 0 6 6 6
51829 - 30 30 30 78 78 78 30 30 30 2 2 6
51830 - 2 2 6 2 2 6 2 2 6 2 2 6
51831 - 2 2 6 2 2 6 2 2 6 2 2 6
51832 - 2 2 6 2 2 6 2 2 6 10 10 10
51833 - 10 10 10 2 2 6 2 2 6 2 2 6
51834 - 2 2 6 2 2 6 2 2 6 78 78 78
51835 - 50 50 50 18 18 18 6 6 6 0 0 0
51836 - 0 0 0 0 0 0 0 0 0 0 0 0
51837 - 0 0 0 0 0 0 0 0 0 0 0 0
51838 - 0 0 0 0 0 0 0 0 0 0 0 0
51839 - 0 0 0 0 0 0 0 0 0 0 0 0
51840 - 0 0 0 0 0 0 0 0 0 0 0 0
51841 - 0 0 0 0 0 0 0 0 0 0 0 0
51842 - 0 0 0 0 0 0 0 0 0 0 0 0
51843 - 0 0 1 0 0 0 0 0 0 0 0 0
51844 - 0 0 0 0 0 0 0 0 0 0 0 0
51845 - 0 0 0 0 0 0 0 0 0 0 0 0
51846 - 0 0 0 0 0 0 0 0 0 0 0 0
51847 - 0 0 0 0 0 0 0 0 0 0 0 0
51848 - 0 0 0 0 0 0 0 0 0 10 10 10
51849 - 38 38 38 86 86 86 14 14 14 2 2 6
51850 - 2 2 6 2 2 6 2 2 6 2 2 6
51851 - 2 2 6 2 2 6 2 2 6 2 2 6
51852 - 2 2 6 2 2 6 2 2 6 2 2 6
51853 - 2 2 6 2 2 6 2 2 6 2 2 6
51854 - 2 2 6 2 2 6 2 2 6 54 54 54
51855 - 66 66 66 26 26 26 6 6 6 0 0 0
51856 - 0 0 0 0 0 0 0 0 0 0 0 0
51857 - 0 0 0 0 0 0 0 0 0 0 0 0
51858 - 0 0 0 0 0 0 0 0 0 0 0 0
51859 - 0 0 0 0 0 0 0 0 0 0 0 0
51860 - 0 0 0 0 0 0 0 0 0 0 0 0
51861 - 0 0 0 0 0 0 0 0 0 0 0 0
51862 - 0 0 0 0 0 0 0 0 0 0 0 0
51863 - 0 0 0 0 0 1 0 0 1 0 0 0
51864 - 0 0 0 0 0 0 0 0 0 0 0 0
51865 - 0 0 0 0 0 0 0 0 0 0 0 0
51866 - 0 0 0 0 0 0 0 0 0 0 0 0
51867 - 0 0 0 0 0 0 0 0 0 0 0 0
51868 - 0 0 0 0 0 0 0 0 0 14 14 14
51869 - 42 42 42 82 82 82 2 2 6 2 2 6
51870 - 2 2 6 6 6 6 10 10 10 2 2 6
51871 - 2 2 6 2 2 6 2 2 6 2 2 6
51872 - 2 2 6 2 2 6 2 2 6 6 6 6
51873 - 14 14 14 10 10 10 2 2 6 2 2 6
51874 - 2 2 6 2 2 6 2 2 6 18 18 18
51875 - 82 82 82 34 34 34 10 10 10 0 0 0
51876 - 0 0 0 0 0 0 0 0 0 0 0 0
51877 - 0 0 0 0 0 0 0 0 0 0 0 0
51878 - 0 0 0 0 0 0 0 0 0 0 0 0
51879 - 0 0 0 0 0 0 0 0 0 0 0 0
51880 - 0 0 0 0 0 0 0 0 0 0 0 0
51881 - 0 0 0 0 0 0 0 0 0 0 0 0
51882 - 0 0 0 0 0 0 0 0 0 0 0 0
51883 - 0 0 1 0 0 0 0 0 0 0 0 0
51884 - 0 0 0 0 0 0 0 0 0 0 0 0
51885 - 0 0 0 0 0 0 0 0 0 0 0 0
51886 - 0 0 0 0 0 0 0 0 0 0 0 0
51887 - 0 0 0 0 0 0 0 0 0 0 0 0
51888 - 0 0 0 0 0 0 0 0 0 14 14 14
51889 - 46 46 46 86 86 86 2 2 6 2 2 6
51890 - 6 6 6 6 6 6 22 22 22 34 34 34
51891 - 6 6 6 2 2 6 2 2 6 2 2 6
51892 - 2 2 6 2 2 6 18 18 18 34 34 34
51893 - 10 10 10 50 50 50 22 22 22 2 2 6
51894 - 2 2 6 2 2 6 2 2 6 10 10 10
51895 - 86 86 86 42 42 42 14 14 14 0 0 0
51896 - 0 0 0 0 0 0 0 0 0 0 0 0
51897 - 0 0 0 0 0 0 0 0 0 0 0 0
51898 - 0 0 0 0 0 0 0 0 0 0 0 0
51899 - 0 0 0 0 0 0 0 0 0 0 0 0
51900 - 0 0 0 0 0 0 0 0 0 0 0 0
51901 - 0 0 0 0 0 0 0 0 0 0 0 0
51902 - 0 0 0 0 0 0 0 0 0 0 0 0
51903 - 0 0 1 0 0 1 0 0 1 0 0 0
51904 - 0 0 0 0 0 0 0 0 0 0 0 0
51905 - 0 0 0 0 0 0 0 0 0 0 0 0
51906 - 0 0 0 0 0 0 0 0 0 0 0 0
51907 - 0 0 0 0 0 0 0 0 0 0 0 0
51908 - 0 0 0 0 0 0 0 0 0 14 14 14
51909 - 46 46 46 86 86 86 2 2 6 2 2 6
51910 - 38 38 38 116 116 116 94 94 94 22 22 22
51911 - 22 22 22 2 2 6 2 2 6 2 2 6
51912 - 14 14 14 86 86 86 138 138 138 162 162 162
51913 -154 154 154 38 38 38 26 26 26 6 6 6
51914 - 2 2 6 2 2 6 2 2 6 2 2 6
51915 - 86 86 86 46 46 46 14 14 14 0 0 0
51916 - 0 0 0 0 0 0 0 0 0 0 0 0
51917 - 0 0 0 0 0 0 0 0 0 0 0 0
51918 - 0 0 0 0 0 0 0 0 0 0 0 0
51919 - 0 0 0 0 0 0 0 0 0 0 0 0
51920 - 0 0 0 0 0 0 0 0 0 0 0 0
51921 - 0 0 0 0 0 0 0 0 0 0 0 0
51922 - 0 0 0 0 0 0 0 0 0 0 0 0
51923 - 0 0 0 0 0 0 0 0 0 0 0 0
51924 - 0 0 0 0 0 0 0 0 0 0 0 0
51925 - 0 0 0 0 0 0 0 0 0 0 0 0
51926 - 0 0 0 0 0 0 0 0 0 0 0 0
51927 - 0 0 0 0 0 0 0 0 0 0 0 0
51928 - 0 0 0 0 0 0 0 0 0 14 14 14
51929 - 46 46 46 86 86 86 2 2 6 14 14 14
51930 -134 134 134 198 198 198 195 195 195 116 116 116
51931 - 10 10 10 2 2 6 2 2 6 6 6 6
51932 -101 98 89 187 187 187 210 210 210 218 218 218
51933 -214 214 214 134 134 134 14 14 14 6 6 6
51934 - 2 2 6 2 2 6 2 2 6 2 2 6
51935 - 86 86 86 50 50 50 18 18 18 6 6 6
51936 - 0 0 0 0 0 0 0 0 0 0 0 0
51937 - 0 0 0 0 0 0 0 0 0 0 0 0
51938 - 0 0 0 0 0 0 0 0 0 0 0 0
51939 - 0 0 0 0 0 0 0 0 0 0 0 0
51940 - 0 0 0 0 0 0 0 0 0 0 0 0
51941 - 0 0 0 0 0 0 0 0 0 0 0 0
51942 - 0 0 0 0 0 0 0 0 1 0 0 0
51943 - 0 0 1 0 0 1 0 0 1 0 0 0
51944 - 0 0 0 0 0 0 0 0 0 0 0 0
51945 - 0 0 0 0 0 0 0 0 0 0 0 0
51946 - 0 0 0 0 0 0 0 0 0 0 0 0
51947 - 0 0 0 0 0 0 0 0 0 0 0 0
51948 - 0 0 0 0 0 0 0 0 0 14 14 14
51949 - 46 46 46 86 86 86 2 2 6 54 54 54
51950 -218 218 218 195 195 195 226 226 226 246 246 246
51951 - 58 58 58 2 2 6 2 2 6 30 30 30
51952 -210 210 210 253 253 253 174 174 174 123 123 123
51953 -221 221 221 234 234 234 74 74 74 2 2 6
51954 - 2 2 6 2 2 6 2 2 6 2 2 6
51955 - 70 70 70 58 58 58 22 22 22 6 6 6
51956 - 0 0 0 0 0 0 0 0 0 0 0 0
51957 - 0 0 0 0 0 0 0 0 0 0 0 0
51958 - 0 0 0 0 0 0 0 0 0 0 0 0
51959 - 0 0 0 0 0 0 0 0 0 0 0 0
51960 - 0 0 0 0 0 0 0 0 0 0 0 0
51961 - 0 0 0 0 0 0 0 0 0 0 0 0
51962 - 0 0 0 0 0 0 0 0 0 0 0 0
51963 - 0 0 0 0 0 0 0 0 0 0 0 0
51964 - 0 0 0 0 0 0 0 0 0 0 0 0
51965 - 0 0 0 0 0 0 0 0 0 0 0 0
51966 - 0 0 0 0 0 0 0 0 0 0 0 0
51967 - 0 0 0 0 0 0 0 0 0 0 0 0
51968 - 0 0 0 0 0 0 0 0 0 14 14 14
51969 - 46 46 46 82 82 82 2 2 6 106 106 106
51970 -170 170 170 26 26 26 86 86 86 226 226 226
51971 -123 123 123 10 10 10 14 14 14 46 46 46
51972 -231 231 231 190 190 190 6 6 6 70 70 70
51973 - 90 90 90 238 238 238 158 158 158 2 2 6
51974 - 2 2 6 2 2 6 2 2 6 2 2 6
51975 - 70 70 70 58 58 58 22 22 22 6 6 6
51976 - 0 0 0 0 0 0 0 0 0 0 0 0
51977 - 0 0 0 0 0 0 0 0 0 0 0 0
51978 - 0 0 0 0 0 0 0 0 0 0 0 0
51979 - 0 0 0 0 0 0 0 0 0 0 0 0
51980 - 0 0 0 0 0 0 0 0 0 0 0 0
51981 - 0 0 0 0 0 0 0 0 0 0 0 0
51982 - 0 0 0 0 0 0 0 0 1 0 0 0
51983 - 0 0 1 0 0 1 0 0 1 0 0 0
51984 - 0 0 0 0 0 0 0 0 0 0 0 0
51985 - 0 0 0 0 0 0 0 0 0 0 0 0
51986 - 0 0 0 0 0 0 0 0 0 0 0 0
51987 - 0 0 0 0 0 0 0 0 0 0 0 0
51988 - 0 0 0 0 0 0 0 0 0 14 14 14
51989 - 42 42 42 86 86 86 6 6 6 116 116 116
51990 -106 106 106 6 6 6 70 70 70 149 149 149
51991 -128 128 128 18 18 18 38 38 38 54 54 54
51992 -221 221 221 106 106 106 2 2 6 14 14 14
51993 - 46 46 46 190 190 190 198 198 198 2 2 6
51994 - 2 2 6 2 2 6 2 2 6 2 2 6
51995 - 74 74 74 62 62 62 22 22 22 6 6 6
51996 - 0 0 0 0 0 0 0 0 0 0 0 0
51997 - 0 0 0 0 0 0 0 0 0 0 0 0
51998 - 0 0 0 0 0 0 0 0 0 0 0 0
51999 - 0 0 0 0 0 0 0 0 0 0 0 0
52000 - 0 0 0 0 0 0 0 0 0 0 0 0
52001 - 0 0 0 0 0 0 0 0 0 0 0 0
52002 - 0 0 0 0 0 0 0 0 1 0 0 0
52003 - 0 0 1 0 0 0 0 0 1 0 0 0
52004 - 0 0 0 0 0 0 0 0 0 0 0 0
52005 - 0 0 0 0 0 0 0 0 0 0 0 0
52006 - 0 0 0 0 0 0 0 0 0 0 0 0
52007 - 0 0 0 0 0 0 0 0 0 0 0 0
52008 - 0 0 0 0 0 0 0 0 0 14 14 14
52009 - 42 42 42 94 94 94 14 14 14 101 101 101
52010 -128 128 128 2 2 6 18 18 18 116 116 116
52011 -118 98 46 121 92 8 121 92 8 98 78 10
52012 -162 162 162 106 106 106 2 2 6 2 2 6
52013 - 2 2 6 195 195 195 195 195 195 6 6 6
52014 - 2 2 6 2 2 6 2 2 6 2 2 6
52015 - 74 74 74 62 62 62 22 22 22 6 6 6
52016 - 0 0 0 0 0 0 0 0 0 0 0 0
52017 - 0 0 0 0 0 0 0 0 0 0 0 0
52018 - 0 0 0 0 0 0 0 0 0 0 0 0
52019 - 0 0 0 0 0 0 0 0 0 0 0 0
52020 - 0 0 0 0 0 0 0 0 0 0 0 0
52021 - 0 0 0 0 0 0 0 0 0 0 0 0
52022 - 0 0 0 0 0 0 0 0 1 0 0 1
52023 - 0 0 1 0 0 0 0 0 1 0 0 0
52024 - 0 0 0 0 0 0 0 0 0 0 0 0
52025 - 0 0 0 0 0 0 0 0 0 0 0 0
52026 - 0 0 0 0 0 0 0 0 0 0 0 0
52027 - 0 0 0 0 0 0 0 0 0 0 0 0
52028 - 0 0 0 0 0 0 0 0 0 10 10 10
52029 - 38 38 38 90 90 90 14 14 14 58 58 58
52030 -210 210 210 26 26 26 54 38 6 154 114 10
52031 -226 170 11 236 186 11 225 175 15 184 144 12
52032 -215 174 15 175 146 61 37 26 9 2 2 6
52033 - 70 70 70 246 246 246 138 138 138 2 2 6
52034 - 2 2 6 2 2 6 2 2 6 2 2 6
52035 - 70 70 70 66 66 66 26 26 26 6 6 6
52036 - 0 0 0 0 0 0 0 0 0 0 0 0
52037 - 0 0 0 0 0 0 0 0 0 0 0 0
52038 - 0 0 0 0 0 0 0 0 0 0 0 0
52039 - 0 0 0 0 0 0 0 0 0 0 0 0
52040 - 0 0 0 0 0 0 0 0 0 0 0 0
52041 - 0 0 0 0 0 0 0 0 0 0 0 0
52042 - 0 0 0 0 0 0 0 0 0 0 0 0
52043 - 0 0 0 0 0 0 0 0 0 0 0 0
52044 - 0 0 0 0 0 0 0 0 0 0 0 0
52045 - 0 0 0 0 0 0 0 0 0 0 0 0
52046 - 0 0 0 0 0 0 0 0 0 0 0 0
52047 - 0 0 0 0 0 0 0 0 0 0 0 0
52048 - 0 0 0 0 0 0 0 0 0 10 10 10
52049 - 38 38 38 86 86 86 14 14 14 10 10 10
52050 -195 195 195 188 164 115 192 133 9 225 175 15
52051 -239 182 13 234 190 10 232 195 16 232 200 30
52052 -245 207 45 241 208 19 232 195 16 184 144 12
52053 -218 194 134 211 206 186 42 42 42 2 2 6
52054 - 2 2 6 2 2 6 2 2 6 2 2 6
52055 - 50 50 50 74 74 74 30 30 30 6 6 6
52056 - 0 0 0 0 0 0 0 0 0 0 0 0
52057 - 0 0 0 0 0 0 0 0 0 0 0 0
52058 - 0 0 0 0 0 0 0 0 0 0 0 0
52059 - 0 0 0 0 0 0 0 0 0 0 0 0
52060 - 0 0 0 0 0 0 0 0 0 0 0 0
52061 - 0 0 0 0 0 0 0 0 0 0 0 0
52062 - 0 0 0 0 0 0 0 0 0 0 0 0
52063 - 0 0 0 0 0 0 0 0 0 0 0 0
52064 - 0 0 0 0 0 0 0 0 0 0 0 0
52065 - 0 0 0 0 0 0 0 0 0 0 0 0
52066 - 0 0 0 0 0 0 0 0 0 0 0 0
52067 - 0 0 0 0 0 0 0 0 0 0 0 0
52068 - 0 0 0 0 0 0 0 0 0 10 10 10
52069 - 34 34 34 86 86 86 14 14 14 2 2 6
52070 -121 87 25 192 133 9 219 162 10 239 182 13
52071 -236 186 11 232 195 16 241 208 19 244 214 54
52072 -246 218 60 246 218 38 246 215 20 241 208 19
52073 -241 208 19 226 184 13 121 87 25 2 2 6
52074 - 2 2 6 2 2 6 2 2 6 2 2 6
52075 - 50 50 50 82 82 82 34 34 34 10 10 10
52076 - 0 0 0 0 0 0 0 0 0 0 0 0
52077 - 0 0 0 0 0 0 0 0 0 0 0 0
52078 - 0 0 0 0 0 0 0 0 0 0 0 0
52079 - 0 0 0 0 0 0 0 0 0 0 0 0
52080 - 0 0 0 0 0 0 0 0 0 0 0 0
52081 - 0 0 0 0 0 0 0 0 0 0 0 0
52082 - 0 0 0 0 0 0 0 0 0 0 0 0
52083 - 0 0 0 0 0 0 0 0 0 0 0 0
52084 - 0 0 0 0 0 0 0 0 0 0 0 0
52085 - 0 0 0 0 0 0 0 0 0 0 0 0
52086 - 0 0 0 0 0 0 0 0 0 0 0 0
52087 - 0 0 0 0 0 0 0 0 0 0 0 0
52088 - 0 0 0 0 0 0 0 0 0 10 10 10
52089 - 34 34 34 82 82 82 30 30 30 61 42 6
52090 -180 123 7 206 145 10 230 174 11 239 182 13
52091 -234 190 10 238 202 15 241 208 19 246 218 74
52092 -246 218 38 246 215 20 246 215 20 246 215 20
52093 -226 184 13 215 174 15 184 144 12 6 6 6
52094 - 2 2 6 2 2 6 2 2 6 2 2 6
52095 - 26 26 26 94 94 94 42 42 42 14 14 14
52096 - 0 0 0 0 0 0 0 0 0 0 0 0
52097 - 0 0 0 0 0 0 0 0 0 0 0 0
52098 - 0 0 0 0 0 0 0 0 0 0 0 0
52099 - 0 0 0 0 0 0 0 0 0 0 0 0
52100 - 0 0 0 0 0 0 0 0 0 0 0 0
52101 - 0 0 0 0 0 0 0 0 0 0 0 0
52102 - 0 0 0 0 0 0 0 0 0 0 0 0
52103 - 0 0 0 0 0 0 0 0 0 0 0 0
52104 - 0 0 0 0 0 0 0 0 0 0 0 0
52105 - 0 0 0 0 0 0 0 0 0 0 0 0
52106 - 0 0 0 0 0 0 0 0 0 0 0 0
52107 - 0 0 0 0 0 0 0 0 0 0 0 0
52108 - 0 0 0 0 0 0 0 0 0 10 10 10
52109 - 30 30 30 78 78 78 50 50 50 104 69 6
52110 -192 133 9 216 158 10 236 178 12 236 186 11
52111 -232 195 16 241 208 19 244 214 54 245 215 43
52112 -246 215 20 246 215 20 241 208 19 198 155 10
52113 -200 144 11 216 158 10 156 118 10 2 2 6
52114 - 2 2 6 2 2 6 2 2 6 2 2 6
52115 - 6 6 6 90 90 90 54 54 54 18 18 18
52116 - 6 6 6 0 0 0 0 0 0 0 0 0
52117 - 0 0 0 0 0 0 0 0 0 0 0 0
52118 - 0 0 0 0 0 0 0 0 0 0 0 0
52119 - 0 0 0 0 0 0 0 0 0 0 0 0
52120 - 0 0 0 0 0 0 0 0 0 0 0 0
52121 - 0 0 0 0 0 0 0 0 0 0 0 0
52122 - 0 0 0 0 0 0 0 0 0 0 0 0
52123 - 0 0 0 0 0 0 0 0 0 0 0 0
52124 - 0 0 0 0 0 0 0 0 0 0 0 0
52125 - 0 0 0 0 0 0 0 0 0 0 0 0
52126 - 0 0 0 0 0 0 0 0 0 0 0 0
52127 - 0 0 0 0 0 0 0 0 0 0 0 0
52128 - 0 0 0 0 0 0 0 0 0 10 10 10
52129 - 30 30 30 78 78 78 46 46 46 22 22 22
52130 -137 92 6 210 162 10 239 182 13 238 190 10
52131 -238 202 15 241 208 19 246 215 20 246 215 20
52132 -241 208 19 203 166 17 185 133 11 210 150 10
52133 -216 158 10 210 150 10 102 78 10 2 2 6
52134 - 6 6 6 54 54 54 14 14 14 2 2 6
52135 - 2 2 6 62 62 62 74 74 74 30 30 30
52136 - 10 10 10 0 0 0 0 0 0 0 0 0
52137 - 0 0 0 0 0 0 0 0 0 0 0 0
52138 - 0 0 0 0 0 0 0 0 0 0 0 0
52139 - 0 0 0 0 0 0 0 0 0 0 0 0
52140 - 0 0 0 0 0 0 0 0 0 0 0 0
52141 - 0 0 0 0 0 0 0 0 0 0 0 0
52142 - 0 0 0 0 0 0 0 0 0 0 0 0
52143 - 0 0 0 0 0 0 0 0 0 0 0 0
52144 - 0 0 0 0 0 0 0 0 0 0 0 0
52145 - 0 0 0 0 0 0 0 0 0 0 0 0
52146 - 0 0 0 0 0 0 0 0 0 0 0 0
52147 - 0 0 0 0 0 0 0 0 0 0 0 0
52148 - 0 0 0 0 0 0 0 0 0 10 10 10
52149 - 34 34 34 78 78 78 50 50 50 6 6 6
52150 - 94 70 30 139 102 15 190 146 13 226 184 13
52151 -232 200 30 232 195 16 215 174 15 190 146 13
52152 -168 122 10 192 133 9 210 150 10 213 154 11
52153 -202 150 34 182 157 106 101 98 89 2 2 6
52154 - 2 2 6 78 78 78 116 116 116 58 58 58
52155 - 2 2 6 22 22 22 90 90 90 46 46 46
52156 - 18 18 18 6 6 6 0 0 0 0 0 0
52157 - 0 0 0 0 0 0 0 0 0 0 0 0
52158 - 0 0 0 0 0 0 0 0 0 0 0 0
52159 - 0 0 0 0 0 0 0 0 0 0 0 0
52160 - 0 0 0 0 0 0 0 0 0 0 0 0
52161 - 0 0 0 0 0 0 0 0 0 0 0 0
52162 - 0 0 0 0 0 0 0 0 0 0 0 0
52163 - 0 0 0 0 0 0 0 0 0 0 0 0
52164 - 0 0 0 0 0 0 0 0 0 0 0 0
52165 - 0 0 0 0 0 0 0 0 0 0 0 0
52166 - 0 0 0 0 0 0 0 0 0 0 0 0
52167 - 0 0 0 0 0 0 0 0 0 0 0 0
52168 - 0 0 0 0 0 0 0 0 0 10 10 10
52169 - 38 38 38 86 86 86 50 50 50 6 6 6
52170 -128 128 128 174 154 114 156 107 11 168 122 10
52171 -198 155 10 184 144 12 197 138 11 200 144 11
52172 -206 145 10 206 145 10 197 138 11 188 164 115
52173 -195 195 195 198 198 198 174 174 174 14 14 14
52174 - 2 2 6 22 22 22 116 116 116 116 116 116
52175 - 22 22 22 2 2 6 74 74 74 70 70 70
52176 - 30 30 30 10 10 10 0 0 0 0 0 0
52177 - 0 0 0 0 0 0 0 0 0 0 0 0
52178 - 0 0 0 0 0 0 0 0 0 0 0 0
52179 - 0 0 0 0 0 0 0 0 0 0 0 0
52180 - 0 0 0 0 0 0 0 0 0 0 0 0
52181 - 0 0 0 0 0 0 0 0 0 0 0 0
52182 - 0 0 0 0 0 0 0 0 0 0 0 0
52183 - 0 0 0 0 0 0 0 0 0 0 0 0
52184 - 0 0 0 0 0 0 0 0 0 0 0 0
52185 - 0 0 0 0 0 0 0 0 0 0 0 0
52186 - 0 0 0 0 0 0 0 0 0 0 0 0
52187 - 0 0 0 0 0 0 0 0 0 0 0 0
52188 - 0 0 0 0 0 0 6 6 6 18 18 18
52189 - 50 50 50 101 101 101 26 26 26 10 10 10
52190 -138 138 138 190 190 190 174 154 114 156 107 11
52191 -197 138 11 200 144 11 197 138 11 192 133 9
52192 -180 123 7 190 142 34 190 178 144 187 187 187
52193 -202 202 202 221 221 221 214 214 214 66 66 66
52194 - 2 2 6 2 2 6 50 50 50 62 62 62
52195 - 6 6 6 2 2 6 10 10 10 90 90 90
52196 - 50 50 50 18 18 18 6 6 6 0 0 0
52197 - 0 0 0 0 0 0 0 0 0 0 0 0
52198 - 0 0 0 0 0 0 0 0 0 0 0 0
52199 - 0 0 0 0 0 0 0 0 0 0 0 0
52200 - 0 0 0 0 0 0 0 0 0 0 0 0
52201 - 0 0 0 0 0 0 0 0 0 0 0 0
52202 - 0 0 0 0 0 0 0 0 0 0 0 0
52203 - 0 0 0 0 0 0 0 0 0 0 0 0
52204 - 0 0 0 0 0 0 0 0 0 0 0 0
52205 - 0 0 0 0 0 0 0 0 0 0 0 0
52206 - 0 0 0 0 0 0 0 0 0 0 0 0
52207 - 0 0 0 0 0 0 0 0 0 0 0 0
52208 - 0 0 0 0 0 0 10 10 10 34 34 34
52209 - 74 74 74 74 74 74 2 2 6 6 6 6
52210 -144 144 144 198 198 198 190 190 190 178 166 146
52211 -154 121 60 156 107 11 156 107 11 168 124 44
52212 -174 154 114 187 187 187 190 190 190 210 210 210
52213 -246 246 246 253 253 253 253 253 253 182 182 182
52214 - 6 6 6 2 2 6 2 2 6 2 2 6
52215 - 2 2 6 2 2 6 2 2 6 62 62 62
52216 - 74 74 74 34 34 34 14 14 14 0 0 0
52217 - 0 0 0 0 0 0 0 0 0 0 0 0
52218 - 0 0 0 0 0 0 0 0 0 0 0 0
52219 - 0 0 0 0 0 0 0 0 0 0 0 0
52220 - 0 0 0 0 0 0 0 0 0 0 0 0
52221 - 0 0 0 0 0 0 0 0 0 0 0 0
52222 - 0 0 0 0 0 0 0 0 0 0 0 0
52223 - 0 0 0 0 0 0 0 0 0 0 0 0
52224 - 0 0 0 0 0 0 0 0 0 0 0 0
52225 - 0 0 0 0 0 0 0 0 0 0 0 0
52226 - 0 0 0 0 0 0 0 0 0 0 0 0
52227 - 0 0 0 0 0 0 0 0 0 0 0 0
52228 - 0 0 0 10 10 10 22 22 22 54 54 54
52229 - 94 94 94 18 18 18 2 2 6 46 46 46
52230 -234 234 234 221 221 221 190 190 190 190 190 190
52231 -190 190 190 187 187 187 187 187 187 190 190 190
52232 -190 190 190 195 195 195 214 214 214 242 242 242
52233 -253 253 253 253 253 253 253 253 253 253 253 253
52234 - 82 82 82 2 2 6 2 2 6 2 2 6
52235 - 2 2 6 2 2 6 2 2 6 14 14 14
52236 - 86 86 86 54 54 54 22 22 22 6 6 6
52237 - 0 0 0 0 0 0 0 0 0 0 0 0
52238 - 0 0 0 0 0 0 0 0 0 0 0 0
52239 - 0 0 0 0 0 0 0 0 0 0 0 0
52240 - 0 0 0 0 0 0 0 0 0 0 0 0
52241 - 0 0 0 0 0 0 0 0 0 0 0 0
52242 - 0 0 0 0 0 0 0 0 0 0 0 0
52243 - 0 0 0 0 0 0 0 0 0 0 0 0
52244 - 0 0 0 0 0 0 0 0 0 0 0 0
52245 - 0 0 0 0 0 0 0 0 0 0 0 0
52246 - 0 0 0 0 0 0 0 0 0 0 0 0
52247 - 0 0 0 0 0 0 0 0 0 0 0 0
52248 - 6 6 6 18 18 18 46 46 46 90 90 90
52249 - 46 46 46 18 18 18 6 6 6 182 182 182
52250 -253 253 253 246 246 246 206 206 206 190 190 190
52251 -190 190 190 190 190 190 190 190 190 190 190 190
52252 -206 206 206 231 231 231 250 250 250 253 253 253
52253 -253 253 253 253 253 253 253 253 253 253 253 253
52254 -202 202 202 14 14 14 2 2 6 2 2 6
52255 - 2 2 6 2 2 6 2 2 6 2 2 6
52256 - 42 42 42 86 86 86 42 42 42 18 18 18
52257 - 6 6 6 0 0 0 0 0 0 0 0 0
52258 - 0 0 0 0 0 0 0 0 0 0 0 0
52259 - 0 0 0 0 0 0 0 0 0 0 0 0
52260 - 0 0 0 0 0 0 0 0 0 0 0 0
52261 - 0 0 0 0 0 0 0 0 0 0 0 0
52262 - 0 0 0 0 0 0 0 0 0 0 0 0
52263 - 0 0 0 0 0 0 0 0 0 0 0 0
52264 - 0 0 0 0 0 0 0 0 0 0 0 0
52265 - 0 0 0 0 0 0 0 0 0 0 0 0
52266 - 0 0 0 0 0 0 0 0 0 0 0 0
52267 - 0 0 0 0 0 0 0 0 0 6 6 6
52268 - 14 14 14 38 38 38 74 74 74 66 66 66
52269 - 2 2 6 6 6 6 90 90 90 250 250 250
52270 -253 253 253 253 253 253 238 238 238 198 198 198
52271 -190 190 190 190 190 190 195 195 195 221 221 221
52272 -246 246 246 253 253 253 253 253 253 253 253 253
52273 -253 253 253 253 253 253 253 253 253 253 253 253
52274 -253 253 253 82 82 82 2 2 6 2 2 6
52275 - 2 2 6 2 2 6 2 2 6 2 2 6
52276 - 2 2 6 78 78 78 70 70 70 34 34 34
52277 - 14 14 14 6 6 6 0 0 0 0 0 0
52278 - 0 0 0 0 0 0 0 0 0 0 0 0
52279 - 0 0 0 0 0 0 0 0 0 0 0 0
52280 - 0 0 0 0 0 0 0 0 0 0 0 0
52281 - 0 0 0 0 0 0 0 0 0 0 0 0
52282 - 0 0 0 0 0 0 0 0 0 0 0 0
52283 - 0 0 0 0 0 0 0 0 0 0 0 0
52284 - 0 0 0 0 0 0 0 0 0 0 0 0
52285 - 0 0 0 0 0 0 0 0 0 0 0 0
52286 - 0 0 0 0 0 0 0 0 0 0 0 0
52287 - 0 0 0 0 0 0 0 0 0 14 14 14
52288 - 34 34 34 66 66 66 78 78 78 6 6 6
52289 - 2 2 6 18 18 18 218 218 218 253 253 253
52290 -253 253 253 253 253 253 253 253 253 246 246 246
52291 -226 226 226 231 231 231 246 246 246 253 253 253
52292 -253 253 253 253 253 253 253 253 253 253 253 253
52293 -253 253 253 253 253 253 253 253 253 253 253 253
52294 -253 253 253 178 178 178 2 2 6 2 2 6
52295 - 2 2 6 2 2 6 2 2 6 2 2 6
52296 - 2 2 6 18 18 18 90 90 90 62 62 62
52297 - 30 30 30 10 10 10 0 0 0 0 0 0
52298 - 0 0 0 0 0 0 0 0 0 0 0 0
52299 - 0 0 0 0 0 0 0 0 0 0 0 0
52300 - 0 0 0 0 0 0 0 0 0 0 0 0
52301 - 0 0 0 0 0 0 0 0 0 0 0 0
52302 - 0 0 0 0 0 0 0 0 0 0 0 0
52303 - 0 0 0 0 0 0 0 0 0 0 0 0
52304 - 0 0 0 0 0 0 0 0 0 0 0 0
52305 - 0 0 0 0 0 0 0 0 0 0 0 0
52306 - 0 0 0 0 0 0 0 0 0 0 0 0
52307 - 0 0 0 0 0 0 10 10 10 26 26 26
52308 - 58 58 58 90 90 90 18 18 18 2 2 6
52309 - 2 2 6 110 110 110 253 253 253 253 253 253
52310 -253 253 253 253 253 253 253 253 253 253 253 253
52311 -250 250 250 253 253 253 253 253 253 253 253 253
52312 -253 253 253 253 253 253 253 253 253 253 253 253
52313 -253 253 253 253 253 253 253 253 253 253 253 253
52314 -253 253 253 231 231 231 18 18 18 2 2 6
52315 - 2 2 6 2 2 6 2 2 6 2 2 6
52316 - 2 2 6 2 2 6 18 18 18 94 94 94
52317 - 54 54 54 26 26 26 10 10 10 0 0 0
52318 - 0 0 0 0 0 0 0 0 0 0 0 0
52319 - 0 0 0 0 0 0 0 0 0 0 0 0
52320 - 0 0 0 0 0 0 0 0 0 0 0 0
52321 - 0 0 0 0 0 0 0 0 0 0 0 0
52322 - 0 0 0 0 0 0 0 0 0 0 0 0
52323 - 0 0 0 0 0 0 0 0 0 0 0 0
52324 - 0 0 0 0 0 0 0 0 0 0 0 0
52325 - 0 0 0 0 0 0 0 0 0 0 0 0
52326 - 0 0 0 0 0 0 0 0 0 0 0 0
52327 - 0 0 0 6 6 6 22 22 22 50 50 50
52328 - 90 90 90 26 26 26 2 2 6 2 2 6
52329 - 14 14 14 195 195 195 250 250 250 253 253 253
52330 -253 253 253 253 253 253 253 253 253 253 253 253
52331 -253 253 253 253 253 253 253 253 253 253 253 253
52332 -253 253 253 253 253 253 253 253 253 253 253 253
52333 -253 253 253 253 253 253 253 253 253 253 253 253
52334 -250 250 250 242 242 242 54 54 54 2 2 6
52335 - 2 2 6 2 2 6 2 2 6 2 2 6
52336 - 2 2 6 2 2 6 2 2 6 38 38 38
52337 - 86 86 86 50 50 50 22 22 22 6 6 6
52338 - 0 0 0 0 0 0 0 0 0 0 0 0
52339 - 0 0 0 0 0 0 0 0 0 0 0 0
52340 - 0 0 0 0 0 0 0 0 0 0 0 0
52341 - 0 0 0 0 0 0 0 0 0 0 0 0
52342 - 0 0 0 0 0 0 0 0 0 0 0 0
52343 - 0 0 0 0 0 0 0 0 0 0 0 0
52344 - 0 0 0 0 0 0 0 0 0 0 0 0
52345 - 0 0 0 0 0 0 0 0 0 0 0 0
52346 - 0 0 0 0 0 0 0 0 0 0 0 0
52347 - 6 6 6 14 14 14 38 38 38 82 82 82
52348 - 34 34 34 2 2 6 2 2 6 2 2 6
52349 - 42 42 42 195 195 195 246 246 246 253 253 253
52350 -253 253 253 253 253 253 253 253 253 250 250 250
52351 -242 242 242 242 242 242 250 250 250 253 253 253
52352 -253 253 253 253 253 253 253 253 253 253 253 253
52353 -253 253 253 250 250 250 246 246 246 238 238 238
52354 -226 226 226 231 231 231 101 101 101 6 6 6
52355 - 2 2 6 2 2 6 2 2 6 2 2 6
52356 - 2 2 6 2 2 6 2 2 6 2 2 6
52357 - 38 38 38 82 82 82 42 42 42 14 14 14
52358 - 6 6 6 0 0 0 0 0 0 0 0 0
52359 - 0 0 0 0 0 0 0 0 0 0 0 0
52360 - 0 0 0 0 0 0 0 0 0 0 0 0
52361 - 0 0 0 0 0 0 0 0 0 0 0 0
52362 - 0 0 0 0 0 0 0 0 0 0 0 0
52363 - 0 0 0 0 0 0 0 0 0 0 0 0
52364 - 0 0 0 0 0 0 0 0 0 0 0 0
52365 - 0 0 0 0 0 0 0 0 0 0 0 0
52366 - 0 0 0 0 0 0 0 0 0 0 0 0
52367 - 10 10 10 26 26 26 62 62 62 66 66 66
52368 - 2 2 6 2 2 6 2 2 6 6 6 6
52369 - 70 70 70 170 170 170 206 206 206 234 234 234
52370 -246 246 246 250 250 250 250 250 250 238 238 238
52371 -226 226 226 231 231 231 238 238 238 250 250 250
52372 -250 250 250 250 250 250 246 246 246 231 231 231
52373 -214 214 214 206 206 206 202 202 202 202 202 202
52374 -198 198 198 202 202 202 182 182 182 18 18 18
52375 - 2 2 6 2 2 6 2 2 6 2 2 6
52376 - 2 2 6 2 2 6 2 2 6 2 2 6
52377 - 2 2 6 62 62 62 66 66 66 30 30 30
52378 - 10 10 10 0 0 0 0 0 0 0 0 0
52379 - 0 0 0 0 0 0 0 0 0 0 0 0
52380 - 0 0 0 0 0 0 0 0 0 0 0 0
52381 - 0 0 0 0 0 0 0 0 0 0 0 0
52382 - 0 0 0 0 0 0 0 0 0 0 0 0
52383 - 0 0 0 0 0 0 0 0 0 0 0 0
52384 - 0 0 0 0 0 0 0 0 0 0 0 0
52385 - 0 0 0 0 0 0 0 0 0 0 0 0
52386 - 0 0 0 0 0 0 0 0 0 0 0 0
52387 - 14 14 14 42 42 42 82 82 82 18 18 18
52388 - 2 2 6 2 2 6 2 2 6 10 10 10
52389 - 94 94 94 182 182 182 218 218 218 242 242 242
52390 -250 250 250 253 253 253 253 253 253 250 250 250
52391 -234 234 234 253 253 253 253 253 253 253 253 253
52392 -253 253 253 253 253 253 253 253 253 246 246 246
52393 -238 238 238 226 226 226 210 210 210 202 202 202
52394 -195 195 195 195 195 195 210 210 210 158 158 158
52395 - 6 6 6 14 14 14 50 50 50 14 14 14
52396 - 2 2 6 2 2 6 2 2 6 2 2 6
52397 - 2 2 6 6 6 6 86 86 86 46 46 46
52398 - 18 18 18 6 6 6 0 0 0 0 0 0
52399 - 0 0 0 0 0 0 0 0 0 0 0 0
52400 - 0 0 0 0 0 0 0 0 0 0 0 0
52401 - 0 0 0 0 0 0 0 0 0 0 0 0
52402 - 0 0 0 0 0 0 0 0 0 0 0 0
52403 - 0 0 0 0 0 0 0 0 0 0 0 0
52404 - 0 0 0 0 0 0 0 0 0 0 0 0
52405 - 0 0 0 0 0 0 0 0 0 0 0 0
52406 - 0 0 0 0 0 0 0 0 0 6 6 6
52407 - 22 22 22 54 54 54 70 70 70 2 2 6
52408 - 2 2 6 10 10 10 2 2 6 22 22 22
52409 -166 166 166 231 231 231 250 250 250 253 253 253
52410 -253 253 253 253 253 253 253 253 253 250 250 250
52411 -242 242 242 253 253 253 253 253 253 253 253 253
52412 -253 253 253 253 253 253 253 253 253 253 253 253
52413 -253 253 253 253 253 253 253 253 253 246 246 246
52414 -231 231 231 206 206 206 198 198 198 226 226 226
52415 - 94 94 94 2 2 6 6 6 6 38 38 38
52416 - 30 30 30 2 2 6 2 2 6 2 2 6
52417 - 2 2 6 2 2 6 62 62 62 66 66 66
52418 - 26 26 26 10 10 10 0 0 0 0 0 0
52419 - 0 0 0 0 0 0 0 0 0 0 0 0
52420 - 0 0 0 0 0 0 0 0 0 0 0 0
52421 - 0 0 0 0 0 0 0 0 0 0 0 0
52422 - 0 0 0 0 0 0 0 0 0 0 0 0
52423 - 0 0 0 0 0 0 0 0 0 0 0 0
52424 - 0 0 0 0 0 0 0 0 0 0 0 0
52425 - 0 0 0 0 0 0 0 0 0 0 0 0
52426 - 0 0 0 0 0 0 0 0 0 10 10 10
52427 - 30 30 30 74 74 74 50 50 50 2 2 6
52428 - 26 26 26 26 26 26 2 2 6 106 106 106
52429 -238 238 238 253 253 253 253 253 253 253 253 253
52430 -253 253 253 253 253 253 253 253 253 253 253 253
52431 -253 253 253 253 253 253 253 253 253 253 253 253
52432 -253 253 253 253 253 253 253 253 253 253 253 253
52433 -253 253 253 253 253 253 253 253 253 253 253 253
52434 -253 253 253 246 246 246 218 218 218 202 202 202
52435 -210 210 210 14 14 14 2 2 6 2 2 6
52436 - 30 30 30 22 22 22 2 2 6 2 2 6
52437 - 2 2 6 2 2 6 18 18 18 86 86 86
52438 - 42 42 42 14 14 14 0 0 0 0 0 0
52439 - 0 0 0 0 0 0 0 0 0 0 0 0
52440 - 0 0 0 0 0 0 0 0 0 0 0 0
52441 - 0 0 0 0 0 0 0 0 0 0 0 0
52442 - 0 0 0 0 0 0 0 0 0 0 0 0
52443 - 0 0 0 0 0 0 0 0 0 0 0 0
52444 - 0 0 0 0 0 0 0 0 0 0 0 0
52445 - 0 0 0 0 0 0 0 0 0 0 0 0
52446 - 0 0 0 0 0 0 0 0 0 14 14 14
52447 - 42 42 42 90 90 90 22 22 22 2 2 6
52448 - 42 42 42 2 2 6 18 18 18 218 218 218
52449 -253 253 253 253 253 253 253 253 253 253 253 253
52450 -253 253 253 253 253 253 253 253 253 253 253 253
52451 -253 253 253 253 253 253 253 253 253 253 253 253
52452 -253 253 253 253 253 253 253 253 253 253 253 253
52453 -253 253 253 253 253 253 253 253 253 253 253 253
52454 -253 253 253 253 253 253 250 250 250 221 221 221
52455 -218 218 218 101 101 101 2 2 6 14 14 14
52456 - 18 18 18 38 38 38 10 10 10 2 2 6
52457 - 2 2 6 2 2 6 2 2 6 78 78 78
52458 - 58 58 58 22 22 22 6 6 6 0 0 0
52459 - 0 0 0 0 0 0 0 0 0 0 0 0
52460 - 0 0 0 0 0 0 0 0 0 0 0 0
52461 - 0 0 0 0 0 0 0 0 0 0 0 0
52462 - 0 0 0 0 0 0 0 0 0 0 0 0
52463 - 0 0 0 0 0 0 0 0 0 0 0 0
52464 - 0 0 0 0 0 0 0 0 0 0 0 0
52465 - 0 0 0 0 0 0 0 0 0 0 0 0
52466 - 0 0 0 0 0 0 6 6 6 18 18 18
52467 - 54 54 54 82 82 82 2 2 6 26 26 26
52468 - 22 22 22 2 2 6 123 123 123 253 253 253
52469 -253 253 253 253 253 253 253 253 253 253 253 253
52470 -253 253 253 253 253 253 253 253 253 253 253 253
52471 -253 253 253 253 253 253 253 253 253 253 253 253
52472 -253 253 253 253 253 253 253 253 253 253 253 253
52473 -253 253 253 253 253 253 253 253 253 253 253 253
52474 -253 253 253 253 253 253 253 253 253 250 250 250
52475 -238 238 238 198 198 198 6 6 6 38 38 38
52476 - 58 58 58 26 26 26 38 38 38 2 2 6
52477 - 2 2 6 2 2 6 2 2 6 46 46 46
52478 - 78 78 78 30 30 30 10 10 10 0 0 0
52479 - 0 0 0 0 0 0 0 0 0 0 0 0
52480 - 0 0 0 0 0 0 0 0 0 0 0 0
52481 - 0 0 0 0 0 0 0 0 0 0 0 0
52482 - 0 0 0 0 0 0 0 0 0 0 0 0
52483 - 0 0 0 0 0 0 0 0 0 0 0 0
52484 - 0 0 0 0 0 0 0 0 0 0 0 0
52485 - 0 0 0 0 0 0 0 0 0 0 0 0
52486 - 0 0 0 0 0 0 10 10 10 30 30 30
52487 - 74 74 74 58 58 58 2 2 6 42 42 42
52488 - 2 2 6 22 22 22 231 231 231 253 253 253
52489 -253 253 253 253 253 253 253 253 253 253 253 253
52490 -253 253 253 253 253 253 253 253 253 250 250 250
52491 -253 253 253 253 253 253 253 253 253 253 253 253
52492 -253 253 253 253 253 253 253 253 253 253 253 253
52493 -253 253 253 253 253 253 253 253 253 253 253 253
52494 -253 253 253 253 253 253 253 253 253 253 253 253
52495 -253 253 253 246 246 246 46 46 46 38 38 38
52496 - 42 42 42 14 14 14 38 38 38 14 14 14
52497 - 2 2 6 2 2 6 2 2 6 6 6 6
52498 - 86 86 86 46 46 46 14 14 14 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 6 6 6 14 14 14 42 42 42
52507 - 90 90 90 18 18 18 18 18 18 26 26 26
52508 - 2 2 6 116 116 116 253 253 253 253 253 253
52509 -253 253 253 253 253 253 253 253 253 253 253 253
52510 -253 253 253 253 253 253 250 250 250 238 238 238
52511 -253 253 253 253 253 253 253 253 253 253 253 253
52512 -253 253 253 253 253 253 253 253 253 253 253 253
52513 -253 253 253 253 253 253 253 253 253 253 253 253
52514 -253 253 253 253 253 253 253 253 253 253 253 253
52515 -253 253 253 253 253 253 94 94 94 6 6 6
52516 - 2 2 6 2 2 6 10 10 10 34 34 34
52517 - 2 2 6 2 2 6 2 2 6 2 2 6
52518 - 74 74 74 58 58 58 22 22 22 6 6 6
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 10 10 10 26 26 26 66 66 66
52527 - 82 82 82 2 2 6 38 38 38 6 6 6
52528 - 14 14 14 210 210 210 253 253 253 253 253 253
52529 -253 253 253 253 253 253 253 253 253 253 253 253
52530 -253 253 253 253 253 253 246 246 246 242 242 242
52531 -253 253 253 253 253 253 253 253 253 253 253 253
52532 -253 253 253 253 253 253 253 253 253 253 253 253
52533 -253 253 253 253 253 253 253 253 253 253 253 253
52534 -253 253 253 253 253 253 253 253 253 253 253 253
52535 -253 253 253 253 253 253 144 144 144 2 2 6
52536 - 2 2 6 2 2 6 2 2 6 46 46 46
52537 - 2 2 6 2 2 6 2 2 6 2 2 6
52538 - 42 42 42 74 74 74 30 30 30 10 10 10
52539 - 0 0 0 0 0 0 0 0 0 0 0 0
52540 - 0 0 0 0 0 0 0 0 0 0 0 0
52541 - 0 0 0 0 0 0 0 0 0 0 0 0
52542 - 0 0 0 0 0 0 0 0 0 0 0 0
52543 - 0 0 0 0 0 0 0 0 0 0 0 0
52544 - 0 0 0 0 0 0 0 0 0 0 0 0
52545 - 0 0 0 0 0 0 0 0 0 0 0 0
52546 - 6 6 6 14 14 14 42 42 42 90 90 90
52547 - 26 26 26 6 6 6 42 42 42 2 2 6
52548 - 74 74 74 250 250 250 253 253 253 253 253 253
52549 -253 253 253 253 253 253 253 253 253 253 253 253
52550 -253 253 253 253 253 253 242 242 242 242 242 242
52551 -253 253 253 253 253 253 253 253 253 253 253 253
52552 -253 253 253 253 253 253 253 253 253 253 253 253
52553 -253 253 253 253 253 253 253 253 253 253 253 253
52554 -253 253 253 253 253 253 253 253 253 253 253 253
52555 -253 253 253 253 253 253 182 182 182 2 2 6
52556 - 2 2 6 2 2 6 2 2 6 46 46 46
52557 - 2 2 6 2 2 6 2 2 6 2 2 6
52558 - 10 10 10 86 86 86 38 38 38 10 10 10
52559 - 0 0 0 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 0 0 0
52566 - 10 10 10 26 26 26 66 66 66 82 82 82
52567 - 2 2 6 22 22 22 18 18 18 2 2 6
52568 -149 149 149 253 253 253 253 253 253 253 253 253
52569 -253 253 253 253 253 253 253 253 253 253 253 253
52570 -253 253 253 253 253 253 234 234 234 242 242 242
52571 -253 253 253 253 253 253 253 253 253 253 253 253
52572 -253 253 253 253 253 253 253 253 253 253 253 253
52573 -253 253 253 253 253 253 253 253 253 253 253 253
52574 -253 253 253 253 253 253 253 253 253 253 253 253
52575 -253 253 253 253 253 253 206 206 206 2 2 6
52576 - 2 2 6 2 2 6 2 2 6 38 38 38
52577 - 2 2 6 2 2 6 2 2 6 2 2 6
52578 - 6 6 6 86 86 86 46 46 46 14 14 14
52579 - 0 0 0 0 0 0 0 0 0 0 0 0
52580 - 0 0 0 0 0 0 0 0 0 0 0 0
52581 - 0 0 0 0 0 0 0 0 0 0 0 0
52582 - 0 0 0 0 0 0 0 0 0 0 0 0
52583 - 0 0 0 0 0 0 0 0 0 0 0 0
52584 - 0 0 0 0 0 0 0 0 0 0 0 0
52585 - 0 0 0 0 0 0 0 0 0 6 6 6
52586 - 18 18 18 46 46 46 86 86 86 18 18 18
52587 - 2 2 6 34 34 34 10 10 10 6 6 6
52588 -210 210 210 253 253 253 253 253 253 253 253 253
52589 -253 253 253 253 253 253 253 253 253 253 253 253
52590 -253 253 253 253 253 253 234 234 234 242 242 242
52591 -253 253 253 253 253 253 253 253 253 253 253 253
52592 -253 253 253 253 253 253 253 253 253 253 253 253
52593 -253 253 253 253 253 253 253 253 253 253 253 253
52594 -253 253 253 253 253 253 253 253 253 253 253 253
52595 -253 253 253 253 253 253 221 221 221 6 6 6
52596 - 2 2 6 2 2 6 6 6 6 30 30 30
52597 - 2 2 6 2 2 6 2 2 6 2 2 6
52598 - 2 2 6 82 82 82 54 54 54 18 18 18
52599 - 6 6 6 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 0 0 0 0 0 0 10 10 10
52606 - 26 26 26 66 66 66 62 62 62 2 2 6
52607 - 2 2 6 38 38 38 10 10 10 26 26 26
52608 -238 238 238 253 253 253 253 253 253 253 253 253
52609 -253 253 253 253 253 253 253 253 253 253 253 253
52610 -253 253 253 253 253 253 231 231 231 238 238 238
52611 -253 253 253 253 253 253 253 253 253 253 253 253
52612 -253 253 253 253 253 253 253 253 253 253 253 253
52613 -253 253 253 253 253 253 253 253 253 253 253 253
52614 -253 253 253 253 253 253 253 253 253 253 253 253
52615 -253 253 253 253 253 253 231 231 231 6 6 6
52616 - 2 2 6 2 2 6 10 10 10 30 30 30
52617 - 2 2 6 2 2 6 2 2 6 2 2 6
52618 - 2 2 6 66 66 66 58 58 58 22 22 22
52619 - 6 6 6 0 0 0 0 0 0 0 0 0
52620 - 0 0 0 0 0 0 0 0 0 0 0 0
52621 - 0 0 0 0 0 0 0 0 0 0 0 0
52622 - 0 0 0 0 0 0 0 0 0 0 0 0
52623 - 0 0 0 0 0 0 0 0 0 0 0 0
52624 - 0 0 0 0 0 0 0 0 0 0 0 0
52625 - 0 0 0 0 0 0 0 0 0 10 10 10
52626 - 38 38 38 78 78 78 6 6 6 2 2 6
52627 - 2 2 6 46 46 46 14 14 14 42 42 42
52628 -246 246 246 253 253 253 253 253 253 253 253 253
52629 -253 253 253 253 253 253 253 253 253 253 253 253
52630 -253 253 253 253 253 253 231 231 231 242 242 242
52631 -253 253 253 253 253 253 253 253 253 253 253 253
52632 -253 253 253 253 253 253 253 253 253 253 253 253
52633 -253 253 253 253 253 253 253 253 253 253 253 253
52634 -253 253 253 253 253 253 253 253 253 253 253 253
52635 -253 253 253 253 253 253 234 234 234 10 10 10
52636 - 2 2 6 2 2 6 22 22 22 14 14 14
52637 - 2 2 6 2 2 6 2 2 6 2 2 6
52638 - 2 2 6 66 66 66 62 62 62 22 22 22
52639 - 6 6 6 0 0 0 0 0 0 0 0 0
52640 - 0 0 0 0 0 0 0 0 0 0 0 0
52641 - 0 0 0 0 0 0 0 0 0 0 0 0
52642 - 0 0 0 0 0 0 0 0 0 0 0 0
52643 - 0 0 0 0 0 0 0 0 0 0 0 0
52644 - 0 0 0 0 0 0 0 0 0 0 0 0
52645 - 0 0 0 0 0 0 6 6 6 18 18 18
52646 - 50 50 50 74 74 74 2 2 6 2 2 6
52647 - 14 14 14 70 70 70 34 34 34 62 62 62
52648 -250 250 250 253 253 253 253 253 253 253 253 253
52649 -253 253 253 253 253 253 253 253 253 253 253 253
52650 -253 253 253 253 253 253 231 231 231 246 246 246
52651 -253 253 253 253 253 253 253 253 253 253 253 253
52652 -253 253 253 253 253 253 253 253 253 253 253 253
52653 -253 253 253 253 253 253 253 253 253 253 253 253
52654 -253 253 253 253 253 253 253 253 253 253 253 253
52655 -253 253 253 253 253 253 234 234 234 14 14 14
52656 - 2 2 6 2 2 6 30 30 30 2 2 6
52657 - 2 2 6 2 2 6 2 2 6 2 2 6
52658 - 2 2 6 66 66 66 62 62 62 22 22 22
52659 - 6 6 6 0 0 0 0 0 0 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 - 0 0 0 0 0 0 6 6 6 18 18 18
52666 - 54 54 54 62 62 62 2 2 6 2 2 6
52667 - 2 2 6 30 30 30 46 46 46 70 70 70
52668 -250 250 250 253 253 253 253 253 253 253 253 253
52669 -253 253 253 253 253 253 253 253 253 253 253 253
52670 -253 253 253 253 253 253 231 231 231 246 246 246
52671 -253 253 253 253 253 253 253 253 253 253 253 253
52672 -253 253 253 253 253 253 253 253 253 253 253 253
52673 -253 253 253 253 253 253 253 253 253 253 253 253
52674 -253 253 253 253 253 253 253 253 253 253 253 253
52675 -253 253 253 253 253 253 226 226 226 10 10 10
52676 - 2 2 6 6 6 6 30 30 30 2 2 6
52677 - 2 2 6 2 2 6 2 2 6 2 2 6
52678 - 2 2 6 66 66 66 58 58 58 22 22 22
52679 - 6 6 6 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 0 0 0
52685 - 0 0 0 0 0 0 6 6 6 22 22 22
52686 - 58 58 58 62 62 62 2 2 6 2 2 6
52687 - 2 2 6 2 2 6 30 30 30 78 78 78
52688 -250 250 250 253 253 253 253 253 253 253 253 253
52689 -253 253 253 253 253 253 253 253 253 253 253 253
52690 -253 253 253 253 253 253 231 231 231 246 246 246
52691 -253 253 253 253 253 253 253 253 253 253 253 253
52692 -253 253 253 253 253 253 253 253 253 253 253 253
52693 -253 253 253 253 253 253 253 253 253 253 253 253
52694 -253 253 253 253 253 253 253 253 253 253 253 253
52695 -253 253 253 253 253 253 206 206 206 2 2 6
52696 - 22 22 22 34 34 34 18 14 6 22 22 22
52697 - 26 26 26 18 18 18 6 6 6 2 2 6
52698 - 2 2 6 82 82 82 54 54 54 18 18 18
52699 - 6 6 6 0 0 0 0 0 0 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 0 0 0
52705 - 0 0 0 0 0 0 6 6 6 26 26 26
52706 - 62 62 62 106 106 106 74 54 14 185 133 11
52707 -210 162 10 121 92 8 6 6 6 62 62 62
52708 -238 238 238 253 253 253 253 253 253 253 253 253
52709 -253 253 253 253 253 253 253 253 253 253 253 253
52710 -253 253 253 253 253 253 231 231 231 246 246 246
52711 -253 253 253 253 253 253 253 253 253 253 253 253
52712 -253 253 253 253 253 253 253 253 253 253 253 253
52713 -253 253 253 253 253 253 253 253 253 253 253 253
52714 -253 253 253 253 253 253 253 253 253 253 253 253
52715 -253 253 253 253 253 253 158 158 158 18 18 18
52716 - 14 14 14 2 2 6 2 2 6 2 2 6
52717 - 6 6 6 18 18 18 66 66 66 38 38 38
52718 - 6 6 6 94 94 94 50 50 50 18 18 18
52719 - 6 6 6 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 6 6 6
52725 - 10 10 10 10 10 10 18 18 18 38 38 38
52726 - 78 78 78 142 134 106 216 158 10 242 186 14
52727 -246 190 14 246 190 14 156 118 10 10 10 10
52728 - 90 90 90 238 238 238 253 253 253 253 253 253
52729 -253 253 253 253 253 253 253 253 253 253 253 253
52730 -253 253 253 253 253 253 231 231 231 250 250 250
52731 -253 253 253 253 253 253 253 253 253 253 253 253
52732 -253 253 253 253 253 253 253 253 253 253 253 253
52733 -253 253 253 253 253 253 253 253 253 253 253 253
52734 -253 253 253 253 253 253 253 253 253 246 230 190
52735 -238 204 91 238 204 91 181 142 44 37 26 9
52736 - 2 2 6 2 2 6 2 2 6 2 2 6
52737 - 2 2 6 2 2 6 38 38 38 46 46 46
52738 - 26 26 26 106 106 106 54 54 54 18 18 18
52739 - 6 6 6 0 0 0 0 0 0 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 6 6 6 14 14 14 22 22 22
52745 - 30 30 30 38 38 38 50 50 50 70 70 70
52746 -106 106 106 190 142 34 226 170 11 242 186 14
52747 -246 190 14 246 190 14 246 190 14 154 114 10
52748 - 6 6 6 74 74 74 226 226 226 253 253 253
52749 -253 253 253 253 253 253 253 253 253 253 253 253
52750 -253 253 253 253 253 253 231 231 231 250 250 250
52751 -253 253 253 253 253 253 253 253 253 253 253 253
52752 -253 253 253 253 253 253 253 253 253 253 253 253
52753 -253 253 253 253 253 253 253 253 253 253 253 253
52754 -253 253 253 253 253 253 253 253 253 228 184 62
52755 -241 196 14 241 208 19 232 195 16 38 30 10
52756 - 2 2 6 2 2 6 2 2 6 2 2 6
52757 - 2 2 6 6 6 6 30 30 30 26 26 26
52758 -203 166 17 154 142 90 66 66 66 26 26 26
52759 - 6 6 6 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 - 6 6 6 18 18 18 38 38 38 58 58 58
52765 - 78 78 78 86 86 86 101 101 101 123 123 123
52766 -175 146 61 210 150 10 234 174 13 246 186 14
52767 -246 190 14 246 190 14 246 190 14 238 190 10
52768 -102 78 10 2 2 6 46 46 46 198 198 198
52769 -253 253 253 253 253 253 253 253 253 253 253 253
52770 -253 253 253 253 253 253 234 234 234 242 242 242
52771 -253 253 253 253 253 253 253 253 253 253 253 253
52772 -253 253 253 253 253 253 253 253 253 253 253 253
52773 -253 253 253 253 253 253 253 253 253 253 253 253
52774 -253 253 253 253 253 253 253 253 253 224 178 62
52775 -242 186 14 241 196 14 210 166 10 22 18 6
52776 - 2 2 6 2 2 6 2 2 6 2 2 6
52777 - 2 2 6 2 2 6 6 6 6 121 92 8
52778 -238 202 15 232 195 16 82 82 82 34 34 34
52779 - 10 10 10 0 0 0 0 0 0 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 - 14 14 14 38 38 38 70 70 70 154 122 46
52785 -190 142 34 200 144 11 197 138 11 197 138 11
52786 -213 154 11 226 170 11 242 186 14 246 190 14
52787 -246 190 14 246 190 14 246 190 14 246 190 14
52788 -225 175 15 46 32 6 2 2 6 22 22 22
52789 -158 158 158 250 250 250 253 253 253 253 253 253
52790 -253 253 253 253 253 253 253 253 253 253 253 253
52791 -253 253 253 253 253 253 253 253 253 253 253 253
52792 -253 253 253 253 253 253 253 253 253 253 253 253
52793 -253 253 253 253 253 253 253 253 253 253 253 253
52794 -253 253 253 250 250 250 242 242 242 224 178 62
52795 -239 182 13 236 186 11 213 154 11 46 32 6
52796 - 2 2 6 2 2 6 2 2 6 2 2 6
52797 - 2 2 6 2 2 6 61 42 6 225 175 15
52798 -238 190 10 236 186 11 112 100 78 42 42 42
52799 - 14 14 14 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 6 6 6
52804 - 22 22 22 54 54 54 154 122 46 213 154 11
52805 -226 170 11 230 174 11 226 170 11 226 170 11
52806 -236 178 12 242 186 14 246 190 14 246 190 14
52807 -246 190 14 246 190 14 246 190 14 246 190 14
52808 -241 196 14 184 144 12 10 10 10 2 2 6
52809 - 6 6 6 116 116 116 242 242 242 253 253 253
52810 -253 253 253 253 253 253 253 253 253 253 253 253
52811 -253 253 253 253 253 253 253 253 253 253 253 253
52812 -253 253 253 253 253 253 253 253 253 253 253 253
52813 -253 253 253 253 253 253 253 253 253 253 253 253
52814 -253 253 253 231 231 231 198 198 198 214 170 54
52815 -236 178 12 236 178 12 210 150 10 137 92 6
52816 - 18 14 6 2 2 6 2 2 6 2 2 6
52817 - 6 6 6 70 47 6 200 144 11 236 178 12
52818 -239 182 13 239 182 13 124 112 88 58 58 58
52819 - 22 22 22 6 6 6 0 0 0 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 10 10 10
52824 - 30 30 30 70 70 70 180 133 36 226 170 11
52825 -239 182 13 242 186 14 242 186 14 246 186 14
52826 -246 190 14 246 190 14 246 190 14 246 190 14
52827 -246 190 14 246 190 14 246 190 14 246 190 14
52828 -246 190 14 232 195 16 98 70 6 2 2 6
52829 - 2 2 6 2 2 6 66 66 66 221 221 221
52830 -253 253 253 253 253 253 253 253 253 253 253 253
52831 -253 253 253 253 253 253 253 253 253 253 253 253
52832 -253 253 253 253 253 253 253 253 253 253 253 253
52833 -253 253 253 253 253 253 253 253 253 253 253 253
52834 -253 253 253 206 206 206 198 198 198 214 166 58
52835 -230 174 11 230 174 11 216 158 10 192 133 9
52836 -163 110 8 116 81 8 102 78 10 116 81 8
52837 -167 114 7 197 138 11 226 170 11 239 182 13
52838 -242 186 14 242 186 14 162 146 94 78 78 78
52839 - 34 34 34 14 14 14 6 6 6 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 6 6 6
52844 - 30 30 30 78 78 78 190 142 34 226 170 11
52845 -239 182 13 246 190 14 246 190 14 246 190 14
52846 -246 190 14 246 190 14 246 190 14 246 190 14
52847 -246 190 14 246 190 14 246 190 14 246 190 14
52848 -246 190 14 241 196 14 203 166 17 22 18 6
52849 - 2 2 6 2 2 6 2 2 6 38 38 38
52850 -218 218 218 253 253 253 253 253 253 253 253 253
52851 -253 253 253 253 253 253 253 253 253 253 253 253
52852 -253 253 253 253 253 253 253 253 253 253 253 253
52853 -253 253 253 253 253 253 253 253 253 253 253 253
52854 -250 250 250 206 206 206 198 198 198 202 162 69
52855 -226 170 11 236 178 12 224 166 10 210 150 10
52856 -200 144 11 197 138 11 192 133 9 197 138 11
52857 -210 150 10 226 170 11 242 186 14 246 190 14
52858 -246 190 14 246 186 14 225 175 15 124 112 88
52859 - 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
52864 - 30 30 30 78 78 78 174 135 50 224 166 10
52865 -239 182 13 246 190 14 246 190 14 246 190 14
52866 -246 190 14 246 190 14 246 190 14 246 190 14
52867 -246 190 14 246 190 14 246 190 14 246 190 14
52868 -246 190 14 246 190 14 241 196 14 139 102 15
52869 - 2 2 6 2 2 6 2 2 6 2 2 6
52870 - 78 78 78 250 250 250 253 253 253 253 253 253
52871 -253 253 253 253 253 253 253 253 253 253 253 253
52872 -253 253 253 253 253 253 253 253 253 253 253 253
52873 -253 253 253 253 253 253 253 253 253 253 253 253
52874 -250 250 250 214 214 214 198 198 198 190 150 46
52875 -219 162 10 236 178 12 234 174 13 224 166 10
52876 -216 158 10 213 154 11 213 154 11 216 158 10
52877 -226 170 11 239 182 13 246 190 14 246 190 14
52878 -246 190 14 246 190 14 242 186 14 206 162 42
52879 -101 101 101 58 58 58 30 30 30 14 14 14
52880 - 6 6 6 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 10 10 10
52884 - 30 30 30 74 74 74 174 135 50 216 158 10
52885 -236 178 12 246 190 14 246 190 14 246 190 14
52886 -246 190 14 246 190 14 246 190 14 246 190 14
52887 -246 190 14 246 190 14 246 190 14 246 190 14
52888 -246 190 14 246 190 14 241 196 14 226 184 13
52889 - 61 42 6 2 2 6 2 2 6 2 2 6
52890 - 22 22 22 238 238 238 253 253 253 253 253 253
52891 -253 253 253 253 253 253 253 253 253 253 253 253
52892 -253 253 253 253 253 253 253 253 253 253 253 253
52893 -253 253 253 253 253 253 253 253 253 253 253 253
52894 -253 253 253 226 226 226 187 187 187 180 133 36
52895 -216 158 10 236 178 12 239 182 13 236 178 12
52896 -230 174 11 226 170 11 226 170 11 230 174 11
52897 -236 178 12 242 186 14 246 190 14 246 190 14
52898 -246 190 14 246 190 14 246 186 14 239 182 13
52899 -206 162 42 106 106 106 66 66 66 34 34 34
52900 - 14 14 14 6 6 6 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 6 6 6
52904 - 26 26 26 70 70 70 163 133 67 213 154 11
52905 -236 178 12 246 190 14 246 190 14 246 190 14
52906 -246 190 14 246 190 14 246 190 14 246 190 14
52907 -246 190 14 246 190 14 246 190 14 246 190 14
52908 -246 190 14 246 190 14 246 190 14 241 196 14
52909 -190 146 13 18 14 6 2 2 6 2 2 6
52910 - 46 46 46 246 246 246 253 253 253 253 253 253
52911 -253 253 253 253 253 253 253 253 253 253 253 253
52912 -253 253 253 253 253 253 253 253 253 253 253 253
52913 -253 253 253 253 253 253 253 253 253 253 253 253
52914 -253 253 253 221 221 221 86 86 86 156 107 11
52915 -216 158 10 236 178 12 242 186 14 246 186 14
52916 -242 186 14 239 182 13 239 182 13 242 186 14
52917 -242 186 14 246 186 14 246 190 14 246 190 14
52918 -246 190 14 246 190 14 246 190 14 246 190 14
52919 -242 186 14 225 175 15 142 122 72 66 66 66
52920 - 30 30 30 10 10 10 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 6 6 6
52924 - 26 26 26 70 70 70 163 133 67 210 150 10
52925 -236 178 12 246 190 14 246 190 14 246 190 14
52926 -246 190 14 246 190 14 246 190 14 246 190 14
52927 -246 190 14 246 190 14 246 190 14 246 190 14
52928 -246 190 14 246 190 14 246 190 14 246 190 14
52929 -232 195 16 121 92 8 34 34 34 106 106 106
52930 -221 221 221 253 253 253 253 253 253 253 253 253
52931 -253 253 253 253 253 253 253 253 253 253 253 253
52932 -253 253 253 253 253 253 253 253 253 253 253 253
52933 -253 253 253 253 253 253 253 253 253 253 253 253
52934 -242 242 242 82 82 82 18 14 6 163 110 8
52935 -216 158 10 236 178 12 242 186 14 246 190 14
52936 -246 190 14 246 190 14 246 190 14 246 190 14
52937 -246 190 14 246 190 14 246 190 14 246 190 14
52938 -246 190 14 246 190 14 246 190 14 246 190 14
52939 -246 190 14 246 190 14 242 186 14 163 133 67
52940 - 46 46 46 18 18 18 6 6 6 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 10 10 10
52944 - 30 30 30 78 78 78 163 133 67 210 150 10
52945 -236 178 12 246 186 14 246 190 14 246 190 14
52946 -246 190 14 246 190 14 246 190 14 246 190 14
52947 -246 190 14 246 190 14 246 190 14 246 190 14
52948 -246 190 14 246 190 14 246 190 14 246 190 14
52949 -241 196 14 215 174 15 190 178 144 253 253 253
52950 -253 253 253 253 253 253 253 253 253 253 253 253
52951 -253 253 253 253 253 253 253 253 253 253 253 253
52952 -253 253 253 253 253 253 253 253 253 253 253 253
52953 -253 253 253 253 253 253 253 253 253 218 218 218
52954 - 58 58 58 2 2 6 22 18 6 167 114 7
52955 -216 158 10 236 178 12 246 186 14 246 190 14
52956 -246 190 14 246 190 14 246 190 14 246 190 14
52957 -246 190 14 246 190 14 246 190 14 246 190 14
52958 -246 190 14 246 190 14 246 190 14 246 190 14
52959 -246 190 14 246 186 14 242 186 14 190 150 46
52960 - 54 54 54 22 22 22 6 6 6 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 14 14 14
52964 - 38 38 38 86 86 86 180 133 36 213 154 11
52965 -236 178 12 246 186 14 246 190 14 246 190 14
52966 -246 190 14 246 190 14 246 190 14 246 190 14
52967 -246 190 14 246 190 14 246 190 14 246 190 14
52968 -246 190 14 246 190 14 246 190 14 246 190 14
52969 -246 190 14 232 195 16 190 146 13 214 214 214
52970 -253 253 253 253 253 253 253 253 253 253 253 253
52971 -253 253 253 253 253 253 253 253 253 253 253 253
52972 -253 253 253 253 253 253 253 253 253 253 253 253
52973 -253 253 253 250 250 250 170 170 170 26 26 26
52974 - 2 2 6 2 2 6 37 26 9 163 110 8
52975 -219 162 10 239 182 13 246 186 14 246 190 14
52976 -246 190 14 246 190 14 246 190 14 246 190 14
52977 -246 190 14 246 190 14 246 190 14 246 190 14
52978 -246 190 14 246 190 14 246 190 14 246 190 14
52979 -246 186 14 236 178 12 224 166 10 142 122 72
52980 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
52984 - 50 50 50 109 106 95 192 133 9 224 166 10
52985 -242 186 14 246 190 14 246 190 14 246 190 14
52986 -246 190 14 246 190 14 246 190 14 246 190 14
52987 -246 190 14 246 190 14 246 190 14 246 190 14
52988 -246 190 14 246 190 14 246 190 14 246 190 14
52989 -242 186 14 226 184 13 210 162 10 142 110 46
52990 -226 226 226 253 253 253 253 253 253 253 253 253
52991 -253 253 253 253 253 253 253 253 253 253 253 253
52992 -253 253 253 253 253 253 253 253 253 253 253 253
52993 -198 198 198 66 66 66 2 2 6 2 2 6
52994 - 2 2 6 2 2 6 50 34 6 156 107 11
52995 -219 162 10 239 182 13 246 186 14 246 190 14
52996 -246 190 14 246 190 14 246 190 14 246 190 14
52997 -246 190 14 246 190 14 246 190 14 246 190 14
52998 -246 190 14 246 190 14 246 190 14 242 186 14
52999 -234 174 13 213 154 11 154 122 46 66 66 66
53000 - 30 30 30 10 10 10 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 6 6 6 22 22 22
53004 - 58 58 58 154 121 60 206 145 10 234 174 13
53005 -242 186 14 246 186 14 246 190 14 246 190 14
53006 -246 190 14 246 190 14 246 190 14 246 190 14
53007 -246 190 14 246 190 14 246 190 14 246 190 14
53008 -246 190 14 246 190 14 246 190 14 246 190 14
53009 -246 186 14 236 178 12 210 162 10 163 110 8
53010 - 61 42 6 138 138 138 218 218 218 250 250 250
53011 -253 253 253 253 253 253 253 253 253 250 250 250
53012 -242 242 242 210 210 210 144 144 144 66 66 66
53013 - 6 6 6 2 2 6 2 2 6 2 2 6
53014 - 2 2 6 2 2 6 61 42 6 163 110 8
53015 -216 158 10 236 178 12 246 190 14 246 190 14
53016 -246 190 14 246 190 14 246 190 14 246 190 14
53017 -246 190 14 246 190 14 246 190 14 246 190 14
53018 -246 190 14 239 182 13 230 174 11 216 158 10
53019 -190 142 34 124 112 88 70 70 70 38 38 38
53020 - 18 18 18 6 6 6 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 6 6 6 22 22 22
53024 - 62 62 62 168 124 44 206 145 10 224 166 10
53025 -236 178 12 239 182 13 242 186 14 242 186 14
53026 -246 186 14 246 190 14 246 190 14 246 190 14
53027 -246 190 14 246 190 14 246 190 14 246 190 14
53028 -246 190 14 246 190 14 246 190 14 246 190 14
53029 -246 190 14 236 178 12 216 158 10 175 118 6
53030 - 80 54 7 2 2 6 6 6 6 30 30 30
53031 - 54 54 54 62 62 62 50 50 50 38 38 38
53032 - 14 14 14 2 2 6 2 2 6 2 2 6
53033 - 2 2 6 2 2 6 2 2 6 2 2 6
53034 - 2 2 6 6 6 6 80 54 7 167 114 7
53035 -213 154 11 236 178 12 246 190 14 246 190 14
53036 -246 190 14 246 190 14 246 190 14 246 190 14
53037 -246 190 14 242 186 14 239 182 13 239 182 13
53038 -230 174 11 210 150 10 174 135 50 124 112 88
53039 - 82 82 82 54 54 54 34 34 34 18 18 18
53040 - 6 6 6 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 6 6 6 18 18 18
53044 - 50 50 50 158 118 36 192 133 9 200 144 11
53045 -216 158 10 219 162 10 224 166 10 226 170 11
53046 -230 174 11 236 178 12 239 182 13 239 182 13
53047 -242 186 14 246 186 14 246 190 14 246 190 14
53048 -246 190 14 246 190 14 246 190 14 246 190 14
53049 -246 186 14 230 174 11 210 150 10 163 110 8
53050 -104 69 6 10 10 10 2 2 6 2 2 6
53051 - 2 2 6 2 2 6 2 2 6 2 2 6
53052 - 2 2 6 2 2 6 2 2 6 2 2 6
53053 - 2 2 6 2 2 6 2 2 6 2 2 6
53054 - 2 2 6 6 6 6 91 60 6 167 114 7
53055 -206 145 10 230 174 11 242 186 14 246 190 14
53056 -246 190 14 246 190 14 246 186 14 242 186 14
53057 -239 182 13 230 174 11 224 166 10 213 154 11
53058 -180 133 36 124 112 88 86 86 86 58 58 58
53059 - 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
53064 - 34 34 34 70 70 70 138 110 50 158 118 36
53065 -167 114 7 180 123 7 192 133 9 197 138 11
53066 -200 144 11 206 145 10 213 154 11 219 162 10
53067 -224 166 10 230 174 11 239 182 13 242 186 14
53068 -246 186 14 246 186 14 246 186 14 246 186 14
53069 -239 182 13 216 158 10 185 133 11 152 99 6
53070 -104 69 6 18 14 6 2 2 6 2 2 6
53071 - 2 2 6 2 2 6 2 2 6 2 2 6
53072 - 2 2 6 2 2 6 2 2 6 2 2 6
53073 - 2 2 6 2 2 6 2 2 6 2 2 6
53074 - 2 2 6 6 6 6 80 54 7 152 99 6
53075 -192 133 9 219 162 10 236 178 12 239 182 13
53076 -246 186 14 242 186 14 239 182 13 236 178 12
53077 -224 166 10 206 145 10 192 133 9 154 121 60
53078 - 94 94 94 62 62 62 42 42 42 22 22 22
53079 - 14 14 14 6 6 6 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 6 6 6
53084 - 18 18 18 34 34 34 58 58 58 78 78 78
53085 -101 98 89 124 112 88 142 110 46 156 107 11
53086 -163 110 8 167 114 7 175 118 6 180 123 7
53087 -185 133 11 197 138 11 210 150 10 219 162 10
53088 -226 170 11 236 178 12 236 178 12 234 174 13
53089 -219 162 10 197 138 11 163 110 8 130 83 6
53090 - 91 60 6 10 10 10 2 2 6 2 2 6
53091 - 18 18 18 38 38 38 38 38 38 38 38 38
53092 - 38 38 38 38 38 38 38 38 38 38 38 38
53093 - 38 38 38 38 38 38 26 26 26 2 2 6
53094 - 2 2 6 6 6 6 70 47 6 137 92 6
53095 -175 118 6 200 144 11 219 162 10 230 174 11
53096 -234 174 13 230 174 11 219 162 10 210 150 10
53097 -192 133 9 163 110 8 124 112 88 82 82 82
53098 - 50 50 50 30 30 30 14 14 14 6 6 6
53099 - 0 0 0 0 0 0 0 0 0 0 0 0
53100 - 0 0 0 0 0 0 0 0 0 0 0 0
53101 - 0 0 0 0 0 0 0 0 0 0 0 0
53102 - 0 0 0 0 0 0 0 0 0 0 0 0
53103 - 0 0 0 0 0 0 0 0 0 0 0 0
53104 - 6 6 6 14 14 14 22 22 22 34 34 34
53105 - 42 42 42 58 58 58 74 74 74 86 86 86
53106 -101 98 89 122 102 70 130 98 46 121 87 25
53107 -137 92 6 152 99 6 163 110 8 180 123 7
53108 -185 133 11 197 138 11 206 145 10 200 144 11
53109 -180 123 7 156 107 11 130 83 6 104 69 6
53110 - 50 34 6 54 54 54 110 110 110 101 98 89
53111 - 86 86 86 82 82 82 78 78 78 78 78 78
53112 - 78 78 78 78 78 78 78 78 78 78 78 78
53113 - 78 78 78 82 82 82 86 86 86 94 94 94
53114 -106 106 106 101 101 101 86 66 34 124 80 6
53115 -156 107 11 180 123 7 192 133 9 200 144 11
53116 -206 145 10 200 144 11 192 133 9 175 118 6
53117 -139 102 15 109 106 95 70 70 70 42 42 42
53118 - 22 22 22 10 10 10 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 - 0 0 0 0 0 0 6 6 6 10 10 10
53125 - 14 14 14 22 22 22 30 30 30 38 38 38
53126 - 50 50 50 62 62 62 74 74 74 90 90 90
53127 -101 98 89 112 100 78 121 87 25 124 80 6
53128 -137 92 6 152 99 6 152 99 6 152 99 6
53129 -138 86 6 124 80 6 98 70 6 86 66 30
53130 -101 98 89 82 82 82 58 58 58 46 46 46
53131 - 38 38 38 34 34 34 34 34 34 34 34 34
53132 - 34 34 34 34 34 34 34 34 34 34 34 34
53133 - 34 34 34 34 34 34 38 38 38 42 42 42
53134 - 54 54 54 82 82 82 94 86 76 91 60 6
53135 -134 86 6 156 107 11 167 114 7 175 118 6
53136 -175 118 6 167 114 7 152 99 6 121 87 25
53137 -101 98 89 62 62 62 34 34 34 18 18 18
53138 - 6 6 6 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 0 0 0
53144 - 0 0 0 0 0 0 0 0 0 0 0 0
53145 - 0 0 0 6 6 6 6 6 6 10 10 10
53146 - 18 18 18 22 22 22 30 30 30 42 42 42
53147 - 50 50 50 66 66 66 86 86 86 101 98 89
53148 -106 86 58 98 70 6 104 69 6 104 69 6
53149 -104 69 6 91 60 6 82 62 34 90 90 90
53150 - 62 62 62 38 38 38 22 22 22 14 14 14
53151 - 10 10 10 10 10 10 10 10 10 10 10 10
53152 - 10 10 10 10 10 10 6 6 6 10 10 10
53153 - 10 10 10 10 10 10 10 10 10 14 14 14
53154 - 22 22 22 42 42 42 70 70 70 89 81 66
53155 - 80 54 7 104 69 6 124 80 6 137 92 6
53156 -134 86 6 116 81 8 100 82 52 86 86 86
53157 - 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0
53164 - 0 0 0 0 0 0 0 0 0 0 0 0
53165 - 0 0 0 0 0 0 0 0 0 0 0 0
53166 - 0 0 0 6 6 6 10 10 10 14 14 14
53167 - 18 18 18 26 26 26 38 38 38 54 54 54
53168 - 70 70 70 86 86 86 94 86 76 89 81 66
53169 - 89 81 66 86 86 86 74 74 74 50 50 50
53170 - 30 30 30 14 14 14 6 6 6 0 0 0
53171 - 0 0 0 0 0 0 0 0 0 0 0 0
53172 - 0 0 0 0 0 0 0 0 0 0 0 0
53173 - 0 0 0 0 0 0 0 0 0 0 0 0
53174 - 6 6 6 18 18 18 34 34 34 58 58 58
53175 - 82 82 82 89 81 66 89 81 66 89 81 66
53176 - 94 86 66 94 86 76 74 74 74 50 50 50
53177 - 26 26 26 14 14 14 6 6 6 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 0 0 0 0 0 0
53184 - 0 0 0 0 0 0 0 0 0 0 0 0
53185 - 0 0 0 0 0 0 0 0 0 0 0 0
53186 - 0 0 0 0 0 0 0 0 0 0 0 0
53187 - 6 6 6 6 6 6 14 14 14 18 18 18
53188 - 30 30 30 38 38 38 46 46 46 54 54 54
53189 - 50 50 50 42 42 42 30 30 30 18 18 18
53190 - 10 10 10 0 0 0 0 0 0 0 0 0
53191 - 0 0 0 0 0 0 0 0 0 0 0 0
53192 - 0 0 0 0 0 0 0 0 0 0 0 0
53193 - 0 0 0 0 0 0 0 0 0 0 0 0
53194 - 0 0 0 6 6 6 14 14 14 26 26 26
53195 - 38 38 38 50 50 50 58 58 58 58 58 58
53196 - 54 54 54 42 42 42 30 30 30 18 18 18
53197 - 10 10 10 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 0 0 0 0 0 0 0 0 0
53204 - 0 0 0 0 0 0 0 0 0 0 0 0
53205 - 0 0 0 0 0 0 0 0 0 0 0 0
53206 - 0 0 0 0 0 0 0 0 0 0 0 0
53207 - 0 0 0 0 0 0 0 0 0 6 6 6
53208 - 6 6 6 10 10 10 14 14 14 18 18 18
53209 - 18 18 18 14 14 14 10 10 10 6 6 6
53210 - 0 0 0 0 0 0 0 0 0 0 0 0
53211 - 0 0 0 0 0 0 0 0 0 0 0 0
53212 - 0 0 0 0 0 0 0 0 0 0 0 0
53213 - 0 0 0 0 0 0 0 0 0 0 0 0
53214 - 0 0 0 0 0 0 0 0 0 6 6 6
53215 - 14 14 14 18 18 18 22 22 22 22 22 22
53216 - 18 18 18 14 14 14 10 10 10 6 6 6
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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53235 +4 4 4 4 4 4
53236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53249 +4 4 4 4 4 4
53250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53263 +4 4 4 4 4 4
53264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53277 +4 4 4 4 4 4
53278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53291 +4 4 4 4 4 4
53292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53305 +4 4 4 4 4 4
53306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53310 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
53311 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
53312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53315 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
53316 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53317 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
53318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53319 +4 4 4 4 4 4
53320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53324 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
53325 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
53326 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53329 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
53330 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
53331 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
53332 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53333 +4 4 4 4 4 4
53334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53338 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
53339 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
53340 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53343 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
53344 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
53345 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
53346 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
53347 +4 4 4 4 4 4
53348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53351 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
53352 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
53353 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
53354 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
53355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53356 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53357 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
53358 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
53359 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
53360 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
53361 +4 4 4 4 4 4
53362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53365 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
53366 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
53367 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
53368 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
53369 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53370 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
53371 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
53372 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
53373 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
53374 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
53375 +4 4 4 4 4 4
53376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
53379 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
53380 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
53381 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
53382 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
53383 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
53384 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
53385 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
53386 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
53387 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
53388 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
53389 +4 4 4 4 4 4
53390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53392 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
53393 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
53394 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
53395 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
53396 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
53397 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
53398 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
53399 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
53400 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
53401 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
53402 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
53403 +4 4 4 4 4 4
53404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53406 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
53407 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
53408 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
53409 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
53410 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
53411 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
53412 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
53413 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
53414 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
53415 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
53416 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
53417 +4 4 4 4 4 4
53418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53420 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
53421 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
53422 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
53423 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
53424 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
53425 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
53426 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
53427 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
53428 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
53429 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
53430 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53431 +4 4 4 4 4 4
53432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53434 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
53435 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
53436 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
53437 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
53438 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
53439 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
53440 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
53441 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
53442 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
53443 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
53444 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
53445 +4 4 4 4 4 4
53446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53447 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
53448 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
53449 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
53450 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
53451 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
53452 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
53453 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
53454 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
53455 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
53456 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
53457 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
53458 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
53459 +4 4 4 4 4 4
53460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53461 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
53462 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
53463 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
53464 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53465 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
53466 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
53467 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
53468 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
53469 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
53470 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
53471 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
53472 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
53473 +0 0 0 4 4 4
53474 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53475 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
53476 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
53477 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
53478 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
53479 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
53480 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
53481 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
53482 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
53483 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
53484 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
53485 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
53486 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
53487 +2 0 0 0 0 0
53488 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
53489 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
53490 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
53491 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
53492 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
53493 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
53494 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
53495 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
53496 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
53497 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
53498 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
53499 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
53500 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
53501 +37 38 37 0 0 0
53502 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53503 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
53504 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
53505 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
53506 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
53507 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
53508 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
53509 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
53510 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
53511 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
53512 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
53513 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
53514 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
53515 +85 115 134 4 0 0
53516 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
53517 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
53518 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
53519 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
53520 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
53521 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
53522 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
53523 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
53524 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
53525 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
53526 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
53527 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
53528 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
53529 +60 73 81 4 0 0
53530 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
53531 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
53532 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
53533 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
53534 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
53535 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
53536 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
53537 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
53538 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
53539 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
53540 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
53541 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
53542 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
53543 +16 19 21 4 0 0
53544 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
53545 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
53546 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
53547 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
53548 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
53549 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
53550 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
53551 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
53552 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
53553 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
53554 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
53555 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
53556 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
53557 +4 0 0 4 3 3
53558 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
53559 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
53560 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
53561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
53562 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
53563 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
53564 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
53565 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
53566 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
53567 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
53568 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
53569 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
53570 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
53571 +3 2 2 4 4 4
53572 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
53573 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
53574 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
53575 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53576 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
53577 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
53578 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
53579 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
53580 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
53581 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
53582 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
53583 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
53584 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
53585 +4 4 4 4 4 4
53586 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
53587 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
53588 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
53589 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
53590 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
53591 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
53592 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
53593 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
53594 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
53595 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
53596 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
53597 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
53598 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
53599 +4 4 4 4 4 4
53600 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
53601 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
53602 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
53603 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
53604 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
53605 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53606 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
53607 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
53608 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
53609 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
53610 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
53611 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
53612 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
53613 +5 5 5 5 5 5
53614 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
53615 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
53616 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
53617 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
53618 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
53619 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53620 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
53621 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
53622 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
53623 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
53624 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
53625 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
53626 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
53627 +5 5 5 4 4 4
53628 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
53629 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
53630 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
53631 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
53632 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53633 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
53634 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
53635 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
53636 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
53637 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
53638 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
53639 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53641 +4 4 4 4 4 4
53642 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
53643 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
53644 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
53645 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
53646 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
53647 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53648 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53649 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
53650 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
53651 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
53652 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
53653 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
53654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53655 +4 4 4 4 4 4
53656 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
53657 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
53658 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
53659 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
53660 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53661 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
53662 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
53663 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
53664 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
53665 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
53666 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
53667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53669 +4 4 4 4 4 4
53670 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
53671 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
53672 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
53673 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
53674 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53675 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53676 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53677 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
53678 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
53679 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
53680 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
53681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53683 +4 4 4 4 4 4
53684 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
53685 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
53686 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
53687 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
53688 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53689 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
53690 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53691 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
53692 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
53693 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
53694 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53697 +4 4 4 4 4 4
53698 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
53699 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
53700 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
53701 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
53702 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53703 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
53704 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
53705 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
53706 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
53707 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
53708 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
53709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53711 +4 4 4 4 4 4
53712 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
53713 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
53714 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
53715 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
53716 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53717 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
53718 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
53719 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
53720 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
53721 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
53722 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
53723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53725 +4 4 4 4 4 4
53726 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
53727 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
53728 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
53729 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53730 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
53731 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
53732 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
53733 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
53734 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
53735 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
53736 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53739 +4 4 4 4 4 4
53740 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
53741 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
53742 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
53743 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53744 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53745 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
53746 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
53747 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
53748 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
53749 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
53750 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53753 +4 4 4 4 4 4
53754 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
53755 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
53756 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53757 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53758 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53759 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
53760 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
53761 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
53762 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
53763 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
53764 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53767 +4 4 4 4 4 4
53768 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
53769 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
53770 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53771 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53772 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53773 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
53774 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
53775 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
53776 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53777 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53778 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53781 +4 4 4 4 4 4
53782 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53783 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
53784 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53785 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
53786 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
53787 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
53788 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
53789 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
53790 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53791 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53792 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53795 +4 4 4 4 4 4
53796 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53797 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
53798 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53799 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
53800 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53801 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
53802 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
53803 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
53804 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53805 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53806 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53809 +4 4 4 4 4 4
53810 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
53811 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
53812 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53813 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
53814 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
53815 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
53816 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
53817 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
53818 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53819 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53820 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53823 +4 4 4 4 4 4
53824 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
53825 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
53826 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53827 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
53828 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
53829 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
53830 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
53831 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
53832 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53833 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53834 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53837 +4 4 4 4 4 4
53838 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53839 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
53840 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53841 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
53842 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
53843 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
53844 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
53845 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
53846 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53847 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53848 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53851 +4 4 4 4 4 4
53852 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
53853 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
53854 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53855 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
53856 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
53857 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
53858 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
53859 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
53860 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
53861 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53862 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53865 +4 4 4 4 4 4
53866 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53867 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
53868 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
53869 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
53870 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
53871 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
53872 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
53873 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
53874 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53875 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53876 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53879 +4 4 4 4 4 4
53880 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53881 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
53882 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53883 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
53884 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
53885 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
53886 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
53887 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
53888 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53889 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53890 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53893 +4 4 4 4 4 4
53894 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53895 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
53896 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
53897 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
53898 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
53899 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
53900 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53901 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
53902 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53903 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53904 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53907 +4 4 4 4 4 4
53908 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53909 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
53910 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
53911 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53912 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
53913 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
53914 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53915 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
53916 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53917 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53918 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53921 +4 4 4 4 4 4
53922 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53923 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
53924 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
53925 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
53926 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
53927 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
53928 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
53929 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
53930 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
53931 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53932 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53935 +4 4 4 4 4 4
53936 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53937 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
53938 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
53939 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
53940 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
53941 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
53942 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
53943 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
53944 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
53945 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53946 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53949 +4 4 4 4 4 4
53950 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
53951 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
53952 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
53953 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
53954 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53955 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
53956 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
53957 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
53958 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
53959 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53960 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53963 +4 4 4 4 4 4
53964 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53965 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
53966 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
53967 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
53968 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
53969 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
53970 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
53971 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
53972 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
53973 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53974 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53977 +4 4 4 4 4 4
53978 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
53979 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
53980 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
53981 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
53982 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
53983 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
53984 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
53985 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
53986 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
53987 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
53988 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53991 +4 4 4 4 4 4
53992 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
53993 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
53994 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
53995 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
53996 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
53997 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
53998 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
53999 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54000 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54001 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54002 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54005 +4 4 4 4 4 4
54006 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54007 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54008 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54009 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54010 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54011 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54012 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54013 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54014 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54015 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54016 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54019 +4 4 4 4 4 4
54020 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54021 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54022 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54023 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54024 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54025 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54026 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54027 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54028 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54029 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54030 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54033 +4 4 4 4 4 4
54034 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54035 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54036 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54037 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54038 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54039 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54040 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54041 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54042 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54043 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54047 +4 4 4 4 4 4
54048 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54049 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54050 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54051 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54052 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54053 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54054 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54055 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54056 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54057 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54061 +4 4 4 4 4 4
54062 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54063 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54064 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54065 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54066 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54067 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54068 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54069 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54070 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54071 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54075 +4 4 4 4 4 4
54076 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54077 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54078 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54079 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54080 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54081 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54082 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54083 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54084 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54085 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54089 +4 4 4 4 4 4
54090 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54091 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54092 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54093 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54094 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54095 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54096 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54097 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54098 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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
54104 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54105 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54106 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54107 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54108 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54109 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54110 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54111 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54112 +4 0 0 4 0 0 4 0 0 6 6 6 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
54118 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54119 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54120 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54121 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54122 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54123 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54124 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54125 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54126 +4 0 0 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
54132 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54133 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54134 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54135 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54136 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54137 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54138 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54139 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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
54146 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54147 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54148 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54149 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54150 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54151 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54152 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54153 +6 6 6 4 0 0 4 0 0 4 3 3 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
54160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54161 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54162 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54163 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54164 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54165 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54166 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54167 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54173 +4 4 4 4 4 4
54174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54175 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54176 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54177 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54178 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54179 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54180 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54181 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54187 +4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
54190 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54191 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54192 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54193 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54194 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54195 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54201 +4 4 4 4 4 4
54202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54204 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54205 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54206 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54207 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54208 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54209 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54215 +4 4 4 4 4 4
54216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54219 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54220 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54221 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54222 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54229 +4 4 4 4 4 4
54230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54233 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54234 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54235 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54236 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54237 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54243 +4 4 4 4 4 4
54244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54247 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54248 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54249 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54250 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
54251 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
54255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54257 +4 4 4 4 4 4
54258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54261 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
54262 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
54263 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
54264 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
54265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54266 +4 4 4 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 4 4 4 4 4 4
54269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54271 +4 4 4 4 4 4
54272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54276 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
54277 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54278 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
54283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54285 +4 4 4 4 4 4
54286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54290 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
54291 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
54292 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54299 +4 4 4 4 4 4
54300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54304 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
54305 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
54306 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54313 +4 4 4 4 4 4
54314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54318 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
54319 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
54320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54327 +4 4 4 4 4 4
54328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54332 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54333 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
54334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54341 +4 4 4 4 4 4
54342 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
54343 index a01147f..5d896f8 100644
54344 --- a/drivers/video/matrox/matroxfb_DAC1064.c
54345 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
54346 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54347
54348 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54349 struct matrox_switch matrox_mystique = {
54350 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54351 + .preinit = MGA1064_preinit,
54352 + .reset = MGA1064_reset,
54353 + .init = MGA1064_init,
54354 + .restore = MGA1064_restore,
54355 };
54356 EXPORT_SYMBOL(matrox_mystique);
54357 #endif
54358
54359 #ifdef CONFIG_FB_MATROX_G
54360 struct matrox_switch matrox_G100 = {
54361 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54362 + .preinit = MGAG100_preinit,
54363 + .reset = MGAG100_reset,
54364 + .init = MGAG100_init,
54365 + .restore = MGAG100_restore,
54366 };
54367 EXPORT_SYMBOL(matrox_G100);
54368 #endif
54369 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
54370 index 195ad7c..09743fc 100644
54371 --- a/drivers/video/matrox/matroxfb_Ti3026.c
54372 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
54373 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54374 }
54375
54376 struct matrox_switch matrox_millennium = {
54377 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54378 + .preinit = Ti3026_preinit,
54379 + .reset = Ti3026_reset,
54380 + .init = Ti3026_init,
54381 + .restore = Ti3026_restore
54382 };
54383 EXPORT_SYMBOL(matrox_millennium);
54384 #endif
54385 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
54386 index fe92eed..106e085 100644
54387 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
54388 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
54389 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54390 struct mb862xxfb_par *par = info->par;
54391
54392 if (info->var.bits_per_pixel == 32) {
54393 - info->fbops->fb_fillrect = cfb_fillrect;
54394 - info->fbops->fb_copyarea = cfb_copyarea;
54395 - info->fbops->fb_imageblit = cfb_imageblit;
54396 + pax_open_kernel();
54397 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54398 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54399 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54400 + pax_close_kernel();
54401 } else {
54402 outreg(disp, GC_L0EM, 3);
54403 - info->fbops->fb_fillrect = mb86290fb_fillrect;
54404 - info->fbops->fb_copyarea = mb86290fb_copyarea;
54405 - info->fbops->fb_imageblit = mb86290fb_imageblit;
54406 + pax_open_kernel();
54407 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54408 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54409 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54410 + pax_close_kernel();
54411 }
54412 outreg(draw, GDC_REG_DRAW_BASE, 0);
54413 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54414 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
54415 index ff22871..b129bed 100644
54416 --- a/drivers/video/nvidia/nvidia.c
54417 +++ b/drivers/video/nvidia/nvidia.c
54418 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54419 info->fix.line_length = (info->var.xres_virtual *
54420 info->var.bits_per_pixel) >> 3;
54421 if (info->var.accel_flags) {
54422 - info->fbops->fb_imageblit = nvidiafb_imageblit;
54423 - info->fbops->fb_fillrect = nvidiafb_fillrect;
54424 - info->fbops->fb_copyarea = nvidiafb_copyarea;
54425 - info->fbops->fb_sync = nvidiafb_sync;
54426 + pax_open_kernel();
54427 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54428 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54429 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54430 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54431 + pax_close_kernel();
54432 info->pixmap.scan_align = 4;
54433 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54434 info->flags |= FBINFO_READS_FAST;
54435 NVResetGraphics(info);
54436 } else {
54437 - info->fbops->fb_imageblit = cfb_imageblit;
54438 - info->fbops->fb_fillrect = cfb_fillrect;
54439 - info->fbops->fb_copyarea = cfb_copyarea;
54440 - info->fbops->fb_sync = NULL;
54441 + pax_open_kernel();
54442 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54443 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54444 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54445 + *(void **)&info->fbops->fb_sync = NULL;
54446 + pax_close_kernel();
54447 info->pixmap.scan_align = 1;
54448 info->flags |= FBINFO_HWACCEL_DISABLED;
54449 info->flags &= ~FBINFO_READS_FAST;
54450 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54451 info->pixmap.size = 8 * 1024;
54452 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54453
54454 - if (!hwcur)
54455 - info->fbops->fb_cursor = NULL;
54456 + if (!hwcur) {
54457 + pax_open_kernel();
54458 + *(void **)&info->fbops->fb_cursor = NULL;
54459 + pax_close_kernel();
54460 + }
54461
54462 info->var.accel_flags = (!noaccel);
54463
54464 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
54465 index 669a81f..e216d76 100644
54466 --- a/drivers/video/omap2/dss/display.c
54467 +++ b/drivers/video/omap2/dss/display.c
54468 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54469 snprintf(dssdev->alias, sizeof(dssdev->alias),
54470 "display%d", disp_num_counter++);
54471
54472 + pax_open_kernel();
54473 if (drv && drv->get_resolution == NULL)
54474 - drv->get_resolution = omapdss_default_get_resolution;
54475 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54476 if (drv && drv->get_recommended_bpp == NULL)
54477 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54478 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54479 if (drv && drv->get_timings == NULL)
54480 - drv->get_timings = omapdss_default_get_timings;
54481 + *(void **)&drv->get_timings = omapdss_default_get_timings;
54482 + pax_close_kernel();
54483
54484 mutex_lock(&panel_list_mutex);
54485 list_add_tail(&dssdev->panel_list, &panel_list);
54486 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
54487 index 83433cb..71e9b98 100644
54488 --- a/drivers/video/s1d13xxxfb.c
54489 +++ b/drivers/video/s1d13xxxfb.c
54490 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54491
54492 switch(prod_id) {
54493 case S1D13506_PROD_ID: /* activate acceleration */
54494 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54495 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54496 + pax_open_kernel();
54497 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54498 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54499 + pax_close_kernel();
54500 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54501 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54502 break;
54503 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
54504 index d513ed6..90b0de9 100644
54505 --- a/drivers/video/smscufx.c
54506 +++ b/drivers/video/smscufx.c
54507 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54508 fb_deferred_io_cleanup(info);
54509 kfree(info->fbdefio);
54510 info->fbdefio = NULL;
54511 - info->fbops->fb_mmap = ufx_ops_mmap;
54512 + pax_open_kernel();
54513 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54514 + pax_close_kernel();
54515 }
54516
54517 pr_debug("released /dev/fb%d user=%d count=%d",
54518 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
54519 index 025f14e..20eb4db 100644
54520 --- a/drivers/video/udlfb.c
54521 +++ b/drivers/video/udlfb.c
54522 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54523 dlfb_urb_completion(urb);
54524
54525 error:
54526 - atomic_add(bytes_sent, &dev->bytes_sent);
54527 - atomic_add(bytes_identical, &dev->bytes_identical);
54528 - atomic_add(width*height*2, &dev->bytes_rendered);
54529 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54530 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54531 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54532 end_cycles = get_cycles();
54533 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
54534 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54535 >> 10)), /* Kcycles */
54536 &dev->cpu_kcycles_used);
54537
54538 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54539 dlfb_urb_completion(urb);
54540
54541 error:
54542 - atomic_add(bytes_sent, &dev->bytes_sent);
54543 - atomic_add(bytes_identical, &dev->bytes_identical);
54544 - atomic_add(bytes_rendered, &dev->bytes_rendered);
54545 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54546 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54547 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54548 end_cycles = get_cycles();
54549 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
54550 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54551 >> 10)), /* Kcycles */
54552 &dev->cpu_kcycles_used);
54553 }
54554 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
54555 fb_deferred_io_cleanup(info);
54556 kfree(info->fbdefio);
54557 info->fbdefio = NULL;
54558 - info->fbops->fb_mmap = dlfb_ops_mmap;
54559 + pax_open_kernel();
54560 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
54561 + pax_close_kernel();
54562 }
54563
54564 pr_warn("released /dev/fb%d user=%d count=%d\n",
54565 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
54566 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54567 struct dlfb_data *dev = fb_info->par;
54568 return snprintf(buf, PAGE_SIZE, "%u\n",
54569 - atomic_read(&dev->bytes_rendered));
54570 + atomic_read_unchecked(&dev->bytes_rendered));
54571 }
54572
54573 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54574 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54575 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54576 struct dlfb_data *dev = fb_info->par;
54577 return snprintf(buf, PAGE_SIZE, "%u\n",
54578 - atomic_read(&dev->bytes_identical));
54579 + atomic_read_unchecked(&dev->bytes_identical));
54580 }
54581
54582 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54583 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54584 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54585 struct dlfb_data *dev = fb_info->par;
54586 return snprintf(buf, PAGE_SIZE, "%u\n",
54587 - atomic_read(&dev->bytes_sent));
54588 + atomic_read_unchecked(&dev->bytes_sent));
54589 }
54590
54591 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54592 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54593 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54594 struct dlfb_data *dev = fb_info->par;
54595 return snprintf(buf, PAGE_SIZE, "%u\n",
54596 - atomic_read(&dev->cpu_kcycles_used));
54597 + atomic_read_unchecked(&dev->cpu_kcycles_used));
54598 }
54599
54600 static ssize_t edid_show(
54601 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
54602 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54603 struct dlfb_data *dev = fb_info->par;
54604
54605 - atomic_set(&dev->bytes_rendered, 0);
54606 - atomic_set(&dev->bytes_identical, 0);
54607 - atomic_set(&dev->bytes_sent, 0);
54608 - atomic_set(&dev->cpu_kcycles_used, 0);
54609 + atomic_set_unchecked(&dev->bytes_rendered, 0);
54610 + atomic_set_unchecked(&dev->bytes_identical, 0);
54611 + atomic_set_unchecked(&dev->bytes_sent, 0);
54612 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
54613
54614 return count;
54615 }
54616 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
54617 index 256fba7..6e75516 100644
54618 --- a/drivers/video/uvesafb.c
54619 +++ b/drivers/video/uvesafb.c
54620 @@ -19,6 +19,7 @@
54621 #include <linux/io.h>
54622 #include <linux/mutex.h>
54623 #include <linux/slab.h>
54624 +#include <linux/moduleloader.h>
54625 #include <video/edid.h>
54626 #include <video/uvesafb.h>
54627 #ifdef CONFIG_X86
54628 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
54629 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
54630 par->pmi_setpal = par->ypan = 0;
54631 } else {
54632 +
54633 +#ifdef CONFIG_PAX_KERNEXEC
54634 +#ifdef CONFIG_MODULES
54635 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
54636 +#endif
54637 + if (!par->pmi_code) {
54638 + par->pmi_setpal = par->ypan = 0;
54639 + return 0;
54640 + }
54641 +#endif
54642 +
54643 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
54644 + task->t.regs.edi);
54645 +
54646 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54647 + pax_open_kernel();
54648 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
54649 + pax_close_kernel();
54650 +
54651 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
54652 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
54653 +#else
54654 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
54655 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
54656 +#endif
54657 +
54658 printk(KERN_INFO "uvesafb: protected mode interface info at "
54659 "%04x:%04x\n",
54660 (u16)task->t.regs.es, (u16)task->t.regs.edi);
54661 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
54662 par->ypan = ypan;
54663
54664 if (par->pmi_setpal || par->ypan) {
54665 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
54666 if (__supported_pte_mask & _PAGE_NX) {
54667 par->pmi_setpal = par->ypan = 0;
54668 printk(KERN_WARNING "uvesafb: NX protection is active, "
54669 "better not use the PMI.\n");
54670 - } else {
54671 + } else
54672 +#endif
54673 uvesafb_vbe_getpmi(task, par);
54674 - }
54675 }
54676 #else
54677 /* The protected mode interface is not available on non-x86. */
54678 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54679 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
54680
54681 /* Disable blanking if the user requested so. */
54682 - if (!blank)
54683 - info->fbops->fb_blank = NULL;
54684 + if (!blank) {
54685 + pax_open_kernel();
54686 + *(void **)&info->fbops->fb_blank = NULL;
54687 + pax_close_kernel();
54688 + }
54689
54690 /*
54691 * Find out how much IO memory is required for the mode with
54692 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54693 info->flags = FBINFO_FLAG_DEFAULT |
54694 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
54695
54696 - if (!par->ypan)
54697 - info->fbops->fb_pan_display = NULL;
54698 + if (!par->ypan) {
54699 + pax_open_kernel();
54700 + *(void **)&info->fbops->fb_pan_display = NULL;
54701 + pax_close_kernel();
54702 + }
54703 }
54704
54705 static void uvesafb_init_mtrr(struct fb_info *info)
54706 @@ -1792,6 +1822,11 @@ out_mode:
54707 out:
54708 kfree(par->vbe_modes);
54709
54710 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54711 + if (par->pmi_code)
54712 + module_free_exec(NULL, par->pmi_code);
54713 +#endif
54714 +
54715 framebuffer_release(info);
54716 return err;
54717 }
54718 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
54719 kfree(par->vbe_modes);
54720 kfree(par->vbe_state_orig);
54721 kfree(par->vbe_state_saved);
54722 +
54723 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54724 + if (par->pmi_code)
54725 + module_free_exec(NULL, par->pmi_code);
54726 +#endif
54727 +
54728 }
54729
54730 framebuffer_release(info);
54731 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
54732 index 1c7da3b..56ea0bd 100644
54733 --- a/drivers/video/vesafb.c
54734 +++ b/drivers/video/vesafb.c
54735 @@ -9,6 +9,7 @@
54736 */
54737
54738 #include <linux/module.h>
54739 +#include <linux/moduleloader.h>
54740 #include <linux/kernel.h>
54741 #include <linux/errno.h>
54742 #include <linux/string.h>
54743 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
54744 static int vram_total; /* Set total amount of memory */
54745 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
54746 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
54747 -static void (*pmi_start)(void) __read_mostly;
54748 -static void (*pmi_pal) (void) __read_mostly;
54749 +static void (*pmi_start)(void) __read_only;
54750 +static void (*pmi_pal) (void) __read_only;
54751 static int depth __read_mostly;
54752 static int vga_compat __read_mostly;
54753 /* --------------------------------------------------------------------- */
54754 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
54755 unsigned int size_remap;
54756 unsigned int size_total;
54757 char *option = NULL;
54758 + void *pmi_code = NULL;
54759
54760 /* ignore error return of fb_get_options */
54761 fb_get_options("vesafb", &option);
54762 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
54763 size_remap = size_total;
54764 vesafb_fix.smem_len = size_remap;
54765
54766 -#ifndef __i386__
54767 - screen_info.vesapm_seg = 0;
54768 -#endif
54769 -
54770 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
54771 printk(KERN_WARNING
54772 "vesafb: cannot reserve video memory at 0x%lx\n",
54773 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
54774 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
54775 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
54776
54777 +#ifdef __i386__
54778 +
54779 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54780 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
54781 + if (!pmi_code)
54782 +#elif !defined(CONFIG_PAX_KERNEXEC)
54783 + if (0)
54784 +#endif
54785 +
54786 +#endif
54787 + screen_info.vesapm_seg = 0;
54788 +
54789 if (screen_info.vesapm_seg) {
54790 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
54791 - screen_info.vesapm_seg,screen_info.vesapm_off);
54792 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
54793 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
54794 }
54795
54796 if (screen_info.vesapm_seg < 0xc000)
54797 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
54798
54799 if (ypan || pmi_setpal) {
54800 unsigned short *pmi_base;
54801 +
54802 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
54803 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
54804 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
54805 +
54806 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54807 + pax_open_kernel();
54808 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
54809 +#else
54810 + pmi_code = pmi_base;
54811 +#endif
54812 +
54813 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
54814 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
54815 +
54816 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54817 + pmi_start = ktva_ktla(pmi_start);
54818 + pmi_pal = ktva_ktla(pmi_pal);
54819 + pax_close_kernel();
54820 +#endif
54821 +
54822 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
54823 if (pmi_base[3]) {
54824 printk(KERN_INFO "vesafb: pmi: ports = ");
54825 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
54826 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
54827 (ypan ? FBINFO_HWACCEL_YPAN : 0);
54828
54829 - if (!ypan)
54830 - info->fbops->fb_pan_display = NULL;
54831 + if (!ypan) {
54832 + pax_open_kernel();
54833 + *(void **)&info->fbops->fb_pan_display = NULL;
54834 + pax_close_kernel();
54835 + }
54836
54837 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
54838 err = -ENOMEM;
54839 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
54840 fb_info(info, "%s frame buffer device\n", info->fix.id);
54841 return 0;
54842 err:
54843 +
54844 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54845 + module_free_exec(NULL, pmi_code);
54846 +#endif
54847 +
54848 if (info->screen_base)
54849 iounmap(info->screen_base);
54850 framebuffer_release(info);
54851 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
54852 index 88714ae..16c2e11 100644
54853 --- a/drivers/video/via/via_clock.h
54854 +++ b/drivers/video/via/via_clock.h
54855 @@ -56,7 +56,7 @@ struct via_clock {
54856
54857 void (*set_engine_pll_state)(u8 state);
54858 void (*set_engine_pll)(struct via_pll_config config);
54859 -};
54860 +} __no_const;
54861
54862
54863 static inline u32 get_pll_internal_frequency(u32 ref_freq,
54864 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
54865 index fef20db..d28b1ab 100644
54866 --- a/drivers/xen/xenfs/xenstored.c
54867 +++ b/drivers/xen/xenfs/xenstored.c
54868 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
54869 static int xsd_kva_open(struct inode *inode, struct file *file)
54870 {
54871 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
54872 +#ifdef CONFIG_GRKERNSEC_HIDESYM
54873 + NULL);
54874 +#else
54875 xen_store_interface);
54876 +#endif
54877 +
54878 if (!file->private_data)
54879 return -ENOMEM;
54880 return 0;
54881 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
54882 index 9ff073f..05cef23 100644
54883 --- a/fs/9p/vfs_addr.c
54884 +++ b/fs/9p/vfs_addr.c
54885 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
54886
54887 retval = v9fs_file_write_internal(inode,
54888 v9inode->writeback_fid,
54889 - (__force const char __user *)buffer,
54890 + (const char __force_user *)buffer,
54891 len, &offset, 0);
54892 if (retval > 0)
54893 retval = 0;
54894 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
54895 index 4e65aa9..043dc9a 100644
54896 --- a/fs/9p/vfs_inode.c
54897 +++ b/fs/9p/vfs_inode.c
54898 @@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54899 void
54900 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54901 {
54902 - char *s = nd_get_link(nd);
54903 + const char *s = nd_get_link(nd);
54904
54905 p9_debug(P9_DEBUG_VFS, " %s %s\n",
54906 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
54907 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
54908 index 370b24c..ff0be7b 100644
54909 --- a/fs/Kconfig.binfmt
54910 +++ b/fs/Kconfig.binfmt
54911 @@ -103,7 +103,7 @@ config HAVE_AOUT
54912
54913 config BINFMT_AOUT
54914 tristate "Kernel support for a.out and ECOFF binaries"
54915 - depends on HAVE_AOUT
54916 + depends on HAVE_AOUT && BROKEN
54917 ---help---
54918 A.out (Assembler.OUTput) is a set of formats for libraries and
54919 executables used in the earliest versions of UNIX. Linux used
54920 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
54921 index ce25d75..dc09eeb 100644
54922 --- a/fs/afs/inode.c
54923 +++ b/fs/afs/inode.c
54924 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54925 struct afs_vnode *vnode;
54926 struct super_block *sb;
54927 struct inode *inode;
54928 - static atomic_t afs_autocell_ino;
54929 + static atomic_unchecked_t afs_autocell_ino;
54930
54931 _enter("{%x:%u},%*.*s,",
54932 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
54933 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54934 data.fid.unique = 0;
54935 data.fid.vnode = 0;
54936
54937 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
54938 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
54939 afs_iget5_autocell_test, afs_iget5_set,
54940 &data);
54941 if (!inode) {
54942 diff --git a/fs/aio.c b/fs/aio.c
54943 index 062a5f6..e5618e0 100644
54944 --- a/fs/aio.c
54945 +++ b/fs/aio.c
54946 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
54947 size += sizeof(struct io_event) * nr_events;
54948
54949 nr_pages = PFN_UP(size);
54950 - if (nr_pages < 0)
54951 + if (nr_pages <= 0)
54952 return -EINVAL;
54953
54954 file = aio_private_file(ctx, nr_pages);
54955 diff --git a/fs/attr.c b/fs/attr.c
54956 index 267968d..5dd8f96 100644
54957 --- a/fs/attr.c
54958 +++ b/fs/attr.c
54959 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
54960 unsigned long limit;
54961
54962 limit = rlimit(RLIMIT_FSIZE);
54963 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
54964 if (limit != RLIM_INFINITY && offset > limit)
54965 goto out_sig;
54966 if (offset > inode->i_sb->s_maxbytes)
54967 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
54968 index 689e40d..515cac5 100644
54969 --- a/fs/autofs4/waitq.c
54970 +++ b/fs/autofs4/waitq.c
54971 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
54972 {
54973 unsigned long sigpipe, flags;
54974 mm_segment_t fs;
54975 - const char *data = (const char *)addr;
54976 + const char __user *data = (const char __force_user *)addr;
54977 ssize_t wr = 0;
54978
54979 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
54980 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
54981 return 1;
54982 }
54983
54984 +#ifdef CONFIG_GRKERNSEC_HIDESYM
54985 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
54986 +#endif
54987 +
54988 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
54989 enum autofs_notify notify)
54990 {
54991 @@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
54992
54993 /* If this is a direct mount request create a dummy name */
54994 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
54995 +#ifdef CONFIG_GRKERNSEC_HIDESYM
54996 + /* this name does get written to userland via autofs4_write() */
54997 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
54998 +#else
54999 qstr.len = sprintf(name, "%p", dentry);
55000 +#endif
55001 else {
55002 qstr.len = autofs4_getpath(sbi, dentry, &name);
55003 if (!qstr.len) {
55004 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55005 index 2722387..56059b5 100644
55006 --- a/fs/befs/endian.h
55007 +++ b/fs/befs/endian.h
55008 @@ -11,7 +11,7 @@
55009
55010 #include <asm/byteorder.h>
55011
55012 -static inline u64
55013 +static inline u64 __intentional_overflow(-1)
55014 fs64_to_cpu(const struct super_block *sb, fs64 n)
55015 {
55016 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55017 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55018 return (__force fs64)cpu_to_be64(n);
55019 }
55020
55021 -static inline u32
55022 +static inline u32 __intentional_overflow(-1)
55023 fs32_to_cpu(const struct super_block *sb, fs32 n)
55024 {
55025 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55026 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55027 return (__force fs32)cpu_to_be32(n);
55028 }
55029
55030 -static inline u16
55031 +static inline u16 __intentional_overflow(-1)
55032 fs16_to_cpu(const struct super_block *sb, fs16 n)
55033 {
55034 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55035 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55036 index ca0ba15..0fa3257 100644
55037 --- a/fs/binfmt_aout.c
55038 +++ b/fs/binfmt_aout.c
55039 @@ -16,6 +16,7 @@
55040 #include <linux/string.h>
55041 #include <linux/fs.h>
55042 #include <linux/file.h>
55043 +#include <linux/security.h>
55044 #include <linux/stat.h>
55045 #include <linux/fcntl.h>
55046 #include <linux/ptrace.h>
55047 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55048 #endif
55049 # define START_STACK(u) ((void __user *)u.start_stack)
55050
55051 + memset(&dump, 0, sizeof(dump));
55052 +
55053 fs = get_fs();
55054 set_fs(KERNEL_DS);
55055 has_dumped = 1;
55056 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55057
55058 /* If the size of the dump file exceeds the rlimit, then see what would happen
55059 if we wrote the stack, but not the data area. */
55060 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55061 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55062 dump.u_dsize = 0;
55063
55064 /* Make sure we have enough room to write the stack and data areas. */
55065 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55066 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55067 dump.u_ssize = 0;
55068
55069 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55070 rlim = rlimit(RLIMIT_DATA);
55071 if (rlim >= RLIM_INFINITY)
55072 rlim = ~0;
55073 +
55074 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55075 if (ex.a_data + ex.a_bss > rlim)
55076 return -ENOMEM;
55077
55078 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55079
55080 install_exec_creds(bprm);
55081
55082 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55083 + current->mm->pax_flags = 0UL;
55084 +#endif
55085 +
55086 +#ifdef CONFIG_PAX_PAGEEXEC
55087 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55088 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55089 +
55090 +#ifdef CONFIG_PAX_EMUTRAMP
55091 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55092 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55093 +#endif
55094 +
55095 +#ifdef CONFIG_PAX_MPROTECT
55096 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55097 + current->mm->pax_flags |= MF_PAX_MPROTECT;
55098 +#endif
55099 +
55100 + }
55101 +#endif
55102 +
55103 if (N_MAGIC(ex) == OMAGIC) {
55104 unsigned long text_addr, map_size;
55105 loff_t pos;
55106 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55107 }
55108
55109 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55110 - PROT_READ | PROT_WRITE | PROT_EXEC,
55111 + PROT_READ | PROT_WRITE,
55112 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55113 fd_offset + ex.a_text);
55114 if (error != N_DATADDR(ex)) {
55115 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55116 index 571a423..dbb9c6c 100644
55117 --- a/fs/binfmt_elf.c
55118 +++ b/fs/binfmt_elf.c
55119 @@ -34,6 +34,7 @@
55120 #include <linux/utsname.h>
55121 #include <linux/coredump.h>
55122 #include <linux/sched.h>
55123 +#include <linux/xattr.h>
55124 #include <asm/uaccess.h>
55125 #include <asm/param.h>
55126 #include <asm/page.h>
55127 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55128 #define elf_core_dump NULL
55129 #endif
55130
55131 +#ifdef CONFIG_PAX_MPROTECT
55132 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55133 +#endif
55134 +
55135 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55136 +static void elf_handle_mmap(struct file *file);
55137 +#endif
55138 +
55139 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55140 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55141 #else
55142 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55143 .load_binary = load_elf_binary,
55144 .load_shlib = load_elf_library,
55145 .core_dump = elf_core_dump,
55146 +
55147 +#ifdef CONFIG_PAX_MPROTECT
55148 + .handle_mprotect= elf_handle_mprotect,
55149 +#endif
55150 +
55151 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55152 + .handle_mmap = elf_handle_mmap,
55153 +#endif
55154 +
55155 .min_coredump = ELF_EXEC_PAGESIZE,
55156 };
55157
55158 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55159
55160 static int set_brk(unsigned long start, unsigned long end)
55161 {
55162 + unsigned long e = end;
55163 +
55164 start = ELF_PAGEALIGN(start);
55165 end = ELF_PAGEALIGN(end);
55166 if (end > start) {
55167 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55168 if (BAD_ADDR(addr))
55169 return addr;
55170 }
55171 - current->mm->start_brk = current->mm->brk = end;
55172 + current->mm->start_brk = current->mm->brk = e;
55173 return 0;
55174 }
55175
55176 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55177 elf_addr_t __user *u_rand_bytes;
55178 const char *k_platform = ELF_PLATFORM;
55179 const char *k_base_platform = ELF_BASE_PLATFORM;
55180 - unsigned char k_rand_bytes[16];
55181 + u32 k_rand_bytes[4];
55182 int items;
55183 elf_addr_t *elf_info;
55184 int ei_index = 0;
55185 const struct cred *cred = current_cred();
55186 struct vm_area_struct *vma;
55187 + unsigned long saved_auxv[AT_VECTOR_SIZE];
55188
55189 /*
55190 * In some cases (e.g. Hyper-Threading), we want to avoid L1
55191 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55192 * Generate 16 random bytes for userspace PRNG seeding.
55193 */
55194 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
55195 - u_rand_bytes = (elf_addr_t __user *)
55196 - STACK_ALLOC(p, sizeof(k_rand_bytes));
55197 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
55198 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
55199 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
55200 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
55201 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
55202 + u_rand_bytes = (elf_addr_t __user *) p;
55203 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
55204 return -EFAULT;
55205
55206 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55207 return -EFAULT;
55208 current->mm->env_end = p;
55209
55210 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
55211 +
55212 /* Put the elf_info on the stack in the right place. */
55213 sp = (elf_addr_t __user *)envp + 1;
55214 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
55215 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
55216 return -EFAULT;
55217 return 0;
55218 }
55219 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
55220 an ELF header */
55221
55222 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55223 - struct file *interpreter, unsigned long *interp_map_addr,
55224 - unsigned long no_base)
55225 + struct file *interpreter, unsigned long no_base)
55226 {
55227 struct elf_phdr *elf_phdata;
55228 struct elf_phdr *eppnt;
55229 - unsigned long load_addr = 0;
55230 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
55231 int load_addr_set = 0;
55232 unsigned long last_bss = 0, elf_bss = 0;
55233 - unsigned long error = ~0UL;
55234 + unsigned long error = -EINVAL;
55235 unsigned long total_size;
55236 int retval, i, size;
55237
55238 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55239 goto out_close;
55240 }
55241
55242 +#ifdef CONFIG_PAX_SEGMEXEC
55243 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
55244 + pax_task_size = SEGMEXEC_TASK_SIZE;
55245 +#endif
55246 +
55247 eppnt = elf_phdata;
55248 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
55249 if (eppnt->p_type == PT_LOAD) {
55250 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55251 map_addr = elf_map(interpreter, load_addr + vaddr,
55252 eppnt, elf_prot, elf_type, total_size);
55253 total_size = 0;
55254 - if (!*interp_map_addr)
55255 - *interp_map_addr = map_addr;
55256 error = map_addr;
55257 if (BAD_ADDR(map_addr))
55258 goto out_close;
55259 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55260 k = load_addr + eppnt->p_vaddr;
55261 if (BAD_ADDR(k) ||
55262 eppnt->p_filesz > eppnt->p_memsz ||
55263 - eppnt->p_memsz > TASK_SIZE ||
55264 - TASK_SIZE - eppnt->p_memsz < k) {
55265 + eppnt->p_memsz > pax_task_size ||
55266 + pax_task_size - eppnt->p_memsz < k) {
55267 error = -ENOMEM;
55268 goto out_close;
55269 }
55270 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55271 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
55272
55273 /* Map the last of the bss segment */
55274 - error = vm_brk(elf_bss, last_bss - elf_bss);
55275 - if (BAD_ADDR(error))
55276 - goto out_close;
55277 + if (last_bss > elf_bss) {
55278 + error = vm_brk(elf_bss, last_bss - elf_bss);
55279 + if (BAD_ADDR(error))
55280 + goto out_close;
55281 + }
55282 }
55283
55284 error = load_addr;
55285 @@ -538,6 +569,336 @@ out:
55286 return error;
55287 }
55288
55289 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
55290 +#ifdef CONFIG_PAX_SOFTMODE
55291 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
55292 +{
55293 + unsigned long pax_flags = 0UL;
55294 +
55295 +#ifdef CONFIG_PAX_PAGEEXEC
55296 + if (elf_phdata->p_flags & PF_PAGEEXEC)
55297 + pax_flags |= MF_PAX_PAGEEXEC;
55298 +#endif
55299 +
55300 +#ifdef CONFIG_PAX_SEGMEXEC
55301 + if (elf_phdata->p_flags & PF_SEGMEXEC)
55302 + pax_flags |= MF_PAX_SEGMEXEC;
55303 +#endif
55304 +
55305 +#ifdef CONFIG_PAX_EMUTRAMP
55306 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55307 + pax_flags |= MF_PAX_EMUTRAMP;
55308 +#endif
55309 +
55310 +#ifdef CONFIG_PAX_MPROTECT
55311 + if (elf_phdata->p_flags & PF_MPROTECT)
55312 + pax_flags |= MF_PAX_MPROTECT;
55313 +#endif
55314 +
55315 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55316 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
55317 + pax_flags |= MF_PAX_RANDMMAP;
55318 +#endif
55319 +
55320 + return pax_flags;
55321 +}
55322 +#endif
55323 +
55324 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
55325 +{
55326 + unsigned long pax_flags = 0UL;
55327 +
55328 +#ifdef CONFIG_PAX_PAGEEXEC
55329 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
55330 + pax_flags |= MF_PAX_PAGEEXEC;
55331 +#endif
55332 +
55333 +#ifdef CONFIG_PAX_SEGMEXEC
55334 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
55335 + pax_flags |= MF_PAX_SEGMEXEC;
55336 +#endif
55337 +
55338 +#ifdef CONFIG_PAX_EMUTRAMP
55339 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
55340 + pax_flags |= MF_PAX_EMUTRAMP;
55341 +#endif
55342 +
55343 +#ifdef CONFIG_PAX_MPROTECT
55344 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
55345 + pax_flags |= MF_PAX_MPROTECT;
55346 +#endif
55347 +
55348 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55349 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
55350 + pax_flags |= MF_PAX_RANDMMAP;
55351 +#endif
55352 +
55353 + return pax_flags;
55354 +}
55355 +#endif
55356 +
55357 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55358 +#ifdef CONFIG_PAX_SOFTMODE
55359 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
55360 +{
55361 + unsigned long pax_flags = 0UL;
55362 +
55363 +#ifdef CONFIG_PAX_PAGEEXEC
55364 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
55365 + pax_flags |= MF_PAX_PAGEEXEC;
55366 +#endif
55367 +
55368 +#ifdef CONFIG_PAX_SEGMEXEC
55369 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
55370 + pax_flags |= MF_PAX_SEGMEXEC;
55371 +#endif
55372 +
55373 +#ifdef CONFIG_PAX_EMUTRAMP
55374 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55375 + pax_flags |= MF_PAX_EMUTRAMP;
55376 +#endif
55377 +
55378 +#ifdef CONFIG_PAX_MPROTECT
55379 + if (pax_flags_softmode & MF_PAX_MPROTECT)
55380 + pax_flags |= MF_PAX_MPROTECT;
55381 +#endif
55382 +
55383 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55384 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
55385 + pax_flags |= MF_PAX_RANDMMAP;
55386 +#endif
55387 +
55388 + return pax_flags;
55389 +}
55390 +#endif
55391 +
55392 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
55393 +{
55394 + unsigned long pax_flags = 0UL;
55395 +
55396 +#ifdef CONFIG_PAX_PAGEEXEC
55397 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
55398 + pax_flags |= MF_PAX_PAGEEXEC;
55399 +#endif
55400 +
55401 +#ifdef CONFIG_PAX_SEGMEXEC
55402 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
55403 + pax_flags |= MF_PAX_SEGMEXEC;
55404 +#endif
55405 +
55406 +#ifdef CONFIG_PAX_EMUTRAMP
55407 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
55408 + pax_flags |= MF_PAX_EMUTRAMP;
55409 +#endif
55410 +
55411 +#ifdef CONFIG_PAX_MPROTECT
55412 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
55413 + pax_flags |= MF_PAX_MPROTECT;
55414 +#endif
55415 +
55416 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55417 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
55418 + pax_flags |= MF_PAX_RANDMMAP;
55419 +#endif
55420 +
55421 + return pax_flags;
55422 +}
55423 +#endif
55424 +
55425 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55426 +static unsigned long pax_parse_defaults(void)
55427 +{
55428 + unsigned long pax_flags = 0UL;
55429 +
55430 +#ifdef CONFIG_PAX_SOFTMODE
55431 + if (pax_softmode)
55432 + return pax_flags;
55433 +#endif
55434 +
55435 +#ifdef CONFIG_PAX_PAGEEXEC
55436 + pax_flags |= MF_PAX_PAGEEXEC;
55437 +#endif
55438 +
55439 +#ifdef CONFIG_PAX_SEGMEXEC
55440 + pax_flags |= MF_PAX_SEGMEXEC;
55441 +#endif
55442 +
55443 +#ifdef CONFIG_PAX_MPROTECT
55444 + pax_flags |= MF_PAX_MPROTECT;
55445 +#endif
55446 +
55447 +#ifdef CONFIG_PAX_RANDMMAP
55448 + if (randomize_va_space)
55449 + pax_flags |= MF_PAX_RANDMMAP;
55450 +#endif
55451 +
55452 + return pax_flags;
55453 +}
55454 +
55455 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
55456 +{
55457 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
55458 +
55459 +#ifdef CONFIG_PAX_EI_PAX
55460 +
55461 +#ifdef CONFIG_PAX_SOFTMODE
55462 + if (pax_softmode)
55463 + return pax_flags;
55464 +#endif
55465 +
55466 + pax_flags = 0UL;
55467 +
55468 +#ifdef CONFIG_PAX_PAGEEXEC
55469 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
55470 + pax_flags |= MF_PAX_PAGEEXEC;
55471 +#endif
55472 +
55473 +#ifdef CONFIG_PAX_SEGMEXEC
55474 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
55475 + pax_flags |= MF_PAX_SEGMEXEC;
55476 +#endif
55477 +
55478 +#ifdef CONFIG_PAX_EMUTRAMP
55479 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
55480 + pax_flags |= MF_PAX_EMUTRAMP;
55481 +#endif
55482 +
55483 +#ifdef CONFIG_PAX_MPROTECT
55484 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
55485 + pax_flags |= MF_PAX_MPROTECT;
55486 +#endif
55487 +
55488 +#ifdef CONFIG_PAX_ASLR
55489 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
55490 + pax_flags |= MF_PAX_RANDMMAP;
55491 +#endif
55492 +
55493 +#endif
55494 +
55495 + return pax_flags;
55496 +
55497 +}
55498 +
55499 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
55500 +{
55501 +
55502 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
55503 + unsigned long i;
55504 +
55505 + for (i = 0UL; i < elf_ex->e_phnum; i++)
55506 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
55507 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
55508 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
55509 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
55510 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
55511 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
55512 + return PAX_PARSE_FLAGS_FALLBACK;
55513 +
55514 +#ifdef CONFIG_PAX_SOFTMODE
55515 + if (pax_softmode)
55516 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
55517 + else
55518 +#endif
55519 +
55520 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
55521 + break;
55522 + }
55523 +#endif
55524 +
55525 + return PAX_PARSE_FLAGS_FALLBACK;
55526 +}
55527 +
55528 +static unsigned long pax_parse_xattr_pax(struct file * const file)
55529 +{
55530 +
55531 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55532 + ssize_t xattr_size, i;
55533 + unsigned char xattr_value[sizeof("pemrs") - 1];
55534 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
55535 +
55536 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
55537 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
55538 + return PAX_PARSE_FLAGS_FALLBACK;
55539 +
55540 + for (i = 0; i < xattr_size; i++)
55541 + switch (xattr_value[i]) {
55542 + default:
55543 + return PAX_PARSE_FLAGS_FALLBACK;
55544 +
55545 +#define parse_flag(option1, option2, flag) \
55546 + case option1: \
55547 + if (pax_flags_hardmode & MF_PAX_##flag) \
55548 + return PAX_PARSE_FLAGS_FALLBACK;\
55549 + pax_flags_hardmode |= MF_PAX_##flag; \
55550 + break; \
55551 + case option2: \
55552 + if (pax_flags_softmode & MF_PAX_##flag) \
55553 + return PAX_PARSE_FLAGS_FALLBACK;\
55554 + pax_flags_softmode |= MF_PAX_##flag; \
55555 + break;
55556 +
55557 + parse_flag('p', 'P', PAGEEXEC);
55558 + parse_flag('e', 'E', EMUTRAMP);
55559 + parse_flag('m', 'M', MPROTECT);
55560 + parse_flag('r', 'R', RANDMMAP);
55561 + parse_flag('s', 'S', SEGMEXEC);
55562 +
55563 +#undef parse_flag
55564 + }
55565 +
55566 + if (pax_flags_hardmode & pax_flags_softmode)
55567 + return PAX_PARSE_FLAGS_FALLBACK;
55568 +
55569 +#ifdef CONFIG_PAX_SOFTMODE
55570 + if (pax_softmode)
55571 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
55572 + else
55573 +#endif
55574 +
55575 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
55576 +#else
55577 + return PAX_PARSE_FLAGS_FALLBACK;
55578 +#endif
55579 +
55580 +}
55581 +
55582 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
55583 +{
55584 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
55585 +
55586 + pax_flags = pax_parse_defaults();
55587 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
55588 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
55589 + xattr_pax_flags = pax_parse_xattr_pax(file);
55590 +
55591 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55592 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55593 + pt_pax_flags != xattr_pax_flags)
55594 + return -EINVAL;
55595 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55596 + pax_flags = xattr_pax_flags;
55597 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55598 + pax_flags = pt_pax_flags;
55599 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55600 + pax_flags = ei_pax_flags;
55601 +
55602 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
55603 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55604 + if ((__supported_pte_mask & _PAGE_NX))
55605 + pax_flags &= ~MF_PAX_SEGMEXEC;
55606 + else
55607 + pax_flags &= ~MF_PAX_PAGEEXEC;
55608 + }
55609 +#endif
55610 +
55611 + if (0 > pax_check_flags(&pax_flags))
55612 + return -EINVAL;
55613 +
55614 + current->mm->pax_flags = pax_flags;
55615 + return 0;
55616 +}
55617 +#endif
55618 +
55619 /*
55620 * These are the functions used to load ELF style executables and shared
55621 * libraries. There is no binary dependent code anywhere else.
55622 @@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
55623 {
55624 unsigned int random_variable = 0;
55625
55626 +#ifdef CONFIG_PAX_RANDUSTACK
55627 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
55628 + return stack_top - current->mm->delta_stack;
55629 +#endif
55630 +
55631 if ((current->flags & PF_RANDOMIZE) &&
55632 !(current->personality & ADDR_NO_RANDOMIZE)) {
55633 random_variable = get_random_int() & STACK_RND_MASK;
55634 @@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
55635 unsigned long load_addr = 0, load_bias = 0;
55636 int load_addr_set = 0;
55637 char * elf_interpreter = NULL;
55638 - unsigned long error;
55639 + unsigned long error = 0;
55640 struct elf_phdr *elf_ppnt, *elf_phdata;
55641 unsigned long elf_bss, elf_brk;
55642 int retval, i;
55643 @@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
55644 unsigned long start_code, end_code, start_data, end_data;
55645 unsigned long reloc_func_desc __maybe_unused = 0;
55646 int executable_stack = EXSTACK_DEFAULT;
55647 - unsigned long def_flags = 0;
55648 struct pt_regs *regs = current_pt_regs();
55649 struct {
55650 struct elfhdr elf_ex;
55651 struct elfhdr interp_elf_ex;
55652 } *loc;
55653 + unsigned long pax_task_size;
55654
55655 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
55656 if (!loc) {
55657 @@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
55658 goto out_free_dentry;
55659
55660 /* OK, This is the point of no return */
55661 - current->mm->def_flags = def_flags;
55662 + current->mm->def_flags = 0;
55663
55664 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
55665 may depend on the personality. */
55666 SET_PERSONALITY(loc->elf_ex);
55667 +
55668 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55669 + current->mm->pax_flags = 0UL;
55670 +#endif
55671 +
55672 +#ifdef CONFIG_PAX_DLRESOLVE
55673 + current->mm->call_dl_resolve = 0UL;
55674 +#endif
55675 +
55676 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
55677 + current->mm->call_syscall = 0UL;
55678 +#endif
55679 +
55680 +#ifdef CONFIG_PAX_ASLR
55681 + current->mm->delta_mmap = 0UL;
55682 + current->mm->delta_stack = 0UL;
55683 +#endif
55684 +
55685 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55686 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
55687 + send_sig(SIGKILL, current, 0);
55688 + goto out_free_dentry;
55689 + }
55690 +#endif
55691 +
55692 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55693 + pax_set_initial_flags(bprm);
55694 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
55695 + if (pax_set_initial_flags_func)
55696 + (pax_set_initial_flags_func)(bprm);
55697 +#endif
55698 +
55699 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55700 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
55701 + current->mm->context.user_cs_limit = PAGE_SIZE;
55702 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
55703 + }
55704 +#endif
55705 +
55706 +#ifdef CONFIG_PAX_SEGMEXEC
55707 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
55708 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
55709 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
55710 + pax_task_size = SEGMEXEC_TASK_SIZE;
55711 + current->mm->def_flags |= VM_NOHUGEPAGE;
55712 + } else
55713 +#endif
55714 +
55715 + pax_task_size = TASK_SIZE;
55716 +
55717 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
55718 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55719 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
55720 + put_cpu();
55721 + }
55722 +#endif
55723 +
55724 +#ifdef CONFIG_PAX_ASLR
55725 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55726 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
55727 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
55728 + }
55729 +#endif
55730 +
55731 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55732 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55733 + executable_stack = EXSTACK_DISABLE_X;
55734 + current->personality &= ~READ_IMPLIES_EXEC;
55735 + } else
55736 +#endif
55737 +
55738 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
55739 current->personality |= READ_IMPLIES_EXEC;
55740
55741 @@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
55742 #else
55743 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
55744 #endif
55745 +
55746 +#ifdef CONFIG_PAX_RANDMMAP
55747 + /* PaX: randomize base address at the default exe base if requested */
55748 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
55749 +#ifdef CONFIG_SPARC64
55750 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
55751 +#else
55752 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
55753 +#endif
55754 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
55755 + elf_flags |= MAP_FIXED;
55756 + }
55757 +#endif
55758 +
55759 }
55760
55761 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
55762 @@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
55763 * allowed task size. Note that p_filesz must always be
55764 * <= p_memsz so it is only necessary to check p_memsz.
55765 */
55766 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55767 - elf_ppnt->p_memsz > TASK_SIZE ||
55768 - TASK_SIZE - elf_ppnt->p_memsz < k) {
55769 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55770 + elf_ppnt->p_memsz > pax_task_size ||
55771 + pax_task_size - elf_ppnt->p_memsz < k) {
55772 /* set_brk can never work. Avoid overflows. */
55773 send_sig(SIGKILL, current, 0);
55774 retval = -EINVAL;
55775 @@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
55776 goto out_free_dentry;
55777 }
55778 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
55779 - send_sig(SIGSEGV, current, 0);
55780 - retval = -EFAULT; /* Nobody gets to see this, but.. */
55781 - goto out_free_dentry;
55782 + /*
55783 + * This bss-zeroing can fail if the ELF
55784 + * file specifies odd protections. So
55785 + * we don't check the return value
55786 + */
55787 }
55788
55789 +#ifdef CONFIG_PAX_RANDMMAP
55790 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55791 + unsigned long start, size, flags;
55792 + vm_flags_t vm_flags;
55793 +
55794 + start = ELF_PAGEALIGN(elf_brk);
55795 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
55796 + flags = MAP_FIXED | MAP_PRIVATE;
55797 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
55798 +
55799 + down_write(&current->mm->mmap_sem);
55800 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
55801 + retval = -ENOMEM;
55802 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
55803 +// if (current->personality & ADDR_NO_RANDOMIZE)
55804 +// vm_flags |= VM_READ | VM_MAYREAD;
55805 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
55806 + retval = IS_ERR_VALUE(start) ? start : 0;
55807 + }
55808 + up_write(&current->mm->mmap_sem);
55809 + if (retval == 0)
55810 + retval = set_brk(start + size, start + size + PAGE_SIZE);
55811 + if (retval < 0) {
55812 + send_sig(SIGKILL, current, 0);
55813 + goto out_free_dentry;
55814 + }
55815 + }
55816 +#endif
55817 +
55818 if (elf_interpreter) {
55819 - unsigned long interp_map_addr = 0;
55820 -
55821 elf_entry = load_elf_interp(&loc->interp_elf_ex,
55822 interpreter,
55823 - &interp_map_addr,
55824 load_bias);
55825 if (!IS_ERR((void *)elf_entry)) {
55826 /*
55827 @@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
55828 * Decide what to dump of a segment, part, all or none.
55829 */
55830 static unsigned long vma_dump_size(struct vm_area_struct *vma,
55831 - unsigned long mm_flags)
55832 + unsigned long mm_flags, long signr)
55833 {
55834 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
55835
55836 @@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
55837 if (vma->vm_file == NULL)
55838 return 0;
55839
55840 - if (FILTER(MAPPED_PRIVATE))
55841 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
55842 goto whole;
55843
55844 /*
55845 @@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
55846 {
55847 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
55848 int i = 0;
55849 - do
55850 + do {
55851 i += 2;
55852 - while (auxv[i - 2] != AT_NULL);
55853 + } while (auxv[i - 2] != AT_NULL);
55854 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
55855 }
55856
55857 @@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
55858 {
55859 mm_segment_t old_fs = get_fs();
55860 set_fs(KERNEL_DS);
55861 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
55862 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
55863 set_fs(old_fs);
55864 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
55865 }
55866 @@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
55867 }
55868
55869 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
55870 - unsigned long mm_flags)
55871 + struct coredump_params *cprm)
55872 {
55873 struct vm_area_struct *vma;
55874 size_t size = 0;
55875
55876 for (vma = first_vma(current, gate_vma); vma != NULL;
55877 vma = next_vma(vma, gate_vma))
55878 - size += vma_dump_size(vma, mm_flags);
55879 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55880 return size;
55881 }
55882
55883 @@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55884
55885 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
55886
55887 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
55888 + offset += elf_core_vma_data_size(gate_vma, cprm);
55889 offset += elf_core_extra_data_size();
55890 e_shoff = offset;
55891
55892 @@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55893 phdr.p_offset = offset;
55894 phdr.p_vaddr = vma->vm_start;
55895 phdr.p_paddr = 0;
55896 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
55897 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55898 phdr.p_memsz = vma->vm_end - vma->vm_start;
55899 offset += phdr.p_filesz;
55900 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
55901 @@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55902 unsigned long addr;
55903 unsigned long end;
55904
55905 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
55906 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55907
55908 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
55909 struct page *page;
55910 @@ -2202,6 +2681,167 @@ out:
55911
55912 #endif /* CONFIG_ELF_CORE */
55913
55914 +#ifdef CONFIG_PAX_MPROTECT
55915 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
55916 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
55917 + * we'll remove VM_MAYWRITE for good on RELRO segments.
55918 + *
55919 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
55920 + * basis because we want to allow the common case and not the special ones.
55921 + */
55922 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
55923 +{
55924 + struct elfhdr elf_h;
55925 + struct elf_phdr elf_p;
55926 + unsigned long i;
55927 + unsigned long oldflags;
55928 + bool is_textrel_rw, is_textrel_rx, is_relro;
55929 +
55930 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
55931 + return;
55932 +
55933 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
55934 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
55935 +
55936 +#ifdef CONFIG_PAX_ELFRELOCS
55937 + /* possible TEXTREL */
55938 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
55939 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
55940 +#else
55941 + is_textrel_rw = false;
55942 + is_textrel_rx = false;
55943 +#endif
55944 +
55945 + /* possible RELRO */
55946 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
55947 +
55948 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
55949 + return;
55950 +
55951 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
55952 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
55953 +
55954 +#ifdef CONFIG_PAX_ETEXECRELOCS
55955 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55956 +#else
55957 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
55958 +#endif
55959 +
55960 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55961 + !elf_check_arch(&elf_h) ||
55962 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
55963 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
55964 + return;
55965 +
55966 + for (i = 0UL; i < elf_h.e_phnum; i++) {
55967 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
55968 + return;
55969 + switch (elf_p.p_type) {
55970 + case PT_DYNAMIC:
55971 + if (!is_textrel_rw && !is_textrel_rx)
55972 + continue;
55973 + i = 0UL;
55974 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
55975 + elf_dyn dyn;
55976 +
55977 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
55978 + break;
55979 + if (dyn.d_tag == DT_NULL)
55980 + break;
55981 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
55982 + gr_log_textrel(vma);
55983 + if (is_textrel_rw)
55984 + vma->vm_flags |= VM_MAYWRITE;
55985 + else
55986 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
55987 + vma->vm_flags &= ~VM_MAYWRITE;
55988 + break;
55989 + }
55990 + i++;
55991 + }
55992 + is_textrel_rw = false;
55993 + is_textrel_rx = false;
55994 + continue;
55995 +
55996 + case PT_GNU_RELRO:
55997 + if (!is_relro)
55998 + continue;
55999 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56000 + vma->vm_flags &= ~VM_MAYWRITE;
56001 + is_relro = false;
56002 + continue;
56003 +
56004 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56005 + case PT_PAX_FLAGS: {
56006 + const char *msg_mprotect = "", *msg_emutramp = "";
56007 + char *buffer_lib, *buffer_exe;
56008 +
56009 + if (elf_p.p_flags & PF_NOMPROTECT)
56010 + msg_mprotect = "MPROTECT disabled";
56011 +
56012 +#ifdef CONFIG_PAX_EMUTRAMP
56013 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56014 + msg_emutramp = "EMUTRAMP enabled";
56015 +#endif
56016 +
56017 + if (!msg_mprotect[0] && !msg_emutramp[0])
56018 + continue;
56019 +
56020 + if (!printk_ratelimit())
56021 + continue;
56022 +
56023 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56024 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56025 + if (buffer_lib && buffer_exe) {
56026 + char *path_lib, *path_exe;
56027 +
56028 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56029 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56030 +
56031 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56032 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56033 +
56034 + }
56035 + free_page((unsigned long)buffer_exe);
56036 + free_page((unsigned long)buffer_lib);
56037 + continue;
56038 + }
56039 +#endif
56040 +
56041 + }
56042 + }
56043 +}
56044 +#endif
56045 +
56046 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56047 +
56048 +extern int grsec_enable_log_rwxmaps;
56049 +
56050 +static void elf_handle_mmap(struct file *file)
56051 +{
56052 + struct elfhdr elf_h;
56053 + struct elf_phdr elf_p;
56054 + unsigned long i;
56055 +
56056 + if (!grsec_enable_log_rwxmaps)
56057 + return;
56058 +
56059 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56060 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56061 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56062 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56063 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56064 + return;
56065 +
56066 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56067 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56068 + return;
56069 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56070 + gr_log_ptgnustack(file);
56071 + }
56072 +}
56073 +#endif
56074 +
56075 static int __init init_elf_binfmt(void)
56076 {
56077 register_binfmt(&elf_format);
56078 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56079 index d50bbe5..af3b649 100644
56080 --- a/fs/binfmt_flat.c
56081 +++ b/fs/binfmt_flat.c
56082 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56083 realdatastart = (unsigned long) -ENOMEM;
56084 printk("Unable to allocate RAM for process data, errno %d\n",
56085 (int)-realdatastart);
56086 + down_write(&current->mm->mmap_sem);
56087 vm_munmap(textpos, text_len);
56088 + up_write(&current->mm->mmap_sem);
56089 ret = realdatastart;
56090 goto err;
56091 }
56092 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56093 }
56094 if (IS_ERR_VALUE(result)) {
56095 printk("Unable to read data+bss, errno %d\n", (int)-result);
56096 + down_write(&current->mm->mmap_sem);
56097 vm_munmap(textpos, text_len);
56098 vm_munmap(realdatastart, len);
56099 + up_write(&current->mm->mmap_sem);
56100 ret = result;
56101 goto err;
56102 }
56103 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56104 }
56105 if (IS_ERR_VALUE(result)) {
56106 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56107 + down_write(&current->mm->mmap_sem);
56108 vm_munmap(textpos, text_len + data_len + extra +
56109 MAX_SHARED_LIBS * sizeof(unsigned long));
56110 + up_write(&current->mm->mmap_sem);
56111 ret = result;
56112 goto err;
56113 }
56114 diff --git a/fs/bio.c b/fs/bio.c
56115 index 33d79a4..c3c9893 100644
56116 --- a/fs/bio.c
56117 +++ b/fs/bio.c
56118 @@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56119 /*
56120 * Overflow, abort
56121 */
56122 - if (end < start)
56123 + if (end < start || end - start > INT_MAX - nr_pages)
56124 return ERR_PTR(-EINVAL);
56125
56126 nr_pages += end - start;
56127 @@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56128 /*
56129 * Overflow, abort
56130 */
56131 - if (end < start)
56132 + if (end < start || end - start > INT_MAX - nr_pages)
56133 return ERR_PTR(-EINVAL);
56134
56135 nr_pages += end - start;
56136 @@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56137 const int read = bio_data_dir(bio) == READ;
56138 struct bio_map_data *bmd = bio->bi_private;
56139 int i;
56140 - char *p = bmd->sgvecs[0].iov_base;
56141 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56142
56143 bio_for_each_segment_all(bvec, bio, i) {
56144 char *addr = page_address(bvec->bv_page);
56145 diff --git a/fs/block_dev.c b/fs/block_dev.c
56146 index 1e86823..8e34695 100644
56147 --- a/fs/block_dev.c
56148 +++ b/fs/block_dev.c
56149 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56150 else if (bdev->bd_contains == bdev)
56151 return true; /* is a whole device which isn't held */
56152
56153 - else if (whole->bd_holder == bd_may_claim)
56154 + else if (whole->bd_holder == (void *)bd_may_claim)
56155 return true; /* is a partition of a device that is being partitioned */
56156 else if (whole->bd_holder != NULL)
56157 return false; /* is a partition of a held device */
56158 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56159 index 316136b..e7a3a50 100644
56160 --- a/fs/btrfs/ctree.c
56161 +++ b/fs/btrfs/ctree.c
56162 @@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56163 free_extent_buffer(buf);
56164 add_root_to_dirty_list(root);
56165 } else {
56166 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56167 - parent_start = parent->start;
56168 - else
56169 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56170 + if (parent)
56171 + parent_start = parent->start;
56172 + else
56173 + parent_start = 0;
56174 + } else
56175 parent_start = 0;
56176
56177 WARN_ON(trans->transid != btrfs_header_generation(parent));
56178 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56179 index 8d292fb..bc205c2 100644
56180 --- a/fs/btrfs/delayed-inode.c
56181 +++ b/fs/btrfs/delayed-inode.c
56182 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56183
56184 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56185 {
56186 - int seq = atomic_inc_return(&delayed_root->items_seq);
56187 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
56188 if ((atomic_dec_return(&delayed_root->items) <
56189 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
56190 waitqueue_active(&delayed_root->wait))
56191 @@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
56192 static int refs_newer(struct btrfs_delayed_root *delayed_root,
56193 int seq, int count)
56194 {
56195 - int val = atomic_read(&delayed_root->items_seq);
56196 + int val = atomic_read_unchecked(&delayed_root->items_seq);
56197
56198 if (val < seq || val >= seq + count)
56199 return 1;
56200 @@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
56201 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
56202 return;
56203
56204 - seq = atomic_read(&delayed_root->items_seq);
56205 + seq = atomic_read_unchecked(&delayed_root->items_seq);
56206
56207 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
56208 int ret;
56209 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
56210 index a4b38f9..f86a509 100644
56211 --- a/fs/btrfs/delayed-inode.h
56212 +++ b/fs/btrfs/delayed-inode.h
56213 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
56214 */
56215 struct list_head prepare_list;
56216 atomic_t items; /* for delayed items */
56217 - atomic_t items_seq; /* for delayed items */
56218 + atomic_unchecked_t items_seq; /* for delayed items */
56219 int nodes; /* for delayed nodes */
56220 wait_queue_head_t wait;
56221 };
56222 @@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
56223 struct btrfs_delayed_root *delayed_root)
56224 {
56225 atomic_set(&delayed_root->items, 0);
56226 - atomic_set(&delayed_root->items_seq, 0);
56227 + atomic_set_unchecked(&delayed_root->items_seq, 0);
56228 delayed_root->nodes = 0;
56229 spin_lock_init(&delayed_root->lock);
56230 init_waitqueue_head(&delayed_root->wait);
56231 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
56232 index 9f831bb..14afde5 100644
56233 --- a/fs/btrfs/ioctl.c
56234 +++ b/fs/btrfs/ioctl.c
56235 @@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56236 for (i = 0; i < num_types; i++) {
56237 struct btrfs_space_info *tmp;
56238
56239 + /* Don't copy in more than we allocated */
56240 if (!slot_count)
56241 break;
56242
56243 + slot_count--;
56244 +
56245 info = NULL;
56246 rcu_read_lock();
56247 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
56248 @@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56249 memcpy(dest, &space, sizeof(space));
56250 dest++;
56251 space_args.total_spaces++;
56252 - slot_count--;
56253 }
56254 - if (!slot_count)
56255 - break;
56256 }
56257 up_read(&info->groups_sem);
56258 }
56259 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
56260 index d71a11d..384e2c4 100644
56261 --- a/fs/btrfs/super.c
56262 +++ b/fs/btrfs/super.c
56263 @@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
56264 function, line, errstr);
56265 return;
56266 }
56267 - ACCESS_ONCE(trans->transaction->aborted) = errno;
56268 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
56269 /* Wake up anybody who may be waiting on this transaction */
56270 wake_up(&root->fs_info->transaction_wait);
56271 wake_up(&root->fs_info->transaction_blocked_wait);
56272 diff --git a/fs/buffer.c b/fs/buffer.c
56273 index 6024877..7bd000a 100644
56274 --- a/fs/buffer.c
56275 +++ b/fs/buffer.c
56276 @@ -3426,7 +3426,7 @@ void __init buffer_init(void)
56277 bh_cachep = kmem_cache_create("buffer_head",
56278 sizeof(struct buffer_head), 0,
56279 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
56280 - SLAB_MEM_SPREAD),
56281 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
56282 NULL);
56283
56284 /*
56285 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
56286 index 622f469..e8d2d55 100644
56287 --- a/fs/cachefiles/bind.c
56288 +++ b/fs/cachefiles/bind.c
56289 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
56290 args);
56291
56292 /* start by checking things over */
56293 - ASSERT(cache->fstop_percent >= 0 &&
56294 - cache->fstop_percent < cache->fcull_percent &&
56295 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
56296 cache->fcull_percent < cache->frun_percent &&
56297 cache->frun_percent < 100);
56298
56299 - ASSERT(cache->bstop_percent >= 0 &&
56300 - cache->bstop_percent < cache->bcull_percent &&
56301 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
56302 cache->bcull_percent < cache->brun_percent &&
56303 cache->brun_percent < 100);
56304
56305 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
56306 index 0a1467b..6a53245 100644
56307 --- a/fs/cachefiles/daemon.c
56308 +++ b/fs/cachefiles/daemon.c
56309 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
56310 if (n > buflen)
56311 return -EMSGSIZE;
56312
56313 - if (copy_to_user(_buffer, buffer, n) != 0)
56314 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
56315 return -EFAULT;
56316
56317 return n;
56318 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
56319 if (test_bit(CACHEFILES_DEAD, &cache->flags))
56320 return -EIO;
56321
56322 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
56323 + if (datalen > PAGE_SIZE - 1)
56324 return -EOPNOTSUPP;
56325
56326 /* drag the command string into the kernel so we can parse it */
56327 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
56328 if (args[0] != '%' || args[1] != '\0')
56329 return -EINVAL;
56330
56331 - if (fstop < 0 || fstop >= cache->fcull_percent)
56332 + if (fstop >= cache->fcull_percent)
56333 return cachefiles_daemon_range_error(cache, args);
56334
56335 cache->fstop_percent = fstop;
56336 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
56337 if (args[0] != '%' || args[1] != '\0')
56338 return -EINVAL;
56339
56340 - if (bstop < 0 || bstop >= cache->bcull_percent)
56341 + if (bstop >= cache->bcull_percent)
56342 return cachefiles_daemon_range_error(cache, args);
56343
56344 cache->bstop_percent = bstop;
56345 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
56346 index 5349473..d6c0b93 100644
56347 --- a/fs/cachefiles/internal.h
56348 +++ b/fs/cachefiles/internal.h
56349 @@ -59,7 +59,7 @@ struct cachefiles_cache {
56350 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
56351 struct rb_root active_nodes; /* active nodes (can't be culled) */
56352 rwlock_t active_lock; /* lock for active_nodes */
56353 - atomic_t gravecounter; /* graveyard uniquifier */
56354 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
56355 unsigned frun_percent; /* when to stop culling (% files) */
56356 unsigned fcull_percent; /* when to start culling (% files) */
56357 unsigned fstop_percent; /* when to stop allocating (% files) */
56358 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
56359 * proc.c
56360 */
56361 #ifdef CONFIG_CACHEFILES_HISTOGRAM
56362 -extern atomic_t cachefiles_lookup_histogram[HZ];
56363 -extern atomic_t cachefiles_mkdir_histogram[HZ];
56364 -extern atomic_t cachefiles_create_histogram[HZ];
56365 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56366 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56367 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
56368
56369 extern int __init cachefiles_proc_init(void);
56370 extern void cachefiles_proc_cleanup(void);
56371 static inline
56372 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
56373 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
56374 {
56375 unsigned long jif = jiffies - start_jif;
56376 if (jif >= HZ)
56377 jif = HZ - 1;
56378 - atomic_inc(&histogram[jif]);
56379 + atomic_inc_unchecked(&histogram[jif]);
56380 }
56381
56382 #else
56383 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
56384 index ca65f39..48921e3 100644
56385 --- a/fs/cachefiles/namei.c
56386 +++ b/fs/cachefiles/namei.c
56387 @@ -317,7 +317,7 @@ try_again:
56388 /* first step is to make up a grave dentry in the graveyard */
56389 sprintf(nbuffer, "%08x%08x",
56390 (uint32_t) get_seconds(),
56391 - (uint32_t) atomic_inc_return(&cache->gravecounter));
56392 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
56393
56394 /* do the multiway lock magic */
56395 trap = lock_rename(cache->graveyard, dir);
56396 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
56397 index eccd339..4c1d995 100644
56398 --- a/fs/cachefiles/proc.c
56399 +++ b/fs/cachefiles/proc.c
56400 @@ -14,9 +14,9 @@
56401 #include <linux/seq_file.h>
56402 #include "internal.h"
56403
56404 -atomic_t cachefiles_lookup_histogram[HZ];
56405 -atomic_t cachefiles_mkdir_histogram[HZ];
56406 -atomic_t cachefiles_create_histogram[HZ];
56407 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56408 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56409 +atomic_unchecked_t cachefiles_create_histogram[HZ];
56410
56411 /*
56412 * display the latency histogram
56413 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
56414 return 0;
56415 default:
56416 index = (unsigned long) v - 3;
56417 - x = atomic_read(&cachefiles_lookup_histogram[index]);
56418 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
56419 - z = atomic_read(&cachefiles_create_histogram[index]);
56420 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
56421 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
56422 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
56423 if (x == 0 && y == 0 && z == 0)
56424 return 0;
56425
56426 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
56427 index ebaff36..7e3ea26 100644
56428 --- a/fs/cachefiles/rdwr.c
56429 +++ b/fs/cachefiles/rdwr.c
56430 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
56431 old_fs = get_fs();
56432 set_fs(KERNEL_DS);
56433 ret = file->f_op->write(
56434 - file, (const void __user *) data, len, &pos);
56435 + file, (const void __force_user *) data, len, &pos);
56436 set_fs(old_fs);
56437 kunmap(page);
56438 file_end_write(file);
56439 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
56440 index 2a0bcae..34ec24e 100644
56441 --- a/fs/ceph/dir.c
56442 +++ b/fs/ceph/dir.c
56443 @@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
56444 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
56445 struct ceph_mds_client *mdsc = fsc->mdsc;
56446 unsigned frag = fpos_frag(ctx->pos);
56447 - int off = fpos_off(ctx->pos);
56448 + unsigned int off = fpos_off(ctx->pos);
56449 int err;
56450 u32 ftype;
56451 struct ceph_mds_reply_info_parsed *rinfo;
56452 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
56453 index 6a0951e..03fac6d 100644
56454 --- a/fs/ceph/super.c
56455 +++ b/fs/ceph/super.c
56456 @@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
56457 /*
56458 * construct our own bdi so we can control readahead, etc.
56459 */
56460 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
56461 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
56462
56463 static int ceph_register_bdi(struct super_block *sb,
56464 struct ceph_fs_client *fsc)
56465 @@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
56466 default_backing_dev_info.ra_pages;
56467
56468 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
56469 - atomic_long_inc_return(&bdi_seq));
56470 + atomic_long_inc_return_unchecked(&bdi_seq));
56471 if (!err)
56472 sb->s_bdi = &fsc->backing_dev_info;
56473 return err;
56474 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
56475 index f3ac415..3d2420c 100644
56476 --- a/fs/cifs/cifs_debug.c
56477 +++ b/fs/cifs/cifs_debug.c
56478 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56479
56480 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
56481 #ifdef CONFIG_CIFS_STATS2
56482 - atomic_set(&totBufAllocCount, 0);
56483 - atomic_set(&totSmBufAllocCount, 0);
56484 + atomic_set_unchecked(&totBufAllocCount, 0);
56485 + atomic_set_unchecked(&totSmBufAllocCount, 0);
56486 #endif /* CONFIG_CIFS_STATS2 */
56487 spin_lock(&cifs_tcp_ses_lock);
56488 list_for_each(tmp1, &cifs_tcp_ses_list) {
56489 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56490 tcon = list_entry(tmp3,
56491 struct cifs_tcon,
56492 tcon_list);
56493 - atomic_set(&tcon->num_smbs_sent, 0);
56494 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
56495 if (server->ops->clear_stats)
56496 server->ops->clear_stats(tcon);
56497 }
56498 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56499 smBufAllocCount.counter, cifs_min_small);
56500 #ifdef CONFIG_CIFS_STATS2
56501 seq_printf(m, "Total Large %d Small %d Allocations\n",
56502 - atomic_read(&totBufAllocCount),
56503 - atomic_read(&totSmBufAllocCount));
56504 + atomic_read_unchecked(&totBufAllocCount),
56505 + atomic_read_unchecked(&totSmBufAllocCount));
56506 #endif /* CONFIG_CIFS_STATS2 */
56507
56508 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
56509 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56510 if (tcon->need_reconnect)
56511 seq_puts(m, "\tDISCONNECTED ");
56512 seq_printf(m, "\nSMBs: %d",
56513 - atomic_read(&tcon->num_smbs_sent));
56514 + atomic_read_unchecked(&tcon->num_smbs_sent));
56515 if (server->ops->print_stats)
56516 server->ops->print_stats(m, tcon);
56517 }
56518 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
56519 index 849f613..eae6dec 100644
56520 --- a/fs/cifs/cifsfs.c
56521 +++ b/fs/cifs/cifsfs.c
56522 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
56523 */
56524 cifs_req_cachep = kmem_cache_create("cifs_request",
56525 CIFSMaxBufSize + max_hdr_size, 0,
56526 - SLAB_HWCACHE_ALIGN, NULL);
56527 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
56528 if (cifs_req_cachep == NULL)
56529 return -ENOMEM;
56530
56531 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
56532 efficient to alloc 1 per page off the slab compared to 17K (5page)
56533 alloc of large cifs buffers even when page debugging is on */
56534 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
56535 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
56536 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
56537 NULL);
56538 if (cifs_sm_req_cachep == NULL) {
56539 mempool_destroy(cifs_req_poolp);
56540 @@ -1168,8 +1168,8 @@ init_cifs(void)
56541 atomic_set(&bufAllocCount, 0);
56542 atomic_set(&smBufAllocCount, 0);
56543 #ifdef CONFIG_CIFS_STATS2
56544 - atomic_set(&totBufAllocCount, 0);
56545 - atomic_set(&totSmBufAllocCount, 0);
56546 + atomic_set_unchecked(&totBufAllocCount, 0);
56547 + atomic_set_unchecked(&totSmBufAllocCount, 0);
56548 #endif /* CONFIG_CIFS_STATS2 */
56549
56550 atomic_set(&midCount, 0);
56551 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
56552 index f918a99..bb300d5 100644
56553 --- a/fs/cifs/cifsglob.h
56554 +++ b/fs/cifs/cifsglob.h
56555 @@ -787,35 +787,35 @@ struct cifs_tcon {
56556 __u16 Flags; /* optional support bits */
56557 enum statusEnum tidStatus;
56558 #ifdef CONFIG_CIFS_STATS
56559 - atomic_t num_smbs_sent;
56560 + atomic_unchecked_t num_smbs_sent;
56561 union {
56562 struct {
56563 - atomic_t num_writes;
56564 - atomic_t num_reads;
56565 - atomic_t num_flushes;
56566 - atomic_t num_oplock_brks;
56567 - atomic_t num_opens;
56568 - atomic_t num_closes;
56569 - atomic_t num_deletes;
56570 - atomic_t num_mkdirs;
56571 - atomic_t num_posixopens;
56572 - atomic_t num_posixmkdirs;
56573 - atomic_t num_rmdirs;
56574 - atomic_t num_renames;
56575 - atomic_t num_t2renames;
56576 - atomic_t num_ffirst;
56577 - atomic_t num_fnext;
56578 - atomic_t num_fclose;
56579 - atomic_t num_hardlinks;
56580 - atomic_t num_symlinks;
56581 - atomic_t num_locks;
56582 - atomic_t num_acl_get;
56583 - atomic_t num_acl_set;
56584 + atomic_unchecked_t num_writes;
56585 + atomic_unchecked_t num_reads;
56586 + atomic_unchecked_t num_flushes;
56587 + atomic_unchecked_t num_oplock_brks;
56588 + atomic_unchecked_t num_opens;
56589 + atomic_unchecked_t num_closes;
56590 + atomic_unchecked_t num_deletes;
56591 + atomic_unchecked_t num_mkdirs;
56592 + atomic_unchecked_t num_posixopens;
56593 + atomic_unchecked_t num_posixmkdirs;
56594 + atomic_unchecked_t num_rmdirs;
56595 + atomic_unchecked_t num_renames;
56596 + atomic_unchecked_t num_t2renames;
56597 + atomic_unchecked_t num_ffirst;
56598 + atomic_unchecked_t num_fnext;
56599 + atomic_unchecked_t num_fclose;
56600 + atomic_unchecked_t num_hardlinks;
56601 + atomic_unchecked_t num_symlinks;
56602 + atomic_unchecked_t num_locks;
56603 + atomic_unchecked_t num_acl_get;
56604 + atomic_unchecked_t num_acl_set;
56605 } cifs_stats;
56606 #ifdef CONFIG_CIFS_SMB2
56607 struct {
56608 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56609 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56610 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56611 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56612 } smb2_stats;
56613 #endif /* CONFIG_CIFS_SMB2 */
56614 } stats;
56615 @@ -1145,7 +1145,7 @@ convert_delimiter(char *path, char delim)
56616 }
56617
56618 #ifdef CONFIG_CIFS_STATS
56619 -#define cifs_stats_inc atomic_inc
56620 +#define cifs_stats_inc atomic_inc_unchecked
56621
56622 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
56623 unsigned int bytes)
56624 @@ -1511,8 +1511,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
56625 /* Various Debug counters */
56626 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
56627 #ifdef CONFIG_CIFS_STATS2
56628 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
56629 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
56630 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
56631 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
56632 #endif
56633 GLOBAL_EXTERN atomic_t smBufAllocCount;
56634 GLOBAL_EXTERN atomic_t midCount;
56635 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
56636 index 5a5a872..92c3210 100644
56637 --- a/fs/cifs/file.c
56638 +++ b/fs/cifs/file.c
56639 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
56640 index = mapping->writeback_index; /* Start from prev offset */
56641 end = -1;
56642 } else {
56643 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
56644 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
56645 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
56646 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
56647 range_whole = true;
56648 + index = 0;
56649 + end = ULONG_MAX;
56650 + } else {
56651 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
56652 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
56653 + }
56654 scanned = true;
56655 }
56656 retry:
56657 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
56658 index 2f9f379..43f8025 100644
56659 --- a/fs/cifs/misc.c
56660 +++ b/fs/cifs/misc.c
56661 @@ -170,7 +170,7 @@ cifs_buf_get(void)
56662 memset(ret_buf, 0, buf_size + 3);
56663 atomic_inc(&bufAllocCount);
56664 #ifdef CONFIG_CIFS_STATS2
56665 - atomic_inc(&totBufAllocCount);
56666 + atomic_inc_unchecked(&totBufAllocCount);
56667 #endif /* CONFIG_CIFS_STATS2 */
56668 }
56669
56670 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
56671 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
56672 atomic_inc(&smBufAllocCount);
56673 #ifdef CONFIG_CIFS_STATS2
56674 - atomic_inc(&totSmBufAllocCount);
56675 + atomic_inc_unchecked(&totSmBufAllocCount);
56676 #endif /* CONFIG_CIFS_STATS2 */
56677
56678 }
56679 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
56680 index 5f5ba0d..8d6ef7d 100644
56681 --- a/fs/cifs/smb1ops.c
56682 +++ b/fs/cifs/smb1ops.c
56683 @@ -609,27 +609,27 @@ static void
56684 cifs_clear_stats(struct cifs_tcon *tcon)
56685 {
56686 #ifdef CONFIG_CIFS_STATS
56687 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
56688 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
56689 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
56690 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56691 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
56692 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
56693 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56694 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
56695 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
56696 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
56697 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
56698 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
56699 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
56700 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
56701 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
56702 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
56703 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
56704 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
56705 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
56706 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
56707 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
56708 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
56709 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
56710 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
56711 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56712 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
56713 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
56714 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56715 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
56716 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
56717 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
56718 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
56719 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
56720 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
56721 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
56722 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
56723 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
56724 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
56725 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
56726 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
56727 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
56728 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
56729 #endif
56730 }
56731
56732 @@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56733 {
56734 #ifdef CONFIG_CIFS_STATS
56735 seq_printf(m, " Oplocks breaks: %d",
56736 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
56737 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
56738 seq_printf(m, "\nReads: %d Bytes: %llu",
56739 - atomic_read(&tcon->stats.cifs_stats.num_reads),
56740 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
56741 (long long)(tcon->bytes_read));
56742 seq_printf(m, "\nWrites: %d Bytes: %llu",
56743 - atomic_read(&tcon->stats.cifs_stats.num_writes),
56744 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
56745 (long long)(tcon->bytes_written));
56746 seq_printf(m, "\nFlushes: %d",
56747 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
56748 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
56749 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
56750 - atomic_read(&tcon->stats.cifs_stats.num_locks),
56751 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
56752 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
56753 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
56754 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
56755 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
56756 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
56757 - atomic_read(&tcon->stats.cifs_stats.num_opens),
56758 - atomic_read(&tcon->stats.cifs_stats.num_closes),
56759 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
56760 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
56761 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
56762 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
56763 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
56764 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
56765 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
56766 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
56767 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
56768 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
56769 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
56770 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
56771 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
56772 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
56773 seq_printf(m, "\nRenames: %d T2 Renames %d",
56774 - atomic_read(&tcon->stats.cifs_stats.num_renames),
56775 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
56776 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
56777 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
56778 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
56779 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
56780 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
56781 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
56782 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
56783 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
56784 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
56785 #endif
56786 }
56787
56788 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
56789 index 757da3e..07bf1ed 100644
56790 --- a/fs/cifs/smb2ops.c
56791 +++ b/fs/cifs/smb2ops.c
56792 @@ -370,8 +370,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
56793 #ifdef CONFIG_CIFS_STATS
56794 int i;
56795 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
56796 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56797 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56798 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56799 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56800 }
56801 #endif
56802 }
56803 @@ -411,65 +411,65 @@ static void
56804 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56805 {
56806 #ifdef CONFIG_CIFS_STATS
56807 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56808 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56809 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56810 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56811 seq_printf(m, "\nNegotiates: %d sent %d failed",
56812 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
56813 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
56814 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
56815 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
56816 seq_printf(m, "\nSessionSetups: %d sent %d failed",
56817 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
56818 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
56819 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
56820 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
56821 seq_printf(m, "\nLogoffs: %d sent %d failed",
56822 - atomic_read(&sent[SMB2_LOGOFF_HE]),
56823 - atomic_read(&failed[SMB2_LOGOFF_HE]));
56824 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
56825 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
56826 seq_printf(m, "\nTreeConnects: %d sent %d failed",
56827 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
56828 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
56829 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
56830 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
56831 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
56832 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
56833 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
56834 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
56835 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
56836 seq_printf(m, "\nCreates: %d sent %d failed",
56837 - atomic_read(&sent[SMB2_CREATE_HE]),
56838 - atomic_read(&failed[SMB2_CREATE_HE]));
56839 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
56840 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
56841 seq_printf(m, "\nCloses: %d sent %d failed",
56842 - atomic_read(&sent[SMB2_CLOSE_HE]),
56843 - atomic_read(&failed[SMB2_CLOSE_HE]));
56844 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
56845 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
56846 seq_printf(m, "\nFlushes: %d sent %d failed",
56847 - atomic_read(&sent[SMB2_FLUSH_HE]),
56848 - atomic_read(&failed[SMB2_FLUSH_HE]));
56849 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
56850 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
56851 seq_printf(m, "\nReads: %d sent %d failed",
56852 - atomic_read(&sent[SMB2_READ_HE]),
56853 - atomic_read(&failed[SMB2_READ_HE]));
56854 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
56855 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
56856 seq_printf(m, "\nWrites: %d sent %d failed",
56857 - atomic_read(&sent[SMB2_WRITE_HE]),
56858 - atomic_read(&failed[SMB2_WRITE_HE]));
56859 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
56860 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
56861 seq_printf(m, "\nLocks: %d sent %d failed",
56862 - atomic_read(&sent[SMB2_LOCK_HE]),
56863 - atomic_read(&failed[SMB2_LOCK_HE]));
56864 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
56865 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
56866 seq_printf(m, "\nIOCTLs: %d sent %d failed",
56867 - atomic_read(&sent[SMB2_IOCTL_HE]),
56868 - atomic_read(&failed[SMB2_IOCTL_HE]));
56869 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
56870 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
56871 seq_printf(m, "\nCancels: %d sent %d failed",
56872 - atomic_read(&sent[SMB2_CANCEL_HE]),
56873 - atomic_read(&failed[SMB2_CANCEL_HE]));
56874 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
56875 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
56876 seq_printf(m, "\nEchos: %d sent %d failed",
56877 - atomic_read(&sent[SMB2_ECHO_HE]),
56878 - atomic_read(&failed[SMB2_ECHO_HE]));
56879 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
56880 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
56881 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
56882 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
56883 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
56884 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
56885 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
56886 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
56887 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
56888 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
56889 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
56890 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
56891 seq_printf(m, "\nQueryInfos: %d sent %d failed",
56892 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
56893 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
56894 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
56895 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
56896 seq_printf(m, "\nSetInfos: %d sent %d failed",
56897 - atomic_read(&sent[SMB2_SET_INFO_HE]),
56898 - atomic_read(&failed[SMB2_SET_INFO_HE]));
56899 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
56900 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
56901 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
56902 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
56903 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
56904 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
56905 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
56906 #endif
56907 }
56908
56909 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
56910 index 2013234..a720734 100644
56911 --- a/fs/cifs/smb2pdu.c
56912 +++ b/fs/cifs/smb2pdu.c
56913 @@ -2091,8 +2091,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
56914 default:
56915 cifs_dbg(VFS, "info level %u isn't supported\n",
56916 srch_inf->info_level);
56917 - rc = -EINVAL;
56918 - goto qdir_exit;
56919 + return -EINVAL;
56920 }
56921
56922 req->FileIndex = cpu_to_le32(index);
56923 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
56924 index 1da168c..8bc7ff6 100644
56925 --- a/fs/coda/cache.c
56926 +++ b/fs/coda/cache.c
56927 @@ -24,7 +24,7 @@
56928 #include "coda_linux.h"
56929 #include "coda_cache.h"
56930
56931 -static atomic_t permission_epoch = ATOMIC_INIT(0);
56932 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
56933
56934 /* replace or extend an acl cache hit */
56935 void coda_cache_enter(struct inode *inode, int mask)
56936 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
56937 struct coda_inode_info *cii = ITOC(inode);
56938
56939 spin_lock(&cii->c_lock);
56940 - cii->c_cached_epoch = atomic_read(&permission_epoch);
56941 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
56942 if (!uid_eq(cii->c_uid, current_fsuid())) {
56943 cii->c_uid = current_fsuid();
56944 cii->c_cached_perm = mask;
56945 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
56946 {
56947 struct coda_inode_info *cii = ITOC(inode);
56948 spin_lock(&cii->c_lock);
56949 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
56950 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
56951 spin_unlock(&cii->c_lock);
56952 }
56953
56954 /* remove all acl caches */
56955 void coda_cache_clear_all(struct super_block *sb)
56956 {
56957 - atomic_inc(&permission_epoch);
56958 + atomic_inc_unchecked(&permission_epoch);
56959 }
56960
56961
56962 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
56963 spin_lock(&cii->c_lock);
56964 hit = (mask & cii->c_cached_perm) == mask &&
56965 uid_eq(cii->c_uid, current_fsuid()) &&
56966 - cii->c_cached_epoch == atomic_read(&permission_epoch);
56967 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
56968 spin_unlock(&cii->c_lock);
56969
56970 return hit;
56971 diff --git a/fs/compat.c b/fs/compat.c
56972 index 6af20de..fec3fbb 100644
56973 --- a/fs/compat.c
56974 +++ b/fs/compat.c
56975 @@ -54,7 +54,7 @@
56976 #include <asm/ioctls.h>
56977 #include "internal.h"
56978
56979 -int compat_log = 1;
56980 +int compat_log = 0;
56981
56982 int compat_printk(const char *fmt, ...)
56983 {
56984 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
56985
56986 set_fs(KERNEL_DS);
56987 /* The __user pointer cast is valid because of the set_fs() */
56988 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
56989 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
56990 set_fs(oldfs);
56991 /* truncating is ok because it's a user address */
56992 if (!ret)
56993 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
56994 goto out;
56995
56996 ret = -EINVAL;
56997 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
56998 + if (nr_segs > UIO_MAXIOV)
56999 goto out;
57000 if (nr_segs > fast_segs) {
57001 ret = -ENOMEM;
57002 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57003 struct compat_readdir_callback {
57004 struct dir_context ctx;
57005 struct compat_old_linux_dirent __user *dirent;
57006 + struct file * file;
57007 int result;
57008 };
57009
57010 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57011 buf->result = -EOVERFLOW;
57012 return -EOVERFLOW;
57013 }
57014 +
57015 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57016 + return 0;
57017 +
57018 buf->result++;
57019 dirent = buf->dirent;
57020 if (!access_ok(VERIFY_WRITE, dirent,
57021 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57022 if (!f.file)
57023 return -EBADF;
57024
57025 + buf.file = f.file;
57026 error = iterate_dir(f.file, &buf.ctx);
57027 if (buf.result)
57028 error = buf.result;
57029 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
57030 struct dir_context ctx;
57031 struct compat_linux_dirent __user *current_dir;
57032 struct compat_linux_dirent __user *previous;
57033 + struct file * file;
57034 int count;
57035 int error;
57036 };
57037 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57038 buf->error = -EOVERFLOW;
57039 return -EOVERFLOW;
57040 }
57041 +
57042 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57043 + return 0;
57044 +
57045 dirent = buf->previous;
57046 if (dirent) {
57047 if (__put_user(offset, &dirent->d_off))
57048 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57049 if (!f.file)
57050 return -EBADF;
57051
57052 + buf.file = f.file;
57053 error = iterate_dir(f.file, &buf.ctx);
57054 if (error >= 0)
57055 error = buf.error;
57056 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57057 struct dir_context ctx;
57058 struct linux_dirent64 __user *current_dir;
57059 struct linux_dirent64 __user *previous;
57060 + struct file * file;
57061 int count;
57062 int error;
57063 };
57064 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57065 buf->error = -EINVAL; /* only used if we fail.. */
57066 if (reclen > buf->count)
57067 return -EINVAL;
57068 +
57069 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57070 + return 0;
57071 +
57072 dirent = buf->previous;
57073
57074 if (dirent) {
57075 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57076 if (!f.file)
57077 return -EBADF;
57078
57079 + buf.file = f.file;
57080 error = iterate_dir(f.file, &buf.ctx);
57081 if (error >= 0)
57082 error = buf.error;
57083 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57084 index a81147e..20bf2b5 100644
57085 --- a/fs/compat_binfmt_elf.c
57086 +++ b/fs/compat_binfmt_elf.c
57087 @@ -30,11 +30,13 @@
57088 #undef elf_phdr
57089 #undef elf_shdr
57090 #undef elf_note
57091 +#undef elf_dyn
57092 #undef elf_addr_t
57093 #define elfhdr elf32_hdr
57094 #define elf_phdr elf32_phdr
57095 #define elf_shdr elf32_shdr
57096 #define elf_note elf32_note
57097 +#define elf_dyn Elf32_Dyn
57098 #define elf_addr_t Elf32_Addr
57099
57100 /*
57101 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57102 index dc52e13..ec61057 100644
57103 --- a/fs/compat_ioctl.c
57104 +++ b/fs/compat_ioctl.c
57105 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57106 return -EFAULT;
57107 if (__get_user(udata, &ss32->iomem_base))
57108 return -EFAULT;
57109 - ss.iomem_base = compat_ptr(udata);
57110 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57111 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57112 __get_user(ss.port_high, &ss32->port_high))
57113 return -EFAULT;
57114 @@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57115 for (i = 0; i < nmsgs; i++) {
57116 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57117 return -EFAULT;
57118 - if (get_user(datap, &umsgs[i].buf) ||
57119 - put_user(compat_ptr(datap), &tmsgs[i].buf))
57120 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57121 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57122 return -EFAULT;
57123 }
57124 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57125 @@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
57126 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57127 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57128 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57129 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57130 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57131 return -EFAULT;
57132
57133 return ioctl_preallocate(file, p);
57134 @@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57135 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57136 {
57137 unsigned int a, b;
57138 - a = *(unsigned int *)p;
57139 - b = *(unsigned int *)q;
57140 + a = *(const unsigned int *)p;
57141 + b = *(const unsigned int *)q;
57142 if (a > b)
57143 return 1;
57144 if (a < b)
57145 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57146 index e081acb..911df21 100644
57147 --- a/fs/configfs/dir.c
57148 +++ b/fs/configfs/dir.c
57149 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57150 }
57151 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57152 struct configfs_dirent *next;
57153 - const char *name;
57154 + const unsigned char * name;
57155 + char d_name[sizeof(next->s_dentry->d_iname)];
57156 int len;
57157 struct inode *inode = NULL;
57158
57159 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57160 continue;
57161
57162 name = configfs_get_name(next);
57163 - len = strlen(name);
57164 + if (next->s_dentry && name == next->s_dentry->d_iname) {
57165 + len = next->s_dentry->d_name.len;
57166 + memcpy(d_name, name, len);
57167 + name = d_name;
57168 + } else
57169 + len = strlen(name);
57170
57171 /*
57172 * We'll have a dentry and an inode for
57173 diff --git a/fs/coredump.c b/fs/coredump.c
57174 index bc3fbcd..6031650 100644
57175 --- a/fs/coredump.c
57176 +++ b/fs/coredump.c
57177 @@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
57178 struct pipe_inode_info *pipe = file->private_data;
57179
57180 pipe_lock(pipe);
57181 - pipe->readers++;
57182 - pipe->writers--;
57183 + atomic_inc(&pipe->readers);
57184 + atomic_dec(&pipe->writers);
57185 wake_up_interruptible_sync(&pipe->wait);
57186 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57187 pipe_unlock(pipe);
57188 @@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
57189 * We actually want wait_event_freezable() but then we need
57190 * to clear TIF_SIGPENDING and improve dump_interrupted().
57191 */
57192 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
57193 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
57194
57195 pipe_lock(pipe);
57196 - pipe->readers--;
57197 - pipe->writers++;
57198 + atomic_dec(&pipe->readers);
57199 + atomic_inc(&pipe->writers);
57200 pipe_unlock(pipe);
57201 }
57202
57203 @@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
57204 struct files_struct *displaced;
57205 bool need_nonrelative = false;
57206 bool core_dumped = false;
57207 - static atomic_t core_dump_count = ATOMIC_INIT(0);
57208 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
57209 + long signr = siginfo->si_signo;
57210 + int dumpable;
57211 struct coredump_params cprm = {
57212 .siginfo = siginfo,
57213 .regs = signal_pt_regs(),
57214 @@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
57215 .mm_flags = mm->flags,
57216 };
57217
57218 - audit_core_dumps(siginfo->si_signo);
57219 + audit_core_dumps(signr);
57220 +
57221 + dumpable = __get_dumpable(cprm.mm_flags);
57222 +
57223 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
57224 + gr_handle_brute_attach(dumpable);
57225
57226 binfmt = mm->binfmt;
57227 if (!binfmt || !binfmt->core_dump)
57228 goto fail;
57229 - if (!__get_dumpable(cprm.mm_flags))
57230 + if (!dumpable)
57231 goto fail;
57232
57233 cred = prepare_creds();
57234 @@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
57235 need_nonrelative = true;
57236 }
57237
57238 - retval = coredump_wait(siginfo->si_signo, &core_state);
57239 + retval = coredump_wait(signr, &core_state);
57240 if (retval < 0)
57241 goto fail_creds;
57242
57243 @@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
57244 }
57245 cprm.limit = RLIM_INFINITY;
57246
57247 - dump_count = atomic_inc_return(&core_dump_count);
57248 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
57249 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
57250 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
57251 task_tgid_vnr(current), current->comm);
57252 @@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
57253 } else {
57254 struct inode *inode;
57255
57256 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
57257 +
57258 if (cprm.limit < binfmt->min_coredump)
57259 goto fail_unlock;
57260
57261 @@ -669,7 +678,7 @@ close_fail:
57262 filp_close(cprm.file, NULL);
57263 fail_dropcount:
57264 if (ispipe)
57265 - atomic_dec(&core_dump_count);
57266 + atomic_dec_unchecked(&core_dump_count);
57267 fail_unlock:
57268 kfree(cn.corename);
57269 coredump_finish(mm, core_dumped);
57270 @@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
57271 struct file *file = cprm->file;
57272 loff_t pos = file->f_pos;
57273 ssize_t n;
57274 +
57275 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
57276 if (cprm->written + nr > cprm->limit)
57277 return 0;
57278 while (nr) {
57279 diff --git a/fs/dcache.c b/fs/dcache.c
57280 index fdbe230..ba17c1f 100644
57281 --- a/fs/dcache.c
57282 +++ b/fs/dcache.c
57283 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
57284 */
57285 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
57286 if (name->len > DNAME_INLINE_LEN-1) {
57287 - dname = kmalloc(name->len + 1, GFP_KERNEL);
57288 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
57289 if (!dname) {
57290 kmem_cache_free(dentry_cache, dentry);
57291 return NULL;
57292 @@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
57293 mempages -= reserve;
57294
57295 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
57296 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
57297 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
57298 + SLAB_NO_SANITIZE, NULL);
57299
57300 dcache_init();
57301 inode_init();
57302 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
57303 index 9c0444c..628490c 100644
57304 --- a/fs/debugfs/inode.c
57305 +++ b/fs/debugfs/inode.c
57306 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
57307 */
57308 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
57309 {
57310 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
57311 + return __create_file(name, S_IFDIR | S_IRWXU,
57312 +#else
57313 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
57314 +#endif
57315 parent, NULL, NULL);
57316 }
57317 EXPORT_SYMBOL_GPL(debugfs_create_dir);
57318 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
57319 index c36c448..fc96710 100644
57320 --- a/fs/ecryptfs/inode.c
57321 +++ b/fs/ecryptfs/inode.c
57322 @@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
57323 old_fs = get_fs();
57324 set_fs(get_ds());
57325 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
57326 - (char __user *)lower_buf,
57327 + (char __force_user *)lower_buf,
57328 PATH_MAX);
57329 set_fs(old_fs);
57330 if (rc < 0)
57331 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
57332 index e4141f2..d8263e8 100644
57333 --- a/fs/ecryptfs/miscdev.c
57334 +++ b/fs/ecryptfs/miscdev.c
57335 @@ -304,7 +304,7 @@ check_list:
57336 goto out_unlock_msg_ctx;
57337 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
57338 if (msg_ctx->msg) {
57339 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
57340 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
57341 goto out_unlock_msg_ctx;
57342 i += packet_length_size;
57343 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
57344 diff --git a/fs/exec.c b/fs/exec.c
57345 index 7ea097f..0158d8a 100644
57346 --- a/fs/exec.c
57347 +++ b/fs/exec.c
57348 @@ -55,8 +55,20 @@
57349 #include <linux/pipe_fs_i.h>
57350 #include <linux/oom.h>
57351 #include <linux/compat.h>
57352 +#include <linux/random.h>
57353 +#include <linux/seq_file.h>
57354 +#include <linux/coredump.h>
57355 +#include <linux/mman.h>
57356 +
57357 +#ifdef CONFIG_PAX_REFCOUNT
57358 +#include <linux/kallsyms.h>
57359 +#include <linux/kdebug.h>
57360 +#endif
57361 +
57362 +#include <trace/events/fs.h>
57363
57364 #include <asm/uaccess.h>
57365 +#include <asm/sections.h>
57366 #include <asm/mmu_context.h>
57367 #include <asm/tlb.h>
57368
57369 @@ -66,19 +78,34 @@
57370
57371 #include <trace/events/sched.h>
57372
57373 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57374 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
57375 +{
57376 + 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");
57377 +}
57378 +#endif
57379 +
57380 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
57381 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
57382 +EXPORT_SYMBOL(pax_set_initial_flags_func);
57383 +#endif
57384 +
57385 int suid_dumpable = 0;
57386
57387 static LIST_HEAD(formats);
57388 static DEFINE_RWLOCK(binfmt_lock);
57389
57390 +extern int gr_process_kernel_exec_ban(void);
57391 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
57392 +
57393 void __register_binfmt(struct linux_binfmt * fmt, int insert)
57394 {
57395 BUG_ON(!fmt);
57396 if (WARN_ON(!fmt->load_binary))
57397 return;
57398 write_lock(&binfmt_lock);
57399 - insert ? list_add(&fmt->lh, &formats) :
57400 - list_add_tail(&fmt->lh, &formats);
57401 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
57402 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
57403 write_unlock(&binfmt_lock);
57404 }
57405
57406 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
57407 void unregister_binfmt(struct linux_binfmt * fmt)
57408 {
57409 write_lock(&binfmt_lock);
57410 - list_del(&fmt->lh);
57411 + pax_list_del((struct list_head *)&fmt->lh);
57412 write_unlock(&binfmt_lock);
57413 }
57414
57415 @@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57416 int write)
57417 {
57418 struct page *page;
57419 - int ret;
57420
57421 -#ifdef CONFIG_STACK_GROWSUP
57422 - if (write) {
57423 - ret = expand_downwards(bprm->vma, pos);
57424 - if (ret < 0)
57425 - return NULL;
57426 - }
57427 -#endif
57428 - ret = get_user_pages(current, bprm->mm, pos,
57429 - 1, write, 1, &page, NULL);
57430 - if (ret <= 0)
57431 + if (0 > expand_downwards(bprm->vma, pos))
57432 + return NULL;
57433 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
57434 return NULL;
57435
57436 if (write) {
57437 @@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57438 if (size <= ARG_MAX)
57439 return page;
57440
57441 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57442 + // only allow 512KB for argv+env on suid/sgid binaries
57443 + // to prevent easy ASLR exhaustion
57444 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
57445 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
57446 + (size > (512 * 1024))) {
57447 + put_page(page);
57448 + return NULL;
57449 + }
57450 +#endif
57451 +
57452 /*
57453 * Limit to 1/4-th the stack size for the argv+env strings.
57454 * This ensures that:
57455 @@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57456 vma->vm_end = STACK_TOP_MAX;
57457 vma->vm_start = vma->vm_end - PAGE_SIZE;
57458 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
57459 +
57460 +#ifdef CONFIG_PAX_SEGMEXEC
57461 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
57462 +#endif
57463 +
57464 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
57465 INIT_LIST_HEAD(&vma->anon_vma_chain);
57466
57467 @@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57468 mm->stack_vm = mm->total_vm = 1;
57469 up_write(&mm->mmap_sem);
57470 bprm->p = vma->vm_end - sizeof(void *);
57471 +
57472 +#ifdef CONFIG_PAX_RANDUSTACK
57473 + if (randomize_va_space)
57474 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
57475 +#endif
57476 +
57477 return 0;
57478 err:
57479 up_write(&mm->mmap_sem);
57480 @@ -397,7 +438,7 @@ struct user_arg_ptr {
57481 } ptr;
57482 };
57483
57484 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57485 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57486 {
57487 const char __user *native;
57488
57489 @@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57490 compat_uptr_t compat;
57491
57492 if (get_user(compat, argv.ptr.compat + nr))
57493 - return ERR_PTR(-EFAULT);
57494 + return (const char __force_user *)ERR_PTR(-EFAULT);
57495
57496 return compat_ptr(compat);
57497 }
57498 #endif
57499
57500 if (get_user(native, argv.ptr.native + nr))
57501 - return ERR_PTR(-EFAULT);
57502 + return (const char __force_user *)ERR_PTR(-EFAULT);
57503
57504 return native;
57505 }
57506 @@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
57507 if (!p)
57508 break;
57509
57510 - if (IS_ERR(p))
57511 + if (IS_ERR((const char __force_kernel *)p))
57512 return -EFAULT;
57513
57514 if (i >= max)
57515 @@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
57516
57517 ret = -EFAULT;
57518 str = get_user_arg_ptr(argv, argc);
57519 - if (IS_ERR(str))
57520 + if (IS_ERR((const char __force_kernel *)str))
57521 goto out;
57522
57523 len = strnlen_user(str, MAX_ARG_STRLEN);
57524 @@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
57525 int r;
57526 mm_segment_t oldfs = get_fs();
57527 struct user_arg_ptr argv = {
57528 - .ptr.native = (const char __user *const __user *)__argv,
57529 + .ptr.native = (const char __user * const __force_user *)__argv,
57530 };
57531
57532 set_fs(KERNEL_DS);
57533 @@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57534 unsigned long new_end = old_end - shift;
57535 struct mmu_gather tlb;
57536
57537 - BUG_ON(new_start > new_end);
57538 + if (new_start >= new_end || new_start < mmap_min_addr)
57539 + return -ENOMEM;
57540
57541 /*
57542 * ensure there are no vmas between where we want to go
57543 @@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57544 if (vma != find_vma(mm, new_start))
57545 return -EFAULT;
57546
57547 +#ifdef CONFIG_PAX_SEGMEXEC
57548 + BUG_ON(pax_find_mirror_vma(vma));
57549 +#endif
57550 +
57551 /*
57552 * cover the whole range: [new_start, old_end)
57553 */
57554 @@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57555 stack_top = arch_align_stack(stack_top);
57556 stack_top = PAGE_ALIGN(stack_top);
57557
57558 - if (unlikely(stack_top < mmap_min_addr) ||
57559 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
57560 - return -ENOMEM;
57561 -
57562 stack_shift = vma->vm_end - stack_top;
57563
57564 bprm->p -= stack_shift;
57565 @@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
57566 bprm->exec -= stack_shift;
57567
57568 down_write(&mm->mmap_sem);
57569 +
57570 + /* Move stack pages down in memory. */
57571 + if (stack_shift) {
57572 + ret = shift_arg_pages(vma, stack_shift);
57573 + if (ret)
57574 + goto out_unlock;
57575 + }
57576 +
57577 vm_flags = VM_STACK_FLAGS;
57578
57579 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57580 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57581 + vm_flags &= ~VM_EXEC;
57582 +
57583 +#ifdef CONFIG_PAX_MPROTECT
57584 + if (mm->pax_flags & MF_PAX_MPROTECT)
57585 + vm_flags &= ~VM_MAYEXEC;
57586 +#endif
57587 +
57588 + }
57589 +#endif
57590 +
57591 /*
57592 * Adjust stack execute permissions; explicitly enable for
57593 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
57594 @@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57595 goto out_unlock;
57596 BUG_ON(prev != vma);
57597
57598 - /* Move stack pages down in memory. */
57599 - if (stack_shift) {
57600 - ret = shift_arg_pages(vma, stack_shift);
57601 - if (ret)
57602 - goto out_unlock;
57603 - }
57604 -
57605 /* mprotect_fixup is overkill to remove the temporary stack flags */
57606 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
57607
57608 @@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
57609 #endif
57610 current->mm->start_stack = bprm->p;
57611 ret = expand_stack(vma, stack_base);
57612 +
57613 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
57614 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
57615 + unsigned long size;
57616 + vm_flags_t vm_flags;
57617 +
57618 + size = STACK_TOP - vma->vm_end;
57619 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
57620 +
57621 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
57622 +
57623 +#ifdef CONFIG_X86
57624 + if (!ret) {
57625 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
57626 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
57627 + }
57628 +#endif
57629 +
57630 + }
57631 +#endif
57632 +
57633 if (ret)
57634 ret = -EFAULT;
57635
57636 @@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
57637
57638 fsnotify_open(file);
57639
57640 + trace_open_exec(name);
57641 +
57642 err = deny_write_access(file);
57643 if (err)
57644 goto exit;
57645 @@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
57646 old_fs = get_fs();
57647 set_fs(get_ds());
57648 /* The cast to a user pointer is valid due to the set_fs() */
57649 - result = vfs_read(file, (void __user *)addr, count, &pos);
57650 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
57651 set_fs(old_fs);
57652 return result;
57653 }
57654 @@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
57655 }
57656 rcu_read_unlock();
57657
57658 - if (p->fs->users > n_fs) {
57659 + if (atomic_read(&p->fs->users) > n_fs) {
57660 bprm->unsafe |= LSM_UNSAFE_SHARE;
57661 } else {
57662 res = -EAGAIN;
57663 @@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
57664 return ret;
57665 }
57666
57667 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57668 +static DEFINE_PER_CPU(u64, exec_counter);
57669 +static int __init init_exec_counters(void)
57670 +{
57671 + unsigned int cpu;
57672 +
57673 + for_each_possible_cpu(cpu) {
57674 + per_cpu(exec_counter, cpu) = (u64)cpu;
57675 + }
57676 +
57677 + return 0;
57678 +}
57679 +early_initcall(init_exec_counters);
57680 +static inline void increment_exec_counter(void)
57681 +{
57682 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
57683 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
57684 +}
57685 +#else
57686 +static inline void increment_exec_counter(void) {}
57687 +#endif
57688 +
57689 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
57690 + struct user_arg_ptr argv);
57691 +
57692 /*
57693 * sys_execve() executes a new program.
57694 */
57695 @@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
57696 struct user_arg_ptr argv,
57697 struct user_arg_ptr envp)
57698 {
57699 +#ifdef CONFIG_GRKERNSEC
57700 + struct file *old_exec_file;
57701 + struct acl_subject_label *old_acl;
57702 + struct rlimit old_rlim[RLIM_NLIMITS];
57703 +#endif
57704 struct linux_binprm *bprm;
57705 struct file *file;
57706 struct files_struct *displaced;
57707 bool clear_in_exec;
57708 int retval;
57709
57710 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
57711 +
57712 /*
57713 * We move the actual failure in case of RLIMIT_NPROC excess from
57714 * set*uid() to execve() because too many poorly written programs
57715 @@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
57716 if (IS_ERR(file))
57717 goto out_unmark;
57718
57719 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
57720 + retval = -EPERM;
57721 + goto out_file;
57722 + }
57723 +
57724 sched_exec();
57725
57726 bprm->file = file;
57727 bprm->filename = filename;
57728 bprm->interp = filename;
57729
57730 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
57731 + retval = -EACCES;
57732 + goto out_file;
57733 + }
57734 +
57735 retval = bprm_mm_init(bprm);
57736 if (retval)
57737 goto out_file;
57738 @@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
57739 if (retval < 0)
57740 goto out;
57741
57742 +#ifdef CONFIG_GRKERNSEC
57743 + old_acl = current->acl;
57744 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
57745 + old_exec_file = current->exec_file;
57746 + get_file(file);
57747 + current->exec_file = file;
57748 +#endif
57749 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57750 + /* limit suid stack to 8MB
57751 + * we saved the old limits above and will restore them if this exec fails
57752 + */
57753 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
57754 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
57755 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
57756 +#endif
57757 +
57758 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
57759 + retval = -EPERM;
57760 + goto out_fail;
57761 + }
57762 +
57763 + if (!gr_tpe_allow(file)) {
57764 + retval = -EACCES;
57765 + goto out_fail;
57766 + }
57767 +
57768 + if (gr_check_crash_exec(file)) {
57769 + retval = -EACCES;
57770 + goto out_fail;
57771 + }
57772 +
57773 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
57774 + bprm->unsafe);
57775 + if (retval < 0)
57776 + goto out_fail;
57777 +
57778 retval = copy_strings_kernel(1, &bprm->filename, bprm);
57779 if (retval < 0)
57780 - goto out;
57781 + goto out_fail;
57782
57783 bprm->exec = bprm->p;
57784 retval = copy_strings(bprm->envc, envp, bprm);
57785 if (retval < 0)
57786 - goto out;
57787 + goto out_fail;
57788
57789 retval = copy_strings(bprm->argc, argv, bprm);
57790 if (retval < 0)
57791 - goto out;
57792 + goto out_fail;
57793 +
57794 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
57795 +
57796 + gr_handle_exec_args(bprm, argv);
57797
57798 retval = exec_binprm(bprm);
57799 if (retval < 0)
57800 - goto out;
57801 + goto out_fail;
57802 +#ifdef CONFIG_GRKERNSEC
57803 + if (old_exec_file)
57804 + fput(old_exec_file);
57805 +#endif
57806
57807 /* execve succeeded */
57808 +
57809 + increment_exec_counter();
57810 current->fs->in_exec = 0;
57811 current->in_execve = 0;
57812 acct_update_integrals(current);
57813 @@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
57814 put_files_struct(displaced);
57815 return retval;
57816
57817 +out_fail:
57818 +#ifdef CONFIG_GRKERNSEC
57819 + current->acl = old_acl;
57820 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
57821 + fput(current->exec_file);
57822 + current->exec_file = old_exec_file;
57823 +#endif
57824 +
57825 out:
57826 if (bprm->mm) {
57827 acct_arg_size(bprm, 0);
57828 @@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
57829 return error;
57830 }
57831 #endif
57832 +
57833 +int pax_check_flags(unsigned long *flags)
57834 +{
57835 + int retval = 0;
57836 +
57837 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
57838 + if (*flags & MF_PAX_SEGMEXEC)
57839 + {
57840 + *flags &= ~MF_PAX_SEGMEXEC;
57841 + retval = -EINVAL;
57842 + }
57843 +#endif
57844 +
57845 + if ((*flags & MF_PAX_PAGEEXEC)
57846 +
57847 +#ifdef CONFIG_PAX_PAGEEXEC
57848 + && (*flags & MF_PAX_SEGMEXEC)
57849 +#endif
57850 +
57851 + )
57852 + {
57853 + *flags &= ~MF_PAX_PAGEEXEC;
57854 + retval = -EINVAL;
57855 + }
57856 +
57857 + if ((*flags & MF_PAX_MPROTECT)
57858 +
57859 +#ifdef CONFIG_PAX_MPROTECT
57860 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57861 +#endif
57862 +
57863 + )
57864 + {
57865 + *flags &= ~MF_PAX_MPROTECT;
57866 + retval = -EINVAL;
57867 + }
57868 +
57869 + if ((*flags & MF_PAX_EMUTRAMP)
57870 +
57871 +#ifdef CONFIG_PAX_EMUTRAMP
57872 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57873 +#endif
57874 +
57875 + )
57876 + {
57877 + *flags &= ~MF_PAX_EMUTRAMP;
57878 + retval = -EINVAL;
57879 + }
57880 +
57881 + return retval;
57882 +}
57883 +
57884 +EXPORT_SYMBOL(pax_check_flags);
57885 +
57886 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57887 +char *pax_get_path(const struct path *path, char *buf, int buflen)
57888 +{
57889 + char *pathname = d_path(path, buf, buflen);
57890 +
57891 + if (IS_ERR(pathname))
57892 + goto toolong;
57893 +
57894 + pathname = mangle_path(buf, pathname, "\t\n\\");
57895 + if (!pathname)
57896 + goto toolong;
57897 +
57898 + *pathname = 0;
57899 + return buf;
57900 +
57901 +toolong:
57902 + return "<path too long>";
57903 +}
57904 +EXPORT_SYMBOL(pax_get_path);
57905 +
57906 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
57907 +{
57908 + struct task_struct *tsk = current;
57909 + struct mm_struct *mm = current->mm;
57910 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
57911 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
57912 + char *path_exec = NULL;
57913 + char *path_fault = NULL;
57914 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
57915 + siginfo_t info = { };
57916 +
57917 + if (buffer_exec && buffer_fault) {
57918 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
57919 +
57920 + down_read(&mm->mmap_sem);
57921 + vma = mm->mmap;
57922 + while (vma && (!vma_exec || !vma_fault)) {
57923 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
57924 + vma_exec = vma;
57925 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
57926 + vma_fault = vma;
57927 + vma = vma->vm_next;
57928 + }
57929 + if (vma_exec)
57930 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
57931 + if (vma_fault) {
57932 + start = vma_fault->vm_start;
57933 + end = vma_fault->vm_end;
57934 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
57935 + if (vma_fault->vm_file)
57936 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
57937 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
57938 + path_fault = "<heap>";
57939 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
57940 + path_fault = "<stack>";
57941 + else
57942 + path_fault = "<anonymous mapping>";
57943 + }
57944 + up_read(&mm->mmap_sem);
57945 + }
57946 + if (tsk->signal->curr_ip)
57947 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
57948 + else
57949 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
57950 + 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),
57951 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
57952 + free_page((unsigned long)buffer_exec);
57953 + free_page((unsigned long)buffer_fault);
57954 + pax_report_insns(regs, pc, sp);
57955 + info.si_signo = SIGKILL;
57956 + info.si_errno = 0;
57957 + info.si_code = SI_KERNEL;
57958 + info.si_pid = 0;
57959 + info.si_uid = 0;
57960 + do_coredump(&info);
57961 +}
57962 +#endif
57963 +
57964 +#ifdef CONFIG_PAX_REFCOUNT
57965 +void pax_report_refcount_overflow(struct pt_regs *regs)
57966 +{
57967 + if (current->signal->curr_ip)
57968 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
57969 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
57970 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57971 + else
57972 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
57973 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57974 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
57975 + preempt_disable();
57976 + show_regs(regs);
57977 + preempt_enable();
57978 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
57979 +}
57980 +#endif
57981 +
57982 +#ifdef CONFIG_PAX_USERCOPY
57983 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
57984 +static noinline int check_stack_object(const void *obj, unsigned long len)
57985 +{
57986 + const void * const stack = task_stack_page(current);
57987 + const void * const stackend = stack + THREAD_SIZE;
57988 +
57989 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
57990 + const void *frame = NULL;
57991 + const void *oldframe;
57992 +#endif
57993 +
57994 + if (obj + len < obj)
57995 + return -1;
57996 +
57997 + if (obj + len <= stack || stackend <= obj)
57998 + return 0;
57999 +
58000 + if (obj < stack || stackend < obj + len)
58001 + return -1;
58002 +
58003 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58004 + oldframe = __builtin_frame_address(1);
58005 + if (oldframe)
58006 + frame = __builtin_frame_address(2);
58007 + /*
58008 + low ----------------------------------------------> high
58009 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
58010 + ^----------------^
58011 + allow copies only within here
58012 + */
58013 + while (stack <= frame && frame < stackend) {
58014 + /* if obj + len extends past the last frame, this
58015 + check won't pass and the next frame will be 0,
58016 + causing us to bail out and correctly report
58017 + the copy as invalid
58018 + */
58019 + if (obj + len <= frame)
58020 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58021 + oldframe = frame;
58022 + frame = *(const void * const *)frame;
58023 + }
58024 + return -1;
58025 +#else
58026 + return 1;
58027 +#endif
58028 +}
58029 +
58030 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58031 +{
58032 + if (current->signal->curr_ip)
58033 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58034 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58035 + else
58036 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58037 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58038 + dump_stack();
58039 + gr_handle_kernel_exploit();
58040 + do_group_exit(SIGKILL);
58041 +}
58042 +#endif
58043 +
58044 +#ifdef CONFIG_PAX_USERCOPY
58045 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58046 +{
58047 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58048 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
58049 +#ifdef CONFIG_MODULES
58050 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58051 +#else
58052 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58053 +#endif
58054 +
58055 +#else
58056 + unsigned long textlow = (unsigned long)_stext;
58057 + unsigned long texthigh = (unsigned long)_etext;
58058 +
58059 +#ifdef CONFIG_X86_64
58060 + /* check against linear mapping as well */
58061 + if (high > (unsigned long)__va(__pa(textlow)) &&
58062 + low <= (unsigned long)__va(__pa(texthigh)))
58063 + return true;
58064 +#endif
58065 +
58066 +#endif
58067 +
58068 + if (high <= textlow || low > texthigh)
58069 + return false;
58070 + else
58071 + return true;
58072 +}
58073 +#endif
58074 +
58075 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58076 +{
58077 +
58078 +#ifdef CONFIG_PAX_USERCOPY
58079 + const char *type;
58080 +
58081 + if (!n)
58082 + return;
58083 +
58084 + type = check_heap_object(ptr, n);
58085 + if (!type) {
58086 + int ret = check_stack_object(ptr, n);
58087 + if (ret == 1 || ret == 2)
58088 + return;
58089 + if (ret == 0) {
58090 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58091 + type = "<kernel text>";
58092 + else
58093 + return;
58094 + } else
58095 + type = "<process stack>";
58096 + }
58097 +
58098 + pax_report_usercopy(ptr, n, to_user, type);
58099 +#endif
58100 +
58101 +}
58102 +EXPORT_SYMBOL(__check_object_size);
58103 +
58104 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
58105 +void pax_track_stack(void)
58106 +{
58107 + unsigned long sp = (unsigned long)&sp;
58108 + if (sp < current_thread_info()->lowest_stack &&
58109 + sp > (unsigned long)task_stack_page(current))
58110 + current_thread_info()->lowest_stack = sp;
58111 +}
58112 +EXPORT_SYMBOL(pax_track_stack);
58113 +#endif
58114 +
58115 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
58116 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58117 +{
58118 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58119 + dump_stack();
58120 + do_group_exit(SIGKILL);
58121 +}
58122 +EXPORT_SYMBOL(report_size_overflow);
58123 +#endif
58124 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58125 index 9f9992b..8b59411 100644
58126 --- a/fs/ext2/balloc.c
58127 +++ b/fs/ext2/balloc.c
58128 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58129
58130 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58131 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58132 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58133 + if (free_blocks < root_blocks + 1 &&
58134 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58135 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58136 - !in_group_p (sbi->s_resgid))) {
58137 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58138 return 0;
58139 }
58140 return 1;
58141 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58142 index 2d7557d..14e38f94 100644
58143 --- a/fs/ext2/xattr.c
58144 +++ b/fs/ext2/xattr.c
58145 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58146 struct buffer_head *bh = NULL;
58147 struct ext2_xattr_entry *entry;
58148 char *end;
58149 - size_t rest = buffer_size;
58150 + size_t rest = buffer_size, total_size = 0;
58151 int error;
58152
58153 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58154 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58155 buffer += size;
58156 }
58157 rest -= size;
58158 + total_size += size;
58159 }
58160 }
58161 - error = buffer_size - rest; /* total size */
58162 + error = total_size;
58163
58164 cleanup:
58165 brelse(bh);
58166 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58167 index 22548f5..41521d8 100644
58168 --- a/fs/ext3/balloc.c
58169 +++ b/fs/ext3/balloc.c
58170 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58171
58172 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58173 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58174 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58175 + if (free_blocks < root_blocks + 1 &&
58176 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58177 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58178 - !in_group_p (sbi->s_resgid))) {
58179 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58180 return 0;
58181 }
58182 return 1;
58183 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58184 index b1fc963..881228c 100644
58185 --- a/fs/ext3/xattr.c
58186 +++ b/fs/ext3/xattr.c
58187 @@ -330,7 +330,7 @@ static int
58188 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58189 char *buffer, size_t buffer_size)
58190 {
58191 - size_t rest = buffer_size;
58192 + size_t rest = buffer_size, total_size = 0;
58193
58194 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
58195 const struct xattr_handler *handler =
58196 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58197 buffer += size;
58198 }
58199 rest -= size;
58200 + total_size += size;
58201 }
58202 }
58203 - return buffer_size - rest;
58204 + return total_size;
58205 }
58206
58207 static int
58208 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
58209 index 6ea7b14..8fa16d9 100644
58210 --- a/fs/ext4/balloc.c
58211 +++ b/fs/ext4/balloc.c
58212 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
58213 /* Hm, nope. Are (enough) root reserved clusters available? */
58214 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
58215 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
58216 - capable(CAP_SYS_RESOURCE) ||
58217 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
58218 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
58219 + capable_nolog(CAP_SYS_RESOURCE)) {
58220
58221 if (free_clusters >= (nclusters + dirty_clusters +
58222 resv_clusters))
58223 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
58224 index ece5556..e39d3a8 100644
58225 --- a/fs/ext4/ext4.h
58226 +++ b/fs/ext4/ext4.h
58227 @@ -1267,19 +1267,19 @@ struct ext4_sb_info {
58228 unsigned long s_mb_last_start;
58229
58230 /* stats for buddy allocator */
58231 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
58232 - atomic_t s_bal_success; /* we found long enough chunks */
58233 - atomic_t s_bal_allocated; /* in blocks */
58234 - atomic_t s_bal_ex_scanned; /* total extents scanned */
58235 - atomic_t s_bal_goals; /* goal hits */
58236 - atomic_t s_bal_breaks; /* too long searches */
58237 - atomic_t s_bal_2orders; /* 2^order hits */
58238 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
58239 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
58240 + atomic_unchecked_t s_bal_allocated; /* in blocks */
58241 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
58242 + atomic_unchecked_t s_bal_goals; /* goal hits */
58243 + atomic_unchecked_t s_bal_breaks; /* too long searches */
58244 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
58245 spinlock_t s_bal_lock;
58246 unsigned long s_mb_buddies_generated;
58247 unsigned long long s_mb_generation_time;
58248 - atomic_t s_mb_lost_chunks;
58249 - atomic_t s_mb_preallocated;
58250 - atomic_t s_mb_discarded;
58251 + atomic_unchecked_t s_mb_lost_chunks;
58252 + atomic_unchecked_t s_mb_preallocated;
58253 + atomic_unchecked_t s_mb_discarded;
58254 atomic_t s_lock_busy;
58255
58256 /* locality groups */
58257 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
58258 index 04a5c75..09894fa 100644
58259 --- a/fs/ext4/mballoc.c
58260 +++ b/fs/ext4/mballoc.c
58261 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
58262 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
58263
58264 if (EXT4_SB(sb)->s_mb_stats)
58265 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
58266 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
58267
58268 break;
58269 }
58270 @@ -2189,7 +2189,7 @@ repeat:
58271 ac->ac_status = AC_STATUS_CONTINUE;
58272 ac->ac_flags |= EXT4_MB_HINT_FIRST;
58273 cr = 3;
58274 - atomic_inc(&sbi->s_mb_lost_chunks);
58275 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
58276 goto repeat;
58277 }
58278 }
58279 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
58280 if (sbi->s_mb_stats) {
58281 ext4_msg(sb, KERN_INFO,
58282 "mballoc: %u blocks %u reqs (%u success)",
58283 - atomic_read(&sbi->s_bal_allocated),
58284 - atomic_read(&sbi->s_bal_reqs),
58285 - atomic_read(&sbi->s_bal_success));
58286 + atomic_read_unchecked(&sbi->s_bal_allocated),
58287 + atomic_read_unchecked(&sbi->s_bal_reqs),
58288 + atomic_read_unchecked(&sbi->s_bal_success));
58289 ext4_msg(sb, KERN_INFO,
58290 "mballoc: %u extents scanned, %u goal hits, "
58291 "%u 2^N hits, %u breaks, %u lost",
58292 - atomic_read(&sbi->s_bal_ex_scanned),
58293 - atomic_read(&sbi->s_bal_goals),
58294 - atomic_read(&sbi->s_bal_2orders),
58295 - atomic_read(&sbi->s_bal_breaks),
58296 - atomic_read(&sbi->s_mb_lost_chunks));
58297 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
58298 + atomic_read_unchecked(&sbi->s_bal_goals),
58299 + atomic_read_unchecked(&sbi->s_bal_2orders),
58300 + atomic_read_unchecked(&sbi->s_bal_breaks),
58301 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
58302 ext4_msg(sb, KERN_INFO,
58303 "mballoc: %lu generated and it took %Lu",
58304 sbi->s_mb_buddies_generated,
58305 sbi->s_mb_generation_time);
58306 ext4_msg(sb, KERN_INFO,
58307 "mballoc: %u preallocated, %u discarded",
58308 - atomic_read(&sbi->s_mb_preallocated),
58309 - atomic_read(&sbi->s_mb_discarded));
58310 + atomic_read_unchecked(&sbi->s_mb_preallocated),
58311 + atomic_read_unchecked(&sbi->s_mb_discarded));
58312 }
58313
58314 free_percpu(sbi->s_locality_groups);
58315 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
58316 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
58317
58318 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
58319 - atomic_inc(&sbi->s_bal_reqs);
58320 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58321 + atomic_inc_unchecked(&sbi->s_bal_reqs);
58322 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58323 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
58324 - atomic_inc(&sbi->s_bal_success);
58325 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
58326 + atomic_inc_unchecked(&sbi->s_bal_success);
58327 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
58328 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
58329 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
58330 - atomic_inc(&sbi->s_bal_goals);
58331 + atomic_inc_unchecked(&sbi->s_bal_goals);
58332 if (ac->ac_found > sbi->s_mb_max_to_scan)
58333 - atomic_inc(&sbi->s_bal_breaks);
58334 + atomic_inc_unchecked(&sbi->s_bal_breaks);
58335 }
58336
58337 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
58338 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
58339 trace_ext4_mb_new_inode_pa(ac, pa);
58340
58341 ext4_mb_use_inode_pa(ac, pa);
58342 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
58343 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
58344
58345 ei = EXT4_I(ac->ac_inode);
58346 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58347 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
58348 trace_ext4_mb_new_group_pa(ac, pa);
58349
58350 ext4_mb_use_group_pa(ac, pa);
58351 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58352 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58353
58354 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58355 lg = ac->ac_lg;
58356 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
58357 * from the bitmap and continue.
58358 */
58359 }
58360 - atomic_add(free, &sbi->s_mb_discarded);
58361 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
58362
58363 return err;
58364 }
58365 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
58366 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
58367 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
58368 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
58369 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58370 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58371 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
58372
58373 return 0;
58374 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
58375 index 04434ad..6404663 100644
58376 --- a/fs/ext4/mmp.c
58377 +++ b/fs/ext4/mmp.c
58378 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
58379 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
58380 const char *function, unsigned int line, const char *msg)
58381 {
58382 - __ext4_warning(sb, function, line, msg);
58383 + __ext4_warning(sb, function, line, "%s", msg);
58384 __ext4_warning(sb, function, line,
58385 "MMP failure info: last update time: %llu, last update "
58386 "node: %s, last update device: %s\n",
58387 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
58388 index 1f7784d..5d8bbad 100644
58389 --- a/fs/ext4/super.c
58390 +++ b/fs/ext4/super.c
58391 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
58392 }
58393
58394 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
58395 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58396 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58397 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
58398
58399 #ifdef CONFIG_QUOTA
58400 @@ -2450,7 +2450,7 @@ struct ext4_attr {
58401 int offset;
58402 int deprecated_val;
58403 } u;
58404 -};
58405 +} __do_const;
58406
58407 static int parse_strtoull(const char *buf,
58408 unsigned long long max, unsigned long long *value)
58409 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
58410 index 1423c48..9c0c6dc 100644
58411 --- a/fs/ext4/xattr.c
58412 +++ b/fs/ext4/xattr.c
58413 @@ -381,7 +381,7 @@ static int
58414 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58415 char *buffer, size_t buffer_size)
58416 {
58417 - size_t rest = buffer_size;
58418 + size_t rest = buffer_size, total_size = 0;
58419
58420 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
58421 const struct xattr_handler *handler =
58422 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58423 buffer += size;
58424 }
58425 rest -= size;
58426 + total_size += size;
58427 }
58428 }
58429 - return buffer_size - rest;
58430 + return total_size;
58431 }
58432
58433 static int
58434 diff --git a/fs/fcntl.c b/fs/fcntl.c
58435 index ef68665..5deacdc 100644
58436 --- a/fs/fcntl.c
58437 +++ b/fs/fcntl.c
58438 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
58439 if (err)
58440 return err;
58441
58442 + if (gr_handle_chroot_fowner(pid, type))
58443 + return -ENOENT;
58444 + if (gr_check_protected_task_fowner(pid, type))
58445 + return -EACCES;
58446 +
58447 f_modown(filp, pid, type, force);
58448 return 0;
58449 }
58450 diff --git a/fs/fhandle.c b/fs/fhandle.c
58451 index 999ff5c..41f4109 100644
58452 --- a/fs/fhandle.c
58453 +++ b/fs/fhandle.c
58454 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
58455 } else
58456 retval = 0;
58457 /* copy the mount id */
58458 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
58459 - sizeof(*mnt_id)) ||
58460 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
58461 copy_to_user(ufh, handle,
58462 sizeof(struct file_handle) + handle_bytes))
58463 retval = -EFAULT;
58464 diff --git a/fs/file.c b/fs/file.c
58465 index 4a78f98..f9a6d25 100644
58466 --- a/fs/file.c
58467 +++ b/fs/file.c
58468 @@ -16,6 +16,7 @@
58469 #include <linux/slab.h>
58470 #include <linux/vmalloc.h>
58471 #include <linux/file.h>
58472 +#include <linux/security.h>
58473 #include <linux/fdtable.h>
58474 #include <linux/bitops.h>
58475 #include <linux/interrupt.h>
58476 @@ -141,7 +142,7 @@ out:
58477 * Return <0 error code on error; 1 on successful completion.
58478 * The files->file_lock should be held on entry, and will be held on exit.
58479 */
58480 -static int expand_fdtable(struct files_struct *files, int nr)
58481 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
58482 __releases(files->file_lock)
58483 __acquires(files->file_lock)
58484 {
58485 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
58486 * expanded and execution may have blocked.
58487 * The files->file_lock should be held on entry, and will be held on exit.
58488 */
58489 -static int expand_files(struct files_struct *files, int nr)
58490 +static int expand_files(struct files_struct *files, unsigned int nr)
58491 {
58492 struct fdtable *fdt;
58493
58494 @@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
58495 if (!file)
58496 return __close_fd(files, fd);
58497
58498 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
58499 if (fd >= rlimit(RLIMIT_NOFILE))
58500 return -EBADF;
58501
58502 @@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
58503 if (unlikely(oldfd == newfd))
58504 return -EINVAL;
58505
58506 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
58507 if (newfd >= rlimit(RLIMIT_NOFILE))
58508 return -EBADF;
58509
58510 @@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
58511 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
58512 {
58513 int err;
58514 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
58515 if (from >= rlimit(RLIMIT_NOFILE))
58516 return -EINVAL;
58517 err = alloc_fd(from, flags);
58518 diff --git a/fs/filesystems.c b/fs/filesystems.c
58519 index 92567d9..fcd8cbf 100644
58520 --- a/fs/filesystems.c
58521 +++ b/fs/filesystems.c
58522 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
58523 int len = dot ? dot - name : strlen(name);
58524
58525 fs = __get_fs_type(name, len);
58526 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
58527 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
58528 +#else
58529 if (!fs && (request_module("fs-%.*s", len, name) == 0))
58530 +#endif
58531 fs = __get_fs_type(name, len);
58532
58533 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
58534 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
58535 index 7dca743..543d620 100644
58536 --- a/fs/fs_struct.c
58537 +++ b/fs/fs_struct.c
58538 @@ -4,6 +4,7 @@
58539 #include <linux/path.h>
58540 #include <linux/slab.h>
58541 #include <linux/fs_struct.h>
58542 +#include <linux/grsecurity.h>
58543 #include "internal.h"
58544
58545 /*
58546 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
58547 write_seqcount_begin(&fs->seq);
58548 old_root = fs->root;
58549 fs->root = *path;
58550 + gr_set_chroot_entries(current, path);
58551 write_seqcount_end(&fs->seq);
58552 spin_unlock(&fs->lock);
58553 if (old_root.dentry)
58554 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
58555 int hits = 0;
58556 spin_lock(&fs->lock);
58557 write_seqcount_begin(&fs->seq);
58558 + /* this root replacement is only done by pivot_root,
58559 + leave grsec's chroot tagging alone for this task
58560 + so that a pivoted root isn't treated as a chroot
58561 + */
58562 hits += replace_path(&fs->root, old_root, new_root);
58563 hits += replace_path(&fs->pwd, old_root, new_root);
58564 write_seqcount_end(&fs->seq);
58565 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
58566 task_lock(tsk);
58567 spin_lock(&fs->lock);
58568 tsk->fs = NULL;
58569 - kill = !--fs->users;
58570 + gr_clear_chroot_entries(tsk);
58571 + kill = !atomic_dec_return(&fs->users);
58572 spin_unlock(&fs->lock);
58573 task_unlock(tsk);
58574 if (kill)
58575 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58576 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
58577 /* We don't need to lock fs - think why ;-) */
58578 if (fs) {
58579 - fs->users = 1;
58580 + atomic_set(&fs->users, 1);
58581 fs->in_exec = 0;
58582 spin_lock_init(&fs->lock);
58583 seqcount_init(&fs->seq);
58584 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58585 spin_lock(&old->lock);
58586 fs->root = old->root;
58587 path_get(&fs->root);
58588 + /* instead of calling gr_set_chroot_entries here,
58589 + we call it from every caller of this function
58590 + */
58591 fs->pwd = old->pwd;
58592 path_get(&fs->pwd);
58593 spin_unlock(&old->lock);
58594 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
58595
58596 task_lock(current);
58597 spin_lock(&fs->lock);
58598 - kill = !--fs->users;
58599 + kill = !atomic_dec_return(&fs->users);
58600 current->fs = new_fs;
58601 + gr_set_chroot_entries(current, &new_fs->root);
58602 spin_unlock(&fs->lock);
58603 task_unlock(current);
58604
58605 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
58606
58607 int current_umask(void)
58608 {
58609 - return current->fs->umask;
58610 + return current->fs->umask | gr_acl_umask();
58611 }
58612 EXPORT_SYMBOL(current_umask);
58613
58614 /* to be mentioned only in INIT_TASK */
58615 struct fs_struct init_fs = {
58616 - .users = 1,
58617 + .users = ATOMIC_INIT(1),
58618 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
58619 .seq = SEQCNT_ZERO(init_fs.seq),
58620 .umask = 0022,
58621 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
58622 index 29d7feb..303644d 100644
58623 --- a/fs/fscache/cookie.c
58624 +++ b/fs/fscache/cookie.c
58625 @@ -19,7 +19,7 @@
58626
58627 struct kmem_cache *fscache_cookie_jar;
58628
58629 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
58630 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
58631
58632 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
58633 static int fscache_alloc_object(struct fscache_cache *cache,
58634 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
58635 parent ? (char *) parent->def->name : "<no-parent>",
58636 def->name, netfs_data, enable);
58637
58638 - fscache_stat(&fscache_n_acquires);
58639 + fscache_stat_unchecked(&fscache_n_acquires);
58640
58641 /* if there's no parent cookie, then we don't create one here either */
58642 if (!parent) {
58643 - fscache_stat(&fscache_n_acquires_null);
58644 + fscache_stat_unchecked(&fscache_n_acquires_null);
58645 _leave(" [no parent]");
58646 return NULL;
58647 }
58648 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58649 /* allocate and initialise a cookie */
58650 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
58651 if (!cookie) {
58652 - fscache_stat(&fscache_n_acquires_oom);
58653 + fscache_stat_unchecked(&fscache_n_acquires_oom);
58654 _leave(" [ENOMEM]");
58655 return NULL;
58656 }
58657 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
58658
58659 switch (cookie->def->type) {
58660 case FSCACHE_COOKIE_TYPE_INDEX:
58661 - fscache_stat(&fscache_n_cookie_index);
58662 + fscache_stat_unchecked(&fscache_n_cookie_index);
58663 break;
58664 case FSCACHE_COOKIE_TYPE_DATAFILE:
58665 - fscache_stat(&fscache_n_cookie_data);
58666 + fscache_stat_unchecked(&fscache_n_cookie_data);
58667 break;
58668 default:
58669 - fscache_stat(&fscache_n_cookie_special);
58670 + fscache_stat_unchecked(&fscache_n_cookie_special);
58671 break;
58672 }
58673
58674 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58675 } else {
58676 atomic_dec(&parent->n_children);
58677 __fscache_cookie_put(cookie);
58678 - fscache_stat(&fscache_n_acquires_nobufs);
58679 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
58680 _leave(" = NULL");
58681 return NULL;
58682 }
58683 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58684 }
58685 }
58686
58687 - fscache_stat(&fscache_n_acquires_ok);
58688 + fscache_stat_unchecked(&fscache_n_acquires_ok);
58689 _leave(" = %p", cookie);
58690 return cookie;
58691 }
58692 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
58693 cache = fscache_select_cache_for_object(cookie->parent);
58694 if (!cache) {
58695 up_read(&fscache_addremove_sem);
58696 - fscache_stat(&fscache_n_acquires_no_cache);
58697 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
58698 _leave(" = -ENOMEDIUM [no cache]");
58699 return -ENOMEDIUM;
58700 }
58701 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
58702 object = cache->ops->alloc_object(cache, cookie);
58703 fscache_stat_d(&fscache_n_cop_alloc_object);
58704 if (IS_ERR(object)) {
58705 - fscache_stat(&fscache_n_object_no_alloc);
58706 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
58707 ret = PTR_ERR(object);
58708 goto error;
58709 }
58710
58711 - fscache_stat(&fscache_n_object_alloc);
58712 + fscache_stat_unchecked(&fscache_n_object_alloc);
58713
58714 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
58715 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
58716
58717 _debug("ALLOC OBJ%x: %s {%lx}",
58718 object->debug_id, cookie->def->name, object->events);
58719 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
58720
58721 _enter("{%s}", cookie->def->name);
58722
58723 - fscache_stat(&fscache_n_invalidates);
58724 + fscache_stat_unchecked(&fscache_n_invalidates);
58725
58726 /* Only permit invalidation of data files. Invalidating an index will
58727 * require the caller to release all its attachments to the tree rooted
58728 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
58729 {
58730 struct fscache_object *object;
58731
58732 - fscache_stat(&fscache_n_updates);
58733 + fscache_stat_unchecked(&fscache_n_updates);
58734
58735 if (!cookie) {
58736 - fscache_stat(&fscache_n_updates_null);
58737 + fscache_stat_unchecked(&fscache_n_updates_null);
58738 _leave(" [no cookie]");
58739 return;
58740 }
58741 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
58742 */
58743 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
58744 {
58745 - fscache_stat(&fscache_n_relinquishes);
58746 + fscache_stat_unchecked(&fscache_n_relinquishes);
58747 if (retire)
58748 - fscache_stat(&fscache_n_relinquishes_retire);
58749 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
58750
58751 if (!cookie) {
58752 - fscache_stat(&fscache_n_relinquishes_null);
58753 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
58754 _leave(" [no cookie]");
58755 return;
58756 }
58757 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
58758 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
58759 goto inconsistent;
58760
58761 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58762 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58763
58764 __fscache_use_cookie(cookie);
58765 if (fscache_submit_op(object, op) < 0)
58766 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
58767 index 4226f66..0fb3f45 100644
58768 --- a/fs/fscache/internal.h
58769 +++ b/fs/fscache/internal.h
58770 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
58771 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
58772 extern int fscache_wait_for_operation_activation(struct fscache_object *,
58773 struct fscache_operation *,
58774 - atomic_t *,
58775 - atomic_t *,
58776 + atomic_unchecked_t *,
58777 + atomic_unchecked_t *,
58778 void (*)(struct fscache_operation *));
58779 extern void fscache_invalidate_writes(struct fscache_cookie *);
58780
58781 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
58782 * stats.c
58783 */
58784 #ifdef CONFIG_FSCACHE_STATS
58785 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58786 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58787 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58788 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58789
58790 -extern atomic_t fscache_n_op_pend;
58791 -extern atomic_t fscache_n_op_run;
58792 -extern atomic_t fscache_n_op_enqueue;
58793 -extern atomic_t fscache_n_op_deferred_release;
58794 -extern atomic_t fscache_n_op_release;
58795 -extern atomic_t fscache_n_op_gc;
58796 -extern atomic_t fscache_n_op_cancelled;
58797 -extern atomic_t fscache_n_op_rejected;
58798 +extern atomic_unchecked_t fscache_n_op_pend;
58799 +extern atomic_unchecked_t fscache_n_op_run;
58800 +extern atomic_unchecked_t fscache_n_op_enqueue;
58801 +extern atomic_unchecked_t fscache_n_op_deferred_release;
58802 +extern atomic_unchecked_t fscache_n_op_release;
58803 +extern atomic_unchecked_t fscache_n_op_gc;
58804 +extern atomic_unchecked_t fscache_n_op_cancelled;
58805 +extern atomic_unchecked_t fscache_n_op_rejected;
58806
58807 -extern atomic_t fscache_n_attr_changed;
58808 -extern atomic_t fscache_n_attr_changed_ok;
58809 -extern atomic_t fscache_n_attr_changed_nobufs;
58810 -extern atomic_t fscache_n_attr_changed_nomem;
58811 -extern atomic_t fscache_n_attr_changed_calls;
58812 +extern atomic_unchecked_t fscache_n_attr_changed;
58813 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
58814 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
58815 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
58816 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
58817
58818 -extern atomic_t fscache_n_allocs;
58819 -extern atomic_t fscache_n_allocs_ok;
58820 -extern atomic_t fscache_n_allocs_wait;
58821 -extern atomic_t fscache_n_allocs_nobufs;
58822 -extern atomic_t fscache_n_allocs_intr;
58823 -extern atomic_t fscache_n_allocs_object_dead;
58824 -extern atomic_t fscache_n_alloc_ops;
58825 -extern atomic_t fscache_n_alloc_op_waits;
58826 +extern atomic_unchecked_t fscache_n_allocs;
58827 +extern atomic_unchecked_t fscache_n_allocs_ok;
58828 +extern atomic_unchecked_t fscache_n_allocs_wait;
58829 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
58830 +extern atomic_unchecked_t fscache_n_allocs_intr;
58831 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
58832 +extern atomic_unchecked_t fscache_n_alloc_ops;
58833 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
58834
58835 -extern atomic_t fscache_n_retrievals;
58836 -extern atomic_t fscache_n_retrievals_ok;
58837 -extern atomic_t fscache_n_retrievals_wait;
58838 -extern atomic_t fscache_n_retrievals_nodata;
58839 -extern atomic_t fscache_n_retrievals_nobufs;
58840 -extern atomic_t fscache_n_retrievals_intr;
58841 -extern atomic_t fscache_n_retrievals_nomem;
58842 -extern atomic_t fscache_n_retrievals_object_dead;
58843 -extern atomic_t fscache_n_retrieval_ops;
58844 -extern atomic_t fscache_n_retrieval_op_waits;
58845 +extern atomic_unchecked_t fscache_n_retrievals;
58846 +extern atomic_unchecked_t fscache_n_retrievals_ok;
58847 +extern atomic_unchecked_t fscache_n_retrievals_wait;
58848 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
58849 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
58850 +extern atomic_unchecked_t fscache_n_retrievals_intr;
58851 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
58852 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
58853 +extern atomic_unchecked_t fscache_n_retrieval_ops;
58854 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
58855
58856 -extern atomic_t fscache_n_stores;
58857 -extern atomic_t fscache_n_stores_ok;
58858 -extern atomic_t fscache_n_stores_again;
58859 -extern atomic_t fscache_n_stores_nobufs;
58860 -extern atomic_t fscache_n_stores_oom;
58861 -extern atomic_t fscache_n_store_ops;
58862 -extern atomic_t fscache_n_store_calls;
58863 -extern atomic_t fscache_n_store_pages;
58864 -extern atomic_t fscache_n_store_radix_deletes;
58865 -extern atomic_t fscache_n_store_pages_over_limit;
58866 +extern atomic_unchecked_t fscache_n_stores;
58867 +extern atomic_unchecked_t fscache_n_stores_ok;
58868 +extern atomic_unchecked_t fscache_n_stores_again;
58869 +extern atomic_unchecked_t fscache_n_stores_nobufs;
58870 +extern atomic_unchecked_t fscache_n_stores_oom;
58871 +extern atomic_unchecked_t fscache_n_store_ops;
58872 +extern atomic_unchecked_t fscache_n_store_calls;
58873 +extern atomic_unchecked_t fscache_n_store_pages;
58874 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
58875 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
58876
58877 -extern atomic_t fscache_n_store_vmscan_not_storing;
58878 -extern atomic_t fscache_n_store_vmscan_gone;
58879 -extern atomic_t fscache_n_store_vmscan_busy;
58880 -extern atomic_t fscache_n_store_vmscan_cancelled;
58881 -extern atomic_t fscache_n_store_vmscan_wait;
58882 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
58883 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
58884 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
58885 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
58886 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
58887
58888 -extern atomic_t fscache_n_marks;
58889 -extern atomic_t fscache_n_uncaches;
58890 +extern atomic_unchecked_t fscache_n_marks;
58891 +extern atomic_unchecked_t fscache_n_uncaches;
58892
58893 -extern atomic_t fscache_n_acquires;
58894 -extern atomic_t fscache_n_acquires_null;
58895 -extern atomic_t fscache_n_acquires_no_cache;
58896 -extern atomic_t fscache_n_acquires_ok;
58897 -extern atomic_t fscache_n_acquires_nobufs;
58898 -extern atomic_t fscache_n_acquires_oom;
58899 +extern atomic_unchecked_t fscache_n_acquires;
58900 +extern atomic_unchecked_t fscache_n_acquires_null;
58901 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
58902 +extern atomic_unchecked_t fscache_n_acquires_ok;
58903 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
58904 +extern atomic_unchecked_t fscache_n_acquires_oom;
58905
58906 -extern atomic_t fscache_n_invalidates;
58907 -extern atomic_t fscache_n_invalidates_run;
58908 +extern atomic_unchecked_t fscache_n_invalidates;
58909 +extern atomic_unchecked_t fscache_n_invalidates_run;
58910
58911 -extern atomic_t fscache_n_updates;
58912 -extern atomic_t fscache_n_updates_null;
58913 -extern atomic_t fscache_n_updates_run;
58914 +extern atomic_unchecked_t fscache_n_updates;
58915 +extern atomic_unchecked_t fscache_n_updates_null;
58916 +extern atomic_unchecked_t fscache_n_updates_run;
58917
58918 -extern atomic_t fscache_n_relinquishes;
58919 -extern atomic_t fscache_n_relinquishes_null;
58920 -extern atomic_t fscache_n_relinquishes_waitcrt;
58921 -extern atomic_t fscache_n_relinquishes_retire;
58922 +extern atomic_unchecked_t fscache_n_relinquishes;
58923 +extern atomic_unchecked_t fscache_n_relinquishes_null;
58924 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
58925 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
58926
58927 -extern atomic_t fscache_n_cookie_index;
58928 -extern atomic_t fscache_n_cookie_data;
58929 -extern atomic_t fscache_n_cookie_special;
58930 +extern atomic_unchecked_t fscache_n_cookie_index;
58931 +extern atomic_unchecked_t fscache_n_cookie_data;
58932 +extern atomic_unchecked_t fscache_n_cookie_special;
58933
58934 -extern atomic_t fscache_n_object_alloc;
58935 -extern atomic_t fscache_n_object_no_alloc;
58936 -extern atomic_t fscache_n_object_lookups;
58937 -extern atomic_t fscache_n_object_lookups_negative;
58938 -extern atomic_t fscache_n_object_lookups_positive;
58939 -extern atomic_t fscache_n_object_lookups_timed_out;
58940 -extern atomic_t fscache_n_object_created;
58941 -extern atomic_t fscache_n_object_avail;
58942 -extern atomic_t fscache_n_object_dead;
58943 +extern atomic_unchecked_t fscache_n_object_alloc;
58944 +extern atomic_unchecked_t fscache_n_object_no_alloc;
58945 +extern atomic_unchecked_t fscache_n_object_lookups;
58946 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
58947 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
58948 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
58949 +extern atomic_unchecked_t fscache_n_object_created;
58950 +extern atomic_unchecked_t fscache_n_object_avail;
58951 +extern atomic_unchecked_t fscache_n_object_dead;
58952
58953 -extern atomic_t fscache_n_checkaux_none;
58954 -extern atomic_t fscache_n_checkaux_okay;
58955 -extern atomic_t fscache_n_checkaux_update;
58956 -extern atomic_t fscache_n_checkaux_obsolete;
58957 +extern atomic_unchecked_t fscache_n_checkaux_none;
58958 +extern atomic_unchecked_t fscache_n_checkaux_okay;
58959 +extern atomic_unchecked_t fscache_n_checkaux_update;
58960 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
58961
58962 extern atomic_t fscache_n_cop_alloc_object;
58963 extern atomic_t fscache_n_cop_lookup_object;
58964 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
58965 atomic_inc(stat);
58966 }
58967
58968 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
58969 +{
58970 + atomic_inc_unchecked(stat);
58971 +}
58972 +
58973 static inline void fscache_stat_d(atomic_t *stat)
58974 {
58975 atomic_dec(stat);
58976 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
58977
58978 #define __fscache_stat(stat) (NULL)
58979 #define fscache_stat(stat) do {} while (0)
58980 +#define fscache_stat_unchecked(stat) do {} while (0)
58981 #define fscache_stat_d(stat) do {} while (0)
58982 #endif
58983
58984 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
58985 index 53d35c5..5d68ed4 100644
58986 --- a/fs/fscache/object.c
58987 +++ b/fs/fscache/object.c
58988 @@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
58989 _debug("LOOKUP \"%s\" in \"%s\"",
58990 cookie->def->name, object->cache->tag->name);
58991
58992 - fscache_stat(&fscache_n_object_lookups);
58993 + fscache_stat_unchecked(&fscache_n_object_lookups);
58994 fscache_stat(&fscache_n_cop_lookup_object);
58995 ret = object->cache->ops->lookup_object(object);
58996 fscache_stat_d(&fscache_n_cop_lookup_object);
58997 @@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
58998 if (ret == -ETIMEDOUT) {
58999 /* probably stuck behind another object, so move this one to
59000 * the back of the queue */
59001 - fscache_stat(&fscache_n_object_lookups_timed_out);
59002 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59003 _leave(" [timeout]");
59004 return NO_TRANSIT;
59005 }
59006 @@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59007 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59008
59009 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59010 - fscache_stat(&fscache_n_object_lookups_negative);
59011 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59012
59013 /* Allow write requests to begin stacking up and read requests to begin
59014 * returning ENODATA.
59015 @@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
59016 /* if we were still looking up, then we must have a positive lookup
59017 * result, in which case there may be data available */
59018 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59019 - fscache_stat(&fscache_n_object_lookups_positive);
59020 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59021
59022 /* We do (presumably) have data */
59023 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59024 @@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
59025 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59026 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59027 } else {
59028 - fscache_stat(&fscache_n_object_created);
59029 + fscache_stat_unchecked(&fscache_n_object_created);
59030 }
59031
59032 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59033 @@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59034 fscache_stat_d(&fscache_n_cop_lookup_complete);
59035
59036 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59037 - fscache_stat(&fscache_n_object_avail);
59038 + fscache_stat_unchecked(&fscache_n_object_avail);
59039
59040 _leave("");
59041 return transit_to(JUMPSTART_DEPS);
59042 @@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59043
59044 /* this just shifts the object release to the work processor */
59045 fscache_put_object(object);
59046 - fscache_stat(&fscache_n_object_dead);
59047 + fscache_stat_unchecked(&fscache_n_object_dead);
59048
59049 _leave("");
59050 return transit_to(OBJECT_DEAD);
59051 @@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59052 enum fscache_checkaux result;
59053
59054 if (!object->cookie->def->check_aux) {
59055 - fscache_stat(&fscache_n_checkaux_none);
59056 + fscache_stat_unchecked(&fscache_n_checkaux_none);
59057 return FSCACHE_CHECKAUX_OKAY;
59058 }
59059
59060 @@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59061 switch (result) {
59062 /* entry okay as is */
59063 case FSCACHE_CHECKAUX_OKAY:
59064 - fscache_stat(&fscache_n_checkaux_okay);
59065 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
59066 break;
59067
59068 /* entry requires update */
59069 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59070 - fscache_stat(&fscache_n_checkaux_update);
59071 + fscache_stat_unchecked(&fscache_n_checkaux_update);
59072 break;
59073
59074 /* entry requires deletion */
59075 case FSCACHE_CHECKAUX_OBSOLETE:
59076 - fscache_stat(&fscache_n_checkaux_obsolete);
59077 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59078 break;
59079
59080 default:
59081 @@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59082 {
59083 const struct fscache_state *s;
59084
59085 - fscache_stat(&fscache_n_invalidates_run);
59086 + fscache_stat_unchecked(&fscache_n_invalidates_run);
59087 fscache_stat(&fscache_n_cop_invalidate_object);
59088 s = _fscache_invalidate_object(object, event);
59089 fscache_stat_d(&fscache_n_cop_invalidate_object);
59090 @@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59091 {
59092 _enter("{OBJ%x},%d", object->debug_id, event);
59093
59094 - fscache_stat(&fscache_n_updates_run);
59095 + fscache_stat_unchecked(&fscache_n_updates_run);
59096 fscache_stat(&fscache_n_cop_update_object);
59097 object->cache->ops->update_object(object);
59098 fscache_stat_d(&fscache_n_cop_update_object);
59099 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
59100 index 318071a..379938b 100644
59101 --- a/fs/fscache/operation.c
59102 +++ b/fs/fscache/operation.c
59103 @@ -17,7 +17,7 @@
59104 #include <linux/slab.h>
59105 #include "internal.h"
59106
59107 -atomic_t fscache_op_debug_id;
59108 +atomic_unchecked_t fscache_op_debug_id;
59109 EXPORT_SYMBOL(fscache_op_debug_id);
59110
59111 /**
59112 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59113 ASSERTCMP(atomic_read(&op->usage), >, 0);
59114 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59115
59116 - fscache_stat(&fscache_n_op_enqueue);
59117 + fscache_stat_unchecked(&fscache_n_op_enqueue);
59118 switch (op->flags & FSCACHE_OP_TYPE) {
59119 case FSCACHE_OP_ASYNC:
59120 _debug("queue async");
59121 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59122 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59123 if (op->processor)
59124 fscache_enqueue_operation(op);
59125 - fscache_stat(&fscache_n_op_run);
59126 + fscache_stat_unchecked(&fscache_n_op_run);
59127 }
59128
59129 /*
59130 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59131 if (object->n_in_progress > 0) {
59132 atomic_inc(&op->usage);
59133 list_add_tail(&op->pend_link, &object->pending_ops);
59134 - fscache_stat(&fscache_n_op_pend);
59135 + fscache_stat_unchecked(&fscache_n_op_pend);
59136 } else if (!list_empty(&object->pending_ops)) {
59137 atomic_inc(&op->usage);
59138 list_add_tail(&op->pend_link, &object->pending_ops);
59139 - fscache_stat(&fscache_n_op_pend);
59140 + fscache_stat_unchecked(&fscache_n_op_pend);
59141 fscache_start_operations(object);
59142 } else {
59143 ASSERTCMP(object->n_in_progress, ==, 0);
59144 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59145 object->n_exclusive++; /* reads and writes must wait */
59146 atomic_inc(&op->usage);
59147 list_add_tail(&op->pend_link, &object->pending_ops);
59148 - fscache_stat(&fscache_n_op_pend);
59149 + fscache_stat_unchecked(&fscache_n_op_pend);
59150 ret = 0;
59151 } else {
59152 /* If we're in any other state, there must have been an I/O
59153 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59154 if (object->n_exclusive > 0) {
59155 atomic_inc(&op->usage);
59156 list_add_tail(&op->pend_link, &object->pending_ops);
59157 - fscache_stat(&fscache_n_op_pend);
59158 + fscache_stat_unchecked(&fscache_n_op_pend);
59159 } else if (!list_empty(&object->pending_ops)) {
59160 atomic_inc(&op->usage);
59161 list_add_tail(&op->pend_link, &object->pending_ops);
59162 - fscache_stat(&fscache_n_op_pend);
59163 + fscache_stat_unchecked(&fscache_n_op_pend);
59164 fscache_start_operations(object);
59165 } else {
59166 ASSERTCMP(object->n_exclusive, ==, 0);
59167 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59168 object->n_ops++;
59169 atomic_inc(&op->usage);
59170 list_add_tail(&op->pend_link, &object->pending_ops);
59171 - fscache_stat(&fscache_n_op_pend);
59172 + fscache_stat_unchecked(&fscache_n_op_pend);
59173 ret = 0;
59174 } else if (fscache_object_is_dying(object)) {
59175 - fscache_stat(&fscache_n_op_rejected);
59176 + fscache_stat_unchecked(&fscache_n_op_rejected);
59177 op->state = FSCACHE_OP_ST_CANCELLED;
59178 ret = -ENOBUFS;
59179 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59180 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59181 ret = -EBUSY;
59182 if (op->state == FSCACHE_OP_ST_PENDING) {
59183 ASSERT(!list_empty(&op->pend_link));
59184 - fscache_stat(&fscache_n_op_cancelled);
59185 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59186 list_del_init(&op->pend_link);
59187 if (do_cancel)
59188 do_cancel(op);
59189 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
59190 while (!list_empty(&object->pending_ops)) {
59191 op = list_entry(object->pending_ops.next,
59192 struct fscache_operation, pend_link);
59193 - fscache_stat(&fscache_n_op_cancelled);
59194 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59195 list_del_init(&op->pend_link);
59196
59197 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
59198 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
59199 op->state, ==, FSCACHE_OP_ST_CANCELLED);
59200 op->state = FSCACHE_OP_ST_DEAD;
59201
59202 - fscache_stat(&fscache_n_op_release);
59203 + fscache_stat_unchecked(&fscache_n_op_release);
59204
59205 if (op->release) {
59206 op->release(op);
59207 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
59208 * lock, and defer it otherwise */
59209 if (!spin_trylock(&object->lock)) {
59210 _debug("defer put");
59211 - fscache_stat(&fscache_n_op_deferred_release);
59212 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
59213
59214 cache = object->cache;
59215 spin_lock(&cache->op_gc_list_lock);
59216 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
59217
59218 _debug("GC DEFERRED REL OBJ%x OP%x",
59219 object->debug_id, op->debug_id);
59220 - fscache_stat(&fscache_n_op_gc);
59221 + fscache_stat_unchecked(&fscache_n_op_gc);
59222
59223 ASSERTCMP(atomic_read(&op->usage), ==, 0);
59224 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
59225 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
59226 index 7f5c658..6c1e164 100644
59227 --- a/fs/fscache/page.c
59228 +++ b/fs/fscache/page.c
59229 @@ -61,7 +61,7 @@ try_again:
59230 val = radix_tree_lookup(&cookie->stores, page->index);
59231 if (!val) {
59232 rcu_read_unlock();
59233 - fscache_stat(&fscache_n_store_vmscan_not_storing);
59234 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
59235 __fscache_uncache_page(cookie, page);
59236 return true;
59237 }
59238 @@ -91,11 +91,11 @@ try_again:
59239 spin_unlock(&cookie->stores_lock);
59240
59241 if (xpage) {
59242 - fscache_stat(&fscache_n_store_vmscan_cancelled);
59243 - fscache_stat(&fscache_n_store_radix_deletes);
59244 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
59245 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59246 ASSERTCMP(xpage, ==, page);
59247 } else {
59248 - fscache_stat(&fscache_n_store_vmscan_gone);
59249 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
59250 }
59251
59252 wake_up_bit(&cookie->flags, 0);
59253 @@ -110,11 +110,11 @@ page_busy:
59254 * sleeping on memory allocation, so we may need to impose a timeout
59255 * too. */
59256 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
59257 - fscache_stat(&fscache_n_store_vmscan_busy);
59258 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
59259 return false;
59260 }
59261
59262 - fscache_stat(&fscache_n_store_vmscan_wait);
59263 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
59264 __fscache_wait_on_page_write(cookie, page);
59265 gfp &= ~__GFP_WAIT;
59266 goto try_again;
59267 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
59268 FSCACHE_COOKIE_STORING_TAG);
59269 if (!radix_tree_tag_get(&cookie->stores, page->index,
59270 FSCACHE_COOKIE_PENDING_TAG)) {
59271 - fscache_stat(&fscache_n_store_radix_deletes);
59272 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59273 xpage = radix_tree_delete(&cookie->stores, page->index);
59274 }
59275 spin_unlock(&cookie->stores_lock);
59276 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
59277
59278 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
59279
59280 - fscache_stat(&fscache_n_attr_changed_calls);
59281 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
59282
59283 if (fscache_object_is_active(object)) {
59284 fscache_stat(&fscache_n_cop_attr_changed);
59285 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59286
59287 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59288
59289 - fscache_stat(&fscache_n_attr_changed);
59290 + fscache_stat_unchecked(&fscache_n_attr_changed);
59291
59292 op = kzalloc(sizeof(*op), GFP_KERNEL);
59293 if (!op) {
59294 - fscache_stat(&fscache_n_attr_changed_nomem);
59295 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
59296 _leave(" = -ENOMEM");
59297 return -ENOMEM;
59298 }
59299 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59300 if (fscache_submit_exclusive_op(object, op) < 0)
59301 goto nobufs;
59302 spin_unlock(&cookie->lock);
59303 - fscache_stat(&fscache_n_attr_changed_ok);
59304 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
59305 fscache_put_operation(op);
59306 _leave(" = 0");
59307 return 0;
59308 @@ -225,7 +225,7 @@ nobufs:
59309 kfree(op);
59310 if (wake_cookie)
59311 __fscache_wake_unused_cookie(cookie);
59312 - fscache_stat(&fscache_n_attr_changed_nobufs);
59313 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
59314 _leave(" = %d", -ENOBUFS);
59315 return -ENOBUFS;
59316 }
59317 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
59318 /* allocate a retrieval operation and attempt to submit it */
59319 op = kzalloc(sizeof(*op), GFP_NOIO);
59320 if (!op) {
59321 - fscache_stat(&fscache_n_retrievals_nomem);
59322 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59323 return NULL;
59324 }
59325
59326 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
59327 return 0;
59328 }
59329
59330 - fscache_stat(&fscache_n_retrievals_wait);
59331 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
59332
59333 jif = jiffies;
59334 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
59335 fscache_wait_bit_interruptible,
59336 TASK_INTERRUPTIBLE) != 0) {
59337 - fscache_stat(&fscache_n_retrievals_intr);
59338 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59339 _leave(" = -ERESTARTSYS");
59340 return -ERESTARTSYS;
59341 }
59342 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
59343 */
59344 int fscache_wait_for_operation_activation(struct fscache_object *object,
59345 struct fscache_operation *op,
59346 - atomic_t *stat_op_waits,
59347 - atomic_t *stat_object_dead,
59348 + atomic_unchecked_t *stat_op_waits,
59349 + atomic_unchecked_t *stat_object_dead,
59350 void (*do_cancel)(struct fscache_operation *))
59351 {
59352 int ret;
59353 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59354
59355 _debug(">>> WT");
59356 if (stat_op_waits)
59357 - fscache_stat(stat_op_waits);
59358 + fscache_stat_unchecked(stat_op_waits);
59359 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
59360 fscache_wait_bit_interruptible,
59361 TASK_INTERRUPTIBLE) != 0) {
59362 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59363 check_if_dead:
59364 if (op->state == FSCACHE_OP_ST_CANCELLED) {
59365 if (stat_object_dead)
59366 - fscache_stat(stat_object_dead);
59367 + fscache_stat_unchecked(stat_object_dead);
59368 _leave(" = -ENOBUFS [cancelled]");
59369 return -ENOBUFS;
59370 }
59371 @@ -366,7 +366,7 @@ check_if_dead:
59372 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
59373 fscache_cancel_op(op, do_cancel);
59374 if (stat_object_dead)
59375 - fscache_stat(stat_object_dead);
59376 + fscache_stat_unchecked(stat_object_dead);
59377 return -ENOBUFS;
59378 }
59379 return 0;
59380 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59381
59382 _enter("%p,%p,,,", cookie, page);
59383
59384 - fscache_stat(&fscache_n_retrievals);
59385 + fscache_stat_unchecked(&fscache_n_retrievals);
59386
59387 if (hlist_empty(&cookie->backing_objects))
59388 goto nobufs;
59389 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59390 goto nobufs_unlock_dec;
59391 spin_unlock(&cookie->lock);
59392
59393 - fscache_stat(&fscache_n_retrieval_ops);
59394 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
59395
59396 /* pin the netfs read context in case we need to do the actual netfs
59397 * read because we've encountered a cache read failure */
59398 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59399
59400 error:
59401 if (ret == -ENOMEM)
59402 - fscache_stat(&fscache_n_retrievals_nomem);
59403 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59404 else if (ret == -ERESTARTSYS)
59405 - fscache_stat(&fscache_n_retrievals_intr);
59406 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59407 else if (ret == -ENODATA)
59408 - fscache_stat(&fscache_n_retrievals_nodata);
59409 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59410 else if (ret < 0)
59411 - fscache_stat(&fscache_n_retrievals_nobufs);
59412 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59413 else
59414 - fscache_stat(&fscache_n_retrievals_ok);
59415 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
59416
59417 fscache_put_retrieval(op);
59418 _leave(" = %d", ret);
59419 @@ -490,7 +490,7 @@ nobufs_unlock:
59420 __fscache_wake_unused_cookie(cookie);
59421 kfree(op);
59422 nobufs:
59423 - fscache_stat(&fscache_n_retrievals_nobufs);
59424 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59425 _leave(" = -ENOBUFS");
59426 return -ENOBUFS;
59427 }
59428 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59429
59430 _enter("%p,,%d,,,", cookie, *nr_pages);
59431
59432 - fscache_stat(&fscache_n_retrievals);
59433 + fscache_stat_unchecked(&fscache_n_retrievals);
59434
59435 if (hlist_empty(&cookie->backing_objects))
59436 goto nobufs;
59437 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59438 goto nobufs_unlock_dec;
59439 spin_unlock(&cookie->lock);
59440
59441 - fscache_stat(&fscache_n_retrieval_ops);
59442 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
59443
59444 /* pin the netfs read context in case we need to do the actual netfs
59445 * read because we've encountered a cache read failure */
59446 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59447
59448 error:
59449 if (ret == -ENOMEM)
59450 - fscache_stat(&fscache_n_retrievals_nomem);
59451 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59452 else if (ret == -ERESTARTSYS)
59453 - fscache_stat(&fscache_n_retrievals_intr);
59454 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59455 else if (ret == -ENODATA)
59456 - fscache_stat(&fscache_n_retrievals_nodata);
59457 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59458 else if (ret < 0)
59459 - fscache_stat(&fscache_n_retrievals_nobufs);
59460 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59461 else
59462 - fscache_stat(&fscache_n_retrievals_ok);
59463 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
59464
59465 fscache_put_retrieval(op);
59466 _leave(" = %d", ret);
59467 @@ -621,7 +621,7 @@ nobufs_unlock:
59468 if (wake_cookie)
59469 __fscache_wake_unused_cookie(cookie);
59470 nobufs:
59471 - fscache_stat(&fscache_n_retrievals_nobufs);
59472 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59473 _leave(" = -ENOBUFS");
59474 return -ENOBUFS;
59475 }
59476 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59477
59478 _enter("%p,%p,,,", cookie, page);
59479
59480 - fscache_stat(&fscache_n_allocs);
59481 + fscache_stat_unchecked(&fscache_n_allocs);
59482
59483 if (hlist_empty(&cookie->backing_objects))
59484 goto nobufs;
59485 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59486 goto nobufs_unlock_dec;
59487 spin_unlock(&cookie->lock);
59488
59489 - fscache_stat(&fscache_n_alloc_ops);
59490 + fscache_stat_unchecked(&fscache_n_alloc_ops);
59491
59492 ret = fscache_wait_for_operation_activation(
59493 object, &op->op,
59494 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59495
59496 error:
59497 if (ret == -ERESTARTSYS)
59498 - fscache_stat(&fscache_n_allocs_intr);
59499 + fscache_stat_unchecked(&fscache_n_allocs_intr);
59500 else if (ret < 0)
59501 - fscache_stat(&fscache_n_allocs_nobufs);
59502 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59503 else
59504 - fscache_stat(&fscache_n_allocs_ok);
59505 + fscache_stat_unchecked(&fscache_n_allocs_ok);
59506
59507 fscache_put_retrieval(op);
59508 _leave(" = %d", ret);
59509 @@ -715,7 +715,7 @@ nobufs_unlock:
59510 if (wake_cookie)
59511 __fscache_wake_unused_cookie(cookie);
59512 nobufs:
59513 - fscache_stat(&fscache_n_allocs_nobufs);
59514 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59515 _leave(" = -ENOBUFS");
59516 return -ENOBUFS;
59517 }
59518 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59519
59520 spin_lock(&cookie->stores_lock);
59521
59522 - fscache_stat(&fscache_n_store_calls);
59523 + fscache_stat_unchecked(&fscache_n_store_calls);
59524
59525 /* find a page to store */
59526 page = NULL;
59527 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59528 page = results[0];
59529 _debug("gang %d [%lx]", n, page->index);
59530 if (page->index > op->store_limit) {
59531 - fscache_stat(&fscache_n_store_pages_over_limit);
59532 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
59533 goto superseded;
59534 }
59535
59536 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59537 spin_unlock(&cookie->stores_lock);
59538 spin_unlock(&object->lock);
59539
59540 - fscache_stat(&fscache_n_store_pages);
59541 + fscache_stat_unchecked(&fscache_n_store_pages);
59542 fscache_stat(&fscache_n_cop_write_page);
59543 ret = object->cache->ops->write_page(op, page);
59544 fscache_stat_d(&fscache_n_cop_write_page);
59545 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59546 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59547 ASSERT(PageFsCache(page));
59548
59549 - fscache_stat(&fscache_n_stores);
59550 + fscache_stat_unchecked(&fscache_n_stores);
59551
59552 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
59553 _leave(" = -ENOBUFS [invalidating]");
59554 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59555 spin_unlock(&cookie->stores_lock);
59556 spin_unlock(&object->lock);
59557
59558 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
59559 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59560 op->store_limit = object->store_limit;
59561
59562 __fscache_use_cookie(cookie);
59563 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59564
59565 spin_unlock(&cookie->lock);
59566 radix_tree_preload_end();
59567 - fscache_stat(&fscache_n_store_ops);
59568 - fscache_stat(&fscache_n_stores_ok);
59569 + fscache_stat_unchecked(&fscache_n_store_ops);
59570 + fscache_stat_unchecked(&fscache_n_stores_ok);
59571
59572 /* the work queue now carries its own ref on the object */
59573 fscache_put_operation(&op->op);
59574 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59575 return 0;
59576
59577 already_queued:
59578 - fscache_stat(&fscache_n_stores_again);
59579 + fscache_stat_unchecked(&fscache_n_stores_again);
59580 already_pending:
59581 spin_unlock(&cookie->stores_lock);
59582 spin_unlock(&object->lock);
59583 spin_unlock(&cookie->lock);
59584 radix_tree_preload_end();
59585 kfree(op);
59586 - fscache_stat(&fscache_n_stores_ok);
59587 + fscache_stat_unchecked(&fscache_n_stores_ok);
59588 _leave(" = 0");
59589 return 0;
59590
59591 @@ -1024,14 +1024,14 @@ nobufs:
59592 kfree(op);
59593 if (wake_cookie)
59594 __fscache_wake_unused_cookie(cookie);
59595 - fscache_stat(&fscache_n_stores_nobufs);
59596 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
59597 _leave(" = -ENOBUFS");
59598 return -ENOBUFS;
59599
59600 nomem_free:
59601 kfree(op);
59602 nomem:
59603 - fscache_stat(&fscache_n_stores_oom);
59604 + fscache_stat_unchecked(&fscache_n_stores_oom);
59605 _leave(" = -ENOMEM");
59606 return -ENOMEM;
59607 }
59608 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
59609 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59610 ASSERTCMP(page, !=, NULL);
59611
59612 - fscache_stat(&fscache_n_uncaches);
59613 + fscache_stat_unchecked(&fscache_n_uncaches);
59614
59615 /* cache withdrawal may beat us to it */
59616 if (!PageFsCache(page))
59617 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
59618 struct fscache_cookie *cookie = op->op.object->cookie;
59619
59620 #ifdef CONFIG_FSCACHE_STATS
59621 - atomic_inc(&fscache_n_marks);
59622 + atomic_inc_unchecked(&fscache_n_marks);
59623 #endif
59624
59625 _debug("- mark %p{%lx}", page, page->index);
59626 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
59627 index 40d13c7..ddf52b9 100644
59628 --- a/fs/fscache/stats.c
59629 +++ b/fs/fscache/stats.c
59630 @@ -18,99 +18,99 @@
59631 /*
59632 * operation counters
59633 */
59634 -atomic_t fscache_n_op_pend;
59635 -atomic_t fscache_n_op_run;
59636 -atomic_t fscache_n_op_enqueue;
59637 -atomic_t fscache_n_op_requeue;
59638 -atomic_t fscache_n_op_deferred_release;
59639 -atomic_t fscache_n_op_release;
59640 -atomic_t fscache_n_op_gc;
59641 -atomic_t fscache_n_op_cancelled;
59642 -atomic_t fscache_n_op_rejected;
59643 +atomic_unchecked_t fscache_n_op_pend;
59644 +atomic_unchecked_t fscache_n_op_run;
59645 +atomic_unchecked_t fscache_n_op_enqueue;
59646 +atomic_unchecked_t fscache_n_op_requeue;
59647 +atomic_unchecked_t fscache_n_op_deferred_release;
59648 +atomic_unchecked_t fscache_n_op_release;
59649 +atomic_unchecked_t fscache_n_op_gc;
59650 +atomic_unchecked_t fscache_n_op_cancelled;
59651 +atomic_unchecked_t fscache_n_op_rejected;
59652
59653 -atomic_t fscache_n_attr_changed;
59654 -atomic_t fscache_n_attr_changed_ok;
59655 -atomic_t fscache_n_attr_changed_nobufs;
59656 -atomic_t fscache_n_attr_changed_nomem;
59657 -atomic_t fscache_n_attr_changed_calls;
59658 +atomic_unchecked_t fscache_n_attr_changed;
59659 +atomic_unchecked_t fscache_n_attr_changed_ok;
59660 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
59661 +atomic_unchecked_t fscache_n_attr_changed_nomem;
59662 +atomic_unchecked_t fscache_n_attr_changed_calls;
59663
59664 -atomic_t fscache_n_allocs;
59665 -atomic_t fscache_n_allocs_ok;
59666 -atomic_t fscache_n_allocs_wait;
59667 -atomic_t fscache_n_allocs_nobufs;
59668 -atomic_t fscache_n_allocs_intr;
59669 -atomic_t fscache_n_allocs_object_dead;
59670 -atomic_t fscache_n_alloc_ops;
59671 -atomic_t fscache_n_alloc_op_waits;
59672 +atomic_unchecked_t fscache_n_allocs;
59673 +atomic_unchecked_t fscache_n_allocs_ok;
59674 +atomic_unchecked_t fscache_n_allocs_wait;
59675 +atomic_unchecked_t fscache_n_allocs_nobufs;
59676 +atomic_unchecked_t fscache_n_allocs_intr;
59677 +atomic_unchecked_t fscache_n_allocs_object_dead;
59678 +atomic_unchecked_t fscache_n_alloc_ops;
59679 +atomic_unchecked_t fscache_n_alloc_op_waits;
59680
59681 -atomic_t fscache_n_retrievals;
59682 -atomic_t fscache_n_retrievals_ok;
59683 -atomic_t fscache_n_retrievals_wait;
59684 -atomic_t fscache_n_retrievals_nodata;
59685 -atomic_t fscache_n_retrievals_nobufs;
59686 -atomic_t fscache_n_retrievals_intr;
59687 -atomic_t fscache_n_retrievals_nomem;
59688 -atomic_t fscache_n_retrievals_object_dead;
59689 -atomic_t fscache_n_retrieval_ops;
59690 -atomic_t fscache_n_retrieval_op_waits;
59691 +atomic_unchecked_t fscache_n_retrievals;
59692 +atomic_unchecked_t fscache_n_retrievals_ok;
59693 +atomic_unchecked_t fscache_n_retrievals_wait;
59694 +atomic_unchecked_t fscache_n_retrievals_nodata;
59695 +atomic_unchecked_t fscache_n_retrievals_nobufs;
59696 +atomic_unchecked_t fscache_n_retrievals_intr;
59697 +atomic_unchecked_t fscache_n_retrievals_nomem;
59698 +atomic_unchecked_t fscache_n_retrievals_object_dead;
59699 +atomic_unchecked_t fscache_n_retrieval_ops;
59700 +atomic_unchecked_t fscache_n_retrieval_op_waits;
59701
59702 -atomic_t fscache_n_stores;
59703 -atomic_t fscache_n_stores_ok;
59704 -atomic_t fscache_n_stores_again;
59705 -atomic_t fscache_n_stores_nobufs;
59706 -atomic_t fscache_n_stores_oom;
59707 -atomic_t fscache_n_store_ops;
59708 -atomic_t fscache_n_store_calls;
59709 -atomic_t fscache_n_store_pages;
59710 -atomic_t fscache_n_store_radix_deletes;
59711 -atomic_t fscache_n_store_pages_over_limit;
59712 +atomic_unchecked_t fscache_n_stores;
59713 +atomic_unchecked_t fscache_n_stores_ok;
59714 +atomic_unchecked_t fscache_n_stores_again;
59715 +atomic_unchecked_t fscache_n_stores_nobufs;
59716 +atomic_unchecked_t fscache_n_stores_oom;
59717 +atomic_unchecked_t fscache_n_store_ops;
59718 +atomic_unchecked_t fscache_n_store_calls;
59719 +atomic_unchecked_t fscache_n_store_pages;
59720 +atomic_unchecked_t fscache_n_store_radix_deletes;
59721 +atomic_unchecked_t fscache_n_store_pages_over_limit;
59722
59723 -atomic_t fscache_n_store_vmscan_not_storing;
59724 -atomic_t fscache_n_store_vmscan_gone;
59725 -atomic_t fscache_n_store_vmscan_busy;
59726 -atomic_t fscache_n_store_vmscan_cancelled;
59727 -atomic_t fscache_n_store_vmscan_wait;
59728 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59729 +atomic_unchecked_t fscache_n_store_vmscan_gone;
59730 +atomic_unchecked_t fscache_n_store_vmscan_busy;
59731 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59732 +atomic_unchecked_t fscache_n_store_vmscan_wait;
59733
59734 -atomic_t fscache_n_marks;
59735 -atomic_t fscache_n_uncaches;
59736 +atomic_unchecked_t fscache_n_marks;
59737 +atomic_unchecked_t fscache_n_uncaches;
59738
59739 -atomic_t fscache_n_acquires;
59740 -atomic_t fscache_n_acquires_null;
59741 -atomic_t fscache_n_acquires_no_cache;
59742 -atomic_t fscache_n_acquires_ok;
59743 -atomic_t fscache_n_acquires_nobufs;
59744 -atomic_t fscache_n_acquires_oom;
59745 +atomic_unchecked_t fscache_n_acquires;
59746 +atomic_unchecked_t fscache_n_acquires_null;
59747 +atomic_unchecked_t fscache_n_acquires_no_cache;
59748 +atomic_unchecked_t fscache_n_acquires_ok;
59749 +atomic_unchecked_t fscache_n_acquires_nobufs;
59750 +atomic_unchecked_t fscache_n_acquires_oom;
59751
59752 -atomic_t fscache_n_invalidates;
59753 -atomic_t fscache_n_invalidates_run;
59754 +atomic_unchecked_t fscache_n_invalidates;
59755 +atomic_unchecked_t fscache_n_invalidates_run;
59756
59757 -atomic_t fscache_n_updates;
59758 -atomic_t fscache_n_updates_null;
59759 -atomic_t fscache_n_updates_run;
59760 +atomic_unchecked_t fscache_n_updates;
59761 +atomic_unchecked_t fscache_n_updates_null;
59762 +atomic_unchecked_t fscache_n_updates_run;
59763
59764 -atomic_t fscache_n_relinquishes;
59765 -atomic_t fscache_n_relinquishes_null;
59766 -atomic_t fscache_n_relinquishes_waitcrt;
59767 -atomic_t fscache_n_relinquishes_retire;
59768 +atomic_unchecked_t fscache_n_relinquishes;
59769 +atomic_unchecked_t fscache_n_relinquishes_null;
59770 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59771 +atomic_unchecked_t fscache_n_relinquishes_retire;
59772
59773 -atomic_t fscache_n_cookie_index;
59774 -atomic_t fscache_n_cookie_data;
59775 -atomic_t fscache_n_cookie_special;
59776 +atomic_unchecked_t fscache_n_cookie_index;
59777 +atomic_unchecked_t fscache_n_cookie_data;
59778 +atomic_unchecked_t fscache_n_cookie_special;
59779
59780 -atomic_t fscache_n_object_alloc;
59781 -atomic_t fscache_n_object_no_alloc;
59782 -atomic_t fscache_n_object_lookups;
59783 -atomic_t fscache_n_object_lookups_negative;
59784 -atomic_t fscache_n_object_lookups_positive;
59785 -atomic_t fscache_n_object_lookups_timed_out;
59786 -atomic_t fscache_n_object_created;
59787 -atomic_t fscache_n_object_avail;
59788 -atomic_t fscache_n_object_dead;
59789 +atomic_unchecked_t fscache_n_object_alloc;
59790 +atomic_unchecked_t fscache_n_object_no_alloc;
59791 +atomic_unchecked_t fscache_n_object_lookups;
59792 +atomic_unchecked_t fscache_n_object_lookups_negative;
59793 +atomic_unchecked_t fscache_n_object_lookups_positive;
59794 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
59795 +atomic_unchecked_t fscache_n_object_created;
59796 +atomic_unchecked_t fscache_n_object_avail;
59797 +atomic_unchecked_t fscache_n_object_dead;
59798
59799 -atomic_t fscache_n_checkaux_none;
59800 -atomic_t fscache_n_checkaux_okay;
59801 -atomic_t fscache_n_checkaux_update;
59802 -atomic_t fscache_n_checkaux_obsolete;
59803 +atomic_unchecked_t fscache_n_checkaux_none;
59804 +atomic_unchecked_t fscache_n_checkaux_okay;
59805 +atomic_unchecked_t fscache_n_checkaux_update;
59806 +atomic_unchecked_t fscache_n_checkaux_obsolete;
59807
59808 atomic_t fscache_n_cop_alloc_object;
59809 atomic_t fscache_n_cop_lookup_object;
59810 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
59811 seq_puts(m, "FS-Cache statistics\n");
59812
59813 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
59814 - atomic_read(&fscache_n_cookie_index),
59815 - atomic_read(&fscache_n_cookie_data),
59816 - atomic_read(&fscache_n_cookie_special));
59817 + atomic_read_unchecked(&fscache_n_cookie_index),
59818 + atomic_read_unchecked(&fscache_n_cookie_data),
59819 + atomic_read_unchecked(&fscache_n_cookie_special));
59820
59821 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
59822 - atomic_read(&fscache_n_object_alloc),
59823 - atomic_read(&fscache_n_object_no_alloc),
59824 - atomic_read(&fscache_n_object_avail),
59825 - atomic_read(&fscache_n_object_dead));
59826 + atomic_read_unchecked(&fscache_n_object_alloc),
59827 + atomic_read_unchecked(&fscache_n_object_no_alloc),
59828 + atomic_read_unchecked(&fscache_n_object_avail),
59829 + atomic_read_unchecked(&fscache_n_object_dead));
59830 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
59831 - atomic_read(&fscache_n_checkaux_none),
59832 - atomic_read(&fscache_n_checkaux_okay),
59833 - atomic_read(&fscache_n_checkaux_update),
59834 - atomic_read(&fscache_n_checkaux_obsolete));
59835 + atomic_read_unchecked(&fscache_n_checkaux_none),
59836 + atomic_read_unchecked(&fscache_n_checkaux_okay),
59837 + atomic_read_unchecked(&fscache_n_checkaux_update),
59838 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
59839
59840 seq_printf(m, "Pages : mrk=%u unc=%u\n",
59841 - atomic_read(&fscache_n_marks),
59842 - atomic_read(&fscache_n_uncaches));
59843 + atomic_read_unchecked(&fscache_n_marks),
59844 + atomic_read_unchecked(&fscache_n_uncaches));
59845
59846 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
59847 " oom=%u\n",
59848 - atomic_read(&fscache_n_acquires),
59849 - atomic_read(&fscache_n_acquires_null),
59850 - atomic_read(&fscache_n_acquires_no_cache),
59851 - atomic_read(&fscache_n_acquires_ok),
59852 - atomic_read(&fscache_n_acquires_nobufs),
59853 - atomic_read(&fscache_n_acquires_oom));
59854 + atomic_read_unchecked(&fscache_n_acquires),
59855 + atomic_read_unchecked(&fscache_n_acquires_null),
59856 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
59857 + atomic_read_unchecked(&fscache_n_acquires_ok),
59858 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
59859 + atomic_read_unchecked(&fscache_n_acquires_oom));
59860
59861 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
59862 - atomic_read(&fscache_n_object_lookups),
59863 - atomic_read(&fscache_n_object_lookups_negative),
59864 - atomic_read(&fscache_n_object_lookups_positive),
59865 - atomic_read(&fscache_n_object_created),
59866 - atomic_read(&fscache_n_object_lookups_timed_out));
59867 + atomic_read_unchecked(&fscache_n_object_lookups),
59868 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
59869 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
59870 + atomic_read_unchecked(&fscache_n_object_created),
59871 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
59872
59873 seq_printf(m, "Invals : n=%u run=%u\n",
59874 - atomic_read(&fscache_n_invalidates),
59875 - atomic_read(&fscache_n_invalidates_run));
59876 + atomic_read_unchecked(&fscache_n_invalidates),
59877 + atomic_read_unchecked(&fscache_n_invalidates_run));
59878
59879 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
59880 - atomic_read(&fscache_n_updates),
59881 - atomic_read(&fscache_n_updates_null),
59882 - atomic_read(&fscache_n_updates_run));
59883 + atomic_read_unchecked(&fscache_n_updates),
59884 + atomic_read_unchecked(&fscache_n_updates_null),
59885 + atomic_read_unchecked(&fscache_n_updates_run));
59886
59887 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
59888 - atomic_read(&fscache_n_relinquishes),
59889 - atomic_read(&fscache_n_relinquishes_null),
59890 - atomic_read(&fscache_n_relinquishes_waitcrt),
59891 - atomic_read(&fscache_n_relinquishes_retire));
59892 + atomic_read_unchecked(&fscache_n_relinquishes),
59893 + atomic_read_unchecked(&fscache_n_relinquishes_null),
59894 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
59895 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
59896
59897 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
59898 - atomic_read(&fscache_n_attr_changed),
59899 - atomic_read(&fscache_n_attr_changed_ok),
59900 - atomic_read(&fscache_n_attr_changed_nobufs),
59901 - atomic_read(&fscache_n_attr_changed_nomem),
59902 - atomic_read(&fscache_n_attr_changed_calls));
59903 + atomic_read_unchecked(&fscache_n_attr_changed),
59904 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
59905 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
59906 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
59907 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
59908
59909 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
59910 - atomic_read(&fscache_n_allocs),
59911 - atomic_read(&fscache_n_allocs_ok),
59912 - atomic_read(&fscache_n_allocs_wait),
59913 - atomic_read(&fscache_n_allocs_nobufs),
59914 - atomic_read(&fscache_n_allocs_intr));
59915 + atomic_read_unchecked(&fscache_n_allocs),
59916 + atomic_read_unchecked(&fscache_n_allocs_ok),
59917 + atomic_read_unchecked(&fscache_n_allocs_wait),
59918 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
59919 + atomic_read_unchecked(&fscache_n_allocs_intr));
59920 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
59921 - atomic_read(&fscache_n_alloc_ops),
59922 - atomic_read(&fscache_n_alloc_op_waits),
59923 - atomic_read(&fscache_n_allocs_object_dead));
59924 + atomic_read_unchecked(&fscache_n_alloc_ops),
59925 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
59926 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
59927
59928 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
59929 " int=%u oom=%u\n",
59930 - atomic_read(&fscache_n_retrievals),
59931 - atomic_read(&fscache_n_retrievals_ok),
59932 - atomic_read(&fscache_n_retrievals_wait),
59933 - atomic_read(&fscache_n_retrievals_nodata),
59934 - atomic_read(&fscache_n_retrievals_nobufs),
59935 - atomic_read(&fscache_n_retrievals_intr),
59936 - atomic_read(&fscache_n_retrievals_nomem));
59937 + atomic_read_unchecked(&fscache_n_retrievals),
59938 + atomic_read_unchecked(&fscache_n_retrievals_ok),
59939 + atomic_read_unchecked(&fscache_n_retrievals_wait),
59940 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
59941 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
59942 + atomic_read_unchecked(&fscache_n_retrievals_intr),
59943 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
59944 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
59945 - atomic_read(&fscache_n_retrieval_ops),
59946 - atomic_read(&fscache_n_retrieval_op_waits),
59947 - atomic_read(&fscache_n_retrievals_object_dead));
59948 + atomic_read_unchecked(&fscache_n_retrieval_ops),
59949 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
59950 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
59951
59952 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
59953 - atomic_read(&fscache_n_stores),
59954 - atomic_read(&fscache_n_stores_ok),
59955 - atomic_read(&fscache_n_stores_again),
59956 - atomic_read(&fscache_n_stores_nobufs),
59957 - atomic_read(&fscache_n_stores_oom));
59958 + atomic_read_unchecked(&fscache_n_stores),
59959 + atomic_read_unchecked(&fscache_n_stores_ok),
59960 + atomic_read_unchecked(&fscache_n_stores_again),
59961 + atomic_read_unchecked(&fscache_n_stores_nobufs),
59962 + atomic_read_unchecked(&fscache_n_stores_oom));
59963 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
59964 - atomic_read(&fscache_n_store_ops),
59965 - atomic_read(&fscache_n_store_calls),
59966 - atomic_read(&fscache_n_store_pages),
59967 - atomic_read(&fscache_n_store_radix_deletes),
59968 - atomic_read(&fscache_n_store_pages_over_limit));
59969 + atomic_read_unchecked(&fscache_n_store_ops),
59970 + atomic_read_unchecked(&fscache_n_store_calls),
59971 + atomic_read_unchecked(&fscache_n_store_pages),
59972 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
59973 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
59974
59975 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
59976 - atomic_read(&fscache_n_store_vmscan_not_storing),
59977 - atomic_read(&fscache_n_store_vmscan_gone),
59978 - atomic_read(&fscache_n_store_vmscan_busy),
59979 - atomic_read(&fscache_n_store_vmscan_cancelled),
59980 - atomic_read(&fscache_n_store_vmscan_wait));
59981 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
59982 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
59983 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
59984 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
59985 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
59986
59987 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
59988 - atomic_read(&fscache_n_op_pend),
59989 - atomic_read(&fscache_n_op_run),
59990 - atomic_read(&fscache_n_op_enqueue),
59991 - atomic_read(&fscache_n_op_cancelled),
59992 - atomic_read(&fscache_n_op_rejected));
59993 + atomic_read_unchecked(&fscache_n_op_pend),
59994 + atomic_read_unchecked(&fscache_n_op_run),
59995 + atomic_read_unchecked(&fscache_n_op_enqueue),
59996 + atomic_read_unchecked(&fscache_n_op_cancelled),
59997 + atomic_read_unchecked(&fscache_n_op_rejected));
59998 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
59999 - atomic_read(&fscache_n_op_deferred_release),
60000 - atomic_read(&fscache_n_op_release),
60001 - atomic_read(&fscache_n_op_gc));
60002 + atomic_read_unchecked(&fscache_n_op_deferred_release),
60003 + atomic_read_unchecked(&fscache_n_op_release),
60004 + atomic_read_unchecked(&fscache_n_op_gc));
60005
60006 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60007 atomic_read(&fscache_n_cop_alloc_object),
60008 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60009 index b96a49b..9bfdc47 100644
60010 --- a/fs/fuse/cuse.c
60011 +++ b/fs/fuse/cuse.c
60012 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
60013 INIT_LIST_HEAD(&cuse_conntbl[i]);
60014
60015 /* inherit and extend fuse_dev_operations */
60016 - cuse_channel_fops = fuse_dev_operations;
60017 - cuse_channel_fops.owner = THIS_MODULE;
60018 - cuse_channel_fops.open = cuse_channel_open;
60019 - cuse_channel_fops.release = cuse_channel_release;
60020 + pax_open_kernel();
60021 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60022 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60023 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
60024 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
60025 + pax_close_kernel();
60026
60027 cuse_class = class_create(THIS_MODULE, "cuse");
60028 if (IS_ERR(cuse_class))
60029 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60030 index ef74ad5..c9ac759e 100644
60031 --- a/fs/fuse/dev.c
60032 +++ b/fs/fuse/dev.c
60033 @@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60034 ret = 0;
60035 pipe_lock(pipe);
60036
60037 - if (!pipe->readers) {
60038 + if (!atomic_read(&pipe->readers)) {
60039 send_sig(SIGPIPE, current, 0);
60040 if (!ret)
60041 ret = -EPIPE;
60042 @@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60043 page_nr++;
60044 ret += buf->len;
60045
60046 - if (pipe->files)
60047 + if (atomic_read(&pipe->files))
60048 do_wakeup = 1;
60049 }
60050
60051 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60052 index c3eb2c4..98007d4 100644
60053 --- a/fs/fuse/dir.c
60054 +++ b/fs/fuse/dir.c
60055 @@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
60056 return link;
60057 }
60058
60059 -static void free_link(char *link)
60060 +static void free_link(const char *link)
60061 {
60062 if (!IS_ERR(link))
60063 free_page((unsigned long) link);
60064 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60065 index db23ce1..9e6cd9d 100644
60066 --- a/fs/hostfs/hostfs_kern.c
60067 +++ b/fs/hostfs/hostfs_kern.c
60068 @@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60069
60070 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60071 {
60072 - char *s = nd_get_link(nd);
60073 + const char *s = nd_get_link(nd);
60074 if (!IS_ERR(s))
60075 __putname(s);
60076 }
60077 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60078 index d19b30a..ef89c36 100644
60079 --- a/fs/hugetlbfs/inode.c
60080 +++ b/fs/hugetlbfs/inode.c
60081 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60082 struct mm_struct *mm = current->mm;
60083 struct vm_area_struct *vma;
60084 struct hstate *h = hstate_file(file);
60085 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60086 struct vm_unmapped_area_info info;
60087
60088 if (len & ~huge_page_mask(h))
60089 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60090 return addr;
60091 }
60092
60093 +#ifdef CONFIG_PAX_RANDMMAP
60094 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60095 +#endif
60096 +
60097 if (addr) {
60098 addr = ALIGN(addr, huge_page_size(h));
60099 vma = find_vma(mm, addr);
60100 - if (TASK_SIZE - len >= addr &&
60101 - (!vma || addr + len <= vma->vm_start))
60102 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
60103 return addr;
60104 }
60105
60106 info.flags = 0;
60107 info.length = len;
60108 info.low_limit = TASK_UNMAPPED_BASE;
60109 +
60110 +#ifdef CONFIG_PAX_RANDMMAP
60111 + if (mm->pax_flags & MF_PAX_RANDMMAP)
60112 + info.low_limit += mm->delta_mmap;
60113 +#endif
60114 +
60115 info.high_limit = TASK_SIZE;
60116 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60117 info.align_offset = 0;
60118 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60119 };
60120 MODULE_ALIAS_FS("hugetlbfs");
60121
60122 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60123 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60124
60125 static int can_do_hugetlb_shm(void)
60126 {
60127 diff --git a/fs/inode.c b/fs/inode.c
60128 index 4bcdad3..1883822 100644
60129 --- a/fs/inode.c
60130 +++ b/fs/inode.c
60131 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60132
60133 #ifdef CONFIG_SMP
60134 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60135 - static atomic_t shared_last_ino;
60136 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60137 + static atomic_unchecked_t shared_last_ino;
60138 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60139
60140 res = next - LAST_INO_BATCH;
60141 }
60142 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60143 index 4a6cf28..d3a29d3 100644
60144 --- a/fs/jffs2/erase.c
60145 +++ b/fs/jffs2/erase.c
60146 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60147 struct jffs2_unknown_node marker = {
60148 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60149 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60150 - .totlen = cpu_to_je32(c->cleanmarker_size)
60151 + .totlen = cpu_to_je32(c->cleanmarker_size),
60152 + .hdr_crc = cpu_to_je32(0)
60153 };
60154
60155 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60156 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60157 index a6597d6..41b30ec 100644
60158 --- a/fs/jffs2/wbuf.c
60159 +++ b/fs/jffs2/wbuf.c
60160 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60161 {
60162 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60163 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60164 - .totlen = constant_cpu_to_je32(8)
60165 + .totlen = constant_cpu_to_je32(8),
60166 + .hdr_crc = constant_cpu_to_je32(0)
60167 };
60168
60169 /*
60170 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60171 index 6669aa2..36b033d 100644
60172 --- a/fs/jfs/super.c
60173 +++ b/fs/jfs/super.c
60174 @@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
60175
60176 jfs_inode_cachep =
60177 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60178 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60179 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60180 init_once);
60181 if (jfs_inode_cachep == NULL)
60182 return -ENOMEM;
60183 diff --git a/fs/libfs.c b/fs/libfs.c
60184 index a184424..944ddce 100644
60185 --- a/fs/libfs.c
60186 +++ b/fs/libfs.c
60187 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60188
60189 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
60190 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
60191 + char d_name[sizeof(next->d_iname)];
60192 + const unsigned char *name;
60193 +
60194 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
60195 if (!simple_positive(next)) {
60196 spin_unlock(&next->d_lock);
60197 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60198
60199 spin_unlock(&next->d_lock);
60200 spin_unlock(&dentry->d_lock);
60201 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
60202 + name = next->d_name.name;
60203 + if (name == next->d_iname) {
60204 + memcpy(d_name, name, next->d_name.len);
60205 + name = d_name;
60206 + }
60207 + if (!dir_emit(ctx, name, next->d_name.len,
60208 next->d_inode->i_ino, dt_type(next->d_inode)))
60209 return 0;
60210 spin_lock(&dentry->d_lock);
60211 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
60212 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
60213 void *cookie)
60214 {
60215 - char *s = nd_get_link(nd);
60216 + const char *s = nd_get_link(nd);
60217 if (!IS_ERR(s))
60218 kfree(s);
60219 }
60220 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
60221 index acd3947..1f896e2 100644
60222 --- a/fs/lockd/clntproc.c
60223 +++ b/fs/lockd/clntproc.c
60224 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
60225 /*
60226 * Cookie counter for NLM requests
60227 */
60228 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
60229 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
60230
60231 void nlmclnt_next_cookie(struct nlm_cookie *c)
60232 {
60233 - u32 cookie = atomic_inc_return(&nlm_cookie);
60234 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
60235
60236 memcpy(c->data, &cookie, 4);
60237 c->len=4;
60238 diff --git a/fs/locks.c b/fs/locks.c
60239 index 92a0f0a..45a48f0 100644
60240 --- a/fs/locks.c
60241 +++ b/fs/locks.c
60242 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
60243 return;
60244
60245 if (filp->f_op->flock) {
60246 - struct file_lock fl = {
60247 + struct file_lock flock = {
60248 .fl_pid = current->tgid,
60249 .fl_file = filp,
60250 .fl_flags = FL_FLOCK,
60251 .fl_type = F_UNLCK,
60252 .fl_end = OFFSET_MAX,
60253 };
60254 - filp->f_op->flock(filp, F_SETLKW, &fl);
60255 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
60256 - fl.fl_ops->fl_release_private(&fl);
60257 + filp->f_op->flock(filp, F_SETLKW, &flock);
60258 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
60259 + flock.fl_ops->fl_release_private(&flock);
60260 }
60261
60262 spin_lock(&inode->i_lock);
60263 diff --git a/fs/mount.h b/fs/mount.h
60264 index a17458c..e69fb5b 100644
60265 --- a/fs/mount.h
60266 +++ b/fs/mount.h
60267 @@ -11,7 +11,7 @@ struct mnt_namespace {
60268 u64 seq; /* Sequence number to prevent loops */
60269 wait_queue_head_t poll;
60270 int event;
60271 -};
60272 +} __randomize_layout;
60273
60274 struct mnt_pcp {
60275 int mnt_count;
60276 @@ -57,7 +57,7 @@ struct mount {
60277 int mnt_expiry_mark; /* true if marked for expiry */
60278 int mnt_pinned;
60279 struct path mnt_ex_mountpoint;
60280 -};
60281 +} __randomize_layout;
60282
60283 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
60284
60285 diff --git a/fs/namei.c b/fs/namei.c
60286 index 3531dee..3177227 100644
60287 --- a/fs/namei.c
60288 +++ b/fs/namei.c
60289 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
60290 if (ret != -EACCES)
60291 return ret;
60292
60293 +#ifdef CONFIG_GRKERNSEC
60294 + /* we'll block if we have to log due to a denied capability use */
60295 + if (mask & MAY_NOT_BLOCK)
60296 + return -ECHILD;
60297 +#endif
60298 +
60299 if (S_ISDIR(inode->i_mode)) {
60300 /* DACs are overridable for directories */
60301 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
60302 - return 0;
60303 if (!(mask & MAY_WRITE))
60304 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60305 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60306 + inode_capable(inode, CAP_DAC_READ_SEARCH))
60307 return 0;
60308 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
60309 + return 0;
60310 return -EACCES;
60311 }
60312 /*
60313 + * Searching includes executable on directories, else just read.
60314 + */
60315 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60316 + if (mask == MAY_READ)
60317 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60318 + inode_capable(inode, CAP_DAC_READ_SEARCH))
60319 + return 0;
60320 +
60321 + /*
60322 * Read/write DACs are always overridable.
60323 * Executable DACs are overridable when there is
60324 * at least one exec bit set.
60325 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
60326 if (inode_capable(inode, CAP_DAC_OVERRIDE))
60327 return 0;
60328
60329 - /*
60330 - * Searching includes executable on directories, else just read.
60331 - */
60332 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60333 - if (mask == MAY_READ)
60334 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60335 - return 0;
60336 -
60337 return -EACCES;
60338 }
60339
60340 @@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60341 {
60342 struct dentry *dentry = link->dentry;
60343 int error;
60344 - char *s;
60345 + const char *s;
60346
60347 BUG_ON(nd->flags & LOOKUP_RCU);
60348
60349 @@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60350 if (error)
60351 goto out_put_nd_path;
60352
60353 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
60354 + dentry->d_inode, dentry, nd->path.mnt)) {
60355 + error = -EACCES;
60356 + goto out_put_nd_path;
60357 + }
60358 +
60359 nd->last_type = LAST_BIND;
60360 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
60361 error = PTR_ERR(*p);
60362 @@ -1582,6 +1596,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
60363 if (res)
60364 break;
60365 res = walk_component(nd, path, LOOKUP_FOLLOW);
60366 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
60367 + res = -EACCES;
60368 put_link(nd, &link, cookie);
60369 } while (res > 0);
60370
60371 @@ -1655,7 +1671,7 @@ EXPORT_SYMBOL(full_name_hash);
60372 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
60373 {
60374 unsigned long a, b, adata, bdata, mask, hash, len;
60375 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60376 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60377
60378 hash = a = 0;
60379 len = -sizeof(unsigned long);
60380 @@ -1939,6 +1955,8 @@ static int path_lookupat(int dfd, const char *name,
60381 if (err)
60382 break;
60383 err = lookup_last(nd, &path);
60384 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
60385 + err = -EACCES;
60386 put_link(nd, &link, cookie);
60387 }
60388 }
60389 @@ -1946,6 +1964,13 @@ static int path_lookupat(int dfd, const char *name,
60390 if (!err)
60391 err = complete_walk(nd);
60392
60393 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
60394 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60395 + path_put(&nd->path);
60396 + err = -ENOENT;
60397 + }
60398 + }
60399 +
60400 if (!err && nd->flags & LOOKUP_DIRECTORY) {
60401 if (!d_is_directory(nd->path.dentry)) {
60402 path_put(&nd->path);
60403 @@ -1973,8 +1998,15 @@ static int filename_lookup(int dfd, struct filename *name,
60404 retval = path_lookupat(dfd, name->name,
60405 flags | LOOKUP_REVAL, nd);
60406
60407 - if (likely(!retval))
60408 + if (likely(!retval)) {
60409 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
60410 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
60411 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
60412 + path_put(&nd->path);
60413 + return -ENOENT;
60414 + }
60415 + }
60416 + }
60417 return retval;
60418 }
60419
60420 @@ -2548,6 +2580,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
60421 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
60422 return -EPERM;
60423
60424 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
60425 + return -EPERM;
60426 + if (gr_handle_rawio(inode))
60427 + return -EPERM;
60428 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
60429 + return -EACCES;
60430 +
60431 return 0;
60432 }
60433
60434 @@ -2779,7 +2818,7 @@ looked_up:
60435 * cleared otherwise prior to returning.
60436 */
60437 static int lookup_open(struct nameidata *nd, struct path *path,
60438 - struct file *file,
60439 + struct path *link, struct file *file,
60440 const struct open_flags *op,
60441 bool got_write, int *opened)
60442 {
60443 @@ -2814,6 +2853,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60444 /* Negative dentry, just create the file */
60445 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
60446 umode_t mode = op->mode;
60447 +
60448 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
60449 + error = -EACCES;
60450 + goto out_dput;
60451 + }
60452 +
60453 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
60454 + error = -EACCES;
60455 + goto out_dput;
60456 + }
60457 +
60458 if (!IS_POSIXACL(dir->d_inode))
60459 mode &= ~current_umask();
60460 /*
60461 @@ -2835,6 +2885,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60462 nd->flags & LOOKUP_EXCL);
60463 if (error)
60464 goto out_dput;
60465 + else
60466 + gr_handle_create(dentry, nd->path.mnt);
60467 }
60468 out_no_open:
60469 path->dentry = dentry;
60470 @@ -2849,7 +2901,7 @@ out_dput:
60471 /*
60472 * Handle the last step of open()
60473 */
60474 -static int do_last(struct nameidata *nd, struct path *path,
60475 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
60476 struct file *file, const struct open_flags *op,
60477 int *opened, struct filename *name)
60478 {
60479 @@ -2899,6 +2951,15 @@ static int do_last(struct nameidata *nd, struct path *path,
60480 if (error)
60481 return error;
60482
60483 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
60484 + error = -ENOENT;
60485 + goto out;
60486 + }
60487 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
60488 + error = -EACCES;
60489 + goto out;
60490 + }
60491 +
60492 audit_inode(name, dir, LOOKUP_PARENT);
60493 error = -EISDIR;
60494 /* trailing slashes? */
60495 @@ -2918,7 +2979,7 @@ retry_lookup:
60496 */
60497 }
60498 mutex_lock(&dir->d_inode->i_mutex);
60499 - error = lookup_open(nd, path, file, op, got_write, opened);
60500 + error = lookup_open(nd, path, link, file, op, got_write, opened);
60501 mutex_unlock(&dir->d_inode->i_mutex);
60502
60503 if (error <= 0) {
60504 @@ -2942,11 +3003,28 @@ retry_lookup:
60505 goto finish_open_created;
60506 }
60507
60508 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
60509 + error = -ENOENT;
60510 + goto exit_dput;
60511 + }
60512 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
60513 + error = -EACCES;
60514 + goto exit_dput;
60515 + }
60516 +
60517 /*
60518 * create/update audit record if it already exists.
60519 */
60520 - if (d_is_positive(path->dentry))
60521 + if (d_is_positive(path->dentry)) {
60522 + /* only check if O_CREAT is specified, all other checks need to go
60523 + into may_open */
60524 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
60525 + error = -EACCES;
60526 + goto exit_dput;
60527 + }
60528 +
60529 audit_inode(name, path->dentry, 0);
60530 + }
60531
60532 /*
60533 * If atomic_open() acquired write access it is dropped now due to
60534 @@ -2987,6 +3065,11 @@ finish_lookup:
60535 }
60536 }
60537 BUG_ON(inode != path->dentry->d_inode);
60538 + /* if we're resolving a symlink to another symlink */
60539 + if (link && gr_handle_symlink_owner(link, inode)) {
60540 + error = -EACCES;
60541 + goto out;
60542 + }
60543 return 1;
60544 }
60545
60546 @@ -2996,7 +3079,6 @@ finish_lookup:
60547 save_parent.dentry = nd->path.dentry;
60548 save_parent.mnt = mntget(path->mnt);
60549 nd->path.dentry = path->dentry;
60550 -
60551 }
60552 nd->inode = inode;
60553 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
60554 @@ -3006,7 +3088,18 @@ finish_open:
60555 path_put(&save_parent);
60556 return error;
60557 }
60558 +
60559 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60560 + error = -ENOENT;
60561 + goto out;
60562 + }
60563 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
60564 + error = -EACCES;
60565 + goto out;
60566 + }
60567 +
60568 audit_inode(name, nd->path.dentry, 0);
60569 +
60570 error = -EISDIR;
60571 if ((open_flag & O_CREAT) &&
60572 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
60573 @@ -3170,7 +3263,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60574 if (unlikely(error))
60575 goto out;
60576
60577 - error = do_last(nd, &path, file, op, &opened, pathname);
60578 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
60579 while (unlikely(error > 0)) { /* trailing symlink */
60580 struct path link = path;
60581 void *cookie;
60582 @@ -3188,7 +3281,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60583 error = follow_link(&link, nd, &cookie);
60584 if (unlikely(error))
60585 break;
60586 - error = do_last(nd, &path, file, op, &opened, pathname);
60587 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
60588 put_link(nd, &link, cookie);
60589 }
60590 out:
60591 @@ -3288,9 +3381,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
60592 goto unlock;
60593
60594 error = -EEXIST;
60595 - if (d_is_positive(dentry))
60596 + if (d_is_positive(dentry)) {
60597 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
60598 + error = -ENOENT;
60599 goto fail;
60600 -
60601 + }
60602 /*
60603 * Special case - lookup gave negative, but... we had foo/bar/
60604 * From the vfs_mknod() POV we just have a negative dentry -
60605 @@ -3342,6 +3437,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
60606 }
60607 EXPORT_SYMBOL(user_path_create);
60608
60609 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
60610 +{
60611 + struct filename *tmp = getname(pathname);
60612 + struct dentry *res;
60613 + if (IS_ERR(tmp))
60614 + return ERR_CAST(tmp);
60615 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
60616 + if (IS_ERR(res))
60617 + putname(tmp);
60618 + else
60619 + *to = tmp;
60620 + return res;
60621 +}
60622 +
60623 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
60624 {
60625 int error = may_create(dir, dentry);
60626 @@ -3404,6 +3513,17 @@ retry:
60627
60628 if (!IS_POSIXACL(path.dentry->d_inode))
60629 mode &= ~current_umask();
60630 +
60631 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
60632 + error = -EPERM;
60633 + goto out;
60634 + }
60635 +
60636 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
60637 + error = -EACCES;
60638 + goto out;
60639 + }
60640 +
60641 error = security_path_mknod(&path, dentry, mode, dev);
60642 if (error)
60643 goto out;
60644 @@ -3420,6 +3540,8 @@ retry:
60645 break;
60646 }
60647 out:
60648 + if (!error)
60649 + gr_handle_create(dentry, path.mnt);
60650 done_path_create(&path, dentry);
60651 if (retry_estale(error, lookup_flags)) {
60652 lookup_flags |= LOOKUP_REVAL;
60653 @@ -3472,9 +3594,16 @@ retry:
60654
60655 if (!IS_POSIXACL(path.dentry->d_inode))
60656 mode &= ~current_umask();
60657 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
60658 + error = -EACCES;
60659 + goto out;
60660 + }
60661 error = security_path_mkdir(&path, dentry, mode);
60662 if (!error)
60663 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
60664 + if (!error)
60665 + gr_handle_create(dentry, path.mnt);
60666 +out:
60667 done_path_create(&path, dentry);
60668 if (retry_estale(error, lookup_flags)) {
60669 lookup_flags |= LOOKUP_REVAL;
60670 @@ -3555,6 +3684,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
60671 struct filename *name;
60672 struct dentry *dentry;
60673 struct nameidata nd;
60674 + ino_t saved_ino = 0;
60675 + dev_t saved_dev = 0;
60676 unsigned int lookup_flags = 0;
60677 retry:
60678 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60679 @@ -3587,10 +3718,21 @@ retry:
60680 error = -ENOENT;
60681 goto exit3;
60682 }
60683 +
60684 + saved_ino = dentry->d_inode->i_ino;
60685 + saved_dev = gr_get_dev_from_dentry(dentry);
60686 +
60687 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
60688 + error = -EACCES;
60689 + goto exit3;
60690 + }
60691 +
60692 error = security_path_rmdir(&nd.path, dentry);
60693 if (error)
60694 goto exit3;
60695 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
60696 + if (!error && (saved_dev || saved_ino))
60697 + gr_handle_delete(saved_ino, saved_dev);
60698 exit3:
60699 dput(dentry);
60700 exit2:
60701 @@ -3680,6 +3822,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
60702 struct nameidata nd;
60703 struct inode *inode = NULL;
60704 struct inode *delegated_inode = NULL;
60705 + ino_t saved_ino = 0;
60706 + dev_t saved_dev = 0;
60707 unsigned int lookup_flags = 0;
60708 retry:
60709 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60710 @@ -3706,10 +3850,22 @@ retry_deleg:
60711 if (d_is_negative(dentry))
60712 goto slashes;
60713 ihold(inode);
60714 +
60715 + if (inode->i_nlink <= 1) {
60716 + saved_ino = inode->i_ino;
60717 + saved_dev = gr_get_dev_from_dentry(dentry);
60718 + }
60719 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
60720 + error = -EACCES;
60721 + goto exit2;
60722 + }
60723 +
60724 error = security_path_unlink(&nd.path, dentry);
60725 if (error)
60726 goto exit2;
60727 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
60728 + if (!error && (saved_ino || saved_dev))
60729 + gr_handle_delete(saved_ino, saved_dev);
60730 exit2:
60731 dput(dentry);
60732 }
60733 @@ -3797,9 +3953,17 @@ retry:
60734 if (IS_ERR(dentry))
60735 goto out_putname;
60736
60737 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
60738 + error = -EACCES;
60739 + goto out;
60740 + }
60741 +
60742 error = security_path_symlink(&path, dentry, from->name);
60743 if (!error)
60744 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
60745 + if (!error)
60746 + gr_handle_create(dentry, path.mnt);
60747 +out:
60748 done_path_create(&path, dentry);
60749 if (retry_estale(error, lookup_flags)) {
60750 lookup_flags |= LOOKUP_REVAL;
60751 @@ -3902,6 +4066,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
60752 struct dentry *new_dentry;
60753 struct path old_path, new_path;
60754 struct inode *delegated_inode = NULL;
60755 + struct filename *to = NULL;
60756 int how = 0;
60757 int error;
60758
60759 @@ -3925,7 +4090,7 @@ retry:
60760 if (error)
60761 return error;
60762
60763 - new_dentry = user_path_create(newdfd, newname, &new_path,
60764 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
60765 (how & LOOKUP_REVAL));
60766 error = PTR_ERR(new_dentry);
60767 if (IS_ERR(new_dentry))
60768 @@ -3937,11 +4102,28 @@ retry:
60769 error = may_linkat(&old_path);
60770 if (unlikely(error))
60771 goto out_dput;
60772 +
60773 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
60774 + old_path.dentry->d_inode,
60775 + old_path.dentry->d_inode->i_mode, to)) {
60776 + error = -EACCES;
60777 + goto out_dput;
60778 + }
60779 +
60780 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
60781 + old_path.dentry, old_path.mnt, to)) {
60782 + error = -EACCES;
60783 + goto out_dput;
60784 + }
60785 +
60786 error = security_path_link(old_path.dentry, &new_path, new_dentry);
60787 if (error)
60788 goto out_dput;
60789 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
60790 + if (!error)
60791 + gr_handle_create(new_dentry, new_path.mnt);
60792 out_dput:
60793 + putname(to);
60794 done_path_create(&new_path, new_dentry);
60795 if (delegated_inode) {
60796 error = break_deleg_wait(&delegated_inode);
60797 @@ -4225,6 +4407,12 @@ retry_deleg:
60798 if (new_dentry == trap)
60799 goto exit5;
60800
60801 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
60802 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
60803 + to);
60804 + if (error)
60805 + goto exit5;
60806 +
60807 error = security_path_rename(&oldnd.path, old_dentry,
60808 &newnd.path, new_dentry);
60809 if (error)
60810 @@ -4232,6 +4420,9 @@ retry_deleg:
60811 error = vfs_rename(old_dir->d_inode, old_dentry,
60812 new_dir->d_inode, new_dentry,
60813 &delegated_inode);
60814 + if (!error)
60815 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
60816 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
60817 exit5:
60818 dput(new_dentry);
60819 exit4:
60820 @@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
60821
60822 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
60823 {
60824 + char tmpbuf[64];
60825 + const char *newlink;
60826 int len;
60827
60828 len = PTR_ERR(link);
60829 @@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
60830 len = strlen(link);
60831 if (len > (unsigned) buflen)
60832 len = buflen;
60833 - if (copy_to_user(buffer, link, len))
60834 +
60835 + if (len < sizeof(tmpbuf)) {
60836 + memcpy(tmpbuf, link, len);
60837 + newlink = tmpbuf;
60838 + } else
60839 + newlink = link;
60840 +
60841 + if (copy_to_user(buffer, newlink, len))
60842 len = -EFAULT;
60843 out:
60844 return len;
60845 diff --git a/fs/namespace.c b/fs/namespace.c
60846 index be32ebc..c595734 100644
60847 --- a/fs/namespace.c
60848 +++ b/fs/namespace.c
60849 @@ -1293,6 +1293,9 @@ static int do_umount(struct mount *mnt, int flags)
60850 if (!(sb->s_flags & MS_RDONLY))
60851 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
60852 up_write(&sb->s_umount);
60853 +
60854 + gr_log_remount(mnt->mnt_devname, retval);
60855 +
60856 return retval;
60857 }
60858
60859 @@ -1315,6 +1318,9 @@ static int do_umount(struct mount *mnt, int flags)
60860 }
60861 unlock_mount_hash();
60862 namespace_unlock();
60863 +
60864 + gr_log_unmount(mnt->mnt_devname, retval);
60865 +
60866 return retval;
60867 }
60868
60869 @@ -1334,7 +1340,7 @@ static inline bool may_mount(void)
60870 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
60871 */
60872
60873 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
60874 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
60875 {
60876 struct path path;
60877 struct mount *mnt;
60878 @@ -1376,7 +1382,7 @@ out:
60879 /*
60880 * The 2.0 compatible umount. No flags.
60881 */
60882 -SYSCALL_DEFINE1(oldumount, char __user *, name)
60883 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
60884 {
60885 return sys_umount(name, 0);
60886 }
60887 @@ -2379,6 +2385,16 @@ long do_mount(const char *dev_name, const char *dir_name,
60888 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
60889 MS_STRICTATIME);
60890
60891 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
60892 + retval = -EPERM;
60893 + goto dput_out;
60894 + }
60895 +
60896 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
60897 + retval = -EPERM;
60898 + goto dput_out;
60899 + }
60900 +
60901 if (flags & MS_REMOUNT)
60902 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
60903 data_page);
60904 @@ -2393,6 +2409,9 @@ long do_mount(const char *dev_name, const char *dir_name,
60905 dev_name, data_page);
60906 dput_out:
60907 path_put(&path);
60908 +
60909 + gr_log_mount(dev_name, dir_name, retval);
60910 +
60911 return retval;
60912 }
60913
60914 @@ -2410,7 +2429,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
60915 * number incrementing at 10Ghz will take 12,427 years to wrap which
60916 * is effectively never, so we can ignore the possibility.
60917 */
60918 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
60919 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
60920
60921 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60922 {
60923 @@ -2425,7 +2444,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60924 kfree(new_ns);
60925 return ERR_PTR(ret);
60926 }
60927 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
60928 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
60929 atomic_set(&new_ns->count, 1);
60930 new_ns->root = NULL;
60931 INIT_LIST_HEAD(&new_ns->list);
60932 @@ -2435,7 +2454,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60933 return new_ns;
60934 }
60935
60936 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60937 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60938 struct user_namespace *user_ns, struct fs_struct *new_fs)
60939 {
60940 struct mnt_namespace *new_ns;
60941 @@ -2556,8 +2575,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
60942 }
60943 EXPORT_SYMBOL(mount_subtree);
60944
60945 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
60946 - char __user *, type, unsigned long, flags, void __user *, data)
60947 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
60948 + const char __user *, type, unsigned long, flags, void __user *, data)
60949 {
60950 int ret;
60951 char *kernel_type;
60952 @@ -2670,6 +2689,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
60953 if (error)
60954 goto out2;
60955
60956 + if (gr_handle_chroot_pivot()) {
60957 + error = -EPERM;
60958 + goto out2;
60959 + }
60960 +
60961 get_fs_root(current->fs, &root);
60962 old_mp = lock_mount(&old);
60963 error = PTR_ERR(old_mp);
60964 @@ -2930,7 +2954,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
60965 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
60966 return -EPERM;
60967
60968 - if (fs->users != 1)
60969 + if (atomic_read(&fs->users) != 1)
60970 return -EINVAL;
60971
60972 get_mnt_ns(mnt_ns);
60973 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
60974 index f4ccfe6..a5cf064 100644
60975 --- a/fs/nfs/callback_xdr.c
60976 +++ b/fs/nfs/callback_xdr.c
60977 @@ -51,7 +51,7 @@ struct callback_op {
60978 callback_decode_arg_t decode_args;
60979 callback_encode_res_t encode_res;
60980 long res_maxsize;
60981 -};
60982 +} __do_const;
60983
60984 static struct callback_op callback_ops[];
60985
60986 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
60987 index 00ad1c2..2fde15e 100644
60988 --- a/fs/nfs/inode.c
60989 +++ b/fs/nfs/inode.c
60990 @@ -1146,16 +1146,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
60991 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
60992 }
60993
60994 -static atomic_long_t nfs_attr_generation_counter;
60995 +static atomic_long_unchecked_t nfs_attr_generation_counter;
60996
60997 static unsigned long nfs_read_attr_generation_counter(void)
60998 {
60999 - return atomic_long_read(&nfs_attr_generation_counter);
61000 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61001 }
61002
61003 unsigned long nfs_inc_attr_generation_counter(void)
61004 {
61005 - return atomic_long_inc_return(&nfs_attr_generation_counter);
61006 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61007 }
61008
61009 void nfs_fattr_init(struct nfs_fattr *fattr)
61010 diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
61011 index b4a160a..2b9bfba 100644
61012 --- a/fs/nfs/nfs4client.c
61013 +++ b/fs/nfs/nfs4client.c
61014 @@ -409,13 +409,11 @@ struct nfs_client *nfs4_init_client(struct nfs_client *clp,
61015 error = nfs4_discover_server_trunking(clp, &old);
61016 if (error < 0)
61017 goto error;
61018 - nfs_put_client(clp);
61019 - if (clp != old) {
61020 +
61021 + if (clp != old)
61022 clp->cl_preserve_clid = true;
61023 - clp = old;
61024 - }
61025 -
61026 - return clp;
61027 + nfs_put_client(clp);
61028 + return old;
61029
61030 error:
61031 nfs_mark_client_ready(clp, error);
61032 @@ -493,9 +491,10 @@ int nfs40_walk_client_list(struct nfs_client *new,
61033 prev = pos;
61034
61035 status = nfs_wait_client_init_complete(pos);
61036 - spin_lock(&nn->nfs_client_lock);
61037 if (status < 0)
61038 - continue;
61039 + goto out;
61040 + status = -NFS4ERR_STALE_CLIENTID;
61041 + spin_lock(&nn->nfs_client_lock);
61042 }
61043 if (pos->cl_cons_state != NFS_CS_READY)
61044 continue;
61045 @@ -633,7 +632,8 @@ int nfs41_walk_client_list(struct nfs_client *new,
61046 }
61047 spin_lock(&nn->nfs_client_lock);
61048 if (status < 0)
61049 - continue;
61050 + break;
61051 + status = -NFS4ERR_STALE_CLIENTID;
61052 }
61053 if (pos->cl_cons_state != NFS_CS_READY)
61054 continue;
61055 diff --git a/fs/nfs/write.c b/fs/nfs/write.c
61056 index c1d5482..6a85038 100644
61057 --- a/fs/nfs/write.c
61058 +++ b/fs/nfs/write.c
61059 @@ -922,19 +922,20 @@ out:
61060 * extend the write to cover the entire page in order to avoid fragmentation
61061 * inefficiencies.
61062 *
61063 - * If the file is opened for synchronous writes or if we have a write delegation
61064 - * from the server then we can just skip the rest of the checks.
61065 + * If the file is opened for synchronous writes then we can just skip the rest
61066 + * of the checks.
61067 */
61068 static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode)
61069 {
61070 if (file->f_flags & O_DSYNC)
61071 return 0;
61072 + if (!nfs_write_pageuptodate(page, inode))
61073 + return 0;
61074 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
61075 return 1;
61076 - if (nfs_write_pageuptodate(page, inode) && (inode->i_flock == NULL ||
61077 - (inode->i_flock->fl_start == 0 &&
61078 + if (inode->i_flock == NULL || (inode->i_flock->fl_start == 0 &&
61079 inode->i_flock->fl_end == OFFSET_MAX &&
61080 - inode->i_flock->fl_type != F_RDLCK)))
61081 + inode->i_flock->fl_type != F_RDLCK))
61082 return 1;
61083 return 0;
61084 }
61085 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61086 index 419572f..5414a23 100644
61087 --- a/fs/nfsd/nfs4proc.c
61088 +++ b/fs/nfsd/nfs4proc.c
61089 @@ -1168,7 +1168,7 @@ struct nfsd4_operation {
61090 nfsd4op_rsize op_rsize_bop;
61091 stateid_getter op_get_currentstateid;
61092 stateid_setter op_set_currentstateid;
61093 -};
61094 +} __do_const;
61095
61096 static struct nfsd4_operation nfsd4_ops[];
61097
61098 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61099 index ee7237f..e3ae60a 100644
61100 --- a/fs/nfsd/nfs4xdr.c
61101 +++ b/fs/nfsd/nfs4xdr.c
61102 @@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61103
61104 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61105
61106 -static nfsd4_dec nfsd4_dec_ops[] = {
61107 +static const nfsd4_dec nfsd4_dec_ops[] = {
61108 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61109 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61110 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61111 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61112 index b6af150..f6ec5e3 100644
61113 --- a/fs/nfsd/nfscache.c
61114 +++ b/fs/nfsd/nfscache.c
61115 @@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61116 {
61117 struct svc_cacherep *rp = rqstp->rq_cacherep;
61118 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61119 - int len;
61120 + long len;
61121 size_t bufsize = 0;
61122
61123 if (!rp)
61124 return;
61125
61126 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61127 - len >>= 2;
61128 + if (statp) {
61129 + len = (char*)statp - (char*)resv->iov_base;
61130 + len = resv->iov_len - len;
61131 + len >>= 2;
61132 + }
61133
61134 /* Don't cache excessive amounts of data and XDR failures */
61135 if (!statp || len > (256 >> 2)) {
61136 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61137 index 7eea63c..a35f4fb 100644
61138 --- a/fs/nfsd/vfs.c
61139 +++ b/fs/nfsd/vfs.c
61140 @@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61141 } else {
61142 oldfs = get_fs();
61143 set_fs(KERNEL_DS);
61144 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61145 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61146 set_fs(oldfs);
61147 }
61148
61149 @@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61150
61151 /* Write the data. */
61152 oldfs = get_fs(); set_fs(KERNEL_DS);
61153 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61154 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61155 set_fs(oldfs);
61156 if (host_err < 0)
61157 goto out_nfserr;
61158 @@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61159 */
61160
61161 oldfs = get_fs(); set_fs(KERNEL_DS);
61162 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61163 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61164 set_fs(oldfs);
61165
61166 if (host_err < 0)
61167 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61168 index fea6bd5..8ee9d81 100644
61169 --- a/fs/nls/nls_base.c
61170 +++ b/fs/nls/nls_base.c
61171 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61172
61173 int register_nls(struct nls_table * nls)
61174 {
61175 - struct nls_table ** tmp = &tables;
61176 + struct nls_table *tmp = tables;
61177
61178 if (nls->next)
61179 return -EBUSY;
61180
61181 spin_lock(&nls_lock);
61182 - while (*tmp) {
61183 - if (nls == *tmp) {
61184 + while (tmp) {
61185 + if (nls == tmp) {
61186 spin_unlock(&nls_lock);
61187 return -EBUSY;
61188 }
61189 - tmp = &(*tmp)->next;
61190 + tmp = tmp->next;
61191 }
61192 - nls->next = tables;
61193 + pax_open_kernel();
61194 + *(struct nls_table **)&nls->next = tables;
61195 + pax_close_kernel();
61196 tables = nls;
61197 spin_unlock(&nls_lock);
61198 return 0;
61199 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
61200
61201 int unregister_nls(struct nls_table * nls)
61202 {
61203 - struct nls_table ** tmp = &tables;
61204 + struct nls_table * const * tmp = &tables;
61205
61206 spin_lock(&nls_lock);
61207 while (*tmp) {
61208 if (nls == *tmp) {
61209 - *tmp = nls->next;
61210 + pax_open_kernel();
61211 + *(struct nls_table **)tmp = nls->next;
61212 + pax_close_kernel();
61213 spin_unlock(&nls_lock);
61214 return 0;
61215 }
61216 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
61217 index 7424929..35f6be5 100644
61218 --- a/fs/nls/nls_euc-jp.c
61219 +++ b/fs/nls/nls_euc-jp.c
61220 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
61221 p_nls = load_nls("cp932");
61222
61223 if (p_nls) {
61224 - table.charset2upper = p_nls->charset2upper;
61225 - table.charset2lower = p_nls->charset2lower;
61226 + pax_open_kernel();
61227 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61228 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61229 + pax_close_kernel();
61230 return register_nls(&table);
61231 }
61232
61233 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
61234 index e7bc1d7..06bd4bb 100644
61235 --- a/fs/nls/nls_koi8-ru.c
61236 +++ b/fs/nls/nls_koi8-ru.c
61237 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
61238 p_nls = load_nls("koi8-u");
61239
61240 if (p_nls) {
61241 - table.charset2upper = p_nls->charset2upper;
61242 - table.charset2lower = p_nls->charset2lower;
61243 + pax_open_kernel();
61244 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61245 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61246 + pax_close_kernel();
61247 return register_nls(&table);
61248 }
61249
61250 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
61251 index e44cb64..7668ca4 100644
61252 --- a/fs/notify/fanotify/fanotify_user.c
61253 +++ b/fs/notify/fanotify/fanotify_user.c
61254 @@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
61255
61256 fd = fanotify_event_metadata.fd;
61257 ret = -EFAULT;
61258 - if (copy_to_user(buf, &fanotify_event_metadata,
61259 - fanotify_event_metadata.event_len))
61260 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
61261 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
61262 goto out_close_fd;
61263
61264 ret = prepare_for_access_response(group, event, fd);
61265 @@ -888,9 +888,9 @@ COMPAT_SYSCALL_DEFINE6(fanotify_mark,
61266 {
61267 return sys_fanotify_mark(fanotify_fd, flags,
61268 #ifdef __BIG_ENDIAN
61269 - ((__u64)mask1 << 32) | mask0,
61270 -#else
61271 ((__u64)mask0 << 32) | mask1,
61272 +#else
61273 + ((__u64)mask1 << 32) | mask0,
61274 #endif
61275 dfd, pathname);
61276 }
61277 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
61278 index 7b51b05..5ea5ef6 100644
61279 --- a/fs/notify/notification.c
61280 +++ b/fs/notify/notification.c
61281 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
61282 * get set to 0 so it will never get 'freed'
61283 */
61284 static struct fsnotify_event *q_overflow_event;
61285 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61286 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61287
61288 /**
61289 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
61290 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61291 */
61292 u32 fsnotify_get_cookie(void)
61293 {
61294 - return atomic_inc_return(&fsnotify_sync_cookie);
61295 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
61296 }
61297 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
61298
61299 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
61300 index 9e38daf..5727cae 100644
61301 --- a/fs/ntfs/dir.c
61302 +++ b/fs/ntfs/dir.c
61303 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
61304 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
61305 ~(s64)(ndir->itype.index.block_size - 1)));
61306 /* Bounds checks. */
61307 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61308 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61309 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
61310 "inode 0x%lx or driver bug.", vdir->i_ino);
61311 goto err_out;
61312 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
61313 index ea4ba9d..1e13d34 100644
61314 --- a/fs/ntfs/file.c
61315 +++ b/fs/ntfs/file.c
61316 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
61317 char *addr;
61318 size_t total = 0;
61319 unsigned len;
61320 - int left;
61321 + unsigned left;
61322
61323 do {
61324 len = PAGE_CACHE_SIZE - ofs;
61325 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
61326 index 82650d5..db37dcf 100644
61327 --- a/fs/ntfs/super.c
61328 +++ b/fs/ntfs/super.c
61329 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61330 if (!silent)
61331 ntfs_error(sb, "Primary boot sector is invalid.");
61332 } else if (!silent)
61333 - ntfs_error(sb, read_err_str, "primary");
61334 + ntfs_error(sb, read_err_str, "%s", "primary");
61335 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
61336 if (bh_primary)
61337 brelse(bh_primary);
61338 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61339 goto hotfix_primary_boot_sector;
61340 brelse(bh_backup);
61341 } else if (!silent)
61342 - ntfs_error(sb, read_err_str, "backup");
61343 + ntfs_error(sb, read_err_str, "%s", "backup");
61344 /* Try to read NT3.51- backup boot sector. */
61345 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
61346 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
61347 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61348 "sector.");
61349 brelse(bh_backup);
61350 } else if (!silent)
61351 - ntfs_error(sb, read_err_str, "backup");
61352 + ntfs_error(sb, read_err_str, "%s", "backup");
61353 /* We failed. Cleanup and return. */
61354 if (bh_primary)
61355 brelse(bh_primary);
61356 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
61357 index cd5496b..26a1055 100644
61358 --- a/fs/ocfs2/localalloc.c
61359 +++ b/fs/ocfs2/localalloc.c
61360 @@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
61361 goto bail;
61362 }
61363
61364 - atomic_inc(&osb->alloc_stats.moves);
61365 + atomic_inc_unchecked(&osb->alloc_stats.moves);
61366
61367 bail:
61368 if (handle)
61369 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
61370 index 3a90347..c40bef8 100644
61371 --- a/fs/ocfs2/ocfs2.h
61372 +++ b/fs/ocfs2/ocfs2.h
61373 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
61374
61375 struct ocfs2_alloc_stats
61376 {
61377 - atomic_t moves;
61378 - atomic_t local_data;
61379 - atomic_t bitmap_data;
61380 - atomic_t bg_allocs;
61381 - atomic_t bg_extends;
61382 + atomic_unchecked_t moves;
61383 + atomic_unchecked_t local_data;
61384 + atomic_unchecked_t bitmap_data;
61385 + atomic_unchecked_t bg_allocs;
61386 + atomic_unchecked_t bg_extends;
61387 };
61388
61389 enum ocfs2_local_alloc_state
61390 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
61391 index 2c91452..77a3cd2 100644
61392 --- a/fs/ocfs2/suballoc.c
61393 +++ b/fs/ocfs2/suballoc.c
61394 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
61395 mlog_errno(status);
61396 goto bail;
61397 }
61398 - atomic_inc(&osb->alloc_stats.bg_extends);
61399 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
61400
61401 /* You should never ask for this much metadata */
61402 BUG_ON(bits_wanted >
61403 @@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
61404 mlog_errno(status);
61405 goto bail;
61406 }
61407 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61408 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61409
61410 *suballoc_loc = res.sr_bg_blkno;
61411 *suballoc_bit_start = res.sr_bit_offset;
61412 @@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
61413 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
61414 res->sr_bits);
61415
61416 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61417 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61418
61419 BUG_ON(res->sr_bits != 1);
61420
61421 @@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
61422 mlog_errno(status);
61423 goto bail;
61424 }
61425 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61426 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61427
61428 BUG_ON(res.sr_bits != 1);
61429
61430 @@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61431 cluster_start,
61432 num_clusters);
61433 if (!status)
61434 - atomic_inc(&osb->alloc_stats.local_data);
61435 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
61436 } else {
61437 if (min_clusters > (osb->bitmap_cpg - 1)) {
61438 /* The only paths asking for contiguousness
61439 @@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61440 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
61441 res.sr_bg_blkno,
61442 res.sr_bit_offset);
61443 - atomic_inc(&osb->alloc_stats.bitmap_data);
61444 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
61445 *num_clusters = res.sr_bits;
61446 }
61447 }
61448 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
61449 index c414929..5c9ee542 100644
61450 --- a/fs/ocfs2/super.c
61451 +++ b/fs/ocfs2/super.c
61452 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
61453 "%10s => GlobalAllocs: %d LocalAllocs: %d "
61454 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
61455 "Stats",
61456 - atomic_read(&osb->alloc_stats.bitmap_data),
61457 - atomic_read(&osb->alloc_stats.local_data),
61458 - atomic_read(&osb->alloc_stats.bg_allocs),
61459 - atomic_read(&osb->alloc_stats.moves),
61460 - atomic_read(&osb->alloc_stats.bg_extends));
61461 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
61462 + atomic_read_unchecked(&osb->alloc_stats.local_data),
61463 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
61464 + atomic_read_unchecked(&osb->alloc_stats.moves),
61465 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
61466
61467 out += snprintf(buf + out, len - out,
61468 "%10s => State: %u Descriptor: %llu Size: %u bits "
61469 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
61470 spin_lock_init(&osb->osb_xattr_lock);
61471 ocfs2_init_steal_slots(osb);
61472
61473 - atomic_set(&osb->alloc_stats.moves, 0);
61474 - atomic_set(&osb->alloc_stats.local_data, 0);
61475 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
61476 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
61477 - atomic_set(&osb->alloc_stats.bg_extends, 0);
61478 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
61479 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
61480 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
61481 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
61482 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
61483
61484 /* Copy the blockcheck stats from the superblock probe */
61485 osb->osb_ecc_stats = *stats;
61486 diff --git a/fs/open.c b/fs/open.c
61487 index 4b3e1ed..1c84599 100644
61488 --- a/fs/open.c
61489 +++ b/fs/open.c
61490 @@ -32,6 +32,8 @@
61491 #include <linux/dnotify.h>
61492 #include <linux/compat.h>
61493
61494 +#define CREATE_TRACE_POINTS
61495 +#include <trace/events/fs.h>
61496 #include "internal.h"
61497
61498 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
61499 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
61500 error = locks_verify_truncate(inode, NULL, length);
61501 if (!error)
61502 error = security_path_truncate(path);
61503 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
61504 + error = -EACCES;
61505 if (!error)
61506 error = do_truncate(path->dentry, length, 0, NULL);
61507
61508 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
61509 error = locks_verify_truncate(inode, f.file, length);
61510 if (!error)
61511 error = security_path_truncate(&f.file->f_path);
61512 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
61513 + error = -EACCES;
61514 if (!error)
61515 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
61516 sb_end_write(inode->i_sb);
61517 @@ -361,6 +367,9 @@ retry:
61518 if (__mnt_is_readonly(path.mnt))
61519 res = -EROFS;
61520
61521 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
61522 + res = -EACCES;
61523 +
61524 out_path_release:
61525 path_put(&path);
61526 if (retry_estale(res, lookup_flags)) {
61527 @@ -392,6 +401,8 @@ retry:
61528 if (error)
61529 goto dput_and_out;
61530
61531 + gr_log_chdir(path.dentry, path.mnt);
61532 +
61533 set_fs_pwd(current->fs, &path);
61534
61535 dput_and_out:
61536 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
61537 goto out_putf;
61538
61539 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
61540 +
61541 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
61542 + error = -EPERM;
61543 +
61544 + if (!error)
61545 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
61546 +
61547 if (!error)
61548 set_fs_pwd(current->fs, &f.file->f_path);
61549 out_putf:
61550 @@ -450,7 +468,13 @@ retry:
61551 if (error)
61552 goto dput_and_out;
61553
61554 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
61555 + goto dput_and_out;
61556 +
61557 set_fs_root(current->fs, &path);
61558 +
61559 + gr_handle_chroot_chdir(&path);
61560 +
61561 error = 0;
61562 dput_and_out:
61563 path_put(&path);
61564 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
61565 return error;
61566 retry_deleg:
61567 mutex_lock(&inode->i_mutex);
61568 +
61569 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
61570 + error = -EACCES;
61571 + goto out_unlock;
61572 + }
61573 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
61574 + error = -EACCES;
61575 + goto out_unlock;
61576 + }
61577 +
61578 error = security_path_chmod(path, mode);
61579 if (error)
61580 goto out_unlock;
61581 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
61582 uid = make_kuid(current_user_ns(), user);
61583 gid = make_kgid(current_user_ns(), group);
61584
61585 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
61586 + return -EACCES;
61587 +
61588 newattrs.ia_valid = ATTR_CTIME;
61589 if (user != (uid_t) -1) {
61590 if (!uid_valid(uid))
61591 @@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
61592 } else {
61593 fsnotify_open(f);
61594 fd_install(fd, f);
61595 + trace_do_sys_open(tmp->name, flags, mode);
61596 }
61597 }
61598 putname(tmp);
61599 diff --git a/fs/pipe.c b/fs/pipe.c
61600 index 0e0752e..7cfdd50 100644
61601 --- a/fs/pipe.c
61602 +++ b/fs/pipe.c
61603 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
61604
61605 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
61606 {
61607 - if (pipe->files)
61608 + if (atomic_read(&pipe->files))
61609 mutex_lock_nested(&pipe->mutex, subclass);
61610 }
61611
61612 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
61613
61614 void pipe_unlock(struct pipe_inode_info *pipe)
61615 {
61616 - if (pipe->files)
61617 + if (atomic_read(&pipe->files))
61618 mutex_unlock(&pipe->mutex);
61619 }
61620 EXPORT_SYMBOL(pipe_unlock);
61621 @@ -449,9 +449,9 @@ redo:
61622 }
61623 if (bufs) /* More to do? */
61624 continue;
61625 - if (!pipe->writers)
61626 + if (!atomic_read(&pipe->writers))
61627 break;
61628 - if (!pipe->waiting_writers) {
61629 + if (!atomic_read(&pipe->waiting_writers)) {
61630 /* syscall merging: Usually we must not sleep
61631 * if O_NONBLOCK is set, or if we got some data.
61632 * But if a writer sleeps in kernel space, then
61633 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
61634 ret = 0;
61635 __pipe_lock(pipe);
61636
61637 - if (!pipe->readers) {
61638 + if (!atomic_read(&pipe->readers)) {
61639 send_sig(SIGPIPE, current, 0);
61640 ret = -EPIPE;
61641 goto out;
61642 @@ -562,7 +562,7 @@ redo1:
61643 for (;;) {
61644 int bufs;
61645
61646 - if (!pipe->readers) {
61647 + if (!atomic_read(&pipe->readers)) {
61648 send_sig(SIGPIPE, current, 0);
61649 if (!ret)
61650 ret = -EPIPE;
61651 @@ -653,9 +653,9 @@ redo2:
61652 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61653 do_wakeup = 0;
61654 }
61655 - pipe->waiting_writers++;
61656 + atomic_inc(&pipe->waiting_writers);
61657 pipe_wait(pipe);
61658 - pipe->waiting_writers--;
61659 + atomic_dec(&pipe->waiting_writers);
61660 }
61661 out:
61662 __pipe_unlock(pipe);
61663 @@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61664 mask = 0;
61665 if (filp->f_mode & FMODE_READ) {
61666 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
61667 - if (!pipe->writers && filp->f_version != pipe->w_counter)
61668 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
61669 mask |= POLLHUP;
61670 }
61671
61672 @@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61673 * Most Unices do not set POLLERR for FIFOs but on Linux they
61674 * behave exactly like pipes for poll().
61675 */
61676 - if (!pipe->readers)
61677 + if (!atomic_read(&pipe->readers))
61678 mask |= POLLERR;
61679 }
61680
61681 @@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
61682 int kill = 0;
61683
61684 spin_lock(&inode->i_lock);
61685 - if (!--pipe->files) {
61686 + if (atomic_dec_and_test(&pipe->files)) {
61687 inode->i_pipe = NULL;
61688 kill = 1;
61689 }
61690 @@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
61691
61692 __pipe_lock(pipe);
61693 if (file->f_mode & FMODE_READ)
61694 - pipe->readers--;
61695 + atomic_dec(&pipe->readers);
61696 if (file->f_mode & FMODE_WRITE)
61697 - pipe->writers--;
61698 + atomic_dec(&pipe->writers);
61699
61700 - if (pipe->readers || pipe->writers) {
61701 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
61702 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
61703 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61704 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
61705 @@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
61706 kfree(pipe);
61707 }
61708
61709 -static struct vfsmount *pipe_mnt __read_mostly;
61710 +struct vfsmount *pipe_mnt __read_mostly;
61711
61712 /*
61713 * pipefs_dname() is called from d_path().
61714 @@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
61715 goto fail_iput;
61716
61717 inode->i_pipe = pipe;
61718 - pipe->files = 2;
61719 - pipe->readers = pipe->writers = 1;
61720 + atomic_set(&pipe->files, 2);
61721 + atomic_set(&pipe->readers, 1);
61722 + atomic_set(&pipe->writers, 1);
61723 inode->i_fop = &pipefifo_fops;
61724
61725 /*
61726 @@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
61727 spin_lock(&inode->i_lock);
61728 if (inode->i_pipe) {
61729 pipe = inode->i_pipe;
61730 - pipe->files++;
61731 + atomic_inc(&pipe->files);
61732 spin_unlock(&inode->i_lock);
61733 } else {
61734 spin_unlock(&inode->i_lock);
61735 pipe = alloc_pipe_info();
61736 if (!pipe)
61737 return -ENOMEM;
61738 - pipe->files = 1;
61739 + atomic_set(&pipe->files, 1);
61740 spin_lock(&inode->i_lock);
61741 if (unlikely(inode->i_pipe)) {
61742 - inode->i_pipe->files++;
61743 + atomic_inc(&inode->i_pipe->files);
61744 spin_unlock(&inode->i_lock);
61745 free_pipe_info(pipe);
61746 pipe = inode->i_pipe;
61747 @@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
61748 * opened, even when there is no process writing the FIFO.
61749 */
61750 pipe->r_counter++;
61751 - if (pipe->readers++ == 0)
61752 + if (atomic_inc_return(&pipe->readers) == 1)
61753 wake_up_partner(pipe);
61754
61755 - if (!is_pipe && !pipe->writers) {
61756 + if (!is_pipe && !atomic_read(&pipe->writers)) {
61757 if ((filp->f_flags & O_NONBLOCK)) {
61758 /* suppress POLLHUP until we have
61759 * seen a writer */
61760 @@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
61761 * errno=ENXIO when there is no process reading the FIFO.
61762 */
61763 ret = -ENXIO;
61764 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
61765 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
61766 goto err;
61767
61768 pipe->w_counter++;
61769 - if (!pipe->writers++)
61770 + if (atomic_inc_return(&pipe->writers) == 1)
61771 wake_up_partner(pipe);
61772
61773 - if (!is_pipe && !pipe->readers) {
61774 + if (!is_pipe && !atomic_read(&pipe->readers)) {
61775 if (wait_for_partner(pipe, &pipe->r_counter))
61776 goto err_wr;
61777 }
61778 @@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
61779 * the process can at least talk to itself.
61780 */
61781
61782 - pipe->readers++;
61783 - pipe->writers++;
61784 + atomic_inc(&pipe->readers);
61785 + atomic_inc(&pipe->writers);
61786 pipe->r_counter++;
61787 pipe->w_counter++;
61788 - if (pipe->readers == 1 || pipe->writers == 1)
61789 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
61790 wake_up_partner(pipe);
61791 break;
61792
61793 @@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
61794 return 0;
61795
61796 err_rd:
61797 - if (!--pipe->readers)
61798 + if (atomic_dec_and_test(&pipe->readers))
61799 wake_up_interruptible(&pipe->wait);
61800 ret = -ERESTARTSYS;
61801 goto err;
61802
61803 err_wr:
61804 - if (!--pipe->writers)
61805 + if (atomic_dec_and_test(&pipe->writers))
61806 wake_up_interruptible(&pipe->wait);
61807 ret = -ERESTARTSYS;
61808 goto err;
61809 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
61810 index 2183fcf..3c32a98 100644
61811 --- a/fs/proc/Kconfig
61812 +++ b/fs/proc/Kconfig
61813 @@ -30,7 +30,7 @@ config PROC_FS
61814
61815 config PROC_KCORE
61816 bool "/proc/kcore support" if !ARM
61817 - depends on PROC_FS && MMU
61818 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
61819 help
61820 Provides a virtual ELF core file of the live kernel. This can
61821 be read with gdb and other ELF tools. No modifications can be
61822 @@ -38,8 +38,8 @@ config PROC_KCORE
61823
61824 config PROC_VMCORE
61825 bool "/proc/vmcore support"
61826 - depends on PROC_FS && CRASH_DUMP
61827 - default y
61828 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
61829 + default n
61830 help
61831 Exports the dump image of crashed kernel in ELF format.
61832
61833 @@ -63,8 +63,8 @@ config PROC_SYSCTL
61834 limited in memory.
61835
61836 config PROC_PAGE_MONITOR
61837 - default y
61838 - depends on PROC_FS && MMU
61839 + default n
61840 + depends on PROC_FS && MMU && !GRKERNSEC
61841 bool "Enable /proc page monitoring" if EXPERT
61842 help
61843 Various /proc files exist to monitor process memory utilization:
61844 diff --git a/fs/proc/array.c b/fs/proc/array.c
61845 index 1bd2077..2f7cfd5 100644
61846 --- a/fs/proc/array.c
61847 +++ b/fs/proc/array.c
61848 @@ -60,6 +60,7 @@
61849 #include <linux/tty.h>
61850 #include <linux/string.h>
61851 #include <linux/mman.h>
61852 +#include <linux/grsecurity.h>
61853 #include <linux/proc_fs.h>
61854 #include <linux/ioport.h>
61855 #include <linux/uaccess.h>
61856 @@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
61857 seq_putc(m, '\n');
61858 }
61859
61860 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61861 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
61862 +{
61863 + if (p->mm)
61864 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
61865 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
61866 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
61867 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
61868 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
61869 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
61870 + else
61871 + seq_printf(m, "PaX:\t-----\n");
61872 +}
61873 +#endif
61874 +
61875 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61876 struct pid *pid, struct task_struct *task)
61877 {
61878 @@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61879 task_cpus_allowed(m, task);
61880 cpuset_task_status_allowed(m, task);
61881 task_context_switch_counts(m, task);
61882 +
61883 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61884 + task_pax(m, task);
61885 +#endif
61886 +
61887 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
61888 + task_grsec_rbac(m, task);
61889 +#endif
61890 +
61891 return 0;
61892 }
61893
61894 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61895 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61896 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
61897 + _mm->pax_flags & MF_PAX_SEGMEXEC))
61898 +#endif
61899 +
61900 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61901 struct pid *pid, struct task_struct *task, int whole)
61902 {
61903 @@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61904 char tcomm[sizeof(task->comm)];
61905 unsigned long flags;
61906
61907 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61908 + if (current->exec_id != m->exec_id) {
61909 + gr_log_badprocpid("stat");
61910 + return 0;
61911 + }
61912 +#endif
61913 +
61914 state = *get_task_state(task);
61915 vsize = eip = esp = 0;
61916 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61917 @@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61918 gtime = task_gtime(task);
61919 }
61920
61921 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61922 + if (PAX_RAND_FLAGS(mm)) {
61923 + eip = 0;
61924 + esp = 0;
61925 + wchan = 0;
61926 + }
61927 +#endif
61928 +#ifdef CONFIG_GRKERNSEC_HIDESYM
61929 + wchan = 0;
61930 + eip =0;
61931 + esp =0;
61932 +#endif
61933 +
61934 /* scale priority and nice values from timeslices to -20..20 */
61935 /* to make it look like a "normal" Unix priority/nice value */
61936 priority = task_prio(task);
61937 @@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61938 seq_put_decimal_ull(m, ' ', vsize);
61939 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
61940 seq_put_decimal_ull(m, ' ', rsslim);
61941 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61942 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
61943 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
61944 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
61945 +#else
61946 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
61947 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
61948 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
61949 +#endif
61950 seq_put_decimal_ull(m, ' ', esp);
61951 seq_put_decimal_ull(m, ' ', eip);
61952 /* The signal information here is obsolete.
61953 @@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61954 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
61955 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
61956
61957 - if (mm && permitted) {
61958 + if (mm && permitted
61959 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61960 + && !PAX_RAND_FLAGS(mm)
61961 +#endif
61962 + ) {
61963 seq_put_decimal_ull(m, ' ', mm->start_data);
61964 seq_put_decimal_ull(m, ' ', mm->end_data);
61965 seq_put_decimal_ull(m, ' ', mm->start_brk);
61966 @@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61967 struct pid *pid, struct task_struct *task)
61968 {
61969 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
61970 - struct mm_struct *mm = get_task_mm(task);
61971 + struct mm_struct *mm;
61972
61973 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61974 + if (current->exec_id != m->exec_id) {
61975 + gr_log_badprocpid("statm");
61976 + return 0;
61977 + }
61978 +#endif
61979 + mm = get_task_mm(task);
61980 if (mm) {
61981 size = task_statm(mm, &shared, &text, &data, &resident);
61982 mmput(mm);
61983 @@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61984 return 0;
61985 }
61986
61987 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
61988 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
61989 +{
61990 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
61991 +}
61992 +#endif
61993 +
61994 #ifdef CONFIG_CHECKPOINT_RESTORE
61995 static struct pid *
61996 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
61997 diff --git a/fs/proc/base.c b/fs/proc/base.c
61998 index 03c8d74..4efb575 100644
61999 --- a/fs/proc/base.c
62000 +++ b/fs/proc/base.c
62001 @@ -113,6 +113,14 @@ struct pid_entry {
62002 union proc_op op;
62003 };
62004
62005 +struct getdents_callback {
62006 + struct linux_dirent __user * current_dir;
62007 + struct linux_dirent __user * previous;
62008 + struct file * file;
62009 + int count;
62010 + int error;
62011 +};
62012 +
62013 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62014 .name = (NAME), \
62015 .len = sizeof(NAME) - 1, \
62016 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62017 if (!mm->arg_end)
62018 goto out_mm; /* Shh! No looking before we're done */
62019
62020 + if (gr_acl_handle_procpidmem(task))
62021 + goto out_mm;
62022 +
62023 len = mm->arg_end - mm->arg_start;
62024
62025 if (len > PAGE_SIZE)
62026 @@ -237,12 +248,28 @@ out:
62027 return res;
62028 }
62029
62030 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62031 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62032 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62033 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62034 +#endif
62035 +
62036 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62037 {
62038 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62039 int res = PTR_ERR(mm);
62040 if (mm && !IS_ERR(mm)) {
62041 unsigned int nwords = 0;
62042 +
62043 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62044 + /* allow if we're currently ptracing this task */
62045 + if (PAX_RAND_FLAGS(mm) &&
62046 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62047 + mmput(mm);
62048 + return 0;
62049 + }
62050 +#endif
62051 +
62052 do {
62053 nwords += 2;
62054 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62055 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62056 }
62057
62058
62059 -#ifdef CONFIG_KALLSYMS
62060 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62061 /*
62062 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62063 * Returns the resolved symbol. If that fails, simply return the address.
62064 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62065 mutex_unlock(&task->signal->cred_guard_mutex);
62066 }
62067
62068 -#ifdef CONFIG_STACKTRACE
62069 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62070
62071 #define MAX_STACK_TRACE_DEPTH 64
62072
62073 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62074 return count;
62075 }
62076
62077 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62078 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62079 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62080 {
62081 long nr;
62082 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62083 /************************************************************************/
62084
62085 /* permission checks */
62086 -static int proc_fd_access_allowed(struct inode *inode)
62087 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62088 {
62089 struct task_struct *task;
62090 int allowed = 0;
62091 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62092 */
62093 task = get_proc_task(inode);
62094 if (task) {
62095 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62096 + if (log)
62097 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62098 + else
62099 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62100 put_task_struct(task);
62101 }
62102 return allowed;
62103 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
62104 struct task_struct *task,
62105 int hide_pid_min)
62106 {
62107 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62108 + return false;
62109 +
62110 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62111 + rcu_read_lock();
62112 + {
62113 + const struct cred *tmpcred = current_cred();
62114 + const struct cred *cred = __task_cred(task);
62115 +
62116 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
62117 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62118 + || in_group_p(grsec_proc_gid)
62119 +#endif
62120 + ) {
62121 + rcu_read_unlock();
62122 + return true;
62123 + }
62124 + }
62125 + rcu_read_unlock();
62126 +
62127 + if (!pid->hide_pid)
62128 + return false;
62129 +#endif
62130 +
62131 if (pid->hide_pid < hide_pid_min)
62132 return true;
62133 if (in_group_p(pid->pid_gid))
62134 return true;
62135 +
62136 return ptrace_may_access(task, PTRACE_MODE_READ);
62137 }
62138
62139 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
62140 put_task_struct(task);
62141
62142 if (!has_perms) {
62143 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62144 + {
62145 +#else
62146 if (pid->hide_pid == 2) {
62147 +#endif
62148 /*
62149 * Let's make getdents(), stat(), and open()
62150 * consistent with each other. If a process
62151 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62152 if (!task)
62153 return -ESRCH;
62154
62155 + if (gr_acl_handle_procpidmem(task)) {
62156 + put_task_struct(task);
62157 + return -EPERM;
62158 + }
62159 +
62160 mm = mm_access(task, mode);
62161 put_task_struct(task);
62162
62163 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62164
62165 file->private_data = mm;
62166
62167 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62168 + file->f_version = current->exec_id;
62169 +#endif
62170 +
62171 return 0;
62172 }
62173
62174 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62175 ssize_t copied;
62176 char *page;
62177
62178 +#ifdef CONFIG_GRKERNSEC
62179 + if (write)
62180 + return -EPERM;
62181 +#endif
62182 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62183 + if (file->f_version != current->exec_id) {
62184 + gr_log_badprocpid("mem");
62185 + return 0;
62186 + }
62187 +#endif
62188 +
62189 if (!mm)
62190 return 0;
62191
62192 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62193 goto free;
62194
62195 while (count > 0) {
62196 - int this_len = min_t(int, count, PAGE_SIZE);
62197 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
62198
62199 if (write && copy_from_user(page, buf, this_len)) {
62200 copied = -EFAULT;
62201 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62202 if (!mm)
62203 return 0;
62204
62205 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62206 + if (file->f_version != current->exec_id) {
62207 + gr_log_badprocpid("environ");
62208 + return 0;
62209 + }
62210 +#endif
62211 +
62212 page = (char *)__get_free_page(GFP_TEMPORARY);
62213 if (!page)
62214 return -ENOMEM;
62215 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62216 goto free;
62217 while (count > 0) {
62218 size_t this_len, max_len;
62219 - int retval;
62220 + ssize_t retval;
62221
62222 if (src >= (mm->env_end - mm->env_start))
62223 break;
62224 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
62225 int error = -EACCES;
62226
62227 /* Are we allowed to snoop on the tasks file descriptors? */
62228 - if (!proc_fd_access_allowed(inode))
62229 + if (!proc_fd_access_allowed(inode, 0))
62230 goto out;
62231
62232 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62233 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
62234 struct path path;
62235
62236 /* Are we allowed to snoop on the tasks file descriptors? */
62237 - if (!proc_fd_access_allowed(inode))
62238 - goto out;
62239 + /* logging this is needed for learning on chromium to work properly,
62240 + but we don't want to flood the logs from 'ps' which does a readlink
62241 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
62242 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
62243 + */
62244 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
62245 + if (!proc_fd_access_allowed(inode,0))
62246 + goto out;
62247 + } else {
62248 + if (!proc_fd_access_allowed(inode,1))
62249 + goto out;
62250 + }
62251
62252 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62253 if (error)
62254 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
62255 rcu_read_lock();
62256 cred = __task_cred(task);
62257 inode->i_uid = cred->euid;
62258 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62259 + inode->i_gid = grsec_proc_gid;
62260 +#else
62261 inode->i_gid = cred->egid;
62262 +#endif
62263 rcu_read_unlock();
62264 }
62265 security_task_to_inode(task, inode);
62266 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
62267 return -ENOENT;
62268 }
62269 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62270 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62271 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62272 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62273 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62274 +#endif
62275 task_dumpable(task)) {
62276 cred = __task_cred(task);
62277 stat->uid = cred->euid;
62278 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62279 + stat->gid = grsec_proc_gid;
62280 +#else
62281 stat->gid = cred->egid;
62282 +#endif
62283 }
62284 }
62285 rcu_read_unlock();
62286 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
62287
62288 if (task) {
62289 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62290 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62291 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62292 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62293 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62294 +#endif
62295 task_dumpable(task)) {
62296 rcu_read_lock();
62297 cred = __task_cred(task);
62298 inode->i_uid = cred->euid;
62299 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62300 + inode->i_gid = grsec_proc_gid;
62301 +#else
62302 inode->i_gid = cred->egid;
62303 +#endif
62304 rcu_read_unlock();
62305 } else {
62306 inode->i_uid = GLOBAL_ROOT_UID;
62307 @@ -2172,6 +2290,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
62308 if (!task)
62309 goto out_no_task;
62310
62311 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62312 + goto out;
62313 +
62314 /*
62315 * Yes, it does not scale. And it should not. Don't add
62316 * new entries into /proc/<tgid>/ without very good reasons.
62317 @@ -2202,6 +2323,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
62318 if (!task)
62319 return -ENOENT;
62320
62321 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62322 + goto out;
62323 +
62324 if (!dir_emit_dots(file, ctx))
62325 goto out;
62326
62327 @@ -2591,7 +2715,7 @@ static const struct pid_entry tgid_base_stuff[] = {
62328 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
62329 #endif
62330 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62331 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62332 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62333 INF("syscall", S_IRUGO, proc_pid_syscall),
62334 #endif
62335 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62336 @@ -2616,10 +2740,10 @@ static const struct pid_entry tgid_base_stuff[] = {
62337 #ifdef CONFIG_SECURITY
62338 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62339 #endif
62340 -#ifdef CONFIG_KALLSYMS
62341 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62342 INF("wchan", S_IRUGO, proc_pid_wchan),
62343 #endif
62344 -#ifdef CONFIG_STACKTRACE
62345 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62346 ONE("stack", S_IRUGO, proc_pid_stack),
62347 #endif
62348 #ifdef CONFIG_SCHEDSTATS
62349 @@ -2653,6 +2777,9 @@ static const struct pid_entry tgid_base_stuff[] = {
62350 #ifdef CONFIG_HARDWALL
62351 INF("hardwall", S_IRUGO, proc_pid_hardwall),
62352 #endif
62353 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62354 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
62355 +#endif
62356 #ifdef CONFIG_USER_NS
62357 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
62358 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
62359 @@ -2783,7 +2910,14 @@ static int proc_pid_instantiate(struct inode *dir,
62360 if (!inode)
62361 goto out;
62362
62363 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62364 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
62365 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62366 + inode->i_gid = grsec_proc_gid;
62367 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
62368 +#else
62369 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
62370 +#endif
62371 inode->i_op = &proc_tgid_base_inode_operations;
62372 inode->i_fop = &proc_tgid_base_operations;
62373 inode->i_flags|=S_IMMUTABLE;
62374 @@ -2821,7 +2955,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
62375 if (!task)
62376 goto out;
62377
62378 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62379 + goto out_put_task;
62380 +
62381 result = proc_pid_instantiate(dir, dentry, task, NULL);
62382 +out_put_task:
62383 put_task_struct(task);
62384 out:
62385 return ERR_PTR(result);
62386 @@ -2927,7 +3065,7 @@ static const struct pid_entry tid_base_stuff[] = {
62387 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
62388 #endif
62389 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62390 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62391 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62392 INF("syscall", S_IRUGO, proc_pid_syscall),
62393 #endif
62394 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62395 @@ -2954,10 +3092,10 @@ static const struct pid_entry tid_base_stuff[] = {
62396 #ifdef CONFIG_SECURITY
62397 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62398 #endif
62399 -#ifdef CONFIG_KALLSYMS
62400 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62401 INF("wchan", S_IRUGO, proc_pid_wchan),
62402 #endif
62403 -#ifdef CONFIG_STACKTRACE
62404 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62405 ONE("stack", S_IRUGO, proc_pid_stack),
62406 #endif
62407 #ifdef CONFIG_SCHEDSTATS
62408 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
62409 index 82676e3..5f8518a 100644
62410 --- a/fs/proc/cmdline.c
62411 +++ b/fs/proc/cmdline.c
62412 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
62413
62414 static int __init proc_cmdline_init(void)
62415 {
62416 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62417 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
62418 +#else
62419 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
62420 +#endif
62421 return 0;
62422 }
62423 module_init(proc_cmdline_init);
62424 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
62425 index b143471..bb105e5 100644
62426 --- a/fs/proc/devices.c
62427 +++ b/fs/proc/devices.c
62428 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
62429
62430 static int __init proc_devices_init(void)
62431 {
62432 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62433 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
62434 +#else
62435 proc_create("devices", 0, NULL, &proc_devinfo_operations);
62436 +#endif
62437 return 0;
62438 }
62439 module_init(proc_devices_init);
62440 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
62441 index 985ea88..d118a0a 100644
62442 --- a/fs/proc/fd.c
62443 +++ b/fs/proc/fd.c
62444 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
62445 if (!task)
62446 return -ENOENT;
62447
62448 - files = get_files_struct(task);
62449 + if (!gr_acl_handle_procpidmem(task))
62450 + files = get_files_struct(task);
62451 put_task_struct(task);
62452
62453 if (files) {
62454 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
62455 */
62456 int proc_fd_permission(struct inode *inode, int mask)
62457 {
62458 + struct task_struct *task;
62459 int rv = generic_permission(inode, mask);
62460 - if (rv == 0)
62461 - return 0;
62462 +
62463 if (task_tgid(current) == proc_pid(inode))
62464 rv = 0;
62465 +
62466 + task = get_proc_task(inode);
62467 + if (task == NULL)
62468 + return rv;
62469 +
62470 + if (gr_acl_handle_procpidmem(task))
62471 + rv = -EACCES;
62472 +
62473 + put_task_struct(task);
62474 +
62475 return rv;
62476 }
62477
62478 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
62479 index 124fc43..8afbb02 100644
62480 --- a/fs/proc/inode.c
62481 +++ b/fs/proc/inode.c
62482 @@ -23,11 +23,17 @@
62483 #include <linux/slab.h>
62484 #include <linux/mount.h>
62485 #include <linux/magic.h>
62486 +#include <linux/grsecurity.h>
62487
62488 #include <asm/uaccess.h>
62489
62490 #include "internal.h"
62491
62492 +#ifdef CONFIG_PROC_SYSCTL
62493 +extern const struct inode_operations proc_sys_inode_operations;
62494 +extern const struct inode_operations proc_sys_dir_operations;
62495 +#endif
62496 +
62497 static void proc_evict_inode(struct inode *inode)
62498 {
62499 struct proc_dir_entry *de;
62500 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
62501 ns = PROC_I(inode)->ns.ns;
62502 if (ns_ops && ns)
62503 ns_ops->put(ns);
62504 +
62505 +#ifdef CONFIG_PROC_SYSCTL
62506 + if (inode->i_op == &proc_sys_inode_operations ||
62507 + inode->i_op == &proc_sys_dir_operations)
62508 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
62509 +#endif
62510 +
62511 }
62512
62513 static struct kmem_cache * proc_inode_cachep;
62514 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
62515 if (de->mode) {
62516 inode->i_mode = de->mode;
62517 inode->i_uid = de->uid;
62518 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62519 + inode->i_gid = grsec_proc_gid;
62520 +#else
62521 inode->i_gid = de->gid;
62522 +#endif
62523 }
62524 if (de->size)
62525 inode->i_size = de->size;
62526 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
62527 index 651d09a..3d7f0bf 100644
62528 --- a/fs/proc/internal.h
62529 +++ b/fs/proc/internal.h
62530 @@ -48,7 +48,7 @@ struct proc_dir_entry {
62531 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
62532 u8 namelen;
62533 char name[];
62534 -};
62535 +} __randomize_layout;
62536
62537 union proc_op {
62538 int (*proc_get_link)(struct dentry *, struct path *);
62539 @@ -67,7 +67,7 @@ struct proc_inode {
62540 struct ctl_table *sysctl_entry;
62541 struct proc_ns ns;
62542 struct inode vfs_inode;
62543 -};
62544 +} __randomize_layout;
62545
62546 /*
62547 * General functions
62548 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
62549 struct pid *, struct task_struct *);
62550 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
62551 struct pid *, struct task_struct *);
62552 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62553 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
62554 +#endif
62555
62556 /*
62557 * base.c
62558 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
62559 index 05029c0..7ea1987 100644
62560 --- a/fs/proc/interrupts.c
62561 +++ b/fs/proc/interrupts.c
62562 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
62563
62564 static int __init proc_interrupts_init(void)
62565 {
62566 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62567 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
62568 +#else
62569 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
62570 +#endif
62571 return 0;
62572 }
62573 module_init(proc_interrupts_init);
62574 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
62575 index 5ed0e52..a1c1f2e 100644
62576 --- a/fs/proc/kcore.c
62577 +++ b/fs/proc/kcore.c
62578 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62579 * the addresses in the elf_phdr on our list.
62580 */
62581 start = kc_offset_to_vaddr(*fpos - elf_buflen);
62582 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
62583 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
62584 + if (tsz > buflen)
62585 tsz = buflen;
62586 -
62587 +
62588 while (buflen) {
62589 struct kcore_list *m;
62590
62591 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62592 kfree(elf_buf);
62593 } else {
62594 if (kern_addr_valid(start)) {
62595 - unsigned long n;
62596 + char *elf_buf;
62597 + mm_segment_t oldfs;
62598
62599 - n = copy_to_user(buffer, (char *)start, tsz);
62600 - /*
62601 - * We cannot distinguish between fault on source
62602 - * and fault on destination. When this happens
62603 - * we clear too and hope it will trigger the
62604 - * EFAULT again.
62605 - */
62606 - if (n) {
62607 - if (clear_user(buffer + tsz - n,
62608 - n))
62609 + elf_buf = kmalloc(tsz, GFP_KERNEL);
62610 + if (!elf_buf)
62611 + return -ENOMEM;
62612 + oldfs = get_fs();
62613 + set_fs(KERNEL_DS);
62614 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
62615 + set_fs(oldfs);
62616 + if (copy_to_user(buffer, elf_buf, tsz)) {
62617 + kfree(elf_buf);
62618 return -EFAULT;
62619 + }
62620 }
62621 + set_fs(oldfs);
62622 + kfree(elf_buf);
62623 } else {
62624 if (clear_user(buffer, tsz))
62625 return -EFAULT;
62626 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62627
62628 static int open_kcore(struct inode *inode, struct file *filp)
62629 {
62630 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62631 + return -EPERM;
62632 +#endif
62633 if (!capable(CAP_SYS_RAWIO))
62634 return -EPERM;
62635 if (kcore_need_update)
62636 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
62637 index a77d2b2..a9153f0 100644
62638 --- a/fs/proc/meminfo.c
62639 +++ b/fs/proc/meminfo.c
62640 @@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
62641 vmi.used >> 10,
62642 vmi.largest_chunk >> 10
62643 #ifdef CONFIG_MEMORY_FAILURE
62644 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62645 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62646 #endif
62647 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
62648 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
62649 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
62650 index 5f9bc8a..5c35f08 100644
62651 --- a/fs/proc/nommu.c
62652 +++ b/fs/proc/nommu.c
62653 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
62654
62655 if (file) {
62656 seq_pad(m, ' ');
62657 - seq_path(m, &file->f_path, "");
62658 + seq_path(m, &file->f_path, "\n\\");
62659 }
62660
62661 seq_putc(m, '\n');
62662 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
62663 index 4677bb7..408e936 100644
62664 --- a/fs/proc/proc_net.c
62665 +++ b/fs/proc/proc_net.c
62666 @@ -23,6 +23,7 @@
62667 #include <linux/nsproxy.h>
62668 #include <net/net_namespace.h>
62669 #include <linux/seq_file.h>
62670 +#include <linux/grsecurity.h>
62671
62672 #include "internal.h"
62673
62674 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
62675 struct task_struct *task;
62676 struct nsproxy *ns;
62677 struct net *net = NULL;
62678 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62679 + const struct cred *cred = current_cred();
62680 +#endif
62681 +
62682 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62683 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
62684 + return net;
62685 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62686 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
62687 + return net;
62688 +#endif
62689
62690 rcu_read_lock();
62691 task = pid_task(proc_pid(dir), PIDTYPE_PID);
62692 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
62693 index 7129046..6914844 100644
62694 --- a/fs/proc/proc_sysctl.c
62695 +++ b/fs/proc/proc_sysctl.c
62696 @@ -11,13 +11,21 @@
62697 #include <linux/namei.h>
62698 #include <linux/mm.h>
62699 #include <linux/module.h>
62700 +#include <linux/nsproxy.h>
62701 +#ifdef CONFIG_GRKERNSEC
62702 +#include <net/net_namespace.h>
62703 +#endif
62704 #include "internal.h"
62705
62706 +extern int gr_handle_chroot_sysctl(const int op);
62707 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
62708 + const int op);
62709 +
62710 static const struct dentry_operations proc_sys_dentry_operations;
62711 static const struct file_operations proc_sys_file_operations;
62712 -static const struct inode_operations proc_sys_inode_operations;
62713 +const struct inode_operations proc_sys_inode_operations;
62714 static const struct file_operations proc_sys_dir_file_operations;
62715 -static const struct inode_operations proc_sys_dir_operations;
62716 +const struct inode_operations proc_sys_dir_operations;
62717
62718 void proc_sys_poll_notify(struct ctl_table_poll *poll)
62719 {
62720 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
62721
62722 err = NULL;
62723 d_set_d_op(dentry, &proc_sys_dentry_operations);
62724 +
62725 + gr_handle_proc_create(dentry, inode);
62726 +
62727 d_add(dentry, inode);
62728
62729 out:
62730 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62731 struct inode *inode = file_inode(filp);
62732 struct ctl_table_header *head = grab_header(inode);
62733 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
62734 + int op = write ? MAY_WRITE : MAY_READ;
62735 ssize_t error;
62736 size_t res;
62737
62738 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62739 * and won't be until we finish.
62740 */
62741 error = -EPERM;
62742 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
62743 + if (sysctl_perm(head, table, op))
62744 goto out;
62745
62746 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
62747 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62748 if (!table->proc_handler)
62749 goto out;
62750
62751 +#ifdef CONFIG_GRKERNSEC
62752 + error = -EPERM;
62753 + if (gr_handle_chroot_sysctl(op))
62754 + goto out;
62755 + dget(filp->f_path.dentry);
62756 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
62757 + dput(filp->f_path.dentry);
62758 + goto out;
62759 + }
62760 + dput(filp->f_path.dentry);
62761 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
62762 + goto out;
62763 + if (write) {
62764 + if (current->nsproxy->net_ns != table->extra2) {
62765 + if (!capable(CAP_SYS_ADMIN))
62766 + goto out;
62767 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
62768 + goto out;
62769 + }
62770 +#endif
62771 +
62772 /* careful: calling conventions are nasty here */
62773 res = count;
62774 error = table->proc_handler(table, write, buf, &res, ppos);
62775 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
62776 return false;
62777 } else {
62778 d_set_d_op(child, &proc_sys_dentry_operations);
62779 +
62780 + gr_handle_proc_create(child, inode);
62781 +
62782 d_add(child, inode);
62783 }
62784 } else {
62785 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
62786 if ((*pos)++ < ctx->pos)
62787 return true;
62788
62789 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
62790 + return 0;
62791 +
62792 if (unlikely(S_ISLNK(table->mode)))
62793 res = proc_sys_link_fill_cache(file, ctx, head, table);
62794 else
62795 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
62796 if (IS_ERR(head))
62797 return PTR_ERR(head);
62798
62799 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
62800 + return -ENOENT;
62801 +
62802 generic_fillattr(inode, stat);
62803 if (table)
62804 stat->mode = (stat->mode & S_IFMT) | table->mode;
62805 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
62806 .llseek = generic_file_llseek,
62807 };
62808
62809 -static const struct inode_operations proc_sys_inode_operations = {
62810 +const struct inode_operations proc_sys_inode_operations = {
62811 .permission = proc_sys_permission,
62812 .setattr = proc_sys_setattr,
62813 .getattr = proc_sys_getattr,
62814 };
62815
62816 -static const struct inode_operations proc_sys_dir_operations = {
62817 +const struct inode_operations proc_sys_dir_operations = {
62818 .lookup = proc_sys_lookup,
62819 .permission = proc_sys_permission,
62820 .setattr = proc_sys_setattr,
62821 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
62822 static struct ctl_dir *new_dir(struct ctl_table_set *set,
62823 const char *name, int namelen)
62824 {
62825 - struct ctl_table *table;
62826 + ctl_table_no_const *table;
62827 struct ctl_dir *new;
62828 struct ctl_node *node;
62829 char *new_name;
62830 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
62831 return NULL;
62832
62833 node = (struct ctl_node *)(new + 1);
62834 - table = (struct ctl_table *)(node + 1);
62835 + table = (ctl_table_no_const *)(node + 1);
62836 new_name = (char *)(table + 2);
62837 memcpy(new_name, name, namelen);
62838 new_name[namelen] = '\0';
62839 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
62840 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
62841 struct ctl_table_root *link_root)
62842 {
62843 - struct ctl_table *link_table, *entry, *link;
62844 + ctl_table_no_const *link_table, *link;
62845 + struct ctl_table *entry;
62846 struct ctl_table_header *links;
62847 struct ctl_node *node;
62848 char *link_name;
62849 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
62850 return NULL;
62851
62852 node = (struct ctl_node *)(links + 1);
62853 - link_table = (struct ctl_table *)(node + nr_entries);
62854 + link_table = (ctl_table_no_const *)(node + nr_entries);
62855 link_name = (char *)&link_table[nr_entries + 1];
62856
62857 for (link = link_table, entry = table; entry->procname; link++, entry++) {
62858 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62859 struct ctl_table_header ***subheader, struct ctl_table_set *set,
62860 struct ctl_table *table)
62861 {
62862 - struct ctl_table *ctl_table_arg = NULL;
62863 - struct ctl_table *entry, *files;
62864 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
62865 + struct ctl_table *entry;
62866 int nr_files = 0;
62867 int nr_dirs = 0;
62868 int err = -ENOMEM;
62869 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62870 nr_files++;
62871 }
62872
62873 - files = table;
62874 /* If there are mixed files and directories we need a new table */
62875 if (nr_dirs && nr_files) {
62876 - struct ctl_table *new;
62877 + ctl_table_no_const *new;
62878 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
62879 GFP_KERNEL);
62880 if (!files)
62881 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62882 /* Register everything except a directory full of subdirectories */
62883 if (nr_files || !nr_dirs) {
62884 struct ctl_table_header *header;
62885 - header = __register_sysctl_table(set, path, files);
62886 + header = __register_sysctl_table(set, path, files ? files : table);
62887 if (!header) {
62888 kfree(ctl_table_arg);
62889 goto out;
62890 diff --git a/fs/proc/root.c b/fs/proc/root.c
62891 index 87dbcbe..55e1b4d 100644
62892 --- a/fs/proc/root.c
62893 +++ b/fs/proc/root.c
62894 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
62895 #ifdef CONFIG_PROC_DEVICETREE
62896 proc_device_tree_init();
62897 #endif
62898 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62899 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62900 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
62901 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62902 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
62903 +#endif
62904 +#else
62905 proc_mkdir("bus", NULL);
62906 +#endif
62907 proc_sys_init();
62908 }
62909
62910 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
62911 index 1cf86c0..0ee1ca5 100644
62912 --- a/fs/proc/stat.c
62913 +++ b/fs/proc/stat.c
62914 @@ -11,6 +11,7 @@
62915 #include <linux/irqnr.h>
62916 #include <asm/cputime.h>
62917 #include <linux/tick.h>
62918 +#include <linux/grsecurity.h>
62919
62920 #ifndef arch_irq_stat_cpu
62921 #define arch_irq_stat_cpu(cpu) 0
62922 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
62923 u64 sum_softirq = 0;
62924 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
62925 struct timespec boottime;
62926 + int unrestricted = 1;
62927 +
62928 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62929 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62930 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
62931 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62932 + && !in_group_p(grsec_proc_gid)
62933 +#endif
62934 + )
62935 + unrestricted = 0;
62936 +#endif
62937 +#endif
62938
62939 user = nice = system = idle = iowait =
62940 irq = softirq = steal = 0;
62941 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
62942 getboottime(&boottime);
62943 jif = boottime.tv_sec;
62944
62945 + if (unrestricted) {
62946 for_each_possible_cpu(i) {
62947 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
62948 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62949 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
62950 }
62951 }
62952 sum += arch_irq_stat();
62953 + }
62954
62955 seq_puts(p, "cpu ");
62956 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62957 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
62958 seq_putc(p, '\n');
62959
62960 for_each_online_cpu(i) {
62961 + if (unrestricted) {
62962 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
62963 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
62964 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62965 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
62966 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
62967 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
62968 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
62969 + }
62970 seq_printf(p, "cpu%d", i);
62971 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62972 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
62973 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
62974
62975 /* sum again ? it could be updated? */
62976 for_each_irq_nr(j)
62977 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
62978 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
62979
62980 seq_printf(p,
62981 "\nctxt %llu\n"
62982 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
62983 "processes %lu\n"
62984 "procs_running %lu\n"
62985 "procs_blocked %lu\n",
62986 - nr_context_switches(),
62987 + unrestricted ? nr_context_switches() : 0ULL,
62988 (unsigned long)jif,
62989 - total_forks,
62990 - nr_running(),
62991 - nr_iowait());
62992 + unrestricted ? total_forks : 0UL,
62993 + unrestricted ? nr_running() : 0UL,
62994 + unrestricted ? nr_iowait() : 0UL);
62995
62996 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
62997
62998 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
62999 index fb52b54..5fc7c14 100644
63000 --- a/fs/proc/task_mmu.c
63001 +++ b/fs/proc/task_mmu.c
63002 @@ -12,12 +12,19 @@
63003 #include <linux/swap.h>
63004 #include <linux/swapops.h>
63005 #include <linux/mmu_notifier.h>
63006 +#include <linux/grsecurity.h>
63007
63008 #include <asm/elf.h>
63009 #include <asm/uaccess.h>
63010 #include <asm/tlbflush.h>
63011 #include "internal.h"
63012
63013 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63014 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63015 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63016 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63017 +#endif
63018 +
63019 void task_mem(struct seq_file *m, struct mm_struct *mm)
63020 {
63021 unsigned long data, text, lib, swap;
63022 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63023 "VmExe:\t%8lu kB\n"
63024 "VmLib:\t%8lu kB\n"
63025 "VmPTE:\t%8lu kB\n"
63026 - "VmSwap:\t%8lu kB\n",
63027 - hiwater_vm << (PAGE_SHIFT-10),
63028 + "VmSwap:\t%8lu kB\n"
63029 +
63030 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63031 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63032 +#endif
63033 +
63034 + ,hiwater_vm << (PAGE_SHIFT-10),
63035 total_vm << (PAGE_SHIFT-10),
63036 mm->locked_vm << (PAGE_SHIFT-10),
63037 mm->pinned_vm << (PAGE_SHIFT-10),
63038 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63039 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63040 (PTRS_PER_PTE * sizeof(pte_t) *
63041 atomic_long_read(&mm->nr_ptes)) >> 10,
63042 - swap << (PAGE_SHIFT-10));
63043 + swap << (PAGE_SHIFT-10)
63044 +
63045 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63046 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63047 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63048 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63049 +#else
63050 + , mm->context.user_cs_base
63051 + , mm->context.user_cs_limit
63052 +#endif
63053 +#endif
63054 +
63055 + );
63056 }
63057
63058 unsigned long task_vsize(struct mm_struct *mm)
63059 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63060 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63061 }
63062
63063 - /* We don't show the stack guard page in /proc/maps */
63064 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63065 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63066 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63067 +#else
63068 start = vma->vm_start;
63069 - if (stack_guard_page_start(vma, start))
63070 - start += PAGE_SIZE;
63071 end = vma->vm_end;
63072 - if (stack_guard_page_end(vma, end))
63073 - end -= PAGE_SIZE;
63074 +#endif
63075
63076 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63077 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63078 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63079 flags & VM_WRITE ? 'w' : '-',
63080 flags & VM_EXEC ? 'x' : '-',
63081 flags & VM_MAYSHARE ? 's' : 'p',
63082 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63083 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63084 +#else
63085 pgoff,
63086 +#endif
63087 MAJOR(dev), MINOR(dev), ino);
63088
63089 /*
63090 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63091 */
63092 if (file) {
63093 seq_pad(m, ' ');
63094 - seq_path(m, &file->f_path, "\n");
63095 + seq_path(m, &file->f_path, "\n\\");
63096 goto done;
63097 }
63098
63099 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63100 * Thread stack in /proc/PID/task/TID/maps or
63101 * the main process stack.
63102 */
63103 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
63104 - vma->vm_end >= mm->start_stack)) {
63105 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
63106 + (vma->vm_start <= mm->start_stack &&
63107 + vma->vm_end >= mm->start_stack)) {
63108 name = "[stack]";
63109 } else {
63110 /* Thread stack in /proc/PID/maps */
63111 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63112 struct proc_maps_private *priv = m->private;
63113 struct task_struct *task = priv->task;
63114
63115 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63116 + if (current->exec_id != m->exec_id) {
63117 + gr_log_badprocpid("maps");
63118 + return 0;
63119 + }
63120 +#endif
63121 +
63122 show_map_vma(m, vma, is_pid);
63123
63124 if (m->count < m->size) /* vma is copied successfully */
63125 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63126 .private = &mss,
63127 };
63128
63129 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63130 + if (current->exec_id != m->exec_id) {
63131 + gr_log_badprocpid("smaps");
63132 + return 0;
63133 + }
63134 +#endif
63135 memset(&mss, 0, sizeof mss);
63136 - mss.vma = vma;
63137 - /* mmap_sem is held in m_start */
63138 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63139 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63140 -
63141 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63142 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
63143 +#endif
63144 + mss.vma = vma;
63145 + /* mmap_sem is held in m_start */
63146 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63147 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63148 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63149 + }
63150 +#endif
63151 show_map_vma(m, vma, is_pid);
63152
63153 seq_printf(m,
63154 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63155 "KernelPageSize: %8lu kB\n"
63156 "MMUPageSize: %8lu kB\n"
63157 "Locked: %8lu kB\n",
63158 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63159 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
63160 +#else
63161 (vma->vm_end - vma->vm_start) >> 10,
63162 +#endif
63163 mss.resident >> 10,
63164 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
63165 mss.shared_clean >> 10,
63166 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63167 char buffer[64];
63168 int nid;
63169
63170 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63171 + if (current->exec_id != m->exec_id) {
63172 + gr_log_badprocpid("numa_maps");
63173 + return 0;
63174 + }
63175 +#endif
63176 +
63177 if (!mm)
63178 return 0;
63179
63180 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63181 mpol_to_str(buffer, sizeof(buffer), pol);
63182 mpol_cond_put(pol);
63183
63184 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63185 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
63186 +#else
63187 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
63188 +#endif
63189
63190 if (file) {
63191 seq_printf(m, " file=");
63192 - seq_path(m, &file->f_path, "\n\t= ");
63193 + seq_path(m, &file->f_path, "\n\t\\= ");
63194 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
63195 seq_printf(m, " heap");
63196 } else {
63197 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
63198 index 678455d..ebd3245 100644
63199 --- a/fs/proc/task_nommu.c
63200 +++ b/fs/proc/task_nommu.c
63201 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63202 else
63203 bytes += kobjsize(mm);
63204
63205 - if (current->fs && current->fs->users > 1)
63206 + if (current->fs && atomic_read(&current->fs->users) > 1)
63207 sbytes += kobjsize(current->fs);
63208 else
63209 bytes += kobjsize(current->fs);
63210 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
63211
63212 if (file) {
63213 seq_pad(m, ' ');
63214 - seq_path(m, &file->f_path, "");
63215 + seq_path(m, &file->f_path, "\n\\");
63216 } else if (mm) {
63217 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
63218
63219 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
63220 index 9100d69..51cd925 100644
63221 --- a/fs/proc/vmcore.c
63222 +++ b/fs/proc/vmcore.c
63223 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
63224 nr_bytes = count;
63225
63226 /* If pfn is not ram, return zeros for sparse dump files */
63227 - if (pfn_is_ram(pfn) == 0)
63228 - memset(buf, 0, nr_bytes);
63229 - else {
63230 + if (pfn_is_ram(pfn) == 0) {
63231 + if (userbuf) {
63232 + if (clear_user((char __force_user *)buf, nr_bytes))
63233 + return -EFAULT;
63234 + } else
63235 + memset(buf, 0, nr_bytes);
63236 + } else {
63237 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
63238 offset, userbuf);
63239 if (tmp < 0)
63240 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
63241 static int copy_to(void *target, void *src, size_t size, int userbuf)
63242 {
63243 if (userbuf) {
63244 - if (copy_to_user((char __user *) target, src, size))
63245 + if (copy_to_user((char __force_user *) target, src, size))
63246 return -EFAULT;
63247 } else {
63248 memcpy(target, src, size);
63249 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63250 if (*fpos < m->offset + m->size) {
63251 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
63252 start = m->paddr + *fpos - m->offset;
63253 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
63254 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
63255 if (tmp < 0)
63256 return tmp;
63257 buflen -= tsz;
63258 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63259 static ssize_t read_vmcore(struct file *file, char __user *buffer,
63260 size_t buflen, loff_t *fpos)
63261 {
63262 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
63263 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
63264 }
63265
63266 /*
63267 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
63268 index b00fcc9..e0c6381 100644
63269 --- a/fs/qnx6/qnx6.h
63270 +++ b/fs/qnx6/qnx6.h
63271 @@ -74,7 +74,7 @@ enum {
63272 BYTESEX_BE,
63273 };
63274
63275 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63276 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63277 {
63278 if (sbi->s_bytesex == BYTESEX_LE)
63279 return le64_to_cpu((__force __le64)n);
63280 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
63281 return (__force __fs64)cpu_to_be64(n);
63282 }
63283
63284 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63285 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63286 {
63287 if (sbi->s_bytesex == BYTESEX_LE)
63288 return le32_to_cpu((__force __le32)n);
63289 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
63290 index 72d2917..c917c12 100644
63291 --- a/fs/quota/netlink.c
63292 +++ b/fs/quota/netlink.c
63293 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
63294 void quota_send_warning(struct kqid qid, dev_t dev,
63295 const char warntype)
63296 {
63297 - static atomic_t seq;
63298 + static atomic_unchecked_t seq;
63299 struct sk_buff *skb;
63300 void *msg_head;
63301 int ret;
63302 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
63303 "VFS: Not enough memory to send quota warning.\n");
63304 return;
63305 }
63306 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
63307 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
63308 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
63309 if (!msg_head) {
63310 printk(KERN_ERR
63311 diff --git a/fs/read_write.c b/fs/read_write.c
63312 index 58e440d..8ec2838 100644
63313 --- a/fs/read_write.c
63314 +++ b/fs/read_write.c
63315 @@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
63316
63317 old_fs = get_fs();
63318 set_fs(get_ds());
63319 - p = (__force const char __user *)buf;
63320 + p = (const char __force_user *)buf;
63321 if (count > MAX_RW_COUNT)
63322 count = MAX_RW_COUNT;
63323 if (file->f_op->write)
63324 diff --git a/fs/readdir.c b/fs/readdir.c
63325 index 5b53d99..a6c3049 100644
63326 --- a/fs/readdir.c
63327 +++ b/fs/readdir.c
63328 @@ -17,6 +17,7 @@
63329 #include <linux/security.h>
63330 #include <linux/syscalls.h>
63331 #include <linux/unistd.h>
63332 +#include <linux/namei.h>
63333
63334 #include <asm/uaccess.h>
63335
63336 @@ -69,6 +70,7 @@ struct old_linux_dirent {
63337 struct readdir_callback {
63338 struct dir_context ctx;
63339 struct old_linux_dirent __user * dirent;
63340 + struct file * file;
63341 int result;
63342 };
63343
63344 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
63345 buf->result = -EOVERFLOW;
63346 return -EOVERFLOW;
63347 }
63348 +
63349 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63350 + return 0;
63351 +
63352 buf->result++;
63353 dirent = buf->dirent;
63354 if (!access_ok(VERIFY_WRITE, dirent,
63355 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
63356 if (!f.file)
63357 return -EBADF;
63358
63359 + buf.file = f.file;
63360 error = iterate_dir(f.file, &buf.ctx);
63361 if (buf.result)
63362 error = buf.result;
63363 @@ -142,6 +149,7 @@ struct getdents_callback {
63364 struct dir_context ctx;
63365 struct linux_dirent __user * current_dir;
63366 struct linux_dirent __user * previous;
63367 + struct file * file;
63368 int count;
63369 int error;
63370 };
63371 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
63372 buf->error = -EOVERFLOW;
63373 return -EOVERFLOW;
63374 }
63375 +
63376 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63377 + return 0;
63378 +
63379 dirent = buf->previous;
63380 if (dirent) {
63381 if (__put_user(offset, &dirent->d_off))
63382 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
63383 if (!f.file)
63384 return -EBADF;
63385
63386 + buf.file = f.file;
63387 error = iterate_dir(f.file, &buf.ctx);
63388 if (error >= 0)
63389 error = buf.error;
63390 @@ -226,6 +239,7 @@ struct getdents_callback64 {
63391 struct dir_context ctx;
63392 struct linux_dirent64 __user * current_dir;
63393 struct linux_dirent64 __user * previous;
63394 + struct file *file;
63395 int count;
63396 int error;
63397 };
63398 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
63399 buf->error = -EINVAL; /* only used if we fail.. */
63400 if (reclen > buf->count)
63401 return -EINVAL;
63402 +
63403 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63404 + return 0;
63405 +
63406 dirent = buf->previous;
63407 if (dirent) {
63408 if (__put_user(offset, &dirent->d_off))
63409 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
63410 if (!f.file)
63411 return -EBADF;
63412
63413 + buf.file = f.file;
63414 error = iterate_dir(f.file, &buf.ctx);
63415 if (error >= 0)
63416 error = buf.error;
63417 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
63418 index 2b7882b..1c5ef48 100644
63419 --- a/fs/reiserfs/do_balan.c
63420 +++ b/fs/reiserfs/do_balan.c
63421 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
63422 return;
63423 }
63424
63425 - atomic_inc(&(fs_generation(tb->tb_sb)));
63426 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
63427 do_balance_starts(tb);
63428
63429 /* balance leaf returns 0 except if combining L R and S into
63430 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
63431 index ee382ef..f4eb6eb5 100644
63432 --- a/fs/reiserfs/item_ops.c
63433 +++ b/fs/reiserfs/item_ops.c
63434 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
63435 }
63436
63437 static struct item_operations errcatch_ops = {
63438 - errcatch_bytes_number,
63439 - errcatch_decrement_key,
63440 - errcatch_is_left_mergeable,
63441 - errcatch_print_item,
63442 - errcatch_check_item,
63443 + .bytes_number = errcatch_bytes_number,
63444 + .decrement_key = errcatch_decrement_key,
63445 + .is_left_mergeable = errcatch_is_left_mergeable,
63446 + .print_item = errcatch_print_item,
63447 + .check_item = errcatch_check_item,
63448
63449 - errcatch_create_vi,
63450 - errcatch_check_left,
63451 - errcatch_check_right,
63452 - errcatch_part_size,
63453 - errcatch_unit_num,
63454 - errcatch_print_vi
63455 + .create_vi = errcatch_create_vi,
63456 + .check_left = errcatch_check_left,
63457 + .check_right = errcatch_check_right,
63458 + .part_size = errcatch_part_size,
63459 + .unit_num = errcatch_unit_num,
63460 + .print_vi = errcatch_print_vi
63461 };
63462
63463 //////////////////////////////////////////////////////////////////////////////
63464 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
63465 index a958444..42b2323 100644
63466 --- a/fs/reiserfs/procfs.c
63467 +++ b/fs/reiserfs/procfs.c
63468 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
63469 "SMALL_TAILS " : "NO_TAILS ",
63470 replay_only(sb) ? "REPLAY_ONLY " : "",
63471 convert_reiserfs(sb) ? "CONV " : "",
63472 - atomic_read(&r->s_generation_counter),
63473 + atomic_read_unchecked(&r->s_generation_counter),
63474 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
63475 SF(s_do_balance), SF(s_unneeded_left_neighbor),
63476 SF(s_good_search_by_key_reada), SF(s_bmaps),
63477 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
63478 index f8adaee..0eeeeca 100644
63479 --- a/fs/reiserfs/reiserfs.h
63480 +++ b/fs/reiserfs/reiserfs.h
63481 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
63482 /* Comment? -Hans */
63483 wait_queue_head_t s_wait;
63484 /* To be obsoleted soon by per buffer seals.. -Hans */
63485 - atomic_t s_generation_counter; // increased by one every time the
63486 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63487 // tree gets re-balanced
63488 unsigned long s_properties; /* File system properties. Currently holds
63489 on-disk FS format */
63490 @@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63491 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63492
63493 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63494 -#define get_generation(s) atomic_read (&fs_generation(s))
63495 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63496 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63497 #define __fs_changed(gen,s) (gen != get_generation (s))
63498 #define fs_changed(gen,s) \
63499 diff --git a/fs/select.c b/fs/select.c
63500 index 467bb1c..cf9d65a 100644
63501 --- a/fs/select.c
63502 +++ b/fs/select.c
63503 @@ -20,6 +20,7 @@
63504 #include <linux/export.h>
63505 #include <linux/slab.h>
63506 #include <linux/poll.h>
63507 +#include <linux/security.h>
63508 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
63509 #include <linux/file.h>
63510 #include <linux/fdtable.h>
63511 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
63512 struct poll_list *walk = head;
63513 unsigned long todo = nfds;
63514
63515 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
63516 if (nfds > rlimit(RLIMIT_NOFILE))
63517 return -EINVAL;
63518
63519 diff --git a/fs/seq_file.c b/fs/seq_file.c
63520 index 1d641bb..e600623 100644
63521 --- a/fs/seq_file.c
63522 +++ b/fs/seq_file.c
63523 @@ -10,6 +10,7 @@
63524 #include <linux/seq_file.h>
63525 #include <linux/slab.h>
63526 #include <linux/cred.h>
63527 +#include <linux/sched.h>
63528
63529 #include <asm/uaccess.h>
63530 #include <asm/page.h>
63531 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
63532 #ifdef CONFIG_USER_NS
63533 p->user_ns = file->f_cred->user_ns;
63534 #endif
63535 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63536 + p->exec_id = current->exec_id;
63537 +#endif
63538
63539 /*
63540 * Wrappers around seq_open(e.g. swaps_open) need to be
63541 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
63542 return 0;
63543 }
63544 if (!m->buf) {
63545 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63546 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63547 if (!m->buf)
63548 return -ENOMEM;
63549 }
63550 @@ -137,7 +141,7 @@ Eoverflow:
63551 m->op->stop(m, p);
63552 kfree(m->buf);
63553 m->count = 0;
63554 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63555 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63556 return !m->buf ? -ENOMEM : -EAGAIN;
63557 }
63558
63559 @@ -153,7 +157,7 @@ Eoverflow:
63560 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63561 {
63562 struct seq_file *m = file->private_data;
63563 - size_t copied = 0;
63564 + ssize_t copied = 0;
63565 loff_t pos;
63566 size_t n;
63567 void *p;
63568 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63569
63570 /* grab buffer if we didn't have one */
63571 if (!m->buf) {
63572 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63573 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63574 if (!m->buf)
63575 goto Enomem;
63576 }
63577 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63578 m->op->stop(m, p);
63579 kfree(m->buf);
63580 m->count = 0;
63581 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63582 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63583 if (!m->buf)
63584 goto Enomem;
63585 m->version = 0;
63586 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
63587 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
63588 void *data)
63589 {
63590 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
63591 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
63592 int res = -ENOMEM;
63593
63594 if (op) {
63595 diff --git a/fs/splice.c b/fs/splice.c
63596 index 46a08f7..bb163cc 100644
63597 --- a/fs/splice.c
63598 +++ b/fs/splice.c
63599 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63600 pipe_lock(pipe);
63601
63602 for (;;) {
63603 - if (!pipe->readers) {
63604 + if (!atomic_read(&pipe->readers)) {
63605 send_sig(SIGPIPE, current, 0);
63606 if (!ret)
63607 ret = -EPIPE;
63608 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63609 page_nr++;
63610 ret += buf->len;
63611
63612 - if (pipe->files)
63613 + if (atomic_read(&pipe->files))
63614 do_wakeup = 1;
63615
63616 if (!--spd->nr_pages)
63617 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63618 do_wakeup = 0;
63619 }
63620
63621 - pipe->waiting_writers++;
63622 + atomic_inc(&pipe->waiting_writers);
63623 pipe_wait(pipe);
63624 - pipe->waiting_writers--;
63625 + atomic_dec(&pipe->waiting_writers);
63626 }
63627
63628 pipe_unlock(pipe);
63629 @@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
63630 old_fs = get_fs();
63631 set_fs(get_ds());
63632 /* The cast to a user pointer is valid due to the set_fs() */
63633 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
63634 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
63635 set_fs(old_fs);
63636
63637 return res;
63638 @@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
63639 old_fs = get_fs();
63640 set_fs(get_ds());
63641 /* The cast to a user pointer is valid due to the set_fs() */
63642 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
63643 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
63644 set_fs(old_fs);
63645
63646 return res;
63647 @@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
63648 goto err;
63649
63650 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
63651 - vec[i].iov_base = (void __user *) page_address(page);
63652 + vec[i].iov_base = (void __force_user *) page_address(page);
63653 vec[i].iov_len = this_len;
63654 spd.pages[i] = page;
63655 spd.nr_pages++;
63656 @@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
63657 ops->release(pipe, buf);
63658 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
63659 pipe->nrbufs--;
63660 - if (pipe->files)
63661 + if (atomic_read(&pipe->files))
63662 sd->need_wakeup = true;
63663 }
63664
63665 @@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
63666 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
63667 {
63668 while (!pipe->nrbufs) {
63669 - if (!pipe->writers)
63670 + if (!atomic_read(&pipe->writers))
63671 return 0;
63672
63673 - if (!pipe->waiting_writers && sd->num_spliced)
63674 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
63675 return 0;
63676
63677 if (sd->flags & SPLICE_F_NONBLOCK)
63678 @@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
63679 * out of the pipe right after the splice_to_pipe(). So set
63680 * PIPE_READERS appropriately.
63681 */
63682 - pipe->readers = 1;
63683 + atomic_set(&pipe->readers, 1);
63684
63685 current->splice_pipe = pipe;
63686 }
63687 @@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
63688
63689 partial[buffers].offset = off;
63690 partial[buffers].len = plen;
63691 + partial[buffers].private = 0;
63692
63693 off = 0;
63694 len -= plen;
63695 @@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63696 ret = -ERESTARTSYS;
63697 break;
63698 }
63699 - if (!pipe->writers)
63700 + if (!atomic_read(&pipe->writers))
63701 break;
63702 - if (!pipe->waiting_writers) {
63703 + if (!atomic_read(&pipe->waiting_writers)) {
63704 if (flags & SPLICE_F_NONBLOCK) {
63705 ret = -EAGAIN;
63706 break;
63707 @@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63708 pipe_lock(pipe);
63709
63710 while (pipe->nrbufs >= pipe->buffers) {
63711 - if (!pipe->readers) {
63712 + if (!atomic_read(&pipe->readers)) {
63713 send_sig(SIGPIPE, current, 0);
63714 ret = -EPIPE;
63715 break;
63716 @@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63717 ret = -ERESTARTSYS;
63718 break;
63719 }
63720 - pipe->waiting_writers++;
63721 + atomic_inc(&pipe->waiting_writers);
63722 pipe_wait(pipe);
63723 - pipe->waiting_writers--;
63724 + atomic_dec(&pipe->waiting_writers);
63725 }
63726
63727 pipe_unlock(pipe);
63728 @@ -1862,14 +1863,14 @@ retry:
63729 pipe_double_lock(ipipe, opipe);
63730
63731 do {
63732 - if (!opipe->readers) {
63733 + if (!atomic_read(&opipe->readers)) {
63734 send_sig(SIGPIPE, current, 0);
63735 if (!ret)
63736 ret = -EPIPE;
63737 break;
63738 }
63739
63740 - if (!ipipe->nrbufs && !ipipe->writers)
63741 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
63742 break;
63743
63744 /*
63745 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63746 pipe_double_lock(ipipe, opipe);
63747
63748 do {
63749 - if (!opipe->readers) {
63750 + if (!atomic_read(&opipe->readers)) {
63751 send_sig(SIGPIPE, current, 0);
63752 if (!ret)
63753 ret = -EPIPE;
63754 @@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63755 * return EAGAIN if we have the potential of some data in the
63756 * future, otherwise just return 0
63757 */
63758 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
63759 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
63760 ret = -EAGAIN;
63761
63762 pipe_unlock(ipipe);
63763 diff --git a/fs/stat.c b/fs/stat.c
63764 index ae0c3ce..9ee641c 100644
63765 --- a/fs/stat.c
63766 +++ b/fs/stat.c
63767 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
63768 stat->gid = inode->i_gid;
63769 stat->rdev = inode->i_rdev;
63770 stat->size = i_size_read(inode);
63771 - stat->atime = inode->i_atime;
63772 - stat->mtime = inode->i_mtime;
63773 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63774 + stat->atime = inode->i_ctime;
63775 + stat->mtime = inode->i_ctime;
63776 + } else {
63777 + stat->atime = inode->i_atime;
63778 + stat->mtime = inode->i_mtime;
63779 + }
63780 stat->ctime = inode->i_ctime;
63781 stat->blksize = (1 << inode->i_blkbits);
63782 stat->blocks = inode->i_blocks;
63783 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
63784 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
63785 {
63786 struct inode *inode = path->dentry->d_inode;
63787 + int retval;
63788
63789 - if (inode->i_op->getattr)
63790 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
63791 + if (inode->i_op->getattr) {
63792 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
63793 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63794 + stat->atime = stat->ctime;
63795 + stat->mtime = stat->ctime;
63796 + }
63797 + return retval;
63798 + }
63799
63800 generic_fillattr(inode, stat);
63801 return 0;
63802 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
63803 index 5e73d66..4f165fd 100644
63804 --- a/fs/sysfs/dir.c
63805 +++ b/fs/sysfs/dir.c
63806 @@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
63807 *
63808 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63809 */
63810 -static unsigned int sysfs_name_hash(const char *name, const void *ns)
63811 +static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
63812 {
63813 unsigned long hash = init_name_hash();
63814 unsigned int len = strlen(name);
63815 @@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
63816 struct sysfs_dirent *sd;
63817 int rc;
63818
63819 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
63820 + const char *parent_name = parent_sd->s_name;
63821 +
63822 + mode = S_IFDIR | S_IRWXU;
63823 +
63824 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
63825 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
63826 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
63827 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
63828 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
63829 +#endif
63830 +
63831 /* allocate */
63832 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
63833 if (!sd)
63834 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
63835 index 35e7d08..4d6e676 100644
63836 --- a/fs/sysfs/file.c
63837 +++ b/fs/sysfs/file.c
63838 @@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
63839
63840 struct sysfs_open_dirent {
63841 atomic_t refcnt;
63842 - atomic_t event;
63843 + atomic_unchecked_t event;
63844 wait_queue_head_t poll;
63845 struct list_head files; /* goes through sysfs_open_file.list */
63846 };
63847 @@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
63848 return -ENODEV;
63849 }
63850
63851 - of->event = atomic_read(&of->sd->s_attr.open->event);
63852 + of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
63853
63854 /*
63855 * Lookup @ops and invoke show(). Control may reach here via seq
63856 @@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
63857 return ret;
63858 }
63859
63860 -static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63861 - void *buf, int len, int write)
63862 +static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63863 + void *buf, size_t len, int write)
63864 {
63865 struct file *file = vma->vm_file;
63866 struct sysfs_open_file *of = sysfs_of(file);
63867 - int ret;
63868 + ssize_t ret;
63869
63870 if (!of->vm_ops)
63871 return -EINVAL;
63872 @@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
63873 return -ENOMEM;
63874
63875 atomic_set(&new_od->refcnt, 0);
63876 - atomic_set(&new_od->event, 1);
63877 + atomic_set_unchecked(&new_od->event, 1);
63878 init_waitqueue_head(&new_od->poll);
63879 INIT_LIST_HEAD(&new_od->files);
63880 goto retry;
63881 @@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
63882
63883 sysfs_put_active(attr_sd);
63884
63885 - if (of->event != atomic_read(&od->event))
63886 + if (of->event != atomic_read_unchecked(&od->event))
63887 goto trigger;
63888
63889 return DEFAULT_POLLMASK;
63890 @@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
63891 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
63892 od = sd->s_attr.open;
63893 if (od) {
63894 - atomic_inc(&od->event);
63895 + atomic_inc_unchecked(&od->event);
63896 wake_up_interruptible(&od->poll);
63897 }
63898 }
63899 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
63900 index 3ae3f1b..081a26c 100644
63901 --- a/fs/sysfs/symlink.c
63902 +++ b/fs/sysfs/symlink.c
63903 @@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63904 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
63905 void *cookie)
63906 {
63907 - char *page = nd_get_link(nd);
63908 + const char *page = nd_get_link(nd);
63909 if (!IS_ERR(page))
63910 free_page((unsigned long)page);
63911 }
63912 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
63913 index 69d4889..a810bd4 100644
63914 --- a/fs/sysv/sysv.h
63915 +++ b/fs/sysv/sysv.h
63916 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
63917 #endif
63918 }
63919
63920 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63921 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63922 {
63923 if (sbi->s_bytesex == BYTESEX_PDP)
63924 return PDP_swab((__force __u32)n);
63925 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
63926 index e18b988..f1d4ad0f 100644
63927 --- a/fs/ubifs/io.c
63928 +++ b/fs/ubifs/io.c
63929 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
63930 return err;
63931 }
63932
63933 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63934 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63935 {
63936 int err;
63937
63938 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
63939 index c175b4d..8f36a16 100644
63940 --- a/fs/udf/misc.c
63941 +++ b/fs/udf/misc.c
63942 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
63943
63944 u8 udf_tag_checksum(const struct tag *t)
63945 {
63946 - u8 *data = (u8 *)t;
63947 + const u8 *data = (const u8 *)t;
63948 u8 checksum = 0;
63949 int i;
63950 for (i = 0; i < sizeof(struct tag); ++i)
63951 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
63952 index 8d974c4..b82f6ec 100644
63953 --- a/fs/ufs/swab.h
63954 +++ b/fs/ufs/swab.h
63955 @@ -22,7 +22,7 @@ enum {
63956 BYTESEX_BE
63957 };
63958
63959 -static inline u64
63960 +static inline u64 __intentional_overflow(-1)
63961 fs64_to_cpu(struct super_block *sbp, __fs64 n)
63962 {
63963 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63964 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
63965 return (__force __fs64)cpu_to_be64(n);
63966 }
63967
63968 -static inline u32
63969 +static inline u32 __intentional_overflow(-1)
63970 fs32_to_cpu(struct super_block *sbp, __fs32 n)
63971 {
63972 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63973 diff --git a/fs/utimes.c b/fs/utimes.c
63974 index aa138d6..5f3a811 100644
63975 --- a/fs/utimes.c
63976 +++ b/fs/utimes.c
63977 @@ -1,6 +1,7 @@
63978 #include <linux/compiler.h>
63979 #include <linux/file.h>
63980 #include <linux/fs.h>
63981 +#include <linux/security.h>
63982 #include <linux/linkage.h>
63983 #include <linux/mount.h>
63984 #include <linux/namei.h>
63985 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
63986 }
63987 }
63988 retry_deleg:
63989 +
63990 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
63991 + error = -EACCES;
63992 + goto mnt_drop_write_and_out;
63993 + }
63994 +
63995 mutex_lock(&inode->i_mutex);
63996 error = notify_change(path->dentry, &newattrs, &delegated_inode);
63997 mutex_unlock(&inode->i_mutex);
63998 diff --git a/fs/xattr.c b/fs/xattr.c
63999 index 3377dff..f394815 100644
64000 --- a/fs/xattr.c
64001 +++ b/fs/xattr.c
64002 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64003 return rc;
64004 }
64005
64006 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64007 +ssize_t
64008 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
64009 +{
64010 + struct inode *inode = dentry->d_inode;
64011 + ssize_t error;
64012 +
64013 + error = inode_permission(inode, MAY_EXEC);
64014 + if (error)
64015 + return error;
64016 +
64017 + if (inode->i_op->getxattr)
64018 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64019 + else
64020 + error = -EOPNOTSUPP;
64021 +
64022 + return error;
64023 +}
64024 +EXPORT_SYMBOL(pax_getxattr);
64025 +#endif
64026 +
64027 ssize_t
64028 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64029 {
64030 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64031 * Extended attribute SET operations
64032 */
64033 static long
64034 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
64035 +setxattr(struct path *path, const char __user *name, const void __user *value,
64036 size_t size, int flags)
64037 {
64038 int error;
64039 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64040 posix_acl_fix_xattr_from_user(kvalue, size);
64041 }
64042
64043 - error = vfs_setxattr(d, kname, kvalue, size, flags);
64044 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64045 + error = -EACCES;
64046 + goto out;
64047 + }
64048 +
64049 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64050 out:
64051 if (vvalue)
64052 vfree(vvalue);
64053 @@ -377,7 +403,7 @@ retry:
64054 return error;
64055 error = mnt_want_write(path.mnt);
64056 if (!error) {
64057 - error = setxattr(path.dentry, name, value, size, flags);
64058 + error = setxattr(&path, name, value, size, flags);
64059 mnt_drop_write(path.mnt);
64060 }
64061 path_put(&path);
64062 @@ -401,7 +427,7 @@ retry:
64063 return error;
64064 error = mnt_want_write(path.mnt);
64065 if (!error) {
64066 - error = setxattr(path.dentry, name, value, size, flags);
64067 + error = setxattr(&path, name, value, size, flags);
64068 mnt_drop_write(path.mnt);
64069 }
64070 path_put(&path);
64071 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64072 const void __user *,value, size_t, size, int, flags)
64073 {
64074 struct fd f = fdget(fd);
64075 - struct dentry *dentry;
64076 int error = -EBADF;
64077
64078 if (!f.file)
64079 return error;
64080 - dentry = f.file->f_path.dentry;
64081 - audit_inode(NULL, dentry, 0);
64082 + audit_inode(NULL, f.file->f_path.dentry, 0);
64083 error = mnt_want_write_file(f.file);
64084 if (!error) {
64085 - error = setxattr(dentry, name, value, size, flags);
64086 + error = setxattr(&f.file->f_path, name, value, size, flags);
64087 mnt_drop_write_file(f.file);
64088 }
64089 fdput(f);
64090 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64091 * Extended attribute REMOVE operations
64092 */
64093 static long
64094 -removexattr(struct dentry *d, const char __user *name)
64095 +removexattr(struct path *path, const char __user *name)
64096 {
64097 int error;
64098 char kname[XATTR_NAME_MAX + 1];
64099 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64100 if (error < 0)
64101 return error;
64102
64103 - return vfs_removexattr(d, kname);
64104 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
64105 + return -EACCES;
64106 +
64107 + return vfs_removexattr(path->dentry, kname);
64108 }
64109
64110 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64111 @@ -652,7 +679,7 @@ retry:
64112 return error;
64113 error = mnt_want_write(path.mnt);
64114 if (!error) {
64115 - error = removexattr(path.dentry, name);
64116 + error = removexattr(&path, name);
64117 mnt_drop_write(path.mnt);
64118 }
64119 path_put(&path);
64120 @@ -675,7 +702,7 @@ retry:
64121 return error;
64122 error = mnt_want_write(path.mnt);
64123 if (!error) {
64124 - error = removexattr(path.dentry, name);
64125 + error = removexattr(&path, name);
64126 mnt_drop_write(path.mnt);
64127 }
64128 path_put(&path);
64129 @@ -689,16 +716,16 @@ retry:
64130 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64131 {
64132 struct fd f = fdget(fd);
64133 - struct dentry *dentry;
64134 + struct path *path;
64135 int error = -EBADF;
64136
64137 if (!f.file)
64138 return error;
64139 - dentry = f.file->f_path.dentry;
64140 - audit_inode(NULL, dentry, 0);
64141 + path = &f.file->f_path;
64142 + audit_inode(NULL, path->dentry, 0);
64143 error = mnt_want_write_file(f.file);
64144 if (!error) {
64145 - error = removexattr(dentry, name);
64146 + error = removexattr(path, name);
64147 mnt_drop_write_file(f.file);
64148 }
64149 fdput(f);
64150 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
64151 index 9fbea87..6b19972 100644
64152 --- a/fs/xattr_acl.c
64153 +++ b/fs/xattr_acl.c
64154 @@ -76,8 +76,8 @@ struct posix_acl *
64155 posix_acl_from_xattr(struct user_namespace *user_ns,
64156 const void *value, size_t size)
64157 {
64158 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
64159 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
64160 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
64161 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
64162 int count;
64163 struct posix_acl *acl;
64164 struct posix_acl_entry *acl_e;
64165 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
64166 index 3b2c14b..de031fe 100644
64167 --- a/fs/xfs/xfs_bmap.c
64168 +++ b/fs/xfs/xfs_bmap.c
64169 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
64170
64171 #else
64172 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
64173 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
64174 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
64175 #endif /* DEBUG */
64176
64177 /*
64178 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
64179 index c4e50c6..8ba93e3 100644
64180 --- a/fs/xfs/xfs_dir2_readdir.c
64181 +++ b/fs/xfs/xfs_dir2_readdir.c
64182 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
64183 ino = dp->d_ops->sf_get_ino(sfp, sfep);
64184 filetype = dp->d_ops->sf_get_ftype(sfep);
64185 ctx->pos = off & 0x7fffffff;
64186 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64187 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
64188 + char name[sfep->namelen];
64189 + memcpy(name, sfep->name, sfep->namelen);
64190 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
64191 + return 0;
64192 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64193 xfs_dir3_get_dtype(mp, filetype)))
64194 return 0;
64195 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
64196 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
64197 index 33ad9a7..82c18ba 100644
64198 --- a/fs/xfs/xfs_ioctl.c
64199 +++ b/fs/xfs/xfs_ioctl.c
64200 @@ -126,7 +126,7 @@ xfs_find_handle(
64201 }
64202
64203 error = -EFAULT;
64204 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
64205 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
64206 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
64207 goto out_put;
64208
64209 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
64210 index 104455b..764c512 100644
64211 --- a/fs/xfs/xfs_iops.c
64212 +++ b/fs/xfs/xfs_iops.c
64213 @@ -397,7 +397,7 @@ xfs_vn_put_link(
64214 struct nameidata *nd,
64215 void *p)
64216 {
64217 - char *s = nd_get_link(nd);
64218 + const char *s = nd_get_link(nd);
64219
64220 if (!IS_ERR(s))
64221 kfree(s);
64222 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
64223 new file mode 100644
64224 index 0000000..e98584b
64225 --- /dev/null
64226 +++ b/grsecurity/Kconfig
64227 @@ -0,0 +1,1147 @@
64228 +#
64229 +# grecurity configuration
64230 +#
64231 +menu "Memory Protections"
64232 +depends on GRKERNSEC
64233 +
64234 +config GRKERNSEC_KMEM
64235 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
64236 + default y if GRKERNSEC_CONFIG_AUTO
64237 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
64238 + help
64239 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
64240 + be written to or read from to modify or leak the contents of the running
64241 + kernel. /dev/port will also not be allowed to be opened, and support
64242 + for /dev/cpu/*/msr and kexec will be removed. If you have module
64243 + support disabled, enabling this will close up six ways that are
64244 + currently used to insert malicious code into the running kernel.
64245 +
64246 + Even with this feature enabled, we still highly recommend that
64247 + you use the RBAC system, as it is still possible for an attacker to
64248 + modify the running kernel through other more obscure methods.
64249 +
64250 + Enabling this feature will prevent the "cpupower" and "powertop" tools
64251 + from working.
64252 +
64253 + It is highly recommended that you say Y here if you meet all the
64254 + conditions above.
64255 +
64256 +config GRKERNSEC_VM86
64257 + bool "Restrict VM86 mode"
64258 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64259 + depends on X86_32
64260 +
64261 + help
64262 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
64263 + make use of a special execution mode on 32bit x86 processors called
64264 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
64265 + video cards and will still work with this option enabled. The purpose
64266 + of the option is to prevent exploitation of emulation errors in
64267 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
64268 + Nearly all users should be able to enable this option.
64269 +
64270 +config GRKERNSEC_IO
64271 + bool "Disable privileged I/O"
64272 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64273 + depends on X86
64274 + select RTC_CLASS
64275 + select RTC_INTF_DEV
64276 + select RTC_DRV_CMOS
64277 +
64278 + help
64279 + If you say Y here, all ioperm and iopl calls will return an error.
64280 + Ioperm and iopl can be used to modify the running kernel.
64281 + Unfortunately, some programs need this access to operate properly,
64282 + the most notable of which are XFree86 and hwclock. hwclock can be
64283 + remedied by having RTC support in the kernel, so real-time
64284 + clock support is enabled if this option is enabled, to ensure
64285 + that hwclock operates correctly.
64286 +
64287 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
64288 + you may not be able to boot into a graphical environment with this
64289 + option enabled. In this case, you should use the RBAC system instead.
64290 +
64291 +config GRKERNSEC_JIT_HARDEN
64292 + bool "Harden BPF JIT against spray attacks"
64293 + default y if GRKERNSEC_CONFIG_AUTO
64294 + depends on BPF_JIT && X86
64295 + help
64296 + If you say Y here, the native code generated by the kernel's Berkeley
64297 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
64298 + attacks that attempt to fit attacker-beneficial instructions in
64299 + 32bit immediate fields of JIT-generated native instructions. The
64300 + attacker will generally aim to cause an unintended instruction sequence
64301 + of JIT-generated native code to execute by jumping into the middle of
64302 + a generated instruction. This feature effectively randomizes the 32bit
64303 + immediate constants present in the generated code to thwart such attacks.
64304 +
64305 + If you're using KERNEXEC, it's recommended that you enable this option
64306 + to supplement the hardening of the kernel.
64307 +
64308 +config GRKERNSEC_PERF_HARDEN
64309 + bool "Disable unprivileged PERF_EVENTS usage by default"
64310 + default y if GRKERNSEC_CONFIG_AUTO
64311 + depends on PERF_EVENTS
64312 + help
64313 + If you say Y here, the range of acceptable values for the
64314 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
64315 + default to a new value: 3. When the sysctl is set to this value, no
64316 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
64317 +
64318 + Though PERF_EVENTS can be used legitimately for performance monitoring
64319 + and low-level application profiling, it is forced on regardless of
64320 + configuration, has been at fault for several vulnerabilities, and
64321 + creates new opportunities for side channels and other information leaks.
64322 +
64323 + This feature puts PERF_EVENTS into a secure default state and permits
64324 + the administrator to change out of it temporarily if unprivileged
64325 + application profiling is needed.
64326 +
64327 +config GRKERNSEC_RAND_THREADSTACK
64328 + bool "Insert random gaps between thread stacks"
64329 + default y if GRKERNSEC_CONFIG_AUTO
64330 + depends on PAX_RANDMMAP && !PPC
64331 + help
64332 + If you say Y here, a random-sized gap will be enforced between allocated
64333 + thread stacks. Glibc's NPTL and other threading libraries that
64334 + pass MAP_STACK to the kernel for thread stack allocation are supported.
64335 + The implementation currently provides 8 bits of entropy for the gap.
64336 +
64337 + Many distributions do not compile threaded remote services with the
64338 + -fstack-check argument to GCC, causing the variable-sized stack-based
64339 + allocator, alloca(), to not probe the stack on allocation. This
64340 + permits an unbounded alloca() to skip over any guard page and potentially
64341 + modify another thread's stack reliably. An enforced random gap
64342 + reduces the reliability of such an attack and increases the chance
64343 + that such a read/write to another thread's stack instead lands in
64344 + an unmapped area, causing a crash and triggering grsecurity's
64345 + anti-bruteforcing logic.
64346 +
64347 +config GRKERNSEC_PROC_MEMMAP
64348 + bool "Harden ASLR against information leaks and entropy reduction"
64349 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
64350 + depends on PAX_NOEXEC || PAX_ASLR
64351 + help
64352 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
64353 + give no information about the addresses of its mappings if
64354 + PaX features that rely on random addresses are enabled on the task.
64355 + In addition to sanitizing this information and disabling other
64356 + dangerous sources of information, this option causes reads of sensitive
64357 + /proc/<pid> entries where the file descriptor was opened in a different
64358 + task than the one performing the read. Such attempts are logged.
64359 + This option also limits argv/env strings for suid/sgid binaries
64360 + to 512KB to prevent a complete exhaustion of the stack entropy provided
64361 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
64362 + binaries to prevent alternative mmap layouts from being abused.
64363 +
64364 + If you use PaX it is essential that you say Y here as it closes up
64365 + several holes that make full ASLR useless locally.
64366 +
64367 +config GRKERNSEC_BRUTE
64368 + bool "Deter exploit bruteforcing"
64369 + default y if GRKERNSEC_CONFIG_AUTO
64370 + help
64371 + If you say Y here, attempts to bruteforce exploits against forking
64372 + daemons such as apache or sshd, as well as against suid/sgid binaries
64373 + will be deterred. When a child of a forking daemon is killed by PaX
64374 + or crashes due to an illegal instruction or other suspicious signal,
64375 + the parent process will be delayed 30 seconds upon every subsequent
64376 + fork until the administrator is able to assess the situation and
64377 + restart the daemon.
64378 + In the suid/sgid case, the attempt is logged, the user has all their
64379 + existing instances of the suid/sgid binary terminated and will
64380 + be unable to execute any suid/sgid binaries for 15 minutes.
64381 +
64382 + It is recommended that you also enable signal logging in the auditing
64383 + section so that logs are generated when a process triggers a suspicious
64384 + signal.
64385 + If the sysctl option is enabled, a sysctl option with name
64386 + "deter_bruteforce" is created.
64387 +
64388 +config GRKERNSEC_MODHARDEN
64389 + bool "Harden module auto-loading"
64390 + default y if GRKERNSEC_CONFIG_AUTO
64391 + depends on MODULES
64392 + help
64393 + If you say Y here, module auto-loading in response to use of some
64394 + feature implemented by an unloaded module will be restricted to
64395 + root users. Enabling this option helps defend against attacks
64396 + by unprivileged users who abuse the auto-loading behavior to
64397 + cause a vulnerable module to load that is then exploited.
64398 +
64399 + If this option prevents a legitimate use of auto-loading for a
64400 + non-root user, the administrator can execute modprobe manually
64401 + with the exact name of the module mentioned in the alert log.
64402 + Alternatively, the administrator can add the module to the list
64403 + of modules loaded at boot by modifying init scripts.
64404 +
64405 + Modification of init scripts will most likely be needed on
64406 + Ubuntu servers with encrypted home directory support enabled,
64407 + as the first non-root user logging in will cause the ecb(aes),
64408 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
64409 +
64410 +config GRKERNSEC_HIDESYM
64411 + bool "Hide kernel symbols"
64412 + default y if GRKERNSEC_CONFIG_AUTO
64413 + select PAX_USERCOPY_SLABS
64414 + help
64415 + If you say Y here, getting information on loaded modules, and
64416 + displaying all kernel symbols through a syscall will be restricted
64417 + to users with CAP_SYS_MODULE. For software compatibility reasons,
64418 + /proc/kallsyms will be restricted to the root user. The RBAC
64419 + system can hide that entry even from root.
64420 +
64421 + This option also prevents leaking of kernel addresses through
64422 + several /proc entries.
64423 +
64424 + Note that this option is only effective provided the following
64425 + conditions are met:
64426 + 1) The kernel using grsecurity is not precompiled by some distribution
64427 + 2) You have also enabled GRKERNSEC_DMESG
64428 + 3) You are using the RBAC system and hiding other files such as your
64429 + kernel image and System.map. Alternatively, enabling this option
64430 + causes the permissions on /boot, /lib/modules, and the kernel
64431 + source directory to change at compile time to prevent
64432 + reading by non-root users.
64433 + If the above conditions are met, this option will aid in providing a
64434 + useful protection against local kernel exploitation of overflows
64435 + and arbitrary read/write vulnerabilities.
64436 +
64437 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
64438 + in addition to this feature.
64439 +
64440 +config GRKERNSEC_RANDSTRUCT
64441 + bool "Randomize layout of sensitive kernel structures"
64442 + default y if GRKERNSEC_CONFIG_AUTO
64443 + select GRKERNSEC_HIDESYM
64444 + select MODVERSIONS if MODULES
64445 + help
64446 + If you say Y here, the layouts of a number of sensitive kernel
64447 + structures (task, fs, cred, etc) and all structures composed entirely
64448 + of function pointers (aka "ops" structs) will be randomized at compile-time.
64449 + This can introduce the requirement of an additional infoleak
64450 + vulnerability for exploits targeting these structure types.
64451 +
64452 + Enabling this feature will introduce some performance impact, slightly
64453 + increase memory usage, and prevent the use of forensic tools like
64454 + Volatility against the system (unless the kernel source tree isn't
64455 + cleaned after kernel installation).
64456 +
64457 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
64458 + It remains after a make clean to allow for external modules to be compiled
64459 + with the existing seed and will be removed by a make mrproper or
64460 + make distclean.
64461 +
64462 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
64463 + bool "Use cacheline-aware structure randomization"
64464 + depends on GRKERNSEC_RANDSTRUCT
64465 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
64466 + help
64467 + If you say Y here, the RANDSTRUCT randomization will make a best effort
64468 + at restricting randomization to cacheline-sized groups of elements. It
64469 + will further not randomize bitfields in structures. This reduces the
64470 + performance hit of RANDSTRUCT at the cost of weakened randomization.
64471 +
64472 +config GRKERNSEC_KERN_LOCKOUT
64473 + bool "Active kernel exploit response"
64474 + default y if GRKERNSEC_CONFIG_AUTO
64475 + depends on X86 || ARM || PPC || SPARC
64476 + help
64477 + If you say Y here, when a PaX alert is triggered due to suspicious
64478 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
64479 + or an OOPS occurs due to bad memory accesses, instead of just
64480 + terminating the offending process (and potentially allowing
64481 + a subsequent exploit from the same user), we will take one of two
64482 + actions:
64483 + If the user was root, we will panic the system
64484 + If the user was non-root, we will log the attempt, terminate
64485 + all processes owned by the user, then prevent them from creating
64486 + any new processes until the system is restarted
64487 + This deters repeated kernel exploitation/bruteforcing attempts
64488 + and is useful for later forensics.
64489 +
64490 +config GRKERNSEC_OLD_ARM_USERLAND
64491 + bool "Old ARM userland compatibility"
64492 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
64493 + help
64494 + If you say Y here, stubs of executable code to perform such operations
64495 + as "compare-exchange" will be placed at fixed locations in the ARM vector
64496 + table. This is unfortunately needed for old ARM userland meant to run
64497 + across a wide range of processors. Without this option enabled,
64498 + the get_tls and data memory barrier stubs will be emulated by the kernel,
64499 + which is enough for Linaro userlands or other userlands designed for v6
64500 + and newer ARM CPUs. It's recommended that you try without this option enabled
64501 + first, and only enable it if your userland does not boot (it will likely fail
64502 + at init time).
64503 +
64504 +endmenu
64505 +menu "Role Based Access Control Options"
64506 +depends on GRKERNSEC
64507 +
64508 +config GRKERNSEC_RBAC_DEBUG
64509 + bool
64510 +
64511 +config GRKERNSEC_NO_RBAC
64512 + bool "Disable RBAC system"
64513 + help
64514 + If you say Y here, the /dev/grsec device will be removed from the kernel,
64515 + preventing the RBAC system from being enabled. You should only say Y
64516 + here if you have no intention of using the RBAC system, so as to prevent
64517 + an attacker with root access from misusing the RBAC system to hide files
64518 + and processes when loadable module support and /dev/[k]mem have been
64519 + locked down.
64520 +
64521 +config GRKERNSEC_ACL_HIDEKERN
64522 + bool "Hide kernel processes"
64523 + help
64524 + If you say Y here, all kernel threads will be hidden to all
64525 + processes but those whose subject has the "view hidden processes"
64526 + flag.
64527 +
64528 +config GRKERNSEC_ACL_MAXTRIES
64529 + int "Maximum tries before password lockout"
64530 + default 3
64531 + help
64532 + This option enforces the maximum number of times a user can attempt
64533 + to authorize themselves with the grsecurity RBAC system before being
64534 + denied the ability to attempt authorization again for a specified time.
64535 + The lower the number, the harder it will be to brute-force a password.
64536 +
64537 +config GRKERNSEC_ACL_TIMEOUT
64538 + int "Time to wait after max password tries, in seconds"
64539 + default 30
64540 + help
64541 + This option specifies the time the user must wait after attempting to
64542 + authorize to the RBAC system with the maximum number of invalid
64543 + passwords. The higher the number, the harder it will be to brute-force
64544 + a password.
64545 +
64546 +endmenu
64547 +menu "Filesystem Protections"
64548 +depends on GRKERNSEC
64549 +
64550 +config GRKERNSEC_PROC
64551 + bool "Proc restrictions"
64552 + default y if GRKERNSEC_CONFIG_AUTO
64553 + help
64554 + If you say Y here, the permissions of the /proc filesystem
64555 + will be altered to enhance system security and privacy. You MUST
64556 + choose either a user only restriction or a user and group restriction.
64557 + Depending upon the option you choose, you can either restrict users to
64558 + see only the processes they themselves run, or choose a group that can
64559 + view all processes and files normally restricted to root if you choose
64560 + the "restrict to user only" option. NOTE: If you're running identd or
64561 + ntpd as a non-root user, you will have to run it as the group you
64562 + specify here.
64563 +
64564 +config GRKERNSEC_PROC_USER
64565 + bool "Restrict /proc to user only"
64566 + depends on GRKERNSEC_PROC
64567 + help
64568 + If you say Y here, non-root users will only be able to view their own
64569 + processes, and restricts them from viewing network-related information,
64570 + and viewing kernel symbol and module information.
64571 +
64572 +config GRKERNSEC_PROC_USERGROUP
64573 + bool "Allow special group"
64574 + default y if GRKERNSEC_CONFIG_AUTO
64575 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
64576 + help
64577 + If you say Y here, you will be able to select a group that will be
64578 + able to view all processes and network-related information. If you've
64579 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
64580 + remain hidden. This option is useful if you want to run identd as
64581 + a non-root user. The group you select may also be chosen at boot time
64582 + via "grsec_proc_gid=" on the kernel commandline.
64583 +
64584 +config GRKERNSEC_PROC_GID
64585 + int "GID for special group"
64586 + depends on GRKERNSEC_PROC_USERGROUP
64587 + default 1001
64588 +
64589 +config GRKERNSEC_PROC_ADD
64590 + bool "Additional restrictions"
64591 + default y if GRKERNSEC_CONFIG_AUTO
64592 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
64593 + help
64594 + If you say Y here, additional restrictions will be placed on
64595 + /proc that keep normal users from viewing device information and
64596 + slabinfo information that could be useful for exploits.
64597 +
64598 +config GRKERNSEC_LINK
64599 + bool "Linking restrictions"
64600 + default y if GRKERNSEC_CONFIG_AUTO
64601 + help
64602 + If you say Y here, /tmp race exploits will be prevented, since users
64603 + will no longer be able to follow symlinks owned by other users in
64604 + world-writable +t directories (e.g. /tmp), unless the owner of the
64605 + symlink is the owner of the directory. users will also not be
64606 + able to hardlink to files they do not own. If the sysctl option is
64607 + enabled, a sysctl option with name "linking_restrictions" is created.
64608 +
64609 +config GRKERNSEC_SYMLINKOWN
64610 + bool "Kernel-enforced SymlinksIfOwnerMatch"
64611 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64612 + help
64613 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
64614 + that prevents it from being used as a security feature. As Apache
64615 + verifies the symlink by performing a stat() against the target of
64616 + the symlink before it is followed, an attacker can setup a symlink
64617 + to point to a same-owned file, then replace the symlink with one
64618 + that targets another user's file just after Apache "validates" the
64619 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
64620 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
64621 + will be in place for the group you specify. If the sysctl option
64622 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
64623 + created.
64624 +
64625 +config GRKERNSEC_SYMLINKOWN_GID
64626 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
64627 + depends on GRKERNSEC_SYMLINKOWN
64628 + default 1006
64629 + help
64630 + Setting this GID determines what group kernel-enforced
64631 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
64632 + is enabled, a sysctl option with name "symlinkown_gid" is created.
64633 +
64634 +config GRKERNSEC_FIFO
64635 + bool "FIFO restrictions"
64636 + default y if GRKERNSEC_CONFIG_AUTO
64637 + help
64638 + If you say Y here, users will not be able to write to FIFOs they don't
64639 + own in world-writable +t directories (e.g. /tmp), unless the owner of
64640 + the FIFO is the same owner of the directory it's held in. If the sysctl
64641 + option is enabled, a sysctl option with name "fifo_restrictions" is
64642 + created.
64643 +
64644 +config GRKERNSEC_SYSFS_RESTRICT
64645 + bool "Sysfs/debugfs restriction"
64646 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64647 + depends on SYSFS
64648 + help
64649 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
64650 + any filesystem normally mounted under it (e.g. debugfs) will be
64651 + mostly accessible only by root. These filesystems generally provide access
64652 + to hardware and debug information that isn't appropriate for unprivileged
64653 + users of the system. Sysfs and debugfs have also become a large source
64654 + of new vulnerabilities, ranging from infoleaks to local compromise.
64655 + There has been very little oversight with an eye toward security involved
64656 + in adding new exporters of information to these filesystems, so their
64657 + use is discouraged.
64658 + For reasons of compatibility, a few directories have been whitelisted
64659 + for access by non-root users:
64660 + /sys/fs/selinux
64661 + /sys/fs/fuse
64662 + /sys/devices/system/cpu
64663 +
64664 +config GRKERNSEC_ROFS
64665 + bool "Runtime read-only mount protection"
64666 + depends on SYSCTL
64667 + help
64668 + If you say Y here, a sysctl option with name "romount_protect" will
64669 + be created. By setting this option to 1 at runtime, filesystems
64670 + will be protected in the following ways:
64671 + * No new writable mounts will be allowed
64672 + * Existing read-only mounts won't be able to be remounted read/write
64673 + * Write operations will be denied on all block devices
64674 + This option acts independently of grsec_lock: once it is set to 1,
64675 + it cannot be turned off. Therefore, please be mindful of the resulting
64676 + behavior if this option is enabled in an init script on a read-only
64677 + filesystem.
64678 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
64679 + and GRKERNSEC_IO should be enabled and module loading disabled via
64680 + config or at runtime.
64681 + This feature is mainly intended for secure embedded systems.
64682 +
64683 +
64684 +config GRKERNSEC_DEVICE_SIDECHANNEL
64685 + bool "Eliminate stat/notify-based device sidechannels"
64686 + default y if GRKERNSEC_CONFIG_AUTO
64687 + help
64688 + If you say Y here, timing analyses on block or character
64689 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
64690 + will be thwarted for unprivileged users. If a process without
64691 + CAP_MKNOD stats such a device, the last access and last modify times
64692 + will match the device's create time. No access or modify events
64693 + will be triggered through inotify/dnotify/fanotify for such devices.
64694 + This feature will prevent attacks that may at a minimum
64695 + allow an attacker to determine the administrator's password length.
64696 +
64697 +config GRKERNSEC_CHROOT
64698 + bool "Chroot jail restrictions"
64699 + default y if GRKERNSEC_CONFIG_AUTO
64700 + help
64701 + If you say Y here, you will be able to choose several options that will
64702 + make breaking out of a chrooted jail much more difficult. If you
64703 + encounter no software incompatibilities with the following options, it
64704 + is recommended that you enable each one.
64705 +
64706 +config GRKERNSEC_CHROOT_MOUNT
64707 + bool "Deny mounts"
64708 + default y if GRKERNSEC_CONFIG_AUTO
64709 + depends on GRKERNSEC_CHROOT
64710 + help
64711 + If you say Y here, processes inside a chroot will not be able to
64712 + mount or remount filesystems. If the sysctl option is enabled, a
64713 + sysctl option with name "chroot_deny_mount" is created.
64714 +
64715 +config GRKERNSEC_CHROOT_DOUBLE
64716 + bool "Deny double-chroots"
64717 + default y if GRKERNSEC_CONFIG_AUTO
64718 + depends on GRKERNSEC_CHROOT
64719 + help
64720 + If you say Y here, processes inside a chroot will not be able to chroot
64721 + again outside the chroot. This is a widely used method of breaking
64722 + out of a chroot jail and should not be allowed. If the sysctl
64723 + option is enabled, a sysctl option with name
64724 + "chroot_deny_chroot" is created.
64725 +
64726 +config GRKERNSEC_CHROOT_PIVOT
64727 + bool "Deny pivot_root in chroot"
64728 + default y if GRKERNSEC_CONFIG_AUTO
64729 + depends on GRKERNSEC_CHROOT
64730 + help
64731 + If you say Y here, processes inside a chroot will not be able to use
64732 + a function called pivot_root() that was introduced in Linux 2.3.41. It
64733 + works similar to chroot in that it changes the root filesystem. This
64734 + function could be misused in a chrooted process to attempt to break out
64735 + of the chroot, and therefore should not be allowed. If the sysctl
64736 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
64737 + created.
64738 +
64739 +config GRKERNSEC_CHROOT_CHDIR
64740 + bool "Enforce chdir(\"/\") on all chroots"
64741 + default y if GRKERNSEC_CONFIG_AUTO
64742 + depends on GRKERNSEC_CHROOT
64743 + help
64744 + If you say Y here, the current working directory of all newly-chrooted
64745 + applications will be set to the the root directory of the chroot.
64746 + The man page on chroot(2) states:
64747 + Note that this call does not change the current working
64748 + directory, so that `.' can be outside the tree rooted at
64749 + `/'. In particular, the super-user can escape from a
64750 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
64751 +
64752 + It is recommended that you say Y here, since it's not known to break
64753 + any software. If the sysctl option is enabled, a sysctl option with
64754 + name "chroot_enforce_chdir" is created.
64755 +
64756 +config GRKERNSEC_CHROOT_CHMOD
64757 + bool "Deny (f)chmod +s"
64758 + default y if GRKERNSEC_CONFIG_AUTO
64759 + depends on GRKERNSEC_CHROOT
64760 + help
64761 + If you say Y here, processes inside a chroot will not be able to chmod
64762 + or fchmod files to make them have suid or sgid bits. This protects
64763 + against another published method of breaking a chroot. If the sysctl
64764 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
64765 + created.
64766 +
64767 +config GRKERNSEC_CHROOT_FCHDIR
64768 + bool "Deny fchdir out of chroot"
64769 + default y if GRKERNSEC_CONFIG_AUTO
64770 + depends on GRKERNSEC_CHROOT
64771 + help
64772 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
64773 + to a file descriptor of the chrooting process that points to a directory
64774 + outside the filesystem will be stopped. If the sysctl option
64775 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
64776 +
64777 +config GRKERNSEC_CHROOT_MKNOD
64778 + bool "Deny mknod"
64779 + default y if GRKERNSEC_CONFIG_AUTO
64780 + depends on GRKERNSEC_CHROOT
64781 + help
64782 + If you say Y here, processes inside a chroot will not be allowed to
64783 + mknod. The problem with using mknod inside a chroot is that it
64784 + would allow an attacker to create a device entry that is the same
64785 + as one on the physical root of your system, which could range from
64786 + anything from the console device to a device for your harddrive (which
64787 + they could then use to wipe the drive or steal data). It is recommended
64788 + that you say Y here, unless you run into software incompatibilities.
64789 + If the sysctl option is enabled, a sysctl option with name
64790 + "chroot_deny_mknod" is created.
64791 +
64792 +config GRKERNSEC_CHROOT_SHMAT
64793 + bool "Deny shmat() out of chroot"
64794 + default y if GRKERNSEC_CONFIG_AUTO
64795 + depends on GRKERNSEC_CHROOT
64796 + help
64797 + If you say Y here, processes inside a chroot will not be able to attach
64798 + to shared memory segments that were created outside of the chroot jail.
64799 + It is recommended that you say Y here. If the sysctl option is enabled,
64800 + a sysctl option with name "chroot_deny_shmat" is created.
64801 +
64802 +config GRKERNSEC_CHROOT_UNIX
64803 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
64804 + default y if GRKERNSEC_CONFIG_AUTO
64805 + depends on GRKERNSEC_CHROOT
64806 + help
64807 + If you say Y here, processes inside a chroot will not be able to
64808 + connect to abstract (meaning not belonging to a filesystem) Unix
64809 + domain sockets that were bound outside of a chroot. It is recommended
64810 + that you say Y here. If the sysctl option is enabled, a sysctl option
64811 + with name "chroot_deny_unix" is created.
64812 +
64813 +config GRKERNSEC_CHROOT_FINDTASK
64814 + bool "Protect outside processes"
64815 + default y if GRKERNSEC_CONFIG_AUTO
64816 + depends on GRKERNSEC_CHROOT
64817 + help
64818 + If you say Y here, processes inside a chroot will not be able to
64819 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
64820 + getsid, or view any process outside of the chroot. If the sysctl
64821 + option is enabled, a sysctl option with name "chroot_findtask" is
64822 + created.
64823 +
64824 +config GRKERNSEC_CHROOT_NICE
64825 + bool "Restrict priority changes"
64826 + default y if GRKERNSEC_CONFIG_AUTO
64827 + depends on GRKERNSEC_CHROOT
64828 + help
64829 + If you say Y here, processes inside a chroot will not be able to raise
64830 + the priority of processes in the chroot, or alter the priority of
64831 + processes outside the chroot. This provides more security than simply
64832 + removing CAP_SYS_NICE from the process' capability set. If the
64833 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
64834 + is created.
64835 +
64836 +config GRKERNSEC_CHROOT_SYSCTL
64837 + bool "Deny sysctl writes"
64838 + default y if GRKERNSEC_CONFIG_AUTO
64839 + depends on GRKERNSEC_CHROOT
64840 + help
64841 + If you say Y here, an attacker in a chroot will not be able to
64842 + write to sysctl entries, either by sysctl(2) or through a /proc
64843 + interface. It is strongly recommended that you say Y here. If the
64844 + sysctl option is enabled, a sysctl option with name
64845 + "chroot_deny_sysctl" is created.
64846 +
64847 +config GRKERNSEC_CHROOT_CAPS
64848 + bool "Capability restrictions"
64849 + default y if GRKERNSEC_CONFIG_AUTO
64850 + depends on GRKERNSEC_CHROOT
64851 + help
64852 + If you say Y here, the capabilities on all processes within a
64853 + chroot jail will be lowered to stop module insertion, raw i/o,
64854 + system and net admin tasks, rebooting the system, modifying immutable
64855 + files, modifying IPC owned by another, and changing the system time.
64856 + This is left an option because it can break some apps. Disable this
64857 + if your chrooted apps are having problems performing those kinds of
64858 + tasks. If the sysctl option is enabled, a sysctl option with
64859 + name "chroot_caps" is created.
64860 +
64861 +config GRKERNSEC_CHROOT_INITRD
64862 + bool "Exempt initrd tasks from restrictions"
64863 + default y if GRKERNSEC_CONFIG_AUTO
64864 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
64865 + help
64866 + If you say Y here, tasks started prior to init will be exempted from
64867 + grsecurity's chroot restrictions. This option is mainly meant to
64868 + resolve Plymouth's performing privileged operations unnecessarily
64869 + in a chroot.
64870 +
64871 +endmenu
64872 +menu "Kernel Auditing"
64873 +depends on GRKERNSEC
64874 +
64875 +config GRKERNSEC_AUDIT_GROUP
64876 + bool "Single group for auditing"
64877 + help
64878 + If you say Y here, the exec and chdir logging features will only operate
64879 + on a group you specify. This option is recommended if you only want to
64880 + watch certain users instead of having a large amount of logs from the
64881 + entire system. If the sysctl option is enabled, a sysctl option with
64882 + name "audit_group" is created.
64883 +
64884 +config GRKERNSEC_AUDIT_GID
64885 + int "GID for auditing"
64886 + depends on GRKERNSEC_AUDIT_GROUP
64887 + default 1007
64888 +
64889 +config GRKERNSEC_EXECLOG
64890 + bool "Exec logging"
64891 + help
64892 + If you say Y here, all execve() calls will be logged (since the
64893 + other exec*() calls are frontends to execve(), all execution
64894 + will be logged). Useful for shell-servers that like to keep track
64895 + of their users. If the sysctl option is enabled, a sysctl option with
64896 + name "exec_logging" is created.
64897 + WARNING: This option when enabled will produce a LOT of logs, especially
64898 + on an active system.
64899 +
64900 +config GRKERNSEC_RESLOG
64901 + bool "Resource logging"
64902 + default y if GRKERNSEC_CONFIG_AUTO
64903 + help
64904 + If you say Y here, all attempts to overstep resource limits will
64905 + be logged with the resource name, the requested size, and the current
64906 + limit. It is highly recommended that you say Y here. If the sysctl
64907 + option is enabled, a sysctl option with name "resource_logging" is
64908 + created. If the RBAC system is enabled, the sysctl value is ignored.
64909 +
64910 +config GRKERNSEC_CHROOT_EXECLOG
64911 + bool "Log execs within chroot"
64912 + help
64913 + If you say Y here, all executions inside a chroot jail will be logged
64914 + to syslog. This can cause a large amount of logs if certain
64915 + applications (eg. djb's daemontools) are installed on the system, and
64916 + is therefore left as an option. If the sysctl option is enabled, a
64917 + sysctl option with name "chroot_execlog" is created.
64918 +
64919 +config GRKERNSEC_AUDIT_PTRACE
64920 + bool "Ptrace logging"
64921 + help
64922 + If you say Y here, all attempts to attach to a process via ptrace
64923 + will be logged. If the sysctl option is enabled, a sysctl option
64924 + with name "audit_ptrace" is created.
64925 +
64926 +config GRKERNSEC_AUDIT_CHDIR
64927 + bool "Chdir logging"
64928 + help
64929 + If you say Y here, all chdir() calls will be logged. If the sysctl
64930 + option is enabled, a sysctl option with name "audit_chdir" is created.
64931 +
64932 +config GRKERNSEC_AUDIT_MOUNT
64933 + bool "(Un)Mount logging"
64934 + help
64935 + If you say Y here, all mounts and unmounts will be logged. If the
64936 + sysctl option is enabled, a sysctl option with name "audit_mount" is
64937 + created.
64938 +
64939 +config GRKERNSEC_SIGNAL
64940 + bool "Signal logging"
64941 + default y if GRKERNSEC_CONFIG_AUTO
64942 + help
64943 + If you say Y here, certain important signals will be logged, such as
64944 + SIGSEGV, which will as a result inform you of when a error in a program
64945 + occurred, which in some cases could mean a possible exploit attempt.
64946 + If the sysctl option is enabled, a sysctl option with name
64947 + "signal_logging" is created.
64948 +
64949 +config GRKERNSEC_FORKFAIL
64950 + bool "Fork failure logging"
64951 + help
64952 + If you say Y here, all failed fork() attempts will be logged.
64953 + This could suggest a fork bomb, or someone attempting to overstep
64954 + their process limit. If the sysctl option is enabled, a sysctl option
64955 + with name "forkfail_logging" is created.
64956 +
64957 +config GRKERNSEC_TIME
64958 + bool "Time change logging"
64959 + default y if GRKERNSEC_CONFIG_AUTO
64960 + help
64961 + If you say Y here, any changes of the system clock will be logged.
64962 + If the sysctl option is enabled, a sysctl option with name
64963 + "timechange_logging" is created.
64964 +
64965 +config GRKERNSEC_PROC_IPADDR
64966 + bool "/proc/<pid>/ipaddr support"
64967 + default y if GRKERNSEC_CONFIG_AUTO
64968 + help
64969 + If you say Y here, a new entry will be added to each /proc/<pid>
64970 + directory that contains the IP address of the person using the task.
64971 + The IP is carried across local TCP and AF_UNIX stream sockets.
64972 + This information can be useful for IDS/IPSes to perform remote response
64973 + to a local attack. The entry is readable by only the owner of the
64974 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
64975 + the RBAC system), and thus does not create privacy concerns.
64976 +
64977 +config GRKERNSEC_RWXMAP_LOG
64978 + bool 'Denied RWX mmap/mprotect logging'
64979 + default y if GRKERNSEC_CONFIG_AUTO
64980 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
64981 + help
64982 + If you say Y here, calls to mmap() and mprotect() with explicit
64983 + usage of PROT_WRITE and PROT_EXEC together will be logged when
64984 + denied by the PAX_MPROTECT feature. This feature will also
64985 + log other problematic scenarios that can occur when PAX_MPROTECT
64986 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
64987 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
64988 + is created.
64989 +
64990 +endmenu
64991 +
64992 +menu "Executable Protections"
64993 +depends on GRKERNSEC
64994 +
64995 +config GRKERNSEC_DMESG
64996 + bool "Dmesg(8) restriction"
64997 + default y if GRKERNSEC_CONFIG_AUTO
64998 + help
64999 + If you say Y here, non-root users will not be able to use dmesg(8)
65000 + to view the contents of the kernel's circular log buffer.
65001 + The kernel's log buffer often contains kernel addresses and other
65002 + identifying information useful to an attacker in fingerprinting a
65003 + system for a targeted exploit.
65004 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
65005 + created.
65006 +
65007 +config GRKERNSEC_HARDEN_PTRACE
65008 + bool "Deter ptrace-based process snooping"
65009 + default y if GRKERNSEC_CONFIG_AUTO
65010 + help
65011 + If you say Y here, TTY sniffers and other malicious monitoring
65012 + programs implemented through ptrace will be defeated. If you
65013 + have been using the RBAC system, this option has already been
65014 + enabled for several years for all users, with the ability to make
65015 + fine-grained exceptions.
65016 +
65017 + This option only affects the ability of non-root users to ptrace
65018 + processes that are not a descendent of the ptracing process.
65019 + This means that strace ./binary and gdb ./binary will still work,
65020 + but attaching to arbitrary processes will not. If the sysctl
65021 + option is enabled, a sysctl option with name "harden_ptrace" is
65022 + created.
65023 +
65024 +config GRKERNSEC_PTRACE_READEXEC
65025 + bool "Require read access to ptrace sensitive binaries"
65026 + default y if GRKERNSEC_CONFIG_AUTO
65027 + help
65028 + If you say Y here, unprivileged users will not be able to ptrace unreadable
65029 + binaries. This option is useful in environments that
65030 + remove the read bits (e.g. file mode 4711) from suid binaries to
65031 + prevent infoleaking of their contents. This option adds
65032 + consistency to the use of that file mode, as the binary could normally
65033 + be read out when run without privileges while ptracing.
65034 +
65035 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65036 + is created.
65037 +
65038 +config GRKERNSEC_SETXID
65039 + bool "Enforce consistent multithreaded privileges"
65040 + default y if GRKERNSEC_CONFIG_AUTO
65041 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65042 + help
65043 + If you say Y here, a change from a root uid to a non-root uid
65044 + in a multithreaded application will cause the resulting uids,
65045 + gids, supplementary groups, and capabilities in that thread
65046 + to be propagated to the other threads of the process. In most
65047 + cases this is unnecessary, as glibc will emulate this behavior
65048 + on behalf of the application. Other libcs do not act in the
65049 + same way, allowing the other threads of the process to continue
65050 + running with root privileges. If the sysctl option is enabled,
65051 + a sysctl option with name "consistent_setxid" is created.
65052 +
65053 +config GRKERNSEC_HARDEN_IPC
65054 + bool "Disallow access to overly-permissive IPC objects"
65055 + default y if GRKERNSEC_CONFIG_AUTO
65056 + depends on SYSVIPC
65057 + help
65058 + If you say Y here, access to overly-permissive IPC objects (shared
65059 + memory, message queues, and semaphores) will be denied for processes
65060 + given the following criteria beyond normal permission checks:
65061 + 1) If the IPC object is world-accessible and the euid doesn't match
65062 + that of the creator or current uid for the IPC object
65063 + 2) If the IPC object is group-accessible and the egid doesn't
65064 + match that of the creator or current gid for the IPC object
65065 + It's a common error to grant too much permission to these objects,
65066 + with impact ranging from denial of service and information leaking to
65067 + privilege escalation. This feature was developed in response to
65068 + research by Tim Brown:
65069 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
65070 + who found hundreds of such insecure usages. Processes with
65071 + CAP_IPC_OWNER are still permitted to access these IPC objects.
65072 + If the sysctl option is enabled, a sysctl option with name
65073 + "harden_ipc" is created.
65074 +
65075 +config GRKERNSEC_TPE
65076 + bool "Trusted Path Execution (TPE)"
65077 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65078 + help
65079 + If you say Y here, you will be able to choose a gid to add to the
65080 + supplementary groups of users you want to mark as "untrusted."
65081 + These users will not be able to execute any files that are not in
65082 + root-owned directories writable only by root. If the sysctl option
65083 + is enabled, a sysctl option with name "tpe" is created.
65084 +
65085 +config GRKERNSEC_TPE_ALL
65086 + bool "Partially restrict all non-root users"
65087 + depends on GRKERNSEC_TPE
65088 + help
65089 + If you say Y here, all non-root users will be covered under
65090 + a weaker TPE restriction. This is separate from, and in addition to,
65091 + the main TPE options that you have selected elsewhere. Thus, if a
65092 + "trusted" GID is chosen, this restriction applies to even that GID.
65093 + Under this restriction, all non-root users will only be allowed to
65094 + execute files in directories they own that are not group or
65095 + world-writable, or in directories owned by root and writable only by
65096 + root. If the sysctl option is enabled, a sysctl option with name
65097 + "tpe_restrict_all" is created.
65098 +
65099 +config GRKERNSEC_TPE_INVERT
65100 + bool "Invert GID option"
65101 + depends on GRKERNSEC_TPE
65102 + help
65103 + If you say Y here, the group you specify in the TPE configuration will
65104 + decide what group TPE restrictions will be *disabled* for. This
65105 + option is useful if you want TPE restrictions to be applied to most
65106 + users on the system. If the sysctl option is enabled, a sysctl option
65107 + with name "tpe_invert" is created. Unlike other sysctl options, this
65108 + entry will default to on for backward-compatibility.
65109 +
65110 +config GRKERNSEC_TPE_GID
65111 + int
65112 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65113 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65114 +
65115 +config GRKERNSEC_TPE_UNTRUSTED_GID
65116 + int "GID for TPE-untrusted users"
65117 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65118 + default 1005
65119 + help
65120 + Setting this GID determines what group TPE restrictions will be
65121 + *enabled* for. If the sysctl option is enabled, a sysctl option
65122 + with name "tpe_gid" is created.
65123 +
65124 +config GRKERNSEC_TPE_TRUSTED_GID
65125 + int "GID for TPE-trusted users"
65126 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65127 + default 1005
65128 + help
65129 + Setting this GID determines what group TPE restrictions will be
65130 + *disabled* for. If the sysctl option is enabled, a sysctl option
65131 + with name "tpe_gid" is created.
65132 +
65133 +endmenu
65134 +menu "Network Protections"
65135 +depends on GRKERNSEC
65136 +
65137 +config GRKERNSEC_RANDNET
65138 + bool "Larger entropy pools"
65139 + default y if GRKERNSEC_CONFIG_AUTO
65140 + help
65141 + If you say Y here, the entropy pools used for many features of Linux
65142 + and grsecurity will be doubled in size. Since several grsecurity
65143 + features use additional randomness, it is recommended that you say Y
65144 + here. Saying Y here has a similar effect as modifying
65145 + /proc/sys/kernel/random/poolsize.
65146 +
65147 +config GRKERNSEC_BLACKHOLE
65148 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
65149 + default y if GRKERNSEC_CONFIG_AUTO
65150 + depends on NET
65151 + help
65152 + If you say Y here, neither TCP resets nor ICMP
65153 + destination-unreachable packets will be sent in response to packets
65154 + sent to ports for which no associated listening process exists.
65155 + This feature supports both IPV4 and IPV6 and exempts the
65156 + loopback interface from blackholing. Enabling this feature
65157 + makes a host more resilient to DoS attacks and reduces network
65158 + visibility against scanners.
65159 +
65160 + The blackhole feature as-implemented is equivalent to the FreeBSD
65161 + blackhole feature, as it prevents RST responses to all packets, not
65162 + just SYNs. Under most application behavior this causes no
65163 + problems, but applications (like haproxy) may not close certain
65164 + connections in a way that cleanly terminates them on the remote
65165 + end, leaving the remote host in LAST_ACK state. Because of this
65166 + side-effect and to prevent intentional LAST_ACK DoSes, this
65167 + feature also adds automatic mitigation against such attacks.
65168 + The mitigation drastically reduces the amount of time a socket
65169 + can spend in LAST_ACK state. If you're using haproxy and not
65170 + all servers it connects to have this option enabled, consider
65171 + disabling this feature on the haproxy host.
65172 +
65173 + If the sysctl option is enabled, two sysctl options with names
65174 + "ip_blackhole" and "lastack_retries" will be created.
65175 + While "ip_blackhole" takes the standard zero/non-zero on/off
65176 + toggle, "lastack_retries" uses the same kinds of values as
65177 + "tcp_retries1" and "tcp_retries2". The default value of 4
65178 + prevents a socket from lasting more than 45 seconds in LAST_ACK
65179 + state.
65180 +
65181 +config GRKERNSEC_NO_SIMULT_CONNECT
65182 + bool "Disable TCP Simultaneous Connect"
65183 + default y if GRKERNSEC_CONFIG_AUTO
65184 + depends on NET
65185 + help
65186 + If you say Y here, a feature by Willy Tarreau will be enabled that
65187 + removes a weakness in Linux's strict implementation of TCP that
65188 + allows two clients to connect to each other without either entering
65189 + a listening state. The weakness allows an attacker to easily prevent
65190 + a client from connecting to a known server provided the source port
65191 + for the connection is guessed correctly.
65192 +
65193 + As the weakness could be used to prevent an antivirus or IPS from
65194 + fetching updates, or prevent an SSL gateway from fetching a CRL,
65195 + it should be eliminated by enabling this option. Though Linux is
65196 + one of few operating systems supporting simultaneous connect, it
65197 + has no legitimate use in practice and is rarely supported by firewalls.
65198 +
65199 +config GRKERNSEC_SOCKET
65200 + bool "Socket restrictions"
65201 + depends on NET
65202 + help
65203 + If you say Y here, you will be able to choose from several options.
65204 + If you assign a GID on your system and add it to the supplementary
65205 + groups of users you want to restrict socket access to, this patch
65206 + will perform up to three things, based on the option(s) you choose.
65207 +
65208 +config GRKERNSEC_SOCKET_ALL
65209 + bool "Deny any sockets to group"
65210 + depends on GRKERNSEC_SOCKET
65211 + help
65212 + If you say Y here, you will be able to choose a GID of whose users will
65213 + be unable to connect to other hosts from your machine or run server
65214 + applications from your machine. If the sysctl option is enabled, a
65215 + sysctl option with name "socket_all" is created.
65216 +
65217 +config GRKERNSEC_SOCKET_ALL_GID
65218 + int "GID to deny all sockets for"
65219 + depends on GRKERNSEC_SOCKET_ALL
65220 + default 1004
65221 + help
65222 + Here you can choose the GID to disable socket access for. Remember to
65223 + add the users you want socket access disabled for to the GID
65224 + specified here. If the sysctl option is enabled, a sysctl option
65225 + with name "socket_all_gid" is created.
65226 +
65227 +config GRKERNSEC_SOCKET_CLIENT
65228 + bool "Deny client sockets to group"
65229 + depends on GRKERNSEC_SOCKET
65230 + help
65231 + If you say Y here, you will be able to choose a GID of whose users will
65232 + be unable to connect to other hosts from your machine, but will be
65233 + able to run servers. If this option is enabled, all users in the group
65234 + you specify will have to use passive mode when initiating ftp transfers
65235 + from the shell on your machine. If the sysctl option is enabled, a
65236 + sysctl option with name "socket_client" is created.
65237 +
65238 +config GRKERNSEC_SOCKET_CLIENT_GID
65239 + int "GID to deny client sockets for"
65240 + depends on GRKERNSEC_SOCKET_CLIENT
65241 + default 1003
65242 + help
65243 + Here you can choose the GID to disable client socket access for.
65244 + Remember to add the users you want client socket access disabled for to
65245 + the GID specified here. If the sysctl option is enabled, a sysctl
65246 + option with name "socket_client_gid" is created.
65247 +
65248 +config GRKERNSEC_SOCKET_SERVER
65249 + bool "Deny server sockets to group"
65250 + depends on GRKERNSEC_SOCKET
65251 + help
65252 + If you say Y here, you will be able to choose a GID of whose users will
65253 + be unable to run server applications from your machine. If the sysctl
65254 + option is enabled, a sysctl option with name "socket_server" is created.
65255 +
65256 +config GRKERNSEC_SOCKET_SERVER_GID
65257 + int "GID to deny server sockets for"
65258 + depends on GRKERNSEC_SOCKET_SERVER
65259 + default 1002
65260 + help
65261 + Here you can choose the GID to disable server socket access for.
65262 + Remember to add the users you want server socket access disabled for to
65263 + the GID specified here. If the sysctl option is enabled, a sysctl
65264 + option with name "socket_server_gid" is created.
65265 +
65266 +endmenu
65267 +
65268 +menu "Physical Protections"
65269 +depends on GRKERNSEC
65270 +
65271 +config GRKERNSEC_DENYUSB
65272 + bool "Deny new USB connections after toggle"
65273 + default y if GRKERNSEC_CONFIG_AUTO
65274 + depends on SYSCTL && USB_SUPPORT
65275 + help
65276 + If you say Y here, a new sysctl option with name "deny_new_usb"
65277 + will be created. Setting its value to 1 will prevent any new
65278 + USB devices from being recognized by the OS. Any attempted USB
65279 + device insertion will be logged. This option is intended to be
65280 + used against custom USB devices designed to exploit vulnerabilities
65281 + in various USB device drivers.
65282 +
65283 + For greatest effectiveness, this sysctl should be set after any
65284 + relevant init scripts. This option is safe to enable in distros
65285 + as each user can choose whether or not to toggle the sysctl.
65286 +
65287 +config GRKERNSEC_DENYUSB_FORCE
65288 + bool "Reject all USB devices not connected at boot"
65289 + select USB
65290 + depends on GRKERNSEC_DENYUSB
65291 + help
65292 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
65293 + that doesn't involve a sysctl entry. This option should only be
65294 + enabled if you're sure you want to deny all new USB connections
65295 + at runtime and don't want to modify init scripts. This should not
65296 + be enabled by distros. It forces the core USB code to be built
65297 + into the kernel image so that all devices connected at boot time
65298 + can be recognized and new USB device connections can be prevented
65299 + prior to init running.
65300 +
65301 +endmenu
65302 +
65303 +menu "Sysctl Support"
65304 +depends on GRKERNSEC && SYSCTL
65305 +
65306 +config GRKERNSEC_SYSCTL
65307 + bool "Sysctl support"
65308 + default y if GRKERNSEC_CONFIG_AUTO
65309 + help
65310 + If you say Y here, you will be able to change the options that
65311 + grsecurity runs with at bootup, without having to recompile your
65312 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
65313 + to enable (1) or disable (0) various features. All the sysctl entries
65314 + are mutable until the "grsec_lock" entry is set to a non-zero value.
65315 + All features enabled in the kernel configuration are disabled at boot
65316 + if you do not say Y to the "Turn on features by default" option.
65317 + All options should be set at startup, and the grsec_lock entry should
65318 + be set to a non-zero value after all the options are set.
65319 + *THIS IS EXTREMELY IMPORTANT*
65320 +
65321 +config GRKERNSEC_SYSCTL_DISTRO
65322 + bool "Extra sysctl support for distro makers (READ HELP)"
65323 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
65324 + help
65325 + If you say Y here, additional sysctl options will be created
65326 + for features that affect processes running as root. Therefore,
65327 + it is critical when using this option that the grsec_lock entry be
65328 + enabled after boot. Only distros with prebuilt kernel packages
65329 + with this option enabled that can ensure grsec_lock is enabled
65330 + after boot should use this option.
65331 + *Failure to set grsec_lock after boot makes all grsec features
65332 + this option covers useless*
65333 +
65334 + Currently this option creates the following sysctl entries:
65335 + "Disable Privileged I/O": "disable_priv_io"
65336 +
65337 +config GRKERNSEC_SYSCTL_ON
65338 + bool "Turn on features by default"
65339 + default y if GRKERNSEC_CONFIG_AUTO
65340 + depends on GRKERNSEC_SYSCTL
65341 + help
65342 + If you say Y here, instead of having all features enabled in the
65343 + kernel configuration disabled at boot time, the features will be
65344 + enabled at boot time. It is recommended you say Y here unless
65345 + there is some reason you would want all sysctl-tunable features to
65346 + be disabled by default. As mentioned elsewhere, it is important
65347 + to enable the grsec_lock entry once you have finished modifying
65348 + the sysctl entries.
65349 +
65350 +endmenu
65351 +menu "Logging Options"
65352 +depends on GRKERNSEC
65353 +
65354 +config GRKERNSEC_FLOODTIME
65355 + int "Seconds in between log messages (minimum)"
65356 + default 10
65357 + help
65358 + This option allows you to enforce the number of seconds between
65359 + grsecurity log messages. The default should be suitable for most
65360 + people, however, if you choose to change it, choose a value small enough
65361 + to allow informative logs to be produced, but large enough to
65362 + prevent flooding.
65363 +
65364 +config GRKERNSEC_FLOODBURST
65365 + int "Number of messages in a burst (maximum)"
65366 + default 6
65367 + help
65368 + This option allows you to choose the maximum number of messages allowed
65369 + within the flood time interval you chose in a separate option. The
65370 + default should be suitable for most people, however if you find that
65371 + many of your logs are being interpreted as flooding, you may want to
65372 + raise this value.
65373 +
65374 +endmenu
65375 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
65376 new file mode 100644
65377 index 0000000..5307c8a
65378 --- /dev/null
65379 +++ b/grsecurity/Makefile
65380 @@ -0,0 +1,54 @@
65381 +# grsecurity – access control and security hardening for Linux
65382 +# All code in this directory and various hooks located throughout the Linux kernel are
65383 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
65384 +# http://www.grsecurity.net spender@grsecurity.net
65385 +#
65386 +# This program is free software; you can redistribute it and/or
65387 +# modify it under the terms of the GNU General Public License version 2
65388 +# as published by the Free Software Foundation.
65389 +#
65390 +# This program is distributed in the hope that it will be useful,
65391 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
65392 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65393 +# GNU General Public License for more details.
65394 +#
65395 +# You should have received a copy of the GNU General Public License
65396 +# along with this program; if not, write to the Free Software
65397 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
65398 +
65399 +KBUILD_CFLAGS += -Werror
65400 +
65401 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
65402 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
65403 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
65404 + grsec_usb.o grsec_ipc.o
65405 +
65406 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
65407 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
65408 + gracl_learn.o grsec_log.o gracl_policy.o
65409 +ifdef CONFIG_COMPAT
65410 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
65411 +endif
65412 +
65413 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
65414 +
65415 +ifdef CONFIG_NET
65416 +obj-y += grsec_sock.o
65417 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
65418 +endif
65419 +
65420 +ifndef CONFIG_GRKERNSEC
65421 +obj-y += grsec_disabled.o
65422 +endif
65423 +
65424 +ifdef CONFIG_GRKERNSEC_HIDESYM
65425 +extra-y := grsec_hidesym.o
65426 +$(obj)/grsec_hidesym.o:
65427 + @-chmod -f 500 /boot
65428 + @-chmod -f 500 /lib/modules
65429 + @-chmod -f 500 /lib64/modules
65430 + @-chmod -f 500 /lib32/modules
65431 + @-chmod -f 700 .
65432 + @-chmod -f 700 $(objtree)
65433 + @echo ' grsec: protected kernel image paths'
65434 +endif
65435 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
65436 new file mode 100644
65437 index 0000000..19a5b7c
65438 --- /dev/null
65439 +++ b/grsecurity/gracl.c
65440 @@ -0,0 +1,2678 @@
65441 +#include <linux/kernel.h>
65442 +#include <linux/module.h>
65443 +#include <linux/sched.h>
65444 +#include <linux/mm.h>
65445 +#include <linux/file.h>
65446 +#include <linux/fs.h>
65447 +#include <linux/namei.h>
65448 +#include <linux/mount.h>
65449 +#include <linux/tty.h>
65450 +#include <linux/proc_fs.h>
65451 +#include <linux/lglock.h>
65452 +#include <linux/slab.h>
65453 +#include <linux/vmalloc.h>
65454 +#include <linux/types.h>
65455 +#include <linux/sysctl.h>
65456 +#include <linux/netdevice.h>
65457 +#include <linux/ptrace.h>
65458 +#include <linux/gracl.h>
65459 +#include <linux/gralloc.h>
65460 +#include <linux/security.h>
65461 +#include <linux/grinternal.h>
65462 +#include <linux/pid_namespace.h>
65463 +#include <linux/stop_machine.h>
65464 +#include <linux/fdtable.h>
65465 +#include <linux/percpu.h>
65466 +#include <linux/lglock.h>
65467 +#include <linux/hugetlb.h>
65468 +#include <linux/posix-timers.h>
65469 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65470 +#include <linux/magic.h>
65471 +#include <linux/pagemap.h>
65472 +#include "../fs/btrfs/async-thread.h"
65473 +#include "../fs/btrfs/ctree.h"
65474 +#include "../fs/btrfs/btrfs_inode.h"
65475 +#endif
65476 +#include "../fs/mount.h"
65477 +
65478 +#include <asm/uaccess.h>
65479 +#include <asm/errno.h>
65480 +#include <asm/mman.h>
65481 +
65482 +#define FOR_EACH_ROLE_START(role) \
65483 + role = running_polstate.role_list; \
65484 + while (role) {
65485 +
65486 +#define FOR_EACH_ROLE_END(role) \
65487 + role = role->prev; \
65488 + }
65489 +
65490 +extern struct path gr_real_root;
65491 +
65492 +static struct gr_policy_state running_polstate;
65493 +struct gr_policy_state *polstate = &running_polstate;
65494 +extern struct gr_alloc_state *current_alloc_state;
65495 +
65496 +extern char *gr_shared_page[4];
65497 +DEFINE_RWLOCK(gr_inode_lock);
65498 +
65499 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
65500 +
65501 +#ifdef CONFIG_NET
65502 +extern struct vfsmount *sock_mnt;
65503 +#endif
65504 +
65505 +extern struct vfsmount *pipe_mnt;
65506 +extern struct vfsmount *shm_mnt;
65507 +
65508 +#ifdef CONFIG_HUGETLBFS
65509 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65510 +#endif
65511 +
65512 +extern u16 acl_sp_role_value;
65513 +extern struct acl_object_label *fakefs_obj_rw;
65514 +extern struct acl_object_label *fakefs_obj_rwx;
65515 +
65516 +int gr_acl_is_enabled(void)
65517 +{
65518 + return (gr_status & GR_READY);
65519 +}
65520 +
65521 +void gr_enable_rbac_system(void)
65522 +{
65523 + pax_open_kernel();
65524 + gr_status |= GR_READY;
65525 + pax_close_kernel();
65526 +}
65527 +
65528 +int gr_rbac_disable(void *unused)
65529 +{
65530 + pax_open_kernel();
65531 + gr_status &= ~GR_READY;
65532 + pax_close_kernel();
65533 +
65534 + return 0;
65535 +}
65536 +
65537 +static inline dev_t __get_dev(const struct dentry *dentry)
65538 +{
65539 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65540 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
65541 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
65542 + else
65543 +#endif
65544 + return dentry->d_sb->s_dev;
65545 +}
65546 +
65547 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65548 +{
65549 + return __get_dev(dentry);
65550 +}
65551 +
65552 +static char gr_task_roletype_to_char(struct task_struct *task)
65553 +{
65554 + switch (task->role->roletype &
65555 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
65556 + GR_ROLE_SPECIAL)) {
65557 + case GR_ROLE_DEFAULT:
65558 + return 'D';
65559 + case GR_ROLE_USER:
65560 + return 'U';
65561 + case GR_ROLE_GROUP:
65562 + return 'G';
65563 + case GR_ROLE_SPECIAL:
65564 + return 'S';
65565 + }
65566 +
65567 + return 'X';
65568 +}
65569 +
65570 +char gr_roletype_to_char(void)
65571 +{
65572 + return gr_task_roletype_to_char(current);
65573 +}
65574 +
65575 +__inline__ int
65576 +gr_acl_tpe_check(void)
65577 +{
65578 + if (unlikely(!(gr_status & GR_READY)))
65579 + return 0;
65580 + if (current->role->roletype & GR_ROLE_TPE)
65581 + return 1;
65582 + else
65583 + return 0;
65584 +}
65585 +
65586 +int
65587 +gr_handle_rawio(const struct inode *inode)
65588 +{
65589 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65590 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
65591 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
65592 + !capable(CAP_SYS_RAWIO))
65593 + return 1;
65594 +#endif
65595 + return 0;
65596 +}
65597 +
65598 +int
65599 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
65600 +{
65601 + if (likely(lena != lenb))
65602 + return 0;
65603 +
65604 + return !memcmp(a, b, lena);
65605 +}
65606 +
65607 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
65608 +{
65609 + *buflen -= namelen;
65610 + if (*buflen < 0)
65611 + return -ENAMETOOLONG;
65612 + *buffer -= namelen;
65613 + memcpy(*buffer, str, namelen);
65614 + return 0;
65615 +}
65616 +
65617 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
65618 +{
65619 + return prepend(buffer, buflen, name->name, name->len);
65620 +}
65621 +
65622 +static int prepend_path(const struct path *path, struct path *root,
65623 + char **buffer, int *buflen)
65624 +{
65625 + struct dentry *dentry = path->dentry;
65626 + struct vfsmount *vfsmnt = path->mnt;
65627 + struct mount *mnt = real_mount(vfsmnt);
65628 + bool slash = false;
65629 + int error = 0;
65630 +
65631 + while (dentry != root->dentry || vfsmnt != root->mnt) {
65632 + struct dentry * parent;
65633 +
65634 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
65635 + /* Global root? */
65636 + if (!mnt_has_parent(mnt)) {
65637 + goto out;
65638 + }
65639 + dentry = mnt->mnt_mountpoint;
65640 + mnt = mnt->mnt_parent;
65641 + vfsmnt = &mnt->mnt;
65642 + continue;
65643 + }
65644 + parent = dentry->d_parent;
65645 + prefetch(parent);
65646 + spin_lock(&dentry->d_lock);
65647 + error = prepend_name(buffer, buflen, &dentry->d_name);
65648 + spin_unlock(&dentry->d_lock);
65649 + if (!error)
65650 + error = prepend(buffer, buflen, "/", 1);
65651 + if (error)
65652 + break;
65653 +
65654 + slash = true;
65655 + dentry = parent;
65656 + }
65657 +
65658 +out:
65659 + if (!error && !slash)
65660 + error = prepend(buffer, buflen, "/", 1);
65661 +
65662 + return error;
65663 +}
65664 +
65665 +/* this must be called with mount_lock and rename_lock held */
65666 +
65667 +static char *__our_d_path(const struct path *path, struct path *root,
65668 + char *buf, int buflen)
65669 +{
65670 + char *res = buf + buflen;
65671 + int error;
65672 +
65673 + prepend(&res, &buflen, "\0", 1);
65674 + error = prepend_path(path, root, &res, &buflen);
65675 + if (error)
65676 + return ERR_PTR(error);
65677 +
65678 + return res;
65679 +}
65680 +
65681 +static char *
65682 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
65683 +{
65684 + char *retval;
65685 +
65686 + retval = __our_d_path(path, root, buf, buflen);
65687 + if (unlikely(IS_ERR(retval)))
65688 + retval = strcpy(buf, "<path too long>");
65689 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
65690 + retval[1] = '\0';
65691 +
65692 + return retval;
65693 +}
65694 +
65695 +static char *
65696 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65697 + char *buf, int buflen)
65698 +{
65699 + struct path path;
65700 + char *res;
65701 +
65702 + path.dentry = (struct dentry *)dentry;
65703 + path.mnt = (struct vfsmount *)vfsmnt;
65704 +
65705 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
65706 + by the RBAC system */
65707 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
65708 +
65709 + return res;
65710 +}
65711 +
65712 +static char *
65713 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65714 + char *buf, int buflen)
65715 +{
65716 + char *res;
65717 + struct path path;
65718 + struct path root;
65719 + struct task_struct *reaper = init_pid_ns.child_reaper;
65720 +
65721 + path.dentry = (struct dentry *)dentry;
65722 + path.mnt = (struct vfsmount *)vfsmnt;
65723 +
65724 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
65725 + get_fs_root(reaper->fs, &root);
65726 +
65727 + read_seqlock_excl(&mount_lock);
65728 + write_seqlock(&rename_lock);
65729 + res = gen_full_path(&path, &root, buf, buflen);
65730 + write_sequnlock(&rename_lock);
65731 + read_sequnlock_excl(&mount_lock);
65732 +
65733 + path_put(&root);
65734 + return res;
65735 +}
65736 +
65737 +char *
65738 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65739 +{
65740 + char *ret;
65741 + read_seqlock_excl(&mount_lock);
65742 + write_seqlock(&rename_lock);
65743 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65744 + PAGE_SIZE);
65745 + write_sequnlock(&rename_lock);
65746 + read_sequnlock_excl(&mount_lock);
65747 + return ret;
65748 +}
65749 +
65750 +static char *
65751 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65752 +{
65753 + char *ret;
65754 + char *buf;
65755 + int buflen;
65756 +
65757 + read_seqlock_excl(&mount_lock);
65758 + write_seqlock(&rename_lock);
65759 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
65760 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
65761 + buflen = (int)(ret - buf);
65762 + if (buflen >= 5)
65763 + prepend(&ret, &buflen, "/proc", 5);
65764 + else
65765 + ret = strcpy(buf, "<path too long>");
65766 + write_sequnlock(&rename_lock);
65767 + read_sequnlock_excl(&mount_lock);
65768 + return ret;
65769 +}
65770 +
65771 +char *
65772 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
65773 +{
65774 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65775 + PAGE_SIZE);
65776 +}
65777 +
65778 +char *
65779 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
65780 +{
65781 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65782 + PAGE_SIZE);
65783 +}
65784 +
65785 +char *
65786 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
65787 +{
65788 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
65789 + PAGE_SIZE);
65790 +}
65791 +
65792 +char *
65793 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
65794 +{
65795 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
65796 + PAGE_SIZE);
65797 +}
65798 +
65799 +char *
65800 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
65801 +{
65802 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
65803 + PAGE_SIZE);
65804 +}
65805 +
65806 +__inline__ __u32
65807 +to_gr_audit(const __u32 reqmode)
65808 +{
65809 + /* masks off auditable permission flags, then shifts them to create
65810 + auditing flags, and adds the special case of append auditing if
65811 + we're requesting write */
65812 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
65813 +}
65814 +
65815 +struct acl_role_label *
65816 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
65817 + const gid_t gid)
65818 +{
65819 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
65820 + struct acl_role_label *match;
65821 + struct role_allowed_ip *ipp;
65822 + unsigned int x;
65823 + u32 curr_ip = task->signal->saved_ip;
65824 +
65825 + match = state->acl_role_set.r_hash[index];
65826 +
65827 + while (match) {
65828 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
65829 + for (x = 0; x < match->domain_child_num; x++) {
65830 + if (match->domain_children[x] == uid)
65831 + goto found;
65832 + }
65833 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
65834 + break;
65835 + match = match->next;
65836 + }
65837 +found:
65838 + if (match == NULL) {
65839 + try_group:
65840 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
65841 + match = state->acl_role_set.r_hash[index];
65842 +
65843 + while (match) {
65844 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
65845 + for (x = 0; x < match->domain_child_num; x++) {
65846 + if (match->domain_children[x] == gid)
65847 + goto found2;
65848 + }
65849 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
65850 + break;
65851 + match = match->next;
65852 + }
65853 +found2:
65854 + if (match == NULL)
65855 + match = state->default_role;
65856 + if (match->allowed_ips == NULL)
65857 + return match;
65858 + else {
65859 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65860 + if (likely
65861 + ((ntohl(curr_ip) & ipp->netmask) ==
65862 + (ntohl(ipp->addr) & ipp->netmask)))
65863 + return match;
65864 + }
65865 + match = state->default_role;
65866 + }
65867 + } else if (match->allowed_ips == NULL) {
65868 + return match;
65869 + } else {
65870 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65871 + if (likely
65872 + ((ntohl(curr_ip) & ipp->netmask) ==
65873 + (ntohl(ipp->addr) & ipp->netmask)))
65874 + return match;
65875 + }
65876 + goto try_group;
65877 + }
65878 +
65879 + return match;
65880 +}
65881 +
65882 +static struct acl_role_label *
65883 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
65884 + const gid_t gid)
65885 +{
65886 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
65887 +}
65888 +
65889 +struct acl_subject_label *
65890 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
65891 + const struct acl_role_label *role)
65892 +{
65893 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65894 + struct acl_subject_label *match;
65895 +
65896 + match = role->subj_hash[index];
65897 +
65898 + while (match && (match->inode != ino || match->device != dev ||
65899 + (match->mode & GR_DELETED))) {
65900 + match = match->next;
65901 + }
65902 +
65903 + if (match && !(match->mode & GR_DELETED))
65904 + return match;
65905 + else
65906 + return NULL;
65907 +}
65908 +
65909 +struct acl_subject_label *
65910 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
65911 + const struct acl_role_label *role)
65912 +{
65913 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65914 + struct acl_subject_label *match;
65915 +
65916 + match = role->subj_hash[index];
65917 +
65918 + while (match && (match->inode != ino || match->device != dev ||
65919 + !(match->mode & GR_DELETED))) {
65920 + match = match->next;
65921 + }
65922 +
65923 + if (match && (match->mode & GR_DELETED))
65924 + return match;
65925 + else
65926 + return NULL;
65927 +}
65928 +
65929 +static struct acl_object_label *
65930 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
65931 + const struct acl_subject_label *subj)
65932 +{
65933 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65934 + struct acl_object_label *match;
65935 +
65936 + match = subj->obj_hash[index];
65937 +
65938 + while (match && (match->inode != ino || match->device != dev ||
65939 + (match->mode & GR_DELETED))) {
65940 + match = match->next;
65941 + }
65942 +
65943 + if (match && !(match->mode & GR_DELETED))
65944 + return match;
65945 + else
65946 + return NULL;
65947 +}
65948 +
65949 +static struct acl_object_label *
65950 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
65951 + const struct acl_subject_label *subj)
65952 +{
65953 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65954 + struct acl_object_label *match;
65955 +
65956 + match = subj->obj_hash[index];
65957 +
65958 + while (match && (match->inode != ino || match->device != dev ||
65959 + !(match->mode & GR_DELETED))) {
65960 + match = match->next;
65961 + }
65962 +
65963 + if (match && (match->mode & GR_DELETED))
65964 + return match;
65965 +
65966 + match = subj->obj_hash[index];
65967 +
65968 + while (match && (match->inode != ino || match->device != dev ||
65969 + (match->mode & GR_DELETED))) {
65970 + match = match->next;
65971 + }
65972 +
65973 + if (match && !(match->mode & GR_DELETED))
65974 + return match;
65975 + else
65976 + return NULL;
65977 +}
65978 +
65979 +struct name_entry *
65980 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
65981 +{
65982 + unsigned int len = strlen(name);
65983 + unsigned int key = full_name_hash(name, len);
65984 + unsigned int index = key % state->name_set.n_size;
65985 + struct name_entry *match;
65986 +
65987 + match = state->name_set.n_hash[index];
65988 +
65989 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
65990 + match = match->next;
65991 +
65992 + return match;
65993 +}
65994 +
65995 +static struct name_entry *
65996 +lookup_name_entry(const char *name)
65997 +{
65998 + return __lookup_name_entry(&running_polstate, name);
65999 +}
66000 +
66001 +static struct name_entry *
66002 +lookup_name_entry_create(const char *name)
66003 +{
66004 + unsigned int len = strlen(name);
66005 + unsigned int key = full_name_hash(name, len);
66006 + unsigned int index = key % running_polstate.name_set.n_size;
66007 + struct name_entry *match;
66008 +
66009 + match = running_polstate.name_set.n_hash[index];
66010 +
66011 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66012 + !match->deleted))
66013 + match = match->next;
66014 +
66015 + if (match && match->deleted)
66016 + return match;
66017 +
66018 + match = running_polstate.name_set.n_hash[index];
66019 +
66020 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66021 + match->deleted))
66022 + match = match->next;
66023 +
66024 + if (match && !match->deleted)
66025 + return match;
66026 + else
66027 + return NULL;
66028 +}
66029 +
66030 +static struct inodev_entry *
66031 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
66032 +{
66033 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66034 + struct inodev_entry *match;
66035 +
66036 + match = running_polstate.inodev_set.i_hash[index];
66037 +
66038 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66039 + match = match->next;
66040 +
66041 + return match;
66042 +}
66043 +
66044 +void
66045 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66046 +{
66047 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66048 + state->inodev_set.i_size);
66049 + struct inodev_entry **curr;
66050 +
66051 + entry->prev = NULL;
66052 +
66053 + curr = &state->inodev_set.i_hash[index];
66054 + if (*curr != NULL)
66055 + (*curr)->prev = entry;
66056 +
66057 + entry->next = *curr;
66058 + *curr = entry;
66059 +
66060 + return;
66061 +}
66062 +
66063 +static void
66064 +insert_inodev_entry(struct inodev_entry *entry)
66065 +{
66066 + __insert_inodev_entry(&running_polstate, entry);
66067 +}
66068 +
66069 +void
66070 +insert_acl_obj_label(struct acl_object_label *obj,
66071 + struct acl_subject_label *subj)
66072 +{
66073 + unsigned int index =
66074 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
66075 + struct acl_object_label **curr;
66076 +
66077 + obj->prev = NULL;
66078 +
66079 + curr = &subj->obj_hash[index];
66080 + if (*curr != NULL)
66081 + (*curr)->prev = obj;
66082 +
66083 + obj->next = *curr;
66084 + *curr = obj;
66085 +
66086 + return;
66087 +}
66088 +
66089 +void
66090 +insert_acl_subj_label(struct acl_subject_label *obj,
66091 + struct acl_role_label *role)
66092 +{
66093 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
66094 + struct acl_subject_label **curr;
66095 +
66096 + obj->prev = NULL;
66097 +
66098 + curr = &role->subj_hash[index];
66099 + if (*curr != NULL)
66100 + (*curr)->prev = obj;
66101 +
66102 + obj->next = *curr;
66103 + *curr = obj;
66104 +
66105 + return;
66106 +}
66107 +
66108 +/* derived from glibc fnmatch() 0: match, 1: no match*/
66109 +
66110 +static int
66111 +glob_match(const char *p, const char *n)
66112 +{
66113 + char c;
66114 +
66115 + while ((c = *p++) != '\0') {
66116 + switch (c) {
66117 + case '?':
66118 + if (*n == '\0')
66119 + return 1;
66120 + else if (*n == '/')
66121 + return 1;
66122 + break;
66123 + case '\\':
66124 + if (*n != c)
66125 + return 1;
66126 + break;
66127 + case '*':
66128 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
66129 + if (*n == '/')
66130 + return 1;
66131 + else if (c == '?') {
66132 + if (*n == '\0')
66133 + return 1;
66134 + else
66135 + ++n;
66136 + }
66137 + }
66138 + if (c == '\0') {
66139 + return 0;
66140 + } else {
66141 + const char *endp;
66142 +
66143 + if ((endp = strchr(n, '/')) == NULL)
66144 + endp = n + strlen(n);
66145 +
66146 + if (c == '[') {
66147 + for (--p; n < endp; ++n)
66148 + if (!glob_match(p, n))
66149 + return 0;
66150 + } else if (c == '/') {
66151 + while (*n != '\0' && *n != '/')
66152 + ++n;
66153 + if (*n == '/' && !glob_match(p, n + 1))
66154 + return 0;
66155 + } else {
66156 + for (--p; n < endp; ++n)
66157 + if (*n == c && !glob_match(p, n))
66158 + return 0;
66159 + }
66160 +
66161 + return 1;
66162 + }
66163 + case '[':
66164 + {
66165 + int not;
66166 + char cold;
66167 +
66168 + if (*n == '\0' || *n == '/')
66169 + return 1;
66170 +
66171 + not = (*p == '!' || *p == '^');
66172 + if (not)
66173 + ++p;
66174 +
66175 + c = *p++;
66176 + for (;;) {
66177 + unsigned char fn = (unsigned char)*n;
66178 +
66179 + if (c == '\0')
66180 + return 1;
66181 + else {
66182 + if (c == fn)
66183 + goto matched;
66184 + cold = c;
66185 + c = *p++;
66186 +
66187 + if (c == '-' && *p != ']') {
66188 + unsigned char cend = *p++;
66189 +
66190 + if (cend == '\0')
66191 + return 1;
66192 +
66193 + if (cold <= fn && fn <= cend)
66194 + goto matched;
66195 +
66196 + c = *p++;
66197 + }
66198 + }
66199 +
66200 + if (c == ']')
66201 + break;
66202 + }
66203 + if (!not)
66204 + return 1;
66205 + break;
66206 + matched:
66207 + while (c != ']') {
66208 + if (c == '\0')
66209 + return 1;
66210 +
66211 + c = *p++;
66212 + }
66213 + if (not)
66214 + return 1;
66215 + }
66216 + break;
66217 + default:
66218 + if (c != *n)
66219 + return 1;
66220 + }
66221 +
66222 + ++n;
66223 + }
66224 +
66225 + if (*n == '\0')
66226 + return 0;
66227 +
66228 + if (*n == '/')
66229 + return 0;
66230 +
66231 + return 1;
66232 +}
66233 +
66234 +static struct acl_object_label *
66235 +chk_glob_label(struct acl_object_label *globbed,
66236 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
66237 +{
66238 + struct acl_object_label *tmp;
66239 +
66240 + if (*path == NULL)
66241 + *path = gr_to_filename_nolock(dentry, mnt);
66242 +
66243 + tmp = globbed;
66244 +
66245 + while (tmp) {
66246 + if (!glob_match(tmp->filename, *path))
66247 + return tmp;
66248 + tmp = tmp->next;
66249 + }
66250 +
66251 + return NULL;
66252 +}
66253 +
66254 +static struct acl_object_label *
66255 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66256 + const ino_t curr_ino, const dev_t curr_dev,
66257 + const struct acl_subject_label *subj, char **path, const int checkglob)
66258 +{
66259 + struct acl_subject_label *tmpsubj;
66260 + struct acl_object_label *retval;
66261 + struct acl_object_label *retval2;
66262 +
66263 + tmpsubj = (struct acl_subject_label *) subj;
66264 + read_lock(&gr_inode_lock);
66265 + do {
66266 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
66267 + if (retval) {
66268 + if (checkglob && retval->globbed) {
66269 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
66270 + if (retval2)
66271 + retval = retval2;
66272 + }
66273 + break;
66274 + }
66275 + } while ((tmpsubj = tmpsubj->parent_subject));
66276 + read_unlock(&gr_inode_lock);
66277 +
66278 + return retval;
66279 +}
66280 +
66281 +static __inline__ struct acl_object_label *
66282 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66283 + struct dentry *curr_dentry,
66284 + const struct acl_subject_label *subj, char **path, const int checkglob)
66285 +{
66286 + int newglob = checkglob;
66287 + ino_t inode;
66288 + dev_t device;
66289 +
66290 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
66291 + as we don't want a / * rule to match instead of the / object
66292 + don't do this for create lookups that call this function though, since they're looking up
66293 + on the parent and thus need globbing checks on all paths
66294 + */
66295 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
66296 + newglob = GR_NO_GLOB;
66297 +
66298 + spin_lock(&curr_dentry->d_lock);
66299 + inode = curr_dentry->d_inode->i_ino;
66300 + device = __get_dev(curr_dentry);
66301 + spin_unlock(&curr_dentry->d_lock);
66302 +
66303 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
66304 +}
66305 +
66306 +#ifdef CONFIG_HUGETLBFS
66307 +static inline bool
66308 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
66309 +{
66310 + int i;
66311 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
66312 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
66313 + return true;
66314 + }
66315 +
66316 + return false;
66317 +}
66318 +#endif
66319 +
66320 +static struct acl_object_label *
66321 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66322 + const struct acl_subject_label *subj, char *path, const int checkglob)
66323 +{
66324 + struct dentry *dentry = (struct dentry *) l_dentry;
66325 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66326 + struct mount *real_mnt = real_mount(mnt);
66327 + struct acl_object_label *retval;
66328 + struct dentry *parent;
66329 +
66330 + read_seqlock_excl(&mount_lock);
66331 + write_seqlock(&rename_lock);
66332 +
66333 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
66334 +#ifdef CONFIG_NET
66335 + mnt == sock_mnt ||
66336 +#endif
66337 +#ifdef CONFIG_HUGETLBFS
66338 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
66339 +#endif
66340 + /* ignore Eric Biederman */
66341 + IS_PRIVATE(l_dentry->d_inode))) {
66342 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
66343 + goto out;
66344 + }
66345 +
66346 + for (;;) {
66347 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66348 + break;
66349 +
66350 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66351 + if (!mnt_has_parent(real_mnt))
66352 + break;
66353 +
66354 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66355 + if (retval != NULL)
66356 + goto out;
66357 +
66358 + dentry = real_mnt->mnt_mountpoint;
66359 + real_mnt = real_mnt->mnt_parent;
66360 + mnt = &real_mnt->mnt;
66361 + continue;
66362 + }
66363 +
66364 + parent = dentry->d_parent;
66365 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66366 + if (retval != NULL)
66367 + goto out;
66368 +
66369 + dentry = parent;
66370 + }
66371 +
66372 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66373 +
66374 + /* gr_real_root is pinned so we don't have to hold a reference */
66375 + if (retval == NULL)
66376 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
66377 +out:
66378 + write_sequnlock(&rename_lock);
66379 + read_sequnlock_excl(&mount_lock);
66380 +
66381 + BUG_ON(retval == NULL);
66382 +
66383 + return retval;
66384 +}
66385 +
66386 +static __inline__ struct acl_object_label *
66387 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66388 + const struct acl_subject_label *subj)
66389 +{
66390 + char *path = NULL;
66391 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
66392 +}
66393 +
66394 +static __inline__ struct acl_object_label *
66395 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66396 + const struct acl_subject_label *subj)
66397 +{
66398 + char *path = NULL;
66399 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
66400 +}
66401 +
66402 +static __inline__ struct acl_object_label *
66403 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66404 + const struct acl_subject_label *subj, char *path)
66405 +{
66406 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
66407 +}
66408 +
66409 +struct acl_subject_label *
66410 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66411 + const struct acl_role_label *role)
66412 +{
66413 + struct dentry *dentry = (struct dentry *) l_dentry;
66414 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66415 + struct mount *real_mnt = real_mount(mnt);
66416 + struct acl_subject_label *retval;
66417 + struct dentry *parent;
66418 +
66419 + read_seqlock_excl(&mount_lock);
66420 + write_seqlock(&rename_lock);
66421 +
66422 + for (;;) {
66423 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66424 + break;
66425 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66426 + if (!mnt_has_parent(real_mnt))
66427 + break;
66428 +
66429 + spin_lock(&dentry->d_lock);
66430 + read_lock(&gr_inode_lock);
66431 + retval =
66432 + lookup_acl_subj_label(dentry->d_inode->i_ino,
66433 + __get_dev(dentry), role);
66434 + read_unlock(&gr_inode_lock);
66435 + spin_unlock(&dentry->d_lock);
66436 + if (retval != NULL)
66437 + goto out;
66438 +
66439 + dentry = real_mnt->mnt_mountpoint;
66440 + real_mnt = real_mnt->mnt_parent;
66441 + mnt = &real_mnt->mnt;
66442 + continue;
66443 + }
66444 +
66445 + spin_lock(&dentry->d_lock);
66446 + read_lock(&gr_inode_lock);
66447 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66448 + __get_dev(dentry), role);
66449 + read_unlock(&gr_inode_lock);
66450 + parent = dentry->d_parent;
66451 + spin_unlock(&dentry->d_lock);
66452 +
66453 + if (retval != NULL)
66454 + goto out;
66455 +
66456 + dentry = parent;
66457 + }
66458 +
66459 + spin_lock(&dentry->d_lock);
66460 + read_lock(&gr_inode_lock);
66461 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66462 + __get_dev(dentry), role);
66463 + read_unlock(&gr_inode_lock);
66464 + spin_unlock(&dentry->d_lock);
66465 +
66466 + if (unlikely(retval == NULL)) {
66467 + /* gr_real_root is pinned, we don't need to hold a reference */
66468 + read_lock(&gr_inode_lock);
66469 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
66470 + __get_dev(gr_real_root.dentry), role);
66471 + read_unlock(&gr_inode_lock);
66472 + }
66473 +out:
66474 + write_sequnlock(&rename_lock);
66475 + read_sequnlock_excl(&mount_lock);
66476 +
66477 + BUG_ON(retval == NULL);
66478 +
66479 + return retval;
66480 +}
66481 +
66482 +void
66483 +assign_special_role(const char *rolename)
66484 +{
66485 + struct acl_object_label *obj;
66486 + struct acl_role_label *r;
66487 + struct acl_role_label *assigned = NULL;
66488 + struct task_struct *tsk;
66489 + struct file *filp;
66490 +
66491 + FOR_EACH_ROLE_START(r)
66492 + if (!strcmp(rolename, r->rolename) &&
66493 + (r->roletype & GR_ROLE_SPECIAL)) {
66494 + assigned = r;
66495 + break;
66496 + }
66497 + FOR_EACH_ROLE_END(r)
66498 +
66499 + if (!assigned)
66500 + return;
66501 +
66502 + read_lock(&tasklist_lock);
66503 + read_lock(&grsec_exec_file_lock);
66504 +
66505 + tsk = current->real_parent;
66506 + if (tsk == NULL)
66507 + goto out_unlock;
66508 +
66509 + filp = tsk->exec_file;
66510 + if (filp == NULL)
66511 + goto out_unlock;
66512 +
66513 + tsk->is_writable = 0;
66514 + tsk->inherited = 0;
66515 +
66516 + tsk->acl_sp_role = 1;
66517 + tsk->acl_role_id = ++acl_sp_role_value;
66518 + tsk->role = assigned;
66519 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66520 +
66521 + /* ignore additional mmap checks for processes that are writable
66522 + by the default ACL */
66523 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66524 + if (unlikely(obj->mode & GR_WRITE))
66525 + tsk->is_writable = 1;
66526 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66527 + if (unlikely(obj->mode & GR_WRITE))
66528 + tsk->is_writable = 1;
66529 +
66530 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66531 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
66532 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
66533 +#endif
66534 +
66535 +out_unlock:
66536 + read_unlock(&grsec_exec_file_lock);
66537 + read_unlock(&tasklist_lock);
66538 + return;
66539 +}
66540 +
66541 +
66542 +static void
66543 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
66544 +{
66545 + struct task_struct *task = current;
66546 + const struct cred *cred = current_cred();
66547 +
66548 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
66549 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66550 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66551 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
66552 +
66553 + return;
66554 +}
66555 +
66556 +static void
66557 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
66558 +{
66559 + struct task_struct *task = current;
66560 + const struct cred *cred = current_cred();
66561 +
66562 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66563 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66564 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66565 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
66566 +
66567 + return;
66568 +}
66569 +
66570 +static void
66571 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
66572 +{
66573 + struct task_struct *task = current;
66574 + const struct cred *cred = current_cred();
66575 +
66576 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66577 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66578 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66579 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
66580 +
66581 + return;
66582 +}
66583 +
66584 +static void
66585 +gr_set_proc_res(struct task_struct *task)
66586 +{
66587 + struct acl_subject_label *proc;
66588 + unsigned short i;
66589 +
66590 + proc = task->acl;
66591 +
66592 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
66593 + return;
66594 +
66595 + for (i = 0; i < RLIM_NLIMITS; i++) {
66596 + if (!(proc->resmask & (1U << i)))
66597 + continue;
66598 +
66599 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
66600 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
66601 +
66602 + if (i == RLIMIT_CPU)
66603 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
66604 + }
66605 +
66606 + return;
66607 +}
66608 +
66609 +/* both of the below must be called with
66610 + rcu_read_lock();
66611 + read_lock(&tasklist_lock);
66612 + read_lock(&grsec_exec_file_lock);
66613 +*/
66614 +
66615 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
66616 +{
66617 + char *tmpname;
66618 + struct acl_subject_label *tmpsubj;
66619 + struct file *filp;
66620 + struct name_entry *nmatch;
66621 +
66622 + filp = task->exec_file;
66623 + if (filp == NULL)
66624 + return NULL;
66625 +
66626 + /* the following is to apply the correct subject
66627 + on binaries running when the RBAC system
66628 + is enabled, when the binaries have been
66629 + replaced or deleted since their execution
66630 + -----
66631 + when the RBAC system starts, the inode/dev
66632 + from exec_file will be one the RBAC system
66633 + is unaware of. It only knows the inode/dev
66634 + of the present file on disk, or the absence
66635 + of it.
66636 + */
66637 +
66638 + if (filename)
66639 + nmatch = __lookup_name_entry(state, filename);
66640 + else {
66641 + preempt_disable();
66642 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
66643 +
66644 + nmatch = __lookup_name_entry(state, tmpname);
66645 + preempt_enable();
66646 + }
66647 + tmpsubj = NULL;
66648 + if (nmatch) {
66649 + if (nmatch->deleted)
66650 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
66651 + else
66652 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
66653 + }
66654 + /* this also works for the reload case -- if we don't match a potentially inherited subject
66655 + then we fall back to a normal lookup based on the binary's ino/dev
66656 + */
66657 + if (tmpsubj == NULL)
66658 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
66659 +
66660 + return tmpsubj;
66661 +}
66662 +
66663 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
66664 +{
66665 + return __gr_get_subject_for_task(&running_polstate, task, filename);
66666 +}
66667 +
66668 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
66669 +{
66670 + struct acl_object_label *obj;
66671 + struct file *filp;
66672 +
66673 + filp = task->exec_file;
66674 +
66675 + task->acl = subj;
66676 + task->is_writable = 0;
66677 + /* ignore additional mmap checks for processes that are writable
66678 + by the default ACL */
66679 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
66680 + if (unlikely(obj->mode & GR_WRITE))
66681 + task->is_writable = 1;
66682 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66683 + if (unlikely(obj->mode & GR_WRITE))
66684 + task->is_writable = 1;
66685 +
66686 + gr_set_proc_res(task);
66687 +
66688 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66689 + 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);
66690 +#endif
66691 +}
66692 +
66693 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
66694 +{
66695 + __gr_apply_subject_to_task(&running_polstate, task, subj);
66696 +}
66697 +
66698 +__u32
66699 +gr_search_file(const struct dentry * dentry, const __u32 mode,
66700 + const struct vfsmount * mnt)
66701 +{
66702 + __u32 retval = mode;
66703 + struct acl_subject_label *curracl;
66704 + struct acl_object_label *currobj;
66705 +
66706 + if (unlikely(!(gr_status & GR_READY)))
66707 + return (mode & ~GR_AUDITS);
66708 +
66709 + curracl = current->acl;
66710 +
66711 + currobj = chk_obj_label(dentry, mnt, curracl);
66712 + retval = currobj->mode & mode;
66713 +
66714 + /* if we're opening a specified transfer file for writing
66715 + (e.g. /dev/initctl), then transfer our role to init
66716 + */
66717 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
66718 + current->role->roletype & GR_ROLE_PERSIST)) {
66719 + struct task_struct *task = init_pid_ns.child_reaper;
66720 +
66721 + if (task->role != current->role) {
66722 + struct acl_subject_label *subj;
66723 +
66724 + task->acl_sp_role = 0;
66725 + task->acl_role_id = current->acl_role_id;
66726 + task->role = current->role;
66727 + rcu_read_lock();
66728 + read_lock(&grsec_exec_file_lock);
66729 + subj = gr_get_subject_for_task(task, NULL);
66730 + gr_apply_subject_to_task(task, subj);
66731 + read_unlock(&grsec_exec_file_lock);
66732 + rcu_read_unlock();
66733 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
66734 + }
66735 + }
66736 +
66737 + if (unlikely
66738 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
66739 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
66740 + __u32 new_mode = mode;
66741 +
66742 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66743 +
66744 + retval = new_mode;
66745 +
66746 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
66747 + new_mode |= GR_INHERIT;
66748 +
66749 + if (!(mode & GR_NOLEARN))
66750 + gr_log_learn(dentry, mnt, new_mode);
66751 + }
66752 +
66753 + return retval;
66754 +}
66755 +
66756 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
66757 + const struct dentry *parent,
66758 + const struct vfsmount *mnt)
66759 +{
66760 + struct name_entry *match;
66761 + struct acl_object_label *matchpo;
66762 + struct acl_subject_label *curracl;
66763 + char *path;
66764 +
66765 + if (unlikely(!(gr_status & GR_READY)))
66766 + return NULL;
66767 +
66768 + preempt_disable();
66769 + path = gr_to_filename_rbac(new_dentry, mnt);
66770 + match = lookup_name_entry_create(path);
66771 +
66772 + curracl = current->acl;
66773 +
66774 + if (match) {
66775 + read_lock(&gr_inode_lock);
66776 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
66777 + read_unlock(&gr_inode_lock);
66778 +
66779 + if (matchpo) {
66780 + preempt_enable();
66781 + return matchpo;
66782 + }
66783 + }
66784 +
66785 + // lookup parent
66786 +
66787 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
66788 +
66789 + preempt_enable();
66790 + return matchpo;
66791 +}
66792 +
66793 +__u32
66794 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
66795 + const struct vfsmount * mnt, const __u32 mode)
66796 +{
66797 + struct acl_object_label *matchpo;
66798 + __u32 retval;
66799 +
66800 + if (unlikely(!(gr_status & GR_READY)))
66801 + return (mode & ~GR_AUDITS);
66802 +
66803 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
66804 +
66805 + retval = matchpo->mode & mode;
66806 +
66807 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
66808 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66809 + __u32 new_mode = mode;
66810 +
66811 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66812 +
66813 + gr_log_learn(new_dentry, mnt, new_mode);
66814 + return new_mode;
66815 + }
66816 +
66817 + return retval;
66818 +}
66819 +
66820 +__u32
66821 +gr_check_link(const struct dentry * new_dentry,
66822 + const struct dentry * parent_dentry,
66823 + const struct vfsmount * parent_mnt,
66824 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
66825 +{
66826 + struct acl_object_label *obj;
66827 + __u32 oldmode, newmode;
66828 + __u32 needmode;
66829 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
66830 + GR_DELETE | GR_INHERIT;
66831 +
66832 + if (unlikely(!(gr_status & GR_READY)))
66833 + return (GR_CREATE | GR_LINK);
66834 +
66835 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
66836 + oldmode = obj->mode;
66837 +
66838 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
66839 + newmode = obj->mode;
66840 +
66841 + needmode = newmode & checkmodes;
66842 +
66843 + // old name for hardlink must have at least the permissions of the new name
66844 + if ((oldmode & needmode) != needmode)
66845 + goto bad;
66846 +
66847 + // if old name had restrictions/auditing, make sure the new name does as well
66848 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
66849 +
66850 + // don't allow hardlinking of suid/sgid/fcapped files without permission
66851 + if (is_privileged_binary(old_dentry))
66852 + needmode |= GR_SETID;
66853 +
66854 + if ((newmode & needmode) != needmode)
66855 + goto bad;
66856 +
66857 + // enforce minimum permissions
66858 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
66859 + return newmode;
66860 +bad:
66861 + needmode = oldmode;
66862 + if (is_privileged_binary(old_dentry))
66863 + needmode |= GR_SETID;
66864 +
66865 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
66866 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
66867 + return (GR_CREATE | GR_LINK);
66868 + } else if (newmode & GR_SUPPRESS)
66869 + return GR_SUPPRESS;
66870 + else
66871 + return 0;
66872 +}
66873 +
66874 +int
66875 +gr_check_hidden_task(const struct task_struct *task)
66876 +{
66877 + if (unlikely(!(gr_status & GR_READY)))
66878 + return 0;
66879 +
66880 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
66881 + return 1;
66882 +
66883 + return 0;
66884 +}
66885 +
66886 +int
66887 +gr_check_protected_task(const struct task_struct *task)
66888 +{
66889 + if (unlikely(!(gr_status & GR_READY) || !task))
66890 + return 0;
66891 +
66892 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66893 + task->acl != current->acl)
66894 + return 1;
66895 +
66896 + return 0;
66897 +}
66898 +
66899 +int
66900 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
66901 +{
66902 + struct task_struct *p;
66903 + int ret = 0;
66904 +
66905 + if (unlikely(!(gr_status & GR_READY) || !pid))
66906 + return ret;
66907 +
66908 + read_lock(&tasklist_lock);
66909 + do_each_pid_task(pid, type, p) {
66910 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66911 + p->acl != current->acl) {
66912 + ret = 1;
66913 + goto out;
66914 + }
66915 + } while_each_pid_task(pid, type, p);
66916 +out:
66917 + read_unlock(&tasklist_lock);
66918 +
66919 + return ret;
66920 +}
66921 +
66922 +void
66923 +gr_copy_label(struct task_struct *tsk)
66924 +{
66925 + struct task_struct *p = current;
66926 +
66927 + tsk->inherited = p->inherited;
66928 + tsk->acl_sp_role = 0;
66929 + tsk->acl_role_id = p->acl_role_id;
66930 + tsk->acl = p->acl;
66931 + tsk->role = p->role;
66932 + tsk->signal->used_accept = 0;
66933 + tsk->signal->curr_ip = p->signal->curr_ip;
66934 + tsk->signal->saved_ip = p->signal->saved_ip;
66935 + if (p->exec_file)
66936 + get_file(p->exec_file);
66937 + tsk->exec_file = p->exec_file;
66938 + tsk->is_writable = p->is_writable;
66939 + if (unlikely(p->signal->used_accept)) {
66940 + p->signal->curr_ip = 0;
66941 + p->signal->saved_ip = 0;
66942 + }
66943 +
66944 + return;
66945 +}
66946 +
66947 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
66948 +
66949 +int
66950 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
66951 +{
66952 + unsigned int i;
66953 + __u16 num;
66954 + uid_t *uidlist;
66955 + uid_t curuid;
66956 + int realok = 0;
66957 + int effectiveok = 0;
66958 + int fsok = 0;
66959 + uid_t globalreal, globaleffective, globalfs;
66960 +
66961 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
66962 + struct user_struct *user;
66963 +
66964 + if (!uid_valid(real))
66965 + goto skipit;
66966 +
66967 + /* find user based on global namespace */
66968 +
66969 + globalreal = GR_GLOBAL_UID(real);
66970 +
66971 + user = find_user(make_kuid(&init_user_ns, globalreal));
66972 + if (user == NULL)
66973 + goto skipit;
66974 +
66975 + if (gr_process_kernel_setuid_ban(user)) {
66976 + /* for find_user */
66977 + free_uid(user);
66978 + return 1;
66979 + }
66980 +
66981 + /* for find_user */
66982 + free_uid(user);
66983 +
66984 +skipit:
66985 +#endif
66986 +
66987 + if (unlikely(!(gr_status & GR_READY)))
66988 + return 0;
66989 +
66990 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66991 + gr_log_learn_uid_change(real, effective, fs);
66992 +
66993 + num = current->acl->user_trans_num;
66994 + uidlist = current->acl->user_transitions;
66995 +
66996 + if (uidlist == NULL)
66997 + return 0;
66998 +
66999 + if (!uid_valid(real)) {
67000 + realok = 1;
67001 + globalreal = (uid_t)-1;
67002 + } else {
67003 + globalreal = GR_GLOBAL_UID(real);
67004 + }
67005 + if (!uid_valid(effective)) {
67006 + effectiveok = 1;
67007 + globaleffective = (uid_t)-1;
67008 + } else {
67009 + globaleffective = GR_GLOBAL_UID(effective);
67010 + }
67011 + if (!uid_valid(fs)) {
67012 + fsok = 1;
67013 + globalfs = (uid_t)-1;
67014 + } else {
67015 + globalfs = GR_GLOBAL_UID(fs);
67016 + }
67017 +
67018 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
67019 + for (i = 0; i < num; i++) {
67020 + curuid = uidlist[i];
67021 + if (globalreal == curuid)
67022 + realok = 1;
67023 + if (globaleffective == curuid)
67024 + effectiveok = 1;
67025 + if (globalfs == curuid)
67026 + fsok = 1;
67027 + }
67028 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
67029 + for (i = 0; i < num; i++) {
67030 + curuid = uidlist[i];
67031 + if (globalreal == curuid)
67032 + break;
67033 + if (globaleffective == curuid)
67034 + break;
67035 + if (globalfs == curuid)
67036 + break;
67037 + }
67038 + /* not in deny list */
67039 + if (i == num) {
67040 + realok = 1;
67041 + effectiveok = 1;
67042 + fsok = 1;
67043 + }
67044 + }
67045 +
67046 + if (realok && effectiveok && fsok)
67047 + return 0;
67048 + else {
67049 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67050 + return 1;
67051 + }
67052 +}
67053 +
67054 +int
67055 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67056 +{
67057 + unsigned int i;
67058 + __u16 num;
67059 + gid_t *gidlist;
67060 + gid_t curgid;
67061 + int realok = 0;
67062 + int effectiveok = 0;
67063 + int fsok = 0;
67064 + gid_t globalreal, globaleffective, globalfs;
67065 +
67066 + if (unlikely(!(gr_status & GR_READY)))
67067 + return 0;
67068 +
67069 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67070 + gr_log_learn_gid_change(real, effective, fs);
67071 +
67072 + num = current->acl->group_trans_num;
67073 + gidlist = current->acl->group_transitions;
67074 +
67075 + if (gidlist == NULL)
67076 + return 0;
67077 +
67078 + if (!gid_valid(real)) {
67079 + realok = 1;
67080 + globalreal = (gid_t)-1;
67081 + } else {
67082 + globalreal = GR_GLOBAL_GID(real);
67083 + }
67084 + if (!gid_valid(effective)) {
67085 + effectiveok = 1;
67086 + globaleffective = (gid_t)-1;
67087 + } else {
67088 + globaleffective = GR_GLOBAL_GID(effective);
67089 + }
67090 + if (!gid_valid(fs)) {
67091 + fsok = 1;
67092 + globalfs = (gid_t)-1;
67093 + } else {
67094 + globalfs = GR_GLOBAL_GID(fs);
67095 + }
67096 +
67097 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
67098 + for (i = 0; i < num; i++) {
67099 + curgid = gidlist[i];
67100 + if (globalreal == curgid)
67101 + realok = 1;
67102 + if (globaleffective == curgid)
67103 + effectiveok = 1;
67104 + if (globalfs == curgid)
67105 + fsok = 1;
67106 + }
67107 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
67108 + for (i = 0; i < num; i++) {
67109 + curgid = gidlist[i];
67110 + if (globalreal == curgid)
67111 + break;
67112 + if (globaleffective == curgid)
67113 + break;
67114 + if (globalfs == curgid)
67115 + break;
67116 + }
67117 + /* not in deny list */
67118 + if (i == num) {
67119 + realok = 1;
67120 + effectiveok = 1;
67121 + fsok = 1;
67122 + }
67123 + }
67124 +
67125 + if (realok && effectiveok && fsok)
67126 + return 0;
67127 + else {
67128 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67129 + return 1;
67130 + }
67131 +}
67132 +
67133 +extern int gr_acl_is_capable(const int cap);
67134 +
67135 +void
67136 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
67137 +{
67138 + struct acl_role_label *role = task->role;
67139 + struct acl_subject_label *subj = NULL;
67140 + struct acl_object_label *obj;
67141 + struct file *filp;
67142 + uid_t uid;
67143 + gid_t gid;
67144 +
67145 + if (unlikely(!(gr_status & GR_READY)))
67146 + return;
67147 +
67148 + uid = GR_GLOBAL_UID(kuid);
67149 + gid = GR_GLOBAL_GID(kgid);
67150 +
67151 + filp = task->exec_file;
67152 +
67153 + /* kernel process, we'll give them the kernel role */
67154 + if (unlikely(!filp)) {
67155 + task->role = running_polstate.kernel_role;
67156 + task->acl = running_polstate.kernel_role->root_label;
67157 + return;
67158 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
67159 + /* save the current ip at time of role lookup so that the proper
67160 + IP will be learned for role_allowed_ip */
67161 + task->signal->saved_ip = task->signal->curr_ip;
67162 + role = lookup_acl_role_label(task, uid, gid);
67163 + }
67164 +
67165 + /* don't change the role if we're not a privileged process */
67166 + if (role && task->role != role &&
67167 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
67168 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
67169 + return;
67170 +
67171 + /* perform subject lookup in possibly new role
67172 + we can use this result below in the case where role == task->role
67173 + */
67174 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
67175 +
67176 + /* if we changed uid/gid, but result in the same role
67177 + and are using inheritance, don't lose the inherited subject
67178 + if current subject is other than what normal lookup
67179 + would result in, we arrived via inheritance, don't
67180 + lose subject
67181 + */
67182 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
67183 + (subj == task->acl)))
67184 + task->acl = subj;
67185 +
67186 + /* leave task->inherited unaffected */
67187 +
67188 + task->role = role;
67189 +
67190 + task->is_writable = 0;
67191 +
67192 + /* ignore additional mmap checks for processes that are writable
67193 + by the default ACL */
67194 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67195 + if (unlikely(obj->mode & GR_WRITE))
67196 + task->is_writable = 1;
67197 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67198 + if (unlikely(obj->mode & GR_WRITE))
67199 + task->is_writable = 1;
67200 +
67201 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67202 + 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);
67203 +#endif
67204 +
67205 + gr_set_proc_res(task);
67206 +
67207 + return;
67208 +}
67209 +
67210 +int
67211 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
67212 + const int unsafe_flags)
67213 +{
67214 + struct task_struct *task = current;
67215 + struct acl_subject_label *newacl;
67216 + struct acl_object_label *obj;
67217 + __u32 retmode;
67218 +
67219 + if (unlikely(!(gr_status & GR_READY)))
67220 + return 0;
67221 +
67222 + newacl = chk_subj_label(dentry, mnt, task->role);
67223 +
67224 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
67225 + did an exec
67226 + */
67227 + rcu_read_lock();
67228 + read_lock(&tasklist_lock);
67229 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
67230 + (task->parent->acl->mode & GR_POVERRIDE))) {
67231 + read_unlock(&tasklist_lock);
67232 + rcu_read_unlock();
67233 + goto skip_check;
67234 + }
67235 + read_unlock(&tasklist_lock);
67236 + rcu_read_unlock();
67237 +
67238 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
67239 + !(task->role->roletype & GR_ROLE_GOD) &&
67240 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
67241 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67242 + if (unsafe_flags & LSM_UNSAFE_SHARE)
67243 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
67244 + else
67245 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
67246 + return -EACCES;
67247 + }
67248 +
67249 +skip_check:
67250 +
67251 + obj = chk_obj_label(dentry, mnt, task->acl);
67252 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
67253 +
67254 + if (!(task->acl->mode & GR_INHERITLEARN) &&
67255 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
67256 + if (obj->nested)
67257 + task->acl = obj->nested;
67258 + else
67259 + task->acl = newacl;
67260 + task->inherited = 0;
67261 + } else {
67262 + task->inherited = 1;
67263 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
67264 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
67265 + }
67266 +
67267 + task->is_writable = 0;
67268 +
67269 + /* ignore additional mmap checks for processes that are writable
67270 + by the default ACL */
67271 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
67272 + if (unlikely(obj->mode & GR_WRITE))
67273 + task->is_writable = 1;
67274 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
67275 + if (unlikely(obj->mode & GR_WRITE))
67276 + task->is_writable = 1;
67277 +
67278 + gr_set_proc_res(task);
67279 +
67280 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67281 + 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);
67282 +#endif
67283 + return 0;
67284 +}
67285 +
67286 +/* always called with valid inodev ptr */
67287 +static void
67288 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
67289 +{
67290 + struct acl_object_label *matchpo;
67291 + struct acl_subject_label *matchps;
67292 + struct acl_subject_label *subj;
67293 + struct acl_role_label *role;
67294 + unsigned int x;
67295 +
67296 + FOR_EACH_ROLE_START(role)
67297 + FOR_EACH_SUBJECT_START(role, subj, x)
67298 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67299 + matchpo->mode |= GR_DELETED;
67300 + FOR_EACH_SUBJECT_END(subj,x)
67301 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
67302 + /* nested subjects aren't in the role's subj_hash table */
67303 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67304 + matchpo->mode |= GR_DELETED;
67305 + FOR_EACH_NESTED_SUBJECT_END(subj)
67306 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
67307 + matchps->mode |= GR_DELETED;
67308 + FOR_EACH_ROLE_END(role)
67309 +
67310 + inodev->nentry->deleted = 1;
67311 +
67312 + return;
67313 +}
67314 +
67315 +void
67316 +gr_handle_delete(const ino_t ino, const dev_t dev)
67317 +{
67318 + struct inodev_entry *inodev;
67319 +
67320 + if (unlikely(!(gr_status & GR_READY)))
67321 + return;
67322 +
67323 + write_lock(&gr_inode_lock);
67324 + inodev = lookup_inodev_entry(ino, dev);
67325 + if (inodev != NULL)
67326 + do_handle_delete(inodev, ino, dev);
67327 + write_unlock(&gr_inode_lock);
67328 +
67329 + return;
67330 +}
67331 +
67332 +static void
67333 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
67334 + const ino_t newinode, const dev_t newdevice,
67335 + struct acl_subject_label *subj)
67336 +{
67337 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
67338 + struct acl_object_label *match;
67339 +
67340 + match = subj->obj_hash[index];
67341 +
67342 + while (match && (match->inode != oldinode ||
67343 + match->device != olddevice ||
67344 + !(match->mode & GR_DELETED)))
67345 + match = match->next;
67346 +
67347 + if (match && (match->inode == oldinode)
67348 + && (match->device == olddevice)
67349 + && (match->mode & GR_DELETED)) {
67350 + if (match->prev == NULL) {
67351 + subj->obj_hash[index] = match->next;
67352 + if (match->next != NULL)
67353 + match->next->prev = NULL;
67354 + } else {
67355 + match->prev->next = match->next;
67356 + if (match->next != NULL)
67357 + match->next->prev = match->prev;
67358 + }
67359 + match->prev = NULL;
67360 + match->next = NULL;
67361 + match->inode = newinode;
67362 + match->device = newdevice;
67363 + match->mode &= ~GR_DELETED;
67364 +
67365 + insert_acl_obj_label(match, subj);
67366 + }
67367 +
67368 + return;
67369 +}
67370 +
67371 +static void
67372 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
67373 + const ino_t newinode, const dev_t newdevice,
67374 + struct acl_role_label *role)
67375 +{
67376 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
67377 + struct acl_subject_label *match;
67378 +
67379 + match = role->subj_hash[index];
67380 +
67381 + while (match && (match->inode != oldinode ||
67382 + match->device != olddevice ||
67383 + !(match->mode & GR_DELETED)))
67384 + match = match->next;
67385 +
67386 + if (match && (match->inode == oldinode)
67387 + && (match->device == olddevice)
67388 + && (match->mode & GR_DELETED)) {
67389 + if (match->prev == NULL) {
67390 + role->subj_hash[index] = match->next;
67391 + if (match->next != NULL)
67392 + match->next->prev = NULL;
67393 + } else {
67394 + match->prev->next = match->next;
67395 + if (match->next != NULL)
67396 + match->next->prev = match->prev;
67397 + }
67398 + match->prev = NULL;
67399 + match->next = NULL;
67400 + match->inode = newinode;
67401 + match->device = newdevice;
67402 + match->mode &= ~GR_DELETED;
67403 +
67404 + insert_acl_subj_label(match, role);
67405 + }
67406 +
67407 + return;
67408 +}
67409 +
67410 +static void
67411 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
67412 + const ino_t newinode, const dev_t newdevice)
67413 +{
67414 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
67415 + struct inodev_entry *match;
67416 +
67417 + match = running_polstate.inodev_set.i_hash[index];
67418 +
67419 + while (match && (match->nentry->inode != oldinode ||
67420 + match->nentry->device != olddevice || !match->nentry->deleted))
67421 + match = match->next;
67422 +
67423 + if (match && (match->nentry->inode == oldinode)
67424 + && (match->nentry->device == olddevice) &&
67425 + match->nentry->deleted) {
67426 + if (match->prev == NULL) {
67427 + running_polstate.inodev_set.i_hash[index] = match->next;
67428 + if (match->next != NULL)
67429 + match->next->prev = NULL;
67430 + } else {
67431 + match->prev->next = match->next;
67432 + if (match->next != NULL)
67433 + match->next->prev = match->prev;
67434 + }
67435 + match->prev = NULL;
67436 + match->next = NULL;
67437 + match->nentry->inode = newinode;
67438 + match->nentry->device = newdevice;
67439 + match->nentry->deleted = 0;
67440 +
67441 + insert_inodev_entry(match);
67442 + }
67443 +
67444 + return;
67445 +}
67446 +
67447 +static void
67448 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
67449 +{
67450 + struct acl_subject_label *subj;
67451 + struct acl_role_label *role;
67452 + unsigned int x;
67453 +
67454 + FOR_EACH_ROLE_START(role)
67455 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
67456 +
67457 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
67458 + if ((subj->inode == ino) && (subj->device == dev)) {
67459 + subj->inode = ino;
67460 + subj->device = dev;
67461 + }
67462 + /* nested subjects aren't in the role's subj_hash table */
67463 + update_acl_obj_label(matchn->inode, matchn->device,
67464 + ino, dev, subj);
67465 + FOR_EACH_NESTED_SUBJECT_END(subj)
67466 + FOR_EACH_SUBJECT_START(role, subj, x)
67467 + update_acl_obj_label(matchn->inode, matchn->device,
67468 + ino, dev, subj);
67469 + FOR_EACH_SUBJECT_END(subj,x)
67470 + FOR_EACH_ROLE_END(role)
67471 +
67472 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
67473 +
67474 + return;
67475 +}
67476 +
67477 +static void
67478 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
67479 + const struct vfsmount *mnt)
67480 +{
67481 + ino_t ino = dentry->d_inode->i_ino;
67482 + dev_t dev = __get_dev(dentry);
67483 +
67484 + __do_handle_create(matchn, ino, dev);
67485 +
67486 + return;
67487 +}
67488 +
67489 +void
67490 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
67491 +{
67492 + struct name_entry *matchn;
67493 +
67494 + if (unlikely(!(gr_status & GR_READY)))
67495 + return;
67496 +
67497 + preempt_disable();
67498 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
67499 +
67500 + if (unlikely((unsigned long)matchn)) {
67501 + write_lock(&gr_inode_lock);
67502 + do_handle_create(matchn, dentry, mnt);
67503 + write_unlock(&gr_inode_lock);
67504 + }
67505 + preempt_enable();
67506 +
67507 + return;
67508 +}
67509 +
67510 +void
67511 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
67512 +{
67513 + struct name_entry *matchn;
67514 +
67515 + if (unlikely(!(gr_status & GR_READY)))
67516 + return;
67517 +
67518 + preempt_disable();
67519 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
67520 +
67521 + if (unlikely((unsigned long)matchn)) {
67522 + write_lock(&gr_inode_lock);
67523 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
67524 + write_unlock(&gr_inode_lock);
67525 + }
67526 + preempt_enable();
67527 +
67528 + return;
67529 +}
67530 +
67531 +void
67532 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67533 + struct dentry *old_dentry,
67534 + struct dentry *new_dentry,
67535 + struct vfsmount *mnt, const __u8 replace)
67536 +{
67537 + struct name_entry *matchn;
67538 + struct inodev_entry *inodev;
67539 + struct inode *inode = new_dentry->d_inode;
67540 + ino_t old_ino = old_dentry->d_inode->i_ino;
67541 + dev_t old_dev = __get_dev(old_dentry);
67542 +
67543 + /* vfs_rename swaps the name and parent link for old_dentry and
67544 + new_dentry
67545 + at this point, old_dentry has the new name, parent link, and inode
67546 + for the renamed file
67547 + if a file is being replaced by a rename, new_dentry has the inode
67548 + and name for the replaced file
67549 + */
67550 +
67551 + if (unlikely(!(gr_status & GR_READY)))
67552 + return;
67553 +
67554 + preempt_disable();
67555 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
67556 +
67557 + /* we wouldn't have to check d_inode if it weren't for
67558 + NFS silly-renaming
67559 + */
67560 +
67561 + write_lock(&gr_inode_lock);
67562 + if (unlikely(replace && inode)) {
67563 + ino_t new_ino = inode->i_ino;
67564 + dev_t new_dev = __get_dev(new_dentry);
67565 +
67566 + inodev = lookup_inodev_entry(new_ino, new_dev);
67567 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
67568 + do_handle_delete(inodev, new_ino, new_dev);
67569 + }
67570 +
67571 + inodev = lookup_inodev_entry(old_ino, old_dev);
67572 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
67573 + do_handle_delete(inodev, old_ino, old_dev);
67574 +
67575 + if (unlikely((unsigned long)matchn))
67576 + do_handle_create(matchn, old_dentry, mnt);
67577 +
67578 + write_unlock(&gr_inode_lock);
67579 + preempt_enable();
67580 +
67581 + return;
67582 +}
67583 +
67584 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67585 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67586 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67587 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67588 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67589 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67590 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67591 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67592 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67593 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67594 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67595 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67596 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67597 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67598 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67599 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67600 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67601 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67602 +};
67603 +
67604 +void
67605 +gr_learn_resource(const struct task_struct *task,
67606 + const int res, const unsigned long wanted, const int gt)
67607 +{
67608 + struct acl_subject_label *acl;
67609 + const struct cred *cred;
67610 +
67611 + if (unlikely((gr_status & GR_READY) &&
67612 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67613 + goto skip_reslog;
67614 +
67615 + gr_log_resource(task, res, wanted, gt);
67616 +skip_reslog:
67617 +
67618 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67619 + return;
67620 +
67621 + acl = task->acl;
67622 +
67623 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67624 + !(acl->resmask & (1U << (unsigned short) res))))
67625 + return;
67626 +
67627 + if (wanted >= acl->res[res].rlim_cur) {
67628 + unsigned long res_add;
67629 +
67630 + res_add = wanted + res_learn_bumps[res];
67631 +
67632 + acl->res[res].rlim_cur = res_add;
67633 +
67634 + if (wanted > acl->res[res].rlim_max)
67635 + acl->res[res].rlim_max = res_add;
67636 +
67637 + /* only log the subject filename, since resource logging is supported for
67638 + single-subject learning only */
67639 + rcu_read_lock();
67640 + cred = __task_cred(task);
67641 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67642 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67643 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67644 + "", (unsigned long) res, &task->signal->saved_ip);
67645 + rcu_read_unlock();
67646 + }
67647 +
67648 + return;
67649 +}
67650 +EXPORT_SYMBOL(gr_learn_resource);
67651 +#endif
67652 +
67653 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67654 +void
67655 +pax_set_initial_flags(struct linux_binprm *bprm)
67656 +{
67657 + struct task_struct *task = current;
67658 + struct acl_subject_label *proc;
67659 + unsigned long flags;
67660 +
67661 + if (unlikely(!(gr_status & GR_READY)))
67662 + return;
67663 +
67664 + flags = pax_get_flags(task);
67665 +
67666 + proc = task->acl;
67667 +
67668 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67669 + flags &= ~MF_PAX_PAGEEXEC;
67670 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67671 + flags &= ~MF_PAX_SEGMEXEC;
67672 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67673 + flags &= ~MF_PAX_RANDMMAP;
67674 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67675 + flags &= ~MF_PAX_EMUTRAMP;
67676 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67677 + flags &= ~MF_PAX_MPROTECT;
67678 +
67679 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67680 + flags |= MF_PAX_PAGEEXEC;
67681 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67682 + flags |= MF_PAX_SEGMEXEC;
67683 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67684 + flags |= MF_PAX_RANDMMAP;
67685 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67686 + flags |= MF_PAX_EMUTRAMP;
67687 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67688 + flags |= MF_PAX_MPROTECT;
67689 +
67690 + pax_set_flags(task, flags);
67691 +
67692 + return;
67693 +}
67694 +#endif
67695 +
67696 +int
67697 +gr_handle_proc_ptrace(struct task_struct *task)
67698 +{
67699 + struct file *filp;
67700 + struct task_struct *tmp = task;
67701 + struct task_struct *curtemp = current;
67702 + __u32 retmode;
67703 +
67704 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67705 + if (unlikely(!(gr_status & GR_READY)))
67706 + return 0;
67707 +#endif
67708 +
67709 + read_lock(&tasklist_lock);
67710 + read_lock(&grsec_exec_file_lock);
67711 + filp = task->exec_file;
67712 +
67713 + while (task_pid_nr(tmp) > 0) {
67714 + if (tmp == curtemp)
67715 + break;
67716 + tmp = tmp->real_parent;
67717 + }
67718 +
67719 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67720 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67721 + read_unlock(&grsec_exec_file_lock);
67722 + read_unlock(&tasklist_lock);
67723 + return 1;
67724 + }
67725 +
67726 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67727 + if (!(gr_status & GR_READY)) {
67728 + read_unlock(&grsec_exec_file_lock);
67729 + read_unlock(&tasklist_lock);
67730 + return 0;
67731 + }
67732 +#endif
67733 +
67734 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67735 + read_unlock(&grsec_exec_file_lock);
67736 + read_unlock(&tasklist_lock);
67737 +
67738 + if (retmode & GR_NOPTRACE)
67739 + return 1;
67740 +
67741 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67742 + && (current->acl != task->acl || (current->acl != current->role->root_label
67743 + && task_pid_nr(current) != task_pid_nr(task))))
67744 + return 1;
67745 +
67746 + return 0;
67747 +}
67748 +
67749 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67750 +{
67751 + if (unlikely(!(gr_status & GR_READY)))
67752 + return;
67753 +
67754 + if (!(current->role->roletype & GR_ROLE_GOD))
67755 + return;
67756 +
67757 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67758 + p->role->rolename, gr_task_roletype_to_char(p),
67759 + p->acl->filename);
67760 +}
67761 +
67762 +int
67763 +gr_handle_ptrace(struct task_struct *task, const long request)
67764 +{
67765 + struct task_struct *tmp = task;
67766 + struct task_struct *curtemp = current;
67767 + __u32 retmode;
67768 +
67769 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67770 + if (unlikely(!(gr_status & GR_READY)))
67771 + return 0;
67772 +#endif
67773 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67774 + read_lock(&tasklist_lock);
67775 + while (task_pid_nr(tmp) > 0) {
67776 + if (tmp == curtemp)
67777 + break;
67778 + tmp = tmp->real_parent;
67779 + }
67780 +
67781 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67782 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67783 + read_unlock(&tasklist_lock);
67784 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67785 + return 1;
67786 + }
67787 + read_unlock(&tasklist_lock);
67788 + }
67789 +
67790 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67791 + if (!(gr_status & GR_READY))
67792 + return 0;
67793 +#endif
67794 +
67795 + read_lock(&grsec_exec_file_lock);
67796 + if (unlikely(!task->exec_file)) {
67797 + read_unlock(&grsec_exec_file_lock);
67798 + return 0;
67799 + }
67800 +
67801 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67802 + read_unlock(&grsec_exec_file_lock);
67803 +
67804 + if (retmode & GR_NOPTRACE) {
67805 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67806 + return 1;
67807 + }
67808 +
67809 + if (retmode & GR_PTRACERD) {
67810 + switch (request) {
67811 + case PTRACE_SEIZE:
67812 + case PTRACE_POKETEXT:
67813 + case PTRACE_POKEDATA:
67814 + case PTRACE_POKEUSR:
67815 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67816 + case PTRACE_SETREGS:
67817 + case PTRACE_SETFPREGS:
67818 +#endif
67819 +#ifdef CONFIG_X86
67820 + case PTRACE_SETFPXREGS:
67821 +#endif
67822 +#ifdef CONFIG_ALTIVEC
67823 + case PTRACE_SETVRREGS:
67824 +#endif
67825 + return 1;
67826 + default:
67827 + return 0;
67828 + }
67829 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
67830 + !(current->role->roletype & GR_ROLE_GOD) &&
67831 + (current->acl != task->acl)) {
67832 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67833 + return 1;
67834 + }
67835 +
67836 + return 0;
67837 +}
67838 +
67839 +static int is_writable_mmap(const struct file *filp)
67840 +{
67841 + struct task_struct *task = current;
67842 + struct acl_object_label *obj, *obj2;
67843 +
67844 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67845 + !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))) {
67846 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67847 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67848 + task->role->root_label);
67849 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67850 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67851 + return 1;
67852 + }
67853 + }
67854 + return 0;
67855 +}
67856 +
67857 +int
67858 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67859 +{
67860 + __u32 mode;
67861 +
67862 + if (unlikely(!file || !(prot & PROT_EXEC)))
67863 + return 1;
67864 +
67865 + if (is_writable_mmap(file))
67866 + return 0;
67867 +
67868 + mode =
67869 + gr_search_file(file->f_path.dentry,
67870 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67871 + file->f_path.mnt);
67872 +
67873 + if (!gr_tpe_allow(file))
67874 + return 0;
67875 +
67876 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67877 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67878 + return 0;
67879 + } else if (unlikely(!(mode & GR_EXEC))) {
67880 + return 0;
67881 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67882 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67883 + return 1;
67884 + }
67885 +
67886 + return 1;
67887 +}
67888 +
67889 +int
67890 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67891 +{
67892 + __u32 mode;
67893 +
67894 + if (unlikely(!file || !(prot & PROT_EXEC)))
67895 + return 1;
67896 +
67897 + if (is_writable_mmap(file))
67898 + return 0;
67899 +
67900 + mode =
67901 + gr_search_file(file->f_path.dentry,
67902 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67903 + file->f_path.mnt);
67904 +
67905 + if (!gr_tpe_allow(file))
67906 + return 0;
67907 +
67908 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67909 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67910 + return 0;
67911 + } else if (unlikely(!(mode & GR_EXEC))) {
67912 + return 0;
67913 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67914 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67915 + return 1;
67916 + }
67917 +
67918 + return 1;
67919 +}
67920 +
67921 +void
67922 +gr_acl_handle_psacct(struct task_struct *task, const long code)
67923 +{
67924 + unsigned long runtime, cputime;
67925 + cputime_t utime, stime;
67926 + unsigned int wday, cday;
67927 + __u8 whr, chr;
67928 + __u8 wmin, cmin;
67929 + __u8 wsec, csec;
67930 + struct timespec timeval;
67931 +
67932 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67933 + !(task->acl->mode & GR_PROCACCT)))
67934 + return;
67935 +
67936 + do_posix_clock_monotonic_gettime(&timeval);
67937 + runtime = timeval.tv_sec - task->start_time.tv_sec;
67938 + wday = runtime / (60 * 60 * 24);
67939 + runtime -= wday * (60 * 60 * 24);
67940 + whr = runtime / (60 * 60);
67941 + runtime -= whr * (60 * 60);
67942 + wmin = runtime / 60;
67943 + runtime -= wmin * 60;
67944 + wsec = runtime;
67945 +
67946 + task_cputime(task, &utime, &stime);
67947 + cputime = cputime_to_secs(utime + stime);
67948 + cday = cputime / (60 * 60 * 24);
67949 + cputime -= cday * (60 * 60 * 24);
67950 + chr = cputime / (60 * 60);
67951 + cputime -= chr * (60 * 60);
67952 + cmin = cputime / 60;
67953 + cputime -= cmin * 60;
67954 + csec = cputime;
67955 +
67956 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67957 +
67958 + return;
67959 +}
67960 +
67961 +#ifdef CONFIG_TASKSTATS
67962 +int gr_is_taskstats_denied(int pid)
67963 +{
67964 + struct task_struct *task;
67965 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67966 + const struct cred *cred;
67967 +#endif
67968 + int ret = 0;
67969 +
67970 + /* restrict taskstats viewing to un-chrooted root users
67971 + who have the 'view' subject flag if the RBAC system is enabled
67972 + */
67973 +
67974 + rcu_read_lock();
67975 + read_lock(&tasklist_lock);
67976 + task = find_task_by_vpid(pid);
67977 + if (task) {
67978 +#ifdef CONFIG_GRKERNSEC_CHROOT
67979 + if (proc_is_chrooted(task))
67980 + ret = -EACCES;
67981 +#endif
67982 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67983 + cred = __task_cred(task);
67984 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67985 + if (gr_is_global_nonroot(cred->uid))
67986 + ret = -EACCES;
67987 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67988 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
67989 + ret = -EACCES;
67990 +#endif
67991 +#endif
67992 + if (gr_status & GR_READY) {
67993 + if (!(task->acl->mode & GR_VIEW))
67994 + ret = -EACCES;
67995 + }
67996 + } else
67997 + ret = -ENOENT;
67998 +
67999 + read_unlock(&tasklist_lock);
68000 + rcu_read_unlock();
68001 +
68002 + return ret;
68003 +}
68004 +#endif
68005 +
68006 +/* AUXV entries are filled via a descendant of search_binary_handler
68007 + after we've already applied the subject for the target
68008 +*/
68009 +int gr_acl_enable_at_secure(void)
68010 +{
68011 + if (unlikely(!(gr_status & GR_READY)))
68012 + return 0;
68013 +
68014 + if (current->acl->mode & GR_ATSECURE)
68015 + return 1;
68016 +
68017 + return 0;
68018 +}
68019 +
68020 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68021 +{
68022 + struct task_struct *task = current;
68023 + struct dentry *dentry = file->f_path.dentry;
68024 + struct vfsmount *mnt = file->f_path.mnt;
68025 + struct acl_object_label *obj, *tmp;
68026 + struct acl_subject_label *subj;
68027 + unsigned int bufsize;
68028 + int is_not_root;
68029 + char *path;
68030 + dev_t dev = __get_dev(dentry);
68031 +
68032 + if (unlikely(!(gr_status & GR_READY)))
68033 + return 1;
68034 +
68035 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68036 + return 1;
68037 +
68038 + /* ignore Eric Biederman */
68039 + if (IS_PRIVATE(dentry->d_inode))
68040 + return 1;
68041 +
68042 + subj = task->acl;
68043 + read_lock(&gr_inode_lock);
68044 + do {
68045 + obj = lookup_acl_obj_label(ino, dev, subj);
68046 + if (obj != NULL) {
68047 + read_unlock(&gr_inode_lock);
68048 + return (obj->mode & GR_FIND) ? 1 : 0;
68049 + }
68050 + } while ((subj = subj->parent_subject));
68051 + read_unlock(&gr_inode_lock);
68052 +
68053 + /* this is purely an optimization since we're looking for an object
68054 + for the directory we're doing a readdir on
68055 + if it's possible for any globbed object to match the entry we're
68056 + filling into the directory, then the object we find here will be
68057 + an anchor point with attached globbed objects
68058 + */
68059 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
68060 + if (obj->globbed == NULL)
68061 + return (obj->mode & GR_FIND) ? 1 : 0;
68062 +
68063 + is_not_root = ((obj->filename[0] == '/') &&
68064 + (obj->filename[1] == '\0')) ? 0 : 1;
68065 + bufsize = PAGE_SIZE - namelen - is_not_root;
68066 +
68067 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
68068 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
68069 + return 1;
68070 +
68071 + preempt_disable();
68072 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
68073 + bufsize);
68074 +
68075 + bufsize = strlen(path);
68076 +
68077 + /* if base is "/", don't append an additional slash */
68078 + if (is_not_root)
68079 + *(path + bufsize) = '/';
68080 + memcpy(path + bufsize + is_not_root, name, namelen);
68081 + *(path + bufsize + namelen + is_not_root) = '\0';
68082 +
68083 + tmp = obj->globbed;
68084 + while (tmp) {
68085 + if (!glob_match(tmp->filename, path)) {
68086 + preempt_enable();
68087 + return (tmp->mode & GR_FIND) ? 1 : 0;
68088 + }
68089 + tmp = tmp->next;
68090 + }
68091 + preempt_enable();
68092 + return (obj->mode & GR_FIND) ? 1 : 0;
68093 +}
68094 +
68095 +void gr_put_exec_file(struct task_struct *task)
68096 +{
68097 + struct file *filp;
68098 +
68099 + write_lock(&grsec_exec_file_lock);
68100 + filp = task->exec_file;
68101 + task->exec_file = NULL;
68102 + write_unlock(&grsec_exec_file_lock);
68103 +
68104 + if (filp)
68105 + fput(filp);
68106 +
68107 + return;
68108 +}
68109 +
68110 +
68111 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
68112 +EXPORT_SYMBOL(gr_acl_is_enabled);
68113 +#endif
68114 +#ifdef CONFIG_SECURITY
68115 +EXPORT_SYMBOL(gr_check_user_change);
68116 +EXPORT_SYMBOL(gr_check_group_change);
68117 +#endif
68118 +
68119 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
68120 new file mode 100644
68121 index 0000000..18ffbbd
68122 --- /dev/null
68123 +++ b/grsecurity/gracl_alloc.c
68124 @@ -0,0 +1,105 @@
68125 +#include <linux/kernel.h>
68126 +#include <linux/mm.h>
68127 +#include <linux/slab.h>
68128 +#include <linux/vmalloc.h>
68129 +#include <linux/gracl.h>
68130 +#include <linux/grsecurity.h>
68131 +
68132 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
68133 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
68134 +
68135 +static __inline__ int
68136 +alloc_pop(void)
68137 +{
68138 + if (current_alloc_state->alloc_stack_next == 1)
68139 + return 0;
68140 +
68141 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
68142 +
68143 + current_alloc_state->alloc_stack_next--;
68144 +
68145 + return 1;
68146 +}
68147 +
68148 +static __inline__ int
68149 +alloc_push(void *buf)
68150 +{
68151 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
68152 + return 1;
68153 +
68154 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
68155 +
68156 + current_alloc_state->alloc_stack_next++;
68157 +
68158 + return 0;
68159 +}
68160 +
68161 +void *
68162 +acl_alloc(unsigned long len)
68163 +{
68164 + void *ret = NULL;
68165 +
68166 + if (!len || len > PAGE_SIZE)
68167 + goto out;
68168 +
68169 + ret = kmalloc(len, GFP_KERNEL);
68170 +
68171 + if (ret) {
68172 + if (alloc_push(ret)) {
68173 + kfree(ret);
68174 + ret = NULL;
68175 + }
68176 + }
68177 +
68178 +out:
68179 + return ret;
68180 +}
68181 +
68182 +void *
68183 +acl_alloc_num(unsigned long num, unsigned long len)
68184 +{
68185 + if (!len || (num > (PAGE_SIZE / len)))
68186 + return NULL;
68187 +
68188 + return acl_alloc(num * len);
68189 +}
68190 +
68191 +void
68192 +acl_free_all(void)
68193 +{
68194 + if (!current_alloc_state->alloc_stack)
68195 + return;
68196 +
68197 + while (alloc_pop()) ;
68198 +
68199 + if (current_alloc_state->alloc_stack) {
68200 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
68201 + kfree(current_alloc_state->alloc_stack);
68202 + else
68203 + vfree(current_alloc_state->alloc_stack);
68204 + }
68205 +
68206 + current_alloc_state->alloc_stack = NULL;
68207 + current_alloc_state->alloc_stack_size = 1;
68208 + current_alloc_state->alloc_stack_next = 1;
68209 +
68210 + return;
68211 +}
68212 +
68213 +int
68214 +acl_alloc_stack_init(unsigned long size)
68215 +{
68216 + if ((size * sizeof (void *)) <= PAGE_SIZE)
68217 + current_alloc_state->alloc_stack =
68218 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
68219 + else
68220 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
68221 +
68222 + current_alloc_state->alloc_stack_size = size;
68223 + current_alloc_state->alloc_stack_next = 1;
68224 +
68225 + if (!current_alloc_state->alloc_stack)
68226 + return 0;
68227 + else
68228 + return 1;
68229 +}
68230 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
68231 new file mode 100644
68232 index 0000000..bdd51ea
68233 --- /dev/null
68234 +++ b/grsecurity/gracl_cap.c
68235 @@ -0,0 +1,110 @@
68236 +#include <linux/kernel.h>
68237 +#include <linux/module.h>
68238 +#include <linux/sched.h>
68239 +#include <linux/gracl.h>
68240 +#include <linux/grsecurity.h>
68241 +#include <linux/grinternal.h>
68242 +
68243 +extern const char *captab_log[];
68244 +extern int captab_log_entries;
68245 +
68246 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68247 +{
68248 + struct acl_subject_label *curracl;
68249 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68250 + kernel_cap_t cap_audit = __cap_empty_set;
68251 +
68252 + if (!gr_acl_is_enabled())
68253 + return 1;
68254 +
68255 + curracl = task->acl;
68256 +
68257 + cap_drop = curracl->cap_lower;
68258 + cap_mask = curracl->cap_mask;
68259 + cap_audit = curracl->cap_invert_audit;
68260 +
68261 + while ((curracl = curracl->parent_subject)) {
68262 + /* if the cap isn't specified in the current computed mask but is specified in the
68263 + current level subject, and is lowered in the current level subject, then add
68264 + it to the set of dropped capabilities
68265 + otherwise, add the current level subject's mask to the current computed mask
68266 + */
68267 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68268 + cap_raise(cap_mask, cap);
68269 + if (cap_raised(curracl->cap_lower, cap))
68270 + cap_raise(cap_drop, cap);
68271 + if (cap_raised(curracl->cap_invert_audit, cap))
68272 + cap_raise(cap_audit, cap);
68273 + }
68274 + }
68275 +
68276 + if (!cap_raised(cap_drop, cap)) {
68277 + if (cap_raised(cap_audit, cap))
68278 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
68279 + return 1;
68280 + }
68281 +
68282 + curracl = task->acl;
68283 +
68284 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
68285 + && cap_raised(cred->cap_effective, cap)) {
68286 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68287 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
68288 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
68289 + gr_to_filename(task->exec_file->f_path.dentry,
68290 + task->exec_file->f_path.mnt) : curracl->filename,
68291 + curracl->filename, 0UL,
68292 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
68293 + return 1;
68294 + }
68295 +
68296 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
68297 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
68298 +
68299 + return 0;
68300 +}
68301 +
68302 +int
68303 +gr_acl_is_capable(const int cap)
68304 +{
68305 + return gr_task_acl_is_capable(current, current_cred(), cap);
68306 +}
68307 +
68308 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
68309 +{
68310 + struct acl_subject_label *curracl;
68311 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68312 +
68313 + if (!gr_acl_is_enabled())
68314 + return 1;
68315 +
68316 + curracl = task->acl;
68317 +
68318 + cap_drop = curracl->cap_lower;
68319 + cap_mask = curracl->cap_mask;
68320 +
68321 + while ((curracl = curracl->parent_subject)) {
68322 + /* if the cap isn't specified in the current computed mask but is specified in the
68323 + current level subject, and is lowered in the current level subject, then add
68324 + it to the set of dropped capabilities
68325 + otherwise, add the current level subject's mask to the current computed mask
68326 + */
68327 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68328 + cap_raise(cap_mask, cap);
68329 + if (cap_raised(curracl->cap_lower, cap))
68330 + cap_raise(cap_drop, cap);
68331 + }
68332 + }
68333 +
68334 + if (!cap_raised(cap_drop, cap))
68335 + return 1;
68336 +
68337 + return 0;
68338 +}
68339 +
68340 +int
68341 +gr_acl_is_capable_nolog(const int cap)
68342 +{
68343 + return gr_task_acl_is_capable_nolog(current, cap);
68344 +}
68345 +
68346 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
68347 new file mode 100644
68348 index 0000000..ca25605
68349 --- /dev/null
68350 +++ b/grsecurity/gracl_compat.c
68351 @@ -0,0 +1,270 @@
68352 +#include <linux/kernel.h>
68353 +#include <linux/gracl.h>
68354 +#include <linux/compat.h>
68355 +#include <linux/gracl_compat.h>
68356 +
68357 +#include <asm/uaccess.h>
68358 +
68359 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
68360 +{
68361 + struct gr_arg_wrapper_compat uwrapcompat;
68362 +
68363 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
68364 + return -EFAULT;
68365 +
68366 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
68367 + (uwrapcompat.version != 0x2901)) ||
68368 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
68369 + return -EINVAL;
68370 +
68371 + uwrap->arg = compat_ptr(uwrapcompat.arg);
68372 + uwrap->version = uwrapcompat.version;
68373 + uwrap->size = sizeof(struct gr_arg);
68374 +
68375 + return 0;
68376 +}
68377 +
68378 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
68379 +{
68380 + struct gr_arg_compat argcompat;
68381 +
68382 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
68383 + return -EFAULT;
68384 +
68385 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
68386 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
68387 + arg->role_db.num_roles = argcompat.role_db.num_roles;
68388 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
68389 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
68390 + arg->role_db.num_objects = argcompat.role_db.num_objects;
68391 +
68392 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
68393 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
68394 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
68395 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
68396 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
68397 + arg->segv_device = argcompat.segv_device;
68398 + arg->segv_inode = argcompat.segv_inode;
68399 + arg->segv_uid = argcompat.segv_uid;
68400 + arg->num_sprole_pws = argcompat.num_sprole_pws;
68401 + arg->mode = argcompat.mode;
68402 +
68403 + return 0;
68404 +}
68405 +
68406 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
68407 +{
68408 + struct acl_object_label_compat objcompat;
68409 +
68410 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
68411 + return -EFAULT;
68412 +
68413 + obj->filename = compat_ptr(objcompat.filename);
68414 + obj->inode = objcompat.inode;
68415 + obj->device = objcompat.device;
68416 + obj->mode = objcompat.mode;
68417 +
68418 + obj->nested = compat_ptr(objcompat.nested);
68419 + obj->globbed = compat_ptr(objcompat.globbed);
68420 +
68421 + obj->prev = compat_ptr(objcompat.prev);
68422 + obj->next = compat_ptr(objcompat.next);
68423 +
68424 + return 0;
68425 +}
68426 +
68427 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
68428 +{
68429 + unsigned int i;
68430 + struct acl_subject_label_compat subjcompat;
68431 +
68432 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
68433 + return -EFAULT;
68434 +
68435 + subj->filename = compat_ptr(subjcompat.filename);
68436 + subj->inode = subjcompat.inode;
68437 + subj->device = subjcompat.device;
68438 + subj->mode = subjcompat.mode;
68439 + subj->cap_mask = subjcompat.cap_mask;
68440 + subj->cap_lower = subjcompat.cap_lower;
68441 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
68442 +
68443 + for (i = 0; i < GR_NLIMITS; i++) {
68444 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
68445 + subj->res[i].rlim_cur = RLIM_INFINITY;
68446 + else
68447 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
68448 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
68449 + subj->res[i].rlim_max = RLIM_INFINITY;
68450 + else
68451 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
68452 + }
68453 + subj->resmask = subjcompat.resmask;
68454 +
68455 + subj->user_trans_type = subjcompat.user_trans_type;
68456 + subj->group_trans_type = subjcompat.group_trans_type;
68457 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
68458 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
68459 + subj->user_trans_num = subjcompat.user_trans_num;
68460 + subj->group_trans_num = subjcompat.group_trans_num;
68461 +
68462 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
68463 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
68464 + subj->ip_type = subjcompat.ip_type;
68465 + subj->ips = compat_ptr(subjcompat.ips);
68466 + subj->ip_num = subjcompat.ip_num;
68467 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
68468 +
68469 + subj->crashes = subjcompat.crashes;
68470 + subj->expires = subjcompat.expires;
68471 +
68472 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
68473 + subj->hash = compat_ptr(subjcompat.hash);
68474 + subj->prev = compat_ptr(subjcompat.prev);
68475 + subj->next = compat_ptr(subjcompat.next);
68476 +
68477 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
68478 + subj->obj_hash_size = subjcompat.obj_hash_size;
68479 + subj->pax_flags = subjcompat.pax_flags;
68480 +
68481 + return 0;
68482 +}
68483 +
68484 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
68485 +{
68486 + struct acl_role_label_compat rolecompat;
68487 +
68488 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
68489 + return -EFAULT;
68490 +
68491 + role->rolename = compat_ptr(rolecompat.rolename);
68492 + role->uidgid = rolecompat.uidgid;
68493 + role->roletype = rolecompat.roletype;
68494 +
68495 + role->auth_attempts = rolecompat.auth_attempts;
68496 + role->expires = rolecompat.expires;
68497 +
68498 + role->root_label = compat_ptr(rolecompat.root_label);
68499 + role->hash = compat_ptr(rolecompat.hash);
68500 +
68501 + role->prev = compat_ptr(rolecompat.prev);
68502 + role->next = compat_ptr(rolecompat.next);
68503 +
68504 + role->transitions = compat_ptr(rolecompat.transitions);
68505 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68506 + role->domain_children = compat_ptr(rolecompat.domain_children);
68507 + role->domain_child_num = rolecompat.domain_child_num;
68508 +
68509 + role->umask = rolecompat.umask;
68510 +
68511 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
68512 + role->subj_hash_size = rolecompat.subj_hash_size;
68513 +
68514 + return 0;
68515 +}
68516 +
68517 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68518 +{
68519 + struct role_allowed_ip_compat roleip_compat;
68520 +
68521 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68522 + return -EFAULT;
68523 +
68524 + roleip->addr = roleip_compat.addr;
68525 + roleip->netmask = roleip_compat.netmask;
68526 +
68527 + roleip->prev = compat_ptr(roleip_compat.prev);
68528 + roleip->next = compat_ptr(roleip_compat.next);
68529 +
68530 + return 0;
68531 +}
68532 +
68533 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68534 +{
68535 + struct role_transition_compat trans_compat;
68536 +
68537 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68538 + return -EFAULT;
68539 +
68540 + trans->rolename = compat_ptr(trans_compat.rolename);
68541 +
68542 + trans->prev = compat_ptr(trans_compat.prev);
68543 + trans->next = compat_ptr(trans_compat.next);
68544 +
68545 + return 0;
68546 +
68547 +}
68548 +
68549 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68550 +{
68551 + struct gr_hash_struct_compat hash_compat;
68552 +
68553 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68554 + return -EFAULT;
68555 +
68556 + hash->table = compat_ptr(hash_compat.table);
68557 + hash->nametable = compat_ptr(hash_compat.nametable);
68558 + hash->first = compat_ptr(hash_compat.first);
68559 +
68560 + hash->table_size = hash_compat.table_size;
68561 + hash->used_size = hash_compat.used_size;
68562 +
68563 + hash->type = hash_compat.type;
68564 +
68565 + return 0;
68566 +}
68567 +
68568 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68569 +{
68570 + compat_uptr_t ptrcompat;
68571 +
68572 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68573 + return -EFAULT;
68574 +
68575 + *(void **)ptr = compat_ptr(ptrcompat);
68576 +
68577 + return 0;
68578 +}
68579 +
68580 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68581 +{
68582 + struct acl_ip_label_compat ip_compat;
68583 +
68584 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68585 + return -EFAULT;
68586 +
68587 + ip->iface = compat_ptr(ip_compat.iface);
68588 + ip->addr = ip_compat.addr;
68589 + ip->netmask = ip_compat.netmask;
68590 + ip->low = ip_compat.low;
68591 + ip->high = ip_compat.high;
68592 + ip->mode = ip_compat.mode;
68593 + ip->type = ip_compat.type;
68594 +
68595 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68596 +
68597 + ip->prev = compat_ptr(ip_compat.prev);
68598 + ip->next = compat_ptr(ip_compat.next);
68599 +
68600 + return 0;
68601 +}
68602 +
68603 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68604 +{
68605 + struct sprole_pw_compat pw_compat;
68606 +
68607 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68608 + return -EFAULT;
68609 +
68610 + pw->rolename = compat_ptr(pw_compat.rolename);
68611 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68612 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68613 +
68614 + return 0;
68615 +}
68616 +
68617 +size_t get_gr_arg_wrapper_size_compat(void)
68618 +{
68619 + return sizeof(struct gr_arg_wrapper_compat);
68620 +}
68621 +
68622 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68623 new file mode 100644
68624 index 0000000..a89b1f4
68625 --- /dev/null
68626 +++ b/grsecurity/gracl_fs.c
68627 @@ -0,0 +1,437 @@
68628 +#include <linux/kernel.h>
68629 +#include <linux/sched.h>
68630 +#include <linux/types.h>
68631 +#include <linux/fs.h>
68632 +#include <linux/file.h>
68633 +#include <linux/stat.h>
68634 +#include <linux/grsecurity.h>
68635 +#include <linux/grinternal.h>
68636 +#include <linux/gracl.h>
68637 +
68638 +umode_t
68639 +gr_acl_umask(void)
68640 +{
68641 + if (unlikely(!gr_acl_is_enabled()))
68642 + return 0;
68643 +
68644 + return current->role->umask;
68645 +}
68646 +
68647 +__u32
68648 +gr_acl_handle_hidden_file(const struct dentry * dentry,
68649 + const struct vfsmount * mnt)
68650 +{
68651 + __u32 mode;
68652 +
68653 + if (unlikely(d_is_negative(dentry)))
68654 + return GR_FIND;
68655 +
68656 + mode =
68657 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68658 +
68659 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68660 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68661 + return mode;
68662 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68663 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68664 + return 0;
68665 + } else if (unlikely(!(mode & GR_FIND)))
68666 + return 0;
68667 +
68668 + return GR_FIND;
68669 +}
68670 +
68671 +__u32
68672 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68673 + int acc_mode)
68674 +{
68675 + __u32 reqmode = GR_FIND;
68676 + __u32 mode;
68677 +
68678 + if (unlikely(d_is_negative(dentry)))
68679 + return reqmode;
68680 +
68681 + if (acc_mode & MAY_APPEND)
68682 + reqmode |= GR_APPEND;
68683 + else if (acc_mode & MAY_WRITE)
68684 + reqmode |= GR_WRITE;
68685 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68686 + reqmode |= GR_READ;
68687 +
68688 + mode =
68689 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68690 + mnt);
68691 +
68692 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68693 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68694 + reqmode & GR_READ ? " reading" : "",
68695 + reqmode & GR_WRITE ? " writing" : reqmode &
68696 + GR_APPEND ? " appending" : "");
68697 + return reqmode;
68698 + } else
68699 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68700 + {
68701 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68702 + reqmode & GR_READ ? " reading" : "",
68703 + reqmode & GR_WRITE ? " writing" : reqmode &
68704 + GR_APPEND ? " appending" : "");
68705 + return 0;
68706 + } else if (unlikely((mode & reqmode) != reqmode))
68707 + return 0;
68708 +
68709 + return reqmode;
68710 +}
68711 +
68712 +__u32
68713 +gr_acl_handle_creat(const struct dentry * dentry,
68714 + const struct dentry * p_dentry,
68715 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68716 + const int imode)
68717 +{
68718 + __u32 reqmode = GR_WRITE | GR_CREATE;
68719 + __u32 mode;
68720 +
68721 + if (acc_mode & MAY_APPEND)
68722 + reqmode |= GR_APPEND;
68723 + // if a directory was required or the directory already exists, then
68724 + // don't count this open as a read
68725 + if ((acc_mode & MAY_READ) &&
68726 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68727 + reqmode |= GR_READ;
68728 + if ((open_flags & O_CREAT) &&
68729 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68730 + reqmode |= GR_SETID;
68731 +
68732 + mode =
68733 + gr_check_create(dentry, p_dentry, p_mnt,
68734 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68735 +
68736 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68737 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68738 + reqmode & GR_READ ? " reading" : "",
68739 + reqmode & GR_WRITE ? " writing" : reqmode &
68740 + GR_APPEND ? " appending" : "");
68741 + return reqmode;
68742 + } else
68743 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68744 + {
68745 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68746 + reqmode & GR_READ ? " reading" : "",
68747 + reqmode & GR_WRITE ? " writing" : reqmode &
68748 + GR_APPEND ? " appending" : "");
68749 + return 0;
68750 + } else if (unlikely((mode & reqmode) != reqmode))
68751 + return 0;
68752 +
68753 + return reqmode;
68754 +}
68755 +
68756 +__u32
68757 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68758 + const int fmode)
68759 +{
68760 + __u32 mode, reqmode = GR_FIND;
68761 +
68762 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68763 + reqmode |= GR_EXEC;
68764 + if (fmode & S_IWOTH)
68765 + reqmode |= GR_WRITE;
68766 + if (fmode & S_IROTH)
68767 + reqmode |= GR_READ;
68768 +
68769 + mode =
68770 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68771 + mnt);
68772 +
68773 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68774 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68775 + reqmode & GR_READ ? " reading" : "",
68776 + reqmode & GR_WRITE ? " writing" : "",
68777 + reqmode & GR_EXEC ? " executing" : "");
68778 + return reqmode;
68779 + } else
68780 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68781 + {
68782 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68783 + reqmode & GR_READ ? " reading" : "",
68784 + reqmode & GR_WRITE ? " writing" : "",
68785 + reqmode & GR_EXEC ? " executing" : "");
68786 + return 0;
68787 + } else if (unlikely((mode & reqmode) != reqmode))
68788 + return 0;
68789 +
68790 + return reqmode;
68791 +}
68792 +
68793 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68794 +{
68795 + __u32 mode;
68796 +
68797 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68798 +
68799 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68800 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68801 + return mode;
68802 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68803 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68804 + return 0;
68805 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
68806 + return 0;
68807 +
68808 + return (reqmode);
68809 +}
68810 +
68811 +__u32
68812 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68813 +{
68814 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68815 +}
68816 +
68817 +__u32
68818 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68819 +{
68820 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68821 +}
68822 +
68823 +__u32
68824 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68825 +{
68826 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68827 +}
68828 +
68829 +__u32
68830 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68831 +{
68832 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68833 +}
68834 +
68835 +__u32
68836 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68837 + umode_t *modeptr)
68838 +{
68839 + umode_t mode;
68840 +
68841 + *modeptr &= ~gr_acl_umask();
68842 + mode = *modeptr;
68843 +
68844 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68845 + return 1;
68846 +
68847 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68848 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68849 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68850 + GR_CHMOD_ACL_MSG);
68851 + } else {
68852 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68853 + }
68854 +}
68855 +
68856 +__u32
68857 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68858 +{
68859 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68860 +}
68861 +
68862 +__u32
68863 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68864 +{
68865 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68866 +}
68867 +
68868 +__u32
68869 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
68870 +{
68871 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
68872 +}
68873 +
68874 +__u32
68875 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68876 +{
68877 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68878 +}
68879 +
68880 +__u32
68881 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68882 +{
68883 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68884 + GR_UNIXCONNECT_ACL_MSG);
68885 +}
68886 +
68887 +/* hardlinks require at minimum create and link permission,
68888 + any additional privilege required is based on the
68889 + privilege of the file being linked to
68890 +*/
68891 +__u32
68892 +gr_acl_handle_link(const struct dentry * new_dentry,
68893 + const struct dentry * parent_dentry,
68894 + const struct vfsmount * parent_mnt,
68895 + const struct dentry * old_dentry,
68896 + const struct vfsmount * old_mnt, const struct filename *to)
68897 +{
68898 + __u32 mode;
68899 + __u32 needmode = GR_CREATE | GR_LINK;
68900 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68901 +
68902 + mode =
68903 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68904 + old_mnt);
68905 +
68906 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68907 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68908 + return mode;
68909 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68910 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68911 + return 0;
68912 + } else if (unlikely((mode & needmode) != needmode))
68913 + return 0;
68914 +
68915 + return 1;
68916 +}
68917 +
68918 +__u32
68919 +gr_acl_handle_symlink(const struct dentry * new_dentry,
68920 + const struct dentry * parent_dentry,
68921 + const struct vfsmount * parent_mnt, const struct filename *from)
68922 +{
68923 + __u32 needmode = GR_WRITE | GR_CREATE;
68924 + __u32 mode;
68925 +
68926 + mode =
68927 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
68928 + GR_CREATE | GR_AUDIT_CREATE |
68929 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68930 +
68931 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68932 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68933 + return mode;
68934 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68935 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68936 + return 0;
68937 + } else if (unlikely((mode & needmode) != needmode))
68938 + return 0;
68939 +
68940 + return (GR_WRITE | GR_CREATE);
68941 +}
68942 +
68943 +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)
68944 +{
68945 + __u32 mode;
68946 +
68947 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68948 +
68949 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68950 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68951 + return mode;
68952 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68953 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68954 + return 0;
68955 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
68956 + return 0;
68957 +
68958 + return (reqmode);
68959 +}
68960 +
68961 +__u32
68962 +gr_acl_handle_mknod(const struct dentry * new_dentry,
68963 + const struct dentry * parent_dentry,
68964 + const struct vfsmount * parent_mnt,
68965 + const int mode)
68966 +{
68967 + __u32 reqmode = GR_WRITE | GR_CREATE;
68968 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68969 + reqmode |= GR_SETID;
68970 +
68971 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68972 + reqmode, GR_MKNOD_ACL_MSG);
68973 +}
68974 +
68975 +__u32
68976 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
68977 + const struct dentry *parent_dentry,
68978 + const struct vfsmount *parent_mnt)
68979 +{
68980 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68981 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
68982 +}
68983 +
68984 +#define RENAME_CHECK_SUCCESS(old, new) \
68985 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
68986 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
68987 +
68988 +int
68989 +gr_acl_handle_rename(struct dentry *new_dentry,
68990 + struct dentry *parent_dentry,
68991 + const struct vfsmount *parent_mnt,
68992 + struct dentry *old_dentry,
68993 + struct inode *old_parent_inode,
68994 + struct vfsmount *old_mnt, const struct filename *newname)
68995 +{
68996 + __u32 comp1, comp2;
68997 + int error = 0;
68998 +
68999 + if (unlikely(!gr_acl_is_enabled()))
69000 + return 0;
69001 +
69002 + if (d_is_negative(new_dentry)) {
69003 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69004 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69005 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69006 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69007 + GR_DELETE | GR_AUDIT_DELETE |
69008 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69009 + GR_SUPPRESS, old_mnt);
69010 + } else {
69011 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69012 + GR_CREATE | GR_DELETE |
69013 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69014 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69015 + GR_SUPPRESS, parent_mnt);
69016 + comp2 =
69017 + gr_search_file(old_dentry,
69018 + GR_READ | GR_WRITE | GR_AUDIT_READ |
69019 + GR_DELETE | GR_AUDIT_DELETE |
69020 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69021 + }
69022 +
69023 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69024 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69025 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69026 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69027 + && !(comp2 & GR_SUPPRESS)) {
69028 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69029 + error = -EACCES;
69030 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69031 + error = -EACCES;
69032 +
69033 + return error;
69034 +}
69035 +
69036 +void
69037 +gr_acl_handle_exit(void)
69038 +{
69039 + u16 id;
69040 + char *rolename;
69041 +
69042 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69043 + !(current->role->roletype & GR_ROLE_PERSIST))) {
69044 + id = current->acl_role_id;
69045 + rolename = current->role->rolename;
69046 + gr_set_acls(1);
69047 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69048 + }
69049 +
69050 + gr_put_exec_file(current);
69051 + return;
69052 +}
69053 +
69054 +int
69055 +gr_acl_handle_procpidmem(const struct task_struct *task)
69056 +{
69057 + if (unlikely(!gr_acl_is_enabled()))
69058 + return 0;
69059 +
69060 + if (task != current && task->acl->mode & GR_PROTPROCFD)
69061 + return -EACCES;
69062 +
69063 + return 0;
69064 +}
69065 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
69066 new file mode 100644
69067 index 0000000..f056b81
69068 --- /dev/null
69069 +++ b/grsecurity/gracl_ip.c
69070 @@ -0,0 +1,386 @@
69071 +#include <linux/kernel.h>
69072 +#include <asm/uaccess.h>
69073 +#include <asm/errno.h>
69074 +#include <net/sock.h>
69075 +#include <linux/file.h>
69076 +#include <linux/fs.h>
69077 +#include <linux/net.h>
69078 +#include <linux/in.h>
69079 +#include <linux/skbuff.h>
69080 +#include <linux/ip.h>
69081 +#include <linux/udp.h>
69082 +#include <linux/types.h>
69083 +#include <linux/sched.h>
69084 +#include <linux/netdevice.h>
69085 +#include <linux/inetdevice.h>
69086 +#include <linux/gracl.h>
69087 +#include <linux/grsecurity.h>
69088 +#include <linux/grinternal.h>
69089 +
69090 +#define GR_BIND 0x01
69091 +#define GR_CONNECT 0x02
69092 +#define GR_INVERT 0x04
69093 +#define GR_BINDOVERRIDE 0x08
69094 +#define GR_CONNECTOVERRIDE 0x10
69095 +#define GR_SOCK_FAMILY 0x20
69096 +
69097 +static const char * gr_protocols[IPPROTO_MAX] = {
69098 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
69099 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
69100 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
69101 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
69102 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
69103 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
69104 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
69105 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
69106 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
69107 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
69108 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
69109 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
69110 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
69111 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
69112 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
69113 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
69114 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
69115 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
69116 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
69117 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
69118 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
69119 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
69120 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
69121 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
69122 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69123 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69124 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69125 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69126 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69127 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69128 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
69129 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
69130 + };
69131 +
69132 +static const char * gr_socktypes[SOCK_MAX] = {
69133 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
69134 + "unknown:7", "unknown:8", "unknown:9", "packet"
69135 + };
69136 +
69137 +static const char * gr_sockfamilies[AF_MAX+1] = {
69138 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
69139 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
69140 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
69141 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
69142 + };
69143 +
69144 +const char *
69145 +gr_proto_to_name(unsigned char proto)
69146 +{
69147 + return gr_protocols[proto];
69148 +}
69149 +
69150 +const char *
69151 +gr_socktype_to_name(unsigned char type)
69152 +{
69153 + return gr_socktypes[type];
69154 +}
69155 +
69156 +const char *
69157 +gr_sockfamily_to_name(unsigned char family)
69158 +{
69159 + return gr_sockfamilies[family];
69160 +}
69161 +
69162 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
69163 +
69164 +int
69165 +gr_search_socket(const int domain, const int type, const int protocol)
69166 +{
69167 + struct acl_subject_label *curr;
69168 + const struct cred *cred = current_cred();
69169 +
69170 + if (unlikely(!gr_acl_is_enabled()))
69171 + goto exit;
69172 +
69173 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
69174 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
69175 + goto exit; // let the kernel handle it
69176 +
69177 + curr = current->acl;
69178 +
69179 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
69180 + /* the family is allowed, if this is PF_INET allow it only if
69181 + the extra sock type/protocol checks pass */
69182 + if (domain == PF_INET)
69183 + goto inet_check;
69184 + goto exit;
69185 + } else {
69186 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69187 + __u32 fakeip = 0;
69188 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69189 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69190 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69191 + gr_to_filename(current->exec_file->f_path.dentry,
69192 + current->exec_file->f_path.mnt) :
69193 + curr->filename, curr->filename,
69194 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
69195 + &current->signal->saved_ip);
69196 + goto exit;
69197 + }
69198 + goto exit_fail;
69199 + }
69200 +
69201 +inet_check:
69202 + /* the rest of this checking is for IPv4 only */
69203 + if (!curr->ips)
69204 + goto exit;
69205 +
69206 + if ((curr->ip_type & (1U << type)) &&
69207 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
69208 + goto exit;
69209 +
69210 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69211 + /* we don't place acls on raw sockets , and sometimes
69212 + dgram/ip sockets are opened for ioctl and not
69213 + bind/connect, so we'll fake a bind learn log */
69214 + if (type == SOCK_RAW || type == SOCK_PACKET) {
69215 + __u32 fakeip = 0;
69216 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69217 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69218 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69219 + gr_to_filename(current->exec_file->f_path.dentry,
69220 + current->exec_file->f_path.mnt) :
69221 + curr->filename, curr->filename,
69222 + &fakeip, 0, type,
69223 + protocol, GR_CONNECT, &current->signal->saved_ip);
69224 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
69225 + __u32 fakeip = 0;
69226 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69227 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69228 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69229 + gr_to_filename(current->exec_file->f_path.dentry,
69230 + current->exec_file->f_path.mnt) :
69231 + curr->filename, curr->filename,
69232 + &fakeip, 0, type,
69233 + protocol, GR_BIND, &current->signal->saved_ip);
69234 + }
69235 + /* we'll log when they use connect or bind */
69236 + goto exit;
69237 + }
69238 +
69239 +exit_fail:
69240 + if (domain == PF_INET)
69241 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
69242 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
69243 + else if (rcu_access_pointer(net_families[domain]) != NULL)
69244 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
69245 + gr_socktype_to_name(type), protocol);
69246 +
69247 + return 0;
69248 +exit:
69249 + return 1;
69250 +}
69251 +
69252 +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)
69253 +{
69254 + if ((ip->mode & mode) &&
69255 + (ip_port >= ip->low) &&
69256 + (ip_port <= ip->high) &&
69257 + ((ntohl(ip_addr) & our_netmask) ==
69258 + (ntohl(our_addr) & our_netmask))
69259 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
69260 + && (ip->type & (1U << type))) {
69261 + if (ip->mode & GR_INVERT)
69262 + return 2; // specifically denied
69263 + else
69264 + return 1; // allowed
69265 + }
69266 +
69267 + return 0; // not specifically allowed, may continue parsing
69268 +}
69269 +
69270 +static int
69271 +gr_search_connectbind(const int full_mode, struct sock *sk,
69272 + struct sockaddr_in *addr, const int type)
69273 +{
69274 + char iface[IFNAMSIZ] = {0};
69275 + struct acl_subject_label *curr;
69276 + struct acl_ip_label *ip;
69277 + struct inet_sock *isk;
69278 + struct net_device *dev;
69279 + struct in_device *idev;
69280 + unsigned long i;
69281 + int ret;
69282 + int mode = full_mode & (GR_BIND | GR_CONNECT);
69283 + __u32 ip_addr = 0;
69284 + __u32 our_addr;
69285 + __u32 our_netmask;
69286 + char *p;
69287 + __u16 ip_port = 0;
69288 + const struct cred *cred = current_cred();
69289 +
69290 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
69291 + return 0;
69292 +
69293 + curr = current->acl;
69294 + isk = inet_sk(sk);
69295 +
69296 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
69297 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
69298 + addr->sin_addr.s_addr = curr->inaddr_any_override;
69299 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
69300 + struct sockaddr_in saddr;
69301 + int err;
69302 +
69303 + saddr.sin_family = AF_INET;
69304 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
69305 + saddr.sin_port = isk->inet_sport;
69306 +
69307 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69308 + if (err)
69309 + return err;
69310 +
69311 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69312 + if (err)
69313 + return err;
69314 + }
69315 +
69316 + if (!curr->ips)
69317 + return 0;
69318 +
69319 + ip_addr = addr->sin_addr.s_addr;
69320 + ip_port = ntohs(addr->sin_port);
69321 +
69322 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69323 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69324 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69325 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69326 + gr_to_filename(current->exec_file->f_path.dentry,
69327 + current->exec_file->f_path.mnt) :
69328 + curr->filename, curr->filename,
69329 + &ip_addr, ip_port, type,
69330 + sk->sk_protocol, mode, &current->signal->saved_ip);
69331 + return 0;
69332 + }
69333 +
69334 + for (i = 0; i < curr->ip_num; i++) {
69335 + ip = *(curr->ips + i);
69336 + if (ip->iface != NULL) {
69337 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
69338 + p = strchr(iface, ':');
69339 + if (p != NULL)
69340 + *p = '\0';
69341 + dev = dev_get_by_name(sock_net(sk), iface);
69342 + if (dev == NULL)
69343 + continue;
69344 + idev = in_dev_get(dev);
69345 + if (idev == NULL) {
69346 + dev_put(dev);
69347 + continue;
69348 + }
69349 + rcu_read_lock();
69350 + for_ifa(idev) {
69351 + if (!strcmp(ip->iface, ifa->ifa_label)) {
69352 + our_addr = ifa->ifa_address;
69353 + our_netmask = 0xffffffff;
69354 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69355 + if (ret == 1) {
69356 + rcu_read_unlock();
69357 + in_dev_put(idev);
69358 + dev_put(dev);
69359 + return 0;
69360 + } else if (ret == 2) {
69361 + rcu_read_unlock();
69362 + in_dev_put(idev);
69363 + dev_put(dev);
69364 + goto denied;
69365 + }
69366 + }
69367 + } endfor_ifa(idev);
69368 + rcu_read_unlock();
69369 + in_dev_put(idev);
69370 + dev_put(dev);
69371 + } else {
69372 + our_addr = ip->addr;
69373 + our_netmask = ip->netmask;
69374 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69375 + if (ret == 1)
69376 + return 0;
69377 + else if (ret == 2)
69378 + goto denied;
69379 + }
69380 + }
69381 +
69382 +denied:
69383 + if (mode == GR_BIND)
69384 + 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));
69385 + else if (mode == GR_CONNECT)
69386 + 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));
69387 +
69388 + return -EACCES;
69389 +}
69390 +
69391 +int
69392 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
69393 +{
69394 + /* always allow disconnection of dgram sockets with connect */
69395 + if (addr->sin_family == AF_UNSPEC)
69396 + return 0;
69397 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
69398 +}
69399 +
69400 +int
69401 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
69402 +{
69403 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
69404 +}
69405 +
69406 +int gr_search_listen(struct socket *sock)
69407 +{
69408 + struct sock *sk = sock->sk;
69409 + struct sockaddr_in addr;
69410 +
69411 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69412 + addr.sin_port = inet_sk(sk)->inet_sport;
69413 +
69414 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69415 +}
69416 +
69417 +int gr_search_accept(struct socket *sock)
69418 +{
69419 + struct sock *sk = sock->sk;
69420 + struct sockaddr_in addr;
69421 +
69422 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69423 + addr.sin_port = inet_sk(sk)->inet_sport;
69424 +
69425 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69426 +}
69427 +
69428 +int
69429 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
69430 +{
69431 + if (addr)
69432 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
69433 + else {
69434 + struct sockaddr_in sin;
69435 + const struct inet_sock *inet = inet_sk(sk);
69436 +
69437 + sin.sin_addr.s_addr = inet->inet_daddr;
69438 + sin.sin_port = inet->inet_dport;
69439 +
69440 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69441 + }
69442 +}
69443 +
69444 +int
69445 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
69446 +{
69447 + struct sockaddr_in sin;
69448 +
69449 + if (unlikely(skb->len < sizeof (struct udphdr)))
69450 + return 0; // skip this packet
69451 +
69452 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
69453 + sin.sin_port = udp_hdr(skb)->source;
69454 +
69455 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69456 +}
69457 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
69458 new file mode 100644
69459 index 0000000..25f54ef
69460 --- /dev/null
69461 +++ b/grsecurity/gracl_learn.c
69462 @@ -0,0 +1,207 @@
69463 +#include <linux/kernel.h>
69464 +#include <linux/mm.h>
69465 +#include <linux/sched.h>
69466 +#include <linux/poll.h>
69467 +#include <linux/string.h>
69468 +#include <linux/file.h>
69469 +#include <linux/types.h>
69470 +#include <linux/vmalloc.h>
69471 +#include <linux/grinternal.h>
69472 +
69473 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
69474 + size_t count, loff_t *ppos);
69475 +extern int gr_acl_is_enabled(void);
69476 +
69477 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
69478 +static int gr_learn_attached;
69479 +
69480 +/* use a 512k buffer */
69481 +#define LEARN_BUFFER_SIZE (512 * 1024)
69482 +
69483 +static DEFINE_SPINLOCK(gr_learn_lock);
69484 +static DEFINE_MUTEX(gr_learn_user_mutex);
69485 +
69486 +/* we need to maintain two buffers, so that the kernel context of grlearn
69487 + uses a semaphore around the userspace copying, and the other kernel contexts
69488 + use a spinlock when copying into the buffer, since they cannot sleep
69489 +*/
69490 +static char *learn_buffer;
69491 +static char *learn_buffer_user;
69492 +static int learn_buffer_len;
69493 +static int learn_buffer_user_len;
69494 +
69495 +static ssize_t
69496 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
69497 +{
69498 + DECLARE_WAITQUEUE(wait, current);
69499 + ssize_t retval = 0;
69500 +
69501 + add_wait_queue(&learn_wait, &wait);
69502 + set_current_state(TASK_INTERRUPTIBLE);
69503 + do {
69504 + mutex_lock(&gr_learn_user_mutex);
69505 + spin_lock(&gr_learn_lock);
69506 + if (learn_buffer_len)
69507 + break;
69508 + spin_unlock(&gr_learn_lock);
69509 + mutex_unlock(&gr_learn_user_mutex);
69510 + if (file->f_flags & O_NONBLOCK) {
69511 + retval = -EAGAIN;
69512 + goto out;
69513 + }
69514 + if (signal_pending(current)) {
69515 + retval = -ERESTARTSYS;
69516 + goto out;
69517 + }
69518 +
69519 + schedule();
69520 + } while (1);
69521 +
69522 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69523 + learn_buffer_user_len = learn_buffer_len;
69524 + retval = learn_buffer_len;
69525 + learn_buffer_len = 0;
69526 +
69527 + spin_unlock(&gr_learn_lock);
69528 +
69529 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69530 + retval = -EFAULT;
69531 +
69532 + mutex_unlock(&gr_learn_user_mutex);
69533 +out:
69534 + set_current_state(TASK_RUNNING);
69535 + remove_wait_queue(&learn_wait, &wait);
69536 + return retval;
69537 +}
69538 +
69539 +static unsigned int
69540 +poll_learn(struct file * file, poll_table * wait)
69541 +{
69542 + poll_wait(file, &learn_wait, wait);
69543 +
69544 + if (learn_buffer_len)
69545 + return (POLLIN | POLLRDNORM);
69546 +
69547 + return 0;
69548 +}
69549 +
69550 +void
69551 +gr_clear_learn_entries(void)
69552 +{
69553 + char *tmp;
69554 +
69555 + mutex_lock(&gr_learn_user_mutex);
69556 + spin_lock(&gr_learn_lock);
69557 + tmp = learn_buffer;
69558 + learn_buffer = NULL;
69559 + spin_unlock(&gr_learn_lock);
69560 + if (tmp)
69561 + vfree(tmp);
69562 + if (learn_buffer_user != NULL) {
69563 + vfree(learn_buffer_user);
69564 + learn_buffer_user = NULL;
69565 + }
69566 + learn_buffer_len = 0;
69567 + mutex_unlock(&gr_learn_user_mutex);
69568 +
69569 + return;
69570 +}
69571 +
69572 +void
69573 +gr_add_learn_entry(const char *fmt, ...)
69574 +{
69575 + va_list args;
69576 + unsigned int len;
69577 +
69578 + if (!gr_learn_attached)
69579 + return;
69580 +
69581 + spin_lock(&gr_learn_lock);
69582 +
69583 + /* leave a gap at the end so we know when it's "full" but don't have to
69584 + compute the exact length of the string we're trying to append
69585 + */
69586 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69587 + spin_unlock(&gr_learn_lock);
69588 + wake_up_interruptible(&learn_wait);
69589 + return;
69590 + }
69591 + if (learn_buffer == NULL) {
69592 + spin_unlock(&gr_learn_lock);
69593 + return;
69594 + }
69595 +
69596 + va_start(args, fmt);
69597 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69598 + va_end(args);
69599 +
69600 + learn_buffer_len += len + 1;
69601 +
69602 + spin_unlock(&gr_learn_lock);
69603 + wake_up_interruptible(&learn_wait);
69604 +
69605 + return;
69606 +}
69607 +
69608 +static int
69609 +open_learn(struct inode *inode, struct file *file)
69610 +{
69611 + if (file->f_mode & FMODE_READ && gr_learn_attached)
69612 + return -EBUSY;
69613 + if (file->f_mode & FMODE_READ) {
69614 + int retval = 0;
69615 + mutex_lock(&gr_learn_user_mutex);
69616 + if (learn_buffer == NULL)
69617 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69618 + if (learn_buffer_user == NULL)
69619 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69620 + if (learn_buffer == NULL) {
69621 + retval = -ENOMEM;
69622 + goto out_error;
69623 + }
69624 + if (learn_buffer_user == NULL) {
69625 + retval = -ENOMEM;
69626 + goto out_error;
69627 + }
69628 + learn_buffer_len = 0;
69629 + learn_buffer_user_len = 0;
69630 + gr_learn_attached = 1;
69631 +out_error:
69632 + mutex_unlock(&gr_learn_user_mutex);
69633 + return retval;
69634 + }
69635 + return 0;
69636 +}
69637 +
69638 +static int
69639 +close_learn(struct inode *inode, struct file *file)
69640 +{
69641 + if (file->f_mode & FMODE_READ) {
69642 + char *tmp = NULL;
69643 + mutex_lock(&gr_learn_user_mutex);
69644 + spin_lock(&gr_learn_lock);
69645 + tmp = learn_buffer;
69646 + learn_buffer = NULL;
69647 + spin_unlock(&gr_learn_lock);
69648 + if (tmp)
69649 + vfree(tmp);
69650 + if (learn_buffer_user != NULL) {
69651 + vfree(learn_buffer_user);
69652 + learn_buffer_user = NULL;
69653 + }
69654 + learn_buffer_len = 0;
69655 + learn_buffer_user_len = 0;
69656 + gr_learn_attached = 0;
69657 + mutex_unlock(&gr_learn_user_mutex);
69658 + }
69659 +
69660 + return 0;
69661 +}
69662 +
69663 +const struct file_operations grsec_fops = {
69664 + .read = read_learn,
69665 + .write = write_grsec_handler,
69666 + .open = open_learn,
69667 + .release = close_learn,
69668 + .poll = poll_learn,
69669 +};
69670 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
69671 new file mode 100644
69672 index 0000000..361a099
69673 --- /dev/null
69674 +++ b/grsecurity/gracl_policy.c
69675 @@ -0,0 +1,1782 @@
69676 +#include <linux/kernel.h>
69677 +#include <linux/module.h>
69678 +#include <linux/sched.h>
69679 +#include <linux/mm.h>
69680 +#include <linux/file.h>
69681 +#include <linux/fs.h>
69682 +#include <linux/namei.h>
69683 +#include <linux/mount.h>
69684 +#include <linux/tty.h>
69685 +#include <linux/proc_fs.h>
69686 +#include <linux/lglock.h>
69687 +#include <linux/slab.h>
69688 +#include <linux/vmalloc.h>
69689 +#include <linux/types.h>
69690 +#include <linux/sysctl.h>
69691 +#include <linux/netdevice.h>
69692 +#include <linux/ptrace.h>
69693 +#include <linux/gracl.h>
69694 +#include <linux/gralloc.h>
69695 +#include <linux/security.h>
69696 +#include <linux/grinternal.h>
69697 +#include <linux/pid_namespace.h>
69698 +#include <linux/stop_machine.h>
69699 +#include <linux/fdtable.h>
69700 +#include <linux/percpu.h>
69701 +#include <linux/lglock.h>
69702 +#include <linux/hugetlb.h>
69703 +#include <linux/posix-timers.h>
69704 +#include "../fs/mount.h"
69705 +
69706 +#include <asm/uaccess.h>
69707 +#include <asm/errno.h>
69708 +#include <asm/mman.h>
69709 +
69710 +extern struct gr_policy_state *polstate;
69711 +
69712 +#define FOR_EACH_ROLE_START(role) \
69713 + role = polstate->role_list; \
69714 + while (role) {
69715 +
69716 +#define FOR_EACH_ROLE_END(role) \
69717 + role = role->prev; \
69718 + }
69719 +
69720 +struct path gr_real_root;
69721 +
69722 +extern struct gr_alloc_state *current_alloc_state;
69723 +
69724 +u16 acl_sp_role_value;
69725 +
69726 +static DEFINE_MUTEX(gr_dev_mutex);
69727 +
69728 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
69729 +extern void gr_clear_learn_entries(void);
69730 +
69731 +static struct gr_arg gr_usermode;
69732 +static unsigned char gr_system_salt[GR_SALT_LEN];
69733 +static unsigned char gr_system_sum[GR_SHA_LEN];
69734 +
69735 +static unsigned int gr_auth_attempts = 0;
69736 +static unsigned long gr_auth_expires = 0UL;
69737 +
69738 +struct acl_object_label *fakefs_obj_rw;
69739 +struct acl_object_label *fakefs_obj_rwx;
69740 +
69741 +extern int gr_init_uidset(void);
69742 +extern void gr_free_uidset(void);
69743 +extern void gr_remove_uid(uid_t uid);
69744 +extern int gr_find_uid(uid_t uid);
69745 +
69746 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
69747 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
69748 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
69749 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
69750 +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);
69751 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
69752 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
69753 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
69754 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
69755 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69756 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69757 +extern void assign_special_role(const char *rolename);
69758 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
69759 +extern int gr_rbac_disable(void *unused);
69760 +extern void gr_enable_rbac_system(void);
69761 +
69762 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
69763 +{
69764 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
69765 + return -EFAULT;
69766 +
69767 + return 0;
69768 +}
69769 +
69770 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69771 +{
69772 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
69773 + return -EFAULT;
69774 +
69775 + return 0;
69776 +}
69777 +
69778 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69779 +{
69780 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
69781 + return -EFAULT;
69782 +
69783 + return 0;
69784 +}
69785 +
69786 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
69787 +{
69788 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
69789 + return -EFAULT;
69790 +
69791 + return 0;
69792 +}
69793 +
69794 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69795 +{
69796 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
69797 + return -EFAULT;
69798 +
69799 + return 0;
69800 +}
69801 +
69802 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69803 +{
69804 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
69805 + return -EFAULT;
69806 +
69807 + return 0;
69808 +}
69809 +
69810 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69811 +{
69812 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
69813 + return -EFAULT;
69814 +
69815 + return 0;
69816 +}
69817 +
69818 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
69819 +{
69820 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
69821 + return -EFAULT;
69822 +
69823 + return 0;
69824 +}
69825 +
69826 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
69827 +{
69828 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
69829 + return -EFAULT;
69830 +
69831 + return 0;
69832 +}
69833 +
69834 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
69835 +{
69836 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
69837 + return -EFAULT;
69838 +
69839 + if (((uwrap->version != GRSECURITY_VERSION) &&
69840 + (uwrap->version != 0x2901)) ||
69841 + (uwrap->size != sizeof(struct gr_arg)))
69842 + return -EINVAL;
69843 +
69844 + return 0;
69845 +}
69846 +
69847 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
69848 +{
69849 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
69850 + return -EFAULT;
69851 +
69852 + return 0;
69853 +}
69854 +
69855 +static size_t get_gr_arg_wrapper_size_normal(void)
69856 +{
69857 + return sizeof(struct gr_arg_wrapper);
69858 +}
69859 +
69860 +#ifdef CONFIG_COMPAT
69861 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
69862 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
69863 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
69864 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
69865 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
69866 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
69867 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
69868 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
69869 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
69870 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
69871 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
69872 +extern size_t get_gr_arg_wrapper_size_compat(void);
69873 +
69874 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
69875 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
69876 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
69877 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
69878 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
69879 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
69880 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
69881 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
69882 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
69883 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
69884 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
69885 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
69886 +
69887 +#else
69888 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
69889 +#define copy_gr_arg copy_gr_arg_normal
69890 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
69891 +#define copy_acl_object_label copy_acl_object_label_normal
69892 +#define copy_acl_subject_label copy_acl_subject_label_normal
69893 +#define copy_acl_role_label copy_acl_role_label_normal
69894 +#define copy_acl_ip_label copy_acl_ip_label_normal
69895 +#define copy_pointer_from_array copy_pointer_from_array_normal
69896 +#define copy_sprole_pw copy_sprole_pw_normal
69897 +#define copy_role_transition copy_role_transition_normal
69898 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
69899 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
69900 +#endif
69901 +
69902 +static struct acl_subject_label *
69903 +lookup_subject_map(const struct acl_subject_label *userp)
69904 +{
69905 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
69906 + struct subject_map *match;
69907 +
69908 + match = polstate->subj_map_set.s_hash[index];
69909 +
69910 + while (match && match->user != userp)
69911 + match = match->next;
69912 +
69913 + if (match != NULL)
69914 + return match->kernel;
69915 + else
69916 + return NULL;
69917 +}
69918 +
69919 +static void
69920 +insert_subj_map_entry(struct subject_map *subjmap)
69921 +{
69922 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
69923 + struct subject_map **curr;
69924 +
69925 + subjmap->prev = NULL;
69926 +
69927 + curr = &polstate->subj_map_set.s_hash[index];
69928 + if (*curr != NULL)
69929 + (*curr)->prev = subjmap;
69930 +
69931 + subjmap->next = *curr;
69932 + *curr = subjmap;
69933 +
69934 + return;
69935 +}
69936 +
69937 +static void
69938 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
69939 +{
69940 + unsigned int index =
69941 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
69942 + struct acl_role_label **curr;
69943 + struct acl_role_label *tmp, *tmp2;
69944 +
69945 + curr = &polstate->acl_role_set.r_hash[index];
69946 +
69947 + /* simple case, slot is empty, just set it to our role */
69948 + if (*curr == NULL) {
69949 + *curr = role;
69950 + } else {
69951 + /* example:
69952 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
69953 + 2 -> 3
69954 + */
69955 + /* first check to see if we can already be reached via this slot */
69956 + tmp = *curr;
69957 + while (tmp && tmp != role)
69958 + tmp = tmp->next;
69959 + if (tmp == role) {
69960 + /* we don't need to add ourselves to this slot's chain */
69961 + return;
69962 + }
69963 + /* we need to add ourselves to this chain, two cases */
69964 + if (role->next == NULL) {
69965 + /* simple case, append the current chain to our role */
69966 + role->next = *curr;
69967 + *curr = role;
69968 + } else {
69969 + /* 1 -> 2 -> 3 -> 4
69970 + 2 -> 3 -> 4
69971 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
69972 + */
69973 + /* trickier case: walk our role's chain until we find
69974 + the role for the start of the current slot's chain */
69975 + tmp = role;
69976 + tmp2 = *curr;
69977 + while (tmp->next && tmp->next != tmp2)
69978 + tmp = tmp->next;
69979 + if (tmp->next == tmp2) {
69980 + /* from example above, we found 3, so just
69981 + replace this slot's chain with ours */
69982 + *curr = role;
69983 + } else {
69984 + /* we didn't find a subset of our role's chain
69985 + in the current slot's chain, so append their
69986 + chain to ours, and set us as the first role in
69987 + the slot's chain
69988 +
69989 + we could fold this case with the case above,
69990 + but making it explicit for clarity
69991 + */
69992 + tmp->next = tmp2;
69993 + *curr = role;
69994 + }
69995 + }
69996 + }
69997 +
69998 + return;
69999 +}
70000 +
70001 +static void
70002 +insert_acl_role_label(struct acl_role_label *role)
70003 +{
70004 + int i;
70005 +
70006 + if (polstate->role_list == NULL) {
70007 + polstate->role_list = role;
70008 + role->prev = NULL;
70009 + } else {
70010 + role->prev = polstate->role_list;
70011 + polstate->role_list = role;
70012 + }
70013 +
70014 + /* used for hash chains */
70015 + role->next = NULL;
70016 +
70017 + if (role->roletype & GR_ROLE_DOMAIN) {
70018 + for (i = 0; i < role->domain_child_num; i++)
70019 + __insert_acl_role_label(role, role->domain_children[i]);
70020 + } else
70021 + __insert_acl_role_label(role, role->uidgid);
70022 +}
70023 +
70024 +static int
70025 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70026 +{
70027 + struct name_entry **curr, *nentry;
70028 + struct inodev_entry *ientry;
70029 + unsigned int len = strlen(name);
70030 + unsigned int key = full_name_hash(name, len);
70031 + unsigned int index = key % polstate->name_set.n_size;
70032 +
70033 + curr = &polstate->name_set.n_hash[index];
70034 +
70035 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70036 + curr = &((*curr)->next);
70037 +
70038 + if (*curr != NULL)
70039 + return 1;
70040 +
70041 + nentry = acl_alloc(sizeof (struct name_entry));
70042 + if (nentry == NULL)
70043 + return 0;
70044 + ientry = acl_alloc(sizeof (struct inodev_entry));
70045 + if (ientry == NULL)
70046 + return 0;
70047 + ientry->nentry = nentry;
70048 +
70049 + nentry->key = key;
70050 + nentry->name = name;
70051 + nentry->inode = inode;
70052 + nentry->device = device;
70053 + nentry->len = len;
70054 + nentry->deleted = deleted;
70055 +
70056 + nentry->prev = NULL;
70057 + curr = &polstate->name_set.n_hash[index];
70058 + if (*curr != NULL)
70059 + (*curr)->prev = nentry;
70060 + nentry->next = *curr;
70061 + *curr = nentry;
70062 +
70063 + /* insert us into the table searchable by inode/dev */
70064 + __insert_inodev_entry(polstate, ientry);
70065 +
70066 + return 1;
70067 +}
70068 +
70069 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
70070 +
70071 +static void *
70072 +create_table(__u32 * len, int elementsize)
70073 +{
70074 + unsigned int table_sizes[] = {
70075 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
70076 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
70077 + 4194301, 8388593, 16777213, 33554393, 67108859
70078 + };
70079 + void *newtable = NULL;
70080 + unsigned int pwr = 0;
70081 +
70082 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
70083 + table_sizes[pwr] <= *len)
70084 + pwr++;
70085 +
70086 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
70087 + return newtable;
70088 +
70089 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
70090 + newtable =
70091 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
70092 + else
70093 + newtable = vmalloc(table_sizes[pwr] * elementsize);
70094 +
70095 + *len = table_sizes[pwr];
70096 +
70097 + return newtable;
70098 +}
70099 +
70100 +static int
70101 +init_variables(const struct gr_arg *arg, bool reload)
70102 +{
70103 + struct task_struct *reaper = init_pid_ns.child_reaper;
70104 + unsigned int stacksize;
70105 +
70106 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
70107 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
70108 + polstate->name_set.n_size = arg->role_db.num_objects;
70109 + polstate->inodev_set.i_size = arg->role_db.num_objects;
70110 +
70111 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
70112 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
70113 + return 1;
70114 +
70115 + if (!reload) {
70116 + if (!gr_init_uidset())
70117 + return 1;
70118 + }
70119 +
70120 + /* set up the stack that holds allocation info */
70121 +
70122 + stacksize = arg->role_db.num_pointers + 5;
70123 +
70124 + if (!acl_alloc_stack_init(stacksize))
70125 + return 1;
70126 +
70127 + if (!reload) {
70128 + /* grab reference for the real root dentry and vfsmount */
70129 + get_fs_root(reaper->fs, &gr_real_root);
70130 +
70131 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70132 + 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);
70133 +#endif
70134 +
70135 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70136 + if (fakefs_obj_rw == NULL)
70137 + return 1;
70138 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
70139 +
70140 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70141 + if (fakefs_obj_rwx == NULL)
70142 + return 1;
70143 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
70144 + }
70145 +
70146 + polstate->subj_map_set.s_hash =
70147 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
70148 + polstate->acl_role_set.r_hash =
70149 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
70150 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
70151 + polstate->inodev_set.i_hash =
70152 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
70153 +
70154 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
70155 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
70156 + return 1;
70157 +
70158 + memset(polstate->subj_map_set.s_hash, 0,
70159 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
70160 + memset(polstate->acl_role_set.r_hash, 0,
70161 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
70162 + memset(polstate->name_set.n_hash, 0,
70163 + sizeof (struct name_entry *) * polstate->name_set.n_size);
70164 + memset(polstate->inodev_set.i_hash, 0,
70165 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
70166 +
70167 + return 0;
70168 +}
70169 +
70170 +/* free information not needed after startup
70171 + currently contains user->kernel pointer mappings for subjects
70172 +*/
70173 +
70174 +static void
70175 +free_init_variables(void)
70176 +{
70177 + __u32 i;
70178 +
70179 + if (polstate->subj_map_set.s_hash) {
70180 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
70181 + if (polstate->subj_map_set.s_hash[i]) {
70182 + kfree(polstate->subj_map_set.s_hash[i]);
70183 + polstate->subj_map_set.s_hash[i] = NULL;
70184 + }
70185 + }
70186 +
70187 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
70188 + PAGE_SIZE)
70189 + kfree(polstate->subj_map_set.s_hash);
70190 + else
70191 + vfree(polstate->subj_map_set.s_hash);
70192 + }
70193 +
70194 + return;
70195 +}
70196 +
70197 +static void
70198 +free_variables(bool reload)
70199 +{
70200 + struct acl_subject_label *s;
70201 + struct acl_role_label *r;
70202 + struct task_struct *task, *task2;
70203 + unsigned int x;
70204 +
70205 + if (!reload) {
70206 + gr_clear_learn_entries();
70207 +
70208 + read_lock(&tasklist_lock);
70209 + do_each_thread(task2, task) {
70210 + task->acl_sp_role = 0;
70211 + task->acl_role_id = 0;
70212 + task->inherited = 0;
70213 + task->acl = NULL;
70214 + task->role = NULL;
70215 + } while_each_thread(task2, task);
70216 + read_unlock(&tasklist_lock);
70217 +
70218 + kfree(fakefs_obj_rw);
70219 + fakefs_obj_rw = NULL;
70220 + kfree(fakefs_obj_rwx);
70221 + fakefs_obj_rwx = NULL;
70222 +
70223 + /* release the reference to the real root dentry and vfsmount */
70224 + path_put(&gr_real_root);
70225 + memset(&gr_real_root, 0, sizeof(gr_real_root));
70226 + }
70227 +
70228 + /* free all object hash tables */
70229 +
70230 + FOR_EACH_ROLE_START(r)
70231 + if (r->subj_hash == NULL)
70232 + goto next_role;
70233 + FOR_EACH_SUBJECT_START(r, s, x)
70234 + if (s->obj_hash == NULL)
70235 + break;
70236 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70237 + kfree(s->obj_hash);
70238 + else
70239 + vfree(s->obj_hash);
70240 + FOR_EACH_SUBJECT_END(s, x)
70241 + FOR_EACH_NESTED_SUBJECT_START(r, s)
70242 + if (s->obj_hash == NULL)
70243 + break;
70244 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70245 + kfree(s->obj_hash);
70246 + else
70247 + vfree(s->obj_hash);
70248 + FOR_EACH_NESTED_SUBJECT_END(s)
70249 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
70250 + kfree(r->subj_hash);
70251 + else
70252 + vfree(r->subj_hash);
70253 + r->subj_hash = NULL;
70254 +next_role:
70255 + FOR_EACH_ROLE_END(r)
70256 +
70257 + acl_free_all();
70258 +
70259 + if (polstate->acl_role_set.r_hash) {
70260 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
70261 + PAGE_SIZE)
70262 + kfree(polstate->acl_role_set.r_hash);
70263 + else
70264 + vfree(polstate->acl_role_set.r_hash);
70265 + }
70266 + if (polstate->name_set.n_hash) {
70267 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
70268 + PAGE_SIZE)
70269 + kfree(polstate->name_set.n_hash);
70270 + else
70271 + vfree(polstate->name_set.n_hash);
70272 + }
70273 +
70274 + if (polstate->inodev_set.i_hash) {
70275 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
70276 + PAGE_SIZE)
70277 + kfree(polstate->inodev_set.i_hash);
70278 + else
70279 + vfree(polstate->inodev_set.i_hash);
70280 + }
70281 +
70282 + if (!reload)
70283 + gr_free_uidset();
70284 +
70285 + memset(&polstate->name_set, 0, sizeof (struct name_db));
70286 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
70287 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
70288 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
70289 +
70290 + polstate->default_role = NULL;
70291 + polstate->kernel_role = NULL;
70292 + polstate->role_list = NULL;
70293 +
70294 + return;
70295 +}
70296 +
70297 +static struct acl_subject_label *
70298 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
70299 +
70300 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
70301 +{
70302 + unsigned int len = strnlen_user(*name, maxlen);
70303 + char *tmp;
70304 +
70305 + if (!len || len >= maxlen)
70306 + return -EINVAL;
70307 +
70308 + if ((tmp = (char *) acl_alloc(len)) == NULL)
70309 + return -ENOMEM;
70310 +
70311 + if (copy_from_user(tmp, *name, len))
70312 + return -EFAULT;
70313 +
70314 + tmp[len-1] = '\0';
70315 + *name = tmp;
70316 +
70317 + return 0;
70318 +}
70319 +
70320 +static int
70321 +copy_user_glob(struct acl_object_label *obj)
70322 +{
70323 + struct acl_object_label *g_tmp, **guser;
70324 + int error;
70325 +
70326 + if (obj->globbed == NULL)
70327 + return 0;
70328 +
70329 + guser = &obj->globbed;
70330 + while (*guser) {
70331 + g_tmp = (struct acl_object_label *)
70332 + acl_alloc(sizeof (struct acl_object_label));
70333 + if (g_tmp == NULL)
70334 + return -ENOMEM;
70335 +
70336 + if (copy_acl_object_label(g_tmp, *guser))
70337 + return -EFAULT;
70338 +
70339 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
70340 + if (error)
70341 + return error;
70342 +
70343 + *guser = g_tmp;
70344 + guser = &(g_tmp->next);
70345 + }
70346 +
70347 + return 0;
70348 +}
70349 +
70350 +static int
70351 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
70352 + struct acl_role_label *role)
70353 +{
70354 + struct acl_object_label *o_tmp;
70355 + int ret;
70356 +
70357 + while (userp) {
70358 + if ((o_tmp = (struct acl_object_label *)
70359 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
70360 + return -ENOMEM;
70361 +
70362 + if (copy_acl_object_label(o_tmp, userp))
70363 + return -EFAULT;
70364 +
70365 + userp = o_tmp->prev;
70366 +
70367 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
70368 + if (ret)
70369 + return ret;
70370 +
70371 + insert_acl_obj_label(o_tmp, subj);
70372 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
70373 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
70374 + return -ENOMEM;
70375 +
70376 + ret = copy_user_glob(o_tmp);
70377 + if (ret)
70378 + return ret;
70379 +
70380 + if (o_tmp->nested) {
70381 + int already_copied;
70382 +
70383 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
70384 + if (IS_ERR(o_tmp->nested))
70385 + return PTR_ERR(o_tmp->nested);
70386 +
70387 + /* insert into nested subject list if we haven't copied this one yet
70388 + to prevent duplicate entries */
70389 + if (!already_copied) {
70390 + o_tmp->nested->next = role->hash->first;
70391 + role->hash->first = o_tmp->nested;
70392 + }
70393 + }
70394 + }
70395 +
70396 + return 0;
70397 +}
70398 +
70399 +static __u32
70400 +count_user_subjs(struct acl_subject_label *userp)
70401 +{
70402 + struct acl_subject_label s_tmp;
70403 + __u32 num = 0;
70404 +
70405 + while (userp) {
70406 + if (copy_acl_subject_label(&s_tmp, userp))
70407 + break;
70408 +
70409 + userp = s_tmp.prev;
70410 + }
70411 +
70412 + return num;
70413 +}
70414 +
70415 +static int
70416 +copy_user_allowedips(struct acl_role_label *rolep)
70417 +{
70418 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
70419 +
70420 + ruserip = rolep->allowed_ips;
70421 +
70422 + while (ruserip) {
70423 + rlast = rtmp;
70424 +
70425 + if ((rtmp = (struct role_allowed_ip *)
70426 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
70427 + return -ENOMEM;
70428 +
70429 + if (copy_role_allowed_ip(rtmp, ruserip))
70430 + return -EFAULT;
70431 +
70432 + ruserip = rtmp->prev;
70433 +
70434 + if (!rlast) {
70435 + rtmp->prev = NULL;
70436 + rolep->allowed_ips = rtmp;
70437 + } else {
70438 + rlast->next = rtmp;
70439 + rtmp->prev = rlast;
70440 + }
70441 +
70442 + if (!ruserip)
70443 + rtmp->next = NULL;
70444 + }
70445 +
70446 + return 0;
70447 +}
70448 +
70449 +static int
70450 +copy_user_transitions(struct acl_role_label *rolep)
70451 +{
70452 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
70453 + int error;
70454 +
70455 + rusertp = rolep->transitions;
70456 +
70457 + while (rusertp) {
70458 + rlast = rtmp;
70459 +
70460 + if ((rtmp = (struct role_transition *)
70461 + acl_alloc(sizeof (struct role_transition))) == NULL)
70462 + return -ENOMEM;
70463 +
70464 + if (copy_role_transition(rtmp, rusertp))
70465 + return -EFAULT;
70466 +
70467 + rusertp = rtmp->prev;
70468 +
70469 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
70470 + if (error)
70471 + return error;
70472 +
70473 + if (!rlast) {
70474 + rtmp->prev = NULL;
70475 + rolep->transitions = rtmp;
70476 + } else {
70477 + rlast->next = rtmp;
70478 + rtmp->prev = rlast;
70479 + }
70480 +
70481 + if (!rusertp)
70482 + rtmp->next = NULL;
70483 + }
70484 +
70485 + return 0;
70486 +}
70487 +
70488 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
70489 +{
70490 + struct acl_object_label o_tmp;
70491 + __u32 num = 0;
70492 +
70493 + while (userp) {
70494 + if (copy_acl_object_label(&o_tmp, userp))
70495 + break;
70496 +
70497 + userp = o_tmp.prev;
70498 + num++;
70499 + }
70500 +
70501 + return num;
70502 +}
70503 +
70504 +static struct acl_subject_label *
70505 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
70506 +{
70507 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
70508 + __u32 num_objs;
70509 + struct acl_ip_label **i_tmp, *i_utmp2;
70510 + struct gr_hash_struct ghash;
70511 + struct subject_map *subjmap;
70512 + unsigned int i_num;
70513 + int err;
70514 +
70515 + if (already_copied != NULL)
70516 + *already_copied = 0;
70517 +
70518 + s_tmp = lookup_subject_map(userp);
70519 +
70520 + /* we've already copied this subject into the kernel, just return
70521 + the reference to it, and don't copy it over again
70522 + */
70523 + if (s_tmp) {
70524 + if (already_copied != NULL)
70525 + *already_copied = 1;
70526 + return(s_tmp);
70527 + }
70528 +
70529 + if ((s_tmp = (struct acl_subject_label *)
70530 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
70531 + return ERR_PTR(-ENOMEM);
70532 +
70533 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
70534 + if (subjmap == NULL)
70535 + return ERR_PTR(-ENOMEM);
70536 +
70537 + subjmap->user = userp;
70538 + subjmap->kernel = s_tmp;
70539 + insert_subj_map_entry(subjmap);
70540 +
70541 + if (copy_acl_subject_label(s_tmp, userp))
70542 + return ERR_PTR(-EFAULT);
70543 +
70544 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
70545 + if (err)
70546 + return ERR_PTR(err);
70547 +
70548 + if (!strcmp(s_tmp->filename, "/"))
70549 + role->root_label = s_tmp;
70550 +
70551 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
70552 + return ERR_PTR(-EFAULT);
70553 +
70554 + /* copy user and group transition tables */
70555 +
70556 + if (s_tmp->user_trans_num) {
70557 + uid_t *uidlist;
70558 +
70559 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
70560 + if (uidlist == NULL)
70561 + return ERR_PTR(-ENOMEM);
70562 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
70563 + return ERR_PTR(-EFAULT);
70564 +
70565 + s_tmp->user_transitions = uidlist;
70566 + }
70567 +
70568 + if (s_tmp->group_trans_num) {
70569 + gid_t *gidlist;
70570 +
70571 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
70572 + if (gidlist == NULL)
70573 + return ERR_PTR(-ENOMEM);
70574 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
70575 + return ERR_PTR(-EFAULT);
70576 +
70577 + s_tmp->group_transitions = gidlist;
70578 + }
70579 +
70580 + /* set up object hash table */
70581 + num_objs = count_user_objs(ghash.first);
70582 +
70583 + s_tmp->obj_hash_size = num_objs;
70584 + s_tmp->obj_hash =
70585 + (struct acl_object_label **)
70586 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
70587 +
70588 + if (!s_tmp->obj_hash)
70589 + return ERR_PTR(-ENOMEM);
70590 +
70591 + memset(s_tmp->obj_hash, 0,
70592 + s_tmp->obj_hash_size *
70593 + sizeof (struct acl_object_label *));
70594 +
70595 + /* add in objects */
70596 + err = copy_user_objs(ghash.first, s_tmp, role);
70597 +
70598 + if (err)
70599 + return ERR_PTR(err);
70600 +
70601 + /* set pointer for parent subject */
70602 + if (s_tmp->parent_subject) {
70603 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
70604 +
70605 + if (IS_ERR(s_tmp2))
70606 + return s_tmp2;
70607 +
70608 + s_tmp->parent_subject = s_tmp2;
70609 + }
70610 +
70611 + /* add in ip acls */
70612 +
70613 + if (!s_tmp->ip_num) {
70614 + s_tmp->ips = NULL;
70615 + goto insert;
70616 + }
70617 +
70618 + i_tmp =
70619 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
70620 + sizeof (struct acl_ip_label *));
70621 +
70622 + if (!i_tmp)
70623 + return ERR_PTR(-ENOMEM);
70624 +
70625 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
70626 + *(i_tmp + i_num) =
70627 + (struct acl_ip_label *)
70628 + acl_alloc(sizeof (struct acl_ip_label));
70629 + if (!*(i_tmp + i_num))
70630 + return ERR_PTR(-ENOMEM);
70631 +
70632 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
70633 + return ERR_PTR(-EFAULT);
70634 +
70635 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
70636 + return ERR_PTR(-EFAULT);
70637 +
70638 + if ((*(i_tmp + i_num))->iface == NULL)
70639 + continue;
70640 +
70641 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
70642 + if (err)
70643 + return ERR_PTR(err);
70644 + }
70645 +
70646 + s_tmp->ips = i_tmp;
70647 +
70648 +insert:
70649 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
70650 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
70651 + return ERR_PTR(-ENOMEM);
70652 +
70653 + return s_tmp;
70654 +}
70655 +
70656 +static int
70657 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
70658 +{
70659 + struct acl_subject_label s_pre;
70660 + struct acl_subject_label * ret;
70661 + int err;
70662 +
70663 + while (userp) {
70664 + if (copy_acl_subject_label(&s_pre, userp))
70665 + return -EFAULT;
70666 +
70667 + ret = do_copy_user_subj(userp, role, NULL);
70668 +
70669 + err = PTR_ERR(ret);
70670 + if (IS_ERR(ret))
70671 + return err;
70672 +
70673 + insert_acl_subj_label(ret, role);
70674 +
70675 + userp = s_pre.prev;
70676 + }
70677 +
70678 + return 0;
70679 +}
70680 +
70681 +static int
70682 +copy_user_acl(struct gr_arg *arg)
70683 +{
70684 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
70685 + struct acl_subject_label *subj_list;
70686 + struct sprole_pw *sptmp;
70687 + struct gr_hash_struct *ghash;
70688 + uid_t *domainlist;
70689 + unsigned int r_num;
70690 + int err = 0;
70691 + __u16 i;
70692 + __u32 num_subjs;
70693 +
70694 + /* we need a default and kernel role */
70695 + if (arg->role_db.num_roles < 2)
70696 + return -EINVAL;
70697 +
70698 + /* copy special role authentication info from userspace */
70699 +
70700 + polstate->num_sprole_pws = arg->num_sprole_pws;
70701 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
70702 +
70703 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
70704 + return -ENOMEM;
70705 +
70706 + for (i = 0; i < polstate->num_sprole_pws; i++) {
70707 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
70708 + if (!sptmp)
70709 + return -ENOMEM;
70710 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
70711 + return -EFAULT;
70712 +
70713 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
70714 + if (err)
70715 + return err;
70716 +
70717 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70718 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
70719 +#endif
70720 +
70721 + polstate->acl_special_roles[i] = sptmp;
70722 + }
70723 +
70724 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
70725 +
70726 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
70727 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
70728 +
70729 + if (!r_tmp)
70730 + return -ENOMEM;
70731 +
70732 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
70733 + return -EFAULT;
70734 +
70735 + if (copy_acl_role_label(r_tmp, r_utmp2))
70736 + return -EFAULT;
70737 +
70738 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
70739 + if (err)
70740 + return err;
70741 +
70742 + if (!strcmp(r_tmp->rolename, "default")
70743 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
70744 + polstate->default_role = r_tmp;
70745 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
70746 + polstate->kernel_role = r_tmp;
70747 + }
70748 +
70749 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
70750 + return -ENOMEM;
70751 +
70752 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
70753 + return -EFAULT;
70754 +
70755 + r_tmp->hash = ghash;
70756 +
70757 + num_subjs = count_user_subjs(r_tmp->hash->first);
70758 +
70759 + r_tmp->subj_hash_size = num_subjs;
70760 + r_tmp->subj_hash =
70761 + (struct acl_subject_label **)
70762 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
70763 +
70764 + if (!r_tmp->subj_hash)
70765 + return -ENOMEM;
70766 +
70767 + err = copy_user_allowedips(r_tmp);
70768 + if (err)
70769 + return err;
70770 +
70771 + /* copy domain info */
70772 + if (r_tmp->domain_children != NULL) {
70773 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
70774 + if (domainlist == NULL)
70775 + return -ENOMEM;
70776 +
70777 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
70778 + return -EFAULT;
70779 +
70780 + r_tmp->domain_children = domainlist;
70781 + }
70782 +
70783 + err = copy_user_transitions(r_tmp);
70784 + if (err)
70785 + return err;
70786 +
70787 + memset(r_tmp->subj_hash, 0,
70788 + r_tmp->subj_hash_size *
70789 + sizeof (struct acl_subject_label *));
70790 +
70791 + /* acquire the list of subjects, then NULL out
70792 + the list prior to parsing the subjects for this role,
70793 + as during this parsing the list is replaced with a list
70794 + of *nested* subjects for the role
70795 + */
70796 + subj_list = r_tmp->hash->first;
70797 +
70798 + /* set nested subject list to null */
70799 + r_tmp->hash->first = NULL;
70800 +
70801 + err = copy_user_subjs(subj_list, r_tmp);
70802 +
70803 + if (err)
70804 + return err;
70805 +
70806 + insert_acl_role_label(r_tmp);
70807 + }
70808 +
70809 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
70810 + return -EINVAL;
70811 +
70812 + return err;
70813 +}
70814 +
70815 +static int gracl_reload_apply_policies(void *reload)
70816 +{
70817 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
70818 + struct task_struct *task, *task2;
70819 + struct acl_role_label *role, *rtmp;
70820 + struct acl_subject_label *subj;
70821 + const struct cred *cred;
70822 + int role_applied;
70823 + int ret = 0;
70824 +
70825 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
70826 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
70827 +
70828 + /* first make sure we'll be able to apply the new policy cleanly */
70829 + do_each_thread(task2, task) {
70830 + if (task->exec_file == NULL)
70831 + continue;
70832 + role_applied = 0;
70833 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70834 + /* preserve special roles */
70835 + FOR_EACH_ROLE_START(role)
70836 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70837 + rtmp = task->role;
70838 + task->role = role;
70839 + role_applied = 1;
70840 + break;
70841 + }
70842 + FOR_EACH_ROLE_END(role)
70843 + }
70844 + if (!role_applied) {
70845 + cred = __task_cred(task);
70846 + rtmp = task->role;
70847 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70848 + }
70849 + /* this handles non-nested inherited subjects, nested subjects will still
70850 + be dropped currently */
70851 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70852 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
70853 + /* change the role back so that we've made no modifications to the policy */
70854 + task->role = rtmp;
70855 +
70856 + if (subj == NULL || task->tmpacl == NULL) {
70857 + ret = -EINVAL;
70858 + goto out;
70859 + }
70860 + } while_each_thread(task2, task);
70861 +
70862 + /* now actually apply the policy */
70863 +
70864 + do_each_thread(task2, task) {
70865 + if (task->exec_file) {
70866 + role_applied = 0;
70867 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70868 + /* preserve special roles */
70869 + FOR_EACH_ROLE_START(role)
70870 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70871 + task->role = role;
70872 + role_applied = 1;
70873 + break;
70874 + }
70875 + FOR_EACH_ROLE_END(role)
70876 + }
70877 + if (!role_applied) {
70878 + cred = __task_cred(task);
70879 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70880 + }
70881 + /* this handles non-nested inherited subjects, nested subjects will still
70882 + be dropped currently */
70883 + if (!reload_state->oldmode && task->inherited)
70884 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70885 + else {
70886 + /* looked up and tagged to the task previously */
70887 + subj = task->tmpacl;
70888 + }
70889 + /* subj will be non-null */
70890 + __gr_apply_subject_to_task(polstate, task, subj);
70891 + if (reload_state->oldmode) {
70892 + task->acl_role_id = 0;
70893 + task->acl_sp_role = 0;
70894 + task->inherited = 0;
70895 + }
70896 + } else {
70897 + // it's a kernel process
70898 + task->role = polstate->kernel_role;
70899 + task->acl = polstate->kernel_role->root_label;
70900 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
70901 + task->acl->mode &= ~GR_PROCFIND;
70902 +#endif
70903 + }
70904 + } while_each_thread(task2, task);
70905 +
70906 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
70907 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
70908 +
70909 +out:
70910 +
70911 + return ret;
70912 +}
70913 +
70914 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
70915 +{
70916 + struct gr_reload_state new_reload_state = { };
70917 + int err;
70918 +
70919 + new_reload_state.oldpolicy_ptr = polstate;
70920 + new_reload_state.oldalloc_ptr = current_alloc_state;
70921 + new_reload_state.oldmode = oldmode;
70922 +
70923 + current_alloc_state = &new_reload_state.newalloc;
70924 + polstate = &new_reload_state.newpolicy;
70925 +
70926 + /* everything relevant is now saved off, copy in the new policy */
70927 + if (init_variables(args, true)) {
70928 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70929 + err = -ENOMEM;
70930 + goto error;
70931 + }
70932 +
70933 + err = copy_user_acl(args);
70934 + free_init_variables();
70935 + if (err)
70936 + goto error;
70937 + /* the new policy is copied in, with the old policy available via saved_state
70938 + first go through applying roles, making sure to preserve special roles
70939 + then apply new subjects, making sure to preserve inherited and nested subjects,
70940 + though currently only inherited subjects will be preserved
70941 + */
70942 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
70943 + if (err)
70944 + goto error;
70945 +
70946 + /* we've now applied the new policy, so restore the old policy state to free it */
70947 + polstate = &new_reload_state.oldpolicy;
70948 + current_alloc_state = &new_reload_state.oldalloc;
70949 + free_variables(true);
70950 +
70951 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
70952 + to running_polstate/current_alloc_state inside stop_machine
70953 + */
70954 + err = 0;
70955 + goto out;
70956 +error:
70957 + /* on error of loading the new policy, we'll just keep the previous
70958 + policy set around
70959 + */
70960 + free_variables(true);
70961 +
70962 + /* doesn't affect runtime, but maintains consistent state */
70963 +out:
70964 + polstate = new_reload_state.oldpolicy_ptr;
70965 + current_alloc_state = new_reload_state.oldalloc_ptr;
70966 +
70967 + return err;
70968 +}
70969 +
70970 +static int
70971 +gracl_init(struct gr_arg *args)
70972 +{
70973 + int error = 0;
70974 +
70975 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
70976 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
70977 +
70978 + if (init_variables(args, false)) {
70979 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70980 + error = -ENOMEM;
70981 + goto out;
70982 + }
70983 +
70984 + error = copy_user_acl(args);
70985 + free_init_variables();
70986 + if (error)
70987 + goto out;
70988 +
70989 + error = gr_set_acls(0);
70990 + if (error)
70991 + goto out;
70992 +
70993 + gr_enable_rbac_system();
70994 +
70995 + return 0;
70996 +
70997 +out:
70998 + free_variables(false);
70999 + return error;
71000 +}
71001 +
71002 +static int
71003 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71004 + unsigned char **sum)
71005 +{
71006 + struct acl_role_label *r;
71007 + struct role_allowed_ip *ipp;
71008 + struct role_transition *trans;
71009 + unsigned int i;
71010 + int found = 0;
71011 + u32 curr_ip = current->signal->curr_ip;
71012 +
71013 + current->signal->saved_ip = curr_ip;
71014 +
71015 + /* check transition table */
71016 +
71017 + for (trans = current->role->transitions; trans; trans = trans->next) {
71018 + if (!strcmp(rolename, trans->rolename)) {
71019 + found = 1;
71020 + break;
71021 + }
71022 + }
71023 +
71024 + if (!found)
71025 + return 0;
71026 +
71027 + /* handle special roles that do not require authentication
71028 + and check ip */
71029 +
71030 + FOR_EACH_ROLE_START(r)
71031 + if (!strcmp(rolename, r->rolename) &&
71032 + (r->roletype & GR_ROLE_SPECIAL)) {
71033 + found = 0;
71034 + if (r->allowed_ips != NULL) {
71035 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71036 + if ((ntohl(curr_ip) & ipp->netmask) ==
71037 + (ntohl(ipp->addr) & ipp->netmask))
71038 + found = 1;
71039 + }
71040 + } else
71041 + found = 2;
71042 + if (!found)
71043 + return 0;
71044 +
71045 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71046 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71047 + *salt = NULL;
71048 + *sum = NULL;
71049 + return 1;
71050 + }
71051 + }
71052 + FOR_EACH_ROLE_END(r)
71053 +
71054 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71055 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
71056 + *salt = polstate->acl_special_roles[i]->salt;
71057 + *sum = polstate->acl_special_roles[i]->sum;
71058 + return 1;
71059 + }
71060 + }
71061 +
71062 + return 0;
71063 +}
71064 +
71065 +int gr_check_secure_terminal(struct task_struct *task)
71066 +{
71067 + struct task_struct *p, *p2, *p3;
71068 + struct files_struct *files;
71069 + struct fdtable *fdt;
71070 + struct file *our_file = NULL, *file;
71071 + int i;
71072 +
71073 + if (task->signal->tty == NULL)
71074 + return 1;
71075 +
71076 + files = get_files_struct(task);
71077 + if (files != NULL) {
71078 + rcu_read_lock();
71079 + fdt = files_fdtable(files);
71080 + for (i=0; i < fdt->max_fds; i++) {
71081 + file = fcheck_files(files, i);
71082 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
71083 + get_file(file);
71084 + our_file = file;
71085 + }
71086 + }
71087 + rcu_read_unlock();
71088 + put_files_struct(files);
71089 + }
71090 +
71091 + if (our_file == NULL)
71092 + return 1;
71093 +
71094 + read_lock(&tasklist_lock);
71095 + do_each_thread(p2, p) {
71096 + files = get_files_struct(p);
71097 + if (files == NULL ||
71098 + (p->signal && p->signal->tty == task->signal->tty)) {
71099 + if (files != NULL)
71100 + put_files_struct(files);
71101 + continue;
71102 + }
71103 + rcu_read_lock();
71104 + fdt = files_fdtable(files);
71105 + for (i=0; i < fdt->max_fds; i++) {
71106 + file = fcheck_files(files, i);
71107 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
71108 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
71109 + p3 = task;
71110 + while (task_pid_nr(p3) > 0) {
71111 + if (p3 == p)
71112 + break;
71113 + p3 = p3->real_parent;
71114 + }
71115 + if (p3 == p)
71116 + break;
71117 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
71118 + gr_handle_alertkill(p);
71119 + rcu_read_unlock();
71120 + put_files_struct(files);
71121 + read_unlock(&tasklist_lock);
71122 + fput(our_file);
71123 + return 0;
71124 + }
71125 + }
71126 + rcu_read_unlock();
71127 + put_files_struct(files);
71128 + } while_each_thread(p2, p);
71129 + read_unlock(&tasklist_lock);
71130 +
71131 + fput(our_file);
71132 + return 1;
71133 +}
71134 +
71135 +ssize_t
71136 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
71137 +{
71138 + struct gr_arg_wrapper uwrap;
71139 + unsigned char *sprole_salt = NULL;
71140 + unsigned char *sprole_sum = NULL;
71141 + int error = 0;
71142 + int error2 = 0;
71143 + size_t req_count = 0;
71144 + unsigned char oldmode = 0;
71145 +
71146 + mutex_lock(&gr_dev_mutex);
71147 +
71148 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
71149 + error = -EPERM;
71150 + goto out;
71151 + }
71152 +
71153 +#ifdef CONFIG_COMPAT
71154 + pax_open_kernel();
71155 + if (is_compat_task()) {
71156 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
71157 + copy_gr_arg = &copy_gr_arg_compat;
71158 + copy_acl_object_label = &copy_acl_object_label_compat;
71159 + copy_acl_subject_label = &copy_acl_subject_label_compat;
71160 + copy_acl_role_label = &copy_acl_role_label_compat;
71161 + copy_acl_ip_label = &copy_acl_ip_label_compat;
71162 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
71163 + copy_role_transition = &copy_role_transition_compat;
71164 + copy_sprole_pw = &copy_sprole_pw_compat;
71165 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
71166 + copy_pointer_from_array = &copy_pointer_from_array_compat;
71167 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
71168 + } else {
71169 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
71170 + copy_gr_arg = &copy_gr_arg_normal;
71171 + copy_acl_object_label = &copy_acl_object_label_normal;
71172 + copy_acl_subject_label = &copy_acl_subject_label_normal;
71173 + copy_acl_role_label = &copy_acl_role_label_normal;
71174 + copy_acl_ip_label = &copy_acl_ip_label_normal;
71175 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
71176 + copy_role_transition = &copy_role_transition_normal;
71177 + copy_sprole_pw = &copy_sprole_pw_normal;
71178 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
71179 + copy_pointer_from_array = &copy_pointer_from_array_normal;
71180 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
71181 + }
71182 + pax_close_kernel();
71183 +#endif
71184 +
71185 + req_count = get_gr_arg_wrapper_size();
71186 +
71187 + if (count != req_count) {
71188 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
71189 + error = -EINVAL;
71190 + goto out;
71191 + }
71192 +
71193 +
71194 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
71195 + gr_auth_expires = 0;
71196 + gr_auth_attempts = 0;
71197 + }
71198 +
71199 + error = copy_gr_arg_wrapper(buf, &uwrap);
71200 + if (error)
71201 + goto out;
71202 +
71203 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
71204 + if (error)
71205 + goto out;
71206 +
71207 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71208 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71209 + time_after(gr_auth_expires, get_seconds())) {
71210 + error = -EBUSY;
71211 + goto out;
71212 + }
71213 +
71214 + /* if non-root trying to do anything other than use a special role,
71215 + do not attempt authentication, do not count towards authentication
71216 + locking
71217 + */
71218 +
71219 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
71220 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71221 + gr_is_global_nonroot(current_uid())) {
71222 + error = -EPERM;
71223 + goto out;
71224 + }
71225 +
71226 + /* ensure pw and special role name are null terminated */
71227 +
71228 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
71229 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
71230 +
71231 + /* Okay.
71232 + * We have our enough of the argument structure..(we have yet
71233 + * to copy_from_user the tables themselves) . Copy the tables
71234 + * only if we need them, i.e. for loading operations. */
71235 +
71236 + switch (gr_usermode.mode) {
71237 + case GR_STATUS:
71238 + if (gr_acl_is_enabled()) {
71239 + error = 1;
71240 + if (!gr_check_secure_terminal(current))
71241 + error = 3;
71242 + } else
71243 + error = 2;
71244 + goto out;
71245 + case GR_SHUTDOWN:
71246 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71247 + stop_machine(gr_rbac_disable, NULL, NULL);
71248 + free_variables(false);
71249 + memset(&gr_usermode, 0, sizeof(gr_usermode));
71250 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
71251 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
71252 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
71253 + } else if (gr_acl_is_enabled()) {
71254 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
71255 + error = -EPERM;
71256 + } else {
71257 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
71258 + error = -EAGAIN;
71259 + }
71260 + break;
71261 + case GR_ENABLE:
71262 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
71263 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
71264 + else {
71265 + if (gr_acl_is_enabled())
71266 + error = -EAGAIN;
71267 + else
71268 + error = error2;
71269 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
71270 + }
71271 + break;
71272 + case GR_OLDRELOAD:
71273 + oldmode = 1;
71274 + case GR_RELOAD:
71275 + if (!gr_acl_is_enabled()) {
71276 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
71277 + error = -EAGAIN;
71278 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71279 + error2 = gracl_reload(&gr_usermode, oldmode);
71280 + if (!error2)
71281 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
71282 + else {
71283 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71284 + error = error2;
71285 + }
71286 + } else {
71287 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71288 + error = -EPERM;
71289 + }
71290 + break;
71291 + case GR_SEGVMOD:
71292 + if (unlikely(!gr_acl_is_enabled())) {
71293 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
71294 + error = -EAGAIN;
71295 + break;
71296 + }
71297 +
71298 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71299 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
71300 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
71301 + struct acl_subject_label *segvacl;
71302 + segvacl =
71303 + lookup_acl_subj_label(gr_usermode.segv_inode,
71304 + gr_usermode.segv_device,
71305 + current->role);
71306 + if (segvacl) {
71307 + segvacl->crashes = 0;
71308 + segvacl->expires = 0;
71309 + }
71310 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
71311 + gr_remove_uid(gr_usermode.segv_uid);
71312 + }
71313 + } else {
71314 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
71315 + error = -EPERM;
71316 + }
71317 + break;
71318 + case GR_SPROLE:
71319 + case GR_SPROLEPAM:
71320 + if (unlikely(!gr_acl_is_enabled())) {
71321 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
71322 + error = -EAGAIN;
71323 + break;
71324 + }
71325 +
71326 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
71327 + current->role->expires = 0;
71328 + current->role->auth_attempts = 0;
71329 + }
71330 +
71331 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71332 + time_after(current->role->expires, get_seconds())) {
71333 + error = -EBUSY;
71334 + goto out;
71335 + }
71336 +
71337 + if (lookup_special_role_auth
71338 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
71339 + && ((!sprole_salt && !sprole_sum)
71340 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
71341 + char *p = "";
71342 + assign_special_role(gr_usermode.sp_role);
71343 + read_lock(&tasklist_lock);
71344 + if (current->real_parent)
71345 + p = current->real_parent->role->rolename;
71346 + read_unlock(&tasklist_lock);
71347 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
71348 + p, acl_sp_role_value);
71349 + } else {
71350 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
71351 + error = -EPERM;
71352 + if(!(current->role->auth_attempts++))
71353 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71354 +
71355 + goto out;
71356 + }
71357 + break;
71358 + case GR_UNSPROLE:
71359 + if (unlikely(!gr_acl_is_enabled())) {
71360 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
71361 + error = -EAGAIN;
71362 + break;
71363 + }
71364 +
71365 + if (current->role->roletype & GR_ROLE_SPECIAL) {
71366 + char *p = "";
71367 + int i = 0;
71368 +
71369 + read_lock(&tasklist_lock);
71370 + if (current->real_parent) {
71371 + p = current->real_parent->role->rolename;
71372 + i = current->real_parent->acl_role_id;
71373 + }
71374 + read_unlock(&tasklist_lock);
71375 +
71376 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
71377 + gr_set_acls(1);
71378 + } else {
71379 + error = -EPERM;
71380 + goto out;
71381 + }
71382 + break;
71383 + default:
71384 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
71385 + error = -EINVAL;
71386 + break;
71387 + }
71388 +
71389 + if (error != -EPERM)
71390 + goto out;
71391 +
71392 + if(!(gr_auth_attempts++))
71393 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71394 +
71395 + out:
71396 + mutex_unlock(&gr_dev_mutex);
71397 +
71398 + if (!error)
71399 + error = req_count;
71400 +
71401 + return error;
71402 +}
71403 +
71404 +int
71405 +gr_set_acls(const int type)
71406 +{
71407 + struct task_struct *task, *task2;
71408 + struct acl_role_label *role = current->role;
71409 + struct acl_subject_label *subj;
71410 + __u16 acl_role_id = current->acl_role_id;
71411 + const struct cred *cred;
71412 + int ret;
71413 +
71414 + rcu_read_lock();
71415 + read_lock(&tasklist_lock);
71416 + read_lock(&grsec_exec_file_lock);
71417 + do_each_thread(task2, task) {
71418 + /* check to see if we're called from the exit handler,
71419 + if so, only replace ACLs that have inherited the admin
71420 + ACL */
71421 +
71422 + if (type && (task->role != role ||
71423 + task->acl_role_id != acl_role_id))
71424 + continue;
71425 +
71426 + task->acl_role_id = 0;
71427 + task->acl_sp_role = 0;
71428 + task->inherited = 0;
71429 +
71430 + if (task->exec_file) {
71431 + cred = __task_cred(task);
71432 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71433 + subj = __gr_get_subject_for_task(polstate, task, NULL);
71434 + if (subj == NULL) {
71435 + ret = -EINVAL;
71436 + read_unlock(&grsec_exec_file_lock);
71437 + read_unlock(&tasklist_lock);
71438 + rcu_read_unlock();
71439 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
71440 + return ret;
71441 + }
71442 + __gr_apply_subject_to_task(polstate, task, subj);
71443 + } else {
71444 + // it's a kernel process
71445 + task->role = polstate->kernel_role;
71446 + task->acl = polstate->kernel_role->root_label;
71447 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71448 + task->acl->mode &= ~GR_PROCFIND;
71449 +#endif
71450 + }
71451 + } while_each_thread(task2, task);
71452 + read_unlock(&grsec_exec_file_lock);
71453 + read_unlock(&tasklist_lock);
71454 + rcu_read_unlock();
71455 +
71456 + return 0;
71457 +}
71458 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
71459 new file mode 100644
71460 index 0000000..39645c9
71461 --- /dev/null
71462 +++ b/grsecurity/gracl_res.c
71463 @@ -0,0 +1,68 @@
71464 +#include <linux/kernel.h>
71465 +#include <linux/sched.h>
71466 +#include <linux/gracl.h>
71467 +#include <linux/grinternal.h>
71468 +
71469 +static const char *restab_log[] = {
71470 + [RLIMIT_CPU] = "RLIMIT_CPU",
71471 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
71472 + [RLIMIT_DATA] = "RLIMIT_DATA",
71473 + [RLIMIT_STACK] = "RLIMIT_STACK",
71474 + [RLIMIT_CORE] = "RLIMIT_CORE",
71475 + [RLIMIT_RSS] = "RLIMIT_RSS",
71476 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
71477 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
71478 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
71479 + [RLIMIT_AS] = "RLIMIT_AS",
71480 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
71481 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
71482 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
71483 + [RLIMIT_NICE] = "RLIMIT_NICE",
71484 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
71485 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
71486 + [GR_CRASH_RES] = "RLIMIT_CRASH"
71487 +};
71488 +
71489 +void
71490 +gr_log_resource(const struct task_struct *task,
71491 + const int res, const unsigned long wanted, const int gt)
71492 +{
71493 + const struct cred *cred;
71494 + unsigned long rlim;
71495 +
71496 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
71497 + return;
71498 +
71499 + // not yet supported resource
71500 + if (unlikely(!restab_log[res]))
71501 + return;
71502 +
71503 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
71504 + rlim = task_rlimit_max(task, res);
71505 + else
71506 + rlim = task_rlimit(task, res);
71507 +
71508 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
71509 + return;
71510 +
71511 + rcu_read_lock();
71512 + cred = __task_cred(task);
71513 +
71514 + if (res == RLIMIT_NPROC &&
71515 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
71516 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
71517 + goto out_rcu_unlock;
71518 + else if (res == RLIMIT_MEMLOCK &&
71519 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
71520 + goto out_rcu_unlock;
71521 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
71522 + goto out_rcu_unlock;
71523 + rcu_read_unlock();
71524 +
71525 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
71526 +
71527 + return;
71528 +out_rcu_unlock:
71529 + rcu_read_unlock();
71530 + return;
71531 +}
71532 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
71533 new file mode 100644
71534 index 0000000..2040e61
71535 --- /dev/null
71536 +++ b/grsecurity/gracl_segv.c
71537 @@ -0,0 +1,313 @@
71538 +#include <linux/kernel.h>
71539 +#include <linux/mm.h>
71540 +#include <asm/uaccess.h>
71541 +#include <asm/errno.h>
71542 +#include <asm/mman.h>
71543 +#include <net/sock.h>
71544 +#include <linux/file.h>
71545 +#include <linux/fs.h>
71546 +#include <linux/net.h>
71547 +#include <linux/in.h>
71548 +#include <linux/slab.h>
71549 +#include <linux/types.h>
71550 +#include <linux/sched.h>
71551 +#include <linux/timer.h>
71552 +#include <linux/gracl.h>
71553 +#include <linux/grsecurity.h>
71554 +#include <linux/grinternal.h>
71555 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71556 +#include <linux/magic.h>
71557 +#include <linux/pagemap.h>
71558 +#include "../fs/btrfs/async-thread.h"
71559 +#include "../fs/btrfs/ctree.h"
71560 +#include "../fs/btrfs/btrfs_inode.h"
71561 +#endif
71562 +
71563 +static struct crash_uid *uid_set;
71564 +static unsigned short uid_used;
71565 +static DEFINE_SPINLOCK(gr_uid_lock);
71566 +extern rwlock_t gr_inode_lock;
71567 +extern struct acl_subject_label *
71568 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
71569 + struct acl_role_label *role);
71570 +
71571 +static inline dev_t __get_dev(const struct dentry *dentry)
71572 +{
71573 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71574 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
71575 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
71576 + else
71577 +#endif
71578 + return dentry->d_sb->s_dev;
71579 +}
71580 +
71581 +int
71582 +gr_init_uidset(void)
71583 +{
71584 + uid_set =
71585 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
71586 + uid_used = 0;
71587 +
71588 + return uid_set ? 1 : 0;
71589 +}
71590 +
71591 +void
71592 +gr_free_uidset(void)
71593 +{
71594 + if (uid_set) {
71595 + struct crash_uid *tmpset;
71596 + spin_lock(&gr_uid_lock);
71597 + tmpset = uid_set;
71598 + uid_set = NULL;
71599 + uid_used = 0;
71600 + spin_unlock(&gr_uid_lock);
71601 + if (tmpset)
71602 + kfree(tmpset);
71603 + }
71604 +
71605 + return;
71606 +}
71607 +
71608 +int
71609 +gr_find_uid(const uid_t uid)
71610 +{
71611 + struct crash_uid *tmp = uid_set;
71612 + uid_t buid;
71613 + int low = 0, high = uid_used - 1, mid;
71614 +
71615 + while (high >= low) {
71616 + mid = (low + high) >> 1;
71617 + buid = tmp[mid].uid;
71618 + if (buid == uid)
71619 + return mid;
71620 + if (buid > uid)
71621 + high = mid - 1;
71622 + if (buid < uid)
71623 + low = mid + 1;
71624 + }
71625 +
71626 + return -1;
71627 +}
71628 +
71629 +static __inline__ void
71630 +gr_insertsort(void)
71631 +{
71632 + unsigned short i, j;
71633 + struct crash_uid index;
71634 +
71635 + for (i = 1; i < uid_used; i++) {
71636 + index = uid_set[i];
71637 + j = i;
71638 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
71639 + uid_set[j] = uid_set[j - 1];
71640 + j--;
71641 + }
71642 + uid_set[j] = index;
71643 + }
71644 +
71645 + return;
71646 +}
71647 +
71648 +static __inline__ void
71649 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
71650 +{
71651 + int loc;
71652 + uid_t uid = GR_GLOBAL_UID(kuid);
71653 +
71654 + if (uid_used == GR_UIDTABLE_MAX)
71655 + return;
71656 +
71657 + loc = gr_find_uid(uid);
71658 +
71659 + if (loc >= 0) {
71660 + uid_set[loc].expires = expires;
71661 + return;
71662 + }
71663 +
71664 + uid_set[uid_used].uid = uid;
71665 + uid_set[uid_used].expires = expires;
71666 + uid_used++;
71667 +
71668 + gr_insertsort();
71669 +
71670 + return;
71671 +}
71672 +
71673 +void
71674 +gr_remove_uid(const unsigned short loc)
71675 +{
71676 + unsigned short i;
71677 +
71678 + for (i = loc + 1; i < uid_used; i++)
71679 + uid_set[i - 1] = uid_set[i];
71680 +
71681 + uid_used--;
71682 +
71683 + return;
71684 +}
71685 +
71686 +int
71687 +gr_check_crash_uid(const kuid_t kuid)
71688 +{
71689 + int loc;
71690 + int ret = 0;
71691 + uid_t uid;
71692 +
71693 + if (unlikely(!gr_acl_is_enabled()))
71694 + return 0;
71695 +
71696 + uid = GR_GLOBAL_UID(kuid);
71697 +
71698 + spin_lock(&gr_uid_lock);
71699 + loc = gr_find_uid(uid);
71700 +
71701 + if (loc < 0)
71702 + goto out_unlock;
71703 +
71704 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
71705 + gr_remove_uid(loc);
71706 + else
71707 + ret = 1;
71708 +
71709 +out_unlock:
71710 + spin_unlock(&gr_uid_lock);
71711 + return ret;
71712 +}
71713 +
71714 +static __inline__ int
71715 +proc_is_setxid(const struct cred *cred)
71716 +{
71717 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
71718 + !uid_eq(cred->uid, cred->fsuid))
71719 + return 1;
71720 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
71721 + !gid_eq(cred->gid, cred->fsgid))
71722 + return 1;
71723 +
71724 + return 0;
71725 +}
71726 +
71727 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
71728 +
71729 +void
71730 +gr_handle_crash(struct task_struct *task, const int sig)
71731 +{
71732 + struct acl_subject_label *curr;
71733 + struct task_struct *tsk, *tsk2;
71734 + const struct cred *cred;
71735 + const struct cred *cred2;
71736 +
71737 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
71738 + return;
71739 +
71740 + if (unlikely(!gr_acl_is_enabled()))
71741 + return;
71742 +
71743 + curr = task->acl;
71744 +
71745 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
71746 + return;
71747 +
71748 + if (time_before_eq(curr->expires, get_seconds())) {
71749 + curr->expires = 0;
71750 + curr->crashes = 0;
71751 + }
71752 +
71753 + curr->crashes++;
71754 +
71755 + if (!curr->expires)
71756 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
71757 +
71758 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71759 + time_after(curr->expires, get_seconds())) {
71760 + rcu_read_lock();
71761 + cred = __task_cred(task);
71762 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
71763 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71764 + spin_lock(&gr_uid_lock);
71765 + gr_insert_uid(cred->uid, curr->expires);
71766 + spin_unlock(&gr_uid_lock);
71767 + curr->expires = 0;
71768 + curr->crashes = 0;
71769 + read_lock(&tasklist_lock);
71770 + do_each_thread(tsk2, tsk) {
71771 + cred2 = __task_cred(tsk);
71772 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
71773 + gr_fake_force_sig(SIGKILL, tsk);
71774 + } while_each_thread(tsk2, tsk);
71775 + read_unlock(&tasklist_lock);
71776 + } else {
71777 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71778 + read_lock(&tasklist_lock);
71779 + read_lock(&grsec_exec_file_lock);
71780 + do_each_thread(tsk2, tsk) {
71781 + if (likely(tsk != task)) {
71782 + // if this thread has the same subject as the one that triggered
71783 + // RES_CRASH and it's the same binary, kill it
71784 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
71785 + gr_fake_force_sig(SIGKILL, tsk);
71786 + }
71787 + } while_each_thread(tsk2, tsk);
71788 + read_unlock(&grsec_exec_file_lock);
71789 + read_unlock(&tasklist_lock);
71790 + }
71791 + rcu_read_unlock();
71792 + }
71793 +
71794 + return;
71795 +}
71796 +
71797 +int
71798 +gr_check_crash_exec(const struct file *filp)
71799 +{
71800 + struct acl_subject_label *curr;
71801 +
71802 + if (unlikely(!gr_acl_is_enabled()))
71803 + return 0;
71804 +
71805 + read_lock(&gr_inode_lock);
71806 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
71807 + __get_dev(filp->f_path.dentry),
71808 + current->role);
71809 + read_unlock(&gr_inode_lock);
71810 +
71811 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
71812 + (!curr->crashes && !curr->expires))
71813 + return 0;
71814 +
71815 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71816 + time_after(curr->expires, get_seconds()))
71817 + return 1;
71818 + else if (time_before_eq(curr->expires, get_seconds())) {
71819 + curr->crashes = 0;
71820 + curr->expires = 0;
71821 + }
71822 +
71823 + return 0;
71824 +}
71825 +
71826 +void
71827 +gr_handle_alertkill(struct task_struct *task)
71828 +{
71829 + struct acl_subject_label *curracl;
71830 + __u32 curr_ip;
71831 + struct task_struct *p, *p2;
71832 +
71833 + if (unlikely(!gr_acl_is_enabled()))
71834 + return;
71835 +
71836 + curracl = task->acl;
71837 + curr_ip = task->signal->curr_ip;
71838 +
71839 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
71840 + read_lock(&tasklist_lock);
71841 + do_each_thread(p2, p) {
71842 + if (p->signal->curr_ip == curr_ip)
71843 + gr_fake_force_sig(SIGKILL, p);
71844 + } while_each_thread(p2, p);
71845 + read_unlock(&tasklist_lock);
71846 + } else if (curracl->mode & GR_KILLPROC)
71847 + gr_fake_force_sig(SIGKILL, task);
71848 +
71849 + return;
71850 +}
71851 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
71852 new file mode 100644
71853 index 0000000..98011b0
71854 --- /dev/null
71855 +++ b/grsecurity/gracl_shm.c
71856 @@ -0,0 +1,40 @@
71857 +#include <linux/kernel.h>
71858 +#include <linux/mm.h>
71859 +#include <linux/sched.h>
71860 +#include <linux/file.h>
71861 +#include <linux/ipc.h>
71862 +#include <linux/gracl.h>
71863 +#include <linux/grsecurity.h>
71864 +#include <linux/grinternal.h>
71865 +
71866 +int
71867 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71868 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
71869 +{
71870 + struct task_struct *task;
71871 +
71872 + if (!gr_acl_is_enabled())
71873 + return 1;
71874 +
71875 + rcu_read_lock();
71876 + read_lock(&tasklist_lock);
71877 +
71878 + task = find_task_by_vpid(shm_cprid);
71879 +
71880 + if (unlikely(!task))
71881 + task = find_task_by_vpid(shm_lapid);
71882 +
71883 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
71884 + (task_pid_nr(task) == shm_lapid)) &&
71885 + (task->acl->mode & GR_PROTSHM) &&
71886 + (task->acl != current->acl))) {
71887 + read_unlock(&tasklist_lock);
71888 + rcu_read_unlock();
71889 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
71890 + return 0;
71891 + }
71892 + read_unlock(&tasklist_lock);
71893 + rcu_read_unlock();
71894 +
71895 + return 1;
71896 +}
71897 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
71898 new file mode 100644
71899 index 0000000..bc0be01
71900 --- /dev/null
71901 +++ b/grsecurity/grsec_chdir.c
71902 @@ -0,0 +1,19 @@
71903 +#include <linux/kernel.h>
71904 +#include <linux/sched.h>
71905 +#include <linux/fs.h>
71906 +#include <linux/file.h>
71907 +#include <linux/grsecurity.h>
71908 +#include <linux/grinternal.h>
71909 +
71910 +void
71911 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
71912 +{
71913 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71914 + if ((grsec_enable_chdir && grsec_enable_group &&
71915 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
71916 + !grsec_enable_group)) {
71917 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
71918 + }
71919 +#endif
71920 + return;
71921 +}
71922 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
71923 new file mode 100644
71924 index 0000000..e10b319
71925 --- /dev/null
71926 +++ b/grsecurity/grsec_chroot.c
71927 @@ -0,0 +1,370 @@
71928 +#include <linux/kernel.h>
71929 +#include <linux/module.h>
71930 +#include <linux/sched.h>
71931 +#include <linux/file.h>
71932 +#include <linux/fs.h>
71933 +#include <linux/mount.h>
71934 +#include <linux/types.h>
71935 +#include "../fs/mount.h"
71936 +#include <linux/grsecurity.h>
71937 +#include <linux/grinternal.h>
71938 +
71939 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71940 +int gr_init_ran;
71941 +#endif
71942 +
71943 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
71944 +{
71945 +#ifdef CONFIG_GRKERNSEC
71946 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
71947 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
71948 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71949 + && gr_init_ran
71950 +#endif
71951 + )
71952 + task->gr_is_chrooted = 1;
71953 + else {
71954 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71955 + if (task_pid_nr(task) == 1 && !gr_init_ran)
71956 + gr_init_ran = 1;
71957 +#endif
71958 + task->gr_is_chrooted = 0;
71959 + }
71960 +
71961 + task->gr_chroot_dentry = path->dentry;
71962 +#endif
71963 + return;
71964 +}
71965 +
71966 +void gr_clear_chroot_entries(struct task_struct *task)
71967 +{
71968 +#ifdef CONFIG_GRKERNSEC
71969 + task->gr_is_chrooted = 0;
71970 + task->gr_chroot_dentry = NULL;
71971 +#endif
71972 + return;
71973 +}
71974 +
71975 +int
71976 +gr_handle_chroot_unix(const pid_t pid)
71977 +{
71978 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71979 + struct task_struct *p;
71980 +
71981 + if (unlikely(!grsec_enable_chroot_unix))
71982 + return 1;
71983 +
71984 + if (likely(!proc_is_chrooted(current)))
71985 + return 1;
71986 +
71987 + rcu_read_lock();
71988 + read_lock(&tasklist_lock);
71989 + p = find_task_by_vpid_unrestricted(pid);
71990 + if (unlikely(p && !have_same_root(current, p))) {
71991 + read_unlock(&tasklist_lock);
71992 + rcu_read_unlock();
71993 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
71994 + return 0;
71995 + }
71996 + read_unlock(&tasklist_lock);
71997 + rcu_read_unlock();
71998 +#endif
71999 + return 1;
72000 +}
72001 +
72002 +int
72003 +gr_handle_chroot_nice(void)
72004 +{
72005 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72006 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72007 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72008 + return -EPERM;
72009 + }
72010 +#endif
72011 + return 0;
72012 +}
72013 +
72014 +int
72015 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72016 +{
72017 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72018 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72019 + && proc_is_chrooted(current)) {
72020 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72021 + return -EACCES;
72022 + }
72023 +#endif
72024 + return 0;
72025 +}
72026 +
72027 +int
72028 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72029 +{
72030 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72031 + struct task_struct *p;
72032 + int ret = 0;
72033 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72034 + return ret;
72035 +
72036 + read_lock(&tasklist_lock);
72037 + do_each_pid_task(pid, type, p) {
72038 + if (!have_same_root(current, p)) {
72039 + ret = 1;
72040 + goto out;
72041 + }
72042 + } while_each_pid_task(pid, type, p);
72043 +out:
72044 + read_unlock(&tasklist_lock);
72045 + return ret;
72046 +#endif
72047 + return 0;
72048 +}
72049 +
72050 +int
72051 +gr_pid_is_chrooted(struct task_struct *p)
72052 +{
72053 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72054 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
72055 + return 0;
72056 +
72057 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
72058 + !have_same_root(current, p)) {
72059 + return 1;
72060 + }
72061 +#endif
72062 + return 0;
72063 +}
72064 +
72065 +EXPORT_SYMBOL(gr_pid_is_chrooted);
72066 +
72067 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
72068 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
72069 +{
72070 + struct path path, currentroot;
72071 + int ret = 0;
72072 +
72073 + path.dentry = (struct dentry *)u_dentry;
72074 + path.mnt = (struct vfsmount *)u_mnt;
72075 + get_fs_root(current->fs, &currentroot);
72076 + if (path_is_under(&path, &currentroot))
72077 + ret = 1;
72078 + path_put(&currentroot);
72079 +
72080 + return ret;
72081 +}
72082 +#endif
72083 +
72084 +int
72085 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
72086 +{
72087 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72088 + if (!grsec_enable_chroot_fchdir)
72089 + return 1;
72090 +
72091 + if (!proc_is_chrooted(current))
72092 + return 1;
72093 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
72094 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
72095 + return 0;
72096 + }
72097 +#endif
72098 + return 1;
72099 +}
72100 +
72101 +int
72102 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72103 + const time_t shm_createtime)
72104 +{
72105 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72106 + struct task_struct *p;
72107 + time_t starttime;
72108 +
72109 + if (unlikely(!grsec_enable_chroot_shmat))
72110 + return 1;
72111 +
72112 + if (likely(!proc_is_chrooted(current)))
72113 + return 1;
72114 +
72115 + rcu_read_lock();
72116 + read_lock(&tasklist_lock);
72117 +
72118 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
72119 + starttime = p->start_time.tv_sec;
72120 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
72121 + if (have_same_root(current, p)) {
72122 + goto allow;
72123 + } else {
72124 + read_unlock(&tasklist_lock);
72125 + rcu_read_unlock();
72126 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72127 + return 0;
72128 + }
72129 + }
72130 + /* creator exited, pid reuse, fall through to next check */
72131 + }
72132 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
72133 + if (unlikely(!have_same_root(current, p))) {
72134 + read_unlock(&tasklist_lock);
72135 + rcu_read_unlock();
72136 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72137 + return 0;
72138 + }
72139 + }
72140 +
72141 +allow:
72142 + read_unlock(&tasklist_lock);
72143 + rcu_read_unlock();
72144 +#endif
72145 + return 1;
72146 +}
72147 +
72148 +void
72149 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
72150 +{
72151 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72152 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
72153 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
72154 +#endif
72155 + return;
72156 +}
72157 +
72158 +int
72159 +gr_handle_chroot_mknod(const struct dentry *dentry,
72160 + const struct vfsmount *mnt, const int mode)
72161 +{
72162 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72163 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
72164 + proc_is_chrooted(current)) {
72165 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
72166 + return -EPERM;
72167 + }
72168 +#endif
72169 + return 0;
72170 +}
72171 +
72172 +int
72173 +gr_handle_chroot_mount(const struct dentry *dentry,
72174 + const struct vfsmount *mnt, const char *dev_name)
72175 +{
72176 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72177 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
72178 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
72179 + return -EPERM;
72180 + }
72181 +#endif
72182 + return 0;
72183 +}
72184 +
72185 +int
72186 +gr_handle_chroot_pivot(void)
72187 +{
72188 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72189 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
72190 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
72191 + return -EPERM;
72192 + }
72193 +#endif
72194 + return 0;
72195 +}
72196 +
72197 +int
72198 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
72199 +{
72200 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72201 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
72202 + !gr_is_outside_chroot(dentry, mnt)) {
72203 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
72204 + return -EPERM;
72205 + }
72206 +#endif
72207 + return 0;
72208 +}
72209 +
72210 +extern const char *captab_log[];
72211 +extern int captab_log_entries;
72212 +
72213 +int
72214 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72215 +{
72216 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72217 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72218 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72219 + if (cap_raised(chroot_caps, cap)) {
72220 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
72221 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
72222 + }
72223 + return 0;
72224 + }
72225 + }
72226 +#endif
72227 + return 1;
72228 +}
72229 +
72230 +int
72231 +gr_chroot_is_capable(const int cap)
72232 +{
72233 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72234 + return gr_task_chroot_is_capable(current, current_cred(), cap);
72235 +#endif
72236 + return 1;
72237 +}
72238 +
72239 +int
72240 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
72241 +{
72242 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72243 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72244 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72245 + if (cap_raised(chroot_caps, cap)) {
72246 + return 0;
72247 + }
72248 + }
72249 +#endif
72250 + return 1;
72251 +}
72252 +
72253 +int
72254 +gr_chroot_is_capable_nolog(const int cap)
72255 +{
72256 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72257 + return gr_task_chroot_is_capable_nolog(current, cap);
72258 +#endif
72259 + return 1;
72260 +}
72261 +
72262 +int
72263 +gr_handle_chroot_sysctl(const int op)
72264 +{
72265 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72266 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
72267 + proc_is_chrooted(current))
72268 + return -EACCES;
72269 +#endif
72270 + return 0;
72271 +}
72272 +
72273 +void
72274 +gr_handle_chroot_chdir(const struct path *path)
72275 +{
72276 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72277 + if (grsec_enable_chroot_chdir)
72278 + set_fs_pwd(current->fs, path);
72279 +#endif
72280 + return;
72281 +}
72282 +
72283 +int
72284 +gr_handle_chroot_chmod(const struct dentry *dentry,
72285 + const struct vfsmount *mnt, const int mode)
72286 +{
72287 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72288 + /* allow chmod +s on directories, but not files */
72289 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
72290 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
72291 + proc_is_chrooted(current)) {
72292 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
72293 + return -EPERM;
72294 + }
72295 +#endif
72296 + return 0;
72297 +}
72298 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
72299 new file mode 100644
72300 index 0000000..52b3e30
72301 --- /dev/null
72302 +++ b/grsecurity/grsec_disabled.c
72303 @@ -0,0 +1,433 @@
72304 +#include <linux/kernel.h>
72305 +#include <linux/module.h>
72306 +#include <linux/sched.h>
72307 +#include <linux/file.h>
72308 +#include <linux/fs.h>
72309 +#include <linux/kdev_t.h>
72310 +#include <linux/net.h>
72311 +#include <linux/in.h>
72312 +#include <linux/ip.h>
72313 +#include <linux/skbuff.h>
72314 +#include <linux/sysctl.h>
72315 +
72316 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
72317 +void
72318 +pax_set_initial_flags(struct linux_binprm *bprm)
72319 +{
72320 + return;
72321 +}
72322 +#endif
72323 +
72324 +#ifdef CONFIG_SYSCTL
72325 +__u32
72326 +gr_handle_sysctl(const struct ctl_table * table, const int op)
72327 +{
72328 + return 0;
72329 +}
72330 +#endif
72331 +
72332 +#ifdef CONFIG_TASKSTATS
72333 +int gr_is_taskstats_denied(int pid)
72334 +{
72335 + return 0;
72336 +}
72337 +#endif
72338 +
72339 +int
72340 +gr_acl_is_enabled(void)
72341 +{
72342 + return 0;
72343 +}
72344 +
72345 +void
72346 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72347 +{
72348 + return;
72349 +}
72350 +
72351 +int
72352 +gr_handle_rawio(const struct inode *inode)
72353 +{
72354 + return 0;
72355 +}
72356 +
72357 +void
72358 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72359 +{
72360 + return;
72361 +}
72362 +
72363 +int
72364 +gr_handle_ptrace(struct task_struct *task, const long request)
72365 +{
72366 + return 0;
72367 +}
72368 +
72369 +int
72370 +gr_handle_proc_ptrace(struct task_struct *task)
72371 +{
72372 + return 0;
72373 +}
72374 +
72375 +int
72376 +gr_set_acls(const int type)
72377 +{
72378 + return 0;
72379 +}
72380 +
72381 +int
72382 +gr_check_hidden_task(const struct task_struct *tsk)
72383 +{
72384 + return 0;
72385 +}
72386 +
72387 +int
72388 +gr_check_protected_task(const struct task_struct *task)
72389 +{
72390 + return 0;
72391 +}
72392 +
72393 +int
72394 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
72395 +{
72396 + return 0;
72397 +}
72398 +
72399 +void
72400 +gr_copy_label(struct task_struct *tsk)
72401 +{
72402 + return;
72403 +}
72404 +
72405 +void
72406 +gr_set_pax_flags(struct task_struct *task)
72407 +{
72408 + return;
72409 +}
72410 +
72411 +int
72412 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72413 + const int unsafe_share)
72414 +{
72415 + return 0;
72416 +}
72417 +
72418 +void
72419 +gr_handle_delete(const ino_t ino, const dev_t dev)
72420 +{
72421 + return;
72422 +}
72423 +
72424 +void
72425 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72426 +{
72427 + return;
72428 +}
72429 +
72430 +void
72431 +gr_handle_crash(struct task_struct *task, const int sig)
72432 +{
72433 + return;
72434 +}
72435 +
72436 +int
72437 +gr_check_crash_exec(const struct file *filp)
72438 +{
72439 + return 0;
72440 +}
72441 +
72442 +int
72443 +gr_check_crash_uid(const kuid_t uid)
72444 +{
72445 + return 0;
72446 +}
72447 +
72448 +void
72449 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72450 + struct dentry *old_dentry,
72451 + struct dentry *new_dentry,
72452 + struct vfsmount *mnt, const __u8 replace)
72453 +{
72454 + return;
72455 +}
72456 +
72457 +int
72458 +gr_search_socket(const int family, const int type, const int protocol)
72459 +{
72460 + return 1;
72461 +}
72462 +
72463 +int
72464 +gr_search_connectbind(const int mode, const struct socket *sock,
72465 + const struct sockaddr_in *addr)
72466 +{
72467 + return 0;
72468 +}
72469 +
72470 +void
72471 +gr_handle_alertkill(struct task_struct *task)
72472 +{
72473 + return;
72474 +}
72475 +
72476 +__u32
72477 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
72478 +{
72479 + return 1;
72480 +}
72481 +
72482 +__u32
72483 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72484 + const struct vfsmount * mnt)
72485 +{
72486 + return 1;
72487 +}
72488 +
72489 +__u32
72490 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72491 + int acc_mode)
72492 +{
72493 + return 1;
72494 +}
72495 +
72496 +__u32
72497 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72498 +{
72499 + return 1;
72500 +}
72501 +
72502 +__u32
72503 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
72504 +{
72505 + return 1;
72506 +}
72507 +
72508 +int
72509 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
72510 + unsigned int *vm_flags)
72511 +{
72512 + return 1;
72513 +}
72514 +
72515 +__u32
72516 +gr_acl_handle_truncate(const struct dentry * dentry,
72517 + const struct vfsmount * mnt)
72518 +{
72519 + return 1;
72520 +}
72521 +
72522 +__u32
72523 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
72524 +{
72525 + return 1;
72526 +}
72527 +
72528 +__u32
72529 +gr_acl_handle_access(const struct dentry * dentry,
72530 + const struct vfsmount * mnt, const int fmode)
72531 +{
72532 + return 1;
72533 +}
72534 +
72535 +__u32
72536 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
72537 + umode_t *mode)
72538 +{
72539 + return 1;
72540 +}
72541 +
72542 +__u32
72543 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
72544 +{
72545 + return 1;
72546 +}
72547 +
72548 +__u32
72549 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
72550 +{
72551 + return 1;
72552 +}
72553 +
72554 +__u32
72555 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
72556 +{
72557 + return 1;
72558 +}
72559 +
72560 +void
72561 +grsecurity_init(void)
72562 +{
72563 + return;
72564 +}
72565 +
72566 +umode_t gr_acl_umask(void)
72567 +{
72568 + return 0;
72569 +}
72570 +
72571 +__u32
72572 +gr_acl_handle_mknod(const struct dentry * new_dentry,
72573 + const struct dentry * parent_dentry,
72574 + const struct vfsmount * parent_mnt,
72575 + const int mode)
72576 +{
72577 + return 1;
72578 +}
72579 +
72580 +__u32
72581 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
72582 + const struct dentry * parent_dentry,
72583 + const struct vfsmount * parent_mnt)
72584 +{
72585 + return 1;
72586 +}
72587 +
72588 +__u32
72589 +gr_acl_handle_symlink(const struct dentry * new_dentry,
72590 + const struct dentry * parent_dentry,
72591 + const struct vfsmount * parent_mnt, const struct filename *from)
72592 +{
72593 + return 1;
72594 +}
72595 +
72596 +__u32
72597 +gr_acl_handle_link(const struct dentry * new_dentry,
72598 + const struct dentry * parent_dentry,
72599 + const struct vfsmount * parent_mnt,
72600 + const struct dentry * old_dentry,
72601 + const struct vfsmount * old_mnt, const struct filename *to)
72602 +{
72603 + return 1;
72604 +}
72605 +
72606 +int
72607 +gr_acl_handle_rename(const struct dentry *new_dentry,
72608 + const struct dentry *parent_dentry,
72609 + const struct vfsmount *parent_mnt,
72610 + const struct dentry *old_dentry,
72611 + const struct inode *old_parent_inode,
72612 + const struct vfsmount *old_mnt, const struct filename *newname)
72613 +{
72614 + return 0;
72615 +}
72616 +
72617 +int
72618 +gr_acl_handle_filldir(const struct file *file, const char *name,
72619 + const int namelen, const ino_t ino)
72620 +{
72621 + return 1;
72622 +}
72623 +
72624 +int
72625 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72626 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72627 +{
72628 + return 1;
72629 +}
72630 +
72631 +int
72632 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
72633 +{
72634 + return 0;
72635 +}
72636 +
72637 +int
72638 +gr_search_accept(const struct socket *sock)
72639 +{
72640 + return 0;
72641 +}
72642 +
72643 +int
72644 +gr_search_listen(const struct socket *sock)
72645 +{
72646 + return 0;
72647 +}
72648 +
72649 +int
72650 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
72651 +{
72652 + return 0;
72653 +}
72654 +
72655 +__u32
72656 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
72657 +{
72658 + return 1;
72659 +}
72660 +
72661 +__u32
72662 +gr_acl_handle_creat(const struct dentry * dentry,
72663 + const struct dentry * p_dentry,
72664 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72665 + const int imode)
72666 +{
72667 + return 1;
72668 +}
72669 +
72670 +void
72671 +gr_acl_handle_exit(void)
72672 +{
72673 + return;
72674 +}
72675 +
72676 +int
72677 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72678 +{
72679 + return 1;
72680 +}
72681 +
72682 +void
72683 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
72684 +{
72685 + return;
72686 +}
72687 +
72688 +int
72689 +gr_acl_handle_procpidmem(const struct task_struct *task)
72690 +{
72691 + return 0;
72692 +}
72693 +
72694 +int
72695 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
72696 +{
72697 + return 0;
72698 +}
72699 +
72700 +int
72701 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
72702 +{
72703 + return 0;
72704 +}
72705 +
72706 +int
72707 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
72708 +{
72709 + return 0;
72710 +}
72711 +
72712 +int
72713 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72714 +{
72715 + return 0;
72716 +}
72717 +
72718 +int gr_acl_enable_at_secure(void)
72719 +{
72720 + return 0;
72721 +}
72722 +
72723 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
72724 +{
72725 + return dentry->d_sb->s_dev;
72726 +}
72727 +
72728 +void gr_put_exec_file(struct task_struct *task)
72729 +{
72730 + return;
72731 +}
72732 +
72733 +#ifdef CONFIG_SECURITY
72734 +EXPORT_SYMBOL(gr_check_user_change);
72735 +EXPORT_SYMBOL(gr_check_group_change);
72736 +#endif
72737 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
72738 new file mode 100644
72739 index 0000000..387032b
72740 --- /dev/null
72741 +++ b/grsecurity/grsec_exec.c
72742 @@ -0,0 +1,187 @@
72743 +#include <linux/kernel.h>
72744 +#include <linux/sched.h>
72745 +#include <linux/file.h>
72746 +#include <linux/binfmts.h>
72747 +#include <linux/fs.h>
72748 +#include <linux/types.h>
72749 +#include <linux/grdefs.h>
72750 +#include <linux/grsecurity.h>
72751 +#include <linux/grinternal.h>
72752 +#include <linux/capability.h>
72753 +#include <linux/module.h>
72754 +#include <linux/compat.h>
72755 +
72756 +#include <asm/uaccess.h>
72757 +
72758 +#ifdef CONFIG_GRKERNSEC_EXECLOG
72759 +static char gr_exec_arg_buf[132];
72760 +static DEFINE_MUTEX(gr_exec_arg_mutex);
72761 +#endif
72762 +
72763 +struct user_arg_ptr {
72764 +#ifdef CONFIG_COMPAT
72765 + bool is_compat;
72766 +#endif
72767 + union {
72768 + const char __user *const __user *native;
72769 +#ifdef CONFIG_COMPAT
72770 + const compat_uptr_t __user *compat;
72771 +#endif
72772 + } ptr;
72773 +};
72774 +
72775 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
72776 +
72777 +void
72778 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
72779 +{
72780 +#ifdef CONFIG_GRKERNSEC_EXECLOG
72781 + char *grarg = gr_exec_arg_buf;
72782 + unsigned int i, x, execlen = 0;
72783 + char c;
72784 +
72785 + if (!((grsec_enable_execlog && grsec_enable_group &&
72786 + in_group_p(grsec_audit_gid))
72787 + || (grsec_enable_execlog && !grsec_enable_group)))
72788 + return;
72789 +
72790 + mutex_lock(&gr_exec_arg_mutex);
72791 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
72792 +
72793 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
72794 + const char __user *p;
72795 + unsigned int len;
72796 +
72797 + p = get_user_arg_ptr(argv, i);
72798 + if (IS_ERR(p))
72799 + goto log;
72800 +
72801 + len = strnlen_user(p, 128 - execlen);
72802 + if (len > 128 - execlen)
72803 + len = 128 - execlen;
72804 + else if (len > 0)
72805 + len--;
72806 + if (copy_from_user(grarg + execlen, p, len))
72807 + goto log;
72808 +
72809 + /* rewrite unprintable characters */
72810 + for (x = 0; x < len; x++) {
72811 + c = *(grarg + execlen + x);
72812 + if (c < 32 || c > 126)
72813 + *(grarg + execlen + x) = ' ';
72814 + }
72815 +
72816 + execlen += len;
72817 + *(grarg + execlen) = ' ';
72818 + *(grarg + execlen + 1) = '\0';
72819 + execlen++;
72820 + }
72821 +
72822 + log:
72823 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
72824 + bprm->file->f_path.mnt, grarg);
72825 + mutex_unlock(&gr_exec_arg_mutex);
72826 +#endif
72827 + return;
72828 +}
72829 +
72830 +#ifdef CONFIG_GRKERNSEC
72831 +extern int gr_acl_is_capable(const int cap);
72832 +extern int gr_acl_is_capable_nolog(const int cap);
72833 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72834 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
72835 +extern int gr_chroot_is_capable(const int cap);
72836 +extern int gr_chroot_is_capable_nolog(const int cap);
72837 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72838 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
72839 +#endif
72840 +
72841 +const char *captab_log[] = {
72842 + "CAP_CHOWN",
72843 + "CAP_DAC_OVERRIDE",
72844 + "CAP_DAC_READ_SEARCH",
72845 + "CAP_FOWNER",
72846 + "CAP_FSETID",
72847 + "CAP_KILL",
72848 + "CAP_SETGID",
72849 + "CAP_SETUID",
72850 + "CAP_SETPCAP",
72851 + "CAP_LINUX_IMMUTABLE",
72852 + "CAP_NET_BIND_SERVICE",
72853 + "CAP_NET_BROADCAST",
72854 + "CAP_NET_ADMIN",
72855 + "CAP_NET_RAW",
72856 + "CAP_IPC_LOCK",
72857 + "CAP_IPC_OWNER",
72858 + "CAP_SYS_MODULE",
72859 + "CAP_SYS_RAWIO",
72860 + "CAP_SYS_CHROOT",
72861 + "CAP_SYS_PTRACE",
72862 + "CAP_SYS_PACCT",
72863 + "CAP_SYS_ADMIN",
72864 + "CAP_SYS_BOOT",
72865 + "CAP_SYS_NICE",
72866 + "CAP_SYS_RESOURCE",
72867 + "CAP_SYS_TIME",
72868 + "CAP_SYS_TTY_CONFIG",
72869 + "CAP_MKNOD",
72870 + "CAP_LEASE",
72871 + "CAP_AUDIT_WRITE",
72872 + "CAP_AUDIT_CONTROL",
72873 + "CAP_SETFCAP",
72874 + "CAP_MAC_OVERRIDE",
72875 + "CAP_MAC_ADMIN",
72876 + "CAP_SYSLOG",
72877 + "CAP_WAKE_ALARM"
72878 +};
72879 +
72880 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
72881 +
72882 +int gr_is_capable(const int cap)
72883 +{
72884 +#ifdef CONFIG_GRKERNSEC
72885 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
72886 + return 1;
72887 + return 0;
72888 +#else
72889 + return 1;
72890 +#endif
72891 +}
72892 +
72893 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72894 +{
72895 +#ifdef CONFIG_GRKERNSEC
72896 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
72897 + return 1;
72898 + return 0;
72899 +#else
72900 + return 1;
72901 +#endif
72902 +}
72903 +
72904 +int gr_is_capable_nolog(const int cap)
72905 +{
72906 +#ifdef CONFIG_GRKERNSEC
72907 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
72908 + return 1;
72909 + return 0;
72910 +#else
72911 + return 1;
72912 +#endif
72913 +}
72914 +
72915 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
72916 +{
72917 +#ifdef CONFIG_GRKERNSEC
72918 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
72919 + return 1;
72920 + return 0;
72921 +#else
72922 + return 1;
72923 +#endif
72924 +}
72925 +
72926 +EXPORT_SYMBOL(gr_is_capable);
72927 +EXPORT_SYMBOL(gr_is_capable_nolog);
72928 +EXPORT_SYMBOL(gr_task_is_capable);
72929 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
72930 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
72931 new file mode 100644
72932 index 0000000..06cc6ea
72933 --- /dev/null
72934 +++ b/grsecurity/grsec_fifo.c
72935 @@ -0,0 +1,24 @@
72936 +#include <linux/kernel.h>
72937 +#include <linux/sched.h>
72938 +#include <linux/fs.h>
72939 +#include <linux/file.h>
72940 +#include <linux/grinternal.h>
72941 +
72942 +int
72943 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
72944 + const struct dentry *dir, const int flag, const int acc_mode)
72945 +{
72946 +#ifdef CONFIG_GRKERNSEC_FIFO
72947 + const struct cred *cred = current_cred();
72948 +
72949 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
72950 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
72951 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
72952 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
72953 + if (!inode_permission(dentry->d_inode, acc_mode))
72954 + 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));
72955 + return -EACCES;
72956 + }
72957 +#endif
72958 + return 0;
72959 +}
72960 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
72961 new file mode 100644
72962 index 0000000..8ca18bf
72963 --- /dev/null
72964 +++ b/grsecurity/grsec_fork.c
72965 @@ -0,0 +1,23 @@
72966 +#include <linux/kernel.h>
72967 +#include <linux/sched.h>
72968 +#include <linux/grsecurity.h>
72969 +#include <linux/grinternal.h>
72970 +#include <linux/errno.h>
72971 +
72972 +void
72973 +gr_log_forkfail(const int retval)
72974 +{
72975 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
72976 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
72977 + switch (retval) {
72978 + case -EAGAIN:
72979 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
72980 + break;
72981 + case -ENOMEM:
72982 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
72983 + break;
72984 + }
72985 + }
72986 +#endif
72987 + return;
72988 +}
72989 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
72990 new file mode 100644
72991 index 0000000..a88e901
72992 --- /dev/null
72993 +++ b/grsecurity/grsec_init.c
72994 @@ -0,0 +1,272 @@
72995 +#include <linux/kernel.h>
72996 +#include <linux/sched.h>
72997 +#include <linux/mm.h>
72998 +#include <linux/gracl.h>
72999 +#include <linux/slab.h>
73000 +#include <linux/vmalloc.h>
73001 +#include <linux/percpu.h>
73002 +#include <linux/module.h>
73003 +
73004 +int grsec_enable_ptrace_readexec;
73005 +int grsec_enable_setxid;
73006 +int grsec_enable_symlinkown;
73007 +kgid_t grsec_symlinkown_gid;
73008 +int grsec_enable_brute;
73009 +int grsec_enable_link;
73010 +int grsec_enable_dmesg;
73011 +int grsec_enable_harden_ptrace;
73012 +int grsec_enable_harden_ipc;
73013 +int grsec_enable_fifo;
73014 +int grsec_enable_execlog;
73015 +int grsec_enable_signal;
73016 +int grsec_enable_forkfail;
73017 +int grsec_enable_audit_ptrace;
73018 +int grsec_enable_time;
73019 +int grsec_enable_group;
73020 +kgid_t grsec_audit_gid;
73021 +int grsec_enable_chdir;
73022 +int grsec_enable_mount;
73023 +int grsec_enable_rofs;
73024 +int grsec_deny_new_usb;
73025 +int grsec_enable_chroot_findtask;
73026 +int grsec_enable_chroot_mount;
73027 +int grsec_enable_chroot_shmat;
73028 +int grsec_enable_chroot_fchdir;
73029 +int grsec_enable_chroot_double;
73030 +int grsec_enable_chroot_pivot;
73031 +int grsec_enable_chroot_chdir;
73032 +int grsec_enable_chroot_chmod;
73033 +int grsec_enable_chroot_mknod;
73034 +int grsec_enable_chroot_nice;
73035 +int grsec_enable_chroot_execlog;
73036 +int grsec_enable_chroot_caps;
73037 +int grsec_enable_chroot_sysctl;
73038 +int grsec_enable_chroot_unix;
73039 +int grsec_enable_tpe;
73040 +kgid_t grsec_tpe_gid;
73041 +int grsec_enable_blackhole;
73042 +#ifdef CONFIG_IPV6_MODULE
73043 +EXPORT_SYMBOL(grsec_enable_blackhole);
73044 +#endif
73045 +int grsec_lastack_retries;
73046 +int grsec_enable_tpe_all;
73047 +int grsec_enable_tpe_invert;
73048 +int grsec_enable_socket_all;
73049 +kgid_t grsec_socket_all_gid;
73050 +int grsec_enable_socket_client;
73051 +kgid_t grsec_socket_client_gid;
73052 +int grsec_enable_socket_server;
73053 +kgid_t grsec_socket_server_gid;
73054 +int grsec_resource_logging;
73055 +int grsec_disable_privio;
73056 +int grsec_enable_log_rwxmaps;
73057 +int grsec_lock;
73058 +
73059 +DEFINE_SPINLOCK(grsec_alert_lock);
73060 +unsigned long grsec_alert_wtime = 0;
73061 +unsigned long grsec_alert_fyet = 0;
73062 +
73063 +DEFINE_SPINLOCK(grsec_audit_lock);
73064 +
73065 +DEFINE_RWLOCK(grsec_exec_file_lock);
73066 +
73067 +char *gr_shared_page[4];
73068 +
73069 +char *gr_alert_log_fmt;
73070 +char *gr_audit_log_fmt;
73071 +char *gr_alert_log_buf;
73072 +char *gr_audit_log_buf;
73073 +
73074 +void __init
73075 +grsecurity_init(void)
73076 +{
73077 + int j;
73078 + /* create the per-cpu shared pages */
73079 +
73080 +#ifdef CONFIG_X86
73081 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
73082 +#endif
73083 +
73084 + for (j = 0; j < 4; j++) {
73085 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
73086 + if (gr_shared_page[j] == NULL) {
73087 + panic("Unable to allocate grsecurity shared page");
73088 + return;
73089 + }
73090 + }
73091 +
73092 + /* allocate log buffers */
73093 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
73094 + if (!gr_alert_log_fmt) {
73095 + panic("Unable to allocate grsecurity alert log format buffer");
73096 + return;
73097 + }
73098 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
73099 + if (!gr_audit_log_fmt) {
73100 + panic("Unable to allocate grsecurity audit log format buffer");
73101 + return;
73102 + }
73103 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73104 + if (!gr_alert_log_buf) {
73105 + panic("Unable to allocate grsecurity alert log buffer");
73106 + return;
73107 + }
73108 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73109 + if (!gr_audit_log_buf) {
73110 + panic("Unable to allocate grsecurity audit log buffer");
73111 + return;
73112 + }
73113 +
73114 +#ifdef CONFIG_GRKERNSEC_IO
73115 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
73116 + grsec_disable_privio = 1;
73117 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73118 + grsec_disable_privio = 1;
73119 +#else
73120 + grsec_disable_privio = 0;
73121 +#endif
73122 +#endif
73123 +
73124 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73125 + /* for backward compatibility, tpe_invert always defaults to on if
73126 + enabled in the kernel
73127 + */
73128 + grsec_enable_tpe_invert = 1;
73129 +#endif
73130 +
73131 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73132 +#ifndef CONFIG_GRKERNSEC_SYSCTL
73133 + grsec_lock = 1;
73134 +#endif
73135 +
73136 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73137 + grsec_enable_log_rwxmaps = 1;
73138 +#endif
73139 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73140 + grsec_enable_group = 1;
73141 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
73142 +#endif
73143 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73144 + grsec_enable_ptrace_readexec = 1;
73145 +#endif
73146 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73147 + grsec_enable_chdir = 1;
73148 +#endif
73149 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73150 + grsec_enable_harden_ptrace = 1;
73151 +#endif
73152 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73153 + grsec_enable_harden_ipc = 1;
73154 +#endif
73155 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73156 + grsec_enable_mount = 1;
73157 +#endif
73158 +#ifdef CONFIG_GRKERNSEC_LINK
73159 + grsec_enable_link = 1;
73160 +#endif
73161 +#ifdef CONFIG_GRKERNSEC_BRUTE
73162 + grsec_enable_brute = 1;
73163 +#endif
73164 +#ifdef CONFIG_GRKERNSEC_DMESG
73165 + grsec_enable_dmesg = 1;
73166 +#endif
73167 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73168 + grsec_enable_blackhole = 1;
73169 + grsec_lastack_retries = 4;
73170 +#endif
73171 +#ifdef CONFIG_GRKERNSEC_FIFO
73172 + grsec_enable_fifo = 1;
73173 +#endif
73174 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73175 + grsec_enable_execlog = 1;
73176 +#endif
73177 +#ifdef CONFIG_GRKERNSEC_SETXID
73178 + grsec_enable_setxid = 1;
73179 +#endif
73180 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73181 + grsec_enable_signal = 1;
73182 +#endif
73183 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73184 + grsec_enable_forkfail = 1;
73185 +#endif
73186 +#ifdef CONFIG_GRKERNSEC_TIME
73187 + grsec_enable_time = 1;
73188 +#endif
73189 +#ifdef CONFIG_GRKERNSEC_RESLOG
73190 + grsec_resource_logging = 1;
73191 +#endif
73192 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73193 + grsec_enable_chroot_findtask = 1;
73194 +#endif
73195 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73196 + grsec_enable_chroot_unix = 1;
73197 +#endif
73198 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73199 + grsec_enable_chroot_mount = 1;
73200 +#endif
73201 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73202 + grsec_enable_chroot_fchdir = 1;
73203 +#endif
73204 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73205 + grsec_enable_chroot_shmat = 1;
73206 +#endif
73207 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73208 + grsec_enable_audit_ptrace = 1;
73209 +#endif
73210 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73211 + grsec_enable_chroot_double = 1;
73212 +#endif
73213 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73214 + grsec_enable_chroot_pivot = 1;
73215 +#endif
73216 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73217 + grsec_enable_chroot_chdir = 1;
73218 +#endif
73219 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73220 + grsec_enable_chroot_chmod = 1;
73221 +#endif
73222 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73223 + grsec_enable_chroot_mknod = 1;
73224 +#endif
73225 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73226 + grsec_enable_chroot_nice = 1;
73227 +#endif
73228 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73229 + grsec_enable_chroot_execlog = 1;
73230 +#endif
73231 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73232 + grsec_enable_chroot_caps = 1;
73233 +#endif
73234 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73235 + grsec_enable_chroot_sysctl = 1;
73236 +#endif
73237 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73238 + grsec_enable_symlinkown = 1;
73239 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
73240 +#endif
73241 +#ifdef CONFIG_GRKERNSEC_TPE
73242 + grsec_enable_tpe = 1;
73243 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
73244 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
73245 + grsec_enable_tpe_all = 1;
73246 +#endif
73247 +#endif
73248 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73249 + grsec_enable_socket_all = 1;
73250 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
73251 +#endif
73252 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
73253 + grsec_enable_socket_client = 1;
73254 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
73255 +#endif
73256 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
73257 + grsec_enable_socket_server = 1;
73258 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
73259 +#endif
73260 +#endif
73261 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
73262 + grsec_deny_new_usb = 1;
73263 +#endif
73264 +
73265 + return;
73266 +}
73267 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
73268 new file mode 100644
73269 index 0000000..78d1680
73270 --- /dev/null
73271 +++ b/grsecurity/grsec_ipc.c
73272 @@ -0,0 +1,48 @@
73273 +#include <linux/kernel.h>
73274 +#include <linux/mm.h>
73275 +#include <linux/sched.h>
73276 +#include <linux/file.h>
73277 +#include <linux/ipc.h>
73278 +#include <linux/ipc_namespace.h>
73279 +#include <linux/grsecurity.h>
73280 +#include <linux/grinternal.h>
73281 +
73282 +int
73283 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
73284 +{
73285 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73286 + int write;
73287 + int orig_granted_mode;
73288 + kuid_t euid;
73289 + kgid_t egid;
73290 +
73291 + if (!grsec_enable_harden_ipc)
73292 + return 0;
73293 +
73294 + euid = current_euid();
73295 + egid = current_egid();
73296 +
73297 + write = requested_mode & 00002;
73298 + orig_granted_mode = ipcp->mode;
73299 +
73300 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
73301 + orig_granted_mode >>= 6;
73302 + else {
73303 + /* if likely wrong permissions, lock to user */
73304 + if (orig_granted_mode & 0007)
73305 + orig_granted_mode = 0;
73306 + /* otherwise do a egid-only check */
73307 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
73308 + orig_granted_mode >>= 3;
73309 + /* otherwise, no access */
73310 + else
73311 + orig_granted_mode = 0;
73312 + }
73313 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
73314 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
73315 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
73316 + return 0;
73317 + }
73318 +#endif
73319 + return 1;
73320 +}
73321 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
73322 new file mode 100644
73323 index 0000000..5e05e20
73324 --- /dev/null
73325 +++ b/grsecurity/grsec_link.c
73326 @@ -0,0 +1,58 @@
73327 +#include <linux/kernel.h>
73328 +#include <linux/sched.h>
73329 +#include <linux/fs.h>
73330 +#include <linux/file.h>
73331 +#include <linux/grinternal.h>
73332 +
73333 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
73334 +{
73335 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73336 + const struct inode *link_inode = link->dentry->d_inode;
73337 +
73338 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
73339 + /* ignore root-owned links, e.g. /proc/self */
73340 + gr_is_global_nonroot(link_inode->i_uid) && target &&
73341 + !uid_eq(link_inode->i_uid, target->i_uid)) {
73342 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
73343 + return 1;
73344 + }
73345 +#endif
73346 + return 0;
73347 +}
73348 +
73349 +int
73350 +gr_handle_follow_link(const struct inode *parent,
73351 + const struct inode *inode,
73352 + const struct dentry *dentry, const struct vfsmount *mnt)
73353 +{
73354 +#ifdef CONFIG_GRKERNSEC_LINK
73355 + const struct cred *cred = current_cred();
73356 +
73357 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
73358 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
73359 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
73360 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
73361 + return -EACCES;
73362 + }
73363 +#endif
73364 + return 0;
73365 +}
73366 +
73367 +int
73368 +gr_handle_hardlink(const struct dentry *dentry,
73369 + const struct vfsmount *mnt,
73370 + struct inode *inode, const int mode, const struct filename *to)
73371 +{
73372 +#ifdef CONFIG_GRKERNSEC_LINK
73373 + const struct cred *cred = current_cred();
73374 +
73375 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
73376 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
73377 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
73378 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
73379 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
73380 + return -EPERM;
73381 + }
73382 +#endif
73383 + return 0;
73384 +}
73385 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
73386 new file mode 100644
73387 index 0000000..dbe0a6b
73388 --- /dev/null
73389 +++ b/grsecurity/grsec_log.c
73390 @@ -0,0 +1,341 @@
73391 +#include <linux/kernel.h>
73392 +#include <linux/sched.h>
73393 +#include <linux/file.h>
73394 +#include <linux/tty.h>
73395 +#include <linux/fs.h>
73396 +#include <linux/mm.h>
73397 +#include <linux/grinternal.h>
73398 +
73399 +#ifdef CONFIG_TREE_PREEMPT_RCU
73400 +#define DISABLE_PREEMPT() preempt_disable()
73401 +#define ENABLE_PREEMPT() preempt_enable()
73402 +#else
73403 +#define DISABLE_PREEMPT()
73404 +#define ENABLE_PREEMPT()
73405 +#endif
73406 +
73407 +#define BEGIN_LOCKS(x) \
73408 + DISABLE_PREEMPT(); \
73409 + rcu_read_lock(); \
73410 + read_lock(&tasklist_lock); \
73411 + read_lock(&grsec_exec_file_lock); \
73412 + if (x != GR_DO_AUDIT) \
73413 + spin_lock(&grsec_alert_lock); \
73414 + else \
73415 + spin_lock(&grsec_audit_lock)
73416 +
73417 +#define END_LOCKS(x) \
73418 + if (x != GR_DO_AUDIT) \
73419 + spin_unlock(&grsec_alert_lock); \
73420 + else \
73421 + spin_unlock(&grsec_audit_lock); \
73422 + read_unlock(&grsec_exec_file_lock); \
73423 + read_unlock(&tasklist_lock); \
73424 + rcu_read_unlock(); \
73425 + ENABLE_PREEMPT(); \
73426 + if (x == GR_DONT_AUDIT) \
73427 + gr_handle_alertkill(current)
73428 +
73429 +enum {
73430 + FLOODING,
73431 + NO_FLOODING
73432 +};
73433 +
73434 +extern char *gr_alert_log_fmt;
73435 +extern char *gr_audit_log_fmt;
73436 +extern char *gr_alert_log_buf;
73437 +extern char *gr_audit_log_buf;
73438 +
73439 +static int gr_log_start(int audit)
73440 +{
73441 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
73442 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
73443 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73444 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
73445 + unsigned long curr_secs = get_seconds();
73446 +
73447 + if (audit == GR_DO_AUDIT)
73448 + goto set_fmt;
73449 +
73450 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
73451 + grsec_alert_wtime = curr_secs;
73452 + grsec_alert_fyet = 0;
73453 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
73454 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
73455 + grsec_alert_fyet++;
73456 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
73457 + grsec_alert_wtime = curr_secs;
73458 + grsec_alert_fyet++;
73459 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
73460 + return FLOODING;
73461 + }
73462 + else return FLOODING;
73463 +
73464 +set_fmt:
73465 +#endif
73466 + memset(buf, 0, PAGE_SIZE);
73467 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
73468 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
73469 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73470 + } else if (current->signal->curr_ip) {
73471 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
73472 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
73473 + } else if (gr_acl_is_enabled()) {
73474 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
73475 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73476 + } else {
73477 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
73478 + strcpy(buf, fmt);
73479 + }
73480 +
73481 + return NO_FLOODING;
73482 +}
73483 +
73484 +static void gr_log_middle(int audit, const char *msg, va_list ap)
73485 + __attribute__ ((format (printf, 2, 0)));
73486 +
73487 +static void gr_log_middle(int audit, const char *msg, va_list ap)
73488 +{
73489 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73490 + unsigned int len = strlen(buf);
73491 +
73492 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73493 +
73494 + return;
73495 +}
73496 +
73497 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
73498 + __attribute__ ((format (printf, 2, 3)));
73499 +
73500 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
73501 +{
73502 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73503 + unsigned int len = strlen(buf);
73504 + va_list ap;
73505 +
73506 + va_start(ap, msg);
73507 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73508 + va_end(ap);
73509 +
73510 + return;
73511 +}
73512 +
73513 +static void gr_log_end(int audit, int append_default)
73514 +{
73515 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73516 + if (append_default) {
73517 + struct task_struct *task = current;
73518 + struct task_struct *parent = task->real_parent;
73519 + const struct cred *cred = __task_cred(task);
73520 + const struct cred *pcred = __task_cred(parent);
73521 + unsigned int len = strlen(buf);
73522 +
73523 + 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));
73524 + }
73525 +
73526 + printk("%s\n", buf);
73527 +
73528 + return;
73529 +}
73530 +
73531 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
73532 +{
73533 + int logtype;
73534 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
73535 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
73536 + void *voidptr = NULL;
73537 + int num1 = 0, num2 = 0;
73538 + unsigned long ulong1 = 0, ulong2 = 0;
73539 + struct dentry *dentry = NULL;
73540 + struct vfsmount *mnt = NULL;
73541 + struct file *file = NULL;
73542 + struct task_struct *task = NULL;
73543 + struct vm_area_struct *vma = NULL;
73544 + const struct cred *cred, *pcred;
73545 + va_list ap;
73546 +
73547 + BEGIN_LOCKS(audit);
73548 + logtype = gr_log_start(audit);
73549 + if (logtype == FLOODING) {
73550 + END_LOCKS(audit);
73551 + return;
73552 + }
73553 + va_start(ap, argtypes);
73554 + switch (argtypes) {
73555 + case GR_TTYSNIFF:
73556 + task = va_arg(ap, struct task_struct *);
73557 + 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));
73558 + break;
73559 + case GR_SYSCTL_HIDDEN:
73560 + str1 = va_arg(ap, char *);
73561 + gr_log_middle_varargs(audit, msg, result, str1);
73562 + break;
73563 + case GR_RBAC:
73564 + dentry = va_arg(ap, struct dentry *);
73565 + mnt = va_arg(ap, struct vfsmount *);
73566 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
73567 + break;
73568 + case GR_RBAC_STR:
73569 + dentry = va_arg(ap, struct dentry *);
73570 + mnt = va_arg(ap, struct vfsmount *);
73571 + str1 = va_arg(ap, char *);
73572 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
73573 + break;
73574 + case GR_STR_RBAC:
73575 + str1 = va_arg(ap, char *);
73576 + dentry = va_arg(ap, struct dentry *);
73577 + mnt = va_arg(ap, struct vfsmount *);
73578 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
73579 + break;
73580 + case GR_RBAC_MODE2:
73581 + dentry = va_arg(ap, struct dentry *);
73582 + mnt = va_arg(ap, struct vfsmount *);
73583 + str1 = va_arg(ap, char *);
73584 + str2 = va_arg(ap, char *);
73585 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
73586 + break;
73587 + case GR_RBAC_MODE3:
73588 + dentry = va_arg(ap, struct dentry *);
73589 + mnt = va_arg(ap, struct vfsmount *);
73590 + str1 = va_arg(ap, char *);
73591 + str2 = va_arg(ap, char *);
73592 + str3 = va_arg(ap, char *);
73593 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
73594 + break;
73595 + case GR_FILENAME:
73596 + dentry = va_arg(ap, struct dentry *);
73597 + mnt = va_arg(ap, struct vfsmount *);
73598 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
73599 + break;
73600 + case GR_STR_FILENAME:
73601 + str1 = va_arg(ap, char *);
73602 + dentry = va_arg(ap, struct dentry *);
73603 + mnt = va_arg(ap, struct vfsmount *);
73604 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
73605 + break;
73606 + case GR_FILENAME_STR:
73607 + dentry = va_arg(ap, struct dentry *);
73608 + mnt = va_arg(ap, struct vfsmount *);
73609 + str1 = va_arg(ap, char *);
73610 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
73611 + break;
73612 + case GR_FILENAME_TWO_INT:
73613 + dentry = va_arg(ap, struct dentry *);
73614 + mnt = va_arg(ap, struct vfsmount *);
73615 + num1 = va_arg(ap, int);
73616 + num2 = va_arg(ap, int);
73617 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
73618 + break;
73619 + case GR_FILENAME_TWO_INT_STR:
73620 + dentry = va_arg(ap, struct dentry *);
73621 + mnt = va_arg(ap, struct vfsmount *);
73622 + num1 = va_arg(ap, int);
73623 + num2 = va_arg(ap, int);
73624 + str1 = va_arg(ap, char *);
73625 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
73626 + break;
73627 + case GR_TEXTREL:
73628 + file = va_arg(ap, struct file *);
73629 + ulong1 = va_arg(ap, unsigned long);
73630 + ulong2 = va_arg(ap, unsigned long);
73631 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
73632 + break;
73633 + case GR_PTRACE:
73634 + task = va_arg(ap, struct task_struct *);
73635 + 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));
73636 + break;
73637 + case GR_RESOURCE:
73638 + task = va_arg(ap, struct task_struct *);
73639 + cred = __task_cred(task);
73640 + pcred = __task_cred(task->real_parent);
73641 + ulong1 = va_arg(ap, unsigned long);
73642 + str1 = va_arg(ap, char *);
73643 + ulong2 = va_arg(ap, unsigned long);
73644 + 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));
73645 + break;
73646 + case GR_CAP:
73647 + task = va_arg(ap, struct task_struct *);
73648 + cred = __task_cred(task);
73649 + pcred = __task_cred(task->real_parent);
73650 + str1 = va_arg(ap, char *);
73651 + 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));
73652 + break;
73653 + case GR_SIG:
73654 + str1 = va_arg(ap, char *);
73655 + voidptr = va_arg(ap, void *);
73656 + gr_log_middle_varargs(audit, msg, str1, voidptr);
73657 + break;
73658 + case GR_SIG2:
73659 + task = va_arg(ap, struct task_struct *);
73660 + cred = __task_cred(task);
73661 + pcred = __task_cred(task->real_parent);
73662 + num1 = va_arg(ap, int);
73663 + 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));
73664 + break;
73665 + case GR_CRASH1:
73666 + task = va_arg(ap, struct task_struct *);
73667 + cred = __task_cred(task);
73668 + pcred = __task_cred(task->real_parent);
73669 + ulong1 = va_arg(ap, unsigned long);
73670 + 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);
73671 + break;
73672 + case GR_CRASH2:
73673 + task = va_arg(ap, struct task_struct *);
73674 + cred = __task_cred(task);
73675 + pcred = __task_cred(task->real_parent);
73676 + ulong1 = va_arg(ap, unsigned long);
73677 + 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);
73678 + break;
73679 + case GR_RWXMAP:
73680 + file = va_arg(ap, struct file *);
73681 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
73682 + break;
73683 + case GR_RWXMAPVMA:
73684 + vma = va_arg(ap, struct vm_area_struct *);
73685 + if (vma->vm_file)
73686 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
73687 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
73688 + str1 = "<stack>";
73689 + else if (vma->vm_start <= current->mm->brk &&
73690 + vma->vm_end >= current->mm->start_brk)
73691 + str1 = "<heap>";
73692 + else
73693 + str1 = "<anonymous mapping>";
73694 + gr_log_middle_varargs(audit, msg, str1);
73695 + break;
73696 + case GR_PSACCT:
73697 + {
73698 + unsigned int wday, cday;
73699 + __u8 whr, chr;
73700 + __u8 wmin, cmin;
73701 + __u8 wsec, csec;
73702 + char cur_tty[64] = { 0 };
73703 + char parent_tty[64] = { 0 };
73704 +
73705 + task = va_arg(ap, struct task_struct *);
73706 + wday = va_arg(ap, unsigned int);
73707 + cday = va_arg(ap, unsigned int);
73708 + whr = va_arg(ap, int);
73709 + chr = va_arg(ap, int);
73710 + wmin = va_arg(ap, int);
73711 + cmin = va_arg(ap, int);
73712 + wsec = va_arg(ap, int);
73713 + csec = va_arg(ap, int);
73714 + ulong1 = va_arg(ap, unsigned long);
73715 + cred = __task_cred(task);
73716 + pcred = __task_cred(task->real_parent);
73717 +
73718 + 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));
73719 + }
73720 + break;
73721 + default:
73722 + gr_log_middle(audit, msg, ap);
73723 + }
73724 + va_end(ap);
73725 + // these don't need DEFAULTSECARGS printed on the end
73726 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
73727 + gr_log_end(audit, 0);
73728 + else
73729 + gr_log_end(audit, 1);
73730 + END_LOCKS(audit);
73731 +}
73732 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
73733 new file mode 100644
73734 index 0000000..f536303
73735 --- /dev/null
73736 +++ b/grsecurity/grsec_mem.c
73737 @@ -0,0 +1,40 @@
73738 +#include <linux/kernel.h>
73739 +#include <linux/sched.h>
73740 +#include <linux/mm.h>
73741 +#include <linux/mman.h>
73742 +#include <linux/grinternal.h>
73743 +
73744 +void
73745 +gr_handle_ioperm(void)
73746 +{
73747 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
73748 + return;
73749 +}
73750 +
73751 +void
73752 +gr_handle_iopl(void)
73753 +{
73754 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
73755 + return;
73756 +}
73757 +
73758 +void
73759 +gr_handle_mem_readwrite(u64 from, u64 to)
73760 +{
73761 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
73762 + return;
73763 +}
73764 +
73765 +void
73766 +gr_handle_vm86(void)
73767 +{
73768 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
73769 + return;
73770 +}
73771 +
73772 +void
73773 +gr_log_badprocpid(const char *entry)
73774 +{
73775 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
73776 + return;
73777 +}
73778 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
73779 new file mode 100644
73780 index 0000000..cd9e124
73781 --- /dev/null
73782 +++ b/grsecurity/grsec_mount.c
73783 @@ -0,0 +1,65 @@
73784 +#include <linux/kernel.h>
73785 +#include <linux/sched.h>
73786 +#include <linux/mount.h>
73787 +#include <linux/major.h>
73788 +#include <linux/grsecurity.h>
73789 +#include <linux/grinternal.h>
73790 +
73791 +void
73792 +gr_log_remount(const char *devname, const int retval)
73793 +{
73794 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73795 + if (grsec_enable_mount && (retval >= 0))
73796 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
73797 +#endif
73798 + return;
73799 +}
73800 +
73801 +void
73802 +gr_log_unmount(const char *devname, const int retval)
73803 +{
73804 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73805 + if (grsec_enable_mount && (retval >= 0))
73806 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
73807 +#endif
73808 + return;
73809 +}
73810 +
73811 +void
73812 +gr_log_mount(const char *from, const char *to, const int retval)
73813 +{
73814 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73815 + if (grsec_enable_mount && (retval >= 0))
73816 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
73817 +#endif
73818 + return;
73819 +}
73820 +
73821 +int
73822 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
73823 +{
73824 +#ifdef CONFIG_GRKERNSEC_ROFS
73825 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
73826 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
73827 + return -EPERM;
73828 + } else
73829 + return 0;
73830 +#endif
73831 + return 0;
73832 +}
73833 +
73834 +int
73835 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
73836 +{
73837 +#ifdef CONFIG_GRKERNSEC_ROFS
73838 + struct inode *inode = dentry->d_inode;
73839 +
73840 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
73841 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
73842 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
73843 + return -EPERM;
73844 + } else
73845 + return 0;
73846 +#endif
73847 + return 0;
73848 +}
73849 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
73850 new file mode 100644
73851 index 0000000..6ee9d50
73852 --- /dev/null
73853 +++ b/grsecurity/grsec_pax.c
73854 @@ -0,0 +1,45 @@
73855 +#include <linux/kernel.h>
73856 +#include <linux/sched.h>
73857 +#include <linux/mm.h>
73858 +#include <linux/file.h>
73859 +#include <linux/grinternal.h>
73860 +#include <linux/grsecurity.h>
73861 +
73862 +void
73863 +gr_log_textrel(struct vm_area_struct * vma)
73864 +{
73865 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73866 + if (grsec_enable_log_rwxmaps)
73867 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
73868 +#endif
73869 + return;
73870 +}
73871 +
73872 +void gr_log_ptgnustack(struct file *file)
73873 +{
73874 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73875 + if (grsec_enable_log_rwxmaps)
73876 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
73877 +#endif
73878 + return;
73879 +}
73880 +
73881 +void
73882 +gr_log_rwxmmap(struct file *file)
73883 +{
73884 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73885 + if (grsec_enable_log_rwxmaps)
73886 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
73887 +#endif
73888 + return;
73889 +}
73890 +
73891 +void
73892 +gr_log_rwxmprotect(struct vm_area_struct *vma)
73893 +{
73894 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73895 + if (grsec_enable_log_rwxmaps)
73896 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
73897 +#endif
73898 + return;
73899 +}
73900 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
73901 new file mode 100644
73902 index 0000000..f7f29aa
73903 --- /dev/null
73904 +++ b/grsecurity/grsec_ptrace.c
73905 @@ -0,0 +1,30 @@
73906 +#include <linux/kernel.h>
73907 +#include <linux/sched.h>
73908 +#include <linux/grinternal.h>
73909 +#include <linux/security.h>
73910 +
73911 +void
73912 +gr_audit_ptrace(struct task_struct *task)
73913 +{
73914 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73915 + if (grsec_enable_audit_ptrace)
73916 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
73917 +#endif
73918 + return;
73919 +}
73920 +
73921 +int
73922 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
73923 +{
73924 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73925 + const struct dentry *dentry = file->f_path.dentry;
73926 + const struct vfsmount *mnt = file->f_path.mnt;
73927 +
73928 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
73929 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
73930 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
73931 + return -EACCES;
73932 + }
73933 +#endif
73934 + return 0;
73935 +}
73936 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
73937 new file mode 100644
73938 index 0000000..3860c7e
73939 --- /dev/null
73940 +++ b/grsecurity/grsec_sig.c
73941 @@ -0,0 +1,236 @@
73942 +#include <linux/kernel.h>
73943 +#include <linux/sched.h>
73944 +#include <linux/fs.h>
73945 +#include <linux/delay.h>
73946 +#include <linux/grsecurity.h>
73947 +#include <linux/grinternal.h>
73948 +#include <linux/hardirq.h>
73949 +
73950 +char *signames[] = {
73951 + [SIGSEGV] = "Segmentation fault",
73952 + [SIGILL] = "Illegal instruction",
73953 + [SIGABRT] = "Abort",
73954 + [SIGBUS] = "Invalid alignment/Bus error"
73955 +};
73956 +
73957 +void
73958 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
73959 +{
73960 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73961 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
73962 + (sig == SIGABRT) || (sig == SIGBUS))) {
73963 + if (task_pid_nr(t) == task_pid_nr(current)) {
73964 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
73965 + } else {
73966 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
73967 + }
73968 + }
73969 +#endif
73970 + return;
73971 +}
73972 +
73973 +int
73974 +gr_handle_signal(const struct task_struct *p, const int sig)
73975 +{
73976 +#ifdef CONFIG_GRKERNSEC
73977 + /* ignore the 0 signal for protected task checks */
73978 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
73979 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
73980 + return -EPERM;
73981 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
73982 + return -EPERM;
73983 + }
73984 +#endif
73985 + return 0;
73986 +}
73987 +
73988 +#ifdef CONFIG_GRKERNSEC
73989 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
73990 +
73991 +int gr_fake_force_sig(int sig, struct task_struct *t)
73992 +{
73993 + unsigned long int flags;
73994 + int ret, blocked, ignored;
73995 + struct k_sigaction *action;
73996 +
73997 + spin_lock_irqsave(&t->sighand->siglock, flags);
73998 + action = &t->sighand->action[sig-1];
73999 + ignored = action->sa.sa_handler == SIG_IGN;
74000 + blocked = sigismember(&t->blocked, sig);
74001 + if (blocked || ignored) {
74002 + action->sa.sa_handler = SIG_DFL;
74003 + if (blocked) {
74004 + sigdelset(&t->blocked, sig);
74005 + recalc_sigpending_and_wake(t);
74006 + }
74007 + }
74008 + if (action->sa.sa_handler == SIG_DFL)
74009 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
74010 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74011 +
74012 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
74013 +
74014 + return ret;
74015 +}
74016 +#endif
74017 +
74018 +#define GR_USER_BAN_TIME (15 * 60)
74019 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
74020 +
74021 +void gr_handle_brute_attach(int dumpable)
74022 +{
74023 +#ifdef CONFIG_GRKERNSEC_BRUTE
74024 + struct task_struct *p = current;
74025 + kuid_t uid = GLOBAL_ROOT_UID;
74026 + int daemon = 0;
74027 +
74028 + if (!grsec_enable_brute)
74029 + return;
74030 +
74031 + rcu_read_lock();
74032 + read_lock(&tasklist_lock);
74033 + read_lock(&grsec_exec_file_lock);
74034 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74035 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74036 + p->real_parent->brute = 1;
74037 + daemon = 1;
74038 + } else {
74039 + const struct cred *cred = __task_cred(p), *cred2;
74040 + struct task_struct *tsk, *tsk2;
74041 +
74042 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
74043 + struct user_struct *user;
74044 +
74045 + uid = cred->uid;
74046 +
74047 + /* this is put upon execution past expiration */
74048 + user = find_user(uid);
74049 + if (user == NULL)
74050 + goto unlock;
74051 + user->suid_banned = 1;
74052 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
74053 + if (user->suid_ban_expires == ~0UL)
74054 + user->suid_ban_expires--;
74055 +
74056 + /* only kill other threads of the same binary, from the same user */
74057 + do_each_thread(tsk2, tsk) {
74058 + cred2 = __task_cred(tsk);
74059 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
74060 + gr_fake_force_sig(SIGKILL, tsk);
74061 + } while_each_thread(tsk2, tsk);
74062 + }
74063 + }
74064 +unlock:
74065 + read_unlock(&grsec_exec_file_lock);
74066 + read_unlock(&tasklist_lock);
74067 + rcu_read_unlock();
74068 +
74069 + if (gr_is_global_nonroot(uid))
74070 + 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);
74071 + else if (daemon)
74072 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
74073 +
74074 +#endif
74075 + return;
74076 +}
74077 +
74078 +void gr_handle_brute_check(void)
74079 +{
74080 +#ifdef CONFIG_GRKERNSEC_BRUTE
74081 + struct task_struct *p = current;
74082 +
74083 + if (unlikely(p->brute)) {
74084 + if (!grsec_enable_brute)
74085 + p->brute = 0;
74086 + else if (time_before(get_seconds(), p->brute_expires))
74087 + msleep(30 * 1000);
74088 + }
74089 +#endif
74090 + return;
74091 +}
74092 +
74093 +void gr_handle_kernel_exploit(void)
74094 +{
74095 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74096 + const struct cred *cred;
74097 + struct task_struct *tsk, *tsk2;
74098 + struct user_struct *user;
74099 + kuid_t uid;
74100 +
74101 + if (in_irq() || in_serving_softirq() || in_nmi())
74102 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
74103 +
74104 + uid = current_uid();
74105 +
74106 + if (gr_is_global_root(uid))
74107 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
74108 + else {
74109 + /* kill all the processes of this user, hold a reference
74110 + to their creds struct, and prevent them from creating
74111 + another process until system reset
74112 + */
74113 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
74114 + GR_GLOBAL_UID(uid));
74115 + /* we intentionally leak this ref */
74116 + user = get_uid(current->cred->user);
74117 + if (user)
74118 + user->kernel_banned = 1;
74119 +
74120 + /* kill all processes of this user */
74121 + read_lock(&tasklist_lock);
74122 + do_each_thread(tsk2, tsk) {
74123 + cred = __task_cred(tsk);
74124 + if (uid_eq(cred->uid, uid))
74125 + gr_fake_force_sig(SIGKILL, tsk);
74126 + } while_each_thread(tsk2, tsk);
74127 + read_unlock(&tasklist_lock);
74128 + }
74129 +#endif
74130 +}
74131 +
74132 +#ifdef CONFIG_GRKERNSEC_BRUTE
74133 +static bool suid_ban_expired(struct user_struct *user)
74134 +{
74135 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
74136 + user->suid_banned = 0;
74137 + user->suid_ban_expires = 0;
74138 + free_uid(user);
74139 + return true;
74140 + }
74141 +
74142 + return false;
74143 +}
74144 +#endif
74145 +
74146 +int gr_process_kernel_exec_ban(void)
74147 +{
74148 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74149 + if (unlikely(current->cred->user->kernel_banned))
74150 + return -EPERM;
74151 +#endif
74152 + return 0;
74153 +}
74154 +
74155 +int gr_process_kernel_setuid_ban(struct user_struct *user)
74156 +{
74157 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74158 + if (unlikely(user->kernel_banned))
74159 + gr_fake_force_sig(SIGKILL, current);
74160 +#endif
74161 + return 0;
74162 +}
74163 +
74164 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
74165 +{
74166 +#ifdef CONFIG_GRKERNSEC_BRUTE
74167 + struct user_struct *user = current->cred->user;
74168 + if (unlikely(user->suid_banned)) {
74169 + if (suid_ban_expired(user))
74170 + return 0;
74171 + /* disallow execution of suid binaries only */
74172 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
74173 + return -EPERM;
74174 + }
74175 +#endif
74176 + return 0;
74177 +}
74178 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
74179 new file mode 100644
74180 index 0000000..4030d57
74181 --- /dev/null
74182 +++ b/grsecurity/grsec_sock.c
74183 @@ -0,0 +1,244 @@
74184 +#include <linux/kernel.h>
74185 +#include <linux/module.h>
74186 +#include <linux/sched.h>
74187 +#include <linux/file.h>
74188 +#include <linux/net.h>
74189 +#include <linux/in.h>
74190 +#include <linux/ip.h>
74191 +#include <net/sock.h>
74192 +#include <net/inet_sock.h>
74193 +#include <linux/grsecurity.h>
74194 +#include <linux/grinternal.h>
74195 +#include <linux/gracl.h>
74196 +
74197 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
74198 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
74199 +
74200 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
74201 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
74202 +
74203 +#ifdef CONFIG_UNIX_MODULE
74204 +EXPORT_SYMBOL(gr_acl_handle_unix);
74205 +EXPORT_SYMBOL(gr_acl_handle_mknod);
74206 +EXPORT_SYMBOL(gr_handle_chroot_unix);
74207 +EXPORT_SYMBOL(gr_handle_create);
74208 +#endif
74209 +
74210 +#ifdef CONFIG_GRKERNSEC
74211 +#define gr_conn_table_size 32749
74212 +struct conn_table_entry {
74213 + struct conn_table_entry *next;
74214 + struct signal_struct *sig;
74215 +};
74216 +
74217 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
74218 +DEFINE_SPINLOCK(gr_conn_table_lock);
74219 +
74220 +extern const char * gr_socktype_to_name(unsigned char type);
74221 +extern const char * gr_proto_to_name(unsigned char proto);
74222 +extern const char * gr_sockfamily_to_name(unsigned char family);
74223 +
74224 +static __inline__ int
74225 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
74226 +{
74227 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
74228 +}
74229 +
74230 +static __inline__ int
74231 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
74232 + __u16 sport, __u16 dport)
74233 +{
74234 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
74235 + sig->gr_sport == sport && sig->gr_dport == dport))
74236 + return 1;
74237 + else
74238 + return 0;
74239 +}
74240 +
74241 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
74242 +{
74243 + struct conn_table_entry **match;
74244 + unsigned int index;
74245 +
74246 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74247 + sig->gr_sport, sig->gr_dport,
74248 + gr_conn_table_size);
74249 +
74250 + newent->sig = sig;
74251 +
74252 + match = &gr_conn_table[index];
74253 + newent->next = *match;
74254 + *match = newent;
74255 +
74256 + return;
74257 +}
74258 +
74259 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
74260 +{
74261 + struct conn_table_entry *match, *last = NULL;
74262 + unsigned int index;
74263 +
74264 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74265 + sig->gr_sport, sig->gr_dport,
74266 + gr_conn_table_size);
74267 +
74268 + match = gr_conn_table[index];
74269 + while (match && !conn_match(match->sig,
74270 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
74271 + sig->gr_dport)) {
74272 + last = match;
74273 + match = match->next;
74274 + }
74275 +
74276 + if (match) {
74277 + if (last)
74278 + last->next = match->next;
74279 + else
74280 + gr_conn_table[index] = NULL;
74281 + kfree(match);
74282 + }
74283 +
74284 + return;
74285 +}
74286 +
74287 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
74288 + __u16 sport, __u16 dport)
74289 +{
74290 + struct conn_table_entry *match;
74291 + unsigned int index;
74292 +
74293 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
74294 +
74295 + match = gr_conn_table[index];
74296 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
74297 + match = match->next;
74298 +
74299 + if (match)
74300 + return match->sig;
74301 + else
74302 + return NULL;
74303 +}
74304 +
74305 +#endif
74306 +
74307 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
74308 +{
74309 +#ifdef CONFIG_GRKERNSEC
74310 + struct signal_struct *sig = task->signal;
74311 + struct conn_table_entry *newent;
74312 +
74313 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
74314 + if (newent == NULL)
74315 + return;
74316 + /* no bh lock needed since we are called with bh disabled */
74317 + spin_lock(&gr_conn_table_lock);
74318 + gr_del_task_from_ip_table_nolock(sig);
74319 + sig->gr_saddr = inet->inet_rcv_saddr;
74320 + sig->gr_daddr = inet->inet_daddr;
74321 + sig->gr_sport = inet->inet_sport;
74322 + sig->gr_dport = inet->inet_dport;
74323 + gr_add_to_task_ip_table_nolock(sig, newent);
74324 + spin_unlock(&gr_conn_table_lock);
74325 +#endif
74326 + return;
74327 +}
74328 +
74329 +void gr_del_task_from_ip_table(struct task_struct *task)
74330 +{
74331 +#ifdef CONFIG_GRKERNSEC
74332 + spin_lock_bh(&gr_conn_table_lock);
74333 + gr_del_task_from_ip_table_nolock(task->signal);
74334 + spin_unlock_bh(&gr_conn_table_lock);
74335 +#endif
74336 + return;
74337 +}
74338 +
74339 +void
74340 +gr_attach_curr_ip(const struct sock *sk)
74341 +{
74342 +#ifdef CONFIG_GRKERNSEC
74343 + struct signal_struct *p, *set;
74344 + const struct inet_sock *inet = inet_sk(sk);
74345 +
74346 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
74347 + return;
74348 +
74349 + set = current->signal;
74350 +
74351 + spin_lock_bh(&gr_conn_table_lock);
74352 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
74353 + inet->inet_dport, inet->inet_sport);
74354 + if (unlikely(p != NULL)) {
74355 + set->curr_ip = p->curr_ip;
74356 + set->used_accept = 1;
74357 + gr_del_task_from_ip_table_nolock(p);
74358 + spin_unlock_bh(&gr_conn_table_lock);
74359 + return;
74360 + }
74361 + spin_unlock_bh(&gr_conn_table_lock);
74362 +
74363 + set->curr_ip = inet->inet_daddr;
74364 + set->used_accept = 1;
74365 +#endif
74366 + return;
74367 +}
74368 +
74369 +int
74370 +gr_handle_sock_all(const int family, const int type, const int protocol)
74371 +{
74372 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74373 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
74374 + (family != AF_UNIX)) {
74375 + if (family == AF_INET)
74376 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
74377 + else
74378 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
74379 + return -EACCES;
74380 + }
74381 +#endif
74382 + return 0;
74383 +}
74384 +
74385 +int
74386 +gr_handle_sock_server(const struct sockaddr *sck)
74387 +{
74388 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74389 + if (grsec_enable_socket_server &&
74390 + in_group_p(grsec_socket_server_gid) &&
74391 + sck && (sck->sa_family != AF_UNIX) &&
74392 + (sck->sa_family != AF_LOCAL)) {
74393 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74394 + return -EACCES;
74395 + }
74396 +#endif
74397 + return 0;
74398 +}
74399 +
74400 +int
74401 +gr_handle_sock_server_other(const struct sock *sck)
74402 +{
74403 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74404 + if (grsec_enable_socket_server &&
74405 + in_group_p(grsec_socket_server_gid) &&
74406 + sck && (sck->sk_family != AF_UNIX) &&
74407 + (sck->sk_family != AF_LOCAL)) {
74408 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74409 + return -EACCES;
74410 + }
74411 +#endif
74412 + return 0;
74413 +}
74414 +
74415 +int
74416 +gr_handle_sock_client(const struct sockaddr *sck)
74417 +{
74418 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74419 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
74420 + sck && (sck->sa_family != AF_UNIX) &&
74421 + (sck->sa_family != AF_LOCAL)) {
74422 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
74423 + return -EACCES;
74424 + }
74425 +#endif
74426 + return 0;
74427 +}
74428 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
74429 new file mode 100644
74430 index 0000000..8159888
74431 --- /dev/null
74432 +++ b/grsecurity/grsec_sysctl.c
74433 @@ -0,0 +1,479 @@
74434 +#include <linux/kernel.h>
74435 +#include <linux/sched.h>
74436 +#include <linux/sysctl.h>
74437 +#include <linux/grsecurity.h>
74438 +#include <linux/grinternal.h>
74439 +
74440 +int
74441 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
74442 +{
74443 +#ifdef CONFIG_GRKERNSEC_SYSCTL
74444 + if (dirname == NULL || name == NULL)
74445 + return 0;
74446 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
74447 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
74448 + return -EACCES;
74449 + }
74450 +#endif
74451 + return 0;
74452 +}
74453 +
74454 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
74455 +static int __maybe_unused __read_only one = 1;
74456 +#endif
74457 +
74458 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
74459 + defined(CONFIG_GRKERNSEC_DENYUSB)
74460 +struct ctl_table grsecurity_table[] = {
74461 +#ifdef CONFIG_GRKERNSEC_SYSCTL
74462 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
74463 +#ifdef CONFIG_GRKERNSEC_IO
74464 + {
74465 + .procname = "disable_priv_io",
74466 + .data = &grsec_disable_privio,
74467 + .maxlen = sizeof(int),
74468 + .mode = 0600,
74469 + .proc_handler = &proc_dointvec,
74470 + },
74471 +#endif
74472 +#endif
74473 +#ifdef CONFIG_GRKERNSEC_LINK
74474 + {
74475 + .procname = "linking_restrictions",
74476 + .data = &grsec_enable_link,
74477 + .maxlen = sizeof(int),
74478 + .mode = 0600,
74479 + .proc_handler = &proc_dointvec,
74480 + },
74481 +#endif
74482 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74483 + {
74484 + .procname = "enforce_symlinksifowner",
74485 + .data = &grsec_enable_symlinkown,
74486 + .maxlen = sizeof(int),
74487 + .mode = 0600,
74488 + .proc_handler = &proc_dointvec,
74489 + },
74490 + {
74491 + .procname = "symlinkown_gid",
74492 + .data = &grsec_symlinkown_gid,
74493 + .maxlen = sizeof(int),
74494 + .mode = 0600,
74495 + .proc_handler = &proc_dointvec,
74496 + },
74497 +#endif
74498 +#ifdef CONFIG_GRKERNSEC_BRUTE
74499 + {
74500 + .procname = "deter_bruteforce",
74501 + .data = &grsec_enable_brute,
74502 + .maxlen = sizeof(int),
74503 + .mode = 0600,
74504 + .proc_handler = &proc_dointvec,
74505 + },
74506 +#endif
74507 +#ifdef CONFIG_GRKERNSEC_FIFO
74508 + {
74509 + .procname = "fifo_restrictions",
74510 + .data = &grsec_enable_fifo,
74511 + .maxlen = sizeof(int),
74512 + .mode = 0600,
74513 + .proc_handler = &proc_dointvec,
74514 + },
74515 +#endif
74516 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74517 + {
74518 + .procname = "ptrace_readexec",
74519 + .data = &grsec_enable_ptrace_readexec,
74520 + .maxlen = sizeof(int),
74521 + .mode = 0600,
74522 + .proc_handler = &proc_dointvec,
74523 + },
74524 +#endif
74525 +#ifdef CONFIG_GRKERNSEC_SETXID
74526 + {
74527 + .procname = "consistent_setxid",
74528 + .data = &grsec_enable_setxid,
74529 + .maxlen = sizeof(int),
74530 + .mode = 0600,
74531 + .proc_handler = &proc_dointvec,
74532 + },
74533 +#endif
74534 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74535 + {
74536 + .procname = "ip_blackhole",
74537 + .data = &grsec_enable_blackhole,
74538 + .maxlen = sizeof(int),
74539 + .mode = 0600,
74540 + .proc_handler = &proc_dointvec,
74541 + },
74542 + {
74543 + .procname = "lastack_retries",
74544 + .data = &grsec_lastack_retries,
74545 + .maxlen = sizeof(int),
74546 + .mode = 0600,
74547 + .proc_handler = &proc_dointvec,
74548 + },
74549 +#endif
74550 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74551 + {
74552 + .procname = "exec_logging",
74553 + .data = &grsec_enable_execlog,
74554 + .maxlen = sizeof(int),
74555 + .mode = 0600,
74556 + .proc_handler = &proc_dointvec,
74557 + },
74558 +#endif
74559 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74560 + {
74561 + .procname = "rwxmap_logging",
74562 + .data = &grsec_enable_log_rwxmaps,
74563 + .maxlen = sizeof(int),
74564 + .mode = 0600,
74565 + .proc_handler = &proc_dointvec,
74566 + },
74567 +#endif
74568 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74569 + {
74570 + .procname = "signal_logging",
74571 + .data = &grsec_enable_signal,
74572 + .maxlen = sizeof(int),
74573 + .mode = 0600,
74574 + .proc_handler = &proc_dointvec,
74575 + },
74576 +#endif
74577 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74578 + {
74579 + .procname = "forkfail_logging",
74580 + .data = &grsec_enable_forkfail,
74581 + .maxlen = sizeof(int),
74582 + .mode = 0600,
74583 + .proc_handler = &proc_dointvec,
74584 + },
74585 +#endif
74586 +#ifdef CONFIG_GRKERNSEC_TIME
74587 + {
74588 + .procname = "timechange_logging",
74589 + .data = &grsec_enable_time,
74590 + .maxlen = sizeof(int),
74591 + .mode = 0600,
74592 + .proc_handler = &proc_dointvec,
74593 + },
74594 +#endif
74595 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74596 + {
74597 + .procname = "chroot_deny_shmat",
74598 + .data = &grsec_enable_chroot_shmat,
74599 + .maxlen = sizeof(int),
74600 + .mode = 0600,
74601 + .proc_handler = &proc_dointvec,
74602 + },
74603 +#endif
74604 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74605 + {
74606 + .procname = "chroot_deny_unix",
74607 + .data = &grsec_enable_chroot_unix,
74608 + .maxlen = sizeof(int),
74609 + .mode = 0600,
74610 + .proc_handler = &proc_dointvec,
74611 + },
74612 +#endif
74613 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74614 + {
74615 + .procname = "chroot_deny_mount",
74616 + .data = &grsec_enable_chroot_mount,
74617 + .maxlen = sizeof(int),
74618 + .mode = 0600,
74619 + .proc_handler = &proc_dointvec,
74620 + },
74621 +#endif
74622 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74623 + {
74624 + .procname = "chroot_deny_fchdir",
74625 + .data = &grsec_enable_chroot_fchdir,
74626 + .maxlen = sizeof(int),
74627 + .mode = 0600,
74628 + .proc_handler = &proc_dointvec,
74629 + },
74630 +#endif
74631 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74632 + {
74633 + .procname = "chroot_deny_chroot",
74634 + .data = &grsec_enable_chroot_double,
74635 + .maxlen = sizeof(int),
74636 + .mode = 0600,
74637 + .proc_handler = &proc_dointvec,
74638 + },
74639 +#endif
74640 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74641 + {
74642 + .procname = "chroot_deny_pivot",
74643 + .data = &grsec_enable_chroot_pivot,
74644 + .maxlen = sizeof(int),
74645 + .mode = 0600,
74646 + .proc_handler = &proc_dointvec,
74647 + },
74648 +#endif
74649 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74650 + {
74651 + .procname = "chroot_enforce_chdir",
74652 + .data = &grsec_enable_chroot_chdir,
74653 + .maxlen = sizeof(int),
74654 + .mode = 0600,
74655 + .proc_handler = &proc_dointvec,
74656 + },
74657 +#endif
74658 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74659 + {
74660 + .procname = "chroot_deny_chmod",
74661 + .data = &grsec_enable_chroot_chmod,
74662 + .maxlen = sizeof(int),
74663 + .mode = 0600,
74664 + .proc_handler = &proc_dointvec,
74665 + },
74666 +#endif
74667 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74668 + {
74669 + .procname = "chroot_deny_mknod",
74670 + .data = &grsec_enable_chroot_mknod,
74671 + .maxlen = sizeof(int),
74672 + .mode = 0600,
74673 + .proc_handler = &proc_dointvec,
74674 + },
74675 +#endif
74676 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74677 + {
74678 + .procname = "chroot_restrict_nice",
74679 + .data = &grsec_enable_chroot_nice,
74680 + .maxlen = sizeof(int),
74681 + .mode = 0600,
74682 + .proc_handler = &proc_dointvec,
74683 + },
74684 +#endif
74685 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74686 + {
74687 + .procname = "chroot_execlog",
74688 + .data = &grsec_enable_chroot_execlog,
74689 + .maxlen = sizeof(int),
74690 + .mode = 0600,
74691 + .proc_handler = &proc_dointvec,
74692 + },
74693 +#endif
74694 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74695 + {
74696 + .procname = "chroot_caps",
74697 + .data = &grsec_enable_chroot_caps,
74698 + .maxlen = sizeof(int),
74699 + .mode = 0600,
74700 + .proc_handler = &proc_dointvec,
74701 + },
74702 +#endif
74703 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74704 + {
74705 + .procname = "chroot_deny_sysctl",
74706 + .data = &grsec_enable_chroot_sysctl,
74707 + .maxlen = sizeof(int),
74708 + .mode = 0600,
74709 + .proc_handler = &proc_dointvec,
74710 + },
74711 +#endif
74712 +#ifdef CONFIG_GRKERNSEC_TPE
74713 + {
74714 + .procname = "tpe",
74715 + .data = &grsec_enable_tpe,
74716 + .maxlen = sizeof(int),
74717 + .mode = 0600,
74718 + .proc_handler = &proc_dointvec,
74719 + },
74720 + {
74721 + .procname = "tpe_gid",
74722 + .data = &grsec_tpe_gid,
74723 + .maxlen = sizeof(int),
74724 + .mode = 0600,
74725 + .proc_handler = &proc_dointvec,
74726 + },
74727 +#endif
74728 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74729 + {
74730 + .procname = "tpe_invert",
74731 + .data = &grsec_enable_tpe_invert,
74732 + .maxlen = sizeof(int),
74733 + .mode = 0600,
74734 + .proc_handler = &proc_dointvec,
74735 + },
74736 +#endif
74737 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74738 + {
74739 + .procname = "tpe_restrict_all",
74740 + .data = &grsec_enable_tpe_all,
74741 + .maxlen = sizeof(int),
74742 + .mode = 0600,
74743 + .proc_handler = &proc_dointvec,
74744 + },
74745 +#endif
74746 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74747 + {
74748 + .procname = "socket_all",
74749 + .data = &grsec_enable_socket_all,
74750 + .maxlen = sizeof(int),
74751 + .mode = 0600,
74752 + .proc_handler = &proc_dointvec,
74753 + },
74754 + {
74755 + .procname = "socket_all_gid",
74756 + .data = &grsec_socket_all_gid,
74757 + .maxlen = sizeof(int),
74758 + .mode = 0600,
74759 + .proc_handler = &proc_dointvec,
74760 + },
74761 +#endif
74762 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74763 + {
74764 + .procname = "socket_client",
74765 + .data = &grsec_enable_socket_client,
74766 + .maxlen = sizeof(int),
74767 + .mode = 0600,
74768 + .proc_handler = &proc_dointvec,
74769 + },
74770 + {
74771 + .procname = "socket_client_gid",
74772 + .data = &grsec_socket_client_gid,
74773 + .maxlen = sizeof(int),
74774 + .mode = 0600,
74775 + .proc_handler = &proc_dointvec,
74776 + },
74777 +#endif
74778 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74779 + {
74780 + .procname = "socket_server",
74781 + .data = &grsec_enable_socket_server,
74782 + .maxlen = sizeof(int),
74783 + .mode = 0600,
74784 + .proc_handler = &proc_dointvec,
74785 + },
74786 + {
74787 + .procname = "socket_server_gid",
74788 + .data = &grsec_socket_server_gid,
74789 + .maxlen = sizeof(int),
74790 + .mode = 0600,
74791 + .proc_handler = &proc_dointvec,
74792 + },
74793 +#endif
74794 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74795 + {
74796 + .procname = "audit_group",
74797 + .data = &grsec_enable_group,
74798 + .maxlen = sizeof(int),
74799 + .mode = 0600,
74800 + .proc_handler = &proc_dointvec,
74801 + },
74802 + {
74803 + .procname = "audit_gid",
74804 + .data = &grsec_audit_gid,
74805 + .maxlen = sizeof(int),
74806 + .mode = 0600,
74807 + .proc_handler = &proc_dointvec,
74808 + },
74809 +#endif
74810 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74811 + {
74812 + .procname = "audit_chdir",
74813 + .data = &grsec_enable_chdir,
74814 + .maxlen = sizeof(int),
74815 + .mode = 0600,
74816 + .proc_handler = &proc_dointvec,
74817 + },
74818 +#endif
74819 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74820 + {
74821 + .procname = "audit_mount",
74822 + .data = &grsec_enable_mount,
74823 + .maxlen = sizeof(int),
74824 + .mode = 0600,
74825 + .proc_handler = &proc_dointvec,
74826 + },
74827 +#endif
74828 +#ifdef CONFIG_GRKERNSEC_DMESG
74829 + {
74830 + .procname = "dmesg",
74831 + .data = &grsec_enable_dmesg,
74832 + .maxlen = sizeof(int),
74833 + .mode = 0600,
74834 + .proc_handler = &proc_dointvec,
74835 + },
74836 +#endif
74837 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74838 + {
74839 + .procname = "chroot_findtask",
74840 + .data = &grsec_enable_chroot_findtask,
74841 + .maxlen = sizeof(int),
74842 + .mode = 0600,
74843 + .proc_handler = &proc_dointvec,
74844 + },
74845 +#endif
74846 +#ifdef CONFIG_GRKERNSEC_RESLOG
74847 + {
74848 + .procname = "resource_logging",
74849 + .data = &grsec_resource_logging,
74850 + .maxlen = sizeof(int),
74851 + .mode = 0600,
74852 + .proc_handler = &proc_dointvec,
74853 + },
74854 +#endif
74855 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74856 + {
74857 + .procname = "audit_ptrace",
74858 + .data = &grsec_enable_audit_ptrace,
74859 + .maxlen = sizeof(int),
74860 + .mode = 0600,
74861 + .proc_handler = &proc_dointvec,
74862 + },
74863 +#endif
74864 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74865 + {
74866 + .procname = "harden_ptrace",
74867 + .data = &grsec_enable_harden_ptrace,
74868 + .maxlen = sizeof(int),
74869 + .mode = 0600,
74870 + .proc_handler = &proc_dointvec,
74871 + },
74872 +#endif
74873 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74874 + {
74875 + .procname = "harden_ipc",
74876 + .data = &grsec_enable_harden_ipc,
74877 + .maxlen = sizeof(int),
74878 + .mode = 0600,
74879 + .proc_handler = &proc_dointvec,
74880 + },
74881 +#endif
74882 + {
74883 + .procname = "grsec_lock",
74884 + .data = &grsec_lock,
74885 + .maxlen = sizeof(int),
74886 + .mode = 0600,
74887 + .proc_handler = &proc_dointvec,
74888 + },
74889 +#endif
74890 +#ifdef CONFIG_GRKERNSEC_ROFS
74891 + {
74892 + .procname = "romount_protect",
74893 + .data = &grsec_enable_rofs,
74894 + .maxlen = sizeof(int),
74895 + .mode = 0600,
74896 + .proc_handler = &proc_dointvec_minmax,
74897 + .extra1 = &one,
74898 + .extra2 = &one,
74899 + },
74900 +#endif
74901 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
74902 + {
74903 + .procname = "deny_new_usb",
74904 + .data = &grsec_deny_new_usb,
74905 + .maxlen = sizeof(int),
74906 + .mode = 0600,
74907 + .proc_handler = &proc_dointvec,
74908 + },
74909 +#endif
74910 + { }
74911 +};
74912 +#endif
74913 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
74914 new file mode 100644
74915 index 0000000..0dc13c3
74916 --- /dev/null
74917 +++ b/grsecurity/grsec_time.c
74918 @@ -0,0 +1,16 @@
74919 +#include <linux/kernel.h>
74920 +#include <linux/sched.h>
74921 +#include <linux/grinternal.h>
74922 +#include <linux/module.h>
74923 +
74924 +void
74925 +gr_log_timechange(void)
74926 +{
74927 +#ifdef CONFIG_GRKERNSEC_TIME
74928 + if (grsec_enable_time)
74929 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
74930 +#endif
74931 + return;
74932 +}
74933 +
74934 +EXPORT_SYMBOL(gr_log_timechange);
74935 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
74936 new file mode 100644
74937 index 0000000..ee57dcf
74938 --- /dev/null
74939 +++ b/grsecurity/grsec_tpe.c
74940 @@ -0,0 +1,73 @@
74941 +#include <linux/kernel.h>
74942 +#include <linux/sched.h>
74943 +#include <linux/file.h>
74944 +#include <linux/fs.h>
74945 +#include <linux/grinternal.h>
74946 +
74947 +extern int gr_acl_tpe_check(void);
74948 +
74949 +int
74950 +gr_tpe_allow(const struct file *file)
74951 +{
74952 +#ifdef CONFIG_GRKERNSEC
74953 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
74954 + const struct cred *cred = current_cred();
74955 + char *msg = NULL;
74956 + char *msg2 = NULL;
74957 +
74958 + // never restrict root
74959 + if (gr_is_global_root(cred->uid))
74960 + return 1;
74961 +
74962 + if (grsec_enable_tpe) {
74963 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74964 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
74965 + msg = "not being in trusted group";
74966 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
74967 + msg = "being in untrusted group";
74968 +#else
74969 + if (in_group_p(grsec_tpe_gid))
74970 + msg = "being in untrusted group";
74971 +#endif
74972 + }
74973 + if (!msg && gr_acl_tpe_check())
74974 + msg = "being in untrusted role";
74975 +
74976 + // not in any affected group/role
74977 + if (!msg)
74978 + goto next_check;
74979 +
74980 + if (gr_is_global_nonroot(inode->i_uid))
74981 + msg2 = "file in non-root-owned directory";
74982 + else if (inode->i_mode & S_IWOTH)
74983 + msg2 = "file in world-writable directory";
74984 + else if (inode->i_mode & S_IWGRP)
74985 + msg2 = "file in group-writable directory";
74986 +
74987 + if (msg && msg2) {
74988 + char fullmsg[70] = {0};
74989 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
74990 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
74991 + return 0;
74992 + }
74993 + msg = NULL;
74994 +next_check:
74995 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74996 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
74997 + return 1;
74998 +
74999 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75000 + msg = "directory not owned by user";
75001 + else if (inode->i_mode & S_IWOTH)
75002 + msg = "file in world-writable directory";
75003 + else if (inode->i_mode & S_IWGRP)
75004 + msg = "file in group-writable directory";
75005 +
75006 + if (msg) {
75007 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75008 + return 0;
75009 + }
75010 +#endif
75011 +#endif
75012 + return 1;
75013 +}
75014 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75015 new file mode 100644
75016 index 0000000..ae02d8e
75017 --- /dev/null
75018 +++ b/grsecurity/grsec_usb.c
75019 @@ -0,0 +1,15 @@
75020 +#include <linux/kernel.h>
75021 +#include <linux/grinternal.h>
75022 +#include <linux/module.h>
75023 +
75024 +int gr_handle_new_usb(void)
75025 +{
75026 +#ifdef CONFIG_GRKERNSEC_DENYUSB
75027 + if (grsec_deny_new_usb) {
75028 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75029 + return 1;
75030 + }
75031 +#endif
75032 + return 0;
75033 +}
75034 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75035 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75036 new file mode 100644
75037 index 0000000..9f7b1ac
75038 --- /dev/null
75039 +++ b/grsecurity/grsum.c
75040 @@ -0,0 +1,61 @@
75041 +#include <linux/err.h>
75042 +#include <linux/kernel.h>
75043 +#include <linux/sched.h>
75044 +#include <linux/mm.h>
75045 +#include <linux/scatterlist.h>
75046 +#include <linux/crypto.h>
75047 +#include <linux/gracl.h>
75048 +
75049 +
75050 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
75051 +#error "crypto and sha256 must be built into the kernel"
75052 +#endif
75053 +
75054 +int
75055 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
75056 +{
75057 + char *p;
75058 + struct crypto_hash *tfm;
75059 + struct hash_desc desc;
75060 + struct scatterlist sg;
75061 + unsigned char temp_sum[GR_SHA_LEN];
75062 + volatile int retval = 0;
75063 + volatile int dummy = 0;
75064 + unsigned int i;
75065 +
75066 + sg_init_table(&sg, 1);
75067 +
75068 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
75069 + if (IS_ERR(tfm)) {
75070 + /* should never happen, since sha256 should be built in */
75071 + return 1;
75072 + }
75073 +
75074 + desc.tfm = tfm;
75075 + desc.flags = 0;
75076 +
75077 + crypto_hash_init(&desc);
75078 +
75079 + p = salt;
75080 + sg_set_buf(&sg, p, GR_SALT_LEN);
75081 + crypto_hash_update(&desc, &sg, sg.length);
75082 +
75083 + p = entry->pw;
75084 + sg_set_buf(&sg, p, strlen(p));
75085 +
75086 + crypto_hash_update(&desc, &sg, sg.length);
75087 +
75088 + crypto_hash_final(&desc, temp_sum);
75089 +
75090 + memset(entry->pw, 0, GR_PW_LEN);
75091 +
75092 + for (i = 0; i < GR_SHA_LEN; i++)
75093 + if (sum[i] != temp_sum[i])
75094 + retval = 1;
75095 + else
75096 + dummy = 1; // waste a cycle
75097 +
75098 + crypto_free_hash(tfm);
75099 +
75100 + return retval;
75101 +}
75102 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
75103 index 77ff547..181834f 100644
75104 --- a/include/asm-generic/4level-fixup.h
75105 +++ b/include/asm-generic/4level-fixup.h
75106 @@ -13,8 +13,10 @@
75107 #define pmd_alloc(mm, pud, address) \
75108 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
75109 NULL: pmd_offset(pud, address))
75110 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
75111
75112 #define pud_alloc(mm, pgd, address) (pgd)
75113 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
75114 #define pud_offset(pgd, start) (pgd)
75115 #define pud_none(pud) 0
75116 #define pud_bad(pud) 0
75117 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
75118 index b7babf0..97f4c4f 100644
75119 --- a/include/asm-generic/atomic-long.h
75120 +++ b/include/asm-generic/atomic-long.h
75121 @@ -22,6 +22,12 @@
75122
75123 typedef atomic64_t atomic_long_t;
75124
75125 +#ifdef CONFIG_PAX_REFCOUNT
75126 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
75127 +#else
75128 +typedef atomic64_t atomic_long_unchecked_t;
75129 +#endif
75130 +
75131 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
75132
75133 static inline long atomic_long_read(atomic_long_t *l)
75134 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75135 return (long)atomic64_read(v);
75136 }
75137
75138 +#ifdef CONFIG_PAX_REFCOUNT
75139 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75140 +{
75141 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75142 +
75143 + return (long)atomic64_read_unchecked(v);
75144 +}
75145 +#endif
75146 +
75147 static inline void atomic_long_set(atomic_long_t *l, long i)
75148 {
75149 atomic64_t *v = (atomic64_t *)l;
75150 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75151 atomic64_set(v, i);
75152 }
75153
75154 +#ifdef CONFIG_PAX_REFCOUNT
75155 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75156 +{
75157 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75158 +
75159 + atomic64_set_unchecked(v, i);
75160 +}
75161 +#endif
75162 +
75163 static inline void atomic_long_inc(atomic_long_t *l)
75164 {
75165 atomic64_t *v = (atomic64_t *)l;
75166 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75167 atomic64_inc(v);
75168 }
75169
75170 +#ifdef CONFIG_PAX_REFCOUNT
75171 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75172 +{
75173 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75174 +
75175 + atomic64_inc_unchecked(v);
75176 +}
75177 +#endif
75178 +
75179 static inline void atomic_long_dec(atomic_long_t *l)
75180 {
75181 atomic64_t *v = (atomic64_t *)l;
75182 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75183 atomic64_dec(v);
75184 }
75185
75186 +#ifdef CONFIG_PAX_REFCOUNT
75187 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75188 +{
75189 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75190 +
75191 + atomic64_dec_unchecked(v);
75192 +}
75193 +#endif
75194 +
75195 static inline void atomic_long_add(long i, atomic_long_t *l)
75196 {
75197 atomic64_t *v = (atomic64_t *)l;
75198 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75199 atomic64_add(i, v);
75200 }
75201
75202 +#ifdef CONFIG_PAX_REFCOUNT
75203 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75204 +{
75205 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75206 +
75207 + atomic64_add_unchecked(i, v);
75208 +}
75209 +#endif
75210 +
75211 static inline void atomic_long_sub(long i, atomic_long_t *l)
75212 {
75213 atomic64_t *v = (atomic64_t *)l;
75214 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75215 atomic64_sub(i, v);
75216 }
75217
75218 +#ifdef CONFIG_PAX_REFCOUNT
75219 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75220 +{
75221 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75222 +
75223 + atomic64_sub_unchecked(i, v);
75224 +}
75225 +#endif
75226 +
75227 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75228 {
75229 atomic64_t *v = (atomic64_t *)l;
75230 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
75231 return atomic64_add_negative(i, v);
75232 }
75233
75234 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
75235 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
75236 {
75237 atomic64_t *v = (atomic64_t *)l;
75238
75239 return (long)atomic64_add_return(i, v);
75240 }
75241
75242 +#ifdef CONFIG_PAX_REFCOUNT
75243 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75244 +{
75245 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75246 +
75247 + return (long)atomic64_add_return_unchecked(i, v);
75248 +}
75249 +#endif
75250 +
75251 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75252 {
75253 atomic64_t *v = (atomic64_t *)l;
75254 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75255 return (long)atomic64_inc_return(v);
75256 }
75257
75258 +#ifdef CONFIG_PAX_REFCOUNT
75259 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75260 +{
75261 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75262 +
75263 + return (long)atomic64_inc_return_unchecked(v);
75264 +}
75265 +#endif
75266 +
75267 static inline long atomic_long_dec_return(atomic_long_t *l)
75268 {
75269 atomic64_t *v = (atomic64_t *)l;
75270 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75271
75272 typedef atomic_t atomic_long_t;
75273
75274 +#ifdef CONFIG_PAX_REFCOUNT
75275 +typedef atomic_unchecked_t atomic_long_unchecked_t;
75276 +#else
75277 +typedef atomic_t atomic_long_unchecked_t;
75278 +#endif
75279 +
75280 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
75281 static inline long atomic_long_read(atomic_long_t *l)
75282 {
75283 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75284 return (long)atomic_read(v);
75285 }
75286
75287 +#ifdef CONFIG_PAX_REFCOUNT
75288 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75289 +{
75290 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75291 +
75292 + return (long)atomic_read_unchecked(v);
75293 +}
75294 +#endif
75295 +
75296 static inline void atomic_long_set(atomic_long_t *l, long i)
75297 {
75298 atomic_t *v = (atomic_t *)l;
75299 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75300 atomic_set(v, i);
75301 }
75302
75303 +#ifdef CONFIG_PAX_REFCOUNT
75304 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75305 +{
75306 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75307 +
75308 + atomic_set_unchecked(v, i);
75309 +}
75310 +#endif
75311 +
75312 static inline void atomic_long_inc(atomic_long_t *l)
75313 {
75314 atomic_t *v = (atomic_t *)l;
75315 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75316 atomic_inc(v);
75317 }
75318
75319 +#ifdef CONFIG_PAX_REFCOUNT
75320 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75321 +{
75322 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75323 +
75324 + atomic_inc_unchecked(v);
75325 +}
75326 +#endif
75327 +
75328 static inline void atomic_long_dec(atomic_long_t *l)
75329 {
75330 atomic_t *v = (atomic_t *)l;
75331 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75332 atomic_dec(v);
75333 }
75334
75335 +#ifdef CONFIG_PAX_REFCOUNT
75336 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75337 +{
75338 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75339 +
75340 + atomic_dec_unchecked(v);
75341 +}
75342 +#endif
75343 +
75344 static inline void atomic_long_add(long i, atomic_long_t *l)
75345 {
75346 atomic_t *v = (atomic_t *)l;
75347 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75348 atomic_add(i, v);
75349 }
75350
75351 +#ifdef CONFIG_PAX_REFCOUNT
75352 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75353 +{
75354 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75355 +
75356 + atomic_add_unchecked(i, v);
75357 +}
75358 +#endif
75359 +
75360 static inline void atomic_long_sub(long i, atomic_long_t *l)
75361 {
75362 atomic_t *v = (atomic_t *)l;
75363 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75364 atomic_sub(i, v);
75365 }
75366
75367 +#ifdef CONFIG_PAX_REFCOUNT
75368 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75369 +{
75370 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75371 +
75372 + atomic_sub_unchecked(i, v);
75373 +}
75374 +#endif
75375 +
75376 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75377 {
75378 atomic_t *v = (atomic_t *)l;
75379 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
75380 return (long)atomic_add_return(i, v);
75381 }
75382
75383 +#ifdef CONFIG_PAX_REFCOUNT
75384 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75385 +{
75386 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75387 +
75388 + return (long)atomic_add_return_unchecked(i, v);
75389 +}
75390 +
75391 +#endif
75392 +
75393 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75394 {
75395 atomic_t *v = (atomic_t *)l;
75396 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75397 return (long)atomic_inc_return(v);
75398 }
75399
75400 +#ifdef CONFIG_PAX_REFCOUNT
75401 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75402 +{
75403 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75404 +
75405 + return (long)atomic_inc_return_unchecked(v);
75406 +}
75407 +#endif
75408 +
75409 static inline long atomic_long_dec_return(atomic_long_t *l)
75410 {
75411 atomic_t *v = (atomic_t *)l;
75412 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75413
75414 #endif /* BITS_PER_LONG == 64 */
75415
75416 +#ifdef CONFIG_PAX_REFCOUNT
75417 +static inline void pax_refcount_needs_these_functions(void)
75418 +{
75419 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
75420 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
75421 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
75422 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
75423 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
75424 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
75425 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
75426 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
75427 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
75428 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
75429 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
75430 +#ifdef CONFIG_X86
75431 + atomic_clear_mask_unchecked(0, NULL);
75432 + atomic_set_mask_unchecked(0, NULL);
75433 +#endif
75434 +
75435 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
75436 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
75437 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
75438 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
75439 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
75440 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
75441 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
75442 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
75443 +}
75444 +#else
75445 +#define atomic_read_unchecked(v) atomic_read(v)
75446 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
75447 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
75448 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
75449 +#define atomic_inc_unchecked(v) atomic_inc(v)
75450 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
75451 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
75452 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
75453 +#define atomic_dec_unchecked(v) atomic_dec(v)
75454 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
75455 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
75456 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
75457 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
75458 +
75459 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
75460 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
75461 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
75462 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
75463 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
75464 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
75465 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
75466 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
75467 +#endif
75468 +
75469 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
75470 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
75471 index 33bd2de..f31bff97 100644
75472 --- a/include/asm-generic/atomic.h
75473 +++ b/include/asm-generic/atomic.h
75474 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
75475 * Atomically clears the bits set in @mask from @v
75476 */
75477 #ifndef atomic_clear_mask
75478 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
75479 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
75480 {
75481 unsigned long flags;
75482
75483 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
75484 index b18ce4f..2ee2843 100644
75485 --- a/include/asm-generic/atomic64.h
75486 +++ b/include/asm-generic/atomic64.h
75487 @@ -16,6 +16,8 @@ typedef struct {
75488 long long counter;
75489 } atomic64_t;
75490
75491 +typedef atomic64_t atomic64_unchecked_t;
75492 +
75493 #define ATOMIC64_INIT(i) { (i) }
75494
75495 extern long long atomic64_read(const atomic64_t *v);
75496 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
75497 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
75498 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
75499
75500 +#define atomic64_read_unchecked(v) atomic64_read(v)
75501 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
75502 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
75503 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
75504 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
75505 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
75506 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
75507 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
75508 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
75509 +
75510 #endif /* _ASM_GENERIC_ATOMIC64_H */
75511 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
75512 index a60a7cc..0fe12f2 100644
75513 --- a/include/asm-generic/bitops/__fls.h
75514 +++ b/include/asm-generic/bitops/__fls.h
75515 @@ -9,7 +9,7 @@
75516 *
75517 * Undefined if no set bit exists, so code should check against 0 first.
75518 */
75519 -static __always_inline unsigned long __fls(unsigned long word)
75520 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
75521 {
75522 int num = BITS_PER_LONG - 1;
75523
75524 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
75525 index 0576d1f..dad6c71 100644
75526 --- a/include/asm-generic/bitops/fls.h
75527 +++ b/include/asm-generic/bitops/fls.h
75528 @@ -9,7 +9,7 @@
75529 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
75530 */
75531
75532 -static __always_inline int fls(int x)
75533 +static __always_inline int __intentional_overflow(-1) fls(int x)
75534 {
75535 int r = 32;
75536
75537 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
75538 index b097cf8..3d40e14 100644
75539 --- a/include/asm-generic/bitops/fls64.h
75540 +++ b/include/asm-generic/bitops/fls64.h
75541 @@ -15,7 +15,7 @@
75542 * at position 64.
75543 */
75544 #if BITS_PER_LONG == 32
75545 -static __always_inline int fls64(__u64 x)
75546 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75547 {
75548 __u32 h = x >> 32;
75549 if (h)
75550 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
75551 return fls(x);
75552 }
75553 #elif BITS_PER_LONG == 64
75554 -static __always_inline int fls64(__u64 x)
75555 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75556 {
75557 if (x == 0)
75558 return 0;
75559 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
75560 index 1bfcfe5..e04c5c9 100644
75561 --- a/include/asm-generic/cache.h
75562 +++ b/include/asm-generic/cache.h
75563 @@ -6,7 +6,7 @@
75564 * cache lines need to provide their own cache.h.
75565 */
75566
75567 -#define L1_CACHE_SHIFT 5
75568 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
75569 +#define L1_CACHE_SHIFT 5UL
75570 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
75571
75572 #endif /* __ASM_GENERIC_CACHE_H */
75573 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
75574 index 0d68a1e..b74a761 100644
75575 --- a/include/asm-generic/emergency-restart.h
75576 +++ b/include/asm-generic/emergency-restart.h
75577 @@ -1,7 +1,7 @@
75578 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
75579 #define _ASM_GENERIC_EMERGENCY_RESTART_H
75580
75581 -static inline void machine_emergency_restart(void)
75582 +static inline __noreturn void machine_emergency_restart(void)
75583 {
75584 machine_restart(NULL);
75585 }
75586 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
75587 index 90f99c7..00ce236 100644
75588 --- a/include/asm-generic/kmap_types.h
75589 +++ b/include/asm-generic/kmap_types.h
75590 @@ -2,9 +2,9 @@
75591 #define _ASM_GENERIC_KMAP_TYPES_H
75592
75593 #ifdef __WITH_KM_FENCE
75594 -# define KM_TYPE_NR 41
75595 +# define KM_TYPE_NR 42
75596 #else
75597 -# define KM_TYPE_NR 20
75598 +# define KM_TYPE_NR 21
75599 #endif
75600
75601 #endif
75602 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
75603 index 9ceb03b..62b0b8f 100644
75604 --- a/include/asm-generic/local.h
75605 +++ b/include/asm-generic/local.h
75606 @@ -23,24 +23,37 @@ typedef struct
75607 atomic_long_t a;
75608 } local_t;
75609
75610 +typedef struct {
75611 + atomic_long_unchecked_t a;
75612 +} local_unchecked_t;
75613 +
75614 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
75615
75616 #define local_read(l) atomic_long_read(&(l)->a)
75617 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
75618 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
75619 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
75620 #define local_inc(l) atomic_long_inc(&(l)->a)
75621 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
75622 #define local_dec(l) atomic_long_dec(&(l)->a)
75623 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
75624 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
75625 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
75626 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
75627 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
75628
75629 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
75630 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
75631 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
75632 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
75633 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
75634 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
75635 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
75636 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
75637 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
75638
75639 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75640 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75641 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
75642 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
75643 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
75644 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
75645 index 725612b..9cc513a 100644
75646 --- a/include/asm-generic/pgtable-nopmd.h
75647 +++ b/include/asm-generic/pgtable-nopmd.h
75648 @@ -1,14 +1,19 @@
75649 #ifndef _PGTABLE_NOPMD_H
75650 #define _PGTABLE_NOPMD_H
75651
75652 -#ifndef __ASSEMBLY__
75653 -
75654 #include <asm-generic/pgtable-nopud.h>
75655
75656 -struct mm_struct;
75657 -
75658 #define __PAGETABLE_PMD_FOLDED
75659
75660 +#define PMD_SHIFT PUD_SHIFT
75661 +#define PTRS_PER_PMD 1
75662 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
75663 +#define PMD_MASK (~(PMD_SIZE-1))
75664 +
75665 +#ifndef __ASSEMBLY__
75666 +
75667 +struct mm_struct;
75668 +
75669 /*
75670 * Having the pmd type consist of a pud gets the size right, and allows
75671 * us to conceptually access the pud entry that this pmd is folded into
75672 @@ -16,11 +21,6 @@ struct mm_struct;
75673 */
75674 typedef struct { pud_t pud; } pmd_t;
75675
75676 -#define PMD_SHIFT PUD_SHIFT
75677 -#define PTRS_PER_PMD 1
75678 -#define PMD_SIZE (1UL << PMD_SHIFT)
75679 -#define PMD_MASK (~(PMD_SIZE-1))
75680 -
75681 /*
75682 * The "pud_xxx()" functions here are trivial for a folded two-level
75683 * setup: the pmd is never bad, and a pmd always exists (as it's folded
75684 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
75685 index 810431d..0ec4804f 100644
75686 --- a/include/asm-generic/pgtable-nopud.h
75687 +++ b/include/asm-generic/pgtable-nopud.h
75688 @@ -1,10 +1,15 @@
75689 #ifndef _PGTABLE_NOPUD_H
75690 #define _PGTABLE_NOPUD_H
75691
75692 -#ifndef __ASSEMBLY__
75693 -
75694 #define __PAGETABLE_PUD_FOLDED
75695
75696 +#define PUD_SHIFT PGDIR_SHIFT
75697 +#define PTRS_PER_PUD 1
75698 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
75699 +#define PUD_MASK (~(PUD_SIZE-1))
75700 +
75701 +#ifndef __ASSEMBLY__
75702 +
75703 /*
75704 * Having the pud type consist of a pgd gets the size right, and allows
75705 * us to conceptually access the pgd entry that this pud is folded into
75706 @@ -12,11 +17,6 @@
75707 */
75708 typedef struct { pgd_t pgd; } pud_t;
75709
75710 -#define PUD_SHIFT PGDIR_SHIFT
75711 -#define PTRS_PER_PUD 1
75712 -#define PUD_SIZE (1UL << PUD_SHIFT)
75713 -#define PUD_MASK (~(PUD_SIZE-1))
75714 -
75715 /*
75716 * The "pgd_xxx()" functions here are trivial for a folded two-level
75717 * setup: the pud is never bad, and a pud always exists (as it's folded
75718 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
75719 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
75720
75721 #define pgd_populate(mm, pgd, pud) do { } while (0)
75722 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
75723 /*
75724 * (puds are folded into pgds so this doesn't get actually called,
75725 * but the define is needed for a generic inline function.)
75726 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
75727 index db09234..86683e3 100644
75728 --- a/include/asm-generic/pgtable.h
75729 +++ b/include/asm-generic/pgtable.h
75730 @@ -736,6 +736,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
75731 }
75732 #endif /* CONFIG_NUMA_BALANCING */
75733
75734 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
75735 +#ifdef CONFIG_PAX_KERNEXEC
75736 +#error KERNEXEC requires pax_open_kernel
75737 +#else
75738 +static inline unsigned long pax_open_kernel(void) { return 0; }
75739 +#endif
75740 +#endif
75741 +
75742 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
75743 +#ifdef CONFIG_PAX_KERNEXEC
75744 +#error KERNEXEC requires pax_close_kernel
75745 +#else
75746 +static inline unsigned long pax_close_kernel(void) { return 0; }
75747 +#endif
75748 +#endif
75749 +
75750 #endif /* CONFIG_MMU */
75751
75752 #endif /* !__ASSEMBLY__ */
75753 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
75754 index dc1269c..48a4f51 100644
75755 --- a/include/asm-generic/uaccess.h
75756 +++ b/include/asm-generic/uaccess.h
75757 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
75758 return __clear_user(to, n);
75759 }
75760
75761 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
75762 +#ifdef CONFIG_PAX_MEMORY_UDEREF
75763 +#error UDEREF requires pax_open_userland
75764 +#else
75765 +static inline unsigned long pax_open_userland(void) { return 0; }
75766 +#endif
75767 +#endif
75768 +
75769 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
75770 +#ifdef CONFIG_PAX_MEMORY_UDEREF
75771 +#error UDEREF requires pax_close_userland
75772 +#else
75773 +static inline unsigned long pax_close_userland(void) { return 0; }
75774 +#endif
75775 +#endif
75776 +
75777 #endif /* __ASM_GENERIC_UACCESS_H */
75778 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
75779 index bc2121f..2f41f9a 100644
75780 --- a/include/asm-generic/vmlinux.lds.h
75781 +++ b/include/asm-generic/vmlinux.lds.h
75782 @@ -232,6 +232,7 @@
75783 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
75784 VMLINUX_SYMBOL(__start_rodata) = .; \
75785 *(.rodata) *(.rodata.*) \
75786 + *(.data..read_only) \
75787 *(__vermagic) /* Kernel version magic */ \
75788 . = ALIGN(8); \
75789 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
75790 @@ -716,17 +717,18 @@
75791 * section in the linker script will go there too. @phdr should have
75792 * a leading colon.
75793 *
75794 - * Note that this macros defines __per_cpu_load as an absolute symbol.
75795 + * Note that this macros defines per_cpu_load as an absolute symbol.
75796 * If there is no need to put the percpu section at a predetermined
75797 * address, use PERCPU_SECTION.
75798 */
75799 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
75800 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
75801 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
75802 + per_cpu_load = .; \
75803 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
75804 - LOAD_OFFSET) { \
75805 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
75806 PERCPU_INPUT(cacheline) \
75807 } phdr \
75808 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
75809 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
75810
75811 /**
75812 * PERCPU_SECTION - define output section for percpu area, simple version
75813 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
75814 index e73c19e..5b89e00 100644
75815 --- a/include/crypto/algapi.h
75816 +++ b/include/crypto/algapi.h
75817 @@ -34,7 +34,7 @@ struct crypto_type {
75818 unsigned int maskclear;
75819 unsigned int maskset;
75820 unsigned int tfmsize;
75821 -};
75822 +} __do_const;
75823
75824 struct crypto_instance {
75825 struct crypto_alg alg;
75826 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
75827 index 1d4a920..da65658 100644
75828 --- a/include/drm/drmP.h
75829 +++ b/include/drm/drmP.h
75830 @@ -66,6 +66,7 @@
75831 #include <linux/workqueue.h>
75832 #include <linux/poll.h>
75833 #include <asm/pgalloc.h>
75834 +#include <asm/local.h>
75835 #include <drm/drm.h>
75836 #include <drm/drm_sarea.h>
75837 #include <drm/drm_vma_manager.h>
75838 @@ -278,10 +279,12 @@ do { \
75839 * \param cmd command.
75840 * \param arg argument.
75841 */
75842 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
75843 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
75844 + struct drm_file *file_priv);
75845 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
75846 struct drm_file *file_priv);
75847
75848 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75849 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
75850 unsigned long arg);
75851
75852 #define DRM_IOCTL_NR(n) _IOC_NR(n)
75853 @@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75854 struct drm_ioctl_desc {
75855 unsigned int cmd;
75856 int flags;
75857 - drm_ioctl_t *func;
75858 + drm_ioctl_t func;
75859 unsigned int cmd_drv;
75860 const char *name;
75861 -};
75862 +} __do_const;
75863
75864 /**
75865 * Creates a driver or general drm_ioctl_desc array entry for the given
75866 @@ -1013,7 +1016,8 @@ struct drm_info_list {
75867 int (*show)(struct seq_file*, void*); /** show callback */
75868 u32 driver_features; /**< Required driver features for this entry */
75869 void *data;
75870 -};
75871 +} __do_const;
75872 +typedef struct drm_info_list __no_const drm_info_list_no_const;
75873
75874 /**
75875 * debugfs node structure. This structure represents a debugfs file.
75876 @@ -1097,7 +1101,7 @@ struct drm_device {
75877
75878 /** \name Usage Counters */
75879 /*@{ */
75880 - int open_count; /**< Outstanding files open */
75881 + local_t open_count; /**< Outstanding files open */
75882 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
75883 atomic_t vma_count; /**< Outstanding vma areas open */
75884 int buf_use; /**< Buffers in use -- cannot alloc */
75885 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
75886 index ef6ad3a..be34b16 100644
75887 --- a/include/drm/drm_crtc_helper.h
75888 +++ b/include/drm/drm_crtc_helper.h
75889 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
75890 struct drm_connector *connector);
75891 /* disable encoder when not in use - more explicit than dpms off */
75892 void (*disable)(struct drm_encoder *encoder);
75893 -};
75894 +} __no_const;
75895
75896 /**
75897 * drm_connector_helper_funcs - helper operations for connectors
75898 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
75899 index 940ece4..8cb727f 100644
75900 --- a/include/drm/i915_pciids.h
75901 +++ b/include/drm/i915_pciids.h
75902 @@ -37,7 +37,7 @@
75903 */
75904 #define INTEL_VGA_DEVICE(id, info) { \
75905 0x8086, id, \
75906 - ~0, ~0, \
75907 + PCI_ANY_ID, PCI_ANY_ID, \
75908 0x030000, 0xff0000, \
75909 (unsigned long) info }
75910
75911 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
75912 index 72dcbe8..8db58d7 100644
75913 --- a/include/drm/ttm/ttm_memory.h
75914 +++ b/include/drm/ttm/ttm_memory.h
75915 @@ -48,7 +48,7 @@
75916
75917 struct ttm_mem_shrink {
75918 int (*do_shrink) (struct ttm_mem_shrink *);
75919 -};
75920 +} __no_const;
75921
75922 /**
75923 * struct ttm_mem_global - Global memory accounting structure.
75924 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
75925 index d1f61bf..2239439 100644
75926 --- a/include/drm/ttm/ttm_page_alloc.h
75927 +++ b/include/drm/ttm/ttm_page_alloc.h
75928 @@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
75929 */
75930 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
75931
75932 +struct device;
75933 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
75934 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
75935
75936 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
75937 index 4b840e8..155d235 100644
75938 --- a/include/keys/asymmetric-subtype.h
75939 +++ b/include/keys/asymmetric-subtype.h
75940 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
75941 /* Verify the signature on a key of this subtype (optional) */
75942 int (*verify_signature)(const struct key *key,
75943 const struct public_key_signature *sig);
75944 -};
75945 +} __do_const;
75946
75947 /**
75948 * asymmetric_key_subtype - Get the subtype from an asymmetric key
75949 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
75950 index c1da539..1dcec55 100644
75951 --- a/include/linux/atmdev.h
75952 +++ b/include/linux/atmdev.h
75953 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
75954 #endif
75955
75956 struct k_atm_aal_stats {
75957 -#define __HANDLE_ITEM(i) atomic_t i
75958 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
75959 __AAL_STAT_ITEMS
75960 #undef __HANDLE_ITEM
75961 };
75962 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
75963 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
75964 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
75965 struct module *owner;
75966 -};
75967 +} __do_const ;
75968
75969 struct atmphy_ops {
75970 int (*start)(struct atm_dev *dev);
75971 diff --git a/include/linux/audit.h b/include/linux/audit.h
75972 index a406419..c2bb164 100644
75973 --- a/include/linux/audit.h
75974 +++ b/include/linux/audit.h
75975 @@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
75976 extern unsigned int audit_serial(void);
75977 extern int auditsc_get_stamp(struct audit_context *ctx,
75978 struct timespec *t, unsigned int *serial);
75979 -extern int audit_set_loginuid(kuid_t loginuid);
75980 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
75981
75982 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
75983 {
75984 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
75985 index fd8bf32..2cccd5a 100644
75986 --- a/include/linux/binfmts.h
75987 +++ b/include/linux/binfmts.h
75988 @@ -74,8 +74,10 @@ struct linux_binfmt {
75989 int (*load_binary)(struct linux_binprm *);
75990 int (*load_shlib)(struct file *);
75991 int (*core_dump)(struct coredump_params *cprm);
75992 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
75993 + void (*handle_mmap)(struct file *);
75994 unsigned long min_coredump; /* minimal dump size */
75995 -};
75996 +} __do_const;
75997
75998 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
75999
76000 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76001 index abc9ca7..e54ee27 100644
76002 --- a/include/linux/bitops.h
76003 +++ b/include/linux/bitops.h
76004 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76005 * @word: value to rotate
76006 * @shift: bits to roll
76007 */
76008 -static inline __u32 rol32(__u32 word, unsigned int shift)
76009 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76010 {
76011 return (word << shift) | (word >> (32 - shift));
76012 }
76013 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76014 * @word: value to rotate
76015 * @shift: bits to roll
76016 */
76017 -static inline __u32 ror32(__u32 word, unsigned int shift)
76018 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76019 {
76020 return (word >> shift) | (word << (32 - shift));
76021 }
76022 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76023 return (__s32)(value << shift) >> shift;
76024 }
76025
76026 -static inline unsigned fls_long(unsigned long l)
76027 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76028 {
76029 if (sizeof(l) == 4)
76030 return fls(l);
76031 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76032 index 1b135d4..59fc876 100644
76033 --- a/include/linux/blkdev.h
76034 +++ b/include/linux/blkdev.h
76035 @@ -1578,7 +1578,7 @@ struct block_device_operations {
76036 /* this callback is with swap_lock and sometimes page table lock held */
76037 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
76038 struct module *owner;
76039 -};
76040 +} __do_const;
76041
76042 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
76043 unsigned long);
76044 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
76045 index afc1343..9735539 100644
76046 --- a/include/linux/blktrace_api.h
76047 +++ b/include/linux/blktrace_api.h
76048 @@ -25,7 +25,7 @@ struct blk_trace {
76049 struct dentry *dropped_file;
76050 struct dentry *msg_file;
76051 struct list_head running_list;
76052 - atomic_t dropped;
76053 + atomic_unchecked_t dropped;
76054 };
76055
76056 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
76057 diff --git a/include/linux/cache.h b/include/linux/cache.h
76058 index 4c57065..40346da 100644
76059 --- a/include/linux/cache.h
76060 +++ b/include/linux/cache.h
76061 @@ -16,6 +16,14 @@
76062 #define __read_mostly
76063 #endif
76064
76065 +#ifndef __read_only
76066 +#ifdef CONFIG_PAX_KERNEXEC
76067 +#error KERNEXEC requires __read_only
76068 +#else
76069 +#define __read_only __read_mostly
76070 +#endif
76071 +#endif
76072 +
76073 #ifndef ____cacheline_aligned
76074 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
76075 #endif
76076 diff --git a/include/linux/capability.h b/include/linux/capability.h
76077 index a6ee1f9..e1ca49d 100644
76078 --- a/include/linux/capability.h
76079 +++ b/include/linux/capability.h
76080 @@ -212,8 +212,13 @@ extern bool capable(int cap);
76081 extern bool ns_capable(struct user_namespace *ns, int cap);
76082 extern bool inode_capable(const struct inode *inode, int cap);
76083 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
76084 +extern bool capable_nolog(int cap);
76085 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
76086 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
76087
76088 /* audit system wants to get cap info from files as well */
76089 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
76090
76091 +extern int is_privileged_binary(const struct dentry *dentry);
76092 +
76093 #endif /* !_LINUX_CAPABILITY_H */
76094 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
76095 index 8609d57..86e4d79 100644
76096 --- a/include/linux/cdrom.h
76097 +++ b/include/linux/cdrom.h
76098 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
76099
76100 /* driver specifications */
76101 const int capability; /* capability flags */
76102 - int n_minors; /* number of active minor devices */
76103 /* handle uniform packets for scsi type devices (scsi,atapi) */
76104 int (*generic_packet) (struct cdrom_device_info *,
76105 struct packet_command *);
76106 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
76107 index 4ce9056..86caac6 100644
76108 --- a/include/linux/cleancache.h
76109 +++ b/include/linux/cleancache.h
76110 @@ -31,7 +31,7 @@ struct cleancache_ops {
76111 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
76112 void (*invalidate_inode)(int, struct cleancache_filekey);
76113 void (*invalidate_fs)(int);
76114 -};
76115 +} __no_const;
76116
76117 extern struct cleancache_ops *
76118 cleancache_register_ops(struct cleancache_ops *ops);
76119 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
76120 index 7e59253..d6e4cae 100644
76121 --- a/include/linux/clk-provider.h
76122 +++ b/include/linux/clk-provider.h
76123 @@ -141,6 +141,7 @@ struct clk_ops {
76124 unsigned long);
76125 void (*init)(struct clk_hw *hw);
76126 };
76127 +typedef struct clk_ops __no_const clk_ops_no_const;
76128
76129 /**
76130 * struct clk_init_data - holds init data that's common to all clocks and is
76131 diff --git a/include/linux/compat.h b/include/linux/compat.h
76132 index eb8a49d..6b66ed9 100644
76133 --- a/include/linux/compat.h
76134 +++ b/include/linux/compat.h
76135 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
76136 compat_size_t __user *len_ptr);
76137
76138 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
76139 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
76140 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
76141 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
76142 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
76143 compat_ssize_t msgsz, int msgflg);
76144 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
76145 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
76146 compat_ulong_t addr, compat_ulong_t data);
76147 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76148 - compat_long_t addr, compat_long_t data);
76149 + compat_ulong_t addr, compat_ulong_t data);
76150
76151 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
76152 /*
76153 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
76154 index ded4299..ddcbe31 100644
76155 --- a/include/linux/compiler-gcc4.h
76156 +++ b/include/linux/compiler-gcc4.h
76157 @@ -39,9 +39,34 @@
76158 # define __compiletime_warning(message) __attribute__((warning(message)))
76159 # define __compiletime_error(message) __attribute__((error(message)))
76160 #endif /* __CHECKER__ */
76161 +
76162 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
76163 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
76164 +#define __bos0(ptr) __bos((ptr), 0)
76165 +#define __bos1(ptr) __bos((ptr), 1)
76166 #endif /* GCC_VERSION >= 40300 */
76167
76168 #if GCC_VERSION >= 40500
76169 +
76170 +#ifdef RANDSTRUCT_PLUGIN
76171 +#define __randomize_layout __attribute__((randomize_layout))
76172 +#define __no_randomize_layout __attribute__((no_randomize_layout))
76173 +#endif
76174 +
76175 +#ifdef CONSTIFY_PLUGIN
76176 +#define __no_const __attribute__((no_const))
76177 +#define __do_const __attribute__((do_const))
76178 +#endif
76179 +
76180 +#ifdef SIZE_OVERFLOW_PLUGIN
76181 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
76182 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
76183 +#endif
76184 +
76185 +#ifdef LATENT_ENTROPY_PLUGIN
76186 +#define __latent_entropy __attribute__((latent_entropy))
76187 +#endif
76188 +
76189 /*
76190 * Mark a position in code as unreachable. This can be used to
76191 * suppress control flow warnings after asm blocks that transfer
76192 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
76193 index 92669cd..cc564c0 100644
76194 --- a/include/linux/compiler.h
76195 +++ b/include/linux/compiler.h
76196 @@ -5,11 +5,14 @@
76197
76198 #ifdef __CHECKER__
76199 # define __user __attribute__((noderef, address_space(1)))
76200 +# define __force_user __force __user
76201 # define __kernel __attribute__((address_space(0)))
76202 +# define __force_kernel __force __kernel
76203 # define __safe __attribute__((safe))
76204 # define __force __attribute__((force))
76205 # define __nocast __attribute__((nocast))
76206 # define __iomem __attribute__((noderef, address_space(2)))
76207 +# define __force_iomem __force __iomem
76208 # define __must_hold(x) __attribute__((context(x,1,1)))
76209 # define __acquires(x) __attribute__((context(x,0,1)))
76210 # define __releases(x) __attribute__((context(x,1,0)))
76211 @@ -17,20 +20,37 @@
76212 # define __release(x) __context__(x,-1)
76213 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
76214 # define __percpu __attribute__((noderef, address_space(3)))
76215 +# define __force_percpu __force __percpu
76216 #ifdef CONFIG_SPARSE_RCU_POINTER
76217 # define __rcu __attribute__((noderef, address_space(4)))
76218 +# define __force_rcu __force __rcu
76219 #else
76220 # define __rcu
76221 +# define __force_rcu
76222 #endif
76223 extern void __chk_user_ptr(const volatile void __user *);
76224 extern void __chk_io_ptr(const volatile void __iomem *);
76225 #else
76226 -# define __user
76227 -# define __kernel
76228 +# ifdef CHECKER_PLUGIN
76229 +//# define __user
76230 +//# define __force_user
76231 +//# define __kernel
76232 +//# define __force_kernel
76233 +# else
76234 +# ifdef STRUCTLEAK_PLUGIN
76235 +# define __user __attribute__((user))
76236 +# else
76237 +# define __user
76238 +# endif
76239 +# define __force_user
76240 +# define __kernel
76241 +# define __force_kernel
76242 +# endif
76243 # define __safe
76244 # define __force
76245 # define __nocast
76246 # define __iomem
76247 +# define __force_iomem
76248 # define __chk_user_ptr(x) (void)0
76249 # define __chk_io_ptr(x) (void)0
76250 # define __builtin_warning(x, y...) (1)
76251 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
76252 # define __release(x) (void)0
76253 # define __cond_lock(x,c) (c)
76254 # define __percpu
76255 +# define __force_percpu
76256 # define __rcu
76257 +# define __force_rcu
76258 #endif
76259
76260 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
76261 @@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76262 # define __attribute_const__ /* unimplemented */
76263 #endif
76264
76265 +#ifndef __randomize_layout
76266 +# define __randomize_layout
76267 +#endif
76268 +
76269 +#ifndef __no_randomize_layout
76270 +# define __no_randomize_layout
76271 +#endif
76272 +
76273 +#ifndef __no_const
76274 +# define __no_const
76275 +#endif
76276 +
76277 +#ifndef __do_const
76278 +# define __do_const
76279 +#endif
76280 +
76281 +#ifndef __size_overflow
76282 +# define __size_overflow(...)
76283 +#endif
76284 +
76285 +#ifndef __intentional_overflow
76286 +# define __intentional_overflow(...)
76287 +#endif
76288 +
76289 +#ifndef __latent_entropy
76290 +# define __latent_entropy
76291 +#endif
76292 +
76293 /*
76294 * Tell gcc if a function is cold. The compiler will assume any path
76295 * directly leading to the call is unlikely.
76296 @@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76297 #define __cold
76298 #endif
76299
76300 +#ifndef __alloc_size
76301 +#define __alloc_size(...)
76302 +#endif
76303 +
76304 +#ifndef __bos
76305 +#define __bos(ptr, arg)
76306 +#endif
76307 +
76308 +#ifndef __bos0
76309 +#define __bos0(ptr)
76310 +#endif
76311 +
76312 +#ifndef __bos1
76313 +#define __bos1(ptr)
76314 +#endif
76315 +
76316 /* Simple shorthand for a section definition */
76317 #ifndef __section
76318 # define __section(S) __attribute__ ((__section__(#S)))
76319 @@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76320 * use is to mediate communication between process-level code and irq/NMI
76321 * handlers, all running on the same CPU.
76322 */
76323 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
76324 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
76325 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
76326
76327 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
76328 #ifdef CONFIG_KPROBES
76329 diff --git a/include/linux/completion.h b/include/linux/completion.h
76330 index 5d5aaae..0ea9b84 100644
76331 --- a/include/linux/completion.h
76332 +++ b/include/linux/completion.h
76333 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
76334
76335 extern void wait_for_completion(struct completion *);
76336 extern void wait_for_completion_io(struct completion *);
76337 -extern int wait_for_completion_interruptible(struct completion *x);
76338 -extern int wait_for_completion_killable(struct completion *x);
76339 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
76340 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
76341 extern unsigned long wait_for_completion_timeout(struct completion *x,
76342 - unsigned long timeout);
76343 + unsigned long timeout) __intentional_overflow(-1);
76344 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
76345 - unsigned long timeout);
76346 + unsigned long timeout) __intentional_overflow(-1);
76347 extern long wait_for_completion_interruptible_timeout(
76348 - struct completion *x, unsigned long timeout);
76349 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76350 extern long wait_for_completion_killable_timeout(
76351 - struct completion *x, unsigned long timeout);
76352 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76353 extern bool try_wait_for_completion(struct completion *x);
76354 extern bool completion_done(struct completion *x);
76355
76356 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
76357 index 34025df..d94bbbc 100644
76358 --- a/include/linux/configfs.h
76359 +++ b/include/linux/configfs.h
76360 @@ -125,7 +125,7 @@ struct configfs_attribute {
76361 const char *ca_name;
76362 struct module *ca_owner;
76363 umode_t ca_mode;
76364 -};
76365 +} __do_const;
76366
76367 /*
76368 * Users often need to create attribute structures for their configurable
76369 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
76370 index dc196bb..c55a50f 100644
76371 --- a/include/linux/cpufreq.h
76372 +++ b/include/linux/cpufreq.h
76373 @@ -189,6 +189,7 @@ struct global_attr {
76374 ssize_t (*store)(struct kobject *a, struct attribute *b,
76375 const char *c, size_t count);
76376 };
76377 +typedef struct global_attr __no_const global_attr_no_const;
76378
76379 #define define_one_global_ro(_name) \
76380 static struct global_attr _name = \
76381 @@ -225,7 +226,7 @@ struct cpufreq_driver {
76382 int (*suspend) (struct cpufreq_policy *policy);
76383 int (*resume) (struct cpufreq_policy *policy);
76384 struct freq_attr **attr;
76385 -};
76386 +} __do_const;
76387
76388 /* flags */
76389 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
76390 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
76391 index 50fcbb0..9d2dbd9 100644
76392 --- a/include/linux/cpuidle.h
76393 +++ b/include/linux/cpuidle.h
76394 @@ -50,7 +50,8 @@ struct cpuidle_state {
76395 int index);
76396
76397 int (*enter_dead) (struct cpuidle_device *dev, int index);
76398 -};
76399 +} __do_const;
76400 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
76401
76402 /* Idle State Flags */
76403 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
76404 @@ -192,7 +193,7 @@ struct cpuidle_governor {
76405 void (*reflect) (struct cpuidle_device *dev, int index);
76406
76407 struct module *owner;
76408 -};
76409 +} __do_const;
76410
76411 #ifdef CONFIG_CPU_IDLE
76412 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
76413 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
76414 index d08e4d2..95fad61 100644
76415 --- a/include/linux/cpumask.h
76416 +++ b/include/linux/cpumask.h
76417 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76418 }
76419
76420 /* Valid inputs for n are -1 and 0. */
76421 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76422 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76423 {
76424 return n+1;
76425 }
76426
76427 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76428 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76429 {
76430 return n+1;
76431 }
76432
76433 -static inline unsigned int cpumask_next_and(int n,
76434 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
76435 const struct cpumask *srcp,
76436 const struct cpumask *andp)
76437 {
76438 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76439 *
76440 * Returns >= nr_cpu_ids if no further cpus set.
76441 */
76442 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76443 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76444 {
76445 /* -1 is a legal arg here. */
76446 if (n != -1)
76447 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76448 *
76449 * Returns >= nr_cpu_ids if no further cpus unset.
76450 */
76451 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76452 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76453 {
76454 /* -1 is a legal arg here. */
76455 if (n != -1)
76456 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76457 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
76458 }
76459
76460 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
76461 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
76462 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
76463
76464 /**
76465 diff --git a/include/linux/cred.h b/include/linux/cred.h
76466 index 04421e8..117e17a 100644
76467 --- a/include/linux/cred.h
76468 +++ b/include/linux/cred.h
76469 @@ -35,7 +35,7 @@ struct group_info {
76470 int nblocks;
76471 kgid_t small_block[NGROUPS_SMALL];
76472 kgid_t *blocks[0];
76473 -};
76474 +} __randomize_layout;
76475
76476 /**
76477 * get_group_info - Get a reference to a group info structure
76478 @@ -136,7 +136,7 @@ struct cred {
76479 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
76480 struct group_info *group_info; /* supplementary groups for euid/fsgid */
76481 struct rcu_head rcu; /* RCU deletion hook */
76482 -};
76483 +} __randomize_layout;
76484
76485 extern void __put_cred(struct cred *);
76486 extern void exit_creds(struct task_struct *);
76487 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
76488 static inline void validate_process_creds(void)
76489 {
76490 }
76491 +static inline void validate_task_creds(struct task_struct *task)
76492 +{
76493 +}
76494 #endif
76495
76496 /**
76497 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
76498 index b92eadf..b4ecdc1 100644
76499 --- a/include/linux/crypto.h
76500 +++ b/include/linux/crypto.h
76501 @@ -373,7 +373,7 @@ struct cipher_tfm {
76502 const u8 *key, unsigned int keylen);
76503 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76504 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76505 -};
76506 +} __no_const;
76507
76508 struct hash_tfm {
76509 int (*init)(struct hash_desc *desc);
76510 @@ -394,13 +394,13 @@ struct compress_tfm {
76511 int (*cot_decompress)(struct crypto_tfm *tfm,
76512 const u8 *src, unsigned int slen,
76513 u8 *dst, unsigned int *dlen);
76514 -};
76515 +} __no_const;
76516
76517 struct rng_tfm {
76518 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
76519 unsigned int dlen);
76520 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
76521 -};
76522 +} __no_const;
76523
76524 #define crt_ablkcipher crt_u.ablkcipher
76525 #define crt_aead crt_u.aead
76526 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
76527 index 653589e..4ef254a 100644
76528 --- a/include/linux/ctype.h
76529 +++ b/include/linux/ctype.h
76530 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
76531 * Fast implementation of tolower() for internal usage. Do not use in your
76532 * code.
76533 */
76534 -static inline char _tolower(const char c)
76535 +static inline unsigned char _tolower(const unsigned char c)
76536 {
76537 return c | 0x20;
76538 }
76539 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
76540 index bf72e9a..4ca7927 100644
76541 --- a/include/linux/dcache.h
76542 +++ b/include/linux/dcache.h
76543 @@ -133,7 +133,7 @@ struct dentry {
76544 } d_u;
76545 struct list_head d_subdirs; /* our children */
76546 struct hlist_node d_alias; /* inode alias list */
76547 -};
76548 +} __randomize_layout;
76549
76550 /*
76551 * dentry->d_lock spinlock nesting subclasses:
76552 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
76553 index 7925bf0..d5143d2 100644
76554 --- a/include/linux/decompress/mm.h
76555 +++ b/include/linux/decompress/mm.h
76556 @@ -77,7 +77,7 @@ static void free(void *where)
76557 * warnings when not needed (indeed large_malloc / large_free are not
76558 * needed by inflate */
76559
76560 -#define malloc(a) kmalloc(a, GFP_KERNEL)
76561 +#define malloc(a) kmalloc((a), GFP_KERNEL)
76562 #define free(a) kfree(a)
76563
76564 #define large_malloc(a) vmalloc(a)
76565 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
76566 index d48dc00..211ee54 100644
76567 --- a/include/linux/devfreq.h
76568 +++ b/include/linux/devfreq.h
76569 @@ -114,7 +114,7 @@ struct devfreq_governor {
76570 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
76571 int (*event_handler)(struct devfreq *devfreq,
76572 unsigned int event, void *data);
76573 -};
76574 +} __do_const;
76575
76576 /**
76577 * struct devfreq - Device devfreq structure
76578 diff --git a/include/linux/device.h b/include/linux/device.h
76579 index 952b010..d5b7691 100644
76580 --- a/include/linux/device.h
76581 +++ b/include/linux/device.h
76582 @@ -310,7 +310,7 @@ struct subsys_interface {
76583 struct list_head node;
76584 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
76585 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
76586 -};
76587 +} __do_const;
76588
76589 int subsys_interface_register(struct subsys_interface *sif);
76590 void subsys_interface_unregister(struct subsys_interface *sif);
76591 @@ -506,7 +506,7 @@ struct device_type {
76592 void (*release)(struct device *dev);
76593
76594 const struct dev_pm_ops *pm;
76595 -};
76596 +} __do_const;
76597
76598 /* interface for exporting device attributes */
76599 struct device_attribute {
76600 @@ -516,11 +516,12 @@ struct device_attribute {
76601 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
76602 const char *buf, size_t count);
76603 };
76604 +typedef struct device_attribute __no_const device_attribute_no_const;
76605
76606 struct dev_ext_attribute {
76607 struct device_attribute attr;
76608 void *var;
76609 -};
76610 +} __do_const;
76611
76612 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
76613 char *buf);
76614 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
76615 index fd4aee2..1f28db9 100644
76616 --- a/include/linux/dma-mapping.h
76617 +++ b/include/linux/dma-mapping.h
76618 @@ -54,7 +54,7 @@ struct dma_map_ops {
76619 u64 (*get_required_mask)(struct device *dev);
76620 #endif
76621 int is_phys;
76622 -};
76623 +} __do_const;
76624
76625 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
76626
76627 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
76628 index 41cf0c3..f3b771c 100644
76629 --- a/include/linux/dmaengine.h
76630 +++ b/include/linux/dmaengine.h
76631 @@ -1114,9 +1114,9 @@ struct dma_pinned_list {
76632 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
76633 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
76634
76635 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76636 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76637 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
76638 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76639 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76640 struct dma_pinned_list *pinned_list, struct page *page,
76641 unsigned int offset, size_t len);
76642
76643 diff --git a/include/linux/efi.h b/include/linux/efi.h
76644 index 11ce678..7b8c69c 100644
76645 --- a/include/linux/efi.h
76646 +++ b/include/linux/efi.h
76647 @@ -764,6 +764,7 @@ struct efivar_operations {
76648 efi_set_variable_t *set_variable;
76649 efi_query_variable_store_t *query_variable_store;
76650 };
76651 +typedef struct efivar_operations __no_const efivar_operations_no_const;
76652
76653 struct efivars {
76654 /*
76655 diff --git a/include/linux/elf.h b/include/linux/elf.h
76656 index 67a5fa7..b817372 100644
76657 --- a/include/linux/elf.h
76658 +++ b/include/linux/elf.h
76659 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
76660 #define elf_note elf32_note
76661 #define elf_addr_t Elf32_Off
76662 #define Elf_Half Elf32_Half
76663 +#define elf_dyn Elf32_Dyn
76664
76665 #else
76666
76667 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
76668 #define elf_note elf64_note
76669 #define elf_addr_t Elf64_Off
76670 #define Elf_Half Elf64_Half
76671 +#define elf_dyn Elf64_Dyn
76672
76673 #endif
76674
76675 diff --git a/include/linux/err.h b/include/linux/err.h
76676 index 15f92e0..e825a8e 100644
76677 --- a/include/linux/err.h
76678 +++ b/include/linux/err.h
76679 @@ -19,12 +19,12 @@
76680
76681 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
76682
76683 -static inline void * __must_check ERR_PTR(long error)
76684 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
76685 {
76686 return (void *) error;
76687 }
76688
76689 -static inline long __must_check PTR_ERR(__force const void *ptr)
76690 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
76691 {
76692 return (long) ptr;
76693 }
76694 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
76695 index 21c59af..6057a03 100644
76696 --- a/include/linux/extcon.h
76697 +++ b/include/linux/extcon.h
76698 @@ -135,7 +135,7 @@ struct extcon_dev {
76699 /* /sys/class/extcon/.../mutually_exclusive/... */
76700 struct attribute_group attr_g_muex;
76701 struct attribute **attrs_muex;
76702 - struct device_attribute *d_attrs_muex;
76703 + device_attribute_no_const *d_attrs_muex;
76704 };
76705
76706 /**
76707 diff --git a/include/linux/fb.h b/include/linux/fb.h
76708 index 70c4836..ff3daec 100644
76709 --- a/include/linux/fb.h
76710 +++ b/include/linux/fb.h
76711 @@ -304,7 +304,7 @@ struct fb_ops {
76712 /* called at KDB enter and leave time to prepare the console */
76713 int (*fb_debug_enter)(struct fb_info *info);
76714 int (*fb_debug_leave)(struct fb_info *info);
76715 -};
76716 +} __do_const;
76717
76718 #ifdef CONFIG_FB_TILEBLITTING
76719 #define FB_TILE_CURSOR_NONE 0
76720 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
76721 index 085197b..0fa6f0b 100644
76722 --- a/include/linux/fdtable.h
76723 +++ b/include/linux/fdtable.h
76724 @@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
76725 void put_files_struct(struct files_struct *fs);
76726 void reset_files_struct(struct files_struct *);
76727 int unshare_files(struct files_struct **);
76728 -struct files_struct *dup_fd(struct files_struct *, int *);
76729 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
76730 void do_close_on_exec(struct files_struct *);
76731 int iterate_fd(struct files_struct *, unsigned,
76732 int (*)(const void *, struct file *, unsigned),
76733 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
76734 index 8293262..2b3b8bd 100644
76735 --- a/include/linux/frontswap.h
76736 +++ b/include/linux/frontswap.h
76737 @@ -11,7 +11,7 @@ struct frontswap_ops {
76738 int (*load)(unsigned, pgoff_t, struct page *);
76739 void (*invalidate_page)(unsigned, pgoff_t);
76740 void (*invalidate_area)(unsigned);
76741 -};
76742 +} __no_const;
76743
76744 extern bool frontswap_enabled;
76745 extern struct frontswap_ops *
76746 diff --git a/include/linux/fs.h b/include/linux/fs.h
76747 index 121f11f..0f2a863 100644
76748 --- a/include/linux/fs.h
76749 +++ b/include/linux/fs.h
76750 @@ -423,7 +423,7 @@ struct address_space {
76751 spinlock_t private_lock; /* for use by the address_space */
76752 struct list_head private_list; /* ditto */
76753 void *private_data; /* ditto */
76754 -} __attribute__((aligned(sizeof(long))));
76755 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
76756 /*
76757 * On most architectures that alignment is already the case; but
76758 * must be enforced here for CRIS, to let the least significant bit
76759 @@ -466,7 +466,7 @@ struct block_device {
76760 int bd_fsfreeze_count;
76761 /* Mutex for freeze */
76762 struct mutex bd_fsfreeze_mutex;
76763 -};
76764 +} __randomize_layout;
76765
76766 /*
76767 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
76768 @@ -610,7 +610,7 @@ struct inode {
76769 atomic_t i_readcount; /* struct files open RO */
76770 #endif
76771 void *i_private; /* fs or device private pointer */
76772 -};
76773 +} __randomize_layout;
76774
76775 static inline int inode_unhashed(struct inode *inode)
76776 {
76777 @@ -808,7 +808,7 @@ struct file {
76778 #ifdef CONFIG_DEBUG_WRITECOUNT
76779 unsigned long f_mnt_write_state;
76780 #endif
76781 -};
76782 +} __randomize_layout;
76783
76784 struct file_handle {
76785 __u32 handle_bytes;
76786 @@ -978,7 +978,7 @@ struct file_lock {
76787 int state; /* state of grant or error if -ve */
76788 } afs;
76789 } fl_u;
76790 -};
76791 +} __randomize_layout;
76792
76793 /* The following constant reflects the upper bound of the file/locking space */
76794 #ifndef OFFSET_MAX
76795 @@ -1325,7 +1325,7 @@ struct super_block {
76796 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
76797 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
76798 struct rcu_head rcu;
76799 -};
76800 +} __randomize_layout;
76801
76802 extern struct timespec current_fs_time(struct super_block *sb);
76803
76804 @@ -1547,7 +1547,8 @@ struct file_operations {
76805 long (*fallocate)(struct file *file, int mode, loff_t offset,
76806 loff_t len);
76807 int (*show_fdinfo)(struct seq_file *m, struct file *f);
76808 -};
76809 +} __do_const __randomize_layout;
76810 +typedef struct file_operations __no_const file_operations_no_const;
76811
76812 struct inode_operations {
76813 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
76814 @@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
76815 return !IS_DEADDIR(inode);
76816 }
76817
76818 +static inline bool is_sidechannel_device(const struct inode *inode)
76819 +{
76820 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
76821 + umode_t mode = inode->i_mode;
76822 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
76823 +#else
76824 + return false;
76825 +#endif
76826 +}
76827 +
76828 #endif /* _LINUX_FS_H */
76829 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
76830 index 0efc3e6..fd23610 100644
76831 --- a/include/linux/fs_struct.h
76832 +++ b/include/linux/fs_struct.h
76833 @@ -6,13 +6,13 @@
76834 #include <linux/seqlock.h>
76835
76836 struct fs_struct {
76837 - int users;
76838 + atomic_t users;
76839 spinlock_t lock;
76840 seqcount_t seq;
76841 int umask;
76842 int in_exec;
76843 struct path root, pwd;
76844 -};
76845 +} __randomize_layout;
76846
76847 extern struct kmem_cache *fs_cachep;
76848
76849 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
76850 index 7714849..a4a5c7a 100644
76851 --- a/include/linux/fscache-cache.h
76852 +++ b/include/linux/fscache-cache.h
76853 @@ -113,7 +113,7 @@ struct fscache_operation {
76854 fscache_operation_release_t release;
76855 };
76856
76857 -extern atomic_t fscache_op_debug_id;
76858 +extern atomic_unchecked_t fscache_op_debug_id;
76859 extern void fscache_op_work_func(struct work_struct *work);
76860
76861 extern void fscache_enqueue_operation(struct fscache_operation *);
76862 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
76863 INIT_WORK(&op->work, fscache_op_work_func);
76864 atomic_set(&op->usage, 1);
76865 op->state = FSCACHE_OP_ST_INITIALISED;
76866 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
76867 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
76868 op->processor = processor;
76869 op->release = release;
76870 INIT_LIST_HEAD(&op->pend_link);
76871 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
76872 index 115bb81..e7b812b 100644
76873 --- a/include/linux/fscache.h
76874 +++ b/include/linux/fscache.h
76875 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
76876 * - this is mandatory for any object that may have data
76877 */
76878 void (*now_uncached)(void *cookie_netfs_data);
76879 -};
76880 +} __do_const;
76881
76882 /*
76883 * fscache cached network filesystem type
76884 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
76885 index 1c804b0..1432c2b 100644
76886 --- a/include/linux/fsnotify.h
76887 +++ b/include/linux/fsnotify.h
76888 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
76889 struct inode *inode = file_inode(file);
76890 __u32 mask = FS_ACCESS;
76891
76892 + if (is_sidechannel_device(inode))
76893 + return;
76894 +
76895 if (S_ISDIR(inode->i_mode))
76896 mask |= FS_ISDIR;
76897
76898 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
76899 struct inode *inode = file_inode(file);
76900 __u32 mask = FS_MODIFY;
76901
76902 + if (is_sidechannel_device(inode))
76903 + return;
76904 +
76905 if (S_ISDIR(inode->i_mode))
76906 mask |= FS_ISDIR;
76907
76908 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
76909 */
76910 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
76911 {
76912 - return kstrdup(name, GFP_KERNEL);
76913 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
76914 }
76915
76916 /*
76917 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
76918 index 9f3c275..8bdff5d 100644
76919 --- a/include/linux/genhd.h
76920 +++ b/include/linux/genhd.h
76921 @@ -194,7 +194,7 @@ struct gendisk {
76922 struct kobject *slave_dir;
76923
76924 struct timer_rand_state *random;
76925 - atomic_t sync_io; /* RAID */
76926 + atomic_unchecked_t sync_io; /* RAID */
76927 struct disk_events *ev;
76928 #ifdef CONFIG_BLK_DEV_INTEGRITY
76929 struct blk_integrity *integrity;
76930 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
76931 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
76932
76933 /* drivers/char/random.c */
76934 -extern void add_disk_randomness(struct gendisk *disk);
76935 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
76936 extern void rand_initialize_disk(struct gendisk *disk);
76937
76938 static inline sector_t get_start_sect(struct block_device *bdev)
76939 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
76940 index c0894dd..2fbf10c 100644
76941 --- a/include/linux/genl_magic_func.h
76942 +++ b/include/linux/genl_magic_func.h
76943 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
76944 },
76945
76946 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
76947 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
76948 +static struct genl_ops ZZZ_genl_ops[] = {
76949 #include GENL_MAGIC_INCLUDE_FILE
76950 };
76951
76952 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
76953 index 9b4dd49..61fd41d 100644
76954 --- a/include/linux/gfp.h
76955 +++ b/include/linux/gfp.h
76956 @@ -35,6 +35,13 @@ struct vm_area_struct;
76957 #define ___GFP_NO_KSWAPD 0x400000u
76958 #define ___GFP_OTHER_NODE 0x800000u
76959 #define ___GFP_WRITE 0x1000000u
76960 +
76961 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76962 +#define ___GFP_USERCOPY 0x2000000u
76963 +#else
76964 +#define ___GFP_USERCOPY 0
76965 +#endif
76966 +
76967 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
76968
76969 /*
76970 @@ -92,6 +99,7 @@ struct vm_area_struct;
76971 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
76972 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
76973 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
76974 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
76975
76976 /*
76977 * This may seem redundant, but it's a way of annotating false positives vs.
76978 @@ -99,7 +107,7 @@ struct vm_area_struct;
76979 */
76980 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
76981
76982 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
76983 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
76984 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
76985
76986 /* This equals 0, but use constants in case they ever change */
76987 @@ -153,6 +161,8 @@ struct vm_area_struct;
76988 /* 4GB DMA on some platforms */
76989 #define GFP_DMA32 __GFP_DMA32
76990
76991 +#define GFP_USERCOPY __GFP_USERCOPY
76992 +
76993 /* Convert GFP flags to their corresponding migrate type */
76994 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
76995 {
76996 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
76997 new file mode 100644
76998 index 0000000..edb2cb6
76999 --- /dev/null
77000 +++ b/include/linux/gracl.h
77001 @@ -0,0 +1,340 @@
77002 +#ifndef GR_ACL_H
77003 +#define GR_ACL_H
77004 +
77005 +#include <linux/grdefs.h>
77006 +#include <linux/resource.h>
77007 +#include <linux/capability.h>
77008 +#include <linux/dcache.h>
77009 +#include <asm/resource.h>
77010 +
77011 +/* Major status information */
77012 +
77013 +#define GR_VERSION "grsecurity 3.0"
77014 +#define GRSECURITY_VERSION 0x3000
77015 +
77016 +enum {
77017 + GR_SHUTDOWN = 0,
77018 + GR_ENABLE = 1,
77019 + GR_SPROLE = 2,
77020 + GR_OLDRELOAD = 3,
77021 + GR_SEGVMOD = 4,
77022 + GR_STATUS = 5,
77023 + GR_UNSPROLE = 6,
77024 + GR_PASSSET = 7,
77025 + GR_SPROLEPAM = 8,
77026 + GR_RELOAD = 9,
77027 +};
77028 +
77029 +/* Password setup definitions
77030 + * kernel/grhash.c */
77031 +enum {
77032 + GR_PW_LEN = 128,
77033 + GR_SALT_LEN = 16,
77034 + GR_SHA_LEN = 32,
77035 +};
77036 +
77037 +enum {
77038 + GR_SPROLE_LEN = 64,
77039 +};
77040 +
77041 +enum {
77042 + GR_NO_GLOB = 0,
77043 + GR_REG_GLOB,
77044 + GR_CREATE_GLOB
77045 +};
77046 +
77047 +#define GR_NLIMITS 32
77048 +
77049 +/* Begin Data Structures */
77050 +
77051 +struct sprole_pw {
77052 + unsigned char *rolename;
77053 + unsigned char salt[GR_SALT_LEN];
77054 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
77055 +};
77056 +
77057 +struct name_entry {
77058 + __u32 key;
77059 + ino_t inode;
77060 + dev_t device;
77061 + char *name;
77062 + __u16 len;
77063 + __u8 deleted;
77064 + struct name_entry *prev;
77065 + struct name_entry *next;
77066 +};
77067 +
77068 +struct inodev_entry {
77069 + struct name_entry *nentry;
77070 + struct inodev_entry *prev;
77071 + struct inodev_entry *next;
77072 +};
77073 +
77074 +struct acl_role_db {
77075 + struct acl_role_label **r_hash;
77076 + __u32 r_size;
77077 +};
77078 +
77079 +struct inodev_db {
77080 + struct inodev_entry **i_hash;
77081 + __u32 i_size;
77082 +};
77083 +
77084 +struct name_db {
77085 + struct name_entry **n_hash;
77086 + __u32 n_size;
77087 +};
77088 +
77089 +struct crash_uid {
77090 + uid_t uid;
77091 + unsigned long expires;
77092 +};
77093 +
77094 +struct gr_hash_struct {
77095 + void **table;
77096 + void **nametable;
77097 + void *first;
77098 + __u32 table_size;
77099 + __u32 used_size;
77100 + int type;
77101 +};
77102 +
77103 +/* Userspace Grsecurity ACL data structures */
77104 +
77105 +struct acl_subject_label {
77106 + char *filename;
77107 + ino_t inode;
77108 + dev_t device;
77109 + __u32 mode;
77110 + kernel_cap_t cap_mask;
77111 + kernel_cap_t cap_lower;
77112 + kernel_cap_t cap_invert_audit;
77113 +
77114 + struct rlimit res[GR_NLIMITS];
77115 + __u32 resmask;
77116 +
77117 + __u8 user_trans_type;
77118 + __u8 group_trans_type;
77119 + uid_t *user_transitions;
77120 + gid_t *group_transitions;
77121 + __u16 user_trans_num;
77122 + __u16 group_trans_num;
77123 +
77124 + __u32 sock_families[2];
77125 + __u32 ip_proto[8];
77126 + __u32 ip_type;
77127 + struct acl_ip_label **ips;
77128 + __u32 ip_num;
77129 + __u32 inaddr_any_override;
77130 +
77131 + __u32 crashes;
77132 + unsigned long expires;
77133 +
77134 + struct acl_subject_label *parent_subject;
77135 + struct gr_hash_struct *hash;
77136 + struct acl_subject_label *prev;
77137 + struct acl_subject_label *next;
77138 +
77139 + struct acl_object_label **obj_hash;
77140 + __u32 obj_hash_size;
77141 + __u16 pax_flags;
77142 +};
77143 +
77144 +struct role_allowed_ip {
77145 + __u32 addr;
77146 + __u32 netmask;
77147 +
77148 + struct role_allowed_ip *prev;
77149 + struct role_allowed_ip *next;
77150 +};
77151 +
77152 +struct role_transition {
77153 + char *rolename;
77154 +
77155 + struct role_transition *prev;
77156 + struct role_transition *next;
77157 +};
77158 +
77159 +struct acl_role_label {
77160 + char *rolename;
77161 + uid_t uidgid;
77162 + __u16 roletype;
77163 +
77164 + __u16 auth_attempts;
77165 + unsigned long expires;
77166 +
77167 + struct acl_subject_label *root_label;
77168 + struct gr_hash_struct *hash;
77169 +
77170 + struct acl_role_label *prev;
77171 + struct acl_role_label *next;
77172 +
77173 + struct role_transition *transitions;
77174 + struct role_allowed_ip *allowed_ips;
77175 + uid_t *domain_children;
77176 + __u16 domain_child_num;
77177 +
77178 + umode_t umask;
77179 +
77180 + struct acl_subject_label **subj_hash;
77181 + __u32 subj_hash_size;
77182 +};
77183 +
77184 +struct user_acl_role_db {
77185 + struct acl_role_label **r_table;
77186 + __u32 num_pointers; /* Number of allocations to track */
77187 + __u32 num_roles; /* Number of roles */
77188 + __u32 num_domain_children; /* Number of domain children */
77189 + __u32 num_subjects; /* Number of subjects */
77190 + __u32 num_objects; /* Number of objects */
77191 +};
77192 +
77193 +struct acl_object_label {
77194 + char *filename;
77195 + ino_t inode;
77196 + dev_t device;
77197 + __u32 mode;
77198 +
77199 + struct acl_subject_label *nested;
77200 + struct acl_object_label *globbed;
77201 +
77202 + /* next two structures not used */
77203 +
77204 + struct acl_object_label *prev;
77205 + struct acl_object_label *next;
77206 +};
77207 +
77208 +struct acl_ip_label {
77209 + char *iface;
77210 + __u32 addr;
77211 + __u32 netmask;
77212 + __u16 low, high;
77213 + __u8 mode;
77214 + __u32 type;
77215 + __u32 proto[8];
77216 +
77217 + /* next two structures not used */
77218 +
77219 + struct acl_ip_label *prev;
77220 + struct acl_ip_label *next;
77221 +};
77222 +
77223 +struct gr_arg {
77224 + struct user_acl_role_db role_db;
77225 + unsigned char pw[GR_PW_LEN];
77226 + unsigned char salt[GR_SALT_LEN];
77227 + unsigned char sum[GR_SHA_LEN];
77228 + unsigned char sp_role[GR_SPROLE_LEN];
77229 + struct sprole_pw *sprole_pws;
77230 + dev_t segv_device;
77231 + ino_t segv_inode;
77232 + uid_t segv_uid;
77233 + __u16 num_sprole_pws;
77234 + __u16 mode;
77235 +};
77236 +
77237 +struct gr_arg_wrapper {
77238 + struct gr_arg *arg;
77239 + __u32 version;
77240 + __u32 size;
77241 +};
77242 +
77243 +struct subject_map {
77244 + struct acl_subject_label *user;
77245 + struct acl_subject_label *kernel;
77246 + struct subject_map *prev;
77247 + struct subject_map *next;
77248 +};
77249 +
77250 +struct acl_subj_map_db {
77251 + struct subject_map **s_hash;
77252 + __u32 s_size;
77253 +};
77254 +
77255 +struct gr_policy_state {
77256 + struct sprole_pw **acl_special_roles;
77257 + __u16 num_sprole_pws;
77258 + struct acl_role_label *kernel_role;
77259 + struct acl_role_label *role_list;
77260 + struct acl_role_label *default_role;
77261 + struct acl_role_db acl_role_set;
77262 + struct acl_subj_map_db subj_map_set;
77263 + struct name_db name_set;
77264 + struct inodev_db inodev_set;
77265 +};
77266 +
77267 +struct gr_alloc_state {
77268 + unsigned long alloc_stack_next;
77269 + unsigned long alloc_stack_size;
77270 + void **alloc_stack;
77271 +};
77272 +
77273 +struct gr_reload_state {
77274 + struct gr_policy_state oldpolicy;
77275 + struct gr_alloc_state oldalloc;
77276 + struct gr_policy_state newpolicy;
77277 + struct gr_alloc_state newalloc;
77278 + struct gr_policy_state *oldpolicy_ptr;
77279 + struct gr_alloc_state *oldalloc_ptr;
77280 + unsigned char oldmode;
77281 +};
77282 +
77283 +/* End Data Structures Section */
77284 +
77285 +/* Hash functions generated by empirical testing by Brad Spengler
77286 + Makes good use of the low bits of the inode. Generally 0-1 times
77287 + in loop for successful match. 0-3 for unsuccessful match.
77288 + Shift/add algorithm with modulus of table size and an XOR*/
77289 +
77290 +static __inline__ unsigned int
77291 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
77292 +{
77293 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
77294 +}
77295 +
77296 + static __inline__ unsigned int
77297 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
77298 +{
77299 + return ((const unsigned long)userp % sz);
77300 +}
77301 +
77302 +static __inline__ unsigned int
77303 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
77304 +{
77305 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
77306 +}
77307 +
77308 +static __inline__ unsigned int
77309 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
77310 +{
77311 + return full_name_hash((const unsigned char *)name, len) % sz;
77312 +}
77313 +
77314 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
77315 + subj = NULL; \
77316 + iter = 0; \
77317 + while (iter < role->subj_hash_size) { \
77318 + if (subj == NULL) \
77319 + subj = role->subj_hash[iter]; \
77320 + if (subj == NULL) { \
77321 + iter++; \
77322 + continue; \
77323 + }
77324 +
77325 +#define FOR_EACH_SUBJECT_END(subj,iter) \
77326 + subj = subj->next; \
77327 + if (subj == NULL) \
77328 + iter++; \
77329 + }
77330 +
77331 +
77332 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
77333 + subj = role->hash->first; \
77334 + while (subj != NULL) {
77335 +
77336 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
77337 + subj = subj->next; \
77338 + }
77339 +
77340 +#endif
77341 +
77342 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
77343 new file mode 100644
77344 index 0000000..33ebd1f
77345 --- /dev/null
77346 +++ b/include/linux/gracl_compat.h
77347 @@ -0,0 +1,156 @@
77348 +#ifndef GR_ACL_COMPAT_H
77349 +#define GR_ACL_COMPAT_H
77350 +
77351 +#include <linux/resource.h>
77352 +#include <asm/resource.h>
77353 +
77354 +struct sprole_pw_compat {
77355 + compat_uptr_t rolename;
77356 + unsigned char salt[GR_SALT_LEN];
77357 + unsigned char sum[GR_SHA_LEN];
77358 +};
77359 +
77360 +struct gr_hash_struct_compat {
77361 + compat_uptr_t table;
77362 + compat_uptr_t nametable;
77363 + compat_uptr_t first;
77364 + __u32 table_size;
77365 + __u32 used_size;
77366 + int type;
77367 +};
77368 +
77369 +struct acl_subject_label_compat {
77370 + compat_uptr_t filename;
77371 + compat_ino_t inode;
77372 + __u32 device;
77373 + __u32 mode;
77374 + kernel_cap_t cap_mask;
77375 + kernel_cap_t cap_lower;
77376 + kernel_cap_t cap_invert_audit;
77377 +
77378 + struct compat_rlimit res[GR_NLIMITS];
77379 + __u32 resmask;
77380 +
77381 + __u8 user_trans_type;
77382 + __u8 group_trans_type;
77383 + compat_uptr_t user_transitions;
77384 + compat_uptr_t group_transitions;
77385 + __u16 user_trans_num;
77386 + __u16 group_trans_num;
77387 +
77388 + __u32 sock_families[2];
77389 + __u32 ip_proto[8];
77390 + __u32 ip_type;
77391 + compat_uptr_t ips;
77392 + __u32 ip_num;
77393 + __u32 inaddr_any_override;
77394 +
77395 + __u32 crashes;
77396 + compat_ulong_t expires;
77397 +
77398 + compat_uptr_t parent_subject;
77399 + compat_uptr_t hash;
77400 + compat_uptr_t prev;
77401 + compat_uptr_t next;
77402 +
77403 + compat_uptr_t obj_hash;
77404 + __u32 obj_hash_size;
77405 + __u16 pax_flags;
77406 +};
77407 +
77408 +struct role_allowed_ip_compat {
77409 + __u32 addr;
77410 + __u32 netmask;
77411 +
77412 + compat_uptr_t prev;
77413 + compat_uptr_t next;
77414 +};
77415 +
77416 +struct role_transition_compat {
77417 + compat_uptr_t rolename;
77418 +
77419 + compat_uptr_t prev;
77420 + compat_uptr_t next;
77421 +};
77422 +
77423 +struct acl_role_label_compat {
77424 + compat_uptr_t rolename;
77425 + uid_t uidgid;
77426 + __u16 roletype;
77427 +
77428 + __u16 auth_attempts;
77429 + compat_ulong_t expires;
77430 +
77431 + compat_uptr_t root_label;
77432 + compat_uptr_t hash;
77433 +
77434 + compat_uptr_t prev;
77435 + compat_uptr_t next;
77436 +
77437 + compat_uptr_t transitions;
77438 + compat_uptr_t allowed_ips;
77439 + compat_uptr_t domain_children;
77440 + __u16 domain_child_num;
77441 +
77442 + umode_t umask;
77443 +
77444 + compat_uptr_t subj_hash;
77445 + __u32 subj_hash_size;
77446 +};
77447 +
77448 +struct user_acl_role_db_compat {
77449 + compat_uptr_t r_table;
77450 + __u32 num_pointers;
77451 + __u32 num_roles;
77452 + __u32 num_domain_children;
77453 + __u32 num_subjects;
77454 + __u32 num_objects;
77455 +};
77456 +
77457 +struct acl_object_label_compat {
77458 + compat_uptr_t filename;
77459 + compat_ino_t inode;
77460 + __u32 device;
77461 + __u32 mode;
77462 +
77463 + compat_uptr_t nested;
77464 + compat_uptr_t globbed;
77465 +
77466 + compat_uptr_t prev;
77467 + compat_uptr_t next;
77468 +};
77469 +
77470 +struct acl_ip_label_compat {
77471 + compat_uptr_t iface;
77472 + __u32 addr;
77473 + __u32 netmask;
77474 + __u16 low, high;
77475 + __u8 mode;
77476 + __u32 type;
77477 + __u32 proto[8];
77478 +
77479 + compat_uptr_t prev;
77480 + compat_uptr_t next;
77481 +};
77482 +
77483 +struct gr_arg_compat {
77484 + struct user_acl_role_db_compat role_db;
77485 + unsigned char pw[GR_PW_LEN];
77486 + unsigned char salt[GR_SALT_LEN];
77487 + unsigned char sum[GR_SHA_LEN];
77488 + unsigned char sp_role[GR_SPROLE_LEN];
77489 + compat_uptr_t sprole_pws;
77490 + __u32 segv_device;
77491 + compat_ino_t segv_inode;
77492 + uid_t segv_uid;
77493 + __u16 num_sprole_pws;
77494 + __u16 mode;
77495 +};
77496 +
77497 +struct gr_arg_wrapper_compat {
77498 + compat_uptr_t arg;
77499 + __u32 version;
77500 + __u32 size;
77501 +};
77502 +
77503 +#endif
77504 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
77505 new file mode 100644
77506 index 0000000..323ecf2
77507 --- /dev/null
77508 +++ b/include/linux/gralloc.h
77509 @@ -0,0 +1,9 @@
77510 +#ifndef __GRALLOC_H
77511 +#define __GRALLOC_H
77512 +
77513 +void acl_free_all(void);
77514 +int acl_alloc_stack_init(unsigned long size);
77515 +void *acl_alloc(unsigned long len);
77516 +void *acl_alloc_num(unsigned long num, unsigned long len);
77517 +
77518 +#endif
77519 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
77520 new file mode 100644
77521 index 0000000..be66033
77522 --- /dev/null
77523 +++ b/include/linux/grdefs.h
77524 @@ -0,0 +1,140 @@
77525 +#ifndef GRDEFS_H
77526 +#define GRDEFS_H
77527 +
77528 +/* Begin grsecurity status declarations */
77529 +
77530 +enum {
77531 + GR_READY = 0x01,
77532 + GR_STATUS_INIT = 0x00 // disabled state
77533 +};
77534 +
77535 +/* Begin ACL declarations */
77536 +
77537 +/* Role flags */
77538 +
77539 +enum {
77540 + GR_ROLE_USER = 0x0001,
77541 + GR_ROLE_GROUP = 0x0002,
77542 + GR_ROLE_DEFAULT = 0x0004,
77543 + GR_ROLE_SPECIAL = 0x0008,
77544 + GR_ROLE_AUTH = 0x0010,
77545 + GR_ROLE_NOPW = 0x0020,
77546 + GR_ROLE_GOD = 0x0040,
77547 + GR_ROLE_LEARN = 0x0080,
77548 + GR_ROLE_TPE = 0x0100,
77549 + GR_ROLE_DOMAIN = 0x0200,
77550 + GR_ROLE_PAM = 0x0400,
77551 + GR_ROLE_PERSIST = 0x0800
77552 +};
77553 +
77554 +/* ACL Subject and Object mode flags */
77555 +enum {
77556 + GR_DELETED = 0x80000000
77557 +};
77558 +
77559 +/* ACL Object-only mode flags */
77560 +enum {
77561 + GR_READ = 0x00000001,
77562 + GR_APPEND = 0x00000002,
77563 + GR_WRITE = 0x00000004,
77564 + GR_EXEC = 0x00000008,
77565 + GR_FIND = 0x00000010,
77566 + GR_INHERIT = 0x00000020,
77567 + GR_SETID = 0x00000040,
77568 + GR_CREATE = 0x00000080,
77569 + GR_DELETE = 0x00000100,
77570 + GR_LINK = 0x00000200,
77571 + GR_AUDIT_READ = 0x00000400,
77572 + GR_AUDIT_APPEND = 0x00000800,
77573 + GR_AUDIT_WRITE = 0x00001000,
77574 + GR_AUDIT_EXEC = 0x00002000,
77575 + GR_AUDIT_FIND = 0x00004000,
77576 + GR_AUDIT_INHERIT= 0x00008000,
77577 + GR_AUDIT_SETID = 0x00010000,
77578 + GR_AUDIT_CREATE = 0x00020000,
77579 + GR_AUDIT_DELETE = 0x00040000,
77580 + GR_AUDIT_LINK = 0x00080000,
77581 + GR_PTRACERD = 0x00100000,
77582 + GR_NOPTRACE = 0x00200000,
77583 + GR_SUPPRESS = 0x00400000,
77584 + GR_NOLEARN = 0x00800000,
77585 + GR_INIT_TRANSFER= 0x01000000
77586 +};
77587 +
77588 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
77589 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
77590 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
77591 +
77592 +/* ACL subject-only mode flags */
77593 +enum {
77594 + GR_KILL = 0x00000001,
77595 + GR_VIEW = 0x00000002,
77596 + GR_PROTECTED = 0x00000004,
77597 + GR_LEARN = 0x00000008,
77598 + GR_OVERRIDE = 0x00000010,
77599 + /* just a placeholder, this mode is only used in userspace */
77600 + GR_DUMMY = 0x00000020,
77601 + GR_PROTSHM = 0x00000040,
77602 + GR_KILLPROC = 0x00000080,
77603 + GR_KILLIPPROC = 0x00000100,
77604 + /* just a placeholder, this mode is only used in userspace */
77605 + GR_NOTROJAN = 0x00000200,
77606 + GR_PROTPROCFD = 0x00000400,
77607 + GR_PROCACCT = 0x00000800,
77608 + GR_RELAXPTRACE = 0x00001000,
77609 + //GR_NESTED = 0x00002000,
77610 + GR_INHERITLEARN = 0x00004000,
77611 + GR_PROCFIND = 0x00008000,
77612 + GR_POVERRIDE = 0x00010000,
77613 + GR_KERNELAUTH = 0x00020000,
77614 + GR_ATSECURE = 0x00040000,
77615 + GR_SHMEXEC = 0x00080000
77616 +};
77617 +
77618 +enum {
77619 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
77620 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
77621 + GR_PAX_ENABLE_MPROTECT = 0x0004,
77622 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
77623 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
77624 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
77625 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
77626 + GR_PAX_DISABLE_MPROTECT = 0x0400,
77627 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
77628 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
77629 +};
77630 +
77631 +enum {
77632 + GR_ID_USER = 0x01,
77633 + GR_ID_GROUP = 0x02,
77634 +};
77635 +
77636 +enum {
77637 + GR_ID_ALLOW = 0x01,
77638 + GR_ID_DENY = 0x02,
77639 +};
77640 +
77641 +#define GR_CRASH_RES 31
77642 +#define GR_UIDTABLE_MAX 500
77643 +
77644 +/* begin resource learning section */
77645 +enum {
77646 + GR_RLIM_CPU_BUMP = 60,
77647 + GR_RLIM_FSIZE_BUMP = 50000,
77648 + GR_RLIM_DATA_BUMP = 10000,
77649 + GR_RLIM_STACK_BUMP = 1000,
77650 + GR_RLIM_CORE_BUMP = 10000,
77651 + GR_RLIM_RSS_BUMP = 500000,
77652 + GR_RLIM_NPROC_BUMP = 1,
77653 + GR_RLIM_NOFILE_BUMP = 5,
77654 + GR_RLIM_MEMLOCK_BUMP = 50000,
77655 + GR_RLIM_AS_BUMP = 500000,
77656 + GR_RLIM_LOCKS_BUMP = 2,
77657 + GR_RLIM_SIGPENDING_BUMP = 5,
77658 + GR_RLIM_MSGQUEUE_BUMP = 10000,
77659 + GR_RLIM_NICE_BUMP = 1,
77660 + GR_RLIM_RTPRIO_BUMP = 1,
77661 + GR_RLIM_RTTIME_BUMP = 1000000
77662 +};
77663 +
77664 +#endif
77665 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
77666 new file mode 100644
77667 index 0000000..d25522e
77668 --- /dev/null
77669 +++ b/include/linux/grinternal.h
77670 @@ -0,0 +1,229 @@
77671 +#ifndef __GRINTERNAL_H
77672 +#define __GRINTERNAL_H
77673 +
77674 +#ifdef CONFIG_GRKERNSEC
77675 +
77676 +#include <linux/fs.h>
77677 +#include <linux/mnt_namespace.h>
77678 +#include <linux/nsproxy.h>
77679 +#include <linux/gracl.h>
77680 +#include <linux/grdefs.h>
77681 +#include <linux/grmsg.h>
77682 +
77683 +void gr_add_learn_entry(const char *fmt, ...)
77684 + __attribute__ ((format (printf, 1, 2)));
77685 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
77686 + const struct vfsmount *mnt);
77687 +__u32 gr_check_create(const struct dentry *new_dentry,
77688 + const struct dentry *parent,
77689 + const struct vfsmount *mnt, const __u32 mode);
77690 +int gr_check_protected_task(const struct task_struct *task);
77691 +__u32 to_gr_audit(const __u32 reqmode);
77692 +int gr_set_acls(const int type);
77693 +int gr_acl_is_enabled(void);
77694 +char gr_roletype_to_char(void);
77695 +
77696 +void gr_handle_alertkill(struct task_struct *task);
77697 +char *gr_to_filename(const struct dentry *dentry,
77698 + const struct vfsmount *mnt);
77699 +char *gr_to_filename1(const struct dentry *dentry,
77700 + const struct vfsmount *mnt);
77701 +char *gr_to_filename2(const struct dentry *dentry,
77702 + const struct vfsmount *mnt);
77703 +char *gr_to_filename3(const struct dentry *dentry,
77704 + const struct vfsmount *mnt);
77705 +
77706 +extern int grsec_enable_ptrace_readexec;
77707 +extern int grsec_enable_harden_ptrace;
77708 +extern int grsec_enable_link;
77709 +extern int grsec_enable_fifo;
77710 +extern int grsec_enable_execve;
77711 +extern int grsec_enable_shm;
77712 +extern int grsec_enable_execlog;
77713 +extern int grsec_enable_signal;
77714 +extern int grsec_enable_audit_ptrace;
77715 +extern int grsec_enable_forkfail;
77716 +extern int grsec_enable_time;
77717 +extern int grsec_enable_rofs;
77718 +extern int grsec_deny_new_usb;
77719 +extern int grsec_enable_chroot_shmat;
77720 +extern int grsec_enable_chroot_mount;
77721 +extern int grsec_enable_chroot_double;
77722 +extern int grsec_enable_chroot_pivot;
77723 +extern int grsec_enable_chroot_chdir;
77724 +extern int grsec_enable_chroot_chmod;
77725 +extern int grsec_enable_chroot_mknod;
77726 +extern int grsec_enable_chroot_fchdir;
77727 +extern int grsec_enable_chroot_nice;
77728 +extern int grsec_enable_chroot_execlog;
77729 +extern int grsec_enable_chroot_caps;
77730 +extern int grsec_enable_chroot_sysctl;
77731 +extern int grsec_enable_chroot_unix;
77732 +extern int grsec_enable_symlinkown;
77733 +extern kgid_t grsec_symlinkown_gid;
77734 +extern int grsec_enable_tpe;
77735 +extern kgid_t grsec_tpe_gid;
77736 +extern int grsec_enable_tpe_all;
77737 +extern int grsec_enable_tpe_invert;
77738 +extern int grsec_enable_socket_all;
77739 +extern kgid_t grsec_socket_all_gid;
77740 +extern int grsec_enable_socket_client;
77741 +extern kgid_t grsec_socket_client_gid;
77742 +extern int grsec_enable_socket_server;
77743 +extern kgid_t grsec_socket_server_gid;
77744 +extern kgid_t grsec_audit_gid;
77745 +extern int grsec_enable_group;
77746 +extern int grsec_enable_log_rwxmaps;
77747 +extern int grsec_enable_mount;
77748 +extern int grsec_enable_chdir;
77749 +extern int grsec_resource_logging;
77750 +extern int grsec_enable_blackhole;
77751 +extern int grsec_lastack_retries;
77752 +extern int grsec_enable_brute;
77753 +extern int grsec_enable_harden_ipc;
77754 +extern int grsec_lock;
77755 +
77756 +extern spinlock_t grsec_alert_lock;
77757 +extern unsigned long grsec_alert_wtime;
77758 +extern unsigned long grsec_alert_fyet;
77759 +
77760 +extern spinlock_t grsec_audit_lock;
77761 +
77762 +extern rwlock_t grsec_exec_file_lock;
77763 +
77764 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
77765 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
77766 + (tsk)->exec_file->f_path.mnt) : "/")
77767 +
77768 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
77769 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
77770 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77771 +
77772 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
77773 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
77774 + (tsk)->exec_file->f_path.mnt) : "/")
77775 +
77776 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
77777 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
77778 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77779 +
77780 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
77781 +
77782 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
77783 +
77784 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
77785 +{
77786 + if (file1 && file2) {
77787 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
77788 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
77789 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
77790 + return true;
77791 + }
77792 +
77793 + return false;
77794 +}
77795 +
77796 +#define GR_CHROOT_CAPS {{ \
77797 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
77798 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
77799 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
77800 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
77801 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
77802 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
77803 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
77804 +
77805 +#define security_learn(normal_msg,args...) \
77806 +({ \
77807 + read_lock(&grsec_exec_file_lock); \
77808 + gr_add_learn_entry(normal_msg "\n", ## args); \
77809 + read_unlock(&grsec_exec_file_lock); \
77810 +})
77811 +
77812 +enum {
77813 + GR_DO_AUDIT,
77814 + GR_DONT_AUDIT,
77815 + /* used for non-audit messages that we shouldn't kill the task on */
77816 + GR_DONT_AUDIT_GOOD
77817 +};
77818 +
77819 +enum {
77820 + GR_TTYSNIFF,
77821 + GR_RBAC,
77822 + GR_RBAC_STR,
77823 + GR_STR_RBAC,
77824 + GR_RBAC_MODE2,
77825 + GR_RBAC_MODE3,
77826 + GR_FILENAME,
77827 + GR_SYSCTL_HIDDEN,
77828 + GR_NOARGS,
77829 + GR_ONE_INT,
77830 + GR_ONE_INT_TWO_STR,
77831 + GR_ONE_STR,
77832 + GR_STR_INT,
77833 + GR_TWO_STR_INT,
77834 + GR_TWO_INT,
77835 + GR_TWO_U64,
77836 + GR_THREE_INT,
77837 + GR_FIVE_INT_TWO_STR,
77838 + GR_TWO_STR,
77839 + GR_THREE_STR,
77840 + GR_FOUR_STR,
77841 + GR_STR_FILENAME,
77842 + GR_FILENAME_STR,
77843 + GR_FILENAME_TWO_INT,
77844 + GR_FILENAME_TWO_INT_STR,
77845 + GR_TEXTREL,
77846 + GR_PTRACE,
77847 + GR_RESOURCE,
77848 + GR_CAP,
77849 + GR_SIG,
77850 + GR_SIG2,
77851 + GR_CRASH1,
77852 + GR_CRASH2,
77853 + GR_PSACCT,
77854 + GR_RWXMAP,
77855 + GR_RWXMAPVMA
77856 +};
77857 +
77858 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
77859 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
77860 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
77861 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
77862 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
77863 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
77864 +#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)
77865 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
77866 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
77867 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
77868 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
77869 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
77870 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
77871 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
77872 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
77873 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
77874 +#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)
77875 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
77876 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
77877 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
77878 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
77879 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
77880 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
77881 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
77882 +#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)
77883 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
77884 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
77885 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
77886 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
77887 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
77888 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
77889 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
77890 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
77891 +#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)
77892 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
77893 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
77894 +
77895 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
77896 +
77897 +#endif
77898 +
77899 +#endif
77900 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
77901 new file mode 100644
77902 index 0000000..195cbe4
77903 --- /dev/null
77904 +++ b/include/linux/grmsg.h
77905 @@ -0,0 +1,115 @@
77906 +#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"
77907 +#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"
77908 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
77909 +#define GR_STOPMOD_MSG "denied modification of module state by "
77910 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
77911 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
77912 +#define GR_IOPERM_MSG "denied use of ioperm() by "
77913 +#define GR_IOPL_MSG "denied use of iopl() by "
77914 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
77915 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
77916 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
77917 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
77918 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
77919 +#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"
77920 +#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"
77921 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
77922 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
77923 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
77924 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
77925 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
77926 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
77927 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
77928 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
77929 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
77930 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
77931 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
77932 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
77933 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
77934 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
77935 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
77936 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
77937 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
77938 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
77939 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
77940 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
77941 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
77942 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
77943 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
77944 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
77945 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
77946 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
77947 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
77948 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
77949 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
77950 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
77951 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
77952 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
77953 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
77954 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
77955 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
77956 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
77957 +#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"
77958 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
77959 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
77960 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
77961 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
77962 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
77963 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
77964 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
77965 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
77966 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
77967 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
77968 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
77969 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
77970 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
77971 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
77972 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
77973 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
77974 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
77975 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
77976 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
77977 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
77978 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
77979 +#define GR_NICE_CHROOT_MSG "denied priority change by "
77980 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
77981 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
77982 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
77983 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
77984 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
77985 +#define GR_TIME_MSG "time set by "
77986 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
77987 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
77988 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
77989 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
77990 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
77991 +#define GR_BIND_MSG "denied bind() by "
77992 +#define GR_CONNECT_MSG "denied connect() by "
77993 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
77994 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
77995 +#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"
77996 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
77997 +#define GR_CAP_ACL_MSG "use of %s denied for "
77998 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
77999 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78000 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78001 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78002 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78003 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78004 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78005 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78006 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78007 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78008 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78009 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78010 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78011 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78012 +#define GR_VM86_MSG "denied use of vm86 by "
78013 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78014 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78015 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78016 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78017 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78018 +#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 "
78019 +#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 "
78020 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78021 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78022 new file mode 100644
78023 index 0000000..d8b5b48
78024 --- /dev/null
78025 +++ b/include/linux/grsecurity.h
78026 @@ -0,0 +1,245 @@
78027 +#ifndef GR_SECURITY_H
78028 +#define GR_SECURITY_H
78029 +#include <linux/fs.h>
78030 +#include <linux/fs_struct.h>
78031 +#include <linux/binfmts.h>
78032 +#include <linux/gracl.h>
78033 +
78034 +/* notify of brain-dead configs */
78035 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78036 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
78037 +#endif
78038 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
78039 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
78040 +#endif
78041 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
78042 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
78043 +#endif
78044 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
78045 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
78046 +#endif
78047 +
78048 +int gr_handle_new_usb(void);
78049 +
78050 +void gr_handle_brute_attach(int dumpable);
78051 +void gr_handle_brute_check(void);
78052 +void gr_handle_kernel_exploit(void);
78053 +
78054 +char gr_roletype_to_char(void);
78055 +
78056 +int gr_acl_enable_at_secure(void);
78057 +
78058 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
78059 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
78060 +
78061 +void gr_del_task_from_ip_table(struct task_struct *p);
78062 +
78063 +int gr_pid_is_chrooted(struct task_struct *p);
78064 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
78065 +int gr_handle_chroot_nice(void);
78066 +int gr_handle_chroot_sysctl(const int op);
78067 +int gr_handle_chroot_setpriority(struct task_struct *p,
78068 + const int niceval);
78069 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
78070 +int gr_handle_chroot_chroot(const struct dentry *dentry,
78071 + const struct vfsmount *mnt);
78072 +void gr_handle_chroot_chdir(const struct path *path);
78073 +int gr_handle_chroot_chmod(const struct dentry *dentry,
78074 + const struct vfsmount *mnt, const int mode);
78075 +int gr_handle_chroot_mknod(const struct dentry *dentry,
78076 + const struct vfsmount *mnt, const int mode);
78077 +int gr_handle_chroot_mount(const struct dentry *dentry,
78078 + const struct vfsmount *mnt,
78079 + const char *dev_name);
78080 +int gr_handle_chroot_pivot(void);
78081 +int gr_handle_chroot_unix(const pid_t pid);
78082 +
78083 +int gr_handle_rawio(const struct inode *inode);
78084 +
78085 +void gr_handle_ioperm(void);
78086 +void gr_handle_iopl(void);
78087 +
78088 +umode_t gr_acl_umask(void);
78089 +
78090 +int gr_tpe_allow(const struct file *file);
78091 +
78092 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
78093 +void gr_clear_chroot_entries(struct task_struct *task);
78094 +
78095 +void gr_log_forkfail(const int retval);
78096 +void gr_log_timechange(void);
78097 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
78098 +void gr_log_chdir(const struct dentry *dentry,
78099 + const struct vfsmount *mnt);
78100 +void gr_log_chroot_exec(const struct dentry *dentry,
78101 + const struct vfsmount *mnt);
78102 +void gr_log_remount(const char *devname, const int retval);
78103 +void gr_log_unmount(const char *devname, const int retval);
78104 +void gr_log_mount(const char *from, const char *to, const int retval);
78105 +void gr_log_textrel(struct vm_area_struct *vma);
78106 +void gr_log_ptgnustack(struct file *file);
78107 +void gr_log_rwxmmap(struct file *file);
78108 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
78109 +
78110 +int gr_handle_follow_link(const struct inode *parent,
78111 + const struct inode *inode,
78112 + const struct dentry *dentry,
78113 + const struct vfsmount *mnt);
78114 +int gr_handle_fifo(const struct dentry *dentry,
78115 + const struct vfsmount *mnt,
78116 + const struct dentry *dir, const int flag,
78117 + const int acc_mode);
78118 +int gr_handle_hardlink(const struct dentry *dentry,
78119 + const struct vfsmount *mnt,
78120 + struct inode *inode,
78121 + const int mode, const struct filename *to);
78122 +
78123 +int gr_is_capable(const int cap);
78124 +int gr_is_capable_nolog(const int cap);
78125 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
78126 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
78127 +
78128 +void gr_copy_label(struct task_struct *tsk);
78129 +void gr_handle_crash(struct task_struct *task, const int sig);
78130 +int gr_handle_signal(const struct task_struct *p, const int sig);
78131 +int gr_check_crash_uid(const kuid_t uid);
78132 +int gr_check_protected_task(const struct task_struct *task);
78133 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
78134 +int gr_acl_handle_mmap(const struct file *file,
78135 + const unsigned long prot);
78136 +int gr_acl_handle_mprotect(const struct file *file,
78137 + const unsigned long prot);
78138 +int gr_check_hidden_task(const struct task_struct *tsk);
78139 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
78140 + const struct vfsmount *mnt);
78141 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
78142 + const struct vfsmount *mnt);
78143 +__u32 gr_acl_handle_access(const struct dentry *dentry,
78144 + const struct vfsmount *mnt, const int fmode);
78145 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
78146 + const struct vfsmount *mnt, umode_t *mode);
78147 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
78148 + const struct vfsmount *mnt);
78149 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
78150 + const struct vfsmount *mnt);
78151 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
78152 + const struct vfsmount *mnt);
78153 +int gr_handle_ptrace(struct task_struct *task, const long request);
78154 +int gr_handle_proc_ptrace(struct task_struct *task);
78155 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
78156 + const struct vfsmount *mnt);
78157 +int gr_check_crash_exec(const struct file *filp);
78158 +int gr_acl_is_enabled(void);
78159 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
78160 + const kgid_t gid);
78161 +int gr_set_proc_label(const struct dentry *dentry,
78162 + const struct vfsmount *mnt,
78163 + const int unsafe_flags);
78164 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
78165 + const struct vfsmount *mnt);
78166 +__u32 gr_acl_handle_open(const struct dentry *dentry,
78167 + const struct vfsmount *mnt, int acc_mode);
78168 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
78169 + const struct dentry *p_dentry,
78170 + const struct vfsmount *p_mnt,
78171 + int open_flags, int acc_mode, const int imode);
78172 +void gr_handle_create(const struct dentry *dentry,
78173 + const struct vfsmount *mnt);
78174 +void gr_handle_proc_create(const struct dentry *dentry,
78175 + const struct inode *inode);
78176 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
78177 + const struct dentry *parent_dentry,
78178 + const struct vfsmount *parent_mnt,
78179 + const int mode);
78180 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
78181 + const struct dentry *parent_dentry,
78182 + const struct vfsmount *parent_mnt);
78183 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
78184 + const struct vfsmount *mnt);
78185 +void gr_handle_delete(const ino_t ino, const dev_t dev);
78186 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
78187 + const struct vfsmount *mnt);
78188 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
78189 + const struct dentry *parent_dentry,
78190 + const struct vfsmount *parent_mnt,
78191 + const struct filename *from);
78192 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
78193 + const struct dentry *parent_dentry,
78194 + const struct vfsmount *parent_mnt,
78195 + const struct dentry *old_dentry,
78196 + const struct vfsmount *old_mnt, const struct filename *to);
78197 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
78198 +int gr_acl_handle_rename(struct dentry *new_dentry,
78199 + struct dentry *parent_dentry,
78200 + const struct vfsmount *parent_mnt,
78201 + struct dentry *old_dentry,
78202 + struct inode *old_parent_inode,
78203 + struct vfsmount *old_mnt, const struct filename *newname);
78204 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
78205 + struct dentry *old_dentry,
78206 + struct dentry *new_dentry,
78207 + struct vfsmount *mnt, const __u8 replace);
78208 +__u32 gr_check_link(const struct dentry *new_dentry,
78209 + const struct dentry *parent_dentry,
78210 + const struct vfsmount *parent_mnt,
78211 + const struct dentry *old_dentry,
78212 + const struct vfsmount *old_mnt);
78213 +int gr_acl_handle_filldir(const struct file *file, const char *name,
78214 + const unsigned int namelen, const ino_t ino);
78215 +
78216 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
78217 + const struct vfsmount *mnt);
78218 +void gr_acl_handle_exit(void);
78219 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
78220 +int gr_acl_handle_procpidmem(const struct task_struct *task);
78221 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
78222 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
78223 +void gr_audit_ptrace(struct task_struct *task);
78224 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
78225 +void gr_put_exec_file(struct task_struct *task);
78226 +
78227 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
78228 +
78229 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
78230 +extern void gr_learn_resource(const struct task_struct *task, const int res,
78231 + const unsigned long wanted, const int gt);
78232 +#else
78233 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
78234 + const unsigned long wanted, const int gt)
78235 +{
78236 +}
78237 +#endif
78238 +
78239 +#ifdef CONFIG_GRKERNSEC_RESLOG
78240 +extern void gr_log_resource(const struct task_struct *task, const int res,
78241 + const unsigned long wanted, const int gt);
78242 +#else
78243 +static inline void gr_log_resource(const struct task_struct *task, const int res,
78244 + const unsigned long wanted, const int gt)
78245 +{
78246 +}
78247 +#endif
78248 +
78249 +#ifdef CONFIG_GRKERNSEC
78250 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
78251 +void gr_handle_vm86(void);
78252 +void gr_handle_mem_readwrite(u64 from, u64 to);
78253 +
78254 +void gr_log_badprocpid(const char *entry);
78255 +
78256 +extern int grsec_enable_dmesg;
78257 +extern int grsec_disable_privio;
78258 +
78259 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78260 +extern kgid_t grsec_proc_gid;
78261 +#endif
78262 +
78263 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78264 +extern int grsec_enable_chroot_findtask;
78265 +#endif
78266 +#ifdef CONFIG_GRKERNSEC_SETXID
78267 +extern int grsec_enable_setxid;
78268 +#endif
78269 +#endif
78270 +
78271 +#endif
78272 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
78273 new file mode 100644
78274 index 0000000..e7ffaaf
78275 --- /dev/null
78276 +++ b/include/linux/grsock.h
78277 @@ -0,0 +1,19 @@
78278 +#ifndef __GRSOCK_H
78279 +#define __GRSOCK_H
78280 +
78281 +extern void gr_attach_curr_ip(const struct sock *sk);
78282 +extern int gr_handle_sock_all(const int family, const int type,
78283 + const int protocol);
78284 +extern int gr_handle_sock_server(const struct sockaddr *sck);
78285 +extern int gr_handle_sock_server_other(const struct sock *sck);
78286 +extern int gr_handle_sock_client(const struct sockaddr *sck);
78287 +extern int gr_search_connect(struct socket * sock,
78288 + struct sockaddr_in * addr);
78289 +extern int gr_search_bind(struct socket * sock,
78290 + struct sockaddr_in * addr);
78291 +extern int gr_search_listen(struct socket * sock);
78292 +extern int gr_search_accept(struct socket * sock);
78293 +extern int gr_search_socket(const int domain, const int type,
78294 + const int protocol);
78295 +
78296 +#endif
78297 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
78298 index 7fb31da..08b5114 100644
78299 --- a/include/linux/highmem.h
78300 +++ b/include/linux/highmem.h
78301 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
78302 kunmap_atomic(kaddr);
78303 }
78304
78305 +static inline void sanitize_highpage(struct page *page)
78306 +{
78307 + void *kaddr;
78308 + unsigned long flags;
78309 +
78310 + local_irq_save(flags);
78311 + kaddr = kmap_atomic(page);
78312 + clear_page(kaddr);
78313 + kunmap_atomic(kaddr);
78314 + local_irq_restore(flags);
78315 +}
78316 +
78317 static inline void zero_user_segments(struct page *page,
78318 unsigned start1, unsigned end1,
78319 unsigned start2, unsigned end2)
78320 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
78321 index 1c7b89a..7dda400 100644
78322 --- a/include/linux/hwmon-sysfs.h
78323 +++ b/include/linux/hwmon-sysfs.h
78324 @@ -25,7 +25,8 @@
78325 struct sensor_device_attribute{
78326 struct device_attribute dev_attr;
78327 int index;
78328 -};
78329 +} __do_const;
78330 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
78331 #define to_sensor_dev_attr(_dev_attr) \
78332 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
78333
78334 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
78335 struct device_attribute dev_attr;
78336 u8 index;
78337 u8 nr;
78338 -};
78339 +} __do_const;
78340 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
78341 #define to_sensor_dev_attr_2(_dev_attr) \
78342 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
78343
78344 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
78345 index d9c8dbd3..def6e5a 100644
78346 --- a/include/linux/i2c.h
78347 +++ b/include/linux/i2c.h
78348 @@ -364,6 +364,7 @@ struct i2c_algorithm {
78349 /* To determine what the adapter supports */
78350 u32 (*functionality) (struct i2c_adapter *);
78351 };
78352 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
78353
78354 /**
78355 * struct i2c_bus_recovery_info - I2C bus recovery information
78356 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
78357 index d23c3c2..eb63c81 100644
78358 --- a/include/linux/i2o.h
78359 +++ b/include/linux/i2o.h
78360 @@ -565,7 +565,7 @@ struct i2o_controller {
78361 struct i2o_device *exec; /* Executive */
78362 #if BITS_PER_LONG == 64
78363 spinlock_t context_list_lock; /* lock for context_list */
78364 - atomic_t context_list_counter; /* needed for unique contexts */
78365 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
78366 struct list_head context_list; /* list of context id's
78367 and pointers */
78368 #endif
78369 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
78370 index aff7ad8..3942bbd 100644
78371 --- a/include/linux/if_pppox.h
78372 +++ b/include/linux/if_pppox.h
78373 @@ -76,7 +76,7 @@ struct pppox_proto {
78374 int (*ioctl)(struct socket *sock, unsigned int cmd,
78375 unsigned long arg);
78376 struct module *owner;
78377 -};
78378 +} __do_const;
78379
78380 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
78381 extern void unregister_pppox_proto(int proto_num);
78382 diff --git a/include/linux/init.h b/include/linux/init.h
78383 index 8e68a64..3f977a0 100644
78384 --- a/include/linux/init.h
78385 +++ b/include/linux/init.h
78386 @@ -37,9 +37,17 @@
78387 * section.
78388 */
78389
78390 +#define add_init_latent_entropy __latent_entropy
78391 +
78392 +#ifdef CONFIG_MEMORY_HOTPLUG
78393 +#define add_meminit_latent_entropy
78394 +#else
78395 +#define add_meminit_latent_entropy __latent_entropy
78396 +#endif
78397 +
78398 /* These are for everybody (although not all archs will actually
78399 discard it in modules) */
78400 -#define __init __section(.init.text) __cold notrace
78401 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
78402 #define __initdata __section(.init.data)
78403 #define __initconst __constsection(.init.rodata)
78404 #define __exitdata __section(.exit.data)
78405 @@ -100,7 +108,7 @@
78406 #define __cpuexitconst
78407
78408 /* Used for MEMORY_HOTPLUG */
78409 -#define __meminit __section(.meminit.text) __cold notrace
78410 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
78411 #define __meminitdata __section(.meminit.data)
78412 #define __meminitconst __constsection(.meminit.rodata)
78413 #define __memexit __section(.memexit.text) __exitused __cold notrace
78414 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
78415 index b0ed422..d79ea23 100644
78416 --- a/include/linux/init_task.h
78417 +++ b/include/linux/init_task.h
78418 @@ -154,6 +154,12 @@ extern struct task_group root_task_group;
78419
78420 #define INIT_TASK_COMM "swapper"
78421
78422 +#ifdef CONFIG_X86
78423 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
78424 +#else
78425 +#define INIT_TASK_THREAD_INFO
78426 +#endif
78427 +
78428 /*
78429 * INIT_TASK is used to set up the first task table, touch at
78430 * your own risk!. Base=0, limit=0x1fffff (=2MB)
78431 @@ -193,6 +199,7 @@ extern struct task_group root_task_group;
78432 RCU_POINTER_INITIALIZER(cred, &init_cred), \
78433 .comm = INIT_TASK_COMM, \
78434 .thread = INIT_THREAD, \
78435 + INIT_TASK_THREAD_INFO \
78436 .fs = &init_fs, \
78437 .files = &init_files, \
78438 .signal = &init_signals, \
78439 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
78440 index db43b58..5d5084b 100644
78441 --- a/include/linux/interrupt.h
78442 +++ b/include/linux/interrupt.h
78443 @@ -360,7 +360,7 @@ enum
78444 /* map softirq index to softirq name. update 'softirq_to_name' in
78445 * kernel/softirq.c when adding a new softirq.
78446 */
78447 -extern char *softirq_to_name[NR_SOFTIRQS];
78448 +extern const char * const softirq_to_name[NR_SOFTIRQS];
78449
78450 /* softirq mask and active fields moved to irq_cpustat_t in
78451 * asm/hardirq.h to get better cache usage. KAO
78452 @@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
78453
78454 struct softirq_action
78455 {
78456 - void (*action)(struct softirq_action *);
78457 -};
78458 + void (*action)(void);
78459 +} __no_const;
78460
78461 asmlinkage void do_softirq(void);
78462 asmlinkage void __do_softirq(void);
78463 @@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
78464 }
78465 #endif
78466
78467 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
78468 +extern void open_softirq(int nr, void (*action)(void));
78469 extern void softirq_init(void);
78470 extern void __raise_softirq_irqoff(unsigned int nr);
78471
78472 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
78473 index a444c79..8c41ea9 100644
78474 --- a/include/linux/iommu.h
78475 +++ b/include/linux/iommu.h
78476 @@ -130,7 +130,7 @@ struct iommu_ops {
78477 u32 (*domain_get_windows)(struct iommu_domain *domain);
78478
78479 unsigned long pgsize_bitmap;
78480 -};
78481 +} __do_const;
78482
78483 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
78484 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
78485 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
78486 index 89b7c24..382af74 100644
78487 --- a/include/linux/ioport.h
78488 +++ b/include/linux/ioport.h
78489 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
78490 int adjust_resource(struct resource *res, resource_size_t start,
78491 resource_size_t size);
78492 resource_size_t resource_alignment(struct resource *res);
78493 -static inline resource_size_t resource_size(const struct resource *res)
78494 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
78495 {
78496 return res->end - res->start + 1;
78497 }
78498 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
78499 index f6c82de..de8619e 100644
78500 --- a/include/linux/ipc_namespace.h
78501 +++ b/include/linux/ipc_namespace.h
78502 @@ -70,7 +70,7 @@ struct ipc_namespace {
78503 struct user_namespace *user_ns;
78504
78505 unsigned int proc_inum;
78506 -};
78507 +} __randomize_layout;
78508
78509 extern struct ipc_namespace init_ipc_ns;
78510 extern atomic_t nr_ipc_ns;
78511 diff --git a/include/linux/irq.h b/include/linux/irq.h
78512 index 7dc1003..407327b 100644
78513 --- a/include/linux/irq.h
78514 +++ b/include/linux/irq.h
78515 @@ -338,7 +338,8 @@ struct irq_chip {
78516 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
78517
78518 unsigned long flags;
78519 -};
78520 +} __do_const;
78521 +typedef struct irq_chip __no_const irq_chip_no_const;
78522
78523 /*
78524 * irq_chip specific flags
78525 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
78526 index cac496b..ffa0567 100644
78527 --- a/include/linux/irqchip/arm-gic.h
78528 +++ b/include/linux/irqchip/arm-gic.h
78529 @@ -61,9 +61,11 @@
78530
78531 #ifndef __ASSEMBLY__
78532
78533 +#include <linux/irq.h>
78534 +
78535 struct device_node;
78536
78537 -extern struct irq_chip gic_arch_extn;
78538 +extern irq_chip_no_const gic_arch_extn;
78539
78540 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
78541 u32 offset, struct device_node *);
78542 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
78543 index d235e88..8ccbe74 100644
78544 --- a/include/linux/jiffies.h
78545 +++ b/include/linux/jiffies.h
78546 @@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
78547 /*
78548 * Convert various time units to each other:
78549 */
78550 -extern unsigned int jiffies_to_msecs(const unsigned long j);
78551 -extern unsigned int jiffies_to_usecs(const unsigned long j);
78552 -extern unsigned long msecs_to_jiffies(const unsigned int m);
78553 -extern unsigned long usecs_to_jiffies(const unsigned int u);
78554 -extern unsigned long timespec_to_jiffies(const struct timespec *value);
78555 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
78556 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
78557 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
78558 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
78559 +extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
78560 extern void jiffies_to_timespec(const unsigned long jiffies,
78561 struct timespec *value);
78562 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
78563 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
78564 extern void jiffies_to_timeval(const unsigned long jiffies,
78565 struct timeval *value);
78566
78567 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
78568 index 6883e19..e854fcb 100644
78569 --- a/include/linux/kallsyms.h
78570 +++ b/include/linux/kallsyms.h
78571 @@ -15,7 +15,8 @@
78572
78573 struct module;
78574
78575 -#ifdef CONFIG_KALLSYMS
78576 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
78577 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
78578 /* Lookup the address for a symbol. Returns 0 if not found. */
78579 unsigned long kallsyms_lookup_name(const char *name);
78580
78581 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
78582 /* Stupid that this does nothing, but I didn't create this mess. */
78583 #define __print_symbol(fmt, addr)
78584 #endif /*CONFIG_KALLSYMS*/
78585 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
78586 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
78587 +extern unsigned long kallsyms_lookup_name(const char *name);
78588 +extern void __print_symbol(const char *fmt, unsigned long address);
78589 +extern int sprint_backtrace(char *buffer, unsigned long address);
78590 +extern int sprint_symbol(char *buffer, unsigned long address);
78591 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
78592 +const char *kallsyms_lookup(unsigned long addr,
78593 + unsigned long *symbolsize,
78594 + unsigned long *offset,
78595 + char **modname, char *namebuf);
78596 +extern int kallsyms_lookup_size_offset(unsigned long addr,
78597 + unsigned long *symbolsize,
78598 + unsigned long *offset);
78599 +#endif
78600
78601 /* This macro allows us to keep printk typechecking */
78602 static __printf(1, 2)
78603 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
78604 index a74c3a8..28d3f21 100644
78605 --- a/include/linux/key-type.h
78606 +++ b/include/linux/key-type.h
78607 @@ -131,7 +131,7 @@ struct key_type {
78608 /* internal fields */
78609 struct list_head link; /* link in types list */
78610 struct lock_class_key lock_class; /* key->sem lock class */
78611 -};
78612 +} __do_const;
78613
78614 extern struct key_type key_type_keyring;
78615
78616 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
78617 index dfb4f2f..7927e62 100644
78618 --- a/include/linux/kgdb.h
78619 +++ b/include/linux/kgdb.h
78620 @@ -52,7 +52,7 @@ extern int kgdb_connected;
78621 extern int kgdb_io_module_registered;
78622
78623 extern atomic_t kgdb_setting_breakpoint;
78624 -extern atomic_t kgdb_cpu_doing_single_step;
78625 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
78626
78627 extern struct task_struct *kgdb_usethread;
78628 extern struct task_struct *kgdb_contthread;
78629 @@ -254,7 +254,7 @@ struct kgdb_arch {
78630 void (*correct_hw_break)(void);
78631
78632 void (*enable_nmi)(bool on);
78633 -};
78634 +} __do_const;
78635
78636 /**
78637 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
78638 @@ -279,7 +279,7 @@ struct kgdb_io {
78639 void (*pre_exception) (void);
78640 void (*post_exception) (void);
78641 int is_console;
78642 -};
78643 +} __do_const;
78644
78645 extern struct kgdb_arch arch_kgdb_ops;
78646
78647 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
78648 index 0555cc6..40116ce 100644
78649 --- a/include/linux/kmod.h
78650 +++ b/include/linux/kmod.h
78651 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
78652 * usually useless though. */
78653 extern __printf(2, 3)
78654 int __request_module(bool wait, const char *name, ...);
78655 +extern __printf(3, 4)
78656 +int ___request_module(bool wait, char *param_name, const char *name, ...);
78657 #define request_module(mod...) __request_module(true, mod)
78658 #define request_module_nowait(mod...) __request_module(false, mod)
78659 #define try_then_request_module(x, mod...) \
78660 @@ -57,6 +59,9 @@ struct subprocess_info {
78661 struct work_struct work;
78662 struct completion *complete;
78663 char *path;
78664 +#ifdef CONFIG_GRKERNSEC
78665 + char *origpath;
78666 +#endif
78667 char **argv;
78668 char **envp;
78669 int wait;
78670 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
78671 index e7ba650..0af3acb 100644
78672 --- a/include/linux/kobject.h
78673 +++ b/include/linux/kobject.h
78674 @@ -116,7 +116,7 @@ struct kobj_type {
78675 struct attribute **default_attrs;
78676 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
78677 const void *(*namespace)(struct kobject *kobj);
78678 -};
78679 +} __do_const;
78680
78681 struct kobj_uevent_env {
78682 char *envp[UEVENT_NUM_ENVP];
78683 @@ -139,6 +139,7 @@ struct kobj_attribute {
78684 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
78685 const char *buf, size_t count);
78686 };
78687 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
78688
78689 extern const struct sysfs_ops kobj_sysfs_ops;
78690
78691 @@ -166,7 +167,7 @@ struct kset {
78692 spinlock_t list_lock;
78693 struct kobject kobj;
78694 const struct kset_uevent_ops *uevent_ops;
78695 -};
78696 +} __randomize_layout;
78697
78698 extern void kset_init(struct kset *kset);
78699 extern int __must_check kset_register(struct kset *kset);
78700 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
78701 index df32d25..fb52e27 100644
78702 --- a/include/linux/kobject_ns.h
78703 +++ b/include/linux/kobject_ns.h
78704 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
78705 const void *(*netlink_ns)(struct sock *sk);
78706 const void *(*initial_ns)(void);
78707 void (*drop_ns)(void *);
78708 -};
78709 +} __do_const;
78710
78711 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
78712 int kobj_ns_type_registered(enum kobj_ns_type type);
78713 diff --git a/include/linux/kref.h b/include/linux/kref.h
78714 index 484604d..0f6c5b6 100644
78715 --- a/include/linux/kref.h
78716 +++ b/include/linux/kref.h
78717 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
78718 static inline int kref_sub(struct kref *kref, unsigned int count,
78719 void (*release)(struct kref *kref))
78720 {
78721 - WARN_ON(release == NULL);
78722 + BUG_ON(release == NULL);
78723
78724 if (atomic_sub_and_test((int) count, &kref->refcount)) {
78725 release(kref);
78726 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
78727 index 9523d2a..16c0424 100644
78728 --- a/include/linux/kvm_host.h
78729 +++ b/include/linux/kvm_host.h
78730 @@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
78731 {
78732 }
78733 #endif
78734 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78735 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78736 struct module *module);
78737 void kvm_exit(void);
78738
78739 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
78740 struct kvm_guest_debug *dbg);
78741 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
78742
78743 -int kvm_arch_init(void *opaque);
78744 +int kvm_arch_init(const void *opaque);
78745 void kvm_arch_exit(void);
78746
78747 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
78748 diff --git a/include/linux/libata.h b/include/linux/libata.h
78749 index bec6dbe..2873d64 100644
78750 --- a/include/linux/libata.h
78751 +++ b/include/linux/libata.h
78752 @@ -975,7 +975,7 @@ struct ata_port_operations {
78753 * fields must be pointers.
78754 */
78755 const struct ata_port_operations *inherits;
78756 -};
78757 +} __do_const;
78758
78759 struct ata_port_info {
78760 unsigned long flags;
78761 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
78762 index d3e8ad2..a949f68 100644
78763 --- a/include/linux/linkage.h
78764 +++ b/include/linux/linkage.h
78765 @@ -31,6 +31,7 @@
78766 #endif
78767
78768 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
78769 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
78770 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
78771
78772 /*
78773 diff --git a/include/linux/list.h b/include/linux/list.h
78774 index ef95941..82db65a 100644
78775 --- a/include/linux/list.h
78776 +++ b/include/linux/list.h
78777 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
78778 extern void list_del(struct list_head *entry);
78779 #endif
78780
78781 +extern void __pax_list_add(struct list_head *new,
78782 + struct list_head *prev,
78783 + struct list_head *next);
78784 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
78785 +{
78786 + __pax_list_add(new, head, head->next);
78787 +}
78788 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
78789 +{
78790 + __pax_list_add(new, head->prev, head);
78791 +}
78792 +extern void pax_list_del(struct list_head *entry);
78793 +
78794 /**
78795 * list_replace - replace old entry by new one
78796 * @old : the element to be replaced
78797 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
78798 INIT_LIST_HEAD(entry);
78799 }
78800
78801 +extern void pax_list_del_init(struct list_head *entry);
78802 +
78803 /**
78804 * list_move - delete from one list and add as another's head
78805 * @list: the entry to move
78806 diff --git a/include/linux/math64.h b/include/linux/math64.h
78807 index c45c089..298841c 100644
78808 --- a/include/linux/math64.h
78809 +++ b/include/linux/math64.h
78810 @@ -15,7 +15,7 @@
78811 * This is commonly provided by 32bit archs to provide an optimized 64bit
78812 * divide.
78813 */
78814 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78815 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78816 {
78817 *remainder = dividend % divisor;
78818 return dividend / divisor;
78819 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
78820 /**
78821 * div64_u64 - unsigned 64bit divide with 64bit divisor
78822 */
78823 -static inline u64 div64_u64(u64 dividend, u64 divisor)
78824 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
78825 {
78826 return dividend / divisor;
78827 }
78828 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
78829 #define div64_ul(x, y) div_u64((x), (y))
78830
78831 #ifndef div_u64_rem
78832 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78833 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78834 {
78835 *remainder = do_div(dividend, divisor);
78836 return dividend;
78837 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
78838 #endif
78839
78840 #ifndef div64_u64
78841 -extern u64 div64_u64(u64 dividend, u64 divisor);
78842 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
78843 #endif
78844
78845 #ifndef div64_s64
78846 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
78847 * divide.
78848 */
78849 #ifndef div_u64
78850 -static inline u64 div_u64(u64 dividend, u32 divisor)
78851 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
78852 {
78853 u32 remainder;
78854 return div_u64_rem(dividend, divisor, &remainder);
78855 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
78856 index 9fe426b..8148be6 100644
78857 --- a/include/linux/mempolicy.h
78858 +++ b/include/linux/mempolicy.h
78859 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
78860 }
78861
78862 #define vma_policy(vma) ((vma)->vm_policy)
78863 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78864 +{
78865 + vma->vm_policy = pol;
78866 +}
78867
78868 static inline void mpol_get(struct mempolicy *pol)
78869 {
78870 @@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
78871 }
78872
78873 #define vma_policy(vma) NULL
78874 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78875 +{
78876 +}
78877
78878 static inline int
78879 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
78880 diff --git a/include/linux/mm.h b/include/linux/mm.h
78881 index 9fac6dd..158ca43 100644
78882 --- a/include/linux/mm.h
78883 +++ b/include/linux/mm.h
78884 @@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
78885 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
78886 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
78887 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
78888 +
78889 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
78890 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
78891 +#endif
78892 +
78893 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
78894
78895 #ifdef CONFIG_MEM_SOFT_DIRTY
78896 @@ -219,8 +224,8 @@ struct vm_operations_struct {
78897 /* called by access_process_vm when get_user_pages() fails, typically
78898 * for use by special VMAs that can switch between memory and hardware
78899 */
78900 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
78901 - void *buf, int len, int write);
78902 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
78903 + void *buf, size_t len, int write);
78904 #ifdef CONFIG_NUMA
78905 /*
78906 * set_policy() op must add a reference to any non-NULL @new mempolicy
78907 @@ -250,6 +255,7 @@ struct vm_operations_struct {
78908 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
78909 unsigned long size, pgoff_t pgoff);
78910 };
78911 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
78912
78913 struct mmu_gather;
78914 struct inode;
78915 @@ -1064,8 +1070,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
78916 unsigned long *pfn);
78917 int follow_phys(struct vm_area_struct *vma, unsigned long address,
78918 unsigned int flags, unsigned long *prot, resource_size_t *phys);
78919 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78920 - void *buf, int len, int write);
78921 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78922 + void *buf, size_t len, int write);
78923
78924 static inline void unmap_shared_mapping_range(struct address_space *mapping,
78925 loff_t const holebegin, loff_t const holelen)
78926 @@ -1104,9 +1110,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
78927 }
78928 #endif
78929
78930 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
78931 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
78932 - void *buf, int len, int write);
78933 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
78934 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
78935 + void *buf, size_t len, int write);
78936
78937 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
78938 unsigned long start, unsigned long nr_pages,
78939 @@ -1138,34 +1144,6 @@ int set_page_dirty(struct page *page);
78940 int set_page_dirty_lock(struct page *page);
78941 int clear_page_dirty_for_io(struct page *page);
78942
78943 -/* Is the vma a continuation of the stack vma above it? */
78944 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
78945 -{
78946 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
78947 -}
78948 -
78949 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
78950 - unsigned long addr)
78951 -{
78952 - return (vma->vm_flags & VM_GROWSDOWN) &&
78953 - (vma->vm_start == addr) &&
78954 - !vma_growsdown(vma->vm_prev, addr);
78955 -}
78956 -
78957 -/* Is the vma a continuation of the stack vma below it? */
78958 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
78959 -{
78960 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
78961 -}
78962 -
78963 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
78964 - unsigned long addr)
78965 -{
78966 - return (vma->vm_flags & VM_GROWSUP) &&
78967 - (vma->vm_end == addr) &&
78968 - !vma_growsup(vma->vm_next, addr);
78969 -}
78970 -
78971 extern pid_t
78972 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
78973
78974 @@ -1265,6 +1243,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
78975 }
78976 #endif
78977
78978 +#ifdef CONFIG_MMU
78979 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
78980 +#else
78981 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
78982 +{
78983 + return __pgprot(0);
78984 +}
78985 +#endif
78986 +
78987 int vma_wants_writenotify(struct vm_area_struct *vma);
78988
78989 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
78990 @@ -1283,8 +1270,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
78991 {
78992 return 0;
78993 }
78994 +
78995 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
78996 + unsigned long address)
78997 +{
78998 + return 0;
78999 +}
79000 #else
79001 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79002 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79003 #endif
79004
79005 #ifdef __PAGETABLE_PMD_FOLDED
79006 @@ -1293,8 +1287,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79007 {
79008 return 0;
79009 }
79010 +
79011 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79012 + unsigned long address)
79013 +{
79014 + return 0;
79015 +}
79016 #else
79017 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79018 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79019 #endif
79020
79021 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79022 @@ -1312,11 +1313,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79023 NULL: pud_offset(pgd, address);
79024 }
79025
79026 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79027 +{
79028 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79029 + NULL: pud_offset(pgd, address);
79030 +}
79031 +
79032 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79033 {
79034 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
79035 NULL: pmd_offset(pud, address);
79036 }
79037 +
79038 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79039 +{
79040 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
79041 + NULL: pmd_offset(pud, address);
79042 +}
79043 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
79044
79045 #if USE_SPLIT_PTE_PTLOCKS
79046 @@ -1694,7 +1707,7 @@ extern int install_special_mapping(struct mm_struct *mm,
79047 unsigned long addr, unsigned long len,
79048 unsigned long flags, struct page **pages);
79049
79050 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
79051 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
79052
79053 extern unsigned long mmap_region(struct file *file, unsigned long addr,
79054 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
79055 @@ -1702,6 +1715,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
79056 unsigned long len, unsigned long prot, unsigned long flags,
79057 unsigned long pgoff, unsigned long *populate);
79058 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
79059 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
79060
79061 #ifdef CONFIG_MMU
79062 extern int __mm_populate(unsigned long addr, unsigned long len,
79063 @@ -1730,10 +1744,11 @@ struct vm_unmapped_area_info {
79064 unsigned long high_limit;
79065 unsigned long align_mask;
79066 unsigned long align_offset;
79067 + unsigned long threadstack_offset;
79068 };
79069
79070 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
79071 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79072 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
79073 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
79074
79075 /*
79076 * Search for an unmapped address range.
79077 @@ -1745,7 +1760,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79078 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
79079 */
79080 static inline unsigned long
79081 -vm_unmapped_area(struct vm_unmapped_area_info *info)
79082 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
79083 {
79084 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
79085 return unmapped_area(info);
79086 @@ -1808,6 +1823,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
79087 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
79088 struct vm_area_struct **pprev);
79089
79090 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
79091 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
79092 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
79093 +
79094 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
79095 NULL if none. Assume start_addr < end_addr. */
79096 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
79097 @@ -1836,15 +1855,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
79098 return vma;
79099 }
79100
79101 -#ifdef CONFIG_MMU
79102 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
79103 -#else
79104 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
79105 -{
79106 - return __pgprot(0);
79107 -}
79108 -#endif
79109 -
79110 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
79111 unsigned long change_prot_numa(struct vm_area_struct *vma,
79112 unsigned long start, unsigned long end);
79113 @@ -1896,6 +1906,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
79114 static inline void vm_stat_account(struct mm_struct *mm,
79115 unsigned long flags, struct file *file, long pages)
79116 {
79117 +
79118 +#ifdef CONFIG_PAX_RANDMMAP
79119 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
79120 +#endif
79121 +
79122 mm->total_vm += pages;
79123 }
79124 #endif /* CONFIG_PROC_FS */
79125 @@ -1977,7 +1992,7 @@ extern int unpoison_memory(unsigned long pfn);
79126 extern int sysctl_memory_failure_early_kill;
79127 extern int sysctl_memory_failure_recovery;
79128 extern void shake_page(struct page *p, int access);
79129 -extern atomic_long_t num_poisoned_pages;
79130 +extern atomic_long_unchecked_t num_poisoned_pages;
79131 extern int soft_offline_page(struct page *page, int flags);
79132
79133 extern void dump_page(struct page *page);
79134 @@ -2014,5 +2029,11 @@ void __init setup_nr_node_ids(void);
79135 static inline void setup_nr_node_ids(void) {}
79136 #endif
79137
79138 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
79139 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
79140 +#else
79141 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
79142 +#endif
79143 +
79144 #endif /* __KERNEL__ */
79145 #endif /* _LINUX_MM_H */
79146 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
79147 index 290901a..e99b01c 100644
79148 --- a/include/linux/mm_types.h
79149 +++ b/include/linux/mm_types.h
79150 @@ -307,7 +307,9 @@ struct vm_area_struct {
79151 #ifdef CONFIG_NUMA
79152 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
79153 #endif
79154 -};
79155 +
79156 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
79157 +} __randomize_layout;
79158
79159 struct core_thread {
79160 struct task_struct *task;
79161 @@ -453,7 +455,25 @@ struct mm_struct {
79162 bool tlb_flush_pending;
79163 #endif
79164 struct uprobes_state uprobes_state;
79165 -};
79166 +
79167 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
79168 + unsigned long pax_flags;
79169 +#endif
79170 +
79171 +#ifdef CONFIG_PAX_DLRESOLVE
79172 + unsigned long call_dl_resolve;
79173 +#endif
79174 +
79175 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
79176 + unsigned long call_syscall;
79177 +#endif
79178 +
79179 +#ifdef CONFIG_PAX_ASLR
79180 + unsigned long delta_mmap; /* randomized offset */
79181 + unsigned long delta_stack; /* randomized offset */
79182 +#endif
79183 +
79184 +} __randomize_layout;
79185
79186 static inline void mm_init_cpumask(struct mm_struct *mm)
79187 {
79188 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
79189 index c5d5278..f0b68c8 100644
79190 --- a/include/linux/mmiotrace.h
79191 +++ b/include/linux/mmiotrace.h
79192 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
79193 /* Called from ioremap.c */
79194 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
79195 void __iomem *addr);
79196 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
79197 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
79198
79199 /* For anyone to insert markers. Remember trailing newline. */
79200 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
79201 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
79202 {
79203 }
79204
79205 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
79206 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
79207 {
79208 }
79209
79210 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
79211 index bd791e4..8617c34f 100644
79212 --- a/include/linux/mmzone.h
79213 +++ b/include/linux/mmzone.h
79214 @@ -396,7 +396,7 @@ struct zone {
79215 unsigned long flags; /* zone flags, see below */
79216
79217 /* Zone statistics */
79218 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79219 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79220
79221 /*
79222 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
79223 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
79224 index 45e9214..a7227d6 100644
79225 --- a/include/linux/mod_devicetable.h
79226 +++ b/include/linux/mod_devicetable.h
79227 @@ -13,7 +13,7 @@
79228 typedef unsigned long kernel_ulong_t;
79229 #endif
79230
79231 -#define PCI_ANY_ID (~0)
79232 +#define PCI_ANY_ID ((__u16)~0)
79233
79234 struct pci_device_id {
79235 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
79236 @@ -139,7 +139,7 @@ struct usb_device_id {
79237 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
79238 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
79239
79240 -#define HID_ANY_ID (~0)
79241 +#define HID_ANY_ID (~0U)
79242 #define HID_BUS_ANY 0xffff
79243 #define HID_GROUP_ANY 0x0000
79244
79245 @@ -467,7 +467,7 @@ struct dmi_system_id {
79246 const char *ident;
79247 struct dmi_strmatch matches[4];
79248 void *driver_data;
79249 -};
79250 +} __do_const;
79251 /*
79252 * struct dmi_device_id appears during expansion of
79253 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
79254 diff --git a/include/linux/module.h b/include/linux/module.h
79255 index 15cd6b1..f6e2e6a 100644
79256 --- a/include/linux/module.h
79257 +++ b/include/linux/module.h
79258 @@ -17,9 +17,11 @@
79259 #include <linux/moduleparam.h>
79260 #include <linux/tracepoint.h>
79261 #include <linux/export.h>
79262 +#include <linux/fs.h>
79263
79264 #include <linux/percpu.h>
79265 #include <asm/module.h>
79266 +#include <asm/pgtable.h>
79267
79268 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
79269 #define MODULE_SIG_STRING "~Module signature appended~\n"
79270 @@ -43,7 +45,7 @@ struct module_kobject {
79271 struct kobject *drivers_dir;
79272 struct module_param_attrs *mp;
79273 struct completion *kobj_completion;
79274 -};
79275 +} __randomize_layout;
79276
79277 struct module_attribute {
79278 struct attribute attr;
79279 @@ -55,12 +57,13 @@ struct module_attribute {
79280 int (*test)(struct module *);
79281 void (*free)(struct module *);
79282 };
79283 +typedef struct module_attribute __no_const module_attribute_no_const;
79284
79285 struct module_version_attribute {
79286 struct module_attribute mattr;
79287 const char *module_name;
79288 const char *version;
79289 -} __attribute__ ((__aligned__(sizeof(void *))));
79290 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
79291
79292 extern ssize_t __modver_version_show(struct module_attribute *,
79293 struct module_kobject *, char *);
79294 @@ -238,7 +241,7 @@ struct module
79295
79296 /* Sysfs stuff. */
79297 struct module_kobject mkobj;
79298 - struct module_attribute *modinfo_attrs;
79299 + module_attribute_no_const *modinfo_attrs;
79300 const char *version;
79301 const char *srcversion;
79302 struct kobject *holders_dir;
79303 @@ -287,19 +290,16 @@ struct module
79304 int (*init)(void);
79305
79306 /* If this is non-NULL, vfree after init() returns */
79307 - void *module_init;
79308 + void *module_init_rx, *module_init_rw;
79309
79310 /* Here is the actual code + data, vfree'd on unload. */
79311 - void *module_core;
79312 + void *module_core_rx, *module_core_rw;
79313
79314 /* Here are the sizes of the init and core sections */
79315 - unsigned int init_size, core_size;
79316 + unsigned int init_size_rw, core_size_rw;
79317
79318 /* The size of the executable code in each section. */
79319 - unsigned int init_text_size, core_text_size;
79320 -
79321 - /* Size of RO sections of the module (text+rodata) */
79322 - unsigned int init_ro_size, core_ro_size;
79323 + unsigned int init_size_rx, core_size_rx;
79324
79325 /* Arch-specific module values */
79326 struct mod_arch_specific arch;
79327 @@ -355,6 +355,10 @@ struct module
79328 #ifdef CONFIG_EVENT_TRACING
79329 struct ftrace_event_call **trace_events;
79330 unsigned int num_trace_events;
79331 + struct file_operations trace_id;
79332 + struct file_operations trace_enable;
79333 + struct file_operations trace_format;
79334 + struct file_operations trace_filter;
79335 #endif
79336 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
79337 unsigned int num_ftrace_callsites;
79338 @@ -378,7 +382,7 @@ struct module
79339 ctor_fn_t *ctors;
79340 unsigned int num_ctors;
79341 #endif
79342 -};
79343 +} __randomize_layout;
79344 #ifndef MODULE_ARCH_INIT
79345 #define MODULE_ARCH_INIT {}
79346 #endif
79347 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
79348 bool is_module_percpu_address(unsigned long addr);
79349 bool is_module_text_address(unsigned long addr);
79350
79351 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
79352 +{
79353 +
79354 +#ifdef CONFIG_PAX_KERNEXEC
79355 + if (ktla_ktva(addr) >= (unsigned long)start &&
79356 + ktla_ktva(addr) < (unsigned long)start + size)
79357 + return 1;
79358 +#endif
79359 +
79360 + return ((void *)addr >= start && (void *)addr < start + size);
79361 +}
79362 +
79363 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
79364 +{
79365 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
79366 +}
79367 +
79368 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
79369 +{
79370 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
79371 +}
79372 +
79373 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
79374 +{
79375 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
79376 +}
79377 +
79378 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
79379 +{
79380 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
79381 +}
79382 +
79383 static inline int within_module_core(unsigned long addr, const struct module *mod)
79384 {
79385 - return (unsigned long)mod->module_core <= addr &&
79386 - addr < (unsigned long)mod->module_core + mod->core_size;
79387 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
79388 }
79389
79390 static inline int within_module_init(unsigned long addr, const struct module *mod)
79391 {
79392 - return (unsigned long)mod->module_init <= addr &&
79393 - addr < (unsigned long)mod->module_init + mod->init_size;
79394 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
79395 }
79396
79397 /* Search for module by name: must hold module_mutex. */
79398 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
79399 index 560ca53..ef621ef 100644
79400 --- a/include/linux/moduleloader.h
79401 +++ b/include/linux/moduleloader.h
79402 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
79403 sections. Returns NULL on failure. */
79404 void *module_alloc(unsigned long size);
79405
79406 +#ifdef CONFIG_PAX_KERNEXEC
79407 +void *module_alloc_exec(unsigned long size);
79408 +#else
79409 +#define module_alloc_exec(x) module_alloc(x)
79410 +#endif
79411 +
79412 /* Free memory returned from module_alloc. */
79413 void module_free(struct module *mod, void *module_region);
79414
79415 +#ifdef CONFIG_PAX_KERNEXEC
79416 +void module_free_exec(struct module *mod, void *module_region);
79417 +#else
79418 +#define module_free_exec(x, y) module_free((x), (y))
79419 +#endif
79420 +
79421 /*
79422 * Apply the given relocation to the (simplified) ELF. Return -error
79423 * or 0.
79424 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
79425 unsigned int relsec,
79426 struct module *me)
79427 {
79428 +#ifdef CONFIG_MODULES
79429 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79430 +#endif
79431 return -ENOEXEC;
79432 }
79433 #endif
79434 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
79435 unsigned int relsec,
79436 struct module *me)
79437 {
79438 +#ifdef CONFIG_MODULES
79439 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79440 +#endif
79441 return -ENOEXEC;
79442 }
79443 #endif
79444 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
79445 index c3eb102..073c4a6 100644
79446 --- a/include/linux/moduleparam.h
79447 +++ b/include/linux/moduleparam.h
79448 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
79449 * @len is usually just sizeof(string).
79450 */
79451 #define module_param_string(name, string, len, perm) \
79452 - static const struct kparam_string __param_string_##name \
79453 + static const struct kparam_string __param_string_##name __used \
79454 = { len, string }; \
79455 __module_param_call(MODULE_PARAM_PREFIX, name, \
79456 &param_ops_string, \
79457 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
79458 */
79459 #define module_param_array_named(name, array, type, nump, perm) \
79460 param_check_##type(name, &(array)[0]); \
79461 - static const struct kparam_array __param_arr_##name \
79462 + static const struct kparam_array __param_arr_##name __used \
79463 = { .max = ARRAY_SIZE(array), .num = nump, \
79464 .ops = &param_ops_##type, \
79465 .elemsize = sizeof(array[0]), .elem = array }; \
79466 diff --git a/include/linux/mount.h b/include/linux/mount.h
79467 index 371d346..fba2819 100644
79468 --- a/include/linux/mount.h
79469 +++ b/include/linux/mount.h
79470 @@ -56,7 +56,7 @@ struct vfsmount {
79471 struct dentry *mnt_root; /* root of the mounted tree */
79472 struct super_block *mnt_sb; /* pointer to superblock */
79473 int mnt_flags;
79474 -};
79475 +} __randomize_layout;
79476
79477 struct file; /* forward dec */
79478
79479 diff --git a/include/linux/namei.h b/include/linux/namei.h
79480 index 492de72..1bddcd4 100644
79481 --- a/include/linux/namei.h
79482 +++ b/include/linux/namei.h
79483 @@ -19,7 +19,7 @@ struct nameidata {
79484 unsigned seq, m_seq;
79485 int last_type;
79486 unsigned depth;
79487 - char *saved_names[MAX_NESTED_LINKS + 1];
79488 + const char *saved_names[MAX_NESTED_LINKS + 1];
79489 };
79490
79491 /*
79492 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
79493
79494 extern void nd_jump_link(struct nameidata *nd, struct path *path);
79495
79496 -static inline void nd_set_link(struct nameidata *nd, char *path)
79497 +static inline void nd_set_link(struct nameidata *nd, const char *path)
79498 {
79499 nd->saved_names[nd->depth] = path;
79500 }
79501
79502 -static inline char *nd_get_link(struct nameidata *nd)
79503 +static inline const char *nd_get_link(const struct nameidata *nd)
79504 {
79505 return nd->saved_names[nd->depth];
79506 }
79507 diff --git a/include/linux/net.h b/include/linux/net.h
79508 index 69be3e6..0fb422d 100644
79509 --- a/include/linux/net.h
79510 +++ b/include/linux/net.h
79511 @@ -192,7 +192,7 @@ struct net_proto_family {
79512 int (*create)(struct net *net, struct socket *sock,
79513 int protocol, int kern);
79514 struct module *owner;
79515 -};
79516 +} __do_const;
79517
79518 struct iovec;
79519 struct kvec;
79520 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
79521 index ce2a1f5..cb9bc8c 100644
79522 --- a/include/linux/netdevice.h
79523 +++ b/include/linux/netdevice.h
79524 @@ -1129,6 +1129,7 @@ struct net_device_ops {
79525 struct net_device *dev,
79526 void *priv);
79527 };
79528 +typedef struct net_device_ops __no_const net_device_ops_no_const;
79529
79530 /*
79531 * The DEVICE structure.
79532 @@ -1211,7 +1212,7 @@ struct net_device {
79533 int iflink;
79534
79535 struct net_device_stats stats;
79536 - atomic_long_t rx_dropped; /* dropped packets by core network
79537 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
79538 * Do not use this in drivers.
79539 */
79540
79541 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
79542 index 2077489..a15e561 100644
79543 --- a/include/linux/netfilter.h
79544 +++ b/include/linux/netfilter.h
79545 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
79546 #endif
79547 /* Use the module struct to lock set/get code in place */
79548 struct module *owner;
79549 -};
79550 +} __do_const;
79551
79552 /* Function to register/unregister hook points. */
79553 int nf_register_hook(struct nf_hook_ops *reg);
79554 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
79555 index 28c7436..2d6156a 100644
79556 --- a/include/linux/netfilter/nfnetlink.h
79557 +++ b/include/linux/netfilter/nfnetlink.h
79558 @@ -19,7 +19,7 @@ struct nfnl_callback {
79559 const struct nlattr * const cda[]);
79560 const struct nla_policy *policy; /* netlink attribute policy */
79561 const u_int16_t attr_count; /* number of nlattr's */
79562 -};
79563 +} __do_const;
79564
79565 struct nfnetlink_subsystem {
79566 const char *name;
79567 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
79568 new file mode 100644
79569 index 0000000..33f4af8
79570 --- /dev/null
79571 +++ b/include/linux/netfilter/xt_gradm.h
79572 @@ -0,0 +1,9 @@
79573 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
79574 +#define _LINUX_NETFILTER_XT_GRADM_H 1
79575 +
79576 +struct xt_gradm_mtinfo {
79577 + __u16 flags;
79578 + __u16 invflags;
79579 +};
79580 +
79581 +#endif
79582 diff --git a/include/linux/nls.h b/include/linux/nls.h
79583 index 5dc635f..35f5e11 100644
79584 --- a/include/linux/nls.h
79585 +++ b/include/linux/nls.h
79586 @@ -31,7 +31,7 @@ struct nls_table {
79587 const unsigned char *charset2upper;
79588 struct module *owner;
79589 struct nls_table *next;
79590 -};
79591 +} __do_const;
79592
79593 /* this value hold the maximum octet of charset */
79594 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
79595 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
79596 index d14a4c3..a078786 100644
79597 --- a/include/linux/notifier.h
79598 +++ b/include/linux/notifier.h
79599 @@ -54,7 +54,8 @@ struct notifier_block {
79600 notifier_fn_t notifier_call;
79601 struct notifier_block __rcu *next;
79602 int priority;
79603 -};
79604 +} __do_const;
79605 +typedef struct notifier_block __no_const notifier_block_no_const;
79606
79607 struct atomic_notifier_head {
79608 spinlock_t lock;
79609 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
79610 index b2a0f15..4d7da32 100644
79611 --- a/include/linux/oprofile.h
79612 +++ b/include/linux/oprofile.h
79613 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
79614 int oprofilefs_create_ro_ulong(struct dentry * root,
79615 char const * name, ulong * val);
79616
79617 -/** Create a file for read-only access to an atomic_t. */
79618 +/** Create a file for read-only access to an atomic_unchecked_t. */
79619 int oprofilefs_create_ro_atomic(struct dentry * root,
79620 - char const * name, atomic_t * val);
79621 + char const * name, atomic_unchecked_t * val);
79622
79623 /** create a directory */
79624 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
79625 diff --git a/include/linux/padata.h b/include/linux/padata.h
79626 index 4386946..f50c615 100644
79627 --- a/include/linux/padata.h
79628 +++ b/include/linux/padata.h
79629 @@ -129,7 +129,7 @@ struct parallel_data {
79630 struct padata_serial_queue __percpu *squeue;
79631 atomic_t reorder_objects;
79632 atomic_t refcnt;
79633 - atomic_t seq_nr;
79634 + atomic_unchecked_t seq_nr;
79635 struct padata_cpumask cpumask;
79636 spinlock_t lock ____cacheline_aligned;
79637 unsigned int processed;
79638 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
79639 index a2e2f1d..8a391d2 100644
79640 --- a/include/linux/pci_hotplug.h
79641 +++ b/include/linux/pci_hotplug.h
79642 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
79643 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
79644 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
79645 int (*reset_slot) (struct hotplug_slot *slot, int probe);
79646 -};
79647 +} __do_const;
79648 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
79649
79650 /**
79651 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
79652 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
79653 index 2e069d1..27054b8 100644
79654 --- a/include/linux/perf_event.h
79655 +++ b/include/linux/perf_event.h
79656 @@ -327,8 +327,8 @@ struct perf_event {
79657
79658 enum perf_event_active_state state;
79659 unsigned int attach_state;
79660 - local64_t count;
79661 - atomic64_t child_count;
79662 + local64_t count; /* PaX: fix it one day */
79663 + atomic64_unchecked_t child_count;
79664
79665 /*
79666 * These are the total time in nanoseconds that the event
79667 @@ -379,8 +379,8 @@ struct perf_event {
79668 * These accumulate total time (in nanoseconds) that children
79669 * events have been enabled and running, respectively.
79670 */
79671 - atomic64_t child_total_time_enabled;
79672 - atomic64_t child_total_time_running;
79673 + atomic64_unchecked_t child_total_time_enabled;
79674 + atomic64_unchecked_t child_total_time_running;
79675
79676 /*
79677 * Protect attach/detach and child_list:
79678 @@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
79679 entry->ip[entry->nr++] = ip;
79680 }
79681
79682 -extern int sysctl_perf_event_paranoid;
79683 +extern int sysctl_perf_event_legitimately_concerned;
79684 extern int sysctl_perf_event_mlock;
79685 extern int sysctl_perf_event_sample_rate;
79686 extern int sysctl_perf_cpu_time_max_percent;
79687 @@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
79688 loff_t *ppos);
79689
79690
79691 +static inline bool perf_paranoid_any(void)
79692 +{
79693 + return sysctl_perf_event_legitimately_concerned > 2;
79694 +}
79695 +
79696 static inline bool perf_paranoid_tracepoint_raw(void)
79697 {
79698 - return sysctl_perf_event_paranoid > -1;
79699 + return sysctl_perf_event_legitimately_concerned > -1;
79700 }
79701
79702 static inline bool perf_paranoid_cpu(void)
79703 {
79704 - return sysctl_perf_event_paranoid > 0;
79705 + return sysctl_perf_event_legitimately_concerned > 0;
79706 }
79707
79708 static inline bool perf_paranoid_kernel(void)
79709 {
79710 - return sysctl_perf_event_paranoid > 1;
79711 + return sysctl_perf_event_legitimately_concerned > 1;
79712 }
79713
79714 extern void perf_event_init(void);
79715 @@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
79716 struct device_attribute attr;
79717 u64 id;
79718 const char *event_str;
79719 -};
79720 +} __do_const;
79721
79722 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
79723 static struct perf_pmu_events_attr _var = { \
79724 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
79725 index 7246ef3..1539ea4 100644
79726 --- a/include/linux/pid_namespace.h
79727 +++ b/include/linux/pid_namespace.h
79728 @@ -43,7 +43,7 @@ struct pid_namespace {
79729 int hide_pid;
79730 int reboot; /* group exit code if this pidns was rebooted */
79731 unsigned int proc_inum;
79732 -};
79733 +} __randomize_layout;
79734
79735 extern struct pid_namespace init_pid_ns;
79736
79737 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
79738 index b8809fe..ae4ccd0 100644
79739 --- a/include/linux/pipe_fs_i.h
79740 +++ b/include/linux/pipe_fs_i.h
79741 @@ -47,10 +47,10 @@ struct pipe_inode_info {
79742 struct mutex mutex;
79743 wait_queue_head_t wait;
79744 unsigned int nrbufs, curbuf, buffers;
79745 - unsigned int readers;
79746 - unsigned int writers;
79747 - unsigned int files;
79748 - unsigned int waiting_writers;
79749 + atomic_t readers;
79750 + atomic_t writers;
79751 + atomic_t files;
79752 + atomic_t waiting_writers;
79753 unsigned int r_counter;
79754 unsigned int w_counter;
79755 struct page *tmp_page;
79756 diff --git a/include/linux/pm.h b/include/linux/pm.h
79757 index a224c7f..92d8a97 100644
79758 --- a/include/linux/pm.h
79759 +++ b/include/linux/pm.h
79760 @@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
79761 struct dev_pm_domain {
79762 struct dev_pm_ops ops;
79763 };
79764 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
79765
79766 /*
79767 * The PM_EVENT_ messages are also used by drivers implementing the legacy
79768 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
79769 index 7c1d252..c5c773e 100644
79770 --- a/include/linux/pm_domain.h
79771 +++ b/include/linux/pm_domain.h
79772 @@ -48,7 +48,7 @@ struct gpd_dev_ops {
79773
79774 struct gpd_cpu_data {
79775 unsigned int saved_exit_latency;
79776 - struct cpuidle_state *idle_state;
79777 + cpuidle_state_no_const *idle_state;
79778 };
79779
79780 struct generic_pm_domain {
79781 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
79782 index 6fa7cea..7bf6415 100644
79783 --- a/include/linux/pm_runtime.h
79784 +++ b/include/linux/pm_runtime.h
79785 @@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
79786
79787 static inline void pm_runtime_mark_last_busy(struct device *dev)
79788 {
79789 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
79790 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
79791 }
79792
79793 #else /* !CONFIG_PM_RUNTIME */
79794 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
79795 index 195aafc..49a7bc2 100644
79796 --- a/include/linux/pnp.h
79797 +++ b/include/linux/pnp.h
79798 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
79799 struct pnp_fixup {
79800 char id[7];
79801 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
79802 -};
79803 +} __do_const;
79804
79805 /* config parameters */
79806 #define PNP_CONFIG_NORMAL 0x0001
79807 diff --git a/include/linux/poison.h b/include/linux/poison.h
79808 index 2110a81..13a11bb 100644
79809 --- a/include/linux/poison.h
79810 +++ b/include/linux/poison.h
79811 @@ -19,8 +19,8 @@
79812 * under normal circumstances, used to verify that nobody uses
79813 * non-initialized list entries.
79814 */
79815 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
79816 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
79817 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
79818 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
79819
79820 /********** include/linux/timer.h **********/
79821 /*
79822 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
79823 index d8b187c3..9a9257a 100644
79824 --- a/include/linux/power/smartreflex.h
79825 +++ b/include/linux/power/smartreflex.h
79826 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
79827 int (*notify)(struct omap_sr *sr, u32 status);
79828 u8 notify_flags;
79829 u8 class_type;
79830 -};
79831 +} __do_const;
79832
79833 /**
79834 * struct omap_sr_nvalue_table - Smartreflex n-target value info
79835 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
79836 index 4ea1d37..80f4b33 100644
79837 --- a/include/linux/ppp-comp.h
79838 +++ b/include/linux/ppp-comp.h
79839 @@ -84,7 +84,7 @@ struct compressor {
79840 struct module *owner;
79841 /* Extra skb space needed by the compressor algorithm */
79842 unsigned int comp_extra;
79843 -};
79844 +} __do_const;
79845
79846 /*
79847 * The return value from decompress routine is the length of the
79848 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
79849 index a3d9dc8..8af9922 100644
79850 --- a/include/linux/preempt.h
79851 +++ b/include/linux/preempt.h
79852 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
79853 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
79854 #endif
79855
79856 +#define raw_preempt_count_add(val) __preempt_count_add(val)
79857 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
79858 +
79859 #define __preempt_count_inc() __preempt_count_add(1)
79860 #define __preempt_count_dec() __preempt_count_sub(1)
79861
79862 #define preempt_count_inc() preempt_count_add(1)
79863 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
79864 #define preempt_count_dec() preempt_count_sub(1)
79865 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
79866
79867 #ifdef CONFIG_PREEMPT_COUNT
79868
79869 @@ -41,6 +46,12 @@ do { \
79870 barrier(); \
79871 } while (0)
79872
79873 +#define raw_preempt_disable() \
79874 +do { \
79875 + raw_preempt_count_inc(); \
79876 + barrier(); \
79877 +} while (0)
79878 +
79879 #define sched_preempt_enable_no_resched() \
79880 do { \
79881 barrier(); \
79882 @@ -49,6 +60,12 @@ do { \
79883
79884 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
79885
79886 +#define raw_preempt_enable_no_resched() \
79887 +do { \
79888 + barrier(); \
79889 + raw_preempt_count_dec(); \
79890 +} while (0)
79891 +
79892 #ifdef CONFIG_PREEMPT
79893 #define preempt_enable() \
79894 do { \
79895 @@ -105,8 +122,10 @@ do { \
79896 * region.
79897 */
79898 #define preempt_disable() barrier()
79899 +#define raw_preempt_disable() barrier()
79900 #define sched_preempt_enable_no_resched() barrier()
79901 #define preempt_enable_no_resched() barrier()
79902 +#define raw_preempt_enable_no_resched() barrier()
79903 #define preempt_enable() barrier()
79904 #define preempt_check_resched() do { } while (0)
79905
79906 diff --git a/include/linux/printk.h b/include/linux/printk.h
79907 index 6949258..7c4730e 100644
79908 --- a/include/linux/printk.h
79909 +++ b/include/linux/printk.h
79910 @@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
79911 void early_printk(const char *s, ...) { }
79912 #endif
79913
79914 +extern int kptr_restrict;
79915 +
79916 #ifdef CONFIG_PRINTK
79917 asmlinkage __printf(5, 0)
79918 int vprintk_emit(int facility, int level,
79919 @@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
79920
79921 extern int printk_delay_msec;
79922 extern int dmesg_restrict;
79923 -extern int kptr_restrict;
79924
79925 extern void wake_up_klogd(void);
79926
79927 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
79928 index 608e60a..c26f864 100644
79929 --- a/include/linux/proc_fs.h
79930 +++ b/include/linux/proc_fs.h
79931 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
79932 return proc_create_data(name, mode, parent, proc_fops, NULL);
79933 }
79934
79935 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
79936 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
79937 +{
79938 +#ifdef CONFIG_GRKERNSEC_PROC_USER
79939 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
79940 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79941 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
79942 +#else
79943 + return proc_create_data(name, mode, parent, proc_fops, NULL);
79944 +#endif
79945 +}
79946 +
79947 +
79948 extern void proc_set_size(struct proc_dir_entry *, loff_t);
79949 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
79950 extern void *PDE_DATA(const struct inode *);
79951 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
79952 index 34a1e10..70f6bde 100644
79953 --- a/include/linux/proc_ns.h
79954 +++ b/include/linux/proc_ns.h
79955 @@ -14,7 +14,7 @@ struct proc_ns_operations {
79956 void (*put)(void *ns);
79957 int (*install)(struct nsproxy *nsproxy, void *ns);
79958 unsigned int (*inum)(void *ns);
79959 -};
79960 +} __do_const __randomize_layout;
79961
79962 struct proc_ns {
79963 void *ns;
79964 diff --git a/include/linux/quota.h b/include/linux/quota.h
79965 index cc7494a..1e27036 100644
79966 --- a/include/linux/quota.h
79967 +++ b/include/linux/quota.h
79968 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
79969
79970 extern bool qid_eq(struct kqid left, struct kqid right);
79971 extern bool qid_lt(struct kqid left, struct kqid right);
79972 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
79973 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
79974 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
79975 extern bool qid_valid(struct kqid qid);
79976
79977 diff --git a/include/linux/random.h b/include/linux/random.h
79978 index 4002b3d..d5ad855 100644
79979 --- a/include/linux/random.h
79980 +++ b/include/linux/random.h
79981 @@ -10,9 +10,19 @@
79982
79983
79984 extern void add_device_randomness(const void *, unsigned int);
79985 +
79986 +static inline void add_latent_entropy(void)
79987 +{
79988 +
79989 +#ifdef LATENT_ENTROPY_PLUGIN
79990 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
79991 +#endif
79992 +
79993 +}
79994 +
79995 extern void add_input_randomness(unsigned int type, unsigned int code,
79996 - unsigned int value);
79997 -extern void add_interrupt_randomness(int irq, int irq_flags);
79998 + unsigned int value) __latent_entropy;
79999 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80000
80001 extern void get_random_bytes(void *buf, int nbytes);
80002 extern void get_random_bytes_arch(void *buf, int nbytes);
80003 @@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
80004 extern const struct file_operations random_fops, urandom_fops;
80005 #endif
80006
80007 -unsigned int get_random_int(void);
80008 +unsigned int __intentional_overflow(-1) get_random_int(void);
80009 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
80010
80011 -u32 prandom_u32(void);
80012 +u32 prandom_u32(void) __intentional_overflow(-1);
80013 void prandom_bytes(void *buf, int nbytes);
80014 void prandom_seed(u32 seed);
80015 void prandom_reseed_late(void);
80016 @@ -38,6 +48,11 @@ struct rnd_state {
80017 u32 prandom_u32_state(struct rnd_state *state);
80018 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80019
80020 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80021 +{
80022 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80023 +}
80024 +
80025 /*
80026 * Handle minimum values for seeds
80027 */
80028 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
80029 index fea49b5..2ac22bb 100644
80030 --- a/include/linux/rbtree_augmented.h
80031 +++ b/include/linux/rbtree_augmented.h
80032 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
80033 old->rbaugmented = rbcompute(old); \
80034 } \
80035 rbstatic const struct rb_augment_callbacks rbname = { \
80036 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
80037 + .propagate = rbname ## _propagate, \
80038 + .copy = rbname ## _copy, \
80039 + .rotate = rbname ## _rotate \
80040 };
80041
80042
80043 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
80044 index 45a0a9e..e83788e 100644
80045 --- a/include/linux/rculist.h
80046 +++ b/include/linux/rculist.h
80047 @@ -29,8 +29,8 @@
80048 */
80049 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80050 {
80051 - ACCESS_ONCE(list->next) = list;
80052 - ACCESS_ONCE(list->prev) = list;
80053 + ACCESS_ONCE_RW(list->next) = list;
80054 + ACCESS_ONCE_RW(list->prev) = list;
80055 }
80056
80057 /*
80058 @@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
80059 struct list_head *prev, struct list_head *next);
80060 #endif
80061
80062 +extern void __pax_list_add_rcu(struct list_head *new,
80063 + struct list_head *prev, struct list_head *next);
80064 +
80065 /**
80066 * list_add_rcu - add a new entry to rcu-protected list
80067 * @new: new entry to be added
80068 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
80069 __list_add_rcu(new, head, head->next);
80070 }
80071
80072 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
80073 +{
80074 + __pax_list_add_rcu(new, head, head->next);
80075 +}
80076 +
80077 /**
80078 * list_add_tail_rcu - add a new entry to rcu-protected list
80079 * @new: new entry to be added
80080 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
80081 __list_add_rcu(new, head->prev, head);
80082 }
80083
80084 +static inline void pax_list_add_tail_rcu(struct list_head *new,
80085 + struct list_head *head)
80086 +{
80087 + __pax_list_add_rcu(new, head->prev, head);
80088 +}
80089 +
80090 /**
80091 * list_del_rcu - deletes entry from list without re-initialization
80092 * @entry: the element to delete from the list.
80093 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
80094 entry->prev = LIST_POISON2;
80095 }
80096
80097 +extern void pax_list_del_rcu(struct list_head *entry);
80098 +
80099 /**
80100 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
80101 * @n: the element to delete from the hash list.
80102 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
80103 index 9e7db9e..7d4fd72 100644
80104 --- a/include/linux/reboot.h
80105 +++ b/include/linux/reboot.h
80106 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
80107 */
80108
80109 extern void migrate_to_reboot_cpu(void);
80110 -extern void machine_restart(char *cmd);
80111 -extern void machine_halt(void);
80112 -extern void machine_power_off(void);
80113 +extern void machine_restart(char *cmd) __noreturn;
80114 +extern void machine_halt(void) __noreturn;
80115 +extern void machine_power_off(void) __noreturn;
80116
80117 extern void machine_shutdown(void);
80118 struct pt_regs;
80119 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
80120 */
80121
80122 extern void kernel_restart_prepare(char *cmd);
80123 -extern void kernel_restart(char *cmd);
80124 -extern void kernel_halt(void);
80125 -extern void kernel_power_off(void);
80126 +extern void kernel_restart(char *cmd) __noreturn;
80127 +extern void kernel_halt(void) __noreturn;
80128 +extern void kernel_power_off(void) __noreturn;
80129
80130 extern int C_A_D; /* for sysctl */
80131 void ctrl_alt_del(void);
80132 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
80133 * Emergency restart, callable from an interrupt handler.
80134 */
80135
80136 -extern void emergency_restart(void);
80137 +extern void emergency_restart(void) __noreturn;
80138 #include <asm/emergency-restart.h>
80139
80140 #endif /* _LINUX_REBOOT_H */
80141 diff --git a/include/linux/regset.h b/include/linux/regset.h
80142 index 8e0c9fe..ac4d221 100644
80143 --- a/include/linux/regset.h
80144 +++ b/include/linux/regset.h
80145 @@ -161,7 +161,8 @@ struct user_regset {
80146 unsigned int align;
80147 unsigned int bias;
80148 unsigned int core_note_type;
80149 -};
80150 +} __do_const;
80151 +typedef struct user_regset __no_const user_regset_no_const;
80152
80153 /**
80154 * struct user_regset_view - available regsets
80155 diff --git a/include/linux/relay.h b/include/linux/relay.h
80156 index d7c8359..818daf5 100644
80157 --- a/include/linux/relay.h
80158 +++ b/include/linux/relay.h
80159 @@ -157,7 +157,7 @@ struct rchan_callbacks
80160 * The callback should return 0 if successful, negative if not.
80161 */
80162 int (*remove_buf_file)(struct dentry *dentry);
80163 -};
80164 +} __no_const;
80165
80166 /*
80167 * CONFIG_RELAY kernel API, kernel/relay.c
80168 diff --git a/include/linux/rio.h b/include/linux/rio.h
80169 index b71d573..2f940bd 100644
80170 --- a/include/linux/rio.h
80171 +++ b/include/linux/rio.h
80172 @@ -355,7 +355,7 @@ struct rio_ops {
80173 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
80174 u64 rstart, u32 size, u32 flags);
80175 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
80176 -};
80177 +} __no_const;
80178
80179 #define RIO_RESOURCE_MEM 0x00000100
80180 #define RIO_RESOURCE_DOORBELL 0x00000200
80181 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
80182 index 6dacb93..6174423 100644
80183 --- a/include/linux/rmap.h
80184 +++ b/include/linux/rmap.h
80185 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
80186 void anon_vma_init(void); /* create anon_vma_cachep */
80187 int anon_vma_prepare(struct vm_area_struct *);
80188 void unlink_anon_vmas(struct vm_area_struct *);
80189 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
80190 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
80191 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
80192 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
80193
80194 static inline void anon_vma_merge(struct vm_area_struct *vma,
80195 struct vm_area_struct *next)
80196 diff --git a/include/linux/sched.h b/include/linux/sched.h
80197 index 53f97eb..1d90705 100644
80198 --- a/include/linux/sched.h
80199 +++ b/include/linux/sched.h
80200 @@ -63,6 +63,7 @@ struct bio_list;
80201 struct fs_struct;
80202 struct perf_event_context;
80203 struct blk_plug;
80204 +struct linux_binprm;
80205
80206 /*
80207 * List of flags we want to share for kernel threads,
80208 @@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
80209 extern int in_sched_functions(unsigned long addr);
80210
80211 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
80212 -extern signed long schedule_timeout(signed long timeout);
80213 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
80214 extern signed long schedule_timeout_interruptible(signed long timeout);
80215 extern signed long schedule_timeout_killable(signed long timeout);
80216 extern signed long schedule_timeout_uninterruptible(signed long timeout);
80217 @@ -315,6 +316,19 @@ struct nsproxy;
80218 struct user_namespace;
80219
80220 #ifdef CONFIG_MMU
80221 +
80222 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80223 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
80224 +#else
80225 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80226 +{
80227 + return 0;
80228 +}
80229 +#endif
80230 +
80231 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
80232 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
80233 +
80234 extern void arch_pick_mmap_layout(struct mm_struct *mm);
80235 extern unsigned long
80236 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
80237 @@ -600,6 +614,17 @@ struct signal_struct {
80238 #ifdef CONFIG_TASKSTATS
80239 struct taskstats *stats;
80240 #endif
80241 +
80242 +#ifdef CONFIG_GRKERNSEC
80243 + u32 curr_ip;
80244 + u32 saved_ip;
80245 + u32 gr_saddr;
80246 + u32 gr_daddr;
80247 + u16 gr_sport;
80248 + u16 gr_dport;
80249 + u8 used_accept:1;
80250 +#endif
80251 +
80252 #ifdef CONFIG_AUDIT
80253 unsigned audit_tty;
80254 unsigned audit_tty_log_passwd;
80255 @@ -626,7 +651,7 @@ struct signal_struct {
80256 struct mutex cred_guard_mutex; /* guard against foreign influences on
80257 * credential calculations
80258 * (notably. ptrace) */
80259 -};
80260 +} __randomize_layout;
80261
80262 /*
80263 * Bits in flags field of signal_struct.
80264 @@ -680,6 +705,14 @@ struct user_struct {
80265 struct key *session_keyring; /* UID's default session keyring */
80266 #endif
80267
80268 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
80269 + unsigned char kernel_banned;
80270 +#endif
80271 +#ifdef CONFIG_GRKERNSEC_BRUTE
80272 + unsigned char suid_banned;
80273 + unsigned long suid_ban_expires;
80274 +#endif
80275 +
80276 /* Hash table maintenance information */
80277 struct hlist_node uidhash_node;
80278 kuid_t uid;
80279 @@ -687,7 +720,7 @@ struct user_struct {
80280 #ifdef CONFIG_PERF_EVENTS
80281 atomic_long_t locked_vm;
80282 #endif
80283 -};
80284 +} __randomize_layout;
80285
80286 extern int uids_sysfs_init(void);
80287
80288 @@ -1162,8 +1195,8 @@ struct task_struct {
80289 struct list_head thread_group;
80290
80291 struct completion *vfork_done; /* for vfork() */
80292 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
80293 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80294 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
80295 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80296
80297 cputime_t utime, stime, utimescaled, stimescaled;
80298 cputime_t gtime;
80299 @@ -1188,11 +1221,6 @@ struct task_struct {
80300 struct task_cputime cputime_expires;
80301 struct list_head cpu_timers[3];
80302
80303 -/* process credentials */
80304 - const struct cred __rcu *real_cred; /* objective and real subjective task
80305 - * credentials (COW) */
80306 - const struct cred __rcu *cred; /* effective (overridable) subjective task
80307 - * credentials (COW) */
80308 char comm[TASK_COMM_LEN]; /* executable name excluding path
80309 - access with [gs]et_task_comm (which lock
80310 it with task_lock())
80311 @@ -1209,6 +1237,10 @@ struct task_struct {
80312 #endif
80313 /* CPU-specific state of this task */
80314 struct thread_struct thread;
80315 +/* thread_info moved to task_struct */
80316 +#ifdef CONFIG_X86
80317 + struct thread_info tinfo;
80318 +#endif
80319 /* filesystem information */
80320 struct fs_struct *fs;
80321 /* open file information */
80322 @@ -1282,6 +1314,10 @@ struct task_struct {
80323 gfp_t lockdep_reclaim_gfp;
80324 #endif
80325
80326 +/* process credentials */
80327 + const struct cred __rcu *real_cred; /* objective and real subjective task
80328 + * credentials (COW) */
80329 +
80330 /* journalling filesystem info */
80331 void *journal_info;
80332
80333 @@ -1320,6 +1356,10 @@ struct task_struct {
80334 /* cg_list protected by css_set_lock and tsk->alloc_lock */
80335 struct list_head cg_list;
80336 #endif
80337 +
80338 + const struct cred __rcu *cred; /* effective (overridable) subjective task
80339 + * credentials (COW) */
80340 +
80341 #ifdef CONFIG_FUTEX
80342 struct robust_list_head __user *robust_list;
80343 #ifdef CONFIG_COMPAT
80344 @@ -1454,7 +1494,78 @@ struct task_struct {
80345 unsigned int sequential_io;
80346 unsigned int sequential_io_avg;
80347 #endif
80348 -};
80349 +
80350 +#ifdef CONFIG_GRKERNSEC
80351 + /* grsecurity */
80352 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80353 + u64 exec_id;
80354 +#endif
80355 +#ifdef CONFIG_GRKERNSEC_SETXID
80356 + const struct cred *delayed_cred;
80357 +#endif
80358 + struct dentry *gr_chroot_dentry;
80359 + struct acl_subject_label *acl;
80360 + struct acl_subject_label *tmpacl;
80361 + struct acl_role_label *role;
80362 + struct file *exec_file;
80363 + unsigned long brute_expires;
80364 + u16 acl_role_id;
80365 + u8 inherited;
80366 + /* is this the task that authenticated to the special role */
80367 + u8 acl_sp_role;
80368 + u8 is_writable;
80369 + u8 brute;
80370 + u8 gr_is_chrooted;
80371 +#endif
80372 +
80373 +} __randomize_layout;
80374 +
80375 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
80376 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
80377 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
80378 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
80379 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
80380 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
80381 +
80382 +#ifdef CONFIG_PAX_SOFTMODE
80383 +extern int pax_softmode;
80384 +#endif
80385 +
80386 +extern int pax_check_flags(unsigned long *);
80387 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
80388 +
80389 +/* if tsk != current then task_lock must be held on it */
80390 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80391 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
80392 +{
80393 + if (likely(tsk->mm))
80394 + return tsk->mm->pax_flags;
80395 + else
80396 + return 0UL;
80397 +}
80398 +
80399 +/* if tsk != current then task_lock must be held on it */
80400 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
80401 +{
80402 + if (likely(tsk->mm)) {
80403 + tsk->mm->pax_flags = flags;
80404 + return 0;
80405 + }
80406 + return -EINVAL;
80407 +}
80408 +#endif
80409 +
80410 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
80411 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
80412 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
80413 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
80414 +#endif
80415 +
80416 +struct path;
80417 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
80418 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
80419 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
80420 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
80421
80422 /* Future-safe accessor for struct task_struct's cpus_allowed. */
80423 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
80424 @@ -1531,7 +1642,7 @@ struct pid_namespace;
80425 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
80426 struct pid_namespace *ns);
80427
80428 -static inline pid_t task_pid_nr(struct task_struct *tsk)
80429 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
80430 {
80431 return tsk->pid;
80432 }
80433 @@ -1981,7 +2092,9 @@ void yield(void);
80434 extern struct exec_domain default_exec_domain;
80435
80436 union thread_union {
80437 +#ifndef CONFIG_X86
80438 struct thread_info thread_info;
80439 +#endif
80440 unsigned long stack[THREAD_SIZE/sizeof(long)];
80441 };
80442
80443 @@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
80444 */
80445
80446 extern struct task_struct *find_task_by_vpid(pid_t nr);
80447 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
80448 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
80449 struct pid_namespace *ns);
80450
80451 @@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
80452 extern void exit_itimers(struct signal_struct *);
80453 extern void flush_itimer_signals(void);
80454
80455 -extern void do_group_exit(int);
80456 +extern __noreturn void do_group_exit(int);
80457
80458 extern int allow_signal(int);
80459 extern int disallow_signal(int);
80460 @@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
80461
80462 #endif
80463
80464 -static inline int object_is_on_stack(void *obj)
80465 +static inline int object_starts_on_stack(void *obj)
80466 {
80467 - void *stack = task_stack_page(current);
80468 + const void *stack = task_stack_page(current);
80469
80470 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
80471 }
80472 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
80473 index 41467f8..1e4253d 100644
80474 --- a/include/linux/sched/sysctl.h
80475 +++ b/include/linux/sched/sysctl.h
80476 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
80477 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
80478
80479 extern int sysctl_max_map_count;
80480 +extern unsigned long sysctl_heap_stack_gap;
80481
80482 extern unsigned int sysctl_sched_latency;
80483 extern unsigned int sysctl_sched_min_granularity;
80484 diff --git a/include/linux/security.h b/include/linux/security.h
80485 index 5623a7f..b352409 100644
80486 --- a/include/linux/security.h
80487 +++ b/include/linux/security.h
80488 @@ -27,6 +27,7 @@
80489 #include <linux/slab.h>
80490 #include <linux/err.h>
80491 #include <linux/string.h>
80492 +#include <linux/grsecurity.h>
80493
80494 struct linux_binprm;
80495 struct cred;
80496 @@ -116,8 +117,6 @@ struct seq_file;
80497
80498 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
80499
80500 -void reset_security_ops(void);
80501 -
80502 #ifdef CONFIG_MMU
80503 extern unsigned long mmap_min_addr;
80504 extern unsigned long dac_mmap_min_addr;
80505 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
80506 index dc368b8..e895209 100644
80507 --- a/include/linux/semaphore.h
80508 +++ b/include/linux/semaphore.h
80509 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
80510 }
80511
80512 extern void down(struct semaphore *sem);
80513 -extern int __must_check down_interruptible(struct semaphore *sem);
80514 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
80515 extern int __must_check down_killable(struct semaphore *sem);
80516 extern int __must_check down_trylock(struct semaphore *sem);
80517 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
80518 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
80519 index 52e0097..09625ef 100644
80520 --- a/include/linux/seq_file.h
80521 +++ b/include/linux/seq_file.h
80522 @@ -27,6 +27,9 @@ struct seq_file {
80523 struct mutex lock;
80524 const struct seq_operations *op;
80525 int poll_event;
80526 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80527 + u64 exec_id;
80528 +#endif
80529 #ifdef CONFIG_USER_NS
80530 struct user_namespace *user_ns;
80531 #endif
80532 @@ -39,6 +42,7 @@ struct seq_operations {
80533 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
80534 int (*show) (struct seq_file *m, void *v);
80535 };
80536 +typedef struct seq_operations __no_const seq_operations_no_const;
80537
80538 #define SEQ_SKIP 1
80539
80540 diff --git a/include/linux/shm.h b/include/linux/shm.h
80541 index 429c199..4d42e38 100644
80542 --- a/include/linux/shm.h
80543 +++ b/include/linux/shm.h
80544 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
80545
80546 /* The task created the shm object. NULL if the task is dead. */
80547 struct task_struct *shm_creator;
80548 +#ifdef CONFIG_GRKERNSEC
80549 + time_t shm_createtime;
80550 + pid_t shm_lapid;
80551 +#endif
80552 };
80553
80554 /* shm_mode upper byte flags */
80555 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
80556 index 6f69b3f..71ac613 100644
80557 --- a/include/linux/skbuff.h
80558 +++ b/include/linux/skbuff.h
80559 @@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
80560 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
80561 int node);
80562 struct sk_buff *build_skb(void *data, unsigned int frag_size);
80563 -static inline struct sk_buff *alloc_skb(unsigned int size,
80564 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
80565 gfp_t priority)
80566 {
80567 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
80568 @@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
80569 */
80570 static inline int skb_queue_empty(const struct sk_buff_head *list)
80571 {
80572 - return list->next == (struct sk_buff *)list;
80573 + return list->next == (const struct sk_buff *)list;
80574 }
80575
80576 /**
80577 @@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
80578 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80579 const struct sk_buff *skb)
80580 {
80581 - return skb->next == (struct sk_buff *)list;
80582 + return skb->next == (const struct sk_buff *)list;
80583 }
80584
80585 /**
80586 @@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80587 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
80588 const struct sk_buff *skb)
80589 {
80590 - return skb->prev == (struct sk_buff *)list;
80591 + return skb->prev == (const struct sk_buff *)list;
80592 }
80593
80594 /**
80595 @@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
80596 return skb->inner_transport_header - skb->inner_network_header;
80597 }
80598
80599 -static inline int skb_network_offset(const struct sk_buff *skb)
80600 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
80601 {
80602 return skb_network_header(skb) - skb->data;
80603 }
80604 @@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
80605 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
80606 */
80607 #ifndef NET_SKB_PAD
80608 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
80609 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
80610 #endif
80611
80612 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
80613 @@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
80614 int *err);
80615 unsigned int datagram_poll(struct file *file, struct socket *sock,
80616 struct poll_table_struct *wait);
80617 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80618 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80619 struct iovec *to, int size);
80620 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
80621 struct iovec *iov);
80622 @@ -2617,6 +2617,9 @@ static inline void nf_reset(struct sk_buff *skb)
80623 nf_bridge_put(skb->nf_bridge);
80624 skb->nf_bridge = NULL;
80625 #endif
80626 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
80627 + skb->nf_trace = 0;
80628 +#endif
80629 }
80630
80631 static inline void nf_reset_trace(struct sk_buff *skb)
80632 diff --git a/include/linux/slab.h b/include/linux/slab.h
80633 index 1e2f4fe..df49ca6 100644
80634 --- a/include/linux/slab.h
80635 +++ b/include/linux/slab.h
80636 @@ -14,15 +14,29 @@
80637 #include <linux/gfp.h>
80638 #include <linux/types.h>
80639 #include <linux/workqueue.h>
80640 -
80641 +#include <linux/err.h>
80642
80643 /*
80644 * Flags to pass to kmem_cache_create().
80645 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
80646 */
80647 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
80648 +
80649 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80650 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
80651 +#else
80652 +#define SLAB_USERCOPY 0x00000000UL
80653 +#endif
80654 +
80655 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
80656 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
80657 +
80658 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
80659 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
80660 +#else
80661 +#define SLAB_NO_SANITIZE 0x00000000UL
80662 +#endif
80663 +
80664 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
80665 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
80666 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
80667 @@ -98,10 +112,13 @@
80668 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
80669 * Both make kfree a no-op.
80670 */
80671 -#define ZERO_SIZE_PTR ((void *)16)
80672 +#define ZERO_SIZE_PTR \
80673 +({ \
80674 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
80675 + (void *)(-MAX_ERRNO-1L); \
80676 +})
80677
80678 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
80679 - (unsigned long)ZERO_SIZE_PTR)
80680 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
80681
80682 #include <linux/kmemleak.h>
80683
80684 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
80685 void kfree(const void *);
80686 void kzfree(const void *);
80687 size_t ksize(const void *);
80688 +const char *check_heap_object(const void *ptr, unsigned long n);
80689 +bool is_usercopy_object(const void *ptr);
80690
80691 /*
80692 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
80693 @@ -174,7 +193,7 @@ struct kmem_cache {
80694 unsigned int align; /* Alignment as calculated */
80695 unsigned long flags; /* Active flags on the slab */
80696 const char *name; /* Slab name for sysfs */
80697 - int refcount; /* Use counter */
80698 + atomic_t refcount; /* Use counter */
80699 void (*ctor)(void *); /* Called on object slot creation */
80700 struct list_head list; /* List of all slab caches on the system */
80701 };
80702 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
80703 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80704 #endif
80705
80706 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80707 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
80708 +#endif
80709 +
80710 /*
80711 * Figure out which kmalloc slab an allocation of a certain size
80712 * belongs to.
80713 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80714 * 2 = 120 .. 192 bytes
80715 * n = 2^(n-1) .. 2^n -1
80716 */
80717 -static __always_inline int kmalloc_index(size_t size)
80718 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
80719 {
80720 if (!size)
80721 return 0;
80722 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
80723 }
80724 #endif /* !CONFIG_SLOB */
80725
80726 -void *__kmalloc(size_t size, gfp_t flags);
80727 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
80728 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
80729
80730 #ifdef CONFIG_NUMA
80731 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
80732 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
80733 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
80734 #else
80735 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
80736 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
80737 index 09bfffb..4fc80fb 100644
80738 --- a/include/linux/slab_def.h
80739 +++ b/include/linux/slab_def.h
80740 @@ -36,7 +36,7 @@ struct kmem_cache {
80741 /* 4) cache creation/removal */
80742 const char *name;
80743 struct list_head list;
80744 - int refcount;
80745 + atomic_t refcount;
80746 int object_size;
80747 int align;
80748
80749 @@ -52,10 +52,14 @@ struct kmem_cache {
80750 unsigned long node_allocs;
80751 unsigned long node_frees;
80752 unsigned long node_overflow;
80753 - atomic_t allochit;
80754 - atomic_t allocmiss;
80755 - atomic_t freehit;
80756 - atomic_t freemiss;
80757 + atomic_unchecked_t allochit;
80758 + atomic_unchecked_t allocmiss;
80759 + atomic_unchecked_t freehit;
80760 + atomic_unchecked_t freemiss;
80761 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
80762 + atomic_unchecked_t sanitized;
80763 + atomic_unchecked_t not_sanitized;
80764 +#endif
80765
80766 /*
80767 * If debugging is enabled, then the allocator can add additional
80768 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
80769 index f56bfa9..8378a26 100644
80770 --- a/include/linux/slub_def.h
80771 +++ b/include/linux/slub_def.h
80772 @@ -74,7 +74,7 @@ struct kmem_cache {
80773 struct kmem_cache_order_objects max;
80774 struct kmem_cache_order_objects min;
80775 gfp_t allocflags; /* gfp flags to use on each alloc */
80776 - int refcount; /* Refcount for slab cache destroy */
80777 + atomic_t refcount; /* Refcount for slab cache destroy */
80778 void (*ctor)(void *);
80779 int inuse; /* Offset to metadata */
80780 int align; /* Alignment */
80781 diff --git a/include/linux/smp.h b/include/linux/smp.h
80782 index 5da22ee..71d8a28 100644
80783 --- a/include/linux/smp.h
80784 +++ b/include/linux/smp.h
80785 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
80786 #endif
80787
80788 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
80789 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
80790 #define put_cpu() preempt_enable()
80791 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
80792
80793 /*
80794 * Callback to arch code if there's nosmp or maxcpus=0 on the
80795 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
80796 index 54f91d3..be2c379 100644
80797 --- a/include/linux/sock_diag.h
80798 +++ b/include/linux/sock_diag.h
80799 @@ -11,7 +11,7 @@ struct sock;
80800 struct sock_diag_handler {
80801 __u8 family;
80802 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
80803 -};
80804 +} __do_const;
80805
80806 int sock_diag_register(const struct sock_diag_handler *h);
80807 void sock_diag_unregister(const struct sock_diag_handler *h);
80808 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
80809 index 680f9a3..f13aeb0 100644
80810 --- a/include/linux/sonet.h
80811 +++ b/include/linux/sonet.h
80812 @@ -7,7 +7,7 @@
80813 #include <uapi/linux/sonet.h>
80814
80815 struct k_sonet_stats {
80816 -#define __HANDLE_ITEM(i) atomic_t i
80817 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80818 __SONET_ITEMS
80819 #undef __HANDLE_ITEM
80820 };
80821 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
80822 index 07d8e53..dc934c9 100644
80823 --- a/include/linux/sunrpc/addr.h
80824 +++ b/include/linux/sunrpc/addr.h
80825 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
80826 {
80827 switch (sap->sa_family) {
80828 case AF_INET:
80829 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
80830 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
80831 case AF_INET6:
80832 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
80833 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
80834 }
80835 return 0;
80836 }
80837 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
80838 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
80839 const struct sockaddr *src)
80840 {
80841 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
80842 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
80843 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
80844
80845 dsin->sin_family = ssin->sin_family;
80846 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
80847 if (sa->sa_family != AF_INET6)
80848 return 0;
80849
80850 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
80851 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
80852 }
80853
80854 #endif /* _LINUX_SUNRPC_ADDR_H */
80855 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
80856 index 8af2804..c7414ef 100644
80857 --- a/include/linux/sunrpc/clnt.h
80858 +++ b/include/linux/sunrpc/clnt.h
80859 @@ -97,7 +97,7 @@ struct rpc_procinfo {
80860 unsigned int p_timer; /* Which RTT timer to use */
80861 u32 p_statidx; /* Which procedure to account */
80862 const char * p_name; /* name of procedure */
80863 -};
80864 +} __do_const;
80865
80866 #ifdef __KERNEL__
80867
80868 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
80869 index 6eecfc2..7ada79d 100644
80870 --- a/include/linux/sunrpc/svc.h
80871 +++ b/include/linux/sunrpc/svc.h
80872 @@ -410,7 +410,7 @@ struct svc_procedure {
80873 unsigned int pc_count; /* call count */
80874 unsigned int pc_cachetype; /* cache info (NFS) */
80875 unsigned int pc_xdrressize; /* maximum size of XDR reply */
80876 -};
80877 +} __do_const;
80878
80879 /*
80880 * Function prototypes.
80881 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
80882 index 0b8e3e6..33e0a01 100644
80883 --- a/include/linux/sunrpc/svc_rdma.h
80884 +++ b/include/linux/sunrpc/svc_rdma.h
80885 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
80886 extern unsigned int svcrdma_max_requests;
80887 extern unsigned int svcrdma_max_req_size;
80888
80889 -extern atomic_t rdma_stat_recv;
80890 -extern atomic_t rdma_stat_read;
80891 -extern atomic_t rdma_stat_write;
80892 -extern atomic_t rdma_stat_sq_starve;
80893 -extern atomic_t rdma_stat_rq_starve;
80894 -extern atomic_t rdma_stat_rq_poll;
80895 -extern atomic_t rdma_stat_rq_prod;
80896 -extern atomic_t rdma_stat_sq_poll;
80897 -extern atomic_t rdma_stat_sq_prod;
80898 +extern atomic_unchecked_t rdma_stat_recv;
80899 +extern atomic_unchecked_t rdma_stat_read;
80900 +extern atomic_unchecked_t rdma_stat_write;
80901 +extern atomic_unchecked_t rdma_stat_sq_starve;
80902 +extern atomic_unchecked_t rdma_stat_rq_starve;
80903 +extern atomic_unchecked_t rdma_stat_rq_poll;
80904 +extern atomic_unchecked_t rdma_stat_rq_prod;
80905 +extern atomic_unchecked_t rdma_stat_sq_poll;
80906 +extern atomic_unchecked_t rdma_stat_sq_prod;
80907
80908 #define RPCRDMA_VERSION 1
80909
80910 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
80911 index 8d71d65..f79586e 100644
80912 --- a/include/linux/sunrpc/svcauth.h
80913 +++ b/include/linux/sunrpc/svcauth.h
80914 @@ -120,7 +120,7 @@ struct auth_ops {
80915 int (*release)(struct svc_rqst *rq);
80916 void (*domain_release)(struct auth_domain *);
80917 int (*set_client)(struct svc_rqst *rq);
80918 -};
80919 +} __do_const;
80920
80921 #define SVC_GARBAGE 1
80922 #define SVC_SYSERR 2
80923 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
80924 index a5ffd32..0935dea 100644
80925 --- a/include/linux/swiotlb.h
80926 +++ b/include/linux/swiotlb.h
80927 @@ -60,7 +60,8 @@ extern void
80928
80929 extern void
80930 swiotlb_free_coherent(struct device *hwdev, size_t size,
80931 - void *vaddr, dma_addr_t dma_handle);
80932 + void *vaddr, dma_addr_t dma_handle,
80933 + struct dma_attrs *attrs);
80934
80935 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
80936 unsigned long offset, size_t size,
80937 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
80938 index 94273bb..c2e05fc 100644
80939 --- a/include/linux/syscalls.h
80940 +++ b/include/linux/syscalls.h
80941 @@ -97,8 +97,14 @@ struct sigaltstack;
80942 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
80943
80944 #define __SC_DECL(t, a) t a
80945 +#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))
80946 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
80947 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
80948 +#define __SC_LONG(t, a) __typeof( \
80949 + __builtin_choose_expr( \
80950 + sizeof(t) > sizeof(int), \
80951 + (t) 0, \
80952 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
80953 + )) a
80954 #define __SC_CAST(t, a) (t) a
80955 #define __SC_ARGS(t, a) a
80956 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
80957 @@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
80958 asmlinkage long sys_fsync(unsigned int fd);
80959 asmlinkage long sys_fdatasync(unsigned int fd);
80960 asmlinkage long sys_bdflush(int func, long data);
80961 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
80962 - char __user *type, unsigned long flags,
80963 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
80964 + const char __user *type, unsigned long flags,
80965 void __user *data);
80966 -asmlinkage long sys_umount(char __user *name, int flags);
80967 -asmlinkage long sys_oldumount(char __user *name);
80968 +asmlinkage long sys_umount(const char __user *name, int flags);
80969 +asmlinkage long sys_oldumount(const char __user *name);
80970 asmlinkage long sys_truncate(const char __user *path, long length);
80971 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
80972 asmlinkage long sys_stat(const char __user *filename,
80973 @@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
80974 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
80975 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
80976 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
80977 - struct sockaddr __user *, int);
80978 + struct sockaddr __user *, int) __intentional_overflow(0);
80979 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
80980 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
80981 unsigned int vlen, unsigned flags);
80982 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
80983 index 27b3b0b..e093dd9 100644
80984 --- a/include/linux/syscore_ops.h
80985 +++ b/include/linux/syscore_ops.h
80986 @@ -16,7 +16,7 @@ struct syscore_ops {
80987 int (*suspend)(void);
80988 void (*resume)(void);
80989 void (*shutdown)(void);
80990 -};
80991 +} __do_const;
80992
80993 extern void register_syscore_ops(struct syscore_ops *ops);
80994 extern void unregister_syscore_ops(struct syscore_ops *ops);
80995 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
80996 index 14a8ff2..fa95f3a 100644
80997 --- a/include/linux/sysctl.h
80998 +++ b/include/linux/sysctl.h
80999 @@ -34,13 +34,13 @@ struct ctl_table_root;
81000 struct ctl_table_header;
81001 struct ctl_dir;
81002
81003 -typedef struct ctl_table ctl_table;
81004 -
81005 typedef int proc_handler (struct ctl_table *ctl, int write,
81006 void __user *buffer, size_t *lenp, loff_t *ppos);
81007
81008 extern int proc_dostring(struct ctl_table *, int,
81009 void __user *, size_t *, loff_t *);
81010 +extern int proc_dostring_modpriv(struct ctl_table *, int,
81011 + void __user *, size_t *, loff_t *);
81012 extern int proc_dointvec(struct ctl_table *, int,
81013 void __user *, size_t *, loff_t *);
81014 extern int proc_dointvec_minmax(struct ctl_table *, int,
81015 @@ -115,7 +115,9 @@ struct ctl_table
81016 struct ctl_table_poll *poll;
81017 void *extra1;
81018 void *extra2;
81019 -};
81020 +} __do_const __randomize_layout;
81021 +typedef struct ctl_table __no_const ctl_table_no_const;
81022 +typedef struct ctl_table ctl_table;
81023
81024 struct ctl_node {
81025 struct rb_node node;
81026 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81027 index 6695040..3d4192d 100644
81028 --- a/include/linux/sysfs.h
81029 +++ b/include/linux/sysfs.h
81030 @@ -33,7 +33,8 @@ struct attribute {
81031 struct lock_class_key *key;
81032 struct lock_class_key skey;
81033 #endif
81034 -};
81035 +} __do_const;
81036 +typedef struct attribute __no_const attribute_no_const;
81037
81038 /**
81039 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
81040 @@ -62,7 +63,8 @@ struct attribute_group {
81041 struct attribute *, int);
81042 struct attribute **attrs;
81043 struct bin_attribute **bin_attrs;
81044 -};
81045 +} __do_const;
81046 +typedef struct attribute_group __no_const attribute_group_no_const;
81047
81048 /**
81049 * Use these macros to make defining attributes easier. See include/linux/device.h
81050 @@ -126,7 +128,8 @@ struct bin_attribute {
81051 char *, loff_t, size_t);
81052 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
81053 struct vm_area_struct *vma);
81054 -};
81055 +} __do_const;
81056 +typedef struct bin_attribute __no_const bin_attribute_no_const;
81057
81058 /**
81059 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
81060 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
81061 index 387fa7d..3fcde6b 100644
81062 --- a/include/linux/sysrq.h
81063 +++ b/include/linux/sysrq.h
81064 @@ -16,6 +16,7 @@
81065
81066 #include <linux/errno.h>
81067 #include <linux/types.h>
81068 +#include <linux/compiler.h>
81069
81070 /* Possible values of bitmask for enabling sysrq functions */
81071 /* 0x0001 is reserved for enable everything */
81072 @@ -33,7 +34,7 @@ struct sysrq_key_op {
81073 char *help_msg;
81074 char *action_msg;
81075 int enable_mask;
81076 -};
81077 +} __do_const;
81078
81079 #ifdef CONFIG_MAGIC_SYSRQ
81080
81081 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
81082 index fddbe20..0312de8 100644
81083 --- a/include/linux/thread_info.h
81084 +++ b/include/linux/thread_info.h
81085 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
81086 #error "no set_restore_sigmask() provided and default one won't work"
81087 #endif
81088
81089 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
81090 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
81091 +{
81092 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
81093 + if (!__builtin_constant_p(n))
81094 +#endif
81095 + __check_object_size(ptr, n, to_user);
81096 +}
81097 +
81098 #endif /* __KERNEL__ */
81099
81100 #endif /* _LINUX_THREAD_INFO_H */
81101 diff --git a/include/linux/tty.h b/include/linux/tty.h
81102 index 97d660e..6356755 100644
81103 --- a/include/linux/tty.h
81104 +++ b/include/linux/tty.h
81105 @@ -196,7 +196,7 @@ struct tty_port {
81106 const struct tty_port_operations *ops; /* Port operations */
81107 spinlock_t lock; /* Lock protecting tty field */
81108 int blocked_open; /* Waiting to open */
81109 - int count; /* Usage count */
81110 + atomic_t count; /* Usage count */
81111 wait_queue_head_t open_wait; /* Open waiters */
81112 wait_queue_head_t close_wait; /* Close waiters */
81113 wait_queue_head_t delta_msr_wait; /* Modem status change */
81114 @@ -278,7 +278,7 @@ struct tty_struct {
81115 /* If the tty has a pending do_SAK, queue it here - akpm */
81116 struct work_struct SAK_work;
81117 struct tty_port *port;
81118 -};
81119 +} __randomize_layout;
81120
81121 /* Each of a tty's open files has private_data pointing to tty_file_private */
81122 struct tty_file_private {
81123 @@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
81124 struct tty_struct *tty, struct file *filp);
81125 static inline int tty_port_users(struct tty_port *port)
81126 {
81127 - return port->count + port->blocked_open;
81128 + return atomic_read(&port->count) + port->blocked_open;
81129 }
81130
81131 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
81132 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
81133 index 756a609..f61242d 100644
81134 --- a/include/linux/tty_driver.h
81135 +++ b/include/linux/tty_driver.h
81136 @@ -285,7 +285,7 @@ struct tty_operations {
81137 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
81138 #endif
81139 const struct file_operations *proc_fops;
81140 -};
81141 +} __do_const;
81142
81143 struct tty_driver {
81144 int magic; /* magic number for this structure */
81145 @@ -319,7 +319,7 @@ struct tty_driver {
81146
81147 const struct tty_operations *ops;
81148 struct list_head tty_drivers;
81149 -};
81150 +} __randomize_layout;
81151
81152 extern struct list_head tty_drivers;
81153
81154 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
81155 index f15c898..207b7d1 100644
81156 --- a/include/linux/tty_ldisc.h
81157 +++ b/include/linux/tty_ldisc.h
81158 @@ -211,7 +211,7 @@ struct tty_ldisc_ops {
81159
81160 struct module *owner;
81161
81162 - int refcount;
81163 + atomic_t refcount;
81164 };
81165
81166 struct tty_ldisc {
81167 diff --git a/include/linux/types.h b/include/linux/types.h
81168 index 4d118ba..c3ee9bf 100644
81169 --- a/include/linux/types.h
81170 +++ b/include/linux/types.h
81171 @@ -176,10 +176,26 @@ typedef struct {
81172 int counter;
81173 } atomic_t;
81174
81175 +#ifdef CONFIG_PAX_REFCOUNT
81176 +typedef struct {
81177 + int counter;
81178 +} atomic_unchecked_t;
81179 +#else
81180 +typedef atomic_t atomic_unchecked_t;
81181 +#endif
81182 +
81183 #ifdef CONFIG_64BIT
81184 typedef struct {
81185 long counter;
81186 } atomic64_t;
81187 +
81188 +#ifdef CONFIG_PAX_REFCOUNT
81189 +typedef struct {
81190 + long counter;
81191 +} atomic64_unchecked_t;
81192 +#else
81193 +typedef atomic64_t atomic64_unchecked_t;
81194 +#endif
81195 #endif
81196
81197 struct list_head {
81198 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
81199 index 9d8cf05..0ed74dd 100644
81200 --- a/include/linux/uaccess.h
81201 +++ b/include/linux/uaccess.h
81202 @@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
81203 long ret; \
81204 mm_segment_t old_fs = get_fs(); \
81205 \
81206 - set_fs(KERNEL_DS); \
81207 pagefault_disable(); \
81208 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
81209 - pagefault_enable(); \
81210 + set_fs(KERNEL_DS); \
81211 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
81212 set_fs(old_fs); \
81213 + pagefault_enable(); \
81214 ret; \
81215 })
81216
81217 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
81218 index 8e522cbc..aa8572d 100644
81219 --- a/include/linux/uidgid.h
81220 +++ b/include/linux/uidgid.h
81221 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
81222
81223 #endif /* CONFIG_USER_NS */
81224
81225 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
81226 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
81227 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
81228 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
81229 +
81230 #endif /* _LINUX_UIDGID_H */
81231 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
81232 index 99c1b4d..562e6f3 100644
81233 --- a/include/linux/unaligned/access_ok.h
81234 +++ b/include/linux/unaligned/access_ok.h
81235 @@ -4,34 +4,34 @@
81236 #include <linux/kernel.h>
81237 #include <asm/byteorder.h>
81238
81239 -static inline u16 get_unaligned_le16(const void *p)
81240 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
81241 {
81242 - return le16_to_cpup((__le16 *)p);
81243 + return le16_to_cpup((const __le16 *)p);
81244 }
81245
81246 -static inline u32 get_unaligned_le32(const void *p)
81247 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
81248 {
81249 - return le32_to_cpup((__le32 *)p);
81250 + return le32_to_cpup((const __le32 *)p);
81251 }
81252
81253 -static inline u64 get_unaligned_le64(const void *p)
81254 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
81255 {
81256 - return le64_to_cpup((__le64 *)p);
81257 + return le64_to_cpup((const __le64 *)p);
81258 }
81259
81260 -static inline u16 get_unaligned_be16(const void *p)
81261 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
81262 {
81263 - return be16_to_cpup((__be16 *)p);
81264 + return be16_to_cpup((const __be16 *)p);
81265 }
81266
81267 -static inline u32 get_unaligned_be32(const void *p)
81268 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
81269 {
81270 - return be32_to_cpup((__be32 *)p);
81271 + return be32_to_cpup((const __be32 *)p);
81272 }
81273
81274 -static inline u64 get_unaligned_be64(const void *p)
81275 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
81276 {
81277 - return be64_to_cpup((__be64 *)p);
81278 + return be64_to_cpup((const __be64 *)p);
81279 }
81280
81281 static inline void put_unaligned_le16(u16 val, void *p)
81282 diff --git a/include/linux/usb.h b/include/linux/usb.h
81283 index 512ab16..f53e1bf 100644
81284 --- a/include/linux/usb.h
81285 +++ b/include/linux/usb.h
81286 @@ -563,7 +563,7 @@ struct usb_device {
81287 int maxchild;
81288
81289 u32 quirks;
81290 - atomic_t urbnum;
81291 + atomic_unchecked_t urbnum;
81292
81293 unsigned long active_duration;
81294
81295 @@ -1643,7 +1643,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
81296
81297 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
81298 __u8 request, __u8 requesttype, __u16 value, __u16 index,
81299 - void *data, __u16 size, int timeout);
81300 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
81301 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
81302 void *data, int len, int *actual_length, int timeout);
81303 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
81304 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
81305 index e452ba6..78f8e80 100644
81306 --- a/include/linux/usb/renesas_usbhs.h
81307 +++ b/include/linux/usb/renesas_usbhs.h
81308 @@ -39,7 +39,7 @@ enum {
81309 */
81310 struct renesas_usbhs_driver_callback {
81311 int (*notify_hotplug)(struct platform_device *pdev);
81312 -};
81313 +} __no_const;
81314
81315 /*
81316 * callback functions for platform
81317 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
81318 index 4836ba3..603f6ee 100644
81319 --- a/include/linux/user_namespace.h
81320 +++ b/include/linux/user_namespace.h
81321 @@ -33,7 +33,7 @@ struct user_namespace {
81322 struct key *persistent_keyring_register;
81323 struct rw_semaphore persistent_keyring_register_sem;
81324 #endif
81325 -};
81326 +} __randomize_layout;
81327
81328 extern struct user_namespace init_user_ns;
81329
81330 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
81331 index 239e277..22a5cf5 100644
81332 --- a/include/linux/utsname.h
81333 +++ b/include/linux/utsname.h
81334 @@ -24,7 +24,7 @@ struct uts_namespace {
81335 struct new_utsname name;
81336 struct user_namespace *user_ns;
81337 unsigned int proc_inum;
81338 -};
81339 +} __randomize_layout;
81340 extern struct uts_namespace init_uts_ns;
81341
81342 #ifdef CONFIG_UTS_NS
81343 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
81344 index 6f8fbcf..4efc177 100644
81345 --- a/include/linux/vermagic.h
81346 +++ b/include/linux/vermagic.h
81347 @@ -25,9 +25,42 @@
81348 #define MODULE_ARCH_VERMAGIC ""
81349 #endif
81350
81351 +#ifdef CONFIG_PAX_REFCOUNT
81352 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
81353 +#else
81354 +#define MODULE_PAX_REFCOUNT ""
81355 +#endif
81356 +
81357 +#ifdef CONSTIFY_PLUGIN
81358 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
81359 +#else
81360 +#define MODULE_CONSTIFY_PLUGIN ""
81361 +#endif
81362 +
81363 +#ifdef STACKLEAK_PLUGIN
81364 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
81365 +#else
81366 +#define MODULE_STACKLEAK_PLUGIN ""
81367 +#endif
81368 +
81369 +#ifdef RANDSTRUCT_PLUGIN
81370 +#include <generated/randomize_layout_hash.h>
81371 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
81372 +#else
81373 +#define MODULE_RANDSTRUCT_PLUGIN
81374 +#endif
81375 +
81376 +#ifdef CONFIG_GRKERNSEC
81377 +#define MODULE_GRSEC "GRSEC "
81378 +#else
81379 +#define MODULE_GRSEC ""
81380 +#endif
81381 +
81382 #define VERMAGIC_STRING \
81383 UTS_RELEASE " " \
81384 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
81385 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
81386 - MODULE_ARCH_VERMAGIC
81387 + MODULE_ARCH_VERMAGIC \
81388 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
81389 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
81390
81391 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
81392 index 502073a..a7de024 100644
81393 --- a/include/linux/vga_switcheroo.h
81394 +++ b/include/linux/vga_switcheroo.h
81395 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
81396
81397 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
81398
81399 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
81400 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
81401 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
81402 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
81403 #else
81404
81405 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
81406 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
81407
81408 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
81409
81410 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81411 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81412 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81413 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81414
81415 #endif
81416 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
81417 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
81418 index 4b8a891..cb8df6e 100644
81419 --- a/include/linux/vmalloc.h
81420 +++ b/include/linux/vmalloc.h
81421 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
81422 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
81423 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
81424 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
81425 +
81426 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
81427 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
81428 +#endif
81429 +
81430 /* bits [20..32] reserved for arch specific ioremap internals */
81431
81432 /*
81433 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
81434
81435 /* for /dev/kmem */
81436 extern long vread(char *buf, char *addr, unsigned long count);
81437 -extern long vwrite(char *buf, char *addr, unsigned long count);
81438 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
81439
81440 /*
81441 * Internals. Dont't use..
81442 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
81443 index e4b9480..5a5f65a 100644
81444 --- a/include/linux/vmstat.h
81445 +++ b/include/linux/vmstat.h
81446 @@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
81447 /*
81448 * Zone based page accounting with per cpu differentials.
81449 */
81450 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81451 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81452
81453 static inline void zone_page_state_add(long x, struct zone *zone,
81454 enum zone_stat_item item)
81455 {
81456 - atomic_long_add(x, &zone->vm_stat[item]);
81457 - atomic_long_add(x, &vm_stat[item]);
81458 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
81459 + atomic_long_add_unchecked(x, &vm_stat[item]);
81460 }
81461
81462 -static inline unsigned long global_page_state(enum zone_stat_item item)
81463 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
81464 {
81465 - long x = atomic_long_read(&vm_stat[item]);
81466 + long x = atomic_long_read_unchecked(&vm_stat[item]);
81467 #ifdef CONFIG_SMP
81468 if (x < 0)
81469 x = 0;
81470 @@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
81471 return x;
81472 }
81473
81474 -static inline unsigned long zone_page_state(struct zone *zone,
81475 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
81476 enum zone_stat_item item)
81477 {
81478 - long x = atomic_long_read(&zone->vm_stat[item]);
81479 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81480 #ifdef CONFIG_SMP
81481 if (x < 0)
81482 x = 0;
81483 @@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
81484 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
81485 enum zone_stat_item item)
81486 {
81487 - long x = atomic_long_read(&zone->vm_stat[item]);
81488 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81489
81490 #ifdef CONFIG_SMP
81491 int cpu;
81492 @@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
81493
81494 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
81495 {
81496 - atomic_long_inc(&zone->vm_stat[item]);
81497 - atomic_long_inc(&vm_stat[item]);
81498 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
81499 + atomic_long_inc_unchecked(&vm_stat[item]);
81500 }
81501
81502 static inline void __inc_zone_page_state(struct page *page,
81503 @@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
81504
81505 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
81506 {
81507 - atomic_long_dec(&zone->vm_stat[item]);
81508 - atomic_long_dec(&vm_stat[item]);
81509 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
81510 + atomic_long_dec_unchecked(&vm_stat[item]);
81511 }
81512
81513 static inline void __dec_zone_page_state(struct page *page,
81514 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
81515 index 91b0a68..0e9adf6 100644
81516 --- a/include/linux/xattr.h
81517 +++ b/include/linux/xattr.h
81518 @@ -28,7 +28,7 @@ struct xattr_handler {
81519 size_t size, int handler_flags);
81520 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
81521 size_t size, int flags, int handler_flags);
81522 -};
81523 +} __do_const;
81524
81525 struct xattr {
81526 const char *name;
81527 @@ -37,6 +37,9 @@ struct xattr {
81528 };
81529
81530 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
81531 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81532 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
81533 +#endif
81534 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
81535 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
81536 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
81537 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
81538 index 9c5a6b4..09c9438 100644
81539 --- a/include/linux/zlib.h
81540 +++ b/include/linux/zlib.h
81541 @@ -31,6 +31,7 @@
81542 #define _ZLIB_H
81543
81544 #include <linux/zconf.h>
81545 +#include <linux/compiler.h>
81546
81547 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
81548 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
81549 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
81550
81551 /* basic functions */
81552
81553 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
81554 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
81555 /*
81556 Returns the number of bytes that needs to be allocated for a per-
81557 stream workspace with the specified parameters. A pointer to this
81558 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
81559 index c768c9f..bdcaa5a 100644
81560 --- a/include/media/v4l2-dev.h
81561 +++ b/include/media/v4l2-dev.h
81562 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
81563 int (*mmap) (struct file *, struct vm_area_struct *);
81564 int (*open) (struct file *);
81565 int (*release) (struct file *);
81566 -};
81567 +} __do_const;
81568
81569 /*
81570 * Newer version of video_device, handled by videodev2.c
81571 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
81572 index c9b1593..a572459 100644
81573 --- a/include/media/v4l2-device.h
81574 +++ b/include/media/v4l2-device.h
81575 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
81576 this function returns 0. If the name ends with a digit (e.g. cx18),
81577 then the name will be set to cx18-0 since cx180 looks really odd. */
81578 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
81579 - atomic_t *instance);
81580 + atomic_unchecked_t *instance);
81581
81582 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
81583 Since the parent disappears this ensures that v4l2_dev doesn't have an
81584 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
81585 index 9a36d92..0aafe2a 100644
81586 --- a/include/net/9p/transport.h
81587 +++ b/include/net/9p/transport.h
81588 @@ -60,7 +60,7 @@ struct p9_trans_module {
81589 int (*cancel) (struct p9_client *, struct p9_req_t *req);
81590 int (*zc_request)(struct p9_client *, struct p9_req_t *,
81591 char *, char *, int , int, int, int);
81592 -};
81593 +} __do_const;
81594
81595 void v9fs_register_trans(struct p9_trans_module *m);
81596 void v9fs_unregister_trans(struct p9_trans_module *m);
81597 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
81598 index c853b16d..37fccb7 100644
81599 --- a/include/net/bluetooth/l2cap.h
81600 +++ b/include/net/bluetooth/l2cap.h
81601 @@ -557,7 +557,7 @@ struct l2cap_ops {
81602 long (*get_sndtimeo) (struct l2cap_chan *chan);
81603 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
81604 unsigned long len, int nb);
81605 -};
81606 +} __do_const;
81607
81608 struct l2cap_conn {
81609 struct hci_conn *hcon;
81610 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
81611 index f2ae33d..c457cf0 100644
81612 --- a/include/net/caif/cfctrl.h
81613 +++ b/include/net/caif/cfctrl.h
81614 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
81615 void (*radioset_rsp)(void);
81616 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
81617 struct cflayer *client_layer);
81618 -};
81619 +} __no_const;
81620
81621 /* Link Setup Parameters for CAIF-Links. */
81622 struct cfctrl_link_param {
81623 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
81624 struct cfctrl {
81625 struct cfsrvl serv;
81626 struct cfctrl_rsp res;
81627 - atomic_t req_seq_no;
81628 - atomic_t rsp_seq_no;
81629 + atomic_unchecked_t req_seq_no;
81630 + atomic_unchecked_t rsp_seq_no;
81631 struct list_head list;
81632 /* Protects from simultaneous access to first_req list */
81633 spinlock_t info_list_lock;
81634 diff --git a/include/net/flow.h b/include/net/flow.h
81635 index 65ce471..b7bbe9b 100644
81636 --- a/include/net/flow.h
81637 +++ b/include/net/flow.h
81638 @@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
81639
81640 void flow_cache_flush(void);
81641 void flow_cache_flush_deferred(void);
81642 -extern atomic_t flow_cache_genid;
81643 +extern atomic_unchecked_t flow_cache_genid;
81644
81645 #endif
81646 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
81647 index 1b177ed..a24a138 100644
81648 --- a/include/net/genetlink.h
81649 +++ b/include/net/genetlink.h
81650 @@ -118,7 +118,7 @@ struct genl_ops {
81651 u8 cmd;
81652 u8 internal_flags;
81653 u8 flags;
81654 -};
81655 +} __do_const;
81656
81657 int __genl_register_family(struct genl_family *family);
81658
81659 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
81660 index 734d9b5..48a9a4b 100644
81661 --- a/include/net/gro_cells.h
81662 +++ b/include/net/gro_cells.h
81663 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
81664 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
81665
81666 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
81667 - atomic_long_inc(&dev->rx_dropped);
81668 + atomic_long_inc_unchecked(&dev->rx_dropped);
81669 kfree_skb(skb);
81670 return;
81671 }
81672 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
81673 index c55aeed..b3393f4 100644
81674 --- a/include/net/inet_connection_sock.h
81675 +++ b/include/net/inet_connection_sock.h
81676 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
81677 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
81678 int (*bind_conflict)(const struct sock *sk,
81679 const struct inet_bind_bucket *tb, bool relax);
81680 -};
81681 +} __do_const;
81682
81683 /** inet_connection_sock - INET connection oriented sock
81684 *
81685 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
81686 index f4e127a..c3d5e9c 100644
81687 --- a/include/net/inetpeer.h
81688 +++ b/include/net/inetpeer.h
81689 @@ -47,8 +47,8 @@ struct inet_peer {
81690 */
81691 union {
81692 struct {
81693 - atomic_t rid; /* Frag reception counter */
81694 - atomic_t ip_id_count; /* IP ID for the next packet */
81695 + atomic_unchecked_t rid; /* Frag reception counter */
81696 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
81697 };
81698 struct rcu_head rcu;
81699 struct inet_peer *gc_next;
81700 @@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
81701 /* can be called with or without local BH being disabled */
81702 static inline int inet_getid(struct inet_peer *p, int more)
81703 {
81704 - int old, new;
81705 + int id;
81706 more++;
81707 inet_peer_refcheck(p);
81708 - do {
81709 - old = atomic_read(&p->ip_id_count);
81710 - new = old + more;
81711 - if (!new)
81712 - new = 1;
81713 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
81714 - return new;
81715 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
81716 + if (!id)
81717 + id = atomic_inc_return_unchecked(&p->ip_id_count);
81718 + return id;
81719 }
81720
81721 #endif /* _NET_INETPEER_H */
81722 diff --git a/include/net/ip.h b/include/net/ip.h
81723 index 5a25f36..2e73203 100644
81724 --- a/include/net/ip.h
81725 +++ b/include/net/ip.h
81726 @@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
81727
81728 void inet_get_local_port_range(struct net *net, int *low, int *high);
81729
81730 -extern unsigned long *sysctl_local_reserved_ports;
81731 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
81732 static inline int inet_is_reserved_local_port(int port)
81733 {
81734 return test_bit(port, sysctl_local_reserved_ports);
81735 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
81736 index 9922093..a1755d6 100644
81737 --- a/include/net/ip_fib.h
81738 +++ b/include/net/ip_fib.h
81739 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
81740
81741 #define FIB_RES_SADDR(net, res) \
81742 ((FIB_RES_NH(res).nh_saddr_genid == \
81743 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
81744 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
81745 FIB_RES_NH(res).nh_saddr : \
81746 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
81747 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
81748 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
81749 index 5679d92..2e7a690 100644
81750 --- a/include/net/ip_vs.h
81751 +++ b/include/net/ip_vs.h
81752 @@ -558,7 +558,7 @@ struct ip_vs_conn {
81753 struct ip_vs_conn *control; /* Master control connection */
81754 atomic_t n_control; /* Number of controlled ones */
81755 struct ip_vs_dest *dest; /* real server */
81756 - atomic_t in_pkts; /* incoming packet counter */
81757 + atomic_unchecked_t in_pkts; /* incoming packet counter */
81758
81759 /* packet transmitter for different forwarding methods. If it
81760 mangles the packet, it must return NF_DROP or better NF_STOLEN,
81761 @@ -705,7 +705,7 @@ struct ip_vs_dest {
81762 __be16 port; /* port number of the server */
81763 union nf_inet_addr addr; /* IP address of the server */
81764 volatile unsigned int flags; /* dest status flags */
81765 - atomic_t conn_flags; /* flags to copy to conn */
81766 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
81767 atomic_t weight; /* server weight */
81768
81769 atomic_t refcnt; /* reference counter */
81770 @@ -960,11 +960,11 @@ struct netns_ipvs {
81771 /* ip_vs_lblc */
81772 int sysctl_lblc_expiration;
81773 struct ctl_table_header *lblc_ctl_header;
81774 - struct ctl_table *lblc_ctl_table;
81775 + ctl_table_no_const *lblc_ctl_table;
81776 /* ip_vs_lblcr */
81777 int sysctl_lblcr_expiration;
81778 struct ctl_table_header *lblcr_ctl_header;
81779 - struct ctl_table *lblcr_ctl_table;
81780 + ctl_table_no_const *lblcr_ctl_table;
81781 /* ip_vs_est */
81782 struct list_head est_list; /* estimator list */
81783 spinlock_t est_lock;
81784 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
81785 index 0224402..dafaf94a 100644
81786 --- a/include/net/irda/ircomm_tty.h
81787 +++ b/include/net/irda/ircomm_tty.h
81788 @@ -35,6 +35,7 @@
81789 #include <linux/termios.h>
81790 #include <linux/timer.h>
81791 #include <linux/tty.h> /* struct tty_struct */
81792 +#include <asm/local.h>
81793
81794 #include <net/irda/irias_object.h>
81795 #include <net/irda/ircomm_core.h>
81796 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
81797 index 714cc9a..ea05f3e 100644
81798 --- a/include/net/iucv/af_iucv.h
81799 +++ b/include/net/iucv/af_iucv.h
81800 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
81801 struct iucv_sock_list {
81802 struct hlist_head head;
81803 rwlock_t lock;
81804 - atomic_t autobind_name;
81805 + atomic_unchecked_t autobind_name;
81806 };
81807
81808 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
81809 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
81810 index f3be818..bf46196 100644
81811 --- a/include/net/llc_c_ac.h
81812 +++ b/include/net/llc_c_ac.h
81813 @@ -87,7 +87,7 @@
81814 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
81815 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
81816
81817 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81818 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81819
81820 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
81821 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
81822 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
81823 index 3948cf1..83b28c4 100644
81824 --- a/include/net/llc_c_ev.h
81825 +++ b/include/net/llc_c_ev.h
81826 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
81827 return (struct llc_conn_state_ev *)skb->cb;
81828 }
81829
81830 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81831 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81832 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81833 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81834
81835 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
81836 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
81837 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
81838 index 0e79cfb..f46db31 100644
81839 --- a/include/net/llc_c_st.h
81840 +++ b/include/net/llc_c_st.h
81841 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
81842 u8 next_state;
81843 llc_conn_ev_qfyr_t *ev_qualifiers;
81844 llc_conn_action_t *ev_actions;
81845 -};
81846 +} __do_const;
81847
81848 struct llc_conn_state {
81849 u8 current_state;
81850 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
81851 index a61b98c..aade1eb 100644
81852 --- a/include/net/llc_s_ac.h
81853 +++ b/include/net/llc_s_ac.h
81854 @@ -23,7 +23,7 @@
81855 #define SAP_ACT_TEST_IND 9
81856
81857 /* All action functions must look like this */
81858 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81859 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81860
81861 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
81862 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
81863 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
81864 index 567c681..cd73ac0 100644
81865 --- a/include/net/llc_s_st.h
81866 +++ b/include/net/llc_s_st.h
81867 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
81868 llc_sap_ev_t ev;
81869 u8 next_state;
81870 llc_sap_action_t *ev_actions;
81871 -};
81872 +} __do_const;
81873
81874 struct llc_sap_state {
81875 u8 curr_state;
81876 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
81877 index 7ceed99..d3ffaa2 100644
81878 --- a/include/net/mac80211.h
81879 +++ b/include/net/mac80211.h
81880 @@ -4407,7 +4407,7 @@ struct rate_control_ops {
81881 void (*add_sta_debugfs)(void *priv, void *priv_sta,
81882 struct dentry *dir);
81883 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
81884 -};
81885 +} __do_const;
81886
81887 static inline int rate_supported(struct ieee80211_sta *sta,
81888 enum ieee80211_band band,
81889 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
81890 index 536501a..74ad02bc 100644
81891 --- a/include/net/neighbour.h
81892 +++ b/include/net/neighbour.h
81893 @@ -123,7 +123,7 @@ struct neigh_ops {
81894 void (*error_report)(struct neighbour *, struct sk_buff *);
81895 int (*output)(struct neighbour *, struct sk_buff *);
81896 int (*connected_output)(struct neighbour *, struct sk_buff *);
81897 -};
81898 +} __do_const;
81899
81900 struct pneigh_entry {
81901 struct pneigh_entry *next;
81902 @@ -178,7 +178,7 @@ struct neigh_table {
81903 struct neigh_statistics __percpu *stats;
81904 struct neigh_hash_table __rcu *nht;
81905 struct pneigh_entry **phash_buckets;
81906 -};
81907 +} __randomize_layout;
81908
81909 #define NEIGH_PRIV_ALIGN sizeof(long long)
81910 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
81911 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
81912 index da68c9a..c4a0720 100644
81913 --- a/include/net/net_namespace.h
81914 +++ b/include/net/net_namespace.h
81915 @@ -124,8 +124,8 @@ struct net {
81916 struct netns_ipvs *ipvs;
81917 #endif
81918 struct sock *diag_nlsk;
81919 - atomic_t fnhe_genid;
81920 -};
81921 + atomic_unchecked_t fnhe_genid;
81922 +} __randomize_layout;
81923
81924 /*
81925 * ifindex generation is per-net namespace, and loopback is
81926 @@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
81927 #define __net_init __init
81928 #define __net_exit __exit_refok
81929 #define __net_initdata __initdata
81930 +#ifdef CONSTIFY_PLUGIN
81931 #define __net_initconst __initconst
81932 +#else
81933 +#define __net_initconst __initdata
81934 +#endif
81935 #endif
81936
81937 struct pernet_operations {
81938 @@ -291,7 +295,7 @@ struct pernet_operations {
81939 void (*exit_batch)(struct list_head *net_exit_list);
81940 int *id;
81941 size_t size;
81942 -};
81943 +} __do_const;
81944
81945 /*
81946 * Use these carefully. If you implement a network device and it
81947 @@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
81948
81949 static inline int rt_genid_ipv4(struct net *net)
81950 {
81951 - return atomic_read(&net->ipv4.rt_genid);
81952 + return atomic_read_unchecked(&net->ipv4.rt_genid);
81953 }
81954
81955 static inline void rt_genid_bump_ipv4(struct net *net)
81956 {
81957 - atomic_inc(&net->ipv4.rt_genid);
81958 + atomic_inc_unchecked(&net->ipv4.rt_genid);
81959 }
81960
81961 #if IS_ENABLED(CONFIG_IPV6)
81962 static inline int rt_genid_ipv6(struct net *net)
81963 {
81964 - return atomic_read(&net->ipv6.rt_genid);
81965 + return atomic_read_unchecked(&net->ipv6.rt_genid);
81966 }
81967
81968 static inline void rt_genid_bump_ipv6(struct net *net)
81969 {
81970 - atomic_inc(&net->ipv6.rt_genid);
81971 + atomic_inc_unchecked(&net->ipv6.rt_genid);
81972 }
81973 #else
81974 static inline int rt_genid_ipv6(struct net *net)
81975 @@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
81976
81977 static inline int fnhe_genid(struct net *net)
81978 {
81979 - return atomic_read(&net->fnhe_genid);
81980 + return atomic_read_unchecked(&net->fnhe_genid);
81981 }
81982
81983 static inline void fnhe_genid_bump(struct net *net)
81984 {
81985 - atomic_inc(&net->fnhe_genid);
81986 + atomic_inc_unchecked(&net->fnhe_genid);
81987 }
81988
81989 #endif /* __NET_NET_NAMESPACE_H */
81990 diff --git a/include/net/netdma.h b/include/net/netdma.h
81991 index 8ba8ce2..99b7fff 100644
81992 --- a/include/net/netdma.h
81993 +++ b/include/net/netdma.h
81994 @@ -24,7 +24,7 @@
81995 #include <linux/dmaengine.h>
81996 #include <linux/skbuff.h>
81997
81998 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81999 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82000 struct sk_buff *skb, int offset, struct iovec *to,
82001 size_t len, struct dma_pinned_list *pinned_list);
82002
82003 diff --git a/include/net/netlink.h b/include/net/netlink.h
82004 index 2b47eaa..6d5bcc2 100644
82005 --- a/include/net/netlink.h
82006 +++ b/include/net/netlink.h
82007 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
82008 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
82009 {
82010 if (mark)
82011 - skb_trim(skb, (unsigned char *) mark - skb->data);
82012 + skb_trim(skb, (const unsigned char *) mark - skb->data);
82013 }
82014
82015 /**
82016 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82017 index c9c0c53..53f24c3 100644
82018 --- a/include/net/netns/conntrack.h
82019 +++ b/include/net/netns/conntrack.h
82020 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
82021 struct nf_proto_net {
82022 #ifdef CONFIG_SYSCTL
82023 struct ctl_table_header *ctl_table_header;
82024 - struct ctl_table *ctl_table;
82025 + ctl_table_no_const *ctl_table;
82026 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
82027 struct ctl_table_header *ctl_compat_header;
82028 - struct ctl_table *ctl_compat_table;
82029 + ctl_table_no_const *ctl_compat_table;
82030 #endif
82031 #endif
82032 unsigned int users;
82033 @@ -58,7 +58,7 @@ struct nf_ip_net {
82034 struct nf_icmp_net icmpv6;
82035 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
82036 struct ctl_table_header *ctl_table_header;
82037 - struct ctl_table *ctl_table;
82038 + ctl_table_no_const *ctl_table;
82039 #endif
82040 };
82041
82042 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
82043 index ee520cb..9a0fd88 100644
82044 --- a/include/net/netns/ipv4.h
82045 +++ b/include/net/netns/ipv4.h
82046 @@ -72,7 +72,7 @@ struct netns_ipv4 {
82047
82048 kgid_t sysctl_ping_group_range[2];
82049
82050 - atomic_t dev_addr_genid;
82051 + atomic_unchecked_t dev_addr_genid;
82052
82053 #ifdef CONFIG_IP_MROUTE
82054 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
82055 @@ -82,6 +82,6 @@ struct netns_ipv4 {
82056 struct fib_rules_ops *mr_rules_ops;
82057 #endif
82058 #endif
82059 - atomic_t rt_genid;
82060 + atomic_unchecked_t rt_genid;
82061 };
82062 #endif
82063 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
82064 index 0fb2401..477d81c 100644
82065 --- a/include/net/netns/ipv6.h
82066 +++ b/include/net/netns/ipv6.h
82067 @@ -71,8 +71,8 @@ struct netns_ipv6 {
82068 struct fib_rules_ops *mr6_rules_ops;
82069 #endif
82070 #endif
82071 - atomic_t dev_addr_genid;
82072 - atomic_t rt_genid;
82073 + atomic_unchecked_t dev_addr_genid;
82074 + atomic_unchecked_t rt_genid;
82075 };
82076
82077 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
82078 diff --git a/include/net/ping.h b/include/net/ping.h
82079 index 90f4841..74446a8 100644
82080 --- a/include/net/ping.h
82081 +++ b/include/net/ping.h
82082 @@ -56,7 +56,7 @@ struct ping_iter_state {
82083 extern struct proto ping_prot;
82084 extern struct ping_table ping_table;
82085 #if IS_ENABLED(CONFIG_IPV6)
82086 -extern struct pingv6_ops pingv6_ops;
82087 +extern struct pingv6_ops *pingv6_ops;
82088 #endif
82089
82090 struct pingfakehdr {
82091 diff --git a/include/net/protocol.h b/include/net/protocol.h
82092 index fbf7676..a5e21c3 100644
82093 --- a/include/net/protocol.h
82094 +++ b/include/net/protocol.h
82095 @@ -44,7 +44,7 @@ struct net_protocol {
82096 void (*err_handler)(struct sk_buff *skb, u32 info);
82097 unsigned int no_policy:1,
82098 netns_ok:1;
82099 -};
82100 +} __do_const;
82101
82102 #if IS_ENABLED(CONFIG_IPV6)
82103 struct inet6_protocol {
82104 @@ -57,7 +57,7 @@ struct inet6_protocol {
82105 u8 type, u8 code, int offset,
82106 __be32 info);
82107 unsigned int flags; /* INET6_PROTO_xxx */
82108 -};
82109 +} __do_const;
82110
82111 #define INET6_PROTO_NOPOLICY 0x1
82112 #define INET6_PROTO_FINAL 0x2
82113 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
82114 index bb13a18..e734116 100644
82115 --- a/include/net/rtnetlink.h
82116 +++ b/include/net/rtnetlink.h
82117 @@ -79,7 +79,7 @@ struct rtnl_link_ops {
82118 const struct net_device *dev);
82119 unsigned int (*get_num_tx_queues)(void);
82120 unsigned int (*get_num_rx_queues)(void);
82121 -};
82122 +} __do_const;
82123
82124 int __rtnl_link_register(struct rtnl_link_ops *ops);
82125 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
82126 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
82127 index 6bd44fe..96f364e 100644
82128 --- a/include/net/sctp/checksum.h
82129 +++ b/include/net/sctp/checksum.h
82130 @@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
82131 unsigned int offset)
82132 {
82133 struct sctphdr *sh = sctp_hdr(skb);
82134 - __le32 ret, old = sh->checksum;
82135 - const struct skb_checksum_ops ops = {
82136 + __le32 ret, old = sh->checksum;
82137 + static const struct skb_checksum_ops ops = {
82138 .update = sctp_csum_update,
82139 .combine = sctp_csum_combine,
82140 };
82141 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
82142 index 4ef75af..5aa073a 100644
82143 --- a/include/net/sctp/sm.h
82144 +++ b/include/net/sctp/sm.h
82145 @@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
82146 typedef struct {
82147 sctp_state_fn_t *fn;
82148 const char *name;
82149 -} sctp_sm_table_entry_t;
82150 +} __do_const sctp_sm_table_entry_t;
82151
82152 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
82153 * currently in use.
82154 @@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
82155 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
82156
82157 /* Extern declarations for major data structures. */
82158 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82159 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82160
82161
82162 /* Get the size of a DATA chunk payload. */
82163 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
82164 index 0a248b3..4dcbe5c 100644
82165 --- a/include/net/sctp/structs.h
82166 +++ b/include/net/sctp/structs.h
82167 @@ -508,7 +508,7 @@ struct sctp_pf {
82168 struct sctp_association *asoc);
82169 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
82170 struct sctp_af *af;
82171 -};
82172 +} __do_const;
82173
82174
82175 /* Structure to track chunk fragments that have been acked, but peer
82176 diff --git a/include/net/sock.h b/include/net/sock.h
82177 index 2ef3c3e..e02013e 100644
82178 --- a/include/net/sock.h
82179 +++ b/include/net/sock.h
82180 @@ -348,7 +348,7 @@ struct sock {
82181 unsigned int sk_napi_id;
82182 unsigned int sk_ll_usec;
82183 #endif
82184 - atomic_t sk_drops;
82185 + atomic_unchecked_t sk_drops;
82186 int sk_rcvbuf;
82187
82188 struct sk_filter __rcu *sk_filter;
82189 @@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
82190 return ret >> PAGE_SHIFT;
82191 }
82192
82193 -static inline long
82194 +static inline long __intentional_overflow(-1)
82195 sk_memory_allocated(const struct sock *sk)
82196 {
82197 struct proto *prot = sk->sk_prot;
82198 @@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
82199 }
82200
82201 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
82202 - char __user *from, char *to,
82203 + char __user *from, unsigned char *to,
82204 int copy, int offset)
82205 {
82206 if (skb->ip_summed == CHECKSUM_NONE) {
82207 @@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
82208 }
82209 }
82210
82211 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82212 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82213
82214 /**
82215 * sk_page_frag - return an appropriate page_frag
82216 diff --git a/include/net/tcp.h b/include/net/tcp.h
82217 index 70e55d2..c5d8d53 100644
82218 --- a/include/net/tcp.h
82219 +++ b/include/net/tcp.h
82220 @@ -540,7 +540,7 @@ void tcp_retransmit_timer(struct sock *sk);
82221 void tcp_xmit_retransmit_queue(struct sock *);
82222 void tcp_simple_retransmit(struct sock *);
82223 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
82224 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82225 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82226
82227 void tcp_send_probe0(struct sock *);
82228 void tcp_send_partial(struct sock *);
82229 @@ -711,8 +711,8 @@ struct tcp_skb_cb {
82230 struct inet6_skb_parm h6;
82231 #endif
82232 } header; /* For incoming frames */
82233 - __u32 seq; /* Starting sequence number */
82234 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
82235 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
82236 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
82237 __u32 when; /* used to compute rtt's */
82238 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
82239
82240 @@ -726,7 +726,7 @@ struct tcp_skb_cb {
82241
82242 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
82243 /* 1 byte hole */
82244 - __u32 ack_seq; /* Sequence number ACK'd */
82245 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
82246 };
82247
82248 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
82249 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
82250 index 6b82fdf..14d74d2 100644
82251 --- a/include/net/xfrm.h
82252 +++ b/include/net/xfrm.h
82253 @@ -287,7 +287,6 @@ struct xfrm_dst;
82254 struct xfrm_policy_afinfo {
82255 unsigned short family;
82256 struct dst_ops *dst_ops;
82257 - void (*garbage_collect)(struct net *net);
82258 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
82259 const xfrm_address_t *saddr,
82260 const xfrm_address_t *daddr);
82261 @@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
82262 struct net_device *dev,
82263 const struct flowi *fl);
82264 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
82265 -};
82266 +} __do_const;
82267
82268 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
82269 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
82270 @@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
82271 int (*transport_finish)(struct sk_buff *skb,
82272 int async);
82273 void (*local_error)(struct sk_buff *skb, u32 mtu);
82274 -};
82275 +} __do_const;
82276
82277 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
82278 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
82279 @@ -429,7 +428,7 @@ struct xfrm_mode {
82280 struct module *owner;
82281 unsigned int encap;
82282 int flags;
82283 -};
82284 +} __do_const;
82285
82286 /* Flags for xfrm_mode. */
82287 enum {
82288 @@ -526,7 +525,7 @@ struct xfrm_policy {
82289 struct timer_list timer;
82290
82291 struct flow_cache_object flo;
82292 - atomic_t genid;
82293 + atomic_unchecked_t genid;
82294 u32 priority;
82295 u32 index;
82296 struct xfrm_mark mark;
82297 @@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
82298 }
82299
82300 void xfrm_garbage_collect(struct net *net);
82301 +void xfrm_garbage_collect_deferred(struct net *net);
82302
82303 #else
82304
82305 @@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
82306 static inline void xfrm_garbage_collect(struct net *net)
82307 {
82308 }
82309 +static inline void xfrm_garbage_collect_deferred(struct net *net)
82310 +{
82311 +}
82312 #endif
82313
82314 static __inline__
82315 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
82316 index 1017e0b..227aa4d 100644
82317 --- a/include/rdma/iw_cm.h
82318 +++ b/include/rdma/iw_cm.h
82319 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
82320 int backlog);
82321
82322 int (*destroy_listen)(struct iw_cm_id *cm_id);
82323 -};
82324 +} __no_const;
82325
82326 /**
82327 * iw_create_cm_id - Create an IW CM identifier.
82328 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
82329 index 52beadf..598734c 100644
82330 --- a/include/scsi/libfc.h
82331 +++ b/include/scsi/libfc.h
82332 @@ -771,6 +771,7 @@ struct libfc_function_template {
82333 */
82334 void (*disc_stop_final) (struct fc_lport *);
82335 };
82336 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
82337
82338 /**
82339 * struct fc_disc - Discovery context
82340 @@ -875,7 +876,7 @@ struct fc_lport {
82341 struct fc_vport *vport;
82342
82343 /* Operational Information */
82344 - struct libfc_function_template tt;
82345 + libfc_function_template_no_const tt;
82346 u8 link_up;
82347 u8 qfull;
82348 enum fc_lport_state state;
82349 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
82350 index d65fbec..f80fef2 100644
82351 --- a/include/scsi/scsi_device.h
82352 +++ b/include/scsi/scsi_device.h
82353 @@ -180,9 +180,9 @@ struct scsi_device {
82354 unsigned int max_device_blocked; /* what device_blocked counts down from */
82355 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
82356
82357 - atomic_t iorequest_cnt;
82358 - atomic_t iodone_cnt;
82359 - atomic_t ioerr_cnt;
82360 + atomic_unchecked_t iorequest_cnt;
82361 + atomic_unchecked_t iodone_cnt;
82362 + atomic_unchecked_t ioerr_cnt;
82363
82364 struct device sdev_gendev,
82365 sdev_dev;
82366 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
82367 index b797e8f..8e2c3aa 100644
82368 --- a/include/scsi/scsi_transport_fc.h
82369 +++ b/include/scsi/scsi_transport_fc.h
82370 @@ -751,7 +751,8 @@ struct fc_function_template {
82371 unsigned long show_host_system_hostname:1;
82372
82373 unsigned long disable_target_scan:1;
82374 -};
82375 +} __do_const;
82376 +typedef struct fc_function_template __no_const fc_function_template_no_const;
82377
82378
82379 /**
82380 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
82381 index ae6c3b8..fd748ac 100644
82382 --- a/include/sound/compress_driver.h
82383 +++ b/include/sound/compress_driver.h
82384 @@ -128,7 +128,7 @@ struct snd_compr_ops {
82385 struct snd_compr_caps *caps);
82386 int (*get_codec_caps) (struct snd_compr_stream *stream,
82387 struct snd_compr_codec_caps *codec);
82388 -};
82389 +} __no_const;
82390
82391 /**
82392 * struct snd_compr: Compressed device
82393 diff --git a/include/sound/soc.h b/include/sound/soc.h
82394 index 1f741cb..8cefc08 100644
82395 --- a/include/sound/soc.h
82396 +++ b/include/sound/soc.h
82397 @@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
82398 /* probe ordering - for components with runtime dependencies */
82399 int probe_order;
82400 int remove_order;
82401 -};
82402 +} __do_const;
82403
82404 /* SoC platform interface */
82405 struct snd_soc_platform_driver {
82406 @@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
82407 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
82408 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
82409 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
82410 -};
82411 +} __do_const;
82412
82413 struct snd_soc_platform {
82414 const char *name;
82415 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
82416 index 321301c..2ae5cb0 100644
82417 --- a/include/target/target_core_base.h
82418 +++ b/include/target/target_core_base.h
82419 @@ -687,7 +687,7 @@ struct se_device {
82420 atomic_long_t write_bytes;
82421 /* Active commands on this virtual SE device */
82422 atomic_t simple_cmds;
82423 - atomic_t dev_ordered_id;
82424 + atomic_unchecked_t dev_ordered_id;
82425 atomic_t dev_ordered_sync;
82426 atomic_t dev_qf_count;
82427 int export_count;
82428 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
82429 new file mode 100644
82430 index 0000000..fb634b7
82431 --- /dev/null
82432 +++ b/include/trace/events/fs.h
82433 @@ -0,0 +1,53 @@
82434 +#undef TRACE_SYSTEM
82435 +#define TRACE_SYSTEM fs
82436 +
82437 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
82438 +#define _TRACE_FS_H
82439 +
82440 +#include <linux/fs.h>
82441 +#include <linux/tracepoint.h>
82442 +
82443 +TRACE_EVENT(do_sys_open,
82444 +
82445 + TP_PROTO(const char *filename, int flags, int mode),
82446 +
82447 + TP_ARGS(filename, flags, mode),
82448 +
82449 + TP_STRUCT__entry(
82450 + __string( filename, filename )
82451 + __field( int, flags )
82452 + __field( int, mode )
82453 + ),
82454 +
82455 + TP_fast_assign(
82456 + __assign_str(filename, filename);
82457 + __entry->flags = flags;
82458 + __entry->mode = mode;
82459 + ),
82460 +
82461 + TP_printk("\"%s\" %x %o",
82462 + __get_str(filename), __entry->flags, __entry->mode)
82463 +);
82464 +
82465 +TRACE_EVENT(open_exec,
82466 +
82467 + TP_PROTO(const char *filename),
82468 +
82469 + TP_ARGS(filename),
82470 +
82471 + TP_STRUCT__entry(
82472 + __string( filename, filename )
82473 + ),
82474 +
82475 + TP_fast_assign(
82476 + __assign_str(filename, filename);
82477 + ),
82478 +
82479 + TP_printk("\"%s\"",
82480 + __get_str(filename))
82481 +);
82482 +
82483 +#endif /* _TRACE_FS_H */
82484 +
82485 +/* This part must be outside protection */
82486 +#include <trace/define_trace.h>
82487 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
82488 index 1c09820..7f5ec79 100644
82489 --- a/include/trace/events/irq.h
82490 +++ b/include/trace/events/irq.h
82491 @@ -36,7 +36,7 @@ struct softirq_action;
82492 */
82493 TRACE_EVENT(irq_handler_entry,
82494
82495 - TP_PROTO(int irq, struct irqaction *action),
82496 + TP_PROTO(int irq, const struct irqaction *action),
82497
82498 TP_ARGS(irq, action),
82499
82500 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
82501 */
82502 TRACE_EVENT(irq_handler_exit,
82503
82504 - TP_PROTO(int irq, struct irqaction *action, int ret),
82505 + TP_PROTO(int irq, const struct irqaction *action, int ret),
82506
82507 TP_ARGS(irq, action, ret),
82508
82509 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
82510 index 7caf44c..23c6f27 100644
82511 --- a/include/uapi/linux/a.out.h
82512 +++ b/include/uapi/linux/a.out.h
82513 @@ -39,6 +39,14 @@ enum machine_type {
82514 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
82515 };
82516
82517 +/* Constants for the N_FLAGS field */
82518 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82519 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
82520 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
82521 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
82522 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82523 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82524 +
82525 #if !defined (N_MAGIC)
82526 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
82527 #endif
82528 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
82529 index d876736..ccce5c0 100644
82530 --- a/include/uapi/linux/byteorder/little_endian.h
82531 +++ b/include/uapi/linux/byteorder/little_endian.h
82532 @@ -42,51 +42,51 @@
82533
82534 static inline __le64 __cpu_to_le64p(const __u64 *p)
82535 {
82536 - return (__force __le64)*p;
82537 + return (__force const __le64)*p;
82538 }
82539 -static inline __u64 __le64_to_cpup(const __le64 *p)
82540 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
82541 {
82542 - return (__force __u64)*p;
82543 + return (__force const __u64)*p;
82544 }
82545 static inline __le32 __cpu_to_le32p(const __u32 *p)
82546 {
82547 - return (__force __le32)*p;
82548 + return (__force const __le32)*p;
82549 }
82550 static inline __u32 __le32_to_cpup(const __le32 *p)
82551 {
82552 - return (__force __u32)*p;
82553 + return (__force const __u32)*p;
82554 }
82555 static inline __le16 __cpu_to_le16p(const __u16 *p)
82556 {
82557 - return (__force __le16)*p;
82558 + return (__force const __le16)*p;
82559 }
82560 static inline __u16 __le16_to_cpup(const __le16 *p)
82561 {
82562 - return (__force __u16)*p;
82563 + return (__force const __u16)*p;
82564 }
82565 static inline __be64 __cpu_to_be64p(const __u64 *p)
82566 {
82567 - return (__force __be64)__swab64p(p);
82568 + return (__force const __be64)__swab64p(p);
82569 }
82570 static inline __u64 __be64_to_cpup(const __be64 *p)
82571 {
82572 - return __swab64p((__u64 *)p);
82573 + return __swab64p((const __u64 *)p);
82574 }
82575 static inline __be32 __cpu_to_be32p(const __u32 *p)
82576 {
82577 - return (__force __be32)__swab32p(p);
82578 + return (__force const __be32)__swab32p(p);
82579 }
82580 -static inline __u32 __be32_to_cpup(const __be32 *p)
82581 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
82582 {
82583 - return __swab32p((__u32 *)p);
82584 + return __swab32p((const __u32 *)p);
82585 }
82586 static inline __be16 __cpu_to_be16p(const __u16 *p)
82587 {
82588 - return (__force __be16)__swab16p(p);
82589 + return (__force const __be16)__swab16p(p);
82590 }
82591 static inline __u16 __be16_to_cpup(const __be16 *p)
82592 {
82593 - return __swab16p((__u16 *)p);
82594 + return __swab16p((const __u16 *)p);
82595 }
82596 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
82597 #define __le64_to_cpus(x) do { (void)(x); } while (0)
82598 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
82599 index ef6103b..d4e65dd 100644
82600 --- a/include/uapi/linux/elf.h
82601 +++ b/include/uapi/linux/elf.h
82602 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
82603 #define PT_GNU_EH_FRAME 0x6474e550
82604
82605 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
82606 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
82607 +
82608 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
82609 +
82610 +/* Constants for the e_flags field */
82611 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82612 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
82613 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
82614 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
82615 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82616 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82617
82618 /*
82619 * Extended Numbering
82620 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
82621 #define DT_DEBUG 21
82622 #define DT_TEXTREL 22
82623 #define DT_JMPREL 23
82624 +#define DT_FLAGS 30
82625 + #define DF_TEXTREL 0x00000004
82626 #define DT_ENCODING 32
82627 #define OLD_DT_LOOS 0x60000000
82628 #define DT_LOOS 0x6000000d
82629 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
82630 #define PF_W 0x2
82631 #define PF_X 0x1
82632
82633 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
82634 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
82635 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
82636 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
82637 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
82638 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
82639 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
82640 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
82641 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
82642 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
82643 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
82644 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
82645 +
82646 typedef struct elf32_phdr{
82647 Elf32_Word p_type;
82648 Elf32_Off p_offset;
82649 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
82650 #define EI_OSABI 7
82651 #define EI_PAD 8
82652
82653 +#define EI_PAX 14
82654 +
82655 #define ELFMAG0 0x7f /* EI_MAG */
82656 #define ELFMAG1 'E'
82657 #define ELFMAG2 'L'
82658 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
82659 index aa169c4..6a2771d 100644
82660 --- a/include/uapi/linux/personality.h
82661 +++ b/include/uapi/linux/personality.h
82662 @@ -30,6 +30,7 @@ enum {
82663 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
82664 ADDR_NO_RANDOMIZE | \
82665 ADDR_COMPAT_LAYOUT | \
82666 + ADDR_LIMIT_3GB | \
82667 MMAP_PAGE_ZERO)
82668
82669 /*
82670 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
82671 index 7530e74..e714828 100644
82672 --- a/include/uapi/linux/screen_info.h
82673 +++ b/include/uapi/linux/screen_info.h
82674 @@ -43,7 +43,8 @@ struct screen_info {
82675 __u16 pages; /* 0x32 */
82676 __u16 vesa_attributes; /* 0x34 */
82677 __u32 capabilities; /* 0x36 */
82678 - __u8 _reserved[6]; /* 0x3a */
82679 + __u16 vesapm_size; /* 0x3a */
82680 + __u8 _reserved[4]; /* 0x3c */
82681 } __attribute__((packed));
82682
82683 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
82684 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
82685 index 0e011eb..82681b1 100644
82686 --- a/include/uapi/linux/swab.h
82687 +++ b/include/uapi/linux/swab.h
82688 @@ -43,7 +43,7 @@
82689 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
82690 */
82691
82692 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
82693 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
82694 {
82695 #ifdef __HAVE_BUILTIN_BSWAP16__
82696 return __builtin_bswap16(val);
82697 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
82698 #endif
82699 }
82700
82701 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
82702 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
82703 {
82704 #ifdef __HAVE_BUILTIN_BSWAP32__
82705 return __builtin_bswap32(val);
82706 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
82707 #endif
82708 }
82709
82710 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
82711 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
82712 {
82713 #ifdef __HAVE_BUILTIN_BSWAP64__
82714 return __builtin_bswap64(val);
82715 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
82716 index 6d67213..552fdd9 100644
82717 --- a/include/uapi/linux/sysctl.h
82718 +++ b/include/uapi/linux/sysctl.h
82719 @@ -155,8 +155,6 @@ enum
82720 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
82721 };
82722
82723 -
82724 -
82725 /* CTL_VM names: */
82726 enum
82727 {
82728 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
82729 index 437f1b0..0eeb38d 100644
82730 --- a/include/uapi/linux/videodev2.h
82731 +++ b/include/uapi/linux/videodev2.h
82732 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
82733 union {
82734 __s32 value;
82735 __s64 value64;
82736 - char *string;
82737 + char __user *string;
82738 };
82739 } __attribute__ ((packed));
82740
82741 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
82742 index e4629b9..6958086 100644
82743 --- a/include/uapi/linux/xattr.h
82744 +++ b/include/uapi/linux/xattr.h
82745 @@ -63,5 +63,9 @@
82746 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
82747 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
82748
82749 +/* User namespace */
82750 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
82751 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
82752 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
82753
82754 #endif /* _UAPI_LINUX_XATTR_H */
82755 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
82756 index f9466fa..f4e2b81 100644
82757 --- a/include/video/udlfb.h
82758 +++ b/include/video/udlfb.h
82759 @@ -53,10 +53,10 @@ struct dlfb_data {
82760 u32 pseudo_palette[256];
82761 int blank_mode; /*one of FB_BLANK_ */
82762 /* blit-only rendering path metrics, exposed through sysfs */
82763 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82764 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
82765 - atomic_t bytes_sent; /* to usb, after compression including overhead */
82766 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
82767 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82768 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
82769 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
82770 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
82771 };
82772
82773 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
82774 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
82775 index 30f5362..8ed8ac9 100644
82776 --- a/include/video/uvesafb.h
82777 +++ b/include/video/uvesafb.h
82778 @@ -122,6 +122,7 @@ struct uvesafb_par {
82779 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
82780 u8 pmi_setpal; /* PMI for palette changes */
82781 u16 *pmi_base; /* protected mode interface location */
82782 + u8 *pmi_code; /* protected mode code location */
82783 void *pmi_start;
82784 void *pmi_pal;
82785 u8 *vbe_state_orig; /*
82786 diff --git a/init/Kconfig b/init/Kconfig
82787 index 4e5d96a..93cd8a1 100644
82788 --- a/init/Kconfig
82789 +++ b/init/Kconfig
82790 @@ -1079,6 +1079,7 @@ endif # CGROUPS
82791
82792 config CHECKPOINT_RESTORE
82793 bool "Checkpoint/restore support" if EXPERT
82794 + depends on !GRKERNSEC
82795 default n
82796 help
82797 Enables additional kernel features in a sake of checkpoint/restore.
82798 @@ -1550,7 +1551,7 @@ config SLUB_DEBUG
82799
82800 config COMPAT_BRK
82801 bool "Disable heap randomization"
82802 - default y
82803 + default n
82804 help
82805 Randomizing heap placement makes heap exploits harder, but it
82806 also breaks ancient binaries (including anything libc5 based).
82807 @@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
82808 config STOP_MACHINE
82809 bool
82810 default y
82811 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
82812 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
82813 help
82814 Need stop_machine() primitive.
82815
82816 diff --git a/init/Makefile b/init/Makefile
82817 index 7bc47ee..6da2dc7 100644
82818 --- a/init/Makefile
82819 +++ b/init/Makefile
82820 @@ -2,6 +2,9 @@
82821 # Makefile for the linux kernel.
82822 #
82823
82824 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
82825 +asflags-y := $(GCC_PLUGINS_AFLAGS)
82826 +
82827 obj-y := main.o version.o mounts.o
82828 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
82829 obj-y += noinitramfs.o
82830 diff --git a/init/do_mounts.c b/init/do_mounts.c
82831 index 8e5addc..c96ea61 100644
82832 --- a/init/do_mounts.c
82833 +++ b/init/do_mounts.c
82834 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
82835 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
82836 {
82837 struct super_block *s;
82838 - int err = sys_mount(name, "/root", fs, flags, data);
82839 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
82840 if (err)
82841 return err;
82842
82843 - sys_chdir("/root");
82844 + sys_chdir((const char __force_user *)"/root");
82845 s = current->fs->pwd.dentry->d_sb;
82846 ROOT_DEV = s->s_dev;
82847 printk(KERN_INFO
82848 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
82849 va_start(args, fmt);
82850 vsprintf(buf, fmt, args);
82851 va_end(args);
82852 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
82853 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
82854 if (fd >= 0) {
82855 sys_ioctl(fd, FDEJECT, 0);
82856 sys_close(fd);
82857 }
82858 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
82859 - fd = sys_open("/dev/console", O_RDWR, 0);
82860 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
82861 if (fd >= 0) {
82862 sys_ioctl(fd, TCGETS, (long)&termios);
82863 termios.c_lflag &= ~ICANON;
82864 sys_ioctl(fd, TCSETSF, (long)&termios);
82865 - sys_read(fd, &c, 1);
82866 + sys_read(fd, (char __user *)&c, 1);
82867 termios.c_lflag |= ICANON;
82868 sys_ioctl(fd, TCSETSF, (long)&termios);
82869 sys_close(fd);
82870 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
82871 mount_root();
82872 out:
82873 devtmpfs_mount("dev");
82874 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
82875 - sys_chroot(".");
82876 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82877 + sys_chroot((const char __force_user *)".");
82878 }
82879
82880 static bool is_tmpfs;
82881 diff --git a/init/do_mounts.h b/init/do_mounts.h
82882 index f5b978a..69dbfe8 100644
82883 --- a/init/do_mounts.h
82884 +++ b/init/do_mounts.h
82885 @@ -15,15 +15,15 @@ extern int root_mountflags;
82886
82887 static inline int create_dev(char *name, dev_t dev)
82888 {
82889 - sys_unlink(name);
82890 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
82891 + sys_unlink((char __force_user *)name);
82892 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
82893 }
82894
82895 #if BITS_PER_LONG == 32
82896 static inline u32 bstat(char *name)
82897 {
82898 struct stat64 stat;
82899 - if (sys_stat64(name, &stat) != 0)
82900 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
82901 return 0;
82902 if (!S_ISBLK(stat.st_mode))
82903 return 0;
82904 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
82905 static inline u32 bstat(char *name)
82906 {
82907 struct stat stat;
82908 - if (sys_newstat(name, &stat) != 0)
82909 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
82910 return 0;
82911 if (!S_ISBLK(stat.st_mode))
82912 return 0;
82913 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
82914 index 3e0878e..8a9d7a0 100644
82915 --- a/init/do_mounts_initrd.c
82916 +++ b/init/do_mounts_initrd.c
82917 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
82918 {
82919 sys_unshare(CLONE_FS | CLONE_FILES);
82920 /* stdin/stdout/stderr for /linuxrc */
82921 - sys_open("/dev/console", O_RDWR, 0);
82922 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
82923 sys_dup(0);
82924 sys_dup(0);
82925 /* move initrd over / and chdir/chroot in initrd root */
82926 - sys_chdir("/root");
82927 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
82928 - sys_chroot(".");
82929 + sys_chdir((const char __force_user *)"/root");
82930 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82931 + sys_chroot((const char __force_user *)".");
82932 sys_setsid();
82933 return 0;
82934 }
82935 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
82936 create_dev("/dev/root.old", Root_RAM0);
82937 /* mount initrd on rootfs' /root */
82938 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
82939 - sys_mkdir("/old", 0700);
82940 - sys_chdir("/old");
82941 + sys_mkdir((const char __force_user *)"/old", 0700);
82942 + sys_chdir((const char __force_user *)"/old");
82943
82944 /* try loading default modules from initrd */
82945 load_default_modules();
82946 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
82947 current->flags &= ~PF_FREEZER_SKIP;
82948
82949 /* move initrd to rootfs' /old */
82950 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
82951 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
82952 /* switch root and cwd back to / of rootfs */
82953 - sys_chroot("..");
82954 + sys_chroot((const char __force_user *)"..");
82955
82956 if (new_decode_dev(real_root_dev) == Root_RAM0) {
82957 - sys_chdir("/old");
82958 + sys_chdir((const char __force_user *)"/old");
82959 return;
82960 }
82961
82962 - sys_chdir("/");
82963 + sys_chdir((const char __force_user *)"/");
82964 ROOT_DEV = new_decode_dev(real_root_dev);
82965 mount_root();
82966
82967 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
82968 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
82969 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
82970 if (!error)
82971 printk("okay\n");
82972 else {
82973 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
82974 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
82975 if (error == -ENOENT)
82976 printk("/initrd does not exist. Ignored.\n");
82977 else
82978 printk("failed\n");
82979 printk(KERN_NOTICE "Unmounting old root\n");
82980 - sys_umount("/old", MNT_DETACH);
82981 + sys_umount((char __force_user *)"/old", MNT_DETACH);
82982 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
82983 if (fd < 0) {
82984 error = fd;
82985 @@ -127,11 +127,11 @@ int __init initrd_load(void)
82986 * mounted in the normal path.
82987 */
82988 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
82989 - sys_unlink("/initrd.image");
82990 + sys_unlink((const char __force_user *)"/initrd.image");
82991 handle_initrd();
82992 return 1;
82993 }
82994 }
82995 - sys_unlink("/initrd.image");
82996 + sys_unlink((const char __force_user *)"/initrd.image");
82997 return 0;
82998 }
82999 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
83000 index 8cb6db5..d729f50 100644
83001 --- a/init/do_mounts_md.c
83002 +++ b/init/do_mounts_md.c
83003 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
83004 partitioned ? "_d" : "", minor,
83005 md_setup_args[ent].device_names);
83006
83007 - fd = sys_open(name, 0, 0);
83008 + fd = sys_open((char __force_user *)name, 0, 0);
83009 if (fd < 0) {
83010 printk(KERN_ERR "md: open failed - cannot start "
83011 "array %s\n", name);
83012 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
83013 * array without it
83014 */
83015 sys_close(fd);
83016 - fd = sys_open(name, 0, 0);
83017 + fd = sys_open((char __force_user *)name, 0, 0);
83018 sys_ioctl(fd, BLKRRPART, 0);
83019 }
83020 sys_close(fd);
83021 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
83022
83023 wait_for_device_probe();
83024
83025 - fd = sys_open("/dev/md0", 0, 0);
83026 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
83027 if (fd >= 0) {
83028 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
83029 sys_close(fd);
83030 diff --git a/init/init_task.c b/init/init_task.c
83031 index ba0a7f36..2bcf1d5 100644
83032 --- a/init/init_task.c
83033 +++ b/init/init_task.c
83034 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
83035 * Initial thread structure. Alignment of this is handled by a special
83036 * linker map entry.
83037 */
83038 +#ifdef CONFIG_X86
83039 +union thread_union init_thread_union __init_task_data;
83040 +#else
83041 union thread_union init_thread_union __init_task_data =
83042 { INIT_THREAD_INFO(init_task) };
83043 +#endif
83044 diff --git a/init/initramfs.c b/init/initramfs.c
83045 index a67ef9d..2d17ed9 100644
83046 --- a/init/initramfs.c
83047 +++ b/init/initramfs.c
83048 @@ -84,7 +84,7 @@ static void __init free_hash(void)
83049 }
83050 }
83051
83052 -static long __init do_utime(char *filename, time_t mtime)
83053 +static long __init do_utime(char __force_user *filename, time_t mtime)
83054 {
83055 struct timespec t[2];
83056
83057 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
83058 struct dir_entry *de, *tmp;
83059 list_for_each_entry_safe(de, tmp, &dir_list, list) {
83060 list_del(&de->list);
83061 - do_utime(de->name, de->mtime);
83062 + do_utime((char __force_user *)de->name, de->mtime);
83063 kfree(de->name);
83064 kfree(de);
83065 }
83066 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
83067 if (nlink >= 2) {
83068 char *old = find_link(major, minor, ino, mode, collected);
83069 if (old)
83070 - return (sys_link(old, collected) < 0) ? -1 : 1;
83071 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
83072 }
83073 return 0;
83074 }
83075 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
83076 {
83077 struct stat st;
83078
83079 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
83080 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
83081 if (S_ISDIR(st.st_mode))
83082 - sys_rmdir(path);
83083 + sys_rmdir((char __force_user *)path);
83084 else
83085 - sys_unlink(path);
83086 + sys_unlink((char __force_user *)path);
83087 }
83088 }
83089
83090 @@ -315,7 +315,7 @@ static int __init do_name(void)
83091 int openflags = O_WRONLY|O_CREAT;
83092 if (ml != 1)
83093 openflags |= O_TRUNC;
83094 - wfd = sys_open(collected, openflags, mode);
83095 + wfd = sys_open((char __force_user *)collected, openflags, mode);
83096
83097 if (wfd >= 0) {
83098 sys_fchown(wfd, uid, gid);
83099 @@ -327,17 +327,17 @@ static int __init do_name(void)
83100 }
83101 }
83102 } else if (S_ISDIR(mode)) {
83103 - sys_mkdir(collected, mode);
83104 - sys_chown(collected, uid, gid);
83105 - sys_chmod(collected, mode);
83106 + sys_mkdir((char __force_user *)collected, mode);
83107 + sys_chown((char __force_user *)collected, uid, gid);
83108 + sys_chmod((char __force_user *)collected, mode);
83109 dir_add(collected, mtime);
83110 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
83111 S_ISFIFO(mode) || S_ISSOCK(mode)) {
83112 if (maybe_link() == 0) {
83113 - sys_mknod(collected, mode, rdev);
83114 - sys_chown(collected, uid, gid);
83115 - sys_chmod(collected, mode);
83116 - do_utime(collected, mtime);
83117 + sys_mknod((char __force_user *)collected, mode, rdev);
83118 + sys_chown((char __force_user *)collected, uid, gid);
83119 + sys_chmod((char __force_user *)collected, mode);
83120 + do_utime((char __force_user *)collected, mtime);
83121 }
83122 }
83123 return 0;
83124 @@ -346,15 +346,15 @@ static int __init do_name(void)
83125 static int __init do_copy(void)
83126 {
83127 if (count >= body_len) {
83128 - sys_write(wfd, victim, body_len);
83129 + sys_write(wfd, (char __force_user *)victim, body_len);
83130 sys_close(wfd);
83131 - do_utime(vcollected, mtime);
83132 + do_utime((char __force_user *)vcollected, mtime);
83133 kfree(vcollected);
83134 eat(body_len);
83135 state = SkipIt;
83136 return 0;
83137 } else {
83138 - sys_write(wfd, victim, count);
83139 + sys_write(wfd, (char __force_user *)victim, count);
83140 body_len -= count;
83141 eat(count);
83142 return 1;
83143 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
83144 {
83145 collected[N_ALIGN(name_len) + body_len] = '\0';
83146 clean_path(collected, 0);
83147 - sys_symlink(collected + N_ALIGN(name_len), collected);
83148 - sys_lchown(collected, uid, gid);
83149 - do_utime(collected, mtime);
83150 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
83151 + sys_lchown((char __force_user *)collected, uid, gid);
83152 + do_utime((char __force_user *)collected, mtime);
83153 state = SkipIt;
83154 next_state = Reset;
83155 return 0;
83156 @@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
83157 {
83158 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
83159 if (err)
83160 - panic(err); /* Failed to decompress INTERNAL initramfs */
83161 + panic("%s", err); /* Failed to decompress INTERNAL initramfs */
83162 if (initrd_start) {
83163 #ifdef CONFIG_BLK_DEV_RAM
83164 int fd;
83165 diff --git a/init/main.c b/init/main.c
83166 index febc511..f0851763 100644
83167 --- a/init/main.c
83168 +++ b/init/main.c
83169 @@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
83170 extern void tc_init(void);
83171 #endif
83172
83173 +extern void grsecurity_init(void);
83174 +
83175 /*
83176 * Debug helper: via this flag we know that we are in 'early bootup code'
83177 * where only the boot processor is running with IRQ disabled. This means
83178 @@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
83179
83180 __setup("reset_devices", set_reset_devices);
83181
83182 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83183 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
83184 +static int __init setup_grsec_proc_gid(char *str)
83185 +{
83186 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
83187 + return 1;
83188 +}
83189 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
83190 +#endif
83191 +
83192 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
83193 +unsigned long pax_user_shadow_base __read_only;
83194 +EXPORT_SYMBOL(pax_user_shadow_base);
83195 +extern char pax_enter_kernel_user[];
83196 +extern char pax_exit_kernel_user[];
83197 +#endif
83198 +
83199 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
83200 +static int __init setup_pax_nouderef(char *str)
83201 +{
83202 +#ifdef CONFIG_X86_32
83203 + unsigned int cpu;
83204 + struct desc_struct *gdt;
83205 +
83206 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
83207 + gdt = get_cpu_gdt_table(cpu);
83208 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
83209 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
83210 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
83211 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
83212 + }
83213 + loadsegment(ds, __KERNEL_DS);
83214 + loadsegment(es, __KERNEL_DS);
83215 + loadsegment(ss, __KERNEL_DS);
83216 +#else
83217 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
83218 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
83219 + clone_pgd_mask = ~(pgdval_t)0UL;
83220 + pax_user_shadow_base = 0UL;
83221 + setup_clear_cpu_cap(X86_FEATURE_PCID);
83222 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
83223 +#endif
83224 +
83225 + return 0;
83226 +}
83227 +early_param("pax_nouderef", setup_pax_nouderef);
83228 +
83229 +#ifdef CONFIG_X86_64
83230 +static int __init setup_pax_weakuderef(char *str)
83231 +{
83232 + if (clone_pgd_mask != ~(pgdval_t)0UL)
83233 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
83234 + return 1;
83235 +}
83236 +__setup("pax_weakuderef", setup_pax_weakuderef);
83237 +#endif
83238 +#endif
83239 +
83240 +#ifdef CONFIG_PAX_SOFTMODE
83241 +int pax_softmode;
83242 +
83243 +static int __init setup_pax_softmode(char *str)
83244 +{
83245 + get_option(&str, &pax_softmode);
83246 + return 1;
83247 +}
83248 +__setup("pax_softmode=", setup_pax_softmode);
83249 +#endif
83250 +
83251 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
83252 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
83253 static const char *panic_later, *panic_param;
83254 @@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
83255 {
83256 int count = preempt_count();
83257 int ret;
83258 - char msgbuf[64];
83259 + const char *msg1 = "", *msg2 = "";
83260
83261 if (initcall_debug)
83262 ret = do_one_initcall_debug(fn);
83263 else
83264 ret = fn();
83265
83266 - msgbuf[0] = 0;
83267 -
83268 if (preempt_count() != count) {
83269 - sprintf(msgbuf, "preemption imbalance ");
83270 + msg1 = " preemption imbalance";
83271 preempt_count_set(count);
83272 }
83273 if (irqs_disabled()) {
83274 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
83275 + msg2 = " disabled interrupts";
83276 local_irq_enable();
83277 }
83278 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
83279 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
83280
83281 + add_latent_entropy();
83282 return ret;
83283 }
83284
83285 @@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
83286 {
83287 argv_init[0] = init_filename;
83288 return do_execve(init_filename,
83289 - (const char __user *const __user *)argv_init,
83290 - (const char __user *const __user *)envp_init);
83291 + (const char __user *const __force_user *)argv_init,
83292 + (const char __user *const __force_user *)envp_init);
83293 }
83294
83295 static int try_to_run_init_process(const char *init_filename)
83296 @@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
83297 return ret;
83298 }
83299
83300 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83301 +extern int gr_init_ran;
83302 +#endif
83303 +
83304 static noinline void __init kernel_init_freeable(void);
83305
83306 static int __ref kernel_init(void *unused)
83307 @@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
83308 ramdisk_execute_command, ret);
83309 }
83310
83311 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83312 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
83313 + gr_init_ran = 1;
83314 +#endif
83315 +
83316 /*
83317 * We try each of these until one succeeds.
83318 *
83319 @@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
83320 do_basic_setup();
83321
83322 /* Open the /dev/console on the rootfs, this should never fail */
83323 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
83324 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
83325 pr_err("Warning: unable to open an initial console.\n");
83326
83327 (void) sys_dup(0);
83328 @@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
83329 if (!ramdisk_execute_command)
83330 ramdisk_execute_command = "/init";
83331
83332 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
83333 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
83334 ramdisk_execute_command = NULL;
83335 prepare_namespace();
83336 }
83337
83338 + grsecurity_init();
83339 +
83340 /*
83341 * Ok, we have completed the initial bootup, and
83342 * we're essentially up and running. Get rid of the
83343 diff --git a/ipc/compat.c b/ipc/compat.c
83344 index 892f658..e7c6320 100644
83345 --- a/ipc/compat.c
83346 +++ b/ipc/compat.c
83347 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
83348 COMPAT_SHMLBA);
83349 if (err < 0)
83350 return err;
83351 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
83352 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
83353 }
83354 case SHMDT:
83355 return sys_shmdt(compat_ptr(ptr));
83356 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
83357 index b0e99de..09f385c 100644
83358 --- a/ipc/ipc_sysctl.c
83359 +++ b/ipc/ipc_sysctl.c
83360 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
83361 static int proc_ipc_dointvec(ctl_table *table, int write,
83362 void __user *buffer, size_t *lenp, loff_t *ppos)
83363 {
83364 - struct ctl_table ipc_table;
83365 + ctl_table_no_const ipc_table;
83366
83367 memcpy(&ipc_table, table, sizeof(ipc_table));
83368 ipc_table.data = get_ipc(table);
83369 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
83370 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
83371 void __user *buffer, size_t *lenp, loff_t *ppos)
83372 {
83373 - struct ctl_table ipc_table;
83374 + ctl_table_no_const ipc_table;
83375
83376 memcpy(&ipc_table, table, sizeof(ipc_table));
83377 ipc_table.data = get_ipc(table);
83378 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
83379 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83380 void __user *buffer, size_t *lenp, loff_t *ppos)
83381 {
83382 - struct ctl_table ipc_table;
83383 + ctl_table_no_const ipc_table;
83384 size_t lenp_bef = *lenp;
83385 int rc;
83386
83387 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83388 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
83389 void __user *buffer, size_t *lenp, loff_t *ppos)
83390 {
83391 - struct ctl_table ipc_table;
83392 + ctl_table_no_const ipc_table;
83393 memcpy(&ipc_table, table, sizeof(ipc_table));
83394 ipc_table.data = get_ipc(table);
83395
83396 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
83397 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
83398 void __user *buffer, size_t *lenp, loff_t *ppos)
83399 {
83400 - struct ctl_table ipc_table;
83401 + ctl_table_no_const ipc_table;
83402 size_t lenp_bef = *lenp;
83403 int oldval;
83404 int rc;
83405 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
83406 index 383d638..943fdbb 100644
83407 --- a/ipc/mq_sysctl.c
83408 +++ b/ipc/mq_sysctl.c
83409 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
83410 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
83411 void __user *buffer, size_t *lenp, loff_t *ppos)
83412 {
83413 - struct ctl_table mq_table;
83414 + ctl_table_no_const mq_table;
83415 memcpy(&mq_table, table, sizeof(mq_table));
83416 mq_table.data = get_mq(table);
83417
83418 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
83419 index 95827ce..09e6d38 100644
83420 --- a/ipc/mqueue.c
83421 +++ b/ipc/mqueue.c
83422 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
83423 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
83424 info->attr.mq_msgsize);
83425
83426 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
83427 spin_lock(&mq_lock);
83428 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
83429 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
83430 diff --git a/ipc/msg.c b/ipc/msg.c
83431 index 558aa91..359e718 100644
83432 --- a/ipc/msg.c
83433 +++ b/ipc/msg.c
83434 @@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
83435 return security_msg_queue_associate(msq, msgflg);
83436 }
83437
83438 +static struct ipc_ops msg_ops = {
83439 + .getnew = newque,
83440 + .associate = msg_security,
83441 + .more_checks = NULL
83442 +};
83443 +
83444 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
83445 {
83446 struct ipc_namespace *ns;
83447 - struct ipc_ops msg_ops;
83448 struct ipc_params msg_params;
83449
83450 ns = current->nsproxy->ipc_ns;
83451
83452 - msg_ops.getnew = newque;
83453 - msg_ops.associate = msg_security;
83454 - msg_ops.more_checks = NULL;
83455 -
83456 msg_params.key = key;
83457 msg_params.flg = msgflg;
83458
83459 diff --git a/ipc/sem.c b/ipc/sem.c
83460 index db9d241..bc8427c 100644
83461 --- a/ipc/sem.c
83462 +++ b/ipc/sem.c
83463 @@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
83464 return 0;
83465 }
83466
83467 +static struct ipc_ops sem_ops = {
83468 + .getnew = newary,
83469 + .associate = sem_security,
83470 + .more_checks = sem_more_checks
83471 +};
83472 +
83473 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83474 {
83475 struct ipc_namespace *ns;
83476 - struct ipc_ops sem_ops;
83477 struct ipc_params sem_params;
83478
83479 ns = current->nsproxy->ipc_ns;
83480 @@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83481 if (nsems < 0 || nsems > ns->sc_semmsl)
83482 return -EINVAL;
83483
83484 - sem_ops.getnew = newary;
83485 - sem_ops.associate = sem_security;
83486 - sem_ops.more_checks = sem_more_checks;
83487 -
83488 sem_params.key = key;
83489 sem_params.flg = semflg;
83490 sem_params.u.nsems = nsems;
83491 diff --git a/ipc/shm.c b/ipc/shm.c
83492 index 7a51443..3a257d8 100644
83493 --- a/ipc/shm.c
83494 +++ b/ipc/shm.c
83495 @@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
83496 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
83497 #endif
83498
83499 +#ifdef CONFIG_GRKERNSEC
83500 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83501 + const time_t shm_createtime, const kuid_t cuid,
83502 + const int shmid);
83503 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83504 + const time_t shm_createtime);
83505 +#endif
83506 +
83507 void shm_init_ns(struct ipc_namespace *ns)
83508 {
83509 ns->shm_ctlmax = SHMMAX;
83510 @@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
83511 shp->shm_lprid = 0;
83512 shp->shm_atim = shp->shm_dtim = 0;
83513 shp->shm_ctim = get_seconds();
83514 +#ifdef CONFIG_GRKERNSEC
83515 + {
83516 + struct timespec timeval;
83517 + do_posix_clock_monotonic_gettime(&timeval);
83518 +
83519 + shp->shm_createtime = timeval.tv_sec;
83520 + }
83521 +#endif
83522 shp->shm_segsz = size;
83523 shp->shm_nattch = 0;
83524 shp->shm_file = file;
83525 @@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
83526 return 0;
83527 }
83528
83529 +static struct ipc_ops shm_ops = {
83530 + .getnew = newseg,
83531 + .associate = shm_security,
83532 + .more_checks = shm_more_checks
83533 +};
83534 +
83535 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
83536 {
83537 struct ipc_namespace *ns;
83538 - struct ipc_ops shm_ops;
83539 struct ipc_params shm_params;
83540
83541 ns = current->nsproxy->ipc_ns;
83542
83543 - shm_ops.getnew = newseg;
83544 - shm_ops.associate = shm_security;
83545 - shm_ops.more_checks = shm_more_checks;
83546 -
83547 shm_params.key = key;
83548 shm_params.flg = shmflg;
83549 shm_params.u.size = size;
83550 @@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83551 f_mode = FMODE_READ | FMODE_WRITE;
83552 }
83553 if (shmflg & SHM_EXEC) {
83554 +
83555 +#ifdef CONFIG_PAX_MPROTECT
83556 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
83557 + goto out;
83558 +#endif
83559 +
83560 prot |= PROT_EXEC;
83561 acc_mode |= S_IXUGO;
83562 }
83563 @@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83564 if (err)
83565 goto out_unlock;
83566
83567 +#ifdef CONFIG_GRKERNSEC
83568 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
83569 + shp->shm_perm.cuid, shmid) ||
83570 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
83571 + err = -EACCES;
83572 + goto out_unlock;
83573 + }
83574 +#endif
83575 +
83576 ipc_lock_object(&shp->shm_perm);
83577
83578 /* check if shm_destroy() is tearing down shp */
83579 @@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83580 path = shp->shm_file->f_path;
83581 path_get(&path);
83582 shp->shm_nattch++;
83583 +#ifdef CONFIG_GRKERNSEC
83584 + shp->shm_lapid = current->pid;
83585 +#endif
83586 size = i_size_read(path.dentry->d_inode);
83587 ipc_unlock_object(&shp->shm_perm);
83588 rcu_read_unlock();
83589 diff --git a/ipc/util.c b/ipc/util.c
83590 index 3ae17a4..d67c32f 100644
83591 --- a/ipc/util.c
83592 +++ b/ipc/util.c
83593 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
83594 int (*show)(struct seq_file *, void *);
83595 };
83596
83597 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
83598 +
83599 static void ipc_memory_notifier(struct work_struct *work)
83600 {
83601 ipcns_notify(IPCNS_MEMCHANGED);
83602 @@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
83603 granted_mode >>= 6;
83604 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
83605 granted_mode >>= 3;
83606 +
83607 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
83608 + return -1;
83609 +
83610 /* is there some bit set in requested_mode but not in granted_mode? */
83611 if ((requested_mode & ~granted_mode & 0007) &&
83612 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
83613 diff --git a/kernel/acct.c b/kernel/acct.c
83614 index 8d6e145..33e0b1e 100644
83615 --- a/kernel/acct.c
83616 +++ b/kernel/acct.c
83617 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
83618 */
83619 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
83620 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
83621 - file->f_op->write(file, (char *)&ac,
83622 + file->f_op->write(file, (char __force_user *)&ac,
83623 sizeof(acct_t), &file->f_pos);
83624 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
83625 set_fs(fs);
83626 diff --git a/kernel/audit.c b/kernel/audit.c
83627 index 906ae5a0..a7ad0b4 100644
83628 --- a/kernel/audit.c
83629 +++ b/kernel/audit.c
83630 @@ -117,7 +117,7 @@ u32 audit_sig_sid = 0;
83631 3) suppressed due to audit_rate_limit
83632 4) suppressed due to audit_backlog_limit
83633 */
83634 -static atomic_t audit_lost = ATOMIC_INIT(0);
83635 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
83636
83637 /* The netlink socket. */
83638 static struct sock *audit_sock;
83639 @@ -250,7 +250,7 @@ void audit_log_lost(const char *message)
83640 unsigned long now;
83641 int print;
83642
83643 - atomic_inc(&audit_lost);
83644 + atomic_inc_unchecked(&audit_lost);
83645
83646 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
83647
83648 @@ -269,7 +269,7 @@ void audit_log_lost(const char *message)
83649 printk(KERN_WARNING
83650 "audit: audit_lost=%d audit_rate_limit=%d "
83651 "audit_backlog_limit=%d\n",
83652 - atomic_read(&audit_lost),
83653 + atomic_read_unchecked(&audit_lost),
83654 audit_rate_limit,
83655 audit_backlog_limit);
83656 audit_panic(message);
83657 @@ -765,7 +765,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
83658 status_set.pid = audit_pid;
83659 status_set.rate_limit = audit_rate_limit;
83660 status_set.backlog_limit = audit_backlog_limit;
83661 - status_set.lost = atomic_read(&audit_lost);
83662 + status_set.lost = atomic_read_unchecked(&audit_lost);
83663 status_set.backlog = skb_queue_len(&audit_skb_queue);
83664 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
83665 &status_set, sizeof(status_set));
83666 @@ -1356,7 +1356,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
83667 int i, avail, new_len;
83668 unsigned char *ptr;
83669 struct sk_buff *skb;
83670 - static const unsigned char *hex = "0123456789ABCDEF";
83671 + static const unsigned char hex[] = "0123456789ABCDEF";
83672
83673 if (!ab)
83674 return;
83675 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
83676 index 90594c9..abbeed7 100644
83677 --- a/kernel/auditsc.c
83678 +++ b/kernel/auditsc.c
83679 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
83680 }
83681
83682 /* global counter which is incremented every time something logs in */
83683 -static atomic_t session_id = ATOMIC_INIT(0);
83684 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
83685
83686 static int audit_set_loginuid_perm(kuid_t loginuid)
83687 {
83688 @@ -2008,7 +2008,7 @@ int audit_set_loginuid(kuid_t loginuid)
83689
83690 /* are we setting or clearing? */
83691 if (uid_valid(loginuid))
83692 - sessionid = atomic_inc_return(&session_id);
83693 + sessionid = atomic_inc_return_unchecked(&session_id);
83694
83695 task->sessionid = sessionid;
83696 task->loginuid = loginuid;
83697 diff --git a/kernel/capability.c b/kernel/capability.c
83698 index 4e66bf9..cdccecf 100644
83699 --- a/kernel/capability.c
83700 +++ b/kernel/capability.c
83701 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
83702 * before modification is attempted and the application
83703 * fails.
83704 */
83705 + if (tocopy > ARRAY_SIZE(kdata))
83706 + return -EFAULT;
83707 +
83708 if (copy_to_user(dataptr, kdata, tocopy
83709 * sizeof(struct __user_cap_data_struct))) {
83710 return -EFAULT;
83711 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
83712 int ret;
83713
83714 rcu_read_lock();
83715 - ret = security_capable(__task_cred(t), ns, cap);
83716 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
83717 + gr_task_is_capable(t, __task_cred(t), cap);
83718 rcu_read_unlock();
83719
83720 - return (ret == 0);
83721 + return ret;
83722 }
83723
83724 /**
83725 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
83726 int ret;
83727
83728 rcu_read_lock();
83729 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
83730 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
83731 rcu_read_unlock();
83732
83733 - return (ret == 0);
83734 + return ret;
83735 }
83736
83737 /**
83738 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
83739 BUG();
83740 }
83741
83742 - if (security_capable(current_cred(), ns, cap) == 0) {
83743 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
83744 current->flags |= PF_SUPERPRIV;
83745 return true;
83746 }
83747 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
83748 }
83749 EXPORT_SYMBOL(ns_capable);
83750
83751 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
83752 +{
83753 + if (unlikely(!cap_valid(cap))) {
83754 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
83755 + BUG();
83756 + }
83757 +
83758 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
83759 + current->flags |= PF_SUPERPRIV;
83760 + return true;
83761 + }
83762 + return false;
83763 +}
83764 +EXPORT_SYMBOL(ns_capable_nolog);
83765 +
83766 /**
83767 * file_ns_capable - Determine if the file's opener had a capability in effect
83768 * @file: The file we want to check
83769 @@ -432,6 +451,12 @@ bool capable(int cap)
83770 }
83771 EXPORT_SYMBOL(capable);
83772
83773 +bool capable_nolog(int cap)
83774 +{
83775 + return ns_capable_nolog(&init_user_ns, cap);
83776 +}
83777 +EXPORT_SYMBOL(capable_nolog);
83778 +
83779 /**
83780 * inode_capable - Check superior capability over inode
83781 * @inode: The inode in question
83782 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
83783 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83784 }
83785 EXPORT_SYMBOL(inode_capable);
83786 +
83787 +bool inode_capable_nolog(const struct inode *inode, int cap)
83788 +{
83789 + struct user_namespace *ns = current_user_ns();
83790 +
83791 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83792 +}
83793 +EXPORT_SYMBOL(inode_capable_nolog);
83794 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
83795 index bc1dcab..f3a6b42 100644
83796 --- a/kernel/cgroup.c
83797 +++ b/kernel/cgroup.c
83798 @@ -5607,7 +5607,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
83799 struct css_set *cset = link->cset;
83800 struct task_struct *task;
83801 int count = 0;
83802 - seq_printf(seq, "css_set %p\n", cset);
83803 + seq_printf(seq, "css_set %pK\n", cset);
83804 list_for_each_entry(task, &cset->tasks, cg_list) {
83805 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
83806 seq_puts(seq, " ...\n");
83807 diff --git a/kernel/compat.c b/kernel/compat.c
83808 index 0a09e48..b46b3d78 100644
83809 --- a/kernel/compat.c
83810 +++ b/kernel/compat.c
83811 @@ -13,6 +13,7 @@
83812
83813 #include <linux/linkage.h>
83814 #include <linux/compat.h>
83815 +#include <linux/module.h>
83816 #include <linux/errno.h>
83817 #include <linux/time.h>
83818 #include <linux/signal.h>
83819 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
83820 mm_segment_t oldfs;
83821 long ret;
83822
83823 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
83824 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
83825 oldfs = get_fs();
83826 set_fs(KERNEL_DS);
83827 ret = hrtimer_nanosleep_restart(restart);
83828 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
83829 oldfs = get_fs();
83830 set_fs(KERNEL_DS);
83831 ret = hrtimer_nanosleep(&tu,
83832 - rmtp ? (struct timespec __user *)&rmt : NULL,
83833 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
83834 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
83835 set_fs(oldfs);
83836
83837 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
83838 mm_segment_t old_fs = get_fs();
83839
83840 set_fs(KERNEL_DS);
83841 - ret = sys_sigpending((old_sigset_t __user *) &s);
83842 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
83843 set_fs(old_fs);
83844 if (ret == 0)
83845 ret = put_user(s, set);
83846 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
83847 mm_segment_t old_fs = get_fs();
83848
83849 set_fs(KERNEL_DS);
83850 - ret = sys_old_getrlimit(resource, &r);
83851 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
83852 set_fs(old_fs);
83853
83854 if (!ret) {
83855 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
83856 set_fs (KERNEL_DS);
83857 ret = sys_wait4(pid,
83858 (stat_addr ?
83859 - (unsigned int __user *) &status : NULL),
83860 - options, (struct rusage __user *) &r);
83861 + (unsigned int __force_user *) &status : NULL),
83862 + options, (struct rusage __force_user *) &r);
83863 set_fs (old_fs);
83864
83865 if (ret > 0) {
83866 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
83867 memset(&info, 0, sizeof(info));
83868
83869 set_fs(KERNEL_DS);
83870 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
83871 - uru ? (struct rusage __user *)&ru : NULL);
83872 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
83873 + uru ? (struct rusage __force_user *)&ru : NULL);
83874 set_fs(old_fs);
83875
83876 if ((ret < 0) || (info.si_signo == 0))
83877 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
83878 oldfs = get_fs();
83879 set_fs(KERNEL_DS);
83880 err = sys_timer_settime(timer_id, flags,
83881 - (struct itimerspec __user *) &newts,
83882 - (struct itimerspec __user *) &oldts);
83883 + (struct itimerspec __force_user *) &newts,
83884 + (struct itimerspec __force_user *) &oldts);
83885 set_fs(oldfs);
83886 if (!err && old && put_compat_itimerspec(old, &oldts))
83887 return -EFAULT;
83888 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
83889 oldfs = get_fs();
83890 set_fs(KERNEL_DS);
83891 err = sys_timer_gettime(timer_id,
83892 - (struct itimerspec __user *) &ts);
83893 + (struct itimerspec __force_user *) &ts);
83894 set_fs(oldfs);
83895 if (!err && put_compat_itimerspec(setting, &ts))
83896 return -EFAULT;
83897 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
83898 oldfs = get_fs();
83899 set_fs(KERNEL_DS);
83900 err = sys_clock_settime(which_clock,
83901 - (struct timespec __user *) &ts);
83902 + (struct timespec __force_user *) &ts);
83903 set_fs(oldfs);
83904 return err;
83905 }
83906 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
83907 oldfs = get_fs();
83908 set_fs(KERNEL_DS);
83909 err = sys_clock_gettime(which_clock,
83910 - (struct timespec __user *) &ts);
83911 + (struct timespec __force_user *) &ts);
83912 set_fs(oldfs);
83913 if (!err && put_compat_timespec(&ts, tp))
83914 return -EFAULT;
83915 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
83916
83917 oldfs = get_fs();
83918 set_fs(KERNEL_DS);
83919 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
83920 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
83921 set_fs(oldfs);
83922
83923 err = compat_put_timex(utp, &txc);
83924 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
83925 oldfs = get_fs();
83926 set_fs(KERNEL_DS);
83927 err = sys_clock_getres(which_clock,
83928 - (struct timespec __user *) &ts);
83929 + (struct timespec __force_user *) &ts);
83930 set_fs(oldfs);
83931 if (!err && tp && put_compat_timespec(&ts, tp))
83932 return -EFAULT;
83933 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
83934 long err;
83935 mm_segment_t oldfs;
83936 struct timespec tu;
83937 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
83938 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
83939
83940 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
83941 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
83942 oldfs = get_fs();
83943 set_fs(KERNEL_DS);
83944 err = clock_nanosleep_restart(restart);
83945 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
83946 oldfs = get_fs();
83947 set_fs(KERNEL_DS);
83948 err = sys_clock_nanosleep(which_clock, flags,
83949 - (struct timespec __user *) &in,
83950 - (struct timespec __user *) &out);
83951 + (struct timespec __force_user *) &in,
83952 + (struct timespec __force_user *) &out);
83953 set_fs(oldfs);
83954
83955 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
83956 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
83957 mm_segment_t old_fs = get_fs();
83958
83959 set_fs(KERNEL_DS);
83960 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
83961 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
83962 set_fs(old_fs);
83963 if (put_compat_timespec(&t, interval))
83964 return -EFAULT;
83965 diff --git a/kernel/configs.c b/kernel/configs.c
83966 index c18b1f1..b9a0132 100644
83967 --- a/kernel/configs.c
83968 +++ b/kernel/configs.c
83969 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
83970 struct proc_dir_entry *entry;
83971
83972 /* create the current config file */
83973 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
83974 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
83975 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
83976 + &ikconfig_file_ops);
83977 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83978 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
83979 + &ikconfig_file_ops);
83980 +#endif
83981 +#else
83982 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
83983 &ikconfig_file_ops);
83984 +#endif
83985 +
83986 if (!entry)
83987 return -ENOMEM;
83988
83989 diff --git a/kernel/cred.c b/kernel/cred.c
83990 index e0573a4..3874e41 100644
83991 --- a/kernel/cred.c
83992 +++ b/kernel/cred.c
83993 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
83994 validate_creds(cred);
83995 alter_cred_subscribers(cred, -1);
83996 put_cred(cred);
83997 +
83998 +#ifdef CONFIG_GRKERNSEC_SETXID
83999 + cred = (struct cred *) tsk->delayed_cred;
84000 + if (cred != NULL) {
84001 + tsk->delayed_cred = NULL;
84002 + validate_creds(cred);
84003 + alter_cred_subscribers(cred, -1);
84004 + put_cred(cred);
84005 + }
84006 +#endif
84007 }
84008
84009 /**
84010 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
84011 * Always returns 0 thus allowing this function to be tail-called at the end
84012 * of, say, sys_setgid().
84013 */
84014 -int commit_creds(struct cred *new)
84015 +static int __commit_creds(struct cred *new)
84016 {
84017 struct task_struct *task = current;
84018 const struct cred *old = task->real_cred;
84019 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
84020
84021 get_cred(new); /* we will require a ref for the subj creds too */
84022
84023 + gr_set_role_label(task, new->uid, new->gid);
84024 +
84025 /* dumpability changes */
84026 if (!uid_eq(old->euid, new->euid) ||
84027 !gid_eq(old->egid, new->egid) ||
84028 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
84029 put_cred(old);
84030 return 0;
84031 }
84032 +#ifdef CONFIG_GRKERNSEC_SETXID
84033 +extern int set_user(struct cred *new);
84034 +
84035 +void gr_delayed_cred_worker(void)
84036 +{
84037 + const struct cred *new = current->delayed_cred;
84038 + struct cred *ncred;
84039 +
84040 + current->delayed_cred = NULL;
84041 +
84042 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
84043 + // from doing get_cred on it when queueing this
84044 + put_cred(new);
84045 + return;
84046 + } else if (new == NULL)
84047 + return;
84048 +
84049 + ncred = prepare_creds();
84050 + if (!ncred)
84051 + goto die;
84052 + // uids
84053 + ncred->uid = new->uid;
84054 + ncred->euid = new->euid;
84055 + ncred->suid = new->suid;
84056 + ncred->fsuid = new->fsuid;
84057 + // gids
84058 + ncred->gid = new->gid;
84059 + ncred->egid = new->egid;
84060 + ncred->sgid = new->sgid;
84061 + ncred->fsgid = new->fsgid;
84062 + // groups
84063 + if (set_groups(ncred, new->group_info) < 0) {
84064 + abort_creds(ncred);
84065 + goto die;
84066 + }
84067 + // caps
84068 + ncred->securebits = new->securebits;
84069 + ncred->cap_inheritable = new->cap_inheritable;
84070 + ncred->cap_permitted = new->cap_permitted;
84071 + ncred->cap_effective = new->cap_effective;
84072 + ncred->cap_bset = new->cap_bset;
84073 +
84074 + if (set_user(ncred)) {
84075 + abort_creds(ncred);
84076 + goto die;
84077 + }
84078 +
84079 + // from doing get_cred on it when queueing this
84080 + put_cred(new);
84081 +
84082 + __commit_creds(ncred);
84083 + return;
84084 +die:
84085 + // from doing get_cred on it when queueing this
84086 + put_cred(new);
84087 + do_group_exit(SIGKILL);
84088 +}
84089 +#endif
84090 +
84091 +int commit_creds(struct cred *new)
84092 +{
84093 +#ifdef CONFIG_GRKERNSEC_SETXID
84094 + int ret;
84095 + int schedule_it = 0;
84096 + struct task_struct *t;
84097 +
84098 + /* we won't get called with tasklist_lock held for writing
84099 + and interrupts disabled as the cred struct in that case is
84100 + init_cred
84101 + */
84102 + if (grsec_enable_setxid && !current_is_single_threaded() &&
84103 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
84104 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
84105 + schedule_it = 1;
84106 + }
84107 + ret = __commit_creds(new);
84108 + if (schedule_it) {
84109 + rcu_read_lock();
84110 + read_lock(&tasklist_lock);
84111 + for (t = next_thread(current); t != current;
84112 + t = next_thread(t)) {
84113 + if (t->delayed_cred == NULL) {
84114 + t->delayed_cred = get_cred(new);
84115 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
84116 + set_tsk_need_resched(t);
84117 + }
84118 + }
84119 + read_unlock(&tasklist_lock);
84120 + rcu_read_unlock();
84121 + }
84122 + return ret;
84123 +#else
84124 + return __commit_creds(new);
84125 +#endif
84126 +}
84127 +
84128 EXPORT_SYMBOL(commit_creds);
84129
84130 /**
84131 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
84132 index 7d2f35e..1bafcd0 100644
84133 --- a/kernel/debug/debug_core.c
84134 +++ b/kernel/debug/debug_core.c
84135 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
84136 */
84137 static atomic_t masters_in_kgdb;
84138 static atomic_t slaves_in_kgdb;
84139 -static atomic_t kgdb_break_tasklet_var;
84140 +static atomic_unchecked_t kgdb_break_tasklet_var;
84141 atomic_t kgdb_setting_breakpoint;
84142
84143 struct task_struct *kgdb_usethread;
84144 @@ -133,7 +133,7 @@ int kgdb_single_step;
84145 static pid_t kgdb_sstep_pid;
84146
84147 /* to keep track of the CPU which is doing the single stepping*/
84148 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84149 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84150
84151 /*
84152 * If you are debugging a problem where roundup (the collection of
84153 @@ -541,7 +541,7 @@ return_normal:
84154 * kernel will only try for the value of sstep_tries before
84155 * giving up and continuing on.
84156 */
84157 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
84158 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
84159 (kgdb_info[cpu].task &&
84160 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
84161 atomic_set(&kgdb_active, -1);
84162 @@ -639,8 +639,8 @@ cpu_master_loop:
84163 }
84164
84165 kgdb_restore:
84166 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
84167 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
84168 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
84169 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
84170 if (kgdb_info[sstep_cpu].task)
84171 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
84172 else
84173 @@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
84174 static void kgdb_tasklet_bpt(unsigned long ing)
84175 {
84176 kgdb_breakpoint();
84177 - atomic_set(&kgdb_break_tasklet_var, 0);
84178 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
84179 }
84180
84181 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
84182
84183 void kgdb_schedule_breakpoint(void)
84184 {
84185 - if (atomic_read(&kgdb_break_tasklet_var) ||
84186 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
84187 atomic_read(&kgdb_active) != -1 ||
84188 atomic_read(&kgdb_setting_breakpoint))
84189 return;
84190 - atomic_inc(&kgdb_break_tasklet_var);
84191 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
84192 tasklet_schedule(&kgdb_tasklet_breakpoint);
84193 }
84194 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
84195 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
84196 index 0b097c8..11dd5c5 100644
84197 --- a/kernel/debug/kdb/kdb_main.c
84198 +++ b/kernel/debug/kdb/kdb_main.c
84199 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
84200 continue;
84201
84202 kdb_printf("%-20s%8u 0x%p ", mod->name,
84203 - mod->core_size, (void *)mod);
84204 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
84205 #ifdef CONFIG_MODULE_UNLOAD
84206 kdb_printf("%4ld ", module_refcount(mod));
84207 #endif
84208 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
84209 kdb_printf(" (Loading)");
84210 else
84211 kdb_printf(" (Live)");
84212 - kdb_printf(" 0x%p", mod->module_core);
84213 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
84214
84215 #ifdef CONFIG_MODULE_UNLOAD
84216 {
84217 diff --git a/kernel/events/core.c b/kernel/events/core.c
84218 index f574401..11b21f0 100644
84219 --- a/kernel/events/core.c
84220 +++ b/kernel/events/core.c
84221 @@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
84222 * 0 - disallow raw tracepoint access for unpriv
84223 * 1 - disallow cpu events for unpriv
84224 * 2 - disallow kernel profiling for unpriv
84225 + * 3 - disallow all unpriv perf event use
84226 */
84227 -int sysctl_perf_event_paranoid __read_mostly = 1;
84228 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84229 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
84230 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
84231 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
84232 +#else
84233 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
84234 +#endif
84235
84236 /* Minimum for 512 kiB + 1 user control page */
84237 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
84238 @@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
84239
84240 tmp *= sysctl_perf_cpu_time_max_percent;
84241 do_div(tmp, 100);
84242 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
84243 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
84244 }
84245
84246 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
84247 @@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
84248 update_perf_cpu_limits();
84249 }
84250
84251 -static atomic64_t perf_event_id;
84252 +static atomic64_unchecked_t perf_event_id;
84253
84254 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
84255 enum event_type_t event_type);
84256 @@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
84257
84258 static inline u64 perf_event_count(struct perf_event *event)
84259 {
84260 - return local64_read(&event->count) + atomic64_read(&event->child_count);
84261 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
84262 }
84263
84264 static u64 perf_event_read(struct perf_event *event)
84265 @@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
84266 mutex_lock(&event->child_mutex);
84267 total += perf_event_read(event);
84268 *enabled += event->total_time_enabled +
84269 - atomic64_read(&event->child_total_time_enabled);
84270 + atomic64_read_unchecked(&event->child_total_time_enabled);
84271 *running += event->total_time_running +
84272 - atomic64_read(&event->child_total_time_running);
84273 + atomic64_read_unchecked(&event->child_total_time_running);
84274
84275 list_for_each_entry(child, &event->child_list, child_list) {
84276 total += perf_event_read(child);
84277 @@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
84278 userpg->offset -= local64_read(&event->hw.prev_count);
84279
84280 userpg->time_enabled = enabled +
84281 - atomic64_read(&event->child_total_time_enabled);
84282 + atomic64_read_unchecked(&event->child_total_time_enabled);
84283
84284 userpg->time_running = running +
84285 - atomic64_read(&event->child_total_time_running);
84286 + atomic64_read_unchecked(&event->child_total_time_running);
84287
84288 arch_perf_update_userpage(userpg, now);
84289
84290 @@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
84291
84292 /* Data. */
84293 sp = perf_user_stack_pointer(regs);
84294 - rem = __output_copy_user(handle, (void *) sp, dump_size);
84295 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
84296 dyn_size = dump_size - rem;
84297
84298 perf_output_skip(handle, rem);
84299 @@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
84300 values[n++] = perf_event_count(event);
84301 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
84302 values[n++] = enabled +
84303 - atomic64_read(&event->child_total_time_enabled);
84304 + atomic64_read_unchecked(&event->child_total_time_enabled);
84305 }
84306 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
84307 values[n++] = running +
84308 - atomic64_read(&event->child_total_time_running);
84309 + atomic64_read_unchecked(&event->child_total_time_running);
84310 }
84311 if (read_format & PERF_FORMAT_ID)
84312 values[n++] = primary_event_id(event);
84313 @@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
84314 event->parent = parent_event;
84315
84316 event->ns = get_pid_ns(task_active_pid_ns(current));
84317 - event->id = atomic64_inc_return(&perf_event_id);
84318 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
84319
84320 event->state = PERF_EVENT_STATE_INACTIVE;
84321
84322 @@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
84323 if (flags & ~PERF_FLAG_ALL)
84324 return -EINVAL;
84325
84326 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84327 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
84328 + return -EACCES;
84329 +#endif
84330 +
84331 err = perf_copy_attr(attr_uptr, &attr);
84332 if (err)
84333 return err;
84334 @@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
84335 /*
84336 * Add back the child's count to the parent's count:
84337 */
84338 - atomic64_add(child_val, &parent_event->child_count);
84339 - atomic64_add(child_event->total_time_enabled,
84340 + atomic64_add_unchecked(child_val, &parent_event->child_count);
84341 + atomic64_add_unchecked(child_event->total_time_enabled,
84342 &parent_event->child_total_time_enabled);
84343 - atomic64_add(child_event->total_time_running,
84344 + atomic64_add_unchecked(child_event->total_time_running,
84345 &parent_event->child_total_time_running);
84346
84347 /*
84348 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
84349 index 569b2187..19940d9 100644
84350 --- a/kernel/events/internal.h
84351 +++ b/kernel/events/internal.h
84352 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
84353 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
84354 }
84355
84356 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
84357 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
84358 static inline unsigned long \
84359 func_name(struct perf_output_handle *handle, \
84360 - const void *buf, unsigned long len) \
84361 + const void user *buf, unsigned long len) \
84362 { \
84363 unsigned long size, written; \
84364 \
84365 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
84366 return 0;
84367 }
84368
84369 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
84370 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
84371
84372 static inline unsigned long
84373 memcpy_skip(void *dst, const void *src, unsigned long n)
84374 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
84375 return 0;
84376 }
84377
84378 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
84379 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
84380
84381 #ifndef arch_perf_out_copy_user
84382 #define arch_perf_out_copy_user arch_perf_out_copy_user
84383 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
84384 }
84385 #endif
84386
84387 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
84388 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
84389
84390 /* Callchain handling */
84391 extern struct perf_callchain_entry *
84392 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
84393 index 24b7d6c..40cf797 100644
84394 --- a/kernel/events/uprobes.c
84395 +++ b/kernel/events/uprobes.c
84396 @@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
84397 {
84398 struct page *page;
84399 uprobe_opcode_t opcode;
84400 - int result;
84401 + long result;
84402
84403 pagefault_disable();
84404 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
84405 diff --git a/kernel/exit.c b/kernel/exit.c
84406 index a949819..a5f127d 100644
84407 --- a/kernel/exit.c
84408 +++ b/kernel/exit.c
84409 @@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
84410 struct task_struct *leader;
84411 int zap_leader;
84412 repeat:
84413 +#ifdef CONFIG_NET
84414 + gr_del_task_from_ip_table(p);
84415 +#endif
84416 +
84417 /* don't need to get the RCU readlock here - the process is dead and
84418 * can't be modifying its own credentials. But shut RCU-lockdep up */
84419 rcu_read_lock();
84420 @@ -329,7 +333,7 @@ int allow_signal(int sig)
84421 * know it'll be handled, so that they don't get converted to
84422 * SIGKILL or just silently dropped.
84423 */
84424 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
84425 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
84426 recalc_sigpending();
84427 spin_unlock_irq(&current->sighand->siglock);
84428 return 0;
84429 @@ -698,6 +702,8 @@ void do_exit(long code)
84430 struct task_struct *tsk = current;
84431 int group_dead;
84432
84433 + set_fs(USER_DS);
84434 +
84435 profile_task_exit(tsk);
84436
84437 WARN_ON(blk_needs_flush_plug(tsk));
84438 @@ -714,7 +720,6 @@ void do_exit(long code)
84439 * mm_release()->clear_child_tid() from writing to a user-controlled
84440 * kernel address.
84441 */
84442 - set_fs(USER_DS);
84443
84444 ptrace_event(PTRACE_EVENT_EXIT, code);
84445
84446 @@ -773,6 +778,9 @@ void do_exit(long code)
84447 tsk->exit_code = code;
84448 taskstats_exit(tsk, group_dead);
84449
84450 + gr_acl_handle_psacct(tsk, code);
84451 + gr_acl_handle_exit();
84452 +
84453 exit_mm(tsk);
84454
84455 if (group_dead)
84456 @@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
84457 * Take down every thread in the group. This is called by fatal signals
84458 * as well as by sys_exit_group (below).
84459 */
84460 -void
84461 +__noreturn void
84462 do_group_exit(int exit_code)
84463 {
84464 struct signal_struct *sig = current->signal;
84465 diff --git a/kernel/fork.c b/kernel/fork.c
84466 index dfa736c..d170f9b 100644
84467 --- a/kernel/fork.c
84468 +++ b/kernel/fork.c
84469 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
84470 *stackend = STACK_END_MAGIC; /* for overflow detection */
84471
84472 #ifdef CONFIG_CC_STACKPROTECTOR
84473 - tsk->stack_canary = get_random_int();
84474 + tsk->stack_canary = pax_get_random_long();
84475 #endif
84476
84477 /*
84478 @@ -345,12 +345,80 @@ free_tsk:
84479 }
84480
84481 #ifdef CONFIG_MMU
84482 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84483 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
84484 +{
84485 + struct vm_area_struct *tmp;
84486 + unsigned long charge;
84487 + struct file *file;
84488 + int retval;
84489 +
84490 + charge = 0;
84491 + if (mpnt->vm_flags & VM_ACCOUNT) {
84492 + unsigned long len = vma_pages(mpnt);
84493 +
84494 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84495 + goto fail_nomem;
84496 + charge = len;
84497 + }
84498 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84499 + if (!tmp)
84500 + goto fail_nomem;
84501 + *tmp = *mpnt;
84502 + tmp->vm_mm = mm;
84503 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
84504 + retval = vma_dup_policy(mpnt, tmp);
84505 + if (retval)
84506 + goto fail_nomem_policy;
84507 + if (anon_vma_fork(tmp, mpnt))
84508 + goto fail_nomem_anon_vma_fork;
84509 + tmp->vm_flags &= ~VM_LOCKED;
84510 + tmp->vm_next = tmp->vm_prev = NULL;
84511 + tmp->vm_mirror = NULL;
84512 + file = tmp->vm_file;
84513 + if (file) {
84514 + struct inode *inode = file_inode(file);
84515 + struct address_space *mapping = file->f_mapping;
84516 +
84517 + get_file(file);
84518 + if (tmp->vm_flags & VM_DENYWRITE)
84519 + atomic_dec(&inode->i_writecount);
84520 + mutex_lock(&mapping->i_mmap_mutex);
84521 + if (tmp->vm_flags & VM_SHARED)
84522 + mapping->i_mmap_writable++;
84523 + flush_dcache_mmap_lock(mapping);
84524 + /* insert tmp into the share list, just after mpnt */
84525 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84526 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
84527 + else
84528 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
84529 + flush_dcache_mmap_unlock(mapping);
84530 + mutex_unlock(&mapping->i_mmap_mutex);
84531 + }
84532 +
84533 + /*
84534 + * Clear hugetlb-related page reserves for children. This only
84535 + * affects MAP_PRIVATE mappings. Faults generated by the child
84536 + * are not guaranteed to succeed, even if read-only
84537 + */
84538 + if (is_vm_hugetlb_page(tmp))
84539 + reset_vma_resv_huge_pages(tmp);
84540 +
84541 + return tmp;
84542 +
84543 +fail_nomem_anon_vma_fork:
84544 + mpol_put(vma_policy(tmp));
84545 +fail_nomem_policy:
84546 + kmem_cache_free(vm_area_cachep, tmp);
84547 +fail_nomem:
84548 + vm_unacct_memory(charge);
84549 + return NULL;
84550 +}
84551 +
84552 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84553 {
84554 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
84555 struct rb_node **rb_link, *rb_parent;
84556 int retval;
84557 - unsigned long charge;
84558
84559 uprobe_start_dup_mmap();
84560 down_write(&oldmm->mmap_sem);
84561 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84562
84563 prev = NULL;
84564 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
84565 - struct file *file;
84566 -
84567 if (mpnt->vm_flags & VM_DONTCOPY) {
84568 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
84569 -vma_pages(mpnt));
84570 continue;
84571 }
84572 - charge = 0;
84573 - if (mpnt->vm_flags & VM_ACCOUNT) {
84574 - unsigned long len = vma_pages(mpnt);
84575 -
84576 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84577 - goto fail_nomem;
84578 - charge = len;
84579 - }
84580 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84581 - if (!tmp)
84582 - goto fail_nomem;
84583 - *tmp = *mpnt;
84584 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
84585 - retval = vma_dup_policy(mpnt, tmp);
84586 - if (retval)
84587 - goto fail_nomem_policy;
84588 - tmp->vm_mm = mm;
84589 - if (anon_vma_fork(tmp, mpnt))
84590 - goto fail_nomem_anon_vma_fork;
84591 - tmp->vm_flags &= ~VM_LOCKED;
84592 - tmp->vm_next = tmp->vm_prev = NULL;
84593 - file = tmp->vm_file;
84594 - if (file) {
84595 - struct inode *inode = file_inode(file);
84596 - struct address_space *mapping = file->f_mapping;
84597 -
84598 - get_file(file);
84599 - if (tmp->vm_flags & VM_DENYWRITE)
84600 - atomic_dec(&inode->i_writecount);
84601 - mutex_lock(&mapping->i_mmap_mutex);
84602 - if (tmp->vm_flags & VM_SHARED)
84603 - mapping->i_mmap_writable++;
84604 - flush_dcache_mmap_lock(mapping);
84605 - /* insert tmp into the share list, just after mpnt */
84606 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84607 - vma_nonlinear_insert(tmp,
84608 - &mapping->i_mmap_nonlinear);
84609 - else
84610 - vma_interval_tree_insert_after(tmp, mpnt,
84611 - &mapping->i_mmap);
84612 - flush_dcache_mmap_unlock(mapping);
84613 - mutex_unlock(&mapping->i_mmap_mutex);
84614 + tmp = dup_vma(mm, oldmm, mpnt);
84615 + if (!tmp) {
84616 + retval = -ENOMEM;
84617 + goto out;
84618 }
84619
84620 /*
84621 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84622 if (retval)
84623 goto out;
84624 }
84625 +
84626 +#ifdef CONFIG_PAX_SEGMEXEC
84627 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
84628 + struct vm_area_struct *mpnt_m;
84629 +
84630 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
84631 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
84632 +
84633 + if (!mpnt->vm_mirror)
84634 + continue;
84635 +
84636 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
84637 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
84638 + mpnt->vm_mirror = mpnt_m;
84639 + } else {
84640 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
84641 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
84642 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
84643 + mpnt->vm_mirror->vm_mirror = mpnt;
84644 + }
84645 + }
84646 + BUG_ON(mpnt_m);
84647 + }
84648 +#endif
84649 +
84650 /* a new mm has just been created */
84651 arch_dup_mmap(oldmm, mm);
84652 retval = 0;
84653 @@ -468,14 +521,6 @@ out:
84654 up_write(&oldmm->mmap_sem);
84655 uprobe_end_dup_mmap();
84656 return retval;
84657 -fail_nomem_anon_vma_fork:
84658 - mpol_put(vma_policy(tmp));
84659 -fail_nomem_policy:
84660 - kmem_cache_free(vm_area_cachep, tmp);
84661 -fail_nomem:
84662 - retval = -ENOMEM;
84663 - vm_unacct_memory(charge);
84664 - goto out;
84665 }
84666
84667 static inline int mm_alloc_pgd(struct mm_struct *mm)
84668 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
84669 return ERR_PTR(err);
84670
84671 mm = get_task_mm(task);
84672 - if (mm && mm != current->mm &&
84673 - !ptrace_may_access(task, mode)) {
84674 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
84675 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
84676 mmput(mm);
84677 mm = ERR_PTR(-EACCES);
84678 }
84679 @@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
84680 spin_unlock(&fs->lock);
84681 return -EAGAIN;
84682 }
84683 - fs->users++;
84684 + atomic_inc(&fs->users);
84685 spin_unlock(&fs->lock);
84686 return 0;
84687 }
84688 tsk->fs = copy_fs_struct(fs);
84689 if (!tsk->fs)
84690 return -ENOMEM;
84691 + /* Carry through gr_chroot_dentry and is_chrooted instead
84692 + of recomputing it here. Already copied when the task struct
84693 + is duplicated. This allows pivot_root to not be treated as
84694 + a chroot
84695 + */
84696 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
84697 +
84698 return 0;
84699 }
84700
84701 @@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
84702 * parts of the process environment (as per the clone
84703 * flags). The actual kick-off is left to the caller.
84704 */
84705 -static struct task_struct *copy_process(unsigned long clone_flags,
84706 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
84707 unsigned long stack_start,
84708 unsigned long stack_size,
84709 int __user *child_tidptr,
84710 @@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84711 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
84712 #endif
84713 retval = -EAGAIN;
84714 +
84715 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
84716 +
84717 if (atomic_read(&p->real_cred->user->processes) >=
84718 task_rlimit(p, RLIMIT_NPROC)) {
84719 if (p->real_cred->user != INIT_USER &&
84720 @@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84721 goto bad_fork_free_pid;
84722 }
84723
84724 + /* synchronizes with gr_set_acls()
84725 + we need to call this past the point of no return for fork()
84726 + */
84727 + gr_copy_label(p);
84728 +
84729 if (likely(p->pid)) {
84730 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
84731
84732 @@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
84733 bad_fork_free:
84734 free_task(p);
84735 fork_out:
84736 + gr_log_forkfail(retval);
84737 +
84738 return ERR_PTR(retval);
84739 }
84740
84741 @@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
84742
84743 p = copy_process(clone_flags, stack_start, stack_size,
84744 child_tidptr, NULL, trace);
84745 + add_latent_entropy();
84746 /*
84747 * Do this prior waking up the new thread - the thread pointer
84748 * might get invalid after that point, if the thread exits quickly.
84749 @@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
84750 if (clone_flags & CLONE_PARENT_SETTID)
84751 put_user(nr, parent_tidptr);
84752
84753 + gr_handle_brute_check();
84754 +
84755 if (clone_flags & CLONE_VFORK) {
84756 p->vfork_done = &vfork;
84757 init_completion(&vfork);
84758 @@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
84759 mm_cachep = kmem_cache_create("mm_struct",
84760 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
84761 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
84762 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
84763 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
84764 mmap_init();
84765 nsproxy_cache_init();
84766 }
84767 @@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
84768 return 0;
84769
84770 /* don't need lock here; in the worst case we'll do useless copy */
84771 - if (fs->users == 1)
84772 + if (atomic_read(&fs->users) == 1)
84773 return 0;
84774
84775 *new_fsp = copy_fs_struct(fs);
84776 @@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
84777 fs = current->fs;
84778 spin_lock(&fs->lock);
84779 current->fs = new_fs;
84780 - if (--fs->users)
84781 + gr_set_chroot_entries(current, &current->fs->root);
84782 + if (atomic_dec_return(&fs->users))
84783 new_fs = NULL;
84784 else
84785 new_fs = fs;
84786 diff --git a/kernel/futex.c b/kernel/futex.c
84787 index f6ff019..ac53307 100644
84788 --- a/kernel/futex.c
84789 +++ b/kernel/futex.c
84790 @@ -54,6 +54,7 @@
84791 #include <linux/mount.h>
84792 #include <linux/pagemap.h>
84793 #include <linux/syscalls.h>
84794 +#include <linux/ptrace.h>
84795 #include <linux/signal.h>
84796 #include <linux/export.h>
84797 #include <linux/magic.h>
84798 @@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
84799 struct page *page, *page_head;
84800 int err, ro = 0;
84801
84802 +#ifdef CONFIG_PAX_SEGMEXEC
84803 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
84804 + return -EFAULT;
84805 +#endif
84806 +
84807 /*
84808 * The futex address must be "naturally" aligned.
84809 */
84810 @@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
84811
84812 static int get_futex_value_locked(u32 *dest, u32 __user *from)
84813 {
84814 - int ret;
84815 + unsigned long ret;
84816
84817 pagefault_disable();
84818 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
84819 @@ -2735,6 +2741,7 @@ static int __init futex_init(void)
84820 {
84821 u32 curval;
84822 int i;
84823 + mm_segment_t oldfs;
84824
84825 /*
84826 * This will fail and we want it. Some arch implementations do
84827 @@ -2746,8 +2753,11 @@ static int __init futex_init(void)
84828 * implementation, the non-functional ones will return
84829 * -ENOSYS.
84830 */
84831 + oldfs = get_fs();
84832 + set_fs(USER_DS);
84833 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
84834 futex_cmpxchg_enabled = 1;
84835 + set_fs(oldfs);
84836
84837 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
84838 plist_head_init(&futex_queues[i].chain);
84839 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
84840 index f9f44fd..29885e4 100644
84841 --- a/kernel/futex_compat.c
84842 +++ b/kernel/futex_compat.c
84843 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
84844 return 0;
84845 }
84846
84847 -static void __user *futex_uaddr(struct robust_list __user *entry,
84848 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
84849 compat_long_t futex_offset)
84850 {
84851 compat_uptr_t base = ptr_to_compat(entry);
84852 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
84853 index f45b75b..bfac6d5 100644
84854 --- a/kernel/gcov/base.c
84855 +++ b/kernel/gcov/base.c
84856 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
84857 }
84858
84859 #ifdef CONFIG_MODULES
84860 -static inline int within(void *addr, void *start, unsigned long size)
84861 -{
84862 - return ((addr >= start) && (addr < start + size));
84863 -}
84864 -
84865 /* Update list and generate events when modules are unloaded. */
84866 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84867 void *data)
84868 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84869
84870 /* Remove entries located in module from linked list. */
84871 while ((info = gcov_info_next(info))) {
84872 - if (within(info, mod->module_core, mod->core_size)) {
84873 + if (within_module_core_rw((unsigned long)info, mod)) {
84874 gcov_info_unlink(prev, info);
84875 if (gcov_events_enabled)
84876 gcov_event(GCOV_REMOVE, info);
84877 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
84878 index 383319b..56ebb13 100644
84879 --- a/kernel/hrtimer.c
84880 +++ b/kernel/hrtimer.c
84881 @@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
84882 local_irq_restore(flags);
84883 }
84884
84885 -static void run_hrtimer_softirq(struct softirq_action *h)
84886 +static __latent_entropy void run_hrtimer_softirq(void)
84887 {
84888 hrtimer_peek_ahead_timers();
84889 }
84890 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
84891 index 55fcce6..0e4cf34 100644
84892 --- a/kernel/irq_work.c
84893 +++ b/kernel/irq_work.c
84894 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
84895 return NOTIFY_OK;
84896 }
84897
84898 -static struct notifier_block cpu_notify;
84899 +static struct notifier_block cpu_notify = {
84900 + .notifier_call = irq_work_cpu_notify,
84901 + .priority = 0,
84902 +};
84903
84904 static __init int irq_work_init_cpu_notifier(void)
84905 {
84906 - cpu_notify.notifier_call = irq_work_cpu_notify;
84907 - cpu_notify.priority = 0;
84908 register_cpu_notifier(&cpu_notify);
84909 return 0;
84910 }
84911 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
84912 index 9019f15..9a3c42e 100644
84913 --- a/kernel/jump_label.c
84914 +++ b/kernel/jump_label.c
84915 @@ -14,6 +14,7 @@
84916 #include <linux/err.h>
84917 #include <linux/static_key.h>
84918 #include <linux/jump_label_ratelimit.h>
84919 +#include <linux/mm.h>
84920
84921 #ifdef HAVE_JUMP_LABEL
84922
84923 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
84924
84925 size = (((unsigned long)stop - (unsigned long)start)
84926 / sizeof(struct jump_entry));
84927 + pax_open_kernel();
84928 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
84929 + pax_close_kernel();
84930 }
84931
84932 static void jump_label_update(struct static_key *key, int enable);
84933 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
84934 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
84935 struct jump_entry *iter;
84936
84937 + pax_open_kernel();
84938 for (iter = iter_start; iter < iter_stop; iter++) {
84939 if (within_module_init(iter->code, mod))
84940 iter->code = 0;
84941 }
84942 + pax_close_kernel();
84943 }
84944
84945 static int
84946 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
84947 index 3127ad5..159d880 100644
84948 --- a/kernel/kallsyms.c
84949 +++ b/kernel/kallsyms.c
84950 @@ -11,6 +11,9 @@
84951 * Changed the compression method from stem compression to "table lookup"
84952 * compression (see scripts/kallsyms.c for a more complete description)
84953 */
84954 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84955 +#define __INCLUDED_BY_HIDESYM 1
84956 +#endif
84957 #include <linux/kallsyms.h>
84958 #include <linux/module.h>
84959 #include <linux/init.h>
84960 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
84961
84962 static inline int is_kernel_inittext(unsigned long addr)
84963 {
84964 + if (system_state != SYSTEM_BOOTING)
84965 + return 0;
84966 +
84967 if (addr >= (unsigned long)_sinittext
84968 && addr <= (unsigned long)_einittext)
84969 return 1;
84970 return 0;
84971 }
84972
84973 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84974 +#ifdef CONFIG_MODULES
84975 +static inline int is_module_text(unsigned long addr)
84976 +{
84977 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
84978 + return 1;
84979 +
84980 + addr = ktla_ktva(addr);
84981 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
84982 +}
84983 +#else
84984 +static inline int is_module_text(unsigned long addr)
84985 +{
84986 + return 0;
84987 +}
84988 +#endif
84989 +#endif
84990 +
84991 static inline int is_kernel_text(unsigned long addr)
84992 {
84993 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
84994 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
84995
84996 static inline int is_kernel(unsigned long addr)
84997 {
84998 +
84999 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85000 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
85001 + return 1;
85002 +
85003 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
85004 +#else
85005 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
85006 +#endif
85007 +
85008 return 1;
85009 return in_gate_area_no_mm(addr);
85010 }
85011
85012 static int is_ksym_addr(unsigned long addr)
85013 {
85014 +
85015 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85016 + if (is_module_text(addr))
85017 + return 0;
85018 +#endif
85019 +
85020 if (all_var)
85021 return is_kernel(addr);
85022
85023 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
85024
85025 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
85026 {
85027 - iter->name[0] = '\0';
85028 iter->nameoff = get_symbol_offset(new_pos);
85029 iter->pos = new_pos;
85030 }
85031 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
85032 {
85033 struct kallsym_iter *iter = m->private;
85034
85035 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85036 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
85037 + return 0;
85038 +#endif
85039 +
85040 /* Some debugging symbols have no name. Ignore them. */
85041 if (!iter->name[0])
85042 return 0;
85043 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
85044 */
85045 type = iter->exported ? toupper(iter->type) :
85046 tolower(iter->type);
85047 +
85048 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
85049 type, iter->name, iter->module_name);
85050 } else
85051 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
85052 struct kallsym_iter *iter;
85053 int ret;
85054
85055 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
85056 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
85057 if (!iter)
85058 return -ENOMEM;
85059 reset_iter(iter, 0);
85060 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
85061 index e30ac0f..3528cac 100644
85062 --- a/kernel/kcmp.c
85063 +++ b/kernel/kcmp.c
85064 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
85065 struct task_struct *task1, *task2;
85066 int ret;
85067
85068 +#ifdef CONFIG_GRKERNSEC
85069 + return -ENOSYS;
85070 +#endif
85071 +
85072 rcu_read_lock();
85073
85074 /*
85075 diff --git a/kernel/kexec.c b/kernel/kexec.c
85076 index 9c97016..df438f8 100644
85077 --- a/kernel/kexec.c
85078 +++ b/kernel/kexec.c
85079 @@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
85080 unsigned long flags)
85081 {
85082 struct compat_kexec_segment in;
85083 - struct kexec_segment out, __user *ksegments;
85084 + struct kexec_segment out;
85085 + struct kexec_segment __user *ksegments;
85086 unsigned long i, result;
85087
85088 /* Don't allow clients that don't understand the native
85089 diff --git a/kernel/kmod.c b/kernel/kmod.c
85090 index b086006..655e2aa 100644
85091 --- a/kernel/kmod.c
85092 +++ b/kernel/kmod.c
85093 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
85094 kfree(info->argv);
85095 }
85096
85097 -static int call_modprobe(char *module_name, int wait)
85098 +static int call_modprobe(char *module_name, char *module_param, int wait)
85099 {
85100 struct subprocess_info *info;
85101 static char *envp[] = {
85102 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
85103 NULL
85104 };
85105
85106 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
85107 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
85108 if (!argv)
85109 goto out;
85110
85111 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
85112 argv[1] = "-q";
85113 argv[2] = "--";
85114 argv[3] = module_name; /* check free_modprobe_argv() */
85115 - argv[4] = NULL;
85116 + argv[4] = module_param;
85117 + argv[5] = NULL;
85118
85119 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
85120 NULL, free_modprobe_argv, NULL);
85121 @@ -129,9 +130,8 @@ out:
85122 * If module auto-loading support is disabled then this function
85123 * becomes a no-operation.
85124 */
85125 -int __request_module(bool wait, const char *fmt, ...)
85126 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
85127 {
85128 - va_list args;
85129 char module_name[MODULE_NAME_LEN];
85130 unsigned int max_modprobes;
85131 int ret;
85132 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
85133 if (!modprobe_path[0])
85134 return 0;
85135
85136 - va_start(args, fmt);
85137 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
85138 - va_end(args);
85139 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
85140 if (ret >= MODULE_NAME_LEN)
85141 return -ENAMETOOLONG;
85142
85143 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
85144 if (ret)
85145 return ret;
85146
85147 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85148 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85149 + /* hack to workaround consolekit/udisks stupidity */
85150 + read_lock(&tasklist_lock);
85151 + if (!strcmp(current->comm, "mount") &&
85152 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
85153 + read_unlock(&tasklist_lock);
85154 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
85155 + return -EPERM;
85156 + }
85157 + read_unlock(&tasklist_lock);
85158 + }
85159 +#endif
85160 +
85161 /* If modprobe needs a service that is in a module, we get a recursive
85162 * loop. Limit the number of running kmod threads to max_threads/2 or
85163 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
85164 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
85165
85166 trace_module_request(module_name, wait, _RET_IP_);
85167
85168 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85169 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85170
85171 atomic_dec(&kmod_concurrent);
85172 return ret;
85173 }
85174 +
85175 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
85176 +{
85177 + va_list args;
85178 + int ret;
85179 +
85180 + va_start(args, fmt);
85181 + ret = ____request_module(wait, module_param, fmt, args);
85182 + va_end(args);
85183 +
85184 + return ret;
85185 +}
85186 +
85187 +int __request_module(bool wait, const char *fmt, ...)
85188 +{
85189 + va_list args;
85190 + int ret;
85191 +
85192 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85193 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85194 + char module_param[MODULE_NAME_LEN];
85195 +
85196 + memset(module_param, 0, sizeof(module_param));
85197 +
85198 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
85199 +
85200 + va_start(args, fmt);
85201 + ret = ____request_module(wait, module_param, fmt, args);
85202 + va_end(args);
85203 +
85204 + return ret;
85205 + }
85206 +#endif
85207 +
85208 + va_start(args, fmt);
85209 + ret = ____request_module(wait, NULL, fmt, args);
85210 + va_end(args);
85211 +
85212 + return ret;
85213 +}
85214 +
85215 EXPORT_SYMBOL(__request_module);
85216 #endif /* CONFIG_MODULES */
85217
85218 @@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
85219 */
85220 set_user_nice(current, 0);
85221
85222 +#ifdef CONFIG_GRKERNSEC
85223 + /* this is race-free as far as userland is concerned as we copied
85224 + out the path to be used prior to this point and are now operating
85225 + on that copy
85226 + */
85227 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
85228 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
85229 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
85230 + retval = -EPERM;
85231 + goto fail;
85232 + }
85233 +#endif
85234 +
85235 retval = -ENOMEM;
85236 new = prepare_kernel_cred(current);
85237 if (!new)
85238 @@ -240,8 +306,8 @@ static int ____call_usermodehelper(void *data)
85239 commit_creds(new);
85240
85241 retval = do_execve(sub_info->path,
85242 - (const char __user *const __user *)sub_info->argv,
85243 - (const char __user *const __user *)sub_info->envp);
85244 + (const char __user *const __force_user *)sub_info->argv,
85245 + (const char __user *const __force_user *)sub_info->envp);
85246 if (!retval)
85247 return 0;
85248
85249 @@ -260,6 +326,10 @@ static int call_helper(void *data)
85250
85251 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
85252 {
85253 +#ifdef CONFIG_GRKERNSEC
85254 + kfree(info->path);
85255 + info->path = info->origpath;
85256 +#endif
85257 if (info->cleanup)
85258 (*info->cleanup)(info);
85259 kfree(info);
85260 @@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
85261 *
85262 * Thus the __user pointer cast is valid here.
85263 */
85264 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
85265 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
85266
85267 /*
85268 * If ret is 0, either ____call_usermodehelper failed and the
85269 @@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
85270 goto out;
85271
85272 INIT_WORK(&sub_info->work, __call_usermodehelper);
85273 +#ifdef CONFIG_GRKERNSEC
85274 + sub_info->origpath = path;
85275 + sub_info->path = kstrdup(path, gfp_mask);
85276 +#else
85277 sub_info->path = path;
85278 +#endif
85279 sub_info->argv = argv;
85280 sub_info->envp = envp;
85281
85282 @@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
85283 static int proc_cap_handler(struct ctl_table *table, int write,
85284 void __user *buffer, size_t *lenp, loff_t *ppos)
85285 {
85286 - struct ctl_table t;
85287 + ctl_table_no_const t;
85288 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
85289 kernel_cap_t new_cap;
85290 int err, i;
85291 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
85292 index ceeadfc..11c18b6 100644
85293 --- a/kernel/kprobes.c
85294 +++ b/kernel/kprobes.c
85295 @@ -31,6 +31,9 @@
85296 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
85297 * <prasanna@in.ibm.com> added function-return probes.
85298 */
85299 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85300 +#define __INCLUDED_BY_HIDESYM 1
85301 +#endif
85302 #include <linux/kprobes.h>
85303 #include <linux/hash.h>
85304 #include <linux/init.h>
85305 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
85306
85307 static void *alloc_insn_page(void)
85308 {
85309 - return module_alloc(PAGE_SIZE);
85310 + return module_alloc_exec(PAGE_SIZE);
85311 }
85312
85313 static void free_insn_page(void *page)
85314 {
85315 - module_free(NULL, page);
85316 + module_free_exec(NULL, page);
85317 }
85318
85319 struct kprobe_insn_cache kprobe_insn_slots = {
85320 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
85321 kprobe_type = "k";
85322
85323 if (sym)
85324 - seq_printf(pi, "%p %s %s+0x%x %s ",
85325 + seq_printf(pi, "%pK %s %s+0x%x %s ",
85326 p->addr, kprobe_type, sym, offset,
85327 (modname ? modname : " "));
85328 else
85329 - seq_printf(pi, "%p %s %p ",
85330 + seq_printf(pi, "%pK %s %pK ",
85331 p->addr, kprobe_type, p->addr);
85332
85333 if (!pp)
85334 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
85335 index 9659d38..bffd520 100644
85336 --- a/kernel/ksysfs.c
85337 +++ b/kernel/ksysfs.c
85338 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
85339 {
85340 if (count+1 > UEVENT_HELPER_PATH_LEN)
85341 return -ENOENT;
85342 + if (!capable(CAP_SYS_ADMIN))
85343 + return -EPERM;
85344 memcpy(uevent_helper, buf, count);
85345 uevent_helper[count] = '\0';
85346 if (count && uevent_helper[count-1] == '\n')
85347 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
85348 return count;
85349 }
85350
85351 -static struct bin_attribute notes_attr = {
85352 +static bin_attribute_no_const notes_attr __read_only = {
85353 .attr = {
85354 .name = "notes",
85355 .mode = S_IRUGO,
85356 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
85357 index 576ba75..7c256e4 100644
85358 --- a/kernel/locking/lockdep.c
85359 +++ b/kernel/locking/lockdep.c
85360 @@ -596,6 +596,10 @@ static int static_obj(void *obj)
85361 end = (unsigned long) &_end,
85362 addr = (unsigned long) obj;
85363
85364 +#ifdef CONFIG_PAX_KERNEXEC
85365 + start = ktla_ktva(start);
85366 +#endif
85367 +
85368 /*
85369 * static variable?
85370 */
85371 @@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
85372 if (!static_obj(lock->key)) {
85373 debug_locks_off();
85374 printk("INFO: trying to register non-static key.\n");
85375 + printk("lock:%pS key:%pS.\n", lock, lock->key);
85376 printk("the code is fine but needs lockdep annotation.\n");
85377 printk("turning off the locking correctness validator.\n");
85378 dump_stack();
85379 @@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
85380 if (!class)
85381 return 0;
85382 }
85383 - atomic_inc((atomic_t *)&class->ops);
85384 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
85385 if (very_verbose(class)) {
85386 printk("\nacquire class [%p] %s", class->key, class->name);
85387 if (class->name_version > 1)
85388 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
85389 index ef43ac4..2720dfa 100644
85390 --- a/kernel/locking/lockdep_proc.c
85391 +++ b/kernel/locking/lockdep_proc.c
85392 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
85393 return 0;
85394 }
85395
85396 - seq_printf(m, "%p", class->key);
85397 + seq_printf(m, "%pK", class->key);
85398 #ifdef CONFIG_DEBUG_LOCKDEP
85399 seq_printf(m, " OPS:%8ld", class->ops);
85400 #endif
85401 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
85402
85403 list_for_each_entry(entry, &class->locks_after, entry) {
85404 if (entry->distance == 1) {
85405 - seq_printf(m, " -> [%p] ", entry->class->key);
85406 + seq_printf(m, " -> [%pK] ", entry->class->key);
85407 print_name(m, entry->class);
85408 seq_puts(m, "\n");
85409 }
85410 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
85411 if (!class->key)
85412 continue;
85413
85414 - seq_printf(m, "[%p] ", class->key);
85415 + seq_printf(m, "[%pK] ", class->key);
85416 print_name(m, class);
85417 seq_puts(m, "\n");
85418 }
85419 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85420 if (!i)
85421 seq_line(m, '-', 40-namelen, namelen);
85422
85423 - snprintf(ip, sizeof(ip), "[<%p>]",
85424 + snprintf(ip, sizeof(ip), "[<%pK>]",
85425 (void *)class->contention_point[i]);
85426 seq_printf(m, "%40s %14lu %29s %pS\n",
85427 name, stats->contention_point[i],
85428 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85429 if (!i)
85430 seq_line(m, '-', 40-namelen, namelen);
85431
85432 - snprintf(ip, sizeof(ip), "[<%p>]",
85433 + snprintf(ip, sizeof(ip), "[<%pK>]",
85434 (void *)class->contending_point[i]);
85435 seq_printf(m, "%40s %14lu %29s %pS\n",
85436 name, stats->contending_point[i],
85437 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
85438 index 7e3443f..b2a1e6b 100644
85439 --- a/kernel/locking/mutex-debug.c
85440 +++ b/kernel/locking/mutex-debug.c
85441 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
85442 }
85443
85444 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85445 - struct thread_info *ti)
85446 + struct task_struct *task)
85447 {
85448 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
85449
85450 /* Mark the current thread as blocked on the lock: */
85451 - ti->task->blocked_on = waiter;
85452 + task->blocked_on = waiter;
85453 }
85454
85455 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85456 - struct thread_info *ti)
85457 + struct task_struct *task)
85458 {
85459 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
85460 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
85461 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
85462 - ti->task->blocked_on = NULL;
85463 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
85464 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
85465 + task->blocked_on = NULL;
85466
85467 list_del_init(&waiter->list);
85468 waiter->task = NULL;
85469 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
85470 index 0799fd3..d06ae3b 100644
85471 --- a/kernel/locking/mutex-debug.h
85472 +++ b/kernel/locking/mutex-debug.h
85473 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
85474 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
85475 extern void debug_mutex_add_waiter(struct mutex *lock,
85476 struct mutex_waiter *waiter,
85477 - struct thread_info *ti);
85478 + struct task_struct *task);
85479 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85480 - struct thread_info *ti);
85481 + struct task_struct *task);
85482 extern void debug_mutex_unlock(struct mutex *lock);
85483 extern void debug_mutex_init(struct mutex *lock, const char *name,
85484 struct lock_class_key *key);
85485 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
85486 index 4dd6e4c..df52693 100644
85487 --- a/kernel/locking/mutex.c
85488 +++ b/kernel/locking/mutex.c
85489 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
85490 node->locked = 1;
85491 return;
85492 }
85493 - ACCESS_ONCE(prev->next) = node;
85494 + ACCESS_ONCE_RW(prev->next) = node;
85495 smp_wmb();
85496 /* Wait until the lock holder passes the lock down */
85497 while (!ACCESS_ONCE(node->locked))
85498 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
85499 while (!(next = ACCESS_ONCE(node->next)))
85500 arch_mutex_cpu_relax();
85501 }
85502 - ACCESS_ONCE(next->locked) = 1;
85503 + ACCESS_ONCE_RW(next->locked) = 1;
85504 smp_wmb();
85505 }
85506
85507 @@ -520,7 +520,7 @@ slowpath:
85508 goto skip_wait;
85509
85510 debug_mutex_lock_common(lock, &waiter);
85511 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
85512 + debug_mutex_add_waiter(lock, &waiter, task);
85513
85514 /* add waiting tasks to the end of the waitqueue (FIFO): */
85515 list_add_tail(&waiter.list, &lock->wait_list);
85516 @@ -564,7 +564,7 @@ slowpath:
85517 schedule_preempt_disabled();
85518 spin_lock_mutex(&lock->wait_lock, flags);
85519 }
85520 - mutex_remove_waiter(lock, &waiter, current_thread_info());
85521 + mutex_remove_waiter(lock, &waiter, task);
85522 /* set it to 0 if there are no waiters left: */
85523 if (likely(list_empty(&lock->wait_list)))
85524 atomic_set(&lock->count, 0);
85525 @@ -601,7 +601,7 @@ skip_wait:
85526 return 0;
85527
85528 err:
85529 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
85530 + mutex_remove_waiter(lock, &waiter, task);
85531 spin_unlock_mutex(&lock->wait_lock, flags);
85532 debug_mutex_free_waiter(&waiter);
85533 mutex_release(&lock->dep_map, 1, ip);
85534 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
85535 index 1d96dd0..994ff19 100644
85536 --- a/kernel/locking/rtmutex-tester.c
85537 +++ b/kernel/locking/rtmutex-tester.c
85538 @@ -22,7 +22,7 @@
85539 #define MAX_RT_TEST_MUTEXES 8
85540
85541 static spinlock_t rttest_lock;
85542 -static atomic_t rttest_event;
85543 +static atomic_unchecked_t rttest_event;
85544
85545 struct test_thread_data {
85546 int opcode;
85547 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85548
85549 case RTTEST_LOCKCONT:
85550 td->mutexes[td->opdata] = 1;
85551 - td->event = atomic_add_return(1, &rttest_event);
85552 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85553 return 0;
85554
85555 case RTTEST_RESET:
85556 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85557 return 0;
85558
85559 case RTTEST_RESETEVENT:
85560 - atomic_set(&rttest_event, 0);
85561 + atomic_set_unchecked(&rttest_event, 0);
85562 return 0;
85563
85564 default:
85565 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85566 return ret;
85567
85568 td->mutexes[id] = 1;
85569 - td->event = atomic_add_return(1, &rttest_event);
85570 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85571 rt_mutex_lock(&mutexes[id]);
85572 - td->event = atomic_add_return(1, &rttest_event);
85573 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85574 td->mutexes[id] = 4;
85575 return 0;
85576
85577 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85578 return ret;
85579
85580 td->mutexes[id] = 1;
85581 - td->event = atomic_add_return(1, &rttest_event);
85582 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85583 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
85584 - td->event = atomic_add_return(1, &rttest_event);
85585 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85586 td->mutexes[id] = ret ? 0 : 4;
85587 return ret ? -EINTR : 0;
85588
85589 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85590 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
85591 return ret;
85592
85593 - td->event = atomic_add_return(1, &rttest_event);
85594 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85595 rt_mutex_unlock(&mutexes[id]);
85596 - td->event = atomic_add_return(1, &rttest_event);
85597 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85598 td->mutexes[id] = 0;
85599 return 0;
85600
85601 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85602 break;
85603
85604 td->mutexes[dat] = 2;
85605 - td->event = atomic_add_return(1, &rttest_event);
85606 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85607 break;
85608
85609 default:
85610 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85611 return;
85612
85613 td->mutexes[dat] = 3;
85614 - td->event = atomic_add_return(1, &rttest_event);
85615 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85616 break;
85617
85618 case RTTEST_LOCKNOWAIT:
85619 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85620 return;
85621
85622 td->mutexes[dat] = 1;
85623 - td->event = atomic_add_return(1, &rttest_event);
85624 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85625 return;
85626
85627 default:
85628 diff --git a/kernel/module.c b/kernel/module.c
85629 index f5a3b1e..97ebb15 100644
85630 --- a/kernel/module.c
85631 +++ b/kernel/module.c
85632 @@ -61,6 +61,7 @@
85633 #include <linux/pfn.h>
85634 #include <linux/bsearch.h>
85635 #include <linux/fips.h>
85636 +#include <linux/grsecurity.h>
85637 #include <uapi/linux/module.h>
85638 #include "module-internal.h"
85639
85640 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
85641
85642 /* Bounds of module allocation, for speeding __module_address.
85643 * Protected by module_mutex. */
85644 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
85645 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
85646 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
85647
85648 int register_module_notifier(struct notifier_block * nb)
85649 {
85650 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85651 return true;
85652
85653 list_for_each_entry_rcu(mod, &modules, list) {
85654 - struct symsearch arr[] = {
85655 + struct symsearch modarr[] = {
85656 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
85657 NOT_GPL_ONLY, false },
85658 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
85659 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85660 if (mod->state == MODULE_STATE_UNFORMED)
85661 continue;
85662
85663 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
85664 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
85665 return true;
85666 }
85667 return false;
85668 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
85669 if (!pcpusec->sh_size)
85670 return 0;
85671
85672 - if (align > PAGE_SIZE) {
85673 + if (align-1 >= PAGE_SIZE) {
85674 pr_warn("%s: per-cpu alignment %li > %li\n",
85675 mod->name, align, PAGE_SIZE);
85676 align = PAGE_SIZE;
85677 @@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
85678 static ssize_t show_coresize(struct module_attribute *mattr,
85679 struct module_kobject *mk, char *buffer)
85680 {
85681 - return sprintf(buffer, "%u\n", mk->mod->core_size);
85682 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
85683 }
85684
85685 static struct module_attribute modinfo_coresize =
85686 @@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
85687 static ssize_t show_initsize(struct module_attribute *mattr,
85688 struct module_kobject *mk, char *buffer)
85689 {
85690 - return sprintf(buffer, "%u\n", mk->mod->init_size);
85691 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
85692 }
85693
85694 static struct module_attribute modinfo_initsize =
85695 @@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
85696 goto bad_version;
85697 }
85698
85699 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
85700 + /*
85701 + * avoid potentially printing jibberish on attempted load
85702 + * of a module randomized with a different seed
85703 + */
85704 + pr_warn("no symbol version for %s\n", symname);
85705 +#else
85706 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
85707 +#endif
85708 return 0;
85709
85710 bad_version:
85711 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
85712 + /*
85713 + * avoid potentially printing jibberish on attempted load
85714 + * of a module randomized with a different seed
85715 + */
85716 + printk("attempted module disagrees about version of symbol %s\n",
85717 + symname);
85718 +#else
85719 printk("%s: disagrees about version of symbol %s\n",
85720 mod->name, symname);
85721 +#endif
85722 return 0;
85723 }
85724
85725 @@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
85726 */
85727 #ifdef CONFIG_SYSFS
85728
85729 -#ifdef CONFIG_KALLSYMS
85730 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
85731 static inline bool sect_empty(const Elf_Shdr *sect)
85732 {
85733 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
85734 @@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
85735 {
85736 unsigned int notes, loaded, i;
85737 struct module_notes_attrs *notes_attrs;
85738 - struct bin_attribute *nattr;
85739 + bin_attribute_no_const *nattr;
85740
85741 /* failed to create section attributes, so can't create notes */
85742 if (!mod->sect_attrs)
85743 @@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
85744 static int module_add_modinfo_attrs(struct module *mod)
85745 {
85746 struct module_attribute *attr;
85747 - struct module_attribute *temp_attr;
85748 + module_attribute_no_const *temp_attr;
85749 int error = 0;
85750 int i;
85751
85752 @@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
85753
85754 static void unset_module_core_ro_nx(struct module *mod)
85755 {
85756 - set_page_attributes(mod->module_core + mod->core_text_size,
85757 - mod->module_core + mod->core_size,
85758 + set_page_attributes(mod->module_core_rw,
85759 + mod->module_core_rw + mod->core_size_rw,
85760 set_memory_x);
85761 - set_page_attributes(mod->module_core,
85762 - mod->module_core + mod->core_ro_size,
85763 + set_page_attributes(mod->module_core_rx,
85764 + mod->module_core_rx + mod->core_size_rx,
85765 set_memory_rw);
85766 }
85767
85768 static void unset_module_init_ro_nx(struct module *mod)
85769 {
85770 - set_page_attributes(mod->module_init + mod->init_text_size,
85771 - mod->module_init + mod->init_size,
85772 + set_page_attributes(mod->module_init_rw,
85773 + mod->module_init_rw + mod->init_size_rw,
85774 set_memory_x);
85775 - set_page_attributes(mod->module_init,
85776 - mod->module_init + mod->init_ro_size,
85777 + set_page_attributes(mod->module_init_rx,
85778 + mod->module_init_rx + mod->init_size_rx,
85779 set_memory_rw);
85780 }
85781
85782 @@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
85783 list_for_each_entry_rcu(mod, &modules, list) {
85784 if (mod->state == MODULE_STATE_UNFORMED)
85785 continue;
85786 - if ((mod->module_core) && (mod->core_text_size)) {
85787 - set_page_attributes(mod->module_core,
85788 - mod->module_core + mod->core_text_size,
85789 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
85790 + set_page_attributes(mod->module_core_rx,
85791 + mod->module_core_rx + mod->core_size_rx,
85792 set_memory_rw);
85793 }
85794 - if ((mod->module_init) && (mod->init_text_size)) {
85795 - set_page_attributes(mod->module_init,
85796 - mod->module_init + mod->init_text_size,
85797 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
85798 + set_page_attributes(mod->module_init_rx,
85799 + mod->module_init_rx + mod->init_size_rx,
85800 set_memory_rw);
85801 }
85802 }
85803 @@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
85804 list_for_each_entry_rcu(mod, &modules, list) {
85805 if (mod->state == MODULE_STATE_UNFORMED)
85806 continue;
85807 - if ((mod->module_core) && (mod->core_text_size)) {
85808 - set_page_attributes(mod->module_core,
85809 - mod->module_core + mod->core_text_size,
85810 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
85811 + set_page_attributes(mod->module_core_rx,
85812 + mod->module_core_rx + mod->core_size_rx,
85813 set_memory_ro);
85814 }
85815 - if ((mod->module_init) && (mod->init_text_size)) {
85816 - set_page_attributes(mod->module_init,
85817 - mod->module_init + mod->init_text_size,
85818 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
85819 + set_page_attributes(mod->module_init_rx,
85820 + mod->module_init_rx + mod->init_size_rx,
85821 set_memory_ro);
85822 }
85823 }
85824 @@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
85825
85826 /* This may be NULL, but that's OK */
85827 unset_module_init_ro_nx(mod);
85828 - module_free(mod, mod->module_init);
85829 + module_free(mod, mod->module_init_rw);
85830 + module_free_exec(mod, mod->module_init_rx);
85831 kfree(mod->args);
85832 percpu_modfree(mod);
85833
85834 /* Free lock-classes: */
85835 - lockdep_free_key_range(mod->module_core, mod->core_size);
85836 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
85837 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
85838
85839 /* Finally, free the core (containing the module structure) */
85840 unset_module_core_ro_nx(mod);
85841 - module_free(mod, mod->module_core);
85842 + module_free_exec(mod, mod->module_core_rx);
85843 + module_free(mod, mod->module_core_rw);
85844
85845 #ifdef CONFIG_MPU
85846 update_protections(current->mm);
85847 @@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85848 int ret = 0;
85849 const struct kernel_symbol *ksym;
85850
85851 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85852 + int is_fs_load = 0;
85853 + int register_filesystem_found = 0;
85854 + char *p;
85855 +
85856 + p = strstr(mod->args, "grsec_modharden_fs");
85857 + if (p) {
85858 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
85859 + /* copy \0 as well */
85860 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
85861 + is_fs_load = 1;
85862 + }
85863 +#endif
85864 +
85865 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
85866 const char *name = info->strtab + sym[i].st_name;
85867
85868 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85869 + /* it's a real shame this will never get ripped and copied
85870 + upstream! ;(
85871 + */
85872 + if (is_fs_load && !strcmp(name, "register_filesystem"))
85873 + register_filesystem_found = 1;
85874 +#endif
85875 +
85876 switch (sym[i].st_shndx) {
85877 case SHN_COMMON:
85878 /* We compiled with -fno-common. These are not
85879 @@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85880 ksym = resolve_symbol_wait(mod, info, name);
85881 /* Ok if resolved. */
85882 if (ksym && !IS_ERR(ksym)) {
85883 + pax_open_kernel();
85884 sym[i].st_value = ksym->value;
85885 + pax_close_kernel();
85886 break;
85887 }
85888
85889 @@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85890 secbase = (unsigned long)mod_percpu(mod);
85891 else
85892 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
85893 + pax_open_kernel();
85894 sym[i].st_value += secbase;
85895 + pax_close_kernel();
85896 break;
85897 }
85898 }
85899
85900 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85901 + if (is_fs_load && !register_filesystem_found) {
85902 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
85903 + ret = -EPERM;
85904 + }
85905 +#endif
85906 +
85907 return ret;
85908 }
85909
85910 @@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
85911 || s->sh_entsize != ~0UL
85912 || strstarts(sname, ".init"))
85913 continue;
85914 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
85915 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85916 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
85917 + else
85918 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
85919 pr_debug("\t%s\n", sname);
85920 }
85921 - switch (m) {
85922 - case 0: /* executable */
85923 - mod->core_size = debug_align(mod->core_size);
85924 - mod->core_text_size = mod->core_size;
85925 - break;
85926 - case 1: /* RO: text and ro-data */
85927 - mod->core_size = debug_align(mod->core_size);
85928 - mod->core_ro_size = mod->core_size;
85929 - break;
85930 - case 3: /* whole core */
85931 - mod->core_size = debug_align(mod->core_size);
85932 - break;
85933 - }
85934 }
85935
85936 pr_debug("Init section allocation order:\n");
85937 @@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
85938 || s->sh_entsize != ~0UL
85939 || !strstarts(sname, ".init"))
85940 continue;
85941 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
85942 - | INIT_OFFSET_MASK);
85943 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85944 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
85945 + else
85946 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
85947 + s->sh_entsize |= INIT_OFFSET_MASK;
85948 pr_debug("\t%s\n", sname);
85949 }
85950 - switch (m) {
85951 - case 0: /* executable */
85952 - mod->init_size = debug_align(mod->init_size);
85953 - mod->init_text_size = mod->init_size;
85954 - break;
85955 - case 1: /* RO: text and ro-data */
85956 - mod->init_size = debug_align(mod->init_size);
85957 - mod->init_ro_size = mod->init_size;
85958 - break;
85959 - case 3: /* whole init */
85960 - mod->init_size = debug_align(mod->init_size);
85961 - break;
85962 - }
85963 }
85964 }
85965
85966 @@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85967
85968 /* Put symbol section at end of init part of module. */
85969 symsect->sh_flags |= SHF_ALLOC;
85970 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
85971 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
85972 info->index.sym) | INIT_OFFSET_MASK;
85973 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
85974
85975 @@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85976 }
85977
85978 /* Append room for core symbols at end of core part. */
85979 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
85980 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
85981 - mod->core_size += strtab_size;
85982 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
85983 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
85984 + mod->core_size_rx += strtab_size;
85985
85986 /* Put string table section at end of init part of module. */
85987 strsect->sh_flags |= SHF_ALLOC;
85988 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
85989 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
85990 info->index.str) | INIT_OFFSET_MASK;
85991 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
85992 }
85993 @@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85994 /* Make sure we get permanent strtab: don't use info->strtab. */
85995 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
85996
85997 + pax_open_kernel();
85998 +
85999 /* Set types up while we still have access to sections. */
86000 for (i = 0; i < mod->num_symtab; i++)
86001 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
86002
86003 - mod->core_symtab = dst = mod->module_core + info->symoffs;
86004 - mod->core_strtab = s = mod->module_core + info->stroffs;
86005 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
86006 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
86007 src = mod->symtab;
86008 for (ndst = i = 0; i < mod->num_symtab; i++) {
86009 if (i == 0 ||
86010 @@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86011 }
86012 }
86013 mod->core_num_syms = ndst;
86014 +
86015 + pax_close_kernel();
86016 }
86017 #else
86018 static inline void layout_symtab(struct module *mod, struct load_info *info)
86019 @@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
86020 return vmalloc_exec(size);
86021 }
86022
86023 -static void *module_alloc_update_bounds(unsigned long size)
86024 +static void *module_alloc_update_bounds_rw(unsigned long size)
86025 {
86026 void *ret = module_alloc(size);
86027
86028 if (ret) {
86029 mutex_lock(&module_mutex);
86030 /* Update module bounds. */
86031 - if ((unsigned long)ret < module_addr_min)
86032 - module_addr_min = (unsigned long)ret;
86033 - if ((unsigned long)ret + size > module_addr_max)
86034 - module_addr_max = (unsigned long)ret + size;
86035 + if ((unsigned long)ret < module_addr_min_rw)
86036 + module_addr_min_rw = (unsigned long)ret;
86037 + if ((unsigned long)ret + size > module_addr_max_rw)
86038 + module_addr_max_rw = (unsigned long)ret + size;
86039 + mutex_unlock(&module_mutex);
86040 + }
86041 + return ret;
86042 +}
86043 +
86044 +static void *module_alloc_update_bounds_rx(unsigned long size)
86045 +{
86046 + void *ret = module_alloc_exec(size);
86047 +
86048 + if (ret) {
86049 + mutex_lock(&module_mutex);
86050 + /* Update module bounds. */
86051 + if ((unsigned long)ret < module_addr_min_rx)
86052 + module_addr_min_rx = (unsigned long)ret;
86053 + if ((unsigned long)ret + size > module_addr_max_rx)
86054 + module_addr_max_rx = (unsigned long)ret + size;
86055 mutex_unlock(&module_mutex);
86056 }
86057 return ret;
86058 @@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86059 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
86060
86061 if (info->index.sym == 0) {
86062 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86063 + /*
86064 + * avoid potentially printing jibberish on attempted load
86065 + * of a module randomized with a different seed
86066 + */
86067 + pr_warn("module has no symbols (stripped?)\n");
86068 +#else
86069 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
86070 +#endif
86071 return ERR_PTR(-ENOEXEC);
86072 }
86073
86074 @@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86075 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86076 {
86077 const char *modmagic = get_modinfo(info, "vermagic");
86078 + const char *license = get_modinfo(info, "license");
86079 int err;
86080
86081 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
86082 + if (!license || !license_is_gpl_compatible(license))
86083 + return -ENOEXEC;
86084 +#endif
86085 +
86086 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
86087 modmagic = NULL;
86088
86089 @@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86090 }
86091
86092 /* Set up license info based on the info section */
86093 - set_license(mod, get_modinfo(info, "license"));
86094 + set_license(mod, license);
86095
86096 return 0;
86097 }
86098 @@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
86099 void *ptr;
86100
86101 /* Do the allocs. */
86102 - ptr = module_alloc_update_bounds(mod->core_size);
86103 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
86104 /*
86105 * The pointer to this block is stored in the module structure
86106 * which is inside the block. Just mark it as not being a
86107 @@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
86108 if (!ptr)
86109 return -ENOMEM;
86110
86111 - memset(ptr, 0, mod->core_size);
86112 - mod->module_core = ptr;
86113 + memset(ptr, 0, mod->core_size_rw);
86114 + mod->module_core_rw = ptr;
86115
86116 - if (mod->init_size) {
86117 - ptr = module_alloc_update_bounds(mod->init_size);
86118 + if (mod->init_size_rw) {
86119 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
86120 /*
86121 * The pointer to this block is stored in the module structure
86122 * which is inside the block. This block doesn't need to be
86123 @@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
86124 */
86125 kmemleak_ignore(ptr);
86126 if (!ptr) {
86127 - module_free(mod, mod->module_core);
86128 + module_free(mod, mod->module_core_rw);
86129 return -ENOMEM;
86130 }
86131 - memset(ptr, 0, mod->init_size);
86132 - mod->module_init = ptr;
86133 + memset(ptr, 0, mod->init_size_rw);
86134 + mod->module_init_rw = ptr;
86135 } else
86136 - mod->module_init = NULL;
86137 + mod->module_init_rw = NULL;
86138 +
86139 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
86140 + kmemleak_not_leak(ptr);
86141 + if (!ptr) {
86142 + if (mod->module_init_rw)
86143 + module_free(mod, mod->module_init_rw);
86144 + module_free(mod, mod->module_core_rw);
86145 + return -ENOMEM;
86146 + }
86147 +
86148 + pax_open_kernel();
86149 + memset(ptr, 0, mod->core_size_rx);
86150 + pax_close_kernel();
86151 + mod->module_core_rx = ptr;
86152 +
86153 + if (mod->init_size_rx) {
86154 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
86155 + kmemleak_ignore(ptr);
86156 + if (!ptr && mod->init_size_rx) {
86157 + module_free_exec(mod, mod->module_core_rx);
86158 + if (mod->module_init_rw)
86159 + module_free(mod, mod->module_init_rw);
86160 + module_free(mod, mod->module_core_rw);
86161 + return -ENOMEM;
86162 + }
86163 +
86164 + pax_open_kernel();
86165 + memset(ptr, 0, mod->init_size_rx);
86166 + pax_close_kernel();
86167 + mod->module_init_rx = ptr;
86168 + } else
86169 + mod->module_init_rx = NULL;
86170
86171 /* Transfer each section which specifies SHF_ALLOC */
86172 pr_debug("final section addresses:\n");
86173 @@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
86174 if (!(shdr->sh_flags & SHF_ALLOC))
86175 continue;
86176
86177 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
86178 - dest = mod->module_init
86179 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86180 - else
86181 - dest = mod->module_core + shdr->sh_entsize;
86182 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
86183 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86184 + dest = mod->module_init_rw
86185 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86186 + else
86187 + dest = mod->module_init_rx
86188 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86189 + } else {
86190 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86191 + dest = mod->module_core_rw + shdr->sh_entsize;
86192 + else
86193 + dest = mod->module_core_rx + shdr->sh_entsize;
86194 + }
86195 +
86196 + if (shdr->sh_type != SHT_NOBITS) {
86197 +
86198 +#ifdef CONFIG_PAX_KERNEXEC
86199 +#ifdef CONFIG_X86_64
86200 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
86201 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
86202 +#endif
86203 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
86204 + pax_open_kernel();
86205 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86206 + pax_close_kernel();
86207 + } else
86208 +#endif
86209
86210 - if (shdr->sh_type != SHT_NOBITS)
86211 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86212 + }
86213 /* Update sh_addr to point to copy in image. */
86214 - shdr->sh_addr = (unsigned long)dest;
86215 +
86216 +#ifdef CONFIG_PAX_KERNEXEC
86217 + if (shdr->sh_flags & SHF_EXECINSTR)
86218 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
86219 + else
86220 +#endif
86221 +
86222 + shdr->sh_addr = (unsigned long)dest;
86223 pr_debug("\t0x%lx %s\n",
86224 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
86225 }
86226 @@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
86227 * Do it before processing of module parameters, so the module
86228 * can provide parameter accessor functions of its own.
86229 */
86230 - if (mod->module_init)
86231 - flush_icache_range((unsigned long)mod->module_init,
86232 - (unsigned long)mod->module_init
86233 - + mod->init_size);
86234 - flush_icache_range((unsigned long)mod->module_core,
86235 - (unsigned long)mod->module_core + mod->core_size);
86236 + if (mod->module_init_rx)
86237 + flush_icache_range((unsigned long)mod->module_init_rx,
86238 + (unsigned long)mod->module_init_rx
86239 + + mod->init_size_rx);
86240 + flush_icache_range((unsigned long)mod->module_core_rx,
86241 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
86242
86243 set_fs(old_fs);
86244 }
86245 @@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
86246 static void module_deallocate(struct module *mod, struct load_info *info)
86247 {
86248 percpu_modfree(mod);
86249 - module_free(mod, mod->module_init);
86250 - module_free(mod, mod->module_core);
86251 + module_free_exec(mod, mod->module_init_rx);
86252 + module_free_exec(mod, mod->module_core_rx);
86253 + module_free(mod, mod->module_init_rw);
86254 + module_free(mod, mod->module_core_rw);
86255 }
86256
86257 int __weak module_finalize(const Elf_Ehdr *hdr,
86258 @@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
86259 static int post_relocation(struct module *mod, const struct load_info *info)
86260 {
86261 /* Sort exception table now relocations are done. */
86262 + pax_open_kernel();
86263 sort_extable(mod->extable, mod->extable + mod->num_exentries);
86264 + pax_close_kernel();
86265
86266 /* Copy relocated percpu area over. */
86267 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
86268 @@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
86269 MODULE_STATE_COMING, mod);
86270
86271 /* Set RO and NX regions for core */
86272 - set_section_ro_nx(mod->module_core,
86273 - mod->core_text_size,
86274 - mod->core_ro_size,
86275 - mod->core_size);
86276 + set_section_ro_nx(mod->module_core_rx,
86277 + mod->core_size_rx,
86278 + mod->core_size_rx,
86279 + mod->core_size_rx);
86280
86281 /* Set RO and NX regions for init */
86282 - set_section_ro_nx(mod->module_init,
86283 - mod->init_text_size,
86284 - mod->init_ro_size,
86285 - mod->init_size);
86286 + set_section_ro_nx(mod->module_init_rx,
86287 + mod->init_size_rx,
86288 + mod->init_size_rx,
86289 + mod->init_size_rx);
86290
86291 do_mod_ctors(mod);
86292 /* Start the module */
86293 @@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
86294 mod->strtab = mod->core_strtab;
86295 #endif
86296 unset_module_init_ro_nx(mod);
86297 - module_free(mod, mod->module_init);
86298 - mod->module_init = NULL;
86299 - mod->init_size = 0;
86300 - mod->init_ro_size = 0;
86301 - mod->init_text_size = 0;
86302 + module_free(mod, mod->module_init_rw);
86303 + module_free_exec(mod, mod->module_init_rx);
86304 + mod->module_init_rw = NULL;
86305 + mod->module_init_rx = NULL;
86306 + mod->init_size_rw = 0;
86307 + mod->init_size_rx = 0;
86308 mutex_unlock(&module_mutex);
86309 wake_up_all(&module_wq);
86310
86311 @@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
86312 if (err)
86313 goto free_unload;
86314
86315 + /* Now copy in args */
86316 + mod->args = strndup_user(uargs, ~0UL >> 1);
86317 + if (IS_ERR(mod->args)) {
86318 + err = PTR_ERR(mod->args);
86319 + goto free_unload;
86320 + }
86321 +
86322 /* Set up MODINFO_ATTR fields */
86323 setup_modinfo(mod, info);
86324
86325 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86326 + {
86327 + char *p, *p2;
86328 +
86329 + if (strstr(mod->args, "grsec_modharden_netdev")) {
86330 + 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);
86331 + err = -EPERM;
86332 + goto free_modinfo;
86333 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
86334 + p += sizeof("grsec_modharden_normal") - 1;
86335 + p2 = strstr(p, "_");
86336 + if (p2) {
86337 + *p2 = '\0';
86338 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
86339 + *p2 = '_';
86340 + }
86341 + err = -EPERM;
86342 + goto free_modinfo;
86343 + }
86344 + }
86345 +#endif
86346 +
86347 /* Fix up syms, so that st_value is a pointer to location. */
86348 err = simplify_symbols(mod, info);
86349 if (err < 0)
86350 @@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
86351
86352 flush_module_icache(mod);
86353
86354 - /* Now copy in args */
86355 - mod->args = strndup_user(uargs, ~0UL >> 1);
86356 - if (IS_ERR(mod->args)) {
86357 - err = PTR_ERR(mod->args);
86358 - goto free_arch_cleanup;
86359 - }
86360 -
86361 dynamic_debug_setup(info->debug, info->num_debug);
86362
86363 /* Finally it's fully formed, ready to start executing. */
86364 @@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
86365 ddebug_cleanup:
86366 dynamic_debug_remove(info->debug);
86367 synchronize_sched();
86368 - kfree(mod->args);
86369 - free_arch_cleanup:
86370 module_arch_cleanup(mod);
86371 free_modinfo:
86372 free_modinfo(mod);
86373 + kfree(mod->args);
86374 free_unload:
86375 module_unload_free(mod);
86376 unlink_mod:
86377 @@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
86378 unsigned long nextval;
86379
86380 /* At worse, next value is at end of module */
86381 - if (within_module_init(addr, mod))
86382 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
86383 + if (within_module_init_rx(addr, mod))
86384 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
86385 + else if (within_module_init_rw(addr, mod))
86386 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
86387 + else if (within_module_core_rx(addr, mod))
86388 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
86389 + else if (within_module_core_rw(addr, mod))
86390 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
86391 else
86392 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
86393 + return NULL;
86394
86395 /* Scan for closest preceding symbol, and next symbol. (ELF
86396 starts real symbols at 1). */
86397 @@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
86398 return 0;
86399
86400 seq_printf(m, "%s %u",
86401 - mod->name, mod->init_size + mod->core_size);
86402 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
86403 print_unload_info(m, mod);
86404
86405 /* Informative for users. */
86406 @@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
86407 mod->state == MODULE_STATE_COMING ? "Loading":
86408 "Live");
86409 /* Used by oprofile and other similar tools. */
86410 - seq_printf(m, " 0x%pK", mod->module_core);
86411 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
86412
86413 /* Taints info */
86414 if (mod->taints)
86415 @@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
86416
86417 static int __init proc_modules_init(void)
86418 {
86419 +#ifndef CONFIG_GRKERNSEC_HIDESYM
86420 +#ifdef CONFIG_GRKERNSEC_PROC_USER
86421 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86422 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86423 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
86424 +#else
86425 proc_create("modules", 0, NULL, &proc_modules_operations);
86426 +#endif
86427 +#else
86428 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86429 +#endif
86430 return 0;
86431 }
86432 module_init(proc_modules_init);
86433 @@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
86434 {
86435 struct module *mod;
86436
86437 - if (addr < module_addr_min || addr > module_addr_max)
86438 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
86439 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
86440 return NULL;
86441
86442 list_for_each_entry_rcu(mod, &modules, list) {
86443 if (mod->state == MODULE_STATE_UNFORMED)
86444 continue;
86445 - if (within_module_core(addr, mod)
86446 - || within_module_init(addr, mod))
86447 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
86448 return mod;
86449 }
86450 return NULL;
86451 @@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
86452 */
86453 struct module *__module_text_address(unsigned long addr)
86454 {
86455 - struct module *mod = __module_address(addr);
86456 + struct module *mod;
86457 +
86458 +#ifdef CONFIG_X86_32
86459 + addr = ktla_ktva(addr);
86460 +#endif
86461 +
86462 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
86463 + return NULL;
86464 +
86465 + mod = __module_address(addr);
86466 +
86467 if (mod) {
86468 /* Make sure it's within the text section. */
86469 - if (!within(addr, mod->module_init, mod->init_text_size)
86470 - && !within(addr, mod->module_core, mod->core_text_size))
86471 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
86472 mod = NULL;
86473 }
86474 return mod;
86475 diff --git a/kernel/notifier.c b/kernel/notifier.c
86476 index 2d5cc4c..d9ea600 100644
86477 --- a/kernel/notifier.c
86478 +++ b/kernel/notifier.c
86479 @@ -5,6 +5,7 @@
86480 #include <linux/rcupdate.h>
86481 #include <linux/vmalloc.h>
86482 #include <linux/reboot.h>
86483 +#include <linux/mm.h>
86484
86485 /*
86486 * Notifier list for kernel code which wants to be called
86487 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
86488 while ((*nl) != NULL) {
86489 if (n->priority > (*nl)->priority)
86490 break;
86491 - nl = &((*nl)->next);
86492 + nl = (struct notifier_block **)&((*nl)->next);
86493 }
86494 - n->next = *nl;
86495 + pax_open_kernel();
86496 + *(const void **)&n->next = *nl;
86497 rcu_assign_pointer(*nl, n);
86498 + pax_close_kernel();
86499 return 0;
86500 }
86501
86502 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
86503 return 0;
86504 if (n->priority > (*nl)->priority)
86505 break;
86506 - nl = &((*nl)->next);
86507 + nl = (struct notifier_block **)&((*nl)->next);
86508 }
86509 - n->next = *nl;
86510 + pax_open_kernel();
86511 + *(const void **)&n->next = *nl;
86512 rcu_assign_pointer(*nl, n);
86513 + pax_close_kernel();
86514 return 0;
86515 }
86516
86517 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
86518 {
86519 while ((*nl) != NULL) {
86520 if ((*nl) == n) {
86521 + pax_open_kernel();
86522 rcu_assign_pointer(*nl, n->next);
86523 + pax_close_kernel();
86524 return 0;
86525 }
86526 - nl = &((*nl)->next);
86527 + nl = (struct notifier_block **)&((*nl)->next);
86528 }
86529 return -ENOENT;
86530 }
86531 diff --git a/kernel/padata.c b/kernel/padata.c
86532 index 2abd25d..02c4faa 100644
86533 --- a/kernel/padata.c
86534 +++ b/kernel/padata.c
86535 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
86536 * seq_nr mod. number of cpus in use.
86537 */
86538
86539 - seq_nr = atomic_inc_return(&pd->seq_nr);
86540 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
86541 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
86542
86543 return padata_index_to_cpu(pd, cpu_index);
86544 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
86545 padata_init_pqueues(pd);
86546 padata_init_squeues(pd);
86547 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
86548 - atomic_set(&pd->seq_nr, -1);
86549 + atomic_set_unchecked(&pd->seq_nr, -1);
86550 atomic_set(&pd->reorder_objects, 0);
86551 atomic_set(&pd->refcnt, 0);
86552 pd->pinst = pinst;
86553 diff --git a/kernel/panic.c b/kernel/panic.c
86554 index c00b4ce..a846117 100644
86555 --- a/kernel/panic.c
86556 +++ b/kernel/panic.c
86557 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
86558 disable_trace_on_warning();
86559
86560 pr_warn("------------[ cut here ]------------\n");
86561 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
86562 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
86563 raw_smp_processor_id(), current->pid, file, line, caller);
86564
86565 if (args)
86566 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
86567 */
86568 void __stack_chk_fail(void)
86569 {
86570 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
86571 + dump_stack();
86572 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
86573 __builtin_return_address(0));
86574 }
86575 EXPORT_SYMBOL(__stack_chk_fail);
86576 diff --git a/kernel/pid.c b/kernel/pid.c
86577 index 9b9a266..c20ef80 100644
86578 --- a/kernel/pid.c
86579 +++ b/kernel/pid.c
86580 @@ -33,6 +33,7 @@
86581 #include <linux/rculist.h>
86582 #include <linux/bootmem.h>
86583 #include <linux/hash.h>
86584 +#include <linux/security.h>
86585 #include <linux/pid_namespace.h>
86586 #include <linux/init_task.h>
86587 #include <linux/syscalls.h>
86588 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
86589
86590 int pid_max = PID_MAX_DEFAULT;
86591
86592 -#define RESERVED_PIDS 300
86593 +#define RESERVED_PIDS 500
86594
86595 int pid_max_min = RESERVED_PIDS + 1;
86596 int pid_max_max = PID_MAX_LIMIT;
86597 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
86598 */
86599 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
86600 {
86601 + struct task_struct *task;
86602 +
86603 rcu_lockdep_assert(rcu_read_lock_held(),
86604 "find_task_by_pid_ns() needs rcu_read_lock()"
86605 " protection");
86606 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86607 +
86608 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86609 +
86610 + if (gr_pid_is_chrooted(task))
86611 + return NULL;
86612 +
86613 + return task;
86614 }
86615
86616 struct task_struct *find_task_by_vpid(pid_t vnr)
86617 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
86618 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
86619 }
86620
86621 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
86622 +{
86623 + rcu_lockdep_assert(rcu_read_lock_held(),
86624 + "find_task_by_pid_ns() needs rcu_read_lock()"
86625 + " protection");
86626 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
86627 +}
86628 +
86629 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
86630 {
86631 struct pid *pid;
86632 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
86633 index 06c62de..b08cc6c 100644
86634 --- a/kernel/pid_namespace.c
86635 +++ b/kernel/pid_namespace.c
86636 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
86637 void __user *buffer, size_t *lenp, loff_t *ppos)
86638 {
86639 struct pid_namespace *pid_ns = task_active_pid_ns(current);
86640 - struct ctl_table tmp = *table;
86641 + ctl_table_no_const tmp = *table;
86642
86643 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
86644 return -EPERM;
86645 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
86646 index c7f31aa..2b44977 100644
86647 --- a/kernel/posix-cpu-timers.c
86648 +++ b/kernel/posix-cpu-timers.c
86649 @@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
86650
86651 static __init int init_posix_cpu_timers(void)
86652 {
86653 - struct k_clock process = {
86654 + static struct k_clock process = {
86655 .clock_getres = process_cpu_clock_getres,
86656 .clock_get = process_cpu_clock_get,
86657 .timer_create = process_cpu_timer_create,
86658 .nsleep = process_cpu_nsleep,
86659 .nsleep_restart = process_cpu_nsleep_restart,
86660 };
86661 - struct k_clock thread = {
86662 + static struct k_clock thread = {
86663 .clock_getres = thread_cpu_clock_getres,
86664 .clock_get = thread_cpu_clock_get,
86665 .timer_create = thread_cpu_timer_create,
86666 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
86667 index 424c2d4..679242f 100644
86668 --- a/kernel/posix-timers.c
86669 +++ b/kernel/posix-timers.c
86670 @@ -43,6 +43,7 @@
86671 #include <linux/hash.h>
86672 #include <linux/posix-clock.h>
86673 #include <linux/posix-timers.h>
86674 +#include <linux/grsecurity.h>
86675 #include <linux/syscalls.h>
86676 #include <linux/wait.h>
86677 #include <linux/workqueue.h>
86678 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
86679 * which we beg off on and pass to do_sys_settimeofday().
86680 */
86681
86682 -static struct k_clock posix_clocks[MAX_CLOCKS];
86683 +static struct k_clock *posix_clocks[MAX_CLOCKS];
86684
86685 /*
86686 * These ones are defined below.
86687 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
86688 */
86689 static __init int init_posix_timers(void)
86690 {
86691 - struct k_clock clock_realtime = {
86692 + static struct k_clock clock_realtime = {
86693 .clock_getres = hrtimer_get_res,
86694 .clock_get = posix_clock_realtime_get,
86695 .clock_set = posix_clock_realtime_set,
86696 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
86697 .timer_get = common_timer_get,
86698 .timer_del = common_timer_del,
86699 };
86700 - struct k_clock clock_monotonic = {
86701 + static struct k_clock clock_monotonic = {
86702 .clock_getres = hrtimer_get_res,
86703 .clock_get = posix_ktime_get_ts,
86704 .nsleep = common_nsleep,
86705 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
86706 .timer_get = common_timer_get,
86707 .timer_del = common_timer_del,
86708 };
86709 - struct k_clock clock_monotonic_raw = {
86710 + static struct k_clock clock_monotonic_raw = {
86711 .clock_getres = hrtimer_get_res,
86712 .clock_get = posix_get_monotonic_raw,
86713 };
86714 - struct k_clock clock_realtime_coarse = {
86715 + static struct k_clock clock_realtime_coarse = {
86716 .clock_getres = posix_get_coarse_res,
86717 .clock_get = posix_get_realtime_coarse,
86718 };
86719 - struct k_clock clock_monotonic_coarse = {
86720 + static struct k_clock clock_monotonic_coarse = {
86721 .clock_getres = posix_get_coarse_res,
86722 .clock_get = posix_get_monotonic_coarse,
86723 };
86724 - struct k_clock clock_tai = {
86725 + static struct k_clock clock_tai = {
86726 .clock_getres = hrtimer_get_res,
86727 .clock_get = posix_get_tai,
86728 .nsleep = common_nsleep,
86729 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
86730 .timer_get = common_timer_get,
86731 .timer_del = common_timer_del,
86732 };
86733 - struct k_clock clock_boottime = {
86734 + static struct k_clock clock_boottime = {
86735 .clock_getres = hrtimer_get_res,
86736 .clock_get = posix_get_boottime,
86737 .nsleep = common_nsleep,
86738 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
86739 return;
86740 }
86741
86742 - posix_clocks[clock_id] = *new_clock;
86743 + posix_clocks[clock_id] = new_clock;
86744 }
86745 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
86746
86747 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
86748 return (id & CLOCKFD_MASK) == CLOCKFD ?
86749 &clock_posix_dynamic : &clock_posix_cpu;
86750
86751 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
86752 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
86753 return NULL;
86754 - return &posix_clocks[id];
86755 + return posix_clocks[id];
86756 }
86757
86758 static int common_timer_create(struct k_itimer *new_timer)
86759 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
86760 struct k_clock *kc = clockid_to_kclock(which_clock);
86761 struct k_itimer *new_timer;
86762 int error, new_timer_id;
86763 - sigevent_t event;
86764 + sigevent_t event = { };
86765 int it_id_set = IT_ID_NOT_SET;
86766
86767 if (!kc)
86768 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
86769 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
86770 return -EFAULT;
86771
86772 + /* only the CLOCK_REALTIME clock can be set, all other clocks
86773 + have their clock_set fptr set to a nosettime dummy function
86774 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
86775 + call common_clock_set, which calls do_sys_settimeofday, which
86776 + we hook
86777 + */
86778 +
86779 return kc->clock_set(which_clock, &new_tp);
86780 }
86781
86782 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
86783 index 2fac9cc..56fef29 100644
86784 --- a/kernel/power/Kconfig
86785 +++ b/kernel/power/Kconfig
86786 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
86787 config HIBERNATION
86788 bool "Hibernation (aka 'suspend to disk')"
86789 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
86790 + depends on !GRKERNSEC_KMEM
86791 + depends on !PAX_MEMORY_SANITIZE
86792 select HIBERNATE_CALLBACKS
86793 select LZO_COMPRESS
86794 select LZO_DECOMPRESS
86795 diff --git a/kernel/power/process.c b/kernel/power/process.c
86796 index 06ec886..9dba35e 100644
86797 --- a/kernel/power/process.c
86798 +++ b/kernel/power/process.c
86799 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
86800 unsigned int elapsed_msecs;
86801 bool wakeup = false;
86802 int sleep_usecs = USEC_PER_MSEC;
86803 + bool timedout = false;
86804
86805 do_gettimeofday(&start);
86806
86807 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
86808
86809 while (true) {
86810 todo = 0;
86811 + if (time_after(jiffies, end_time))
86812 + timedout = true;
86813 read_lock(&tasklist_lock);
86814 do_each_thread(g, p) {
86815 if (p == current || !freeze_task(p))
86816 continue;
86817
86818 - if (!freezer_should_skip(p))
86819 + if (!freezer_should_skip(p)) {
86820 todo++;
86821 + if (timedout) {
86822 + printk(KERN_ERR "Task refusing to freeze:\n");
86823 + sched_show_task(p);
86824 + }
86825 + }
86826 } while_each_thread(g, p);
86827 read_unlock(&tasklist_lock);
86828
86829 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
86830 todo += wq_busy;
86831 }
86832
86833 - if (!todo || time_after(jiffies, end_time))
86834 + if (!todo || timedout)
86835 break;
86836
86837 if (pm_wakeup_pending()) {
86838 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
86839 index be7c86b..c741464 100644
86840 --- a/kernel/printk/printk.c
86841 +++ b/kernel/printk/printk.c
86842 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
86843 if (from_file && type != SYSLOG_ACTION_OPEN)
86844 return 0;
86845
86846 +#ifdef CONFIG_GRKERNSEC_DMESG
86847 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
86848 + return -EPERM;
86849 +#endif
86850 +
86851 if (syslog_action_restricted(type)) {
86852 if (capable(CAP_SYSLOG))
86853 return 0;
86854 diff --git a/kernel/profile.c b/kernel/profile.c
86855 index 6631e1e..310c266 100644
86856 --- a/kernel/profile.c
86857 +++ b/kernel/profile.c
86858 @@ -37,7 +37,7 @@ struct profile_hit {
86859 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
86860 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
86861
86862 -static atomic_t *prof_buffer;
86863 +static atomic_unchecked_t *prof_buffer;
86864 static unsigned long prof_len, prof_shift;
86865
86866 int prof_on __read_mostly;
86867 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
86868 hits[i].pc = 0;
86869 continue;
86870 }
86871 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86872 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86873 hits[i].hits = hits[i].pc = 0;
86874 }
86875 }
86876 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86877 * Add the current hit(s) and flush the write-queue out
86878 * to the global buffer:
86879 */
86880 - atomic_add(nr_hits, &prof_buffer[pc]);
86881 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
86882 for (i = 0; i < NR_PROFILE_HIT; ++i) {
86883 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86884 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86885 hits[i].pc = hits[i].hits = 0;
86886 }
86887 out:
86888 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86889 {
86890 unsigned long pc;
86891 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
86892 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86893 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86894 }
86895 #endif /* !CONFIG_SMP */
86896
86897 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
86898 return -EFAULT;
86899 buf++; p++; count--; read++;
86900 }
86901 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
86902 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
86903 if (copy_to_user(buf, (void *)pnt, count))
86904 return -EFAULT;
86905 read += count;
86906 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
86907 }
86908 #endif
86909 profile_discard_flip_buffers();
86910 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
86911 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
86912 return count;
86913 }
86914
86915 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
86916 index 1f4bcb3..99cf7ab 100644
86917 --- a/kernel/ptrace.c
86918 +++ b/kernel/ptrace.c
86919 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
86920 if (seize)
86921 flags |= PT_SEIZED;
86922 rcu_read_lock();
86923 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86924 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86925 flags |= PT_PTRACE_CAP;
86926 rcu_read_unlock();
86927 task->ptrace = flags;
86928 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
86929 break;
86930 return -EIO;
86931 }
86932 - if (copy_to_user(dst, buf, retval))
86933 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
86934 return -EFAULT;
86935 copied += retval;
86936 src += retval;
86937 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
86938 bool seized = child->ptrace & PT_SEIZED;
86939 int ret = -EIO;
86940 siginfo_t siginfo, *si;
86941 - void __user *datavp = (void __user *) data;
86942 + void __user *datavp = (__force void __user *) data;
86943 unsigned long __user *datalp = datavp;
86944 unsigned long flags;
86945
86946 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
86947 goto out;
86948 }
86949
86950 + if (gr_handle_ptrace(child, request)) {
86951 + ret = -EPERM;
86952 + goto out_put_task_struct;
86953 + }
86954 +
86955 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86956 ret = ptrace_attach(child, request, addr, data);
86957 /*
86958 * Some architectures need to do book-keeping after
86959 * a ptrace attach.
86960 */
86961 - if (!ret)
86962 + if (!ret) {
86963 arch_ptrace_attach(child);
86964 + gr_audit_ptrace(child);
86965 + }
86966 goto out_put_task_struct;
86967 }
86968
86969 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
86970 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
86971 if (copied != sizeof(tmp))
86972 return -EIO;
86973 - return put_user(tmp, (unsigned long __user *)data);
86974 + return put_user(tmp, (__force unsigned long __user *)data);
86975 }
86976
86977 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
86978 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
86979 }
86980
86981 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86982 - compat_long_t addr, compat_long_t data)
86983 + compat_ulong_t addr, compat_ulong_t data)
86984 {
86985 struct task_struct *child;
86986 long ret;
86987 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86988 goto out;
86989 }
86990
86991 + if (gr_handle_ptrace(child, request)) {
86992 + ret = -EPERM;
86993 + goto out_put_task_struct;
86994 + }
86995 +
86996 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86997 ret = ptrace_attach(child, request, addr, data);
86998 /*
86999 * Some architectures need to do book-keeping after
87000 * a ptrace attach.
87001 */
87002 - if (!ret)
87003 + if (!ret) {
87004 arch_ptrace_attach(child);
87005 + gr_audit_ptrace(child);
87006 + }
87007 goto out_put_task_struct;
87008 }
87009
87010 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
87011 index 01d5ccb..cdcbee6 100644
87012 --- a/kernel/rcu/srcu.c
87013 +++ b/kernel/rcu/srcu.c
87014 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
87015
87016 idx = ACCESS_ONCE(sp->completed) & 0x1;
87017 preempt_disable();
87018 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87019 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87020 smp_mb(); /* B */ /* Avoid leaking the critical section. */
87021 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87022 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87023 preempt_enable();
87024 return idx;
87025 }
87026 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
87027 index 1254f31..16258dc 100644
87028 --- a/kernel/rcu/tiny.c
87029 +++ b/kernel/rcu/tiny.c
87030 @@ -46,7 +46,7 @@
87031 /* Forward declarations for tiny_plugin.h. */
87032 struct rcu_ctrlblk;
87033 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
87034 -static void rcu_process_callbacks(struct softirq_action *unused);
87035 +static void rcu_process_callbacks(void);
87036 static void __call_rcu(struct rcu_head *head,
87037 void (*func)(struct rcu_head *rcu),
87038 struct rcu_ctrlblk *rcp);
87039 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
87040 false));
87041 }
87042
87043 -static void rcu_process_callbacks(struct softirq_action *unused)
87044 +static __latent_entropy void rcu_process_callbacks(void)
87045 {
87046 __rcu_process_callbacks(&rcu_sched_ctrlblk);
87047 __rcu_process_callbacks(&rcu_bh_ctrlblk);
87048 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
87049 index 3929cd4..421624d 100644
87050 --- a/kernel/rcu/torture.c
87051 +++ b/kernel/rcu/torture.c
87052 @@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
87053 { 0 };
87054 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
87055 { 0 };
87056 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87057 -static atomic_t n_rcu_torture_alloc;
87058 -static atomic_t n_rcu_torture_alloc_fail;
87059 -static atomic_t n_rcu_torture_free;
87060 -static atomic_t n_rcu_torture_mberror;
87061 -static atomic_t n_rcu_torture_error;
87062 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87063 +static atomic_unchecked_t n_rcu_torture_alloc;
87064 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
87065 +static atomic_unchecked_t n_rcu_torture_free;
87066 +static atomic_unchecked_t n_rcu_torture_mberror;
87067 +static atomic_unchecked_t n_rcu_torture_error;
87068 static long n_rcu_torture_barrier_error;
87069 static long n_rcu_torture_boost_ktrerror;
87070 static long n_rcu_torture_boost_rterror;
87071 @@ -299,11 +299,11 @@ rcu_torture_alloc(void)
87072
87073 spin_lock_bh(&rcu_torture_lock);
87074 if (list_empty(&rcu_torture_freelist)) {
87075 - atomic_inc(&n_rcu_torture_alloc_fail);
87076 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
87077 spin_unlock_bh(&rcu_torture_lock);
87078 return NULL;
87079 }
87080 - atomic_inc(&n_rcu_torture_alloc);
87081 + atomic_inc_unchecked(&n_rcu_torture_alloc);
87082 p = rcu_torture_freelist.next;
87083 list_del_init(p);
87084 spin_unlock_bh(&rcu_torture_lock);
87085 @@ -316,7 +316,7 @@ rcu_torture_alloc(void)
87086 static void
87087 rcu_torture_free(struct rcu_torture *p)
87088 {
87089 - atomic_inc(&n_rcu_torture_free);
87090 + atomic_inc_unchecked(&n_rcu_torture_free);
87091 spin_lock_bh(&rcu_torture_lock);
87092 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
87093 spin_unlock_bh(&rcu_torture_lock);
87094 @@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
87095 i = rp->rtort_pipe_count;
87096 if (i > RCU_TORTURE_PIPE_LEN)
87097 i = RCU_TORTURE_PIPE_LEN;
87098 - atomic_inc(&rcu_torture_wcount[i]);
87099 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87100 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
87101 rp->rtort_mbtest = 0;
87102 rcu_torture_free(rp);
87103 @@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
87104 i = old_rp->rtort_pipe_count;
87105 if (i > RCU_TORTURE_PIPE_LEN)
87106 i = RCU_TORTURE_PIPE_LEN;
87107 - atomic_inc(&rcu_torture_wcount[i]);
87108 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87109 old_rp->rtort_pipe_count++;
87110 if (gp_normal == gp_exp)
87111 exp = !!(rcu_random(&rand) & 0x80);
87112 @@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
87113 i = rp->rtort_pipe_count;
87114 if (i > RCU_TORTURE_PIPE_LEN)
87115 i = RCU_TORTURE_PIPE_LEN;
87116 - atomic_inc(&rcu_torture_wcount[i]);
87117 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87118 if (++rp->rtort_pipe_count >=
87119 RCU_TORTURE_PIPE_LEN) {
87120 rp->rtort_mbtest = 0;
87121 @@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
87122 return;
87123 }
87124 if (p->rtort_mbtest == 0)
87125 - atomic_inc(&n_rcu_torture_mberror);
87126 + atomic_inc_unchecked(&n_rcu_torture_mberror);
87127 spin_lock(&rand_lock);
87128 cur_ops->read_delay(&rand);
87129 n_rcu_torture_timers++;
87130 @@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
87131 continue;
87132 }
87133 if (p->rtort_mbtest == 0)
87134 - atomic_inc(&n_rcu_torture_mberror);
87135 + atomic_inc_unchecked(&n_rcu_torture_mberror);
87136 cur_ops->read_delay(&rand);
87137 preempt_disable();
87138 pipe_count = p->rtort_pipe_count;
87139 @@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
87140 rcu_torture_current,
87141 rcu_torture_current_version,
87142 list_empty(&rcu_torture_freelist),
87143 - atomic_read(&n_rcu_torture_alloc),
87144 - atomic_read(&n_rcu_torture_alloc_fail),
87145 - atomic_read(&n_rcu_torture_free));
87146 + atomic_read_unchecked(&n_rcu_torture_alloc),
87147 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
87148 + atomic_read_unchecked(&n_rcu_torture_free));
87149 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
87150 - atomic_read(&n_rcu_torture_mberror),
87151 + atomic_read_unchecked(&n_rcu_torture_mberror),
87152 n_rcu_torture_boost_ktrerror,
87153 n_rcu_torture_boost_rterror);
87154 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
87155 @@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
87156 n_barrier_attempts,
87157 n_rcu_torture_barrier_error);
87158 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
87159 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
87160 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
87161 n_rcu_torture_barrier_error != 0 ||
87162 n_rcu_torture_boost_ktrerror != 0 ||
87163 n_rcu_torture_boost_rterror != 0 ||
87164 n_rcu_torture_boost_failure != 0 ||
87165 i > 1) {
87166 cnt += sprintf(&page[cnt], "!!! ");
87167 - atomic_inc(&n_rcu_torture_error);
87168 + atomic_inc_unchecked(&n_rcu_torture_error);
87169 WARN_ON_ONCE(1);
87170 }
87171 cnt += sprintf(&page[cnt], "Reader Pipe: ");
87172 @@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
87173 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
87174 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87175 cnt += sprintf(&page[cnt], " %d",
87176 - atomic_read(&rcu_torture_wcount[i]));
87177 + atomic_read_unchecked(&rcu_torture_wcount[i]));
87178 }
87179 cnt += sprintf(&page[cnt], "\n");
87180 if (cur_ops->stats)
87181 @@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
87182
87183 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
87184
87185 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87186 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87187 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
87188 else if (n_online_successes != n_online_attempts ||
87189 n_offline_successes != n_offline_attempts)
87190 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
87191
87192 rcu_torture_current = NULL;
87193 rcu_torture_current_version = 0;
87194 - atomic_set(&n_rcu_torture_alloc, 0);
87195 - atomic_set(&n_rcu_torture_alloc_fail, 0);
87196 - atomic_set(&n_rcu_torture_free, 0);
87197 - atomic_set(&n_rcu_torture_mberror, 0);
87198 - atomic_set(&n_rcu_torture_error, 0);
87199 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
87200 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
87201 + atomic_set_unchecked(&n_rcu_torture_free, 0);
87202 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
87203 + atomic_set_unchecked(&n_rcu_torture_error, 0);
87204 n_rcu_torture_barrier_error = 0;
87205 n_rcu_torture_boost_ktrerror = 0;
87206 n_rcu_torture_boost_rterror = 0;
87207 n_rcu_torture_boost_failure = 0;
87208 n_rcu_torture_boosts = 0;
87209 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
87210 - atomic_set(&rcu_torture_wcount[i], 0);
87211 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
87212 for_each_possible_cpu(cpu) {
87213 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87214 per_cpu(rcu_torture_count, cpu)[i] = 0;
87215 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
87216 index dd08198..5ccccbe 100644
87217 --- a/kernel/rcu/tree.c
87218 +++ b/kernel/rcu/tree.c
87219 @@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
87220 rcu_prepare_for_idle(smp_processor_id());
87221 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87222 smp_mb__before_atomic_inc(); /* See above. */
87223 - atomic_inc(&rdtp->dynticks);
87224 + atomic_inc_unchecked(&rdtp->dynticks);
87225 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
87226 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87227 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87228
87229 /*
87230 * It is illegal to enter an extended quiescent state while
87231 @@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
87232 int user)
87233 {
87234 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
87235 - atomic_inc(&rdtp->dynticks);
87236 + atomic_inc_unchecked(&rdtp->dynticks);
87237 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87238 smp_mb__after_atomic_inc(); /* See above. */
87239 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87240 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87241 rcu_cleanup_after_idle(smp_processor_id());
87242 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
87243 if (!user && !is_idle_task(current)) {
87244 @@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
87245 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
87246
87247 if (rdtp->dynticks_nmi_nesting == 0 &&
87248 - (atomic_read(&rdtp->dynticks) & 0x1))
87249 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
87250 return;
87251 rdtp->dynticks_nmi_nesting++;
87252 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
87253 - atomic_inc(&rdtp->dynticks);
87254 + atomic_inc_unchecked(&rdtp->dynticks);
87255 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87256 smp_mb__after_atomic_inc(); /* See above. */
87257 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87258 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87259 }
87260
87261 /**
87262 @@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
87263 return;
87264 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87265 smp_mb__before_atomic_inc(); /* See above. */
87266 - atomic_inc(&rdtp->dynticks);
87267 + atomic_inc_unchecked(&rdtp->dynticks);
87268 smp_mb__after_atomic_inc(); /* Force delay to next write. */
87269 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87270 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87271 }
87272
87273 /**
87274 @@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
87275 */
87276 bool notrace __rcu_is_watching(void)
87277 {
87278 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87279 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87280 }
87281
87282 /**
87283 @@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
87284 static int dyntick_save_progress_counter(struct rcu_data *rdp,
87285 bool *isidle, unsigned long *maxj)
87286 {
87287 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
87288 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87289 rcu_sysidle_check_cpu(rdp, isidle, maxj);
87290 return (rdp->dynticks_snap & 0x1) == 0;
87291 }
87292 @@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
87293 unsigned int curr;
87294 unsigned int snap;
87295
87296 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
87297 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87298 snap = (unsigned int)rdp->dynticks_snap;
87299
87300 /*
87301 @@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
87302 rdp = this_cpu_ptr(rsp->rda);
87303 rcu_preempt_check_blocked_tasks(rnp);
87304 rnp->qsmask = rnp->qsmaskinit;
87305 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
87306 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
87307 WARN_ON_ONCE(rnp->completed != rsp->completed);
87308 - ACCESS_ONCE(rnp->completed) = rsp->completed;
87309 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
87310 if (rnp == rdp->mynode)
87311 __note_gp_changes(rsp, rnp, rdp);
87312 rcu_preempt_boost_start_gp(rnp);
87313 @@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
87314 */
87315 rcu_for_each_node_breadth_first(rsp, rnp) {
87316 raw_spin_lock_irq(&rnp->lock);
87317 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
87318 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
87319 rdp = this_cpu_ptr(rsp->rda);
87320 if (rnp == rdp->mynode)
87321 __note_gp_changes(rsp, rnp, rdp);
87322 @@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
87323 rsp->qlen += rdp->qlen;
87324 rdp->n_cbs_orphaned += rdp->qlen;
87325 rdp->qlen_lazy = 0;
87326 - ACCESS_ONCE(rdp->qlen) = 0;
87327 + ACCESS_ONCE_RW(rdp->qlen) = 0;
87328 }
87329
87330 /*
87331 @@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
87332 }
87333 smp_mb(); /* List handling before counting for rcu_barrier(). */
87334 rdp->qlen_lazy -= count_lazy;
87335 - ACCESS_ONCE(rdp->qlen) -= count;
87336 + ACCESS_ONCE_RW(rdp->qlen) -= count;
87337 rdp->n_cbs_invoked += count;
87338
87339 /* Reinstate batch limit if we have worked down the excess. */
87340 @@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
87341 /*
87342 * Do RCU core processing for the current CPU.
87343 */
87344 -static void rcu_process_callbacks(struct softirq_action *unused)
87345 +static void rcu_process_callbacks(void)
87346 {
87347 struct rcu_state *rsp;
87348
87349 @@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87350 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
87351 if (debug_rcu_head_queue(head)) {
87352 /* Probable double call_rcu(), so leak the callback. */
87353 - ACCESS_ONCE(head->func) = rcu_leak_callback;
87354 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
87355 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
87356 return;
87357 }
87358 @@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87359 local_irq_restore(flags);
87360 return;
87361 }
87362 - ACCESS_ONCE(rdp->qlen)++;
87363 + ACCESS_ONCE_RW(rdp->qlen)++;
87364 if (lazy)
87365 rdp->qlen_lazy++;
87366 else
87367 @@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
87368 * counter wrap on a 32-bit system. Quite a few more CPUs would of
87369 * course be required on a 64-bit system.
87370 */
87371 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
87372 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
87373 (ulong)atomic_long_read(&rsp->expedited_done) +
87374 ULONG_MAX / 8)) {
87375 synchronize_sched();
87376 - atomic_long_inc(&rsp->expedited_wrap);
87377 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
87378 return;
87379 }
87380
87381 @@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
87382 * Take a ticket. Note that atomic_inc_return() implies a
87383 * full memory barrier.
87384 */
87385 - snap = atomic_long_inc_return(&rsp->expedited_start);
87386 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
87387 firstsnap = snap;
87388 get_online_cpus();
87389 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
87390 @@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
87391 synchronize_sched_expedited_cpu_stop,
87392 NULL) == -EAGAIN) {
87393 put_online_cpus();
87394 - atomic_long_inc(&rsp->expedited_tryfail);
87395 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
87396
87397 /* Check to see if someone else did our work for us. */
87398 s = atomic_long_read(&rsp->expedited_done);
87399 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87400 /* ensure test happens before caller kfree */
87401 smp_mb__before_atomic_inc(); /* ^^^ */
87402 - atomic_long_inc(&rsp->expedited_workdone1);
87403 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
87404 return;
87405 }
87406
87407 @@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
87408 udelay(trycount * num_online_cpus());
87409 } else {
87410 wait_rcu_gp(call_rcu_sched);
87411 - atomic_long_inc(&rsp->expedited_normal);
87412 + atomic_long_inc_unchecked(&rsp->expedited_normal);
87413 return;
87414 }
87415
87416 @@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
87417 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87418 /* ensure test happens before caller kfree */
87419 smp_mb__before_atomic_inc(); /* ^^^ */
87420 - atomic_long_inc(&rsp->expedited_workdone2);
87421 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
87422 return;
87423 }
87424
87425 @@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
87426 * period works for us.
87427 */
87428 get_online_cpus();
87429 - snap = atomic_long_read(&rsp->expedited_start);
87430 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
87431 smp_mb(); /* ensure read is before try_stop_cpus(). */
87432 }
87433 - atomic_long_inc(&rsp->expedited_stoppedcpus);
87434 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
87435
87436 /*
87437 * Everyone up to our most recent fetch is covered by our grace
87438 @@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
87439 * than we did already did their update.
87440 */
87441 do {
87442 - atomic_long_inc(&rsp->expedited_done_tries);
87443 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
87444 s = atomic_long_read(&rsp->expedited_done);
87445 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
87446 /* ensure test happens before caller kfree */
87447 smp_mb__before_atomic_inc(); /* ^^^ */
87448 - atomic_long_inc(&rsp->expedited_done_lost);
87449 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
87450 break;
87451 }
87452 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
87453 - atomic_long_inc(&rsp->expedited_done_exit);
87454 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
87455
87456 put_online_cpus();
87457 }
87458 @@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87459 * ACCESS_ONCE() to prevent the compiler from speculating
87460 * the increment to precede the early-exit check.
87461 */
87462 - ACCESS_ONCE(rsp->n_barrier_done)++;
87463 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87464 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
87465 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
87466 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
87467 @@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87468
87469 /* Increment ->n_barrier_done to prevent duplicate work. */
87470 smp_mb(); /* Keep increment after above mechanism. */
87471 - ACCESS_ONCE(rsp->n_barrier_done)++;
87472 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87473 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
87474 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
87475 smp_mb(); /* Keep increment before caller's subsequent code. */
87476 @@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
87477 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
87478 init_callback_list(rdp);
87479 rdp->qlen_lazy = 0;
87480 - ACCESS_ONCE(rdp->qlen) = 0;
87481 + ACCESS_ONCE_RW(rdp->qlen) = 0;
87482 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
87483 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
87484 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
87485 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
87486 rdp->cpu = cpu;
87487 rdp->rsp = rsp;
87488 rcu_boot_init_nocb_percpu_data(rdp);
87489 @@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
87490 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
87491 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
87492 rcu_sysidle_init_percpu_data(rdp->dynticks);
87493 - atomic_set(&rdp->dynticks->dynticks,
87494 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
87495 + atomic_set_unchecked(&rdp->dynticks->dynticks,
87496 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
87497 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
87498
87499 /* Add CPU to rcu_node bitmasks. */
87500 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
87501 index 52be957..365ded3 100644
87502 --- a/kernel/rcu/tree.h
87503 +++ b/kernel/rcu/tree.h
87504 @@ -87,11 +87,11 @@ struct rcu_dynticks {
87505 long long dynticks_nesting; /* Track irq/process nesting level. */
87506 /* Process level is worth LLONG_MAX/2. */
87507 int dynticks_nmi_nesting; /* Track NMI nesting level. */
87508 - atomic_t dynticks; /* Even value for idle, else odd. */
87509 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
87510 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
87511 long long dynticks_idle_nesting;
87512 /* irq/process nesting level from idle. */
87513 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
87514 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
87515 /* "Idle" excludes userspace execution. */
87516 unsigned long dynticks_idle_jiffies;
87517 /* End of last non-NMI non-idle period. */
87518 @@ -429,17 +429,17 @@ struct rcu_state {
87519 /* _rcu_barrier(). */
87520 /* End of fields guarded by barrier_mutex. */
87521
87522 - atomic_long_t expedited_start; /* Starting ticket. */
87523 - atomic_long_t expedited_done; /* Done ticket. */
87524 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
87525 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
87526 - atomic_long_t expedited_workdone1; /* # done by others #1. */
87527 - atomic_long_t expedited_workdone2; /* # done by others #2. */
87528 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
87529 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
87530 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
87531 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
87532 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
87533 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
87534 + atomic_long_t expedited_done; /* Done ticket. */
87535 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
87536 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
87537 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
87538 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
87539 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
87540 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
87541 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
87542 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
87543 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
87544
87545 unsigned long jiffies_force_qs; /* Time at which to invoke */
87546 /* force_quiescent_state(). */
87547 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
87548 index 08a7652..3598c7e 100644
87549 --- a/kernel/rcu/tree_plugin.h
87550 +++ b/kernel/rcu/tree_plugin.h
87551 @@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
87552 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
87553 {
87554 return !rcu_preempted_readers_exp(rnp) &&
87555 - ACCESS_ONCE(rnp->expmask) == 0;
87556 + ACCESS_ONCE_RW(rnp->expmask) == 0;
87557 }
87558
87559 /*
87560 @@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
87561
87562 /* Clean up and exit. */
87563 smp_mb(); /* ensure expedited GP seen before counter increment. */
87564 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
87565 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
87566 unlock_mb_ret:
87567 mutex_unlock(&sync_rcu_preempt_exp_mutex);
87568 mb_ret:
87569 @@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
87570 free_cpumask_var(cm);
87571 }
87572
87573 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
87574 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
87575 .store = &rcu_cpu_kthread_task,
87576 .thread_should_run = rcu_cpu_kthread_should_run,
87577 .thread_fn = rcu_cpu_kthread,
87578 @@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
87579 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
87580 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
87581 cpu, ticks_value, ticks_title,
87582 - atomic_read(&rdtp->dynticks) & 0xfff,
87583 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
87584 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
87585 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
87586 fast_no_hz);
87587 @@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
87588
87589 /* Enqueue the callback on the nocb list and update counts. */
87590 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
87591 - ACCESS_ONCE(*old_rhpp) = rhp;
87592 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
87593 atomic_long_add(rhcount, &rdp->nocb_q_count);
87594 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
87595
87596 @@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
87597 * Extract queued callbacks, update counts, and wait
87598 * for a grace period to elapse.
87599 */
87600 - ACCESS_ONCE(rdp->nocb_head) = NULL;
87601 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
87602 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
87603 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
87604 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
87605 - ACCESS_ONCE(rdp->nocb_p_count) += c;
87606 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
87607 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
87608 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
87609 rcu_nocb_wait_gp(rdp);
87610
87611 /* Each pass through the following loop invokes a callback. */
87612 @@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
87613 list = next;
87614 }
87615 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
87616 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
87617 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
87618 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
87619 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
87620 rdp->n_nocbs_invoked += c;
87621 }
87622 return 0;
87623 @@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
87624 t = kthread_run(rcu_nocb_kthread, rdp,
87625 "rcuo%c/%d", rsp->abbr, cpu);
87626 BUG_ON(IS_ERR(t));
87627 - ACCESS_ONCE(rdp->nocb_kthread) = t;
87628 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
87629 }
87630 }
87631
87632 @@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
87633
87634 /* Record start of fully idle period. */
87635 j = jiffies;
87636 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
87637 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
87638 smp_mb__before_atomic_inc();
87639 - atomic_inc(&rdtp->dynticks_idle);
87640 + atomic_inc_unchecked(&rdtp->dynticks_idle);
87641 smp_mb__after_atomic_inc();
87642 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
87643 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
87644 }
87645
87646 /*
87647 @@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
87648
87649 /* Record end of idle period. */
87650 smp_mb__before_atomic_inc();
87651 - atomic_inc(&rdtp->dynticks_idle);
87652 + atomic_inc_unchecked(&rdtp->dynticks_idle);
87653 smp_mb__after_atomic_inc();
87654 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
87655 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
87656
87657 /*
87658 * If we are the timekeeping CPU, we are permitted to be non-idle
87659 @@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
87660 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
87661
87662 /* Pick up current idle and NMI-nesting counter and check. */
87663 - cur = atomic_read(&rdtp->dynticks_idle);
87664 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
87665 if (cur & 0x1) {
87666 *isidle = false; /* We are not idle! */
87667 return;
87668 @@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
87669 case RCU_SYSIDLE_NOT:
87670
87671 /* First time all are idle, so note a short idle period. */
87672 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87673 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87674 break;
87675
87676 case RCU_SYSIDLE_SHORT:
87677 @@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
87678 static void rcu_sysidle_cancel(void)
87679 {
87680 smp_mb();
87681 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
87682 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
87683 }
87684
87685 /*
87686 @@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
87687 smp_mb(); /* grace period precedes setting inuse. */
87688
87689 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
87690 - ACCESS_ONCE(rshp->inuse) = 0;
87691 + ACCESS_ONCE_RW(rshp->inuse) = 0;
87692 }
87693
87694 /*
87695 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
87696 index 3596797..f78391c 100644
87697 --- a/kernel/rcu/tree_trace.c
87698 +++ b/kernel/rcu/tree_trace.c
87699 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
87700 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
87701 rdp->passed_quiesce, rdp->qs_pending);
87702 seq_printf(m, " dt=%d/%llx/%d df=%lu",
87703 - atomic_read(&rdp->dynticks->dynticks),
87704 + atomic_read_unchecked(&rdp->dynticks->dynticks),
87705 rdp->dynticks->dynticks_nesting,
87706 rdp->dynticks->dynticks_nmi_nesting,
87707 rdp->dynticks_fqs);
87708 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
87709 struct rcu_state *rsp = (struct rcu_state *)m->private;
87710
87711 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",
87712 - atomic_long_read(&rsp->expedited_start),
87713 + atomic_long_read_unchecked(&rsp->expedited_start),
87714 atomic_long_read(&rsp->expedited_done),
87715 - atomic_long_read(&rsp->expedited_wrap),
87716 - atomic_long_read(&rsp->expedited_tryfail),
87717 - atomic_long_read(&rsp->expedited_workdone1),
87718 - atomic_long_read(&rsp->expedited_workdone2),
87719 - atomic_long_read(&rsp->expedited_normal),
87720 - atomic_long_read(&rsp->expedited_stoppedcpus),
87721 - atomic_long_read(&rsp->expedited_done_tries),
87722 - atomic_long_read(&rsp->expedited_done_lost),
87723 - atomic_long_read(&rsp->expedited_done_exit));
87724 + atomic_long_read_unchecked(&rsp->expedited_wrap),
87725 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
87726 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
87727 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
87728 + atomic_long_read_unchecked(&rsp->expedited_normal),
87729 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
87730 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
87731 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
87732 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
87733 return 0;
87734 }
87735
87736 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
87737 index 6cb3dff..dc5710f 100644
87738 --- a/kernel/rcu/update.c
87739 +++ b/kernel/rcu/update.c
87740 @@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
87741 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
87742 */
87743 if (till_stall_check < 3) {
87744 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
87745 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
87746 till_stall_check = 3;
87747 } else if (till_stall_check > 300) {
87748 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
87749 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
87750 till_stall_check = 300;
87751 }
87752 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
87753 diff --git a/kernel/resource.c b/kernel/resource.c
87754 index 3f285dc..5755f62 100644
87755 --- a/kernel/resource.c
87756 +++ b/kernel/resource.c
87757 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
87758
87759 static int __init ioresources_init(void)
87760 {
87761 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
87762 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87763 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
87764 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
87765 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87766 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
87767 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
87768 +#endif
87769 +#else
87770 proc_create("ioports", 0, NULL, &proc_ioports_operations);
87771 proc_create("iomem", 0, NULL, &proc_iomem_operations);
87772 +#endif
87773 return 0;
87774 }
87775 __initcall(ioresources_init);
87776 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
87777 index 4a07353..66b5291 100644
87778 --- a/kernel/sched/auto_group.c
87779 +++ b/kernel/sched/auto_group.c
87780 @@ -11,7 +11,7 @@
87781
87782 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
87783 static struct autogroup autogroup_default;
87784 -static atomic_t autogroup_seq_nr;
87785 +static atomic_unchecked_t autogroup_seq_nr;
87786
87787 void __init autogroup_init(struct task_struct *init_task)
87788 {
87789 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
87790
87791 kref_init(&ag->kref);
87792 init_rwsem(&ag->lock);
87793 - ag->id = atomic_inc_return(&autogroup_seq_nr);
87794 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
87795 ag->tg = tg;
87796 #ifdef CONFIG_RT_GROUP_SCHED
87797 /*
87798 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
87799 index a63f4dc..349bbb0 100644
87800 --- a/kernel/sched/completion.c
87801 +++ b/kernel/sched/completion.c
87802 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
87803 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87804 * or number of jiffies left till timeout) if completed.
87805 */
87806 -long __sched
87807 +long __sched __intentional_overflow(-1)
87808 wait_for_completion_interruptible_timeout(struct completion *x,
87809 unsigned long timeout)
87810 {
87811 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
87812 *
87813 * Return: -ERESTARTSYS if interrupted, 0 if completed.
87814 */
87815 -int __sched wait_for_completion_killable(struct completion *x)
87816 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
87817 {
87818 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
87819 if (t == -ERESTARTSYS)
87820 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
87821 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87822 * or number of jiffies left till timeout) if completed.
87823 */
87824 -long __sched
87825 +long __sched __intentional_overflow(-1)
87826 wait_for_completion_killable_timeout(struct completion *x,
87827 unsigned long timeout)
87828 {
87829 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
87830 index a88f4a4..9d57ac9 100644
87831 --- a/kernel/sched/core.c
87832 +++ b/kernel/sched/core.c
87833 @@ -2871,6 +2871,8 @@ int can_nice(const struct task_struct *p, const int nice)
87834 /* convert nice value [19,-20] to rlimit style value [1,40] */
87835 int nice_rlim = 20 - nice;
87836
87837 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
87838 +
87839 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
87840 capable(CAP_SYS_NICE));
87841 }
87842 @@ -2904,7 +2906,8 @@ SYSCALL_DEFINE1(nice, int, increment)
87843 if (nice > 19)
87844 nice = 19;
87845
87846 - if (increment < 0 && !can_nice(current, nice))
87847 + if (increment < 0 && (!can_nice(current, nice) ||
87848 + gr_handle_chroot_nice()))
87849 return -EPERM;
87850
87851 retval = security_task_setnice(current, nice);
87852 @@ -3066,6 +3069,7 @@ recheck:
87853 unsigned long rlim_rtprio =
87854 task_rlimit(p, RLIMIT_RTPRIO);
87855
87856 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
87857 /* can't set/change the rt policy */
87858 if (policy != p->policy && !rlim_rtprio)
87859 return -EPERM;
87860 @@ -4232,7 +4236,7 @@ static void migrate_tasks(unsigned int dead_cpu)
87861
87862 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
87863
87864 -static struct ctl_table sd_ctl_dir[] = {
87865 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
87866 {
87867 .procname = "sched_domain",
87868 .mode = 0555,
87869 @@ -4249,17 +4253,17 @@ static struct ctl_table sd_ctl_root[] = {
87870 {}
87871 };
87872
87873 -static struct ctl_table *sd_alloc_ctl_entry(int n)
87874 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
87875 {
87876 - struct ctl_table *entry =
87877 + ctl_table_no_const *entry =
87878 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
87879
87880 return entry;
87881 }
87882
87883 -static void sd_free_ctl_entry(struct ctl_table **tablep)
87884 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
87885 {
87886 - struct ctl_table *entry;
87887 + ctl_table_no_const *entry;
87888
87889 /*
87890 * In the intermediate directories, both the child directory and
87891 @@ -4267,22 +4271,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
87892 * will always be set. In the lowest directory the names are
87893 * static strings and all have proc handlers.
87894 */
87895 - for (entry = *tablep; entry->mode; entry++) {
87896 - if (entry->child)
87897 - sd_free_ctl_entry(&entry->child);
87898 + for (entry = tablep; entry->mode; entry++) {
87899 + if (entry->child) {
87900 + sd_free_ctl_entry(entry->child);
87901 + pax_open_kernel();
87902 + entry->child = NULL;
87903 + pax_close_kernel();
87904 + }
87905 if (entry->proc_handler == NULL)
87906 kfree(entry->procname);
87907 }
87908
87909 - kfree(*tablep);
87910 - *tablep = NULL;
87911 + kfree(tablep);
87912 }
87913
87914 static int min_load_idx = 0;
87915 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
87916
87917 static void
87918 -set_table_entry(struct ctl_table *entry,
87919 +set_table_entry(ctl_table_no_const *entry,
87920 const char *procname, void *data, int maxlen,
87921 umode_t mode, proc_handler *proc_handler,
87922 bool load_idx)
87923 @@ -4302,7 +4309,7 @@ set_table_entry(struct ctl_table *entry,
87924 static struct ctl_table *
87925 sd_alloc_ctl_domain_table(struct sched_domain *sd)
87926 {
87927 - struct ctl_table *table = sd_alloc_ctl_entry(13);
87928 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
87929
87930 if (table == NULL)
87931 return NULL;
87932 @@ -4337,9 +4344,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
87933 return table;
87934 }
87935
87936 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
87937 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
87938 {
87939 - struct ctl_table *entry, *table;
87940 + ctl_table_no_const *entry, *table;
87941 struct sched_domain *sd;
87942 int domain_num = 0, i;
87943 char buf[32];
87944 @@ -4366,11 +4373,13 @@ static struct ctl_table_header *sd_sysctl_header;
87945 static void register_sched_domain_sysctl(void)
87946 {
87947 int i, cpu_num = num_possible_cpus();
87948 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
87949 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
87950 char buf[32];
87951
87952 WARN_ON(sd_ctl_dir[0].child);
87953 + pax_open_kernel();
87954 sd_ctl_dir[0].child = entry;
87955 + pax_close_kernel();
87956
87957 if (entry == NULL)
87958 return;
87959 @@ -4393,8 +4402,12 @@ static void unregister_sched_domain_sysctl(void)
87960 if (sd_sysctl_header)
87961 unregister_sysctl_table(sd_sysctl_header);
87962 sd_sysctl_header = NULL;
87963 - if (sd_ctl_dir[0].child)
87964 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
87965 + if (sd_ctl_dir[0].child) {
87966 + sd_free_ctl_entry(sd_ctl_dir[0].child);
87967 + pax_open_kernel();
87968 + sd_ctl_dir[0].child = NULL;
87969 + pax_close_kernel();
87970 + }
87971 }
87972 #else
87973 static void register_sched_domain_sysctl(void)
87974 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
87975 index e64b079..a46bd34 100644
87976 --- a/kernel/sched/fair.c
87977 +++ b/kernel/sched/fair.c
87978 @@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
87979
87980 static void reset_ptenuma_scan(struct task_struct *p)
87981 {
87982 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
87983 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
87984 p->mm->numa_scan_offset = 0;
87985 }
87986
87987 @@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
87988 * run_rebalance_domains is triggered when needed from the scheduler tick.
87989 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
87990 */
87991 -static void run_rebalance_domains(struct softirq_action *h)
87992 +static __latent_entropy void run_rebalance_domains(void)
87993 {
87994 int this_cpu = smp_processor_id();
87995 struct rq *this_rq = cpu_rq(this_cpu);
87996 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
87997 index 88c85b2..a1dec86 100644
87998 --- a/kernel/sched/sched.h
87999 +++ b/kernel/sched/sched.h
88000 @@ -1035,7 +1035,7 @@ struct sched_class {
88001 #ifdef CONFIG_FAIR_GROUP_SCHED
88002 void (*task_move_group) (struct task_struct *p, int on_rq);
88003 #endif
88004 -};
88005 +} __do_const;
88006
88007 #define sched_class_highest (&stop_sched_class)
88008 #define for_each_class(class) \
88009 diff --git a/kernel/signal.c b/kernel/signal.c
88010 index 940b30e..7fd6041 100644
88011 --- a/kernel/signal.c
88012 +++ b/kernel/signal.c
88013 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
88014
88015 int print_fatal_signals __read_mostly;
88016
88017 -static void __user *sig_handler(struct task_struct *t, int sig)
88018 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
88019 {
88020 return t->sighand->action[sig - 1].sa.sa_handler;
88021 }
88022
88023 -static int sig_handler_ignored(void __user *handler, int sig)
88024 +static int sig_handler_ignored(__sighandler_t handler, int sig)
88025 {
88026 /* Is it explicitly or implicitly ignored? */
88027 return handler == SIG_IGN ||
88028 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
88029
88030 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
88031 {
88032 - void __user *handler;
88033 + __sighandler_t handler;
88034
88035 handler = sig_handler(t, sig);
88036
88037 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
88038 atomic_inc(&user->sigpending);
88039 rcu_read_unlock();
88040
88041 + if (!override_rlimit)
88042 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
88043 +
88044 if (override_rlimit ||
88045 atomic_read(&user->sigpending) <=
88046 task_rlimit(t, RLIMIT_SIGPENDING)) {
88047 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
88048
88049 int unhandled_signal(struct task_struct *tsk, int sig)
88050 {
88051 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
88052 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
88053 if (is_global_init(tsk))
88054 return 1;
88055 if (handler != SIG_IGN && handler != SIG_DFL)
88056 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
88057 }
88058 }
88059
88060 + /* allow glibc communication via tgkill to other threads in our
88061 + thread group */
88062 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
88063 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
88064 + && gr_handle_signal(t, sig))
88065 + return -EPERM;
88066 +
88067 return security_task_kill(t, info, sig, 0);
88068 }
88069
88070 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
88071 return send_signal(sig, info, p, 1);
88072 }
88073
88074 -static int
88075 +int
88076 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88077 {
88078 return send_signal(sig, info, t, 0);
88079 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88080 unsigned long int flags;
88081 int ret, blocked, ignored;
88082 struct k_sigaction *action;
88083 + int is_unhandled = 0;
88084
88085 spin_lock_irqsave(&t->sighand->siglock, flags);
88086 action = &t->sighand->action[sig-1];
88087 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88088 }
88089 if (action->sa.sa_handler == SIG_DFL)
88090 t->signal->flags &= ~SIGNAL_UNKILLABLE;
88091 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
88092 + is_unhandled = 1;
88093 ret = specific_send_sig_info(sig, info, t);
88094 spin_unlock_irqrestore(&t->sighand->siglock, flags);
88095
88096 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
88097 + normal operation */
88098 + if (is_unhandled) {
88099 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
88100 + gr_handle_crash(t, sig);
88101 + }
88102 +
88103 return ret;
88104 }
88105
88106 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
88107 ret = check_kill_permission(sig, info, p);
88108 rcu_read_unlock();
88109
88110 - if (!ret && sig)
88111 + if (!ret && sig) {
88112 ret = do_send_sig_info(sig, info, p, true);
88113 + if (!ret)
88114 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
88115 + }
88116
88117 return ret;
88118 }
88119 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
88120 int error = -ESRCH;
88121
88122 rcu_read_lock();
88123 - p = find_task_by_vpid(pid);
88124 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
88125 + /* allow glibc communication via tgkill to other threads in our
88126 + thread group */
88127 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
88128 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
88129 + p = find_task_by_vpid_unrestricted(pid);
88130 + else
88131 +#endif
88132 + p = find_task_by_vpid(pid);
88133 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
88134 error = check_kill_permission(sig, info, p);
88135 /*
88136 @@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
88137 }
88138 seg = get_fs();
88139 set_fs(KERNEL_DS);
88140 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
88141 - (stack_t __force __user *) &uoss,
88142 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
88143 + (stack_t __force_user *) &uoss,
88144 compat_user_stack_pointer());
88145 set_fs(seg);
88146 if (ret >= 0 && uoss_ptr) {
88147 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
88148 index eb89e18..a4e6792 100644
88149 --- a/kernel/smpboot.c
88150 +++ b/kernel/smpboot.c
88151 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
88152 }
88153 smpboot_unpark_thread(plug_thread, cpu);
88154 }
88155 - list_add(&plug_thread->list, &hotplug_threads);
88156 + pax_list_add(&plug_thread->list, &hotplug_threads);
88157 out:
88158 mutex_unlock(&smpboot_threads_lock);
88159 return ret;
88160 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
88161 {
88162 get_online_cpus();
88163 mutex_lock(&smpboot_threads_lock);
88164 - list_del(&plug_thread->list);
88165 + pax_list_del(&plug_thread->list);
88166 smpboot_destroy_threads(plug_thread);
88167 mutex_unlock(&smpboot_threads_lock);
88168 put_online_cpus();
88169 diff --git a/kernel/softirq.c b/kernel/softirq.c
88170 index 11025cc..bc0e4dc 100644
88171 --- a/kernel/softirq.c
88172 +++ b/kernel/softirq.c
88173 @@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
88174 EXPORT_SYMBOL(irq_stat);
88175 #endif
88176
88177 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
88178 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
88179
88180 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
88181
88182 -char *softirq_to_name[NR_SOFTIRQS] = {
88183 +const char * const softirq_to_name[NR_SOFTIRQS] = {
88184 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
88185 "TASKLET", "SCHED", "HRTIMER", "RCU"
88186 };
88187 @@ -250,7 +250,7 @@ restart:
88188 kstat_incr_softirqs_this_cpu(vec_nr);
88189
88190 trace_softirq_entry(vec_nr);
88191 - h->action(h);
88192 + h->action();
88193 trace_softirq_exit(vec_nr);
88194 if (unlikely(prev_count != preempt_count())) {
88195 printk(KERN_ERR "huh, entered softirq %u %s %p"
88196 @@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
88197 or_softirq_pending(1UL << nr);
88198 }
88199
88200 -void open_softirq(int nr, void (*action)(struct softirq_action *))
88201 +void __init open_softirq(int nr, void (*action)(void))
88202 {
88203 softirq_vec[nr].action = action;
88204 }
88205 @@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
88206
88207 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
88208
88209 -static void tasklet_action(struct softirq_action *a)
88210 +static __latent_entropy void tasklet_action(void)
88211 {
88212 struct tasklet_struct *list;
88213
88214 @@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
88215 }
88216 }
88217
88218 -static void tasklet_hi_action(struct softirq_action *a)
88219 +static __latent_entropy void tasklet_hi_action(void)
88220 {
88221 struct tasklet_struct *list;
88222
88223 @@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
88224 .notifier_call = cpu_callback
88225 };
88226
88227 -static struct smp_hotplug_thread softirq_threads = {
88228 +static struct smp_hotplug_thread softirq_threads __read_only = {
88229 .store = &ksoftirqd,
88230 .thread_should_run = ksoftirqd_should_run,
88231 .thread_fn = run_ksoftirqd,
88232 diff --git a/kernel/sys.c b/kernel/sys.c
88233 index c723113..46bf922 100644
88234 --- a/kernel/sys.c
88235 +++ b/kernel/sys.c
88236 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
88237 error = -EACCES;
88238 goto out;
88239 }
88240 +
88241 + if (gr_handle_chroot_setpriority(p, niceval)) {
88242 + error = -EACCES;
88243 + goto out;
88244 + }
88245 +
88246 no_nice = security_task_setnice(p, niceval);
88247 if (no_nice) {
88248 error = no_nice;
88249 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
88250 goto error;
88251 }
88252
88253 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
88254 + goto error;
88255 +
88256 if (rgid != (gid_t) -1 ||
88257 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
88258 new->sgid = new->egid;
88259 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
88260 old = current_cred();
88261
88262 retval = -EPERM;
88263 +
88264 + if (gr_check_group_change(kgid, kgid, kgid))
88265 + goto error;
88266 +
88267 if (ns_capable(old->user_ns, CAP_SETGID))
88268 new->gid = new->egid = new->sgid = new->fsgid = kgid;
88269 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
88270 @@ -403,7 +416,7 @@ error:
88271 /*
88272 * change the user struct in a credentials set to match the new UID
88273 */
88274 -static int set_user(struct cred *new)
88275 +int set_user(struct cred *new)
88276 {
88277 struct user_struct *new_user;
88278
88279 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
88280 goto error;
88281 }
88282
88283 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
88284 + goto error;
88285 +
88286 if (!uid_eq(new->uid, old->uid)) {
88287 retval = set_user(new);
88288 if (retval < 0)
88289 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
88290 old = current_cred();
88291
88292 retval = -EPERM;
88293 +
88294 + if (gr_check_crash_uid(kuid))
88295 + goto error;
88296 + if (gr_check_user_change(kuid, kuid, kuid))
88297 + goto error;
88298 +
88299 if (ns_capable(old->user_ns, CAP_SETUID)) {
88300 new->suid = new->uid = kuid;
88301 if (!uid_eq(kuid, old->uid)) {
88302 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
88303 goto error;
88304 }
88305
88306 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
88307 + goto error;
88308 +
88309 if (ruid != (uid_t) -1) {
88310 new->uid = kruid;
88311 if (!uid_eq(kruid, old->uid)) {
88312 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
88313 goto error;
88314 }
88315
88316 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
88317 + goto error;
88318 +
88319 if (rgid != (gid_t) -1)
88320 new->gid = krgid;
88321 if (egid != (gid_t) -1)
88322 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
88323 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
88324 ns_capable(old->user_ns, CAP_SETUID)) {
88325 if (!uid_eq(kuid, old->fsuid)) {
88326 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
88327 + goto error;
88328 +
88329 new->fsuid = kuid;
88330 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
88331 goto change_okay;
88332 }
88333 }
88334
88335 +error:
88336 abort_creds(new);
88337 return old_fsuid;
88338
88339 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
88340 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
88341 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
88342 ns_capable(old->user_ns, CAP_SETGID)) {
88343 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
88344 + goto error;
88345 +
88346 if (!gid_eq(kgid, old->fsgid)) {
88347 new->fsgid = kgid;
88348 goto change_okay;
88349 }
88350 }
88351
88352 +error:
88353 abort_creds(new);
88354 return old_fsgid;
88355
88356 @@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
88357 return -EFAULT;
88358
88359 down_read(&uts_sem);
88360 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
88361 + error = __copy_to_user(name->sysname, &utsname()->sysname,
88362 __OLD_UTS_LEN);
88363 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
88364 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
88365 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
88366 __OLD_UTS_LEN);
88367 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
88368 - error |= __copy_to_user(&name->release, &utsname()->release,
88369 + error |= __copy_to_user(name->release, &utsname()->release,
88370 __OLD_UTS_LEN);
88371 error |= __put_user(0, name->release + __OLD_UTS_LEN);
88372 - error |= __copy_to_user(&name->version, &utsname()->version,
88373 + error |= __copy_to_user(name->version, &utsname()->version,
88374 __OLD_UTS_LEN);
88375 error |= __put_user(0, name->version + __OLD_UTS_LEN);
88376 - error |= __copy_to_user(&name->machine, &utsname()->machine,
88377 + error |= __copy_to_user(name->machine, &utsname()->machine,
88378 __OLD_UTS_LEN);
88379 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
88380 up_read(&uts_sem);
88381 @@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
88382 */
88383 new_rlim->rlim_cur = 1;
88384 }
88385 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
88386 + is changed to a lower value. Since tasks can be created by the same
88387 + user in between this limit change and an execve by this task, force
88388 + a recheck only for this task by setting PF_NPROC_EXCEEDED
88389 + */
88390 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
88391 + tsk->flags |= PF_NPROC_EXCEEDED;
88392 }
88393 if (!retval) {
88394 if (old_rlim)
88395 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
88396 index 34a6047..5665aa7 100644
88397 --- a/kernel/sysctl.c
88398 +++ b/kernel/sysctl.c
88399 @@ -93,7 +93,6 @@
88400
88401
88402 #if defined(CONFIG_SYSCTL)
88403 -
88404 /* External variables not in a header file. */
88405 extern int sysctl_overcommit_memory;
88406 extern int sysctl_overcommit_ratio;
88407 @@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
88408
88409 /* Constants used for minimum and maximum */
88410 #ifdef CONFIG_LOCKUP_DETECTOR
88411 -static int sixty = 60;
88412 +static int sixty __read_only = 60;
88413 #endif
88414
88415 -static int zero;
88416 -static int __maybe_unused one = 1;
88417 -static int __maybe_unused two = 2;
88418 -static int __maybe_unused three = 3;
88419 -static unsigned long one_ul = 1;
88420 -static int one_hundred = 100;
88421 +static int neg_one __read_only = -1;
88422 +static int zero __read_only = 0;
88423 +static int __maybe_unused one __read_only = 1;
88424 +static int __maybe_unused two __read_only = 2;
88425 +static int __maybe_unused three __read_only = 3;
88426 +static unsigned long one_ul __read_only = 1;
88427 +static int one_hundred __read_only = 100;
88428 #ifdef CONFIG_PRINTK
88429 -static int ten_thousand = 10000;
88430 +static int ten_thousand __read_only = 10000;
88431 #endif
88432
88433 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
88434 @@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
88435 void __user *buffer, size_t *lenp, loff_t *ppos);
88436 #endif
88437
88438 -#ifdef CONFIG_PRINTK
88439 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88440 void __user *buffer, size_t *lenp, loff_t *ppos);
88441 -#endif
88442
88443 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
88444 void __user *buffer, size_t *lenp, loff_t *ppos);
88445 @@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
88446
88447 #endif
88448
88449 +extern struct ctl_table grsecurity_table[];
88450 +
88451 static struct ctl_table kern_table[];
88452 static struct ctl_table vm_table[];
88453 static struct ctl_table fs_table[];
88454 @@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
88455 int sysctl_legacy_va_layout;
88456 #endif
88457
88458 +#ifdef CONFIG_PAX_SOFTMODE
88459 +static ctl_table pax_table[] = {
88460 + {
88461 + .procname = "softmode",
88462 + .data = &pax_softmode,
88463 + .maxlen = sizeof(unsigned int),
88464 + .mode = 0600,
88465 + .proc_handler = &proc_dointvec,
88466 + },
88467 +
88468 + { }
88469 +};
88470 +#endif
88471 +
88472 /* The default sysctl tables: */
88473
88474 static struct ctl_table sysctl_base_table[] = {
88475 @@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
88476 #endif
88477
88478 static struct ctl_table kern_table[] = {
88479 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
88480 + {
88481 + .procname = "grsecurity",
88482 + .mode = 0500,
88483 + .child = grsecurity_table,
88484 + },
88485 +#endif
88486 +
88487 +#ifdef CONFIG_PAX_SOFTMODE
88488 + {
88489 + .procname = "pax",
88490 + .mode = 0500,
88491 + .child = pax_table,
88492 + },
88493 +#endif
88494 +
88495 {
88496 .procname = "sched_child_runs_first",
88497 .data = &sysctl_sched_child_runs_first,
88498 @@ -620,7 +650,7 @@ static struct ctl_table kern_table[] = {
88499 .data = &modprobe_path,
88500 .maxlen = KMOD_PATH_LEN,
88501 .mode = 0644,
88502 - .proc_handler = proc_dostring,
88503 + .proc_handler = proc_dostring_modpriv,
88504 },
88505 {
88506 .procname = "modules_disabled",
88507 @@ -787,16 +817,20 @@ static struct ctl_table kern_table[] = {
88508 .extra1 = &zero,
88509 .extra2 = &one,
88510 },
88511 +#endif
88512 {
88513 .procname = "kptr_restrict",
88514 .data = &kptr_restrict,
88515 .maxlen = sizeof(int),
88516 .mode = 0644,
88517 .proc_handler = proc_dointvec_minmax_sysadmin,
88518 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88519 + .extra1 = &two,
88520 +#else
88521 .extra1 = &zero,
88522 +#endif
88523 .extra2 = &two,
88524 },
88525 -#endif
88526 {
88527 .procname = "ngroups_max",
88528 .data = &ngroups_max,
88529 @@ -1039,10 +1073,17 @@ static struct ctl_table kern_table[] = {
88530 */
88531 {
88532 .procname = "perf_event_paranoid",
88533 - .data = &sysctl_perf_event_paranoid,
88534 - .maxlen = sizeof(sysctl_perf_event_paranoid),
88535 + .data = &sysctl_perf_event_legitimately_concerned,
88536 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
88537 .mode = 0644,
88538 - .proc_handler = proc_dointvec,
88539 + /* go ahead, be a hero */
88540 + .proc_handler = proc_dointvec_minmax_sysadmin,
88541 + .extra1 = &neg_one,
88542 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88543 + .extra2 = &three,
88544 +#else
88545 + .extra2 = &two,
88546 +#endif
88547 },
88548 {
88549 .procname = "perf_event_mlock_kb",
88550 @@ -1306,6 +1347,13 @@ static struct ctl_table vm_table[] = {
88551 .proc_handler = proc_dointvec_minmax,
88552 .extra1 = &zero,
88553 },
88554 + {
88555 + .procname = "heap_stack_gap",
88556 + .data = &sysctl_heap_stack_gap,
88557 + .maxlen = sizeof(sysctl_heap_stack_gap),
88558 + .mode = 0644,
88559 + .proc_handler = proc_doulongvec_minmax,
88560 + },
88561 #else
88562 {
88563 .procname = "nr_trim_pages",
88564 @@ -1770,6 +1818,16 @@ int proc_dostring(struct ctl_table *table, int write,
88565 buffer, lenp, ppos);
88566 }
88567
88568 +int proc_dostring_modpriv(struct ctl_table *table, int write,
88569 + void __user *buffer, size_t *lenp, loff_t *ppos)
88570 +{
88571 + if (write && !capable(CAP_SYS_MODULE))
88572 + return -EPERM;
88573 +
88574 + return _proc_do_string(table->data, table->maxlen, write,
88575 + buffer, lenp, ppos);
88576 +}
88577 +
88578 static size_t proc_skip_spaces(char **buf)
88579 {
88580 size_t ret;
88581 @@ -1875,6 +1933,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
88582 len = strlen(tmp);
88583 if (len > *size)
88584 len = *size;
88585 + if (len > sizeof(tmp))
88586 + len = sizeof(tmp);
88587 if (copy_to_user(*buf, tmp, len))
88588 return -EFAULT;
88589 *size -= len;
88590 @@ -2039,7 +2099,7 @@ int proc_dointvec(struct ctl_table *table, int write,
88591 static int proc_taint(struct ctl_table *table, int write,
88592 void __user *buffer, size_t *lenp, loff_t *ppos)
88593 {
88594 - struct ctl_table t;
88595 + ctl_table_no_const t;
88596 unsigned long tmptaint = get_taint();
88597 int err;
88598
88599 @@ -2067,7 +2127,6 @@ static int proc_taint(struct ctl_table *table, int write,
88600 return err;
88601 }
88602
88603 -#ifdef CONFIG_PRINTK
88604 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88605 void __user *buffer, size_t *lenp, loff_t *ppos)
88606 {
88607 @@ -2076,7 +2135,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88608
88609 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
88610 }
88611 -#endif
88612
88613 struct do_proc_dointvec_minmax_conv_param {
88614 int *min;
88615 @@ -2623,6 +2681,12 @@ int proc_dostring(struct ctl_table *table, int write,
88616 return -ENOSYS;
88617 }
88618
88619 +int proc_dostring_modpriv(struct ctl_table *table, int write,
88620 + void __user *buffer, size_t *lenp, loff_t *ppos)
88621 +{
88622 + return -ENOSYS;
88623 +}
88624 +
88625 int proc_dointvec(struct ctl_table *table, int write,
88626 void __user *buffer, size_t *lenp, loff_t *ppos)
88627 {
88628 @@ -2679,5 +2743,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
88629 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
88630 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
88631 EXPORT_SYMBOL(proc_dostring);
88632 +EXPORT_SYMBOL(proc_dostring_modpriv);
88633 EXPORT_SYMBOL(proc_doulongvec_minmax);
88634 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
88635 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
88636 index 13d2f7c..c93d0b0 100644
88637 --- a/kernel/taskstats.c
88638 +++ b/kernel/taskstats.c
88639 @@ -28,9 +28,12 @@
88640 #include <linux/fs.h>
88641 #include <linux/file.h>
88642 #include <linux/pid_namespace.h>
88643 +#include <linux/grsecurity.h>
88644 #include <net/genetlink.h>
88645 #include <linux/atomic.h>
88646
88647 +extern int gr_is_taskstats_denied(int pid);
88648 +
88649 /*
88650 * Maximum length of a cpumask that can be specified in
88651 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
88652 @@ -576,6 +579,9 @@ err:
88653
88654 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
88655 {
88656 + if (gr_is_taskstats_denied(current->pid))
88657 + return -EACCES;
88658 +
88659 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
88660 return cmd_attr_register_cpumask(info);
88661 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
88662 diff --git a/kernel/time.c b/kernel/time.c
88663 index 7c7964c..2a0d412 100644
88664 --- a/kernel/time.c
88665 +++ b/kernel/time.c
88666 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
88667 return error;
88668
88669 if (tz) {
88670 + /* we log in do_settimeofday called below, so don't log twice
88671 + */
88672 + if (!tv)
88673 + gr_log_timechange();
88674 +
88675 sys_tz = *tz;
88676 update_vsyscall_tz();
88677 if (firsttime) {
88678 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
88679 index 88c9c65..7497ebc 100644
88680 --- a/kernel/time/alarmtimer.c
88681 +++ b/kernel/time/alarmtimer.c
88682 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
88683 struct platform_device *pdev;
88684 int error = 0;
88685 int i;
88686 - struct k_clock alarm_clock = {
88687 + static struct k_clock alarm_clock = {
88688 .clock_getres = alarm_clock_getres,
88689 .clock_get = alarm_clock_get,
88690 .timer_create = alarm_timer_create,
88691 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
88692 index 87b4f00..b7f77a7 100644
88693 --- a/kernel/time/timekeeping.c
88694 +++ b/kernel/time/timekeeping.c
88695 @@ -15,6 +15,7 @@
88696 #include <linux/init.h>
88697 #include <linux/mm.h>
88698 #include <linux/sched.h>
88699 +#include <linux/grsecurity.h>
88700 #include <linux/syscore_ops.h>
88701 #include <linux/clocksource.h>
88702 #include <linux/jiffies.h>
88703 @@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
88704 if (!timespec_valid_strict(tv))
88705 return -EINVAL;
88706
88707 + gr_log_timechange();
88708 +
88709 raw_spin_lock_irqsave(&timekeeper_lock, flags);
88710 write_seqcount_begin(&timekeeper_seq);
88711
88712 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
88713 index 61ed862..3b52c65 100644
88714 --- a/kernel/time/timer_list.c
88715 +++ b/kernel/time/timer_list.c
88716 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
88717
88718 static void print_name_offset(struct seq_file *m, void *sym)
88719 {
88720 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88721 + SEQ_printf(m, "<%p>", NULL);
88722 +#else
88723 char symname[KSYM_NAME_LEN];
88724
88725 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
88726 SEQ_printf(m, "<%pK>", sym);
88727 else
88728 SEQ_printf(m, "%s", symname);
88729 +#endif
88730 }
88731
88732 static void
88733 @@ -119,7 +123,11 @@ next_one:
88734 static void
88735 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
88736 {
88737 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88738 + SEQ_printf(m, " .base: %p\n", NULL);
88739 +#else
88740 SEQ_printf(m, " .base: %pK\n", base);
88741 +#endif
88742 SEQ_printf(m, " .index: %d\n",
88743 base->index);
88744 SEQ_printf(m, " .resolution: %Lu nsecs\n",
88745 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
88746 {
88747 struct proc_dir_entry *pe;
88748
88749 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88750 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
88751 +#else
88752 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
88753 +#endif
88754 if (!pe)
88755 return -ENOMEM;
88756 return 0;
88757 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
88758 index 1fb08f2..ca4bb1e 100644
88759 --- a/kernel/time/timer_stats.c
88760 +++ b/kernel/time/timer_stats.c
88761 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
88762 static unsigned long nr_entries;
88763 static struct entry entries[MAX_ENTRIES];
88764
88765 -static atomic_t overflow_count;
88766 +static atomic_unchecked_t overflow_count;
88767
88768 /*
88769 * The entries are in a hash-table, for fast lookup:
88770 @@ -140,7 +140,7 @@ static void reset_entries(void)
88771 nr_entries = 0;
88772 memset(entries, 0, sizeof(entries));
88773 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
88774 - atomic_set(&overflow_count, 0);
88775 + atomic_set_unchecked(&overflow_count, 0);
88776 }
88777
88778 static struct entry *alloc_entry(void)
88779 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88780 if (likely(entry))
88781 entry->count++;
88782 else
88783 - atomic_inc(&overflow_count);
88784 + atomic_inc_unchecked(&overflow_count);
88785
88786 out_unlock:
88787 raw_spin_unlock_irqrestore(lock, flags);
88788 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88789
88790 static void print_name_offset(struct seq_file *m, unsigned long addr)
88791 {
88792 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88793 + seq_printf(m, "<%p>", NULL);
88794 +#else
88795 char symname[KSYM_NAME_LEN];
88796
88797 if (lookup_symbol_name(addr, symname) < 0)
88798 - seq_printf(m, "<%p>", (void *)addr);
88799 + seq_printf(m, "<%pK>", (void *)addr);
88800 else
88801 seq_printf(m, "%s", symname);
88802 +#endif
88803 }
88804
88805 static int tstats_show(struct seq_file *m, void *v)
88806 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
88807
88808 seq_puts(m, "Timer Stats Version: v0.3\n");
88809 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
88810 - if (atomic_read(&overflow_count))
88811 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
88812 + if (atomic_read_unchecked(&overflow_count))
88813 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
88814 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
88815
88816 for (i = 0; i < nr_entries; i++) {
88817 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
88818 {
88819 struct proc_dir_entry *pe;
88820
88821 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88822 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
88823 +#else
88824 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
88825 +#endif
88826 if (!pe)
88827 return -ENOMEM;
88828 return 0;
88829 diff --git a/kernel/timer.c b/kernel/timer.c
88830 index accfd24..e00f0c0 100644
88831 --- a/kernel/timer.c
88832 +++ b/kernel/timer.c
88833 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
88834 /*
88835 * This function runs timers and the timer-tq in bottom half context.
88836 */
88837 -static void run_timer_softirq(struct softirq_action *h)
88838 +static __latent_entropy void run_timer_softirq(void)
88839 {
88840 struct tvec_base *base = __this_cpu_read(tvec_bases);
88841
88842 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
88843 *
88844 * In all cases the return value is guaranteed to be non-negative.
88845 */
88846 -signed long __sched schedule_timeout(signed long timeout)
88847 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
88848 {
88849 struct timer_list timer;
88850 unsigned long expire;
88851 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
88852 index f785aef..59f1b18 100644
88853 --- a/kernel/trace/blktrace.c
88854 +++ b/kernel/trace/blktrace.c
88855 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
88856 struct blk_trace *bt = filp->private_data;
88857 char buf[16];
88858
88859 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
88860 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
88861
88862 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
88863 }
88864 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
88865 return 1;
88866
88867 bt = buf->chan->private_data;
88868 - atomic_inc(&bt->dropped);
88869 + atomic_inc_unchecked(&bt->dropped);
88870 return 0;
88871 }
88872
88873 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
88874
88875 bt->dir = dir;
88876 bt->dev = dev;
88877 - atomic_set(&bt->dropped, 0);
88878 + atomic_set_unchecked(&bt->dropped, 0);
88879 INIT_LIST_HEAD(&bt->running_list);
88880
88881 ret = -EIO;
88882 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
88883 index 72a0f81..0bbfd090 100644
88884 --- a/kernel/trace/ftrace.c
88885 +++ b/kernel/trace/ftrace.c
88886 @@ -1944,12 +1944,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
88887 if (unlikely(ftrace_disabled))
88888 return 0;
88889
88890 + ret = ftrace_arch_code_modify_prepare();
88891 + FTRACE_WARN_ON(ret);
88892 + if (ret)
88893 + return 0;
88894 +
88895 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
88896 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
88897 if (ret) {
88898 ftrace_bug(ret, ip);
88899 - return 0;
88900 }
88901 - return 1;
88902 + return ret ? 0 : 1;
88903 }
88904
88905 /*
88906 @@ -4119,8 +4124,10 @@ static int ftrace_process_locs(struct module *mod,
88907 if (!count)
88908 return 0;
88909
88910 + pax_open_kernel();
88911 sort(start, count, sizeof(*start),
88912 ftrace_cmp_ips, ftrace_swap_ips);
88913 + pax_close_kernel();
88914
88915 start_pg = ftrace_allocate_pages(count);
88916 if (!start_pg)
88917 @@ -4851,8 +4858,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
88918 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
88919
88920 static int ftrace_graph_active;
88921 -static struct notifier_block ftrace_suspend_notifier;
88922 -
88923 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
88924 {
88925 return 0;
88926 @@ -5003,6 +5008,10 @@ static struct ftrace_ops fgraph_ops __read_mostly = {
88927 FTRACE_OPS_FL_RECURSION_SAFE,
88928 };
88929
88930 +static struct notifier_block ftrace_suspend_notifier = {
88931 + .notifier_call = ftrace_suspend_notifier_call
88932 +};
88933 +
88934 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88935 trace_func_graph_ent_t entryfunc)
88936 {
88937 @@ -5016,7 +5025,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88938 goto out;
88939 }
88940
88941 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
88942 register_pm_notifier(&ftrace_suspend_notifier);
88943
88944 ftrace_graph_active++;
88945 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
88946 index cc2f66f..05edd54 100644
88947 --- a/kernel/trace/ring_buffer.c
88948 +++ b/kernel/trace/ring_buffer.c
88949 @@ -352,9 +352,9 @@ struct buffer_data_page {
88950 */
88951 struct buffer_page {
88952 struct list_head list; /* list of buffer pages */
88953 - local_t write; /* index for next write */
88954 + local_unchecked_t write; /* index for next write */
88955 unsigned read; /* index for next read */
88956 - local_t entries; /* entries on this page */
88957 + local_unchecked_t entries; /* entries on this page */
88958 unsigned long real_end; /* real end of data */
88959 struct buffer_data_page *page; /* Actual data page */
88960 };
88961 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
88962 unsigned long last_overrun;
88963 local_t entries_bytes;
88964 local_t entries;
88965 - local_t overrun;
88966 - local_t commit_overrun;
88967 + local_unchecked_t overrun;
88968 + local_unchecked_t commit_overrun;
88969 local_t dropped_events;
88970 local_t committing;
88971 local_t commits;
88972 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88973 *
88974 * We add a counter to the write field to denote this.
88975 */
88976 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
88977 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
88978 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
88979 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
88980
88981 /*
88982 * Just make sure we have seen our old_write and synchronize
88983 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88984 * cmpxchg to only update if an interrupt did not already
88985 * do it for us. If the cmpxchg fails, we don't care.
88986 */
88987 - (void)local_cmpxchg(&next_page->write, old_write, val);
88988 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
88989 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
88990 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
88991
88992 /*
88993 * No need to worry about races with clearing out the commit.
88994 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
88995
88996 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
88997 {
88998 - return local_read(&bpage->entries) & RB_WRITE_MASK;
88999 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
89000 }
89001
89002 static inline unsigned long rb_page_write(struct buffer_page *bpage)
89003 {
89004 - return local_read(&bpage->write) & RB_WRITE_MASK;
89005 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
89006 }
89007
89008 static int
89009 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
89010 * bytes consumed in ring buffer from here.
89011 * Increment overrun to account for the lost events.
89012 */
89013 - local_add(page_entries, &cpu_buffer->overrun);
89014 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
89015 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89016 }
89017
89018 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
89019 * it is our responsibility to update
89020 * the counters.
89021 */
89022 - local_add(entries, &cpu_buffer->overrun);
89023 + local_add_unchecked(entries, &cpu_buffer->overrun);
89024 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89025
89026 /*
89027 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89028 if (tail == BUF_PAGE_SIZE)
89029 tail_page->real_end = 0;
89030
89031 - local_sub(length, &tail_page->write);
89032 + local_sub_unchecked(length, &tail_page->write);
89033 return;
89034 }
89035
89036 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89037 rb_event_set_padding(event);
89038
89039 /* Set the write back to the previous setting */
89040 - local_sub(length, &tail_page->write);
89041 + local_sub_unchecked(length, &tail_page->write);
89042 return;
89043 }
89044
89045 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89046
89047 /* Set write to end of buffer */
89048 length = (tail + length) - BUF_PAGE_SIZE;
89049 - local_sub(length, &tail_page->write);
89050 + local_sub_unchecked(length, &tail_page->write);
89051 }
89052
89053 /*
89054 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89055 * about it.
89056 */
89057 if (unlikely(next_page == commit_page)) {
89058 - local_inc(&cpu_buffer->commit_overrun);
89059 + local_inc_unchecked(&cpu_buffer->commit_overrun);
89060 goto out_reset;
89061 }
89062
89063 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89064 cpu_buffer->tail_page) &&
89065 (cpu_buffer->commit_page ==
89066 cpu_buffer->reader_page))) {
89067 - local_inc(&cpu_buffer->commit_overrun);
89068 + local_inc_unchecked(&cpu_buffer->commit_overrun);
89069 goto out_reset;
89070 }
89071 }
89072 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
89073 length += RB_LEN_TIME_EXTEND;
89074
89075 tail_page = cpu_buffer->tail_page;
89076 - write = local_add_return(length, &tail_page->write);
89077 + write = local_add_return_unchecked(length, &tail_page->write);
89078
89079 /* set write to only the index of the write */
89080 write &= RB_WRITE_MASK;
89081 @@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
89082 kmemcheck_annotate_bitfield(event, bitfield);
89083 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
89084
89085 - local_inc(&tail_page->entries);
89086 + local_inc_unchecked(&tail_page->entries);
89087
89088 /*
89089 * If this is the first commit on the page, then update
89090 @@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
89091
89092 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
89093 unsigned long write_mask =
89094 - local_read(&bpage->write) & ~RB_WRITE_MASK;
89095 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
89096 unsigned long event_length = rb_event_length(event);
89097 /*
89098 * This is on the tail page. It is possible that
89099 @@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
89100 */
89101 old_index += write_mask;
89102 new_index += write_mask;
89103 - index = local_cmpxchg(&bpage->write, old_index, new_index);
89104 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
89105 if (index == old_index) {
89106 /* update counters */
89107 local_sub(event_length, &cpu_buffer->entries_bytes);
89108 @@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
89109
89110 /* Do the likely case first */
89111 if (likely(bpage->page == (void *)addr)) {
89112 - local_dec(&bpage->entries);
89113 + local_dec_unchecked(&bpage->entries);
89114 return;
89115 }
89116
89117 @@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
89118 start = bpage;
89119 do {
89120 if (bpage->page == (void *)addr) {
89121 - local_dec(&bpage->entries);
89122 + local_dec_unchecked(&bpage->entries);
89123 return;
89124 }
89125 rb_inc_page(cpu_buffer, &bpage);
89126 @@ -3139,7 +3139,7 @@ static inline unsigned long
89127 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
89128 {
89129 return local_read(&cpu_buffer->entries) -
89130 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
89131 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
89132 }
89133
89134 /**
89135 @@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
89136 return 0;
89137
89138 cpu_buffer = buffer->buffers[cpu];
89139 - ret = local_read(&cpu_buffer->overrun);
89140 + ret = local_read_unchecked(&cpu_buffer->overrun);
89141
89142 return ret;
89143 }
89144 @@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
89145 return 0;
89146
89147 cpu_buffer = buffer->buffers[cpu];
89148 - ret = local_read(&cpu_buffer->commit_overrun);
89149 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
89150
89151 return ret;
89152 }
89153 @@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
89154 /* if you care about this being correct, lock the buffer */
89155 for_each_buffer_cpu(buffer, cpu) {
89156 cpu_buffer = buffer->buffers[cpu];
89157 - overruns += local_read(&cpu_buffer->overrun);
89158 + overruns += local_read_unchecked(&cpu_buffer->overrun);
89159 }
89160
89161 return overruns;
89162 @@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
89163 /*
89164 * Reset the reader page to size zero.
89165 */
89166 - local_set(&cpu_buffer->reader_page->write, 0);
89167 - local_set(&cpu_buffer->reader_page->entries, 0);
89168 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89169 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89170 local_set(&cpu_buffer->reader_page->page->commit, 0);
89171 cpu_buffer->reader_page->real_end = 0;
89172
89173 @@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
89174 * want to compare with the last_overrun.
89175 */
89176 smp_mb();
89177 - overwrite = local_read(&(cpu_buffer->overrun));
89178 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
89179
89180 /*
89181 * Here's the tricky part.
89182 @@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89183
89184 cpu_buffer->head_page
89185 = list_entry(cpu_buffer->pages, struct buffer_page, list);
89186 - local_set(&cpu_buffer->head_page->write, 0);
89187 - local_set(&cpu_buffer->head_page->entries, 0);
89188 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
89189 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
89190 local_set(&cpu_buffer->head_page->page->commit, 0);
89191
89192 cpu_buffer->head_page->read = 0;
89193 @@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89194
89195 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
89196 INIT_LIST_HEAD(&cpu_buffer->new_pages);
89197 - local_set(&cpu_buffer->reader_page->write, 0);
89198 - local_set(&cpu_buffer->reader_page->entries, 0);
89199 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89200 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89201 local_set(&cpu_buffer->reader_page->page->commit, 0);
89202 cpu_buffer->reader_page->read = 0;
89203
89204 local_set(&cpu_buffer->entries_bytes, 0);
89205 - local_set(&cpu_buffer->overrun, 0);
89206 - local_set(&cpu_buffer->commit_overrun, 0);
89207 + local_set_unchecked(&cpu_buffer->overrun, 0);
89208 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
89209 local_set(&cpu_buffer->dropped_events, 0);
89210 local_set(&cpu_buffer->entries, 0);
89211 local_set(&cpu_buffer->committing, 0);
89212 @@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
89213 rb_init_page(bpage);
89214 bpage = reader->page;
89215 reader->page = *data_page;
89216 - local_set(&reader->write, 0);
89217 - local_set(&reader->entries, 0);
89218 + local_set_unchecked(&reader->write, 0);
89219 + local_set_unchecked(&reader->entries, 0);
89220 reader->read = 0;
89221 *data_page = bpage;
89222
89223 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
89224 index 9d20cd9..221d816 100644
89225 --- a/kernel/trace/trace.c
89226 +++ b/kernel/trace/trace.c
89227 @@ -3346,7 +3346,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
89228 return 0;
89229 }
89230
89231 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
89232 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
89233 {
89234 /* do nothing if flag is already set */
89235 if (!!(trace_flags & mask) == !!enabled)
89236 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
89237 index ea189e0..a5b48c4 100644
89238 --- a/kernel/trace/trace.h
89239 +++ b/kernel/trace/trace.h
89240 @@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
89241 void trace_printk_init_buffers(void);
89242 void trace_printk_start_comm(void);
89243 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
89244 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
89245 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
89246
89247 /*
89248 * Normal trace_printk() and friends allocates special buffers
89249 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
89250 index 26dc348..8708ca7 100644
89251 --- a/kernel/trace/trace_clock.c
89252 +++ b/kernel/trace/trace_clock.c
89253 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
89254 return now;
89255 }
89256
89257 -static atomic64_t trace_counter;
89258 +static atomic64_unchecked_t trace_counter;
89259
89260 /*
89261 * trace_clock_counter(): simply an atomic counter.
89262 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
89263 */
89264 u64 notrace trace_clock_counter(void)
89265 {
89266 - return atomic64_add_return(1, &trace_counter);
89267 + return atomic64_inc_return_unchecked(&trace_counter);
89268 }
89269 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
89270 index a11800a..3dafde5 100644
89271 --- a/kernel/trace/trace_events.c
89272 +++ b/kernel/trace/trace_events.c
89273 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
89274 return 0;
89275 }
89276
89277 -struct ftrace_module_file_ops;
89278 static void __add_event_to_tracers(struct ftrace_event_call *call);
89279
89280 /* Add an additional event_call dynamically */
89281 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
89282 index 0abd9b8..6a663a2 100644
89283 --- a/kernel/trace/trace_mmiotrace.c
89284 +++ b/kernel/trace/trace_mmiotrace.c
89285 @@ -24,7 +24,7 @@ struct header_iter {
89286 static struct trace_array *mmio_trace_array;
89287 static bool overrun_detected;
89288 static unsigned long prev_overruns;
89289 -static atomic_t dropped_count;
89290 +static atomic_unchecked_t dropped_count;
89291
89292 static void mmio_reset_data(struct trace_array *tr)
89293 {
89294 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
89295
89296 static unsigned long count_overruns(struct trace_iterator *iter)
89297 {
89298 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
89299 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
89300 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
89301
89302 if (over > prev_overruns)
89303 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
89304 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
89305 sizeof(*entry), 0, pc);
89306 if (!event) {
89307 - atomic_inc(&dropped_count);
89308 + atomic_inc_unchecked(&dropped_count);
89309 return;
89310 }
89311 entry = ring_buffer_event_data(event);
89312 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
89313 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
89314 sizeof(*entry), 0, pc);
89315 if (!event) {
89316 - atomic_inc(&dropped_count);
89317 + atomic_inc_unchecked(&dropped_count);
89318 return;
89319 }
89320 entry = ring_buffer_event_data(event);
89321 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
89322 index ed32284..884d6c3 100644
89323 --- a/kernel/trace/trace_output.c
89324 +++ b/kernel/trace/trace_output.c
89325 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
89326
89327 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
89328 if (!IS_ERR(p)) {
89329 - p = mangle_path(s->buffer + s->len, p, "\n");
89330 + p = mangle_path(s->buffer + s->len, p, "\n\\");
89331 if (p) {
89332 s->len = p - s->buffer;
89333 return 1;
89334 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
89335 goto out;
89336 }
89337
89338 + pax_open_kernel();
89339 if (event->funcs->trace == NULL)
89340 - event->funcs->trace = trace_nop_print;
89341 + *(void **)&event->funcs->trace = trace_nop_print;
89342 if (event->funcs->raw == NULL)
89343 - event->funcs->raw = trace_nop_print;
89344 + *(void **)&event->funcs->raw = trace_nop_print;
89345 if (event->funcs->hex == NULL)
89346 - event->funcs->hex = trace_nop_print;
89347 + *(void **)&event->funcs->hex = trace_nop_print;
89348 if (event->funcs->binary == NULL)
89349 - event->funcs->binary = trace_nop_print;
89350 + *(void **)&event->funcs->binary = trace_nop_print;
89351 + pax_close_kernel();
89352
89353 key = event->type & (EVENT_HASHSIZE - 1);
89354
89355 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
89356 index b20428c..4845a10 100644
89357 --- a/kernel/trace/trace_stack.c
89358 +++ b/kernel/trace/trace_stack.c
89359 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
89360 return;
89361
89362 /* we do not handle interrupt stacks yet */
89363 - if (!object_is_on_stack(stack))
89364 + if (!object_starts_on_stack(stack))
89365 return;
89366
89367 local_irq_save(flags);
89368 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
89369 index 240fb62..583473e 100644
89370 --- a/kernel/user_namespace.c
89371 +++ b/kernel/user_namespace.c
89372 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
89373 !kgid_has_mapping(parent_ns, group))
89374 return -EPERM;
89375
89376 +#ifdef CONFIG_GRKERNSEC
89377 + /*
89378 + * This doesn't really inspire confidence:
89379 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
89380 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
89381 + * Increases kernel attack surface in areas developers
89382 + * previously cared little about ("low importance due
89383 + * to requiring "root" capability")
89384 + * To be removed when this code receives *proper* review
89385 + */
89386 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
89387 + !capable(CAP_SETGID))
89388 + return -EPERM;
89389 +#endif
89390 +
89391 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
89392 if (!ns)
89393 return -ENOMEM;
89394 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
89395 if (atomic_read(&current->mm->mm_users) > 1)
89396 return -EINVAL;
89397
89398 - if (current->fs->users != 1)
89399 + if (atomic_read(&current->fs->users) != 1)
89400 return -EINVAL;
89401
89402 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
89403 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
89404 index 4f69f9a..7c6f8f8 100644
89405 --- a/kernel/utsname_sysctl.c
89406 +++ b/kernel/utsname_sysctl.c
89407 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
89408 static int proc_do_uts_string(ctl_table *table, int write,
89409 void __user *buffer, size_t *lenp, loff_t *ppos)
89410 {
89411 - struct ctl_table uts_table;
89412 + ctl_table_no_const uts_table;
89413 int r;
89414 memcpy(&uts_table, table, sizeof(uts_table));
89415 uts_table.data = get_uts(table, write);
89416 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
89417 index 4431610..4265616 100644
89418 --- a/kernel/watchdog.c
89419 +++ b/kernel/watchdog.c
89420 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
89421 static void watchdog_nmi_disable(unsigned int cpu) { return; }
89422 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
89423
89424 -static struct smp_hotplug_thread watchdog_threads = {
89425 +static struct smp_hotplug_thread watchdog_threads __read_only = {
89426 .store = &softlockup_watchdog,
89427 .thread_should_run = watchdog_should_run,
89428 .thread_fn = watchdog,
89429 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
89430 index b010eac..e4bda78 100644
89431 --- a/kernel/workqueue.c
89432 +++ b/kernel/workqueue.c
89433 @@ -4671,7 +4671,7 @@ static void rebind_workers(struct worker_pool *pool)
89434 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
89435 worker_flags |= WORKER_REBOUND;
89436 worker_flags &= ~WORKER_UNBOUND;
89437 - ACCESS_ONCE(worker->flags) = worker_flags;
89438 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
89439 }
89440
89441 spin_unlock_irq(&pool->lock);
89442 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
89443 index db25707..8b16430 100644
89444 --- a/lib/Kconfig.debug
89445 +++ b/lib/Kconfig.debug
89446 @@ -845,7 +845,7 @@ config DEBUG_MUTEXES
89447
89448 config DEBUG_WW_MUTEX_SLOWPATH
89449 bool "Wait/wound mutex debugging: Slowpath testing"
89450 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89451 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89452 select DEBUG_LOCK_ALLOC
89453 select DEBUG_SPINLOCK
89454 select DEBUG_MUTEXES
89455 @@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
89456
89457 config DEBUG_LOCK_ALLOC
89458 bool "Lock debugging: detect incorrect freeing of live locks"
89459 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89460 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89461 select DEBUG_SPINLOCK
89462 select DEBUG_MUTEXES
89463 select LOCKDEP
89464 @@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
89465
89466 config PROVE_LOCKING
89467 bool "Lock debugging: prove locking correctness"
89468 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89469 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89470 select LOCKDEP
89471 select DEBUG_SPINLOCK
89472 select DEBUG_MUTEXES
89473 @@ -923,7 +923,7 @@ config LOCKDEP
89474
89475 config LOCK_STAT
89476 bool "Lock usage statistics"
89477 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89478 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89479 select LOCKDEP
89480 select DEBUG_SPINLOCK
89481 select DEBUG_MUTEXES
89482 @@ -1385,6 +1385,7 @@ config LATENCYTOP
89483 depends on DEBUG_KERNEL
89484 depends on STACKTRACE_SUPPORT
89485 depends on PROC_FS
89486 + depends on !GRKERNSEC_HIDESYM
89487 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
89488 select KALLSYMS
89489 select KALLSYMS_ALL
89490 @@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89491 config DEBUG_STRICT_USER_COPY_CHECKS
89492 bool "Strict user copy size checks"
89493 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89494 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
89495 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
89496 help
89497 Enabling this option turns a certain set of sanity checks for user
89498 copy operations into compile time failures.
89499 @@ -1520,7 +1521,7 @@ endmenu # runtime tests
89500
89501 config PROVIDE_OHCI1394_DMA_INIT
89502 bool "Remote debugging over FireWire early on boot"
89503 - depends on PCI && X86
89504 + depends on PCI && X86 && !GRKERNSEC
89505 help
89506 If you want to debug problems which hang or crash the kernel early
89507 on boot and the crashing machine has a FireWire port, you can use
89508 @@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
89509
89510 config FIREWIRE_OHCI_REMOTE_DMA
89511 bool "Remote debugging over FireWire with firewire-ohci"
89512 - depends on FIREWIRE_OHCI
89513 + depends on FIREWIRE_OHCI && !GRKERNSEC
89514 help
89515 This option lets you use the FireWire bus for remote debugging
89516 with help of the firewire-ohci driver. It enables unfiltered
89517 diff --git a/lib/Makefile b/lib/Makefile
89518 index a459c31..3320e82 100644
89519 --- a/lib/Makefile
89520 +++ b/lib/Makefile
89521 @@ -49,7 +49,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
89522 obj-$(CONFIG_BTREE) += btree.o
89523 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
89524 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
89525 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
89526 +obj-y += list_debug.o
89527 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
89528
89529 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
89530 diff --git a/lib/bitmap.c b/lib/bitmap.c
89531 index 06f7e4f..f3cf2b0 100644
89532 --- a/lib/bitmap.c
89533 +++ b/lib/bitmap.c
89534 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
89535 {
89536 int c, old_c, totaldigits, ndigits, nchunks, nbits;
89537 u32 chunk;
89538 - const char __user __force *ubuf = (const char __user __force *)buf;
89539 + const char __user *ubuf = (const char __force_user *)buf;
89540
89541 bitmap_zero(maskp, nmaskbits);
89542
89543 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
89544 {
89545 if (!access_ok(VERIFY_READ, ubuf, ulen))
89546 return -EFAULT;
89547 - return __bitmap_parse((const char __force *)ubuf,
89548 + return __bitmap_parse((const char __force_kernel *)ubuf,
89549 ulen, 1, maskp, nmaskbits);
89550
89551 }
89552 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
89553 {
89554 unsigned a, b;
89555 int c, old_c, totaldigits;
89556 - const char __user __force *ubuf = (const char __user __force *)buf;
89557 + const char __user *ubuf = (const char __force_user *)buf;
89558 int exp_digit, in_range;
89559
89560 totaldigits = c = 0;
89561 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
89562 {
89563 if (!access_ok(VERIFY_READ, ubuf, ulen))
89564 return -EFAULT;
89565 - return __bitmap_parselist((const char __force *)ubuf,
89566 + return __bitmap_parselist((const char __force_kernel *)ubuf,
89567 ulen, 1, maskp, nmaskbits);
89568 }
89569 EXPORT_SYMBOL(bitmap_parselist_user);
89570 diff --git a/lib/bug.c b/lib/bug.c
89571 index 1686034..a9c00c8 100644
89572 --- a/lib/bug.c
89573 +++ b/lib/bug.c
89574 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
89575 return BUG_TRAP_TYPE_NONE;
89576
89577 bug = find_bug(bugaddr);
89578 + if (!bug)
89579 + return BUG_TRAP_TYPE_NONE;
89580
89581 file = NULL;
89582 line = 0;
89583 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
89584 index e0731c3..ad66444 100644
89585 --- a/lib/debugobjects.c
89586 +++ b/lib/debugobjects.c
89587 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
89588 if (limit > 4)
89589 return;
89590
89591 - is_on_stack = object_is_on_stack(addr);
89592 + is_on_stack = object_starts_on_stack(addr);
89593 if (is_on_stack == onstack)
89594 return;
89595
89596 diff --git a/lib/devres.c b/lib/devres.c
89597 index 8235331..5881053 100644
89598 --- a/lib/devres.c
89599 +++ b/lib/devres.c
89600 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
89601 void devm_iounmap(struct device *dev, void __iomem *addr)
89602 {
89603 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
89604 - (void *)addr));
89605 + (void __force *)addr));
89606 iounmap(addr);
89607 }
89608 EXPORT_SYMBOL(devm_iounmap);
89609 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
89610 {
89611 ioport_unmap(addr);
89612 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
89613 - devm_ioport_map_match, (void *)addr));
89614 + devm_ioport_map_match, (void __force *)addr));
89615 }
89616 EXPORT_SYMBOL(devm_ioport_unmap);
89617 #endif /* CONFIG_HAS_IOPORT */
89618 diff --git a/lib/div64.c b/lib/div64.c
89619 index 4382ad7..08aa558 100644
89620 --- a/lib/div64.c
89621 +++ b/lib/div64.c
89622 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
89623 EXPORT_SYMBOL(__div64_32);
89624
89625 #ifndef div_s64_rem
89626 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89627 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89628 {
89629 u64 quotient;
89630
89631 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
89632 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
89633 */
89634 #ifndef div64_u64
89635 -u64 div64_u64(u64 dividend, u64 divisor)
89636 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
89637 {
89638 u32 high = divisor >> 32;
89639 u64 quot;
89640 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
89641 index d87a17a..ac0d79a 100644
89642 --- a/lib/dma-debug.c
89643 +++ b/lib/dma-debug.c
89644 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
89645
89646 void dma_debug_add_bus(struct bus_type *bus)
89647 {
89648 - struct notifier_block *nb;
89649 + notifier_block_no_const *nb;
89650
89651 if (global_disable)
89652 return;
89653 @@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
89654
89655 static void check_for_stack(struct device *dev, void *addr)
89656 {
89657 - if (object_is_on_stack(addr))
89658 + if (object_starts_on_stack(addr))
89659 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
89660 "stack [addr=%p]\n", addr);
89661 }
89662 diff --git a/lib/inflate.c b/lib/inflate.c
89663 index 013a761..c28f3fc 100644
89664 --- a/lib/inflate.c
89665 +++ b/lib/inflate.c
89666 @@ -269,7 +269,7 @@ static void free(void *where)
89667 malloc_ptr = free_mem_ptr;
89668 }
89669 #else
89670 -#define malloc(a) kmalloc(a, GFP_KERNEL)
89671 +#define malloc(a) kmalloc((a), GFP_KERNEL)
89672 #define free(a) kfree(a)
89673 #endif
89674
89675 diff --git a/lib/ioremap.c b/lib/ioremap.c
89676 index 0c9216c..863bd89 100644
89677 --- a/lib/ioremap.c
89678 +++ b/lib/ioremap.c
89679 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
89680 unsigned long next;
89681
89682 phys_addr -= addr;
89683 - pmd = pmd_alloc(&init_mm, pud, addr);
89684 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
89685 if (!pmd)
89686 return -ENOMEM;
89687 do {
89688 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
89689 unsigned long next;
89690
89691 phys_addr -= addr;
89692 - pud = pud_alloc(&init_mm, pgd, addr);
89693 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
89694 if (!pud)
89695 return -ENOMEM;
89696 do {
89697 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
89698 index bd2bea9..6b3c95e 100644
89699 --- a/lib/is_single_threaded.c
89700 +++ b/lib/is_single_threaded.c
89701 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
89702 struct task_struct *p, *t;
89703 bool ret;
89704
89705 + if (!mm)
89706 + return true;
89707 +
89708 if (atomic_read(&task->signal->live) != 1)
89709 return false;
89710
89711 diff --git a/lib/kobject.c b/lib/kobject.c
89712 index 5b4b888..c2950f7 100644
89713 --- a/lib/kobject.c
89714 +++ b/lib/kobject.c
89715 @@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
89716
89717
89718 static DEFINE_SPINLOCK(kobj_ns_type_lock);
89719 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
89720 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
89721
89722 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89723 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89724 {
89725 enum kobj_ns_type type = ops->type;
89726 int error;
89727 diff --git a/lib/list_debug.c b/lib/list_debug.c
89728 index c24c2f7..f0296f4 100644
89729 --- a/lib/list_debug.c
89730 +++ b/lib/list_debug.c
89731 @@ -11,7 +11,9 @@
89732 #include <linux/bug.h>
89733 #include <linux/kernel.h>
89734 #include <linux/rculist.h>
89735 +#include <linux/mm.h>
89736
89737 +#ifdef CONFIG_DEBUG_LIST
89738 /*
89739 * Insert a new entry between two known consecutive entries.
89740 *
89741 @@ -19,21 +21,40 @@
89742 * the prev/next entries already!
89743 */
89744
89745 +static bool __list_add_debug(struct list_head *new,
89746 + struct list_head *prev,
89747 + struct list_head *next)
89748 +{
89749 + if (unlikely(next->prev != prev)) {
89750 + printk(KERN_ERR "list_add corruption. next->prev should be "
89751 + "prev (%p), but was %p. (next=%p).\n",
89752 + prev, next->prev, next);
89753 + BUG();
89754 + return false;
89755 + }
89756 + if (unlikely(prev->next != next)) {
89757 + printk(KERN_ERR "list_add corruption. prev->next should be "
89758 + "next (%p), but was %p. (prev=%p).\n",
89759 + next, prev->next, prev);
89760 + BUG();
89761 + return false;
89762 + }
89763 + if (unlikely(new == prev || new == next)) {
89764 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
89765 + new, prev, next);
89766 + BUG();
89767 + return false;
89768 + }
89769 + return true;
89770 +}
89771 +
89772 void __list_add(struct list_head *new,
89773 - struct list_head *prev,
89774 - struct list_head *next)
89775 + struct list_head *prev,
89776 + struct list_head *next)
89777 {
89778 - WARN(next->prev != prev,
89779 - "list_add corruption. next->prev should be "
89780 - "prev (%p), but was %p. (next=%p).\n",
89781 - prev, next->prev, next);
89782 - WARN(prev->next != next,
89783 - "list_add corruption. prev->next should be "
89784 - "next (%p), but was %p. (prev=%p).\n",
89785 - next, prev->next, prev);
89786 - WARN(new == prev || new == next,
89787 - "list_add double add: new=%p, prev=%p, next=%p.\n",
89788 - new, prev, next);
89789 + if (!__list_add_debug(new, prev, next))
89790 + return;
89791 +
89792 next->prev = new;
89793 new->next = next;
89794 new->prev = prev;
89795 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
89796 }
89797 EXPORT_SYMBOL(__list_add);
89798
89799 -void __list_del_entry(struct list_head *entry)
89800 +static bool __list_del_entry_debug(struct list_head *entry)
89801 {
89802 struct list_head *prev, *next;
89803
89804 prev = entry->prev;
89805 next = entry->next;
89806
89807 - if (WARN(next == LIST_POISON1,
89808 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89809 - entry, LIST_POISON1) ||
89810 - WARN(prev == LIST_POISON2,
89811 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89812 - entry, LIST_POISON2) ||
89813 - WARN(prev->next != entry,
89814 - "list_del corruption. prev->next should be %p, "
89815 - "but was %p\n", entry, prev->next) ||
89816 - WARN(next->prev != entry,
89817 - "list_del corruption. next->prev should be %p, "
89818 - "but was %p\n", entry, next->prev))
89819 + if (unlikely(next == LIST_POISON1)) {
89820 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89821 + entry, LIST_POISON1);
89822 + BUG();
89823 + return false;
89824 + }
89825 + if (unlikely(prev == LIST_POISON2)) {
89826 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89827 + entry, LIST_POISON2);
89828 + BUG();
89829 + return false;
89830 + }
89831 + if (unlikely(entry->prev->next != entry)) {
89832 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
89833 + "but was %p\n", entry, prev->next);
89834 + BUG();
89835 + return false;
89836 + }
89837 + if (unlikely(entry->next->prev != entry)) {
89838 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
89839 + "but was %p\n", entry, next->prev);
89840 + BUG();
89841 + return false;
89842 + }
89843 + return true;
89844 +}
89845 +
89846 +void __list_del_entry(struct list_head *entry)
89847 +{
89848 + if (!__list_del_entry_debug(entry))
89849 return;
89850
89851 - __list_del(prev, next);
89852 + __list_del(entry->prev, entry->next);
89853 }
89854 EXPORT_SYMBOL(__list_del_entry);
89855
89856 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
89857 void __list_add_rcu(struct list_head *new,
89858 struct list_head *prev, struct list_head *next)
89859 {
89860 - WARN(next->prev != prev,
89861 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
89862 - prev, next->prev, next);
89863 - WARN(prev->next != next,
89864 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
89865 - next, prev->next, prev);
89866 + if (!__list_add_debug(new, prev, next))
89867 + return;
89868 +
89869 new->next = next;
89870 new->prev = prev;
89871 rcu_assign_pointer(list_next_rcu(prev), new);
89872 next->prev = new;
89873 }
89874 EXPORT_SYMBOL(__list_add_rcu);
89875 +#endif
89876 +
89877 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
89878 +{
89879 +#ifdef CONFIG_DEBUG_LIST
89880 + if (!__list_add_debug(new, prev, next))
89881 + return;
89882 +#endif
89883 +
89884 + pax_open_kernel();
89885 + next->prev = new;
89886 + new->next = next;
89887 + new->prev = prev;
89888 + prev->next = new;
89889 + pax_close_kernel();
89890 +}
89891 +EXPORT_SYMBOL(__pax_list_add);
89892 +
89893 +void pax_list_del(struct list_head *entry)
89894 +{
89895 +#ifdef CONFIG_DEBUG_LIST
89896 + if (!__list_del_entry_debug(entry))
89897 + return;
89898 +#endif
89899 +
89900 + pax_open_kernel();
89901 + __list_del(entry->prev, entry->next);
89902 + entry->next = LIST_POISON1;
89903 + entry->prev = LIST_POISON2;
89904 + pax_close_kernel();
89905 +}
89906 +EXPORT_SYMBOL(pax_list_del);
89907 +
89908 +void pax_list_del_init(struct list_head *entry)
89909 +{
89910 + pax_open_kernel();
89911 + __list_del(entry->prev, entry->next);
89912 + INIT_LIST_HEAD(entry);
89913 + pax_close_kernel();
89914 +}
89915 +EXPORT_SYMBOL(pax_list_del_init);
89916 +
89917 +void __pax_list_add_rcu(struct list_head *new,
89918 + struct list_head *prev, struct list_head *next)
89919 +{
89920 +#ifdef CONFIG_DEBUG_LIST
89921 + if (!__list_add_debug(new, prev, next))
89922 + return;
89923 +#endif
89924 +
89925 + pax_open_kernel();
89926 + new->next = next;
89927 + new->prev = prev;
89928 + rcu_assign_pointer(list_next_rcu(prev), new);
89929 + next->prev = new;
89930 + pax_close_kernel();
89931 +}
89932 +EXPORT_SYMBOL(__pax_list_add_rcu);
89933 +
89934 +void pax_list_del_rcu(struct list_head *entry)
89935 +{
89936 +#ifdef CONFIG_DEBUG_LIST
89937 + if (!__list_del_entry_debug(entry))
89938 + return;
89939 +#endif
89940 +
89941 + pax_open_kernel();
89942 + __list_del(entry->prev, entry->next);
89943 + entry->next = LIST_POISON1;
89944 + entry->prev = LIST_POISON2;
89945 + pax_close_kernel();
89946 +}
89947 +EXPORT_SYMBOL(pax_list_del_rcu);
89948 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
89949 index 1a53d49..ace934c 100644
89950 --- a/lib/percpu-refcount.c
89951 +++ b/lib/percpu-refcount.c
89952 @@ -29,7 +29,7 @@
89953 * can't hit 0 before we've added up all the percpu refs.
89954 */
89955
89956 -#define PCPU_COUNT_BIAS (1U << 31)
89957 +#define PCPU_COUNT_BIAS (1U << 30)
89958
89959 /**
89960 * percpu_ref_init - initialize a percpu refcount
89961 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
89962 index 7811ed3..f80ca19 100644
89963 --- a/lib/radix-tree.c
89964 +++ b/lib/radix-tree.c
89965 @@ -93,7 +93,7 @@ struct radix_tree_preload {
89966 int nr;
89967 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
89968 };
89969 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
89970 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
89971
89972 static inline void *ptr_to_indirect(void *ptr)
89973 {
89974 diff --git a/lib/rbtree.c b/lib/rbtree.c
89975 index 65f4eff..2cfa167 100644
89976 --- a/lib/rbtree.c
89977 +++ b/lib/rbtree.c
89978 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
89979 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
89980
89981 static const struct rb_augment_callbacks dummy_callbacks = {
89982 - dummy_propagate, dummy_copy, dummy_rotate
89983 + .propagate = dummy_propagate,
89984 + .copy = dummy_copy,
89985 + .rotate = dummy_rotate
89986 };
89987
89988 void rb_insert_color(struct rb_node *node, struct rb_root *root)
89989 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
89990 index bb2b201..46abaf9 100644
89991 --- a/lib/strncpy_from_user.c
89992 +++ b/lib/strncpy_from_user.c
89993 @@ -21,7 +21,7 @@
89994 */
89995 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
89996 {
89997 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89998 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89999 long res = 0;
90000
90001 /*
90002 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
90003 index a28df52..3d55877 100644
90004 --- a/lib/strnlen_user.c
90005 +++ b/lib/strnlen_user.c
90006 @@ -26,7 +26,7 @@
90007 */
90008 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
90009 {
90010 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90011 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90012 long align, res = 0;
90013 unsigned long c;
90014
90015 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
90016 index e4399fa..5e8b214 100644
90017 --- a/lib/swiotlb.c
90018 +++ b/lib/swiotlb.c
90019 @@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
90020
90021 void
90022 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
90023 - dma_addr_t dev_addr)
90024 + dma_addr_t dev_addr, struct dma_attrs *attrs)
90025 {
90026 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
90027
90028 diff --git a/lib/usercopy.c b/lib/usercopy.c
90029 index 4f5b1dd..7cab418 100644
90030 --- a/lib/usercopy.c
90031 +++ b/lib/usercopy.c
90032 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
90033 WARN(1, "Buffer overflow detected!\n");
90034 }
90035 EXPORT_SYMBOL(copy_from_user_overflow);
90036 +
90037 +void copy_to_user_overflow(void)
90038 +{
90039 + WARN(1, "Buffer overflow detected!\n");
90040 +}
90041 +EXPORT_SYMBOL(copy_to_user_overflow);
90042 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
90043 index 10909c5..653e1b8 100644
90044 --- a/lib/vsprintf.c
90045 +++ b/lib/vsprintf.c
90046 @@ -16,6 +16,9 @@
90047 * - scnprintf and vscnprintf
90048 */
90049
90050 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90051 +#define __INCLUDED_BY_HIDESYM 1
90052 +#endif
90053 #include <stdarg.h>
90054 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
90055 #include <linux/types.h>
90056 @@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
90057 return number(buf, end, *(const netdev_features_t *)addr, spec);
90058 }
90059
90060 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90061 +int kptr_restrict __read_mostly = 2;
90062 +#else
90063 int kptr_restrict __read_mostly;
90064 +#endif
90065
90066 /*
90067 * Show a '%p' thing. A kernel extension is that the '%p' is followed
90068 @@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
90069 * - 'f' For simple symbolic function names without offset
90070 * - 'S' For symbolic direct pointers with offset
90071 * - 's' For symbolic direct pointers without offset
90072 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
90073 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
90074 * - 'B' For backtraced symbolic direct pointers with offset
90075 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
90076 @@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90077
90078 if (!ptr && *fmt != 'K') {
90079 /*
90080 - * Print (null) with the same width as a pointer so it makes
90081 + * Print (nil) with the same width as a pointer so it makes
90082 * tabular output look nice.
90083 */
90084 if (spec.field_width == -1)
90085 spec.field_width = default_width;
90086 - return string(buf, end, "(null)", spec);
90087 + return string(buf, end, "(nil)", spec);
90088 }
90089
90090 switch (*fmt) {
90091 @@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90092 /* Fallthrough */
90093 case 'S':
90094 case 's':
90095 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90096 + break;
90097 +#else
90098 + return symbol_string(buf, end, ptr, spec, fmt);
90099 +#endif
90100 + case 'A':
90101 case 'B':
90102 return symbol_string(buf, end, ptr, spec, fmt);
90103 case 'R':
90104 @@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90105 va_end(va);
90106 return buf;
90107 }
90108 + case 'P':
90109 + break;
90110 case 'K':
90111 /*
90112 * %pK cannot be used in IRQ context because its test
90113 @@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90114 ((const struct file *)ptr)->f_path.dentry,
90115 spec, fmt);
90116 }
90117 +
90118 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90119 + /* 'P' = approved pointers to copy to userland,
90120 + as in the /proc/kallsyms case, as we make it display nothing
90121 + for non-root users, and the real contents for root users
90122 + Also ignore 'K' pointers, since we force their NULLing for non-root users
90123 + above
90124 + */
90125 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
90126 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
90127 + dump_stack();
90128 + ptr = NULL;
90129 + }
90130 +#endif
90131 +
90132 spec.flags |= SMALL;
90133 if (spec.field_width == -1) {
90134 spec.field_width = default_width;
90135 @@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90136 typeof(type) value; \
90137 if (sizeof(type) == 8) { \
90138 args = PTR_ALIGN(args, sizeof(u32)); \
90139 - *(u32 *)&value = *(u32 *)args; \
90140 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
90141 + *(u32 *)&value = *(const u32 *)args; \
90142 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
90143 } else { \
90144 args = PTR_ALIGN(args, sizeof(type)); \
90145 - value = *(typeof(type) *)args; \
90146 + value = *(const typeof(type) *)args; \
90147 } \
90148 args += sizeof(type); \
90149 value; \
90150 @@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90151 case FORMAT_TYPE_STR: {
90152 const char *str_arg = args;
90153 args += strlen(str_arg) + 1;
90154 - str = string(str, end, (char *)str_arg, spec);
90155 + str = string(str, end, str_arg, spec);
90156 break;
90157 }
90158
90159 diff --git a/localversion-grsec b/localversion-grsec
90160 new file mode 100644
90161 index 0000000..7cd6065
90162 --- /dev/null
90163 +++ b/localversion-grsec
90164 @@ -0,0 +1 @@
90165 +-grsec
90166 diff --git a/mm/Kconfig b/mm/Kconfig
90167 index 723bbe0..ea624b1 100644
90168 --- a/mm/Kconfig
90169 +++ b/mm/Kconfig
90170 @@ -326,10 +326,11 @@ config KSM
90171 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
90172
90173 config DEFAULT_MMAP_MIN_ADDR
90174 - int "Low address space to protect from user allocation"
90175 + int "Low address space to protect from user allocation"
90176 depends on MMU
90177 - default 4096
90178 - help
90179 + default 32768 if ALPHA || ARM || PARISC || SPARC32
90180 + default 65536
90181 + help
90182 This is the portion of low virtual memory which should be protected
90183 from userspace allocation. Keeping a user from writing to low pages
90184 can help reduce the impact of kernel NULL pointer bugs.
90185 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
90186
90187 config HWPOISON_INJECT
90188 tristate "HWPoison pages injector"
90189 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
90190 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
90191 select PROC_PAGE_MONITOR
90192
90193 config NOMMU_INITIAL_TRIM_EXCESS
90194 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
90195 index ce682f7..1fb54f9 100644
90196 --- a/mm/backing-dev.c
90197 +++ b/mm/backing-dev.c
90198 @@ -12,7 +12,7 @@
90199 #include <linux/device.h>
90200 #include <trace/events/writeback.h>
90201
90202 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
90203 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
90204
90205 struct backing_dev_info default_backing_dev_info = {
90206 .name = "default",
90207 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
90208 return err;
90209
90210 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
90211 - atomic_long_inc_return(&bdi_seq));
90212 + atomic_long_inc_return_unchecked(&bdi_seq));
90213 if (err) {
90214 bdi_destroy(bdi);
90215 return err;
90216 diff --git a/mm/filemap.c b/mm/filemap.c
90217 index b7749a9..50d1123 100644
90218 --- a/mm/filemap.c
90219 +++ b/mm/filemap.c
90220 @@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
90221 struct address_space *mapping = file->f_mapping;
90222
90223 if (!mapping->a_ops->readpage)
90224 - return -ENOEXEC;
90225 + return -ENODEV;
90226 file_accessed(file);
90227 vma->vm_ops = &generic_file_vm_ops;
90228 return 0;
90229 @@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
90230
90231 while (bytes) {
90232 char __user *buf = iov->iov_base + base;
90233 - int copy = min(bytes, iov->iov_len - base);
90234 + size_t copy = min(bytes, iov->iov_len - base);
90235
90236 base = 0;
90237 left = __copy_from_user_inatomic(vaddr, buf, copy);
90238 @@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
90239 BUG_ON(!in_atomic());
90240 kaddr = kmap_atomic(page);
90241 if (likely(i->nr_segs == 1)) {
90242 - int left;
90243 + size_t left;
90244 char __user *buf = i->iov->iov_base + i->iov_offset;
90245 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
90246 copied = bytes - left;
90247 @@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
90248
90249 kaddr = kmap(page);
90250 if (likely(i->nr_segs == 1)) {
90251 - int left;
90252 + size_t left;
90253 char __user *buf = i->iov->iov_base + i->iov_offset;
90254 left = __copy_from_user(kaddr + offset, buf, bytes);
90255 copied = bytes - left;
90256 @@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
90257 * zero-length segments (without overruning the iovec).
90258 */
90259 while (bytes || unlikely(i->count && !iov->iov_len)) {
90260 - int copy;
90261 + size_t copy;
90262
90263 copy = min(bytes, iov->iov_len - base);
90264 BUG_ON(!i->count || i->count < copy);
90265 @@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
90266 *pos = i_size_read(inode);
90267
90268 if (limit != RLIM_INFINITY) {
90269 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
90270 if (*pos >= limit) {
90271 send_sig(SIGXFSZ, current, 0);
90272 return -EFBIG;
90273 diff --git a/mm/fremap.c b/mm/fremap.c
90274 index bbc4d66..117b798 100644
90275 --- a/mm/fremap.c
90276 +++ b/mm/fremap.c
90277 @@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
90278 retry:
90279 vma = find_vma(mm, start);
90280
90281 +#ifdef CONFIG_PAX_SEGMEXEC
90282 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
90283 + goto out;
90284 +#endif
90285 +
90286 /*
90287 * Make sure the vma is shared, that it supports prefaulting,
90288 * and that the remapped range is valid and fully within
90289 diff --git a/mm/highmem.c b/mm/highmem.c
90290 index b32b70c..e512eb0 100644
90291 --- a/mm/highmem.c
90292 +++ b/mm/highmem.c
90293 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
90294 * So no dangers, even with speculative execution.
90295 */
90296 page = pte_page(pkmap_page_table[i]);
90297 + pax_open_kernel();
90298 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
90299 -
90300 + pax_close_kernel();
90301 set_page_address(page, NULL);
90302 need_flush = 1;
90303 }
90304 @@ -198,9 +199,11 @@ start:
90305 }
90306 }
90307 vaddr = PKMAP_ADDR(last_pkmap_nr);
90308 +
90309 + pax_open_kernel();
90310 set_pte_at(&init_mm, vaddr,
90311 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
90312 -
90313 + pax_close_kernel();
90314 pkmap_count[last_pkmap_nr] = 1;
90315 set_page_address(page, (void *)vaddr);
90316
90317 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
90318 index dee6cf4..52b94f7 100644
90319 --- a/mm/hugetlb.c
90320 +++ b/mm/hugetlb.c
90321 @@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
90322 struct hstate *h = &default_hstate;
90323 unsigned long tmp;
90324 int ret;
90325 + ctl_table_no_const hugetlb_table;
90326
90327 tmp = h->max_huge_pages;
90328
90329 if (write && h->order >= MAX_ORDER)
90330 return -EINVAL;
90331
90332 - table->data = &tmp;
90333 - table->maxlen = sizeof(unsigned long);
90334 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90335 + hugetlb_table = *table;
90336 + hugetlb_table.data = &tmp;
90337 + hugetlb_table.maxlen = sizeof(unsigned long);
90338 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90339 if (ret)
90340 goto out;
90341
90342 @@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
90343 struct hstate *h = &default_hstate;
90344 unsigned long tmp;
90345 int ret;
90346 + ctl_table_no_const hugetlb_table;
90347
90348 tmp = h->nr_overcommit_huge_pages;
90349
90350 if (write && h->order >= MAX_ORDER)
90351 return -EINVAL;
90352
90353 - table->data = &tmp;
90354 - table->maxlen = sizeof(unsigned long);
90355 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90356 + hugetlb_table = *table;
90357 + hugetlb_table.data = &tmp;
90358 + hugetlb_table.maxlen = sizeof(unsigned long);
90359 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90360 if (ret)
90361 goto out;
90362
90363 @@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
90364 return 1;
90365 }
90366
90367 +#ifdef CONFIG_PAX_SEGMEXEC
90368 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
90369 +{
90370 + struct mm_struct *mm = vma->vm_mm;
90371 + struct vm_area_struct *vma_m;
90372 + unsigned long address_m;
90373 + pte_t *ptep_m;
90374 +
90375 + vma_m = pax_find_mirror_vma(vma);
90376 + if (!vma_m)
90377 + return;
90378 +
90379 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90380 + address_m = address + SEGMEXEC_TASK_SIZE;
90381 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
90382 + get_page(page_m);
90383 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
90384 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
90385 +}
90386 +#endif
90387 +
90388 /*
90389 * Hugetlb_cow() should be called with page lock of the original hugepage held.
90390 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
90391 @@ -2712,6 +2737,11 @@ retry_avoidcopy:
90392 make_huge_pte(vma, new_page, 1));
90393 page_remove_rmap(old_page);
90394 hugepage_add_new_anon_rmap(new_page, vma, address);
90395 +
90396 +#ifdef CONFIG_PAX_SEGMEXEC
90397 + pax_mirror_huge_pte(vma, address, new_page);
90398 +#endif
90399 +
90400 /* Make the old page be freed below */
90401 new_page = old_page;
90402 }
90403 @@ -2876,6 +2906,10 @@ retry:
90404 && (vma->vm_flags & VM_SHARED)));
90405 set_huge_pte_at(mm, address, ptep, new_pte);
90406
90407 +#ifdef CONFIG_PAX_SEGMEXEC
90408 + pax_mirror_huge_pte(vma, address, page);
90409 +#endif
90410 +
90411 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
90412 /* Optimization, do the COW without a second fault */
90413 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
90414 @@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90415 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
90416 struct hstate *h = hstate_vma(vma);
90417
90418 +#ifdef CONFIG_PAX_SEGMEXEC
90419 + struct vm_area_struct *vma_m;
90420 +#endif
90421 +
90422 address &= huge_page_mask(h);
90423
90424 ptep = huge_pte_offset(mm, address);
90425 @@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90426 VM_FAULT_SET_HINDEX(hstate_index(h));
90427 }
90428
90429 +#ifdef CONFIG_PAX_SEGMEXEC
90430 + vma_m = pax_find_mirror_vma(vma);
90431 + if (vma_m) {
90432 + unsigned long address_m;
90433 +
90434 + if (vma->vm_start > vma_m->vm_start) {
90435 + address_m = address;
90436 + address -= SEGMEXEC_TASK_SIZE;
90437 + vma = vma_m;
90438 + h = hstate_vma(vma);
90439 + } else
90440 + address_m = address + SEGMEXEC_TASK_SIZE;
90441 +
90442 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
90443 + return VM_FAULT_OOM;
90444 + address_m &= HPAGE_MASK;
90445 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
90446 + }
90447 +#endif
90448 +
90449 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
90450 if (!ptep)
90451 return VM_FAULT_OOM;
90452 diff --git a/mm/internal.h b/mm/internal.h
90453 index 684f7aa..9eb9edc 100644
90454 --- a/mm/internal.h
90455 +++ b/mm/internal.h
90456 @@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
90457 * in mm/page_alloc.c
90458 */
90459 extern void __free_pages_bootmem(struct page *page, unsigned int order);
90460 +extern void free_compound_page(struct page *page);
90461 extern void prep_compound_page(struct page *page, unsigned long order);
90462 #ifdef CONFIG_MEMORY_FAILURE
90463 extern bool is_free_buddy_page(struct page *page);
90464 @@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
90465
90466 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
90467 unsigned long, unsigned long,
90468 - unsigned long, unsigned long);
90469 + unsigned long, unsigned long) __intentional_overflow(-1);
90470
90471 extern void set_pageblock_order(void);
90472 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
90473 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
90474 index 31f01c5..7015178 100644
90475 --- a/mm/kmemleak.c
90476 +++ b/mm/kmemleak.c
90477 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
90478
90479 for (i = 0; i < object->trace_len; i++) {
90480 void *ptr = (void *)object->trace[i];
90481 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
90482 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
90483 }
90484 }
90485
90486 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
90487 return -ENOMEM;
90488 }
90489
90490 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
90491 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
90492 &kmemleak_fops);
90493 if (!dentry)
90494 pr_warning("Failed to create the debugfs kmemleak file\n");
90495 diff --git a/mm/maccess.c b/mm/maccess.c
90496 index d53adf9..03a24bf 100644
90497 --- a/mm/maccess.c
90498 +++ b/mm/maccess.c
90499 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
90500 set_fs(KERNEL_DS);
90501 pagefault_disable();
90502 ret = __copy_from_user_inatomic(dst,
90503 - (__force const void __user *)src, size);
90504 + (const void __force_user *)src, size);
90505 pagefault_enable();
90506 set_fs(old_fs);
90507
90508 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
90509
90510 set_fs(KERNEL_DS);
90511 pagefault_disable();
90512 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
90513 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
90514 pagefault_enable();
90515 set_fs(old_fs);
90516
90517 diff --git a/mm/madvise.c b/mm/madvise.c
90518 index 539eeb9..e24a987 100644
90519 --- a/mm/madvise.c
90520 +++ b/mm/madvise.c
90521 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
90522 pgoff_t pgoff;
90523 unsigned long new_flags = vma->vm_flags;
90524
90525 +#ifdef CONFIG_PAX_SEGMEXEC
90526 + struct vm_area_struct *vma_m;
90527 +#endif
90528 +
90529 switch (behavior) {
90530 case MADV_NORMAL:
90531 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
90532 @@ -126,6 +130,13 @@ success:
90533 /*
90534 * vm_flags is protected by the mmap_sem held in write mode.
90535 */
90536 +
90537 +#ifdef CONFIG_PAX_SEGMEXEC
90538 + vma_m = pax_find_mirror_vma(vma);
90539 + if (vma_m)
90540 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
90541 +#endif
90542 +
90543 vma->vm_flags = new_flags;
90544
90545 out:
90546 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90547 struct vm_area_struct **prev,
90548 unsigned long start, unsigned long end)
90549 {
90550 +
90551 +#ifdef CONFIG_PAX_SEGMEXEC
90552 + struct vm_area_struct *vma_m;
90553 +#endif
90554 +
90555 *prev = vma;
90556 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
90557 return -EINVAL;
90558 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90559 zap_page_range(vma, start, end - start, &details);
90560 } else
90561 zap_page_range(vma, start, end - start, NULL);
90562 +
90563 +#ifdef CONFIG_PAX_SEGMEXEC
90564 + vma_m = pax_find_mirror_vma(vma);
90565 + if (vma_m) {
90566 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
90567 + struct zap_details details = {
90568 + .nonlinear_vma = vma_m,
90569 + .last_index = ULONG_MAX,
90570 + };
90571 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
90572 + } else
90573 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
90574 + }
90575 +#endif
90576 +
90577 return 0;
90578 }
90579
90580 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
90581 if (end < start)
90582 return error;
90583
90584 +#ifdef CONFIG_PAX_SEGMEXEC
90585 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90586 + if (end > SEGMEXEC_TASK_SIZE)
90587 + return error;
90588 + } else
90589 +#endif
90590 +
90591 + if (end > TASK_SIZE)
90592 + return error;
90593 +
90594 error = 0;
90595 if (end == start)
90596 return error;
90597 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
90598 index fabe550..f31b51c 100644
90599 --- a/mm/memory-failure.c
90600 +++ b/mm/memory-failure.c
90601 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
90602
90603 int sysctl_memory_failure_recovery __read_mostly = 1;
90604
90605 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90606 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90607
90608 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
90609
90610 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
90611 pfn, t->comm, t->pid);
90612 si.si_signo = SIGBUS;
90613 si.si_errno = 0;
90614 - si.si_addr = (void *)addr;
90615 + si.si_addr = (void __user *)addr;
90616 #ifdef __ARCH_SI_TRAPNO
90617 si.si_trapno = trapno;
90618 #endif
90619 @@ -762,7 +762,7 @@ static struct page_state {
90620 unsigned long res;
90621 char *msg;
90622 int (*action)(struct page *p, unsigned long pfn);
90623 -} error_states[] = {
90624 +} __do_const error_states[] = {
90625 { reserved, reserved, "reserved kernel", me_kernel },
90626 /*
90627 * free pages are specially detected outside this table:
90628 @@ -1063,7 +1063,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90629 nr_pages = 1 << compound_order(hpage);
90630 else /* normal page or thp */
90631 nr_pages = 1;
90632 - atomic_long_add(nr_pages, &num_poisoned_pages);
90633 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
90634
90635 /*
90636 * We need/can do nothing about count=0 pages.
90637 @@ -1093,7 +1093,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90638 if (!PageHWPoison(hpage)
90639 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
90640 || (p != hpage && TestSetPageHWPoison(hpage))) {
90641 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90642 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90643 return 0;
90644 }
90645 set_page_hwpoison_huge_page(hpage);
90646 @@ -1162,7 +1162,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90647 }
90648 if (hwpoison_filter(p)) {
90649 if (TestClearPageHWPoison(p))
90650 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90651 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90652 unlock_page(hpage);
90653 put_page(hpage);
90654 return 0;
90655 @@ -1380,7 +1380,7 @@ int unpoison_memory(unsigned long pfn)
90656 return 0;
90657 }
90658 if (TestClearPageHWPoison(p))
90659 - atomic_long_dec(&num_poisoned_pages);
90660 + atomic_long_dec_unchecked(&num_poisoned_pages);
90661 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
90662 return 0;
90663 }
90664 @@ -1394,7 +1394,7 @@ int unpoison_memory(unsigned long pfn)
90665 */
90666 if (TestClearPageHWPoison(page)) {
90667 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
90668 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90669 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90670 freeit = 1;
90671 if (PageHuge(page))
90672 clear_page_hwpoison_huge_page(page);
90673 @@ -1519,11 +1519,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
90674 if (PageHuge(page)) {
90675 set_page_hwpoison_huge_page(hpage);
90676 dequeue_hwpoisoned_huge_page(hpage);
90677 - atomic_long_add(1 << compound_order(hpage),
90678 + atomic_long_add_unchecked(1 << compound_order(hpage),
90679 &num_poisoned_pages);
90680 } else {
90681 SetPageHWPoison(page);
90682 - atomic_long_inc(&num_poisoned_pages);
90683 + atomic_long_inc_unchecked(&num_poisoned_pages);
90684 }
90685 }
90686 return ret;
90687 @@ -1562,7 +1562,7 @@ static int __soft_offline_page(struct page *page, int flags)
90688 put_page(page);
90689 pr_info("soft_offline: %#lx: invalidated\n", pfn);
90690 SetPageHWPoison(page);
90691 - atomic_long_inc(&num_poisoned_pages);
90692 + atomic_long_inc_unchecked(&num_poisoned_pages);
90693 return 0;
90694 }
90695
90696 @@ -1607,7 +1607,7 @@ static int __soft_offline_page(struct page *page, int flags)
90697 if (!is_free_buddy_page(page))
90698 pr_info("soft offline: %#lx: page leaked\n",
90699 pfn);
90700 - atomic_long_inc(&num_poisoned_pages);
90701 + atomic_long_inc_unchecked(&num_poisoned_pages);
90702 }
90703 } else {
90704 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
90705 @@ -1681,11 +1681,11 @@ int soft_offline_page(struct page *page, int flags)
90706 if (PageHuge(page)) {
90707 set_page_hwpoison_huge_page(hpage);
90708 dequeue_hwpoisoned_huge_page(hpage);
90709 - atomic_long_add(1 << compound_order(hpage),
90710 + atomic_long_add_unchecked(1 << compound_order(hpage),
90711 &num_poisoned_pages);
90712 } else {
90713 SetPageHWPoison(page);
90714 - atomic_long_inc(&num_poisoned_pages);
90715 + atomic_long_inc_unchecked(&num_poisoned_pages);
90716 }
90717 }
90718 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
90719 diff --git a/mm/memory.c b/mm/memory.c
90720 index 6768ce9..4c41d69 100644
90721 --- a/mm/memory.c
90722 +++ b/mm/memory.c
90723 @@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90724 free_pte_range(tlb, pmd, addr);
90725 } while (pmd++, addr = next, addr != end);
90726
90727 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
90728 start &= PUD_MASK;
90729 if (start < floor)
90730 return;
90731 @@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90732 pmd = pmd_offset(pud, start);
90733 pud_clear(pud);
90734 pmd_free_tlb(tlb, pmd, start);
90735 +#endif
90736 +
90737 }
90738
90739 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90740 @@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90741 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
90742 } while (pud++, addr = next, addr != end);
90743
90744 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
90745 start &= PGDIR_MASK;
90746 if (start < floor)
90747 return;
90748 @@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90749 pud = pud_offset(pgd, start);
90750 pgd_clear(pgd);
90751 pud_free_tlb(tlb, pud, start);
90752 +#endif
90753 +
90754 }
90755
90756 /*
90757 @@ -1635,12 +1641,6 @@ no_page_table:
90758 return page;
90759 }
90760
90761 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
90762 -{
90763 - return stack_guard_page_start(vma, addr) ||
90764 - stack_guard_page_end(vma, addr+PAGE_SIZE);
90765 -}
90766 -
90767 /**
90768 * __get_user_pages() - pin user pages in memory
90769 * @tsk: task_struct of target task
90770 @@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90771
90772 i = 0;
90773
90774 - do {
90775 + while (nr_pages) {
90776 struct vm_area_struct *vma;
90777
90778 - vma = find_extend_vma(mm, start);
90779 + vma = find_vma(mm, start);
90780 if (!vma && in_gate_area(mm, start)) {
90781 unsigned long pg = start & PAGE_MASK;
90782 pgd_t *pgd;
90783 @@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90784 goto next_page;
90785 }
90786
90787 - if (!vma ||
90788 + if (!vma || start < vma->vm_start ||
90789 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
90790 !(vm_flags & vma->vm_flags))
90791 return i ? : -EFAULT;
90792 @@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90793 int ret;
90794 unsigned int fault_flags = 0;
90795
90796 - /* For mlock, just skip the stack guard page. */
90797 - if (foll_flags & FOLL_MLOCK) {
90798 - if (stack_guard_page(vma, start))
90799 - goto next_page;
90800 - }
90801 if (foll_flags & FOLL_WRITE)
90802 fault_flags |= FAULT_FLAG_WRITE;
90803 if (nonblocking)
90804 @@ -1892,7 +1887,7 @@ next_page:
90805 start += page_increm * PAGE_SIZE;
90806 nr_pages -= page_increm;
90807 } while (nr_pages && start < vma->vm_end);
90808 - } while (nr_pages);
90809 + }
90810 return i;
90811 }
90812 EXPORT_SYMBOL(__get_user_pages);
90813 @@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
90814 page_add_file_rmap(page);
90815 set_pte_at(mm, addr, pte, mk_pte(page, prot));
90816
90817 +#ifdef CONFIG_PAX_SEGMEXEC
90818 + pax_mirror_file_pte(vma, addr, page, ptl);
90819 +#endif
90820 +
90821 retval = 0;
90822 pte_unmap_unlock(pte, ptl);
90823 return retval;
90824 @@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
90825 if (!page_count(page))
90826 return -EINVAL;
90827 if (!(vma->vm_flags & VM_MIXEDMAP)) {
90828 +
90829 +#ifdef CONFIG_PAX_SEGMEXEC
90830 + struct vm_area_struct *vma_m;
90831 +#endif
90832 +
90833 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
90834 BUG_ON(vma->vm_flags & VM_PFNMAP);
90835 vma->vm_flags |= VM_MIXEDMAP;
90836 +
90837 +#ifdef CONFIG_PAX_SEGMEXEC
90838 + vma_m = pax_find_mirror_vma(vma);
90839 + if (vma_m)
90840 + vma_m->vm_flags |= VM_MIXEDMAP;
90841 +#endif
90842 +
90843 }
90844 return insert_page(vma, addr, page, vma->vm_page_prot);
90845 }
90846 @@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
90847 unsigned long pfn)
90848 {
90849 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
90850 + BUG_ON(vma->vm_mirror);
90851
90852 if (addr < vma->vm_start || addr >= vma->vm_end)
90853 return -EFAULT;
90854 @@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
90855
90856 BUG_ON(pud_huge(*pud));
90857
90858 - pmd = pmd_alloc(mm, pud, addr);
90859 + pmd = (mm == &init_mm) ?
90860 + pmd_alloc_kernel(mm, pud, addr) :
90861 + pmd_alloc(mm, pud, addr);
90862 if (!pmd)
90863 return -ENOMEM;
90864 do {
90865 @@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
90866 unsigned long next;
90867 int err;
90868
90869 - pud = pud_alloc(mm, pgd, addr);
90870 + pud = (mm == &init_mm) ?
90871 + pud_alloc_kernel(mm, pgd, addr) :
90872 + pud_alloc(mm, pgd, addr);
90873 if (!pud)
90874 return -ENOMEM;
90875 do {
90876 @@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
90877 copy_user_highpage(dst, src, va, vma);
90878 }
90879
90880 +#ifdef CONFIG_PAX_SEGMEXEC
90881 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
90882 +{
90883 + struct mm_struct *mm = vma->vm_mm;
90884 + spinlock_t *ptl;
90885 + pte_t *pte, entry;
90886 +
90887 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
90888 + entry = *pte;
90889 + if (!pte_present(entry)) {
90890 + if (!pte_none(entry)) {
90891 + BUG_ON(pte_file(entry));
90892 + free_swap_and_cache(pte_to_swp_entry(entry));
90893 + pte_clear_not_present_full(mm, address, pte, 0);
90894 + }
90895 + } else {
90896 + struct page *page;
90897 +
90898 + flush_cache_page(vma, address, pte_pfn(entry));
90899 + entry = ptep_clear_flush(vma, address, pte);
90900 + BUG_ON(pte_dirty(entry));
90901 + page = vm_normal_page(vma, address, entry);
90902 + if (page) {
90903 + update_hiwater_rss(mm);
90904 + if (PageAnon(page))
90905 + dec_mm_counter_fast(mm, MM_ANONPAGES);
90906 + else
90907 + dec_mm_counter_fast(mm, MM_FILEPAGES);
90908 + page_remove_rmap(page);
90909 + page_cache_release(page);
90910 + }
90911 + }
90912 + pte_unmap_unlock(pte, ptl);
90913 +}
90914 +
90915 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
90916 + *
90917 + * the ptl of the lower mapped page is held on entry and is not released on exit
90918 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
90919 + */
90920 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90921 +{
90922 + struct mm_struct *mm = vma->vm_mm;
90923 + unsigned long address_m;
90924 + spinlock_t *ptl_m;
90925 + struct vm_area_struct *vma_m;
90926 + pmd_t *pmd_m;
90927 + pte_t *pte_m, entry_m;
90928 +
90929 + BUG_ON(!page_m || !PageAnon(page_m));
90930 +
90931 + vma_m = pax_find_mirror_vma(vma);
90932 + if (!vma_m)
90933 + return;
90934 +
90935 + BUG_ON(!PageLocked(page_m));
90936 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90937 + address_m = address + SEGMEXEC_TASK_SIZE;
90938 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90939 + pte_m = pte_offset_map(pmd_m, address_m);
90940 + ptl_m = pte_lockptr(mm, pmd_m);
90941 + if (ptl != ptl_m) {
90942 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90943 + if (!pte_none(*pte_m))
90944 + goto out;
90945 + }
90946 +
90947 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90948 + page_cache_get(page_m);
90949 + page_add_anon_rmap(page_m, vma_m, address_m);
90950 + inc_mm_counter_fast(mm, MM_ANONPAGES);
90951 + set_pte_at(mm, address_m, pte_m, entry_m);
90952 + update_mmu_cache(vma_m, address_m, pte_m);
90953 +out:
90954 + if (ptl != ptl_m)
90955 + spin_unlock(ptl_m);
90956 + pte_unmap(pte_m);
90957 + unlock_page(page_m);
90958 +}
90959 +
90960 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90961 +{
90962 + struct mm_struct *mm = vma->vm_mm;
90963 + unsigned long address_m;
90964 + spinlock_t *ptl_m;
90965 + struct vm_area_struct *vma_m;
90966 + pmd_t *pmd_m;
90967 + pte_t *pte_m, entry_m;
90968 +
90969 + BUG_ON(!page_m || PageAnon(page_m));
90970 +
90971 + vma_m = pax_find_mirror_vma(vma);
90972 + if (!vma_m)
90973 + return;
90974 +
90975 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90976 + address_m = address + SEGMEXEC_TASK_SIZE;
90977 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90978 + pte_m = pte_offset_map(pmd_m, address_m);
90979 + ptl_m = pte_lockptr(mm, pmd_m);
90980 + if (ptl != ptl_m) {
90981 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90982 + if (!pte_none(*pte_m))
90983 + goto out;
90984 + }
90985 +
90986 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90987 + page_cache_get(page_m);
90988 + page_add_file_rmap(page_m);
90989 + inc_mm_counter_fast(mm, MM_FILEPAGES);
90990 + set_pte_at(mm, address_m, pte_m, entry_m);
90991 + update_mmu_cache(vma_m, address_m, pte_m);
90992 +out:
90993 + if (ptl != ptl_m)
90994 + spin_unlock(ptl_m);
90995 + pte_unmap(pte_m);
90996 +}
90997 +
90998 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
90999 +{
91000 + struct mm_struct *mm = vma->vm_mm;
91001 + unsigned long address_m;
91002 + spinlock_t *ptl_m;
91003 + struct vm_area_struct *vma_m;
91004 + pmd_t *pmd_m;
91005 + pte_t *pte_m, entry_m;
91006 +
91007 + vma_m = pax_find_mirror_vma(vma);
91008 + if (!vma_m)
91009 + return;
91010 +
91011 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91012 + address_m = address + SEGMEXEC_TASK_SIZE;
91013 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91014 + pte_m = pte_offset_map(pmd_m, address_m);
91015 + ptl_m = pte_lockptr(mm, pmd_m);
91016 + if (ptl != ptl_m) {
91017 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91018 + if (!pte_none(*pte_m))
91019 + goto out;
91020 + }
91021 +
91022 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
91023 + set_pte_at(mm, address_m, pte_m, entry_m);
91024 +out:
91025 + if (ptl != ptl_m)
91026 + spin_unlock(ptl_m);
91027 + pte_unmap(pte_m);
91028 +}
91029 +
91030 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
91031 +{
91032 + struct page *page_m;
91033 + pte_t entry;
91034 +
91035 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
91036 + goto out;
91037 +
91038 + entry = *pte;
91039 + page_m = vm_normal_page(vma, address, entry);
91040 + if (!page_m)
91041 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
91042 + else if (PageAnon(page_m)) {
91043 + if (pax_find_mirror_vma(vma)) {
91044 + pte_unmap_unlock(pte, ptl);
91045 + lock_page(page_m);
91046 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
91047 + if (pte_same(entry, *pte))
91048 + pax_mirror_anon_pte(vma, address, page_m, ptl);
91049 + else
91050 + unlock_page(page_m);
91051 + }
91052 + } else
91053 + pax_mirror_file_pte(vma, address, page_m, ptl);
91054 +
91055 +out:
91056 + pte_unmap_unlock(pte, ptl);
91057 +}
91058 +#endif
91059 +
91060 /*
91061 * This routine handles present pages, when users try to write
91062 * to a shared page. It is done by copying the page to a new address
91063 @@ -2807,6 +3003,12 @@ gotten:
91064 */
91065 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
91066 if (likely(pte_same(*page_table, orig_pte))) {
91067 +
91068 +#ifdef CONFIG_PAX_SEGMEXEC
91069 + if (pax_find_mirror_vma(vma))
91070 + BUG_ON(!trylock_page(new_page));
91071 +#endif
91072 +
91073 if (old_page) {
91074 if (!PageAnon(old_page)) {
91075 dec_mm_counter_fast(mm, MM_FILEPAGES);
91076 @@ -2858,6 +3060,10 @@ gotten:
91077 page_remove_rmap(old_page);
91078 }
91079
91080 +#ifdef CONFIG_PAX_SEGMEXEC
91081 + pax_mirror_anon_pte(vma, address, new_page, ptl);
91082 +#endif
91083 +
91084 /* Free the old page.. */
91085 new_page = old_page;
91086 ret |= VM_FAULT_WRITE;
91087 @@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91088 swap_free(entry);
91089 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
91090 try_to_free_swap(page);
91091 +
91092 +#ifdef CONFIG_PAX_SEGMEXEC
91093 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
91094 +#endif
91095 +
91096 unlock_page(page);
91097 if (page != swapcache) {
91098 /*
91099 @@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91100
91101 /* No need to invalidate - it was non-present before */
91102 update_mmu_cache(vma, address, page_table);
91103 +
91104 +#ifdef CONFIG_PAX_SEGMEXEC
91105 + pax_mirror_anon_pte(vma, address, page, ptl);
91106 +#endif
91107 +
91108 unlock:
91109 pte_unmap_unlock(page_table, ptl);
91110 out:
91111 @@ -3177,40 +3393,6 @@ out_release:
91112 }
91113
91114 /*
91115 - * This is like a special single-page "expand_{down|up}wards()",
91116 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
91117 - * doesn't hit another vma.
91118 - */
91119 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
91120 -{
91121 - address &= PAGE_MASK;
91122 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
91123 - struct vm_area_struct *prev = vma->vm_prev;
91124 -
91125 - /*
91126 - * Is there a mapping abutting this one below?
91127 - *
91128 - * That's only ok if it's the same stack mapping
91129 - * that has gotten split..
91130 - */
91131 - if (prev && prev->vm_end == address)
91132 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
91133 -
91134 - expand_downwards(vma, address - PAGE_SIZE);
91135 - }
91136 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
91137 - struct vm_area_struct *next = vma->vm_next;
91138 -
91139 - /* As VM_GROWSDOWN but s/below/above/ */
91140 - if (next && next->vm_start == address + PAGE_SIZE)
91141 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
91142 -
91143 - expand_upwards(vma, address + PAGE_SIZE);
91144 - }
91145 - return 0;
91146 -}
91147 -
91148 -/*
91149 * We enter with non-exclusive mmap_sem (to exclude vma changes,
91150 * but allow concurrent faults), and pte mapped but not yet locked.
91151 * We return with mmap_sem still held, but pte unmapped and unlocked.
91152 @@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91153 unsigned long address, pte_t *page_table, pmd_t *pmd,
91154 unsigned int flags)
91155 {
91156 - struct page *page;
91157 + struct page *page = NULL;
91158 spinlock_t *ptl;
91159 pte_t entry;
91160
91161 - pte_unmap(page_table);
91162 -
91163 - /* Check if we need to add a guard page to the stack */
91164 - if (check_stack_guard_page(vma, address) < 0)
91165 - return VM_FAULT_SIGBUS;
91166 -
91167 - /* Use the zero-page for reads */
91168 if (!(flags & FAULT_FLAG_WRITE)) {
91169 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
91170 vma->vm_page_prot));
91171 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
91172 + ptl = pte_lockptr(mm, pmd);
91173 + spin_lock(ptl);
91174 if (!pte_none(*page_table))
91175 goto unlock;
91176 goto setpte;
91177 }
91178
91179 /* Allocate our own private page. */
91180 + pte_unmap(page_table);
91181 +
91182 if (unlikely(anon_vma_prepare(vma)))
91183 goto oom;
91184 page = alloc_zeroed_user_highpage_movable(vma, address);
91185 @@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91186 if (!pte_none(*page_table))
91187 goto release;
91188
91189 +#ifdef CONFIG_PAX_SEGMEXEC
91190 + if (pax_find_mirror_vma(vma))
91191 + BUG_ON(!trylock_page(page));
91192 +#endif
91193 +
91194 inc_mm_counter_fast(mm, MM_ANONPAGES);
91195 page_add_new_anon_rmap(page, vma, address);
91196 setpte:
91197 @@ -3270,6 +3453,12 @@ setpte:
91198
91199 /* No need to invalidate - it was non-present before */
91200 update_mmu_cache(vma, address, page_table);
91201 +
91202 +#ifdef CONFIG_PAX_SEGMEXEC
91203 + if (page)
91204 + pax_mirror_anon_pte(vma, address, page, ptl);
91205 +#endif
91206 +
91207 unlock:
91208 pte_unmap_unlock(page_table, ptl);
91209 return 0;
91210 @@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91211 */
91212 /* Only go through if we didn't race with anybody else... */
91213 if (likely(pte_same(*page_table, orig_pte))) {
91214 +
91215 +#ifdef CONFIG_PAX_SEGMEXEC
91216 + if (anon && pax_find_mirror_vma(vma))
91217 + BUG_ON(!trylock_page(page));
91218 +#endif
91219 +
91220 flush_icache_page(vma, page);
91221 entry = mk_pte(page, vma->vm_page_prot);
91222 if (flags & FAULT_FLAG_WRITE)
91223 @@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91224
91225 /* no need to invalidate: a not-present page won't be cached */
91226 update_mmu_cache(vma, address, page_table);
91227 +
91228 +#ifdef CONFIG_PAX_SEGMEXEC
91229 + if (anon)
91230 + pax_mirror_anon_pte(vma, address, page, ptl);
91231 + else
91232 + pax_mirror_file_pte(vma, address, page, ptl);
91233 +#endif
91234 +
91235 } else {
91236 if (cow_page)
91237 mem_cgroup_uncharge_page(cow_page);
91238 @@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
91239 if (flags & FAULT_FLAG_WRITE)
91240 flush_tlb_fix_spurious_fault(vma, address);
91241 }
91242 +
91243 +#ifdef CONFIG_PAX_SEGMEXEC
91244 + pax_mirror_pte(vma, address, pte, pmd, ptl);
91245 + return 0;
91246 +#endif
91247 +
91248 unlock:
91249 pte_unmap_unlock(pte, ptl);
91250 return 0;
91251 @@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91252 pmd_t *pmd;
91253 pte_t *pte;
91254
91255 +#ifdef CONFIG_PAX_SEGMEXEC
91256 + struct vm_area_struct *vma_m;
91257 +#endif
91258 +
91259 if (unlikely(is_vm_hugetlb_page(vma)))
91260 return hugetlb_fault(mm, vma, address, flags);
91261
91262 +#ifdef CONFIG_PAX_SEGMEXEC
91263 + vma_m = pax_find_mirror_vma(vma);
91264 + if (vma_m) {
91265 + unsigned long address_m;
91266 + pgd_t *pgd_m;
91267 + pud_t *pud_m;
91268 + pmd_t *pmd_m;
91269 +
91270 + if (vma->vm_start > vma_m->vm_start) {
91271 + address_m = address;
91272 + address -= SEGMEXEC_TASK_SIZE;
91273 + vma = vma_m;
91274 + } else
91275 + address_m = address + SEGMEXEC_TASK_SIZE;
91276 +
91277 + pgd_m = pgd_offset(mm, address_m);
91278 + pud_m = pud_alloc(mm, pgd_m, address_m);
91279 + if (!pud_m)
91280 + return VM_FAULT_OOM;
91281 + pmd_m = pmd_alloc(mm, pud_m, address_m);
91282 + if (!pmd_m)
91283 + return VM_FAULT_OOM;
91284 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
91285 + return VM_FAULT_OOM;
91286 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
91287 + }
91288 +#endif
91289 +
91290 retry:
91291 pgd = pgd_offset(mm, address);
91292 pud = pud_alloc(mm, pgd, address);
91293 @@ -3838,6 +4079,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91294 spin_unlock(&mm->page_table_lock);
91295 return 0;
91296 }
91297 +
91298 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91299 +{
91300 + pud_t *new = pud_alloc_one(mm, address);
91301 + if (!new)
91302 + return -ENOMEM;
91303 +
91304 + smp_wmb(); /* See comment in __pte_alloc */
91305 +
91306 + spin_lock(&mm->page_table_lock);
91307 + if (pgd_present(*pgd)) /* Another has populated it */
91308 + pud_free(mm, new);
91309 + else
91310 + pgd_populate_kernel(mm, pgd, new);
91311 + spin_unlock(&mm->page_table_lock);
91312 + return 0;
91313 +}
91314 #endif /* __PAGETABLE_PUD_FOLDED */
91315
91316 #ifndef __PAGETABLE_PMD_FOLDED
91317 @@ -3868,6 +4126,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
91318 spin_unlock(&mm->page_table_lock);
91319 return 0;
91320 }
91321 +
91322 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
91323 +{
91324 + pmd_t *new = pmd_alloc_one(mm, address);
91325 + if (!new)
91326 + return -ENOMEM;
91327 +
91328 + smp_wmb(); /* See comment in __pte_alloc */
91329 +
91330 + spin_lock(&mm->page_table_lock);
91331 +#ifndef __ARCH_HAS_4LEVEL_HACK
91332 + if (pud_present(*pud)) /* Another has populated it */
91333 + pmd_free(mm, new);
91334 + else
91335 + pud_populate_kernel(mm, pud, new);
91336 +#else
91337 + if (pgd_present(*pud)) /* Another has populated it */
91338 + pmd_free(mm, new);
91339 + else
91340 + pgd_populate_kernel(mm, pud, new);
91341 +#endif /* __ARCH_HAS_4LEVEL_HACK */
91342 + spin_unlock(&mm->page_table_lock);
91343 + return 0;
91344 +}
91345 #endif /* __PAGETABLE_PMD_FOLDED */
91346
91347 #if !defined(__HAVE_ARCH_GATE_AREA)
91348 @@ -3881,7 +4163,7 @@ static int __init gate_vma_init(void)
91349 gate_vma.vm_start = FIXADDR_USER_START;
91350 gate_vma.vm_end = FIXADDR_USER_END;
91351 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
91352 - gate_vma.vm_page_prot = __P101;
91353 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
91354
91355 return 0;
91356 }
91357 @@ -4015,8 +4297,8 @@ out:
91358 return ret;
91359 }
91360
91361 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91362 - void *buf, int len, int write)
91363 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91364 + void *buf, size_t len, int write)
91365 {
91366 resource_size_t phys_addr;
91367 unsigned long prot = 0;
91368 @@ -4042,8 +4324,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
91369 * Access another process' address space as given in mm. If non-NULL, use the
91370 * given task for page fault accounting.
91371 */
91372 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91373 - unsigned long addr, void *buf, int len, int write)
91374 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91375 + unsigned long addr, void *buf, size_t len, int write)
91376 {
91377 struct vm_area_struct *vma;
91378 void *old_buf = buf;
91379 @@ -4051,7 +4333,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91380 down_read(&mm->mmap_sem);
91381 /* ignore errors, just check how much was successfully transferred */
91382 while (len) {
91383 - int bytes, ret, offset;
91384 + ssize_t bytes, ret, offset;
91385 void *maddr;
91386 struct page *page = NULL;
91387
91388 @@ -4110,8 +4392,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91389 *
91390 * The caller must hold a reference on @mm.
91391 */
91392 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91393 - void *buf, int len, int write)
91394 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
91395 + void *buf, size_t len, int write)
91396 {
91397 return __access_remote_vm(NULL, mm, addr, buf, len, write);
91398 }
91399 @@ -4121,11 +4403,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91400 * Source/target buffer must be kernel space,
91401 * Do not walk the page table directly, use get_user_pages
91402 */
91403 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
91404 - void *buf, int len, int write)
91405 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
91406 + void *buf, size_t len, int write)
91407 {
91408 struct mm_struct *mm;
91409 - int ret;
91410 + ssize_t ret;
91411
91412 mm = get_task_mm(tsk);
91413 if (!mm)
91414 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
91415 index e1bd997..055f496 100644
91416 --- a/mm/mempolicy.c
91417 +++ b/mm/mempolicy.c
91418 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91419 unsigned long vmstart;
91420 unsigned long vmend;
91421
91422 +#ifdef CONFIG_PAX_SEGMEXEC
91423 + struct vm_area_struct *vma_m;
91424 +#endif
91425 +
91426 vma = find_vma(mm, start);
91427 if (!vma || vma->vm_start > start)
91428 return -EFAULT;
91429 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91430 err = vma_replace_policy(vma, new_pol);
91431 if (err)
91432 goto out;
91433 +
91434 +#ifdef CONFIG_PAX_SEGMEXEC
91435 + vma_m = pax_find_mirror_vma(vma);
91436 + if (vma_m) {
91437 + err = vma_replace_policy(vma_m, new_pol);
91438 + if (err)
91439 + goto out;
91440 + }
91441 +#endif
91442 +
91443 }
91444
91445 out:
91446 @@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
91447
91448 if (end < start)
91449 return -EINVAL;
91450 +
91451 +#ifdef CONFIG_PAX_SEGMEXEC
91452 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
91453 + if (end > SEGMEXEC_TASK_SIZE)
91454 + return -EINVAL;
91455 + } else
91456 +#endif
91457 +
91458 + if (end > TASK_SIZE)
91459 + return -EINVAL;
91460 +
91461 if (end == start)
91462 return 0;
91463
91464 @@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91465 */
91466 tcred = __task_cred(task);
91467 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91468 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91469 - !capable(CAP_SYS_NICE)) {
91470 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91471 rcu_read_unlock();
91472 err = -EPERM;
91473 goto out_put;
91474 @@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91475 goto out;
91476 }
91477
91478 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
91479 + if (mm != current->mm &&
91480 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
91481 + mmput(mm);
91482 + err = -EPERM;
91483 + goto out;
91484 + }
91485 +#endif
91486 +
91487 err = do_migrate_pages(mm, old, new,
91488 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
91489
91490 diff --git a/mm/migrate.c b/mm/migrate.c
91491 index 9194375..75c81e2 100644
91492 --- a/mm/migrate.c
91493 +++ b/mm/migrate.c
91494 @@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
91495 */
91496 tcred = __task_cred(task);
91497 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91498 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91499 - !capable(CAP_SYS_NICE)) {
91500 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91501 rcu_read_unlock();
91502 err = -EPERM;
91503 goto out;
91504 diff --git a/mm/mlock.c b/mm/mlock.c
91505 index 192e6ee..b044449 100644
91506 --- a/mm/mlock.c
91507 +++ b/mm/mlock.c
91508 @@ -14,6 +14,7 @@
91509 #include <linux/pagevec.h>
91510 #include <linux/mempolicy.h>
91511 #include <linux/syscalls.h>
91512 +#include <linux/security.h>
91513 #include <linux/sched.h>
91514 #include <linux/export.h>
91515 #include <linux/rmap.h>
91516 @@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
91517 {
91518 unsigned long nstart, end, tmp;
91519 struct vm_area_struct * vma, * prev;
91520 - int error;
91521 + int error = 0;
91522
91523 VM_BUG_ON(start & ~PAGE_MASK);
91524 VM_BUG_ON(len != PAGE_ALIGN(len));
91525 @@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
91526 return -EINVAL;
91527 if (end == start)
91528 return 0;
91529 + if (end > TASK_SIZE)
91530 + return -EINVAL;
91531 +
91532 vma = find_vma(current->mm, start);
91533 if (!vma || vma->vm_start > start)
91534 return -ENOMEM;
91535 @@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
91536 for (nstart = start ; ; ) {
91537 vm_flags_t newflags;
91538
91539 +#ifdef CONFIG_PAX_SEGMEXEC
91540 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91541 + break;
91542 +#endif
91543 +
91544 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
91545
91546 newflags = vma->vm_flags & ~VM_LOCKED;
91547 @@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
91548 lock_limit >>= PAGE_SHIFT;
91549
91550 /* check against resource limits */
91551 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
91552 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
91553 error = do_mlock(start, len, 1);
91554 up_write(&current->mm->mmap_sem);
91555 @@ -754,6 +764,11 @@ static int do_mlockall(int flags)
91556 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
91557 vm_flags_t newflags;
91558
91559 +#ifdef CONFIG_PAX_SEGMEXEC
91560 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91561 + break;
91562 +#endif
91563 +
91564 newflags = vma->vm_flags & ~VM_LOCKED;
91565 if (flags & MCL_CURRENT)
91566 newflags |= VM_LOCKED;
91567 @@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
91568 lock_limit >>= PAGE_SHIFT;
91569
91570 ret = -ENOMEM;
91571 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
91572 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
91573 capable(CAP_IPC_LOCK))
91574 ret = do_mlockall(flags);
91575 diff --git a/mm/mmap.c b/mm/mmap.c
91576 index 834b2d7..650d1b9 100644
91577 --- a/mm/mmap.c
91578 +++ b/mm/mmap.c
91579 @@ -36,6 +36,7 @@
91580 #include <linux/sched/sysctl.h>
91581 #include <linux/notifier.h>
91582 #include <linux/memory.h>
91583 +#include <linux/random.h>
91584
91585 #include <asm/uaccess.h>
91586 #include <asm/cacheflush.h>
91587 @@ -52,6 +53,16 @@
91588 #define arch_rebalance_pgtables(addr, len) (addr)
91589 #endif
91590
91591 +static inline void verify_mm_writelocked(struct mm_struct *mm)
91592 +{
91593 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
91594 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
91595 + up_read(&mm->mmap_sem);
91596 + BUG();
91597 + }
91598 +#endif
91599 +}
91600 +
91601 static void unmap_region(struct mm_struct *mm,
91602 struct vm_area_struct *vma, struct vm_area_struct *prev,
91603 unsigned long start, unsigned long end);
91604 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
91605 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
91606 *
91607 */
91608 -pgprot_t protection_map[16] = {
91609 +pgprot_t protection_map[16] __read_only = {
91610 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
91611 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
91612 };
91613
91614 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
91615 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
91616 {
91617 - return __pgprot(pgprot_val(protection_map[vm_flags &
91618 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
91619 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
91620 pgprot_val(arch_vm_get_page_prot(vm_flags)));
91621 +
91622 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91623 + if (!(__supported_pte_mask & _PAGE_NX) &&
91624 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
91625 + (vm_flags & (VM_READ | VM_WRITE)))
91626 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
91627 +#endif
91628 +
91629 + return prot;
91630 }
91631 EXPORT_SYMBOL(vm_get_page_prot);
91632
91633 @@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
91634 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
91635 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91636 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
91637 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
91638 /*
91639 * Make sure vm_committed_as in one cacheline and not cacheline shared with
91640 * other variables. It can be updated by several CPUs frequently.
91641 @@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
91642 struct vm_area_struct *next = vma->vm_next;
91643
91644 might_sleep();
91645 + BUG_ON(vma->vm_mirror);
91646 if (vma->vm_ops && vma->vm_ops->close)
91647 vma->vm_ops->close(vma);
91648 if (vma->vm_file)
91649 @@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
91650 * not page aligned -Ram Gupta
91651 */
91652 rlim = rlimit(RLIMIT_DATA);
91653 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
91654 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
91655 (mm->end_data - mm->start_data) > rlim)
91656 goto out;
91657 @@ -893,7 +916,15 @@ again: remove_next = 1 + (end > next->vm_end);
91658 static inline int is_mergeable_vma(struct vm_area_struct *vma,
91659 struct file *file, unsigned long vm_flags)
91660 {
91661 - if (vma->vm_flags ^ vm_flags)
91662 + /*
91663 + * VM_SOFTDIRTY should not prevent from VMA merging, if we
91664 + * match the flags but dirty bit -- the caller should mark
91665 + * merged VMA as dirty. If dirty bit won't be excluded from
91666 + * comparison, we increase pressue on the memory system forcing
91667 + * the kernel to generate new VMAs when old one could be
91668 + * extended instead.
91669 + */
91670 + if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY)
91671 return 0;
91672 if (vma->vm_file != file)
91673 return 0;
91674 @@ -931,6 +962,12 @@ static int
91675 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
91676 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91677 {
91678 +
91679 +#ifdef CONFIG_PAX_SEGMEXEC
91680 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
91681 + return 0;
91682 +#endif
91683 +
91684 if (is_mergeable_vma(vma, file, vm_flags) &&
91685 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91686 if (vma->vm_pgoff == vm_pgoff)
91687 @@ -950,6 +987,12 @@ static int
91688 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91689 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91690 {
91691 +
91692 +#ifdef CONFIG_PAX_SEGMEXEC
91693 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
91694 + return 0;
91695 +#endif
91696 +
91697 if (is_mergeable_vma(vma, file, vm_flags) &&
91698 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91699 pgoff_t vm_pglen;
91700 @@ -992,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91701 struct vm_area_struct *vma_merge(struct mm_struct *mm,
91702 struct vm_area_struct *prev, unsigned long addr,
91703 unsigned long end, unsigned long vm_flags,
91704 - struct anon_vma *anon_vma, struct file *file,
91705 + struct anon_vma *anon_vma, struct file *file,
91706 pgoff_t pgoff, struct mempolicy *policy)
91707 {
91708 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
91709 struct vm_area_struct *area, *next;
91710 int err;
91711
91712 +#ifdef CONFIG_PAX_SEGMEXEC
91713 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
91714 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
91715 +
91716 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
91717 +#endif
91718 +
91719 /*
91720 * We later require that vma->vm_flags == vm_flags,
91721 * so this tests vma->vm_flags & VM_SPECIAL, too.
91722 @@ -1014,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91723 if (next && next->vm_end == end) /* cases 6, 7, 8 */
91724 next = next->vm_next;
91725
91726 +#ifdef CONFIG_PAX_SEGMEXEC
91727 + if (prev)
91728 + prev_m = pax_find_mirror_vma(prev);
91729 + if (area)
91730 + area_m = pax_find_mirror_vma(area);
91731 + if (next)
91732 + next_m = pax_find_mirror_vma(next);
91733 +#endif
91734 +
91735 /*
91736 * Can it merge with the predecessor?
91737 */
91738 @@ -1033,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91739 /* cases 1, 6 */
91740 err = vma_adjust(prev, prev->vm_start,
91741 next->vm_end, prev->vm_pgoff, NULL);
91742 - } else /* cases 2, 5, 7 */
91743 +
91744 +#ifdef CONFIG_PAX_SEGMEXEC
91745 + if (!err && prev_m)
91746 + err = vma_adjust(prev_m, prev_m->vm_start,
91747 + next_m->vm_end, prev_m->vm_pgoff, NULL);
91748 +#endif
91749 +
91750 + } else { /* cases 2, 5, 7 */
91751 err = vma_adjust(prev, prev->vm_start,
91752 end, prev->vm_pgoff, NULL);
91753 +
91754 +#ifdef CONFIG_PAX_SEGMEXEC
91755 + if (!err && prev_m)
91756 + err = vma_adjust(prev_m, prev_m->vm_start,
91757 + end_m, prev_m->vm_pgoff, NULL);
91758 +#endif
91759 +
91760 + }
91761 if (err)
91762 return NULL;
91763 khugepaged_enter_vma_merge(prev);
91764 @@ -1049,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91765 mpol_equal(policy, vma_policy(next)) &&
91766 can_vma_merge_before(next, vm_flags,
91767 anon_vma, file, pgoff+pglen)) {
91768 - if (prev && addr < prev->vm_end) /* case 4 */
91769 + if (prev && addr < prev->vm_end) { /* case 4 */
91770 err = vma_adjust(prev, prev->vm_start,
91771 addr, prev->vm_pgoff, NULL);
91772 - else /* cases 3, 8 */
91773 +
91774 +#ifdef CONFIG_PAX_SEGMEXEC
91775 + if (!err && prev_m)
91776 + err = vma_adjust(prev_m, prev_m->vm_start,
91777 + addr_m, prev_m->vm_pgoff, NULL);
91778 +#endif
91779 +
91780 + } else { /* cases 3, 8 */
91781 err = vma_adjust(area, addr, next->vm_end,
91782 next->vm_pgoff - pglen, NULL);
91783 +
91784 +#ifdef CONFIG_PAX_SEGMEXEC
91785 + if (!err && area_m)
91786 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
91787 + next_m->vm_pgoff - pglen, NULL);
91788 +#endif
91789 +
91790 + }
91791 if (err)
91792 return NULL;
91793 khugepaged_enter_vma_merge(area);
91794 @@ -1082,7 +1171,7 @@ static int anon_vma_compatible(struct vm_area_struct *a, struct vm_area_struct *
91795 return a->vm_end == b->vm_start &&
91796 mpol_equal(vma_policy(a), vma_policy(b)) &&
91797 a->vm_file == b->vm_file &&
91798 - !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC)) &&
91799 + !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC|VM_SOFTDIRTY)) &&
91800 b->vm_pgoff == a->vm_pgoff + ((b->vm_start - a->vm_start) >> PAGE_SHIFT);
91801 }
91802
91803 @@ -1163,8 +1252,10 @@ none:
91804 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91805 struct file *file, long pages)
91806 {
91807 - const unsigned long stack_flags
91808 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
91809 +
91810 +#ifdef CONFIG_PAX_RANDMMAP
91811 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91812 +#endif
91813
91814 mm->total_vm += pages;
91815
91816 @@ -1172,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91817 mm->shared_vm += pages;
91818 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
91819 mm->exec_vm += pages;
91820 - } else if (flags & stack_flags)
91821 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
91822 mm->stack_vm += pages;
91823 }
91824 #endif /* CONFIG_PROC_FS */
91825 @@ -1210,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91826 * (the exception is when the underlying filesystem is noexec
91827 * mounted, in which case we dont add PROT_EXEC.)
91828 */
91829 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
91830 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
91831 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
91832 prot |= PROT_EXEC;
91833
91834 @@ -1236,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91835 /* Obtain the address to map to. we verify (or select) it and ensure
91836 * that it represents a valid section of the address space.
91837 */
91838 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
91839 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
91840 if (addr & ~PAGE_MASK)
91841 return addr;
91842
91843 @@ -1247,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91844 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
91845 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
91846
91847 +#ifdef CONFIG_PAX_MPROTECT
91848 + if (mm->pax_flags & MF_PAX_MPROTECT) {
91849 +
91850 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
91851 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
91852 + mm->binfmt->handle_mmap)
91853 + mm->binfmt->handle_mmap(file);
91854 +#endif
91855 +
91856 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
91857 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
91858 + gr_log_rwxmmap(file);
91859 +
91860 +#ifdef CONFIG_PAX_EMUPLT
91861 + vm_flags &= ~VM_EXEC;
91862 +#else
91863 + return -EPERM;
91864 +#endif
91865 +
91866 + }
91867 +
91868 + if (!(vm_flags & VM_EXEC))
91869 + vm_flags &= ~VM_MAYEXEC;
91870 +#else
91871 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
91872 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
91873 +#endif
91874 + else
91875 + vm_flags &= ~VM_MAYWRITE;
91876 + }
91877 +#endif
91878 +
91879 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91880 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
91881 + vm_flags &= ~VM_PAGEEXEC;
91882 +#endif
91883 +
91884 if (flags & MAP_LOCKED)
91885 if (!can_do_mlock())
91886 return -EPERM;
91887 @@ -1258,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91888 locked += mm->locked_vm;
91889 lock_limit = rlimit(RLIMIT_MEMLOCK);
91890 lock_limit >>= PAGE_SHIFT;
91891 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
91892 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
91893 return -EAGAIN;
91894 }
91895 @@ -1342,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91896 vm_flags |= VM_NORESERVE;
91897 }
91898
91899 + if (!gr_acl_handle_mmap(file, prot))
91900 + return -EACCES;
91901 +
91902 addr = mmap_region(file, addr, len, vm_flags, pgoff);
91903 if (!IS_ERR_VALUE(addr) &&
91904 ((vm_flags & VM_LOCKED) ||
91905 @@ -1435,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
91906 vm_flags_t vm_flags = vma->vm_flags;
91907
91908 /* If it was private or non-writable, the write bit is already clear */
91909 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
91910 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
91911 return 0;
91912
91913 /* The backer wishes to know when pages are first written to? */
91914 @@ -1481,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91915 struct rb_node **rb_link, *rb_parent;
91916 unsigned long charged = 0;
91917
91918 +#ifdef CONFIG_PAX_SEGMEXEC
91919 + struct vm_area_struct *vma_m = NULL;
91920 +#endif
91921 +
91922 + /*
91923 + * mm->mmap_sem is required to protect against another thread
91924 + * changing the mappings in case we sleep.
91925 + */
91926 + verify_mm_writelocked(mm);
91927 +
91928 /* Check against address space limit. */
91929 +
91930 +#ifdef CONFIG_PAX_RANDMMAP
91931 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91932 +#endif
91933 +
91934 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
91935 unsigned long nr_pages;
91936
91937 @@ -1500,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91938
91939 /* Clear old maps */
91940 error = -ENOMEM;
91941 -munmap_back:
91942 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
91943 if (do_munmap(mm, addr, len))
91944 return -ENOMEM;
91945 - goto munmap_back;
91946 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
91947 }
91948
91949 /*
91950 @@ -1535,6 +1681,16 @@ munmap_back:
91951 goto unacct_error;
91952 }
91953
91954 +#ifdef CONFIG_PAX_SEGMEXEC
91955 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
91956 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
91957 + if (!vma_m) {
91958 + error = -ENOMEM;
91959 + goto free_vma;
91960 + }
91961 + }
91962 +#endif
91963 +
91964 vma->vm_mm = mm;
91965 vma->vm_start = addr;
91966 vma->vm_end = addr + len;
91967 @@ -1554,6 +1710,13 @@ munmap_back:
91968 if (error)
91969 goto unmap_and_free_vma;
91970
91971 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91972 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
91973 + vma->vm_flags |= VM_PAGEEXEC;
91974 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
91975 + }
91976 +#endif
91977 +
91978 /* Can addr have changed??
91979 *
91980 * Answer: Yes, several device drivers can do it in their
91981 @@ -1587,6 +1750,12 @@ munmap_back:
91982 }
91983
91984 vma_link(mm, vma, prev, rb_link, rb_parent);
91985 +
91986 +#ifdef CONFIG_PAX_SEGMEXEC
91987 + if (vma_m)
91988 + BUG_ON(pax_mirror_vma(vma_m, vma));
91989 +#endif
91990 +
91991 /* Once vma denies write, undo our temporary denial count */
91992 if (vm_flags & VM_DENYWRITE)
91993 allow_write_access(file);
91994 @@ -1595,6 +1764,7 @@ out:
91995 perf_event_mmap(vma);
91996
91997 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
91998 + track_exec_limit(mm, addr, addr + len, vm_flags);
91999 if (vm_flags & VM_LOCKED) {
92000 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
92001 vma == get_gate_vma(current->mm)))
92002 @@ -1627,6 +1797,12 @@ unmap_and_free_vma:
92003 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
92004 charged = 0;
92005 free_vma:
92006 +
92007 +#ifdef CONFIG_PAX_SEGMEXEC
92008 + if (vma_m)
92009 + kmem_cache_free(vm_area_cachep, vma_m);
92010 +#endif
92011 +
92012 kmem_cache_free(vm_area_cachep, vma);
92013 unacct_error:
92014 if (charged)
92015 @@ -1634,7 +1810,63 @@ unacct_error:
92016 return error;
92017 }
92018
92019 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
92020 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
92021 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
92022 +{
92023 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
92024 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
92025 +
92026 + return 0;
92027 +}
92028 +#endif
92029 +
92030 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
92031 +{
92032 + if (!vma) {
92033 +#ifdef CONFIG_STACK_GROWSUP
92034 + if (addr > sysctl_heap_stack_gap)
92035 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
92036 + else
92037 + vma = find_vma(current->mm, 0);
92038 + if (vma && (vma->vm_flags & VM_GROWSUP))
92039 + return false;
92040 +#endif
92041 + return true;
92042 + }
92043 +
92044 + if (addr + len > vma->vm_start)
92045 + return false;
92046 +
92047 + if (vma->vm_flags & VM_GROWSDOWN)
92048 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
92049 +#ifdef CONFIG_STACK_GROWSUP
92050 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
92051 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
92052 +#endif
92053 + else if (offset)
92054 + return offset <= vma->vm_start - addr - len;
92055 +
92056 + return true;
92057 +}
92058 +
92059 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
92060 +{
92061 + if (vma->vm_start < len)
92062 + return -ENOMEM;
92063 +
92064 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
92065 + if (offset <= vma->vm_start - len)
92066 + return vma->vm_start - len - offset;
92067 + else
92068 + return -ENOMEM;
92069 + }
92070 +
92071 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
92072 + return vma->vm_start - len - sysctl_heap_stack_gap;
92073 + return -ENOMEM;
92074 +}
92075 +
92076 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
92077 {
92078 /*
92079 * We implement the search by looking for an rbtree node that
92080 @@ -1682,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
92081 }
92082 }
92083
92084 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
92085 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
92086 check_current:
92087 /* Check if current node has a suitable gap */
92088 if (gap_start > high_limit)
92089 return -ENOMEM;
92090 +
92091 + if (gap_end - gap_start > info->threadstack_offset)
92092 + gap_start += info->threadstack_offset;
92093 + else
92094 + gap_start = gap_end;
92095 +
92096 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92097 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92098 + gap_start += sysctl_heap_stack_gap;
92099 + else
92100 + gap_start = gap_end;
92101 + }
92102 + if (vma->vm_flags & VM_GROWSDOWN) {
92103 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92104 + gap_end -= sysctl_heap_stack_gap;
92105 + else
92106 + gap_end = gap_start;
92107 + }
92108 if (gap_end >= low_limit && gap_end - gap_start >= length)
92109 goto found;
92110
92111 @@ -1736,7 +1986,7 @@ found:
92112 return gap_start;
92113 }
92114
92115 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
92116 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
92117 {
92118 struct mm_struct *mm = current->mm;
92119 struct vm_area_struct *vma;
92120 @@ -1790,6 +2040,24 @@ check_current:
92121 gap_end = vma->vm_start;
92122 if (gap_end < low_limit)
92123 return -ENOMEM;
92124 +
92125 + if (gap_end - gap_start > info->threadstack_offset)
92126 + gap_end -= info->threadstack_offset;
92127 + else
92128 + gap_end = gap_start;
92129 +
92130 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92131 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92132 + gap_start += sysctl_heap_stack_gap;
92133 + else
92134 + gap_start = gap_end;
92135 + }
92136 + if (vma->vm_flags & VM_GROWSDOWN) {
92137 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92138 + gap_end -= sysctl_heap_stack_gap;
92139 + else
92140 + gap_end = gap_start;
92141 + }
92142 if (gap_start <= high_limit && gap_end - gap_start >= length)
92143 goto found;
92144
92145 @@ -1853,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92146 struct mm_struct *mm = current->mm;
92147 struct vm_area_struct *vma;
92148 struct vm_unmapped_area_info info;
92149 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92150
92151 if (len > TASK_SIZE - mmap_min_addr)
92152 return -ENOMEM;
92153 @@ -1860,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92154 if (flags & MAP_FIXED)
92155 return addr;
92156
92157 +#ifdef CONFIG_PAX_RANDMMAP
92158 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92159 +#endif
92160 +
92161 if (addr) {
92162 addr = PAGE_ALIGN(addr);
92163 vma = find_vma(mm, addr);
92164 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92165 - (!vma || addr + len <= vma->vm_start))
92166 + check_heap_stack_gap(vma, addr, len, offset))
92167 return addr;
92168 }
92169
92170 @@ -1873,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92171 info.low_limit = mm->mmap_base;
92172 info.high_limit = TASK_SIZE;
92173 info.align_mask = 0;
92174 + info.threadstack_offset = offset;
92175 return vm_unmapped_area(&info);
92176 }
92177 #endif
92178 @@ -1891,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92179 struct mm_struct *mm = current->mm;
92180 unsigned long addr = addr0;
92181 struct vm_unmapped_area_info info;
92182 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92183
92184 /* requested length too big for entire address space */
92185 if (len > TASK_SIZE - mmap_min_addr)
92186 @@ -1899,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92187 if (flags & MAP_FIXED)
92188 return addr;
92189
92190 +#ifdef CONFIG_PAX_RANDMMAP
92191 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92192 +#endif
92193 +
92194 /* requesting a specific address */
92195 if (addr) {
92196 addr = PAGE_ALIGN(addr);
92197 vma = find_vma(mm, addr);
92198 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92199 - (!vma || addr + len <= vma->vm_start))
92200 + check_heap_stack_gap(vma, addr, len, offset))
92201 return addr;
92202 }
92203
92204 @@ -1913,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92205 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
92206 info.high_limit = mm->mmap_base;
92207 info.align_mask = 0;
92208 + info.threadstack_offset = offset;
92209 addr = vm_unmapped_area(&info);
92210
92211 /*
92212 @@ -1925,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92213 VM_BUG_ON(addr != -ENOMEM);
92214 info.flags = 0;
92215 info.low_limit = TASK_UNMAPPED_BASE;
92216 +
92217 +#ifdef CONFIG_PAX_RANDMMAP
92218 + if (mm->pax_flags & MF_PAX_RANDMMAP)
92219 + info.low_limit += mm->delta_mmap;
92220 +#endif
92221 +
92222 info.high_limit = TASK_SIZE;
92223 addr = vm_unmapped_area(&info);
92224 }
92225 @@ -2026,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
92226 return vma;
92227 }
92228
92229 +#ifdef CONFIG_PAX_SEGMEXEC
92230 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
92231 +{
92232 + struct vm_area_struct *vma_m;
92233 +
92234 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
92235 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
92236 + BUG_ON(vma->vm_mirror);
92237 + return NULL;
92238 + }
92239 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
92240 + vma_m = vma->vm_mirror;
92241 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
92242 + BUG_ON(vma->vm_file != vma_m->vm_file);
92243 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
92244 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
92245 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
92246 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
92247 + return vma_m;
92248 +}
92249 +#endif
92250 +
92251 /*
92252 * Verify that the stack growth is acceptable and
92253 * update accounting. This is shared with both the
92254 @@ -2042,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92255 return -ENOMEM;
92256
92257 /* Stack limit test */
92258 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
92259 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
92260 return -ENOMEM;
92261
92262 @@ -2052,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92263 locked = mm->locked_vm + grow;
92264 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
92265 limit >>= PAGE_SHIFT;
92266 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92267 if (locked > limit && !capable(CAP_IPC_LOCK))
92268 return -ENOMEM;
92269 }
92270 @@ -2081,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92271 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
92272 * vma is the last one with address > vma->vm_end. Have to extend vma.
92273 */
92274 +#ifndef CONFIG_IA64
92275 +static
92276 +#endif
92277 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92278 {
92279 int error;
92280 + bool locknext;
92281
92282 if (!(vma->vm_flags & VM_GROWSUP))
92283 return -EFAULT;
92284
92285 + /* Also guard against wrapping around to address 0. */
92286 + if (address < PAGE_ALIGN(address+1))
92287 + address = PAGE_ALIGN(address+1);
92288 + else
92289 + return -ENOMEM;
92290 +
92291 /*
92292 * We must make sure the anon_vma is allocated
92293 * so that the anon_vma locking is not a noop.
92294 */
92295 if (unlikely(anon_vma_prepare(vma)))
92296 return -ENOMEM;
92297 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
92298 + if (locknext && anon_vma_prepare(vma->vm_next))
92299 + return -ENOMEM;
92300 vma_lock_anon_vma(vma);
92301 + if (locknext)
92302 + vma_lock_anon_vma(vma->vm_next);
92303
92304 /*
92305 * vma->vm_start/vm_end cannot change under us because the caller
92306 * is required to hold the mmap_sem in read mode. We need the
92307 - * anon_vma lock to serialize against concurrent expand_stacks.
92308 - * Also guard against wrapping around to address 0.
92309 + * anon_vma locks to serialize against concurrent expand_stacks
92310 + * and expand_upwards.
92311 */
92312 - if (address < PAGE_ALIGN(address+4))
92313 - address = PAGE_ALIGN(address+4);
92314 - else {
92315 - vma_unlock_anon_vma(vma);
92316 - return -ENOMEM;
92317 - }
92318 error = 0;
92319
92320 /* Somebody else might have raced and expanded it already */
92321 - if (address > vma->vm_end) {
92322 + 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)
92323 + error = -ENOMEM;
92324 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
92325 unsigned long size, grow;
92326
92327 size = address - vma->vm_start;
92328 @@ -2146,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92329 }
92330 }
92331 }
92332 + if (locknext)
92333 + vma_unlock_anon_vma(vma->vm_next);
92334 vma_unlock_anon_vma(vma);
92335 khugepaged_enter_vma_merge(vma);
92336 validate_mm(vma->vm_mm);
92337 @@ -2160,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
92338 unsigned long address)
92339 {
92340 int error;
92341 + bool lockprev = false;
92342 + struct vm_area_struct *prev;
92343
92344 /*
92345 * We must make sure the anon_vma is allocated
92346 @@ -2173,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
92347 if (error)
92348 return error;
92349
92350 + prev = vma->vm_prev;
92351 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
92352 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
92353 +#endif
92354 + if (lockprev && anon_vma_prepare(prev))
92355 + return -ENOMEM;
92356 + if (lockprev)
92357 + vma_lock_anon_vma(prev);
92358 +
92359 vma_lock_anon_vma(vma);
92360
92361 /*
92362 @@ -2182,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
92363 */
92364
92365 /* Somebody else might have raced and expanded it already */
92366 - if (address < vma->vm_start) {
92367 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
92368 + error = -ENOMEM;
92369 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
92370 unsigned long size, grow;
92371
92372 +#ifdef CONFIG_PAX_SEGMEXEC
92373 + struct vm_area_struct *vma_m;
92374 +
92375 + vma_m = pax_find_mirror_vma(vma);
92376 +#endif
92377 +
92378 size = vma->vm_end - address;
92379 grow = (vma->vm_start - address) >> PAGE_SHIFT;
92380
92381 @@ -2209,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
92382 vma->vm_pgoff -= grow;
92383 anon_vma_interval_tree_post_update_vma(vma);
92384 vma_gap_update(vma);
92385 +
92386 +#ifdef CONFIG_PAX_SEGMEXEC
92387 + if (vma_m) {
92388 + anon_vma_interval_tree_pre_update_vma(vma_m);
92389 + vma_m->vm_start -= grow << PAGE_SHIFT;
92390 + vma_m->vm_pgoff -= grow;
92391 + anon_vma_interval_tree_post_update_vma(vma_m);
92392 + vma_gap_update(vma_m);
92393 + }
92394 +#endif
92395 +
92396 spin_unlock(&vma->vm_mm->page_table_lock);
92397
92398 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
92399 perf_event_mmap(vma);
92400 }
92401 }
92402 }
92403 vma_unlock_anon_vma(vma);
92404 + if (lockprev)
92405 + vma_unlock_anon_vma(prev);
92406 khugepaged_enter_vma_merge(vma);
92407 validate_mm(vma->vm_mm);
92408 return error;
92409 @@ -2313,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
92410 do {
92411 long nrpages = vma_pages(vma);
92412
92413 +#ifdef CONFIG_PAX_SEGMEXEC
92414 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
92415 + vma = remove_vma(vma);
92416 + continue;
92417 + }
92418 +#endif
92419 +
92420 if (vma->vm_flags & VM_ACCOUNT)
92421 nr_accounted += nrpages;
92422 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
92423 @@ -2357,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
92424 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
92425 vma->vm_prev = NULL;
92426 do {
92427 +
92428 +#ifdef CONFIG_PAX_SEGMEXEC
92429 + if (vma->vm_mirror) {
92430 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
92431 + vma->vm_mirror->vm_mirror = NULL;
92432 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
92433 + vma->vm_mirror = NULL;
92434 + }
92435 +#endif
92436 +
92437 vma_rb_erase(vma, &mm->mm_rb);
92438 mm->map_count--;
92439 tail_vma = vma;
92440 @@ -2382,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92441 struct vm_area_struct *new;
92442 int err = -ENOMEM;
92443
92444 +#ifdef CONFIG_PAX_SEGMEXEC
92445 + struct vm_area_struct *vma_m, *new_m = NULL;
92446 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
92447 +#endif
92448 +
92449 if (is_vm_hugetlb_page(vma) && (addr &
92450 ~(huge_page_mask(hstate_vma(vma)))))
92451 return -EINVAL;
92452
92453 +#ifdef CONFIG_PAX_SEGMEXEC
92454 + vma_m = pax_find_mirror_vma(vma);
92455 +#endif
92456 +
92457 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92458 if (!new)
92459 goto out_err;
92460
92461 +#ifdef CONFIG_PAX_SEGMEXEC
92462 + if (vma_m) {
92463 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92464 + if (!new_m) {
92465 + kmem_cache_free(vm_area_cachep, new);
92466 + goto out_err;
92467 + }
92468 + }
92469 +#endif
92470 +
92471 /* most fields are the same, copy all, and then fixup */
92472 *new = *vma;
92473
92474 @@ -2402,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92475 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
92476 }
92477
92478 +#ifdef CONFIG_PAX_SEGMEXEC
92479 + if (vma_m) {
92480 + *new_m = *vma_m;
92481 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
92482 + new_m->vm_mirror = new;
92483 + new->vm_mirror = new_m;
92484 +
92485 + if (new_below)
92486 + new_m->vm_end = addr_m;
92487 + else {
92488 + new_m->vm_start = addr_m;
92489 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
92490 + }
92491 + }
92492 +#endif
92493 +
92494 err = vma_dup_policy(vma, new);
92495 if (err)
92496 goto out_free_vma;
92497 @@ -2421,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92498 else
92499 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
92500
92501 +#ifdef CONFIG_PAX_SEGMEXEC
92502 + if (!err && vma_m) {
92503 + struct mempolicy *pol = vma_policy(new);
92504 +
92505 + if (anon_vma_clone(new_m, vma_m))
92506 + goto out_free_mpol;
92507 +
92508 + mpol_get(pol);
92509 + set_vma_policy(new_m, pol);
92510 +
92511 + if (new_m->vm_file)
92512 + get_file(new_m->vm_file);
92513 +
92514 + if (new_m->vm_ops && new_m->vm_ops->open)
92515 + new_m->vm_ops->open(new_m);
92516 +
92517 + if (new_below)
92518 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
92519 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
92520 + else
92521 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
92522 +
92523 + if (err) {
92524 + if (new_m->vm_ops && new_m->vm_ops->close)
92525 + new_m->vm_ops->close(new_m);
92526 + if (new_m->vm_file)
92527 + fput(new_m->vm_file);
92528 + mpol_put(pol);
92529 + }
92530 + }
92531 +#endif
92532 +
92533 /* Success. */
92534 if (!err)
92535 return 0;
92536 @@ -2430,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92537 new->vm_ops->close(new);
92538 if (new->vm_file)
92539 fput(new->vm_file);
92540 - unlink_anon_vmas(new);
92541 out_free_mpol:
92542 mpol_put(vma_policy(new));
92543 out_free_vma:
92544 +
92545 +#ifdef CONFIG_PAX_SEGMEXEC
92546 + if (new_m) {
92547 + unlink_anon_vmas(new_m);
92548 + kmem_cache_free(vm_area_cachep, new_m);
92549 + }
92550 +#endif
92551 +
92552 + unlink_anon_vmas(new);
92553 kmem_cache_free(vm_area_cachep, new);
92554 out_err:
92555 return err;
92556 @@ -2446,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92557 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92558 unsigned long addr, int new_below)
92559 {
92560 +
92561 +#ifdef CONFIG_PAX_SEGMEXEC
92562 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92563 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
92564 + if (mm->map_count >= sysctl_max_map_count-1)
92565 + return -ENOMEM;
92566 + } else
92567 +#endif
92568 +
92569 if (mm->map_count >= sysctl_max_map_count)
92570 return -ENOMEM;
92571
92572 @@ -2457,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92573 * work. This now handles partial unmappings.
92574 * Jeremy Fitzhardinge <jeremy@goop.org>
92575 */
92576 +#ifdef CONFIG_PAX_SEGMEXEC
92577 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92578 {
92579 + int ret = __do_munmap(mm, start, len);
92580 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
92581 + return ret;
92582 +
92583 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
92584 +}
92585 +
92586 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92587 +#else
92588 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92589 +#endif
92590 +{
92591 unsigned long end;
92592 struct vm_area_struct *vma, *prev, *last;
92593
92594 + /*
92595 + * mm->mmap_sem is required to protect against another thread
92596 + * changing the mappings in case we sleep.
92597 + */
92598 + verify_mm_writelocked(mm);
92599 +
92600 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
92601 return -EINVAL;
92602
92603 @@ -2536,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92604 /* Fix up all other VM information */
92605 remove_vma_list(mm, vma);
92606
92607 + track_exec_limit(mm, start, end, 0UL);
92608 +
92609 return 0;
92610 }
92611
92612 @@ -2544,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
92613 int ret;
92614 struct mm_struct *mm = current->mm;
92615
92616 +
92617 +#ifdef CONFIG_PAX_SEGMEXEC
92618 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
92619 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
92620 + return -EINVAL;
92621 +#endif
92622 +
92623 down_write(&mm->mmap_sem);
92624 ret = do_munmap(mm, start, len);
92625 up_write(&mm->mmap_sem);
92626 @@ -2557,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
92627 return vm_munmap(addr, len);
92628 }
92629
92630 -static inline void verify_mm_writelocked(struct mm_struct *mm)
92631 -{
92632 -#ifdef CONFIG_DEBUG_VM
92633 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92634 - WARN_ON(1);
92635 - up_read(&mm->mmap_sem);
92636 - }
92637 -#endif
92638 -}
92639 -
92640 /*
92641 * this is really a simplified "do_mmap". it only handles
92642 * anonymous maps. eventually we may be able to do some
92643 @@ -2580,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92644 struct rb_node ** rb_link, * rb_parent;
92645 pgoff_t pgoff = addr >> PAGE_SHIFT;
92646 int error;
92647 + unsigned long charged;
92648
92649 len = PAGE_ALIGN(len);
92650 if (!len)
92651 @@ -2587,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92652
92653 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
92654
92655 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
92656 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
92657 + flags &= ~VM_EXEC;
92658 +
92659 +#ifdef CONFIG_PAX_MPROTECT
92660 + if (mm->pax_flags & MF_PAX_MPROTECT)
92661 + flags &= ~VM_MAYEXEC;
92662 +#endif
92663 +
92664 + }
92665 +#endif
92666 +
92667 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
92668 if (error & ~PAGE_MASK)
92669 return error;
92670
92671 + charged = len >> PAGE_SHIFT;
92672 +
92673 /*
92674 * mlock MCL_FUTURE?
92675 */
92676 if (mm->def_flags & VM_LOCKED) {
92677 unsigned long locked, lock_limit;
92678 - locked = len >> PAGE_SHIFT;
92679 + locked = charged;
92680 locked += mm->locked_vm;
92681 lock_limit = rlimit(RLIMIT_MEMLOCK);
92682 lock_limit >>= PAGE_SHIFT;
92683 @@ -2613,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92684 /*
92685 * Clear old maps. this also does some error checking for us
92686 */
92687 - munmap_back:
92688 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92689 if (do_munmap(mm, addr, len))
92690 return -ENOMEM;
92691 - goto munmap_back;
92692 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92693 }
92694
92695 /* Check against address space limits *after* clearing old maps... */
92696 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
92697 + if (!may_expand_vm(mm, charged))
92698 return -ENOMEM;
92699
92700 if (mm->map_count > sysctl_max_map_count)
92701 return -ENOMEM;
92702
92703 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
92704 + if (security_vm_enough_memory_mm(mm, charged))
92705 return -ENOMEM;
92706
92707 /* Can we just expand an old private anonymous mapping? */
92708 @@ -2641,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92709 */
92710 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92711 if (!vma) {
92712 - vm_unacct_memory(len >> PAGE_SHIFT);
92713 + vm_unacct_memory(charged);
92714 return -ENOMEM;
92715 }
92716
92717 @@ -2655,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92718 vma_link(mm, vma, prev, rb_link, rb_parent);
92719 out:
92720 perf_event_mmap(vma);
92721 - mm->total_vm += len >> PAGE_SHIFT;
92722 + mm->total_vm += charged;
92723 if (flags & VM_LOCKED)
92724 - mm->locked_vm += (len >> PAGE_SHIFT);
92725 + mm->locked_vm += charged;
92726 vma->vm_flags |= VM_SOFTDIRTY;
92727 + track_exec_limit(mm, addr, addr + len, flags);
92728 return addr;
92729 }
92730
92731 @@ -2720,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
92732 while (vma) {
92733 if (vma->vm_flags & VM_ACCOUNT)
92734 nr_accounted += vma_pages(vma);
92735 + vma->vm_mirror = NULL;
92736 vma = remove_vma(vma);
92737 }
92738 vm_unacct_memory(nr_accounted);
92739 @@ -2737,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92740 struct vm_area_struct *prev;
92741 struct rb_node **rb_link, *rb_parent;
92742
92743 +#ifdef CONFIG_PAX_SEGMEXEC
92744 + struct vm_area_struct *vma_m = NULL;
92745 +#endif
92746 +
92747 + if (security_mmap_addr(vma->vm_start))
92748 + return -EPERM;
92749 +
92750 /*
92751 * The vm_pgoff of a purely anonymous vma should be irrelevant
92752 * until its first write fault, when page's anon_vma and index
92753 @@ -2760,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92754 security_vm_enough_memory_mm(mm, vma_pages(vma)))
92755 return -ENOMEM;
92756
92757 +#ifdef CONFIG_PAX_SEGMEXEC
92758 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
92759 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92760 + if (!vma_m)
92761 + return -ENOMEM;
92762 + }
92763 +#endif
92764 +
92765 vma_link(mm, vma, prev, rb_link, rb_parent);
92766 +
92767 +#ifdef CONFIG_PAX_SEGMEXEC
92768 + if (vma_m)
92769 + BUG_ON(pax_mirror_vma(vma_m, vma));
92770 +#endif
92771 +
92772 return 0;
92773 }
92774
92775 @@ -2779,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92776 struct rb_node **rb_link, *rb_parent;
92777 bool faulted_in_anon_vma = true;
92778
92779 + BUG_ON(vma->vm_mirror);
92780 +
92781 /*
92782 * If anonymous vma has not yet been faulted, update new pgoff
92783 * to match new location, to increase its chance of merging.
92784 @@ -2843,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92785 return NULL;
92786 }
92787
92788 +#ifdef CONFIG_PAX_SEGMEXEC
92789 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
92790 +{
92791 + struct vm_area_struct *prev_m;
92792 + struct rb_node **rb_link_m, *rb_parent_m;
92793 + struct mempolicy *pol_m;
92794 +
92795 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
92796 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
92797 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
92798 + *vma_m = *vma;
92799 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
92800 + if (anon_vma_clone(vma_m, vma))
92801 + return -ENOMEM;
92802 + pol_m = vma_policy(vma_m);
92803 + mpol_get(pol_m);
92804 + set_vma_policy(vma_m, pol_m);
92805 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
92806 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
92807 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
92808 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
92809 + if (vma_m->vm_file)
92810 + get_file(vma_m->vm_file);
92811 + if (vma_m->vm_ops && vma_m->vm_ops->open)
92812 + vma_m->vm_ops->open(vma_m);
92813 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
92814 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
92815 + vma_m->vm_mirror = vma;
92816 + vma->vm_mirror = vma_m;
92817 + return 0;
92818 +}
92819 +#endif
92820 +
92821 /*
92822 * Return true if the calling process may expand its vm space by the passed
92823 * number of pages
92824 @@ -2854,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
92825
92826 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
92827
92828 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
92829 if (cur + npages > lim)
92830 return 0;
92831 return 1;
92832 @@ -2924,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
92833 vma->vm_start = addr;
92834 vma->vm_end = addr + len;
92835
92836 +#ifdef CONFIG_PAX_MPROTECT
92837 + if (mm->pax_flags & MF_PAX_MPROTECT) {
92838 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
92839 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
92840 + return -EPERM;
92841 + if (!(vm_flags & VM_EXEC))
92842 + vm_flags &= ~VM_MAYEXEC;
92843 +#else
92844 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92845 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92846 +#endif
92847 + else
92848 + vm_flags &= ~VM_MAYWRITE;
92849 + }
92850 +#endif
92851 +
92852 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
92853 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92854
92855 diff --git a/mm/mprotect.c b/mm/mprotect.c
92856 index bb53a65..249c052 100644
92857 --- a/mm/mprotect.c
92858 +++ b/mm/mprotect.c
92859 @@ -23,10 +23,18 @@
92860 #include <linux/mmu_notifier.h>
92861 #include <linux/migrate.h>
92862 #include <linux/perf_event.h>
92863 +#include <linux/sched/sysctl.h>
92864 +
92865 +#ifdef CONFIG_PAX_MPROTECT
92866 +#include <linux/elf.h>
92867 +#include <linux/binfmts.h>
92868 +#endif
92869 +
92870 #include <asm/uaccess.h>
92871 #include <asm/pgtable.h>
92872 #include <asm/cacheflush.h>
92873 #include <asm/tlbflush.h>
92874 +#include <asm/mmu_context.h>
92875
92876 #ifndef pgprot_modify
92877 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
92878 @@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
92879 return pages;
92880 }
92881
92882 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92883 +/* called while holding the mmap semaphor for writing except stack expansion */
92884 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
92885 +{
92886 + unsigned long oldlimit, newlimit = 0UL;
92887 +
92888 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
92889 + return;
92890 +
92891 + spin_lock(&mm->page_table_lock);
92892 + oldlimit = mm->context.user_cs_limit;
92893 + if ((prot & VM_EXEC) && oldlimit < end)
92894 + /* USER_CS limit moved up */
92895 + newlimit = end;
92896 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
92897 + /* USER_CS limit moved down */
92898 + newlimit = start;
92899 +
92900 + if (newlimit) {
92901 + mm->context.user_cs_limit = newlimit;
92902 +
92903 +#ifdef CONFIG_SMP
92904 + wmb();
92905 + cpus_clear(mm->context.cpu_user_cs_mask);
92906 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
92907 +#endif
92908 +
92909 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
92910 + }
92911 + spin_unlock(&mm->page_table_lock);
92912 + if (newlimit == end) {
92913 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
92914 +
92915 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
92916 + if (is_vm_hugetlb_page(vma))
92917 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
92918 + else
92919 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
92920 + }
92921 +}
92922 +#endif
92923 +
92924 int
92925 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92926 unsigned long start, unsigned long end, unsigned long newflags)
92927 @@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92928 int error;
92929 int dirty_accountable = 0;
92930
92931 +#ifdef CONFIG_PAX_SEGMEXEC
92932 + struct vm_area_struct *vma_m = NULL;
92933 + unsigned long start_m, end_m;
92934 +
92935 + start_m = start + SEGMEXEC_TASK_SIZE;
92936 + end_m = end + SEGMEXEC_TASK_SIZE;
92937 +#endif
92938 +
92939 if (newflags == oldflags) {
92940 *pprev = vma;
92941 return 0;
92942 }
92943
92944 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
92945 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
92946 +
92947 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
92948 + return -ENOMEM;
92949 +
92950 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
92951 + return -ENOMEM;
92952 + }
92953 +
92954 /*
92955 * If we make a private mapping writable we increase our commit;
92956 * but (without finer accounting) cannot reduce our commit if we
92957 @@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92958 }
92959 }
92960
92961 +#ifdef CONFIG_PAX_SEGMEXEC
92962 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
92963 + if (start != vma->vm_start) {
92964 + error = split_vma(mm, vma, start, 1);
92965 + if (error)
92966 + goto fail;
92967 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
92968 + *pprev = (*pprev)->vm_next;
92969 + }
92970 +
92971 + if (end != vma->vm_end) {
92972 + error = split_vma(mm, vma, end, 0);
92973 + if (error)
92974 + goto fail;
92975 + }
92976 +
92977 + if (pax_find_mirror_vma(vma)) {
92978 + error = __do_munmap(mm, start_m, end_m - start_m);
92979 + if (error)
92980 + goto fail;
92981 + } else {
92982 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92983 + if (!vma_m) {
92984 + error = -ENOMEM;
92985 + goto fail;
92986 + }
92987 + vma->vm_flags = newflags;
92988 + error = pax_mirror_vma(vma_m, vma);
92989 + if (error) {
92990 + vma->vm_flags = oldflags;
92991 + goto fail;
92992 + }
92993 + }
92994 + }
92995 +#endif
92996 +
92997 /*
92998 * First try to merge with previous and/or next vma.
92999 */
93000 @@ -285,9 +389,21 @@ success:
93001 * vm_flags and vm_page_prot are protected by the mmap_sem
93002 * held in write mode.
93003 */
93004 +
93005 +#ifdef CONFIG_PAX_SEGMEXEC
93006 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
93007 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
93008 +#endif
93009 +
93010 vma->vm_flags = newflags;
93011 +
93012 +#ifdef CONFIG_PAX_MPROTECT
93013 + if (mm->binfmt && mm->binfmt->handle_mprotect)
93014 + mm->binfmt->handle_mprotect(vma, newflags);
93015 +#endif
93016 +
93017 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
93018 - vm_get_page_prot(newflags));
93019 + vm_get_page_prot(vma->vm_flags));
93020
93021 if (vma_wants_writenotify(vma)) {
93022 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
93023 @@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93024 end = start + len;
93025 if (end <= start)
93026 return -ENOMEM;
93027 +
93028 +#ifdef CONFIG_PAX_SEGMEXEC
93029 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
93030 + if (end > SEGMEXEC_TASK_SIZE)
93031 + return -EINVAL;
93032 + } else
93033 +#endif
93034 +
93035 + if (end > TASK_SIZE)
93036 + return -EINVAL;
93037 +
93038 if (!arch_validate_prot(prot))
93039 return -EINVAL;
93040
93041 @@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93042 /*
93043 * Does the application expect PROT_READ to imply PROT_EXEC:
93044 */
93045 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93046 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93047 prot |= PROT_EXEC;
93048
93049 vm_flags = calc_vm_prot_bits(prot);
93050 @@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93051 if (start > vma->vm_start)
93052 prev = vma;
93053
93054 +#ifdef CONFIG_PAX_MPROTECT
93055 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
93056 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
93057 +#endif
93058 +
93059 for (nstart = start ; ; ) {
93060 unsigned long newflags;
93061
93062 @@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93063
93064 /* newflags >> 4 shift VM_MAY% in place of VM_% */
93065 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
93066 + if (prot & (PROT_WRITE | PROT_EXEC))
93067 + gr_log_rwxmprotect(vma);
93068 +
93069 + error = -EACCES;
93070 + goto out;
93071 + }
93072 +
93073 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
93074 error = -EACCES;
93075 goto out;
93076 }
93077 @@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93078 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
93079 if (error)
93080 goto out;
93081 +
93082 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
93083 +
93084 nstart = tmp;
93085
93086 if (nstart < prev->vm_end)
93087 diff --git a/mm/mremap.c b/mm/mremap.c
93088 index 0843feb..4f5b2e6 100644
93089 --- a/mm/mremap.c
93090 +++ b/mm/mremap.c
93091 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
93092 continue;
93093 pte = ptep_get_and_clear(mm, old_addr, old_pte);
93094 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
93095 +
93096 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93097 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
93098 + pte = pte_exprotect(pte);
93099 +#endif
93100 +
93101 pte = move_soft_dirty_pte(pte);
93102 set_pte_at(mm, new_addr, new_pte, pte);
93103 }
93104 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
93105 if (is_vm_hugetlb_page(vma))
93106 goto Einval;
93107
93108 +#ifdef CONFIG_PAX_SEGMEXEC
93109 + if (pax_find_mirror_vma(vma))
93110 + goto Einval;
93111 +#endif
93112 +
93113 /* We can't remap across vm area boundaries */
93114 if (old_len > vma->vm_end - addr)
93115 goto Efault;
93116 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
93117 unsigned long ret = -EINVAL;
93118 unsigned long charged = 0;
93119 unsigned long map_flags;
93120 + unsigned long pax_task_size = TASK_SIZE;
93121
93122 if (new_addr & ~PAGE_MASK)
93123 goto out;
93124
93125 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
93126 +#ifdef CONFIG_PAX_SEGMEXEC
93127 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
93128 + pax_task_size = SEGMEXEC_TASK_SIZE;
93129 +#endif
93130 +
93131 + pax_task_size -= PAGE_SIZE;
93132 +
93133 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
93134 goto out;
93135
93136 /* Check if the location we're moving into overlaps the
93137 * old location at all, and fail if it does.
93138 */
93139 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
93140 - goto out;
93141 -
93142 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
93143 + if (addr + old_len > new_addr && new_addr + new_len > addr)
93144 goto out;
93145
93146 ret = do_munmap(mm, new_addr, new_len);
93147 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93148 unsigned long ret = -EINVAL;
93149 unsigned long charged = 0;
93150 bool locked = false;
93151 + unsigned long pax_task_size = TASK_SIZE;
93152
93153 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
93154 return ret;
93155 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93156 if (!new_len)
93157 return ret;
93158
93159 +#ifdef CONFIG_PAX_SEGMEXEC
93160 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
93161 + pax_task_size = SEGMEXEC_TASK_SIZE;
93162 +#endif
93163 +
93164 + pax_task_size -= PAGE_SIZE;
93165 +
93166 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
93167 + old_len > pax_task_size || addr > pax_task_size-old_len)
93168 + return ret;
93169 +
93170 down_write(&current->mm->mmap_sem);
93171
93172 if (flags & MREMAP_FIXED) {
93173 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93174 new_addr = addr;
93175 }
93176 ret = addr;
93177 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
93178 goto out;
93179 }
93180 }
93181 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93182 goto out;
93183 }
93184
93185 + map_flags = vma->vm_flags;
93186 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
93187 + if (!(ret & ~PAGE_MASK)) {
93188 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
93189 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
93190 + }
93191 }
93192 out:
93193 if (ret & ~PAGE_MASK)
93194 diff --git a/mm/nommu.c b/mm/nommu.c
93195 index fec093a..8162f74 100644
93196 --- a/mm/nommu.c
93197 +++ b/mm/nommu.c
93198 @@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
93199 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
93200 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93201 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93202 -int heap_stack_gap = 0;
93203
93204 atomic_long_t mmap_pages_allocated;
93205
93206 @@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
93207 EXPORT_SYMBOL(find_vma);
93208
93209 /*
93210 - * find a VMA
93211 - * - we don't extend stack VMAs under NOMMU conditions
93212 - */
93213 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
93214 -{
93215 - return find_vma(mm, addr);
93216 -}
93217 -
93218 -/*
93219 * expand a stack to a given address
93220 * - not supported under NOMMU conditions
93221 */
93222 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93223
93224 /* most fields are the same, copy all, and then fixup */
93225 *new = *vma;
93226 + INIT_LIST_HEAD(&new->anon_vma_chain);
93227 *region = *vma->vm_region;
93228 new->vm_region = region;
93229
93230 @@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
93231 }
93232 EXPORT_SYMBOL(generic_file_remap_pages);
93233
93234 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93235 - unsigned long addr, void *buf, int len, int write)
93236 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93237 + unsigned long addr, void *buf, size_t len, int write)
93238 {
93239 struct vm_area_struct *vma;
93240
93241 @@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93242 *
93243 * The caller must hold a reference on @mm.
93244 */
93245 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93246 - void *buf, int len, int write)
93247 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93248 + void *buf, size_t len, int write)
93249 {
93250 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93251 }
93252 @@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93253 * Access another process' address space.
93254 * - source/target buffer must be kernel space
93255 */
93256 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
93257 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
93258 {
93259 struct mm_struct *mm;
93260
93261 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
93262 index 6380758..4064aec 100644
93263 --- a/mm/page-writeback.c
93264 +++ b/mm/page-writeback.c
93265 @@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
93266 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
93267 * - the bdi dirty thresh drops quickly due to change of JBOD workload
93268 */
93269 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
93270 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
93271 unsigned long thresh,
93272 unsigned long bg_thresh,
93273 unsigned long dirty,
93274 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
93275 index 5248fe0..0f693aa 100644
93276 --- a/mm/page_alloc.c
93277 +++ b/mm/page_alloc.c
93278 @@ -61,6 +61,7 @@
93279 #include <linux/page-debug-flags.h>
93280 #include <linux/hugetlb.h>
93281 #include <linux/sched/rt.h>
93282 +#include <linux/random.h>
93283
93284 #include <asm/sections.h>
93285 #include <asm/tlbflush.h>
93286 @@ -354,7 +355,7 @@ out:
93287 * This usage means that zero-order pages may not be compound.
93288 */
93289
93290 -static void free_compound_page(struct page *page)
93291 +void free_compound_page(struct page *page)
93292 {
93293 __free_pages_ok(page, compound_order(page));
93294 }
93295 @@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93296 int i;
93297 int bad = 0;
93298
93299 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93300 + unsigned long index = 1UL << order;
93301 +#endif
93302 +
93303 trace_mm_page_free(page, order);
93304 kmemcheck_free_shadow(page, order);
93305
93306 @@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93307 debug_check_no_obj_freed(page_address(page),
93308 PAGE_SIZE << order);
93309 }
93310 +
93311 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93312 + for (; index; --index)
93313 + sanitize_highpage(page + index - 1);
93314 +#endif
93315 +
93316 arch_free_page(page, order);
93317 kernel_map_pages(page, 1 << order, 0);
93318
93319 @@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
93320 local_irq_restore(flags);
93321 }
93322
93323 +#ifdef CONFIG_PAX_LATENT_ENTROPY
93324 +bool __meminitdata extra_latent_entropy;
93325 +
93326 +static int __init setup_pax_extra_latent_entropy(char *str)
93327 +{
93328 + extra_latent_entropy = true;
93329 + return 0;
93330 +}
93331 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
93332 +
93333 +volatile u64 latent_entropy __latent_entropy;
93334 +EXPORT_SYMBOL(latent_entropy);
93335 +#endif
93336 +
93337 void __init __free_pages_bootmem(struct page *page, unsigned int order)
93338 {
93339 unsigned int nr_pages = 1 << order;
93340 @@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
93341 __ClearPageReserved(p);
93342 set_page_count(p, 0);
93343
93344 +#ifdef CONFIG_PAX_LATENT_ENTROPY
93345 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
93346 + u64 hash = 0;
93347 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
93348 + const u64 *data = lowmem_page_address(page);
93349 +
93350 + for (index = 0; index < end; index++)
93351 + hash ^= hash + data[index];
93352 + latent_entropy ^= hash;
93353 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
93354 + }
93355 +#endif
93356 +
93357 page_zone(page)->managed_pages += nr_pages;
93358 set_page_refcounted(page);
93359 __free_pages(page, order);
93360 @@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
93361 arch_alloc_page(page, order);
93362 kernel_map_pages(page, 1 << order, 1);
93363
93364 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
93365 if (gfp_flags & __GFP_ZERO)
93366 prep_zero_page(page, order, gfp_flags);
93367 +#endif
93368
93369 if (order && (gfp_flags & __GFP_COMP))
93370 prep_compound_page(page, order);
93371 diff --git a/mm/page_io.c b/mm/page_io.c
93372 index 8c79a47..a689e0d 100644
93373 --- a/mm/page_io.c
93374 +++ b/mm/page_io.c
93375 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
93376 struct file *swap_file = sis->swap_file;
93377 struct address_space *mapping = swap_file->f_mapping;
93378 struct iovec iov = {
93379 - .iov_base = kmap(page),
93380 + .iov_base = (void __force_user *)kmap(page),
93381 .iov_len = PAGE_SIZE,
93382 };
93383
93384 diff --git a/mm/percpu.c b/mm/percpu.c
93385 index 0d10def..6dc822d 100644
93386 --- a/mm/percpu.c
93387 +++ b/mm/percpu.c
93388 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
93389 static unsigned int pcpu_high_unit_cpu __read_mostly;
93390
93391 /* the address of the first chunk which starts with the kernel static area */
93392 -void *pcpu_base_addr __read_mostly;
93393 +void *pcpu_base_addr __read_only;
93394 EXPORT_SYMBOL_GPL(pcpu_base_addr);
93395
93396 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
93397 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
93398 index fd26d04..0cea1b0 100644
93399 --- a/mm/process_vm_access.c
93400 +++ b/mm/process_vm_access.c
93401 @@ -13,6 +13,7 @@
93402 #include <linux/uio.h>
93403 #include <linux/sched.h>
93404 #include <linux/highmem.h>
93405 +#include <linux/security.h>
93406 #include <linux/ptrace.h>
93407 #include <linux/slab.h>
93408 #include <linux/syscalls.h>
93409 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93410 size_t iov_l_curr_offset = 0;
93411 ssize_t iov_len;
93412
93413 + return -ENOSYS; // PaX: until properly audited
93414 +
93415 /*
93416 * Work out how many pages of struct pages we're going to need
93417 * when eventually calling get_user_pages
93418 */
93419 for (i = 0; i < riovcnt; i++) {
93420 iov_len = rvec[i].iov_len;
93421 - if (iov_len > 0) {
93422 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
93423 - + iov_len)
93424 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
93425 - / PAGE_SIZE + 1;
93426 - nr_pages = max(nr_pages, nr_pages_iov);
93427 - }
93428 + if (iov_len <= 0)
93429 + continue;
93430 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
93431 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
93432 + nr_pages = max(nr_pages, nr_pages_iov);
93433 }
93434
93435 if (nr_pages == 0)
93436 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93437 goto free_proc_pages;
93438 }
93439
93440 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
93441 + rc = -EPERM;
93442 + goto put_task_struct;
93443 + }
93444 +
93445 mm = mm_access(task, PTRACE_MODE_ATTACH);
93446 if (!mm || IS_ERR(mm)) {
93447 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
93448 diff --git a/mm/rmap.c b/mm/rmap.c
93449 index 068522d..f539f21 100644
93450 --- a/mm/rmap.c
93451 +++ b/mm/rmap.c
93452 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93453 struct anon_vma *anon_vma = vma->anon_vma;
93454 struct anon_vma_chain *avc;
93455
93456 +#ifdef CONFIG_PAX_SEGMEXEC
93457 + struct anon_vma_chain *avc_m = NULL;
93458 +#endif
93459 +
93460 might_sleep();
93461 if (unlikely(!anon_vma)) {
93462 struct mm_struct *mm = vma->vm_mm;
93463 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93464 if (!avc)
93465 goto out_enomem;
93466
93467 +#ifdef CONFIG_PAX_SEGMEXEC
93468 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
93469 + if (!avc_m)
93470 + goto out_enomem_free_avc;
93471 +#endif
93472 +
93473 anon_vma = find_mergeable_anon_vma(vma);
93474 allocated = NULL;
93475 if (!anon_vma) {
93476 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93477 /* page_table_lock to protect against threads */
93478 spin_lock(&mm->page_table_lock);
93479 if (likely(!vma->anon_vma)) {
93480 +
93481 +#ifdef CONFIG_PAX_SEGMEXEC
93482 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
93483 +
93484 + if (vma_m) {
93485 + BUG_ON(vma_m->anon_vma);
93486 + vma_m->anon_vma = anon_vma;
93487 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
93488 + avc_m = NULL;
93489 + }
93490 +#endif
93491 +
93492 vma->anon_vma = anon_vma;
93493 anon_vma_chain_link(vma, avc, anon_vma);
93494 allocated = NULL;
93495 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93496
93497 if (unlikely(allocated))
93498 put_anon_vma(allocated);
93499 +
93500 +#ifdef CONFIG_PAX_SEGMEXEC
93501 + if (unlikely(avc_m))
93502 + anon_vma_chain_free(avc_m);
93503 +#endif
93504 +
93505 if (unlikely(avc))
93506 anon_vma_chain_free(avc);
93507 }
93508 return 0;
93509
93510 out_enomem_free_avc:
93511 +
93512 +#ifdef CONFIG_PAX_SEGMEXEC
93513 + if (avc_m)
93514 + anon_vma_chain_free(avc_m);
93515 +#endif
93516 +
93517 anon_vma_chain_free(avc);
93518 out_enomem:
93519 return -ENOMEM;
93520 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
93521 * Attach the anon_vmas from src to dst.
93522 * Returns 0 on success, -ENOMEM on failure.
93523 */
93524 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93525 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
93526 {
93527 struct anon_vma_chain *avc, *pavc;
93528 struct anon_vma *root = NULL;
93529 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93530 * the corresponding VMA in the parent process is attached to.
93531 * Returns 0 on success, non-zero on failure.
93532 */
93533 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
93534 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
93535 {
93536 struct anon_vma_chain *avc;
93537 struct anon_vma *anon_vma;
93538 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
93539 void __init anon_vma_init(void)
93540 {
93541 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
93542 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
93543 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
93544 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
93545 + anon_vma_ctor);
93546 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
93547 + SLAB_PANIC|SLAB_NO_SANITIZE);
93548 }
93549
93550 /*
93551 diff --git a/mm/shmem.c b/mm/shmem.c
93552 index 902a148..58f9d59 100644
93553 --- a/mm/shmem.c
93554 +++ b/mm/shmem.c
93555 @@ -33,7 +33,7 @@
93556 #include <linux/swap.h>
93557 #include <linux/aio.h>
93558
93559 -static struct vfsmount *shm_mnt;
93560 +struct vfsmount *shm_mnt;
93561
93562 #ifdef CONFIG_SHMEM
93563 /*
93564 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
93565 #define BOGO_DIRENT_SIZE 20
93566
93567 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
93568 -#define SHORT_SYMLINK_LEN 128
93569 +#define SHORT_SYMLINK_LEN 64
93570
93571 /*
93572 * shmem_fallocate and shmem_writepage communicate via inode->i_private
93573 @@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
93574 static int shmem_xattr_validate(const char *name)
93575 {
93576 struct { const char *prefix; size_t len; } arr[] = {
93577 +
93578 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93579 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
93580 +#endif
93581 +
93582 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
93583 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
93584 };
93585 @@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
93586 if (err)
93587 return err;
93588
93589 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93590 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
93591 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
93592 + return -EOPNOTSUPP;
93593 + if (size > 8)
93594 + return -EINVAL;
93595 + }
93596 +#endif
93597 +
93598 return simple_xattr_set(&info->xattrs, name, value, size, flags);
93599 }
93600
93601 @@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
93602 int err = -ENOMEM;
93603
93604 /* Round up to L1_CACHE_BYTES to resist false sharing */
93605 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
93606 - L1_CACHE_BYTES), GFP_KERNEL);
93607 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
93608 if (!sbinfo)
93609 return -ENOMEM;
93610
93611 diff --git a/mm/slab.c b/mm/slab.c
93612 index eb043bf..d82f5a8 100644
93613 --- a/mm/slab.c
93614 +++ b/mm/slab.c
93615 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93616 if ((x)->max_freeable < i) \
93617 (x)->max_freeable = i; \
93618 } while (0)
93619 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
93620 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
93621 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
93622 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
93623 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
93624 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
93625 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
93626 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
93627 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
93628 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
93629 #else
93630 #define STATS_INC_ACTIVE(x) do { } while (0)
93631 #define STATS_DEC_ACTIVE(x) do { } while (0)
93632 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93633 #define STATS_INC_ALLOCMISS(x) do { } while (0)
93634 #define STATS_INC_FREEHIT(x) do { } while (0)
93635 #define STATS_INC_FREEMISS(x) do { } while (0)
93636 +#define STATS_INC_SANITIZED(x) do { } while (0)
93637 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
93638 #endif
93639
93640 #if DEBUG
93641 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
93642 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
93643 */
93644 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
93645 - const struct page *page, void *obj)
93646 + const struct page *page, const void *obj)
93647 {
93648 u32 offset = (obj - page->s_mem);
93649 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
93650 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
93651 */
93652
93653 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
93654 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
93655 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93656
93657 if (INDEX_AC != INDEX_NODE)
93658 kmalloc_caches[INDEX_NODE] =
93659 create_kmalloc_cache("kmalloc-node",
93660 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
93661 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93662
93663 slab_early_init = 0;
93664
93665 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
93666 struct array_cache *ac = cpu_cache_get(cachep);
93667
93668 check_irq_off();
93669 +
93670 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93671 + if (pax_sanitize_slab) {
93672 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
93673 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
93674 +
93675 + if (cachep->ctor)
93676 + cachep->ctor(objp);
93677 +
93678 + STATS_INC_SANITIZED(cachep);
93679 + } else
93680 + STATS_INC_NOT_SANITIZED(cachep);
93681 + }
93682 +#endif
93683 +
93684 kmemleak_free_recursive(objp, cachep->flags);
93685 objp = cache_free_debugcheck(cachep, objp, caller);
93686
93687 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
93688
93689 if (unlikely(ZERO_OR_NULL_PTR(objp)))
93690 return;
93691 + VM_BUG_ON(!virt_addr_valid(objp));
93692 local_irq_save(flags);
93693 kfree_debugcheck(objp);
93694 c = virt_to_cache(objp);
93695 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
93696 }
93697 /* cpu stats */
93698 {
93699 - unsigned long allochit = atomic_read(&cachep->allochit);
93700 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
93701 - unsigned long freehit = atomic_read(&cachep->freehit);
93702 - unsigned long freemiss = atomic_read(&cachep->freemiss);
93703 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
93704 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
93705 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
93706 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
93707
93708 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
93709 allochit, allocmiss, freehit, freemiss);
93710 }
93711 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93712 + {
93713 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
93714 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
93715 +
93716 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
93717 + }
93718 +#endif
93719 #endif
93720 }
93721
93722 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
93723 static int __init slab_proc_init(void)
93724 {
93725 #ifdef CONFIG_DEBUG_SLAB_LEAK
93726 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
93727 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
93728 #endif
93729 return 0;
93730 }
93731 module_init(slab_proc_init);
93732 #endif
93733
93734 +bool is_usercopy_object(const void *ptr)
93735 +{
93736 + struct page *page;
93737 + struct kmem_cache *cachep;
93738 +
93739 + if (ZERO_OR_NULL_PTR(ptr))
93740 + return false;
93741 +
93742 + if (!slab_is_available())
93743 + return false;
93744 +
93745 + if (!virt_addr_valid(ptr))
93746 + return false;
93747 +
93748 + page = virt_to_head_page(ptr);
93749 +
93750 + if (!PageSlab(page))
93751 + return false;
93752 +
93753 + cachep = page->slab_cache;
93754 + return cachep->flags & SLAB_USERCOPY;
93755 +}
93756 +
93757 +#ifdef CONFIG_PAX_USERCOPY
93758 +const char *check_heap_object(const void *ptr, unsigned long n)
93759 +{
93760 + struct page *page;
93761 + struct kmem_cache *cachep;
93762 + unsigned int objnr;
93763 + unsigned long offset;
93764 +
93765 + if (ZERO_OR_NULL_PTR(ptr))
93766 + return "<null>";
93767 +
93768 + if (!virt_addr_valid(ptr))
93769 + return NULL;
93770 +
93771 + page = virt_to_head_page(ptr);
93772 +
93773 + if (!PageSlab(page))
93774 + return NULL;
93775 +
93776 + cachep = page->slab_cache;
93777 + if (!(cachep->flags & SLAB_USERCOPY))
93778 + return cachep->name;
93779 +
93780 + objnr = obj_to_index(cachep, page, ptr);
93781 + BUG_ON(objnr >= cachep->num);
93782 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
93783 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
93784 + return NULL;
93785 +
93786 + return cachep->name;
93787 +}
93788 +#endif
93789 +
93790 /**
93791 * ksize - get the actual amount of memory allocated for a given object
93792 * @objp: Pointer to the object
93793 diff --git a/mm/slab.h b/mm/slab.h
93794 index 0859c42..2f7b737 100644
93795 --- a/mm/slab.h
93796 +++ b/mm/slab.h
93797 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
93798 /* The slab cache that manages slab cache information */
93799 extern struct kmem_cache *kmem_cache;
93800
93801 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93802 +#ifdef CONFIG_X86_64
93803 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
93804 +#else
93805 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
93806 +#endif
93807 +extern bool pax_sanitize_slab;
93808 +#endif
93809 +
93810 unsigned long calculate_alignment(unsigned long flags,
93811 unsigned long align, unsigned long size);
93812
93813 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
93814
93815 /* Legal flag mask for kmem_cache_create(), for various configurations */
93816 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
93817 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
93818 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
93819 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
93820
93821 #if defined(CONFIG_DEBUG_SLAB)
93822 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
93823 @@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
93824 return s;
93825
93826 page = virt_to_head_page(x);
93827 +
93828 + BUG_ON(!PageSlab(page));
93829 +
93830 cachep = page->slab_cache;
93831 if (slab_equal_or_root(cachep, s))
93832 return cachep;
93833 diff --git a/mm/slab_common.c b/mm/slab_common.c
93834 index 0b7bb39..334c328 100644
93835 --- a/mm/slab_common.c
93836 +++ b/mm/slab_common.c
93837 @@ -23,11 +23,22 @@
93838
93839 #include "slab.h"
93840
93841 -enum slab_state slab_state;
93842 +enum slab_state slab_state __read_only;
93843 LIST_HEAD(slab_caches);
93844 DEFINE_MUTEX(slab_mutex);
93845 struct kmem_cache *kmem_cache;
93846
93847 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93848 +bool pax_sanitize_slab __read_only = true;
93849 +static int __init pax_sanitize_slab_setup(char *str)
93850 +{
93851 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
93852 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
93853 + return 1;
93854 +}
93855 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
93856 +#endif
93857 +
93858 #ifdef CONFIG_DEBUG_VM
93859 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
93860 size_t size)
93861 @@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
93862
93863 err = __kmem_cache_create(s, flags);
93864 if (!err) {
93865 - s->refcount = 1;
93866 + atomic_set(&s->refcount, 1);
93867 list_add(&s->list, &slab_caches);
93868 memcg_cache_list_add(memcg, s);
93869 } else {
93870 @@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
93871
93872 get_online_cpus();
93873 mutex_lock(&slab_mutex);
93874 - s->refcount--;
93875 - if (!s->refcount) {
93876 + if (atomic_dec_and_test(&s->refcount)) {
93877 list_del(&s->list);
93878
93879 if (!__kmem_cache_shutdown(s)) {
93880 @@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
93881 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
93882 name, size, err);
93883
93884 - s->refcount = -1; /* Exempt from merging for now */
93885 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
93886 }
93887
93888 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93889 @@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93890
93891 create_boot_cache(s, name, size, flags);
93892 list_add(&s->list, &slab_caches);
93893 - s->refcount = 1;
93894 + atomic_set(&s->refcount, 1);
93895 return s;
93896 }
93897
93898 @@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
93899 EXPORT_SYMBOL(kmalloc_dma_caches);
93900 #endif
93901
93902 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93903 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
93904 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
93905 +#endif
93906 +
93907 /*
93908 * Conversion table for small slabs sizes / 8 to the index in the
93909 * kmalloc array. This is necessary for slabs < 192 since we have non power
93910 @@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
93911 return kmalloc_dma_caches[index];
93912
93913 #endif
93914 +
93915 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93916 + if (unlikely((flags & GFP_USERCOPY)))
93917 + return kmalloc_usercopy_caches[index];
93918 +
93919 +#endif
93920 +
93921 return kmalloc_caches[index];
93922 }
93923
93924 @@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
93925 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
93926 if (!kmalloc_caches[i]) {
93927 kmalloc_caches[i] = create_kmalloc_cache(NULL,
93928 - 1 << i, flags);
93929 + 1 << i, SLAB_USERCOPY | flags);
93930 }
93931
93932 /*
93933 @@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
93934 * earlier power of two caches
93935 */
93936 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
93937 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
93938 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
93939
93940 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
93941 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
93942 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
93943 }
93944
93945 /* Kmalloc array is now usable */
93946 @@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
93947 }
93948 }
93949 #endif
93950 +
93951 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93952 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
93953 + struct kmem_cache *s = kmalloc_caches[i];
93954 +
93955 + if (s) {
93956 + int size = kmalloc_size(i);
93957 + char *n = kasprintf(GFP_NOWAIT,
93958 + "usercopy-kmalloc-%d", size);
93959 +
93960 + BUG_ON(!n);
93961 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
93962 + size, SLAB_USERCOPY | flags);
93963 + }
93964 + }
93965 +#endif
93966 +
93967 }
93968 #endif /* !CONFIG_SLOB */
93969
93970 @@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
93971 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
93972 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
93973 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
93974 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93975 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
93976 +#endif
93977 #endif
93978 seq_putc(m, '\n');
93979 }
93980 diff --git a/mm/slob.c b/mm/slob.c
93981 index 4bf8809..98a6914 100644
93982 --- a/mm/slob.c
93983 +++ b/mm/slob.c
93984 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
93985 /*
93986 * Return the size of a slob block.
93987 */
93988 -static slobidx_t slob_units(slob_t *s)
93989 +static slobidx_t slob_units(const slob_t *s)
93990 {
93991 if (s->units > 0)
93992 return s->units;
93993 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
93994 /*
93995 * Return the next free slob block pointer after this one.
93996 */
93997 -static slob_t *slob_next(slob_t *s)
93998 +static slob_t *slob_next(const slob_t *s)
93999 {
94000 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
94001 slobidx_t next;
94002 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
94003 /*
94004 * Returns true if s is the last free block in its page.
94005 */
94006 -static int slob_last(slob_t *s)
94007 +static int slob_last(const slob_t *s)
94008 {
94009 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
94010 }
94011
94012 -static void *slob_new_pages(gfp_t gfp, int order, int node)
94013 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
94014 {
94015 - void *page;
94016 + struct page *page;
94017
94018 #ifdef CONFIG_NUMA
94019 if (node != NUMA_NO_NODE)
94020 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
94021 if (!page)
94022 return NULL;
94023
94024 - return page_address(page);
94025 + __SetPageSlab(page);
94026 + return page;
94027 }
94028
94029 -static void slob_free_pages(void *b, int order)
94030 +static void slob_free_pages(struct page *sp, int order)
94031 {
94032 if (current->reclaim_state)
94033 current->reclaim_state->reclaimed_slab += 1 << order;
94034 - free_pages((unsigned long)b, order);
94035 + __ClearPageSlab(sp);
94036 + page_mapcount_reset(sp);
94037 + sp->private = 0;
94038 + __free_pages(sp, order);
94039 }
94040
94041 /*
94042 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
94043
94044 /* Not enough space: must allocate a new page */
94045 if (!b) {
94046 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
94047 - if (!b)
94048 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
94049 + if (!sp)
94050 return NULL;
94051 - sp = virt_to_page(b);
94052 - __SetPageSlab(sp);
94053 + b = page_address(sp);
94054
94055 spin_lock_irqsave(&slob_lock, flags);
94056 sp->units = SLOB_UNITS(PAGE_SIZE);
94057 sp->freelist = b;
94058 + sp->private = 0;
94059 INIT_LIST_HEAD(&sp->list);
94060 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
94061 set_slob_page_free(sp, slob_list);
94062 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
94063 if (slob_page_free(sp))
94064 clear_slob_page_free(sp);
94065 spin_unlock_irqrestore(&slob_lock, flags);
94066 - __ClearPageSlab(sp);
94067 - page_mapcount_reset(sp);
94068 - slob_free_pages(b, 0);
94069 + slob_free_pages(sp, 0);
94070 return;
94071 }
94072
94073 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94074 + if (pax_sanitize_slab)
94075 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
94076 +#endif
94077 +
94078 if (!slob_page_free(sp)) {
94079 /* This slob page is about to become partially free. Easy! */
94080 sp->units = units;
94081 @@ -424,11 +431,10 @@ out:
94082 */
94083
94084 static __always_inline void *
94085 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94086 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
94087 {
94088 - unsigned int *m;
94089 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94090 - void *ret;
94091 + slob_t *m;
94092 + void *ret = NULL;
94093
94094 gfp &= gfp_allowed_mask;
94095
94096 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94097
94098 if (!m)
94099 return NULL;
94100 - *m = size;
94101 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
94102 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
94103 + m[0].units = size;
94104 + m[1].units = align;
94105 ret = (void *)m + align;
94106
94107 trace_kmalloc_node(caller, ret,
94108 size, size + align, gfp, node);
94109 } else {
94110 unsigned int order = get_order(size);
94111 + struct page *page;
94112
94113 if (likely(order))
94114 gfp |= __GFP_COMP;
94115 - ret = slob_new_pages(gfp, order, node);
94116 + page = slob_new_pages(gfp, order, node);
94117 + if (page) {
94118 + ret = page_address(page);
94119 + page->private = size;
94120 + }
94121
94122 trace_kmalloc_node(caller, ret,
94123 size, PAGE_SIZE << order, gfp, node);
94124 }
94125
94126 - kmemleak_alloc(ret, size, 1, gfp);
94127 + return ret;
94128 +}
94129 +
94130 +static __always_inline void *
94131 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94132 +{
94133 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94134 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
94135 +
94136 + if (!ZERO_OR_NULL_PTR(ret))
94137 + kmemleak_alloc(ret, size, 1, gfp);
94138 return ret;
94139 }
94140
94141 @@ -493,34 +517,112 @@ void kfree(const void *block)
94142 return;
94143 kmemleak_free(block);
94144
94145 + VM_BUG_ON(!virt_addr_valid(block));
94146 sp = virt_to_page(block);
94147 - if (PageSlab(sp)) {
94148 + VM_BUG_ON(!PageSlab(sp));
94149 + if (!sp->private) {
94150 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94151 - unsigned int *m = (unsigned int *)(block - align);
94152 - slob_free(m, *m + align);
94153 - } else
94154 + slob_t *m = (slob_t *)(block - align);
94155 + slob_free(m, m[0].units + align);
94156 + } else {
94157 + __ClearPageSlab(sp);
94158 + page_mapcount_reset(sp);
94159 + sp->private = 0;
94160 __free_pages(sp, compound_order(sp));
94161 + }
94162 }
94163 EXPORT_SYMBOL(kfree);
94164
94165 +bool is_usercopy_object(const void *ptr)
94166 +{
94167 + if (!slab_is_available())
94168 + return false;
94169 +
94170 + // PAX: TODO
94171 +
94172 + return false;
94173 +}
94174 +
94175 +#ifdef CONFIG_PAX_USERCOPY
94176 +const char *check_heap_object(const void *ptr, unsigned long n)
94177 +{
94178 + struct page *page;
94179 + const slob_t *free;
94180 + const void *base;
94181 + unsigned long flags;
94182 +
94183 + if (ZERO_OR_NULL_PTR(ptr))
94184 + return "<null>";
94185 +
94186 + if (!virt_addr_valid(ptr))
94187 + return NULL;
94188 +
94189 + page = virt_to_head_page(ptr);
94190 + if (!PageSlab(page))
94191 + return NULL;
94192 +
94193 + if (page->private) {
94194 + base = page;
94195 + if (base <= ptr && n <= page->private - (ptr - base))
94196 + return NULL;
94197 + return "<slob>";
94198 + }
94199 +
94200 + /* some tricky double walking to find the chunk */
94201 + spin_lock_irqsave(&slob_lock, flags);
94202 + base = (void *)((unsigned long)ptr & PAGE_MASK);
94203 + free = page->freelist;
94204 +
94205 + while (!slob_last(free) && (void *)free <= ptr) {
94206 + base = free + slob_units(free);
94207 + free = slob_next(free);
94208 + }
94209 +
94210 + while (base < (void *)free) {
94211 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
94212 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
94213 + int offset;
94214 +
94215 + if (ptr < base + align)
94216 + break;
94217 +
94218 + offset = ptr - base - align;
94219 + if (offset >= m) {
94220 + base += size;
94221 + continue;
94222 + }
94223 +
94224 + if (n > m - offset)
94225 + break;
94226 +
94227 + spin_unlock_irqrestore(&slob_lock, flags);
94228 + return NULL;
94229 + }
94230 +
94231 + spin_unlock_irqrestore(&slob_lock, flags);
94232 + return "<slob>";
94233 +}
94234 +#endif
94235 +
94236 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
94237 size_t ksize(const void *block)
94238 {
94239 struct page *sp;
94240 int align;
94241 - unsigned int *m;
94242 + slob_t *m;
94243
94244 BUG_ON(!block);
94245 if (unlikely(block == ZERO_SIZE_PTR))
94246 return 0;
94247
94248 sp = virt_to_page(block);
94249 - if (unlikely(!PageSlab(sp)))
94250 - return PAGE_SIZE << compound_order(sp);
94251 + VM_BUG_ON(!PageSlab(sp));
94252 + if (sp->private)
94253 + return sp->private;
94254
94255 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94256 - m = (unsigned int *)(block - align);
94257 - return SLOB_UNITS(*m) * SLOB_UNIT;
94258 + m = (slob_t *)(block - align);
94259 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
94260 }
94261 EXPORT_SYMBOL(ksize);
94262
94263 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
94264
94265 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
94266 {
94267 - void *b;
94268 + void *b = NULL;
94269
94270 flags &= gfp_allowed_mask;
94271
94272 lockdep_trace_alloc(flags);
94273
94274 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94275 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
94276 +#else
94277 if (c->size < PAGE_SIZE) {
94278 b = slob_alloc(c->size, flags, c->align, node);
94279 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94280 SLOB_UNITS(c->size) * SLOB_UNIT,
94281 flags, node);
94282 } else {
94283 - b = slob_new_pages(flags, get_order(c->size), node);
94284 + struct page *sp;
94285 +
94286 + sp = slob_new_pages(flags, get_order(c->size), node);
94287 + if (sp) {
94288 + b = page_address(sp);
94289 + sp->private = c->size;
94290 + }
94291 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94292 PAGE_SIZE << get_order(c->size),
94293 flags, node);
94294 }
94295 +#endif
94296
94297 if (b && c->ctor)
94298 c->ctor(b);
94299 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
94300
94301 static void __kmem_cache_free(void *b, int size)
94302 {
94303 - if (size < PAGE_SIZE)
94304 + struct page *sp;
94305 +
94306 + sp = virt_to_page(b);
94307 + BUG_ON(!PageSlab(sp));
94308 + if (!sp->private)
94309 slob_free(b, size);
94310 else
94311 - slob_free_pages(b, get_order(size));
94312 + slob_free_pages(sp, get_order(size));
94313 }
94314
94315 static void kmem_rcu_free(struct rcu_head *head)
94316 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
94317
94318 void kmem_cache_free(struct kmem_cache *c, void *b)
94319 {
94320 + int size = c->size;
94321 +
94322 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94323 + if (size + c->align < PAGE_SIZE) {
94324 + size += c->align;
94325 + b -= c->align;
94326 + }
94327 +#endif
94328 +
94329 kmemleak_free_recursive(b, c->flags);
94330 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
94331 struct slob_rcu *slob_rcu;
94332 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
94333 - slob_rcu->size = c->size;
94334 + slob_rcu = b + (size - sizeof(struct slob_rcu));
94335 + slob_rcu->size = size;
94336 call_rcu(&slob_rcu->head, kmem_rcu_free);
94337 } else {
94338 - __kmem_cache_free(b, c->size);
94339 + __kmem_cache_free(b, size);
94340 }
94341
94342 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94343 + trace_kfree(_RET_IP_, b);
94344 +#else
94345 trace_kmem_cache_free(_RET_IP_, b);
94346 +#endif
94347 +
94348 }
94349 EXPORT_SYMBOL(kmem_cache_free);
94350
94351 diff --git a/mm/slub.c b/mm/slub.c
94352 index 545a170..a086226 100644
94353 --- a/mm/slub.c
94354 +++ b/mm/slub.c
94355 @@ -207,7 +207,7 @@ struct track {
94356
94357 enum track_item { TRACK_ALLOC, TRACK_FREE };
94358
94359 -#ifdef CONFIG_SYSFS
94360 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94361 static int sysfs_slab_add(struct kmem_cache *);
94362 static int sysfs_slab_alias(struct kmem_cache *, const char *);
94363 static void sysfs_slab_remove(struct kmem_cache *);
94364 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
94365 if (!t->addr)
94366 return;
94367
94368 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
94369 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
94370 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
94371 #ifdef CONFIG_STACKTRACE
94372 {
94373 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
94374
94375 slab_free_hook(s, x);
94376
94377 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94378 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
94379 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
94380 + if (s->ctor)
94381 + s->ctor(x);
94382 + }
94383 +#endif
94384 +
94385 redo:
94386 /*
94387 * Determine the currently cpus per cpu slab.
94388 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
94389 * Merge control. If this is set then no merging of slab caches will occur.
94390 * (Could be removed. This was introduced to pacify the merge skeptics.)
94391 */
94392 -static int slub_nomerge;
94393 +static int slub_nomerge = 1;
94394
94395 /*
94396 * Calculate the order of allocation given an slab object size.
94397 @@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
94398 s->inuse = size;
94399
94400 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
94401 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94402 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
94403 +#endif
94404 s->ctor)) {
94405 /*
94406 * Relocate free pointer after the object if it is not
94407 @@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
94408 EXPORT_SYMBOL(__kmalloc_node);
94409 #endif
94410
94411 +bool is_usercopy_object(const void *ptr)
94412 +{
94413 + struct page *page;
94414 + struct kmem_cache *s;
94415 +
94416 + if (ZERO_OR_NULL_PTR(ptr))
94417 + return false;
94418 +
94419 + if (!slab_is_available())
94420 + return false;
94421 +
94422 + if (!virt_addr_valid(ptr))
94423 + return false;
94424 +
94425 + page = virt_to_head_page(ptr);
94426 +
94427 + if (!PageSlab(page))
94428 + return false;
94429 +
94430 + s = page->slab_cache;
94431 + return s->flags & SLAB_USERCOPY;
94432 +}
94433 +
94434 +#ifdef CONFIG_PAX_USERCOPY
94435 +const char *check_heap_object(const void *ptr, unsigned long n)
94436 +{
94437 + struct page *page;
94438 + struct kmem_cache *s;
94439 + unsigned long offset;
94440 +
94441 + if (ZERO_OR_NULL_PTR(ptr))
94442 + return "<null>";
94443 +
94444 + if (!virt_addr_valid(ptr))
94445 + return NULL;
94446 +
94447 + page = virt_to_head_page(ptr);
94448 +
94449 + if (!PageSlab(page))
94450 + return NULL;
94451 +
94452 + s = page->slab_cache;
94453 + if (!(s->flags & SLAB_USERCOPY))
94454 + return s->name;
94455 +
94456 + offset = (ptr - page_address(page)) % s->size;
94457 + if (offset <= s->object_size && n <= s->object_size - offset)
94458 + return NULL;
94459 +
94460 + return s->name;
94461 +}
94462 +#endif
94463 +
94464 size_t ksize(const void *object)
94465 {
94466 struct page *page;
94467 @@ -3360,6 +3424,7 @@ void kfree(const void *x)
94468 if (unlikely(ZERO_OR_NULL_PTR(x)))
94469 return;
94470
94471 + VM_BUG_ON(!virt_addr_valid(x));
94472 page = virt_to_head_page(x);
94473 if (unlikely(!PageSlab(page))) {
94474 BUG_ON(!PageCompound(page));
94475 @@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
94476 /*
94477 * We may have set a slab to be unmergeable during bootstrap.
94478 */
94479 - if (s->refcount < 0)
94480 + if (atomic_read(&s->refcount) < 0)
94481 return 1;
94482
94483 return 0;
94484 @@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94485
94486 s = find_mergeable(memcg, size, align, flags, name, ctor);
94487 if (s) {
94488 - s->refcount++;
94489 + atomic_inc(&s->refcount);
94490 /*
94491 * Adjust the object sizes so that we clear
94492 * the complete object on kzalloc.
94493 @@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94494 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
94495
94496 if (sysfs_slab_alias(s, name)) {
94497 - s->refcount--;
94498 + atomic_dec(&s->refcount);
94499 s = NULL;
94500 }
94501 }
94502 @@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
94503 }
94504 #endif
94505
94506 -#ifdef CONFIG_SYSFS
94507 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94508 static int count_inuse(struct page *page)
94509 {
94510 return page->inuse;
94511 @@ -4241,12 +4306,12 @@ static void resiliency_test(void)
94512 validate_slab_cache(kmalloc_caches[9]);
94513 }
94514 #else
94515 -#ifdef CONFIG_SYSFS
94516 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94517 static void resiliency_test(void) {};
94518 #endif
94519 #endif
94520
94521 -#ifdef CONFIG_SYSFS
94522 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94523 enum slab_stat_type {
94524 SL_ALL, /* All slabs */
94525 SL_PARTIAL, /* Only partially allocated slabs */
94526 @@ -4486,7 +4551,7 @@ SLAB_ATTR_RO(ctor);
94527
94528 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
94529 {
94530 - return sprintf(buf, "%d\n", s->refcount - 1);
94531 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
94532 }
94533 SLAB_ATTR_RO(aliases);
94534
94535 @@ -4574,6 +4639,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
94536 SLAB_ATTR_RO(cache_dma);
94537 #endif
94538
94539 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94540 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
94541 +{
94542 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
94543 +}
94544 +SLAB_ATTR_RO(usercopy);
94545 +#endif
94546 +
94547 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
94548 {
94549 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
94550 @@ -4908,6 +4981,9 @@ static struct attribute *slab_attrs[] = {
94551 #ifdef CONFIG_ZONE_DMA
94552 &cache_dma_attr.attr,
94553 #endif
94554 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94555 + &usercopy_attr.attr,
94556 +#endif
94557 #ifdef CONFIG_NUMA
94558 &remote_node_defrag_ratio_attr.attr,
94559 #endif
94560 @@ -5140,6 +5216,7 @@ static char *create_unique_id(struct kmem_cache *s)
94561 return name;
94562 }
94563
94564 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94565 static int sysfs_slab_add(struct kmem_cache *s)
94566 {
94567 int err;
94568 @@ -5163,7 +5240,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
94569 }
94570
94571 s->kobj.kset = slab_kset;
94572 - err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
94573 + err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
94574 if (err) {
94575 kobject_put(&s->kobj);
94576 return err;
94577 @@ -5197,6 +5274,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
94578 kobject_del(&s->kobj);
94579 kobject_put(&s->kobj);
94580 }
94581 +#endif
94582
94583 /*
94584 * Need to buffer aliases during bootup until sysfs becomes
94585 @@ -5210,6 +5288,7 @@ struct saved_alias {
94586
94587 static struct saved_alias *alias_list;
94588
94589 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94590 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94591 {
94592 struct saved_alias *al;
94593 @@ -5232,6 +5311,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94594 alias_list = al;
94595 return 0;
94596 }
94597 +#endif
94598
94599 static int __init slab_sysfs_init(void)
94600 {
94601 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
94602 index 27eeab3..7c3f7f2 100644
94603 --- a/mm/sparse-vmemmap.c
94604 +++ b/mm/sparse-vmemmap.c
94605 @@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
94606 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94607 if (!p)
94608 return NULL;
94609 - pud_populate(&init_mm, pud, p);
94610 + pud_populate_kernel(&init_mm, pud, p);
94611 }
94612 return pud;
94613 }
94614 @@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
94615 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94616 if (!p)
94617 return NULL;
94618 - pgd_populate(&init_mm, pgd, p);
94619 + pgd_populate_kernel(&init_mm, pgd, p);
94620 }
94621 return pgd;
94622 }
94623 diff --git a/mm/sparse.c b/mm/sparse.c
94624 index 8cc7be0..d0f7d7a 100644
94625 --- a/mm/sparse.c
94626 +++ b/mm/sparse.c
94627 @@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
94628
94629 for (i = 0; i < PAGES_PER_SECTION; i++) {
94630 if (PageHWPoison(&memmap[i])) {
94631 - atomic_long_sub(1, &num_poisoned_pages);
94632 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
94633 ClearPageHWPoison(&memmap[i]);
94634 }
94635 }
94636 diff --git a/mm/swap.c b/mm/swap.c
94637 index 84b26aa..ce39899 100644
94638 --- a/mm/swap.c
94639 +++ b/mm/swap.c
94640 @@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
94641
94642 __page_cache_release(page);
94643 dtor = get_compound_page_dtor(page);
94644 + if (!PageHuge(page))
94645 + BUG_ON(dtor != free_compound_page);
94646 (*dtor)(page);
94647 }
94648
94649 diff --git a/mm/swapfile.c b/mm/swapfile.c
94650 index 612a7c9..66b0f5a 100644
94651 --- a/mm/swapfile.c
94652 +++ b/mm/swapfile.c
94653 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
94654
94655 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
94656 /* Activity counter to indicate that a swapon or swapoff has occurred */
94657 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
94658 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
94659
94660 static inline unsigned char swap_count(unsigned char ent)
94661 {
94662 @@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
94663 }
94664 filp_close(swap_file, NULL);
94665 err = 0;
94666 - atomic_inc(&proc_poll_event);
94667 + atomic_inc_unchecked(&proc_poll_event);
94668 wake_up_interruptible(&proc_poll_wait);
94669
94670 out_dput:
94671 @@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
94672
94673 poll_wait(file, &proc_poll_wait, wait);
94674
94675 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
94676 - seq->poll_event = atomic_read(&proc_poll_event);
94677 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
94678 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94679 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
94680 }
94681
94682 @@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
94683 return ret;
94684
94685 seq = file->private_data;
94686 - seq->poll_event = atomic_read(&proc_poll_event);
94687 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94688 return 0;
94689 }
94690
94691 @@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
94692 (frontswap_map) ? "FS" : "");
94693
94694 mutex_unlock(&swapon_mutex);
94695 - atomic_inc(&proc_poll_event);
94696 + atomic_inc_unchecked(&proc_poll_event);
94697 wake_up_interruptible(&proc_poll_wait);
94698
94699 if (S_ISREG(inode->i_mode))
94700 diff --git a/mm/util.c b/mm/util.c
94701 index 808f375..e4764b5 100644
94702 --- a/mm/util.c
94703 +++ b/mm/util.c
94704 @@ -297,6 +297,12 @@ done:
94705 void arch_pick_mmap_layout(struct mm_struct *mm)
94706 {
94707 mm->mmap_base = TASK_UNMAPPED_BASE;
94708 +
94709 +#ifdef CONFIG_PAX_RANDMMAP
94710 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94711 + mm->mmap_base += mm->delta_mmap;
94712 +#endif
94713 +
94714 mm->get_unmapped_area = arch_get_unmapped_area;
94715 }
94716 #endif
94717 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
94718 index 0fdf968..d6686e8 100644
94719 --- a/mm/vmalloc.c
94720 +++ b/mm/vmalloc.c
94721 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
94722
94723 pte = pte_offset_kernel(pmd, addr);
94724 do {
94725 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94726 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94727 +
94728 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94729 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
94730 + BUG_ON(!pte_exec(*pte));
94731 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
94732 + continue;
94733 + }
94734 +#endif
94735 +
94736 + {
94737 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94738 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94739 + }
94740 } while (pte++, addr += PAGE_SIZE, addr != end);
94741 }
94742
94743 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
94744 pte = pte_alloc_kernel(pmd, addr);
94745 if (!pte)
94746 return -ENOMEM;
94747 +
94748 + pax_open_kernel();
94749 do {
94750 struct page *page = pages[*nr];
94751
94752 - if (WARN_ON(!pte_none(*pte)))
94753 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94754 + if (pgprot_val(prot) & _PAGE_NX)
94755 +#endif
94756 +
94757 + if (!pte_none(*pte)) {
94758 + pax_close_kernel();
94759 + WARN_ON(1);
94760 return -EBUSY;
94761 - if (WARN_ON(!page))
94762 + }
94763 + if (!page) {
94764 + pax_close_kernel();
94765 + WARN_ON(1);
94766 return -ENOMEM;
94767 + }
94768 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
94769 (*nr)++;
94770 } while (pte++, addr += PAGE_SIZE, addr != end);
94771 + pax_close_kernel();
94772 return 0;
94773 }
94774
94775 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
94776 pmd_t *pmd;
94777 unsigned long next;
94778
94779 - pmd = pmd_alloc(&init_mm, pud, addr);
94780 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94781 if (!pmd)
94782 return -ENOMEM;
94783 do {
94784 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
94785 pud_t *pud;
94786 unsigned long next;
94787
94788 - pud = pud_alloc(&init_mm, pgd, addr);
94789 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94790 if (!pud)
94791 return -ENOMEM;
94792 do {
94793 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
94794 if (addr >= MODULES_VADDR && addr < MODULES_END)
94795 return 1;
94796 #endif
94797 +
94798 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94799 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
94800 + return 1;
94801 +#endif
94802 +
94803 return is_vmalloc_addr(x);
94804 }
94805
94806 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
94807
94808 if (!pgd_none(*pgd)) {
94809 pud_t *pud = pud_offset(pgd, addr);
94810 +#ifdef CONFIG_X86
94811 + if (!pud_large(*pud))
94812 +#endif
94813 if (!pud_none(*pud)) {
94814 pmd_t *pmd = pmd_offset(pud, addr);
94815 +#ifdef CONFIG_X86
94816 + if (!pmd_large(*pmd))
94817 +#endif
94818 if (!pmd_none(*pmd)) {
94819 pte_t *ptep, pte;
94820
94821 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
94822 struct vm_struct *area;
94823
94824 BUG_ON(in_interrupt());
94825 +
94826 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94827 + if (flags & VM_KERNEXEC) {
94828 + if (start != VMALLOC_START || end != VMALLOC_END)
94829 + return NULL;
94830 + start = (unsigned long)MODULES_EXEC_VADDR;
94831 + end = (unsigned long)MODULES_EXEC_END;
94832 + }
94833 +#endif
94834 +
94835 if (flags & VM_IOREMAP)
94836 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
94837
94838 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
94839 if (count > totalram_pages)
94840 return NULL;
94841
94842 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94843 + if (!(pgprot_val(prot) & _PAGE_NX))
94844 + flags |= VM_KERNEXEC;
94845 +#endif
94846 +
94847 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
94848 __builtin_return_address(0));
94849 if (!area)
94850 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
94851 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
94852 goto fail;
94853
94854 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94855 + if (!(pgprot_val(prot) & _PAGE_NX))
94856 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
94857 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
94858 + else
94859 +#endif
94860 +
94861 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
94862 start, end, node, gfp_mask, caller);
94863 if (!area)
94864 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
94865 * For tight control over page level allocator and protection flags
94866 * use __vmalloc() instead.
94867 */
94868 -
94869 void *vmalloc_exec(unsigned long size)
94870 {
94871 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
94872 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
94873 NUMA_NO_NODE, __builtin_return_address(0));
94874 }
94875
94876 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
94877 {
94878 struct vm_struct *area;
94879
94880 + BUG_ON(vma->vm_mirror);
94881 +
94882 size = PAGE_ALIGN(size);
94883
94884 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
94885 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
94886 v->addr, v->addr + v->size, v->size);
94887
94888 if (v->caller)
94889 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94890 + seq_printf(m, " %pK", v->caller);
94891 +#else
94892 seq_printf(m, " %pS", v->caller);
94893 +#endif
94894
94895 if (v->nr_pages)
94896 seq_printf(m, " pages=%d", v->nr_pages);
94897 diff --git a/mm/vmstat.c b/mm/vmstat.c
94898 index 7249614..2639fc7 100644
94899 --- a/mm/vmstat.c
94900 +++ b/mm/vmstat.c
94901 @@ -20,6 +20,7 @@
94902 #include <linux/writeback.h>
94903 #include <linux/compaction.h>
94904 #include <linux/mm_inline.h>
94905 +#include <linux/grsecurity.h>
94906
94907 #include "internal.h"
94908
94909 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
94910 *
94911 * vm_stat contains the global counters
94912 */
94913 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94914 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94915 EXPORT_SYMBOL(vm_stat);
94916
94917 #ifdef CONFIG_SMP
94918 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
94919
94920 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94921 if (diff[i])
94922 - atomic_long_add(diff[i], &vm_stat[i]);
94923 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
94924 }
94925
94926 /*
94927 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
94928 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
94929 if (v) {
94930
94931 - atomic_long_add(v, &zone->vm_stat[i]);
94932 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94933 global_diff[i] += v;
94934 #ifdef CONFIG_NUMA
94935 /* 3 seconds idle till flush */
94936 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
94937
94938 v = p->vm_stat_diff[i];
94939 p->vm_stat_diff[i] = 0;
94940 - atomic_long_add(v, &zone->vm_stat[i]);
94941 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94942 global_diff[i] += v;
94943 }
94944 }
94945 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
94946 if (pset->vm_stat_diff[i]) {
94947 int v = pset->vm_stat_diff[i];
94948 pset->vm_stat_diff[i] = 0;
94949 - atomic_long_add(v, &zone->vm_stat[i]);
94950 - atomic_long_add(v, &vm_stat[i]);
94951 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94952 + atomic_long_add_unchecked(v, &vm_stat[i]);
94953 }
94954 }
94955 #endif
94956 @@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
94957 stat_items_size += sizeof(struct vm_event_state);
94958 #endif
94959
94960 - v = kmalloc(stat_items_size, GFP_KERNEL);
94961 + v = kzalloc(stat_items_size, GFP_KERNEL);
94962 m->private = v;
94963 if (!v)
94964 return ERR_PTR(-ENOMEM);
94965 +
94966 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94967 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94968 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
94969 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
94970 + && !in_group_p(grsec_proc_gid)
94971 +#endif
94972 + )
94973 + return (unsigned long *)m->private + *pos;
94974 +#endif
94975 +#endif
94976 +
94977 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94978 v[i] = global_page_state(i);
94979 v += NR_VM_ZONE_STAT_ITEMS;
94980 @@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
94981 put_online_cpus();
94982 #endif
94983 #ifdef CONFIG_PROC_FS
94984 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
94985 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
94986 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94987 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
94988 + {
94989 + mode_t gr_mode = S_IRUGO;
94990 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94991 + gr_mode = S_IRUSR;
94992 +#endif
94993 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
94994 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
94995 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94996 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
94997 + }
94998 #endif
94999 return 0;
95000 }
95001 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
95002 index b3d17d1..e8e4cdd 100644
95003 --- a/net/8021q/vlan.c
95004 +++ b/net/8021q/vlan.c
95005 @@ -472,7 +472,7 @@ out:
95006 return NOTIFY_DONE;
95007 }
95008
95009 -static struct notifier_block vlan_notifier_block __read_mostly = {
95010 +static struct notifier_block vlan_notifier_block = {
95011 .notifier_call = vlan_device_event,
95012 };
95013
95014 @@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
95015 err = -EPERM;
95016 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
95017 break;
95018 - if ((args.u.name_type >= 0) &&
95019 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
95020 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
95021 struct vlan_net *vn;
95022
95023 vn = net_generic(net, vlan_net_id);
95024 diff --git a/net/9p/client.c b/net/9p/client.c
95025 index ee8fd6b..0469d50 100644
95026 --- a/net/9p/client.c
95027 +++ b/net/9p/client.c
95028 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
95029 len - inline_len);
95030 } else {
95031 err = copy_from_user(ename + inline_len,
95032 - uidata, len - inline_len);
95033 + (char __force_user *)uidata, len - inline_len);
95034 if (err) {
95035 err = -EFAULT;
95036 goto out_err;
95037 @@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
95038 kernel_buf = 1;
95039 indata = data;
95040 } else
95041 - indata = (__force char *)udata;
95042 + indata = (__force_kernel char *)udata;
95043 /*
95044 * response header len is 11
95045 * PDU Header(7) + IO Size (4)
95046 @@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
95047 kernel_buf = 1;
95048 odata = data;
95049 } else
95050 - odata = (char *)udata;
95051 + odata = (char __force_kernel *)udata;
95052 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
95053 P9_ZC_HDR_SZ, kernel_buf, "dqd",
95054 fid->fid, offset, rsize);
95055 diff --git a/net/9p/mod.c b/net/9p/mod.c
95056 index 6ab36ae..6f1841b 100644
95057 --- a/net/9p/mod.c
95058 +++ b/net/9p/mod.c
95059 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
95060 void v9fs_register_trans(struct p9_trans_module *m)
95061 {
95062 spin_lock(&v9fs_trans_lock);
95063 - list_add_tail(&m->list, &v9fs_trans_list);
95064 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
95065 spin_unlock(&v9fs_trans_lock);
95066 }
95067 EXPORT_SYMBOL(v9fs_register_trans);
95068 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
95069 void v9fs_unregister_trans(struct p9_trans_module *m)
95070 {
95071 spin_lock(&v9fs_trans_lock);
95072 - list_del_init(&m->list);
95073 + pax_list_del_init((struct list_head *)&m->list);
95074 spin_unlock(&v9fs_trans_lock);
95075 }
95076 EXPORT_SYMBOL(v9fs_unregister_trans);
95077 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
95078 index 9321a77..ed2f256 100644
95079 --- a/net/9p/trans_fd.c
95080 +++ b/net/9p/trans_fd.c
95081 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
95082 oldfs = get_fs();
95083 set_fs(get_ds());
95084 /* The cast to a user pointer is valid due to the set_fs() */
95085 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
95086 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
95087 set_fs(oldfs);
95088
95089 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
95090 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
95091 index 876fbe8..8bbea9f 100644
95092 --- a/net/atm/atm_misc.c
95093 +++ b/net/atm/atm_misc.c
95094 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
95095 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
95096 return 1;
95097 atm_return(vcc, truesize);
95098 - atomic_inc(&vcc->stats->rx_drop);
95099 + atomic_inc_unchecked(&vcc->stats->rx_drop);
95100 return 0;
95101 }
95102 EXPORT_SYMBOL(atm_charge);
95103 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
95104 }
95105 }
95106 atm_return(vcc, guess);
95107 - atomic_inc(&vcc->stats->rx_drop);
95108 + atomic_inc_unchecked(&vcc->stats->rx_drop);
95109 return NULL;
95110 }
95111 EXPORT_SYMBOL(atm_alloc_charge);
95112 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
95113
95114 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95115 {
95116 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95117 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95118 __SONET_ITEMS
95119 #undef __HANDLE_ITEM
95120 }
95121 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
95122
95123 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95124 {
95125 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95126 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
95127 __SONET_ITEMS
95128 #undef __HANDLE_ITEM
95129 }
95130 diff --git a/net/atm/lec.c b/net/atm/lec.c
95131 index f23916b..dd4d26b 100644
95132 --- a/net/atm/lec.c
95133 +++ b/net/atm/lec.c
95134 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
95135 }
95136
95137 static struct lane2_ops lane2_ops = {
95138 - lane2_resolve, /* resolve, spec 3.1.3 */
95139 - lane2_associate_req, /* associate_req, spec 3.1.4 */
95140 - NULL /* associate indicator, spec 3.1.5 */
95141 + .resolve = lane2_resolve,
95142 + .associate_req = lane2_associate_req,
95143 + .associate_indicator = NULL
95144 };
95145
95146 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
95147 diff --git a/net/atm/lec.h b/net/atm/lec.h
95148 index 4149db1..f2ab682 100644
95149 --- a/net/atm/lec.h
95150 +++ b/net/atm/lec.h
95151 @@ -48,7 +48,7 @@ struct lane2_ops {
95152 const u8 *tlvs, u32 sizeoftlvs);
95153 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
95154 const u8 *tlvs, u32 sizeoftlvs);
95155 -};
95156 +} __no_const;
95157
95158 /*
95159 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
95160 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
95161 index d1b2d9a..d549f7f 100644
95162 --- a/net/atm/mpoa_caches.c
95163 +++ b/net/atm/mpoa_caches.c
95164 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
95165
95166
95167 static struct in_cache_ops ingress_ops = {
95168 - in_cache_add_entry, /* add_entry */
95169 - in_cache_get, /* get */
95170 - in_cache_get_with_mask, /* get_with_mask */
95171 - in_cache_get_by_vcc, /* get_by_vcc */
95172 - in_cache_put, /* put */
95173 - in_cache_remove_entry, /* remove_entry */
95174 - cache_hit, /* cache_hit */
95175 - clear_count_and_expired, /* clear_count */
95176 - check_resolving_entries, /* check_resolving */
95177 - refresh_entries, /* refresh */
95178 - in_destroy_cache /* destroy_cache */
95179 + .add_entry = in_cache_add_entry,
95180 + .get = in_cache_get,
95181 + .get_with_mask = in_cache_get_with_mask,
95182 + .get_by_vcc = in_cache_get_by_vcc,
95183 + .put = in_cache_put,
95184 + .remove_entry = in_cache_remove_entry,
95185 + .cache_hit = cache_hit,
95186 + .clear_count = clear_count_and_expired,
95187 + .check_resolving = check_resolving_entries,
95188 + .refresh = refresh_entries,
95189 + .destroy_cache = in_destroy_cache
95190 };
95191
95192 static struct eg_cache_ops egress_ops = {
95193 - eg_cache_add_entry, /* add_entry */
95194 - eg_cache_get_by_cache_id, /* get_by_cache_id */
95195 - eg_cache_get_by_tag, /* get_by_tag */
95196 - eg_cache_get_by_vcc, /* get_by_vcc */
95197 - eg_cache_get_by_src_ip, /* get_by_src_ip */
95198 - eg_cache_put, /* put */
95199 - eg_cache_remove_entry, /* remove_entry */
95200 - update_eg_cache_entry, /* update */
95201 - clear_expired, /* clear_expired */
95202 - eg_destroy_cache /* destroy_cache */
95203 + .add_entry = eg_cache_add_entry,
95204 + .get_by_cache_id = eg_cache_get_by_cache_id,
95205 + .get_by_tag = eg_cache_get_by_tag,
95206 + .get_by_vcc = eg_cache_get_by_vcc,
95207 + .get_by_src_ip = eg_cache_get_by_src_ip,
95208 + .put = eg_cache_put,
95209 + .remove_entry = eg_cache_remove_entry,
95210 + .update = update_eg_cache_entry,
95211 + .clear_expired = clear_expired,
95212 + .destroy_cache = eg_destroy_cache
95213 };
95214
95215
95216 diff --git a/net/atm/proc.c b/net/atm/proc.c
95217 index bbb6461..cf04016 100644
95218 --- a/net/atm/proc.c
95219 +++ b/net/atm/proc.c
95220 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
95221 const struct k_atm_aal_stats *stats)
95222 {
95223 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
95224 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
95225 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
95226 - atomic_read(&stats->rx_drop));
95227 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
95228 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
95229 + atomic_read_unchecked(&stats->rx_drop));
95230 }
95231
95232 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
95233 diff --git a/net/atm/resources.c b/net/atm/resources.c
95234 index 0447d5d..3cf4728 100644
95235 --- a/net/atm/resources.c
95236 +++ b/net/atm/resources.c
95237 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
95238 static void copy_aal_stats(struct k_atm_aal_stats *from,
95239 struct atm_aal_stats *to)
95240 {
95241 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95242 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95243 __AAL_STAT_ITEMS
95244 #undef __HANDLE_ITEM
95245 }
95246 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
95247 static void subtract_aal_stats(struct k_atm_aal_stats *from,
95248 struct atm_aal_stats *to)
95249 {
95250 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95251 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
95252 __AAL_STAT_ITEMS
95253 #undef __HANDLE_ITEM
95254 }
95255 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
95256 index 919a5ce..cc6b444 100644
95257 --- a/net/ax25/sysctl_net_ax25.c
95258 +++ b/net/ax25/sysctl_net_ax25.c
95259 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
95260 {
95261 char path[sizeof("net/ax25/") + IFNAMSIZ];
95262 int k;
95263 - struct ctl_table *table;
95264 + ctl_table_no_const *table;
95265
95266 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
95267 if (!table)
95268 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
95269 index b9c8a6e..ed0f711 100644
95270 --- a/net/batman-adv/bat_iv_ogm.c
95271 +++ b/net/batman-adv/bat_iv_ogm.c
95272 @@ -297,7 +297,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
95273
95274 /* randomize initial seqno to avoid collision */
95275 get_random_bytes(&random_seqno, sizeof(random_seqno));
95276 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95277 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95278
95279 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
95280 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
95281 @@ -884,9 +884,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
95282 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
95283
95284 /* change sequence number to network order */
95285 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
95286 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
95287 batadv_ogm_packet->seqno = htonl(seqno);
95288 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
95289 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
95290
95291 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
95292 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
95293 @@ -1251,7 +1251,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
95294 return;
95295
95296 /* could be changed by schedule_own_packet() */
95297 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
95298 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
95299
95300 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
95301 has_directlink_flag = 1;
95302 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
95303 index 6ddb614..ca7e886 100644
95304 --- a/net/batman-adv/fragmentation.c
95305 +++ b/net/batman-adv/fragmentation.c
95306 @@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
95307 frag_header.packet_type = BATADV_UNICAST_FRAG;
95308 frag_header.version = BATADV_COMPAT_VERSION;
95309 frag_header.ttl = BATADV_TTL;
95310 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
95311 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
95312 frag_header.reserved = 0;
95313 frag_header.no = 0;
95314 frag_header.total_size = htons(skb->len);
95315 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
95316 index a8f99d1..11797ef 100644
95317 --- a/net/batman-adv/soft-interface.c
95318 +++ b/net/batman-adv/soft-interface.c
95319 @@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
95320 primary_if->net_dev->dev_addr, ETH_ALEN);
95321
95322 /* set broadcast sequence number */
95323 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
95324 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
95325 bcast_packet->seqno = htonl(seqno);
95326
95327 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
95328 @@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95329 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
95330
95331 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
95332 - atomic_set(&bat_priv->bcast_seqno, 1);
95333 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
95334 atomic_set(&bat_priv->tt.vn, 0);
95335 atomic_set(&bat_priv->tt.local_changes, 0);
95336 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
95337 @@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95338
95339 /* randomize initial seqno to avoid collision */
95340 get_random_bytes(&random_seqno, sizeof(random_seqno));
95341 - atomic_set(&bat_priv->frag_seqno, random_seqno);
95342 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
95343
95344 bat_priv->primary_if = NULL;
95345 bat_priv->num_ifaces = 0;
95346 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
95347 index 91dd369..9c25750 100644
95348 --- a/net/batman-adv/types.h
95349 +++ b/net/batman-adv/types.h
95350 @@ -56,7 +56,7 @@
95351 struct batadv_hard_iface_bat_iv {
95352 unsigned char *ogm_buff;
95353 int ogm_buff_len;
95354 - atomic_t ogm_seqno;
95355 + atomic_unchecked_t ogm_seqno;
95356 };
95357
95358 /**
95359 @@ -673,7 +673,7 @@ struct batadv_priv {
95360 atomic_t bonding;
95361 atomic_t fragmentation;
95362 atomic_t packet_size_max;
95363 - atomic_t frag_seqno;
95364 + atomic_unchecked_t frag_seqno;
95365 #ifdef CONFIG_BATMAN_ADV_BLA
95366 atomic_t bridge_loop_avoidance;
95367 #endif
95368 @@ -687,7 +687,7 @@ struct batadv_priv {
95369 #ifdef CONFIG_BATMAN_ADV_DEBUG
95370 atomic_t log_level;
95371 #endif
95372 - atomic_t bcast_seqno;
95373 + atomic_unchecked_t bcast_seqno;
95374 atomic_t bcast_queue_left;
95375 atomic_t batman_queue_left;
95376 char num_ifaces;
95377 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
95378 index 7552f9e..074ce29 100644
95379 --- a/net/bluetooth/hci_sock.c
95380 +++ b/net/bluetooth/hci_sock.c
95381 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
95382 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
95383 }
95384
95385 - len = min_t(unsigned int, len, sizeof(uf));
95386 + len = min((size_t)len, sizeof(uf));
95387 if (copy_from_user(&uf, optval, len)) {
95388 err = -EFAULT;
95389 break;
95390 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
95391 index 4af3821..f2ba46c 100644
95392 --- a/net/bluetooth/l2cap_core.c
95393 +++ b/net/bluetooth/l2cap_core.c
95394 @@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
95395 break;
95396
95397 case L2CAP_CONF_RFC:
95398 - if (olen == sizeof(rfc))
95399 - memcpy(&rfc, (void *)val, olen);
95400 + if (olen != sizeof(rfc))
95401 + break;
95402 +
95403 + memcpy(&rfc, (void *)val, olen);
95404
95405 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
95406 rfc.mode != chan->mode)
95407 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
95408 index 7cc24d2..e83f531 100644
95409 --- a/net/bluetooth/l2cap_sock.c
95410 +++ b/net/bluetooth/l2cap_sock.c
95411 @@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95412 struct sock *sk = sock->sk;
95413 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
95414 struct l2cap_options opts;
95415 - int len, err = 0;
95416 + int err = 0;
95417 + size_t len = optlen;
95418 u32 opt;
95419
95420 BT_DBG("sk %p", sk);
95421 @@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95422 opts.max_tx = chan->max_tx;
95423 opts.txwin_size = chan->tx_win;
95424
95425 - len = min_t(unsigned int, sizeof(opts), optlen);
95426 + len = min(sizeof(opts), len);
95427 if (copy_from_user((char *) &opts, optval, len)) {
95428 err = -EFAULT;
95429 break;
95430 @@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95431 struct bt_security sec;
95432 struct bt_power pwr;
95433 struct l2cap_conn *conn;
95434 - int len, err = 0;
95435 + int err = 0;
95436 + size_t len = optlen;
95437 u32 opt;
95438
95439 BT_DBG("sk %p", sk);
95440 @@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95441
95442 sec.level = BT_SECURITY_LOW;
95443
95444 - len = min_t(unsigned int, sizeof(sec), optlen);
95445 + len = min(sizeof(sec), len);
95446 if (copy_from_user((char *) &sec, optval, len)) {
95447 err = -EFAULT;
95448 break;
95449 @@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95450
95451 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
95452
95453 - len = min_t(unsigned int, sizeof(pwr), optlen);
95454 + len = min(sizeof(pwr), len);
95455 if (copy_from_user((char *) &pwr, optval, len)) {
95456 err = -EFAULT;
95457 break;
95458 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
95459 index 3c2d3e4..884855a 100644
95460 --- a/net/bluetooth/rfcomm/sock.c
95461 +++ b/net/bluetooth/rfcomm/sock.c
95462 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95463 struct sock *sk = sock->sk;
95464 struct bt_security sec;
95465 int err = 0;
95466 - size_t len;
95467 + size_t len = optlen;
95468 u32 opt;
95469
95470 BT_DBG("sk %p", sk);
95471 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95472
95473 sec.level = BT_SECURITY_LOW;
95474
95475 - len = min_t(unsigned int, sizeof(sec), optlen);
95476 + len = min(sizeof(sec), len);
95477 if (copy_from_user((char *) &sec, optval, len)) {
95478 err = -EFAULT;
95479 break;
95480 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
95481 index 84fcf9f..e389b27 100644
95482 --- a/net/bluetooth/rfcomm/tty.c
95483 +++ b/net/bluetooth/rfcomm/tty.c
95484 @@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
95485 BT_DBG("tty %p id %d", tty, tty->index);
95486
95487 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
95488 - dev->channel, dev->port.count);
95489 + dev->channel, atomic_read(&dev->port.count));
95490
95491 err = tty_port_open(&dev->port, tty, filp);
95492 if (err)
95493 @@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
95494 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
95495
95496 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
95497 - dev->port.count);
95498 + atomic_read(&dev->port.count));
95499
95500 tty_port_close(&dev->port, tty, filp);
95501 }
95502 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
95503 index ac78024..161a80c 100644
95504 --- a/net/bridge/netfilter/ebtables.c
95505 +++ b/net/bridge/netfilter/ebtables.c
95506 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95507 tmp.valid_hooks = t->table->valid_hooks;
95508 }
95509 mutex_unlock(&ebt_mutex);
95510 - if (copy_to_user(user, &tmp, *len) != 0){
95511 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
95512 BUGPRINT("c2u Didn't work\n");
95513 ret = -EFAULT;
95514 break;
95515 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95516 goto out;
95517 tmp.valid_hooks = t->valid_hooks;
95518
95519 - if (copy_to_user(user, &tmp, *len) != 0) {
95520 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95521 ret = -EFAULT;
95522 break;
95523 }
95524 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95525 tmp.entries_size = t->table->entries_size;
95526 tmp.valid_hooks = t->table->valid_hooks;
95527
95528 - if (copy_to_user(user, &tmp, *len) != 0) {
95529 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95530 ret = -EFAULT;
95531 break;
95532 }
95533 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
95534 index 0f45522..dab651f 100644
95535 --- a/net/caif/cfctrl.c
95536 +++ b/net/caif/cfctrl.c
95537 @@ -10,6 +10,7 @@
95538 #include <linux/spinlock.h>
95539 #include <linux/slab.h>
95540 #include <linux/pkt_sched.h>
95541 +#include <linux/sched.h>
95542 #include <net/caif/caif_layer.h>
95543 #include <net/caif/cfpkt.h>
95544 #include <net/caif/cfctrl.h>
95545 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
95546 memset(&dev_info, 0, sizeof(dev_info));
95547 dev_info.id = 0xff;
95548 cfsrvl_init(&this->serv, 0, &dev_info, false);
95549 - atomic_set(&this->req_seq_no, 1);
95550 - atomic_set(&this->rsp_seq_no, 1);
95551 + atomic_set_unchecked(&this->req_seq_no, 1);
95552 + atomic_set_unchecked(&this->rsp_seq_no, 1);
95553 this->serv.layer.receive = cfctrl_recv;
95554 sprintf(this->serv.layer.name, "ctrl");
95555 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
95556 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
95557 struct cfctrl_request_info *req)
95558 {
95559 spin_lock_bh(&ctrl->info_list_lock);
95560 - atomic_inc(&ctrl->req_seq_no);
95561 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
95562 + atomic_inc_unchecked(&ctrl->req_seq_no);
95563 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
95564 list_add_tail(&req->list, &ctrl->list);
95565 spin_unlock_bh(&ctrl->info_list_lock);
95566 }
95567 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
95568 if (p != first)
95569 pr_warn("Requests are not received in order\n");
95570
95571 - atomic_set(&ctrl->rsp_seq_no,
95572 + atomic_set_unchecked(&ctrl->rsp_seq_no,
95573 p->sequence_no);
95574 list_del(&p->list);
95575 goto out;
95576 diff --git a/net/can/af_can.c b/net/can/af_can.c
95577 index d249874..99e197b 100644
95578 --- a/net/can/af_can.c
95579 +++ b/net/can/af_can.c
95580 @@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
95581 };
95582
95583 /* notifier block for netdevice event */
95584 -static struct notifier_block can_netdev_notifier __read_mostly = {
95585 +static struct notifier_block can_netdev_notifier = {
95586 .notifier_call = can_notifier,
95587 };
95588
95589 diff --git a/net/can/gw.c b/net/can/gw.c
95590 index 3f9b0f3..fc6d4fa 100644
95591 --- a/net/can/gw.c
95592 +++ b/net/can/gw.c
95593 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
95594 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
95595
95596 static HLIST_HEAD(cgw_list);
95597 -static struct notifier_block notifier;
95598
95599 static struct kmem_cache *cgw_cache __read_mostly;
95600
95601 @@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
95602 return err;
95603 }
95604
95605 +static struct notifier_block notifier = {
95606 + .notifier_call = cgw_notifier
95607 +};
95608 +
95609 static __init int cgw_module_init(void)
95610 {
95611 /* sanitize given module parameter */
95612 @@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
95613 return -ENOMEM;
95614
95615 /* set notifier */
95616 - notifier.notifier_call = cgw_notifier;
95617 register_netdevice_notifier(&notifier);
95618
95619 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
95620 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
95621 index 4a5df7b..9ad1f1d 100644
95622 --- a/net/ceph/messenger.c
95623 +++ b/net/ceph/messenger.c
95624 @@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
95625 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
95626
95627 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
95628 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
95629 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
95630
95631 static struct page *zero_page; /* used in certain error cases */
95632
95633 @@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
95634 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
95635 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
95636
95637 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95638 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95639 s = addr_str[i];
95640
95641 switch (ss->ss_family) {
95642 diff --git a/net/compat.c b/net/compat.c
95643 index f50161f..94fa415 100644
95644 --- a/net/compat.c
95645 +++ b/net/compat.c
95646 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
95647 return -EFAULT;
95648 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
95649 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
95650 - kmsg->msg_name = compat_ptr(tmp1);
95651 - kmsg->msg_iov = compat_ptr(tmp2);
95652 - kmsg->msg_control = compat_ptr(tmp3);
95653 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
95654 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
95655 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
95656 return 0;
95657 }
95658
95659 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95660
95661 if (kern_msg->msg_namelen) {
95662 if (mode == VERIFY_READ) {
95663 - int err = move_addr_to_kernel(kern_msg->msg_name,
95664 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
95665 kern_msg->msg_namelen,
95666 kern_address);
95667 if (err < 0)
95668 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95669 kern_msg->msg_name = NULL;
95670
95671 tot_len = iov_from_user_compat_to_kern(kern_iov,
95672 - (struct compat_iovec __user *)kern_msg->msg_iov,
95673 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
95674 kern_msg->msg_iovlen);
95675 if (tot_len >= 0)
95676 kern_msg->msg_iov = kern_iov;
95677 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95678
95679 #define CMSG_COMPAT_FIRSTHDR(msg) \
95680 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
95681 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
95682 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
95683 (struct compat_cmsghdr __user *)NULL)
95684
95685 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
95686 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
95687 (ucmlen) <= (unsigned long) \
95688 ((mhdr)->msg_controllen - \
95689 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
95690 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
95691
95692 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
95693 struct compat_cmsghdr __user *cmsg, int cmsg_len)
95694 {
95695 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
95696 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
95697 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
95698 msg->msg_controllen)
95699 return NULL;
95700 return (struct compat_cmsghdr __user *)ptr;
95701 @@ -222,7 +222,7 @@ Efault:
95702
95703 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
95704 {
95705 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95706 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95707 struct compat_cmsghdr cmhdr;
95708 struct compat_timeval ctv;
95709 struct compat_timespec cts[3];
95710 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
95711
95712 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
95713 {
95714 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95715 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95716 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
95717 int fdnum = scm->fp->count;
95718 struct file **fp = scm->fp->fp;
95719 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
95720 return -EFAULT;
95721 old_fs = get_fs();
95722 set_fs(KERNEL_DS);
95723 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
95724 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
95725 set_fs(old_fs);
95726
95727 return err;
95728 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
95729 len = sizeof(ktime);
95730 old_fs = get_fs();
95731 set_fs(KERNEL_DS);
95732 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
95733 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
95734 set_fs(old_fs);
95735
95736 if (!err) {
95737 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95738 case MCAST_JOIN_GROUP:
95739 case MCAST_LEAVE_GROUP:
95740 {
95741 - struct compat_group_req __user *gr32 = (void *)optval;
95742 + struct compat_group_req __user *gr32 = (void __user *)optval;
95743 struct group_req __user *kgr =
95744 compat_alloc_user_space(sizeof(struct group_req));
95745 u32 interface;
95746 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95747 case MCAST_BLOCK_SOURCE:
95748 case MCAST_UNBLOCK_SOURCE:
95749 {
95750 - struct compat_group_source_req __user *gsr32 = (void *)optval;
95751 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
95752 struct group_source_req __user *kgsr = compat_alloc_user_space(
95753 sizeof(struct group_source_req));
95754 u32 interface;
95755 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95756 }
95757 case MCAST_MSFILTER:
95758 {
95759 - struct compat_group_filter __user *gf32 = (void *)optval;
95760 + struct compat_group_filter __user *gf32 = (void __user *)optval;
95761 struct group_filter __user *kgf;
95762 u32 interface, fmode, numsrc;
95763
95764 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
95765 char __user *optval, int __user *optlen,
95766 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
95767 {
95768 - struct compat_group_filter __user *gf32 = (void *)optval;
95769 + struct compat_group_filter __user *gf32 = (void __user *)optval;
95770 struct group_filter __user *kgf;
95771 int __user *koptlen;
95772 u32 interface, fmode, numsrc;
95773 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
95774
95775 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
95776 return -EINVAL;
95777 - if (copy_from_user(a, args, nas[call]))
95778 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
95779 return -EFAULT;
95780 a0 = a[0];
95781 a1 = a[1];
95782 diff --git a/net/core/datagram.c b/net/core/datagram.c
95783 index a16ed7b..eb44d17 100644
95784 --- a/net/core/datagram.c
95785 +++ b/net/core/datagram.c
95786 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
95787 }
95788
95789 kfree_skb(skb);
95790 - atomic_inc(&sk->sk_drops);
95791 + atomic_inc_unchecked(&sk->sk_drops);
95792 sk_mem_reclaim_partial(sk);
95793
95794 return err;
95795 diff --git a/net/core/dev.c b/net/core/dev.c
95796 index 0ce469e..dfb53d2 100644
95797 --- a/net/core/dev.c
95798 +++ b/net/core/dev.c
95799 @@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
95800 {
95801 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
95802 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
95803 - atomic_long_inc(&dev->rx_dropped);
95804 + atomic_long_inc_unchecked(&dev->rx_dropped);
95805 kfree_skb(skb);
95806 return NET_RX_DROP;
95807 }
95808 }
95809
95810 if (unlikely(!is_skb_forwardable(dev, skb))) {
95811 - atomic_long_inc(&dev->rx_dropped);
95812 + atomic_long_inc_unchecked(&dev->rx_dropped);
95813 kfree_skb(skb);
95814 return NET_RX_DROP;
95815 }
95816 @@ -2434,7 +2434,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
95817
95818 struct dev_gso_cb {
95819 void (*destructor)(struct sk_buff *skb);
95820 -};
95821 +} __no_const;
95822
95823 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
95824
95825 @@ -3222,7 +3222,7 @@ enqueue:
95826
95827 local_irq_restore(flags);
95828
95829 - atomic_long_inc(&skb->dev->rx_dropped);
95830 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95831 kfree_skb(skb);
95832 return NET_RX_DROP;
95833 }
95834 @@ -3294,7 +3294,7 @@ int netif_rx_ni(struct sk_buff *skb)
95835 }
95836 EXPORT_SYMBOL(netif_rx_ni);
95837
95838 -static void net_tx_action(struct softirq_action *h)
95839 +static __latent_entropy void net_tx_action(void)
95840 {
95841 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95842
95843 @@ -3628,7 +3628,7 @@ ncls:
95844 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
95845 } else {
95846 drop:
95847 - atomic_long_inc(&skb->dev->rx_dropped);
95848 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95849 kfree_skb(skb);
95850 /* Jamal, now you will not able to escape explaining
95851 * me how you were going to use this. :-)
95852 @@ -4288,7 +4288,7 @@ void netif_napi_del(struct napi_struct *napi)
95853 }
95854 EXPORT_SYMBOL(netif_napi_del);
95855
95856 -static void net_rx_action(struct softirq_action *h)
95857 +static __latent_entropy void net_rx_action(void)
95858 {
95859 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95860 unsigned long time_limit = jiffies + 2;
95861 @@ -6177,7 +6177,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
95862 } else {
95863 netdev_stats_to_stats64(storage, &dev->stats);
95864 }
95865 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
95866 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
95867 return storage;
95868 }
95869 EXPORT_SYMBOL(dev_get_stats);
95870 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
95871 index 5b7d0e1..cb960fc 100644
95872 --- a/net/core/dev_ioctl.c
95873 +++ b/net/core/dev_ioctl.c
95874 @@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
95875 if (no_module && capable(CAP_NET_ADMIN))
95876 no_module = request_module("netdev-%s", name);
95877 if (no_module && capable(CAP_SYS_MODULE)) {
95878 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
95879 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
95880 +#else
95881 if (!request_module("%s", name))
95882 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
95883 name);
95884 +#endif
95885 }
95886 }
95887 EXPORT_SYMBOL(dev_load);
95888 diff --git a/net/core/filter.c b/net/core/filter.c
95889 index ad30d62..c2757df 100644
95890 --- a/net/core/filter.c
95891 +++ b/net/core/filter.c
95892 @@ -679,7 +679,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
95893 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
95894 if (!fp)
95895 return -ENOMEM;
95896 - memcpy(fp->insns, fprog->filter, fsize);
95897 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
95898
95899 atomic_set(&fp->refcnt, 1);
95900 fp->len = fprog->len;
95901 diff --git a/net/core/flow.c b/net/core/flow.c
95902 index dfa602c..3103d88 100644
95903 --- a/net/core/flow.c
95904 +++ b/net/core/flow.c
95905 @@ -61,7 +61,7 @@ struct flow_cache {
95906 struct timer_list rnd_timer;
95907 };
95908
95909 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
95910 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
95911 EXPORT_SYMBOL(flow_cache_genid);
95912 static struct flow_cache flow_cache_global;
95913 static struct kmem_cache *flow_cachep __read_mostly;
95914 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
95915
95916 static int flow_entry_valid(struct flow_cache_entry *fle)
95917 {
95918 - if (atomic_read(&flow_cache_genid) != fle->genid)
95919 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
95920 return 0;
95921 if (fle->object && !fle->object->ops->check(fle->object))
95922 return 0;
95923 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
95924 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
95925 fcp->hash_count++;
95926 }
95927 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
95928 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
95929 flo = fle->object;
95930 if (!flo)
95931 goto ret_object;
95932 @@ -279,7 +279,7 @@ nocache:
95933 }
95934 flo = resolver(net, key, family, dir, flo, ctx);
95935 if (fle) {
95936 - fle->genid = atomic_read(&flow_cache_genid);
95937 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
95938 if (!IS_ERR(flo))
95939 fle->object = flo;
95940 else
95941 diff --git a/net/core/iovec.c b/net/core/iovec.c
95942 index b618694..192bbba 100644
95943 --- a/net/core/iovec.c
95944 +++ b/net/core/iovec.c
95945 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95946 if (m->msg_namelen) {
95947 if (mode == VERIFY_READ) {
95948 void __user *namep;
95949 - namep = (void __user __force *) m->msg_name;
95950 + namep = (void __force_user *) m->msg_name;
95951 err = move_addr_to_kernel(namep, m->msg_namelen,
95952 address);
95953 if (err < 0)
95954 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95955 }
95956
95957 size = m->msg_iovlen * sizeof(struct iovec);
95958 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
95959 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
95960 return -EFAULT;
95961
95962 m->msg_iov = iov;
95963 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
95964 index 932c6d7..7c7aa10 100644
95965 --- a/net/core/neighbour.c
95966 +++ b/net/core/neighbour.c
95967 @@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
95968 void __user *buffer, size_t *lenp, loff_t *ppos)
95969 {
95970 int size, ret;
95971 - struct ctl_table tmp = *ctl;
95972 + ctl_table_no_const tmp = *ctl;
95973
95974 tmp.extra1 = &zero;
95975 tmp.extra2 = &unres_qlen_max;
95976 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
95977 index 2bf8329..7960607 100644
95978 --- a/net/core/net-procfs.c
95979 +++ b/net/core/net-procfs.c
95980 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
95981 else
95982 seq_printf(seq, "%04x", ntohs(pt->type));
95983
95984 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95985 + seq_printf(seq, " %-8s %pf\n",
95986 + pt->dev ? pt->dev->name : "", NULL);
95987 +#else
95988 seq_printf(seq, " %-8s %pf\n",
95989 pt->dev ? pt->dev->name : "", pt->func);
95990 +#endif
95991 }
95992
95993 return 0;
95994 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
95995 index f3edf96..3cd8b40 100644
95996 --- a/net/core/net-sysfs.c
95997 +++ b/net/core/net-sysfs.c
95998 @@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
95999 }
96000 EXPORT_SYMBOL(netdev_class_remove_file_ns);
96001
96002 -int netdev_kobject_init(void)
96003 +int __init netdev_kobject_init(void)
96004 {
96005 kobj_ns_type_register(&net_ns_type_operations);
96006 return class_register(&net_class);
96007 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
96008 index 81d3a9a..a0bd7a8 100644
96009 --- a/net/core/net_namespace.c
96010 +++ b/net/core/net_namespace.c
96011 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
96012 int error;
96013 LIST_HEAD(net_exit_list);
96014
96015 - list_add_tail(&ops->list, list);
96016 + pax_list_add_tail((struct list_head *)&ops->list, list);
96017 if (ops->init || (ops->id && ops->size)) {
96018 for_each_net(net) {
96019 error = ops_init(ops, net);
96020 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
96021
96022 out_undo:
96023 /* If I have an error cleanup all namespaces I initialized */
96024 - list_del(&ops->list);
96025 + pax_list_del((struct list_head *)&ops->list);
96026 ops_exit_list(ops, &net_exit_list);
96027 ops_free_list(ops, &net_exit_list);
96028 return error;
96029 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
96030 struct net *net;
96031 LIST_HEAD(net_exit_list);
96032
96033 - list_del(&ops->list);
96034 + pax_list_del((struct list_head *)&ops->list);
96035 for_each_net(net)
96036 list_add_tail(&net->exit_list, &net_exit_list);
96037 ops_exit_list(ops, &net_exit_list);
96038 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
96039 mutex_lock(&net_mutex);
96040 error = register_pernet_operations(&pernet_list, ops);
96041 if (!error && (first_device == &pernet_list))
96042 - first_device = &ops->list;
96043 + first_device = (struct list_head *)&ops->list;
96044 mutex_unlock(&net_mutex);
96045 return error;
96046 }
96047 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
96048 index 19fe9c7..b6bb620 100644
96049 --- a/net/core/netpoll.c
96050 +++ b/net/core/netpoll.c
96051 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96052 struct udphdr *udph;
96053 struct iphdr *iph;
96054 struct ethhdr *eth;
96055 - static atomic_t ip_ident;
96056 + static atomic_unchecked_t ip_ident;
96057 struct ipv6hdr *ip6h;
96058
96059 udp_len = len + sizeof(*udph);
96060 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96061 put_unaligned(0x45, (unsigned char *)iph);
96062 iph->tos = 0;
96063 put_unaligned(htons(ip_len), &(iph->tot_len));
96064 - iph->id = htons(atomic_inc_return(&ip_ident));
96065 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
96066 iph->frag_off = 0;
96067 iph->ttl = 64;
96068 iph->protocol = IPPROTO_UDP;
96069 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
96070 index cf67144..12bf94c 100644
96071 --- a/net/core/rtnetlink.c
96072 +++ b/net/core/rtnetlink.c
96073 @@ -58,7 +58,7 @@ struct rtnl_link {
96074 rtnl_doit_func doit;
96075 rtnl_dumpit_func dumpit;
96076 rtnl_calcit_func calcit;
96077 -};
96078 +} __no_const;
96079
96080 static DEFINE_MUTEX(rtnl_mutex);
96081
96082 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
96083 if (rtnl_link_ops_get(ops->kind))
96084 return -EEXIST;
96085
96086 - if (!ops->dellink)
96087 - ops->dellink = unregister_netdevice_queue;
96088 + if (!ops->dellink) {
96089 + pax_open_kernel();
96090 + *(void **)&ops->dellink = unregister_netdevice_queue;
96091 + pax_close_kernel();
96092 + }
96093
96094 - list_add_tail(&ops->list, &link_ops);
96095 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
96096 return 0;
96097 }
96098 EXPORT_SYMBOL_GPL(__rtnl_link_register);
96099 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
96100 for_each_net(net) {
96101 __rtnl_kill_links(net, ops);
96102 }
96103 - list_del(&ops->list);
96104 + pax_list_del((struct list_head *)&ops->list);
96105 }
96106 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
96107
96108 diff --git a/net/core/scm.c b/net/core/scm.c
96109 index b442e7e..6f5b5a2 100644
96110 --- a/net/core/scm.c
96111 +++ b/net/core/scm.c
96112 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
96113 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
96114 {
96115 struct cmsghdr __user *cm
96116 - = (__force struct cmsghdr __user *)msg->msg_control;
96117 + = (struct cmsghdr __force_user *)msg->msg_control;
96118 struct cmsghdr cmhdr;
96119 int cmlen = CMSG_LEN(len);
96120 int err;
96121 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
96122 err = -EFAULT;
96123 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
96124 goto out;
96125 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
96126 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
96127 goto out;
96128 cmlen = CMSG_SPACE(len);
96129 if (msg->msg_controllen < cmlen)
96130 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
96131 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
96132 {
96133 struct cmsghdr __user *cm
96134 - = (__force struct cmsghdr __user*)msg->msg_control;
96135 + = (struct cmsghdr __force_user *)msg->msg_control;
96136
96137 int fdmax = 0;
96138 int fdnum = scm->fp->count;
96139 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
96140 if (fdnum < fdmax)
96141 fdmax = fdnum;
96142
96143 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
96144 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
96145 i++, cmfptr++)
96146 {
96147 struct socket *sock;
96148 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
96149 index 06e72d3..19dfa7b 100644
96150 --- a/net/core/skbuff.c
96151 +++ b/net/core/skbuff.c
96152 @@ -2034,7 +2034,7 @@ EXPORT_SYMBOL(__skb_checksum);
96153 __wsum skb_checksum(const struct sk_buff *skb, int offset,
96154 int len, __wsum csum)
96155 {
96156 - const struct skb_checksum_ops ops = {
96157 + static const struct skb_checksum_ops ops = {
96158 .update = csum_partial_ext,
96159 .combine = csum_block_add_ext,
96160 };
96161 @@ -3147,13 +3147,15 @@ void __init skb_init(void)
96162 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
96163 sizeof(struct sk_buff),
96164 0,
96165 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96166 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96167 + SLAB_NO_SANITIZE,
96168 NULL);
96169 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
96170 (2*sizeof(struct sk_buff)) +
96171 sizeof(atomic_t),
96172 0,
96173 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96174 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96175 + SLAB_NO_SANITIZE,
96176 NULL);
96177 }
96178
96179 diff --git a/net/core/sock.c b/net/core/sock.c
96180 index 5393b4b..997c88b 100644
96181 --- a/net/core/sock.c
96182 +++ b/net/core/sock.c
96183 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96184 struct sk_buff_head *list = &sk->sk_receive_queue;
96185
96186 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
96187 - atomic_inc(&sk->sk_drops);
96188 + atomic_inc_unchecked(&sk->sk_drops);
96189 trace_sock_rcvqueue_full(sk, skb);
96190 return -ENOMEM;
96191 }
96192 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96193 return err;
96194
96195 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
96196 - atomic_inc(&sk->sk_drops);
96197 + atomic_inc_unchecked(&sk->sk_drops);
96198 return -ENOBUFS;
96199 }
96200
96201 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96202 skb_dst_force(skb);
96203
96204 spin_lock_irqsave(&list->lock, flags);
96205 - skb->dropcount = atomic_read(&sk->sk_drops);
96206 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
96207 __skb_queue_tail(list, skb);
96208 spin_unlock_irqrestore(&list->lock, flags);
96209
96210 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96211 skb->dev = NULL;
96212
96213 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
96214 - atomic_inc(&sk->sk_drops);
96215 + atomic_inc_unchecked(&sk->sk_drops);
96216 goto discard_and_relse;
96217 }
96218 if (nested)
96219 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96220 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
96221 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
96222 bh_unlock_sock(sk);
96223 - atomic_inc(&sk->sk_drops);
96224 + atomic_inc_unchecked(&sk->sk_drops);
96225 goto discard_and_relse;
96226 }
96227
96228 @@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96229 struct timeval tm;
96230 } v;
96231
96232 - int lv = sizeof(int);
96233 - int len;
96234 + unsigned int lv = sizeof(int);
96235 + unsigned int len;
96236
96237 if (get_user(len, optlen))
96238 return -EFAULT;
96239 - if (len < 0)
96240 + if (len > INT_MAX)
96241 return -EINVAL;
96242
96243 memset(&v, 0, sizeof(v));
96244 @@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96245
96246 case SO_PEERNAME:
96247 {
96248 - char address[128];
96249 + char address[_K_SS_MAXSIZE];
96250
96251 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
96252 return -ENOTCONN;
96253 - if (lv < len)
96254 + if (lv < len || sizeof address < len)
96255 return -EINVAL;
96256 if (copy_to_user(optval, address, len))
96257 return -EFAULT;
96258 @@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96259
96260 if (len > lv)
96261 len = lv;
96262 - if (copy_to_user(optval, &v, len))
96263 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
96264 return -EFAULT;
96265 lenout:
96266 if (put_user(len, optlen))
96267 @@ -2351,7 +2351,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
96268 */
96269 smp_wmb();
96270 atomic_set(&sk->sk_refcnt, 1);
96271 - atomic_set(&sk->sk_drops, 0);
96272 + atomic_set_unchecked(&sk->sk_drops, 0);
96273 }
96274 EXPORT_SYMBOL(sock_init_data);
96275
96276 @@ -2476,6 +2476,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
96277 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96278 int level, int type)
96279 {
96280 + struct sock_extended_err ee;
96281 struct sock_exterr_skb *serr;
96282 struct sk_buff *skb, *skb2;
96283 int copied, err;
96284 @@ -2497,7 +2498,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96285 sock_recv_timestamp(msg, sk, skb);
96286
96287 serr = SKB_EXT_ERR(skb);
96288 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
96289 + ee = serr->ee;
96290 + put_cmsg(msg, level, type, sizeof ee, &ee);
96291
96292 msg->msg_flags |= MSG_ERRQUEUE;
96293 err = copied;
96294 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
96295 index a0e9cf6..ef7f9ed 100644
96296 --- a/net/core/sock_diag.c
96297 +++ b/net/core/sock_diag.c
96298 @@ -9,26 +9,33 @@
96299 #include <linux/inet_diag.h>
96300 #include <linux/sock_diag.h>
96301
96302 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
96303 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
96304 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
96305 static DEFINE_MUTEX(sock_diag_table_mutex);
96306
96307 int sock_diag_check_cookie(void *sk, __u32 *cookie)
96308 {
96309 +#ifndef CONFIG_GRKERNSEC_HIDESYM
96310 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
96311 cookie[1] != INET_DIAG_NOCOOKIE) &&
96312 ((u32)(unsigned long)sk != cookie[0] ||
96313 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
96314 return -ESTALE;
96315 else
96316 +#endif
96317 return 0;
96318 }
96319 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
96320
96321 void sock_diag_save_cookie(void *sk, __u32 *cookie)
96322 {
96323 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96324 + cookie[0] = 0;
96325 + cookie[1] = 0;
96326 +#else
96327 cookie[0] = (u32)(unsigned long)sk;
96328 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
96329 +#endif
96330 }
96331 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
96332
96333 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
96334 mutex_lock(&sock_diag_table_mutex);
96335 if (sock_diag_handlers[hndl->family])
96336 err = -EBUSY;
96337 - else
96338 + else {
96339 + pax_open_kernel();
96340 sock_diag_handlers[hndl->family] = hndl;
96341 + pax_close_kernel();
96342 + }
96343 mutex_unlock(&sock_diag_table_mutex);
96344
96345 return err;
96346 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
96347
96348 mutex_lock(&sock_diag_table_mutex);
96349 BUG_ON(sock_diag_handlers[family] != hnld);
96350 + pax_open_kernel();
96351 sock_diag_handlers[family] = NULL;
96352 + pax_close_kernel();
96353 mutex_unlock(&sock_diag_table_mutex);
96354 }
96355 EXPORT_SYMBOL_GPL(sock_diag_unregister);
96356 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
96357 index cca4441..5e616de 100644
96358 --- a/net/core/sysctl_net_core.c
96359 +++ b/net/core/sysctl_net_core.c
96360 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
96361 {
96362 unsigned int orig_size, size;
96363 int ret, i;
96364 - struct ctl_table tmp = {
96365 + ctl_table_no_const tmp = {
96366 .data = &size,
96367 .maxlen = sizeof(size),
96368 .mode = table->mode
96369 @@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
96370 void __user *buffer, size_t *lenp, loff_t *ppos)
96371 {
96372 char id[IFNAMSIZ];
96373 - struct ctl_table tbl = {
96374 + ctl_table_no_const tbl = {
96375 .data = id,
96376 .maxlen = IFNAMSIZ,
96377 };
96378 @@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
96379
96380 static __net_init int sysctl_core_net_init(struct net *net)
96381 {
96382 - struct ctl_table *tbl;
96383 + ctl_table_no_const *tbl = NULL;
96384
96385 net->core.sysctl_somaxconn = SOMAXCONN;
96386
96387 - tbl = netns_core_table;
96388 if (!net_eq(net, &init_net)) {
96389 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
96390 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
96391 if (tbl == NULL)
96392 goto err_dup;
96393
96394 @@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
96395 if (net->user_ns != &init_user_ns) {
96396 tbl[0].procname = NULL;
96397 }
96398 - }
96399 -
96400 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96401 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96402 + } else
96403 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
96404 if (net->core.sysctl_hdr == NULL)
96405 goto err_reg;
96406
96407 return 0;
96408
96409 err_reg:
96410 - if (tbl != netns_core_table)
96411 - kfree(tbl);
96412 + kfree(tbl);
96413 err_dup:
96414 return -ENOMEM;
96415 }
96416 @@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
96417 kfree(tbl);
96418 }
96419
96420 -static __net_initdata struct pernet_operations sysctl_core_ops = {
96421 +static __net_initconst struct pernet_operations sysctl_core_ops = {
96422 .init = sysctl_core_net_init,
96423 .exit = sysctl_core_net_exit,
96424 };
96425 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
96426 index dd4d506..fb2fb87 100644
96427 --- a/net/decnet/af_decnet.c
96428 +++ b/net/decnet/af_decnet.c
96429 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
96430 .sysctl_rmem = sysctl_decnet_rmem,
96431 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
96432 .obj_size = sizeof(struct dn_sock),
96433 + .slab_flags = SLAB_USERCOPY,
96434 };
96435
96436 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
96437 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
96438 index dd0dfb2..fdbc764 100644
96439 --- a/net/decnet/dn_dev.c
96440 +++ b/net/decnet/dn_dev.c
96441 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
96442 .extra1 = &min_t3,
96443 .extra2 = &max_t3
96444 },
96445 - {0}
96446 + { }
96447 },
96448 };
96449
96450 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
96451 index 5325b54..a0d4d69 100644
96452 --- a/net/decnet/sysctl_net_decnet.c
96453 +++ b/net/decnet/sysctl_net_decnet.c
96454 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
96455
96456 if (len > *lenp) len = *lenp;
96457
96458 - if (copy_to_user(buffer, addr, len))
96459 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
96460 return -EFAULT;
96461
96462 *lenp = len;
96463 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
96464
96465 if (len > *lenp) len = *lenp;
96466
96467 - if (copy_to_user(buffer, devname, len))
96468 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
96469 return -EFAULT;
96470
96471 *lenp = len;
96472 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
96473 index 1865fdf..581a595 100644
96474 --- a/net/ieee802154/dgram.c
96475 +++ b/net/ieee802154/dgram.c
96476 @@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
96477 if (saddr) {
96478 saddr->family = AF_IEEE802154;
96479 saddr->addr = mac_cb(skb)->sa;
96480 + }
96481 + if (addr_len)
96482 *addr_len = sizeof(*saddr);
96483 - }
96484
96485 if (flags & MSG_TRUNC)
96486 copied = skb->len;
96487 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
96488 index 70011e0..454ca6a 100644
96489 --- a/net/ipv4/af_inet.c
96490 +++ b/net/ipv4/af_inet.c
96491 @@ -1683,13 +1683,9 @@ static int __init inet_init(void)
96492
96493 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
96494
96495 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
96496 - if (!sysctl_local_reserved_ports)
96497 - goto out;
96498 -
96499 rc = proto_register(&tcp_prot, 1);
96500 if (rc)
96501 - goto out_free_reserved_ports;
96502 + goto out;
96503
96504 rc = proto_register(&udp_prot, 1);
96505 if (rc)
96506 @@ -1796,8 +1792,6 @@ out_unregister_udp_proto:
96507 proto_unregister(&udp_prot);
96508 out_unregister_tcp_proto:
96509 proto_unregister(&tcp_prot);
96510 -out_free_reserved_ports:
96511 - kfree(sysctl_local_reserved_ports);
96512 goto out;
96513 }
96514
96515 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
96516 index a1b5bcb..62ec5c6 100644
96517 --- a/net/ipv4/devinet.c
96518 +++ b/net/ipv4/devinet.c
96519 @@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
96520 idx = 0;
96521 head = &net->dev_index_head[h];
96522 rcu_read_lock();
96523 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96524 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96525 net->dev_base_seq;
96526 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96527 if (idx < s_idx)
96528 @@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
96529 idx = 0;
96530 head = &net->dev_index_head[h];
96531 rcu_read_lock();
96532 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96533 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96534 net->dev_base_seq;
96535 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96536 if (idx < s_idx)
96537 @@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
96538 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
96539 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
96540
96541 -static struct devinet_sysctl_table {
96542 +static const struct devinet_sysctl_table {
96543 struct ctl_table_header *sysctl_header;
96544 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
96545 } devinet_sysctl = {
96546 @@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
96547 int err;
96548 struct ipv4_devconf *all, *dflt;
96549 #ifdef CONFIG_SYSCTL
96550 - struct ctl_table *tbl = ctl_forward_entry;
96551 + ctl_table_no_const *tbl = NULL;
96552 struct ctl_table_header *forw_hdr;
96553 #endif
96554
96555 @@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
96556 goto err_alloc_dflt;
96557
96558 #ifdef CONFIG_SYSCTL
96559 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
96560 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
96561 if (tbl == NULL)
96562 goto err_alloc_ctl;
96563
96564 @@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
96565 goto err_reg_dflt;
96566
96567 err = -ENOMEM;
96568 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96569 + if (!net_eq(net, &init_net))
96570 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96571 + else
96572 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
96573 if (forw_hdr == NULL)
96574 goto err_reg_ctl;
96575 net->ipv4.forw_hdr = forw_hdr;
96576 @@ -2245,8 +2248,7 @@ err_reg_ctl:
96577 err_reg_dflt:
96578 __devinet_sysctl_unregister(all);
96579 err_reg_all:
96580 - if (tbl != ctl_forward_entry)
96581 - kfree(tbl);
96582 + kfree(tbl);
96583 err_alloc_ctl:
96584 #endif
96585 if (dflt != &ipv4_devconf_dflt)
96586 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
96587 index c7539e2..b455e51 100644
96588 --- a/net/ipv4/fib_frontend.c
96589 +++ b/net/ipv4/fib_frontend.c
96590 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
96591 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96592 fib_sync_up(dev);
96593 #endif
96594 - atomic_inc(&net->ipv4.dev_addr_genid);
96595 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96596 rt_cache_flush(dev_net(dev));
96597 break;
96598 case NETDEV_DOWN:
96599 fib_del_ifaddr(ifa, NULL);
96600 - atomic_inc(&net->ipv4.dev_addr_genid);
96601 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96602 if (ifa->ifa_dev->ifa_list == NULL) {
96603 /* Last address was deleted from this interface.
96604 * Disable IP.
96605 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
96606 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96607 fib_sync_up(dev);
96608 #endif
96609 - atomic_inc(&net->ipv4.dev_addr_genid);
96610 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96611 rt_cache_flush(net);
96612 break;
96613 case NETDEV_DOWN:
96614 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
96615 index e63f47a..e5c531d 100644
96616 --- a/net/ipv4/fib_semantics.c
96617 +++ b/net/ipv4/fib_semantics.c
96618 @@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
96619 nh->nh_saddr = inet_select_addr(nh->nh_dev,
96620 nh->nh_gw,
96621 nh->nh_parent->fib_scope);
96622 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
96623 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
96624
96625 return nh->nh_saddr;
96626 }
96627 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
96628 index fc0e649..febfa65 100644
96629 --- a/net/ipv4/inet_connection_sock.c
96630 +++ b/net/ipv4/inet_connection_sock.c
96631 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
96632 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
96633 #endif
96634
96635 -unsigned long *sysctl_local_reserved_ports;
96636 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
96637 EXPORT_SYMBOL(sysctl_local_reserved_ports);
96638
96639 void inet_get_local_port_range(struct net *net, int *low, int *high)
96640 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
96641 index 8b9cf27..0d8d592 100644
96642 --- a/net/ipv4/inet_hashtables.c
96643 +++ b/net/ipv4/inet_hashtables.c
96644 @@ -18,6 +18,7 @@
96645 #include <linux/sched.h>
96646 #include <linux/slab.h>
96647 #include <linux/wait.h>
96648 +#include <linux/security.h>
96649
96650 #include <net/inet_connection_sock.h>
96651 #include <net/inet_hashtables.h>
96652 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
96653 return inet_ehashfn(net, laddr, lport, faddr, fport);
96654 }
96655
96656 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
96657 +
96658 /*
96659 * Allocate and initialize a new local port bind bucket.
96660 * The bindhash mutex for snum's hash chain must be held here.
96661 @@ -554,6 +557,8 @@ ok:
96662 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
96663 spin_unlock(&head->lock);
96664
96665 + gr_update_task_in_ip_table(current, inet_sk(sk));
96666 +
96667 if (tw) {
96668 inet_twsk_deschedule(tw, death_row);
96669 while (twrefcnt) {
96670 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
96671 index 33d5537..da337a4 100644
96672 --- a/net/ipv4/inetpeer.c
96673 +++ b/net/ipv4/inetpeer.c
96674 @@ -503,8 +503,8 @@ relookup:
96675 if (p) {
96676 p->daddr = *daddr;
96677 atomic_set(&p->refcnt, 1);
96678 - atomic_set(&p->rid, 0);
96679 - atomic_set(&p->ip_id_count,
96680 + atomic_set_unchecked(&p->rid, 0);
96681 + atomic_set_unchecked(&p->ip_id_count,
96682 (daddr->family == AF_INET) ?
96683 secure_ip_id(daddr->addr.a4) :
96684 secure_ipv6_id(daddr->addr.a6));
96685 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
96686 index 2481993..2d9a7a7 100644
96687 --- a/net/ipv4/ip_fragment.c
96688 +++ b/net/ipv4/ip_fragment.c
96689 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
96690 return 0;
96691
96692 start = qp->rid;
96693 - end = atomic_inc_return(&peer->rid);
96694 + end = atomic_inc_return_unchecked(&peer->rid);
96695 qp->rid = end;
96696
96697 rc = qp->q.fragments && (end - start) > max;
96698 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
96699
96700 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96701 {
96702 - struct ctl_table *table;
96703 + ctl_table_no_const *table = NULL;
96704 struct ctl_table_header *hdr;
96705
96706 - table = ip4_frags_ns_ctl_table;
96707 if (!net_eq(net, &init_net)) {
96708 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96709 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96710 if (table == NULL)
96711 goto err_alloc;
96712
96713 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96714 /* Don't export sysctls to unprivileged users */
96715 if (net->user_ns != &init_user_ns)
96716 table[0].procname = NULL;
96717 - }
96718 + hdr = register_net_sysctl(net, "net/ipv4", table);
96719 + } else
96720 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
96721
96722 - hdr = register_net_sysctl(net, "net/ipv4", table);
96723 if (hdr == NULL)
96724 goto err_reg;
96725
96726 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96727 return 0;
96728
96729 err_reg:
96730 - if (!net_eq(net, &init_net))
96731 - kfree(table);
96732 + kfree(table);
96733 err_alloc:
96734 return -ENOMEM;
96735 }
96736 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
96737 index d306360..1c1a1f1 100644
96738 --- a/net/ipv4/ip_gre.c
96739 +++ b/net/ipv4/ip_gre.c
96740 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
96741 module_param(log_ecn_error, bool, 0644);
96742 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96743
96744 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
96745 +static struct rtnl_link_ops ipgre_link_ops;
96746 static int ipgre_tunnel_init(struct net_device *dev);
96747
96748 static int ipgre_net_id __read_mostly;
96749 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
96750 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
96751 };
96752
96753 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96754 +static struct rtnl_link_ops ipgre_link_ops = {
96755 .kind = "gre",
96756 .maxtype = IFLA_GRE_MAX,
96757 .policy = ipgre_policy,
96758 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96759 .fill_info = ipgre_fill_info,
96760 };
96761
96762 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
96763 +static struct rtnl_link_ops ipgre_tap_ops = {
96764 .kind = "gretap",
96765 .maxtype = IFLA_GRE_MAX,
96766 .policy = ipgre_policy,
96767 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
96768 index ddf32a6..3fdeea9 100644
96769 --- a/net/ipv4/ip_sockglue.c
96770 +++ b/net/ipv4/ip_sockglue.c
96771 @@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96772 len = min_t(unsigned int, len, opt->optlen);
96773 if (put_user(len, optlen))
96774 return -EFAULT;
96775 - if (copy_to_user(optval, opt->__data, len))
96776 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
96777 + copy_to_user(optval, opt->__data, len))
96778 return -EFAULT;
96779 return 0;
96780 }
96781 @@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96782 if (sk->sk_type != SOCK_STREAM)
96783 return -ENOPROTOOPT;
96784
96785 - msg.msg_control = optval;
96786 + msg.msg_control = (void __force_kernel *)optval;
96787 msg.msg_controllen = len;
96788 msg.msg_flags = flags;
96789
96790 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
96791 index 52b802a..b725179 100644
96792 --- a/net/ipv4/ip_vti.c
96793 +++ b/net/ipv4/ip_vti.c
96794 @@ -44,7 +44,7 @@
96795 #include <net/net_namespace.h>
96796 #include <net/netns/generic.h>
96797
96798 -static struct rtnl_link_ops vti_link_ops __read_mostly;
96799 +static struct rtnl_link_ops vti_link_ops;
96800
96801 static int vti_net_id __read_mostly;
96802 static int vti_tunnel_init(struct net_device *dev);
96803 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
96804 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
96805 };
96806
96807 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
96808 +static struct rtnl_link_ops vti_link_ops = {
96809 .kind = "vti",
96810 .maxtype = IFLA_VTI_MAX,
96811 .policy = vti_policy,
96812 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
96813 index efa1138..20dbba0 100644
96814 --- a/net/ipv4/ipconfig.c
96815 +++ b/net/ipv4/ipconfig.c
96816 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
96817
96818 mm_segment_t oldfs = get_fs();
96819 set_fs(get_ds());
96820 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96821 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96822 set_fs(oldfs);
96823 return res;
96824 }
96825 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
96826
96827 mm_segment_t oldfs = get_fs();
96828 set_fs(get_ds());
96829 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96830 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96831 set_fs(oldfs);
96832 return res;
96833 }
96834 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
96835
96836 mm_segment_t oldfs = get_fs();
96837 set_fs(get_ds());
96838 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
96839 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
96840 set_fs(oldfs);
96841 return res;
96842 }
96843 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
96844 index fe3e9f7..4956990 100644
96845 --- a/net/ipv4/ipip.c
96846 +++ b/net/ipv4/ipip.c
96847 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96848 static int ipip_net_id __read_mostly;
96849
96850 static int ipip_tunnel_init(struct net_device *dev);
96851 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
96852 +static struct rtnl_link_ops ipip_link_ops;
96853
96854 static int ipip_err(struct sk_buff *skb, u32 info)
96855 {
96856 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
96857 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
96858 };
96859
96860 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
96861 +static struct rtnl_link_ops ipip_link_ops = {
96862 .kind = "ipip",
96863 .maxtype = IFLA_IPTUN_MAX,
96864 .policy = ipip_policy,
96865 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
96866 index 59da7cd..e318de1 100644
96867 --- a/net/ipv4/netfilter/arp_tables.c
96868 +++ b/net/ipv4/netfilter/arp_tables.c
96869 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
96870 #endif
96871
96872 static int get_info(struct net *net, void __user *user,
96873 - const int *len, int compat)
96874 + int len, int compat)
96875 {
96876 char name[XT_TABLE_MAXNAMELEN];
96877 struct xt_table *t;
96878 int ret;
96879
96880 - if (*len != sizeof(struct arpt_getinfo)) {
96881 - duprintf("length %u != %Zu\n", *len,
96882 + if (len != sizeof(struct arpt_getinfo)) {
96883 + duprintf("length %u != %Zu\n", len,
96884 sizeof(struct arpt_getinfo));
96885 return -EINVAL;
96886 }
96887 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
96888 info.size = private->size;
96889 strcpy(info.name, name);
96890
96891 - if (copy_to_user(user, &info, *len) != 0)
96892 + if (copy_to_user(user, &info, len) != 0)
96893 ret = -EFAULT;
96894 else
96895 ret = 0;
96896 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
96897
96898 switch (cmd) {
96899 case ARPT_SO_GET_INFO:
96900 - ret = get_info(sock_net(sk), user, len, 1);
96901 + ret = get_info(sock_net(sk), user, *len, 1);
96902 break;
96903 case ARPT_SO_GET_ENTRIES:
96904 ret = compat_get_entries(sock_net(sk), user, len);
96905 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
96906
96907 switch (cmd) {
96908 case ARPT_SO_GET_INFO:
96909 - ret = get_info(sock_net(sk), user, len, 0);
96910 + ret = get_info(sock_net(sk), user, *len, 0);
96911 break;
96912
96913 case ARPT_SO_GET_ENTRIES:
96914 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
96915 index 718dfbd..cef4152 100644
96916 --- a/net/ipv4/netfilter/ip_tables.c
96917 +++ b/net/ipv4/netfilter/ip_tables.c
96918 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
96919 #endif
96920
96921 static int get_info(struct net *net, void __user *user,
96922 - const int *len, int compat)
96923 + int len, int compat)
96924 {
96925 char name[XT_TABLE_MAXNAMELEN];
96926 struct xt_table *t;
96927 int ret;
96928
96929 - if (*len != sizeof(struct ipt_getinfo)) {
96930 - duprintf("length %u != %zu\n", *len,
96931 + if (len != sizeof(struct ipt_getinfo)) {
96932 + duprintf("length %u != %zu\n", len,
96933 sizeof(struct ipt_getinfo));
96934 return -EINVAL;
96935 }
96936 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
96937 info.size = private->size;
96938 strcpy(info.name, name);
96939
96940 - if (copy_to_user(user, &info, *len) != 0)
96941 + if (copy_to_user(user, &info, len) != 0)
96942 ret = -EFAULT;
96943 else
96944 ret = 0;
96945 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96946
96947 switch (cmd) {
96948 case IPT_SO_GET_INFO:
96949 - ret = get_info(sock_net(sk), user, len, 1);
96950 + ret = get_info(sock_net(sk), user, *len, 1);
96951 break;
96952 case IPT_SO_GET_ENTRIES:
96953 ret = compat_get_entries(sock_net(sk), user, len);
96954 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96955
96956 switch (cmd) {
96957 case IPT_SO_GET_INFO:
96958 - ret = get_info(sock_net(sk), user, len, 0);
96959 + ret = get_info(sock_net(sk), user, *len, 0);
96960 break;
96961
96962 case IPT_SO_GET_ENTRIES:
96963 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
96964 index 242e7f4..a084e95 100644
96965 --- a/net/ipv4/ping.c
96966 +++ b/net/ipv4/ping.c
96967 @@ -55,7 +55,7 @@
96968
96969
96970 struct ping_table ping_table;
96971 -struct pingv6_ops pingv6_ops;
96972 +struct pingv6_ops *pingv6_ops;
96973 EXPORT_SYMBOL_GPL(pingv6_ops);
96974
96975 static u16 ping_port_rover;
96976 @@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
96977 return -ENODEV;
96978 }
96979 }
96980 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
96981 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
96982 scoped);
96983 rcu_read_unlock();
96984
96985 @@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96986 }
96987 #if IS_ENABLED(CONFIG_IPV6)
96988 } else if (skb->protocol == htons(ETH_P_IPV6)) {
96989 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
96990 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
96991 #endif
96992 }
96993
96994 @@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96995 info, (u8 *)icmph);
96996 #if IS_ENABLED(CONFIG_IPV6)
96997 } else if (family == AF_INET6) {
96998 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
96999 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
97000 info, (u8 *)icmph);
97001 #endif
97002 }
97003 @@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97004 {
97005 struct inet_sock *isk = inet_sk(sk);
97006 int family = sk->sk_family;
97007 + struct sockaddr_in *sin;
97008 + struct sockaddr_in6 *sin6;
97009 struct sk_buff *skb;
97010 int copied, err;
97011
97012 @@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97013 if (flags & MSG_OOB)
97014 goto out;
97015
97016 + if (addr_len) {
97017 + if (family == AF_INET)
97018 + *addr_len = sizeof(*sin);
97019 + else if (family == AF_INET6 && addr_len)
97020 + *addr_len = sizeof(*sin6);
97021 + }
97022 +
97023 if (flags & MSG_ERRQUEUE) {
97024 if (family == AF_INET) {
97025 return ip_recv_error(sk, msg, len, addr_len);
97026 #if IS_ENABLED(CONFIG_IPV6)
97027 } else if (family == AF_INET6) {
97028 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
97029 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
97030 addr_len);
97031 #endif
97032 }
97033 @@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97034 sin->sin_port = 0 /* skb->h.uh->source */;
97035 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97036 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97037 - *addr_len = sizeof(*sin);
97038 }
97039
97040 if (isk->cmsg_flags)
97041 @@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97042 sin6->sin6_scope_id =
97043 ipv6_iface_scope_id(&sin6->sin6_addr,
97044 IP6CB(skb)->iif);
97045 - *addr_len = sizeof(*sin6);
97046 }
97047
97048 if (inet6_sk(sk)->rxopt.all)
97049 - pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
97050 + pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
97051 #endif
97052 } else {
97053 BUG();
97054 @@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
97055 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97056 0, sock_i_ino(sp),
97057 atomic_read(&sp->sk_refcnt), sp,
97058 - atomic_read(&sp->sk_drops));
97059 + atomic_read_unchecked(&sp->sk_drops));
97060 }
97061
97062 static int ping_v4_seq_show(struct seq_file *seq, void *v)
97063 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
97064 index 23c3e5b..cdb8b36 100644
97065 --- a/net/ipv4/raw.c
97066 +++ b/net/ipv4/raw.c
97067 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
97068 int raw_rcv(struct sock *sk, struct sk_buff *skb)
97069 {
97070 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
97071 - atomic_inc(&sk->sk_drops);
97072 + atomic_inc_unchecked(&sk->sk_drops);
97073 kfree_skb(skb);
97074 return NET_RX_DROP;
97075 }
97076 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97077 if (flags & MSG_OOB)
97078 goto out;
97079
97080 + if (addr_len)
97081 + *addr_len = sizeof(*sin);
97082 +
97083 if (flags & MSG_ERRQUEUE) {
97084 err = ip_recv_error(sk, msg, len, addr_len);
97085 goto out;
97086 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97087 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97088 sin->sin_port = 0;
97089 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
97090 - *addr_len = sizeof(*sin);
97091 }
97092 if (inet->cmsg_flags)
97093 ip_cmsg_recv(msg, skb);
97094 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
97095
97096 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
97097 {
97098 + struct icmp_filter filter;
97099 +
97100 if (optlen > sizeof(struct icmp_filter))
97101 optlen = sizeof(struct icmp_filter);
97102 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
97103 + if (copy_from_user(&filter, optval, optlen))
97104 return -EFAULT;
97105 + raw_sk(sk)->filter = filter;
97106 return 0;
97107 }
97108
97109 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
97110 {
97111 int len, ret = -EFAULT;
97112 + struct icmp_filter filter;
97113
97114 if (get_user(len, optlen))
97115 goto out;
97116 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
97117 if (len > sizeof(struct icmp_filter))
97118 len = sizeof(struct icmp_filter);
97119 ret = -EFAULT;
97120 - if (put_user(len, optlen) ||
97121 - copy_to_user(optval, &raw_sk(sk)->filter, len))
97122 + filter = raw_sk(sk)->filter;
97123 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
97124 goto out;
97125 ret = 0;
97126 out: return ret;
97127 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
97128 0, 0L, 0,
97129 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
97130 0, sock_i_ino(sp),
97131 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
97132 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
97133 }
97134
97135 static int raw_seq_show(struct seq_file *seq, void *v)
97136 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
97137 index f8da282..133a1c7 100644
97138 --- a/net/ipv4/route.c
97139 +++ b/net/ipv4/route.c
97140 @@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
97141 .maxlen = sizeof(int),
97142 .mode = 0200,
97143 .proc_handler = ipv4_sysctl_rtcache_flush,
97144 + .extra1 = &init_net,
97145 },
97146 { },
97147 };
97148
97149 static __net_init int sysctl_route_net_init(struct net *net)
97150 {
97151 - struct ctl_table *tbl;
97152 + ctl_table_no_const *tbl = NULL;
97153
97154 - tbl = ipv4_route_flush_table;
97155 if (!net_eq(net, &init_net)) {
97156 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
97157 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
97158 if (tbl == NULL)
97159 goto err_dup;
97160
97161 /* Don't export sysctls to unprivileged users */
97162 if (net->user_ns != &init_user_ns)
97163 tbl[0].procname = NULL;
97164 - }
97165 - tbl[0].extra1 = net;
97166 + tbl[0].extra1 = net;
97167 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97168 + } else
97169 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
97170
97171 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97172 if (net->ipv4.route_hdr == NULL)
97173 goto err_reg;
97174 return 0;
97175
97176 err_reg:
97177 - if (tbl != ipv4_route_flush_table)
97178 - kfree(tbl);
97179 + kfree(tbl);
97180 err_dup:
97181 return -ENOMEM;
97182 }
97183 @@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
97184
97185 static __net_init int rt_genid_init(struct net *net)
97186 {
97187 - atomic_set(&net->ipv4.rt_genid, 0);
97188 - atomic_set(&net->fnhe_genid, 0);
97189 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
97190 + atomic_set_unchecked(&net->fnhe_genid, 0);
97191 get_random_bytes(&net->ipv4.dev_addr_genid,
97192 sizeof(net->ipv4.dev_addr_genid));
97193 return 0;
97194 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
97195 index 3d69ec8..57207b4 100644
97196 --- a/net/ipv4/sysctl_net_ipv4.c
97197 +++ b/net/ipv4/sysctl_net_ipv4.c
97198 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
97199 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
97200 int ret;
97201 int range[2];
97202 - struct ctl_table tmp = {
97203 + ctl_table_no_const tmp = {
97204 .data = &range,
97205 .maxlen = sizeof(range),
97206 .mode = table->mode,
97207 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
97208 int ret;
97209 gid_t urange[2];
97210 kgid_t low, high;
97211 - struct ctl_table tmp = {
97212 + ctl_table_no_const tmp = {
97213 .data = &urange,
97214 .maxlen = sizeof(urange),
97215 .mode = table->mode,
97216 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
97217 void __user *buffer, size_t *lenp, loff_t *ppos)
97218 {
97219 char val[TCP_CA_NAME_MAX];
97220 - struct ctl_table tbl = {
97221 + ctl_table_no_const tbl = {
97222 .data = val,
97223 .maxlen = TCP_CA_NAME_MAX,
97224 };
97225 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
97226 void __user *buffer, size_t *lenp,
97227 loff_t *ppos)
97228 {
97229 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
97230 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
97231 int ret;
97232
97233 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97234 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
97235 void __user *buffer, size_t *lenp,
97236 loff_t *ppos)
97237 {
97238 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
97239 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
97240 int ret;
97241
97242 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97243 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
97244 void __user *buffer, size_t *lenp,
97245 loff_t *ppos)
97246 {
97247 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97248 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97249 struct tcp_fastopen_context *ctxt;
97250 int ret;
97251 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
97252 @@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
97253 },
97254 {
97255 .procname = "ip_local_reserved_ports",
97256 - .data = NULL, /* initialized in sysctl_ipv4_init */
97257 + .data = sysctl_local_reserved_ports,
97258 .maxlen = 65536,
97259 .mode = 0644,
97260 .proc_handler = proc_do_large_bitmap,
97261 @@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
97262
97263 static __net_init int ipv4_sysctl_init_net(struct net *net)
97264 {
97265 - struct ctl_table *table;
97266 + ctl_table_no_const *table = NULL;
97267
97268 - table = ipv4_net_table;
97269 if (!net_eq(net, &init_net)) {
97270 int i;
97271
97272 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
97273 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
97274 if (table == NULL)
97275 goto err_alloc;
97276
97277 @@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
97278 net->ipv4.sysctl_local_ports.range[0] = 32768;
97279 net->ipv4.sysctl_local_ports.range[1] = 61000;
97280
97281 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97282 + if (!net_eq(net, &init_net))
97283 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97284 + else
97285 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
97286 if (net->ipv4.ipv4_hdr == NULL)
97287 goto err_reg;
97288
97289 return 0;
97290
97291 err_reg:
97292 - if (!net_eq(net, &init_net))
97293 - kfree(table);
97294 + kfree(table);
97295 err_alloc:
97296 return -ENOMEM;
97297 }
97298 @@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
97299 static __init int sysctl_ipv4_init(void)
97300 {
97301 struct ctl_table_header *hdr;
97302 - struct ctl_table *i;
97303 -
97304 - for (i = ipv4_table; i->procname; i++) {
97305 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
97306 - i->data = sysctl_local_reserved_ports;
97307 - break;
97308 - }
97309 - }
97310 - if (!i->procname)
97311 - return -EINVAL;
97312
97313 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
97314 if (hdr == NULL)
97315 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
97316 index c53b7f3..a89aadd 100644
97317 --- a/net/ipv4/tcp_input.c
97318 +++ b/net/ipv4/tcp_input.c
97319 @@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
97320 * without any lock. We want to make sure compiler wont store
97321 * intermediate values in this location.
97322 */
97323 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
97324 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
97325 sk->sk_max_pacing_rate);
97326 }
97327
97328 @@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
97329 * simplifies code)
97330 */
97331 static void
97332 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97333 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97334 struct sk_buff *head, struct sk_buff *tail,
97335 u32 start, u32 end)
97336 {
97337 @@ -5559,6 +5559,7 @@ discard:
97338 tcp_paws_reject(&tp->rx_opt, 0))
97339 goto discard_and_undo;
97340
97341 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
97342 if (th->syn) {
97343 /* We see SYN without ACK. It is attempt of
97344 * simultaneous connect with crossed SYNs.
97345 @@ -5609,6 +5610,7 @@ discard:
97346 goto discard;
97347 #endif
97348 }
97349 +#endif
97350 /* "fifth, if neither of the SYN or RST bits is set then
97351 * drop the segment and return."
97352 */
97353 @@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
97354 goto discard;
97355
97356 if (th->syn) {
97357 - if (th->fin)
97358 + if (th->fin || th->urg || th->psh)
97359 goto discard;
97360 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
97361 return 1;
97362 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
97363 index 0672139..cacc17d 100644
97364 --- a/net/ipv4/tcp_ipv4.c
97365 +++ b/net/ipv4/tcp_ipv4.c
97366 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
97367 EXPORT_SYMBOL(sysctl_tcp_low_latency);
97368
97369
97370 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97371 +extern int grsec_enable_blackhole;
97372 +#endif
97373 +
97374 #ifdef CONFIG_TCP_MD5SIG
97375 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
97376 __be32 daddr, __be32 saddr, const struct tcphdr *th);
97377 @@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
97378 return 0;
97379
97380 reset:
97381 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97382 + if (!grsec_enable_blackhole)
97383 +#endif
97384 tcp_v4_send_reset(rsk, skb);
97385 discard:
97386 kfree_skb(skb);
97387 @@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
97388 TCP_SKB_CB(skb)->sacked = 0;
97389
97390 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
97391 - if (!sk)
97392 + if (!sk) {
97393 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97394 + ret = 1;
97395 +#endif
97396 goto no_tcp_socket;
97397 -
97398 + }
97399 process:
97400 - if (sk->sk_state == TCP_TIME_WAIT)
97401 + if (sk->sk_state == TCP_TIME_WAIT) {
97402 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97403 + ret = 2;
97404 +#endif
97405 goto do_time_wait;
97406 + }
97407
97408 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
97409 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
97410 @@ -2034,6 +2048,10 @@ csum_error:
97411 bad_packet:
97412 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
97413 } else {
97414 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97415 + if (!grsec_enable_blackhole || (ret == 1 &&
97416 + (skb->dev->flags & IFF_LOOPBACK)))
97417 +#endif
97418 tcp_v4_send_reset(NULL, skb);
97419 }
97420
97421 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
97422 index 97b6841..0893357 100644
97423 --- a/net/ipv4/tcp_minisocks.c
97424 +++ b/net/ipv4/tcp_minisocks.c
97425 @@ -27,6 +27,10 @@
97426 #include <net/inet_common.h>
97427 #include <net/xfrm.h>
97428
97429 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97430 +extern int grsec_enable_blackhole;
97431 +#endif
97432 +
97433 int sysctl_tcp_syncookies __read_mostly = 1;
97434 EXPORT_SYMBOL(sysctl_tcp_syncookies);
97435
97436 @@ -708,7 +712,10 @@ embryonic_reset:
97437 * avoid becoming vulnerable to outside attack aiming at
97438 * resetting legit local connections.
97439 */
97440 - req->rsk_ops->send_reset(sk, skb);
97441 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97442 + if (!grsec_enable_blackhole)
97443 +#endif
97444 + req->rsk_ops->send_reset(sk, skb);
97445 } else if (fastopen) { /* received a valid RST pkt */
97446 reqsk_fastopen_remove(sk, req, true);
97447 tcp_reset(sk);
97448 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
97449 index 8b97d71..9d7ccf5 100644
97450 --- a/net/ipv4/tcp_probe.c
97451 +++ b/net/ipv4/tcp_probe.c
97452 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
97453 if (cnt + width >= len)
97454 break;
97455
97456 - if (copy_to_user(buf + cnt, tbuf, width))
97457 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
97458 return -EFAULT;
97459 cnt += width;
97460 }
97461 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
97462 index 64f0354..a81b39d 100644
97463 --- a/net/ipv4/tcp_timer.c
97464 +++ b/net/ipv4/tcp_timer.c
97465 @@ -22,6 +22,10 @@
97466 #include <linux/gfp.h>
97467 #include <net/tcp.h>
97468
97469 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97470 +extern int grsec_lastack_retries;
97471 +#endif
97472 +
97473 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
97474 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
97475 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
97476 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
97477 }
97478 }
97479
97480 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97481 + if ((sk->sk_state == TCP_LAST_ACK) &&
97482 + (grsec_lastack_retries > 0) &&
97483 + (grsec_lastack_retries < retry_until))
97484 + retry_until = grsec_lastack_retries;
97485 +#endif
97486 +
97487 if (retransmits_timed_out(sk, retry_until,
97488 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
97489 /* Has it gone just too far? */
97490 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
97491 index a7e4729..2758946 100644
97492 --- a/net/ipv4/udp.c
97493 +++ b/net/ipv4/udp.c
97494 @@ -87,6 +87,7 @@
97495 #include <linux/types.h>
97496 #include <linux/fcntl.h>
97497 #include <linux/module.h>
97498 +#include <linux/security.h>
97499 #include <linux/socket.h>
97500 #include <linux/sockios.h>
97501 #include <linux/igmp.h>
97502 @@ -113,6 +114,10 @@
97503 #include <net/busy_poll.h>
97504 #include "udp_impl.h"
97505
97506 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97507 +extern int grsec_enable_blackhole;
97508 +#endif
97509 +
97510 struct udp_table udp_table __read_mostly;
97511 EXPORT_SYMBOL(udp_table);
97512
97513 @@ -615,6 +620,9 @@ found:
97514 return s;
97515 }
97516
97517 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
97518 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
97519 +
97520 /*
97521 * This routine is called by the ICMP module when it gets some
97522 * sort of error condition. If err < 0 then the socket should
97523 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97524 dport = usin->sin_port;
97525 if (dport == 0)
97526 return -EINVAL;
97527 +
97528 + err = gr_search_udp_sendmsg(sk, usin);
97529 + if (err)
97530 + return err;
97531 } else {
97532 if (sk->sk_state != TCP_ESTABLISHED)
97533 return -EDESTADDRREQ;
97534 +
97535 + err = gr_search_udp_sendmsg(sk, NULL);
97536 + if (err)
97537 + return err;
97538 +
97539 daddr = inet->inet_daddr;
97540 dport = inet->inet_dport;
97541 /* Open fast path for connected socket.
97542 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
97543 IS_UDPLITE(sk));
97544 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97545 IS_UDPLITE(sk));
97546 - atomic_inc(&sk->sk_drops);
97547 + atomic_inc_unchecked(&sk->sk_drops);
97548 __skb_unlink(skb, rcvq);
97549 __skb_queue_tail(&list_kill, skb);
97550 }
97551 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97552 int is_udplite = IS_UDPLITE(sk);
97553 bool slow;
97554
97555 + /*
97556 + * Check any passed addresses
97557 + */
97558 + if (addr_len)
97559 + *addr_len = sizeof(*sin);
97560 +
97561 if (flags & MSG_ERRQUEUE)
97562 return ip_recv_error(sk, msg, len, addr_len);
97563
97564 @@ -1243,6 +1266,10 @@ try_again:
97565 if (!skb)
97566 goto out;
97567
97568 + err = gr_search_udp_recvmsg(sk, skb);
97569 + if (err)
97570 + goto out_free;
97571 +
97572 ulen = skb->len - sizeof(struct udphdr);
97573 copied = len;
97574 if (copied > ulen)
97575 @@ -1276,7 +1303,7 @@ try_again:
97576 if (unlikely(err)) {
97577 trace_kfree_skb(skb, udp_recvmsg);
97578 if (!peeked) {
97579 - atomic_inc(&sk->sk_drops);
97580 + atomic_inc_unchecked(&sk->sk_drops);
97581 UDP_INC_STATS_USER(sock_net(sk),
97582 UDP_MIB_INERRORS, is_udplite);
97583 }
97584 @@ -1295,7 +1322,6 @@ try_again:
97585 sin->sin_port = udp_hdr(skb)->source;
97586 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97587 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97588 - *addr_len = sizeof(*sin);
97589 }
97590 if (inet->cmsg_flags)
97591 ip_cmsg_recv(msg, skb);
97592 @@ -1566,7 +1592,7 @@ csum_error:
97593 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
97594 drop:
97595 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
97596 - atomic_inc(&sk->sk_drops);
97597 + atomic_inc_unchecked(&sk->sk_drops);
97598 kfree_skb(skb);
97599 return -1;
97600 }
97601 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
97602 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
97603
97604 if (!skb1) {
97605 - atomic_inc(&sk->sk_drops);
97606 + atomic_inc_unchecked(&sk->sk_drops);
97607 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
97608 IS_UDPLITE(sk));
97609 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97610 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
97611 goto csum_error;
97612
97613 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
97614 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97615 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
97616 +#endif
97617 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
97618
97619 /*
97620 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
97621 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97622 0, sock_i_ino(sp),
97623 atomic_read(&sp->sk_refcnt), sp,
97624 - atomic_read(&sp->sk_drops));
97625 + atomic_read_unchecked(&sp->sk_drops));
97626 }
97627
97628 int udp4_seq_show(struct seq_file *seq, void *v)
97629 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
97630 index e1a6393..f634ce5 100644
97631 --- a/net/ipv4/xfrm4_policy.c
97632 +++ b/net/ipv4/xfrm4_policy.c
97633 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
97634 fl4->flowi4_tos = iph->tos;
97635 }
97636
97637 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
97638 +static int xfrm4_garbage_collect(struct dst_ops *ops)
97639 {
97640 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
97641
97642 - xfrm4_policy_afinfo.garbage_collect(net);
97643 + xfrm_garbage_collect_deferred(net);
97644 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
97645 }
97646
97647 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
97648
97649 static int __net_init xfrm4_net_init(struct net *net)
97650 {
97651 - struct ctl_table *table;
97652 + ctl_table_no_const *table = NULL;
97653 struct ctl_table_header *hdr;
97654
97655 - table = xfrm4_policy_table;
97656 if (!net_eq(net, &init_net)) {
97657 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97658 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97659 if (!table)
97660 goto err_alloc;
97661
97662 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
97663 - }
97664 -
97665 - hdr = register_net_sysctl(net, "net/ipv4", table);
97666 + hdr = register_net_sysctl(net, "net/ipv4", table);
97667 + } else
97668 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
97669 if (!hdr)
97670 goto err_reg;
97671
97672 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
97673 return 0;
97674
97675 err_reg:
97676 - if (!net_eq(net, &init_net))
97677 - kfree(table);
97678 + kfree(table);
97679 err_alloc:
97680 return -ENOMEM;
97681 }
97682 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
97683 index 4b6b720..272c0c5 100644
97684 --- a/net/ipv6/addrconf.c
97685 +++ b/net/ipv6/addrconf.c
97686 @@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
97687 idx = 0;
97688 head = &net->dev_index_head[h];
97689 rcu_read_lock();
97690 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
97691 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
97692 net->dev_base_seq;
97693 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97694 if (idx < s_idx)
97695 @@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
97696 p.iph.ihl = 5;
97697 p.iph.protocol = IPPROTO_IPV6;
97698 p.iph.ttl = 64;
97699 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
97700 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
97701
97702 if (ops->ndo_do_ioctl) {
97703 mm_segment_t oldfs = get_fs();
97704 @@ -3962,7 +3962,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
97705 s_ip_idx = ip_idx = cb->args[2];
97706
97707 rcu_read_lock();
97708 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97709 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97710 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
97711 idx = 0;
97712 head = &net->dev_index_head[h];
97713 @@ -4569,7 +4569,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
97714 dst_free(&ifp->rt->dst);
97715 break;
97716 }
97717 - atomic_inc(&net->ipv6.dev_addr_genid);
97718 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
97719 rt_genid_bump_ipv6(net);
97720 }
97721
97722 @@ -4590,7 +4590,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
97723 int *valp = ctl->data;
97724 int val = *valp;
97725 loff_t pos = *ppos;
97726 - struct ctl_table lctl;
97727 + ctl_table_no_const lctl;
97728 int ret;
97729
97730 /*
97731 @@ -4675,7 +4675,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
97732 int *valp = ctl->data;
97733 int val = *valp;
97734 loff_t pos = *ppos;
97735 - struct ctl_table lctl;
97736 + ctl_table_no_const lctl;
97737 int ret;
97738
97739 /*
97740 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
97741 index 4fbdb70..f6411f2 100644
97742 --- a/net/ipv6/af_inet6.c
97743 +++ b/net/ipv6/af_inet6.c
97744 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
97745
97746 net->ipv6.sysctl.bindv6only = 0;
97747 net->ipv6.sysctl.icmpv6_time = 1*HZ;
97748 - atomic_set(&net->ipv6.rt_genid, 0);
97749 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
97750
97751 err = ipv6_init_mibs(net);
97752 if (err)
97753 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
97754 index 93b1aa3..e902855 100644
97755 --- a/net/ipv6/datagram.c
97756 +++ b/net/ipv6/datagram.c
97757 @@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
97758 0,
97759 sock_i_ino(sp),
97760 atomic_read(&sp->sk_refcnt), sp,
97761 - atomic_read(&sp->sk_drops));
97762 + atomic_read_unchecked(&sp->sk_drops));
97763 }
97764 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
97765 index eef8d94..cfa1852 100644
97766 --- a/net/ipv6/icmp.c
97767 +++ b/net/ipv6/icmp.c
97768 @@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
97769
97770 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
97771 {
97772 - struct ctl_table *table;
97773 + ctl_table_no_const *table;
97774
97775 table = kmemdup(ipv6_icmp_table_template,
97776 sizeof(ipv6_icmp_table_template),
97777 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
97778 index 8acb286..840dd06 100644
97779 --- a/net/ipv6/ip6_gre.c
97780 +++ b/net/ipv6/ip6_gre.c
97781 @@ -74,7 +74,7 @@ struct ip6gre_net {
97782 struct net_device *fb_tunnel_dev;
97783 };
97784
97785 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
97786 +static struct rtnl_link_ops ip6gre_link_ops;
97787 static int ip6gre_tunnel_init(struct net_device *dev);
97788 static void ip6gre_tunnel_setup(struct net_device *dev);
97789 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
97790 @@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
97791 }
97792
97793
97794 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
97795 +static struct inet6_protocol ip6gre_protocol = {
97796 .handler = ip6gre_rcv,
97797 .err_handler = ip6gre_err,
97798 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
97799 @@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
97800 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
97801 };
97802
97803 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97804 +static struct rtnl_link_ops ip6gre_link_ops = {
97805 .kind = "ip6gre",
97806 .maxtype = IFLA_GRE_MAX,
97807 .policy = ip6gre_policy,
97808 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97809 .fill_info = ip6gre_fill_info,
97810 };
97811
97812 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
97813 +static struct rtnl_link_ops ip6gre_tap_ops = {
97814 .kind = "ip6gretap",
97815 .maxtype = IFLA_GRE_MAX,
97816 .policy = ip6gre_policy,
97817 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
97818 index 7881965..9cf62c4 100644
97819 --- a/net/ipv6/ip6_tunnel.c
97820 +++ b/net/ipv6/ip6_tunnel.c
97821 @@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97822
97823 static int ip6_tnl_dev_init(struct net_device *dev);
97824 static void ip6_tnl_dev_setup(struct net_device *dev);
97825 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
97826 +static struct rtnl_link_ops ip6_link_ops;
97827
97828 static int ip6_tnl_net_id __read_mostly;
97829 struct ip6_tnl_net {
97830 @@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
97831 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
97832 };
97833
97834 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
97835 +static struct rtnl_link_ops ip6_link_ops = {
97836 .kind = "ip6tnl",
97837 .maxtype = IFLA_IPTUN_MAX,
97838 .policy = ip6_tnl_policy,
97839 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
97840 index 7b42d5e..1eff693 100644
97841 --- a/net/ipv6/ip6_vti.c
97842 +++ b/net/ipv6/ip6_vti.c
97843 @@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97844
97845 static int vti6_dev_init(struct net_device *dev);
97846 static void vti6_dev_setup(struct net_device *dev);
97847 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
97848 +static struct rtnl_link_ops vti6_link_ops;
97849
97850 static int vti6_net_id __read_mostly;
97851 struct vti6_net {
97852 @@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
97853 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
97854 };
97855
97856 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
97857 +static struct rtnl_link_ops vti6_link_ops = {
97858 .kind = "vti6",
97859 .maxtype = IFLA_VTI_MAX,
97860 .policy = vti6_policy,
97861 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
97862 index 1c6ce31..299e566 100644
97863 --- a/net/ipv6/ipv6_sockglue.c
97864 +++ b/net/ipv6/ipv6_sockglue.c
97865 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
97866 if (sk->sk_type != SOCK_STREAM)
97867 return -ENOPROTOOPT;
97868
97869 - msg.msg_control = optval;
97870 + msg.msg_control = (void __force_kernel *)optval;
97871 msg.msg_controllen = len;
97872 msg.msg_flags = flags;
97873
97874 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
97875 index 710238f..0fd1816 100644
97876 --- a/net/ipv6/netfilter/ip6_tables.c
97877 +++ b/net/ipv6/netfilter/ip6_tables.c
97878 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
97879 #endif
97880
97881 static int get_info(struct net *net, void __user *user,
97882 - const int *len, int compat)
97883 + int len, int compat)
97884 {
97885 char name[XT_TABLE_MAXNAMELEN];
97886 struct xt_table *t;
97887 int ret;
97888
97889 - if (*len != sizeof(struct ip6t_getinfo)) {
97890 - duprintf("length %u != %zu\n", *len,
97891 + if (len != sizeof(struct ip6t_getinfo)) {
97892 + duprintf("length %u != %zu\n", len,
97893 sizeof(struct ip6t_getinfo));
97894 return -EINVAL;
97895 }
97896 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
97897 info.size = private->size;
97898 strcpy(info.name, name);
97899
97900 - if (copy_to_user(user, &info, *len) != 0)
97901 + if (copy_to_user(user, &info, len) != 0)
97902 ret = -EFAULT;
97903 else
97904 ret = 0;
97905 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97906
97907 switch (cmd) {
97908 case IP6T_SO_GET_INFO:
97909 - ret = get_info(sock_net(sk), user, len, 1);
97910 + ret = get_info(sock_net(sk), user, *len, 1);
97911 break;
97912 case IP6T_SO_GET_ENTRIES:
97913 ret = compat_get_entries(sock_net(sk), user, len);
97914 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97915
97916 switch (cmd) {
97917 case IP6T_SO_GET_INFO:
97918 - ret = get_info(sock_net(sk), user, len, 0);
97919 + ret = get_info(sock_net(sk), user, *len, 0);
97920 break;
97921
97922 case IP6T_SO_GET_ENTRIES:
97923 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
97924 index 767ab8d..c5ec70a 100644
97925 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
97926 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
97927 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
97928
97929 static int nf_ct_frag6_sysctl_register(struct net *net)
97930 {
97931 - struct ctl_table *table;
97932 + ctl_table_no_const *table = NULL;
97933 struct ctl_table_header *hdr;
97934
97935 - table = nf_ct_frag6_sysctl_table;
97936 if (!net_eq(net, &init_net)) {
97937 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
97938 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
97939 GFP_KERNEL);
97940 if (table == NULL)
97941 goto err_alloc;
97942 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97943 table[0].data = &net->nf_frag.frags.timeout;
97944 table[1].data = &net->nf_frag.frags.low_thresh;
97945 table[2].data = &net->nf_frag.frags.high_thresh;
97946 - }
97947 -
97948 - hdr = register_net_sysctl(net, "net/netfilter", table);
97949 + hdr = register_net_sysctl(net, "net/netfilter", table);
97950 + } else
97951 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
97952 if (hdr == NULL)
97953 goto err_reg;
97954
97955 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97956 return 0;
97957
97958 err_reg:
97959 - if (!net_eq(net, &init_net))
97960 - kfree(table);
97961 + kfree(table);
97962 err_alloc:
97963 return -ENOMEM;
97964 }
97965 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
97966 index 827f795..7e28e82 100644
97967 --- a/net/ipv6/output_core.c
97968 +++ b/net/ipv6/output_core.c
97969 @@ -9,8 +9,8 @@
97970
97971 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97972 {
97973 - static atomic_t ipv6_fragmentation_id;
97974 - int old, new;
97975 + static atomic_unchecked_t ipv6_fragmentation_id;
97976 + int id;
97977
97978 #if IS_ENABLED(CONFIG_IPV6)
97979 if (rt && !(rt->dst.flags & DST_NOPEER)) {
97980 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97981 }
97982 }
97983 #endif
97984 - do {
97985 - old = atomic_read(&ipv6_fragmentation_id);
97986 - new = old + 1;
97987 - if (!new)
97988 - new = 1;
97989 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
97990 - fhdr->identification = htonl(new);
97991 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97992 + if (!id)
97993 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97994 + fhdr->identification = htonl(id);
97995 }
97996 EXPORT_SYMBOL(ipv6_select_ident);
97997
97998 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
97999 index a83243c..a1ca589 100644
98000 --- a/net/ipv6/ping.c
98001 +++ b/net/ipv6/ping.c
98002 @@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
98003 };
98004 #endif
98005
98006 +static struct pingv6_ops real_pingv6_ops = {
98007 + .ipv6_recv_error = ipv6_recv_error,
98008 + .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
98009 + .icmpv6_err_convert = icmpv6_err_convert,
98010 + .ipv6_icmp_error = ipv6_icmp_error,
98011 + .ipv6_chk_addr = ipv6_chk_addr,
98012 +};
98013 +
98014 +static struct pingv6_ops dummy_pingv6_ops = {
98015 + .ipv6_recv_error = dummy_ipv6_recv_error,
98016 + .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
98017 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
98018 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
98019 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
98020 +};
98021 +
98022 int __init pingv6_init(void)
98023 {
98024 #ifdef CONFIG_PROC_FS
98025 @@ -253,11 +269,7 @@ int __init pingv6_init(void)
98026 if (ret)
98027 return ret;
98028 #endif
98029 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
98030 - pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
98031 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
98032 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
98033 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
98034 + pingv6_ops = &real_pingv6_ops;
98035 return inet6_register_protosw(&pingv6_protosw);
98036 }
98037
98038 @@ -266,11 +278,7 @@ int __init pingv6_init(void)
98039 */
98040 void pingv6_exit(void)
98041 {
98042 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
98043 - pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
98044 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
98045 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
98046 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
98047 + pingv6_ops = &dummy_pingv6_ops;
98048 #ifdef CONFIG_PROC_FS
98049 unregister_pernet_subsys(&ping_v6_net_ops);
98050 #endif
98051 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
98052 index b6bb87e..06cc9ed 100644
98053 --- a/net/ipv6/raw.c
98054 +++ b/net/ipv6/raw.c
98055 @@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
98056 {
98057 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
98058 skb_checksum_complete(skb)) {
98059 - atomic_inc(&sk->sk_drops);
98060 + atomic_inc_unchecked(&sk->sk_drops);
98061 kfree_skb(skb);
98062 return NET_RX_DROP;
98063 }
98064 @@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98065 struct raw6_sock *rp = raw6_sk(sk);
98066
98067 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
98068 - atomic_inc(&sk->sk_drops);
98069 + atomic_inc_unchecked(&sk->sk_drops);
98070 kfree_skb(skb);
98071 return NET_RX_DROP;
98072 }
98073 @@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98074
98075 if (inet->hdrincl) {
98076 if (skb_checksum_complete(skb)) {
98077 - atomic_inc(&sk->sk_drops);
98078 + atomic_inc_unchecked(&sk->sk_drops);
98079 kfree_skb(skb);
98080 return NET_RX_DROP;
98081 }
98082 @@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98083 if (flags & MSG_OOB)
98084 return -EOPNOTSUPP;
98085
98086 + if (addr_len)
98087 + *addr_len=sizeof(*sin6);
98088 +
98089 if (flags & MSG_ERRQUEUE)
98090 return ipv6_recv_error(sk, msg, len, addr_len);
98091
98092 @@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98093 sin6->sin6_flowinfo = 0;
98094 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
98095 IP6CB(skb)->iif);
98096 - *addr_len = sizeof(*sin6);
98097 }
98098
98099 sock_recv_ts_and_drops(msg, sk, skb);
98100 @@ -606,7 +608,7 @@ out:
98101 return err;
98102 }
98103
98104 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
98105 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
98106 struct flowi6 *fl6, struct dst_entry **dstp,
98107 unsigned int flags)
98108 {
98109 @@ -918,12 +920,15 @@ do_confirm:
98110 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
98111 char __user *optval, int optlen)
98112 {
98113 + struct icmp6_filter filter;
98114 +
98115 switch (optname) {
98116 case ICMPV6_FILTER:
98117 if (optlen > sizeof(struct icmp6_filter))
98118 optlen = sizeof(struct icmp6_filter);
98119 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
98120 + if (copy_from_user(&filter, optval, optlen))
98121 return -EFAULT;
98122 + raw6_sk(sk)->filter = filter;
98123 return 0;
98124 default:
98125 return -ENOPROTOOPT;
98126 @@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
98127 char __user *optval, int __user *optlen)
98128 {
98129 int len;
98130 + struct icmp6_filter filter;
98131
98132 switch (optname) {
98133 case ICMPV6_FILTER:
98134 @@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
98135 len = sizeof(struct icmp6_filter);
98136 if (put_user(len, optlen))
98137 return -EFAULT;
98138 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
98139 + filter = raw6_sk(sk)->filter;
98140 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
98141 return -EFAULT;
98142 return 0;
98143 default:
98144 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
98145 index cc85a9b..526a133 100644
98146 --- a/net/ipv6/reassembly.c
98147 +++ b/net/ipv6/reassembly.c
98148 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
98149
98150 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98151 {
98152 - struct ctl_table *table;
98153 + ctl_table_no_const *table = NULL;
98154 struct ctl_table_header *hdr;
98155
98156 - table = ip6_frags_ns_ctl_table;
98157 if (!net_eq(net, &init_net)) {
98158 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98159 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98160 if (table == NULL)
98161 goto err_alloc;
98162
98163 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98164 /* Don't export sysctls to unprivileged users */
98165 if (net->user_ns != &init_user_ns)
98166 table[0].procname = NULL;
98167 - }
98168 + hdr = register_net_sysctl(net, "net/ipv6", table);
98169 + } else
98170 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
98171
98172 - hdr = register_net_sysctl(net, "net/ipv6", table);
98173 if (hdr == NULL)
98174 goto err_reg;
98175
98176 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98177 return 0;
98178
98179 err_reg:
98180 - if (!net_eq(net, &init_net))
98181 - kfree(table);
98182 + kfree(table);
98183 err_alloc:
98184 return -ENOMEM;
98185 }
98186 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
98187 index 4b4944c..4580b91 100644
98188 --- a/net/ipv6/route.c
98189 +++ b/net/ipv6/route.c
98190 @@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
98191
98192 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
98193 {
98194 - struct ctl_table *table;
98195 + ctl_table_no_const *table;
98196
98197 table = kmemdup(ipv6_route_table_template,
98198 sizeof(ipv6_route_table_template),
98199 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
98200 index d3005b3..b36df4a 100644
98201 --- a/net/ipv6/sit.c
98202 +++ b/net/ipv6/sit.c
98203 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
98204 static void ipip6_dev_free(struct net_device *dev);
98205 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
98206 __be32 *v4dst);
98207 -static struct rtnl_link_ops sit_link_ops __read_mostly;
98208 +static struct rtnl_link_ops sit_link_ops;
98209
98210 static int sit_net_id __read_mostly;
98211 struct sit_net {
98212 @@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
98213 unregister_netdevice_queue(dev, head);
98214 }
98215
98216 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
98217 +static struct rtnl_link_ops sit_link_ops = {
98218 .kind = "sit",
98219 .maxtype = IFLA_IPTUN_MAX,
98220 .policy = ipip6_policy,
98221 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
98222 index 107b2f1..72741a9 100644
98223 --- a/net/ipv6/sysctl_net_ipv6.c
98224 +++ b/net/ipv6/sysctl_net_ipv6.c
98225 @@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
98226
98227 static int __net_init ipv6_sysctl_net_init(struct net *net)
98228 {
98229 - struct ctl_table *ipv6_table;
98230 + ctl_table_no_const *ipv6_table;
98231 struct ctl_table *ipv6_route_table;
98232 struct ctl_table *ipv6_icmp_table;
98233 int err;
98234 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
98235 index f67033b..6f974fc 100644
98236 --- a/net/ipv6/tcp_ipv6.c
98237 +++ b/net/ipv6/tcp_ipv6.c
98238 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
98239 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
98240 }
98241
98242 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98243 +extern int grsec_enable_blackhole;
98244 +#endif
98245 +
98246 static void tcp_v6_hash(struct sock *sk)
98247 {
98248 if (sk->sk_state != TCP_CLOSE) {
98249 @@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
98250 return 0;
98251
98252 reset:
98253 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98254 + if (!grsec_enable_blackhole)
98255 +#endif
98256 tcp_v6_send_reset(sk, skb);
98257 discard:
98258 if (opt_skb)
98259 @@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
98260 TCP_SKB_CB(skb)->sacked = 0;
98261
98262 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98263 - if (!sk)
98264 + if (!sk) {
98265 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98266 + ret = 1;
98267 +#endif
98268 goto no_tcp_socket;
98269 + }
98270
98271 process:
98272 - if (sk->sk_state == TCP_TIME_WAIT)
98273 + if (sk->sk_state == TCP_TIME_WAIT) {
98274 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98275 + ret = 2;
98276 +#endif
98277 goto do_time_wait;
98278 + }
98279
98280 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
98281 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98282 @@ -1536,6 +1551,10 @@ csum_error:
98283 bad_packet:
98284 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98285 } else {
98286 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98287 + if (!grsec_enable_blackhole || (ret == 1 &&
98288 + (skb->dev->flags & IFF_LOOPBACK)))
98289 +#endif
98290 tcp_v6_send_reset(NULL, skb);
98291 }
98292
98293 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
98294 index 089c741..cfee117 100644
98295 --- a/net/ipv6/udp.c
98296 +++ b/net/ipv6/udp.c
98297 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
98298 udp_ipv6_hash_secret + net_hash_mix(net));
98299 }
98300
98301 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98302 +extern int grsec_enable_blackhole;
98303 +#endif
98304 +
98305 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
98306 {
98307 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
98308 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98309 int is_udp4;
98310 bool slow;
98311
98312 + if (addr_len)
98313 + *addr_len = sizeof(struct sockaddr_in6);
98314 +
98315 if (flags & MSG_ERRQUEUE)
98316 return ipv6_recv_error(sk, msg, len, addr_len);
98317
98318 @@ -435,7 +442,7 @@ try_again:
98319 if (unlikely(err)) {
98320 trace_kfree_skb(skb, udpv6_recvmsg);
98321 if (!peeked) {
98322 - atomic_inc(&sk->sk_drops);
98323 + atomic_inc_unchecked(&sk->sk_drops);
98324 if (is_udp4)
98325 UDP_INC_STATS_USER(sock_net(sk),
98326 UDP_MIB_INERRORS,
98327 @@ -477,7 +484,7 @@ try_again:
98328 ipv6_iface_scope_id(&sin6->sin6_addr,
98329 IP6CB(skb)->iif);
98330 }
98331 - *addr_len = sizeof(*sin6);
98332 +
98333 }
98334 if (is_udp4) {
98335 if (inet->cmsg_flags)
98336 @@ -685,7 +692,7 @@ csum_error:
98337 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98338 drop:
98339 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98340 - atomic_inc(&sk->sk_drops);
98341 + atomic_inc_unchecked(&sk->sk_drops);
98342 kfree_skb(skb);
98343 return -1;
98344 }
98345 @@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98346 if (likely(skb1 == NULL))
98347 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98348 if (!skb1) {
98349 - atomic_inc(&sk->sk_drops);
98350 + atomic_inc_unchecked(&sk->sk_drops);
98351 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98352 IS_UDPLITE(sk));
98353 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98354 @@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98355 goto csum_error;
98356
98357 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98358 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98359 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98360 +#endif
98361 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
98362
98363 kfree_skb(skb);
98364 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
98365 index 5f8e128..865d38e 100644
98366 --- a/net/ipv6/xfrm6_policy.c
98367 +++ b/net/ipv6/xfrm6_policy.c
98368 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
98369 }
98370 }
98371
98372 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
98373 +static int xfrm6_garbage_collect(struct dst_ops *ops)
98374 {
98375 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
98376
98377 - xfrm6_policy_afinfo.garbage_collect(net);
98378 + xfrm_garbage_collect_deferred(net);
98379 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
98380 }
98381
98382 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
98383
98384 static int __net_init xfrm6_net_init(struct net *net)
98385 {
98386 - struct ctl_table *table;
98387 + ctl_table_no_const *table = NULL;
98388 struct ctl_table_header *hdr;
98389
98390 - table = xfrm6_policy_table;
98391 if (!net_eq(net, &init_net)) {
98392 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98393 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98394 if (!table)
98395 goto err_alloc;
98396
98397 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
98398 - }
98399 + hdr = register_net_sysctl(net, "net/ipv6", table);
98400 + } else
98401 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
98402
98403 - hdr = register_net_sysctl(net, "net/ipv6", table);
98404 if (!hdr)
98405 goto err_reg;
98406
98407 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
98408 return 0;
98409
98410 err_reg:
98411 - if (!net_eq(net, &init_net))
98412 - kfree(table);
98413 + kfree(table);
98414 err_alloc:
98415 return -ENOMEM;
98416 }
98417 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
98418 index 41ac7938..75e3bb1 100644
98419 --- a/net/irda/ircomm/ircomm_tty.c
98420 +++ b/net/irda/ircomm/ircomm_tty.c
98421 @@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98422 add_wait_queue(&port->open_wait, &wait);
98423
98424 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
98425 - __FILE__, __LINE__, tty->driver->name, port->count);
98426 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98427
98428 spin_lock_irqsave(&port->lock, flags);
98429 if (!tty_hung_up_p(filp))
98430 - port->count--;
98431 + atomic_dec(&port->count);
98432 port->blocked_open++;
98433 spin_unlock_irqrestore(&port->lock, flags);
98434
98435 @@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98436 }
98437
98438 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
98439 - __FILE__, __LINE__, tty->driver->name, port->count);
98440 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98441
98442 schedule();
98443 }
98444 @@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98445
98446 spin_lock_irqsave(&port->lock, flags);
98447 if (!tty_hung_up_p(filp))
98448 - port->count++;
98449 + atomic_inc(&port->count);
98450 port->blocked_open--;
98451 spin_unlock_irqrestore(&port->lock, flags);
98452
98453 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
98454 - __FILE__, __LINE__, tty->driver->name, port->count);
98455 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98456
98457 if (!retval)
98458 port->flags |= ASYNC_NORMAL_ACTIVE;
98459 @@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
98460
98461 /* ++ is not atomic, so this should be protected - Jean II */
98462 spin_lock_irqsave(&self->port.lock, flags);
98463 - self->port.count++;
98464 + atomic_inc(&self->port.count);
98465 spin_unlock_irqrestore(&self->port.lock, flags);
98466 tty_port_tty_set(&self->port, tty);
98467
98468 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
98469 - self->line, self->port.count);
98470 + self->line, atomic_read(&self->port.count));
98471
98472 /* Not really used by us, but lets do it anyway */
98473 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
98474 @@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
98475 tty_kref_put(port->tty);
98476 }
98477 port->tty = NULL;
98478 - port->count = 0;
98479 + atomic_set(&port->count, 0);
98480 spin_unlock_irqrestore(&port->lock, flags);
98481
98482 wake_up_interruptible(&port->open_wait);
98483 @@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
98484 seq_putc(m, '\n');
98485
98486 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
98487 - seq_printf(m, "Open count: %d\n", self->port.count);
98488 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
98489 seq_printf(m, "Max data size: %d\n", self->max_data_size);
98490 seq_printf(m, "Max header size: %d\n", self->max_header_size);
98491
98492 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
98493 index c4b7218..3e83259 100644
98494 --- a/net/iucv/af_iucv.c
98495 +++ b/net/iucv/af_iucv.c
98496 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
98497
98498 write_lock_bh(&iucv_sk_list.lock);
98499
98500 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
98501 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98502 while (__iucv_get_sock_by_name(name)) {
98503 sprintf(name, "%08x",
98504 - atomic_inc_return(&iucv_sk_list.autobind_name));
98505 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98506 }
98507
98508 write_unlock_bh(&iucv_sk_list.lock);
98509 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
98510 index cd5b8ec..f205e6b 100644
98511 --- a/net/iucv/iucv.c
98512 +++ b/net/iucv/iucv.c
98513 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
98514 return NOTIFY_OK;
98515 }
98516
98517 -static struct notifier_block __refdata iucv_cpu_notifier = {
98518 +static struct notifier_block iucv_cpu_notifier = {
98519 .notifier_call = iucv_cpu_notify,
98520 };
98521
98522 diff --git a/net/key/af_key.c b/net/key/af_key.c
98523 index 545f047..9757a9d 100644
98524 --- a/net/key/af_key.c
98525 +++ b/net/key/af_key.c
98526 @@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
98527 static u32 get_acqseq(void)
98528 {
98529 u32 res;
98530 - static atomic_t acqseq;
98531 + static atomic_unchecked_t acqseq;
98532
98533 do {
98534 - res = atomic_inc_return(&acqseq);
98535 + res = atomic_inc_return_unchecked(&acqseq);
98536 } while (!res);
98537 return res;
98538 }
98539 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
98540 index da1a1ce..571db8d 100644
98541 --- a/net/l2tp/l2tp_ip.c
98542 +++ b/net/l2tp/l2tp_ip.c
98543 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98544 if (flags & MSG_OOB)
98545 goto out;
98546
98547 + if (addr_len)
98548 + *addr_len = sizeof(*sin);
98549 +
98550 skb = skb_recv_datagram(sk, flags, noblock, &err);
98551 if (!skb)
98552 goto out;
98553 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98554 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98555 sin->sin_port = 0;
98556 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98557 - *addr_len = sizeof(*sin);
98558 }
98559 if (inet->cmsg_flags)
98560 ip_cmsg_recv(msg, skb);
98561 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
98562 index 364ce0c..3ebb5a4 100644
98563 --- a/net/mac80211/cfg.c
98564 +++ b/net/mac80211/cfg.c
98565 @@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
98566 ret = ieee80211_vif_use_channel(sdata, chandef,
98567 IEEE80211_CHANCTX_EXCLUSIVE);
98568 }
98569 - } else if (local->open_count == local->monitors) {
98570 + } else if (local_read(&local->open_count) == local->monitors) {
98571 local->_oper_chandef = *chandef;
98572 ieee80211_hw_config(local, 0);
98573 }
98574 @@ -3308,7 +3308,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
98575 else
98576 local->probe_req_reg--;
98577
98578 - if (!local->open_count)
98579 + if (!local_read(&local->open_count))
98580 break;
98581
98582 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
98583 @@ -3771,8 +3771,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
98584 if (chanctx_conf) {
98585 *chandef = chanctx_conf->def;
98586 ret = 0;
98587 - } else if (local->open_count > 0 &&
98588 - local->open_count == local->monitors &&
98589 + } else if (local_read(&local->open_count) > 0 &&
98590 + local_read(&local->open_count) == local->monitors &&
98591 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
98592 if (local->use_chanctx)
98593 *chandef = local->monitor_chandef;
98594 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
98595 index 4aea4e7..9e698d1 100644
98596 --- a/net/mac80211/ieee80211_i.h
98597 +++ b/net/mac80211/ieee80211_i.h
98598 @@ -28,6 +28,7 @@
98599 #include <net/ieee80211_radiotap.h>
98600 #include <net/cfg80211.h>
98601 #include <net/mac80211.h>
98602 +#include <asm/local.h>
98603 #include "key.h"
98604 #include "sta_info.h"
98605 #include "debug.h"
98606 @@ -961,7 +962,7 @@ struct ieee80211_local {
98607 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
98608 spinlock_t queue_stop_reason_lock;
98609
98610 - int open_count;
98611 + local_t open_count;
98612 int monitors, cooked_mntrs;
98613 /* number of interfaces with corresponding FIF_ flags */
98614 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
98615 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
98616 index a075791..1d0027f 100644
98617 --- a/net/mac80211/iface.c
98618 +++ b/net/mac80211/iface.c
98619 @@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98620 break;
98621 }
98622
98623 - if (local->open_count == 0) {
98624 + if (local_read(&local->open_count) == 0) {
98625 res = drv_start(local);
98626 if (res)
98627 goto err_del_bss;
98628 @@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98629 res = drv_add_interface(local, sdata);
98630 if (res)
98631 goto err_stop;
98632 - } else if (local->monitors == 0 && local->open_count == 0) {
98633 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
98634 res = ieee80211_add_virtual_monitor(local);
98635 if (res)
98636 goto err_stop;
98637 @@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98638 atomic_inc(&local->iff_promiscs);
98639
98640 if (coming_up)
98641 - local->open_count++;
98642 + local_inc(&local->open_count);
98643
98644 if (hw_reconf_flags)
98645 ieee80211_hw_config(local, hw_reconf_flags);
98646 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98647 err_del_interface:
98648 drv_remove_interface(local, sdata);
98649 err_stop:
98650 - if (!local->open_count)
98651 + if (!local_read(&local->open_count))
98652 drv_stop(local);
98653 err_del_bss:
98654 sdata->bss = NULL;
98655 @@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98656 }
98657
98658 if (going_down)
98659 - local->open_count--;
98660 + local_dec(&local->open_count);
98661
98662 switch (sdata->vif.type) {
98663 case NL80211_IFTYPE_AP_VLAN:
98664 @@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98665 }
98666 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
98667
98668 - if (local->open_count == 0)
98669 + if (local_read(&local->open_count) == 0)
98670 ieee80211_clear_tx_pending(local);
98671
98672 /*
98673 @@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98674
98675 ieee80211_recalc_ps(local, -1);
98676
98677 - if (local->open_count == 0) {
98678 + if (local_read(&local->open_count) == 0) {
98679 ieee80211_stop_device(local);
98680
98681 /* no reconfiguring after stop! */
98682 @@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98683 ieee80211_configure_filter(local);
98684 ieee80211_hw_config(local, hw_reconf_flags);
98685
98686 - if (local->monitors == local->open_count)
98687 + if (local->monitors == local_read(&local->open_count))
98688 ieee80211_add_virtual_monitor(local);
98689 }
98690
98691 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
98692 index 7d1c3ac..b62dd29 100644
98693 --- a/net/mac80211/main.c
98694 +++ b/net/mac80211/main.c
98695 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
98696 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
98697 IEEE80211_CONF_CHANGE_POWER);
98698
98699 - if (changed && local->open_count) {
98700 + if (changed && local_read(&local->open_count)) {
98701 ret = drv_config(local, changed);
98702 /*
98703 * Goal:
98704 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
98705 index 3401262..d5cd68d 100644
98706 --- a/net/mac80211/pm.c
98707 +++ b/net/mac80211/pm.c
98708 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98709 struct ieee80211_sub_if_data *sdata;
98710 struct sta_info *sta;
98711
98712 - if (!local->open_count)
98713 + if (!local_read(&local->open_count))
98714 goto suspend;
98715
98716 ieee80211_scan_cancel(local);
98717 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98718 cancel_work_sync(&local->dynamic_ps_enable_work);
98719 del_timer_sync(&local->dynamic_ps_timer);
98720
98721 - local->wowlan = wowlan && local->open_count;
98722 + local->wowlan = wowlan && local_read(&local->open_count);
98723 if (local->wowlan) {
98724 int err = drv_suspend(local, wowlan);
98725 if (err < 0) {
98726 @@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98727 WARN_ON(!list_empty(&local->chanctx_list));
98728
98729 /* stop hardware - this must stop RX */
98730 - if (local->open_count)
98731 + if (local_read(&local->open_count))
98732 ieee80211_stop_device(local);
98733
98734 suspend:
98735 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
98736 index 22b223f..ab70070 100644
98737 --- a/net/mac80211/rate.c
98738 +++ b/net/mac80211/rate.c
98739 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
98740
98741 ASSERT_RTNL();
98742
98743 - if (local->open_count)
98744 + if (local_read(&local->open_count))
98745 return -EBUSY;
98746
98747 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
98748 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
98749 index 6ff1346..936ca9a 100644
98750 --- a/net/mac80211/rc80211_pid_debugfs.c
98751 +++ b/net/mac80211/rc80211_pid_debugfs.c
98752 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
98753
98754 spin_unlock_irqrestore(&events->lock, status);
98755
98756 - if (copy_to_user(buf, pb, p))
98757 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
98758 return -EFAULT;
98759
98760 return p;
98761 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
98762 index 9f9b9bd..d6fcf59 100644
98763 --- a/net/mac80211/util.c
98764 +++ b/net/mac80211/util.c
98765 @@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98766 }
98767 #endif
98768 /* everything else happens only if HW was up & running */
98769 - if (!local->open_count)
98770 + if (!local_read(&local->open_count))
98771 goto wake_up;
98772
98773 /*
98774 @@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98775 local->in_reconfig = false;
98776 barrier();
98777
98778 - if (local->monitors == local->open_count && local->monitors > 0)
98779 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
98780 ieee80211_add_virtual_monitor(local);
98781
98782 /*
98783 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
98784 index c3398cd..98ad3b4 100644
98785 --- a/net/netfilter/Kconfig
98786 +++ b/net/netfilter/Kconfig
98787 @@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
98788
98789 To compile it as a module, choose M here. If unsure, say N.
98790
98791 +config NETFILTER_XT_MATCH_GRADM
98792 + tristate '"gradm" match support'
98793 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
98794 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
98795 + ---help---
98796 + The gradm match allows to match on grsecurity RBAC being enabled.
98797 + It is useful when iptables rules are applied early on bootup to
98798 + prevent connections to the machine (except from a trusted host)
98799 + while the RBAC system is disabled.
98800 +
98801 config NETFILTER_XT_MATCH_HASHLIMIT
98802 tristate '"hashlimit" match support'
98803 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
98804 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
98805 index 394483b..ed51f2d 100644
98806 --- a/net/netfilter/Makefile
98807 +++ b/net/netfilter/Makefile
98808 @@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
98809 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
98810 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
98811 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
98812 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
98813 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
98814 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
98815 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
98816 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
98817 index bac7e01..1d7a31a 100644
98818 --- a/net/netfilter/ipset/ip_set_core.c
98819 +++ b/net/netfilter/ipset/ip_set_core.c
98820 @@ -1950,7 +1950,7 @@ done:
98821 return ret;
98822 }
98823
98824 -static struct nf_sockopt_ops so_set __read_mostly = {
98825 +static struct nf_sockopt_ops so_set = {
98826 .pf = PF_INET,
98827 .get_optmin = SO_IP_SET,
98828 .get_optmax = SO_IP_SET + 1,
98829 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
98830 index 4c8e5c0..5a79b4d 100644
98831 --- a/net/netfilter/ipvs/ip_vs_conn.c
98832 +++ b/net/netfilter/ipvs/ip_vs_conn.c
98833 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
98834 /* Increase the refcnt counter of the dest */
98835 ip_vs_dest_hold(dest);
98836
98837 - conn_flags = atomic_read(&dest->conn_flags);
98838 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
98839 if (cp->protocol != IPPROTO_UDP)
98840 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
98841 flags = cp->flags;
98842 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
98843
98844 cp->control = NULL;
98845 atomic_set(&cp->n_control, 0);
98846 - atomic_set(&cp->in_pkts, 0);
98847 + atomic_set_unchecked(&cp->in_pkts, 0);
98848
98849 cp->packet_xmit = NULL;
98850 cp->app = NULL;
98851 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
98852
98853 /* Don't drop the entry if its number of incoming packets is not
98854 located in [0, 8] */
98855 - i = atomic_read(&cp->in_pkts);
98856 + i = atomic_read_unchecked(&cp->in_pkts);
98857 if (i > 8 || i < 0) return 0;
98858
98859 if (!todrop_rate[i]) return 0;
98860 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
98861 index 4f26ee4..6a9d7c3 100644
98862 --- a/net/netfilter/ipvs/ip_vs_core.c
98863 +++ b/net/netfilter/ipvs/ip_vs_core.c
98864 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
98865 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
98866 /* do not touch skb anymore */
98867
98868 - atomic_inc(&cp->in_pkts);
98869 + atomic_inc_unchecked(&cp->in_pkts);
98870 ip_vs_conn_put(cp);
98871 return ret;
98872 }
98873 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
98874 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
98875 pkts = sysctl_sync_threshold(ipvs);
98876 else
98877 - pkts = atomic_add_return(1, &cp->in_pkts);
98878 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98879
98880 if (ipvs->sync_state & IP_VS_STATE_MASTER)
98881 ip_vs_sync_conn(net, cp, pkts);
98882 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
98883 index 35be035..dad174b 100644
98884 --- a/net/netfilter/ipvs/ip_vs_ctl.c
98885 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
98886 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
98887 */
98888 ip_vs_rs_hash(ipvs, dest);
98889 }
98890 - atomic_set(&dest->conn_flags, conn_flags);
98891 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
98892
98893 /* bind the service */
98894 old_svc = rcu_dereference_protected(dest->svc, 1);
98895 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
98896 * align with netns init in ip_vs_control_net_init()
98897 */
98898
98899 -static struct ctl_table vs_vars[] = {
98900 +static ctl_table_no_const vs_vars[] __read_only = {
98901 {
98902 .procname = "amemthresh",
98903 .maxlen = sizeof(int),
98904 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98905 " %-7s %-6d %-10d %-10d\n",
98906 &dest->addr.in6,
98907 ntohs(dest->port),
98908 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98909 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98910 atomic_read(&dest->weight),
98911 atomic_read(&dest->activeconns),
98912 atomic_read(&dest->inactconns));
98913 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98914 "%-7s %-6d %-10d %-10d\n",
98915 ntohl(dest->addr.ip),
98916 ntohs(dest->port),
98917 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98918 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98919 atomic_read(&dest->weight),
98920 atomic_read(&dest->activeconns),
98921 atomic_read(&dest->inactconns));
98922 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
98923
98924 entry.addr = dest->addr.ip;
98925 entry.port = dest->port;
98926 - entry.conn_flags = atomic_read(&dest->conn_flags);
98927 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
98928 entry.weight = atomic_read(&dest->weight);
98929 entry.u_threshold = dest->u_threshold;
98930 entry.l_threshold = dest->l_threshold;
98931 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
98932 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
98933 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
98934 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
98935 - (atomic_read(&dest->conn_flags) &
98936 + (atomic_read_unchecked(&dest->conn_flags) &
98937 IP_VS_CONN_F_FWD_MASK)) ||
98938 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
98939 atomic_read(&dest->weight)) ||
98940 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
98941 {
98942 int idx;
98943 struct netns_ipvs *ipvs = net_ipvs(net);
98944 - struct ctl_table *tbl;
98945 + ctl_table_no_const *tbl;
98946
98947 atomic_set(&ipvs->dropentry, 0);
98948 spin_lock_init(&ipvs->dropentry_lock);
98949 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
98950 index ca056a3..9cf01ef 100644
98951 --- a/net/netfilter/ipvs/ip_vs_lblc.c
98952 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
98953 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
98954 * IPVS LBLC sysctl table
98955 */
98956 #ifdef CONFIG_SYSCTL
98957 -static struct ctl_table vs_vars_table[] = {
98958 +static ctl_table_no_const vs_vars_table[] __read_only = {
98959 {
98960 .procname = "lblc_expiration",
98961 .data = NULL,
98962 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
98963 index 3f21a2f..a112e85 100644
98964 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
98965 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
98966 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
98967 * IPVS LBLCR sysctl table
98968 */
98969
98970 -static struct ctl_table vs_vars_table[] = {
98971 +static ctl_table_no_const vs_vars_table[] __read_only = {
98972 {
98973 .procname = "lblcr_expiration",
98974 .data = NULL,
98975 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
98976 index f63c238..1b87f8a 100644
98977 --- a/net/netfilter/ipvs/ip_vs_sync.c
98978 +++ b/net/netfilter/ipvs/ip_vs_sync.c
98979 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
98980 cp = cp->control;
98981 if (cp) {
98982 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98983 - pkts = atomic_add_return(1, &cp->in_pkts);
98984 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98985 else
98986 pkts = sysctl_sync_threshold(ipvs);
98987 ip_vs_sync_conn(net, cp->control, pkts);
98988 @@ -771,7 +771,7 @@ control:
98989 if (!cp)
98990 return;
98991 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98992 - pkts = atomic_add_return(1, &cp->in_pkts);
98993 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98994 else
98995 pkts = sysctl_sync_threshold(ipvs);
98996 goto sloop;
98997 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
98998
98999 if (opt)
99000 memcpy(&cp->in_seq, opt, sizeof(*opt));
99001 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
99002 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
99003 cp->state = state;
99004 cp->old_state = cp->state;
99005 /*
99006 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
99007 index c47444e..b0961c6 100644
99008 --- a/net/netfilter/ipvs/ip_vs_xmit.c
99009 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
99010 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
99011 else
99012 rc = NF_ACCEPT;
99013 /* do not touch skb anymore */
99014 - atomic_inc(&cp->in_pkts);
99015 + atomic_inc_unchecked(&cp->in_pkts);
99016 goto out;
99017 }
99018
99019 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
99020 else
99021 rc = NF_ACCEPT;
99022 /* do not touch skb anymore */
99023 - atomic_inc(&cp->in_pkts);
99024 + atomic_inc_unchecked(&cp->in_pkts);
99025 goto out;
99026 }
99027
99028 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
99029 index a4b5e2a..13b1de3 100644
99030 --- a/net/netfilter/nf_conntrack_acct.c
99031 +++ b/net/netfilter/nf_conntrack_acct.c
99032 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
99033 #ifdef CONFIG_SYSCTL
99034 static int nf_conntrack_acct_init_sysctl(struct net *net)
99035 {
99036 - struct ctl_table *table;
99037 + ctl_table_no_const *table;
99038
99039 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
99040 GFP_KERNEL);
99041 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
99042 index 43549eb..0bbeace 100644
99043 --- a/net/netfilter/nf_conntrack_core.c
99044 +++ b/net/netfilter/nf_conntrack_core.c
99045 @@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
99046 #define DYING_NULLS_VAL ((1<<30)+1)
99047 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
99048
99049 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99050 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
99051 +#endif
99052 +
99053 int nf_conntrack_init_net(struct net *net)
99054 {
99055 int ret;
99056 @@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
99057 goto err_stat;
99058 }
99059
99060 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99061 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
99062 +#else
99063 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
99064 +#endif
99065 if (!net->ct.slabname) {
99066 ret = -ENOMEM;
99067 goto err_slabname;
99068 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
99069 index 1df1761..ce8b88a 100644
99070 --- a/net/netfilter/nf_conntrack_ecache.c
99071 +++ b/net/netfilter/nf_conntrack_ecache.c
99072 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
99073 #ifdef CONFIG_SYSCTL
99074 static int nf_conntrack_event_init_sysctl(struct net *net)
99075 {
99076 - struct ctl_table *table;
99077 + ctl_table_no_const *table;
99078
99079 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
99080 GFP_KERNEL);
99081 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
99082 index 974a2a4..52cc6ff 100644
99083 --- a/net/netfilter/nf_conntrack_helper.c
99084 +++ b/net/netfilter/nf_conntrack_helper.c
99085 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
99086
99087 static int nf_conntrack_helper_init_sysctl(struct net *net)
99088 {
99089 - struct ctl_table *table;
99090 + ctl_table_no_const *table;
99091
99092 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
99093 GFP_KERNEL);
99094 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
99095 index ce30041..3861b5d 100644
99096 --- a/net/netfilter/nf_conntrack_proto.c
99097 +++ b/net/netfilter/nf_conntrack_proto.c
99098 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
99099
99100 static void
99101 nf_ct_unregister_sysctl(struct ctl_table_header **header,
99102 - struct ctl_table **table,
99103 + ctl_table_no_const **table,
99104 unsigned int users)
99105 {
99106 if (users > 0)
99107 diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
99108 index a99b6c3..cb372f9 100644
99109 --- a/net/netfilter/nf_conntrack_proto_dccp.c
99110 +++ b/net/netfilter/nf_conntrack_proto_dccp.c
99111 @@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
99112 const char *msg;
99113 u_int8_t state;
99114
99115 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99116 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99117 BUG_ON(dh == NULL);
99118
99119 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
99120 @@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
99121 out_invalid:
99122 if (LOG_INVALID(net, IPPROTO_DCCP))
99123 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
99124 - NULL, msg);
99125 + NULL, "%s", msg);
99126 return false;
99127 }
99128
99129 @@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
99130 u_int8_t type, old_state, new_state;
99131 enum ct_dccp_roles role;
99132
99133 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99134 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99135 BUG_ON(dh == NULL);
99136 type = dh->dccph_type;
99137
99138 @@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
99139 unsigned int cscov;
99140 const char *msg;
99141
99142 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99143 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99144 if (dh == NULL) {
99145 msg = "nf_ct_dccp: short packet ";
99146 goto out_invalid;
99147 @@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
99148
99149 out_invalid:
99150 if (LOG_INVALID(net, IPPROTO_DCCP))
99151 - nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
99152 + nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
99153 return -NF_ACCEPT;
99154 }
99155
99156 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
99157 index f641751..d3c5b51 100644
99158 --- a/net/netfilter/nf_conntrack_standalone.c
99159 +++ b/net/netfilter/nf_conntrack_standalone.c
99160 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
99161
99162 static int nf_conntrack_standalone_init_sysctl(struct net *net)
99163 {
99164 - struct ctl_table *table;
99165 + ctl_table_no_const *table;
99166
99167 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
99168 GFP_KERNEL);
99169 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
99170 index 7a394df..bd91a8a 100644
99171 --- a/net/netfilter/nf_conntrack_timestamp.c
99172 +++ b/net/netfilter/nf_conntrack_timestamp.c
99173 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
99174 #ifdef CONFIG_SYSCTL
99175 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
99176 {
99177 - struct ctl_table *table;
99178 + ctl_table_no_const *table;
99179
99180 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
99181 GFP_KERNEL);
99182 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
99183 index 85296d4..8becdec 100644
99184 --- a/net/netfilter/nf_log.c
99185 +++ b/net/netfilter/nf_log.c
99186 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
99187
99188 #ifdef CONFIG_SYSCTL
99189 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
99190 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
99191 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
99192
99193 static int nf_log_proc_dostring(struct ctl_table *table, int write,
99194 void __user *buffer, size_t *lenp, loff_t *ppos)
99195 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
99196 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
99197 mutex_unlock(&nf_log_mutex);
99198 } else {
99199 + ctl_table_no_const nf_log_table = *table;
99200 +
99201 mutex_lock(&nf_log_mutex);
99202 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
99203 lockdep_is_held(&nf_log_mutex));
99204 if (!logger)
99205 - table->data = "NONE";
99206 + nf_log_table.data = "NONE";
99207 else
99208 - table->data = logger->name;
99209 - r = proc_dostring(table, write, buffer, lenp, ppos);
99210 + nf_log_table.data = logger->name;
99211 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
99212 mutex_unlock(&nf_log_mutex);
99213 }
99214
99215 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
99216 index f042ae5..30ea486 100644
99217 --- a/net/netfilter/nf_sockopt.c
99218 +++ b/net/netfilter/nf_sockopt.c
99219 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
99220 }
99221 }
99222
99223 - list_add(&reg->list, &nf_sockopts);
99224 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
99225 out:
99226 mutex_unlock(&nf_sockopt_mutex);
99227 return ret;
99228 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
99229 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
99230 {
99231 mutex_lock(&nf_sockopt_mutex);
99232 - list_del(&reg->list);
99233 + pax_list_del((struct list_head *)&reg->list);
99234 mutex_unlock(&nf_sockopt_mutex);
99235 }
99236 EXPORT_SYMBOL(nf_unregister_sockopt);
99237 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
99238 index a155d19..726b0f2 100644
99239 --- a/net/netfilter/nfnetlink_log.c
99240 +++ b/net/netfilter/nfnetlink_log.c
99241 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
99242 struct nfnl_log_net {
99243 spinlock_t instances_lock;
99244 struct hlist_head instance_table[INSTANCE_BUCKETS];
99245 - atomic_t global_seq;
99246 + atomic_unchecked_t global_seq;
99247 };
99248
99249 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
99250 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
99251 /* global sequence number */
99252 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
99253 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
99254 - htonl(atomic_inc_return(&log->global_seq))))
99255 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
99256 goto nla_put_failure;
99257
99258 if (data_len) {
99259 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
99260 index da0c1f4..f79737a 100644
99261 --- a/net/netfilter/nft_compat.c
99262 +++ b/net/netfilter/nft_compat.c
99263 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
99264 /* We want to reuse existing compat_to_user */
99265 old_fs = get_fs();
99266 set_fs(KERNEL_DS);
99267 - t->compat_to_user(out, in);
99268 + t->compat_to_user((void __force_user *)out, in);
99269 set_fs(old_fs);
99270 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
99271 kfree(out);
99272 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
99273 /* We want to reuse existing compat_to_user */
99274 old_fs = get_fs();
99275 set_fs(KERNEL_DS);
99276 - m->compat_to_user(out, in);
99277 + m->compat_to_user((void __force_user *)out, in);
99278 set_fs(old_fs);
99279 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
99280 kfree(out);
99281 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
99282 new file mode 100644
99283 index 0000000..c566332
99284 --- /dev/null
99285 +++ b/net/netfilter/xt_gradm.c
99286 @@ -0,0 +1,51 @@
99287 +/*
99288 + * gradm match for netfilter
99289 + * Copyright © Zbigniew Krzystolik, 2010
99290 + *
99291 + * This program is free software; you can redistribute it and/or modify
99292 + * it under the terms of the GNU General Public License; either version
99293 + * 2 or 3 as published by the Free Software Foundation.
99294 + */
99295 +#include <linux/module.h>
99296 +#include <linux/moduleparam.h>
99297 +#include <linux/skbuff.h>
99298 +#include <linux/netfilter/x_tables.h>
99299 +#include <linux/grsecurity.h>
99300 +#include <linux/netfilter/xt_gradm.h>
99301 +
99302 +static bool
99303 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
99304 +{
99305 + const struct xt_gradm_mtinfo *info = par->matchinfo;
99306 + bool retval = false;
99307 + if (gr_acl_is_enabled())
99308 + retval = true;
99309 + return retval ^ info->invflags;
99310 +}
99311 +
99312 +static struct xt_match gradm_mt_reg __read_mostly = {
99313 + .name = "gradm",
99314 + .revision = 0,
99315 + .family = NFPROTO_UNSPEC,
99316 + .match = gradm_mt,
99317 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
99318 + .me = THIS_MODULE,
99319 +};
99320 +
99321 +static int __init gradm_mt_init(void)
99322 +{
99323 + return xt_register_match(&gradm_mt_reg);
99324 +}
99325 +
99326 +static void __exit gradm_mt_exit(void)
99327 +{
99328 + xt_unregister_match(&gradm_mt_reg);
99329 +}
99330 +
99331 +module_init(gradm_mt_init);
99332 +module_exit(gradm_mt_exit);
99333 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
99334 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
99335 +MODULE_LICENSE("GPL");
99336 +MODULE_ALIAS("ipt_gradm");
99337 +MODULE_ALIAS("ip6t_gradm");
99338 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
99339 index 4fe4fb4..87a89e5 100644
99340 --- a/net/netfilter/xt_statistic.c
99341 +++ b/net/netfilter/xt_statistic.c
99342 @@ -19,7 +19,7 @@
99343 #include <linux/module.h>
99344
99345 struct xt_statistic_priv {
99346 - atomic_t count;
99347 + atomic_unchecked_t count;
99348 } ____cacheline_aligned_in_smp;
99349
99350 MODULE_LICENSE("GPL");
99351 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
99352 break;
99353 case XT_STATISTIC_MODE_NTH:
99354 do {
99355 - oval = atomic_read(&info->master->count);
99356 + oval = atomic_read_unchecked(&info->master->count);
99357 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
99358 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
99359 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
99360 if (nval == 0)
99361 ret = !ret;
99362 break;
99363 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
99364 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
99365 if (info->master == NULL)
99366 return -ENOMEM;
99367 - atomic_set(&info->master->count, info->u.nth.count);
99368 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
99369
99370 return 0;
99371 }
99372 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
99373 index bca50b9..8f8a85e 100644
99374 --- a/net/netlink/af_netlink.c
99375 +++ b/net/netlink/af_netlink.c
99376 @@ -249,7 +249,7 @@ static void netlink_overrun(struct sock *sk)
99377 sk->sk_error_report(sk);
99378 }
99379 }
99380 - atomic_inc(&sk->sk_drops);
99381 + atomic_inc_unchecked(&sk->sk_drops);
99382 }
99383
99384 static void netlink_rcv_wake(struct sock *sk)
99385 @@ -2940,7 +2940,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
99386 sk_wmem_alloc_get(s),
99387 nlk->cb_running,
99388 atomic_read(&s->sk_refcnt),
99389 - atomic_read(&s->sk_drops),
99390 + atomic_read_unchecked(&s->sk_drops),
99391 sock_i_ino(s)
99392 );
99393
99394 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
99395 index 53c19a3..b0ac04a 100644
99396 --- a/net/netrom/af_netrom.c
99397 +++ b/net/netrom/af_netrom.c
99398 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
99399 *uaddr_len = sizeof(struct full_sockaddr_ax25);
99400 } else {
99401 sax->fsa_ax25.sax25_family = AF_NETROM;
99402 - sax->fsa_ax25.sax25_ndigis = 0;
99403 sax->fsa_ax25.sax25_call = nr->source_addr;
99404 *uaddr_len = sizeof(struct sockaddr_ax25);
99405 }
99406 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
99407 index 88cfbc1..05d73f5 100644
99408 --- a/net/packet/af_packet.c
99409 +++ b/net/packet/af_packet.c
99410 @@ -1720,7 +1720,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
99411
99412 spin_lock(&sk->sk_receive_queue.lock);
99413 po->stats.stats1.tp_packets++;
99414 - skb->dropcount = atomic_read(&sk->sk_drops);
99415 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
99416 __skb_queue_tail(&sk->sk_receive_queue, skb);
99417 spin_unlock(&sk->sk_receive_queue.lock);
99418 sk->sk_data_ready(sk, skb->len);
99419 @@ -1729,7 +1729,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
99420 drop_n_acct:
99421 spin_lock(&sk->sk_receive_queue.lock);
99422 po->stats.stats1.tp_drops++;
99423 - atomic_inc(&sk->sk_drops);
99424 + atomic_inc_unchecked(&sk->sk_drops);
99425 spin_unlock(&sk->sk_receive_queue.lock);
99426
99427 drop_n_restore:
99428 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
99429 case PACKET_HDRLEN:
99430 if (len > sizeof(int))
99431 len = sizeof(int);
99432 - if (copy_from_user(&val, optval, len))
99433 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
99434 return -EFAULT;
99435 switch (val) {
99436 case TPACKET_V1:
99437 @@ -3318,7 +3318,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
99438 len = lv;
99439 if (put_user(len, optlen))
99440 return -EFAULT;
99441 - if (copy_to_user(optval, data, len))
99442 + if (len > sizeof(st) || copy_to_user(optval, data, len))
99443 return -EFAULT;
99444 return 0;
99445 }
99446 diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
99447 index 38946b2..12c30f3 100644
99448 --- a/net/phonet/datagram.c
99449 +++ b/net/phonet/datagram.c
99450 @@ -139,6 +139,9 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
99451 MSG_CMSG_COMPAT))
99452 goto out_nofree;
99453
99454 + if (addr_len)
99455 + *addr_len = sizeof(sa);
99456 +
99457 skb = skb_recv_datagram(sk, flags, noblock, &rval);
99458 if (skb == NULL)
99459 goto out_nofree;
99460 @@ -159,10 +162,8 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
99461
99462 rval = (flags & MSG_TRUNC) ? skb->len : copylen;
99463
99464 - if (msg->msg_name != NULL) {
99465 - memcpy(msg->msg_name, &sa, sizeof(sa));
99466 - *addr_len = sizeof(sa);
99467 - }
99468 + if (msg->msg_name != NULL)
99469 + memcpy(msg->msg_name, &sa, sizeof(struct sockaddr_pn));
99470
99471 out:
99472 skb_free_datagram(sk, skb);
99473 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
99474 index e774117..900b8b7 100644
99475 --- a/net/phonet/pep.c
99476 +++ b/net/phonet/pep.c
99477 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
99478
99479 case PNS_PEP_CTRL_REQ:
99480 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
99481 - atomic_inc(&sk->sk_drops);
99482 + atomic_inc_unchecked(&sk->sk_drops);
99483 break;
99484 }
99485 __skb_pull(skb, 4);
99486 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
99487 }
99488
99489 if (pn->rx_credits == 0) {
99490 - atomic_inc(&sk->sk_drops);
99491 + atomic_inc_unchecked(&sk->sk_drops);
99492 err = -ENOBUFS;
99493 break;
99494 }
99495 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
99496 }
99497
99498 if (pn->rx_credits == 0) {
99499 - atomic_inc(&sk->sk_drops);
99500 + atomic_inc_unchecked(&sk->sk_drops);
99501 err = NET_RX_DROP;
99502 break;
99503 }
99504 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
99505 index 008214a..bb68240 100644
99506 --- a/net/phonet/socket.c
99507 +++ b/net/phonet/socket.c
99508 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
99509 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
99510 sock_i_ino(sk),
99511 atomic_read(&sk->sk_refcnt), sk,
99512 - atomic_read(&sk->sk_drops));
99513 + atomic_read_unchecked(&sk->sk_drops));
99514 }
99515 seq_pad(seq, '\n');
99516 return 0;
99517 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
99518 index c02a8c4..3c5b600 100644
99519 --- a/net/phonet/sysctl.c
99520 +++ b/net/phonet/sysctl.c
99521 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
99522 {
99523 int ret;
99524 int range[2] = {local_port_range[0], local_port_range[1]};
99525 - struct ctl_table tmp = {
99526 + ctl_table_no_const tmp = {
99527 .data = &range,
99528 .maxlen = sizeof(range),
99529 .mode = table->mode,
99530 diff --git a/net/rds/cong.c b/net/rds/cong.c
99531 index e5b65ac..f3b6fb7 100644
99532 --- a/net/rds/cong.c
99533 +++ b/net/rds/cong.c
99534 @@ -78,7 +78,7 @@
99535 * finds that the saved generation number is smaller than the global generation
99536 * number, it wakes up the process.
99537 */
99538 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
99539 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
99540
99541 /*
99542 * Congestion monitoring
99543 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
99544 rdsdebug("waking map %p for %pI4\n",
99545 map, &map->m_addr);
99546 rds_stats_inc(s_cong_update_received);
99547 - atomic_inc(&rds_cong_generation);
99548 + atomic_inc_unchecked(&rds_cong_generation);
99549 if (waitqueue_active(&map->m_waitq))
99550 wake_up(&map->m_waitq);
99551 if (waitqueue_active(&rds_poll_waitq))
99552 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
99553
99554 int rds_cong_updated_since(unsigned long *recent)
99555 {
99556 - unsigned long gen = atomic_read(&rds_cong_generation);
99557 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
99558
99559 if (likely(*recent == gen))
99560 return 0;
99561 diff --git a/net/rds/ib.h b/net/rds/ib.h
99562 index 7280ab8..e04f4ea 100644
99563 --- a/net/rds/ib.h
99564 +++ b/net/rds/ib.h
99565 @@ -128,7 +128,7 @@ struct rds_ib_connection {
99566 /* sending acks */
99567 unsigned long i_ack_flags;
99568 #ifdef KERNEL_HAS_ATOMIC64
99569 - atomic64_t i_ack_next; /* next ACK to send */
99570 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
99571 #else
99572 spinlock_t i_ack_lock; /* protect i_ack_next */
99573 u64 i_ack_next; /* next ACK to send */
99574 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
99575 index 31b74f5..dc1fbfa 100644
99576 --- a/net/rds/ib_cm.c
99577 +++ b/net/rds/ib_cm.c
99578 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
99579 /* Clear the ACK state */
99580 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
99581 #ifdef KERNEL_HAS_ATOMIC64
99582 - atomic64_set(&ic->i_ack_next, 0);
99583 + atomic64_set_unchecked(&ic->i_ack_next, 0);
99584 #else
99585 ic->i_ack_next = 0;
99586 #endif
99587 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
99588 index b7ebe23..b6352f6 100644
99589 --- a/net/rds/ib_recv.c
99590 +++ b/net/rds/ib_recv.c
99591 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
99592 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
99593 int ack_required)
99594 {
99595 - atomic64_set(&ic->i_ack_next, seq);
99596 + atomic64_set_unchecked(&ic->i_ack_next, seq);
99597 if (ack_required) {
99598 smp_mb__before_clear_bit();
99599 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99600 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
99601 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99602 smp_mb__after_clear_bit();
99603
99604 - return atomic64_read(&ic->i_ack_next);
99605 + return atomic64_read_unchecked(&ic->i_ack_next);
99606 }
99607 #endif
99608
99609 diff --git a/net/rds/iw.h b/net/rds/iw.h
99610 index 04ce3b1..48119a6 100644
99611 --- a/net/rds/iw.h
99612 +++ b/net/rds/iw.h
99613 @@ -134,7 +134,7 @@ struct rds_iw_connection {
99614 /* sending acks */
99615 unsigned long i_ack_flags;
99616 #ifdef KERNEL_HAS_ATOMIC64
99617 - atomic64_t i_ack_next; /* next ACK to send */
99618 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
99619 #else
99620 spinlock_t i_ack_lock; /* protect i_ack_next */
99621 u64 i_ack_next; /* next ACK to send */
99622 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
99623 index a91e1db..cf3053f 100644
99624 --- a/net/rds/iw_cm.c
99625 +++ b/net/rds/iw_cm.c
99626 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
99627 /* Clear the ACK state */
99628 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
99629 #ifdef KERNEL_HAS_ATOMIC64
99630 - atomic64_set(&ic->i_ack_next, 0);
99631 + atomic64_set_unchecked(&ic->i_ack_next, 0);
99632 #else
99633 ic->i_ack_next = 0;
99634 #endif
99635 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
99636 index 4503335..db566b4 100644
99637 --- a/net/rds/iw_recv.c
99638 +++ b/net/rds/iw_recv.c
99639 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
99640 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
99641 int ack_required)
99642 {
99643 - atomic64_set(&ic->i_ack_next, seq);
99644 + atomic64_set_unchecked(&ic->i_ack_next, seq);
99645 if (ack_required) {
99646 smp_mb__before_clear_bit();
99647 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99648 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
99649 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99650 smp_mb__after_clear_bit();
99651
99652 - return atomic64_read(&ic->i_ack_next);
99653 + return atomic64_read_unchecked(&ic->i_ack_next);
99654 }
99655 #endif
99656
99657 diff --git a/net/rds/rds.h b/net/rds/rds.h
99658 index 48f8ffc..0ef3eec 100644
99659 --- a/net/rds/rds.h
99660 +++ b/net/rds/rds.h
99661 @@ -449,7 +449,7 @@ struct rds_transport {
99662 void (*sync_mr)(void *trans_private, int direction);
99663 void (*free_mr)(void *trans_private, int invalidate);
99664 void (*flush_mrs)(void);
99665 -};
99666 +} __do_const;
99667
99668 struct rds_sock {
99669 struct sock rs_sk;
99670 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
99671 index edac9ef..16bcb98 100644
99672 --- a/net/rds/tcp.c
99673 +++ b/net/rds/tcp.c
99674 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
99675 int val = 1;
99676
99677 set_fs(KERNEL_DS);
99678 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
99679 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
99680 sizeof(val));
99681 set_fs(oldfs);
99682 }
99683 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
99684 index 81cf5a4..b5826ff 100644
99685 --- a/net/rds/tcp_send.c
99686 +++ b/net/rds/tcp_send.c
99687 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
99688
99689 oldfs = get_fs();
99690 set_fs(KERNEL_DS);
99691 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
99692 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
99693 sizeof(val));
99694 set_fs(oldfs);
99695 }
99696 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
99697 index e61aa60..f07cc89 100644
99698 --- a/net/rxrpc/af_rxrpc.c
99699 +++ b/net/rxrpc/af_rxrpc.c
99700 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
99701 __be32 rxrpc_epoch;
99702
99703 /* current debugging ID */
99704 -atomic_t rxrpc_debug_id;
99705 +atomic_unchecked_t rxrpc_debug_id;
99706
99707 /* count of skbs currently in use */
99708 atomic_t rxrpc_n_skbs;
99709 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
99710 index e4d9cbc..b229649 100644
99711 --- a/net/rxrpc/ar-ack.c
99712 +++ b/net/rxrpc/ar-ack.c
99713 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
99714
99715 _enter("{%d,%d,%d,%d},",
99716 call->acks_hard, call->acks_unacked,
99717 - atomic_read(&call->sequence),
99718 + atomic_read_unchecked(&call->sequence),
99719 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
99720
99721 stop = 0;
99722 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
99723
99724 /* each Tx packet has a new serial number */
99725 sp->hdr.serial =
99726 - htonl(atomic_inc_return(&call->conn->serial));
99727 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
99728
99729 hdr = (struct rxrpc_header *) txb->head;
99730 hdr->serial = sp->hdr.serial;
99731 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
99732 */
99733 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
99734 {
99735 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
99736 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
99737 }
99738
99739 /*
99740 @@ -629,7 +629,7 @@ process_further:
99741
99742 latest = ntohl(sp->hdr.serial);
99743 hard = ntohl(ack.firstPacket);
99744 - tx = atomic_read(&call->sequence);
99745 + tx = atomic_read_unchecked(&call->sequence);
99746
99747 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
99748 latest,
99749 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
99750 goto maybe_reschedule;
99751
99752 send_ACK_with_skew:
99753 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
99754 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
99755 ntohl(ack.serial));
99756 send_ACK:
99757 mtu = call->conn->trans->peer->if_mtu;
99758 @@ -1173,7 +1173,7 @@ send_ACK:
99759 ackinfo.rxMTU = htonl(5692);
99760 ackinfo.jumbo_max = htonl(4);
99761
99762 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
99763 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
99764 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
99765 ntohl(hdr.serial),
99766 ntohs(ack.maxSkew),
99767 @@ -1191,7 +1191,7 @@ send_ACK:
99768 send_message:
99769 _debug("send message");
99770
99771 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
99772 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
99773 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
99774 send_message_2:
99775
99776 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
99777 index a3bbb36..3341fb9 100644
99778 --- a/net/rxrpc/ar-call.c
99779 +++ b/net/rxrpc/ar-call.c
99780 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
99781 spin_lock_init(&call->lock);
99782 rwlock_init(&call->state_lock);
99783 atomic_set(&call->usage, 1);
99784 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
99785 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99786 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
99787
99788 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
99789 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
99790 index 4106ca9..a338d7a 100644
99791 --- a/net/rxrpc/ar-connection.c
99792 +++ b/net/rxrpc/ar-connection.c
99793 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
99794 rwlock_init(&conn->lock);
99795 spin_lock_init(&conn->state_lock);
99796 atomic_set(&conn->usage, 1);
99797 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
99798 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99799 conn->avail_calls = RXRPC_MAXCALLS;
99800 conn->size_align = 4;
99801 conn->header_size = sizeof(struct rxrpc_header);
99802 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
99803 index e7ed43a..6afa140 100644
99804 --- a/net/rxrpc/ar-connevent.c
99805 +++ b/net/rxrpc/ar-connevent.c
99806 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
99807
99808 len = iov[0].iov_len + iov[1].iov_len;
99809
99810 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
99811 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99812 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
99813
99814 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
99815 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
99816 index 529572f..c758ca7 100644
99817 --- a/net/rxrpc/ar-input.c
99818 +++ b/net/rxrpc/ar-input.c
99819 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
99820 /* track the latest serial number on this connection for ACK packet
99821 * information */
99822 serial = ntohl(sp->hdr.serial);
99823 - hi_serial = atomic_read(&call->conn->hi_serial);
99824 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
99825 while (serial > hi_serial)
99826 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
99827 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
99828 serial);
99829
99830 /* request ACK generation for any ACK or DATA packet that requests
99831 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
99832 index 5f43675..ca07817 100644
99833 --- a/net/rxrpc/ar-internal.h
99834 +++ b/net/rxrpc/ar-internal.h
99835 @@ -272,8 +272,8 @@ struct rxrpc_connection {
99836 int error; /* error code for local abort */
99837 int debug_id; /* debug ID for printks */
99838 unsigned int call_counter; /* call ID counter */
99839 - atomic_t serial; /* packet serial number counter */
99840 - atomic_t hi_serial; /* highest serial number received */
99841 + atomic_unchecked_t serial; /* packet serial number counter */
99842 + atomic_unchecked_t hi_serial; /* highest serial number received */
99843 u8 avail_calls; /* number of calls available */
99844 u8 size_align; /* data size alignment (for security) */
99845 u8 header_size; /* rxrpc + security header size */
99846 @@ -346,7 +346,7 @@ struct rxrpc_call {
99847 spinlock_t lock;
99848 rwlock_t state_lock; /* lock for state transition */
99849 atomic_t usage;
99850 - atomic_t sequence; /* Tx data packet sequence counter */
99851 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
99852 u32 abort_code; /* local/remote abort code */
99853 enum { /* current state of call */
99854 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
99855 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
99856 */
99857 extern atomic_t rxrpc_n_skbs;
99858 extern __be32 rxrpc_epoch;
99859 -extern atomic_t rxrpc_debug_id;
99860 +extern atomic_unchecked_t rxrpc_debug_id;
99861 extern struct workqueue_struct *rxrpc_workqueue;
99862
99863 /*
99864 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
99865 index 87f7135..74d3703 100644
99866 --- a/net/rxrpc/ar-local.c
99867 +++ b/net/rxrpc/ar-local.c
99868 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
99869 spin_lock_init(&local->lock);
99870 rwlock_init(&local->services_lock);
99871 atomic_set(&local->usage, 1);
99872 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
99873 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99874 memcpy(&local->srx, srx, sizeof(*srx));
99875 }
99876
99877 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
99878 index e1ac183..b43e10e 100644
99879 --- a/net/rxrpc/ar-output.c
99880 +++ b/net/rxrpc/ar-output.c
99881 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
99882 sp->hdr.cid = call->cid;
99883 sp->hdr.callNumber = call->call_id;
99884 sp->hdr.seq =
99885 - htonl(atomic_inc_return(&call->sequence));
99886 + htonl(atomic_inc_return_unchecked(&call->sequence));
99887 sp->hdr.serial =
99888 - htonl(atomic_inc_return(&conn->serial));
99889 + htonl(atomic_inc_return_unchecked(&conn->serial));
99890 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
99891 sp->hdr.userStatus = 0;
99892 sp->hdr.securityIndex = conn->security_ix;
99893 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
99894 index bebaa43..2644591 100644
99895 --- a/net/rxrpc/ar-peer.c
99896 +++ b/net/rxrpc/ar-peer.c
99897 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
99898 INIT_LIST_HEAD(&peer->error_targets);
99899 spin_lock_init(&peer->lock);
99900 atomic_set(&peer->usage, 1);
99901 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
99902 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99903 memcpy(&peer->srx, srx, sizeof(*srx));
99904
99905 rxrpc_assess_MTU_size(peer);
99906 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
99907 index 38047f7..9f48511 100644
99908 --- a/net/rxrpc/ar-proc.c
99909 +++ b/net/rxrpc/ar-proc.c
99910 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
99911 atomic_read(&conn->usage),
99912 rxrpc_conn_states[conn->state],
99913 key_serial(conn->key),
99914 - atomic_read(&conn->serial),
99915 - atomic_read(&conn->hi_serial));
99916 + atomic_read_unchecked(&conn->serial),
99917 + atomic_read_unchecked(&conn->hi_serial));
99918
99919 return 0;
99920 }
99921 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
99922 index 92df566..87ec1bf 100644
99923 --- a/net/rxrpc/ar-transport.c
99924 +++ b/net/rxrpc/ar-transport.c
99925 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
99926 spin_lock_init(&trans->client_lock);
99927 rwlock_init(&trans->conn_lock);
99928 atomic_set(&trans->usage, 1);
99929 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
99930 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99931
99932 if (peer->srx.transport.family == AF_INET) {
99933 switch (peer->srx.transport_type) {
99934 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
99935 index f226709..0e735a8 100644
99936 --- a/net/rxrpc/rxkad.c
99937 +++ b/net/rxrpc/rxkad.c
99938 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
99939
99940 len = iov[0].iov_len + iov[1].iov_len;
99941
99942 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
99943 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99944 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
99945
99946 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
99947 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
99948
99949 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
99950
99951 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
99952 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99953 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
99954
99955 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
99956 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
99957 index 7567e6f..299382b 100644
99958 --- a/net/sctp/ipv6.c
99959 +++ b/net/sctp/ipv6.c
99960 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
99961 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
99962 };
99963
99964 -static struct sctp_af sctp_af_inet6 = {
99965 +static struct sctp_af sctp_af_inet6 __read_only = {
99966 .sa_family = AF_INET6,
99967 .sctp_xmit = sctp_v6_xmit,
99968 .setsockopt = ipv6_setsockopt,
99969 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
99970 #endif
99971 };
99972
99973 -static struct sctp_pf sctp_pf_inet6 = {
99974 +static struct sctp_pf sctp_pf_inet6 __read_only = {
99975 .event_msgname = sctp_inet6_event_msgname,
99976 .skb_msgname = sctp_inet6_skb_msgname,
99977 .af_supported = sctp_inet6_af_supported,
99978 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
99979
99980 void sctp_v6_pf_exit(void)
99981 {
99982 - list_del(&sctp_af_inet6.list);
99983 + pax_list_del(&sctp_af_inet6.list);
99984 }
99985
99986 /* Initialize IPv6 support and register with socket layer. */
99987 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
99988 index 5e17092..19be1d4 100644
99989 --- a/net/sctp/protocol.c
99990 +++ b/net/sctp/protocol.c
99991 @@ -832,8 +832,10 @@ int sctp_register_af(struct sctp_af *af)
99992 return 0;
99993 }
99994
99995 + pax_open_kernel();
99996 INIT_LIST_HEAD(&af->list);
99997 - list_add_tail(&af->list, &sctp_address_families);
99998 + pax_close_kernel();
99999 + pax_list_add_tail(&af->list, &sctp_address_families);
100000 return 1;
100001 }
100002
100003 @@ -963,7 +965,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
100004
100005 static struct sctp_af sctp_af_inet;
100006
100007 -static struct sctp_pf sctp_pf_inet = {
100008 +static struct sctp_pf sctp_pf_inet __read_only = {
100009 .event_msgname = sctp_inet_event_msgname,
100010 .skb_msgname = sctp_inet_skb_msgname,
100011 .af_supported = sctp_inet_af_supported,
100012 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
100013 };
100014
100015 /* IPv4 address related functions. */
100016 -static struct sctp_af sctp_af_inet = {
100017 +static struct sctp_af sctp_af_inet __read_only = {
100018 .sa_family = AF_INET,
100019 .sctp_xmit = sctp_v4_xmit,
100020 .setsockopt = ip_setsockopt,
100021 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
100022
100023 static void sctp_v4_pf_exit(void)
100024 {
100025 - list_del(&sctp_af_inet.list);
100026 + pax_list_del(&sctp_af_inet.list);
100027 }
100028
100029 static int sctp_v4_protosw_init(void)
100030 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
100031 index 1a6eef3..17e898f 100644
100032 --- a/net/sctp/sm_sideeffect.c
100033 +++ b/net/sctp/sm_sideeffect.c
100034 @@ -440,7 +440,7 @@ static void sctp_generate_sack_event(unsigned long data)
100035 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
100036 }
100037
100038 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
100039 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
100040 NULL,
100041 sctp_generate_t1_cookie_event,
100042 sctp_generate_t1_init_event,
100043 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
100044 index 42b709c..e7d09ac 100644
100045 --- a/net/sctp/socket.c
100046 +++ b/net/sctp/socket.c
100047 @@ -2153,11 +2153,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
100048 {
100049 struct sctp_association *asoc;
100050 struct sctp_ulpevent *event;
100051 + struct sctp_event_subscribe subscribe;
100052
100053 if (optlen > sizeof(struct sctp_event_subscribe))
100054 return -EINVAL;
100055 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
100056 + if (copy_from_user(&subscribe, optval, optlen))
100057 return -EFAULT;
100058 + sctp_sk(sk)->subscribe = subscribe;
100059
100060 /*
100061 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
100062 @@ -4229,13 +4231,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
100063 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
100064 int __user *optlen)
100065 {
100066 + struct sctp_event_subscribe subscribe;
100067 +
100068 if (len <= 0)
100069 return -EINVAL;
100070 if (len > sizeof(struct sctp_event_subscribe))
100071 len = sizeof(struct sctp_event_subscribe);
100072 if (put_user(len, optlen))
100073 return -EFAULT;
100074 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
100075 + subscribe = sctp_sk(sk)->subscribe;
100076 + if (copy_to_user(optval, &subscribe, len))
100077 return -EFAULT;
100078 return 0;
100079 }
100080 @@ -4253,6 +4258,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
100081 */
100082 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
100083 {
100084 + __u32 autoclose;
100085 +
100086 /* Applicable to UDP-style socket only */
100087 if (sctp_style(sk, TCP))
100088 return -EOPNOTSUPP;
100089 @@ -4261,7 +4268,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
100090 len = sizeof(int);
100091 if (put_user(len, optlen))
100092 return -EFAULT;
100093 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
100094 + autoclose = sctp_sk(sk)->autoclose;
100095 + if (copy_to_user(optval, &autoclose, sizeof(int)))
100096 return -EFAULT;
100097 return 0;
100098 }
100099 @@ -4633,12 +4641,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
100100 */
100101 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
100102 {
100103 + struct sctp_initmsg initmsg;
100104 +
100105 if (len < sizeof(struct sctp_initmsg))
100106 return -EINVAL;
100107 len = sizeof(struct sctp_initmsg);
100108 if (put_user(len, optlen))
100109 return -EFAULT;
100110 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
100111 + initmsg = sctp_sk(sk)->initmsg;
100112 + if (copy_to_user(optval, &initmsg, len))
100113 return -EFAULT;
100114 return 0;
100115 }
100116 @@ -4679,6 +4690,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
100117 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
100118 if (space_left < addrlen)
100119 return -ENOMEM;
100120 + if (addrlen > sizeof(temp) || addrlen < 0)
100121 + return -EFAULT;
100122 if (copy_to_user(to, &temp, addrlen))
100123 return -EFAULT;
100124 to += addrlen;
100125 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
100126 index b0565af..d135e6e 100644
100127 --- a/net/sctp/sysctl.c
100128 +++ b/net/sctp/sysctl.c
100129 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
100130 {
100131 struct net *net = current->nsproxy->net_ns;
100132 char tmp[8];
100133 - struct ctl_table tbl;
100134 + ctl_table_no_const tbl;
100135 int ret;
100136 int changed = 0;
100137 char *none = "none";
100138 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
100139 {
100140 struct net *net = current->nsproxy->net_ns;
100141 int new_value;
100142 - struct ctl_table tbl;
100143 + ctl_table_no_const tbl;
100144 unsigned int min = *(unsigned int *) ctl->extra1;
100145 unsigned int max = *(unsigned int *) ctl->extra2;
100146 int ret;
100147 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
100148 {
100149 struct net *net = current->nsproxy->net_ns;
100150 int new_value;
100151 - struct ctl_table tbl;
100152 + ctl_table_no_const tbl;
100153 unsigned int min = *(unsigned int *) ctl->extra1;
100154 unsigned int max = *(unsigned int *) ctl->extra2;
100155 int ret;
100156 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
100157
100158 int sctp_sysctl_net_register(struct net *net)
100159 {
100160 - struct ctl_table *table;
100161 + ctl_table_no_const *table;
100162 int i;
100163
100164 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
100165 diff --git a/net/socket.c b/net/socket.c
100166 index e83c416..1094d88 100644
100167 --- a/net/socket.c
100168 +++ b/net/socket.c
100169 @@ -88,6 +88,7 @@
100170 #include <linux/magic.h>
100171 #include <linux/slab.h>
100172 #include <linux/xattr.h>
100173 +#include <linux/in.h>
100174
100175 #include <asm/uaccess.h>
100176 #include <asm/unistd.h>
100177 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
100178 unsigned int sysctl_net_busy_poll __read_mostly;
100179 #endif
100180
100181 +#include <linux/grsock.h>
100182 +
100183 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
100184 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
100185 unsigned long nr_segs, loff_t pos);
100186 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
100187 */
100188
100189 static DEFINE_SPINLOCK(net_family_lock);
100190 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
100191 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
100192
100193 /*
100194 * Statistics counters of the socket lists
100195 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
100196 &sockfs_dentry_operations, SOCKFS_MAGIC);
100197 }
100198
100199 -static struct vfsmount *sock_mnt __read_mostly;
100200 +struct vfsmount *sock_mnt __read_mostly;
100201
100202 static struct file_system_type sock_fs_type = {
100203 .name = "sockfs",
100204 @@ -1255,6 +1258,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
100205 return -EAFNOSUPPORT;
100206 if (type < 0 || type >= SOCK_MAX)
100207 return -EINVAL;
100208 + if (protocol < 0)
100209 + return -EINVAL;
100210
100211 /* Compatibility.
100212
100213 @@ -1275,6 +1280,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
100214 if (err)
100215 return err;
100216
100217 + if(!kern && !gr_search_socket(family, type, protocol)) {
100218 + if (rcu_access_pointer(net_families[family]) == NULL)
100219 + return -EAFNOSUPPORT;
100220 + else
100221 + return -EACCES;
100222 + }
100223 +
100224 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
100225 + if (rcu_access_pointer(net_families[family]) == NULL)
100226 + return -EAFNOSUPPORT;
100227 + else
100228 + return -EACCES;
100229 + }
100230 +
100231 /*
100232 * Allocate the socket and allow the family to set things up. if
100233 * the protocol is 0, the family is instructed to select an appropriate
100234 @@ -1513,6 +1532,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
100235 if (sock) {
100236 err = move_addr_to_kernel(umyaddr, addrlen, &address);
100237 if (err >= 0) {
100238 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
100239 + err = -EACCES;
100240 + goto error;
100241 + }
100242 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
100243 + if (err)
100244 + goto error;
100245 +
100246 err = security_socket_bind(sock,
100247 (struct sockaddr *)&address,
100248 addrlen);
100249 @@ -1521,6 +1548,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
100250 (struct sockaddr *)
100251 &address, addrlen);
100252 }
100253 +error:
100254 fput_light(sock->file, fput_needed);
100255 }
100256 return err;
100257 @@ -1544,10 +1572,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
100258 if ((unsigned int)backlog > somaxconn)
100259 backlog = somaxconn;
100260
100261 + if (gr_handle_sock_server_other(sock->sk)) {
100262 + err = -EPERM;
100263 + goto error;
100264 + }
100265 +
100266 + err = gr_search_listen(sock);
100267 + if (err)
100268 + goto error;
100269 +
100270 err = security_socket_listen(sock, backlog);
100271 if (!err)
100272 err = sock->ops->listen(sock, backlog);
100273
100274 +error:
100275 fput_light(sock->file, fput_needed);
100276 }
100277 return err;
100278 @@ -1591,6 +1629,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
100279 newsock->type = sock->type;
100280 newsock->ops = sock->ops;
100281
100282 + if (gr_handle_sock_server_other(sock->sk)) {
100283 + err = -EPERM;
100284 + sock_release(newsock);
100285 + goto out_put;
100286 + }
100287 +
100288 + err = gr_search_accept(sock);
100289 + if (err) {
100290 + sock_release(newsock);
100291 + goto out_put;
100292 + }
100293 +
100294 /*
100295 * We don't need try_module_get here, as the listening socket (sock)
100296 * has the protocol module (sock->ops->owner) held.
100297 @@ -1636,6 +1686,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
100298 fd_install(newfd, newfile);
100299 err = newfd;
100300
100301 + gr_attach_curr_ip(newsock->sk);
100302 +
100303 out_put:
100304 fput_light(sock->file, fput_needed);
100305 out:
100306 @@ -1668,6 +1720,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
100307 int, addrlen)
100308 {
100309 struct socket *sock;
100310 + struct sockaddr *sck;
100311 struct sockaddr_storage address;
100312 int err, fput_needed;
100313
100314 @@ -1678,6 +1731,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
100315 if (err < 0)
100316 goto out_put;
100317
100318 + sck = (struct sockaddr *)&address;
100319 +
100320 + if (gr_handle_sock_client(sck)) {
100321 + err = -EACCES;
100322 + goto out_put;
100323 + }
100324 +
100325 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
100326 + if (err)
100327 + goto out_put;
100328 +
100329 err =
100330 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
100331 if (err)
100332 @@ -1759,6 +1823,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
100333 * the protocol.
100334 */
100335
100336 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
100337 +
100338 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
100339 unsigned int, flags, struct sockaddr __user *, addr,
100340 int, addr_len)
100341 @@ -2047,7 +2113,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
100342 * checking falls down on this.
100343 */
100344 if (copy_from_user(ctl_buf,
100345 - (void __user __force *)msg_sys->msg_control,
100346 + (void __force_user *)msg_sys->msg_control,
100347 ctl_len))
100348 goto out_freectl;
100349 msg_sys->msg_control = ctl_buf;
100350 @@ -2227,7 +2293,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
100351 /* Save the user-mode address (verify_iovec will change the
100352 * kernel msghdr to use the kernel address space)
100353 */
100354 - uaddr = (__force void __user *)msg_sys->msg_name;
100355 + uaddr = (void __force_user *)msg_sys->msg_name;
100356 uaddr_len = COMPAT_NAMELEN(msg);
100357 if (MSG_CMSG_COMPAT & flags)
100358 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
100359 @@ -2871,7 +2937,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
100360 ifr = compat_alloc_user_space(buf_size);
100361 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
100362
100363 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
100364 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
100365 return -EFAULT;
100366
100367 if (put_user(convert_in ? rxnfc : compat_ptr(data),
100368 @@ -2985,14 +3051,14 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
100369 old_fs = get_fs();
100370 set_fs(KERNEL_DS);
100371 err = dev_ioctl(net, cmd,
100372 - (struct ifreq __user __force *) &kifr);
100373 + (struct ifreq __force_user *) &kifr);
100374 set_fs(old_fs);
100375
100376 return err;
100377 case SIOCBONDSLAVEINFOQUERY:
100378 case SIOCBONDINFOQUERY:
100379 uifr = compat_alloc_user_space(sizeof(*uifr));
100380 - if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
100381 + if (copy_in_user(uifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
100382 return -EFAULT;
100383
100384 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
100385 @@ -3094,7 +3160,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
100386
100387 old_fs = get_fs();
100388 set_fs(KERNEL_DS);
100389 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
100390 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
100391 set_fs(old_fs);
100392
100393 if (cmd == SIOCGIFMAP && !err) {
100394 @@ -3199,7 +3265,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
100395 ret |= get_user(rtdev, &(ur4->rt_dev));
100396 if (rtdev) {
100397 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
100398 - r4.rt_dev = (char __user __force *)devname;
100399 + r4.rt_dev = (char __force_user *)devname;
100400 devname[15] = 0;
100401 } else
100402 r4.rt_dev = NULL;
100403 @@ -3425,8 +3491,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
100404 int __user *uoptlen;
100405 int err;
100406
100407 - uoptval = (char __user __force *) optval;
100408 - uoptlen = (int __user __force *) optlen;
100409 + uoptval = (char __force_user *) optval;
100410 + uoptlen = (int __force_user *) optlen;
100411
100412 set_fs(KERNEL_DS);
100413 if (level == SOL_SOCKET)
100414 @@ -3446,7 +3512,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
100415 char __user *uoptval;
100416 int err;
100417
100418 - uoptval = (char __user __force *) optval;
100419 + uoptval = (char __force_user *) optval;
100420
100421 set_fs(KERNEL_DS);
100422 if (level == SOL_SOCKET)
100423 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
100424 index 008cdad..6f17474 100644
100425 --- a/net/sunrpc/auth_gss/svcauth_gss.c
100426 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
100427 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
100428 uint64_t *handle)
100429 {
100430 struct rsc rsci, *rscp = NULL;
100431 - static atomic64_t ctxhctr;
100432 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
100433 long long ctxh;
100434 struct gss_api_mech *gm = NULL;
100435 time_t expiry;
100436 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
100437 status = -ENOMEM;
100438 /* the handle needs to be just a unique id,
100439 * use a static counter */
100440 - ctxh = atomic64_inc_return(&ctxhctr);
100441 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
100442
100443 /* make a copy for the caller */
100444 *handle = ctxh;
100445 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
100446 index f09b7db..393c39e 100644
100447 --- a/net/sunrpc/clnt.c
100448 +++ b/net/sunrpc/clnt.c
100449 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
100450 (RPC_IS_ASYNC(task) ? "async" : "sync"));
100451
100452 /* Increment call count */
100453 - task->tk_msg.rpc_proc->p_count++;
100454 + pax_open_kernel();
100455 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
100456 + pax_close_kernel();
100457 clnt->cl_stats->rpccnt++;
100458 task->tk_action = call_reserve;
100459 }
100460 @@ -1529,9 +1531,13 @@ call_refreshresult(struct rpc_task *task)
100461 task->tk_action = call_refresh;
100462 switch (status) {
100463 case 0:
100464 - if (rpcauth_uptodatecred(task))
100465 + if (rpcauth_uptodatecred(task)) {
100466 task->tk_action = call_allocate;
100467 - return;
100468 + return;
100469 + }
100470 + /* Use rate-limiting and a max number of retries if refresh
100471 + * had status 0 but failed to update the cred.
100472 + */
100473 case -ETIMEDOUT:
100474 rpc_delay(task, 3*HZ);
100475 case -EAGAIN:
100476 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
100477 index ff3cc4b..7612a9e 100644
100478 --- a/net/sunrpc/sched.c
100479 +++ b/net/sunrpc/sched.c
100480 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
100481 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
100482 static void rpc_task_set_debuginfo(struct rpc_task *task)
100483 {
100484 - static atomic_t rpc_pid;
100485 + static atomic_unchecked_t rpc_pid;
100486
100487 - task->tk_pid = atomic_inc_return(&rpc_pid);
100488 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
100489 }
100490 #else
100491 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
100492 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
100493 index e7fbe36..8052603 100644
100494 --- a/net/sunrpc/svc.c
100495 +++ b/net/sunrpc/svc.c
100496 @@ -1158,7 +1158,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
100497 svc_putnl(resv, RPC_SUCCESS);
100498
100499 /* Bump per-procedure stats counter */
100500 - procp->pc_count++;
100501 + pax_open_kernel();
100502 + (*(unsigned int *)&procp->pc_count)++;
100503 + pax_close_kernel();
100504
100505 /* Initialize storage for argp and resp */
100506 memset(rqstp->rq_argp, 0, procp->pc_argsize);
100507 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
100508 index 621ca7b..59421dd 100644
100509 --- a/net/sunrpc/svcauth_unix.c
100510 +++ b/net/sunrpc/svcauth_unix.c
100511 @@ -414,7 +414,7 @@ struct unix_gid {
100512 struct group_info *gi;
100513 };
100514
100515 -static int unix_gid_hash(kuid_t uid)
100516 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
100517 {
100518 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
100519 }
100520 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
100521 (*bpp)[-1] = '\n';
100522 }
100523
100524 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
100525 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
100526
100527 static int unix_gid_parse(struct cache_detail *cd,
100528 char *mesg, int mlen)
100529 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
100530 index c1b6270..05089c1 100644
100531 --- a/net/sunrpc/xprtrdma/svc_rdma.c
100532 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
100533 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
100534 static unsigned int min_max_inline = 4096;
100535 static unsigned int max_max_inline = 65536;
100536
100537 -atomic_t rdma_stat_recv;
100538 -atomic_t rdma_stat_read;
100539 -atomic_t rdma_stat_write;
100540 -atomic_t rdma_stat_sq_starve;
100541 -atomic_t rdma_stat_rq_starve;
100542 -atomic_t rdma_stat_rq_poll;
100543 -atomic_t rdma_stat_rq_prod;
100544 -atomic_t rdma_stat_sq_poll;
100545 -atomic_t rdma_stat_sq_prod;
100546 +atomic_unchecked_t rdma_stat_recv;
100547 +atomic_unchecked_t rdma_stat_read;
100548 +atomic_unchecked_t rdma_stat_write;
100549 +atomic_unchecked_t rdma_stat_sq_starve;
100550 +atomic_unchecked_t rdma_stat_rq_starve;
100551 +atomic_unchecked_t rdma_stat_rq_poll;
100552 +atomic_unchecked_t rdma_stat_rq_prod;
100553 +atomic_unchecked_t rdma_stat_sq_poll;
100554 +atomic_unchecked_t rdma_stat_sq_prod;
100555
100556 /* Temporary NFS request map and context caches */
100557 struct kmem_cache *svc_rdma_map_cachep;
100558 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
100559 len -= *ppos;
100560 if (len > *lenp)
100561 len = *lenp;
100562 - if (len && copy_to_user(buffer, str_buf, len))
100563 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
100564 return -EFAULT;
100565 *lenp = len;
100566 *ppos += len;
100567 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
100568 {
100569 .procname = "rdma_stat_read",
100570 .data = &rdma_stat_read,
100571 - .maxlen = sizeof(atomic_t),
100572 + .maxlen = sizeof(atomic_unchecked_t),
100573 .mode = 0644,
100574 .proc_handler = read_reset_stat,
100575 },
100576 {
100577 .procname = "rdma_stat_recv",
100578 .data = &rdma_stat_recv,
100579 - .maxlen = sizeof(atomic_t),
100580 + .maxlen = sizeof(atomic_unchecked_t),
100581 .mode = 0644,
100582 .proc_handler = read_reset_stat,
100583 },
100584 {
100585 .procname = "rdma_stat_write",
100586 .data = &rdma_stat_write,
100587 - .maxlen = sizeof(atomic_t),
100588 + .maxlen = sizeof(atomic_unchecked_t),
100589 .mode = 0644,
100590 .proc_handler = read_reset_stat,
100591 },
100592 {
100593 .procname = "rdma_stat_sq_starve",
100594 .data = &rdma_stat_sq_starve,
100595 - .maxlen = sizeof(atomic_t),
100596 + .maxlen = sizeof(atomic_unchecked_t),
100597 .mode = 0644,
100598 .proc_handler = read_reset_stat,
100599 },
100600 {
100601 .procname = "rdma_stat_rq_starve",
100602 .data = &rdma_stat_rq_starve,
100603 - .maxlen = sizeof(atomic_t),
100604 + .maxlen = sizeof(atomic_unchecked_t),
100605 .mode = 0644,
100606 .proc_handler = read_reset_stat,
100607 },
100608 {
100609 .procname = "rdma_stat_rq_poll",
100610 .data = &rdma_stat_rq_poll,
100611 - .maxlen = sizeof(atomic_t),
100612 + .maxlen = sizeof(atomic_unchecked_t),
100613 .mode = 0644,
100614 .proc_handler = read_reset_stat,
100615 },
100616 {
100617 .procname = "rdma_stat_rq_prod",
100618 .data = &rdma_stat_rq_prod,
100619 - .maxlen = sizeof(atomic_t),
100620 + .maxlen = sizeof(atomic_unchecked_t),
100621 .mode = 0644,
100622 .proc_handler = read_reset_stat,
100623 },
100624 {
100625 .procname = "rdma_stat_sq_poll",
100626 .data = &rdma_stat_sq_poll,
100627 - .maxlen = sizeof(atomic_t),
100628 + .maxlen = sizeof(atomic_unchecked_t),
100629 .mode = 0644,
100630 .proc_handler = read_reset_stat,
100631 },
100632 {
100633 .procname = "rdma_stat_sq_prod",
100634 .data = &rdma_stat_sq_prod,
100635 - .maxlen = sizeof(atomic_t),
100636 + .maxlen = sizeof(atomic_unchecked_t),
100637 .mode = 0644,
100638 .proc_handler = read_reset_stat,
100639 },
100640 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100641 index 0ce7552..d074459 100644
100642 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100643 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100644 @@ -501,7 +501,7 @@ next_sge:
100645 svc_rdma_put_context(ctxt, 0);
100646 goto out;
100647 }
100648 - atomic_inc(&rdma_stat_read);
100649 + atomic_inc_unchecked(&rdma_stat_read);
100650
100651 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
100652 chl_map->ch[ch_no].count -= read_wr.num_sge;
100653 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
100654 dto_q);
100655 list_del_init(&ctxt->dto_q);
100656 } else {
100657 - atomic_inc(&rdma_stat_rq_starve);
100658 + atomic_inc_unchecked(&rdma_stat_rq_starve);
100659 clear_bit(XPT_DATA, &xprt->xpt_flags);
100660 ctxt = NULL;
100661 }
100662 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
100663 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
100664 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
100665 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
100666 - atomic_inc(&rdma_stat_recv);
100667 + atomic_inc_unchecked(&rdma_stat_recv);
100668
100669 /* Build up the XDR from the receive buffers. */
100670 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
100671 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100672 index c1d124d..acfc59e 100644
100673 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100674 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100675 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
100676 write_wr.wr.rdma.remote_addr = to;
100677
100678 /* Post It */
100679 - atomic_inc(&rdma_stat_write);
100680 + atomic_inc_unchecked(&rdma_stat_write);
100681 if (svc_rdma_send(xprt, &write_wr))
100682 goto err;
100683 return 0;
100684 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
100685 index 62e4f9b..dd3f2d7 100644
100686 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
100687 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
100688 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
100689 return;
100690
100691 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
100692 - atomic_inc(&rdma_stat_rq_poll);
100693 + atomic_inc_unchecked(&rdma_stat_rq_poll);
100694
100695 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
100696 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
100697 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
100698 }
100699
100700 if (ctxt)
100701 - atomic_inc(&rdma_stat_rq_prod);
100702 + atomic_inc_unchecked(&rdma_stat_rq_prod);
100703
100704 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
100705 /*
100706 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
100707 return;
100708
100709 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
100710 - atomic_inc(&rdma_stat_sq_poll);
100711 + atomic_inc_unchecked(&rdma_stat_sq_poll);
100712 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
100713 if (wc.status != IB_WC_SUCCESS)
100714 /* Close the transport */
100715 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
100716 }
100717
100718 if (ctxt)
100719 - atomic_inc(&rdma_stat_sq_prod);
100720 + atomic_inc_unchecked(&rdma_stat_sq_prod);
100721 }
100722
100723 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
100724 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
100725 spin_lock_bh(&xprt->sc_lock);
100726 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
100727 spin_unlock_bh(&xprt->sc_lock);
100728 - atomic_inc(&rdma_stat_sq_starve);
100729 + atomic_inc_unchecked(&rdma_stat_sq_starve);
100730
100731 /* See if we can opportunistically reap SQ WR to make room */
100732 sq_cq_reap(xprt);
100733 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
100734 index e7000be..e3b0ba7 100644
100735 --- a/net/sysctl_net.c
100736 +++ b/net/sysctl_net.c
100737 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
100738 kgid_t root_gid = make_kgid(net->user_ns, 0);
100739
100740 /* Allow network administrator to have same access as root. */
100741 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
100742 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
100743 uid_eq(root_uid, current_euid())) {
100744 int mode = (table->mode >> 6) & 7;
100745 return (mode << 6) | (mode << 3) | mode;
100746 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
100747 index d38bb45..38d5df5 100644
100748 --- a/net/tipc/subscr.c
100749 +++ b/net/tipc/subscr.c
100750 @@ -98,7 +98,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
100751 struct kvec msg_sect;
100752 int ret;
100753
100754 - msg_sect.iov_base = (void *)&sub->evt;
100755 + msg_sect.iov_base = &sub->evt;
100756 msg_sect.iov_len = sizeof(struct tipc_event);
100757
100758 sub->evt.event = htohl(event, sub->swap);
100759 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
100760 index a427623..387c80b 100644
100761 --- a/net/unix/af_unix.c
100762 +++ b/net/unix/af_unix.c
100763 @@ -790,6 +790,12 @@ static struct sock *unix_find_other(struct net *net,
100764 err = -ECONNREFUSED;
100765 if (!S_ISSOCK(inode->i_mode))
100766 goto put_fail;
100767 +
100768 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
100769 + err = -EACCES;
100770 + goto put_fail;
100771 + }
100772 +
100773 u = unix_find_socket_byinode(inode);
100774 if (!u)
100775 goto put_fail;
100776 @@ -810,6 +816,13 @@ static struct sock *unix_find_other(struct net *net,
100777 if (u) {
100778 struct dentry *dentry;
100779 dentry = unix_sk(u)->path.dentry;
100780 +
100781 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
100782 + err = -EPERM;
100783 + sock_put(u);
100784 + goto fail;
100785 + }
100786 +
100787 if (dentry)
100788 touch_atime(&unix_sk(u)->path);
100789 } else
100790 @@ -843,12 +856,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
100791 */
100792 err = security_path_mknod(&path, dentry, mode, 0);
100793 if (!err) {
100794 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
100795 + err = -EACCES;
100796 + goto out;
100797 + }
100798 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
100799 if (!err) {
100800 res->mnt = mntget(path.mnt);
100801 res->dentry = dget(dentry);
100802 + gr_handle_create(dentry, path.mnt);
100803 }
100804 }
100805 +out:
100806 done_path_create(&path, dentry);
100807 return err;
100808 }
100809 @@ -2336,9 +2355,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
100810 seq_puts(seq, "Num RefCount Protocol Flags Type St "
100811 "Inode Path\n");
100812 else {
100813 - struct sock *s = v;
100814 + struct sock *s = v, *peer;
100815 struct unix_sock *u = unix_sk(s);
100816 unix_state_lock(s);
100817 + peer = unix_peer(s);
100818 + unix_state_unlock(s);
100819 +
100820 + unix_state_double_lock(s, peer);
100821
100822 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
100823 s,
100824 @@ -2365,8 +2388,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
100825 }
100826 for ( ; i < len; i++)
100827 seq_putc(seq, u->addr->name->sun_path[i]);
100828 - }
100829 - unix_state_unlock(s);
100830 + } else if (peer)
100831 + seq_printf(seq, " P%lu", sock_i_ino(peer));
100832 +
100833 + unix_state_double_unlock(s, peer);
100834 seq_putc(seq, '\n');
100835 }
100836
100837 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
100838 index b3d5150..ff3a837 100644
100839 --- a/net/unix/sysctl_net_unix.c
100840 +++ b/net/unix/sysctl_net_unix.c
100841 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
100842
100843 int __net_init unix_sysctl_register(struct net *net)
100844 {
100845 - struct ctl_table *table;
100846 + ctl_table_no_const *table;
100847
100848 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
100849 if (table == NULL)
100850 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
100851 index 9a73074..aecba9a 100644
100852 --- a/net/vmw_vsock/vmci_transport_notify.c
100853 +++ b/net/vmw_vsock/vmci_transport_notify.c
100854 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
100855
100856 /* Socket control packet based operations. */
100857 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
100858 - vmci_transport_notify_pkt_socket_init,
100859 - vmci_transport_notify_pkt_socket_destruct,
100860 - vmci_transport_notify_pkt_poll_in,
100861 - vmci_transport_notify_pkt_poll_out,
100862 - vmci_transport_notify_pkt_handle_pkt,
100863 - vmci_transport_notify_pkt_recv_init,
100864 - vmci_transport_notify_pkt_recv_pre_block,
100865 - vmci_transport_notify_pkt_recv_pre_dequeue,
100866 - vmci_transport_notify_pkt_recv_post_dequeue,
100867 - vmci_transport_notify_pkt_send_init,
100868 - vmci_transport_notify_pkt_send_pre_block,
100869 - vmci_transport_notify_pkt_send_pre_enqueue,
100870 - vmci_transport_notify_pkt_send_post_enqueue,
100871 - vmci_transport_notify_pkt_process_request,
100872 - vmci_transport_notify_pkt_process_negotiate,
100873 + .socket_init = vmci_transport_notify_pkt_socket_init,
100874 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
100875 + .poll_in = vmci_transport_notify_pkt_poll_in,
100876 + .poll_out = vmci_transport_notify_pkt_poll_out,
100877 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
100878 + .recv_init = vmci_transport_notify_pkt_recv_init,
100879 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
100880 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
100881 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
100882 + .send_init = vmci_transport_notify_pkt_send_init,
100883 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
100884 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
100885 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
100886 + .process_request = vmci_transport_notify_pkt_process_request,
100887 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
100888 };
100889 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
100890 index 622bd7a..b92086c 100644
100891 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
100892 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
100893 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
100894
100895 /* Socket always on control packet based operations. */
100896 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
100897 - vmci_transport_notify_pkt_socket_init,
100898 - vmci_transport_notify_pkt_socket_destruct,
100899 - vmci_transport_notify_pkt_poll_in,
100900 - vmci_transport_notify_pkt_poll_out,
100901 - vmci_transport_notify_pkt_handle_pkt,
100902 - vmci_transport_notify_pkt_recv_init,
100903 - vmci_transport_notify_pkt_recv_pre_block,
100904 - vmci_transport_notify_pkt_recv_pre_dequeue,
100905 - vmci_transport_notify_pkt_recv_post_dequeue,
100906 - vmci_transport_notify_pkt_send_init,
100907 - vmci_transport_notify_pkt_send_pre_block,
100908 - vmci_transport_notify_pkt_send_pre_enqueue,
100909 - vmci_transport_notify_pkt_send_post_enqueue,
100910 - vmci_transport_notify_pkt_process_request,
100911 - vmci_transport_notify_pkt_process_negotiate,
100912 + .socket_init = vmci_transport_notify_pkt_socket_init,
100913 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
100914 + .poll_in = vmci_transport_notify_pkt_poll_in,
100915 + .poll_out = vmci_transport_notify_pkt_poll_out,
100916 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
100917 + .recv_init = vmci_transport_notify_pkt_recv_init,
100918 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
100919 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
100920 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
100921 + .send_init = vmci_transport_notify_pkt_send_init,
100922 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
100923 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
100924 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
100925 + .process_request = vmci_transport_notify_pkt_process_request,
100926 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
100927 };
100928 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
100929 index c8717c1..08539f5 100644
100930 --- a/net/wireless/wext-core.c
100931 +++ b/net/wireless/wext-core.c
100932 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
100933 */
100934
100935 /* Support for very large requests */
100936 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
100937 - (user_length > descr->max_tokens)) {
100938 + if (user_length > descr->max_tokens) {
100939 /* Allow userspace to GET more than max so
100940 * we can support any size GET requests.
100941 * There is still a limit : -ENOMEM.
100942 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
100943 }
100944 }
100945
100946 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
100947 - /*
100948 - * If this is a GET, but not NOMAX, it means that the extra
100949 - * data is not bounded by userspace, but by max_tokens. Thus
100950 - * set the length to max_tokens. This matches the extra data
100951 - * allocation.
100952 - * The driver should fill it with the number of tokens it
100953 - * provided, and it may check iwp->length rather than having
100954 - * knowledge of max_tokens. If the driver doesn't change the
100955 - * iwp->length, this ioctl just copies back max_token tokens
100956 - * filled with zeroes. Hopefully the driver isn't claiming
100957 - * them to be valid data.
100958 - */
100959 - iwp->length = descr->max_tokens;
100960 - }
100961 -
100962 err = handler(dev, info, (union iwreq_data *) iwp, extra);
100963
100964 iwp->length += essid_compat;
100965 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
100966 index 4323952..a06dfe1 100644
100967 --- a/net/x25/sysctl_net_x25.c
100968 +++ b/net/x25/sysctl_net_x25.c
100969 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
100970 .mode = 0644,
100971 .proc_handler = proc_dointvec,
100972 },
100973 - { 0, },
100974 + { },
100975 };
100976
100977 void __init x25_register_sysctl(void)
100978 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
100979 index 9a91f74..502f6605 100644
100980 --- a/net/xfrm/xfrm_policy.c
100981 +++ b/net/xfrm/xfrm_policy.c
100982 @@ -332,7 +332,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
100983 {
100984 policy->walk.dead = 1;
100985
100986 - atomic_inc(&policy->genid);
100987 + atomic_inc_unchecked(&policy->genid);
100988
100989 if (del_timer(&policy->polq.hold_timer))
100990 xfrm_pol_put(policy);
100991 @@ -660,7 +660,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
100992 hlist_add_head(&policy->bydst, chain);
100993 xfrm_pol_hold(policy);
100994 net->xfrm.policy_count[dir]++;
100995 - atomic_inc(&flow_cache_genid);
100996 + atomic_inc_unchecked(&flow_cache_genid);
100997
100998 /* After previous checking, family can either be AF_INET or AF_INET6 */
100999 if (policy->family == AF_INET)
101000 @@ -1636,7 +1636,7 @@ free_dst:
101001 goto out;
101002 }
101003
101004 -static int inline
101005 +static inline int
101006 xfrm_dst_alloc_copy(void **target, const void *src, int size)
101007 {
101008 if (!*target) {
101009 @@ -1648,7 +1648,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
101010 return 0;
101011 }
101012
101013 -static int inline
101014 +static inline int
101015 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
101016 {
101017 #ifdef CONFIG_XFRM_SUB_POLICY
101018 @@ -1660,7 +1660,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
101019 #endif
101020 }
101021
101022 -static int inline
101023 +static inline int
101024 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
101025 {
101026 #ifdef CONFIG_XFRM_SUB_POLICY
101027 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
101028
101029 xdst->num_pols = num_pols;
101030 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
101031 - xdst->policy_genid = atomic_read(&pols[0]->genid);
101032 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
101033
101034 return xdst;
101035 }
101036 @@ -2582,11 +2582,12 @@ void xfrm_garbage_collect(struct net *net)
101037 }
101038 EXPORT_SYMBOL(xfrm_garbage_collect);
101039
101040 -static void xfrm_garbage_collect_deferred(struct net *net)
101041 +void xfrm_garbage_collect_deferred(struct net *net)
101042 {
101043 flow_cache_flush_deferred();
101044 __xfrm_garbage_collect(net);
101045 }
101046 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
101047
101048 static void xfrm_init_pmtu(struct dst_entry *dst)
101049 {
101050 @@ -2636,7 +2637,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
101051 if (xdst->xfrm_genid != dst->xfrm->genid)
101052 return 0;
101053 if (xdst->num_pols > 0 &&
101054 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
101055 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
101056 return 0;
101057
101058 mtu = dst_mtu(dst->child);
101059 @@ -2724,8 +2725,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
101060 dst_ops->link_failure = xfrm_link_failure;
101061 if (likely(dst_ops->neigh_lookup == NULL))
101062 dst_ops->neigh_lookup = xfrm_neigh_lookup;
101063 - if (likely(afinfo->garbage_collect == NULL))
101064 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
101065 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
101066 }
101067 spin_unlock(&xfrm_policy_afinfo_lock);
101068 @@ -2779,7 +2778,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
101069 dst_ops->check = NULL;
101070 dst_ops->negative_advice = NULL;
101071 dst_ops->link_failure = NULL;
101072 - afinfo->garbage_collect = NULL;
101073 }
101074 return err;
101075 }
101076 @@ -3162,7 +3160,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
101077 sizeof(pol->xfrm_vec[i].saddr));
101078 pol->xfrm_vec[i].encap_family = mp->new_family;
101079 /* flush bundles */
101080 - atomic_inc(&pol->genid);
101081 + atomic_inc_unchecked(&pol->genid);
101082 }
101083 }
101084
101085 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
101086 index 68c2f35..9eb05ca 100644
101087 --- a/net/xfrm/xfrm_state.c
101088 +++ b/net/xfrm/xfrm_state.c
101089 @@ -174,12 +174,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
101090
101091 if (unlikely(afinfo == NULL))
101092 return -EAFNOSUPPORT;
101093 - typemap = afinfo->type_map;
101094 + typemap = (const struct xfrm_type **)afinfo->type_map;
101095 spin_lock_bh(&xfrm_type_lock);
101096
101097 - if (likely(typemap[type->proto] == NULL))
101098 + if (likely(typemap[type->proto] == NULL)) {
101099 + pax_open_kernel();
101100 typemap[type->proto] = type;
101101 - else
101102 + pax_close_kernel();
101103 + } else
101104 err = -EEXIST;
101105 spin_unlock_bh(&xfrm_type_lock);
101106 xfrm_state_put_afinfo(afinfo);
101107 @@ -195,13 +197,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
101108
101109 if (unlikely(afinfo == NULL))
101110 return -EAFNOSUPPORT;
101111 - typemap = afinfo->type_map;
101112 + typemap = (const struct xfrm_type **)afinfo->type_map;
101113 spin_lock_bh(&xfrm_type_lock);
101114
101115 if (unlikely(typemap[type->proto] != type))
101116 err = -ENOENT;
101117 - else
101118 + else {
101119 + pax_open_kernel();
101120 typemap[type->proto] = NULL;
101121 + pax_close_kernel();
101122 + }
101123 spin_unlock_bh(&xfrm_type_lock);
101124 xfrm_state_put_afinfo(afinfo);
101125 return err;
101126 @@ -211,7 +216,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
101127 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
101128 {
101129 struct xfrm_state_afinfo *afinfo;
101130 - const struct xfrm_type **typemap;
101131 const struct xfrm_type *type;
101132 int modload_attempted = 0;
101133
101134 @@ -219,9 +223,8 @@ retry:
101135 afinfo = xfrm_state_get_afinfo(family);
101136 if (unlikely(afinfo == NULL))
101137 return NULL;
101138 - typemap = afinfo->type_map;
101139
101140 - type = typemap[proto];
101141 + type = afinfo->type_map[proto];
101142 if (unlikely(type && !try_module_get(type->owner)))
101143 type = NULL;
101144 if (!type && !modload_attempted) {
101145 @@ -255,7 +258,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
101146 return -EAFNOSUPPORT;
101147
101148 err = -EEXIST;
101149 - modemap = afinfo->mode_map;
101150 + modemap = (struct xfrm_mode **)afinfo->mode_map;
101151 spin_lock_bh(&xfrm_mode_lock);
101152 if (modemap[mode->encap])
101153 goto out;
101154 @@ -264,8 +267,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
101155 if (!try_module_get(afinfo->owner))
101156 goto out;
101157
101158 - mode->afinfo = afinfo;
101159 + pax_open_kernel();
101160 + *(const void **)&mode->afinfo = afinfo;
101161 modemap[mode->encap] = mode;
101162 + pax_close_kernel();
101163 err = 0;
101164
101165 out:
101166 @@ -289,10 +294,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
101167 return -EAFNOSUPPORT;
101168
101169 err = -ENOENT;
101170 - modemap = afinfo->mode_map;
101171 + modemap = (struct xfrm_mode **)afinfo->mode_map;
101172 spin_lock_bh(&xfrm_mode_lock);
101173 if (likely(modemap[mode->encap] == mode)) {
101174 + pax_open_kernel();
101175 modemap[mode->encap] = NULL;
101176 + pax_close_kernel();
101177 module_put(mode->afinfo->owner);
101178 err = 0;
101179 }
101180 @@ -1486,10 +1493,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
101181 u32 xfrm_get_acqseq(void)
101182 {
101183 u32 res;
101184 - static atomic_t acqseq;
101185 + static atomic_unchecked_t acqseq;
101186
101187 do {
101188 - res = atomic_inc_return(&acqseq);
101189 + res = atomic_inc_return_unchecked(&acqseq);
101190 } while (!res);
101191
101192 return res;
101193 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
101194 index 05a6e3d..6716ec9 100644
101195 --- a/net/xfrm/xfrm_sysctl.c
101196 +++ b/net/xfrm/xfrm_sysctl.c
101197 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
101198
101199 int __net_init xfrm_sysctl_init(struct net *net)
101200 {
101201 - struct ctl_table *table;
101202 + ctl_table_no_const *table;
101203
101204 __xfrm_sysctl_init(net);
101205
101206 diff --git a/scripts/Makefile b/scripts/Makefile
101207 index 01e7adb..6176d5d 100644
101208 --- a/scripts/Makefile
101209 +++ b/scripts/Makefile
101210 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
101211
101212 # Let clean descend into subdirs
101213 subdir- += basic kconfig package selinux
101214 +
101215 +clean-files := randstruct.seed
101216 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
101217 index d5d859c..781cbcb 100644
101218 --- a/scripts/Makefile.build
101219 +++ b/scripts/Makefile.build
101220 @@ -111,7 +111,7 @@ endif
101221 endif
101222
101223 # Do not include host rules unless needed
101224 -ifneq ($(hostprogs-y)$(hostprogs-m),)
101225 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
101226 include scripts/Makefile.host
101227 endif
101228
101229 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
101230 index 686cb0d..9d653bf 100644
101231 --- a/scripts/Makefile.clean
101232 +++ b/scripts/Makefile.clean
101233 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
101234 __clean-files := $(extra-y) $(always) \
101235 $(targets) $(clean-files) \
101236 $(host-progs) \
101237 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
101238 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
101239 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
101240
101241 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
101242
101243 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
101244 index 1ac414f..38575f7 100644
101245 --- a/scripts/Makefile.host
101246 +++ b/scripts/Makefile.host
101247 @@ -31,6 +31,8 @@
101248 # Note: Shared libraries consisting of C++ files are not supported
101249
101250 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
101251 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
101252 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
101253
101254 # C code
101255 # Executables compiled from a single .c file
101256 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
101257 # Shared libaries (only .c supported)
101258 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
101259 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
101260 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
101261 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
101262 # Remove .so files from "xxx-objs"
101263 host-cobjs := $(filter-out %.so,$(host-cobjs))
101264 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
101265
101266 -#Object (.o) files used by the shared libaries
101267 +# Object (.o) files used by the shared libaries
101268 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
101269 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
101270
101271 # output directory for programs/.o files
101272 # hostprogs-y := tools/build may have been specified. Retrieve directory
101273 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
101274 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
101275 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
101276 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
101277 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
101278 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
101279 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
101280 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
101281
101282 obj-dirs += $(host-objdirs)
101283 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
101284 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
101285 $(call if_changed_dep,host-cshobjs)
101286
101287 +# Compile .c file, create position independent .o file
101288 +# host-cxxshobjs -> .o
101289 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
101290 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
101291 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
101292 + $(call if_changed_dep,host-cxxshobjs)
101293 +
101294 # Link a shared library, based on position independent .o files
101295 # *.o -> .so shared library (host-cshlib)
101296 quiet_cmd_host-cshlib = HOSTLLD -shared $@
101297 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
101298 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
101299 $(call if_changed,host-cshlib)
101300
101301 +# Link a shared library, based on position independent .o files
101302 +# *.o -> .so shared library (host-cxxshlib)
101303 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
101304 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
101305 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
101306 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
101307 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
101308 + $(call if_changed,host-cxxshlib)
101309 +
101310 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
101311 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
101312 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
101313
101314 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
101315 index 078fe1d..fbdb363 100644
101316 --- a/scripts/basic/fixdep.c
101317 +++ b/scripts/basic/fixdep.c
101318 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
101319 /*
101320 * Lookup a value in the configuration string.
101321 */
101322 -static int is_defined_config(const char *name, int len, unsigned int hash)
101323 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
101324 {
101325 struct item *aux;
101326
101327 @@ -211,10 +211,10 @@ static void clear_config(void)
101328 /*
101329 * Record the use of a CONFIG_* word.
101330 */
101331 -static void use_config(const char *m, int slen)
101332 +static void use_config(const char *m, unsigned int slen)
101333 {
101334 unsigned int hash = strhash(m, slen);
101335 - int c, i;
101336 + unsigned int c, i;
101337
101338 if (is_defined_config(m, slen, hash))
101339 return;
101340 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
101341
101342 static void parse_config_file(const char *map, size_t len)
101343 {
101344 - const int *end = (const int *) (map + len);
101345 + const unsigned int *end = (const unsigned int *) (map + len);
101346 /* start at +1, so that p can never be < map */
101347 - const int *m = (const int *) map + 1;
101348 + const unsigned int *m = (const unsigned int *) map + 1;
101349 const char *p, *q;
101350
101351 for (; m < end; m++) {
101352 @@ -435,7 +435,7 @@ static void print_deps(void)
101353 static void traps(void)
101354 {
101355 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
101356 - int *p = (int *)test;
101357 + unsigned int *p = (unsigned int *)test;
101358
101359 if (*p != INT_CONF) {
101360 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
101361 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
101362 new file mode 100644
101363 index 0000000..5e0222d
101364 --- /dev/null
101365 +++ b/scripts/gcc-plugin.sh
101366 @@ -0,0 +1,17 @@
101367 +#!/bin/bash
101368 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
101369 +#include "gcc-plugin.h"
101370 +#include "tree.h"
101371 +#include "tm.h"
101372 +#include "rtl.h"
101373 +#ifdef ENABLE_BUILD_WITH_CXX
101374 +#warning $2
101375 +#else
101376 +#warning $1
101377 +#endif
101378 +EOF`
101379 +if [ $? -eq 0 ]
101380 +then
101381 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
101382 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
101383 +fi
101384 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
101385 index 5de5660..d3deb89 100644
101386 --- a/scripts/headers_install.sh
101387 +++ b/scripts/headers_install.sh
101388 @@ -32,6 +32,7 @@ do
101389 FILE="$(basename "$i")"
101390 sed -r \
101391 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
101392 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
101393 -e 's/__attribute_const__([ \t]|$)/\1/g' \
101394 -e 's@^#include <linux/compiler.h>@@' \
101395 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
101396 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
101397 index 2dcb377..a82c500 100644
101398 --- a/scripts/link-vmlinux.sh
101399 +++ b/scripts/link-vmlinux.sh
101400 @@ -162,7 +162,7 @@ else
101401 fi;
101402
101403 # final build of init/
101404 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
101405 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
101406
101407 kallsymso=""
101408 kallsyms_vmlinux=""
101409 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
101410 index 2370863..212fbca 100644
101411 --- a/scripts/mod/file2alias.c
101412 +++ b/scripts/mod/file2alias.c
101413 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
101414 unsigned long size, unsigned long id_size,
101415 void *symval)
101416 {
101417 - int i;
101418 + unsigned int i;
101419
101420 if (size % id_size || size < id_size) {
101421 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
101422 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
101423 /* USB is special because the bcdDevice can be matched against a numeric range */
101424 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
101425 static void do_usb_entry(void *symval,
101426 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
101427 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
101428 unsigned char range_lo, unsigned char range_hi,
101429 unsigned char max, struct module *mod)
101430 {
101431 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
101432 {
101433 unsigned int devlo, devhi;
101434 unsigned char chi, clo, max;
101435 - int ndigits;
101436 + unsigned int ndigits;
101437
101438 DEF_FIELD(symval, usb_device_id, match_flags);
101439 DEF_FIELD(symval, usb_device_id, idVendor);
101440 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
101441 for (i = 0; i < count; i++) {
101442 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
101443 char acpi_id[sizeof(*id)];
101444 - int j;
101445 + unsigned int j;
101446
101447 buf_printf(&mod->dev_table_buf,
101448 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
101449 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
101450
101451 for (j = 0; j < PNP_MAX_DEVICES; j++) {
101452 const char *id = (char *)(*devs)[j].id;
101453 - int i2, j2;
101454 + unsigned int i2, j2;
101455 int dup = 0;
101456
101457 if (!id[0])
101458 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
101459 /* add an individual alias for every device entry */
101460 if (!dup) {
101461 char acpi_id[PNP_ID_LEN];
101462 - int k;
101463 + unsigned int k;
101464
101465 buf_printf(&mod->dev_table_buf,
101466 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
101467 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
101468 static int do_dmi_entry(const char *filename, void *symval,
101469 char *alias)
101470 {
101471 - int i, j;
101472 + unsigned int i, j;
101473 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
101474 sprintf(alias, "dmi*");
101475
101476 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
101477 index 1785576..5e8e06a 100644
101478 --- a/scripts/mod/modpost.c
101479 +++ b/scripts/mod/modpost.c
101480 @@ -941,6 +941,7 @@ enum mismatch {
101481 ANY_INIT_TO_ANY_EXIT,
101482 ANY_EXIT_TO_ANY_INIT,
101483 EXPORT_TO_INIT_EXIT,
101484 + DATA_TO_TEXT
101485 };
101486
101487 struct sectioncheck {
101488 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
101489 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
101490 .mismatch = EXPORT_TO_INIT_EXIT,
101491 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
101492 +},
101493 +/* Do not reference code from writable data */
101494 +{
101495 + .fromsec = { DATA_SECTIONS, NULL },
101496 + .tosec = { TEXT_SECTIONS, NULL },
101497 + .mismatch = DATA_TO_TEXT
101498 }
101499 };
101500
101501 @@ -1147,10 +1154,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
101502 continue;
101503 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
101504 continue;
101505 - if (sym->st_value == addr)
101506 - return sym;
101507 /* Find a symbol nearby - addr are maybe negative */
101508 d = sym->st_value - addr;
101509 + if (d == 0)
101510 + return sym;
101511 if (d < 0)
101512 d = addr - sym->st_value;
101513 if (d < distance) {
101514 @@ -1428,6 +1435,14 @@ static void report_sec_mismatch(const char *modname,
101515 tosym, prl_to, prl_to, tosym);
101516 free(prl_to);
101517 break;
101518 + case DATA_TO_TEXT:
101519 +#if 0
101520 + fprintf(stderr,
101521 + "The %s %s:%s references\n"
101522 + "the %s %s:%s%s\n",
101523 + from, fromsec, fromsym, to, tosec, tosym, to_p);
101524 +#endif
101525 + break;
101526 }
101527 fprintf(stderr, "\n");
101528 }
101529 @@ -1662,7 +1677,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
101530 static void check_sec_ref(struct module *mod, const char *modname,
101531 struct elf_info *elf)
101532 {
101533 - int i;
101534 + unsigned int i;
101535 Elf_Shdr *sechdrs = elf->sechdrs;
101536
101537 /* Walk through all sections */
101538 @@ -1781,7 +1796,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
101539 va_end(ap);
101540 }
101541
101542 -void buf_write(struct buffer *buf, const char *s, int len)
101543 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
101544 {
101545 if (buf->size - buf->pos < len) {
101546 buf->size += len + SZ;
101547 @@ -2000,7 +2015,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
101548 if (fstat(fileno(file), &st) < 0)
101549 goto close_write;
101550
101551 - if (st.st_size != b->pos)
101552 + if (st.st_size != (off_t)b->pos)
101553 goto close_write;
101554
101555 tmp = NOFAIL(malloc(b->pos));
101556 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
101557 index 51207e4..f7d603d 100644
101558 --- a/scripts/mod/modpost.h
101559 +++ b/scripts/mod/modpost.h
101560 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
101561
101562 struct buffer {
101563 char *p;
101564 - int pos;
101565 - int size;
101566 + unsigned int pos;
101567 + unsigned int size;
101568 };
101569
101570 void __attribute__((format(printf, 2, 3)))
101571 buf_printf(struct buffer *buf, const char *fmt, ...);
101572
101573 void
101574 -buf_write(struct buffer *buf, const char *s, int len);
101575 +buf_write(struct buffer *buf, const char *s, unsigned int len);
101576
101577 struct module {
101578 struct module *next;
101579 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
101580 index deb2994..af4f63e 100644
101581 --- a/scripts/mod/sumversion.c
101582 +++ b/scripts/mod/sumversion.c
101583 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
101584 goto out;
101585 }
101586
101587 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
101588 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
101589 warn("writing sum in %s failed: %s\n",
101590 filename, strerror(errno));
101591 goto out;
101592 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
101593 index 0865b3e..7235dd4 100644
101594 --- a/scripts/module-common.lds
101595 +++ b/scripts/module-common.lds
101596 @@ -6,6 +6,10 @@
101597 SECTIONS {
101598 /DISCARD/ : { *(.discard) }
101599
101600 + .rodata : {
101601 + *(.rodata) *(.rodata.*)
101602 + *(.data..read_only)
101603 + }
101604 __ksymtab : { *(SORT(___ksymtab+*)) }
101605 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
101606 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
101607 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
101608 index 90e521f..e9eaf8f 100644
101609 --- a/scripts/package/builddeb
101610 +++ b/scripts/package/builddeb
101611 @@ -281,6 +281,7 @@ fi
101612 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
101613 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
101614 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
101615 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
101616 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
101617 mkdir -p "$destdir"
101618 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
101619 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
101620 index 68bb4ef..2f419e1 100644
101621 --- a/scripts/pnmtologo.c
101622 +++ b/scripts/pnmtologo.c
101623 @@ -244,14 +244,14 @@ static void write_header(void)
101624 fprintf(out, " * Linux logo %s\n", logoname);
101625 fputs(" */\n\n", out);
101626 fputs("#include <linux/linux_logo.h>\n\n", out);
101627 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
101628 + fprintf(out, "static unsigned char %s_data[] = {\n",
101629 logoname);
101630 }
101631
101632 static void write_footer(void)
101633 {
101634 fputs("\n};\n\n", out);
101635 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
101636 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
101637 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
101638 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
101639 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
101640 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
101641 fputs("\n};\n\n", out);
101642
101643 /* write logo clut */
101644 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
101645 + fprintf(out, "static unsigned char %s_clut[] = {\n",
101646 logoname);
101647 write_hex_cnt = 0;
101648 for (i = 0; i < logo_clutsize; i++) {
101649 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
101650 index 8fac3fd..32ff38d 100644
101651 --- a/scripts/sortextable.h
101652 +++ b/scripts/sortextable.h
101653 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
101654 const char *secstrtab;
101655 const char *strtab;
101656 char *extab_image;
101657 - int extab_index = 0;
101658 - int i;
101659 - int idx;
101660 + unsigned int extab_index = 0;
101661 + unsigned int i;
101662 + unsigned int idx;
101663 unsigned int num_sections;
101664 unsigned int secindex_strings;
101665
101666 diff --git a/security/Kconfig b/security/Kconfig
101667 index e9c6ac7..0ebde711 100644
101668 --- a/security/Kconfig
101669 +++ b/security/Kconfig
101670 @@ -4,6 +4,959 @@
101671
101672 menu "Security options"
101673
101674 +menu "Grsecurity"
101675 +
101676 + config ARCH_TRACK_EXEC_LIMIT
101677 + bool
101678 +
101679 + config PAX_KERNEXEC_PLUGIN
101680 + bool
101681 +
101682 + config PAX_PER_CPU_PGD
101683 + bool
101684 +
101685 + config TASK_SIZE_MAX_SHIFT
101686 + int
101687 + depends on X86_64
101688 + default 47 if !PAX_PER_CPU_PGD
101689 + default 42 if PAX_PER_CPU_PGD
101690 +
101691 + config PAX_ENABLE_PAE
101692 + bool
101693 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
101694 +
101695 + config PAX_USERCOPY_SLABS
101696 + bool
101697 +
101698 +config GRKERNSEC
101699 + bool "Grsecurity"
101700 + select CRYPTO
101701 + select CRYPTO_SHA256
101702 + select PROC_FS
101703 + select STOP_MACHINE
101704 + select TTY
101705 + select DEBUG_KERNEL
101706 + select DEBUG_LIST
101707 + help
101708 + If you say Y here, you will be able to configure many features
101709 + that will enhance the security of your system. It is highly
101710 + recommended that you say Y here and read through the help
101711 + for each option so that you fully understand the features and
101712 + can evaluate their usefulness for your machine.
101713 +
101714 +choice
101715 + prompt "Configuration Method"
101716 + depends on GRKERNSEC
101717 + default GRKERNSEC_CONFIG_CUSTOM
101718 + help
101719 +
101720 +config GRKERNSEC_CONFIG_AUTO
101721 + bool "Automatic"
101722 + help
101723 + If you choose this configuration method, you'll be able to answer a small
101724 + number of simple questions about how you plan to use this kernel.
101725 + The settings of grsecurity and PaX will be automatically configured for
101726 + the highest commonly-used settings within the provided constraints.
101727 +
101728 + If you require additional configuration, custom changes can still be made
101729 + from the "custom configuration" menu.
101730 +
101731 +config GRKERNSEC_CONFIG_CUSTOM
101732 + bool "Custom"
101733 + help
101734 + If you choose this configuration method, you'll be able to configure all
101735 + grsecurity and PaX settings manually. Via this method, no options are
101736 + automatically enabled.
101737 +
101738 +endchoice
101739 +
101740 +choice
101741 + prompt "Usage Type"
101742 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101743 + default GRKERNSEC_CONFIG_SERVER
101744 + help
101745 +
101746 +config GRKERNSEC_CONFIG_SERVER
101747 + bool "Server"
101748 + help
101749 + Choose this option if you plan to use this kernel on a server.
101750 +
101751 +config GRKERNSEC_CONFIG_DESKTOP
101752 + bool "Desktop"
101753 + help
101754 + Choose this option if you plan to use this kernel on a desktop.
101755 +
101756 +endchoice
101757 +
101758 +choice
101759 + prompt "Virtualization Type"
101760 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
101761 + default GRKERNSEC_CONFIG_VIRT_NONE
101762 + help
101763 +
101764 +config GRKERNSEC_CONFIG_VIRT_NONE
101765 + bool "None"
101766 + help
101767 + Choose this option if this kernel will be run on bare metal.
101768 +
101769 +config GRKERNSEC_CONFIG_VIRT_GUEST
101770 + bool "Guest"
101771 + help
101772 + Choose this option if this kernel will be run as a VM guest.
101773 +
101774 +config GRKERNSEC_CONFIG_VIRT_HOST
101775 + bool "Host"
101776 + help
101777 + Choose this option if this kernel will be run as a VM host.
101778 +
101779 +endchoice
101780 +
101781 +choice
101782 + prompt "Virtualization Hardware"
101783 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
101784 + help
101785 +
101786 +config GRKERNSEC_CONFIG_VIRT_EPT
101787 + bool "EPT/RVI Processor Support"
101788 + depends on X86
101789 + help
101790 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
101791 + hardware virtualization. This allows for additional kernel hardening protections
101792 + to operate without additional performance impact.
101793 +
101794 + To see if your Intel processor supports EPT, see:
101795 + http://ark.intel.com/Products/VirtualizationTechnology
101796 + (Most Core i3/5/7 support EPT)
101797 +
101798 + To see if your AMD processor supports RVI, see:
101799 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
101800 +
101801 +config GRKERNSEC_CONFIG_VIRT_SOFT
101802 + bool "First-gen/No Hardware Virtualization"
101803 + help
101804 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
101805 + support hardware virtualization or doesn't support the EPT/RVI extensions.
101806 +
101807 +endchoice
101808 +
101809 +choice
101810 + prompt "Virtualization Software"
101811 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
101812 + help
101813 +
101814 +config GRKERNSEC_CONFIG_VIRT_XEN
101815 + bool "Xen"
101816 + help
101817 + Choose this option if this kernel is running as a Xen guest or host.
101818 +
101819 +config GRKERNSEC_CONFIG_VIRT_VMWARE
101820 + bool "VMWare"
101821 + help
101822 + Choose this option if this kernel is running as a VMWare guest or host.
101823 +
101824 +config GRKERNSEC_CONFIG_VIRT_KVM
101825 + bool "KVM"
101826 + help
101827 + Choose this option if this kernel is running as a KVM guest or host.
101828 +
101829 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
101830 + bool "VirtualBox"
101831 + help
101832 + Choose this option if this kernel is running as a VirtualBox guest or host.
101833 +
101834 +endchoice
101835 +
101836 +choice
101837 + prompt "Required Priorities"
101838 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101839 + default GRKERNSEC_CONFIG_PRIORITY_PERF
101840 + help
101841 +
101842 +config GRKERNSEC_CONFIG_PRIORITY_PERF
101843 + bool "Performance"
101844 + help
101845 + Choose this option if performance is of highest priority for this deployment
101846 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
101847 + clearing of structures intended for userland, and freed memory sanitizing will
101848 + be disabled.
101849 +
101850 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
101851 + bool "Security"
101852 + help
101853 + Choose this option if security is of highest priority for this deployment of
101854 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
101855 + for userland, and freed memory sanitizing will be enabled for this kernel.
101856 + In a worst-case scenario, these features can introduce a 20% performance hit
101857 + (UDEREF on x64 contributing half of this hit).
101858 +
101859 +endchoice
101860 +
101861 +menu "Default Special Groups"
101862 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101863 +
101864 +config GRKERNSEC_PROC_GID
101865 + int "GID exempted from /proc restrictions"
101866 + default 1001
101867 + help
101868 + Setting this GID determines which group will be exempted from
101869 + grsecurity's /proc restrictions, allowing users of the specified
101870 + group to view network statistics and the existence of other users'
101871 + processes on the system. This GID may also be chosen at boot time
101872 + via "grsec_proc_gid=" on the kernel commandline.
101873 +
101874 +config GRKERNSEC_TPE_UNTRUSTED_GID
101875 + int "GID for TPE-untrusted users"
101876 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
101877 + default 1005
101878 + help
101879 + Setting this GID determines which group untrusted users should
101880 + be added to. These users will be placed under grsecurity's Trusted Path
101881 + Execution mechanism, preventing them from executing their own binaries.
101882 + The users will only be able to execute binaries in directories owned and
101883 + writable only by the root user. If the sysctl option is enabled, a sysctl
101884 + option with name "tpe_gid" is created.
101885 +
101886 +config GRKERNSEC_TPE_TRUSTED_GID
101887 + int "GID for TPE-trusted users"
101888 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
101889 + default 1005
101890 + help
101891 + Setting this GID determines what group TPE restrictions will be
101892 + *disabled* for. If the sysctl option is enabled, a sysctl option
101893 + with name "tpe_gid" is created.
101894 +
101895 +config GRKERNSEC_SYMLINKOWN_GID
101896 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
101897 + depends on GRKERNSEC_CONFIG_SERVER
101898 + default 1006
101899 + help
101900 + Setting this GID determines what group kernel-enforced
101901 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
101902 + is enabled, a sysctl option with name "symlinkown_gid" is created.
101903 +
101904 +
101905 +endmenu
101906 +
101907 +menu "Customize Configuration"
101908 +depends on GRKERNSEC
101909 +
101910 +menu "PaX"
101911 +
101912 +config PAX
101913 + bool "Enable various PaX features"
101914 + default y if GRKERNSEC_CONFIG_AUTO
101915 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
101916 + help
101917 + This allows you to enable various PaX features. PaX adds
101918 + intrusion prevention mechanisms to the kernel that reduce
101919 + the risks posed by exploitable memory corruption bugs.
101920 +
101921 +menu "PaX Control"
101922 + depends on PAX
101923 +
101924 +config PAX_SOFTMODE
101925 + bool 'Support soft mode'
101926 + help
101927 + Enabling this option will allow you to run PaX in soft mode, that
101928 + is, PaX features will not be enforced by default, only on executables
101929 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
101930 + support as they are the only way to mark executables for soft mode use.
101931 +
101932 + Soft mode can be activated by using the "pax_softmode=1" kernel command
101933 + line option on boot. Furthermore you can control various PaX features
101934 + at runtime via the entries in /proc/sys/kernel/pax.
101935 +
101936 +config PAX_EI_PAX
101937 + bool 'Use legacy ELF header marking'
101938 + default y if GRKERNSEC_CONFIG_AUTO
101939 + help
101940 + Enabling this option will allow you to control PaX features on
101941 + a per executable basis via the 'chpax' utility available at
101942 + http://pax.grsecurity.net/. The control flags will be read from
101943 + an otherwise reserved part of the ELF header. This marking has
101944 + numerous drawbacks (no support for soft-mode, toolchain does not
101945 + know about the non-standard use of the ELF header) therefore it
101946 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
101947 + support.
101948 +
101949 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
101950 + support as well, they will override the legacy EI_PAX marks.
101951 +
101952 + If you enable none of the marking options then all applications
101953 + will run with PaX enabled on them by default.
101954 +
101955 +config PAX_PT_PAX_FLAGS
101956 + bool 'Use ELF program header marking'
101957 + default y if GRKERNSEC_CONFIG_AUTO
101958 + help
101959 + Enabling this option will allow you to control PaX features on
101960 + a per executable basis via the 'paxctl' utility available at
101961 + http://pax.grsecurity.net/. The control flags will be read from
101962 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
101963 + has the benefits of supporting both soft mode and being fully
101964 + integrated into the toolchain (the binutils patch is available
101965 + from http://pax.grsecurity.net).
101966 +
101967 + Note that if you enable the legacy EI_PAX marking support as well,
101968 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
101969 +
101970 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
101971 + must make sure that the marks are the same if a binary has both marks.
101972 +
101973 + If you enable none of the marking options then all applications
101974 + will run with PaX enabled on them by default.
101975 +
101976 +config PAX_XATTR_PAX_FLAGS
101977 + bool 'Use filesystem extended attributes marking'
101978 + default y if GRKERNSEC_CONFIG_AUTO
101979 + select CIFS_XATTR if CIFS
101980 + select EXT2_FS_XATTR if EXT2_FS
101981 + select EXT3_FS_XATTR if EXT3_FS
101982 + select JFFS2_FS_XATTR if JFFS2_FS
101983 + select REISERFS_FS_XATTR if REISERFS_FS
101984 + select SQUASHFS_XATTR if SQUASHFS
101985 + select TMPFS_XATTR if TMPFS
101986 + select UBIFS_FS_XATTR if UBIFS_FS
101987 + help
101988 + Enabling this option will allow you to control PaX features on
101989 + a per executable basis via the 'setfattr' utility. The control
101990 + flags will be read from the user.pax.flags extended attribute of
101991 + the file. This marking has the benefit of supporting binary-only
101992 + applications that self-check themselves (e.g., skype) and would
101993 + not tolerate chpax/paxctl changes. The main drawback is that
101994 + extended attributes are not supported by some filesystems (e.g.,
101995 + isofs, udf, vfat) so copying files through such filesystems will
101996 + lose the extended attributes and these PaX markings.
101997 +
101998 + Note that if you enable the legacy EI_PAX marking support as well,
101999 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
102000 +
102001 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
102002 + must make sure that the marks are the same if a binary has both marks.
102003 +
102004 + If you enable none of the marking options then all applications
102005 + will run with PaX enabled on them by default.
102006 +
102007 +choice
102008 + prompt 'MAC system integration'
102009 + default PAX_HAVE_ACL_FLAGS
102010 + help
102011 + Mandatory Access Control systems have the option of controlling
102012 + PaX flags on a per executable basis, choose the method supported
102013 + by your particular system.
102014 +
102015 + - "none": if your MAC system does not interact with PaX,
102016 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
102017 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
102018 +
102019 + NOTE: this option is for developers/integrators only.
102020 +
102021 + config PAX_NO_ACL_FLAGS
102022 + bool 'none'
102023 +
102024 + config PAX_HAVE_ACL_FLAGS
102025 + bool 'direct'
102026 +
102027 + config PAX_HOOK_ACL_FLAGS
102028 + bool 'hook'
102029 +endchoice
102030 +
102031 +endmenu
102032 +
102033 +menu "Non-executable pages"
102034 + depends on PAX
102035 +
102036 +config PAX_NOEXEC
102037 + bool "Enforce non-executable pages"
102038 + default y if GRKERNSEC_CONFIG_AUTO
102039 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
102040 + help
102041 + By design some architectures do not allow for protecting memory
102042 + pages against execution or even if they do, Linux does not make
102043 + use of this feature. In practice this means that if a page is
102044 + readable (such as the stack or heap) it is also executable.
102045 +
102046 + There is a well known exploit technique that makes use of this
102047 + fact and a common programming mistake where an attacker can
102048 + introduce code of his choice somewhere in the attacked program's
102049 + memory (typically the stack or the heap) and then execute it.
102050 +
102051 + If the attacked program was running with different (typically
102052 + higher) privileges than that of the attacker, then he can elevate
102053 + his own privilege level (e.g. get a root shell, write to files for
102054 + which he does not have write access to, etc).
102055 +
102056 + Enabling this option will let you choose from various features
102057 + that prevent the injection and execution of 'foreign' code in
102058 + a program.
102059 +
102060 + This will also break programs that rely on the old behaviour and
102061 + expect that dynamically allocated memory via the malloc() family
102062 + of functions is executable (which it is not). Notable examples
102063 + are the XFree86 4.x server, the java runtime and wine.
102064 +
102065 +config PAX_PAGEEXEC
102066 + bool "Paging based non-executable pages"
102067 + default y if GRKERNSEC_CONFIG_AUTO
102068 + 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)
102069 + select ARCH_TRACK_EXEC_LIMIT if X86_32
102070 + help
102071 + This implementation is based on the paging feature of the CPU.
102072 + On i386 without hardware non-executable bit support there is a
102073 + variable but usually low performance impact, however on Intel's
102074 + P4 core based CPUs it is very high so you should not enable this
102075 + for kernels meant to be used on such CPUs.
102076 +
102077 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
102078 + with hardware non-executable bit support there is no performance
102079 + impact, on ppc the impact is negligible.
102080 +
102081 + Note that several architectures require various emulations due to
102082 + badly designed userland ABIs, this will cause a performance impact
102083 + but will disappear as soon as userland is fixed. For example, ppc
102084 + userland MUST have been built with secure-plt by a recent toolchain.
102085 +
102086 +config PAX_SEGMEXEC
102087 + bool "Segmentation based non-executable pages"
102088 + default y if GRKERNSEC_CONFIG_AUTO
102089 + depends on PAX_NOEXEC && X86_32
102090 + help
102091 + This implementation is based on the segmentation feature of the
102092 + CPU and has a very small performance impact, however applications
102093 + will be limited to a 1.5 GB address space instead of the normal
102094 + 3 GB.
102095 +
102096 +config PAX_EMUTRAMP
102097 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
102098 + default y if PARISC
102099 + help
102100 + There are some programs and libraries that for one reason or
102101 + another attempt to execute special small code snippets from
102102 + non-executable memory pages. Most notable examples are the
102103 + signal handler return code generated by the kernel itself and
102104 + the GCC trampolines.
102105 +
102106 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
102107 + such programs will no longer work under your kernel.
102108 +
102109 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
102110 + utilities to enable trampoline emulation for the affected programs
102111 + yet still have the protection provided by the non-executable pages.
102112 +
102113 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
102114 + your system will not even boot.
102115 +
102116 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
102117 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
102118 + for the affected files.
102119 +
102120 + NOTE: enabling this feature *may* open up a loophole in the
102121 + protection provided by non-executable pages that an attacker
102122 + could abuse. Therefore the best solution is to not have any
102123 + files on your system that would require this option. This can
102124 + be achieved by not using libc5 (which relies on the kernel
102125 + signal handler return code) and not using or rewriting programs
102126 + that make use of the nested function implementation of GCC.
102127 + Skilled users can just fix GCC itself so that it implements
102128 + nested function calls in a way that does not interfere with PaX.
102129 +
102130 +config PAX_EMUSIGRT
102131 + bool "Automatically emulate sigreturn trampolines"
102132 + depends on PAX_EMUTRAMP && PARISC
102133 + default y
102134 + help
102135 + Enabling this option will have the kernel automatically detect
102136 + and emulate signal return trampolines executing on the stack
102137 + that would otherwise lead to task termination.
102138 +
102139 + This solution is intended as a temporary one for users with
102140 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
102141 + Modula-3 runtime, etc) or executables linked to such, basically
102142 + everything that does not specify its own SA_RESTORER function in
102143 + normal executable memory like glibc 2.1+ does.
102144 +
102145 + On parisc you MUST enable this option, otherwise your system will
102146 + not even boot.
102147 +
102148 + NOTE: this feature cannot be disabled on a per executable basis
102149 + and since it *does* open up a loophole in the protection provided
102150 + by non-executable pages, the best solution is to not have any
102151 + files on your system that would require this option.
102152 +
102153 +config PAX_MPROTECT
102154 + bool "Restrict mprotect()"
102155 + default y if GRKERNSEC_CONFIG_AUTO
102156 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
102157 + help
102158 + Enabling this option will prevent programs from
102159 + - changing the executable status of memory pages that were
102160 + not originally created as executable,
102161 + - making read-only executable pages writable again,
102162 + - creating executable pages from anonymous memory,
102163 + - making read-only-after-relocations (RELRO) data pages writable again.
102164 +
102165 + You should say Y here to complete the protection provided by
102166 + the enforcement of non-executable pages.
102167 +
102168 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
102169 + this feature on a per file basis.
102170 +
102171 +config PAX_MPROTECT_COMPAT
102172 + bool "Use legacy/compat protection demoting (read help)"
102173 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
102174 + depends on PAX_MPROTECT
102175 + help
102176 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
102177 + by sending the proper error code to the application. For some broken
102178 + userland, this can cause problems with Python or other applications. The
102179 + current implementation however allows for applications like clamav to
102180 + detect if JIT compilation/execution is allowed and to fall back gracefully
102181 + to an interpreter-based mode if it does not. While we encourage everyone
102182 + to use the current implementation as-is and push upstream to fix broken
102183 + userland (note that the RWX logging option can assist with this), in some
102184 + environments this may not be possible. Having to disable MPROTECT
102185 + completely on certain binaries reduces the security benefit of PaX,
102186 + so this option is provided for those environments to revert to the old
102187 + behavior.
102188 +
102189 +config PAX_ELFRELOCS
102190 + bool "Allow ELF text relocations (read help)"
102191 + depends on PAX_MPROTECT
102192 + default n
102193 + help
102194 + Non-executable pages and mprotect() restrictions are effective
102195 + in preventing the introduction of new executable code into an
102196 + attacked task's address space. There remain only two venues
102197 + for this kind of attack: if the attacker can execute already
102198 + existing code in the attacked task then he can either have it
102199 + create and mmap() a file containing his code or have it mmap()
102200 + an already existing ELF library that does not have position
102201 + independent code in it and use mprotect() on it to make it
102202 + writable and copy his code there. While protecting against
102203 + the former approach is beyond PaX, the latter can be prevented
102204 + by having only PIC ELF libraries on one's system (which do not
102205 + need to relocate their code). If you are sure this is your case,
102206 + as is the case with all modern Linux distributions, then leave
102207 + this option disabled. You should say 'n' here.
102208 +
102209 +config PAX_ETEXECRELOCS
102210 + bool "Allow ELF ET_EXEC text relocations"
102211 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
102212 + select PAX_ELFRELOCS
102213 + default y
102214 + help
102215 + On some architectures there are incorrectly created applications
102216 + that require text relocations and would not work without enabling
102217 + this option. If you are an alpha, ia64 or parisc user, you should
102218 + enable this option and disable it once you have made sure that
102219 + none of your applications need it.
102220 +
102221 +config PAX_EMUPLT
102222 + bool "Automatically emulate ELF PLT"
102223 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
102224 + default y
102225 + help
102226 + Enabling this option will have the kernel automatically detect
102227 + and emulate the Procedure Linkage Table entries in ELF files.
102228 + On some architectures such entries are in writable memory, and
102229 + become non-executable leading to task termination. Therefore
102230 + it is mandatory that you enable this option on alpha, parisc,
102231 + sparc and sparc64, otherwise your system would not even boot.
102232 +
102233 + NOTE: this feature *does* open up a loophole in the protection
102234 + provided by the non-executable pages, therefore the proper
102235 + solution is to modify the toolchain to produce a PLT that does
102236 + not need to be writable.
102237 +
102238 +config PAX_DLRESOLVE
102239 + bool 'Emulate old glibc resolver stub'
102240 + depends on PAX_EMUPLT && SPARC
102241 + default n
102242 + help
102243 + This option is needed if userland has an old glibc (before 2.4)
102244 + that puts a 'save' instruction into the runtime generated resolver
102245 + stub that needs special emulation.
102246 +
102247 +config PAX_KERNEXEC
102248 + bool "Enforce non-executable kernel pages"
102249 + default y if GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
102250 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
102251 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
102252 + select PAX_KERNEXEC_PLUGIN if X86_64
102253 + help
102254 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
102255 + that is, enabling this option will make it harder to inject
102256 + and execute 'foreign' code in kernel memory itself.
102257 +
102258 +choice
102259 + prompt "Return Address Instrumentation Method"
102260 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
102261 + depends on PAX_KERNEXEC_PLUGIN
102262 + help
102263 + Select the method used to instrument function pointer dereferences.
102264 + Note that binary modules cannot be instrumented by this approach.
102265 +
102266 + Note that the implementation requires a gcc with plugin support,
102267 + i.e., gcc 4.5 or newer. You may need to install the supporting
102268 + headers explicitly in addition to the normal gcc package.
102269 +
102270 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
102271 + bool "bts"
102272 + help
102273 + This method is compatible with binary only modules but has
102274 + a higher runtime overhead.
102275 +
102276 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
102277 + bool "or"
102278 + depends on !PARAVIRT
102279 + help
102280 + This method is incompatible with binary only modules but has
102281 + a lower runtime overhead.
102282 +endchoice
102283 +
102284 +config PAX_KERNEXEC_PLUGIN_METHOD
102285 + string
102286 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
102287 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
102288 + default ""
102289 +
102290 +config PAX_KERNEXEC_MODULE_TEXT
102291 + int "Minimum amount of memory reserved for module code"
102292 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
102293 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
102294 + depends on PAX_KERNEXEC && X86_32
102295 + help
102296 + Due to implementation details the kernel must reserve a fixed
102297 + amount of memory for runtime allocated code (such as modules)
102298 + at compile time that cannot be changed at runtime. Here you
102299 + can specify the minimum amount in MB that will be reserved.
102300 + Due to the same implementation details this size will always
102301 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
102302 + the actually available memory for runtime allocated code will
102303 + usually be more than this minimum.
102304 +
102305 + The default 4 MB should be enough for most users but if you have
102306 + an excessive number of modules (e.g., most distribution configs
102307 + compile many drivers as modules) or use huge modules such as
102308 + nvidia's kernel driver, you will need to adjust this amount.
102309 + A good rule of thumb is to look at your currently loaded kernel
102310 + modules and add up their sizes.
102311 +
102312 +endmenu
102313 +
102314 +menu "Address Space Layout Randomization"
102315 + depends on PAX
102316 +
102317 +config PAX_ASLR
102318 + bool "Address Space Layout Randomization"
102319 + default y if GRKERNSEC_CONFIG_AUTO
102320 + help
102321 + Many if not most exploit techniques rely on the knowledge of
102322 + certain addresses in the attacked program. The following options
102323 + will allow the kernel to apply a certain amount of randomization
102324 + to specific parts of the program thereby forcing an attacker to
102325 + guess them in most cases. Any failed guess will most likely crash
102326 + the attacked program which allows the kernel to detect such attempts
102327 + and react on them. PaX itself provides no reaction mechanisms,
102328 + instead it is strongly encouraged that you make use of Nergal's
102329 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
102330 + (http://www.grsecurity.net/) built-in crash detection features or
102331 + develop one yourself.
102332 +
102333 + By saying Y here you can choose to randomize the following areas:
102334 + - top of the task's kernel stack
102335 + - top of the task's userland stack
102336 + - base address for mmap() requests that do not specify one
102337 + (this includes all libraries)
102338 + - base address of the main executable
102339 +
102340 + It is strongly recommended to say Y here as address space layout
102341 + randomization has negligible impact on performance yet it provides
102342 + a very effective protection.
102343 +
102344 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
102345 + this feature on a per file basis.
102346 +
102347 +config PAX_RANDKSTACK
102348 + bool "Randomize kernel stack base"
102349 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
102350 + depends on X86_TSC && X86
102351 + help
102352 + By saying Y here the kernel will randomize every task's kernel
102353 + stack on every system call. This will not only force an attacker
102354 + to guess it but also prevent him from making use of possible
102355 + leaked information about it.
102356 +
102357 + Since the kernel stack is a rather scarce resource, randomization
102358 + may cause unexpected stack overflows, therefore you should very
102359 + carefully test your system. Note that once enabled in the kernel
102360 + configuration, this feature cannot be disabled on a per file basis.
102361 +
102362 +config PAX_RANDUSTACK
102363 + bool "Randomize user stack base"
102364 + default y if GRKERNSEC_CONFIG_AUTO
102365 + depends on PAX_ASLR
102366 + help
102367 + By saying Y here the kernel will randomize every task's userland
102368 + stack. The randomization is done in two steps where the second
102369 + one may apply a big amount of shift to the top of the stack and
102370 + cause problems for programs that want to use lots of memory (more
102371 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
102372 + For this reason the second step can be controlled by 'chpax' or
102373 + 'paxctl' on a per file basis.
102374 +
102375 +config PAX_RANDMMAP
102376 + bool "Randomize mmap() base"
102377 + default y if GRKERNSEC_CONFIG_AUTO
102378 + depends on PAX_ASLR
102379 + help
102380 + By saying Y here the kernel will use a randomized base address for
102381 + mmap() requests that do not specify one themselves. As a result
102382 + all dynamically loaded libraries will appear at random addresses
102383 + and therefore be harder to exploit by a technique where an attacker
102384 + attempts to execute library code for his purposes (e.g. spawn a
102385 + shell from an exploited program that is running at an elevated
102386 + privilege level).
102387 +
102388 + Furthermore, if a program is relinked as a dynamic ELF file, its
102389 + base address will be randomized as well, completing the full
102390 + randomization of the address space layout. Attacking such programs
102391 + becomes a guess game. You can find an example of doing this at
102392 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
102393 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
102394 +
102395 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
102396 + feature on a per file basis.
102397 +
102398 +endmenu
102399 +
102400 +menu "Miscellaneous hardening features"
102401 +
102402 +config PAX_MEMORY_SANITIZE
102403 + bool "Sanitize all freed memory"
102404 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102405 + help
102406 + By saying Y here the kernel will erase memory pages and slab objects
102407 + as soon as they are freed. This in turn reduces the lifetime of data
102408 + stored in them, making it less likely that sensitive information such
102409 + as passwords, cryptographic secrets, etc stay in memory for too long.
102410 +
102411 + This is especially useful for programs whose runtime is short, long
102412 + lived processes and the kernel itself benefit from this as long as
102413 + they ensure timely freeing of memory that may hold sensitive
102414 + information.
102415 +
102416 + A nice side effect of the sanitization of slab objects is the
102417 + reduction of possible info leaks caused by padding bytes within the
102418 + leaky structures. Use-after-free bugs for structures containing
102419 + pointers can also be detected as dereferencing the sanitized pointer
102420 + will generate an access violation.
102421 +
102422 + The tradeoff is performance impact, on a single CPU system kernel
102423 + compilation sees a 3% slowdown, other systems and workloads may vary
102424 + and you are advised to test this feature on your expected workload
102425 + before deploying it.
102426 +
102427 + To reduce the performance penalty by sanitizing pages only, albeit
102428 + limiting the effectiveness of this feature at the same time, slab
102429 + sanitization can be disabled with the kernel commandline parameter
102430 + "pax_sanitize_slab=0".
102431 +
102432 + Note that this feature does not protect data stored in live pages,
102433 + e.g., process memory swapped to disk may stay there for a long time.
102434 +
102435 +config PAX_MEMORY_STACKLEAK
102436 + bool "Sanitize kernel stack"
102437 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102438 + depends on X86
102439 + help
102440 + By saying Y here the kernel will erase the kernel stack before it
102441 + returns from a system call. This in turn reduces the information
102442 + that a kernel stack leak bug can reveal.
102443 +
102444 + Note that such a bug can still leak information that was put on
102445 + the stack by the current system call (the one eventually triggering
102446 + the bug) but traces of earlier system calls on the kernel stack
102447 + cannot leak anymore.
102448 +
102449 + The tradeoff is performance impact: on a single CPU system kernel
102450 + compilation sees a 1% slowdown, other systems and workloads may vary
102451 + and you are advised to test this feature on your expected workload
102452 + before deploying it.
102453 +
102454 + Note that the full feature requires a gcc with plugin support,
102455 + i.e., gcc 4.5 or newer. You may need to install the supporting
102456 + headers explicitly in addition to the normal gcc package. Using
102457 + older gcc versions means that functions with large enough stack
102458 + frames may leave uninitialized memory behind that may be exposed
102459 + to a later syscall leaking the stack.
102460 +
102461 +config PAX_MEMORY_STRUCTLEAK
102462 + bool "Forcibly initialize local variables copied to userland"
102463 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102464 + help
102465 + By saying Y here the kernel will zero initialize some local
102466 + variables that are going to be copied to userland. This in
102467 + turn prevents unintended information leakage from the kernel
102468 + stack should later code forget to explicitly set all parts of
102469 + the copied variable.
102470 +
102471 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
102472 + at a much smaller coverage.
102473 +
102474 + Note that the implementation requires a gcc with plugin support,
102475 + i.e., gcc 4.5 or newer. You may need to install the supporting
102476 + headers explicitly in addition to the normal gcc package.
102477 +
102478 +config PAX_MEMORY_UDEREF
102479 + bool "Prevent invalid userland pointer dereference"
102480 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
102481 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
102482 + select PAX_PER_CPU_PGD if X86_64
102483 + help
102484 + By saying Y here the kernel will be prevented from dereferencing
102485 + userland pointers in contexts where the kernel expects only kernel
102486 + pointers. This is both a useful runtime debugging feature and a
102487 + security measure that prevents exploiting a class of kernel bugs.
102488 +
102489 + The tradeoff is that some virtualization solutions may experience
102490 + a huge slowdown and therefore you should not enable this feature
102491 + for kernels meant to run in such environments. Whether a given VM
102492 + solution is affected or not is best determined by simply trying it
102493 + out, the performance impact will be obvious right on boot as this
102494 + mechanism engages from very early on. A good rule of thumb is that
102495 + VMs running on CPUs without hardware virtualization support (i.e.,
102496 + the majority of IA-32 CPUs) will likely experience the slowdown.
102497 +
102498 + On X86_64 the kernel will make use of PCID support when available
102499 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
102500 + or performance impact. Pass pax_weakuderef on the kernel command
102501 + line to choose the latter.
102502 +
102503 +config PAX_REFCOUNT
102504 + bool "Prevent various kernel object reference counter overflows"
102505 + default y if GRKERNSEC_CONFIG_AUTO
102506 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
102507 + help
102508 + By saying Y here the kernel will detect and prevent overflowing
102509 + various (but not all) kinds of object reference counters. Such
102510 + overflows can normally occur due to bugs only and are often, if
102511 + not always, exploitable.
102512 +
102513 + The tradeoff is that data structures protected by an overflowed
102514 + refcount will never be freed and therefore will leak memory. Note
102515 + that this leak also happens even without this protection but in
102516 + that case the overflow can eventually trigger the freeing of the
102517 + data structure while it is still being used elsewhere, resulting
102518 + in the exploitable situation that this feature prevents.
102519 +
102520 + Since this has a negligible performance impact, you should enable
102521 + this feature.
102522 +
102523 +config PAX_CONSTIFY_PLUGIN
102524 + bool "Automatically constify eligible structures"
102525 + default y
102526 + depends on !UML && PAX_KERNEXEC
102527 + help
102528 + By saying Y here the compiler will automatically constify a class
102529 + of types that contain only function pointers. This reduces the
102530 + kernel's attack surface and also produces a better memory layout.
102531 +
102532 + Note that the implementation requires a gcc with plugin support,
102533 + i.e., gcc 4.5 or newer. You may need to install the supporting
102534 + headers explicitly in addition to the normal gcc package.
102535 +
102536 + Note that if some code really has to modify constified variables
102537 + then the source code will have to be patched to allow it. Examples
102538 + can be found in PaX itself (the no_const attribute) and for some
102539 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
102540 +
102541 +config PAX_USERCOPY
102542 + bool "Harden heap object copies between kernel and userland"
102543 + default y if GRKERNSEC_CONFIG_AUTO
102544 + depends on ARM || IA64 || PPC || SPARC || X86
102545 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
102546 + select PAX_USERCOPY_SLABS
102547 + help
102548 + By saying Y here the kernel will enforce the size of heap objects
102549 + when they are copied in either direction between the kernel and
102550 + userland, even if only a part of the heap object is copied.
102551 +
102552 + Specifically, this checking prevents information leaking from the
102553 + kernel heap during kernel to userland copies (if the kernel heap
102554 + object is otherwise fully initialized) and prevents kernel heap
102555 + overflows during userland to kernel copies.
102556 +
102557 + Note that the current implementation provides the strictest bounds
102558 + checks for the SLUB allocator.
102559 +
102560 + Enabling this option also enables per-slab cache protection against
102561 + data in a given cache being copied into/out of via userland
102562 + accessors. Though the whitelist of regions will be reduced over
102563 + time, it notably protects important data structures like task structs.
102564 +
102565 + If frame pointers are enabled on x86, this option will also restrict
102566 + copies into and out of the kernel stack to local variables within a
102567 + single frame.
102568 +
102569 + Since this has a negligible performance impact, you should enable
102570 + this feature.
102571 +
102572 +config PAX_USERCOPY_DEBUG
102573 + bool
102574 + depends on X86 && PAX_USERCOPY
102575 + default n
102576 +
102577 +config PAX_SIZE_OVERFLOW
102578 + bool "Prevent various integer overflows in function size parameters"
102579 + default y if GRKERNSEC_CONFIG_AUTO
102580 + depends on X86
102581 + help
102582 + By saying Y here the kernel recomputes expressions of function
102583 + arguments marked by a size_overflow attribute with double integer
102584 + precision (DImode/TImode for 32/64 bit integer types).
102585 +
102586 + The recomputed argument is checked against TYPE_MAX and an event
102587 + is logged on overflow and the triggering process is killed.
102588 +
102589 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
102590 +
102591 + Note that the implementation requires a gcc with plugin support,
102592 + i.e., gcc 4.5 or newer. You may need to install the supporting
102593 + headers explicitly in addition to the normal gcc package.
102594 +
102595 +config PAX_LATENT_ENTROPY
102596 + bool "Generate some entropy during boot and runtime"
102597 + default y if GRKERNSEC_CONFIG_AUTO
102598 + help
102599 + By saying Y here the kernel will instrument some kernel code to
102600 + extract some entropy from both original and artificially created
102601 + program state. This will help especially embedded systems where
102602 + there is little 'natural' source of entropy normally. The cost
102603 + is some slowdown of the boot process and fork and irq processing.
102604 +
102605 + When pax_extra_latent_entropy is passed on the kernel command line,
102606 + entropy will be extracted from up to the first 4GB of RAM while the
102607 + runtime memory allocator is being initialized. This costs even more
102608 + slowdown of the boot process.
102609 +
102610 + Note that the implementation requires a gcc with plugin support,
102611 + i.e., gcc 4.5 or newer. You may need to install the supporting
102612 + headers explicitly in addition to the normal gcc package.
102613 +
102614 + Note that entropy extracted this way is not cryptographically
102615 + secure!
102616 +
102617 +endmenu
102618 +
102619 +endmenu
102620 +
102621 +source grsecurity/Kconfig
102622 +
102623 +endmenu
102624 +
102625 +endmenu
102626 +
102627 source security/keys/Kconfig
102628
102629 config SECURITY_DMESG_RESTRICT
102630 @@ -103,7 +1056,7 @@ config INTEL_TXT
102631 config LSM_MMAP_MIN_ADDR
102632 int "Low address space for LSM to protect from user allocation"
102633 depends on SECURITY && SECURITY_SELINUX
102634 - default 32768 if ARM
102635 + default 32768 if ALPHA || ARM || PARISC || SPARC32
102636 default 65536
102637 help
102638 This is the portion of low virtual memory which should be protected
102639 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
102640 index 4257b7e..f0c9438 100644
102641 --- a/security/apparmor/lsm.c
102642 +++ b/security/apparmor/lsm.c
102643 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
102644 return error;
102645 }
102646
102647 -static struct security_operations apparmor_ops = {
102648 +static struct security_operations apparmor_ops __read_only = {
102649 .name = "apparmor",
102650
102651 .ptrace_access_check = apparmor_ptrace_access_check,
102652 diff --git a/security/commoncap.c b/security/commoncap.c
102653 index b9d613e..f68305c 100644
102654 --- a/security/commoncap.c
102655 +++ b/security/commoncap.c
102656 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
102657 return 0;
102658 }
102659
102660 +/* returns:
102661 + 1 for suid privilege
102662 + 2 for sgid privilege
102663 + 3 for fscap privilege
102664 +*/
102665 +int is_privileged_binary(const struct dentry *dentry)
102666 +{
102667 + struct cpu_vfs_cap_data capdata;
102668 + struct inode *inode = dentry->d_inode;
102669 +
102670 + if (!inode || S_ISDIR(inode->i_mode))
102671 + return 0;
102672 +
102673 + if (inode->i_mode & S_ISUID)
102674 + return 1;
102675 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
102676 + return 2;
102677 +
102678 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
102679 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
102680 + return 3;
102681 + }
102682 +
102683 + return 0;
102684 +}
102685 +
102686 /*
102687 * Attempt to get the on-exec apply capability sets for an executable file from
102688 * its xattrs and, if present, apply them to the proposed credentials being
102689 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
102690 const struct cred *cred = current_cred();
102691 kuid_t root_uid = make_kuid(cred->user_ns, 0);
102692
102693 + if (gr_acl_enable_at_secure())
102694 + return 1;
102695 +
102696 if (!uid_eq(cred->uid, root_uid)) {
102697 if (bprm->cap_effective)
102698 return 1;
102699 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
102700 index 0356e1d..72332ab 100644
102701 --- a/security/integrity/ima/ima.h
102702 +++ b/security/integrity/ima/ima.h
102703 @@ -118,8 +118,8 @@ int ima_init_template(void);
102704 extern spinlock_t ima_queue_lock;
102705
102706 struct ima_h_table {
102707 - atomic_long_t len; /* number of stored measurements in the list */
102708 - atomic_long_t violations;
102709 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
102710 + atomic_long_unchecked_t violations;
102711 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
102712 };
102713 extern struct ima_h_table ima_htable;
102714 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
102715 index c38bbce..f45133d 100644
102716 --- a/security/integrity/ima/ima_api.c
102717 +++ b/security/integrity/ima/ima_api.c
102718 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
102719 int result;
102720
102721 /* can overflow, only indicator */
102722 - atomic_long_inc(&ima_htable.violations);
102723 + atomic_long_inc_unchecked(&ima_htable.violations);
102724
102725 result = ima_alloc_init_template(NULL, file, filename,
102726 NULL, 0, &entry);
102727 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
102728 index db01125..61f6597 100644
102729 --- a/security/integrity/ima/ima_fs.c
102730 +++ b/security/integrity/ima/ima_fs.c
102731 @@ -28,12 +28,12 @@
102732 static int valid_policy = 1;
102733 #define TMPBUFLEN 12
102734 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
102735 - loff_t *ppos, atomic_long_t *val)
102736 + loff_t *ppos, atomic_long_unchecked_t *val)
102737 {
102738 char tmpbuf[TMPBUFLEN];
102739 ssize_t len;
102740
102741 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
102742 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
102743 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
102744 }
102745
102746 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
102747 index d85e997..6992813 100644
102748 --- a/security/integrity/ima/ima_queue.c
102749 +++ b/security/integrity/ima/ima_queue.c
102750 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
102751 INIT_LIST_HEAD(&qe->later);
102752 list_add_tail_rcu(&qe->later, &ima_measurements);
102753
102754 - atomic_long_inc(&ima_htable.len);
102755 + atomic_long_inc_unchecked(&ima_htable.len);
102756 key = ima_hash_key(entry->digest);
102757 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
102758 return 0;
102759 diff --git a/security/keys/compat.c b/security/keys/compat.c
102760 index bbd32c7..c60c927 100644
102761 --- a/security/keys/compat.c
102762 +++ b/security/keys/compat.c
102763 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
102764 if (ret == 0)
102765 goto no_payload_free;
102766
102767 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
102768 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
102769 err:
102770 if (iov != iovstack)
102771 kfree(iov);
102772 diff --git a/security/keys/internal.h b/security/keys/internal.h
102773 index 80b2aac..bb7ee65 100644
102774 --- a/security/keys/internal.h
102775 +++ b/security/keys/internal.h
102776 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
102777 extern long keyctl_invalidate_key(key_serial_t);
102778
102779 extern long keyctl_instantiate_key_common(key_serial_t,
102780 - const struct iovec *,
102781 + const struct iovec __user *,
102782 unsigned, size_t, key_serial_t);
102783 #ifdef CONFIG_PERSISTENT_KEYRINGS
102784 extern long keyctl_get_persistent(uid_t, key_serial_t);
102785 diff --git a/security/keys/key.c b/security/keys/key.c
102786 index 6e21c11..9ed67ca 100644
102787 --- a/security/keys/key.c
102788 +++ b/security/keys/key.c
102789 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
102790
102791 atomic_set(&key->usage, 1);
102792 init_rwsem(&key->sem);
102793 - lockdep_set_class(&key->sem, &type->lock_class);
102794 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
102795 key->index_key.type = type;
102796 key->user = user;
102797 key->quotalen = quotalen;
102798 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
102799 struct key_type *p;
102800 int ret;
102801
102802 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
102803 + pax_open_kernel();
102804 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
102805 + pax_close_kernel();
102806
102807 ret = -EEXIST;
102808 down_write(&key_types_sem);
102809 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
102810 }
102811
102812 /* store the type */
102813 - list_add(&ktype->link, &key_types_list);
102814 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
102815
102816 pr_notice("Key type %s registered\n", ktype->name);
102817 ret = 0;
102818 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
102819 void unregister_key_type(struct key_type *ktype)
102820 {
102821 down_write(&key_types_sem);
102822 - list_del_init(&ktype->link);
102823 + pax_list_del_init((struct list_head *)&ktype->link);
102824 downgrade_write(&key_types_sem);
102825 key_gc_keytype(ktype);
102826 pr_notice("Key type %s unregistered\n", ktype->name);
102827 @@ -1088,10 +1090,10 @@ void __init key_init(void)
102828 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
102829
102830 /* add the special key types */
102831 - list_add_tail(&key_type_keyring.link, &key_types_list);
102832 - list_add_tail(&key_type_dead.link, &key_types_list);
102833 - list_add_tail(&key_type_user.link, &key_types_list);
102834 - list_add_tail(&key_type_logon.link, &key_types_list);
102835 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
102836 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
102837 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
102838 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
102839
102840 /* record the root user tracking */
102841 rb_link_node(&root_key_user.node,
102842 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
102843 index cee72ce..e46074a 100644
102844 --- a/security/keys/keyctl.c
102845 +++ b/security/keys/keyctl.c
102846 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
102847 /*
102848 * Copy the iovec data from userspace
102849 */
102850 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
102851 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
102852 unsigned ioc)
102853 {
102854 for (; ioc > 0; ioc--) {
102855 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
102856 * If successful, 0 will be returned.
102857 */
102858 long keyctl_instantiate_key_common(key_serial_t id,
102859 - const struct iovec *payload_iov,
102860 + const struct iovec __user *payload_iov,
102861 unsigned ioc,
102862 size_t plen,
102863 key_serial_t ringid)
102864 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
102865 [0].iov_len = plen
102866 };
102867
102868 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
102869 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
102870 }
102871
102872 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
102873 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
102874 if (ret == 0)
102875 goto no_payload_free;
102876
102877 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
102878 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
102879 err:
102880 if (iov != iovstack)
102881 kfree(iov);
102882 diff --git a/security/min_addr.c b/security/min_addr.c
102883 index f728728..6457a0c 100644
102884 --- a/security/min_addr.c
102885 +++ b/security/min_addr.c
102886 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
102887 */
102888 static void update_mmap_min_addr(void)
102889 {
102890 +#ifndef SPARC
102891 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
102892 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
102893 mmap_min_addr = dac_mmap_min_addr;
102894 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
102895 #else
102896 mmap_min_addr = dac_mmap_min_addr;
102897 #endif
102898 +#endif
102899 }
102900
102901 /*
102902 diff --git a/security/security.c b/security/security.c
102903 index 15b6928..60d03ec 100644
102904 --- a/security/security.c
102905 +++ b/security/security.c
102906 @@ -33,8 +33,8 @@
102907 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
102908 CONFIG_DEFAULT_SECURITY;
102909
102910 -static struct security_operations *security_ops;
102911 -static struct security_operations default_security_ops = {
102912 +struct security_operations *security_ops __read_only;
102913 +struct security_operations default_security_ops __read_only = {
102914 .name = "default",
102915 };
102916
102917 @@ -73,11 +73,6 @@ int __init security_init(void)
102918 return 0;
102919 }
102920
102921 -void reset_security_ops(void)
102922 -{
102923 - security_ops = &default_security_ops;
102924 -}
102925 -
102926 /* Save user chosen LSM */
102927 static int __init choose_lsm(char *str)
102928 {
102929 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
102930 index fc3e662..7844c60 100644
102931 --- a/security/selinux/avc.c
102932 +++ b/security/selinux/avc.c
102933 @@ -59,7 +59,7 @@ struct avc_node {
102934 struct avc_cache {
102935 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
102936 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
102937 - atomic_t lru_hint; /* LRU hint for reclaim scan */
102938 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
102939 atomic_t active_nodes;
102940 u32 latest_notif; /* latest revocation notification */
102941 };
102942 @@ -167,7 +167,7 @@ void __init avc_init(void)
102943 spin_lock_init(&avc_cache.slots_lock[i]);
102944 }
102945 atomic_set(&avc_cache.active_nodes, 0);
102946 - atomic_set(&avc_cache.lru_hint, 0);
102947 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
102948
102949 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
102950 0, SLAB_PANIC, NULL);
102951 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
102952 spinlock_t *lock;
102953
102954 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
102955 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
102956 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
102957 head = &avc_cache.slots[hvalue];
102958 lock = &avc_cache.slots_lock[hvalue];
102959
102960 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
102961 index 57b0b49..402063e 100644
102962 --- a/security/selinux/hooks.c
102963 +++ b/security/selinux/hooks.c
102964 @@ -96,8 +96,6 @@
102965 #include "audit.h"
102966 #include "avc_ss.h"
102967
102968 -extern struct security_operations *security_ops;
102969 -
102970 /* SECMARK reference count */
102971 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
102972
102973 @@ -5745,7 +5743,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
102974
102975 #endif
102976
102977 -static struct security_operations selinux_ops = {
102978 +static struct security_operations selinux_ops __read_only = {
102979 .name = "selinux",
102980
102981 .ptrace_access_check = selinux_ptrace_access_check,
102982 @@ -6098,6 +6096,9 @@ static void selinux_nf_ip_exit(void)
102983 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
102984 static int selinux_disabled;
102985
102986 +extern struct security_operations *security_ops;
102987 +extern struct security_operations default_security_ops;
102988 +
102989 int selinux_disable(void)
102990 {
102991 if (ss_initialized) {
102992 @@ -6115,7 +6116,9 @@ int selinux_disable(void)
102993 selinux_disabled = 1;
102994 selinux_enabled = 0;
102995
102996 - reset_security_ops();
102997 + pax_open_kernel();
102998 + security_ops = &default_security_ops;
102999 + pax_close_kernel();
103000
103001 /* Try to destroy the avc node cache */
103002 avc_disable();
103003 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
103004 index 48c3cc9..8022cf7 100644
103005 --- a/security/selinux/include/xfrm.h
103006 +++ b/security/selinux/include/xfrm.h
103007 @@ -45,7 +45,7 @@ static inline void selinux_xfrm_notify_policyload(void)
103008 {
103009 struct net *net;
103010
103011 - atomic_inc(&flow_cache_genid);
103012 + atomic_inc_unchecked(&flow_cache_genid);
103013 rtnl_lock();
103014 for_each_net(net)
103015 rt_genid_bump_all(net);
103016 diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
103017 index d106733..539aadd 100644
103018 --- a/security/selinux/ss/services.c
103019 +++ b/security/selinux/ss/services.c
103020 @@ -1232,6 +1232,10 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
103021 struct context context;
103022 int rc = 0;
103023
103024 + /* An empty security context is never valid. */
103025 + if (!scontext_len)
103026 + return -EINVAL;
103027 +
103028 if (!ss_initialized) {
103029 int i;
103030
103031 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
103032 index b0be893..646bd94 100644
103033 --- a/security/smack/smack_lsm.c
103034 +++ b/security/smack/smack_lsm.c
103035 @@ -3731,7 +3731,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
103036 return 0;
103037 }
103038
103039 -struct security_operations smack_ops = {
103040 +struct security_operations smack_ops __read_only = {
103041 .name = "smack",
103042
103043 .ptrace_access_check = smack_ptrace_access_check,
103044 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
103045 index 390c646..f2f8db3 100644
103046 --- a/security/tomoyo/mount.c
103047 +++ b/security/tomoyo/mount.c
103048 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
103049 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
103050 need_dev = -1; /* dev_name is a directory */
103051 } else {
103052 + if (!capable(CAP_SYS_ADMIN)) {
103053 + error = -EPERM;
103054 + goto out;
103055 + }
103056 fstype = get_fs_type(type);
103057 if (!fstype) {
103058 error = -ENODEV;
103059 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
103060 index f0b756e..b129202 100644
103061 --- a/security/tomoyo/tomoyo.c
103062 +++ b/security/tomoyo/tomoyo.c
103063 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
103064 * tomoyo_security_ops is a "struct security_operations" which is used for
103065 * registering TOMOYO.
103066 */
103067 -static struct security_operations tomoyo_security_ops = {
103068 +static struct security_operations tomoyo_security_ops __read_only = {
103069 .name = "tomoyo",
103070 .cred_alloc_blank = tomoyo_cred_alloc_blank,
103071 .cred_prepare = tomoyo_cred_prepare,
103072 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
103073 index 20ef514..4182bed 100644
103074 --- a/security/yama/Kconfig
103075 +++ b/security/yama/Kconfig
103076 @@ -1,6 +1,6 @@
103077 config SECURITY_YAMA
103078 bool "Yama support"
103079 - depends on SECURITY
103080 + depends on SECURITY && !GRKERNSEC
103081 select SECURITYFS
103082 select SECURITY_PATH
103083 default n
103084 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
103085 index 13c88fbc..f8c115e 100644
103086 --- a/security/yama/yama_lsm.c
103087 +++ b/security/yama/yama_lsm.c
103088 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
103089 }
103090
103091 #ifndef CONFIG_SECURITY_YAMA_STACKED
103092 -static struct security_operations yama_ops = {
103093 +static struct security_operations yama_ops __read_only = {
103094 .name = "yama",
103095
103096 .ptrace_access_check = yama_ptrace_access_check,
103097 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
103098 #endif
103099
103100 #ifdef CONFIG_SYSCTL
103101 +static int zero __read_only;
103102 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
103103 +
103104 static int yama_dointvec_minmax(struct ctl_table *table, int write,
103105 void __user *buffer, size_t *lenp, loff_t *ppos)
103106 {
103107 - int rc;
103108 + ctl_table_no_const yama_table;
103109
103110 if (write && !capable(CAP_SYS_PTRACE))
103111 return -EPERM;
103112
103113 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
103114 - if (rc)
103115 - return rc;
103116 -
103117 + yama_table = *table;
103118 /* Lock the max value if it ever gets set. */
103119 - if (write && *(int *)table->data == *(int *)table->extra2)
103120 - table->extra1 = table->extra2;
103121 -
103122 - return rc;
103123 + if (ptrace_scope == max_scope)
103124 + yama_table.extra1 = &max_scope;
103125 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
103126 }
103127
103128 -static int zero;
103129 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
103130 -
103131 struct ctl_path yama_sysctl_path[] = {
103132 { .procname = "kernel", },
103133 { .procname = "yama", },
103134 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
103135 index 4cedc69..e59d8a3 100644
103136 --- a/sound/aoa/codecs/onyx.c
103137 +++ b/sound/aoa/codecs/onyx.c
103138 @@ -54,7 +54,7 @@ struct onyx {
103139 spdif_locked:1,
103140 analog_locked:1,
103141 original_mute:2;
103142 - int open_count;
103143 + local_t open_count;
103144 struct codec_info *codec_info;
103145
103146 /* mutex serializes concurrent access to the device
103147 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
103148 struct onyx *onyx = cii->codec_data;
103149
103150 mutex_lock(&onyx->mutex);
103151 - onyx->open_count++;
103152 + local_inc(&onyx->open_count);
103153 mutex_unlock(&onyx->mutex);
103154
103155 return 0;
103156 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
103157 struct onyx *onyx = cii->codec_data;
103158
103159 mutex_lock(&onyx->mutex);
103160 - onyx->open_count--;
103161 - if (!onyx->open_count)
103162 + if (local_dec_and_test(&onyx->open_count))
103163 onyx->spdif_locked = onyx->analog_locked = 0;
103164 mutex_unlock(&onyx->mutex);
103165
103166 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
103167 index ffd2025..df062c9 100644
103168 --- a/sound/aoa/codecs/onyx.h
103169 +++ b/sound/aoa/codecs/onyx.h
103170 @@ -11,6 +11,7 @@
103171 #include <linux/i2c.h>
103172 #include <asm/pmac_low_i2c.h>
103173 #include <asm/prom.h>
103174 +#include <asm/local.h>
103175
103176 /* PCM3052 register definitions */
103177
103178 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
103179 index 4c1cc51..16040040 100644
103180 --- a/sound/core/oss/pcm_oss.c
103181 +++ b/sound/core/oss/pcm_oss.c
103182 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
103183 if (in_kernel) {
103184 mm_segment_t fs;
103185 fs = snd_enter_user();
103186 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
103187 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
103188 snd_leave_user(fs);
103189 } else {
103190 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
103191 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
103192 }
103193 if (ret != -EPIPE && ret != -ESTRPIPE)
103194 break;
103195 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
103196 if (in_kernel) {
103197 mm_segment_t fs;
103198 fs = snd_enter_user();
103199 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
103200 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
103201 snd_leave_user(fs);
103202 } else {
103203 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
103204 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
103205 }
103206 if (ret == -EPIPE) {
103207 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
103208 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
103209 struct snd_pcm_plugin_channel *channels;
103210 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
103211 if (!in_kernel) {
103212 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
103213 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
103214 return -EFAULT;
103215 buf = runtime->oss.buffer;
103216 }
103217 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
103218 }
103219 } else {
103220 tmp = snd_pcm_oss_write2(substream,
103221 - (const char __force *)buf,
103222 + (const char __force_kernel *)buf,
103223 runtime->oss.period_bytes, 0);
103224 if (tmp <= 0)
103225 goto err;
103226 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
103227 struct snd_pcm_runtime *runtime = substream->runtime;
103228 snd_pcm_sframes_t frames, frames1;
103229 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
103230 - char __user *final_dst = (char __force __user *)buf;
103231 + char __user *final_dst = (char __force_user *)buf;
103232 if (runtime->oss.plugin_first) {
103233 struct snd_pcm_plugin_channel *channels;
103234 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
103235 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
103236 xfer += tmp;
103237 runtime->oss.buffer_used -= tmp;
103238 } else {
103239 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
103240 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
103241 runtime->oss.period_bytes, 0);
103242 if (tmp <= 0)
103243 goto err;
103244 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
103245 size1);
103246 size1 /= runtime->channels; /* frames */
103247 fs = snd_enter_user();
103248 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
103249 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
103250 snd_leave_user(fs);
103251 }
103252 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
103253 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
103254 index af49721..e85058e 100644
103255 --- a/sound/core/pcm_compat.c
103256 +++ b/sound/core/pcm_compat.c
103257 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
103258 int err;
103259
103260 fs = snd_enter_user();
103261 - err = snd_pcm_delay(substream, &delay);
103262 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
103263 snd_leave_user(fs);
103264 if (err < 0)
103265 return err;
103266 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
103267 index 01a5e05..c6bb425 100644
103268 --- a/sound/core/pcm_native.c
103269 +++ b/sound/core/pcm_native.c
103270 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
103271 switch (substream->stream) {
103272 case SNDRV_PCM_STREAM_PLAYBACK:
103273 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
103274 - (void __user *)arg);
103275 + (void __force_user *)arg);
103276 break;
103277 case SNDRV_PCM_STREAM_CAPTURE:
103278 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
103279 - (void __user *)arg);
103280 + (void __force_user *)arg);
103281 break;
103282 default:
103283 result = -EINVAL;
103284 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
103285 index 8d4d5e8..fdd0826 100644
103286 --- a/sound/core/seq/oss/seq_oss.c
103287 +++ b/sound/core/seq/oss/seq_oss.c
103288 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
103289 {
103290 int rc;
103291 static struct snd_seq_dev_ops ops = {
103292 - snd_seq_oss_synth_register,
103293 - snd_seq_oss_synth_unregister,
103294 + .init_device = snd_seq_oss_synth_register,
103295 + .free_device = snd_seq_oss_synth_unregister,
103296 };
103297
103298 snd_seq_autoload_lock();
103299 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
103300 index 040c60e..989a19a 100644
103301 --- a/sound/core/seq/seq_device.c
103302 +++ b/sound/core/seq/seq_device.c
103303 @@ -64,7 +64,7 @@ struct ops_list {
103304 int argsize; /* argument size */
103305
103306 /* operators */
103307 - struct snd_seq_dev_ops ops;
103308 + struct snd_seq_dev_ops *ops;
103309
103310 /* registered devices */
103311 struct list_head dev_list; /* list of devices */
103312 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
103313
103314 mutex_lock(&ops->reg_mutex);
103315 /* copy driver operators */
103316 - ops->ops = *entry;
103317 + ops->ops = entry;
103318 ops->driver |= DRIVER_LOADED;
103319 ops->argsize = argsize;
103320
103321 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
103322 dev->name, ops->id, ops->argsize, dev->argsize);
103323 return -EINVAL;
103324 }
103325 - if (ops->ops.init_device(dev) >= 0) {
103326 + if (ops->ops->init_device(dev) >= 0) {
103327 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
103328 ops->num_init_devices++;
103329 } else {
103330 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
103331 dev->name, ops->id, ops->argsize, dev->argsize);
103332 return -EINVAL;
103333 }
103334 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
103335 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
103336 dev->status = SNDRV_SEQ_DEVICE_FREE;
103337 dev->driver_data = NULL;
103338 ops->num_init_devices--;
103339 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
103340 index 64069db..3c6d392 100644
103341 --- a/sound/core/seq/seq_midi.c
103342 +++ b/sound/core/seq/seq_midi.c
103343 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
103344 static int __init alsa_seq_midi_init(void)
103345 {
103346 static struct snd_seq_dev_ops ops = {
103347 - snd_seq_midisynth_register_port,
103348 - snd_seq_midisynth_unregister_port,
103349 + .init_device = snd_seq_midisynth_register_port,
103350 + .free_device = snd_seq_midisynth_unregister_port,
103351 };
103352 memset(&synths, 0, sizeof(synths));
103353 snd_seq_autoload_lock();
103354 diff --git a/sound/core/sound.c b/sound/core/sound.c
103355 index 437c25e..cd040ab 100644
103356 --- a/sound/core/sound.c
103357 +++ b/sound/core/sound.c
103358 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
103359 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
103360 default: return;
103361 }
103362 - request_module(str);
103363 + request_module("%s", str);
103364 }
103365
103366 #endif /* modular kernel */
103367 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
103368 index 4e0dd22..7a1f32c 100644
103369 --- a/sound/drivers/mts64.c
103370 +++ b/sound/drivers/mts64.c
103371 @@ -29,6 +29,7 @@
103372 #include <sound/initval.h>
103373 #include <sound/rawmidi.h>
103374 #include <sound/control.h>
103375 +#include <asm/local.h>
103376
103377 #define CARD_NAME "Miditerminal 4140"
103378 #define DRIVER_NAME "MTS64"
103379 @@ -67,7 +68,7 @@ struct mts64 {
103380 struct pardevice *pardev;
103381 int pardev_claimed;
103382
103383 - int open_count;
103384 + local_t open_count;
103385 int current_midi_output_port;
103386 int current_midi_input_port;
103387 u8 mode[MTS64_NUM_INPUT_PORTS];
103388 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
103389 {
103390 struct mts64 *mts = substream->rmidi->private_data;
103391
103392 - if (mts->open_count == 0) {
103393 + if (local_read(&mts->open_count) == 0) {
103394 /* We don't need a spinlock here, because this is just called
103395 if the device has not been opened before.
103396 So there aren't any IRQs from the device */
103397 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
103398
103399 msleep(50);
103400 }
103401 - ++(mts->open_count);
103402 + local_inc(&mts->open_count);
103403
103404 return 0;
103405 }
103406 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
103407 struct mts64 *mts = substream->rmidi->private_data;
103408 unsigned long flags;
103409
103410 - --(mts->open_count);
103411 - if (mts->open_count == 0) {
103412 + if (local_dec_return(&mts->open_count) == 0) {
103413 /* We need the spinlock_irqsave here because we can still
103414 have IRQs at this point */
103415 spin_lock_irqsave(&mts->lock, flags);
103416 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
103417
103418 msleep(500);
103419
103420 - } else if (mts->open_count < 0)
103421 - mts->open_count = 0;
103422 + } else if (local_read(&mts->open_count) < 0)
103423 + local_set(&mts->open_count, 0);
103424
103425 return 0;
103426 }
103427 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
103428 index 6839953..7a0f4b9 100644
103429 --- a/sound/drivers/opl3/opl3_seq.c
103430 +++ b/sound/drivers/opl3/opl3_seq.c
103431 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
103432 {
103433 static struct snd_seq_dev_ops ops =
103434 {
103435 - snd_opl3_seq_new_device,
103436 - snd_opl3_seq_delete_device
103437 + .init_device = snd_opl3_seq_new_device,
103438 + .free_device = snd_opl3_seq_delete_device
103439 };
103440
103441 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
103442 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
103443 index b953fb4..1999c01 100644
103444 --- a/sound/drivers/opl4/opl4_lib.c
103445 +++ b/sound/drivers/opl4/opl4_lib.c
103446 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
103447 MODULE_DESCRIPTION("OPL4 driver");
103448 MODULE_LICENSE("GPL");
103449
103450 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
103451 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
103452 {
103453 int timeout = 10;
103454 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
103455 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
103456 index 9919769..d7de36c 100644
103457 --- a/sound/drivers/opl4/opl4_seq.c
103458 +++ b/sound/drivers/opl4/opl4_seq.c
103459 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
103460 static int __init alsa_opl4_synth_init(void)
103461 {
103462 static struct snd_seq_dev_ops ops = {
103463 - snd_opl4_seq_new_device,
103464 - snd_opl4_seq_delete_device
103465 + .init_device = snd_opl4_seq_new_device,
103466 + .free_device = snd_opl4_seq_delete_device
103467 };
103468
103469 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
103470 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
103471 index 991018d..8984740 100644
103472 --- a/sound/drivers/portman2x4.c
103473 +++ b/sound/drivers/portman2x4.c
103474 @@ -48,6 +48,7 @@
103475 #include <sound/initval.h>
103476 #include <sound/rawmidi.h>
103477 #include <sound/control.h>
103478 +#include <asm/local.h>
103479
103480 #define CARD_NAME "Portman 2x4"
103481 #define DRIVER_NAME "portman"
103482 @@ -85,7 +86,7 @@ struct portman {
103483 struct pardevice *pardev;
103484 int pardev_claimed;
103485
103486 - int open_count;
103487 + local_t open_count;
103488 int mode[PORTMAN_NUM_INPUT_PORTS];
103489 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
103490 };
103491 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
103492 index 9048777..2d8b1fc 100644
103493 --- a/sound/firewire/amdtp.c
103494 +++ b/sound/firewire/amdtp.c
103495 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
103496 ptr = s->pcm_buffer_pointer + data_blocks;
103497 if (ptr >= pcm->runtime->buffer_size)
103498 ptr -= pcm->runtime->buffer_size;
103499 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
103500 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
103501
103502 s->pcm_period_pointer += data_blocks;
103503 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
103504 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
103505 */
103506 void amdtp_out_stream_update(struct amdtp_out_stream *s)
103507 {
103508 - ACCESS_ONCE(s->source_node_id_field) =
103509 + ACCESS_ONCE_RW(s->source_node_id_field) =
103510 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
103511 }
103512 EXPORT_SYMBOL(amdtp_out_stream_update);
103513 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
103514 index 2746ecd..c35dedd 100644
103515 --- a/sound/firewire/amdtp.h
103516 +++ b/sound/firewire/amdtp.h
103517 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
103518 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
103519 struct snd_pcm_substream *pcm)
103520 {
103521 - ACCESS_ONCE(s->pcm) = pcm;
103522 + ACCESS_ONCE_RW(s->pcm) = pcm;
103523 }
103524
103525 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
103526 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
103527 index fd42e6b..c041971 100644
103528 --- a/sound/firewire/isight.c
103529 +++ b/sound/firewire/isight.c
103530 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
103531 ptr += count;
103532 if (ptr >= runtime->buffer_size)
103533 ptr -= runtime->buffer_size;
103534 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
103535 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
103536
103537 isight->period_counter += count;
103538 if (isight->period_counter >= runtime->period_size) {
103539 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
103540 if (err < 0)
103541 return err;
103542
103543 - ACCESS_ONCE(isight->pcm_active) = true;
103544 + ACCESS_ONCE_RW(isight->pcm_active) = true;
103545
103546 return 0;
103547 }
103548 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
103549 {
103550 struct isight *isight = substream->private_data;
103551
103552 - ACCESS_ONCE(isight->pcm_active) = false;
103553 + ACCESS_ONCE_RW(isight->pcm_active) = false;
103554
103555 mutex_lock(&isight->mutex);
103556 isight_stop_streaming(isight);
103557 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
103558
103559 switch (cmd) {
103560 case SNDRV_PCM_TRIGGER_START:
103561 - ACCESS_ONCE(isight->pcm_running) = true;
103562 + ACCESS_ONCE_RW(isight->pcm_running) = true;
103563 break;
103564 case SNDRV_PCM_TRIGGER_STOP:
103565 - ACCESS_ONCE(isight->pcm_running) = false;
103566 + ACCESS_ONCE_RW(isight->pcm_running) = false;
103567 break;
103568 default:
103569 return -EINVAL;
103570 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
103571 index 858023c..83b3d3c 100644
103572 --- a/sound/firewire/scs1x.c
103573 +++ b/sound/firewire/scs1x.c
103574 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
103575 {
103576 struct scs *scs = stream->rmidi->private_data;
103577
103578 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
103579 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
103580 if (up) {
103581 scs->output_idle = false;
103582 tasklet_schedule(&scs->tasklet);
103583 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
103584 {
103585 struct scs *scs = stream->rmidi->private_data;
103586
103587 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
103588 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
103589 }
103590
103591 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
103592 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
103593
103594 snd_card_disconnect(scs->card);
103595
103596 - ACCESS_ONCE(scs->output) = NULL;
103597 - ACCESS_ONCE(scs->input) = NULL;
103598 + ACCESS_ONCE_RW(scs->output) = NULL;
103599 + ACCESS_ONCE_RW(scs->input) = NULL;
103600
103601 wait_event(scs->idle_wait, scs->output_idle);
103602
103603 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
103604 index 4e3fcfb..ab45a9d 100644
103605 --- a/sound/isa/sb/emu8000_synth.c
103606 +++ b/sound/isa/sb/emu8000_synth.c
103607 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
103608 {
103609
103610 static struct snd_seq_dev_ops ops = {
103611 - snd_emu8000_new_device,
103612 - snd_emu8000_delete_device,
103613 + .init_device = snd_emu8000_new_device,
103614 + .free_device = snd_emu8000_delete_device,
103615 };
103616 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
103617 sizeof(struct snd_emu8000*));
103618 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
103619 index 048439a..3be9f6f 100644
103620 --- a/sound/oss/sb_audio.c
103621 +++ b/sound/oss/sb_audio.c
103622 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
103623 buf16 = (signed short *)(localbuf + localoffs);
103624 while (c)
103625 {
103626 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
103627 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
103628 if (copy_from_user(lbuf8,
103629 userbuf+useroffs + p,
103630 locallen))
103631 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
103632 index 7d8803a..559f8d0 100644
103633 --- a/sound/oss/swarm_cs4297a.c
103634 +++ b/sound/oss/swarm_cs4297a.c
103635 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
103636 {
103637 struct cs4297a_state *s;
103638 u32 pwr, id;
103639 - mm_segment_t fs;
103640 int rval;
103641 #ifndef CONFIG_BCM_CS4297A_CSWARM
103642 u64 cfg;
103643 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
103644 if (!rval) {
103645 char *sb1250_duart_present;
103646
103647 +#if 0
103648 + mm_segment_t fs;
103649 fs = get_fs();
103650 set_fs(KERNEL_DS);
103651 -#if 0
103652 val = SOUND_MASK_LINE;
103653 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
103654 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
103655 val = initvol[i].vol;
103656 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
103657 }
103658 + set_fs(fs);
103659 // cs4297a_write_ac97(s, 0x18, 0x0808);
103660 #else
103661 // cs4297a_write_ac97(s, 0x5e, 0x180);
103662 cs4297a_write_ac97(s, 0x02, 0x0808);
103663 cs4297a_write_ac97(s, 0x18, 0x0808);
103664 #endif
103665 - set_fs(fs);
103666
103667 list_add(&s->list, &cs4297a_devs);
103668
103669 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
103670 index 4c41c90..37f3631 100644
103671 --- a/sound/pci/emu10k1/emu10k1_synth.c
103672 +++ b/sound/pci/emu10k1/emu10k1_synth.c
103673 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
103674 {
103675
103676 static struct snd_seq_dev_ops ops = {
103677 - snd_emu10k1_synth_new_device,
103678 - snd_emu10k1_synth_delete_device,
103679 + .init_device = snd_emu10k1_synth_new_device,
103680 + .free_device = snd_emu10k1_synth_delete_device,
103681 };
103682 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
103683 sizeof(struct snd_emu10k1_synth_arg));
103684 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
103685 index 69178c4..4493d52 100644
103686 --- a/sound/pci/hda/hda_codec.c
103687 +++ b/sound/pci/hda/hda_codec.c
103688 @@ -976,14 +976,10 @@ find_codec_preset(struct hda_codec *codec)
103689 mutex_unlock(&preset_mutex);
103690
103691 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
103692 - char name[32];
103693 if (!mod_requested)
103694 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
103695 - codec->vendor_id);
103696 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
103697 else
103698 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
103699 - (codec->vendor_id >> 16) & 0xffff);
103700 - request_module(name);
103701 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
103702 mod_requested++;
103703 goto again;
103704 }
103705 @@ -2668,7 +2664,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
103706 /* FIXME: set_fs() hack for obtaining user-space TLV data */
103707 mm_segment_t fs = get_fs();
103708 set_fs(get_ds());
103709 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
103710 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
103711 tlv = _tlv;
103712 set_fs(fs);
103713 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
103714 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
103715 index 4631a23..001ae57 100644
103716 --- a/sound/pci/ymfpci/ymfpci.h
103717 +++ b/sound/pci/ymfpci/ymfpci.h
103718 @@ -358,7 +358,7 @@ struct snd_ymfpci {
103719 spinlock_t reg_lock;
103720 spinlock_t voice_lock;
103721 wait_queue_head_t interrupt_sleep;
103722 - atomic_t interrupt_sleep_count;
103723 + atomic_unchecked_t interrupt_sleep_count;
103724 struct snd_info_entry *proc_entry;
103725 const struct firmware *dsp_microcode;
103726 const struct firmware *controller_microcode;
103727 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
103728 index d591c15..8cb8f94 100644
103729 --- a/sound/pci/ymfpci/ymfpci_main.c
103730 +++ b/sound/pci/ymfpci/ymfpci_main.c
103731 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
103732 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
103733 break;
103734 }
103735 - if (atomic_read(&chip->interrupt_sleep_count)) {
103736 - atomic_set(&chip->interrupt_sleep_count, 0);
103737 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
103738 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103739 wake_up(&chip->interrupt_sleep);
103740 }
103741 __end:
103742 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
103743 continue;
103744 init_waitqueue_entry(&wait, current);
103745 add_wait_queue(&chip->interrupt_sleep, &wait);
103746 - atomic_inc(&chip->interrupt_sleep_count);
103747 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
103748 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
103749 remove_wait_queue(&chip->interrupt_sleep, &wait);
103750 }
103751 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
103752 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
103753 spin_unlock(&chip->reg_lock);
103754
103755 - if (atomic_read(&chip->interrupt_sleep_count)) {
103756 - atomic_set(&chip->interrupt_sleep_count, 0);
103757 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
103758 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103759 wake_up(&chip->interrupt_sleep);
103760 }
103761 }
103762 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
103763 spin_lock_init(&chip->reg_lock);
103764 spin_lock_init(&chip->voice_lock);
103765 init_waitqueue_head(&chip->interrupt_sleep);
103766 - atomic_set(&chip->interrupt_sleep_count, 0);
103767 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103768 chip->card = card;
103769 chip->pci = pci;
103770 chip->irq = -1;
103771 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
103772 index 35e2773..6d6ceee 100644
103773 --- a/sound/soc/fsl/fsl_ssi.c
103774 +++ b/sound/soc/fsl/fsl_ssi.c
103775 @@ -857,7 +857,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
103776 {
103777 struct fsl_ssi_private *ssi_private;
103778 int ret = 0;
103779 - struct device_attribute *dev_attr = NULL;
103780 + device_attribute_no_const *dev_attr = NULL;
103781 struct device_node *np = pdev->dev.of_node;
103782 const char *p, *sprop;
103783 const uint32_t *iprop;
103784 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
103785 index a66783e..ed1d791 100644
103786 --- a/sound/soc/soc-core.c
103787 +++ b/sound/soc/soc-core.c
103788 @@ -2253,8 +2253,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
103789 if (ret)
103790 return ret;
103791
103792 - ops->warm_reset = snd_soc_ac97_warm_reset;
103793 - ops->reset = snd_soc_ac97_reset;
103794 + pax_open_kernel();
103795 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
103796 + *(void **)&ops->reset = snd_soc_ac97_reset;
103797 + pax_close_kernel();
103798
103799 snd_ac97_rst_cfg = cfg;
103800 return 0;
103801 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
103802 index 7778b8e..3d619fc 100644
103803 --- a/sound/synth/emux/emux_seq.c
103804 +++ b/sound/synth/emux/emux_seq.c
103805 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
103806 * MIDI emulation operators
103807 */
103808 static struct snd_midi_op emux_ops = {
103809 - snd_emux_note_on,
103810 - snd_emux_note_off,
103811 - snd_emux_key_press,
103812 - snd_emux_terminate_note,
103813 - snd_emux_control,
103814 - snd_emux_nrpn,
103815 - snd_emux_sysex,
103816 + .note_on = snd_emux_note_on,
103817 + .note_off = snd_emux_note_off,
103818 + .key_press = snd_emux_key_press,
103819 + .note_terminate = snd_emux_terminate_note,
103820 + .control = snd_emux_control,
103821 + .nrpn = snd_emux_nrpn,
103822 + .sysex = snd_emux_sysex,
103823 };
103824
103825
103826 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
103827 new file mode 100644
103828 index 0000000..4c2c45c
103829 --- /dev/null
103830 +++ b/tools/gcc/.gitignore
103831 @@ -0,0 +1,2 @@
103832 +randomize_layout_seed.h
103833 +size_overflow_hash.h
103834 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
103835 new file mode 100644
103836 index 0000000..0d1d9d3
103837 --- /dev/null
103838 +++ b/tools/gcc/Makefile
103839 @@ -0,0 +1,54 @@
103840 +#CC := gcc
103841 +#PLUGIN_SOURCE_FILES := pax_plugin.c
103842 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
103843 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
103844 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
103845 +
103846 +ifeq ($(PLUGINCC),$(HOSTCC))
103847 +HOSTLIBS := hostlibs
103848 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
103849 +else
103850 +HOSTLIBS := hostcxxlibs
103851 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter
103852 +endif
103853 +
103854 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
103855 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
103856 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
103857 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
103858 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
103859 +$(HOSTLIBS)-y += colorize_plugin.so
103860 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
103861 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
103862 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
103863 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
103864 +
103865 +always := $($(HOSTLIBS)-y)
103866 +
103867 +constify_plugin-objs := constify_plugin.o
103868 +stackleak_plugin-objs := stackleak_plugin.o
103869 +kallocstat_plugin-objs := kallocstat_plugin.o
103870 +kernexec_plugin-objs := kernexec_plugin.o
103871 +checker_plugin-objs := checker_plugin.o
103872 +colorize_plugin-objs := colorize_plugin.o
103873 +size_overflow_plugin-objs := size_overflow_plugin.o
103874 +latent_entropy_plugin-objs := latent_entropy_plugin.o
103875 +structleak_plugin-objs := structleak_plugin.o
103876 +randomize_layout_plugin-objs := randomize_layout_plugin.o
103877 +
103878 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
103879 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
103880 +
103881 +quiet_cmd_build_size_overflow_hash = GENHASH $@
103882 + cmd_build_size_overflow_hash = \
103883 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
103884 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
103885 + $(call if_changed,build_size_overflow_hash)
103886 +
103887 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
103888 + cmd_create_randomize_layout_seed = \
103889 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
103890 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
103891 + $(call if_changed,create_randomize_layout_seed)
103892 +
103893 +targets += size_overflow_hash.h randomize_layout_seed.h randomize_layout_hash.h
103894 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
103895 new file mode 100644
103896 index 0000000..5452feea
103897 --- /dev/null
103898 +++ b/tools/gcc/checker_plugin.c
103899 @@ -0,0 +1,150 @@
103900 +/*
103901 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
103902 + * Licensed under the GPL v2
103903 + *
103904 + * Note: the choice of the license means that the compilation process is
103905 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
103906 + * but for the kernel it doesn't matter since it doesn't link against
103907 + * any of the gcc libraries
103908 + *
103909 + * gcc plugin to implement various sparse (source code checker) features
103910 + *
103911 + * TODO:
103912 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
103913 + *
103914 + * BUGS:
103915 + * - none known
103916 + */
103917 +
103918 +#include "gcc-common.h"
103919 +
103920 +extern void c_register_addr_space (const char *str, addr_space_t as);
103921 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
103922 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
103923 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
103924 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
103925 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
103926 +
103927 +int plugin_is_GPL_compatible;
103928 +
103929 +static struct plugin_info checker_plugin_info = {
103930 + .version = "201304082245",
103931 + .help = NULL,
103932 +};
103933 +
103934 +#define ADDR_SPACE_KERNEL 0
103935 +#define ADDR_SPACE_FORCE_KERNEL 1
103936 +#define ADDR_SPACE_USER 2
103937 +#define ADDR_SPACE_FORCE_USER 3
103938 +#define ADDR_SPACE_IOMEM 0
103939 +#define ADDR_SPACE_FORCE_IOMEM 0
103940 +#define ADDR_SPACE_PERCPU 0
103941 +#define ADDR_SPACE_FORCE_PERCPU 0
103942 +#define ADDR_SPACE_RCU 0
103943 +#define ADDR_SPACE_FORCE_RCU 0
103944 +
103945 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
103946 +{
103947 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
103948 +}
103949 +
103950 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
103951 +{
103952 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
103953 +}
103954 +
103955 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
103956 +{
103957 + return default_addr_space_valid_pointer_mode(mode, as);
103958 +}
103959 +
103960 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
103961 +{
103962 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
103963 +}
103964 +
103965 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
103966 +{
103967 + return default_addr_space_legitimize_address(x, oldx, mode, as);
103968 +}
103969 +
103970 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
103971 +{
103972 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
103973 + return true;
103974 +
103975 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
103976 + return true;
103977 +
103978 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
103979 + return true;
103980 +
103981 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
103982 + return true;
103983 +
103984 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
103985 + return true;
103986 +
103987 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
103988 + return true;
103989 +
103990 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
103991 + return true;
103992 +
103993 + return subset == superset;
103994 +}
103995 +
103996 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
103997 +{
103998 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
103999 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
104000 +
104001 + return op;
104002 +}
104003 +
104004 +static void register_checker_address_spaces(void *event_data, void *data)
104005 +{
104006 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
104007 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
104008 + c_register_addr_space("__user", ADDR_SPACE_USER);
104009 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
104010 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
104011 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
104012 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
104013 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
104014 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
104015 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
104016 +
104017 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
104018 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
104019 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
104020 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
104021 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
104022 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
104023 + targetm.addr_space.convert = checker_addr_space_convert;
104024 +}
104025 +
104026 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104027 +{
104028 + const char * const plugin_name = plugin_info->base_name;
104029 + const int argc = plugin_info->argc;
104030 + const struct plugin_argument * const argv = plugin_info->argv;
104031 + int i;
104032 +
104033 + if (!plugin_default_version_check(version, &gcc_version)) {
104034 + error(G_("incompatible gcc/plugin versions"));
104035 + return 1;
104036 + }
104037 +
104038 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
104039 +
104040 + for (i = 0; i < argc; ++i)
104041 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
104042 +
104043 + if (TARGET_64BIT == 0)
104044 + return 0;
104045 +
104046 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
104047 +
104048 + return 0;
104049 +}
104050 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
104051 new file mode 100644
104052 index 0000000..06dcfda
104053 --- /dev/null
104054 +++ b/tools/gcc/colorize_plugin.c
104055 @@ -0,0 +1,169 @@
104056 +/*
104057 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
104058 + * Licensed under the GPL v2
104059 + *
104060 + * Note: the choice of the license means that the compilation process is
104061 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
104062 + * but for the kernel it doesn't matter since it doesn't link against
104063 + * any of the gcc libraries
104064 + *
104065 + * gcc plugin to colorize diagnostic output
104066 + *
104067 + */
104068 +
104069 +#include "gcc-common.h"
104070 +
104071 +int plugin_is_GPL_compatible;
104072 +
104073 +static struct plugin_info colorize_plugin_info = {
104074 + .version = "201401260140",
104075 + .help = NULL,
104076 +};
104077 +
104078 +#define GREEN "\033[32m\033[2m"
104079 +#define LIGHTGREEN "\033[32m\033[1m"
104080 +#define YELLOW "\033[33m\033[2m"
104081 +#define LIGHTYELLOW "\033[33m\033[1m"
104082 +#define RED "\033[31m\033[2m"
104083 +#define LIGHTRED "\033[31m\033[1m"
104084 +#define BLUE "\033[34m\033[2m"
104085 +#define LIGHTBLUE "\033[34m\033[1m"
104086 +#define BRIGHT "\033[m\033[1m"
104087 +#define NORMAL "\033[m"
104088 +
104089 +static diagnostic_starter_fn old_starter;
104090 +static diagnostic_finalizer_fn old_finalizer;
104091 +
104092 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
104093 +{
104094 + const char *color;
104095 + char *newprefix;
104096 +
104097 + switch (diagnostic->kind) {
104098 + case DK_NOTE:
104099 + color = LIGHTBLUE;
104100 + break;
104101 +
104102 + case DK_PEDWARN:
104103 + case DK_WARNING:
104104 + color = LIGHTYELLOW;
104105 + break;
104106 +
104107 + case DK_ERROR:
104108 + case DK_FATAL:
104109 + case DK_ICE:
104110 + case DK_PERMERROR:
104111 + case DK_SORRY:
104112 + color = LIGHTRED;
104113 + break;
104114 +
104115 + default:
104116 + color = NORMAL;
104117 + }
104118 +
104119 + old_starter(context, diagnostic);
104120 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
104121 + return;
104122 + pp_destroy_prefix(context->printer);
104123 + pp_set_prefix(context->printer, newprefix);
104124 +}
104125 +
104126 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
104127 +{
104128 + old_finalizer(context, diagnostic);
104129 +}
104130 +
104131 +static void colorize_arm(void)
104132 +{
104133 + old_starter = diagnostic_starter(global_dc);
104134 + old_finalizer = diagnostic_finalizer(global_dc);
104135 +
104136 + diagnostic_starter(global_dc) = start_colorize;
104137 + diagnostic_finalizer(global_dc) = finalize_colorize;
104138 +}
104139 +
104140 +static unsigned int execute_colorize_rearm(void)
104141 +{
104142 + if (diagnostic_starter(global_dc) == start_colorize)
104143 + return 0;
104144 +
104145 + colorize_arm();
104146 + return 0;
104147 +}
104148 +
104149 +#if BUILDING_GCC_VERSION >= 4009
104150 +static const struct pass_data colorize_rearm_pass_data = {
104151 +#else
104152 +struct simple_ipa_opt_pass colorize_rearm_pass = {
104153 + .pass = {
104154 +#endif
104155 + .type = SIMPLE_IPA_PASS,
104156 + .name = "colorize_rearm",
104157 +#if BUILDING_GCC_VERSION >= 4008
104158 + .optinfo_flags = OPTGROUP_NONE,
104159 +#endif
104160 +#if BUILDING_GCC_VERSION >= 4009
104161 + .has_gate = false,
104162 + .has_execute = true,
104163 +#else
104164 + .gate = NULL,
104165 + .execute = execute_colorize_rearm,
104166 + .sub = NULL,
104167 + .next = NULL,
104168 + .static_pass_number = 0,
104169 +#endif
104170 + .tv_id = TV_NONE,
104171 + .properties_required = 0,
104172 + .properties_provided = 0,
104173 + .properties_destroyed = 0,
104174 + .todo_flags_start = 0,
104175 + .todo_flags_finish = 0
104176 +#if BUILDING_GCC_VERSION < 4009
104177 + }
104178 +#endif
104179 +};
104180 +
104181 +#if BUILDING_GCC_VERSION >= 4009
104182 +namespace {
104183 +class colorize_rearm_pass : public simple_ipa_opt_pass {
104184 +public:
104185 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
104186 + unsigned int execute() { return execute_colorize_rearm(); }
104187 +};
104188 +}
104189 +#endif
104190 +
104191 +static struct opt_pass *make_colorize_rearm_pass(void)
104192 +{
104193 +#if BUILDING_GCC_VERSION >= 4009
104194 + return new colorize_rearm_pass();
104195 +#else
104196 + return &colorize_rearm_pass.pass;
104197 +#endif
104198 +}
104199 +
104200 +static void colorize_start_unit(void *gcc_data, void *user_data)
104201 +{
104202 + colorize_arm();
104203 +}
104204 +
104205 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104206 +{
104207 + const char * const plugin_name = plugin_info->base_name;
104208 + struct register_pass_info colorize_rearm_pass_info;
104209 +
104210 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
104211 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
104212 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
104213 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
104214 +
104215 + if (!plugin_default_version_check(version, &gcc_version)) {
104216 + error(G_("incompatible gcc/plugin versions"));
104217 + return 1;
104218 + }
104219 +
104220 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
104221 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
104222 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
104223 + return 0;
104224 +}
104225 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
104226 new file mode 100644
104227 index 0000000..4f67ac1
104228 --- /dev/null
104229 +++ b/tools/gcc/constify_plugin.c
104230 @@ -0,0 +1,552 @@
104231 +/*
104232 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
104233 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
104234 + * Licensed under the GPL v2, or (at your option) v3
104235 + *
104236 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
104237 + *
104238 + * Homepage:
104239 + * http://www.grsecurity.net/~ephox/const_plugin/
104240 + *
104241 + * Usage:
104242 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
104243 + * $ gcc -fplugin=constify_plugin.so test.c -O2
104244 + */
104245 +
104246 +#include "gcc-common.h"
104247 +
104248 +// unused C type flag in all versions 4.5-4.9
104249 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
104250 +
104251 +int plugin_is_GPL_compatible;
104252 +
104253 +static struct plugin_info const_plugin_info = {
104254 + .version = "201401270210",
104255 + .help = "no-constify\tturn off constification\n",
104256 +};
104257 +
104258 +typedef struct {
104259 + bool has_fptr_field;
104260 + bool has_writable_field;
104261 + bool has_do_const_field;
104262 + bool has_no_const_field;
104263 +} constify_info;
104264 +
104265 +static const_tree get_field_type(const_tree field)
104266 +{
104267 + return strip_array_types(TREE_TYPE(field));
104268 +}
104269 +
104270 +static bool is_fptr(const_tree field)
104271 +{
104272 + const_tree ptr = get_field_type(field);
104273 +
104274 + if (TREE_CODE(ptr) != POINTER_TYPE)
104275 + return false;
104276 +
104277 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
104278 +}
104279 +
104280 +/*
104281 + * determine whether the given structure type meets the requirements for automatic constification,
104282 + * including the constification attributes on nested structure types
104283 + */
104284 +static void constifiable(const_tree node, constify_info *cinfo)
104285 +{
104286 + const_tree field;
104287 +
104288 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
104289 +
104290 + // e.g., pointer to structure fields while still constructing the structure type
104291 + if (TYPE_FIELDS(node) == NULL_TREE)
104292 + return;
104293 +
104294 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
104295 + const_tree type = get_field_type(field);
104296 + enum tree_code code = TREE_CODE(type);
104297 +
104298 + if (node == type)
104299 + continue;
104300 +
104301 + if (is_fptr(field))
104302 + cinfo->has_fptr_field = true;
104303 + else if (!TREE_READONLY(field))
104304 + cinfo->has_writable_field = true;
104305 +
104306 + if (code == RECORD_TYPE || code == UNION_TYPE) {
104307 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
104308 + cinfo->has_do_const_field = true;
104309 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
104310 + cinfo->has_no_const_field = true;
104311 + else
104312 + constifiable(type, cinfo);
104313 + }
104314 + }
104315 +}
104316 +
104317 +static bool constified(const_tree node)
104318 +{
104319 + constify_info cinfo = {
104320 + .has_fptr_field = false,
104321 + .has_writable_field = false,
104322 + .has_do_const_field = false,
104323 + .has_no_const_field = false
104324 + };
104325 +
104326 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
104327 +
104328 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
104329 +// gcc_assert(!TYPE_READONLY(node));
104330 + return false;
104331 + }
104332 +
104333 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
104334 + gcc_assert(TYPE_READONLY(node));
104335 + return true;
104336 + }
104337 +
104338 + constifiable(node, &cinfo);
104339 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
104340 + return false;
104341 +
104342 + return TYPE_READONLY(node);
104343 +}
104344 +
104345 +static void deconstify_tree(tree node);
104346 +
104347 +static void deconstify_type(tree type)
104348 +{
104349 + tree field;
104350 +
104351 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
104352 +
104353 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
104354 + const_tree fieldtype = get_field_type(field);
104355 +
104356 + // special case handling of simple ptr-to-same-array-type members
104357 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
104358 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
104359 +
104360 + if (TREE_TYPE(TREE_TYPE(field)) == type)
104361 + continue;
104362 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
104363 + continue;
104364 + if (!constified(ptrtype))
104365 + continue;
104366 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
104367 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
104368 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
104369 + }
104370 + continue;
104371 + }
104372 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
104373 + continue;
104374 + if (!constified(fieldtype))
104375 + continue;
104376 +
104377 + deconstify_tree(field);
104378 + TREE_READONLY(field) = 0;
104379 + }
104380 + TYPE_READONLY(type) = 0;
104381 + C_TYPE_FIELDS_READONLY(type) = 0;
104382 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104383 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
104384 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
104385 + }
104386 +}
104387 +
104388 +static void deconstify_tree(tree node)
104389 +{
104390 + tree old_type, new_type, field;
104391 +
104392 + old_type = TREE_TYPE(node);
104393 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
104394 + node = TREE_TYPE(node) = copy_node(old_type);
104395 + old_type = TREE_TYPE(old_type);
104396 + }
104397 +
104398 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
104399 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
104400 +
104401 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
104402 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
104403 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
104404 + DECL_FIELD_CONTEXT(field) = new_type;
104405 +
104406 + deconstify_type(new_type);
104407 +
104408 + TREE_TYPE(node) = new_type;
104409 +}
104410 +
104411 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
104412 +{
104413 + tree type;
104414 + constify_info cinfo = {
104415 + .has_fptr_field = false,
104416 + .has_writable_field = false,
104417 + .has_do_const_field = false,
104418 + .has_no_const_field = false
104419 + };
104420 +
104421 + *no_add_attrs = true;
104422 + if (TREE_CODE(*node) == FUNCTION_DECL) {
104423 + error("%qE attribute does not apply to functions (%qF)", name, *node);
104424 + return NULL_TREE;
104425 + }
104426 +
104427 + if (TREE_CODE(*node) == PARM_DECL) {
104428 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
104429 + return NULL_TREE;
104430 + }
104431 +
104432 + if (TREE_CODE(*node) == VAR_DECL) {
104433 + error("%qE attribute does not apply to variables (%qD)", name, *node);
104434 + return NULL_TREE;
104435 + }
104436 +
104437 + if (TYPE_P(*node)) {
104438 + type = *node;
104439 + } else {
104440 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
104441 + type = TREE_TYPE(*node);
104442 + }
104443 +
104444 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
104445 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
104446 + return NULL_TREE;
104447 + }
104448 +
104449 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
104450 + error("%qE attribute is already applied to the type %qT", name, type);
104451 + return NULL_TREE;
104452 + }
104453 +
104454 + if (TYPE_P(*node)) {
104455 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
104456 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
104457 + else
104458 + *no_add_attrs = false;
104459 + return NULL_TREE;
104460 + }
104461 +
104462 + constifiable(type, &cinfo);
104463 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104464 + deconstify_tree(*node);
104465 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
104466 + return NULL_TREE;
104467 + }
104468 +
104469 + error("%qE attribute used on type %qT that is not constified", name, type);
104470 + return NULL_TREE;
104471 +}
104472 +
104473 +static void constify_type(tree type)
104474 +{
104475 + TYPE_READONLY(type) = 1;
104476 + C_TYPE_FIELDS_READONLY(type) = 1;
104477 + TYPE_CONSTIFY_VISITED(type) = 1;
104478 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
104479 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
104480 +}
104481 +
104482 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
104483 +{
104484 + *no_add_attrs = true;
104485 + if (!TYPE_P(*node)) {
104486 + error("%qE attribute applies to types only (%qD)", name, *node);
104487 + return NULL_TREE;
104488 + }
104489 +
104490 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
104491 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
104492 + return NULL_TREE;
104493 + }
104494 +
104495 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
104496 + error("%qE attribute used on %qT is already applied to the type", name, *node);
104497 + return NULL_TREE;
104498 + }
104499 +
104500 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
104501 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
104502 + return NULL_TREE;
104503 + }
104504 +
104505 + *no_add_attrs = false;
104506 + return NULL_TREE;
104507 +}
104508 +
104509 +static struct attribute_spec no_const_attr = {
104510 + .name = "no_const",
104511 + .min_length = 0,
104512 + .max_length = 0,
104513 + .decl_required = false,
104514 + .type_required = false,
104515 + .function_type_required = false,
104516 + .handler = handle_no_const_attribute,
104517 +#if BUILDING_GCC_VERSION >= 4007
104518 + .affects_type_identity = true
104519 +#endif
104520 +};
104521 +
104522 +static struct attribute_spec do_const_attr = {
104523 + .name = "do_const",
104524 + .min_length = 0,
104525 + .max_length = 0,
104526 + .decl_required = false,
104527 + .type_required = false,
104528 + .function_type_required = false,
104529 + .handler = handle_do_const_attribute,
104530 +#if BUILDING_GCC_VERSION >= 4007
104531 + .affects_type_identity = true
104532 +#endif
104533 +};
104534 +
104535 +static void register_attributes(void *event_data, void *data)
104536 +{
104537 + register_attribute(&no_const_attr);
104538 + register_attribute(&do_const_attr);
104539 +}
104540 +
104541 +static void finish_type(void *event_data, void *data)
104542 +{
104543 + tree type = (tree)event_data;
104544 + constify_info cinfo = {
104545 + .has_fptr_field = false,
104546 + .has_writable_field = false,
104547 + .has_do_const_field = false,
104548 + .has_no_const_field = false
104549 + };
104550 +
104551 + if (type == NULL_TREE || type == error_mark_node)
104552 + return;
104553 +
104554 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
104555 + return;
104556 +
104557 + constifiable(type, &cinfo);
104558 +
104559 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
104560 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
104561 + deconstify_type(type);
104562 + TYPE_CONSTIFY_VISITED(type) = 1;
104563 + } else
104564 + error("'no_const' attribute used on type %qT that is not constified", type);
104565 + return;
104566 + }
104567 +
104568 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104569 + if (!cinfo.has_writable_field) {
104570 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
104571 + return;
104572 + }
104573 + constify_type(type);
104574 + return;
104575 + }
104576 +
104577 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
104578 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104579 + error("'do_const' attribute used on type %qT that is constified", type);
104580 + return;
104581 + }
104582 + constify_type(type);
104583 + return;
104584 + }
104585 +
104586 + deconstify_type(type);
104587 + TYPE_CONSTIFY_VISITED(type) = 1;
104588 +}
104589 +
104590 +static void check_global_variables(void *event_data, void *data)
104591 +{
104592 + struct varpool_node *node;
104593 +
104594 + FOR_EACH_VARIABLE(node) {
104595 + tree var = NODE_DECL(node);
104596 + tree type = TREE_TYPE(var);
104597 +
104598 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
104599 + continue;
104600 +
104601 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
104602 + continue;
104603 +
104604 + if (!TYPE_CONSTIFY_VISITED(type))
104605 + continue;
104606 +
104607 + if (DECL_EXTERNAL(var))
104608 + continue;
104609 +
104610 + if (DECL_INITIAL(var))
104611 + continue;
104612 +
104613 + // this works around a gcc bug/feature where uninitialized globals
104614 + // are moved into the .bss section regardless of any constification
104615 + DECL_INITIAL(var) = build_constructor(type, NULL);
104616 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
104617 + }
104618 +}
104619 +
104620 +static unsigned int check_local_variables(void)
104621 +{
104622 + unsigned int ret = 0;
104623 + tree var;
104624 +
104625 + unsigned int i;
104626 +
104627 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
104628 + tree type = TREE_TYPE(var);
104629 +
104630 + gcc_assert(DECL_P(var));
104631 + if (is_global_var(var))
104632 + continue;
104633 +
104634 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
104635 + continue;
104636 +
104637 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
104638 + continue;
104639 +
104640 + if (!TYPE_CONSTIFY_VISITED(type))
104641 + continue;
104642 +
104643 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
104644 + ret = 1;
104645 + }
104646 + return ret;
104647 +}
104648 +
104649 +#if BUILDING_GCC_VERSION >= 4009
104650 +static const struct pass_data check_local_variables_pass_data = {
104651 +#else
104652 +static struct gimple_opt_pass check_local_variables_pass = {
104653 + .pass = {
104654 +#endif
104655 + .type = GIMPLE_PASS,
104656 + .name = "check_local_variables",
104657 +#if BUILDING_GCC_VERSION >= 4008
104658 + .optinfo_flags = OPTGROUP_NONE,
104659 +#endif
104660 +#if BUILDING_GCC_VERSION >= 4009
104661 + .has_gate = false,
104662 + .has_execute = true,
104663 +#else
104664 + .gate = NULL,
104665 + .execute = check_local_variables,
104666 + .sub = NULL,
104667 + .next = NULL,
104668 + .static_pass_number = 0,
104669 +#endif
104670 + .tv_id = TV_NONE,
104671 + .properties_required = 0,
104672 + .properties_provided = 0,
104673 + .properties_destroyed = 0,
104674 + .todo_flags_start = 0,
104675 + .todo_flags_finish = 0
104676 +#if BUILDING_GCC_VERSION < 4009
104677 + }
104678 +#endif
104679 +};
104680 +
104681 +#if BUILDING_GCC_VERSION >= 4009
104682 +namespace {
104683 +class check_local_variables_pass : public gimple_opt_pass {
104684 +public:
104685 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
104686 + unsigned int execute() { return check_local_variables(); }
104687 +};
104688 +}
104689 +#endif
104690 +
104691 +static struct opt_pass *make_check_local_variables_pass(void)
104692 +{
104693 +#if BUILDING_GCC_VERSION >= 4009
104694 + return new check_local_variables_pass();
104695 +#else
104696 + return &check_local_variables_pass.pass;
104697 +#endif
104698 +}
104699 +
104700 +static struct {
104701 + const char *name;
104702 + const char *asm_op;
104703 +} sections[] = {
104704 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
104705 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
104706 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
104707 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
104708 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
104709 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
104710 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
104711 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
104712 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
104713 +};
104714 +
104715 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
104716 +
104717 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
104718 +{
104719 + size_t i;
104720 +
104721 + for (i = 0; i < ARRAY_SIZE(sections); i++)
104722 + if (!strcmp(sections[i].name, name))
104723 + return 0;
104724 + return old_section_type_flags(decl, name, reloc);
104725 +}
104726 +
104727 +static void constify_start_unit(void *gcc_data, void *user_data)
104728 +{
104729 +// size_t i;
104730 +
104731 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
104732 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
104733 +// sections[i].section = get_section(sections[i].name, 0, NULL);
104734 +
104735 + old_section_type_flags = targetm.section_type_flags;
104736 + targetm.section_type_flags = constify_section_type_flags;
104737 +}
104738 +
104739 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104740 +{
104741 + const char * const plugin_name = plugin_info->base_name;
104742 + const int argc = plugin_info->argc;
104743 + const struct plugin_argument * const argv = plugin_info->argv;
104744 + int i;
104745 + bool constify = true;
104746 +
104747 + struct register_pass_info check_local_variables_pass_info;
104748 +
104749 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
104750 + check_local_variables_pass_info.reference_pass_name = "ssa";
104751 + check_local_variables_pass_info.ref_pass_instance_number = 1;
104752 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
104753 +
104754 + if (!plugin_default_version_check(version, &gcc_version)) {
104755 + error(G_("incompatible gcc/plugin versions"));
104756 + return 1;
104757 + }
104758 +
104759 + for (i = 0; i < argc; ++i) {
104760 + if (!(strcmp(argv[i].key, "no-constify"))) {
104761 + constify = false;
104762 + continue;
104763 + }
104764 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
104765 + }
104766 +
104767 + if (strcmp(lang_hooks.name, "GNU C")) {
104768 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
104769 + constify = false;
104770 + }
104771 +
104772 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
104773 + if (constify) {
104774 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
104775 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
104776 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
104777 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
104778 + }
104779 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
104780 +
104781 + return 0;
104782 +}
104783 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
104784 new file mode 100644
104785 index 0000000..312d3b6
104786 --- /dev/null
104787 +++ b/tools/gcc/gcc-common.h
104788 @@ -0,0 +1,268 @@
104789 +#ifndef GCC_COMMON_H_INCLUDED
104790 +#define GCC_COMMON_H_INCLUDED
104791 +
104792 +#include "plugin.h"
104793 +#include "bversion.h"
104794 +#include "plugin-version.h"
104795 +#include "config.h"
104796 +#include "system.h"
104797 +#include "coretypes.h"
104798 +#include "tm.h"
104799 +#include "line-map.h"
104800 +#include "input.h"
104801 +#include "tree.h"
104802 +
104803 +#include "tree-inline.h"
104804 +#include "version.h"
104805 +#include "rtl.h"
104806 +#include "tm_p.h"
104807 +#include "flags.h"
104808 +//#include "insn-attr.h"
104809 +//#include "insn-config.h"
104810 +//#include "insn-flags.h"
104811 +#include "hard-reg-set.h"
104812 +//#include "recog.h"
104813 +#include "output.h"
104814 +#include "except.h"
104815 +#include "function.h"
104816 +#include "toplev.h"
104817 +//#include "expr.h"
104818 +#include "basic-block.h"
104819 +#include "intl.h"
104820 +#include "ggc.h"
104821 +//#include "regs.h"
104822 +#include "timevar.h"
104823 +
104824 +#include "params.h"
104825 +#include "pointer-set.h"
104826 +#include "emit-rtl.h"
104827 +//#include "reload.h"
104828 +//#include "ira.h"
104829 +//#include "dwarf2asm.h"
104830 +#include "debug.h"
104831 +#include "target.h"
104832 +#include "langhooks.h"
104833 +#include "cfgloop.h"
104834 +//#include "hosthooks.h"
104835 +#include "cgraph.h"
104836 +#include "opts.h"
104837 +//#include "coverage.h"
104838 +//#include "value-prof.h"
104839 +
104840 +#if BUILDING_GCC_VERSION >= 4007
104841 +#include "tree-pretty-print.h"
104842 +#include "gimple-pretty-print.h"
104843 +#include "c-tree.h"
104844 +//#include "alloc-pool.h"
104845 +#endif
104846 +
104847 +#if BUILDING_GCC_VERSION <= 4008
104848 +#include "tree-flow.h"
104849 +#endif
104850 +
104851 +#include "diagnostic.h"
104852 +//#include "tree-diagnostic.h"
104853 +#include "tree-dump.h"
104854 +#include "tree-pass.h"
104855 +//#include "df.h"
104856 +#include "predict.h"
104857 +//#include "lto-streamer.h"
104858 +#include "ipa-utils.h"
104859 +
104860 +#if BUILDING_GCC_VERSION >= 4009
104861 +#include "varasm.h"
104862 +#include "stor-layout.h"
104863 +#include "internal-fn.h"
104864 +#include "gimple-expr.h"
104865 +//#include "diagnostic-color.h"
104866 +#include "context.h"
104867 +#include "tree-ssa-alias.h"
104868 +#include "stringpool.h"
104869 +#include "tree-ssanames.h"
104870 +#include "print-tree.h"
104871 +#include "tree-eh.h"
104872 +#endif
104873 +
104874 +#include "gimple.h"
104875 +
104876 +#if BUILDING_GCC_VERSION >= 4009
104877 +#include "tree-ssa-operands.h"
104878 +#include "tree-phinodes.h"
104879 +#include "tree-cfg.h"
104880 +#include "gimple-iterator.h"
104881 +#include "gimple-ssa.h"
104882 +#include "ssa-iterators.h"
104883 +#endif
104884 +
104885 +//#include "expr.h" where are you...
104886 +extern rtx emit_move_insn(rtx x, rtx y);
104887 +
104888 +#define __unused __attribute__((__unused__))
104889 +
104890 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
104891 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
104892 +
104893 +#if BUILDING_GCC_VERSION == 4005
104894 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
104895 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
104896 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
104897 +
104898 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
104899 +{
104900 + tree fndecl;
104901 +
104902 + if (!is_gimple_call(stmt))
104903 + return false;
104904 + fndecl = gimple_call_fndecl(stmt);
104905 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
104906 + return false;
104907 +// print_node(stderr, "pax", fndecl, 4);
104908 + return DECL_FUNCTION_CODE(fndecl) == code;
104909 +}
104910 +
104911 +static inline bool is_simple_builtin(tree decl)
104912 +{
104913 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
104914 + return false;
104915 +
104916 + switch (DECL_FUNCTION_CODE(decl)) {
104917 + /* Builtins that expand to constants. */
104918 + case BUILT_IN_CONSTANT_P:
104919 + case BUILT_IN_EXPECT:
104920 + case BUILT_IN_OBJECT_SIZE:
104921 + case BUILT_IN_UNREACHABLE:
104922 + /* Simple register moves or loads from stack. */
104923 + case BUILT_IN_RETURN_ADDRESS:
104924 + case BUILT_IN_EXTRACT_RETURN_ADDR:
104925 + case BUILT_IN_FROB_RETURN_ADDR:
104926 + case BUILT_IN_RETURN:
104927 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
104928 + case BUILT_IN_FRAME_ADDRESS:
104929 + case BUILT_IN_VA_END:
104930 + case BUILT_IN_STACK_SAVE:
104931 + case BUILT_IN_STACK_RESTORE:
104932 + /* Exception state returns or moves registers around. */
104933 + case BUILT_IN_EH_FILTER:
104934 + case BUILT_IN_EH_POINTER:
104935 + case BUILT_IN_EH_COPY_VALUES:
104936 + return true;
104937 +
104938 + default:
104939 + return false;
104940 + }
104941 +}
104942 +#endif
104943 +
104944 +#if BUILDING_GCC_VERSION <= 4006
104945 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
104946 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
104947 +
104948 +// should come from c-tree.h if only it were installed for gcc 4.5...
104949 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
104950 +
104951 +#define get_random_seed(noinit) ({ \
104952 + unsigned HOST_WIDE_INT seed; \
104953 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
104954 + seed * seed; })
104955 +
104956 +static inline bool gimple_clobber_p(gimple s)
104957 +{
104958 + return false;
104959 +}
104960 +
104961 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
104962 +{
104963 + return implicit_built_in_decls[fncode];
104964 +}
104965 +
104966 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
104967 +{
104968 + struct cgraph_node *node = cgraph_get_node(decl);
104969 +
104970 + return node ? node : cgraph_node(decl);
104971 +}
104972 +
104973 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
104974 +{
104975 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
104976 +}
104977 +
104978 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
104979 +{
104980 + struct cgraph_node *node;
104981 +
104982 + for (node = cgraph_nodes; node; node = node->next)
104983 + if (cgraph_function_with_gimple_body_p(node))
104984 + return node;
104985 + return NULL;
104986 +}
104987 +
104988 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
104989 +{
104990 + for (node = node->next; node; node = node->next)
104991 + if (cgraph_function_with_gimple_body_p(node))
104992 + return node;
104993 + return NULL;
104994 +}
104995 +
104996 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
104997 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
104998 + (node) = cgraph_next_function_with_gimple_body(node))
104999 +#endif
105000 +
105001 +#if BUILDING_GCC_VERSION == 4006
105002 +extern void debug_gimple_stmt(gimple);
105003 +extern void debug_gimple_seq(gimple_seq);
105004 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
105005 +extern void print_gimple_stmt(FILE *, gimple, int, int);
105006 +extern void print_gimple_expr(FILE *, gimple, int, int);
105007 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
105008 +#endif
105009 +
105010 +#if BUILDING_GCC_VERSION <= 4007
105011 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
105012 +
105013 +static inline bool gimple_store_p(gimple gs)
105014 +{
105015 + tree lhs = gimple_get_lhs(gs);
105016 + return lhs && !is_gimple_reg(lhs);
105017 +}
105018 +#endif
105019 +
105020 +#if BUILDING_GCC_VERSION >= 4007
105021 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
105022 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
105023 +#endif
105024 +
105025 +#if BUILDING_GCC_VERSION <= 4008
105026 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
105027 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
105028 +
105029 +static inline const char *get_tree_code_name(enum tree_code code)
105030 +{
105031 + gcc_assert(code < MAX_TREE_CODES);
105032 + return tree_code_name[code];
105033 +}
105034 +
105035 +#define ipa_remove_stmt_references(cnode, stmt)
105036 +#endif
105037 +
105038 +#if BUILDING_GCC_VERSION == 4008
105039 +#define NODE_DECL(node) node->symbol.decl
105040 +#else
105041 +#define NODE_DECL(node) node->decl
105042 +#endif
105043 +
105044 +#if BUILDING_GCC_VERSION >= 4008
105045 +#define add_referenced_var(var)
105046 +#define mark_sym_for_renaming(var)
105047 +#define varpool_mark_needed_node(node)
105048 +#define TODO_dump_func 0
105049 +#define TODO_dump_cgraph 0
105050 +#endif
105051 +
105052 +#if BUILDING_GCC_VERSION >= 4009
105053 +#define TODO_ggc_collect 0
105054 +#endif
105055 +
105056 +#endif
105057 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
105058 new file mode 100644
105059 index 0000000..7514850
105060 --- /dev/null
105061 +++ b/tools/gcc/gen-random-seed.sh
105062 @@ -0,0 +1,8 @@
105063 +#!/bin/sh
105064 +
105065 +if [ ! -f "$1" ]; then
105066 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
105067 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
105068 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
105069 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
105070 +fi
105071 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
105072 new file mode 100644
105073 index 0000000..e518932
105074 --- /dev/null
105075 +++ b/tools/gcc/generate_size_overflow_hash.sh
105076 @@ -0,0 +1,94 @@
105077 +#!/bin/bash
105078 +
105079 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
105080 +
105081 +header1="size_overflow_hash.h"
105082 +database="size_overflow_hash.data"
105083 +n=65536
105084 +
105085 +usage() {
105086 +cat <<EOF
105087 +usage: $0 options
105088 +OPTIONS:
105089 + -h|--help help
105090 + -o header file
105091 + -d database file
105092 + -n hash array size
105093 +EOF
105094 + return 0
105095 +}
105096 +
105097 +while true
105098 +do
105099 + case "$1" in
105100 + -h|--help) usage && exit 0;;
105101 + -n) n=$2; shift 2;;
105102 + -o) header1="$2"; shift 2;;
105103 + -d) database="$2"; shift 2;;
105104 + --) shift 1; break ;;
105105 + *) break ;;
105106 + esac
105107 +done
105108 +
105109 +create_defines() {
105110 + for i in `seq 0 31`
105111 + do
105112 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
105113 + done
105114 + echo >> "$header1"
105115 +}
105116 +
105117 +create_structs() {
105118 + rm -f "$header1"
105119 +
105120 + create_defines
105121 +
105122 + cat "$database" | while read data
105123 + do
105124 + data_array=($data)
105125 + struct_hash_name="${data_array[0]}"
105126 + funcn="${data_array[1]}"
105127 + params="${data_array[2]}"
105128 + next="${data_array[4]}"
105129 +
105130 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
105131 +
105132 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
105133 + echo -en "\t.param\t= " >> "$header1"
105134 + line=
105135 + for param_num in ${params//-/ };
105136 + do
105137 + line="${line}PARAM"$param_num"|"
105138 + done
105139 +
105140 + echo -e "${line%?},\n};\n" >> "$header1"
105141 + done
105142 +}
105143 +
105144 +create_headers() {
105145 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
105146 +}
105147 +
105148 +create_array_elements() {
105149 + index=0
105150 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
105151 + do
105152 + data_array=($data)
105153 + i="${data_array[3]}"
105154 + hash="${data_array[0]}"
105155 + while [[ $index -lt $i ]]
105156 + do
105157 + echo -e "\t["$index"]\t= NULL," >> "$header1"
105158 + index=$(($index + 1))
105159 + done
105160 + index=$(($index + 1))
105161 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
105162 + done
105163 + echo '};' >> $header1
105164 +}
105165 +
105166 +create_structs
105167 +create_headers
105168 +create_array_elements
105169 +
105170 +exit 0
105171 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
105172 new file mode 100644
105173 index 0000000..b559327
105174 --- /dev/null
105175 +++ b/tools/gcc/kallocstat_plugin.c
105176 @@ -0,0 +1,182 @@
105177 +/*
105178 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105179 + * Licensed under the GPL v2
105180 + *
105181 + * Note: the choice of the license means that the compilation process is
105182 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105183 + * but for the kernel it doesn't matter since it doesn't link against
105184 + * any of the gcc libraries
105185 + *
105186 + * gcc plugin to find the distribution of k*alloc sizes
105187 + *
105188 + * TODO:
105189 + *
105190 + * BUGS:
105191 + * - none known
105192 + */
105193 +
105194 +#include "gcc-common.h"
105195 +
105196 +int plugin_is_GPL_compatible;
105197 +
105198 +static struct plugin_info kallocstat_plugin_info = {
105199 + .version = "201401260140",
105200 + .help = NULL
105201 +};
105202 +
105203 +static const char * const kalloc_functions[] = {
105204 + "__kmalloc",
105205 + "kmalloc",
105206 + "kmalloc_large",
105207 + "kmalloc_node",
105208 + "kmalloc_order",
105209 + "kmalloc_order_trace",
105210 + "kmalloc_slab",
105211 + "kzalloc",
105212 + "kzalloc_node",
105213 +};
105214 +
105215 +static bool is_kalloc(const char *fnname)
105216 +{
105217 + size_t i;
105218 +
105219 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
105220 + if (!strcmp(fnname, kalloc_functions[i]))
105221 + return true;
105222 + return false;
105223 +}
105224 +
105225 +static unsigned int execute_kallocstat(void)
105226 +{
105227 + basic_block bb;
105228 +
105229 + // 1. loop through BBs and GIMPLE statements
105230 + FOR_EACH_BB_FN(bb, cfun) {
105231 + gimple_stmt_iterator gsi;
105232 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105233 + // gimple match:
105234 + tree fndecl, size;
105235 + gimple stmt;
105236 + const char *fnname;
105237 +
105238 + // is it a call
105239 + stmt = gsi_stmt(gsi);
105240 + if (!is_gimple_call(stmt))
105241 + continue;
105242 + fndecl = gimple_call_fndecl(stmt);
105243 + if (fndecl == NULL_TREE)
105244 + continue;
105245 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
105246 + continue;
105247 +
105248 + // is it a call to k*alloc
105249 + fnname = DECL_NAME_POINTER(fndecl);
105250 + if (!is_kalloc(fnname))
105251 + continue;
105252 +
105253 + // is the size arg const or the result of a simple const assignment
105254 + size = gimple_call_arg(stmt, 0);
105255 + while (true) {
105256 + expanded_location xloc;
105257 + size_t size_val;
105258 +
105259 + if (TREE_CONSTANT(size)) {
105260 + xloc = expand_location(gimple_location(stmt));
105261 + if (!xloc.file)
105262 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
105263 + size_val = TREE_INT_CST_LOW(size);
105264 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
105265 + break;
105266 + }
105267 +
105268 + if (TREE_CODE(size) != SSA_NAME)
105269 + break;
105270 + stmt = SSA_NAME_DEF_STMT(size);
105271 +//debug_gimple_stmt(stmt);
105272 +//debug_tree(size);
105273 + if (!stmt || !is_gimple_assign(stmt))
105274 + break;
105275 + if (gimple_num_ops(stmt) != 2)
105276 + break;
105277 + size = gimple_assign_rhs1(stmt);
105278 + }
105279 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
105280 +//debug_tree(gimple_call_fn(call_stmt));
105281 +//print_node(stderr, "pax", fndecl, 4);
105282 + }
105283 + }
105284 +
105285 + return 0;
105286 +}
105287 +
105288 +#if BUILDING_GCC_VERSION >= 4009
105289 +static const struct pass_data kallocstat_pass_data = {
105290 +#else
105291 +static struct gimple_opt_pass kallocstat_pass = {
105292 + .pass = {
105293 +#endif
105294 + .type = GIMPLE_PASS,
105295 + .name = "kallocstat",
105296 +#if BUILDING_GCC_VERSION >= 4008
105297 + .optinfo_flags = OPTGROUP_NONE,
105298 +#endif
105299 +#if BUILDING_GCC_VERSION >= 4009
105300 + .has_gate = false,
105301 + .has_execute = true,
105302 +#else
105303 + .gate = NULL,
105304 + .execute = execute_kallocstat,
105305 + .sub = NULL,
105306 + .next = NULL,
105307 + .static_pass_number = 0,
105308 +#endif
105309 + .tv_id = TV_NONE,
105310 + .properties_required = 0,
105311 + .properties_provided = 0,
105312 + .properties_destroyed = 0,
105313 + .todo_flags_start = 0,
105314 + .todo_flags_finish = 0
105315 +#if BUILDING_GCC_VERSION < 4009
105316 + }
105317 +#endif
105318 +};
105319 +
105320 +#if BUILDING_GCC_VERSION >= 4009
105321 +namespace {
105322 +class kallocstat_pass : public gimple_opt_pass {
105323 +public:
105324 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
105325 + unsigned int execute() { return execute_kallocstat(); }
105326 +};
105327 +}
105328 +#endif
105329 +
105330 +static struct opt_pass *make_kallocstat_pass(void)
105331 +{
105332 +#if BUILDING_GCC_VERSION >= 4009
105333 + return new kallocstat_pass();
105334 +#else
105335 + return &kallocstat_pass.pass;
105336 +#endif
105337 +}
105338 +
105339 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105340 +{
105341 + const char * const plugin_name = plugin_info->base_name;
105342 + struct register_pass_info kallocstat_pass_info;
105343 +
105344 + kallocstat_pass_info.pass = make_kallocstat_pass();
105345 + kallocstat_pass_info.reference_pass_name = "ssa";
105346 + kallocstat_pass_info.ref_pass_instance_number = 1;
105347 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105348 +
105349 + if (!plugin_default_version_check(version, &gcc_version)) {
105350 + error(G_("incompatible gcc/plugin versions"));
105351 + return 1;
105352 + }
105353 +
105354 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
105355 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
105356 +
105357 + return 0;
105358 +}
105359 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
105360 new file mode 100644
105361 index 0000000..dd73713
105362 --- /dev/null
105363 +++ b/tools/gcc/kernexec_plugin.c
105364 @@ -0,0 +1,519 @@
105365 +/*
105366 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105367 + * Licensed under the GPL v2
105368 + *
105369 + * Note: the choice of the license means that the compilation process is
105370 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105371 + * but for the kernel it doesn't matter since it doesn't link against
105372 + * any of the gcc libraries
105373 + *
105374 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
105375 + *
105376 + * TODO:
105377 + *
105378 + * BUGS:
105379 + * - none known
105380 + */
105381 +
105382 +#include "gcc-common.h"
105383 +
105384 +int plugin_is_GPL_compatible;
105385 +
105386 +static struct plugin_info kernexec_plugin_info = {
105387 + .version = "201401260140",
105388 + .help = "method=[bts|or]\tinstrumentation method\n"
105389 +};
105390 +
105391 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
105392 +static void (*kernexec_instrument_retaddr)(rtx);
105393 +
105394 +/*
105395 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
105396 + */
105397 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
105398 +{
105399 + gimple asm_movabs_stmt;
105400 +
105401 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
105402 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
105403 + gimple_asm_set_volatile(asm_movabs_stmt, true);
105404 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
105405 + update_stmt(asm_movabs_stmt);
105406 +}
105407 +
105408 +/*
105409 + * find all asm() stmts that clobber r12 and add a reload of r12
105410 + */
105411 +static unsigned int execute_kernexec_reload(void)
105412 +{
105413 + basic_block bb;
105414 +
105415 + // 1. loop through BBs and GIMPLE statements
105416 + FOR_EACH_BB_FN(bb, cfun) {
105417 + gimple_stmt_iterator gsi;
105418 +
105419 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105420 + // gimple match: __asm__ ("" : : : "r12");
105421 + gimple asm_stmt;
105422 + size_t nclobbers;
105423 +
105424 + // is it an asm ...
105425 + asm_stmt = gsi_stmt(gsi);
105426 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
105427 + continue;
105428 +
105429 + // ... clobbering r12
105430 + nclobbers = gimple_asm_nclobbers(asm_stmt);
105431 + while (nclobbers--) {
105432 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
105433 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
105434 + continue;
105435 + kernexec_reload_fptr_mask(&gsi);
105436 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
105437 + break;
105438 + }
105439 + }
105440 + }
105441 +
105442 + return 0;
105443 +}
105444 +
105445 +/*
105446 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
105447 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
105448 + */
105449 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
105450 +{
105451 + gimple assign_intptr, assign_new_fptr, call_stmt;
105452 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
105453 +
105454 + call_stmt = gsi_stmt(*gsi);
105455 + old_fptr = gimple_call_fn(call_stmt);
105456 +
105457 + // create temporary unsigned long variable used for bitops and cast fptr to it
105458 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
105459 + add_referenced_var(intptr);
105460 + intptr = make_ssa_name(intptr, NULL);
105461 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
105462 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
105463 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
105464 + update_stmt(assign_intptr);
105465 +
105466 + // apply logical or to temporary unsigned long and bitmask
105467 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
105468 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
105469 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
105470 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
105471 + assign_intptr = gimple_build_assign(intptr, orptr);
105472 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
105473 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
105474 + update_stmt(assign_intptr);
105475 +
105476 + // cast temporary unsigned long back to a temporary fptr variable
105477 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
105478 + add_referenced_var(new_fptr);
105479 + new_fptr = make_ssa_name(new_fptr, NULL);
105480 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
105481 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
105482 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
105483 + update_stmt(assign_new_fptr);
105484 +
105485 + // replace call stmt fn with the new fptr
105486 + gimple_call_set_fn(call_stmt, new_fptr);
105487 + update_stmt(call_stmt);
105488 +}
105489 +
105490 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
105491 +{
105492 + gimple asm_or_stmt, call_stmt;
105493 + tree old_fptr, new_fptr, input, output;
105494 +#if BUILDING_GCC_VERSION <= 4007
105495 + VEC(tree, gc) *inputs = NULL;
105496 + VEC(tree, gc) *outputs = NULL;
105497 +#else
105498 + vec<tree, va_gc> *inputs = NULL;
105499 + vec<tree, va_gc> *outputs = NULL;
105500 +#endif
105501 +
105502 + call_stmt = gsi_stmt(*gsi);
105503 + old_fptr = gimple_call_fn(call_stmt);
105504 +
105505 + // create temporary fptr variable
105506 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
105507 + add_referenced_var(new_fptr);
105508 + new_fptr = make_ssa_name(new_fptr, NULL);
105509 +
105510 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
105511 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
105512 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
105513 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
105514 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
105515 +#if BUILDING_GCC_VERSION <= 4007
105516 + VEC_safe_push(tree, gc, inputs, input);
105517 + VEC_safe_push(tree, gc, outputs, output);
105518 +#else
105519 + vec_safe_push(inputs, input);
105520 + vec_safe_push(outputs, output);
105521 +#endif
105522 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
105523 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
105524 + gimple_asm_set_volatile(asm_or_stmt, true);
105525 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
105526 + update_stmt(asm_or_stmt);
105527 +
105528 + // replace call stmt fn with the new fptr
105529 + gimple_call_set_fn(call_stmt, new_fptr);
105530 + update_stmt(call_stmt);
105531 +}
105532 +
105533 +/*
105534 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
105535 + */
105536 +static unsigned int execute_kernexec_fptr(void)
105537 +{
105538 + basic_block bb;
105539 +
105540 + // 1. loop through BBs and GIMPLE statements
105541 + FOR_EACH_BB_FN(bb, cfun) {
105542 + gimple_stmt_iterator gsi;
105543 +
105544 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105545 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
105546 + tree fn;
105547 + gimple call_stmt;
105548 +
105549 + // is it a call ...
105550 + call_stmt = gsi_stmt(gsi);
105551 + if (!is_gimple_call(call_stmt))
105552 + continue;
105553 + fn = gimple_call_fn(call_stmt);
105554 + if (TREE_CODE(fn) == ADDR_EXPR)
105555 + continue;
105556 + if (TREE_CODE(fn) != SSA_NAME)
105557 + gcc_unreachable();
105558 +
105559 + // ... through a function pointer
105560 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
105561 + fn = SSA_NAME_VAR(fn);
105562 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
105563 + debug_tree(fn);
105564 + gcc_unreachable();
105565 + }
105566 + }
105567 + fn = TREE_TYPE(fn);
105568 + if (TREE_CODE(fn) != POINTER_TYPE)
105569 + continue;
105570 + fn = TREE_TYPE(fn);
105571 + if (TREE_CODE(fn) != FUNCTION_TYPE)
105572 + continue;
105573 +
105574 + kernexec_instrument_fptr(&gsi);
105575 +
105576 +//debug_tree(gimple_call_fn(call_stmt));
105577 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
105578 + }
105579 + }
105580 +
105581 + return 0;
105582 +}
105583 +
105584 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
105585 +static void kernexec_instrument_retaddr_bts(rtx insn)
105586 +{
105587 + rtx btsq;
105588 + rtvec argvec, constraintvec, labelvec;
105589 + int line;
105590 +
105591 + // create asm volatile("btsq $63,(%%rsp)":::)
105592 + argvec = rtvec_alloc(0);
105593 + constraintvec = rtvec_alloc(0);
105594 + labelvec = rtvec_alloc(0);
105595 + line = expand_location(RTL_LOCATION(insn)).line;
105596 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
105597 + MEM_VOLATILE_P(btsq) = 1;
105598 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
105599 + emit_insn_before(btsq, insn);
105600 +}
105601 +
105602 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
105603 +static void kernexec_instrument_retaddr_or(rtx insn)
105604 +{
105605 + rtx orq;
105606 + rtvec argvec, constraintvec, labelvec;
105607 + int line;
105608 +
105609 + // create asm volatile("orq %%r12,(%%rsp)":::)
105610 + argvec = rtvec_alloc(0);
105611 + constraintvec = rtvec_alloc(0);
105612 + labelvec = rtvec_alloc(0);
105613 + line = expand_location(RTL_LOCATION(insn)).line;
105614 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
105615 + MEM_VOLATILE_P(orq) = 1;
105616 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
105617 + emit_insn_before(orq, insn);
105618 +}
105619 +
105620 +/*
105621 + * find all asm level function returns and forcibly set the highest bit of the return address
105622 + */
105623 +static unsigned int execute_kernexec_retaddr(void)
105624 +{
105625 + rtx insn;
105626 +
105627 +// if (stack_realign_drap)
105628 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
105629 +
105630 + // 1. find function returns
105631 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
105632 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
105633 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
105634 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
105635 + rtx body;
105636 +
105637 + // is it a retn
105638 + if (!JUMP_P(insn))
105639 + continue;
105640 + body = PATTERN(insn);
105641 + if (GET_CODE(body) == PARALLEL)
105642 + body = XVECEXP(body, 0, 0);
105643 + if (!ANY_RETURN_P(body))
105644 + continue;
105645 + kernexec_instrument_retaddr(insn);
105646 + }
105647 +
105648 +// print_simple_rtl(stderr, get_insns());
105649 +// print_rtl(stderr, get_insns());
105650 +
105651 + return 0;
105652 +}
105653 +
105654 +static bool kernexec_cmodel_check(void)
105655 +{
105656 + tree section;
105657 +
105658 + if (ix86_cmodel != CM_KERNEL)
105659 + return false;
105660 +
105661 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
105662 + if (!section || !TREE_VALUE(section))
105663 + return true;
105664 +
105665 + section = TREE_VALUE(TREE_VALUE(section));
105666 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
105667 + return true;
105668 +
105669 + return false;
105670 +}
105671 +
105672 +#if BUILDING_GCC_VERSION >= 4009
105673 +static const struct pass_data kernexec_reload_pass_data = {
105674 +#else
105675 +static struct gimple_opt_pass kernexec_reload_pass = {
105676 + .pass = {
105677 +#endif
105678 + .type = GIMPLE_PASS,
105679 + .name = "kernexec_reload",
105680 +#if BUILDING_GCC_VERSION >= 4008
105681 + .optinfo_flags = OPTGROUP_NONE,
105682 +#endif
105683 +#if BUILDING_GCC_VERSION >= 4009
105684 + .has_gate = true,
105685 + .has_execute = true,
105686 +#else
105687 + .gate = kernexec_cmodel_check,
105688 + .execute = execute_kernexec_reload,
105689 + .sub = NULL,
105690 + .next = NULL,
105691 + .static_pass_number = 0,
105692 +#endif
105693 + .tv_id = TV_NONE,
105694 + .properties_required = 0,
105695 + .properties_provided = 0,
105696 + .properties_destroyed = 0,
105697 + .todo_flags_start = 0,
105698 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
105699 +#if BUILDING_GCC_VERSION < 4009
105700 + }
105701 +#endif
105702 +};
105703 +
105704 +#if BUILDING_GCC_VERSION >= 4009
105705 +static const struct pass_data kernexec_fptr_pass_data = {
105706 +#else
105707 +static struct gimple_opt_pass kernexec_fptr_pass = {
105708 + .pass = {
105709 +#endif
105710 + .type = GIMPLE_PASS,
105711 + .name = "kernexec_fptr",
105712 +#if BUILDING_GCC_VERSION >= 4008
105713 + .optinfo_flags = OPTGROUP_NONE,
105714 +#endif
105715 +#if BUILDING_GCC_VERSION >= 4009
105716 + .has_gate = true,
105717 + .has_execute = true,
105718 +#else
105719 + .gate = kernexec_cmodel_check,
105720 + .execute = execute_kernexec_fptr,
105721 + .sub = NULL,
105722 + .next = NULL,
105723 + .static_pass_number = 0,
105724 +#endif
105725 + .tv_id = TV_NONE,
105726 + .properties_required = 0,
105727 + .properties_provided = 0,
105728 + .properties_destroyed = 0,
105729 + .todo_flags_start = 0,
105730 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
105731 +#if BUILDING_GCC_VERSION < 4009
105732 + }
105733 +#endif
105734 +};
105735 +
105736 +#if BUILDING_GCC_VERSION >= 4009
105737 +static const struct pass_data kernexec_retaddr_pass_data = {
105738 +#else
105739 +static struct rtl_opt_pass kernexec_retaddr_pass = {
105740 + .pass = {
105741 +#endif
105742 + .type = RTL_PASS,
105743 + .name = "kernexec_retaddr",
105744 +#if BUILDING_GCC_VERSION >= 4008
105745 + .optinfo_flags = OPTGROUP_NONE,
105746 +#endif
105747 +#if BUILDING_GCC_VERSION >= 4009
105748 + .has_gate = true,
105749 + .has_execute = true,
105750 +#else
105751 + .gate = kernexec_cmodel_check,
105752 + .execute = execute_kernexec_retaddr,
105753 + .sub = NULL,
105754 + .next = NULL,
105755 + .static_pass_number = 0,
105756 +#endif
105757 + .tv_id = TV_NONE,
105758 + .properties_required = 0,
105759 + .properties_provided = 0,
105760 + .properties_destroyed = 0,
105761 + .todo_flags_start = 0,
105762 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
105763 +#if BUILDING_GCC_VERSION < 4009
105764 + }
105765 +#endif
105766 +};
105767 +
105768 +#if BUILDING_GCC_VERSION >= 4009
105769 +namespace {
105770 +class kernexec_reload_pass : public gimple_opt_pass {
105771 +public:
105772 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
105773 + bool gate() { return kernexec_cmodel_check(); }
105774 + unsigned int execute() { return execute_kernexec_reload(); }
105775 +};
105776 +
105777 +class kernexec_fptr_pass : public gimple_opt_pass {
105778 +public:
105779 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
105780 + bool gate() { return kernexec_cmodel_check(); }
105781 + unsigned int execute() { return execute_kernexec_fptr(); }
105782 +};
105783 +
105784 +class kernexec_retaddr_pass : public rtl_opt_pass {
105785 +public:
105786 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
105787 + bool gate() { return kernexec_cmodel_check(); }
105788 + unsigned int execute() { return execute_kernexec_retaddr(); }
105789 +};
105790 +}
105791 +#endif
105792 +
105793 +static struct opt_pass *make_kernexec_reload_pass(void)
105794 +{
105795 +#if BUILDING_GCC_VERSION >= 4009
105796 + return new kernexec_reload_pass();
105797 +#else
105798 + return &kernexec_reload_pass.pass;
105799 +#endif
105800 +}
105801 +
105802 +static struct opt_pass *make_kernexec_fptr_pass(void)
105803 +{
105804 +#if BUILDING_GCC_VERSION >= 4009
105805 + return new kernexec_fptr_pass();
105806 +#else
105807 + return &kernexec_fptr_pass.pass;
105808 +#endif
105809 +}
105810 +
105811 +static struct opt_pass *make_kernexec_retaddr_pass(void)
105812 +{
105813 +#if BUILDING_GCC_VERSION >= 4009
105814 + return new kernexec_retaddr_pass();
105815 +#else
105816 + return &kernexec_retaddr_pass.pass;
105817 +#endif
105818 +}
105819 +
105820 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105821 +{
105822 + const char * const plugin_name = plugin_info->base_name;
105823 + const int argc = plugin_info->argc;
105824 + const struct plugin_argument * const argv = plugin_info->argv;
105825 + int i;
105826 + struct register_pass_info kernexec_reload_pass_info;
105827 + struct register_pass_info kernexec_fptr_pass_info;
105828 + struct register_pass_info kernexec_retaddr_pass_info;
105829 +
105830 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
105831 + kernexec_reload_pass_info.reference_pass_name = "ssa";
105832 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
105833 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105834 +
105835 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
105836 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
105837 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
105838 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105839 +
105840 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
105841 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
105842 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
105843 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105844 +
105845 + if (!plugin_default_version_check(version, &gcc_version)) {
105846 + error(G_("incompatible gcc/plugin versions"));
105847 + return 1;
105848 + }
105849 +
105850 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
105851 +
105852 + if (TARGET_64BIT == 0)
105853 + return 0;
105854 +
105855 + for (i = 0; i < argc; ++i) {
105856 + if (!strcmp(argv[i].key, "method")) {
105857 + if (!argv[i].value) {
105858 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105859 + continue;
105860 + }
105861 + if (!strcmp(argv[i].value, "bts")) {
105862 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
105863 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
105864 + } else if (!strcmp(argv[i].value, "or")) {
105865 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
105866 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
105867 + fix_register("r12", 1, 1);
105868 + } else
105869 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
105870 + continue;
105871 + }
105872 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105873 + }
105874 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
105875 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
105876 +
105877 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
105878 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
105879 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
105880 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
105881 +
105882 + return 0;
105883 +}
105884 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
105885 new file mode 100644
105886 index 0000000..592b923
105887 --- /dev/null
105888 +++ b/tools/gcc/latent_entropy_plugin.c
105889 @@ -0,0 +1,325 @@
105890 +/*
105891 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
105892 + * Licensed under the GPL v2
105893 + *
105894 + * Note: the choice of the license means that the compilation process is
105895 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105896 + * but for the kernel it doesn't matter since it doesn't link against
105897 + * any of the gcc libraries
105898 + *
105899 + * gcc plugin to help generate a little bit of entropy from program state,
105900 + * used during boot in the kernel
105901 + *
105902 + * TODO:
105903 + * - add ipa pass to identify not explicitly marked candidate functions
105904 + * - mix in more program state (function arguments/return values, loop variables, etc)
105905 + * - more instrumentation control via attribute parameters
105906 + *
105907 + * BUGS:
105908 + * - LTO needs -flto-partition=none for now
105909 + */
105910 +
105911 +#include "gcc-common.h"
105912 +
105913 +int plugin_is_GPL_compatible;
105914 +
105915 +static tree latent_entropy_decl;
105916 +
105917 +static struct plugin_info latent_entropy_plugin_info = {
105918 + .version = "201401260140",
105919 + .help = NULL
105920 +};
105921 +
105922 +static unsigned HOST_WIDE_INT seed;
105923 +static unsigned HOST_WIDE_INT get_random_const(void)
105924 +{
105925 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
105926 + return seed;
105927 +}
105928 +
105929 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105930 +{
105931 + switch (TREE_CODE(*node)) {
105932 + default:
105933 + *no_add_attrs = true;
105934 + error("%qE attribute only applies to functions and variables", name);
105935 + break;
105936 +
105937 + case VAR_DECL:
105938 + if (DECL_INITIAL(*node)) {
105939 + *no_add_attrs = true;
105940 + error("variable %qD with %qE attribute must not be initialized", *node, name);
105941 + break;
105942 + }
105943 + DECL_INITIAL(*node) = build_int_cstu(long_long_unsigned_type_node, get_random_const());
105944 + break;
105945 +
105946 + case FUNCTION_DECL:
105947 + break;
105948 + }
105949 +
105950 + return NULL_TREE;
105951 +}
105952 +
105953 +static struct attribute_spec latent_entropy_attr = {
105954 + .name = "latent_entropy",
105955 + .min_length = 0,
105956 + .max_length = 0,
105957 + .decl_required = true,
105958 + .type_required = false,
105959 + .function_type_required = false,
105960 + .handler = handle_latent_entropy_attribute,
105961 +#if BUILDING_GCC_VERSION >= 4007
105962 + .affects_type_identity = false
105963 +#endif
105964 +};
105965 +
105966 +static void register_attributes(void *event_data, void *data)
105967 +{
105968 + register_attribute(&latent_entropy_attr);
105969 +}
105970 +
105971 +static bool gate_latent_entropy(void)
105972 +{
105973 + tree latent_entropy_attr;
105974 +
105975 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
105976 + return latent_entropy_attr != NULL_TREE;
105977 +}
105978 +
105979 +static enum tree_code get_op(tree *rhs)
105980 +{
105981 + static enum tree_code op;
105982 + unsigned HOST_WIDE_INT random_const;
105983 +
105984 + random_const = get_random_const();
105985 +
105986 + switch (op) {
105987 + case BIT_XOR_EXPR:
105988 + op = PLUS_EXPR;
105989 + break;
105990 +
105991 + case PLUS_EXPR:
105992 + if (rhs) {
105993 + op = LROTATE_EXPR;
105994 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
105995 + break;
105996 + }
105997 +
105998 + case LROTATE_EXPR:
105999 + default:
106000 + op = BIT_XOR_EXPR;
106001 + break;
106002 + }
106003 + if (rhs)
106004 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
106005 + return op;
106006 +}
106007 +
106008 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
106009 +{
106010 + gimple_stmt_iterator gsi;
106011 + gimple assign;
106012 + tree addxorrol, rhs;
106013 + enum tree_code op;
106014 +
106015 + op = get_op(&rhs);
106016 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
106017 + assign = gimple_build_assign(local_entropy, addxorrol);
106018 + gsi = gsi_after_labels(bb);
106019 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
106020 + update_stmt(assign);
106021 +//debug_bb(bb);
106022 +}
106023 +
106024 +static void perturb_latent_entropy(basic_block bb, tree rhs)
106025 +{
106026 + gimple_stmt_iterator gsi;
106027 + gimple assign;
106028 + tree addxorrol, temp;
106029 +
106030 + // 1. create temporary copy of latent_entropy
106031 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
106032 + add_referenced_var(temp);
106033 +
106034 + // 2. read...
106035 + temp = make_ssa_name(temp, NULL);
106036 + assign = gimple_build_assign(temp, latent_entropy_decl);
106037 + SSA_NAME_DEF_STMT(temp) = assign;
106038 + add_referenced_var(latent_entropy_decl);
106039 + gsi = gsi_after_labels(bb);
106040 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
106041 + update_stmt(assign);
106042 +
106043 + // 3. ...modify...
106044 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
106045 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
106046 + assign = gimple_build_assign(temp, addxorrol);
106047 + SSA_NAME_DEF_STMT(temp) = assign;
106048 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
106049 + update_stmt(assign);
106050 +
106051 + // 4. ...write latent_entropy
106052 + assign = gimple_build_assign(latent_entropy_decl, temp);
106053 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
106054 + update_stmt(assign);
106055 +}
106056 +
106057 +static unsigned int execute_latent_entropy(void)
106058 +{
106059 + basic_block bb;
106060 + gimple assign;
106061 + gimple_stmt_iterator gsi;
106062 + tree local_entropy;
106063 +
106064 + if (!latent_entropy_decl) {
106065 + struct varpool_node *node;
106066 +
106067 + FOR_EACH_VARIABLE(node) {
106068 + tree var = NODE_DECL(node);
106069 +
106070 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
106071 + continue;
106072 + latent_entropy_decl = var;
106073 +// debug_tree(var);
106074 + break;
106075 + }
106076 + if (!latent_entropy_decl) {
106077 +// debug_tree(current_function_decl);
106078 + return 0;
106079 + }
106080 + }
106081 +
106082 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
106083 +
106084 + // 1. create local entropy variable
106085 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
106086 + add_referenced_var(local_entropy);
106087 + mark_sym_for_renaming(local_entropy);
106088 +
106089 + // 2. initialize local entropy variable
106090 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
106091 + if (dom_info_available_p(CDI_DOMINATORS))
106092 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
106093 + gsi = gsi_start_bb(bb);
106094 +
106095 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
106096 +// gimple_set_location(assign, loc);
106097 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
106098 + update_stmt(assign);
106099 +//debug_bb(bb);
106100 + bb = bb->next_bb;
106101 +
106102 + // 3. instrument each BB with an operation on the local entropy variable
106103 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
106104 + perturb_local_entropy(bb, local_entropy);
106105 +//debug_bb(bb);
106106 + bb = bb->next_bb;
106107 + };
106108 +
106109 + // 4. mix local entropy into the global entropy variable
106110 + perturb_latent_entropy(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb, local_entropy);
106111 +//debug_bb(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb);
106112 + return 0;
106113 +}
106114 +
106115 +static void start_unit_callback(void *gcc_data, void *user_data)
106116 +{
106117 + tree latent_entropy_type;
106118 +
106119 + seed = get_random_seed(false);
106120 +
106121 + if (in_lto_p)
106122 + return;
106123 +
106124 + // extern volatile u64 latent_entropy
106125 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
106126 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
106127 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
106128 +
106129 + TREE_STATIC(latent_entropy_decl) = 1;
106130 + TREE_PUBLIC(latent_entropy_decl) = 1;
106131 + TREE_USED(latent_entropy_decl) = 1;
106132 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
106133 + DECL_EXTERNAL(latent_entropy_decl) = 1;
106134 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
106135 + lang_hooks.decls.pushdecl(latent_entropy_decl);
106136 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
106137 +// varpool_finalize_decl(latent_entropy_decl);
106138 +// varpool_mark_needed_node(latent_entropy_decl);
106139 +}
106140 +
106141 +#if BUILDING_GCC_VERSION >= 4009
106142 +static const struct pass_data latent_entropy_pass_data = {
106143 +#else
106144 +static struct gimple_opt_pass latent_entropy_pass = {
106145 + .pass = {
106146 +#endif
106147 + .type = GIMPLE_PASS,
106148 + .name = "latent_entropy",
106149 +#if BUILDING_GCC_VERSION >= 4008
106150 + .optinfo_flags = OPTGROUP_NONE,
106151 +#endif
106152 +#if BUILDING_GCC_VERSION >= 4009
106153 + .has_gate = true,
106154 + .has_execute = true,
106155 +#else
106156 + .gate = gate_latent_entropy,
106157 + .execute = execute_latent_entropy,
106158 + .sub = NULL,
106159 + .next = NULL,
106160 + .static_pass_number = 0,
106161 +#endif
106162 + .tv_id = TV_NONE,
106163 + .properties_required = PROP_gimple_leh | PROP_cfg,
106164 + .properties_provided = 0,
106165 + .properties_destroyed = 0,
106166 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
106167 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
106168 +#if BUILDING_GCC_VERSION < 4009
106169 + }
106170 +#endif
106171 +};
106172 +
106173 +#if BUILDING_GCC_VERSION >= 4009
106174 +namespace {
106175 +class latent_entropy_pass : public gimple_opt_pass {
106176 +public:
106177 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
106178 + bool gate() { return gate_latent_entropy(); }
106179 + unsigned int execute() { return execute_latent_entropy(); }
106180 +};
106181 +}
106182 +#endif
106183 +
106184 +static struct opt_pass *make_latent_entropy_pass(void)
106185 +{
106186 +#if BUILDING_GCC_VERSION >= 4009
106187 + return new latent_entropy_pass();
106188 +#else
106189 + return &latent_entropy_pass.pass;
106190 +#endif
106191 +}
106192 +
106193 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106194 +{
106195 + const char * const plugin_name = plugin_info->base_name;
106196 + struct register_pass_info latent_entropy_pass_info;
106197 +
106198 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
106199 + latent_entropy_pass_info.reference_pass_name = "optimized";
106200 + latent_entropy_pass_info.ref_pass_instance_number = 1;
106201 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
106202 +
106203 + if (!plugin_default_version_check(version, &gcc_version)) {
106204 + error(G_("incompatible gcc/plugin versions"));
106205 + return 1;
106206 + }
106207 +
106208 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
106209 + register_callback(plugin_name, PLUGIN_START_UNIT, &start_unit_callback, NULL);
106210 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
106211 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106212 +
106213 + return 0;
106214 +}
106215 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
106216 new file mode 100644
106217 index 0000000..fed12bf
106218 --- /dev/null
106219 +++ b/tools/gcc/randomize_layout_plugin.c
106220 @@ -0,0 +1,902 @@
106221 +/*
106222 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
106223 + * and PaX Team <pageexec@freemail.hu>
106224 + * Licensed under the GPL v2
106225 + *
106226 + * Usage:
106227 + * $ # for 4.5/4.6/C based 4.7
106228 + * $ 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
106229 + * $ # for C++ based 4.7/4.8+
106230 + * $ 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
106231 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
106232 + */
106233 +
106234 +#include "gcc-common.h"
106235 +#include "randomize_layout_seed.h"
106236 +
106237 +#define ORIG_TYPE_NAME(node) \
106238 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
106239 +
106240 +int plugin_is_GPL_compatible;
106241 +
106242 +static int performance_mode;
106243 +
106244 +static struct plugin_info randomize_layout_plugin_info = {
106245 + .version = "201402061950",
106246 + .help = "disable\t\t\tdo not activate plugin\n"
106247 + "performance-mode\tenable cacheline-aware layout randomization\n"
106248 +};
106249 +
106250 +/* from old Linux dcache.h */
106251 +static inline unsigned long
106252 +partial_name_hash(unsigned long c, unsigned long prevhash)
106253 +{
106254 + return (prevhash + (c << 4) + (c >> 4)) * 11;
106255 +}
106256 +static inline unsigned int
106257 +name_hash(const unsigned char *name)
106258 +{
106259 + unsigned long hash = 0;
106260 + unsigned int len = strlen((const char *)name);
106261 + while (len--)
106262 + hash = partial_name_hash(*name++, hash);
106263 + return (unsigned int)hash;
106264 +}
106265 +
106266 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106267 +{
106268 + tree type;
106269 +
106270 + *no_add_attrs = true;
106271 + if (TREE_CODE(*node) == FUNCTION_DECL) {
106272 + error("%qE attribute does not apply to functions (%qF)", name, *node);
106273 + return NULL_TREE;
106274 + }
106275 +
106276 + if (TREE_CODE(*node) == PARM_DECL) {
106277 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
106278 + return NULL_TREE;
106279 + }
106280 +
106281 + if (TREE_CODE(*node) == VAR_DECL) {
106282 + error("%qE attribute does not apply to variables (%qD)", name, *node);
106283 + return NULL_TREE;
106284 + }
106285 +
106286 + if (TYPE_P(*node)) {
106287 + type = *node;
106288 + } else {
106289 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
106290 + type = TREE_TYPE(*node);
106291 + }
106292 +
106293 + if (TREE_CODE(type) != RECORD_TYPE) {
106294 + error("%qE attribute used on %qT applies to struct types only", name, type);
106295 + return NULL_TREE;
106296 + }
106297 +
106298 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
106299 + error("%qE attribute is already applied to the type %qT", name, type);
106300 + return NULL_TREE;
106301 + }
106302 +
106303 + *no_add_attrs = false;
106304 +
106305 + return NULL_TREE;
106306 +}
106307 +
106308 +/* set on complete types that we don't need to inspect further at all */
106309 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106310 +{
106311 + *no_add_attrs = false;
106312 + return NULL_TREE;
106313 +}
106314 +
106315 +/*
106316 + * set on types that we've performed a shuffle on, to prevent re-shuffling
106317 + * this does not preclude us from inspecting its fields for potential shuffles
106318 + */
106319 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106320 +{
106321 + *no_add_attrs = false;
106322 + return NULL_TREE;
106323 +}
106324 +
106325 +/*
106326 + * 64bit variant of Bob Jenkins' public domain PRNG
106327 + * 256 bits of internal state
106328 + */
106329 +
106330 +typedef unsigned long long u64;
106331 +
106332 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
106333 +
106334 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
106335 +static u64 ranval(ranctx *x) {
106336 + u64 e = x->a - rot(x->b, 7);
106337 + x->a = x->b ^ rot(x->c, 13);
106338 + x->b = x->c + rot(x->d, 37);
106339 + x->c = x->d + e;
106340 + x->d = e + x->a;
106341 + return x->d;
106342 +}
106343 +
106344 +static void raninit(ranctx *x, u64 *seed) {
106345 + int i;
106346 +
106347 + x->a = seed[0];
106348 + x->b = seed[1];
106349 + x->c = seed[2];
106350 + x->d = seed[3];
106351 +
106352 + for (i=0; i < 30; ++i)
106353 + (void)ranval(x);
106354 +}
106355 +
106356 +static u64 shuffle_seed[4];
106357 +
106358 +struct partition_group {
106359 + tree tree_start;
106360 + unsigned long start;
106361 + unsigned long length;
106362 +};
106363 +
106364 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
106365 +{
106366 + unsigned long i;
106367 + unsigned long accum_size = 0;
106368 + unsigned long accum_length = 0;
106369 + unsigned long group_idx = 0;
106370 +
106371 + gcc_assert(length < INT_MAX);
106372 +
106373 + memset(size_groups, 0, sizeof(struct partition_group) * length);
106374 +
106375 + for (i = 0; i < length; i++) {
106376 + if (size_groups[group_idx].tree_start == NULL_TREE) {
106377 + size_groups[group_idx].tree_start = fields[i];
106378 + size_groups[group_idx].start = i;
106379 + accum_length = 0;
106380 + accum_size = 0;
106381 + }
106382 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
106383 + accum_length++;
106384 + if (accum_size >= 64) {
106385 + size_groups[group_idx].length = accum_length;
106386 + accum_length = 0;
106387 + group_idx++;
106388 + }
106389 + }
106390 +
106391 + if (size_groups[group_idx].tree_start != NULL_TREE &&
106392 + !size_groups[group_idx].length) {
106393 + size_groups[group_idx].length = accum_length;
106394 + group_idx++;
106395 + }
106396 +
106397 + *num_groups = group_idx;
106398 +}
106399 +
106400 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
106401 +{
106402 + unsigned long i, x;
106403 + struct partition_group size_group[length];
106404 + unsigned long num_groups = 0;
106405 + unsigned long randnum;
106406 +
106407 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
106408 + for (i = num_groups - 1; i > 0; i--) {
106409 + struct partition_group tmp;
106410 + randnum = ranval(prng_state) % (i + 1);
106411 + tmp = size_group[i];
106412 + size_group[i] = size_group[randnum];
106413 + size_group[randnum] = tmp;
106414 + }
106415 +
106416 + for (x = 0; x < num_groups; x++) {
106417 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
106418 + tree tmp;
106419 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
106420 + continue;
106421 + randnum = ranval(prng_state) % (i + 1);
106422 + // we could handle this case differently if desired
106423 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
106424 + continue;
106425 + tmp = newtree[i];
106426 + newtree[i] = newtree[randnum];
106427 + newtree[randnum] = tmp;
106428 + }
106429 + }
106430 +}
106431 +
106432 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
106433 +{
106434 + unsigned long i, randnum;
106435 +
106436 + for (i = length - 1; i > 0; i--) {
106437 + tree tmp;
106438 + randnum = ranval(prng_state) % (i + 1);
106439 + tmp = newtree[i];
106440 + newtree[i] = newtree[randnum];
106441 + newtree[randnum] = tmp;
106442 + }
106443 +}
106444 +
106445 +/* modern in-place Fisher-Yates shuffle */
106446 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
106447 +{
106448 + unsigned long i;
106449 + u64 seed[4];
106450 + ranctx prng_state;
106451 + const unsigned char *structname;
106452 +
106453 + if (length == 0)
106454 + return;
106455 +
106456 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106457 +
106458 + structname = ORIG_TYPE_NAME(type);
106459 +
106460 +#ifdef __DEBUG_PLUGIN
106461 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
106462 +#ifdef __DEBUG_VERBOSE
106463 + debug_tree((tree)type);
106464 +#endif
106465 +#endif
106466 +
106467 + for (i = 0; i < 4; i++) {
106468 + seed[i] = shuffle_seed[i];
106469 + seed[i] ^= name_hash(structname);
106470 + }
106471 +
106472 + raninit(&prng_state, (u64 *)&seed);
106473 +
106474 + if (performance_mode)
106475 + performance_shuffle(newtree, length, &prng_state);
106476 + else
106477 + full_shuffle(newtree, length, &prng_state);
106478 +}
106479 +
106480 +static bool is_flexible_array(const_tree field)
106481 +{
106482 + const_tree fieldtype;
106483 + const_tree typesize;
106484 + const_tree elemtype;
106485 + const_tree elemsize;
106486 +
106487 + fieldtype = TREE_TYPE(field);
106488 + typesize = TYPE_SIZE(fieldtype);
106489 +
106490 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
106491 + return false;
106492 +
106493 + elemtype = TREE_TYPE(fieldtype);
106494 + elemsize = TYPE_SIZE(elemtype);
106495 +
106496 + /* size of type is represented in bits */
106497 +
106498 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
106499 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
106500 + return true;
106501 +
106502 + if (typesize != NULL_TREE &&
106503 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
106504 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
106505 + return true;
106506 +
106507 + return false;
106508 +}
106509 +
106510 +static int relayout_struct(tree type)
106511 +{
106512 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
106513 + unsigned long shuffle_length = num_fields;
106514 + tree field;
106515 + tree newtree[num_fields];
106516 + unsigned long i;
106517 + tree list;
106518 + tree variant;
106519 + expanded_location xloc;
106520 +
106521 + if (TYPE_FIELDS(type) == NULL_TREE)
106522 + return 0;
106523 +
106524 + if (num_fields < 2)
106525 + return 0;
106526 +
106527 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106528 +
106529 + gcc_assert(num_fields < INT_MAX);
106530 +
106531 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
106532 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
106533 + return 0;
106534 +
106535 + /* throw out any structs in uapi */
106536 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
106537 +
106538 + if (strstr(xloc.file, "/uapi/"))
106539 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
106540 +
106541 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
106542 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
106543 + newtree[i] = field;
106544 + }
106545 +
106546 + /*
106547 + * enforce that we don't randomize the layout of the last
106548 + * element of a struct if it's a 0 or 1-length array
106549 + * or a proper flexible array
106550 + */
106551 + if (is_flexible_array(newtree[num_fields - 1]))
106552 + shuffle_length--;
106553 +
106554 + shuffle(type, (tree *)newtree, shuffle_length);
106555 +
106556 + /*
106557 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
106558 + * as gcc provides no other way to detect such code
106559 + */
106560 + list = make_node(FIELD_DECL);
106561 + TREE_CHAIN(list) = newtree[0];
106562 + TREE_TYPE(list) = void_type_node;
106563 + DECL_SIZE(list) = bitsize_zero_node;
106564 + DECL_NONADDRESSABLE_P(list) = 1;
106565 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
106566 + DECL_SIZE_UNIT(list) = size_zero_node;
106567 + DECL_FIELD_OFFSET(list) = size_zero_node;
106568 + // to satisfy the constify plugin
106569 + TREE_READONLY(list) = 1;
106570 +
106571 + for (i = 0; i < num_fields - 1; i++)
106572 + TREE_CHAIN(newtree[i]) = newtree[i+1];
106573 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
106574 +
106575 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
106576 + TYPE_FIELDS(variant) = list;
106577 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
106578 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
106579 + // force a re-layout
106580 + TYPE_SIZE(variant) = NULL_TREE;
106581 + layout_type(variant);
106582 + }
106583 +
106584 + return 1;
106585 +}
106586 +
106587 +/* from constify plugin */
106588 +static const_tree get_field_type(const_tree field)
106589 +{
106590 + return strip_array_types(TREE_TYPE(field));
106591 +}
106592 +
106593 +/* from constify plugin */
106594 +static bool is_fptr(const_tree fieldtype)
106595 +{
106596 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
106597 + return false;
106598 +
106599 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
106600 +}
106601 +
106602 +/* derived from constify plugin */
106603 +static int is_pure_ops_struct(const_tree node)
106604 +{
106605 + const_tree field;
106606 +
106607 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
106608 +
106609 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
106610 + const_tree fieldtype = get_field_type(field);
106611 + enum tree_code code = TREE_CODE(fieldtype);
106612 +
106613 + if (node == fieldtype)
106614 + continue;
106615 +
106616 + if (!is_fptr(fieldtype))
106617 + return 0;
106618 +
106619 + if (code != RECORD_TYPE && code != UNION_TYPE)
106620 + continue;
106621 +
106622 + if (!is_pure_ops_struct(fieldtype))
106623 + return 0;
106624 + }
106625 +
106626 + return 1;
106627 +}
106628 +
106629 +static void randomize_type(tree type)
106630 +{
106631 + tree variant;
106632 +
106633 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106634 +
106635 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
106636 + return;
106637 +
106638 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
106639 + relayout_struct(type);
106640 +
106641 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
106642 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
106643 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
106644 + }
106645 +#ifdef __DEBUG_PLUGIN
106646 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
106647 +#ifdef __DEBUG_VERBOSE
106648 + debug_tree(type);
106649 +#endif
106650 +#endif
106651 +}
106652 +
106653 +static void finish_decl(void *event_data, void *data)
106654 +{
106655 + tree decl = (tree)event_data;
106656 + tree type;
106657 +
106658 + if (decl == NULL_TREE || decl == error_mark_node)
106659 + return;
106660 +
106661 + type = TREE_TYPE(decl);
106662 +
106663 + if (TREE_CODE(decl) != VAR_DECL)
106664 + return;
106665 +
106666 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
106667 + return;
106668 +
106669 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
106670 + return;
106671 +
106672 + relayout_decl(decl);
106673 +}
106674 +
106675 +static void finish_type(void *event_data, void *data)
106676 +{
106677 + tree type = (tree)event_data;
106678 +
106679 + if (type == NULL_TREE || type == error_mark_node)
106680 + return;
106681 +
106682 + if (TREE_CODE(type) != RECORD_TYPE)
106683 + return;
106684 +
106685 + if (TYPE_FIELDS(type) == NULL_TREE)
106686 + return;
106687 +
106688 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
106689 + return;
106690 +
106691 +#ifdef __DEBUG_PLUGIN
106692 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
106693 +#endif
106694 +#ifdef __DEBUG_VERBOSE
106695 + debug_tree(type);
106696 +#endif
106697 + randomize_type(type);
106698 +
106699 + return;
106700 +}
106701 +
106702 +static struct attribute_spec randomize_layout_attr = {
106703 + .name = "randomize_layout",
106704 + // related to args
106705 + .min_length = 0,
106706 + .max_length = 0,
106707 + .decl_required = false,
106708 + // need type declaration
106709 + .type_required = true,
106710 + .function_type_required = false,
106711 + .handler = handle_randomize_layout_attr,
106712 +#if BUILDING_GCC_VERSION >= 4007
106713 + .affects_type_identity = true
106714 +#endif
106715 +};
106716 +
106717 +static struct attribute_spec no_randomize_layout_attr = {
106718 + .name = "no_randomize_layout",
106719 + // related to args
106720 + .min_length = 0,
106721 + .max_length = 0,
106722 + .decl_required = false,
106723 + // need type declaration
106724 + .type_required = true,
106725 + .function_type_required = false,
106726 + .handler = handle_randomize_layout_attr,
106727 +#if BUILDING_GCC_VERSION >= 4007
106728 + .affects_type_identity = true
106729 +#endif
106730 +};
106731 +
106732 +static struct attribute_spec randomize_considered_attr = {
106733 + .name = "randomize_considered",
106734 + // related to args
106735 + .min_length = 0,
106736 + .max_length = 0,
106737 + .decl_required = false,
106738 + // need type declaration
106739 + .type_required = true,
106740 + .function_type_required = false,
106741 + .handler = handle_randomize_considered_attr,
106742 +#if BUILDING_GCC_VERSION >= 4007
106743 + .affects_type_identity = false
106744 +#endif
106745 +};
106746 +
106747 +static struct attribute_spec randomize_performed_attr = {
106748 + .name = "randomize_performed",
106749 + // related to args
106750 + .min_length = 0,
106751 + .max_length = 0,
106752 + .decl_required = false,
106753 + // need type declaration
106754 + .type_required = true,
106755 + .function_type_required = false,
106756 + .handler = handle_randomize_performed_attr,
106757 +#if BUILDING_GCC_VERSION >= 4007
106758 + .affects_type_identity = false
106759 +#endif
106760 +};
106761 +
106762 +static void register_attributes(void *event_data, void *data)
106763 +{
106764 + register_attribute(&randomize_layout_attr);
106765 + register_attribute(&no_randomize_layout_attr);
106766 + register_attribute(&randomize_considered_attr);
106767 + register_attribute(&randomize_performed_attr);
106768 +}
106769 +
106770 +static void check_bad_casts_in_constructor(tree var, tree init)
106771 +{
106772 + unsigned HOST_WIDE_INT idx;
106773 + tree field, val;
106774 + tree field_type, val_type;
106775 +
106776 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
106777 + if (TREE_CODE(val) == CONSTRUCTOR) {
106778 + check_bad_casts_in_constructor(var, val);
106779 + continue;
106780 + }
106781 +
106782 + field_type = TREE_TYPE(field);
106783 + val_type = TREE_TYPE(val);
106784 +
106785 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
106786 + continue;
106787 +
106788 + if (field_type == val_type)
106789 + continue;
106790 +
106791 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
106792 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
106793 +
106794 + if (field_type == void_type_node)
106795 + continue;
106796 + if (field_type == val_type)
106797 + continue;
106798 + if (TREE_CODE(val_type) != RECORD_TYPE)
106799 + continue;
106800 +
106801 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
106802 + continue;
106803 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
106804 + }
106805 +}
106806 +
106807 +/* derived from the constify plugin */
106808 +static void check_global_variables(void *event_data, void *data)
106809 +{
106810 + struct varpool_node *node;
106811 + tree init;
106812 +
106813 + FOR_EACH_VARIABLE(node) {
106814 + tree var = NODE_DECL(node);
106815 + init = DECL_INITIAL(var);
106816 + if (init == NULL_TREE)
106817 + continue;
106818 +
106819 + if (TREE_CODE(init) != CONSTRUCTOR)
106820 + continue;
106821 +
106822 + check_bad_casts_in_constructor(var, init);
106823 + }
106824 +}
106825 +
106826 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
106827 +{
106828 + basic_block dom;
106829 + gimple dom_stmt;
106830 + gimple call_stmt;
106831 + const_tree dom_lhs;
106832 + const_tree poss_is_err_cond;
106833 + const_tree poss_is_err_func;
106834 + const_tree is_err_arg;
106835 +
106836 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
106837 + if (!dom)
106838 + return false;
106839 +
106840 + dom_stmt = last_stmt(dom);
106841 + if (!dom_stmt)
106842 + return false;
106843 +
106844 + if (gimple_code(dom_stmt) != GIMPLE_COND)
106845 + return false;
106846 +
106847 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
106848 + return false;
106849 +
106850 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
106851 + return false;
106852 +
106853 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
106854 +
106855 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
106856 + return false;
106857 +
106858 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
106859 +
106860 + if (gimple_code(call_stmt) != GIMPLE_CALL)
106861 + return false;
106862 +
106863 + dom_lhs = gimple_get_lhs(call_stmt);
106864 + poss_is_err_func = gimple_call_fndecl(call_stmt);
106865 + if (!poss_is_err_func)
106866 + return false;
106867 + if (dom_lhs != poss_is_err_cond)
106868 + return false;
106869 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
106870 + return false;
106871 +
106872 + is_err_arg = gimple_call_arg(call_stmt, 0);
106873 + if (!is_err_arg)
106874 + return false;
106875 +
106876 + if (is_err_arg != rhs)
106877 + return false;
106878 +
106879 + return true;
106880 +}
106881 +
106882 +static void handle_local_var_initializers(void)
106883 +{
106884 + tree var;
106885 + unsigned int i;
106886 +
106887 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
106888 + tree init = DECL_INITIAL(var);
106889 + if (!init)
106890 + continue;
106891 + if (TREE_CODE(init) != CONSTRUCTOR)
106892 + continue;
106893 + check_bad_casts_in_constructor(var, init);
106894 + }
106895 +}
106896 +
106897 +/*
106898 + * iterate over all statements to find "bad" casts:
106899 + * those where the address of the start of a structure is cast
106900 + * to a pointer of a structure of a different type, or a
106901 + * structure pointer type is cast to a different structure pointer type
106902 + */
106903 +static unsigned int find_bad_casts(void)
106904 +{
106905 + basic_block bb;
106906 +
106907 + handle_local_var_initializers();
106908 +
106909 + FOR_ALL_BB_FN(bb, cfun) {
106910 + gimple_stmt_iterator gsi;
106911 +
106912 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106913 + gimple stmt;
106914 + const_tree lhs;
106915 + const_tree lhs_type;
106916 + const_tree rhs1;
106917 + const_tree rhs_type;
106918 + const_tree ptr_lhs_type;
106919 + const_tree ptr_rhs_type;
106920 + const_tree op0;
106921 + const_tree op0_type;
106922 + enum tree_code rhs_code;
106923 +
106924 + stmt = gsi_stmt(gsi);
106925 +
106926 +#ifdef __DEBUG_PLUGIN
106927 +#ifdef __DEBUG_VERBOSE
106928 + debug_gimple_stmt(stmt);
106929 + debug_tree(gimple_get_lhs(stmt));
106930 +#endif
106931 +#endif
106932 +
106933 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
106934 + continue;
106935 +
106936 +#ifdef __DEBUG_PLUGIN
106937 +#ifdef __DEBUG_VERBOSE
106938 + debug_tree(gimple_assign_rhs1(stmt));
106939 +#endif
106940 +#endif
106941 +
106942 + rhs_code = gimple_assign_rhs_code(stmt);
106943 +
106944 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
106945 + continue;
106946 +
106947 + lhs = gimple_get_lhs(stmt);
106948 + lhs_type = TREE_TYPE(lhs);
106949 + rhs1 = gimple_assign_rhs1(stmt);
106950 + rhs_type = TREE_TYPE(rhs1);
106951 +
106952 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
106953 + TREE_CODE(lhs_type) != POINTER_TYPE)
106954 + continue;
106955 +
106956 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
106957 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
106958 +
106959 + if (ptr_rhs_type == void_type_node)
106960 + continue;
106961 +
106962 + if (ptr_lhs_type == void_type_node)
106963 + continue;
106964 +
106965 + if (dominated_by_is_err(rhs1, bb))
106966 + continue;
106967 +
106968 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
106969 +#ifndef __DEBUG_PLUGIN
106970 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
106971 +#endif
106972 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
106973 + continue;
106974 + }
106975 +
106976 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
106977 + continue;
106978 +
106979 + if (rhs_code == ADDR_EXPR) {
106980 + op0 = TREE_OPERAND(rhs1, 0);
106981 +
106982 + if (op0 == NULL_TREE)
106983 + continue;
106984 +
106985 + if (TREE_CODE(op0) != VAR_DECL)
106986 + continue;
106987 +
106988 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
106989 + if (op0_type == ptr_lhs_type)
106990 + continue;
106991 +
106992 +#ifndef __DEBUG_PLUGIN
106993 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
106994 +#endif
106995 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
106996 + } else {
106997 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
106998 + /* skip bogus type casts introduced by container_of */
106999 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
107000 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
107001 + continue;
107002 +#ifndef __DEBUG_PLUGIN
107003 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
107004 +#endif
107005 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
107006 + }
107007 +
107008 + }
107009 + }
107010 + return 0;
107011 +}
107012 +
107013 +#if BUILDING_GCC_VERSION >= 4009
107014 +static const struct pass_data randomize_layout_bad_cast_data = {
107015 +#else
107016 +static struct gimple_opt_pass randomize_layout_bad_cast = {
107017 + .pass = {
107018 +#endif
107019 + .type = GIMPLE_PASS,
107020 + .name = "randomize_layout_bad_cast",
107021 +#if BUILDING_GCC_VERSION >= 4008
107022 + .optinfo_flags = OPTGROUP_NONE,
107023 +#endif
107024 +#if BUILDING_GCC_VERSION >= 4009
107025 + .has_gate = false,
107026 + .has_execute = true,
107027 +#else
107028 + .gate = NULL,
107029 + .execute = find_bad_casts,
107030 + .sub = NULL,
107031 + .next = NULL,
107032 + .static_pass_number = 0,
107033 +#endif
107034 + .tv_id = TV_NONE,
107035 + .properties_required = PROP_cfg,
107036 + .properties_provided = 0,
107037 + .properties_destroyed = 0,
107038 + .todo_flags_start = 0,
107039 + .todo_flags_finish = TODO_dump_func
107040 +#if BUILDING_GCC_VERSION < 4009
107041 + }
107042 +#endif
107043 +};
107044 +
107045 +#if BUILDING_GCC_VERSION >= 4009
107046 +namespace {
107047 +class randomize_layout_bad_cast : public gimple_opt_pass {
107048 +public:
107049 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
107050 + unsigned int execute() { return find_bad_casts(); }
107051 +};
107052 +}
107053 +#endif
107054 +
107055 +static struct opt_pass *make_randomize_layout_bad_cast(void)
107056 +{
107057 +#if BUILDING_GCC_VERSION >= 4009
107058 + return new randomize_layout_bad_cast();
107059 +#else
107060 + return &randomize_layout_bad_cast.pass;
107061 +#endif
107062 +}
107063 +
107064 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107065 +{
107066 + int i;
107067 + const char * const plugin_name = plugin_info->base_name;
107068 + const int argc = plugin_info->argc;
107069 + const struct plugin_argument * const argv = plugin_info->argv;
107070 + bool enable = true;
107071 + int obtained_seed = 0;
107072 + struct register_pass_info randomize_layout_bad_cast_info;
107073 +
107074 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
107075 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
107076 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
107077 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
107078 +
107079 + if (!plugin_default_version_check(version, &gcc_version)) {
107080 + error(G_("incompatible gcc/plugin versions"));
107081 + return 1;
107082 + }
107083 +
107084 + if (strcmp(lang_hooks.name, "GNU C")) {
107085 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
107086 + enable = false;
107087 + }
107088 +
107089 + for (i = 0; i < argc; ++i) {
107090 + if (!strcmp(argv[i].key, "disable")) {
107091 + enable = false;
107092 + continue;
107093 + }
107094 + if (!strcmp(argv[i].key, "performance-mode")) {
107095 + performance_mode = 1;
107096 + continue;
107097 + }
107098 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107099 + }
107100 +
107101 + if (strlen(randstruct_seed) != 64) {
107102 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
107103 + return 1;
107104 + }
107105 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
107106 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
107107 + if (obtained_seed != 4) {
107108 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
107109 + return 1;
107110 + }
107111 +
107112 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
107113 + if (enable) {
107114 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
107115 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
107116 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
107117 + register_callback(plugin_name, PLUGIN_FINISH_DECL, finish_decl, NULL);
107118 + }
107119 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107120 +
107121 + return 0;
107122 +}
107123 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
107124 new file mode 100644
107125 index 0000000..0c980be
107126 --- /dev/null
107127 +++ b/tools/gcc/size_overflow_hash.data
107128 @@ -0,0 +1,5697 @@
107129 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
107130 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
107131 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
107132 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
107133 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
107134 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
107135 +padzero_55 padzero 1 55 &sel_read_policyvers_55
107136 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
107137 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
107138 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
107139 +load_msg_95 load_msg 2 95 NULL
107140 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
107141 +init_q_132 init_q 4 132 NULL
107142 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
107143 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
107144 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
107145 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
107146 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
107147 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
107148 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
107149 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
107150 +br_port_info_size_268 br_port_info_size 0 268 NULL
107151 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
107152 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
107153 +SYSC_connect_304 SYSC_connect 3 304 NULL
107154 +syslog_print_307 syslog_print 2 307 NULL
107155 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
107156 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
107157 +hw_device_state_409 hw_device_state 0 409 NULL
107158 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
107159 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
107160 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
107161 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
107162 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
107163 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
107164 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
107165 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
107166 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
107167 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
107168 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
107169 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
107170 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
107171 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
107172 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
107173 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
107174 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
107175 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
107176 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
107177 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
107178 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
107179 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
107180 +clone_split_bio_633 clone_split_bio 6 633 NULL
107181 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
107182 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
107183 +unlink_queued_645 unlink_queued 4 645 NULL
107184 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
107185 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
107186 +persistent_ram_vmap_709 persistent_ram_vmap 1-2 709 NULL
107187 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
107188 +dvb_video_write_754 dvb_video_write 3 754 NULL
107189 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
107190 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
107191 +if_writecmd_815 if_writecmd 2 815 NULL
107192 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
107193 +error_state_read_859 error_state_read 6 859 NULL
107194 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
107195 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
107196 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
107197 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
107198 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
107199 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
107200 +memcmp_990 memcmp 0 990 NULL
107201 +readreg_1017 readreg 0-1 1017 NULL
107202 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
107203 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
107204 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
107205 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
107206 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
107207 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
107208 +llc_mac_hdr_init_1094 llc_mac_hdr_init 0 1094 NULL
107209 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
107210 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
107211 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
107212 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
107213 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
107214 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
107215 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
107216 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
107217 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
107218 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
107219 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
107220 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
107221 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
107222 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
107223 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
107224 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
107225 +ffs_1322 ffs 0 1322 NULL
107226 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
107227 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
107228 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
107229 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
107230 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
107231 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
107232 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
107233 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
107234 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
107235 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
107236 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
107237 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
107238 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
107239 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
107240 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
107241 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
107242 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
107243 +fpregs_set_1497 fpregs_set 4 1497 NULL
107244 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
107245 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
107246 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
107247 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
107248 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
107249 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
107250 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
107251 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
107252 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
107253 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
107254 +rmap_add_1677 rmap_add 3 1677 NULL
107255 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
107256 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
107257 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
107258 +internal_create_group_1733 internal_create_group 0 1733 NULL
107259 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
107260 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
107261 +cosa_write_1774 cosa_write 3 1774 NULL
107262 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
107263 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
107264 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
107265 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
107266 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
107267 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
107268 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
107269 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
107270 +bdev_erase_1933 bdev_erase 3 1933 NULL
107271 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
107272 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
107273 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
107274 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
107275 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
107276 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
107277 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
107278 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
107279 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
107280 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
107281 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
107282 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
107283 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
107284 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
107285 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
107286 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
107287 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
107288 +audit_expand_2098 audit_expand 0 2098 NULL
107289 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
107290 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
107291 +enable_read_2117 enable_read 3 2117 NULL
107292 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
107293 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
107294 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
107295 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
107296 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
107297 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
107298 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
107299 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
107300 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
107301 +vhci_write_2224 vhci_write 3 2224 NULL
107302 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
107303 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
107304 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
107305 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
107306 +do_update_counters_2259 do_update_counters 4 2259 NULL
107307 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
107308 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
107309 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
107310 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
107311 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
107312 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
107313 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
107314 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
107315 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
107316 +sysfs_add_file_mode_ns_2362 sysfs_add_file_mode_ns 0 2362 NULL
107317 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
107318 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
107319 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
107320 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
107321 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
107322 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
107323 +raid1_size_2419 raid1_size 0-2 2419 NULL
107324 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
107325 +wiphy_new_2482 wiphy_new 2 2482 NULL
107326 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
107327 +hfsplus_user_setxattr_2485 hfsplus_user_setxattr 4 2485 NULL
107328 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
107329 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
107330 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
107331 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
107332 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
107333 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
107334 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
107335 +slot_bytes_2609 slot_bytes 0 2609 NULL
107336 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
107337 +switch_status_2629 switch_status 5 2629 NULL
107338 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
107339 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
107340 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
107341 +oti6858_write_2692 oti6858_write 4 2692 NULL
107342 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
107343 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
107344 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
107345 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
107346 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
107347 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
107348 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
107349 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
107350 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
107351 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
107352 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
107353 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
107354 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
107355 +nla_padlen_2883 nla_padlen 1 2883 NULL
107356 +cmm_write_2896 cmm_write 3 2896 NULL
107357 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
107358 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
107359 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
107360 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
107361 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
107362 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
107363 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
107364 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
107365 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
107366 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
107367 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
107368 +depth_write_3021 depth_write 3 3021 NULL
107369 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
107370 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
107371 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
107372 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
107373 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
107374 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
107375 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
107376 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
107377 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
107378 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
107379 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
107380 +clone_bio_3100 clone_bio 6 3100 NULL nohasharray
107381 +ttusb2_msg_3100 ttusb2_msg 4 3100 &clone_bio_3100
107382 +rb_alloc_3102 rb_alloc 1 3102 NULL
107383 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
107384 +print_time_3132 print_time 0 3132 NULL
107385 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
107386 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
107387 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
107388 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
107389 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
107390 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
107391 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
107392 +alloc_context_3194 alloc_context 1 3194 NULL
107393 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
107394 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
107395 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
107396 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
107397 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
107398 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
107399 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
107400 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
107401 +key_key_read_3241 key_key_read 3 3241 NULL
107402 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
107403 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
107404 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
107405 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
107406 +ocfs2_extend_xattr_bucket_3328 ocfs2_extend_xattr_bucket 4 3328 NULL
107407 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
107408 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
107409 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
107410 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
107411 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
107412 +scnprintf_3360 scnprintf 0-2 3360 NULL
107413 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
107414 +sr_read_3366 sr_read 3 3366 NULL
107415 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
107416 +send_stream_3397 send_stream 4 3397 NULL
107417 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
107418 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
107419 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
107420 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
107421 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
107422 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
107423 +s3fb_ddc_read_3451 s3fb_ddc_read 0 3451 NULL
107424 +softsynth_write_3455 softsynth_write 3 3455 NULL
107425 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL nohasharray
107426 +jffs2_acl_setxattr_3464 jffs2_acl_setxattr 4 3464 &snd_pcm_lib_readv_transfer_3464
107427 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
107428 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
107429 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
107430 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
107431 +SyS_readv_3539 SyS_readv 3 3539 NULL
107432 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
107433 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
107434 +evtchn_read_3569 evtchn_read 3 3569 NULL
107435 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
107436 +vc_resize_3585 vc_resize 3-2 3585 NULL
107437 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
107438 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
107439 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
107440 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
107441 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
107442 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
107443 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
107444 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
107445 +ci_ll_write_3740 ci_ll_write 4 3740 NULL nohasharray
107446 +ath6kl_mgmt_tx_3740 ath6kl_mgmt_tx 7 3740 &ci_ll_write_3740
107447 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
107448 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
107449 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
107450 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
107451 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
107452 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
107453 +get_fd_set_3866 get_fd_set 1 3866 NULL
107454 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
107455 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
107456 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
107457 +nvram_write_3894 nvram_write 3 3894 NULL
107458 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
107459 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
107460 +vcs_write_3910 vcs_write 3 3910 NULL
107461 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
107462 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
107463 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
107464 +ll_get_max_mdsize_3962 ll_get_max_mdsize 0 3962 NULL
107465 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
107466 +do_add_counters_3992 do_add_counters 3 3992 NULL
107467 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
107468 +userspace_status_4004 userspace_status 4 4004 NULL
107469 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
107470 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
107471 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
107472 +blk_end_request_4024 blk_end_request 3 4024 NULL
107473 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
107474 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
107475 +read_file_queues_4078 read_file_queues 3 4078 NULL
107476 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
107477 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
107478 +tm6000_read_4151 tm6000_read 3 4151 NULL
107479 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
107480 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
107481 +get_alua_req_4166 get_alua_req 3 4166 NULL
107482 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
107483 +read_file_bool_4180 read_file_bool 3 4180 NULL
107484 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
107485 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
107486 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
107487 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
107488 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
107489 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
107490 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
107491 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
107492 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 3-2-5 4303 NULL
107493 +count_strings_4315 count_strings 0 4315 NULL
107494 +__sysfs_add_one_4326 __sysfs_add_one 0 4326 NULL
107495 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
107496 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
107497 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
107498 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
107499 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
107500 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
107501 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
107502 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
107503 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
107504 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
107505 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
107506 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
107507 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
107508 +set_link_security_4502 set_link_security 4 4502 NULL
107509 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
107510 +tty_register_device_4544 tty_register_device 2 4544 NULL
107511 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
107512 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
107513 +bch_alloc_4593 bch_alloc 1 4593 NULL
107514 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
107515 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
107516 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
107517 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
107518 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
107519 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
107520 +kone_receive_4690 kone_receive 4 4690 NULL
107521 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
107522 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
107523 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
107524 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
107525 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
107526 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
107527 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
107528 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
107529 +create_subvol_4791 create_subvol 4 4791 NULL
107530 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
107531 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
107532 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
107533 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
107534 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
107535 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
107536 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
107537 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
107538 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
107539 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
107540 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
107541 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
107542 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
107543 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
107544 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
107545 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
107546 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
107547 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
107548 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
107549 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
107550 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
107551 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
107552 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
107553 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
107554 +sound_write_5102 sound_write 3 5102 NULL
107555 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
107556 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
107557 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
107558 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
107559 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
107560 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
107561 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
107562 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
107563 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
107564 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
107565 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
107566 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
107567 +cq_free_res_5355 cq_free_res 5 5355 NULL
107568 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
107569 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
107570 +__split_bvec_across_targets_5454 __split_bvec_across_targets 3 5454 NULL
107571 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
107572 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
107573 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
107574 +tty_write_5494 tty_write 3 5494 NULL
107575 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
107576 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
107577 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
107578 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
107579 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
107580 +le_readq_5557 le_readq 0 5557 NULL
107581 +inw_5558 inw 0 5558 NULL
107582 +bioset_create_5580 bioset_create 1 5580 NULL
107583 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
107584 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
107585 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
107586 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
107587 +get_arg_5694 get_arg 3 5694 NULL
107588 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
107589 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
107590 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
107591 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
107592 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
107593 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
107594 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
107595 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
107596 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
107597 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
107598 +setup_req_5848 setup_req 3-0 5848 NULL
107599 +ria_page_count_5849 ria_page_count 0 5849 NULL
107600 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
107601 +config_buf_5862 config_buf 0 5862 NULL
107602 +iwl_dbgfs_scan_ant_rxchain_write_5877 iwl_dbgfs_scan_ant_rxchain_write 3 5877 NULL
107603 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
107604 +port_show_regs_5904 port_show_regs 3 5904 NULL
107605 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
107606 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
107607 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
107608 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
107609 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
107610 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
107611 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
107612 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
107613 +SyS_semop_5980 SyS_semop 3 5980 NULL
107614 +alloc_msg_6072 alloc_msg 1 6072 NULL
107615 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
107616 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
107617 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
107618 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
107619 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
107620 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
107621 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
107622 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
107623 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
107624 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
107625 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
107626 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
107627 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
107628 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
107629 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
107630 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
107631 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
107632 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
107633 +serial_port_in_6291 serial_port_in 0 6291 NULL
107634 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
107635 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
107636 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
107637 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
107638 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
107639 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
107640 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
107641 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
107642 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
107643 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
107644 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
107645 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
107646 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
107647 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
107648 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
107649 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
107650 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
107651 +mei_read_6507 mei_read 3 6507 NULL
107652 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
107653 +wdm_read_6549 wdm_read 3 6549 NULL
107654 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
107655 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
107656 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
107657 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
107658 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
107659 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
107660 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
107661 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
107662 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
107663 +mpeg_read_6708 mpeg_read 3 6708 NULL
107664 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
107665 +video_proc_write_6724 video_proc_write 3 6724 NULL
107666 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
107667 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
107668 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
107669 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
107670 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
107671 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
107672 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
107673 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
107674 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
107675 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
107676 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
107677 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
107678 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
107679 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
107680 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
107681 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
107682 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
107683 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
107684 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
107685 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
107686 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
107687 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
107688 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
107689 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
107690 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
107691 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
107692 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
107693 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
107694 +request_key_async_6990 request_key_async 4 6990 NULL
107695 +tpl_write_6998 tpl_write 3 6998 NULL
107696 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
107697 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
107698 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
107699 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
107700 +wimax_msg_7030 wimax_msg 4 7030 NULL
107701 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
107702 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
107703 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
107704 +event_enable_read_7074 event_enable_read 3 7074 NULL
107705 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
107706 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
107707 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
107708 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
107709 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
107710 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
107711 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
107712 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
107713 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
107714 +get_string_7302 get_string 0 7302 NULL
107715 +mgmt_control_7349 mgmt_control 3 7349 NULL
107716 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
107717 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
107718 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
107719 +hweight_long_7388 hweight_long 1-0 7388 NULL
107720 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
107721 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
107722 +readb_7401 readb 0 7401 NULL
107723 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
107724 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
107725 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
107726 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
107727 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
107728 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
107729 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
107730 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
107731 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
107732 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
107733 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
107734 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
107735 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
107736 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
107737 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
107738 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
107739 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
107740 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
107741 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
107742 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
107743 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
107744 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
107745 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
107746 +dev_write_7708 dev_write 3 7708 NULL
107747 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
107748 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
107749 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
107750 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
107751 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
107752 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
107753 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
107754 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
107755 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
107756 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
107757 +config_desc_7878 config_desc 0 7878 NULL
107758 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
107759 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
107760 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
107761 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
107762 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
107763 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
107764 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
107765 +vcs_read_8017 vcs_read 3 8017 NULL
107766 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
107767 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
107768 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
107769 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
107770 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
107771 +venus_lookup_8121 venus_lookup 4 8121 NULL
107772 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
107773 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
107774 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
107775 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
107776 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
107777 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
107778 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
107779 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
107780 +play_iframe_8219 play_iframe 3 8219 NULL
107781 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
107782 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
107783 +ceph_sync_write_8233 ceph_sync_write 4 8233 NULL
107784 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
107785 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
107786 +init_cdev_8274 init_cdev 1 8274 NULL
107787 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
107788 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
107789 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
107790 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
107791 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
107792 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
107793 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
107794 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
107795 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
107796 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
107797 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
107798 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
107799 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
107800 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
107801 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
107802 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
107803 +dev_config_8506 dev_config 3 8506 NULL
107804 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
107805 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
107806 +user_on_off_8552 user_on_off 2 8552 NULL
107807 +profile_remove_8556 profile_remove 3 8556 NULL
107808 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
107809 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
107810 +tower_write_8580 tower_write 3 8580 NULL
107811 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
107812 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
107813 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
107814 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
107815 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
107816 +generic_acl_set_8658 generic_acl_set 4 8658 NULL
107817 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
107818 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
107819 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
107820 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
107821 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
107822 +arcfb_write_8702 arcfb_write 3 8702 NULL
107823 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
107824 +init_header_8703 init_header 0 8703 &i_size_read_8703
107825 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
107826 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
107827 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
107828 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
107829 +__create_irqs_8733 __create_irqs 2 8733 NULL
107830 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
107831 +compound_order_8750 compound_order 0 8750 NULL
107832 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
107833 +yurex_write_8761 yurex_write 3 8761 NULL
107834 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
107835 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
107836 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
107837 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
107838 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
107839 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
107840 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
107841 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
107842 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
107843 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
107844 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
107845 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
107846 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
107847 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
107848 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
107849 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
107850 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
107851 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
107852 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
107853 +write_file_ani_8918 write_file_ani 3 8918 NULL
107854 +layout_commit_8926 layout_commit 3 8926 NULL
107855 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
107856 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
107857 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
107858 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
107859 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
107860 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
107861 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
107862 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
107863 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
107864 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
107865 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
107866 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
107867 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
107868 +nla_put_9042 nla_put 3 9042 NULL
107869 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
107870 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
107871 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
107872 +create_queues_9088 create_queues 2-3 9088 NULL
107873 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
107874 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
107875 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
107876 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110
107877 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
107878 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
107879 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
107880 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
107881 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
107882 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
107883 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
107884 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
107885 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
107886 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
107887 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
107888 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
107889 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
107890 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
107891 +flakey_status_9274 flakey_status 5 9274 NULL
107892 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
107893 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
107894 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
107895 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
107896 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
107897 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
107898 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
107899 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
107900 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
107901 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
107902 +read_9397 read 3 9397 NULL
107903 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
107904 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
107905 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
107906 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
107907 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
107908 +ext3_xattr_set_acl_9467 ext3_xattr_set_acl 4 9467 NULL
107909 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
107910 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
107911 +crypt_status_9492 crypt_status 5 9492 NULL
107912 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
107913 +lp_write_9511 lp_write 3 9511 NULL
107914 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
107915 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
107916 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
107917 +read_file_dma_9530 read_file_dma 3 9530 NULL
107918 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
107919 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
107920 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
107921 +fw_node_create_9559 fw_node_create 2 9559 NULL
107922 +kobj_map_9566 kobj_map 2-3 9566 NULL
107923 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
107924 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
107925 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
107926 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
107927 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
107928 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
107929 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
107930 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
107931 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
107932 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
107933 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
107934 +dns_query_9676 dns_query 3 9676 NULL
107935 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
107936 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
107937 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
107938 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
107939 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
107940 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
107941 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
107942 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
107943 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
107944 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
107945 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
107946 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
107947 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
107948 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
107949 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
107950 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
107951 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
107952 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
107953 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
107954 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
107955 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
107956 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
107957 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
107958 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
107959 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
107960 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
107961 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
107962 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
107963 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
107964 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
107965 +read_file_misc_9948 read_file_misc 3 9948 NULL
107966 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
107967 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
107968 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
107969 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
107970 +gameport_read_9983 gameport_read 0 9983 NULL
107971 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
107972 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
107973 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
107974 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
107975 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
107976 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
107977 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
107978 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
107979 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
107980 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
107981 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
107982 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
107983 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
107984 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
107985 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
107986 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
107987 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
107988 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
107989 +read_emulate_10310 read_emulate 2-4 10310 NULL
107990 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
107991 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
107992 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
107993 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
107994 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
107995 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
107996 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
107997 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
107998 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
107999 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
108000 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
108001 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
108002 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
108003 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
108004 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
108005 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
108006 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
108007 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
108008 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
108009 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
108010 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
108011 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
108012 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
108013 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
108014 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
108015 +otp_read_10594 otp_read 2-4-5 10594 NULL
108016 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
108017 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
108018 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
108019 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
108020 +parport_write_10669 parport_write 0 10669 NULL
108021 +edge_write_10692 edge_write 4 10692 NULL
108022 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
108023 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
108024 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
108025 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
108026 +spi_sync_10731 spi_sync 0 10731 NULL
108027 +apu_get_register_10737 apu_get_register 0 10737 NULL nohasharray
108028 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 &apu_get_register_10737
108029 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
108030 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
108031 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
108032 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
108033 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
108034 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
108035 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
108036 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
108037 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
108038 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
108039 +get_scq_10897 get_scq 2 10897 NULL
108040 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
108041 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
108042 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
108043 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
108044 +kobject_add_10919 kobject_add 0 10919 NULL
108045 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
108046 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
108047 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
108048 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
108049 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
108050 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
108051 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
108052 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
108053 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
108054 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
108055 +count_argc_11083 count_argc 0 11083 NULL
108056 +ocfs2_blocks_per_xattr_bucket_11099 ocfs2_blocks_per_xattr_bucket 0 11099 NULL
108057 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
108058 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
108059 +page_offset_11120 page_offset 0 11120 NULL
108060 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
108061 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
108062 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
108063 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
108064 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
108065 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
108066 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
108067 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
108068 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
108069 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
108070 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
108071 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
108072 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
108073 +construct_key_11329 construct_key 3 11329 NULL nohasharray
108074 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
108075 +next_segment_11330 next_segment 0-2-1 11330 NULL
108076 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 2-1 11332 NULL
108077 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
108078 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
108079 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
108080 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
108081 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
108082 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
108083 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
108084 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
108085 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
108086 +str_to_user_11411 str_to_user 2 11411 NULL
108087 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
108088 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
108089 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL nohasharray
108090 +import_sec_validate_get_11417 import_sec_validate_get 0 11417 &adis16480_show_firmware_revision_11417
108091 +trace_options_read_11419 trace_options_read 3 11419 NULL
108092 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
108093 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
108094 +bttv_read_11432 bttv_read 3 11432 NULL
108095 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
108096 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
108097 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
108098 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
108099 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
108100 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
108101 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
108102 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
108103 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
108104 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
108105 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
108106 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
108107 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
108108 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
108109 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
108110 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
108111 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
108112 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
108113 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
108114 +slab_ksize_11664 slab_ksize 0 11664 NULL
108115 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
108116 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
108117 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
108118 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
108119 +split_11691 split 2 11691 NULL
108120 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
108121 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
108122 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
108123 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
108124 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
108125 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
108126 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
108127 +umc_device_register_11824 umc_device_register 0 11824 NULL
108128 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
108129 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
108130 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
108131 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
108132 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
108133 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
108134 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
108135 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
108136 +ti_write_11916 ti_write 4 11916 NULL
108137 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
108138 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
108139 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
108140 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
108141 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
108142 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
108143 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
108144 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
108145 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
108146 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
108147 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
108148 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
108149 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
108150 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
108151 +set_powered_12129 set_powered 4 12129 NULL
108152 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
108153 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
108154 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
108155 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
108156 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
108157 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
108158 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
108159 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
108160 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
108161 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
108162 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
108163 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
108164 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
108165 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
108166 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
108167 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
108168 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
108169 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
108170 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
108171 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
108172 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
108173 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
108174 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
108175 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
108176 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
108177 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
108178 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
108179 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391 nohasharray
108180 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
108181 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
108182 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
108183 +ptlrpc_set_wait_12426 ptlrpc_set_wait 0 12426 NULL
108184 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
108185 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
108186 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
108187 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
108188 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
108189 +xfs_get_extsz_hint_12531 xfs_get_extsz_hint 0 12531 NULL
108190 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
108191 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
108192 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
108193 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
108194 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
108195 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
108196 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
108197 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
108198 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
108199 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
108200 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
108201 +lustre_pack_request_v2_12665 lustre_pack_request_v2 0 12665 NULL
108202 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
108203 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
108204 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
108205 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
108206 +ivtv_write_12721 ivtv_write 3 12721 NULL
108207 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
108208 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
108209 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
108210 +listxattr_12769 listxattr 3 12769 NULL
108211 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
108212 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
108213 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
108214 +readq_12825 readq 0 12825 NULL
108215 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
108216 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
108217 +spidev_sync_12842 spidev_sync 0 12842 NULL
108218 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
108219 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
108220 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
108221 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
108222 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
108223 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
108224 +bm_status_write_12964 bm_status_write 3 12964 NULL
108225 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
108226 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
108227 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
108228 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
108229 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
108230 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
108231 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
108232 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
108233 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
108234 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
108235 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
108236 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
108237 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
108238 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
108239 +blk_update_request_13146 blk_update_request 3 13146 NULL
108240 +ocfs2_quota_trans_credits_13150 ocfs2_quota_trans_credits 0 13150 NULL
108241 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
108242 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
108243 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
108244 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
108245 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
108246 +comedi_read_13199 comedi_read 3 13199 NULL
108247 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
108248 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
108249 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
108250 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
108251 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
108252 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
108253 +bio_integrity_trim_13259 bio_integrity_trim 3 13259 NULL
108254 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
108255 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
108256 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
108257 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
108258 +sd_major_13294 sd_major 0-1 13294 NULL
108259 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
108260 +__clone_and_map_data_bio_13334 __clone_and_map_data_bio 4-8 13334 NULL
108261 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
108262 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
108263 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
108264 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
108265 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
108266 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
108267 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
108268 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
108269 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
108270 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
108271 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
108272 +data_read_13494 data_read 3 13494 NULL
108273 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
108274 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
108275 +core_status_13515 core_status 4 13515 NULL
108276 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
108277 +bm_init_13529 bm_init 2 13529 NULL
108278 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
108279 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
108280 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
108281 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
108282 +cache_write_13589 cache_write 3 13589 NULL
108283 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
108284 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
108285 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
108286 +packet_snd_13634 packet_snd 3 13634 NULL
108287 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
108288 +cache_downcall_13666 cache_downcall 3 13666 NULL
108289 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
108290 +nv94_aux_13689 nv94_aux 2-5 13689 NULL
108291 +usb_get_string_13693 usb_get_string 0 13693 NULL
108292 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
108293 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
108294 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
108295 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
108296 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
108297 +random_read_13815 random_read 3 13815 NULL
108298 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
108299 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
108300 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
108301 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
108302 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
108303 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
108304 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
108305 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
108306 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
108307 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
108308 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
108309 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
108310 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
108311 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
108312 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
108313 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
108314 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
108315 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
108316 +qcam_read_13977 qcam_read 3 13977 NULL
108317 +dsp_read_13980 dsp_read 2 13980 NULL
108318 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
108319 +create_files_14003 create_files 0 14003 NULL
108320 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
108321 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
108322 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
108323 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
108324 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
108325 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
108326 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
108327 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
108328 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
108329 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
108330 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
108331 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
108332 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
108333 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
108334 +em_canid_change_14150 em_canid_change 3 14150 NULL
108335 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
108336 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
108337 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
108338 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
108339 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
108340 +alloc_async_14208 alloc_async 1 14208 NULL
108341 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
108342 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
108343 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
108344 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
108345 +rr_status_14293 rr_status 5 14293 NULL
108346 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
108347 +oo_objects_14319 oo_objects 0 14319 NULL
108348 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
108349 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
108350 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
108351 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
108352 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
108353 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
108354 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
108355 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
108356 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
108357 +block_size_14443 block_size 0 14443 NULL
108358 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
108359 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
108360 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
108361 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
108362 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
108363 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
108364 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
108365 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
108366 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
108367 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
108368 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
108369 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
108370 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
108371 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
108372 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
108373 +dbJoin_14644 dbJoin 0 14644 NULL
108374 +profile_replace_14652 profile_replace 3 14652 NULL
108375 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
108376 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
108377 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
108378 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
108379 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
108380 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
108381 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
108382 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
108383 +cgroup_path_14713 cgroup_path 3 14713 NULL
108384 +vfd_write_14717 vfd_write 3 14717 NULL
108385 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
108386 +raid1_resize_14740 raid1_resize 2 14740 NULL
108387 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
108388 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
108389 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
108390 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
108391 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
108392 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
108393 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
108394 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
108395 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
108396 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
108397 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
108398 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
108399 +lcd_write_14857 lcd_write 3 14857 NULL
108400 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
108401 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
108402 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
108403 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
108404 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
108405 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
108406 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
108407 +queue_cnt_14951 queue_cnt 0 14951 NULL
108408 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
108409 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
108410 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
108411 +setkey_14987 setkey 3 14987 NULL nohasharray
108412 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
108413 +xfs_dinode_size_14996 xfs_dinode_size 0 14996 NULL
108414 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
108415 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
108416 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
108417 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
108418 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
108419 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
108420 +ceph_calc_ceph_pg_15075 ceph_calc_ceph_pg 0 15075 NULL
108421 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
108422 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
108423 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
108424 +start_port_15124 start_port 0 15124 NULL
108425 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
108426 +iwl_dbgfs_sta_drain_write_15167 iwl_dbgfs_sta_drain_write 3 15167 NULL
108427 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
108428 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
108429 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
108430 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
108431 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
108432 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
108433 +simple_strtol_15273 simple_strtol 0 15273 NULL
108434 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
108435 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
108436 +xlog_ticket_alloc_15335 xlog_ticket_alloc 2 15335 NULL
108437 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
108438 +ioread16_15342 ioread16 0 15342 NULL
108439 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
108440 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
108441 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
108442 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
108443 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
108444 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
108445 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
108446 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
108447 +get_modalias_15406 get_modalias 2 15406 NULL
108448 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
108449 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
108450 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
108451 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
108452 +memweight_15450 memweight 2 15450 NULL
108453 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
108454 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
108455 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
108456 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
108457 +persistent_status_15574 persistent_status 4 15574 NULL
108458 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
108459 +vme_user_write_15587 vme_user_write 3 15587 NULL
108460 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
108461 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
108462 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
108463 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
108464 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
108465 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
108466 +fs_path_add_15648 fs_path_add 3 15648 NULL
108467 +xsd_read_15653 xsd_read 3 15653 NULL
108468 +unix_bind_15668 unix_bind 3 15668 NULL
108469 +dm_read_15674 dm_read 3 15674 NULL nohasharray
108470 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
108471 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
108472 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
108473 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
108474 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
108475 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
108476 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
108477 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
108478 +table_size_15851 table_size 0-1-2 15851 NULL
108479 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
108480 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
108481 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
108482 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
108483 +native_read_msr_15905 native_read_msr 0 15905 NULL
108484 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
108485 +power_read_15939 power_read 3 15939 NULL
108486 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
108487 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
108488 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
108489 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
108490 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
108491 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
108492 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
108493 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
108494 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
108495 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
108496 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
108497 +fsm_init_16134 fsm_init 2 16134 NULL
108498 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
108499 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
108500 +mapping_level_16188 mapping_level 2-0 16188 NULL
108501 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
108502 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
108503 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
108504 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
108505 +create_table_16213 create_table 2 16213 NULL
108506 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
108507 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
108508 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
108509 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
108510 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
108511 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
108512 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
108513 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
108514 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
108515 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
108516 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
108517 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
108518 +account_16283 account 0-4-2 16283 NULL nohasharray
108519 +mirror_status_16283 mirror_status 5 16283 &account_16283
108520 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
108521 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
108522 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
108523 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
108524 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
108525 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
108526 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
108527 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
108528 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
108529 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
108530 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
108531 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
108532 +cmdline_store_16442 cmdline_store 4 16442 NULL
108533 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
108534 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
108535 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
108536 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
108537 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
108538 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
108539 +raid10_resize_16537 raid10_resize 2 16537 NULL
108540 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
108541 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
108542 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
108543 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
108544 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
108545 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
108546 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
108547 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
108548 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
108549 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
108550 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
108551 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
108552 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
108553 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
108554 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
108555 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
108556 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
108557 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
108558 +st_write_16874 st_write 3 16874 NULL
108559 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
108560 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
108561 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
108562 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
108563 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
108564 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
108565 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
108566 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
108567 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
108568 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
108569 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
108570 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
108571 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
108572 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
108573 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
108574 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
108575 +entry_length_17093 entry_length 0 17093 NULL
108576 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
108577 +write_mem_17114 write_mem 3 17114 NULL
108578 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
108579 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
108580 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
108581 +sep_read_17161 sep_read 3 17161 NULL
108582 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
108583 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
108584 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
108585 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
108586 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
108587 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
108588 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
108589 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
108590 +sync_request_17208 sync_request 2 17208 NULL
108591 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
108592 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
108593 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
108594 +alloc_ep_17269 alloc_ep 1 17269 NULL
108595 +pg_read_17276 pg_read 3 17276 NULL
108596 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
108597 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
108598 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
108599 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
108600 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 0 17298 NULL
108601 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
108602 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
108603 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
108604 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
108605 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
108606 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
108607 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
108608 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
108609 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
108610 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
108611 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
108612 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
108613 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
108614 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
108615 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
108616 +qp_free_res_17541 qp_free_res 5 17541 NULL
108617 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
108618 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
108619 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
108620 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
108621 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
108622 +osst_execute_17607 osst_execute 7-6 17607 NULL
108623 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
108624 +dma_map_page_17628 dma_map_page 0 17628 NULL
108625 +ocfs2_rotate_subtree_left_17634 ocfs2_rotate_subtree_left 5 17634 NULL
108626 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
108627 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
108628 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
108629 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
108630 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
108631 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
108632 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
108633 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
108634 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
108635 +brcmf_sdio_chip_verifynvram_17776 brcmf_sdio_chip_verifynvram 4 17776 NULL
108636 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
108637 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
108638 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
108639 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
108640 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
108641 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
108642 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
108643 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
108644 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
108645 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
108646 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
108647 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
108648 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
108649 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
108650 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
108651 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
108652 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
108653 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
108654 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
108655 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
108656 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
108657 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
108658 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
108659 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
108660 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
108661 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
108662 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
108663 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
108664 +fpregs_get_18066 fpregs_get 4 18066 NULL
108665 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
108666 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
108667 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
108668 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
108669 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
108670 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
108671 +svc_getnl_18120 svc_getnl 0 18120 NULL
108672 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
108673 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
108674 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
108675 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
108676 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
108677 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
108678 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
108679 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
108680 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
108681 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
108682 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
108683 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
108684 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
108685 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
108686 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
108687 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
108688 +um_idi_write_18293 um_idi_write 3 18293 NULL
108689 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
108690 +vga_r_18310 vga_r 0 18310 NULL
108691 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
108692 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
108693 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
108694 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
108695 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
108696 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
108697 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
108698 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
108699 +ep_io_18367 ep_io 0 18367 NULL
108700 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
108701 +ci_role_write_18388 ci_role_write 3 18388 NULL
108702 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
108703 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
108704 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
108705 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
108706 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
108707 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
108708 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
108709 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
108710 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
108711 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
108712 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
108713 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
108714 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
108715 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
108716 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
108717 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
108718 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
108719 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
108720 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
108721 +debug_output_18575 debug_output 3 18575 NULL
108722 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
108723 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
108724 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
108725 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL nohasharray
108726 +audio_get_endpoint_req_18624 audio_get_endpoint_req 0 18624 &nvc0_ram_create__18624
108727 +from_buffer_18625 from_buffer 3 18625 NULL
108728 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
108729 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
108730 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
108731 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
108732 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
108733 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
108734 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
108735 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
108736 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
108737 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
108738 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
108739 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
108740 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
108741 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
108742 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
108743 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
108744 +prealloc_18800 prealloc 0 18800 NULL
108745 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
108746 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
108747 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
108748 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
108749 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
108750 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
108751 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
108752 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
108753 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
108754 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
108755 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
108756 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
108757 +huge_page_size_19008 huge_page_size 0 19008 NULL
108758 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
108759 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
108760 +revalidate_19043 revalidate 2 19043 NULL
108761 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
108762 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
108763 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
108764 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
108765 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
108766 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
108767 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
108768 +ATOMIC_SUB_RETURN_19115 ATOMIC_SUB_RETURN 2 19115 NULL
108769 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
108770 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
108771 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
108772 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
108773 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
108774 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
108775 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
108776 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
108777 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
108778 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
108779 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
108780 +ucma_query_19260 ucma_query 4 19260 NULL
108781 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
108782 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
108783 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
108784 +qc_capture_19298 qc_capture 3 19298 NULL
108785 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
108786 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
108787 +debug_read_19322 debug_read 3 19322 NULL
108788 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
108789 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
108790 +closure_sub_19359 closure_sub 2 19359 NULL
108791 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
108792 +read_zero_19366 read_zero 3 19366 NULL
108793 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
108794 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
108795 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
108796 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
108797 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
108798 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
108799 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
108800 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
108801 +sky2_read16_19475 sky2_read16 0 19475 NULL
108802 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
108803 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
108804 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
108805 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
108806 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
108807 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
108808 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
108809 +howmany_64_19548 howmany_64 2 19548 NULL
108810 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
108811 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
108812 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
108813 +nfsd_read_19568 nfsd_read 5 19568 NULL
108814 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
108815 +bm_status_read_19583 bm_status_read 3 19583 NULL
108816 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
108817 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
108818 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
108819 +iwl_dbgfs_pm_params_write_19660 iwl_dbgfs_pm_params_write 3 19660 NULL
108820 +read_reg_19723 read_reg 0 19723 NULL
108821 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
108822 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
108823 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
108824 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
108825 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
108826 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
108827 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
108828 +readhscx_19769 readhscx 0 19769 NULL
108829 +__set_print_fmt_19776 __set_print_fmt 0 19776 NULL
108830 +iwl_dbgfs_disable_power_off_write_19823 iwl_dbgfs_disable_power_off_write 3 19823 NULL
108831 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
108832 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
108833 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
108834 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
108835 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
108836 +__nla_put_19857 __nla_put 3 19857 NULL
108837 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
108838 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
108839 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
108840 +mangle_name_19923 mangle_name 0 19923 NULL
108841 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
108842 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
108843 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
108844 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
108845 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
108846 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
108847 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
108848 +lustre_pack_request_19992 lustre_pack_request 0 19992 NULL
108849 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
108850 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL
108851 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
108852 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
108853 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
108854 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
108855 +target_message_20072 target_message 2 20072 NULL
108856 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
108857 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
108858 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
108859 +team_options_register_20091 team_options_register 3 20091 NULL
108860 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
108861 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
108862 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
108863 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
108864 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
108865 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
108866 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
108867 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
108868 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
108869 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
108870 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
108871 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
108872 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
108873 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
108874 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
108875 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
108876 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
108877 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
108878 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
108879 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
108880 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
108881 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
108882 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
108883 +nfs3_setxattr_20458 nfs3_setxattr 4 20458 NULL
108884 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
108885 +read_buf_20469 read_buf 2 20469 NULL
108886 +bio_trim_20472 bio_trim 2 20472 NULL
108887 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
108888 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
108889 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
108890 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
108891 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
108892 +venus_create_20555 venus_create 4 20555 NULL
108893 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
108894 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
108895 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
108896 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
108897 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
108898 +lirc_write_20604 lirc_write 3 20604 NULL
108899 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
108900 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
108901 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
108902 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
108903 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
108904 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
108905 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
108906 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
108907 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
108908 +cpumask_size_20683 cpumask_size 0 20683 NULL
108909 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
108910 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
108911 +__maestro_read_20700 __maestro_read 0 20700 NULL
108912 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
108913 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
108914 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
108915 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
108916 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
108917 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
108918 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
108919 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
108920 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
108921 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
108922 +strndup_user_20819 strndup_user 2 20819 NULL
108923 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
108924 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
108925 +uvc_alloc_entity_20836 uvc_alloc_entity 3-4 20836 NULL
108926 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
108927 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
108928 +get_name_20855 get_name 4 20855 NULL
108929 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
108930 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
108931 +srq_free_res_20868 srq_free_res 5 20868 NULL
108932 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
108933 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
108934 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
108935 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
108936 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
108937 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
108938 +htable_bits_20933 htable_bits 0 20933 NULL
108939 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
108940 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
108941 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
108942 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
108943 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
108944 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
108945 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
108946 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
108947 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
108948 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
108949 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
108950 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
108951 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
108952 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
108953 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
108954 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
108955 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
108956 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
108957 +ocfs2_extend_meta_needed_21104 ocfs2_extend_meta_needed 0 21104 NULL
108958 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
108959 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
108960 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
108961 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
108962 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
108963 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
108964 +input_ff_create_21240 input_ff_create 2 21240 NULL
108965 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
108966 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
108967 +fru_length_21257 fru_length 0 21257 NULL
108968 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
108969 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
108970 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
108971 +add_res_range_21310 add_res_range 4 21310 NULL
108972 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
108973 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
108974 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
108975 +ocfs2_find_subtree_root_21351 ocfs2_find_subtree_root 0 21351 NULL
108976 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
108977 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
108978 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
108979 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
108980 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
108981 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
108982 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
108983 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
108984 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
108985 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
108986 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
108987 +ReadISAR_21453 ReadISAR 0 21453 NULL
108988 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
108989 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
108990 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
108991 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
108992 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
108993 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
108994 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
108995 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
108996 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
108997 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
108998 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
108999 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
109000 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
109001 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
109002 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
109003 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
109004 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
109005 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
109006 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
109007 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
109008 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
109009 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
109010 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
109011 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
109012 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
109013 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
109014 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
109015 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
109016 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
109017 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
109018 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
109019 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
109020 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
109021 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
109022 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
109023 +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
109024 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
109025 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
109026 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
109027 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
109028 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
109029 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
109030 +mem_rw_22085 mem_rw 3 22085 NULL
109031 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
109032 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
109033 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
109034 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
109035 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
109036 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
109037 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
109038 +mem_write_22232 mem_write 3 22232 NULL
109039 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
109040 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
109041 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
109042 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
109043 +add_res_tree_22263 add_res_tree 7 22263 NULL
109044 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
109045 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
109046 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
109047 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
109048 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
109049 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
109050 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
109051 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
109052 +atomic_read_22342 atomic_read 0 22342 NULL
109053 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
109054 +memcg_size_22360 memcg_size 0 22360 NULL
109055 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
109056 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
109057 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
109058 +zoran_write_22404 zoran_write 3 22404 NULL
109059 +ATOMIC_ADD_RETURN_22413 ATOMIC_ADD_RETURN 2 22413 NULL
109060 +queue_reply_22416 queue_reply 3 22416 NULL
109061 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
109062 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
109063 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
109064 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
109065 +source_sink_start_ep_22472 source_sink_start_ep 0 22472 NULL
109066 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
109067 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
109068 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
109069 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
109070 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
109071 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
109072 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
109073 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
109074 +snapshot_read_22601 snapshot_read 3 22601 NULL
109075 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
109076 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
109077 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
109078 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
109079 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
109080 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
109081 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
109082 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
109083 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
109084 +reg_umr_22686 reg_umr 5 22686 NULL
109085 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
109086 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
109087 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
109088 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
109089 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
109090 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
109091 +print_frame_22769 print_frame 0 22769 NULL
109092 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
109093 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
109094 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
109095 +clone_bio_integrity_22842 clone_bio_integrity 4 22842 NULL
109096 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
109097 +create_attr_set_22861 create_attr_set 1 22861 NULL
109098 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
109099 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
109100 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
109101 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
109102 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL
109103 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
109104 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
109105 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
109106 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
109107 +vme_get_size_22964 vme_get_size 0 22964 NULL
109108 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
109109 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
109110 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
109111 +brcmf_sdio_chip_exit_download_23001 brcmf_sdio_chip_exit_download 4 23001 NULL
109112 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
109113 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
109114 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0-6-7 23029 NULL
109115 +st_status_23032 st_status 5 23032 NULL
109116 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
109117 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
109118 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
109119 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
109120 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
109121 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
109122 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
109123 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
109124 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
109125 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
109126 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
109127 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
109128 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
109129 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
109130 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL
109131 +__clear_user_23118 __clear_user 0-2 23118 NULL
109132 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
109133 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
109134 +read_file_ani_23161 read_file_ani 3 23161 NULL
109135 +usblp_write_23178 usblp_write 3 23178 NULL
109136 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
109137 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
109138 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
109139 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
109140 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
109141 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
109142 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
109143 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
109144 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
109145 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
109146 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
109147 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
109148 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
109149 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
109150 +page_readlink_23346 page_readlink 3 23346 NULL
109151 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
109152 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
109153 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
109154 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
109155 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
109156 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
109157 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
109158 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
109159 +linear_conf_23485 linear_conf 2 23485 NULL
109160 +event_filter_read_23494 event_filter_read 3 23494 NULL
109161 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
109162 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
109163 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
109164 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
109165 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
109166 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
109167 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
109168 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
109169 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
109170 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
109171 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
109172 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
109173 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
109174 +sInW_23663 sInW 0 23663 NULL
109175 +SyS_connect_23669 SyS_connect 3 23669 NULL
109176 +cx18_read_23699 cx18_read 3 23699 NULL
109177 +at_get_23708 at_get 0 23708 NULL
109178 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
109179 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
109180 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
109181 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
109182 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
109183 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
109184 +map_write_23795 map_write 3 23795 NULL
109185 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
109186 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
109187 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
109188 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
109189 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 3-4 23829 NULL
109190 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
109191 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
109192 +p54_init_common_23850 p54_init_common 1 23850 NULL
109193 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
109194 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
109195 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
109196 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL
109197 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
109198 +usbg_prepare_w_request_23895 usbg_prepare_w_request 0 23895 NULL
109199 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
109200 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
109201 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
109202 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
109203 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
109204 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
109205 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
109206 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
109207 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
109208 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
109209 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
109210 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
109211 +give_pages_24021 give_pages 3 24021 NULL
109212 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
109213 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
109214 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
109215 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
109216 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
109217 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
109218 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
109219 +lov_brw_24122 lov_brw 4 24122 NULL
109220 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
109221 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
109222 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
109223 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
109224 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
109225 +adu_read_24177 adu_read 3 24177 NULL
109226 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
109227 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
109228 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
109229 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
109230 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
109231 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
109232 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
109233 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
109234 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
109235 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
109236 +thin_status_24278 thin_status 5 24278 NULL
109237 +msg_size_24288 msg_size 0 24288 NULL
109238 +gserial_connect_24302 gserial_connect 0 24302 NULL
109239 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
109240 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
109241 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
109242 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
109243 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
109244 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
109245 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
109246 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
109247 +igetword_24373 igetword 0 24373 NULL
109248 +max_io_len_24384 max_io_len 0-1 24384 NULL
109249 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
109250 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
109251 +getxattr_24398 getxattr 4 24398 NULL nohasharray
109252 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
109253 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
109254 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
109255 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
109256 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
109257 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
109258 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
109259 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
109260 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
109261 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
109262 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
109263 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
109264 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
109265 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
109266 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
109267 +pd_video_read_24510 pd_video_read 3 24510 NULL
109268 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
109269 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
109270 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
109271 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
109272 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
109273 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
109274 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
109275 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
109276 +SyS_poll_24620 SyS_poll 2 24620 NULL
109277 +context_alloc_24645 context_alloc 3 24645 NULL
109278 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
109279 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
109280 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
109281 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
109282 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
109283 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
109284 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
109285 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
109286 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
109287 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
109288 +cache_read_24790 cache_read 3 24790 NULL
109289 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
109290 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
109291 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
109292 +net2272_read_24825 net2272_read 0 24825 NULL
109293 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
109294 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
109295 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
109296 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
109297 +queues_read_24877 queues_read 3 24877 NULL
109298 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
109299 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
109300 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
109301 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
109302 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
109303 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
109304 +ll_layout_fetch_24961 ll_layout_fetch 0 24961 NULL
109305 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
109306 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
109307 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
109308 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
109309 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
109310 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
109311 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
109312 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
109313 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
109314 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
109315 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
109316 +iwl_dbgfs_tx_flush_write_25091 iwl_dbgfs_tx_flush_write 3 25091 NULL
109317 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
109318 +blkg_path_25099 blkg_path 3 25099 NULL
109319 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
109320 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
109321 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
109322 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
109323 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
109324 +stripe_status_25259 stripe_status 5 25259 NULL
109325 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
109326 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
109327 +vfs_writev_25278 vfs_writev 3 25278 NULL
109328 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
109329 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
109330 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
109331 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
109332 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
109333 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
109334 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
109335 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
109336 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
109337 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
109338 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
109339 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
109340 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
109341 +sb_permission_25523 sb_permission 0 25523 NULL
109342 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
109343 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
109344 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
109345 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
109346 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
109347 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
109348 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
109349 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
109350 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
109351 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
109352 +__direct_map_25647 __direct_map 6-5 25647 NULL
109353 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
109354 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
109355 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
109356 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
109357 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
109358 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
109359 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
109360 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
109361 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
109362 +sg_read_25799 sg_read 3 25799 NULL
109363 +system_enable_read_25815 system_enable_read 3 25815 NULL
109364 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
109365 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
109366 +parport_read_25855 parport_read 0 25855 NULL
109367 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
109368 +key_attr_size_25865 key_attr_size 0 25865 NULL
109369 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
109370 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
109371 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
109372 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
109373 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
109374 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
109375 +rcname_read_25919 rcname_read 3 25919 NULL
109376 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
109377 +key_flags_read_25931 key_flags_read 3 25931 NULL
109378 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
109379 +flush_25957 flush 2 25957 NULL
109380 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
109381 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
109382 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
109383 +xfs_xattr_acl_set_26028 xfs_xattr_acl_set 4 26028 NULL
109384 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
109385 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
109386 +tun_do_read_26047 tun_do_read 5 26047 NULL
109387 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
109388 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
109389 +read_sb_page_26119 read_sb_page 5 26119 NULL
109390 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
109391 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
109392 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
109393 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
109394 +disk_devt_26180 disk_devt 0 26180 NULL
109395 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
109396 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
109397 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
109398 +mce_write_26201 mce_write 3 26201 NULL
109399 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
109400 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
109401 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
109402 +bio_split_26235 bio_split 2 26235 NULL
109403 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
109404 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
109405 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
109406 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL nohasharray
109407 +pax_get_random_long_26309 pax_get_random_long 0 26309 &snd_pcm_plug_client_channels_buf_26309
109408 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
109409 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
109410 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
109411 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
109412 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
109413 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
109414 +ntty_write_26404 ntty_write 3 26404 NULL
109415 +firmware_store_26408 firmware_store 4 26408 NULL
109416 +pagemap_read_26441 pagemap_read 3 26441 NULL
109417 +tower_read_26461 tower_read 3 26461 NULL nohasharray
109418 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
109419 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
109420 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
109421 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
109422 +read_vmcore_26501 read_vmcore 3 26501 NULL
109423 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
109424 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
109425 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
109426 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
109427 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
109428 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
109429 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
109430 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
109431 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
109432 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
109433 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
109434 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
109435 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
109436 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
109437 +bos_desc_26752 bos_desc 0 26752 NULL
109438 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
109439 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
109440 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
109441 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
109442 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
109443 +smk_write_load_26829 smk_write_load 3 26829 NULL
109444 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
109445 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
109446 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
109447 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
109448 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
109449 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
109450 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
109451 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
109452 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
109453 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
109454 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
109455 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
109456 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
109457 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
109458 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
109459 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
109460 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
109461 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
109462 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
109463 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
109464 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
109465 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
109466 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
109467 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
109468 +pms_capture_27142 pms_capture 4 27142 NULL
109469 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
109470 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
109471 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
109472 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
109473 +write_kmem_27225 write_kmem 3 27225 NULL
109474 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
109475 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
109476 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
109477 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
109478 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
109479 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
109480 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
109481 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
109482 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
109483 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
109484 +seq_read_27411 seq_read 3 27411 NULL
109485 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
109486 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
109487 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0-3-4 27422 NULL
109488 +cypress_write_27423 cypress_write 4 27423 NULL
109489 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
109490 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
109491 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
109492 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
109493 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
109494 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
109495 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
109496 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
109497 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
109498 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
109499 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
109500 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
109501 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
109502 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
109503 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
109504 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642
109505 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
109506 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
109507 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
109508 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
109509 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
109510 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
109511 +evm_write_key_27715 evm_write_key 3 27715 NULL
109512 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
109513 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
109514 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
109515 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
109516 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
109517 +SyS_readv_27804 SyS_readv 3 27804 NULL
109518 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
109519 +fwtty_buffer_rx_27821 fwtty_buffer_rx 3 27821 NULL
109520 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
109521 +init_header_complete_27833 init_header_complete 0 27833 NULL
109522 +read_profile_27859 read_profile 3 27859 NULL
109523 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
109524 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
109525 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
109526 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
109527 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
109528 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
109529 +device_register_27972 device_register 0 27972 NULL nohasharray
109530 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
109531 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
109532 +f2fs_bio_alloc_27983 f2fs_bio_alloc 2 27983 NULL
109533 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
109534 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
109535 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
109536 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
109537 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
109538 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
109539 +pool_status_28055 pool_status 5 28055 NULL
109540 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
109541 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
109542 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
109543 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
109544 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
109545 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
109546 +video_read_28148 video_read 3 28148 NULL
109547 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
109548 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
109549 +vread_28173 vread 0-3 28173 NULL
109550 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
109551 +counter_free_res_28187 counter_free_res 5 28187 NULL
109552 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
109553 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
109554 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
109555 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
109556 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
109557 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
109558 +usemap_size_28281 usemap_size 0 28281 NULL
109559 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
109560 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
109561 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
109562 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
109563 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
109564 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
109565 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
109566 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
109567 +snapshot_write_28351 snapshot_write 3 28351 NULL
109568 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
109569 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
109570 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
109571 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
109572 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
109573 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
109574 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
109575 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
109576 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
109577 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
109578 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
109579 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
109580 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
109581 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
109582 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
109583 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
109584 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
109585 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
109586 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
109587 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
109588 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
109589 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
109590 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
109591 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
109592 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
109593 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
109594 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
109595 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
109596 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
109597 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
109598 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
109599 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
109600 +spi_execute_28736 spi_execute 5 28736 NULL
109601 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
109602 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
109603 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
109604 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
109605 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
109606 +sel_write_member_28800 sel_write_member 3 28800 NULL
109607 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
109608 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
109609 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
109610 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
109611 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
109612 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
109613 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
109614 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
109615 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
109616 +push_rx_28939 push_rx 3 28939 NULL
109617 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
109618 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
109619 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
109620 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
109621 +bin_uuid_28999 bin_uuid 3 28999 NULL
109622 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
109623 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
109624 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
109625 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
109626 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
109627 +roundup_64_29066 roundup_64 2-0-1 29066 NULL
109628 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
109629 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
109630 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
109631 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
109632 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
109633 +snprintf_29125 snprintf 0 29125 NULL
109634 +iov_shorten_29130 iov_shorten 0 29130 NULL
109635 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
109636 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
109637 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
109638 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
109639 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
109640 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
109641 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
109642 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
109643 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
109644 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
109645 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
109646 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
109647 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
109648 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
109649 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
109650 +tun_put_user_29337 tun_put_user 5 29337 NULL
109651 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
109652 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
109653 +mwifiex_cfg80211_mgmt_tx_29387 mwifiex_cfg80211_mgmt_tx 7 29387 NULL
109654 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
109655 +mempool_create_29437 mempool_create 1 29437 NULL
109656 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
109657 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
109658 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
109659 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
109660 +do_register_entry_29478 do_register_entry 4 29478 NULL
109661 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
109662 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
109663 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
109664 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
109665 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
109666 +ftrace_write_29551 ftrace_write 3 29551 NULL
109667 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
109668 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
109669 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
109670 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
109671 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
109672 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
109673 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
109674 +slots_per_page_29601 slots_per_page 0 29601 NULL
109675 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
109676 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
109677 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
109678 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
109679 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
109680 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
109681 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
109682 +probes_write_29711 probes_write 3 29711 NULL
109683 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
109684 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
109685 +std_nic_write_29752 std_nic_write 3 29752 NULL
109686 +dbAlloc_29794 dbAlloc 0 29794 NULL
109687 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
109688 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
109689 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
109690 +count_partial_29850 count_partial 0 29850 NULL
109691 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
109692 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
109693 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
109694 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
109695 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
109696 +write_file_queue_29922 write_file_queue 3 29922 NULL
109697 +ext4_xattr_set_acl_29930 ext4_xattr_set_acl 4 29930 NULL
109698 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
109699 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
109700 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
109701 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
109702 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
109703 +drp_wmove_30043 drp_wmove 4 30043 NULL
109704 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
109705 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
109706 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
109707 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
109708 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
109709 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
109710 +recv_stream_30138 recv_stream 4 30138 NULL
109711 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
109712 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
109713 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
109714 +expand_inode_data_30169 expand_inode_data 2-3 30169 NULL
109715 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
109716 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
109717 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
109718 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
109719 +SyS_semop_30227 SyS_semop 3 30227 NULL
109720 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
109721 +ocfs2_calc_bg_discontig_credits_30230 ocfs2_calc_bg_discontig_credits 0 30230 NULL
109722 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
109723 +hfsplus_trusted_setxattr_30270 hfsplus_trusted_setxattr 4 30270 NULL
109724 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
109725 +compat_readv_30273 compat_readv 3 30273 NULL
109726 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
109727 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
109728 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
109729 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
109730 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
109731 +i8254_read_30330 i8254_read 0 30330 NULL
109732 +resource_from_user_30341 resource_from_user 3 30341 NULL
109733 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
109734 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
109735 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
109736 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
109737 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
109738 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
109739 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
109740 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
109741 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
109742 +enable_write_30456 enable_write 3 30456 NULL
109743 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
109744 +urandom_read_30462 urandom_read 3 30462 NULL
109745 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
109746 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
109747 +adu_write_30487 adu_write 3 30487 NULL
109748 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
109749 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
109750 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
109751 +set_config_30526 set_config 0 30526 NULL nohasharray
109752 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
109753 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
109754 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
109755 +set_le_30581 set_le 4 30581 NULL
109756 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
109757 +i2c_hid_get_report_length_30598 i2c_hid_get_report_length 0 30598 NULL
109758 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL nohasharray
109759 +cpufreq_get_global_kobject_30610 cpufreq_get_global_kobject 0 30610 &sgl_map_user_pages_30610
109760 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
109761 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
109762 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
109763 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
109764 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
109765 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
109766 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
109767 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
109768 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
109769 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
109770 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
109771 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
109772 +snapshot_status_30744 snapshot_status 5 30744 NULL
109773 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
109774 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
109775 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
109776 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
109777 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
109778 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
109779 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
109780 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
109781 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
109782 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
109783 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
109784 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
109785 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
109786 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
109787 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
109788 +stride_pg_count_31053 stride_pg_count 0-2-1-4-3-5 31053 NULL
109789 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
109790 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
109791 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
109792 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
109793 +depth_read_31112 depth_read 3 31112 NULL
109794 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
109795 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
109796 +size_inside_page_31141 size_inside_page 0 31141 NULL
109797 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
109798 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
109799 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
109800 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
109801 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
109802 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
109803 +__read_reg_31216 __read_reg 0 31216 NULL
109804 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
109805 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
109806 +cyy_readb_31240 cyy_readb 0 31240 NULL
109807 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
109808 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
109809 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
109810 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
109811 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
109812 +command_file_write_31318 command_file_write 3 31318 NULL
109813 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
109814 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
109815 +outlen_write_31358 outlen_write 3 31358 NULL
109816 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
109817 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
109818 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
109819 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
109820 +inb_31388 inb 0 31388 NULL
109821 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
109822 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
109823 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
109824 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
109825 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
109826 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
109827 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
109828 +alg_setkey_31485 alg_setkey 3 31485 NULL
109829 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
109830 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
109831 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
109832 +hidraw_write_31536 hidraw_write 3 31536 NULL
109833 +usbvision_read_31555 usbvision_read 3 31555 NULL
109834 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
109835 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
109836 +osst_write_31581 osst_write 3 31581 NULL
109837 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
109838 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
109839 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
109840 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
109841 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
109842 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
109843 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
109844 +__lgread_31668 __lgread 4 31668 NULL
109845 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
109846 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
109847 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
109848 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
109849 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
109850 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
109851 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
109852 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
109853 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
109854 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
109855 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
109856 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
109857 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
109858 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
109859 +data_write_31805 data_write 3 31805 NULL
109860 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
109861 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
109862 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
109863 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
109864 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
109865 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
109866 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
109867 +xattr_permission_31907 xattr_permission 0 31907 NULL
109868 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
109869 +new_dir_31919 new_dir 3 31919 NULL
109870 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
109871 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
109872 +read_mem_31942 read_mem 3 31942 NULL nohasharray
109873 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
109874 +vb2_write_31948 vb2_write 3 31948 NULL
109875 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
109876 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
109877 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
109878 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
109879 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
109880 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
109881 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
109882 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
109883 +calc_hmac_32010 calc_hmac 3 32010 NULL
109884 +aead_len_32021 aead_len 0 32021 NULL
109885 +posix_acl_set_32037 posix_acl_set 4 32037 NULL
109886 +stk_read_32038 stk_read 3 32038 NULL
109887 +ocfs2_update_edge_lengths_32046 ocfs2_update_edge_lengths 3 32046 NULL
109888 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
109889 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
109890 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
109891 +bio_alloc_32095 bio_alloc 2 32095 NULL
109892 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
109893 +disk_status_32120 disk_status 4 32120 NULL
109894 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
109895 +venus_link_32165 venus_link 5 32165 NULL
109896 +do_writepages_32173 do_writepages 0 32173 NULL
109897 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
109898 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
109899 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
109900 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
109901 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
109902 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
109903 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
109904 +SyS_select_32319 SyS_select 1 32319 NULL
109905 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
109906 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
109907 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
109908 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
109909 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
109910 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
109911 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
109912 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
109913 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
109914 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
109915 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
109916 +cache_status_32462 cache_status 5 32462 NULL
109917 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
109918 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
109919 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
109920 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
109921 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
109922 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
109923 +disconnect_32521 disconnect 4 32521 NULL
109924 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
109925 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL nohasharray
109926 +audio_get_intf_req_32524 audio_get_intf_req 0 32524 &ocfs2_refresh_qinfo_32524
109927 +ilo_read_32531 ilo_read 3 32531 NULL
109928 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
109929 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
109930 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
109931 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
109932 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
109933 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
109934 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
109935 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
109936 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
109937 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
109938 +kvmalloc_32646 kvmalloc 1 32646 NULL
109939 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
109940 +generic_readlink_32654 generic_readlink 3 32654 NULL
109941 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
109942 +apei_res_add_32674 apei_res_add 0 32674 NULL
109943 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
109944 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
109945 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
109946 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
109947 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
109948 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
109949 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
109950 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
109951 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
109952 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
109953 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
109954 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
109955 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 6-4 32884 NULL
109956 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
109957 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
109958 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
109959 +xfs_log_reserve_32959 xfs_log_reserve 2 32959 NULL
109960 +ocfs2_check_dir_trailer_32968 ocfs2_check_dir_trailer 0 32968 NULL
109961 +compat_filldir_32999 compat_filldir 3 32999 NULL
109962 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
109963 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
109964 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
109965 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
109966 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
109967 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
109968 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
109969 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
109970 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
109971 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
109972 +alloc_tio_33077 alloc_tio 3 33077 NULL
109973 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
109974 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
109975 +__len_within_target_33132 __len_within_target 0 33132 NULL
109976 +SyS_poll_33152 SyS_poll 2 33152 NULL
109977 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
109978 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
109979 +pp_read_33210 pp_read 3 33210 NULL
109980 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
109981 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
109982 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
109983 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
109984 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
109985 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
109986 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
109987 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
109988 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
109989 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
109990 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
109991 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
109992 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
109993 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
109994 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
109995 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
109996 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
109997 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
109998 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
109999 +message_stats_list_33440 message_stats_list 5 33440 NULL
110000 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
110001 +create_entry_33479 create_entry 2 33479 NULL
110002 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL nohasharray
110003 +elf_map_33487 elf_map 0-2 33487 &ip_setsockopt_33487
110004 +res_counter_read_33499 res_counter_read 4 33499 NULL
110005 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
110006 +fb_read_33506 fb_read 3 33506 NULL
110007 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
110008 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
110009 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
110010 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
110011 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
110012 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
110013 +count_subheaders_33591 count_subheaders 0 33591 NULL
110014 +scsi_execute_33596 scsi_execute 5 33596 NULL
110015 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
110016 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
110017 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
110018 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
110019 +stride_page_count_33641 stride_page_count 2 33641 NULL
110020 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
110021 +inw_p_33668 inw_p 0 33668 NULL
110022 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
110023 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
110024 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
110025 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
110026 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
110027 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
110028 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
110029 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
110030 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
110031 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
110032 +hashtab_create_33769 hashtab_create 3 33769 NULL
110033 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
110034 +filter_write_33819 filter_write 3 33819 NULL
110035 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
110036 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
110037 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
110038 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
110039 +get_user_pages_33908 get_user_pages 0 33908 NULL
110040 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
110041 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
110042 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
110043 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
110044 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
110045 +hfsplus_osx_setxattr_33952 hfsplus_osx_setxattr 4 33952 NULL
110046 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
110047 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
110048 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
110049 +ppp_write_34034 ppp_write 3 34034 NULL
110050 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
110051 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
110052 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
110053 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
110054 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
110055 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
110056 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
110057 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
110058 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
110059 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
110060 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
110061 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
110062 +sysfs_bin_read_34228 sysfs_bin_read 3 34228 NULL
110063 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
110064 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
110065 +device_private_init_34279 device_private_init 0 34279 NULL
110066 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
110067 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
110068 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
110069 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
110070 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
110071 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
110072 +ea_read_34378 ea_read 0 34378 NULL
110073 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
110074 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
110075 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
110076 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
110077 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
110078 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
110079 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
110080 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
110081 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
110082 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
110083 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
110084 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
110085 +ocfs2_mv_xattr_buckets_34484 ocfs2_mv_xattr_buckets 6 34484 NULL
110086 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
110087 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
110088 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
110089 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
110090 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
110091 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
110092 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
110093 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
110094 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
110095 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
110096 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
110097 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
110098 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
110099 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
110100 +brcmf_cfg80211_mgmt_tx_34608 brcmf_cfg80211_mgmt_tx 7 34608 NULL
110101 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
110102 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
110103 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
110104 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
110105 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
110106 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
110107 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
110108 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
110109 +port_print_34704 port_print 3 34704 NULL
110110 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
110111 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
110112 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
110113 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
110114 +bootmode_store_34762 bootmode_store 4 34762 NULL
110115 +device_add_34766 device_add 0 34766 NULL
110116 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
110117 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
110118 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
110119 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
110120 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
110121 +file_page_index_34820 file_page_index 0-2 34820 NULL
110122 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
110123 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
110124 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
110125 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
110126 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
110127 +msg_print_text_34889 msg_print_text 0 34889 NULL
110128 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
110129 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
110130 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
110131 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
110132 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
110133 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
110134 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
110135 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
110136 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
110137 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
110138 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
110139 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
110140 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
110141 +brcmf_sdio_chip_writenvram_35042 brcmf_sdio_chip_writenvram 4 35042 NULL
110142 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
110143 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
110144 +capi_write_35104 capi_write 3 35104 NULL nohasharray
110145 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
110146 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
110147 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
110148 +message_stats_print_35158 message_stats_print 6 35158 NULL
110149 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
110150 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
110151 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
110152 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
110153 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
110154 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
110155 +set_fd_set_35249 set_fd_set 1 35249 NULL
110156 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
110157 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
110158 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
110159 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
110160 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
110161 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
110162 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
110163 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
110164 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
110165 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
110166 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
110167 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
110168 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
110169 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
110170 +read_kmem_35372 read_kmem 3 35372 NULL
110171 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
110172 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
110173 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
110174 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
110175 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
110176 +async_setkey_35521 async_setkey 3 35521 NULL
110177 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
110178 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
110179 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
110180 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
110181 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
110182 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
110183 +sysfs_create_subdir_35567 sysfs_create_subdir 0 35567 NULL
110184 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
110185 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
110186 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
110187 +kernel_readv_35617 kernel_readv 3 35617 NULL
110188 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
110189 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
110190 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
110191 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
110192 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
110193 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
110194 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
110195 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
110196 +md_super_write_35703 md_super_write 4 35703 NULL
110197 +ocfs2_extent_recs_per_gd_35710 ocfs2_extent_recs_per_gd 0 35710 NULL
110198 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
110199 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
110200 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
110201 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
110202 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
110203 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
110204 +fls64_35862 fls64 0 35862 NULL
110205 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
110206 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
110207 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
110208 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
110209 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
110210 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
110211 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
110212 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
110213 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
110214 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
110215 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
110216 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
110217 +acl_alloc_35979 acl_alloc 1 35979 NULL
110218 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
110219 +generic_file_aio_read_35987 generic_file_aio_read 0 35987 NULL
110220 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
110221 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
110222 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
110223 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
110224 +account_shadowed_36048 account_shadowed 2 36048 NULL
110225 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
110226 +write_emulate_36065 write_emulate 2-4 36065 NULL
110227 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
110228 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
110229 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
110230 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
110231 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
110232 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
110233 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
110234 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
110235 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
110236 +twl_set_36154 twl_set 2 36154 NULL
110237 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
110238 +btrfs_file_extent_inline_len_36158 btrfs_file_extent_inline_len 0 36158 NULL
110239 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
110240 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
110241 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
110242 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
110243 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
110244 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
110245 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
110246 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
110247 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
110248 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
110249 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
110250 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
110251 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
110252 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
110253 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
110254 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
110255 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
110256 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
110257 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
110258 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
110259 +lc_create_36332 lc_create 4 36332 NULL
110260 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
110261 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
110262 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
110263 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
110264 +to_sector_36361 to_sector 0-1 36361 NULL
110265 +tunables_read_36385 tunables_read 3 36385 NULL
110266 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
110267 +sierra_write_36402 sierra_write 4 36402 NULL
110268 +iwl_dbgfs_d3_sram_write_36403 iwl_dbgfs_d3_sram_write 3 36403 NULL
110269 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
110270 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
110271 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
110272 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
110273 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
110274 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
110275 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
110276 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
110277 +cmd_loop_36491 cmd_loop 0 36491 NULL
110278 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
110279 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
110280 +get_param_l_36518 get_param_l 0 36518 NULL
110281 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
110282 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
110283 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
110284 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL nohasharray
110285 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
110286 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
110287 +__erst_read_36579 __erst_read 0 36579 NULL
110288 +put_cmsg_36589 put_cmsg 4 36589 NULL
110289 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
110290 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
110291 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
110292 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
110293 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
110294 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
110295 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
110296 +xillybus_read_36678 xillybus_read 3 36678 NULL
110297 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
110298 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
110299 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
110300 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
110301 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
110302 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 2-3-4-5 36796 NULL
110303 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
110304 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
110305 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
110306 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
110307 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
110308 +cm_write_36858 cm_write 3 36858 NULL
110309 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
110310 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
110311 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
110312 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
110313 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
110314 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
110315 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
110316 +audio_set_endpoint_req_36918 audio_set_endpoint_req 0 36918 NULL
110317 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
110318 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
110319 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
110320 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
110321 +setxattr_37006 setxattr 4 37006 NULL
110322 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
110323 +command_file_read_37038 command_file_read 3 37038 NULL
110324 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
110325 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
110326 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
110327 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
110328 +parse_command_37079 parse_command 2 37079 NULL
110329 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
110330 +tun_get_user_37094 tun_get_user 5 37094 NULL
110331 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
110332 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
110333 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
110334 +msg_word_37164 msg_word 0 37164 NULL
110335 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
110336 +can_set_xattr_37182 can_set_xattr 4 37182 NULL
110337 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
110338 +sysfs_add_file_37200 sysfs_add_file 0 37200 NULL
110339 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
110340 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
110341 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
110342 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
110343 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
110344 +__do_replace_37227 __do_replace 5 37227 NULL
110345 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
110346 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
110347 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
110348 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
110349 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
110350 +ocfs2_calc_extend_credits_37310 ocfs2_calc_extend_credits 0 37310 NULL
110351 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
110352 +send_msg_37323 send_msg 4 37323 NULL
110353 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
110354 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
110355 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
110356 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
110357 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
110358 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
110359 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
110360 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
110361 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
110362 +fru_alloc_37442 fru_alloc 1 37442 NULL
110363 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
110364 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
110365 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
110366 +get_est_timing_37484 get_est_timing 0 37484 NULL
110367 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
110368 +__hfsplus_setxattr_37499 __hfsplus_setxattr 4 37499 NULL
110369 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
110370 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
110371 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
110372 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
110373 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
110374 +hdr_size_37536 hdr_size 0 37536 NULL
110375 +extent_map_end_37550 extent_map_end 0 37550 NULL
110376 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
110377 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
110378 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
110379 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
110380 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
110381 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
110382 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
110383 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
110384 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
110385 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
110386 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
110387 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
110388 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
110389 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
110390 +page_chain_free_37697 page_chain_free 0 37697 NULL
110391 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
110392 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
110393 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
110394 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
110395 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
110396 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
110397 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
110398 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
110399 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
110400 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
110401 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
110402 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
110403 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
110404 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
110405 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
110406 +set_registers_37883 set_registers 4 37883 NULL
110407 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
110408 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
110409 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
110410 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
110411 +write_file_bool_37957 write_file_bool 3 37957 NULL
110412 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
110413 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
110414 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
110415 +vfs_readv_38011 vfs_readv 3 38011 NULL
110416 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
110417 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
110418 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
110419 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
110420 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
110421 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
110422 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
110423 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
110424 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
110425 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
110426 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
110427 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
110428 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
110429 +ep0_read_38095 ep0_read 3 38095 NULL
110430 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
110431 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
110432 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
110433 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
110434 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
110435 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
110436 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
110437 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
110438 +cdev_add_38176 cdev_add 2-3 38176 NULL
110439 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
110440 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
110441 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
110442 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
110443 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
110444 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
110445 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
110446 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
110447 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
110448 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
110449 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
110450 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
110451 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
110452 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
110453 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
110454 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
110455 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
110456 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
110457 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
110458 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
110459 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
110460 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
110461 +dev_names_read_38509 dev_names_read 3 38509 NULL
110462 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
110463 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
110464 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
110465 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
110466 +kuc_len_38557 kuc_len 0-1 38557 NULL
110467 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
110468 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
110469 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
110470 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
110471 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
110472 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
110473 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
110474 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
110475 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
110476 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
110477 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
110478 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
110479 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
110480 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
110481 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
110482 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
110483 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
110484 +udf_readpages_38761 udf_readpages 4 38761 NULL
110485 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
110486 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
110487 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
110488 +slab_order_38794 slab_order 0 38794 NULL
110489 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
110490 +err_decode_38804 err_decode 2 38804 NULL
110491 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
110492 +direct_entry_38836 direct_entry 3 38836 NULL
110493 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
110494 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
110495 +interfaces_38859 interfaces 2 38859 NULL
110496 +pci_msix_table_size_38867 pci_msix_table_size 0 38867 NULL
110497 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
110498 +f2fs_xattr_set_acl_38895 f2fs_xattr_set_acl 4 38895 NULL
110499 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
110500 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
110501 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
110502 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
110503 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
110504 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
110505 +get_nodes_39012 get_nodes 3 39012 NULL
110506 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
110507 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
110508 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
110509 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
110510 +ReadHFC_39104 ReadHFC 0 39104 NULL
110511 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
110512 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
110513 +ea_foreach_39133 ea_foreach 0 39133 NULL
110514 +generic_permission_39150 generic_permission 0 39150 NULL
110515 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
110516 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
110517 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
110518 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
110519 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
110520 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
110521 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
110522 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
110523 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
110524 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
110525 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
110526 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
110527 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
110528 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
110529 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
110530 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
110531 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
110532 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
110533 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
110534 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
110535 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
110536 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
110537 +__send_to_port_39386 __send_to_port 3 39386 NULL
110538 +user_power_read_39414 user_power_read 3 39414 NULL
110539 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
110540 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
110541 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
110542 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
110543 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
110544 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
110545 +int_proc_write_39542 int_proc_write 3 39542 NULL
110546 +mdc_unpack_capa_39553 mdc_unpack_capa 0 39553 NULL
110547 +pp_write_39554 pp_write 3 39554 NULL
110548 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
110549 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
110550 +ext_depth_39607 ext_depth 0 39607 NULL
110551 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
110552 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
110553 +sdio_readb_39618 sdio_readb 0 39618 NULL
110554 +set_dev_class_39645 set_dev_class 4 39645 NULL
110555 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
110556 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
110557 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
110558 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
110559 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
110560 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
110561 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
110562 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
110563 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
110564 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
110565 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
110566 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
110567 +pkt_add_39897 pkt_add 3 39897 NULL
110568 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
110569 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
110570 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
110571 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
110572 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
110573 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
110574 +__spi_async_39932 __spi_async 0 39932 NULL
110575 +__get_order_39935 __get_order 0 39935 NULL
110576 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
110577 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
110578 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
110579 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
110580 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
110581 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
110582 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
110583 +server_name2svname_39998 server_name2svname 4 39998 NULL
110584 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
110585 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
110586 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
110587 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
110588 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
110589 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
110590 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
110591 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
110592 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
110593 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
110594 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
110595 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
110596 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
110597 +pt_write_40159 pt_write 3 40159 NULL
110598 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
110599 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
110600 +allocate_probes_40204 allocate_probes 1 40204 NULL
110601 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
110602 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
110603 +osst_read_40237 osst_read 3 40237 NULL
110604 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
110605 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
110606 +ptlrpc_queue_wait_40252 ptlrpc_queue_wait 0 40252 NULL
110607 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
110608 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
110609 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
110610 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
110611 +SyS_bind_40303 SyS_bind 3 40303 NULL
110612 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
110613 +mmio_read_40348 mmio_read 4 40348 NULL
110614 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
110615 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
110616 +get_chars_40373 get_chars 3 40373 NULL
110617 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
110618 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
110619 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
110620 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
110621 +SyS_writev_40467 SyS_writev 3 40467 NULL
110622 +SyS_select_40473 SyS_select 1 40473 NULL
110623 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
110624 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
110625 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
110626 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
110627 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
110628 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
110629 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
110630 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
110631 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
110632 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
110633 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
110634 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
110635 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
110636 +fops_read_40672 fops_read 3 40672 NULL
110637 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
110638 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
110639 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
110640 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
110641 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
110642 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
110643 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
110644 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
110645 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
110646 +card_send_command_40757 card_send_command 3 40757 NULL
110647 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
110648 +pg_write_40766 pg_write 3 40766 NULL
110649 +show_list_40775 show_list 3-0 40775 NULL
110650 +kfifo_out_copy_r_40784 kfifo_out_copy_r 3-0 40784 NULL
110651 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
110652 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
110653 +add_action_40811 add_action 4 40811 NULL
110654 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
110655 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
110656 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
110657 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
110658 +read_file_queue_40895 read_file_queue 3 40895 NULL
110659 +waiters_read_40902 waiters_read 3 40902 NULL
110660 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
110661 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
110662 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
110663 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
110664 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
110665 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
110666 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
110667 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
110668 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
110669 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
110670 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
110671 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
110672 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
110673 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
110674 +calculate_order_41061 calculate_order 0 41061 NULL
110675 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
110676 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
110677 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
110678 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
110679 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
110680 +dma_attach_41094 dma_attach 5-6 41094 NULL
110681 +provide_user_output_41105 provide_user_output 3 41105 NULL
110682 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
110683 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
110684 +ocfs2_extend_trans_41116 ocfs2_extend_trans 2 41116 NULL
110685 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
110686 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
110687 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
110688 +dgap_driver_kzmalloc_41189 dgap_driver_kzmalloc 1 41189 NULL
110689 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
110690 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
110691 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
110692 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
110693 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
110694 +erst_read_41260 erst_read 0 41260 NULL
110695 +alloc_context_41283 alloc_context 1 41283 NULL
110696 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
110697 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
110698 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
110699 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
110700 +kmp_init_41373 kmp_init 2 41373 NULL
110701 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
110702 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
110703 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
110704 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
110705 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
110706 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
110707 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
110708 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
110709 +se_io_cb_41461 se_io_cb 3 41461 NULL
110710 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
110711 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
110712 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
110713 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
110714 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
110715 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
110716 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
110717 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
110718 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
110719 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
110720 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
110721 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
110722 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
110723 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
110724 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
110725 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
110726 +vga_io_r_41609 vga_io_r 0 41609 NULL
110727 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
110728 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
110729 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
110730 +a2mp_send_41615 a2mp_send 4 41615 NULL
110731 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
110732 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
110733 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
110734 +get_std_timing_41654 get_std_timing 0 41654 NULL
110735 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
110736 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
110737 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
110738 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
110739 +fillonedir_41746 fillonedir 3 41746 NULL
110740 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
110741 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
110742 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
110743 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
110744 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
110745 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
110746 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
110747 +pci_map_single_41869 pci_map_single 0 41869 NULL
110748 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
110749 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
110750 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
110751 +nfsd_getxattr_41934 nfsd_getxattr 0 41934 NULL
110752 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
110753 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
110754 +read_gssp_41947 read_gssp 3 41947 NULL
110755 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
110756 +portnames_read_41958 portnames_read 3 41958 NULL
110757 +dst_mtu_41969 dst_mtu 0 41969 NULL
110758 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
110759 +pool_allocate_42012 pool_allocate 3 42012 NULL
110760 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
110761 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
110762 +create_dir_42025 create_dir 0 42025 NULL
110763 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
110764 +__btrfs_drop_extents_42032 __btrfs_drop_extents 5 42032 NULL
110765 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
110766 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
110767 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
110768 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
110769 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
110770 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
110771 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
110772 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
110773 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
110774 +obd_get_info_42156 obd_get_info 0 42156 NULL
110775 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
110776 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
110777 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
110778 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
110779 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
110780 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
110781 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
110782 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
110783 +find_last_bit_42260 find_last_bit 0 42260 NULL
110784 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
110785 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
110786 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
110787 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
110788 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
110789 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
110790 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
110791 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
110792 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
110793 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
110794 +tipc_send_42374 tipc_send 3 42374 NULL
110795 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
110796 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
110797 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
110798 +krng_get_random_42420 krng_get_random 3 42420 NULL
110799 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
110800 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
110801 +alloc_request_42448 alloc_request 0 42448 NULL
110802 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
110803 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
110804 +kuc_free_42455 kuc_free 2 42455 NULL
110805 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
110806 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
110807 +bypass_write_42498 bypass_write 3 42498 NULL
110808 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
110809 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
110810 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
110811 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
110812 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
110813 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
110814 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
110815 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
110816 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
110817 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
110818 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
110819 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
110820 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
110821 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
110822 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
110823 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
110824 +vb2_read_42703 vb2_read 3 42703 NULL
110825 +read_status_42722 read_status 0 42722 NULL
110826 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
110827 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
110828 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
110829 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
110830 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
110831 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
110832 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
110833 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
110834 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
110835 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
110836 +ptlrpc_request_bufs_pack_42793 ptlrpc_request_bufs_pack 0 42793 NULL
110837 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
110838 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
110839 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
110840 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
110841 +set_arg_42824 set_arg 3 42824 NULL
110842 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
110843 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
110844 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
110845 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
110846 +hd_end_request_42904 hd_end_request 2 42904 NULL
110847 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
110848 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL nohasharray
110849 +mdc_unpack_acl_42941 mdc_unpack_acl 0 42941 &sctp_getsockopt_maxburst_42941
110850 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
110851 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
110852 +read_file_node_stat_42964 read_file_node_stat 3 42964 NULL
110853 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
110854 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
110855 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
110856 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
110857 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
110858 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
110859 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
110860 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
110861 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
110862 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
110863 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
110864 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
110865 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
110866 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
110867 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
110868 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
110869 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
110870 +uio_write_43202 uio_write 3 43202 NULL
110871 +iso_callback_43208 iso_callback 3 43208 NULL
110872 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
110873 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
110874 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
110875 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
110876 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
110877 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
110878 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
110879 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
110880 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
110881 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
110882 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
110883 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
110884 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
110885 +xenfb_write_43412 xenfb_write 3 43412 NULL
110886 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
110887 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
110888 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
110889 +usb_string_43443 usb_string 0 43443 NULL nohasharray
110890 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
110891 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
110892 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
110893 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
110894 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
110895 +do_readlink_43518 do_readlink 2 43518 NULL
110896 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
110897 +read_events_43534 read_events 3 43534 NULL
110898 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
110899 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
110900 +request_resource_43548 request_resource 0 43548 NULL
110901 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
110902 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
110903 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
110904 +proc_read_43614 proc_read 3 43614 NULL
110905 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
110906 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
110907 +random_write_43656 random_write 3 43656 NULL
110908 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
110909 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
110910 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
110911 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
110912 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
110913 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
110914 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
110915 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
110916 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
110917 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
110918 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
110919 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
110920 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
110921 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
110922 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
110923 +read_flush_43851 read_flush 3 43851 NULL
110924 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
110925 +SendString_43928 SendString 3 43928 NULL
110926 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
110927 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
110928 +nla_reserve_43984 nla_reserve 3 43984 NULL
110929 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
110930 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
110931 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
110932 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
110933 +emit_flags_44006 emit_flags 4-3 44006 NULL
110934 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
110935 +fru_strlen_44046 fru_strlen 0 44046 NULL
110936 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
110937 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
110938 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 NULL
110939 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
110940 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
110941 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
110942 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
110943 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
110944 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
110945 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
110946 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
110947 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
110948 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
110949 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
110950 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
110951 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
110952 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
110953 +device_create_file_44285 device_create_file 0 44285 NULL
110954 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
110955 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
110956 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
110957 +rs_init_44327 rs_init 1 44327 NULL
110958 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
110959 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
110960 +alloc_requests_44372 alloc_requests 0 44372 NULL
110961 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
110962 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
110963 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
110964 +strlcpy_44400 strlcpy 3 44400 NULL
110965 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
110966 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
110967 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
110968 +iwl_dbgfs_bf_params_write_44450 iwl_dbgfs_bf_params_write 3 44450 NULL
110969 +write_file_debug_44476 write_file_debug 3 44476 NULL
110970 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
110971 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
110972 +bio_advance_44496 bio_advance 2 44496 NULL
110973 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
110974 +ac_register_board_44504 ac_register_board 3 44504 NULL
110975 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
110976 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
110977 +spidev_write_44510 spidev_write 3 44510 NULL
110978 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
110979 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
110980 +comm_write_44537 comm_write 3 44537 NULL
110981 +xfs_log_calc_unit_res_44540 xfs_log_calc_unit_res 0-2 44540 NULL
110982 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
110983 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
110984 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
110985 +mpi_resize_44674 mpi_resize 2 44674 NULL
110986 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
110987 +ts_read_44687 ts_read 3 44687 NULL
110988 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
110989 +__ocfs2_rotate_tree_left_44705 __ocfs2_rotate_tree_left 3 44705 NULL
110990 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
110991 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
110992 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
110993 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
110994 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
110995 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
110996 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
110997 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
110998 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
110999 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
111000 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
111001 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
111002 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
111003 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
111004 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
111005 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
111006 +sisusb_write_44834 sisusb_write 3 44834 NULL
111007 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
111008 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
111009 +copydesc_user_44855 copydesc_user 3 44855 NULL
111010 +set_advertising_44870 set_advertising 4 44870 NULL
111011 +init_rs_44873 init_rs 1 44873 NULL
111012 +skb_availroom_44883 skb_availroom 0 44883 NULL
111013 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
111014 +do_tty_write_44896 do_tty_write 5 44896 NULL
111015 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
111016 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
111017 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
111018 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
111019 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
111020 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
111021 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
111022 +sel_write_user_45060 sel_write_user 3 45060 NULL
111023 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
111024 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
111025 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
111026 +usbdev_read_45114 usbdev_read 3 45114 NULL
111027 +send_to_tty_45141 send_to_tty 3 45141 NULL
111028 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
111029 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
111030 +device_write_45156 device_write 3 45156 NULL nohasharray
111031 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
111032 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
111033 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
111034 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
111035 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
111036 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
111037 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
111038 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
111039 +event_enable_write_45238 event_enable_write 3 45238 NULL
111040 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
111041 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
111042 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
111043 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
111044 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
111045 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
111046 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
111047 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
111048 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
111049 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
111050 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
111051 +__node_remap_45458 __node_remap 4 45458 NULL
111052 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
111053 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
111054 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
111055 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
111056 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
111057 +copy_macs_45534 copy_macs 4 45534 NULL
111058 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
111059 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
111060 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
111061 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
111062 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
111063 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
111064 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
111065 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
111066 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
111067 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
111068 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
111069 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
111070 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
111071 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
111072 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
111073 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL nohasharray
111074 +task_cgroup_path_45734 task_cgroup_path 3 45734 &snd_cs46xx_io_read_45734
111075 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
111076 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
111077 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
111078 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
111079 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
111080 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
111081 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
111082 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
111083 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
111084 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
111085 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
111086 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
111087 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
111088 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
111089 +isdn_write_45863 isdn_write 3 45863 NULL
111090 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
111091 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
111092 +ima_eventdigest_init_common_45889 ima_eventdigest_init_common 2 45889 NULL
111093 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
111094 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
111095 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
111096 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
111097 +alloc_mr_45935 alloc_mr 1 45935 NULL
111098 +copy_to_45969 copy_to 3 45969 NULL
111099 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
111100 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
111101 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
111102 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
111103 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
111104 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
111105 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
111106 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
111107 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
111108 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
111109 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
111110 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
111111 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
111112 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
111113 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
111114 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
111115 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
111116 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
111117 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
111118 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
111119 +fq_resize_46195 fq_resize 2 46195 NULL
111120 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
111121 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
111122 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
111123 +dsp_write_46218 dsp_write 2 46218 NULL
111124 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
111125 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
111126 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
111127 +ReadReg_46277 ReadReg 0 46277 NULL
111128 +sptlrpc_req_get_ctx_46303 sptlrpc_req_get_ctx 0 46303 NULL
111129 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
111130 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
111131 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
111132 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
111133 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
111134 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
111135 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
111136 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
111137 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
111138 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
111139 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
111140 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
111141 +filldir64_46469 filldir64 3 46469 NULL
111142 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
111143 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
111144 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
111145 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
111146 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
111147 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
111148 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
111149 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
111150 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
111151 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
111152 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
111153 +__kfifo_out_r_46623 __kfifo_out_r 3-0 46623 NULL
111154 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
111155 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
111156 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
111157 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
111158 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
111159 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
111160 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
111161 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
111162 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
111163 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
111164 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
111165 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
111166 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
111167 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
111168 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
111169 +readreg_46845 readreg 0 46845 NULL
111170 +spi_async_46857 spi_async 0 46857 NULL
111171 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
111172 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
111173 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
111174 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
111175 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
111176 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
111177 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
111178 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
111179 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
111180 +fb_write_46924 fb_write 3 46924 NULL
111181 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
111182 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
111183 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
111184 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
111185 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
111186 +strlcat_46985 strlcat 3 46985 NULL
111187 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
111188 +sel_write_bool_46996 sel_write_bool 3 46996 NULL nohasharray
111189 +gfs2_xattr_system_set_46996 gfs2_xattr_system_set 4 46996 &sel_write_bool_46996
111190 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
111191 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
111192 +fs_path_len_47060 fs_path_len 0 47060 NULL
111193 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
111194 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
111195 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
111196 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
111197 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
111198 +mousedev_read_47123 mousedev_read 3 47123 NULL
111199 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
111200 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
111201 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
111202 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
111203 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
111204 +can_set_system_xattr_47182 can_set_system_xattr 4 47182 NULL
111205 +options_write_47243 options_write 3 47243 NULL
111206 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
111207 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
111208 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
111209 +vsnprintf_47291 vsnprintf 0 47291 NULL
111210 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
111211 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
111212 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
111213 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
111214 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
111215 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
111216 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
111217 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
111218 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
111219 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
111220 +nametbl_list_47391 nametbl_list 2 47391 NULL
111221 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
111222 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
111223 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
111224 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
111225 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
111226 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
111227 +posix_acl_from_disk_47445 posix_acl_from_disk 2 47445 NULL
111228 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
111229 +newpart_47485 newpart 6-4 47485 NULL
111230 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
111231 +core_sys_select_47494 core_sys_select 1 47494 NULL
111232 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
111233 +unlink_simple_47506 unlink_simple 3 47506 NULL
111234 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
111235 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
111236 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
111237 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
111238 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
111239 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
111240 +read_ldt_47570 read_ldt 2 47570 NULL
111241 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
111242 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
111243 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
111244 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
111245 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
111246 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
111247 +get_size_47644 get_size 1-2 47644 NULL
111248 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
111249 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
111250 +save_microcode_47717 save_microcode 3 47717 NULL
111251 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
111252 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
111253 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
111254 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
111255 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
111256 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
111257 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
111258 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
111259 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
111260 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
111261 +lov_packmd_47810 lov_packmd 0 47810 NULL
111262 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
111263 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
111264 +vhci_read_47878 vhci_read 3 47878 NULL
111265 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
111266 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
111267 +comedi_write_47926 comedi_write 3 47926 NULL
111268 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
111269 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
111270 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
111271 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
111272 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
111273 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
111274 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
111275 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
111276 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
111277 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
111278 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
111279 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
111280 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
111281 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
111282 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
111283 +disc_write_48070 disc_write 3 48070 NULL
111284 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
111285 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
111286 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
111287 +set_discoverable_48141 set_discoverable 4 48141 NULL
111288 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
111289 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
111290 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
111291 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
111292 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
111293 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
111294 +brcmf_sdio_chip_cm3_exitdl_48192 brcmf_sdio_chip_cm3_exitdl 4 48192 NULL
111295 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
111296 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
111297 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
111298 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
111299 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
111300 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
111301 +read_file_recv_48232 read_file_recv 3 48232 NULL
111302 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
111303 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
111304 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
111305 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
111306 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
111307 +trace_options_write_48275 trace_options_write 3 48275 NULL
111308 +send_set_info_48288 send_set_info 7 48288 NULL
111309 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
111310 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
111311 +hash_setkey_48310 hash_setkey 3 48310 NULL
111312 +audio_set_intf_req_48319 audio_set_intf_req 0 48319 NULL
111313 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
111314 +skb_add_data_48363 skb_add_data 3 48363 NULL
111315 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
111316 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
111317 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
111318 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
111319 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
111320 +print_filtered_48442 print_filtered 2-0 48442 NULL
111321 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
111322 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
111323 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
111324 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
111325 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
111326 +send_control_msg_48498 send_control_msg 6 48498 NULL
111327 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
111328 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
111329 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
111330 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
111331 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
111332 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
111333 +llog_data_len_48607 llog_data_len 1 48607 NULL
111334 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
111335 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
111336 +mtd_read_48655 mtd_read 0 48655 NULL
111337 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
111338 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
111339 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
111340 +altera_drscan_48698 altera_drscan 2 48698 NULL
111341 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
111342 +recv_msg_48709 recv_msg 4 48709 NULL
111343 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
111344 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
111345 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
111346 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
111347 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
111348 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
111349 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
111350 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
111351 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
111352 +azx_get_position_48841 azx_get_position 0 48841 NULL
111353 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
111354 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
111355 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
111356 +sptlrpc_cli_alloc_reqbuf_48855 sptlrpc_cli_alloc_reqbuf 0 48855 NULL
111357 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
111358 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
111359 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
111360 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
111361 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
111362 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
111363 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
111364 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
111365 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
111366 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
111367 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
111368 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
111369 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
111370 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
111371 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
111372 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
111373 +aic_inb_49023 aic_inb 0 49023 NULL
111374 +transient_status_49027 transient_status 4 49027 NULL
111375 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
111376 +aic7xxx_rem_scb_from_disc_list_49041 aic7xxx_rem_scb_from_disc_list 0 49041 NULL
111377 +scsi_register_49094 scsi_register 2 49094 NULL
111378 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
111379 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
111380 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
111381 +pt_read_49136 pt_read 3 49136 NULL
111382 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
111383 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
111384 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
111385 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
111386 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
111387 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
111388 +print_queue_49191 print_queue 4-0 49191 NULL
111389 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
111390 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
111391 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
111392 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
111393 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
111394 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
111395 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
111396 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
111397 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
111398 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
111399 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
111400 +uio_read_49300 uio_read 3 49300 NULL
111401 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
111402 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
111403 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
111404 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
111405 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
111406 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
111407 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
111408 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
111409 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
111410 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
111411 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
111412 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
111413 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
111414 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
111415 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
111416 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
111417 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
111418 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
111419 +smk_write_access_49561 smk_write_access 3 49561 NULL
111420 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
111421 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
111422 +ptlrpc_request_pack_49581 ptlrpc_request_pack 0 49581 NULL
111423 +readfifo_49583 readfifo 1 49583 NULL
111424 +tap_write_49595 tap_write 3 49595 NULL
111425 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
111426 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
111427 +heap_init_49617 heap_init 2 49617 NULL
111428 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
111429 +port_fops_read_49626 port_fops_read 3 49626 NULL
111430 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
111431 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
111432 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
111433 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
111434 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
111435 +write_pool_49718 write_pool 3 49718 NULL
111436 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
111437 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
111438 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
111439 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
111440 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
111441 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
111442 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
111443 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
111444 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
111445 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
111446 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
111447 +add_uuid_49831 add_uuid 4 49831 NULL
111448 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
111449 +twl4030_write_49846 twl4030_write 2 49846 NULL
111450 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
111451 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
111452 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
111453 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
111454 +ceph_get_caps_49890 ceph_get_caps 0 49890 NULL
111455 +osc_brw_49896 osc_brw 4 49896 NULL
111456 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
111457 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
111458 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
111459 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
111460 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
111461 +isdn_read_50021 isdn_read 3 50021 NULL
111462 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
111463 +ioread8_50049 ioread8 0 50049 NULL
111464 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
111465 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
111466 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
111467 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
111468 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
111469 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
111470 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
111471 +read_file_slot_50111 read_file_slot 3 50111 NULL
111472 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
111473 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
111474 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
111475 +copy_items_50140 copy_items 6 50140 NULL
111476 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
111477 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
111478 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
111479 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
111480 +odev_update_50169 odev_update 2 50169 NULL
111481 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
111482 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
111483 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
111484 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
111485 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
111486 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
111487 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
111488 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
111489 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
111490 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
111491 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
111492 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
111493 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
111494 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
111495 +do_launder_page_50329 do_launder_page 0 50329 NULL
111496 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
111497 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
111498 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
111499 +tpm_read_50344 tpm_read 3 50344 NULL
111500 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
111501 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
111502 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
111503 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
111504 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
111505 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
111506 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
111507 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
111508 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
111509 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
111510 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
111511 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
111512 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
111513 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
111514 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
111515 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
111516 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
111517 +fat_readpages_50582 fat_readpages 4 50582 NULL
111518 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
111519 +xillybus_write_50605 xillybus_write 3 50605 NULL
111520 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
111521 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
111522 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
111523 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
111524 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
111525 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
111526 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
111527 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
111528 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
111529 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
111530 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
111531 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
111532 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
111533 +tpm_write_50798 tpm_write 3 50798 NULL
111534 +write_flush_50803 write_flush 3 50803 NULL
111535 +dvb_play_50814 dvb_play 3 50814 NULL
111536 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
111537 +SetArea_50835 SetArea 4 50835 NULL
111538 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
111539 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
111540 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
111541 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
111542 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
111543 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
111544 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
111545 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
111546 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
111547 +show_device_status_50947 show_device_status 0 50947 NULL
111548 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
111549 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
111550 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
111551 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
111552 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
111553 +timeout_write_50991 timeout_write 3 50991 NULL
111554 +proc_write_51003 proc_write 3 51003 NULL
111555 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
111556 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
111557 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
111558 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
111559 +dump_midi_51040 dump_midi 3 51040 NULL
111560 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
111561 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
111562 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
111563 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
111564 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
111565 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
111566 +ti_recv_51110 ti_recv 3 51110 NULL
111567 +uasp_prepare_r_request_51124 uasp_prepare_r_request 0 51124 NULL
111568 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
111569 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
111570 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
111571 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
111572 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
111573 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
111574 +drm_property_create_51239 drm_property_create 4 51239 NULL
111575 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
111576 +st_read_51251 st_read 3 51251 NULL
111577 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
111578 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
111579 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
111580 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
111581 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
111582 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
111583 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
111584 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
111585 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
111586 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
111587 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
111588 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
111589 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
111590 +ceph_sync_read_51410 ceph_sync_read 3-0 51410 NULL
111591 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
111592 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
111593 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
111594 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
111595 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
111596 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
111597 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
111598 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
111599 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
111600 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
111601 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
111602 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
111603 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
111604 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
111605 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
111606 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
111607 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
111608 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
111609 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
111610 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
111611 +sel_write_access_51704 sel_write_access 3 51704 NULL
111612 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
111613 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
111614 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
111615 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
111616 +cm4040_read_51732 cm4040_read 3 51732 NULL
111617 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
111618 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
111619 +if_write_51756 if_write 3 51756 NULL
111620 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
111621 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
111622 +ioread32_51847 ioread32 0 51847 NULL nohasharray
111623 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
111624 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
111625 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
111626 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
111627 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
111628 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
111629 +user_read_51881 user_read 3 51881 NULL
111630 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
111631 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
111632 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
111633 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
111634 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
111635 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
111636 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
111637 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
111638 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
111639 +get_zone_51981 get_zone 0-1 51981 NULL
111640 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
111641 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
111642 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
111643 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
111644 +rdmalt_52022 rdmalt 0 52022 NULL
111645 +override_release_52032 override_release 2 52032 NULL
111646 +end_port_52042 end_port 0 52042 NULL
111647 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
111648 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
111649 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
111650 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
111651 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
111652 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
111653 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
111654 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
111655 +retry_count_read_52129 retry_count_read 3 52129 NULL
111656 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
111657 +sub_alloc_52140 sub_alloc 0 52140 NULL
111658 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
111659 +htable_size_52148 htable_size 0-1 52148 NULL
111660 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
111661 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
111662 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
111663 +print_prefix_52176 print_prefix 0 52176 NULL
111664 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
111665 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
111666 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
111667 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 3 52243 &fuse_request_alloc_52243
111668 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
111669 +shrink_slab_52261 shrink_slab 2 52261 NULL
111670 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
111671 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
111672 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
111673 +read_file_reset_52310 read_file_reset 3 52310 NULL
111674 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
111675 +hwflags_read_52318 hwflags_read 3 52318 NULL
111676 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
111677 +hur_len_52339 hur_len 0 52339 NULL
111678 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
111679 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
111680 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
111681 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
111682 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
111683 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
111684 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
111685 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
111686 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
111687 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
111688 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
111689 +delay_status_52431 delay_status 5 52431 NULL
111690 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
111691 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
111692 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
111693 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
111694 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
111695 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
111696 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
111697 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
111698 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
111699 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
111700 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
111701 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
111702 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
111703 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
111704 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
111705 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
111706 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
111707 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
111708 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
111709 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
111710 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
111711 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
111712 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
111713 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
111714 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
111715 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
111716 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
111717 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
111718 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
111719 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
111720 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
111721 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
111722 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
111723 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
111724 +ext2_xattr_set_acl_52857 ext2_xattr_set_acl 4 52857 NULL
111725 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
111726 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
111727 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
111728 +twlreg_write_52880 twlreg_write 3 52880 NULL
111729 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
111730 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
111731 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
111732 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
111733 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
111734 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
111735 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
111736 +send_packet_52960 send_packet 4 52960 NULL
111737 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
111738 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
111739 +num_node_state_52989 num_node_state 0 52989 NULL
111740 +uasp_alloc_stream_res_53015 uasp_alloc_stream_res 0 53015 NULL
111741 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
111742 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
111743 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
111744 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
111745 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
111746 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
111747 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
111748 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
111749 +verity_status_53120 verity_status 5 53120 NULL
111750 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
111751 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
111752 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
111753 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
111754 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
111755 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
111756 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
111757 +hfsplus_xattr_set_posix_acl_53249 hfsplus_xattr_set_posix_acl 4 53249 NULL
111758 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
111759 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
111760 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
111761 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
111762 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
111763 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
111764 +vm_mmap_53339 vm_mmap 0 53339 NULL
111765 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
111766 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
111767 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
111768 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
111769 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
111770 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
111771 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
111772 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL
111773 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
111774 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
111775 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
111776 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
111777 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
111778 +ocfs2_xattr_set_acl_53508 ocfs2_xattr_set_acl 4 53508 NULL
111779 +check_acl_53512 check_acl 0 53512 NULL
111780 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
111781 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
111782 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
111783 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
111784 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
111785 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
111786 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
111787 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
111788 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
111789 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
111790 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
111791 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
111792 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
111793 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
111794 +bio_integrity_split_53714 bio_integrity_split 3 53714 NULL
111795 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
111796 +wdm_write_53735 wdm_write 3 53735 NULL
111797 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
111798 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
111799 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
111800 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
111801 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
111802 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
111803 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
111804 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
111805 +setup_data_read_53822 setup_data_read 3 53822 NULL
111806 +pms_read_53873 pms_read 3 53873 NULL
111807 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
111808 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
111809 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
111810 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
111811 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
111812 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
111813 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
111814 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
111815 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
111816 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
111817 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
111818 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
111819 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
111820 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
111821 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
111822 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
111823 +_malloc_54077 _malloc 1 54077 NULL
111824 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
111825 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
111826 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
111827 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
111828 +strn_len_54122 strn_len 0 54122 NULL
111829 +isku_receive_54130 isku_receive 4 54130 NULL
111830 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
111831 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
111832 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
111833 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
111834 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
111835 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
111836 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
111837 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
111838 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
111839 +reada_add_block_54247 reada_add_block 2 54247 NULL
111840 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
111841 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
111842 +audio_write_54261 audio_write 4 54261 NULL nohasharray
111843 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
111844 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
111845 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
111846 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
111847 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
111848 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
111849 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
111850 +sprintf_54306 sprintf 0 54306 NULL
111851 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
111852 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
111853 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
111854 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
111855 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
111856 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
111857 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
111858 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
111859 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
111860 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
111861 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
111862 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
111863 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
111864 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
111865 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
111866 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
111867 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
111868 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
111869 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
111870 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
111871 +viacam_read_54526 viacam_read 3 54526 NULL
111872 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
111873 +setsockopt_54539 setsockopt 5 54539 NULL
111874 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
111875 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
111876 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
111877 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
111878 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
111879 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
111880 +port_fops_write_54627 port_fops_write 3 54627 NULL
111881 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
111882 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
111883 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
111884 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
111885 +bus_add_device_54665 bus_add_device 0 54665 NULL
111886 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
111887 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
111888 +evm_read_key_54674 evm_read_key 3 54674 NULL
111889 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
111890 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
111891 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
111892 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
111893 +kzalloc_54740 kzalloc 1 54740 NULL
111894 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
111895 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
111896 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
111897 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
111898 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
111899 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
111900 +nfsd_write_54809 nfsd_write 6 54809 NULL
111901 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
111902 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
111903 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
111904 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
111905 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
111906 +write_rio_54837 write_rio 3 54837 NULL
111907 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
111908 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
111909 +ll_layout_conf_54841 ll_layout_conf 0 54841 NULL
111910 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
111911 +printer_read_54851 printer_read 3 54851 NULL
111912 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
111913 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
111914 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
111915 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
111916 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
111917 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
111918 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
111919 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
111920 +add_port_54941 add_port 2 54941 NULL
111921 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
111922 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
111923 +c4_add_card_54968 c4_add_card 3 54968 NULL
111924 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
111925 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
111926 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
111927 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
111928 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
111929 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
111930 +read_dma_55086 read_dma 3 55086 NULL
111931 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
111932 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
111933 +filldir_55137 filldir 3 55137 NULL
111934 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
111935 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
111936 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
111937 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
111938 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
111939 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
111940 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
111941 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
111942 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
111943 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
111944 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
111945 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
111946 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
111947 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
111948 +persistent_ram_new_55286 persistent_ram_new 2-1 55286 NULL
111949 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
111950 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
111951 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
111952 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
111953 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
111954 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
111955 +vme_user_read_55338 vme_user_read 3 55338 NULL
111956 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
111957 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
111958 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
111959 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
111960 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
111961 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
111962 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
111963 +sysfs_sd_setattr_55437 sysfs_sd_setattr 0 55437 NULL
111964 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
111965 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
111966 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
111967 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
111968 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
111969 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
111970 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
111971 +ea_get_55522 ea_get 3-0 55522 NULL
111972 +buffer_size_55534 buffer_size 0 55534 NULL
111973 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
111974 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
111975 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
111976 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
111977 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
111978 +add_partition_55588 add_partition 2 55588 NULL
111979 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
111980 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL nohasharray
111981 +config_buf_55602 config_buf 0 55602 &SyS_keyctl_55602
111982 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
111983 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
111984 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
111985 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
111986 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
111987 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
111988 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
111989 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
111990 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
111991 +get_info_55681 get_info 3 55681 NULL
111992 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
111993 +echo_big_lmm_get_55690 echo_big_lmm_get 0 55690 NULL
111994 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
111995 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
111996 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
111997 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
111998 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
111999 +set_local_name_55757 set_local_name 4 55757 NULL
112000 +strlen_55778 strlen 0 55778 NULL
112001 +set_spte_55783 set_spte 4-5 55783 NULL
112002 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
112003 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
112004 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
112005 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
112006 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
112007 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
112008 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
112009 +hsc_write_55875 hsc_write 3 55875 NULL
112010 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
112011 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
112012 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
112013 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
112014 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
112015 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
112016 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
112017 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
112018 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
112019 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
112020 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
112021 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
112022 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
112023 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
112024 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
112025 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
112026 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
112027 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
112028 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
112029 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
112030 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
112031 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
112032 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
112033 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
112034 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
112035 +fd_copyin_56247 fd_copyin 3 56247 NULL
112036 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
112037 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
112038 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
112039 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
112040 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
112041 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
112042 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
112043 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
112044 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
112045 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
112046 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
112047 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
112048 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
112049 +dev_read_56369 dev_read 3 56369 NULL
112050 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
112051 +write_gssp_56404 write_gssp 3 56404 NULL
112052 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
112053 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
112054 +store_msg_56417 store_msg 3 56417 NULL
112055 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
112056 +fl_create_56435 fl_create 5 56435 NULL
112057 +gnttab_map_56439 gnttab_map 2 56439 NULL
112058 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
112059 +set_connectable_56458 set_connectable 4 56458 NULL
112060 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
112061 +putused_user_56467 putused_user 3 56467 NULL
112062 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
112063 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
112064 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
112065 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
112066 +init_map_ip_56508 init_map_ip 5 56508 NULL
112067 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
112068 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
112069 +ip_options_get_56538 ip_options_get 4 56538 NULL
112070 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
112071 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
112072 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
112073 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
112074 +event_filter_write_56609 event_filter_write 3 56609 NULL
112075 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
112076 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
112077 +gather_array_56641 gather_array 3 56641 NULL
112078 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
112079 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
112080 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
112081 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
112082 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
112083 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
112084 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
112085 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
112086 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
112087 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
112088 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
112089 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
112090 +do_syslog_56807 do_syslog 3 56807 NULL
112091 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
112092 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
112093 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
112094 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
112095 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
112096 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
112097 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
112098 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
112099 +hfsplus_setxattr_56902 hfsplus_setxattr 4 56902 NULL
112100 +strcspn_56913 strcspn 0 56913 NULL
112101 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
112102 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
112103 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
112104 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
112105 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
112106 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
112107 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
112108 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
112109 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
112110 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
112111 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
112112 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
112113 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
112114 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
112115 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
112116 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
112117 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
112118 +altera_get_note_57099 altera_get_note 6 57099 NULL
112119 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
112120 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
112121 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
112122 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
112123 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
112124 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
112125 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
112126 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
112127 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
112128 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
112129 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
112130 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
112131 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
112132 +dma_fifo_alloc_57236 dma_fifo_alloc 5-3-2 57236 NULL
112133 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
112134 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
112135 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
112136 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
112137 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
112138 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
112139 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
112140 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
112141 +write_file_regval_57313 write_file_regval 3 57313 NULL
112142 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
112143 +usblp_read_57342 usblp_read 3 57342 NULL
112144 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
112145 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
112146 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
112147 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
112148 +read_file_blob_57406 read_file_blob 3 57406 NULL
112149 +enclosure_register_57412 enclosure_register 3 57412 NULL
112150 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
112151 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
112152 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
112153 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
112154 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
112155 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
112156 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
112157 +skb_headlen_57501 skb_headlen 0 57501 NULL
112158 +copy_in_user_57502 copy_in_user 3 57502 NULL
112159 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
112160 +init_tag_map_57515 init_tag_map 3 57515 NULL
112161 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
112162 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
112163 +cmm_read_57520 cmm_read 3 57520 NULL
112164 +inode_permission_57531 inode_permission 0 57531 NULL
112165 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
112166 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
112167 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
112168 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
112169 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
112170 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
112171 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
112172 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
112173 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
112174 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
112175 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
112176 +mem_read_57631 mem_read 3 57631 NULL
112177 +r3964_write_57662 r3964_write 4 57662 NULL
112178 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
112179 +__lgwrite_57669 __lgwrite 4 57669 NULL
112180 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
112181 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
112182 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
112183 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
112184 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
112185 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
112186 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
112187 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
112188 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
112189 +ld2_57794 ld2 0 57794 NULL
112190 +ivtv_read_57796 ivtv_read 3 57796 NULL
112191 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
112192 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
112193 +flash_read_57843 flash_read 3 57843 NULL
112194 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
112195 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
112196 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
112197 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
112198 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
112199 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
112200 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
112201 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
112202 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
112203 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
112204 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
112205 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
112206 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
112207 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
112208 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
112209 +mce_async_out_58056 mce_async_out 3 58056 NULL
112210 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
112211 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
112212 +cm4040_write_58079 cm4040_write 3 58079 NULL
112213 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
112214 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
112215 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
112216 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
112217 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
112218 +read_file_debug_58256 read_file_debug 3 58256 NULL
112219 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
112220 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
112221 +profile_load_58267 profile_load 3 58267 NULL
112222 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
112223 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
112224 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
112225 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
112226 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
112227 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
112228 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
112229 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
112230 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
112231 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
112232 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
112233 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
112234 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
112235 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
112236 +capabilities_read_58457 capabilities_read 3 58457 NULL
112237 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
112238 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
112239 +nv_rd08_58472 nv_rd08 0 58472 NULL
112240 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
112241 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
112242 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
112243 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
112244 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
112245 +ldlm_srv_pool_shrink_58554 ldlm_srv_pool_shrink 0 58554 NULL
112246 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
112247 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
112248 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
112249 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
112250 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
112251 +xip_file_read_58592 xip_file_read 3 58592 NULL
112252 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
112253 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
112254 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
112255 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
112256 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
112257 +find_zero_58685 find_zero 0-1 58685 NULL
112258 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
112259 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
112260 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
112261 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
112262 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
112263 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
112264 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
112265 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
112266 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
112267 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
112268 +ep_read_58813 ep_read 3 58813 NULL
112269 +command_write_58841 command_write 3 58841 NULL
112270 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
112271 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
112272 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
112273 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
112274 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
112275 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
112276 +sptlrpc_import_sec_adapt_58948 sptlrpc_import_sec_adapt 0 58948 NULL
112277 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
112278 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
112279 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
112280 +init_list_set_59005 init_list_set 3 59005 NULL
112281 +ep_write_59008 ep_write 3 59008 NULL
112282 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
112283 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
112284 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
112285 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
112286 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
112287 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
112288 +sysfs_link_sibling_59078 sysfs_link_sibling 0 59078 NULL
112289 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
112290 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL
112291 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
112292 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
112293 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
112294 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
112295 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
112296 +md_getxattr_59161 md_getxattr 0 59161 NULL
112297 +ksize_59176 ksize 0 59176 NULL
112298 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
112299 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
112300 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
112301 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
112302 +dt3155_read_59226 dt3155_read 3 59226 NULL
112303 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
112304 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
112305 +nla_len_59258 nla_len 0 59258 NULL
112306 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
112307 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
112308 +fd_copyout_59323 fd_copyout 3 59323 NULL
112309 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
112310 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
112311 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
112312 +__map_request_59350 __map_request 0 59350 NULL
112313 +f2fs_fallocate_59377 f2fs_fallocate 3-4 59377 NULL
112314 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
112315 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
112316 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
112317 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
112318 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
112319 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
112320 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
112321 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
112322 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
112323 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
112324 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
112325 +tunables_write_59563 tunables_write 3 59563 NULL
112326 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
112327 +write_pbl_59583 write_pbl 4 59583 NULL
112328 +memdup_user_59590 memdup_user 2 59590 NULL
112329 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
112330 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
112331 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
112332 +mtrr_write_59622 mtrr_write 3 59622 NULL
112333 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
112334 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
112335 +hidraw_read_59650 hidraw_read 3 59650 NULL
112336 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
112337 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
112338 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
112339 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
112340 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
112341 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
112342 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
112343 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
112344 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
112345 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
112346 +strnlen_59746 strnlen 0 59746 NULL
112347 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
112348 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
112349 +venus_remove_59781 venus_remove 4 59781 NULL
112350 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
112351 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
112352 +ipw_write_59807 ipw_write 3 59807 NULL
112353 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
112354 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
112355 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
112356 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
112357 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
112358 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
112359 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
112360 +ocfs2_extend_rotate_transaction_59894 ocfs2_extend_rotate_transaction 2-3 59894 NULL
112361 +aic7xxx_abort_waiting_scb_59932 aic7xxx_abort_waiting_scb 0 59932 NULL
112362 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
112363 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
112364 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
112365 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
112366 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
112367 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
112368 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
112369 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
112370 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
112371 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
112372 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
112373 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
112374 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
112375 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
112376 +vcs_size_60050 vcs_size 0 60050 NULL
112377 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
112378 +compat_writev_60063 compat_writev 3 60063 NULL
112379 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
112380 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
112381 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
112382 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
112383 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
112384 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
112385 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
112386 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
112387 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
112388 +init_state_60165 init_state 2 60165 NULL
112389 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
112390 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
112391 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
112392 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
112393 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
112394 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
112395 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
112396 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
112397 +printer_write_60276 printer_write 3 60276 NULL
112398 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
112399 +getDataLength_60301 getDataLength 0 60301 NULL
112400 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
112401 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
112402 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
112403 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
112404 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
112405 +driver_names_read_60399 driver_names_read 3 60399 NULL
112406 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
112407 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
112408 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
112409 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
112410 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
112411 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
112412 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
112413 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
112414 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
112415 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
112416 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
112417 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
112418 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
112419 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
112420 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
112421 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
112422 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
112423 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
112424 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
112425 +raid_status_60755 raid_status 5 60755 NULL
112426 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
112427 +opticon_write_60775 opticon_write 4 60775 NULL
112428 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
112429 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
112430 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
112431 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
112432 +generic_writepages_60871 generic_writepages 0 60871 NULL
112433 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
112434 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
112435 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
112436 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
112437 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
112438 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
112439 +pti_char_write_60960 pti_char_write 3 60960 NULL
112440 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
112441 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
112442 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
112443 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
112444 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
112445 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
112446 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
112447 +symtab_init_61050 symtab_init 2 61050 NULL
112448 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
112449 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
112450 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
112451 +get_derived_key_61100 get_derived_key 4 61100 NULL
112452 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-1-2-3-4 61104 NULL
112453 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
112454 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
112455 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
112456 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
112457 +brcmf_sdio_chip_cr4_exitdl_61143 brcmf_sdio_chip_cr4_exitdl 4 61143 NULL
112458 +pair_device_61175 pair_device 4 61175 NULL nohasharray
112459 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
112460 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
112461 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
112462 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
112463 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
112464 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
112465 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
112466 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
112467 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
112468 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
112469 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
112470 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
112471 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
112472 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
112473 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
112474 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
112475 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
112476 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
112477 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
112478 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
112479 +system_enable_write_61396 system_enable_write 3 61396 NULL
112480 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
112481 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
112482 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
112483 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
112484 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
112485 +erst_errno_61526 erst_errno 0 61526 NULL
112486 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
112487 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
112488 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
112489 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
112490 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
112491 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
112492 +seq_open_private_61589 seq_open_private 3 61589 NULL
112493 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
112494 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
112495 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
112496 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
112497 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
112498 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
112499 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL
112500 +resize_stripes_61650 resize_stripes 2 61650 NULL
112501 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
112502 +insert_one_name_61668 insert_one_name 7 61668 NULL
112503 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
112504 +lock_loop_61681 lock_loop 1 61681 NULL
112505 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
112506 +filter_read_61692 filter_read 3 61692 NULL
112507 +iov_length_61716 iov_length 0 61716 NULL
112508 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
112509 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
112510 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
112511 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
112512 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
112513 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
112514 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
112515 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
112516 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
112517 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
112518 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
112519 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
112520 +get_fw_name_61874 get_fw_name 3 61874 NULL
112521 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
112522 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
112523 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
112524 +clear_refs_write_61904 clear_refs_write 3 61904 NULL nohasharray
112525 +import_sec_check_expire_61904 import_sec_check_expire 0 61904 &clear_refs_write_61904
112526 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
112527 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
112528 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
112529 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
112530 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
112531 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
112532 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
112533 +fix_read_error_61965 fix_read_error 4 61965 NULL
112534 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
112535 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
112536 +cow_file_range_61979 cow_file_range 3 61979 NULL
112537 +dequeue_event_62000 dequeue_event 3 62000 NULL
112538 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
112539 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
112540 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
112541 +SYSC_select_62024 SYSC_select 1 62024 NULL
112542 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
112543 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
112544 +do_pselect_62061 do_pselect 1 62061 NULL
112545 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
112546 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
112547 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
112548 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
112549 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
112550 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
112551 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
112552 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
112553 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
112554 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
112555 +video_usercopy_62151 video_usercopy 2 62151 NULL
112556 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
112557 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
112558 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
112559 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
112560 +btrfs_xattr_acl_set_62203 btrfs_xattr_acl_set 4 62203 NULL
112561 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
112562 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
112563 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
112564 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
112565 +get_random_int_62279 get_random_int 0 62279 NULL
112566 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
112567 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
112568 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
112569 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
112570 +ocfs2_xattr_buckets_per_cluster_62330 ocfs2_xattr_buckets_per_cluster 0 62330 NULL
112571 +subseq_list_62332 subseq_list 3-0 62332 NULL
112572 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
112573 +flash_write_62354 flash_write 3 62354 NULL
112574 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
112575 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
112576 +altera_irscan_62396 altera_irscan 2 62396 NULL
112577 +set_ssp_62411 set_ssp 4 62411 NULL
112578 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
112579 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
112580 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
112581 +debugfs_read_62535 debugfs_read 3 62535 NULL
112582 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
112583 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
112584 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
112585 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
112586 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
112587 +get_subdir_62581 get_subdir 3 62581 NULL
112588 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
112589 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
112590 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
112591 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
112592 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
112593 +ocfs2_wait_for_mask_interruptible_62675 ocfs2_wait_for_mask_interruptible 0 62675 NULL
112594 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
112595 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
112596 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
112597 +rdm_62719 rdm 0 62719 NULL
112598 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
112599 +key_replays_read_62746 key_replays_read 3 62746 NULL
112600 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
112601 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
112602 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
112603 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
112604 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
112605 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
112606 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
112607 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
112608 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
112609 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
112610 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
112611 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
112612 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
112613 +aoechr_write_62883 aoechr_write 3 62883 NULL
112614 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
112615 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
112616 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
112617 +getdqbuf_62908 getdqbuf 1 62908 NULL
112618 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
112619 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
112620 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
112621 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
112622 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
112623 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
112624 +unlink1_63059 unlink1 3 63059 NULL
112625 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
112626 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
112627 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
112628 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
112629 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
112630 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
112631 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
112632 +vme_master_read_63221 vme_master_read 0 63221 NULL
112633 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
112634 +ptp_read_63251 ptp_read 4 63251 NULL
112635 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
112636 +raid5_resize_63306 raid5_resize 2 63306 NULL
112637 +proc_info_read_63344 proc_info_read 3 63344 NULL
112638 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
112639 +idmouse_read_63374 idmouse_read 3 63374 NULL
112640 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
112641 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
112642 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
112643 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
112644 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
112645 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
112646 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
112647 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
112648 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
112649 +read_kcore_63488 read_kcore 3 63488 NULL
112650 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
112651 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
112652 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
112653 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
112654 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
112655 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
112656 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
112657 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
112658 +write_debug_level_63613 write_debug_level 3 63613 NULL
112659 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
112660 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
112661 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
112662 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
112663 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
112664 +vbi_read_63673 vbi_read 3 63673 NULL
112665 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
112666 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
112667 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
112668 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
112669 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
112670 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
112671 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
112672 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
112673 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
112674 +prepare_copy_63826 prepare_copy 2 63826 NULL
112675 +sel_write_load_63830 sel_write_load 3 63830 NULL
112676 +ll_readlink_63836 ll_readlink 3 63836 NULL
112677 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
112678 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
112679 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
112680 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
112681 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
112682 +__team_options_register_63941 __team_options_register 3 63941 NULL
112683 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
112684 +sysfs_add_one_63969 sysfs_add_one 0 63969 NULL
112685 +set_bredr_63975 set_bredr 4 63975 NULL
112686 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
112687 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
112688 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
112689 +hfsplus_security_setxattr_64009 hfsplus_security_setxattr 4 64009 NULL
112690 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
112691 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
112692 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
112693 +get_u8_64076 get_u8 0 64076 NULL
112694 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
112695 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
112696 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
112697 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
112698 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
112699 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
112700 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
112701 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
112702 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
112703 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
112704 +init_bch_64130 init_bch 1-2 64130 NULL
112705 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
112706 +read_div_64147 read_div 0 64147 NULL
112707 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
112708 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
112709 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
112710 +read_pulse_64227 read_pulse 0-3 64227 NULL
112711 +ea_len_64229 ea_len 0 64229 NULL
112712 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
112713 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
112714 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
112715 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
112716 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
112717 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
112718 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
112719 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
112720 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
112721 +ts_write_64336 ts_write 3 64336 NULL
112722 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
112723 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
112724 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
112725 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
112726 +reg_create_64372 reg_create 5 64372 NULL
112727 +ilo_write_64378 ilo_write 3 64378 NULL
112728 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
112729 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
112730 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
112731 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
112732 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
112733 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
112734 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
112735 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
112736 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
112737 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
112738 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
112739 +single_open_size_64483 single_open_size 4 64483 NULL
112740 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
112741 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
112742 +remove_uuid_64505 remove_uuid 4 64505 NULL
112743 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
112744 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
112745 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
112746 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
112747 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
112748 +SyS_bind_64544 SyS_bind 3 64544 NULL
112749 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
112750 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
112751 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
112752 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
112753 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
112754 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
112755 +do_erase_64574 do_erase 4 64574 NULL
112756 +fanotify_write_64623 fanotify_write 3 64623 NULL
112757 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
112758 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
112759 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
112760 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
112761 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
112762 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
112763 +sec_bulk_write_64691 sec_bulk_write 2-3 64691 NULL
112764 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
112765 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
112766 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
112767 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
112768 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
112769 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
112770 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
112771 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
112772 +message_for_md_64777 message_for_md 5 64777 NULL
112773 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
112774 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
112775 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
112776 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
112777 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
112778 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
112779 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
112780 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
112781 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
112782 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
112783 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
112784 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
112785 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
112786 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
112787 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
112788 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
112789 +insert_dent_65034 insert_dent 7 65034 NULL
112790 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
112791 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
112792 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
112793 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
112794 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
112795 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
112796 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
112797 +uasp_alloc_cmd_65097 uasp_alloc_cmd 0 65097 NULL
112798 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
112799 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
112800 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
112801 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
112802 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
112803 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
112804 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
112805 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
112806 +get_var_len_65304 get_var_len 0 65304 NULL
112807 +unpack_array_65318 unpack_array 0 65318 NULL
112808 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
112809 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
112810 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
112811 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
112812 +SyS_writev_65372 SyS_writev 3 65372 NULL
112813 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
112814 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
112815 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
112816 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
112817 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
112818 +device_add_groups_65423 device_add_groups 0 65423 NULL
112819 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
112820 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
112821 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
112822 +clear_user_65470 clear_user 2 65470 NULL
112823 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
112824 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
112825 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
112826 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
112827 new file mode 100644
112828 index 0000000..4a637ab
112829 --- /dev/null
112830 +++ b/tools/gcc/size_overflow_plugin.c
112831 @@ -0,0 +1,4040 @@
112832 +/*
112833 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112834 + * Licensed under the GPL v2, or (at your option) v3
112835 + *
112836 + * Homepage:
112837 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112838 + *
112839 + * Documentation:
112840 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112841 + *
112842 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112843 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112844 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112845 + *
112846 + * Usage:
112847 + * $ gcc -I`gcc -print-file-name=plugin`/include/c-family -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -ggdb -Wall -W -o size_overflow_plugin.so size_overflow_plugin.c
112848 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
112849 + */
112850 +
112851 +#include "gcc-common.h"
112852 +
112853 +int plugin_is_GPL_compatible;
112854 +
112855 +static struct plugin_info size_overflow_plugin_info = {
112856 + .version = "20140128",
112857 + .help = "no-size-overflow\tturn off size overflow checking\n",
112858 +};
112859 +
112860 +#define BEFORE_STMT true
112861 +#define AFTER_STMT false
112862 +#define CREATE_NEW_VAR NULL_TREE
112863 +#define CODES_LIMIT 32
112864 +#define MAX_PARAM 31
112865 +#define VEC_LEN 128
112866 +#define MY_STMT GF_PLF_1
112867 +#define NO_CAST_CHECK GF_PLF_2
112868 +#define RET_CHECK NULL_TREE
112869 +#define CANNOT_FIND_ARG 32
112870 +#define WRONG_NODE 32
112871 +#define NOT_INTENTIONAL_ASM NULL
112872 +#define MIN_CHECK true
112873 +#define MAX_CHECK false
112874 +
112875 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
112876 +#define YES_ASM_STR "# size_overflow MARK_YES "
112877 +#define OK_ASM_STR "# size_overflow "
112878 +
112879 +struct size_overflow_hash {
112880 + const struct size_overflow_hash * const next;
112881 + const char * const name;
112882 + const unsigned int param;
112883 +};
112884 +
112885 +#include "size_overflow_hash.h"
112886 +
112887 +enum mark {
112888 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
112889 +};
112890 +
112891 +static unsigned int call_count;
112892 +
112893 +struct visited {
112894 + struct visited *next;
112895 + const_tree fndecl;
112896 + unsigned int num;
112897 + const_tree rhs;
112898 +};
112899 +
112900 +struct next_cgraph_node {
112901 + struct next_cgraph_node *next;
112902 + struct cgraph_node *current_function;
112903 + tree callee_fndecl;
112904 + unsigned int num;
112905 +};
112906 +
112907 +struct interesting_node {
112908 + struct interesting_node *next;
112909 + gimple first_stmt;
112910 + const_tree fndecl;
112911 + tree node;
112912 +#if BUILDING_GCC_VERSION <= 4007
112913 + VEC(tree, gc) *last_nodes;
112914 +#else
112915 + vec<tree, va_gc> *last_nodes;
112916 +#endif
112917 + unsigned int num;
112918 + enum mark intentional_attr_decl;
112919 + enum mark intentional_attr_cur_fndecl;
112920 + gimple intentional_mark_from_gimple;
112921 +};
112922 +
112923 +static tree report_size_overflow_decl;
112924 +static const_tree const_char_ptr_type_node;
112925 +
112926 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
112927 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
112928 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
112929 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
112930 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
112931 +
112932 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
112933 +static tree get_size_overflow_type(gimple stmt, const_tree node);
112934 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
112935 +
112936 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
112937 +{
112938 + unsigned int arg_count;
112939 + enum tree_code code = TREE_CODE(*node);
112940 +
112941 + switch (code) {
112942 + case FUNCTION_DECL:
112943 + arg_count = type_num_arguments(TREE_TYPE(*node));
112944 + break;
112945 + case FUNCTION_TYPE:
112946 + case METHOD_TYPE:
112947 + arg_count = type_num_arguments(*node);
112948 + break;
112949 + default:
112950 + *no_add_attrs = true;
112951 + error("%s: %qE attribute only applies to functions", __func__, name);
112952 + return NULL_TREE;
112953 + }
112954 +
112955 + for (; args; args = TREE_CHAIN(args)) {
112956 + tree position = TREE_VALUE(args);
112957 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
112958 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
112959 + *no_add_attrs = true;
112960 + }
112961 + }
112962 + return NULL_TREE;
112963 +}
112964 +
112965 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
112966 +{
112967 + unsigned int arg_count;
112968 + enum tree_code code = TREE_CODE(*node);
112969 +
112970 + switch (code) {
112971 + case FUNCTION_DECL:
112972 + arg_count = type_num_arguments(TREE_TYPE(*node));
112973 + break;
112974 + case FUNCTION_TYPE:
112975 + case METHOD_TYPE:
112976 + arg_count = type_num_arguments(*node);
112977 + break;
112978 + case FIELD_DECL:
112979 + return NULL_TREE;
112980 + default:
112981 + *no_add_attrs = true;
112982 + error("%qE attribute only applies to functions", name);
112983 + return NULL_TREE;
112984 + }
112985 +
112986 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
112987 + return NULL_TREE;
112988 +
112989 + for (; args; args = TREE_CHAIN(args)) {
112990 + tree position = TREE_VALUE(args);
112991 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
112992 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
112993 + *no_add_attrs = true;
112994 + }
112995 + }
112996 + return NULL_TREE;
112997 +}
112998 +
112999 +static struct attribute_spec size_overflow_attr = {
113000 + .name = "size_overflow",
113001 + .min_length = 1,
113002 + .max_length = -1,
113003 + .decl_required = true,
113004 + .type_required = false,
113005 + .function_type_required = false,
113006 + .handler = handle_size_overflow_attribute,
113007 +#if BUILDING_GCC_VERSION >= 4007
113008 + .affects_type_identity = false
113009 +#endif
113010 +};
113011 +
113012 +static struct attribute_spec intentional_overflow_attr = {
113013 + .name = "intentional_overflow",
113014 + .min_length = 1,
113015 + .max_length = -1,
113016 + .decl_required = true,
113017 + .type_required = false,
113018 + .function_type_required = false,
113019 + .handler = handle_intentional_overflow_attribute,
113020 +#if BUILDING_GCC_VERSION >= 4007
113021 + .affects_type_identity = false
113022 +#endif
113023 +};
113024 +
113025 +static void register_attributes(void __unused *event_data, void __unused *data)
113026 +{
113027 + register_attribute(&size_overflow_attr);
113028 + register_attribute(&intentional_overflow_attr);
113029 +}
113030 +
113031 +static bool is_bool(const_tree node)
113032 +{
113033 + const_tree type;
113034 +
113035 + if (node == NULL_TREE)
113036 + return false;
113037 +
113038 + type = TREE_TYPE(node);
113039 + if (!INTEGRAL_TYPE_P(type))
113040 + return false;
113041 + if (TREE_CODE(type) == BOOLEAN_TYPE)
113042 + return true;
113043 + if (TYPE_PRECISION(type) == 1)
113044 + return true;
113045 + return false;
113046 +}
113047 +
113048 +static bool skip_types(const_tree var)
113049 +{
113050 + tree type;
113051 + enum tree_code code;
113052 +
113053 + if (is_gimple_constant(var))
113054 + return true;
113055 +
113056 + switch (TREE_CODE(var)) {
113057 + case ADDR_EXPR:
113058 +#if BUILDING_GCC_VERSION >= 4006
113059 + case MEM_REF:
113060 +#endif
113061 + case ARRAY_REF:
113062 + case BIT_FIELD_REF:
113063 + case INDIRECT_REF:
113064 + case TARGET_MEM_REF:
113065 + case COMPONENT_REF:
113066 + case VAR_DECL:
113067 + case VIEW_CONVERT_EXPR:
113068 + return true;
113069 + default:
113070 + break;
113071 + }
113072 +
113073 + code = TREE_CODE(var);
113074 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
113075 +
113076 + type = TREE_TYPE(var);
113077 + switch (TREE_CODE(type)) {
113078 + case INTEGER_TYPE:
113079 + case ENUMERAL_TYPE:
113080 + return false;
113081 + case BOOLEAN_TYPE:
113082 + return is_bool(var);
113083 + default:
113084 + return true;
113085 + }
113086 +}
113087 +
113088 +static inline gimple get_def_stmt(const_tree node)
113089 +{
113090 + gcc_assert(node != NULL_TREE);
113091 +
113092 + if (skip_types(node))
113093 + return NULL;
113094 +
113095 + if (TREE_CODE(node) != SSA_NAME)
113096 + return NULL;
113097 + return SSA_NAME_DEF_STMT(node);
113098 +}
113099 +
113100 +static unsigned char get_tree_code(const_tree type)
113101 +{
113102 + switch (TREE_CODE(type)) {
113103 + case ARRAY_TYPE:
113104 + return 0;
113105 + case BOOLEAN_TYPE:
113106 + return 1;
113107 + case ENUMERAL_TYPE:
113108 + return 2;
113109 + case FUNCTION_TYPE:
113110 + return 3;
113111 + case INTEGER_TYPE:
113112 + return 4;
113113 + case POINTER_TYPE:
113114 + return 5;
113115 + case RECORD_TYPE:
113116 + return 6;
113117 + case UNION_TYPE:
113118 + return 7;
113119 + case VOID_TYPE:
113120 + return 8;
113121 + case REAL_TYPE:
113122 + return 9;
113123 + case VECTOR_TYPE:
113124 + return 10;
113125 + case REFERENCE_TYPE:
113126 + return 11;
113127 + case OFFSET_TYPE:
113128 + return 12;
113129 + case COMPLEX_TYPE:
113130 + return 13;
113131 + default:
113132 + debug_tree((tree)type);
113133 + gcc_unreachable();
113134 + }
113135 +}
113136 +
113137 +struct function_hash {
113138 + size_t tree_codes_len;
113139 + unsigned char tree_codes[CODES_LIMIT];
113140 + const_tree fndecl;
113141 + unsigned int hash;
113142 +};
113143 +
113144 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
113145 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
113146 +{
113147 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
113148 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
113149 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
113150 +
113151 + unsigned int m = 0x57559429;
113152 + unsigned int n = 0x5052acdb;
113153 + const unsigned int *key4 = (const unsigned int *)key;
113154 + unsigned int h = len;
113155 + unsigned int k = len + seed + n;
113156 + unsigned long long p;
113157 +
113158 + while (len >= 8) {
113159 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
113160 + len -= 8;
113161 + }
113162 + if (len >= 4) {
113163 + cwmixb(key4[0]) key4 += 1;
113164 + len -= 4;
113165 + }
113166 + if (len)
113167 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
113168 + cwmixb(h ^ (k + n));
113169 + return k ^ h;
113170 +
113171 +#undef cwfold
113172 +#undef cwmixa
113173 +#undef cwmixb
113174 +}
113175 +
113176 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
113177 +{
113178 + unsigned int fn, codes, seed = 0;
113179 +
113180 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
113181 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
113182 +
113183 + fn_hash_data->hash = fn ^ codes;
113184 +}
113185 +
113186 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
113187 +{
113188 + gcc_assert(type != NULL_TREE);
113189 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
113190 +
113191 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
113192 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
113193 + fn_hash_data->tree_codes_len++;
113194 + type = TREE_TYPE(type);
113195 + }
113196 +}
113197 +
113198 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
113199 +{
113200 + const_tree result;
113201 +
113202 + gcc_assert(node != NULL_TREE);
113203 +
113204 + if (DECL_P(node)) {
113205 + result = DECL_RESULT(node);
113206 + if (result != NULL_TREE)
113207 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
113208 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
113209 + }
113210 +
113211 + gcc_assert(TYPE_P(node));
113212 +
113213 + if (TREE_CODE(node) == FUNCTION_TYPE)
113214 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
113215 +
113216 + return set_node_codes(node, fn_hash_data);
113217 +}
113218 +
113219 +static void set_function_codes(struct function_hash *fn_hash_data)
113220 +{
113221 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
113222 + enum tree_code code = TREE_CODE(type);
113223 +
113224 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
113225 +
113226 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
113227 +
113228 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
113229 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
113230 +}
113231 +
113232 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
113233 +{
113234 + const struct size_overflow_hash *entry;
113235 + struct function_hash fn_hash_data;
113236 + const char *func_name;
113237 +
113238 + // skip builtins __builtin_constant_p
113239 + if (DECL_BUILT_IN(fndecl))
113240 + return NULL;
113241 +
113242 + fn_hash_data.fndecl = fndecl;
113243 + fn_hash_data.tree_codes_len = 0;
113244 +
113245 + set_function_codes(&fn_hash_data);
113246 + gcc_assert(fn_hash_data.tree_codes_len != 0);
113247 +
113248 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
113249 + set_hash(func_name, &fn_hash_data);
113250 +
113251 + entry = size_overflow_hash[fn_hash_data.hash];
113252 +
113253 + while (entry) {
113254 + if (!strcmp(entry->name, func_name))
113255 + return entry;
113256 + entry = entry->next;
113257 + }
113258 + return NULL;
113259 +}
113260 +
113261 +static void print_missing_msg(const_tree func, unsigned int argnum)
113262 +{
113263 + location_t loc;
113264 + const char *curfunc;
113265 + struct function_hash fn_hash_data;
113266 +
113267 + fn_hash_data.fndecl = DECL_ORIGIN(func);
113268 + fn_hash_data.tree_codes_len = 0;
113269 +
113270 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
113271 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
113272 +
113273 + set_function_codes(&fn_hash_data);
113274 + set_hash(curfunc, &fn_hash_data);
113275 +
113276 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
113277 +}
113278 +
113279 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
113280 +{
113281 + tree var;
113282 + unsigned int argnum = 1;
113283 +
113284 + if (TREE_CODE(arg) == SSA_NAME)
113285 + arg = SSA_NAME_VAR(arg);
113286 +
113287 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
113288 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
113289 + continue;
113290 + if (!skip_types(var))
113291 + return argnum;
113292 + }
113293 +
113294 + return CANNOT_FIND_ARG;
113295 +}
113296 +
113297 +static tree create_new_var(tree type)
113298 +{
113299 + tree new_var = create_tmp_var(type, "cicus");
113300 +
113301 + add_referenced_var(new_var);
113302 + return new_var;
113303 +}
113304 +
113305 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
113306 +{
113307 + gimple assign;
113308 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113309 + tree type = TREE_TYPE(rhs1);
113310 + tree lhs = create_new_var(type);
113311 +
113312 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
113313 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
113314 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113315 +
113316 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113317 + update_stmt(assign);
113318 + gimple_set_plf(assign, MY_STMT, true);
113319 + return assign;
113320 +}
113321 +
113322 +static tree cast_a_tree(tree type, tree var)
113323 +{
113324 + gcc_assert(type != NULL_TREE);
113325 + gcc_assert(var != NULL_TREE);
113326 + gcc_assert(fold_convertible_p(type, var));
113327 +
113328 + return fold_convert(type, var);
113329 +}
113330 +
113331 +static tree get_lhs(const_gimple stmt)
113332 +{
113333 + switch (gimple_code(stmt)) {
113334 + case GIMPLE_ASSIGN:
113335 + case GIMPLE_CALL:
113336 + return gimple_get_lhs(stmt);
113337 + case GIMPLE_PHI:
113338 + return gimple_phi_result(stmt);
113339 + default:
113340 + return NULL_TREE;
113341 + }
113342 +}
113343 +
113344 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
113345 +{
113346 + const_gimple def_stmt = get_def_stmt(rhs);
113347 +
113348 + if (force)
113349 + return false;
113350 +
113351 + if (is_gimple_constant(rhs))
113352 + return false;
113353 +
113354 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
113355 + return false;
113356 +
113357 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
113358 + return false;
113359 +
113360 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
113361 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
113362 + return false;
113363 +
113364 + return true;
113365 +}
113366 +
113367 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
113368 +{
113369 + gimple assign, def_stmt;
113370 +
113371 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
113372 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
113373 + gcc_unreachable();
113374 +
113375 + def_stmt = get_def_stmt(rhs);
113376 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && gimple_plf(def_stmt, MY_STMT))
113377 + return def_stmt;
113378 +
113379 + if (lhs == CREATE_NEW_VAR)
113380 + lhs = create_new_var(dst_type);
113381 +
113382 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
113383 +
113384 + if (!gsi_end_p(*gsi)) {
113385 + location_t loc = gimple_location(gsi_stmt(*gsi));
113386 + gimple_set_location(assign, loc);
113387 + }
113388 +
113389 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113390 +
113391 + if (before)
113392 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
113393 + else
113394 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
113395 + update_stmt(assign);
113396 + return assign;
113397 +}
113398 +
113399 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
113400 +{
113401 + gimple_stmt_iterator gsi;
113402 + tree lhs;
113403 + gimple new_stmt;
113404 +
113405 + if (rhs == NULL_TREE)
113406 + return NULL_TREE;
113407 +
113408 + gsi = gsi_for_stmt(stmt);
113409 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
113410 + gimple_set_plf(new_stmt, MY_STMT, true);
113411 +
113412 + lhs = get_lhs(new_stmt);
113413 + gcc_assert(lhs != NULL_TREE);
113414 + return lhs;
113415 +}
113416 +
113417 +static tree cast_to_TI_type(gimple stmt, tree node)
113418 +{
113419 + gimple_stmt_iterator gsi;
113420 + gimple cast_stmt;
113421 + tree type = TREE_TYPE(node);
113422 +
113423 + if (types_compatible_p(type, intTI_type_node))
113424 + return node;
113425 +
113426 + gsi = gsi_for_stmt(stmt);
113427 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113428 + gimple_set_plf(cast_stmt, MY_STMT, true);
113429 + return gimple_assign_lhs(cast_stmt);
113430 +}
113431 +
113432 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
113433 +{
113434 + tree lhs, new_lhs;
113435 + gimple_stmt_iterator gsi;
113436 +
113437 + if (rhs1 == NULL_TREE) {
113438 + debug_gimple_stmt(oldstmt);
113439 + error("%s: rhs1 is NULL_TREE", __func__);
113440 + gcc_unreachable();
113441 + }
113442 +
113443 + switch (gimple_code(oldstmt)) {
113444 + case GIMPLE_ASM:
113445 + lhs = rhs1;
113446 + break;
113447 + case GIMPLE_CALL:
113448 + case GIMPLE_ASSIGN:
113449 + lhs = gimple_get_lhs(oldstmt);
113450 + break;
113451 + default:
113452 + debug_gimple_stmt(oldstmt);
113453 + gcc_unreachable();
113454 + }
113455 +
113456 + gsi = gsi_for_stmt(oldstmt);
113457 + pointer_set_insert(visited, oldstmt);
113458 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
113459 + basic_block next_bb, cur_bb;
113460 + const_edge e;
113461 +
113462 + gcc_assert(before == false);
113463 + gcc_assert(stmt_can_throw_internal(oldstmt));
113464 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
113465 + gcc_assert(!gsi_end_p(gsi));
113466 +
113467 + cur_bb = gimple_bb(oldstmt);
113468 + next_bb = cur_bb->next_bb;
113469 + e = find_edge(cur_bb, next_bb);
113470 + gcc_assert(e != NULL);
113471 + gcc_assert(e->flags & EDGE_FALLTHRU);
113472 +
113473 + gsi = gsi_after_labels(next_bb);
113474 + gcc_assert(!gsi_end_p(gsi));
113475 +
113476 + before = true;
113477 + oldstmt = gsi_stmt(gsi);
113478 + }
113479 +
113480 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
113481 + return new_lhs;
113482 +}
113483 +
113484 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
113485 +{
113486 + gimple stmt;
113487 + gimple_stmt_iterator gsi;
113488 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
113489 +
113490 + if (gimple_plf(oldstmt, MY_STMT))
113491 + return lhs;
113492 +
113493 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
113494 + rhs1 = gimple_assign_rhs1(oldstmt);
113495 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
113496 + }
113497 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
113498 + rhs2 = gimple_assign_rhs2(oldstmt);
113499 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
113500 + }
113501 +
113502 + stmt = gimple_copy(oldstmt);
113503 + gimple_set_location(stmt, gimple_location(oldstmt));
113504 + gimple_set_plf(stmt, MY_STMT, true);
113505 +
113506 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
113507 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
113508 +
113509 + size_overflow_type = get_size_overflow_type(oldstmt, node);
113510 +
113511 + new_var = create_new_var(size_overflow_type);
113512 + new_var = make_ssa_name(new_var, stmt);
113513 + gimple_assign_set_lhs(stmt, new_var);
113514 +
113515 + if (rhs1 != NULL_TREE)
113516 + gimple_assign_set_rhs1(stmt, rhs1);
113517 +
113518 + if (rhs2 != NULL_TREE)
113519 + gimple_assign_set_rhs2(stmt, rhs2);
113520 +#if BUILDING_GCC_VERSION >= 4006
113521 + if (rhs3 != NULL_TREE)
113522 + gimple_assign_set_rhs3(stmt, rhs3);
113523 +#endif
113524 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
113525 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
113526 +
113527 + gsi = gsi_for_stmt(oldstmt);
113528 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
113529 + update_stmt(stmt);
113530 + pointer_set_insert(visited, oldstmt);
113531 + return gimple_assign_lhs(stmt);
113532 +}
113533 +
113534 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
113535 +{
113536 + gimple assign;
113537 + gimple_stmt_iterator gsi;
113538 + basic_block first_bb;
113539 +
113540 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
113541 +
113542 + if (bb->index == 0) {
113543 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
113544 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
113545 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
113546 + bb = first_bb;
113547 + }
113548 +
113549 + gsi = gsi_after_labels(bb);
113550 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
113551 + gimple_set_plf(assign, MY_STMT, true);
113552 +
113553 + return gimple_assign_lhs(assign);
113554 +}
113555 +
113556 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
113557 +{
113558 + gimple_stmt_iterator gsi;
113559 + gimple assign, def_stmt = get_def_stmt(new_arg);
113560 +
113561 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
113562 + gsi = gsi_after_labels(gimple_bb(def_stmt));
113563 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
113564 + } else {
113565 + gsi = gsi_for_stmt(def_stmt);
113566 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
113567 + }
113568 +
113569 + gimple_set_plf(assign, MY_STMT, true);
113570 + return gimple_assign_lhs(assign);
113571 +}
113572 +
113573 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
113574 +{
113575 + basic_block bb;
113576 + gimple_stmt_iterator gsi;
113577 + const_gimple def_stmt;
113578 + gimple assign;
113579 +
113580 + def_stmt = get_def_stmt(arg);
113581 + bb = gimple_bb(def_stmt);
113582 + gcc_assert(bb->index != 0);
113583 + gsi = gsi_after_labels(bb);
113584 +
113585 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
113586 + gimple_set_plf(assign, MY_STMT, true);
113587 + return gimple_assign_lhs(assign);
113588 +}
113589 +
113590 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
113591 +{
113592 + tree size_overflow_type;
113593 + tree arg;
113594 + const_gimple def_stmt;
113595 +
113596 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
113597 + return new_arg;
113598 +
113599 + arg = gimple_phi_arg_def(oldstmt, i);
113600 + def_stmt = get_def_stmt(arg);
113601 + gcc_assert(def_stmt != NULL);
113602 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
113603 +
113604 + switch (gimple_code(def_stmt)) {
113605 + case GIMPLE_PHI:
113606 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
113607 + case GIMPLE_NOP: {
113608 + basic_block bb;
113609 +
113610 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
113611 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
113612 + }
113613 + case GIMPLE_ASM: {
113614 + gimple_stmt_iterator gsi;
113615 + gimple assign, stmt = get_def_stmt(arg);
113616 +
113617 + gsi = gsi_for_stmt(stmt);
113618 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
113619 + gimple_set_plf(assign, MY_STMT, true);
113620 + return gimple_assign_lhs(assign);
113621 + }
113622 + default:
113623 + gcc_assert(new_arg != NULL_TREE);
113624 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
113625 + return use_phi_ssa_name(ssa_name_var, new_arg);
113626 + }
113627 +}
113628 +
113629 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
113630 +{
113631 + basic_block bb;
113632 + gimple phi;
113633 + gimple_seq seq;
113634 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
113635 +
113636 + bb = gsi_bb(gsi);
113637 +
113638 + if (result == NULL_TREE) {
113639 + tree old_result = gimple_phi_result(oldstmt);
113640 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
113641 +
113642 + result = create_new_var(size_overflow_type);
113643 + }
113644 +
113645 + phi = create_phi_node(result, bb);
113646 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
113647 + seq = phi_nodes(bb);
113648 + gsi = gsi_last(seq);
113649 + gsi_remove(&gsi, false);
113650 +
113651 + gsi = gsi_for_stmt(oldstmt);
113652 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
113653 + gimple_set_bb(phi, bb);
113654 + gimple_set_plf(phi, MY_STMT, true);
113655 + return phi;
113656 +}
113657 +
113658 +#if BUILDING_GCC_VERSION <= 4007
113659 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
113660 +#else
113661 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
113662 +#endif
113663 +{
113664 + gimple new_phi;
113665 + unsigned int i;
113666 + tree arg, result;
113667 + location_t loc = gimple_location(oldstmt);
113668 +
113669 +#if BUILDING_GCC_VERSION <= 4007
113670 + gcc_assert(!VEC_empty(tree, *args));
113671 +#else
113672 + gcc_assert(!args->is_empty());
113673 +#endif
113674 +
113675 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
113676 + result = gimple_phi_result(new_phi);
113677 + ssa_name_var = SSA_NAME_VAR(result);
113678 +
113679 +#if BUILDING_GCC_VERSION <= 4007
113680 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
113681 +#else
113682 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
113683 +#endif
113684 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
113685 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
113686 + }
113687 +
113688 +#if BUILDING_GCC_VERSION <= 4007
113689 + VEC_free(tree, heap, *args);
113690 +#else
113691 + vec_free(args);
113692 +#endif
113693 + update_stmt(new_phi);
113694 + return result;
113695 +}
113696 +
113697 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
113698 +{
113699 + tree ssa_name_var = NULL_TREE;
113700 +#if BUILDING_GCC_VERSION <= 4007
113701 + VEC(tree, heap) *args = NULL;
113702 +#else
113703 + vec<tree, va_heap, vl_embed> *args = NULL;
113704 +#endif
113705 + gimple oldstmt = get_def_stmt(orig_result);
113706 + unsigned int i, len = gimple_phi_num_args(oldstmt);
113707 +
113708 + pointer_set_insert(visited, oldstmt);
113709 + for (i = 0; i < len; i++) {
113710 + tree arg, new_arg;
113711 +
113712 + arg = gimple_phi_arg_def(oldstmt, i);
113713 + new_arg = expand(visited, caller_node, arg);
113714 +
113715 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
113716 + ssa_name_var = SSA_NAME_VAR(new_arg);
113717 +
113718 + if (is_gimple_constant(arg)) {
113719 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
113720 +
113721 + new_arg = cast_a_tree(size_overflow_type, arg);
113722 + }
113723 +
113724 +#if BUILDING_GCC_VERSION <= 4007
113725 + VEC_safe_push(tree, heap, args, new_arg);
113726 +#else
113727 + vec_safe_push(args, new_arg);
113728 +#endif
113729 + }
113730 +
113731 +#if BUILDING_GCC_VERSION <= 4007
113732 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
113733 +#else
113734 + return create_new_phi_node(args, ssa_name_var, oldstmt);
113735 +#endif
113736 +}
113737 +
113738 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
113739 +{
113740 + gimple assign;
113741 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113742 + tree origtype = TREE_TYPE(orig_rhs);
113743 +
113744 + gcc_assert(is_gimple_assign(stmt));
113745 +
113746 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113747 + gimple_set_plf(assign, MY_STMT, true);
113748 + return gimple_assign_lhs(assign);
113749 +}
113750 +
113751 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113752 +{
113753 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113754 + enum machine_mode lhs_mode, rhs_mode;
113755 + gimple def_stmt = get_def_stmt(no_const_rhs);
113756 +
113757 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113758 + return false;
113759 +
113760 + rhs1 = gimple_assign_rhs1(def_stmt);
113761 + lhs = gimple_assign_lhs(def_stmt);
113762 + rhs1_type = TREE_TYPE(rhs1);
113763 + lhs_type = TREE_TYPE(lhs);
113764 + rhs_mode = TYPE_MODE(rhs1_type);
113765 + lhs_mode = TYPE_MODE(lhs_type);
113766 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113767 + return false;
113768 +
113769 + return true;
113770 +}
113771 +
113772 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
113773 +{
113774 + tree rhs1 = gimple_assign_rhs1(stmt);
113775 + tree lhs = gimple_assign_lhs(stmt);
113776 + const_tree rhs1_type = TREE_TYPE(rhs1);
113777 + const_tree lhs_type = TREE_TYPE(lhs);
113778 +
113779 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
113780 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113781 +
113782 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
113783 +}
113784 +
113785 +static bool no_uses(tree node)
113786 +{
113787 + imm_use_iterator imm_iter;
113788 + use_operand_p use_p;
113789 +
113790 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113791 + const_gimple use_stmt = USE_STMT(use_p);
113792 +
113793 + if (use_stmt == NULL)
113794 + return true;
113795 + if (is_gimple_debug(use_stmt))
113796 + continue;
113797 + return false;
113798 + }
113799 + return true;
113800 +}
113801 +
113802 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113803 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113804 +{
113805 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113806 + gimple def_stmt = get_def_stmt(lhs);
113807 +
113808 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113809 + return false;
113810 +
113811 + rhs1 = gimple_assign_rhs1(def_stmt);
113812 + rhs_type = TREE_TYPE(rhs1);
113813 + lhs_type = TREE_TYPE(lhs);
113814 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113815 + return false;
113816 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113817 + return false;
113818 +
113819 + def_stmt = get_def_stmt(rhs1);
113820 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113821 + return false;
113822 +
113823 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113824 + return false;
113825 +
113826 + rhs1 = gimple_assign_rhs1(def_stmt);
113827 + rhs2 = gimple_assign_rhs2(def_stmt);
113828 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113829 + return false;
113830 +
113831 + if (is_gimple_constant(rhs2))
113832 + not_const_rhs = rhs1;
113833 + else
113834 + not_const_rhs = rhs2;
113835 +
113836 + return no_uses(not_const_rhs);
113837 +}
113838 +
113839 +static bool skip_lhs_cast_check(const_gimple stmt)
113840 +{
113841 + const_tree rhs = gimple_assign_rhs1(stmt);
113842 + const_gimple def_stmt = get_def_stmt(rhs);
113843 +
113844 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
113845 + if (gimple_code(def_stmt) == GIMPLE_ASM)
113846 + return true;
113847 +
113848 + if (is_const_plus_unsigned_signed_truncation(rhs))
113849 + return true;
113850 +
113851 + return false;
113852 +}
113853 +
113854 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
113855 +{
113856 + bool cast_lhs, cast_rhs;
113857 + tree lhs = gimple_assign_lhs(stmt);
113858 + tree rhs = gimple_assign_rhs1(stmt);
113859 + const_tree lhs_type = TREE_TYPE(lhs);
113860 + const_tree rhs_type = TREE_TYPE(rhs);
113861 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
113862 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
113863 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
113864 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
113865 +
113866 + static bool check_lhs[3][4] = {
113867 + // ss su us uu
113868 + { false, true, true, false }, // lhs > rhs
113869 + { false, false, false, false }, // lhs = rhs
113870 + { true, true, true, true }, // lhs < rhs
113871 + };
113872 +
113873 + static bool check_rhs[3][4] = {
113874 + // ss su us uu
113875 + { true, false, true, true }, // lhs > rhs
113876 + { true, false, true, true }, // lhs = rhs
113877 + { true, false, true, true }, // lhs < rhs
113878 + };
113879 +
113880 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
113881 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
113882 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113883 +
113884 + if (lhs_size > rhs_size) {
113885 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113886 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113887 + } else if (lhs_size == rhs_size) {
113888 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113889 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113890 + } else {
113891 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113892 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113893 + }
113894 +
113895 + if (!cast_lhs && !cast_rhs)
113896 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113897 +
113898 + if (cast_lhs && !skip_lhs_cast_check(stmt))
113899 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
113900 +
113901 + if (cast_rhs)
113902 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
113903 +
113904 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113905 +}
113906 +
113907 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
113908 +{
113909 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
113910 +
113911 + if (gimple_plf(stmt, MY_STMT))
113912 + return lhs;
113913 +
113914 + rhs1 = gimple_assign_rhs1(stmt);
113915 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
113916 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113917 +
113918 + new_rhs1 = expand(visited, caller_node, rhs1);
113919 +
113920 + if (new_rhs1 == NULL_TREE)
113921 + return create_cast_assign(visited, stmt);
113922 +
113923 + if (gimple_plf(stmt, NO_CAST_CHECK))
113924 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113925 +
113926 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
113927 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
113928 +
113929 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
113930 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
113931 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113932 + }
113933 +
113934 + if (!gimple_assign_cast_p(stmt))
113935 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113936 +
113937 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
113938 +}
113939 +
113940 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
113941 +{
113942 + tree rhs1, lhs = gimple_assign_lhs(stmt);
113943 + gimple def_stmt = get_def_stmt(lhs);
113944 +
113945 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
113946 + rhs1 = gimple_assign_rhs1(def_stmt);
113947 +
113948 + if (is_gimple_constant(rhs1))
113949 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113950 +
113951 + switch (TREE_CODE(rhs1)) {
113952 + case SSA_NAME:
113953 + return handle_unary_rhs(visited, caller_node, def_stmt);
113954 + case ARRAY_REF:
113955 + case BIT_FIELD_REF:
113956 + case ADDR_EXPR:
113957 + case COMPONENT_REF:
113958 + case INDIRECT_REF:
113959 +#if BUILDING_GCC_VERSION >= 4006
113960 + case MEM_REF:
113961 +#endif
113962 + case TARGET_MEM_REF:
113963 + case VIEW_CONVERT_EXPR:
113964 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113965 + case PARM_DECL:
113966 + case VAR_DECL:
113967 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113968 +
113969 + default:
113970 + debug_gimple_stmt(def_stmt);
113971 + debug_tree(rhs1);
113972 + gcc_unreachable();
113973 + }
113974 +}
113975 +
113976 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
113977 +{
113978 + gimple cond_stmt;
113979 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
113980 +
113981 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
113982 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
113983 + update_stmt(cond_stmt);
113984 +}
113985 +
113986 +static tree create_string_param(tree string)
113987 +{
113988 + tree i_type, a_type;
113989 + const int length = TREE_STRING_LENGTH(string);
113990 +
113991 + gcc_assert(length > 0);
113992 +
113993 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
113994 + a_type = build_array_type(char_type_node, i_type);
113995 +
113996 + TREE_TYPE(string) = a_type;
113997 + TREE_CONSTANT(string) = 1;
113998 + TREE_READONLY(string) = 1;
113999 +
114000 + return build1(ADDR_EXPR, ptr_type_node, string);
114001 +}
114002 +
114003 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
114004 +{
114005 + gimple func_stmt;
114006 + const_gimple def_stmt;
114007 + const_tree loc_line;
114008 + tree loc_file, ssa_name, current_func;
114009 + expanded_location xloc;
114010 + char *ssa_name_buf;
114011 + int len;
114012 + struct cgraph_edge *edge;
114013 + struct cgraph_node *callee_node;
114014 + int frequency;
114015 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
114016 +
114017 + def_stmt = get_def_stmt(arg);
114018 + xloc = expand_location(gimple_location(def_stmt));
114019 +
114020 + if (!gimple_has_location(def_stmt)) {
114021 + xloc = expand_location(gimple_location(stmt));
114022 + if (!gimple_has_location(stmt))
114023 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
114024 + }
114025 +
114026 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
114027 +
114028 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
114029 + loc_file = create_string_param(loc_file);
114030 +
114031 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
114032 + current_func = create_string_param(current_func);
114033 +
114034 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
114035 + call_count++;
114036 + 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);
114037 + gcc_assert(len > 0);
114038 + ssa_name = build_string(len + 1, ssa_name_buf);
114039 + free(ssa_name_buf);
114040 + ssa_name = create_string_param(ssa_name);
114041 +
114042 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
114043 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
114044 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
114045 +
114046 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
114047 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
114048 +
114049 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
114050 + gcc_assert(edge != NULL);
114051 +}
114052 +
114053 +static void __unused print_the_code_insertions(const_gimple stmt)
114054 +{
114055 + location_t loc = gimple_location(stmt);
114056 +
114057 + inform(loc, "Integer size_overflow check applied here.");
114058 +}
114059 +
114060 +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)
114061 +{
114062 + basic_block cond_bb, join_bb, bb_true;
114063 + edge e;
114064 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114065 +
114066 + cond_bb = gimple_bb(stmt);
114067 + if (before)
114068 + gsi_prev(&gsi);
114069 + if (gsi_end_p(gsi))
114070 + e = split_block_after_labels(cond_bb);
114071 + else
114072 + e = split_block(cond_bb, gsi_stmt(gsi));
114073 + cond_bb = e->src;
114074 + join_bb = e->dest;
114075 + e->flags = EDGE_FALSE_VALUE;
114076 + e->probability = REG_BR_PROB_BASE;
114077 +
114078 + bb_true = create_empty_bb(cond_bb);
114079 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
114080 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
114081 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
114082 +
114083 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114084 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
114085 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
114086 +
114087 + if (current_loops != NULL) {
114088 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
114089 + add_bb_to_loop(bb_true, cond_bb->loop_father);
114090 + }
114091 +
114092 + insert_cond(cond_bb, arg, cond_code, type_value);
114093 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
114094 +
114095 +// print_the_code_insertions(stmt);
114096 +}
114097 +
114098 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
114099 +{
114100 + const_tree rhs_type = TREE_TYPE(rhs);
114101 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
114102 +
114103 + gcc_assert(rhs_type != NULL_TREE);
114104 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
114105 + return;
114106 +
114107 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
114108 +
114109 + if (is_const_plus_unsigned_signed_truncation(rhs))
114110 + return;
114111 +
114112 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
114113 + // typemax (-1) < typemin (0)
114114 + if (TREE_OVERFLOW(type_max))
114115 + return;
114116 +
114117 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
114118 +
114119 + cast_rhs_type = TREE_TYPE(cast_rhs);
114120 + type_max_type = TREE_TYPE(type_max);
114121 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
114122 +
114123 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
114124 +
114125 + // special case: get_size_overflow_type(), 32, u64->s
114126 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
114127 + return;
114128 +
114129 + type_min_type = TREE_TYPE(type_min);
114130 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
114131 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
114132 +}
114133 +
114134 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
114135 +{
114136 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
114137 + return false;
114138 + if (!is_gimple_constant(rhs))
114139 + return false;
114140 + return true;
114141 +}
114142 +
114143 +static tree get_def_stmt_rhs(const_tree var)
114144 +{
114145 + tree rhs1, def_stmt_rhs1;
114146 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
114147 +
114148 + def_stmt = get_def_stmt(var);
114149 + if (!gimple_assign_cast_p(def_stmt))
114150 + return NULL_TREE;
114151 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
114152 +
114153 + rhs1 = gimple_assign_rhs1(def_stmt);
114154 + rhs1_def_stmt = get_def_stmt(rhs1);
114155 + if (!gimple_assign_cast_p(rhs1_def_stmt))
114156 + return rhs1;
114157 +
114158 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114159 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
114160 +
114161 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
114162 + case GIMPLE_CALL:
114163 + case GIMPLE_NOP:
114164 + case GIMPLE_ASM:
114165 + case GIMPLE_PHI:
114166 + return def_stmt_rhs1;
114167 + case GIMPLE_ASSIGN:
114168 + return rhs1;
114169 + default:
114170 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
114171 + gcc_unreachable();
114172 + }
114173 +}
114174 +
114175 +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)
114176 +{
114177 + tree new_rhs, orig_rhs;
114178 + void (*gimple_assign_set_rhs)(gimple, tree);
114179 + tree rhs1 = gimple_assign_rhs1(stmt);
114180 + tree rhs2 = gimple_assign_rhs2(stmt);
114181 + tree lhs = gimple_assign_lhs(stmt);
114182 +
114183 + if (!check_overflow)
114184 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114185 +
114186 + if (change_rhs == NULL_TREE)
114187 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114188 +
114189 + if (new_rhs2 == NULL_TREE) {
114190 + orig_rhs = rhs1;
114191 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
114192 + } else {
114193 + orig_rhs = rhs2;
114194 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
114195 + }
114196 +
114197 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
114198 +
114199 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
114200 + gimple_assign_set_rhs(stmt, new_rhs);
114201 + update_stmt(stmt);
114202 +
114203 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114204 +}
114205 +
114206 +static bool is_subtraction_special(const_gimple stmt)
114207 +{
114208 + gimple rhs1_def_stmt, rhs2_def_stmt;
114209 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
114210 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
114211 + const_tree rhs1 = gimple_assign_rhs1(stmt);
114212 + const_tree rhs2 = gimple_assign_rhs2(stmt);
114213 +
114214 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
114215 + return false;
114216 +
114217 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
114218 +
114219 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
114220 + return false;
114221 +
114222 + rhs1_def_stmt = get_def_stmt(rhs1);
114223 + rhs2_def_stmt = get_def_stmt(rhs2);
114224 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
114225 + return false;
114226 +
114227 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114228 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
114229 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
114230 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
114231 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
114232 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
114233 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
114234 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
114235 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
114236 + return false;
114237 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
114238 + return false;
114239 +
114240 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
114241 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
114242 + return true;
114243 +}
114244 +
114245 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
114246 +{
114247 + tree new_rhs1, new_rhs2;
114248 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
114249 + gimple assign, stmt = get_def_stmt(lhs);
114250 + tree rhs1 = gimple_assign_rhs1(stmt);
114251 + tree rhs2 = gimple_assign_rhs2(stmt);
114252 +
114253 + if (!is_subtraction_special(stmt))
114254 + return NULL_TREE;
114255 +
114256 + new_rhs1 = expand(visited, caller_node, rhs1);
114257 + new_rhs2 = expand(visited, caller_node, rhs2);
114258 +
114259 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
114260 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
114261 +
114262 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
114263 + return NULL_TREE;
114264 +
114265 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
114266 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
114267 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
114268 + }
114269 +
114270 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
114271 + new_lhs = gimple_assign_lhs(assign);
114272 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
114273 +
114274 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114275 +}
114276 +
114277 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
114278 +{
114279 + const_gimple def_stmt;
114280 +
114281 + if (TREE_CODE(rhs) != SSA_NAME)
114282 + return false;
114283 +
114284 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
114285 + return false;
114286 +
114287 + def_stmt = get_def_stmt(rhs);
114288 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
114289 + return false;
114290 +
114291 + return true;
114292 +}
114293 +
114294 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114295 +{
114296 + tree rhs1, rhs2, new_lhs;
114297 + gimple def_stmt = get_def_stmt(lhs);
114298 + tree new_rhs1 = NULL_TREE;
114299 + tree new_rhs2 = NULL_TREE;
114300 +
114301 + rhs1 = gimple_assign_rhs1(def_stmt);
114302 + rhs2 = gimple_assign_rhs2(def_stmt);
114303 +
114304 + /* no DImode/TImode division in the 32/64 bit kernel */
114305 + switch (gimple_assign_rhs_code(def_stmt)) {
114306 + case RDIV_EXPR:
114307 + case TRUNC_DIV_EXPR:
114308 + case CEIL_DIV_EXPR:
114309 + case FLOOR_DIV_EXPR:
114310 + case ROUND_DIV_EXPR:
114311 + case TRUNC_MOD_EXPR:
114312 + case CEIL_MOD_EXPR:
114313 + case FLOOR_MOD_EXPR:
114314 + case ROUND_MOD_EXPR:
114315 + case EXACT_DIV_EXPR:
114316 + case POINTER_PLUS_EXPR:
114317 + case BIT_AND_EXPR:
114318 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114319 + default:
114320 + break;
114321 + }
114322 +
114323 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
114324 + if (new_lhs != NULL_TREE)
114325 + return new_lhs;
114326 +
114327 + if (TREE_CODE(rhs1) == SSA_NAME)
114328 + new_rhs1 = expand(visited, caller_node, rhs1);
114329 + if (TREE_CODE(rhs2) == SSA_NAME)
114330 + new_rhs2 = expand(visited, caller_node, rhs2);
114331 +
114332 + if (is_a_neg_overflow(def_stmt, rhs2))
114333 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
114334 + if (is_a_neg_overflow(def_stmt, rhs1))
114335 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
114336 +
114337 +
114338 + if (is_a_constant_overflow(def_stmt, rhs2))
114339 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
114340 + if (is_a_constant_overflow(def_stmt, rhs1))
114341 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
114342 +
114343 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114344 +}
114345 +
114346 +#if BUILDING_GCC_VERSION >= 4006
114347 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
114348 +{
114349 + if (is_gimple_constant(rhs))
114350 + return cast_a_tree(size_overflow_type, rhs);
114351 + if (TREE_CODE(rhs) != SSA_NAME)
114352 + return NULL_TREE;
114353 + return expand(visited, caller_node, rhs);
114354 +}
114355 +
114356 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114357 +{
114358 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
114359 + gimple def_stmt = get_def_stmt(lhs);
114360 +
114361 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
114362 +
114363 + rhs1 = gimple_assign_rhs1(def_stmt);
114364 + rhs2 = gimple_assign_rhs2(def_stmt);
114365 + rhs3 = gimple_assign_rhs3(def_stmt);
114366 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
114367 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
114368 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
114369 +
114370 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
114371 +}
114372 +#endif
114373 +
114374 +static tree get_size_overflow_type(gimple stmt, const_tree node)
114375 +{
114376 + const_tree type;
114377 + tree new_type;
114378 +
114379 + gcc_assert(node != NULL_TREE);
114380 +
114381 + type = TREE_TYPE(node);
114382 +
114383 + if (gimple_plf(stmt, MY_STMT))
114384 + return TREE_TYPE(node);
114385 +
114386 + switch (TYPE_MODE(type)) {
114387 + case QImode:
114388 + new_type = intHI_type_node;
114389 + break;
114390 + case HImode:
114391 + new_type = intSI_type_node;
114392 + break;
114393 + case SImode:
114394 + new_type = intDI_type_node;
114395 + break;
114396 + case DImode:
114397 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114398 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114399 + else
114400 + new_type = intTI_type_node;
114401 + break;
114402 + case TImode:
114403 + gcc_assert(!TYPE_UNSIGNED(type));
114404 + new_type = intTI_type_node;
114405 + break;
114406 + default:
114407 + debug_tree((tree)node);
114408 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114409 + gcc_unreachable();
114410 + }
114411 +
114412 + if (TYPE_QUALS(type) != 0)
114413 + return build_qualified_type(new_type, TYPE_QUALS(type));
114414 + return new_type;
114415 +}
114416 +
114417 +static tree expand_visited(gimple def_stmt)
114418 +{
114419 + const_gimple next_stmt;
114420 + gimple_stmt_iterator gsi;
114421 + enum gimple_code code = gimple_code(def_stmt);
114422 +
114423 + if (code == GIMPLE_ASM)
114424 + return NULL_TREE;
114425 +
114426 + gsi = gsi_for_stmt(def_stmt);
114427 + gsi_next(&gsi);
114428 +
114429 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
114430 + return NULL_TREE;
114431 + gcc_assert(!gsi_end_p(gsi));
114432 + next_stmt = gsi_stmt(gsi);
114433 +
114434 + if (gimple_code(def_stmt) == GIMPLE_PHI && !gimple_plf((gimple)next_stmt, MY_STMT))
114435 + return NULL_TREE;
114436 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
114437 +
114438 + return get_lhs(next_stmt);
114439 +}
114440 +
114441 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114442 +{
114443 + gimple def_stmt;
114444 +
114445 + def_stmt = get_def_stmt(lhs);
114446 +
114447 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114448 + return NULL_TREE;
114449 +
114450 + if (gimple_plf(def_stmt, MY_STMT))
114451 + return lhs;
114452 +
114453 + if (pointer_set_contains(visited, def_stmt))
114454 + return expand_visited(def_stmt);
114455 +
114456 + switch (gimple_code(def_stmt)) {
114457 + case GIMPLE_PHI:
114458 + return handle_phi(visited, caller_node, lhs);
114459 + case GIMPLE_CALL:
114460 + case GIMPLE_ASM:
114461 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114462 + case GIMPLE_ASSIGN:
114463 + switch (gimple_num_ops(def_stmt)) {
114464 + case 2:
114465 + return handle_unary_ops(visited, caller_node, def_stmt);
114466 + case 3:
114467 + return handle_binary_ops(visited, caller_node, lhs);
114468 +#if BUILDING_GCC_VERSION >= 4006
114469 + case 4:
114470 + return handle_ternary_ops(visited, caller_node, lhs);
114471 +#endif
114472 + }
114473 + default:
114474 + debug_gimple_stmt(def_stmt);
114475 + error("%s: unknown gimple code", __func__);
114476 + gcc_unreachable();
114477 + }
114478 +}
114479 +
114480 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
114481 +{
114482 + const_gimple assign;
114483 + tree orig_type = TREE_TYPE(orig_node);
114484 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114485 +
114486 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114487 + return gimple_assign_lhs(assign);
114488 +}
114489 +
114490 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
114491 +{
114492 + void (*set_rhs)(gimple, tree);
114493 + gimple stmt = cur_node->first_stmt;
114494 + const_tree orig_node = cur_node->node;
114495 +
114496 + switch (gimple_code(stmt)) {
114497 + case GIMPLE_RETURN:
114498 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
114499 + break;
114500 + case GIMPLE_CALL:
114501 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
114502 + break;
114503 + case GIMPLE_ASSIGN:
114504 + switch (cur_node->num) {
114505 + case 1:
114506 + set_rhs = &gimple_assign_set_rhs1;
114507 + break;
114508 + case 2:
114509 + set_rhs = &gimple_assign_set_rhs2;
114510 + break;
114511 +#if BUILDING_GCC_VERSION >= 4006
114512 + case 3:
114513 + set_rhs = &gimple_assign_set_rhs3;
114514 + break;
114515 +#endif
114516 + default:
114517 + gcc_unreachable();
114518 + }
114519 +
114520 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
114521 + break;
114522 + default:
114523 + debug_gimple_stmt(stmt);
114524 + gcc_unreachable();
114525 + }
114526 +
114527 + update_stmt(stmt);
114528 +}
114529 +
114530 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
114531 +{
114532 + const struct size_overflow_hash *hash;
114533 + unsigned int new_argnum;
114534 + tree arg;
114535 + const_tree origarg;
114536 +
114537 + if (argnum == 0)
114538 + return argnum;
114539 +
114540 + hash = get_function_hash(fndecl);
114541 + if (hash && hash->param & (1U << argnum))
114542 + return argnum;
114543 +
114544 + if (DECL_EXTERNAL(fndecl))
114545 + return argnum;
114546 +
114547 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
114548 + argnum--;
114549 + while (origarg && argnum) {
114550 + origarg = TREE_CHAIN(origarg);
114551 + argnum--;
114552 + }
114553 + gcc_assert(argnum == 0);
114554 + gcc_assert(origarg != NULL_TREE);
114555 +
114556 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
114557 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
114558 + return new_argnum;
114559 +
114560 + return CANNOT_FIND_ARG;
114561 +}
114562 +
114563 +// Don't want to duplicate entries in next_cgraph_node
114564 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
114565 +{
114566 + const_tree new_callee_fndecl;
114567 + struct next_cgraph_node *cur_node;
114568 +
114569 + if (fndecl == RET_CHECK)
114570 + new_callee_fndecl = NODE_DECL(node);
114571 + else
114572 + new_callee_fndecl = fndecl;
114573 +
114574 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
114575 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
114576 + continue;
114577 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
114578 + continue;
114579 + if (num == cur_node->num)
114580 + return true;
114581 + }
114582 + return false;
114583 +}
114584 +
114585 +/* Add a next_cgraph_node into the list for handle_function().
114586 + * handle_function() iterates over all the next cgraph nodes and
114587 + * starts the overflow check insertion process.
114588 + */
114589 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
114590 +{
114591 + struct next_cgraph_node *new_node;
114592 +
114593 + if (is_in_next_cgraph_node(head, node, fndecl, num))
114594 + return head;
114595 +
114596 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
114597 + new_node->current_function = node;
114598 + new_node->next = NULL;
114599 + new_node->num = num;
114600 + if (fndecl == RET_CHECK)
114601 + new_node->callee_fndecl = NODE_DECL(node);
114602 + else
114603 + new_node->callee_fndecl = fndecl;
114604 +
114605 + if (!head)
114606 + return new_node;
114607 +
114608 + new_node->next = head;
114609 + return new_node;
114610 +}
114611 +
114612 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
114613 +{
114614 + struct cgraph_edge *e;
114615 +
114616 + if (num == 0)
114617 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
114618 +
114619 + for (e = node->callers; e; e = e->next_caller) {
114620 + tree fndecl = gimple_call_fndecl(e->call_stmt);
114621 +
114622 + gcc_assert(fndecl != NULL_TREE);
114623 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
114624 + }
114625 +
114626 + return head;
114627 +}
114628 +
114629 +static bool is_a_return_check(const_tree node)
114630 +{
114631 + if (TREE_CODE(node) == FUNCTION_DECL)
114632 + return true;
114633 +
114634 + gcc_assert(TREE_CODE(node) == PARM_DECL);
114635 + return false;
114636 +}
114637 +
114638 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
114639 +{
114640 + const struct size_overflow_hash *hash;
114641 +
114642 + hash = get_function_hash(fndecl);
114643 + if (hash && (hash->param & (1U << num)))
114644 + return true;
114645 + return false;
114646 +}
114647 +
114648 +struct missing_functions {
114649 + struct missing_functions *next;
114650 + const_tree node;
114651 + tree fndecl;
114652 +};
114653 +
114654 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
114655 +{
114656 + struct missing_functions *new_function;
114657 +
114658 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
114659 + new_function->node = node;
114660 + new_function->next = NULL;
114661 +
114662 + if (TREE_CODE(node) == FUNCTION_DECL)
114663 + new_function->fndecl = node;
114664 + else
114665 + new_function->fndecl = current_function_decl;
114666 + gcc_assert(new_function->fndecl);
114667 +
114668 + if (!missing_fn_head)
114669 + return new_function;
114670 +
114671 + new_function->next = missing_fn_head;
114672 + return new_function;
114673 +}
114674 +
114675 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
114676 + * If the function is missing everywhere then print the missing message into stderr.
114677 + */
114678 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
114679 +{
114680 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
114681 +#if BUILDING_GCC_VERSION >= 4008
114682 + case BUILT_IN_BSWAP16:
114683 +#endif
114684 + case BUILT_IN_BSWAP32:
114685 + case BUILT_IN_BSWAP64:
114686 + case BUILT_IN_EXPECT:
114687 + case BUILT_IN_MEMCMP:
114688 + return false;
114689 + default:
114690 + break;
114691 + }
114692 +
114693 + // skip test.c
114694 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
114695 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
114696 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
114697 + }
114698 +
114699 + if (is_in_hash_table(orig_fndecl, num))
114700 + return false;
114701 +
114702 + print_missing_msg(orig_fndecl, num);
114703 + return true;
114704 +}
114705 +
114706 +// Get the argnum of a function decl, if node is a return then the argnum is 0
114707 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
114708 +{
114709 + if (is_a_return_check(node))
114710 + return 0;
114711 + else
114712 + return find_arg_number_tree(node, orig_fndecl);
114713 +}
114714 +
114715 +/* If the function is missing from the hash table and it is a static function
114716 + * then create a next_cgraph_node from it for handle_function()
114717 + */
114718 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
114719 +{
114720 + unsigned int num;
114721 + const_tree orig_fndecl;
114722 + struct cgraph_node *next_node = NULL;
114723 +
114724 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
114725 +
114726 + num = get_function_num(missing_fn_head->node, orig_fndecl);
114727 + if (num == CANNOT_FIND_ARG)
114728 + return cnodes;
114729 +
114730 + if (!is_missing_function(orig_fndecl, num))
114731 + return cnodes;
114732 +
114733 + next_node = cgraph_get_node(missing_fn_head->fndecl);
114734 + if (next_node && next_node->local.local)
114735 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
114736 + return cnodes;
114737 +}
114738 +
114739 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
114740 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
114741 + */
114742 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
114743 +{
114744 + unsigned int i;
114745 + tree node;
114746 + struct missing_functions *cur, *missing_fn_head = NULL;
114747 +
114748 +#if BUILDING_GCC_VERSION <= 4007
114749 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
114750 +#else
114751 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
114752 +#endif
114753 + switch (TREE_CODE(node)) {
114754 + case PARM_DECL:
114755 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
114756 + break;
114757 + case FUNCTION_DECL:
114758 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
114759 + break;
114760 + default:
114761 + break;
114762 + }
114763 + }
114764 +
114765 + while (missing_fn_head) {
114766 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
114767 +
114768 + cur = missing_fn_head->next;
114769 + free(missing_fn_head);
114770 + missing_fn_head = cur;
114771 + }
114772 +
114773 + return cnodes;
114774 +}
114775 +
114776 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
114777 +{
114778 + gimple phi = get_def_stmt(result);
114779 + unsigned int i, n = gimple_phi_num_args(phi);
114780 +
114781 + pointer_set_insert(visited, phi);
114782 + for (i = 0; i < n; i++) {
114783 + const_tree arg = gimple_phi_arg_def(phi, i);
114784 +
114785 + set_conditions(visited, interesting_conditions, arg);
114786 + }
114787 +}
114788 +
114789 +enum conditions {
114790 + FROM_CONST, NOT_UNARY, CAST
114791 +};
114792 +
114793 +// Search for constants, cast assignments and binary/ternary assignments
114794 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
114795 +{
114796 + gimple def_stmt = get_def_stmt(lhs);
114797 +
114798 + if (is_gimple_constant(lhs)) {
114799 + interesting_conditions[FROM_CONST] = true;
114800 + return;
114801 + }
114802 +
114803 + if (!def_stmt)
114804 + return;
114805 +
114806 + if (pointer_set_contains(visited, def_stmt))
114807 + return;
114808 +
114809 + switch (gimple_code(def_stmt)) {
114810 + case GIMPLE_NOP:
114811 + case GIMPLE_CALL:
114812 + case GIMPLE_ASM:
114813 + return;
114814 + case GIMPLE_PHI:
114815 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
114816 + case GIMPLE_ASSIGN:
114817 + if (gimple_num_ops(def_stmt) == 2) {
114818 + const_tree rhs = gimple_assign_rhs1(def_stmt);
114819 +
114820 + if (gimple_assign_cast_p(def_stmt))
114821 + interesting_conditions[CAST] = true;
114822 +
114823 + return set_conditions(visited, interesting_conditions, rhs);
114824 + } else {
114825 + interesting_conditions[NOT_UNARY] = true;
114826 + return;
114827 + }
114828 + default:
114829 + debug_gimple_stmt(def_stmt);
114830 + gcc_unreachable();
114831 + }
114832 +}
114833 +
114834 +// determine whether duplication will be necessary or not.
114835 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
114836 +{
114837 + struct pointer_set_t *visited;
114838 +
114839 + if (gimple_assign_cast_p(cur_node->first_stmt))
114840 + interesting_conditions[CAST] = true;
114841 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
114842 + interesting_conditions[NOT_UNARY] = true;
114843 +
114844 + visited = pointer_set_create();
114845 + set_conditions(visited, interesting_conditions, cur_node->node);
114846 + pointer_set_destroy(visited);
114847 +}
114848 +
114849 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
114850 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
114851 +{
114852 + gimple assign;
114853 + gimple_stmt_iterator gsi;
114854 +
114855 + // already removed
114856 + if (gimple_bb(asm_stmt) == NULL)
114857 + return;
114858 + gsi = gsi_for_stmt(asm_stmt);
114859 +
114860 + assign = gimple_build_assign(lhs, rhs);
114861 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
114862 + SSA_NAME_DEF_STMT(lhs) = assign;
114863 +
114864 + gsi_remove(&gsi, true);
114865 +}
114866 +
114867 +// Get the field decl of a component ref for intentional_overflow checking
114868 +static const_tree search_field_decl(const_tree comp_ref)
114869 +{
114870 + const_tree field = NULL_TREE;
114871 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
114872 +
114873 + for (i = 0; i < len; i++) {
114874 + field = TREE_OPERAND(comp_ref, i);
114875 + if (TREE_CODE(field) == FIELD_DECL)
114876 + break;
114877 + }
114878 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
114879 + return field;
114880 +}
114881 +
114882 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
114883 + * stmt is a return otherwise it is the callee function.
114884 + */
114885 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
114886 +{
114887 + const_tree fndecl;
114888 +
114889 + if (argnum == 0)
114890 + fndecl = current_function_decl;
114891 + else
114892 + fndecl = gimple_call_fndecl(stmt);
114893 +
114894 + if (fndecl == NULL_TREE)
114895 + return NULL_TREE;
114896 +
114897 + return DECL_ORIGIN(fndecl);
114898 +}
114899 +
114900 +/* Get the param of the intentional_overflow attribute.
114901 + * * 0: MARK_NOT_INTENTIONAL
114902 + * * 1..MAX_PARAM: MARK_YES
114903 + * * -1: MARK_TURN_OFF
114904 + */
114905 +static tree get_attribute_param(const_tree decl)
114906 +{
114907 + const_tree attr;
114908 +
114909 + if (decl == NULL_TREE)
114910 + return NULL_TREE;
114911 +
114912 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
114913 + if (!attr || !TREE_VALUE(attr))
114914 + return NULL_TREE;
114915 +
114916 + return TREE_VALUE(attr);
114917 +}
114918 +
114919 +// MARK_TURN_OFF
114920 +static bool is_turn_off_intentional_attr(const_tree decl)
114921 +{
114922 + const_tree param_head;
114923 +
114924 + param_head = get_attribute_param(decl);
114925 + if (param_head == NULL_TREE)
114926 + return false;
114927 +
114928 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
114929 + return true;
114930 + return false;
114931 +}
114932 +
114933 +// MARK_NOT_INTENTIONAL
114934 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
114935 +{
114936 + const_tree param_head;
114937 +
114938 + if (argnum == 0)
114939 + return false;
114940 +
114941 + param_head = get_attribute_param(decl);
114942 + if (param_head == NULL_TREE)
114943 + return false;
114944 +
114945 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
114946 + return true;
114947 + return false;
114948 +}
114949 +
114950 +// MARK_YES
114951 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
114952 +{
114953 + tree param, param_head;
114954 +
114955 + if (argnum == 0)
114956 + return false;
114957 +
114958 + param_head = get_attribute_param(decl);
114959 + for (param = param_head; param; param = TREE_CHAIN(param))
114960 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
114961 + return true;
114962 + return false;
114963 +}
114964 +
114965 +static const char *get_asm_string(const_gimple stmt)
114966 +{
114967 + if (!stmt)
114968 + return NULL;
114969 + if (gimple_code(stmt) != GIMPLE_ASM)
114970 + return NULL;
114971 +
114972 + return gimple_asm_string(stmt);
114973 +}
114974 +
114975 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
114976 +{
114977 + const char *str;
114978 +
114979 + str = get_asm_string(stmt);
114980 + if (!str)
114981 + return false;
114982 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
114983 +}
114984 +
114985 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
114986 +{
114987 + const char *str;
114988 +
114989 + str = get_asm_string(stmt);
114990 + if (!str)
114991 + return false;
114992 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
114993 +}
114994 +
114995 +static bool is_size_overflow_asm(const_gimple stmt)
114996 +{
114997 + const char *str;
114998 +
114999 + str = get_asm_string(stmt);
115000 + if (!str)
115001 + return false;
115002 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
115003 +}
115004 +
115005 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
115006 +{
115007 + location_t loc;
115008 +
115009 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
115010 + return;
115011 +
115012 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
115013 + return;
115014 +
115015 + loc = DECL_SOURCE_LOCATION(decl);
115016 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
115017 +}
115018 +
115019 +/* Get the type of the intentional_overflow attribute of a node
115020 + * * MARK_TURN_OFF
115021 + * * MARK_YES
115022 + * * MARK_NO
115023 + * * MARK_NOT_INTENTIONAL
115024 + */
115025 +static enum mark get_intentional_attr_type(const_tree node)
115026 +{
115027 + const_tree cur_decl;
115028 +
115029 + if (node == NULL_TREE)
115030 + return MARK_NO;
115031 +
115032 + switch (TREE_CODE(node)) {
115033 + case COMPONENT_REF:
115034 + cur_decl = search_field_decl(node);
115035 + if (is_turn_off_intentional_attr(cur_decl))
115036 + return MARK_TURN_OFF;
115037 + if (is_end_intentional_intentional_attr(cur_decl, 1))
115038 + return MARK_YES;
115039 + break;
115040 + case PARM_DECL: {
115041 + unsigned int argnum;
115042 +
115043 + cur_decl = DECL_ORIGIN(current_function_decl);
115044 + argnum = find_arg_number_tree(node, cur_decl);
115045 + if (argnum == CANNOT_FIND_ARG)
115046 + return MARK_NO;
115047 + if (is_yes_intentional_attr(cur_decl, argnum))
115048 + return MARK_YES;
115049 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
115050 + return MARK_NOT_INTENTIONAL;
115051 + break;
115052 + }
115053 + case FUNCTION_DECL:
115054 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
115055 + return MARK_TURN_OFF;
115056 + break;
115057 + default:
115058 + break;
115059 + }
115060 + return MARK_NO;
115061 +}
115062 +
115063 +// Search for the intentional_overflow attribute on the last nodes
115064 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
115065 +{
115066 + unsigned int i;
115067 + tree last_node;
115068 + enum mark mark = MARK_NO;
115069 +
115070 +#if BUILDING_GCC_VERSION <= 4007
115071 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
115072 +#else
115073 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
115074 +#endif
115075 + mark = get_intentional_attr_type(last_node);
115076 + if (mark != MARK_NO)
115077 + break;
115078 + }
115079 + return mark;
115080 +}
115081 +
115082 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
115083 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
115084 + */
115085 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
115086 +{
115087 + if (!cur_node->intentional_mark_from_gimple)
115088 + return false;
115089 +
115090 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
115091 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
115092 + else
115093 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
115094 +
115095 + // skip param decls
115096 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
115097 + return true;
115098 + return true;
115099 +}
115100 +
115101 +/* Search intentional_overflow attribute on caller and on callee too.
115102 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
115103 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
115104 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
115105 +*/
115106 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
115107 +{
115108 + const_tree fndecl;
115109 +
115110 + if (is_intentional_attribute_from_gimple(cur_node))
115111 + return;
115112 +
115113 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
115114 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
115115 + return;
115116 + }
115117 +
115118 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
115119 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
115120 + return;
115121 + }
115122 +
115123 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
115124 + return;
115125 +
115126 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
115127 + if (is_turn_off_intentional_attr(fndecl)) {
115128 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
115129 + return;
115130 + }
115131 +
115132 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
115133 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
115134 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
115135 + cur_node->intentional_attr_decl = MARK_YES;
115136 +
115137 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
115138 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
115139 +}
115140 +
115141 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
115142 +static bool skip_asm(const_tree arg)
115143 +{
115144 + gimple def_stmt = get_def_stmt(arg);
115145 +
115146 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115147 + return false;
115148 +
115149 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
115150 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
115151 +}
115152 +
115153 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
115154 +{
115155 + gimple phi = get_def_stmt(result);
115156 + unsigned int i, n = gimple_phi_num_args(phi);
115157 +
115158 + pointer_set_insert(visited, phi);
115159 + for (i = 0; i < n; i++) {
115160 + tree arg = gimple_phi_arg_def(phi, i);
115161 +
115162 + walk_use_def(visited, cur_node, arg);
115163 + }
115164 +}
115165 +
115166 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115167 +{
115168 + gimple def_stmt = get_def_stmt(lhs);
115169 + tree rhs1, rhs2;
115170 +
115171 + rhs1 = gimple_assign_rhs1(def_stmt);
115172 + rhs2 = gimple_assign_rhs2(def_stmt);
115173 +
115174 + walk_use_def(visited, cur_node, rhs1);
115175 + walk_use_def(visited, cur_node, rhs2);
115176 +}
115177 +
115178 +static void insert_last_node(struct interesting_node *cur_node, tree node)
115179 +{
115180 + unsigned int i;
115181 + tree element;
115182 + enum tree_code code;
115183 +
115184 + gcc_assert(node != NULL_TREE);
115185 +
115186 + if (is_gimple_constant(node))
115187 + return;
115188 +
115189 + code = TREE_CODE(node);
115190 + if (code == VAR_DECL) {
115191 + node = DECL_ORIGIN(node);
115192 + code = TREE_CODE(node);
115193 + }
115194 +
115195 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
115196 + return;
115197 +
115198 +#if BUILDING_GCC_VERSION <= 4007
115199 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
115200 +#else
115201 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
115202 +#endif
115203 + if (operand_equal_p(node, element, 0))
115204 + return;
115205 + }
115206 +
115207 +#if BUILDING_GCC_VERSION <= 4007
115208 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
115209 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
115210 +#else
115211 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
115212 + vec_safe_push(cur_node->last_nodes, node);
115213 +#endif
115214 +}
115215 +
115216 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
115217 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
115218 +{
115219 + if (!is_size_overflow_asm(stmt))
115220 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115221 +}
115222 +
115223 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
115224 + * and component refs (for checking the intentional_overflow attribute).
115225 + */
115226 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115227 +{
115228 + const_gimple def_stmt;
115229 +
115230 + if (TREE_CODE(lhs) != SSA_NAME) {
115231 + insert_last_node(cur_node, lhs);
115232 + return;
115233 + }
115234 +
115235 + def_stmt = get_def_stmt(lhs);
115236 + if (!def_stmt)
115237 + return;
115238 +
115239 + if (pointer_set_insert(visited, def_stmt))
115240 + return;
115241 +
115242 + switch (gimple_code(def_stmt)) {
115243 + case GIMPLE_NOP:
115244 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115245 + case GIMPLE_ASM:
115246 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
115247 + case GIMPLE_CALL: {
115248 + tree fndecl = gimple_call_fndecl(def_stmt);
115249 +
115250 + if (fndecl == NULL_TREE)
115251 + return;
115252 + insert_last_node(cur_node, fndecl);
115253 + return;
115254 + }
115255 + case GIMPLE_PHI:
115256 + return walk_use_def_phi(visited, cur_node, lhs);
115257 + case GIMPLE_ASSIGN:
115258 + switch (gimple_num_ops(def_stmt)) {
115259 + case 2:
115260 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
115261 + case 3:
115262 + return walk_use_def_binary(visited, cur_node, lhs);
115263 + }
115264 + default:
115265 + debug_gimple_stmt((gimple)def_stmt);
115266 + error("%s: unknown gimple code", __func__);
115267 + gcc_unreachable();
115268 + }
115269 +}
115270 +
115271 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
115272 +static void set_last_nodes(struct interesting_node *cur_node)
115273 +{
115274 + struct pointer_set_t *visited;
115275 +
115276 + visited = pointer_set_create();
115277 + walk_use_def(visited, cur_node, cur_node->node);
115278 + pointer_set_destroy(visited);
115279 +}
115280 +
115281 +enum precond {
115282 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
115283 +};
115284 +
115285 +/* 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.
115286 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
115287 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
115288 + * 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.
115289 + */
115290 +static enum precond check_preconditions(struct interesting_node *cur_node)
115291 +{
115292 + bool interesting_conditions[3] = {false, false, false};
115293 +
115294 + set_last_nodes(cur_node);
115295 +
115296 + check_intentional_attribute_ipa(cur_node);
115297 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
115298 + return NO_ATTRIBUTE_SEARCH;
115299 +
115300 + search_interesting_conditions(cur_node, interesting_conditions);
115301 +
115302 + // error code
115303 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
115304 + return NO_ATTRIBUTE_SEARCH;
115305 +
115306 + // unnecessary overflow check
115307 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
115308 + return NO_CHECK_INSERT;
115309 +
115310 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
115311 + return NO_CHECK_INSERT;
115312 +
115313 + return NONE;
115314 +}
115315 +
115316 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
115317 + * 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
115318 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
115319 + */
115320 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
115321 +{
115322 + enum precond ret;
115323 + struct pointer_set_t *visited;
115324 + tree new_node, orig_node = cur_node->node;
115325 +
115326 + ret = check_preconditions(cur_node);
115327 + if (ret == NO_ATTRIBUTE_SEARCH)
115328 + return cnodes;
115329 +
115330 + cnodes = search_overflow_attribute(cnodes, cur_node);
115331 +
115332 + if (ret == NO_CHECK_INSERT)
115333 + return cnodes;
115334 +
115335 + visited = pointer_set_create();
115336 + new_node = expand(visited, caller_node, orig_node);
115337 + pointer_set_destroy(visited);
115338 +
115339 + if (new_node == NULL_TREE)
115340 + return cnodes;
115341 +
115342 + change_orig_node(cur_node, new_node);
115343 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
115344 +
115345 + return cnodes;
115346 +}
115347 +
115348 +// Check visited interesting nodes.
115349 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
115350 +{
115351 + struct interesting_node *cur;
115352 +
115353 + for (cur = head; cur; cur = cur->next) {
115354 + if (!operand_equal_p(node, cur->node, 0))
115355 + continue;
115356 + if (num != cur->num)
115357 + continue;
115358 + if (first_stmt == cur->first_stmt)
115359 + return true;
115360 + }
115361 + return false;
115362 +}
115363 +
115364 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
115365 + 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
115366 + 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
115367 + the intentional_overflow attribute check. They are collected by set_last_nodes().
115368 + num: arg count of a call stmt or 0 when it is a ret
115369 + node: the recursion starts from here, it is a call arg or a return value
115370 + 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.
115371 + intentional_attr_decl: intentional_overflow attribute of the callee function
115372 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
115373 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
115374 + */
115375 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
115376 +{
115377 + struct interesting_node *new_node;
115378 + tree fndecl;
115379 + enum gimple_code code;
115380 +
115381 + gcc_assert(node != NULL_TREE);
115382 + code = gimple_code(first_stmt);
115383 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
115384 +
115385 + if (num == CANNOT_FIND_ARG)
115386 + return head;
115387 +
115388 + if (skip_types(node))
115389 + return head;
115390 +
115391 + if (skip_asm(node))
115392 + return head;
115393 +
115394 + if (is_gimple_call(first_stmt))
115395 + fndecl = gimple_call_fndecl(first_stmt);
115396 + else
115397 + fndecl = current_function_decl;
115398 +
115399 + if (fndecl == NULL_TREE)
115400 + return head;
115401 +
115402 + if (is_in_interesting_node(head, first_stmt, node, num))
115403 + return head;
115404 +
115405 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
115406 +
115407 + new_node->next = NULL;
115408 + new_node->first_stmt = first_stmt;
115409 +#if BUILDING_GCC_VERSION <= 4007
115410 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
115411 +#else
115412 + vec_alloc(new_node->last_nodes, VEC_LEN);
115413 +#endif
115414 + new_node->num = num;
115415 + new_node->node = node;
115416 + new_node->fndecl = fndecl;
115417 + new_node->intentional_attr_decl = MARK_NO;
115418 + new_node->intentional_attr_cur_fndecl = MARK_NO;
115419 + new_node->intentional_mark_from_gimple = asm_stmt;
115420 +
115421 + if (!head)
115422 + return new_node;
115423 +
115424 + new_node->next = head;
115425 + return new_node;
115426 +}
115427 +
115428 +/* 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).
115429 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
115430 + */
115431 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115432 +{
115433 + struct next_cgraph_node *cur_node;
115434 + tree ret = gimple_return_retval(stmt);
115435 +
115436 + if (ret == NULL_TREE)
115437 + return head;
115438 +
115439 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115440 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
115441 + continue;
115442 + if (cur_node->num == 0)
115443 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
115444 + }
115445 +
115446 + return head;
115447 +}
115448 +
115449 +/* 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).
115450 + * If the call stmt is in the next cgraph node list then it's an interesting call.
115451 + */
115452 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115453 +{
115454 + unsigned int argnum;
115455 + tree arg;
115456 + const_tree fndecl;
115457 + struct next_cgraph_node *cur_node;
115458 +
115459 + fndecl = gimple_call_fndecl(stmt);
115460 + if (fndecl == NULL_TREE)
115461 + return head;
115462 +
115463 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115464 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
115465 + continue;
115466 + argnum = get_correct_arg_count(cur_node->num, fndecl);
115467 + gcc_assert(argnum != CANNOT_FIND_ARG);
115468 + if (argnum == 0)
115469 + continue;
115470 +
115471 + arg = gimple_call_arg(stmt, argnum - 1);
115472 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
115473 + }
115474 +
115475 + return head;
115476 +}
115477 +
115478 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
115479 +{
115480 + if (!operand_equal_p(orig_node, node, 0))
115481 + return WRONG_NODE;
115482 + if (skip_types(node))
115483 + return WRONG_NODE;
115484 + return ret_count;
115485 +}
115486 +
115487 +// Get the index of the rhs node in an assignment
115488 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
115489 +{
115490 + const_tree rhs1, rhs2;
115491 + unsigned int ret;
115492 +
115493 + gcc_assert(stmt);
115494 + gcc_assert(is_gimple_assign(stmt));
115495 +
115496 + rhs1 = gimple_assign_rhs1(stmt);
115497 + gcc_assert(rhs1 != NULL_TREE);
115498 +
115499 + switch (gimple_num_ops(stmt)) {
115500 + case 2:
115501 + return check_ops(node, rhs1, 1);
115502 + case 3:
115503 + ret = check_ops(node, rhs1, 1);
115504 + if (ret != WRONG_NODE)
115505 + return ret;
115506 +
115507 + rhs2 = gimple_assign_rhs2(stmt);
115508 + gcc_assert(rhs2 != NULL_TREE);
115509 + return check_ops(node, rhs2, 2);
115510 + default:
115511 + gcc_unreachable();
115512 + }
115513 +}
115514 +
115515 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
115516 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
115517 +{
115518 + unsigned int i;
115519 +
115520 + if (gimple_call_fndecl(stmt) == NULL_TREE)
115521 + return CANNOT_FIND_ARG;
115522 +
115523 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
115524 + tree node;
115525 +
115526 + node = gimple_call_arg(stmt, i);
115527 + if (!operand_equal_p(arg, node, 0))
115528 + continue;
115529 + if (!skip_types(node))
115530 + return i + 1;
115531 + }
115532 +
115533 + return CANNOT_FIND_ARG;
115534 +}
115535 +
115536 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
115537 + * any of return, call or assignment stmts (because of inlining).
115538 + */
115539 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
115540 +{
115541 + use_operand_p use_p;
115542 + imm_use_iterator imm_iter;
115543 + unsigned int argnum;
115544 +
115545 + gcc_assert(TREE_CODE(node) == SSA_NAME);
115546 +
115547 + if (pointer_set_insert(visited, node))
115548 + return head;
115549 +
115550 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115551 + gimple stmt = USE_STMT(use_p);
115552 +
115553 + if (stmt == NULL)
115554 + return head;
115555 + if (is_gimple_debug(stmt))
115556 + continue;
115557 +
115558 + switch (gimple_code(stmt)) {
115559 + case GIMPLE_CALL:
115560 + argnum = find_arg_number_gimple(node, stmt);
115561 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115562 + break;
115563 + case GIMPLE_RETURN:
115564 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
115565 + break;
115566 + case GIMPLE_ASSIGN:
115567 + argnum = get_assign_ops_count(stmt, node);
115568 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115569 + break;
115570 + case GIMPLE_PHI: {
115571 + tree result = gimple_phi_result(stmt);
115572 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
115573 + break;
115574 + }
115575 + case GIMPLE_ASM:
115576 + if (gimple_asm_noutputs(stmt) != 0)
115577 + break;
115578 + if (!is_size_overflow_asm(stmt))
115579 + break;
115580 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
115581 + break;
115582 + case GIMPLE_COND:
115583 + case GIMPLE_SWITCH:
115584 + break;
115585 + default:
115586 + debug_gimple_stmt(stmt);
115587 + gcc_unreachable();
115588 + break;
115589 + }
115590 + }
115591 + return head;
115592 +}
115593 +
115594 +static void remove_size_overflow_asm(gimple stmt)
115595 +{
115596 + gimple_stmt_iterator gsi;
115597 + tree input, output;
115598 +
115599 + if (!is_size_overflow_asm(stmt))
115600 + return;
115601 +
115602 + if (gimple_asm_noutputs(stmt) == 0) {
115603 + gsi = gsi_for_stmt(stmt);
115604 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
115605 + gsi_remove(&gsi, true);
115606 + return;
115607 + }
115608 +
115609 + input = gimple_asm_input_op(stmt, 0);
115610 + output = gimple_asm_output_op(stmt, 0);
115611 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
115612 +}
115613 +
115614 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
115615 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
115616 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
115617 + */
115618 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
115619 +{
115620 + const_tree output;
115621 + struct pointer_set_t *visited;
115622 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
115623 +
115624 + if (!is_size_overflow_asm(stmt))
115625 + return head;
115626 +
115627 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
115628 + intentional_asm = stmt;
115629 +
115630 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
115631 +
115632 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
115633 + return head;
115634 +
115635 + if (gimple_asm_noutputs(stmt) == 0) {
115636 + const_tree input;
115637 +
115638 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
115639 + return head;
115640 +
115641 + input = gimple_asm_input_op(stmt, 0);
115642 + remove_size_overflow_asm(stmt);
115643 + if (is_gimple_constant(TREE_VALUE(input)))
115644 + return head;
115645 + visited = pointer_set_create();
115646 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
115647 + pointer_set_destroy(visited);
115648 + return head;
115649 + }
115650 +
115651 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
115652 + remove_size_overflow_asm(stmt);
115653 +
115654 + visited = pointer_set_create();
115655 + output = gimple_asm_output_op(stmt, 0);
115656 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
115657 + pointer_set_destroy(visited);
115658 + return head;
115659 +}
115660 +
115661 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
115662 + * or a call stmt or a return stmt and store them in the interesting_node list
115663 + */
115664 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
115665 +{
115666 + basic_block bb;
115667 + struct interesting_node *head = NULL;
115668 +
115669 + FOR_ALL_BB_FN(bb, cfun) {
115670 + gimple_stmt_iterator gsi;
115671 +
115672 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
115673 + enum gimple_code code;
115674 + gimple stmt = gsi_stmt(gsi);
115675 +
115676 + code = gimple_code(stmt);
115677 +
115678 + if (code == GIMPLE_ASM)
115679 + head = handle_stmt_by_size_overflow_asm(stmt, head);
115680 +
115681 + if (!next_node)
115682 + continue;
115683 + if (code == GIMPLE_CALL)
115684 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
115685 + if (code == GIMPLE_RETURN)
115686 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
115687 + }
115688 + }
115689 + return head;
115690 +}
115691 +
115692 +static void set_current_function_decl(tree fndecl)
115693 +{
115694 + gcc_assert(fndecl != NULL_TREE);
115695 +
115696 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
115697 + calculate_dominance_info(CDI_DOMINATORS);
115698 + current_function_decl = fndecl;
115699 +}
115700 +
115701 +static void unset_current_function_decl(void)
115702 +{
115703 + free_dominance_info(CDI_DOMINATORS);
115704 + pop_cfun();
115705 + current_function_decl = NULL_TREE;
115706 +}
115707 +
115708 +static void free_interesting_node(struct interesting_node *head)
115709 +{
115710 + struct interesting_node *cur;
115711 +
115712 + while (head) {
115713 + cur = head->next;
115714 +#if BUILDING_GCC_VERSION <= 4007
115715 + VEC_free(tree, gc, head->last_nodes);
115716 +#else
115717 + vec_free(head->last_nodes);
115718 +#endif
115719 + free(head);
115720 + head = cur;
115721 + }
115722 +}
115723 +
115724 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
115725 +{
115726 + struct visited *new_visited;
115727 +
115728 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
115729 + new_visited->fndecl = cur_node->fndecl;
115730 + new_visited->num = cur_node->num;
115731 + new_visited->rhs = cur_node->node;
115732 + new_visited->next = NULL;
115733 +
115734 + if (!head)
115735 + return new_visited;
115736 +
115737 + new_visited->next = head;
115738 + return new_visited;
115739 +}
115740 +
115741 +/* 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
115742 + * it is a visited function.
115743 + */
115744 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
115745 +{
115746 + struct visited *cur;
115747 +
115748 + if (!head)
115749 + return false;
115750 +
115751 + for (cur = head; cur; cur = cur->next) {
115752 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
115753 + continue;
115754 + if (cur_node->num != cur->num)
115755 + continue;
115756 + if (cur_node->node == cur->rhs)
115757 + return true;
115758 + }
115759 + return false;
115760 +}
115761 +
115762 +static void free_next_cgraph_node(struct next_cgraph_node *head)
115763 +{
115764 + struct next_cgraph_node *cur;
115765 +
115766 + while (head) {
115767 + cur = head->next;
115768 + free(head);
115769 + head = cur;
115770 + }
115771 +}
115772 +
115773 +static void remove_all_size_overflow_asm(void)
115774 +{
115775 + basic_block bb;
115776 +
115777 + FOR_ALL_BB_FN(bb, cfun) {
115778 + gimple_stmt_iterator si;
115779 +
115780 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115781 + remove_size_overflow_asm(gsi_stmt(si));
115782 + }
115783 +}
115784 +
115785 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
115786 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
115787 + * the newly collected interesting functions (they are interesting if there is control flow between
115788 + * the interesting stmts and them).
115789 + */
115790 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
115791 +{
115792 + struct interesting_node *head, *cur_node;
115793 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
115794 +
115795 + set_current_function_decl(NODE_DECL(node));
115796 + call_count = 0;
115797 +
115798 + head = collect_interesting_stmts(next_node);
115799 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115800 + if (is_visited_function(visited, cur_node))
115801 + continue;
115802 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
115803 + visited = insert_visited_function(visited, cur_node);
115804 + }
115805 +
115806 + free_interesting_node(head);
115807 + remove_all_size_overflow_asm();
115808 + unset_current_function_decl();
115809 +
115810 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
115811 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
115812 +
115813 + free_next_cgraph_node(cnodes_head);
115814 + return visited;
115815 +}
115816 +
115817 +static void free_visited(struct visited *head)
115818 +{
115819 + struct visited *cur;
115820 +
115821 + while (head) {
115822 + cur = head->next;
115823 + free(head);
115824 + head = cur;
115825 + }
115826 +}
115827 +
115828 +// erase the local flag
115829 +static void set_plf_false(void)
115830 +{
115831 + basic_block bb;
115832 +
115833 + FOR_ALL_BB_FN(bb, cfun) {
115834 + gimple_stmt_iterator si;
115835 +
115836 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115837 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
115838 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
115839 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
115840 + }
115841 +}
115842 +
115843 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
115844 +static unsigned int search_function(void)
115845 +{
115846 + struct cgraph_node *node;
115847 + struct visited *visited = NULL;
115848 +
115849 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115850 + set_current_function_decl(NODE_DECL(node));
115851 + set_plf_false();
115852 + unset_current_function_decl();
115853 + }
115854 +
115855 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115856 + gcc_assert(cgraph_function_flags_ready);
115857 +#if BUILDING_GCC_VERSION <= 4007
115858 + gcc_assert(node->reachable);
115859 +#endif
115860 +
115861 + visited = handle_function(node, NULL, visited);
115862 + }
115863 +
115864 + free_visited(visited);
115865 + return 0;
115866 +}
115867 +
115868 +#if BUILDING_GCC_VERSION >= 4009
115869 +static const struct pass_data ipa_pass_data = {
115870 +#else
115871 +static struct ipa_opt_pass_d ipa_pass = {
115872 + .pass = {
115873 +#endif
115874 + .type = SIMPLE_IPA_PASS,
115875 + .name = "size_overflow",
115876 +#if BUILDING_GCC_VERSION >= 4008
115877 + .optinfo_flags = OPTGROUP_NONE,
115878 +#endif
115879 +#if BUILDING_GCC_VERSION >= 4009
115880 + .has_gate = false,
115881 + .has_execute = true,
115882 +#else
115883 + .gate = NULL,
115884 + .execute = search_function,
115885 + .sub = NULL,
115886 + .next = NULL,
115887 + .static_pass_number = 0,
115888 +#endif
115889 + .tv_id = TV_NONE,
115890 + .properties_required = 0,
115891 + .properties_provided = 0,
115892 + .properties_destroyed = 0,
115893 + .todo_flags_start = 0,
115894 + .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,
115895 +#if BUILDING_GCC_VERSION < 4009
115896 + },
115897 + .generate_summary = NULL,
115898 + .write_summary = NULL,
115899 + .read_summary = NULL,
115900 +#if BUILDING_GCC_VERSION >= 4006
115901 + .write_optimization_summary = NULL,
115902 + .read_optimization_summary = NULL,
115903 +#endif
115904 + .stmt_fixup = NULL,
115905 + .function_transform_todo_flags_start = 0,
115906 + .function_transform = NULL,
115907 + .variable_transform = NULL,
115908 +#endif
115909 +};
115910 +
115911 +#if BUILDING_GCC_VERSION >= 4009
115912 +namespace {
115913 +class ipa_pass : public ipa_opt_pass_d {
115914 +public:
115915 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
115916 + unsigned int execute() { return search_function(); }
115917 +};
115918 +}
115919 +#endif
115920 +
115921 +static struct opt_pass *make_ipa_pass(void)
115922 +{
115923 +#if BUILDING_GCC_VERSION >= 4009
115924 + return new ipa_pass();
115925 +#else
115926 + return &ipa_pass.pass;
115927 +#endif
115928 +}
115929 +
115930 +// data for the size_overflow asm stmt
115931 +struct asm_data {
115932 + gimple def_stmt;
115933 + tree input;
115934 + tree output;
115935 +};
115936 +
115937 +#if BUILDING_GCC_VERSION <= 4007
115938 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
115939 +#else
115940 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
115941 +#endif
115942 +{
115943 + tree list;
115944 +#if BUILDING_GCC_VERSION <= 4007
115945 + VEC(tree, gc) *vec_list = NULL;
115946 +#else
115947 + vec<tree, va_gc> *vec_list = NULL;
115948 +#endif
115949 +
115950 + list = build_tree_list(NULL_TREE, string);
115951 + list = chainon(NULL_TREE, build_tree_list(list, io));
115952 +#if BUILDING_GCC_VERSION <= 4007
115953 + VEC_safe_push(tree, gc, vec_list, list);
115954 +#else
115955 + vec_safe_push(vec_list, list);
115956 +#endif
115957 + return vec_list;
115958 +}
115959 +
115960 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
115961 +{
115962 + gimple asm_stmt;
115963 + gimple_stmt_iterator gsi;
115964 +#if BUILDING_GCC_VERSION <= 4007
115965 + VEC(tree, gc) *input, *output = NULL;
115966 +#else
115967 + vec<tree, va_gc> *input, *output = NULL;
115968 +#endif
115969 +
115970 + input = create_asm_io_list(str_input, asm_data->input);
115971 +
115972 + if (asm_data->output)
115973 + output = create_asm_io_list(str_output, asm_data->output);
115974 +
115975 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
115976 + gsi = gsi_for_stmt(asm_data->def_stmt);
115977 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
115978 +
115979 + if (asm_data->output)
115980 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
115981 +}
115982 +
115983 +static void replace_call_lhs(const struct asm_data *asm_data)
115984 +{
115985 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
115986 + update_stmt(asm_data->def_stmt);
115987 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
115988 +}
115989 +
115990 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
115991 +{
115992 + enum mark cur_fndecl_attr;
115993 + gimple phi = get_def_stmt(result);
115994 + unsigned int i, n = gimple_phi_num_args(phi);
115995 +
115996 + pointer_set_insert(visited, phi);
115997 + for (i = 0; i < n; i++) {
115998 + tree arg = gimple_phi_arg_def(phi, i);
115999 +
116000 + cur_fndecl_attr = search_intentional(visited, arg);
116001 + if (cur_fndecl_attr != MARK_NO)
116002 + return cur_fndecl_attr;
116003 + }
116004 + return MARK_NO;
116005 +}
116006 +
116007 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
116008 +{
116009 + enum mark cur_fndecl_attr;
116010 + const_tree rhs1, rhs2;
116011 + gimple def_stmt = get_def_stmt(lhs);
116012 +
116013 + rhs1 = gimple_assign_rhs1(def_stmt);
116014 + rhs2 = gimple_assign_rhs2(def_stmt);
116015 +
116016 + cur_fndecl_attr = search_intentional(visited, rhs1);
116017 + if (cur_fndecl_attr != MARK_NO)
116018 + return cur_fndecl_attr;
116019 + return search_intentional(visited, rhs2);
116020 +}
116021 +
116022 +// Look up the intentional_overflow attribute on the caller and the callee functions.
116023 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
116024 +{
116025 + const_gimple def_stmt;
116026 +
116027 + if (TREE_CODE(lhs) != SSA_NAME)
116028 + return get_intentional_attr_type(lhs);
116029 +
116030 + def_stmt = get_def_stmt(lhs);
116031 + if (!def_stmt)
116032 + return MARK_NO;
116033 +
116034 + if (pointer_set_contains(visited, def_stmt))
116035 + return MARK_NO;
116036 +
116037 + switch (gimple_code(def_stmt)) {
116038 + case GIMPLE_NOP:
116039 + return search_intentional(visited, SSA_NAME_VAR(lhs));
116040 + case GIMPLE_ASM:
116041 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
116042 + return MARK_TURN_OFF;
116043 + return MARK_NO;
116044 + case GIMPLE_CALL:
116045 + return MARK_NO;
116046 + case GIMPLE_PHI:
116047 + return search_intentional_phi(visited, lhs);
116048 + case GIMPLE_ASSIGN:
116049 + switch (gimple_num_ops(def_stmt)) {
116050 + case 2:
116051 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
116052 + case 3:
116053 + return search_intentional_binary(visited, lhs);
116054 + }
116055 + case GIMPLE_RETURN:
116056 + return MARK_NO;
116057 + default:
116058 + debug_gimple_stmt((gimple)def_stmt);
116059 + error("%s: unknown gimple code", __func__);
116060 + gcc_unreachable();
116061 + }
116062 +}
116063 +
116064 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
116065 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
116066 +{
116067 + const_tree fndecl;
116068 + struct pointer_set_t *visited;
116069 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
116070 +
116071 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
116072 + if (is_end_intentional_intentional_attr(fndecl, argnum))
116073 + decl_attr = MARK_NOT_INTENTIONAL;
116074 + else if (is_yes_intentional_attr(fndecl, argnum))
116075 + decl_attr = MARK_YES;
116076 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116077 + return MARK_TURN_OFF;
116078 + }
116079 +
116080 + visited = pointer_set_create();
116081 + cur_fndecl_attr = search_intentional(visited, arg);
116082 + pointer_set_destroy(visited);
116083 +
116084 + switch (cur_fndecl_attr) {
116085 + case MARK_NO:
116086 + case MARK_TURN_OFF:
116087 + return cur_fndecl_attr;
116088 + default:
116089 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
116090 + return MARK_YES;
116091 + }
116092 +}
116093 +
116094 +static void check_missing_size_overflow_attribute(tree var)
116095 +{
116096 + tree orig_fndecl;
116097 + unsigned int num;
116098 +
116099 + if (is_a_return_check(var))
116100 + orig_fndecl = DECL_ORIGIN(var);
116101 + else
116102 + orig_fndecl = DECL_ORIGIN(current_function_decl);
116103 +
116104 + num = get_function_num(var, orig_fndecl);
116105 + if (num == CANNOT_FIND_ARG)
116106 + return;
116107 +
116108 + is_missing_function(orig_fndecl, num);
116109 +}
116110 +
116111 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
116112 +{
116113 + gimple phi = get_def_stmt(result);
116114 + unsigned int i, n = gimple_phi_num_args(phi);
116115 +
116116 + pointer_set_insert(visited, phi);
116117 + for (i = 0; i < n; i++) {
116118 + tree arg = gimple_phi_arg_def(phi, i);
116119 +
116120 + search_size_overflow_attribute(visited, arg);
116121 + }
116122 +}
116123 +
116124 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
116125 +{
116126 + const_gimple def_stmt = get_def_stmt(lhs);
116127 + tree rhs1, rhs2;
116128 +
116129 + rhs1 = gimple_assign_rhs1(def_stmt);
116130 + rhs2 = gimple_assign_rhs2(def_stmt);
116131 +
116132 + search_size_overflow_attribute(visited, rhs1);
116133 + search_size_overflow_attribute(visited, rhs2);
116134 +}
116135 +
116136 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
116137 +{
116138 + const_gimple def_stmt;
116139 +
116140 + if (TREE_CODE(lhs) == PARM_DECL) {
116141 + check_missing_size_overflow_attribute(lhs);
116142 + return;
116143 + }
116144 +
116145 + def_stmt = get_def_stmt(lhs);
116146 + if (!def_stmt)
116147 + return;
116148 +
116149 + if (pointer_set_insert(visited, def_stmt))
116150 + return;
116151 +
116152 + switch (gimple_code(def_stmt)) {
116153 + case GIMPLE_NOP:
116154 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
116155 + case GIMPLE_ASM:
116156 + return;
116157 + case GIMPLE_CALL: {
116158 + tree fndecl = gimple_call_fndecl(def_stmt);
116159 +
116160 + if (fndecl == NULL_TREE)
116161 + return;
116162 + check_missing_size_overflow_attribute(fndecl);
116163 + return;
116164 + }
116165 + case GIMPLE_PHI:
116166 + return search_size_overflow_attribute_phi(visited, lhs);
116167 + case GIMPLE_ASSIGN:
116168 + switch (gimple_num_ops(def_stmt)) {
116169 + case 2:
116170 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
116171 + case 3:
116172 + return search_size_overflow_attribute_binary(visited, lhs);
116173 + }
116174 + default:
116175 + debug_gimple_stmt((gimple)def_stmt);
116176 + error("%s: unknown gimple code", __func__);
116177 + gcc_unreachable();
116178 + }
116179 +}
116180 +
116181 +// Search missing entries in the hash table (invoked from the gimple pass)
116182 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
116183 +{
116184 + tree fndecl = NULL_TREE;
116185 + tree lhs;
116186 + struct pointer_set_t *visited;
116187 +
116188 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
116189 + return;
116190 +
116191 + if (num == 0) {
116192 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
116193 + lhs = gimple_return_retval(stmt);
116194 + } else {
116195 + gcc_assert(is_gimple_call(stmt));
116196 + lhs = gimple_call_arg(stmt, num - 1);
116197 + fndecl = gimple_call_fndecl(stmt);
116198 + }
116199 +
116200 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
116201 + return;
116202 +
116203 + visited = pointer_set_create();
116204 + search_size_overflow_attribute(visited, lhs);
116205 + pointer_set_destroy(visited);
116206 +}
116207 +
116208 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
116209 +{
116210 + gimple_stmt_iterator gsi;
116211 + gimple assign;
116212 +
116213 + assign = gimple_build_assign(asm_data->input, asm_data->output);
116214 + gsi = gsi_for_stmt(stmt);
116215 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
116216 + asm_data->def_stmt = assign;
116217 +
116218 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
116219 + asm_data->output = make_ssa_name(asm_data->output, stmt);
116220 + if (gimple_code(stmt) == GIMPLE_RETURN)
116221 + gimple_return_set_retval(stmt, asm_data->output);
116222 + else
116223 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
116224 + update_stmt(stmt);
116225 +}
116226 +
116227 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
116228 +{
116229 + const char *fn_name;
116230 + char *asm_comment;
116231 + unsigned int len;
116232 +
116233 + if (argnum == 0)
116234 + fn_name = DECL_NAME_POINTER(current_function_decl);
116235 + else
116236 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
116237 +
116238 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
116239 + gcc_assert(len > 0);
116240 +
116241 + return asm_comment;
116242 +}
116243 +
116244 +static const char *convert_mark_to_str(enum mark mark)
116245 +{
116246 + switch (mark) {
116247 + case MARK_NO:
116248 + return OK_ASM_STR;
116249 + case MARK_YES:
116250 + case MARK_NOT_INTENTIONAL:
116251 + return YES_ASM_STR;
116252 + case MARK_TURN_OFF:
116253 + return TURN_OFF_ASM_STR;
116254 + }
116255 +
116256 + gcc_unreachable();
116257 +}
116258 +
116259 +/* Create the input of the size_overflow asm stmt.
116260 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
116261 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
116262 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
116263 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
116264 + */
116265 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
116266 +{
116267 + if (!asm_data->def_stmt) {
116268 + asm_data->input = NULL_TREE;
116269 + return;
116270 + }
116271 +
116272 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
116273 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
116274 +
116275 + switch (gimple_code(asm_data->def_stmt)) {
116276 + case GIMPLE_ASSIGN:
116277 + case GIMPLE_CALL:
116278 + replace_call_lhs(asm_data);
116279 + break;
116280 + case GIMPLE_PHI:
116281 + create_output_from_phi(stmt, argnum, asm_data);
116282 + break;
116283 + case GIMPLE_NOP: {
116284 + enum mark mark;
116285 + const char *mark_str;
116286 + char *asm_comment;
116287 +
116288 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
116289 +
116290 + asm_data->input = asm_data->output;
116291 + asm_data->output = NULL;
116292 + asm_data->def_stmt = stmt;
116293 +
116294 + mark_str = convert_mark_to_str(mark);
116295 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
116296 +
116297 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
116298 + free(asm_comment);
116299 + asm_data->input = NULL_TREE;
116300 + break;
116301 + }
116302 + case GIMPLE_ASM:
116303 + if (is_size_overflow_asm(asm_data->def_stmt)) {
116304 + asm_data->input = NULL_TREE;
116305 + break;
116306 + }
116307 + default:
116308 + debug_gimple_stmt(asm_data->def_stmt);
116309 + gcc_unreachable();
116310 + }
116311 +}
116312 +
116313 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
116314 + * is of the right kind create the appropriate size_overflow asm stmts:
116315 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
116316 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
116317 + */
116318 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
116319 +{
116320 + struct asm_data asm_data;
116321 + const char *mark_str;
116322 + char *asm_comment;
116323 + enum mark mark;
116324 +
116325 + if (is_gimple_constant(output_node))
116326 + return;
116327 +
116328 + asm_data.output = output_node;
116329 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
116330 + if (mark != MARK_TURN_OFF)
116331 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
116332 +
116333 + asm_data.def_stmt = get_def_stmt(asm_data.output);
116334 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
116335 + return;
116336 +
116337 + create_asm_input(stmt, argnum, &asm_data);
116338 + if (asm_data.input == NULL_TREE)
116339 + return;
116340 +
116341 + mark_str = convert_mark_to_str(mark);
116342 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
116343 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
116344 + free(asm_comment);
116345 +}
116346 +
116347 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
116348 +static bool create_mark_asm(gimple stmt, enum mark mark)
116349 +{
116350 + struct asm_data asm_data;
116351 + const char *asm_str;
116352 +
116353 + switch (mark) {
116354 + case MARK_TURN_OFF:
116355 + asm_str = TURN_OFF_ASM_STR;
116356 + break;
116357 + case MARK_NOT_INTENTIONAL:
116358 + case MARK_YES:
116359 + asm_str = YES_ASM_STR;
116360 + break;
116361 + default:
116362 + gcc_unreachable();
116363 + }
116364 +
116365 + asm_data.def_stmt = stmt;
116366 + asm_data.output = gimple_call_lhs(stmt);
116367 +
116368 + if (asm_data.output == NULL_TREE) {
116369 + asm_data.input = gimple_call_arg(stmt, 0);
116370 + if (is_gimple_constant(asm_data.input))
116371 + return false;
116372 + asm_data.output = NULL;
116373 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
116374 + return true;
116375 + }
116376 +
116377 + create_asm_input(stmt, 0, &asm_data);
116378 + gcc_assert(asm_data.input != NULL_TREE);
116379 +
116380 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
116381 + return true;
116382 +}
116383 +
116384 +static bool is_from_cast(const_tree node)
116385 +{
116386 + gimple def_stmt = get_def_stmt(node);
116387 +
116388 + if (!def_stmt)
116389 + return false;
116390 +
116391 + if (gimple_assign_cast_p(def_stmt))
116392 + return true;
116393 +
116394 + return false;
116395 +}
116396 +
116397 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
116398 +static bool skip_ptr_minus(gimple stmt)
116399 +{
116400 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
116401 +
116402 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116403 + return false;
116404 +
116405 + rhs1 = gimple_assign_rhs1(stmt);
116406 + if (!is_from_cast(rhs1))
116407 + return false;
116408 +
116409 + rhs2 = gimple_assign_rhs2(stmt);
116410 + if (!is_from_cast(rhs2))
116411 + return false;
116412 +
116413 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
116414 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
116415 +
116416 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
116417 + return false;
116418 +
116419 + create_mark_asm(stmt, MARK_YES);
116420 + return true;
116421 +}
116422 +
116423 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
116424 +{
116425 + gimple def_stmt;
116426 +
116427 + def_stmt = get_def_stmt(lhs);
116428 + if (!def_stmt)
116429 + return;
116430 +
116431 + if (pointer_set_insert(visited, def_stmt))
116432 + return;
116433 +
116434 + switch (gimple_code(def_stmt)) {
116435 + case GIMPLE_NOP:
116436 + case GIMPLE_ASM:
116437 + case GIMPLE_CALL:
116438 + break;
116439 + case GIMPLE_PHI: {
116440 + unsigned int i, n = gimple_phi_num_args(def_stmt);
116441 +
116442 + pointer_set_insert(visited, def_stmt);
116443 +
116444 + for (i = 0; i < n; i++) {
116445 + tree arg = gimple_phi_arg_def(def_stmt, i);
116446 +
116447 + walk_use_def_ptr(visited, arg);
116448 + }
116449 + }
116450 + case GIMPLE_ASSIGN:
116451 + switch (gimple_num_ops(def_stmt)) {
116452 + case 2:
116453 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
116454 + return;
116455 + case 3:
116456 + if (skip_ptr_minus(def_stmt))
116457 + return;
116458 +
116459 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
116460 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
116461 + return;
116462 + default:
116463 + return;
116464 + }
116465 + default:
116466 + debug_gimple_stmt((gimple)def_stmt);
116467 + error("%s: unknown gimple code", __func__);
116468 + gcc_unreachable();
116469 + }
116470 +}
116471 +
116472 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
116473 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
116474 +{
116475 + struct pointer_set_t *visited;
116476 +
116477 + visited = pointer_set_create();
116478 + walk_use_def_ptr(visited, arg);
116479 + pointer_set_destroy(visited);
116480 +}
116481 +
116482 +// Determine the return value and insert the asm stmt to mark the return stmt.
116483 +static void insert_asm_ret(gimple stmt)
116484 +{
116485 + tree ret;
116486 +
116487 + ret = gimple_return_retval(stmt);
116488 + create_size_overflow_asm(stmt, ret, 0);
116489 +}
116490 +
116491 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
116492 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
116493 +{
116494 + tree arg;
116495 + unsigned int argnum;
116496 +
116497 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
116498 + gcc_assert(argnum != 0);
116499 + if (argnum == CANNOT_FIND_ARG)
116500 + return;
116501 +
116502 + arg = gimple_call_arg(stmt, argnum - 1);
116503 + gcc_assert(arg != NULL_TREE);
116504 +
116505 + // skip all ptr - ptr expressions
116506 + insert_mark_not_intentional_asm_at_ptr(arg);
116507 +
116508 + create_size_overflow_asm(stmt, arg, argnum);
116509 +}
116510 +
116511 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
116512 +static void set_argnum_attribute(const_tree attr, bool *argnums)
116513 +{
116514 + unsigned int argnum;
116515 + tree attr_value;
116516 +
116517 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
116518 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
116519 + argnums[argnum] = true;
116520 + }
116521 +}
116522 +
116523 +// If a function arg or the return value is in the hash table then set its index in the array.
116524 +static void set_argnum_hash(tree fndecl, bool *argnums)
116525 +{
116526 + unsigned int num;
116527 + const struct size_overflow_hash *hash;
116528 +
116529 + hash = get_function_hash(DECL_ORIGIN(fndecl));
116530 + if (!hash)
116531 + return;
116532 +
116533 + for (num = 0; num <= MAX_PARAM; num++) {
116534 + if (!(hash->param & (1U << num)))
116535 + continue;
116536 +
116537 + argnums[num] = true;
116538 + }
116539 +}
116540 +
116541 +static bool is_all_the_argnums_empty(bool *argnums)
116542 +{
116543 + unsigned int i;
116544 +
116545 + for (i = 0; i <= MAX_PARAM; i++)
116546 + if (argnums[i])
116547 + return false;
116548 + return true;
116549 +}
116550 +
116551 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
116552 +static void search_interesting_args(tree fndecl, bool *argnums)
116553 +{
116554 + const_tree attr;
116555 +
116556 + set_argnum_hash(fndecl, argnums);
116557 + if (!is_all_the_argnums_empty(argnums))
116558 + return;
116559 +
116560 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
116561 + if (attr && TREE_VALUE(attr))
116562 + set_argnum_attribute(attr, argnums);
116563 +}
116564 +
116565 +/*
116566 + * Look up the intentional_overflow attribute that turns off ipa based duplication
116567 + * on the callee function.
116568 + */
116569 +static bool is_mark_turn_off_attribute(gimple stmt)
116570 +{
116571 + enum mark mark;
116572 + const_tree fndecl = gimple_call_fndecl(stmt);
116573 +
116574 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
116575 + if (mark == MARK_TURN_OFF)
116576 + return true;
116577 + return false;
116578 +}
116579 +
116580 +// 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
116581 +static void handle_interesting_function(gimple stmt)
116582 +{
116583 + unsigned int argnum;
116584 + tree fndecl;
116585 + bool orig_argnums[MAX_PARAM + 1] = {false};
116586 +
116587 + if (gimple_call_num_args(stmt) == 0)
116588 + return;
116589 + fndecl = gimple_call_fndecl(stmt);
116590 + if (fndecl == NULL_TREE)
116591 + return;
116592 + fndecl = DECL_ORIGIN(fndecl);
116593 +
116594 + if (is_mark_turn_off_attribute(stmt)) {
116595 + create_mark_asm(stmt, MARK_TURN_OFF);
116596 + return;
116597 + }
116598 +
116599 + search_interesting_args(fndecl, orig_argnums);
116600 +
116601 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
116602 + if (orig_argnums[argnum])
116603 + insert_asm_arg(stmt, argnum);
116604 +}
116605 +
116606 +// 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
116607 +static void handle_interesting_ret(gimple stmt)
116608 +{
116609 + bool orig_argnums[MAX_PARAM + 1] = {false};
116610 +
116611 + search_interesting_args(current_function_decl, orig_argnums);
116612 +
116613 + if (orig_argnums[0])
116614 + insert_asm_ret(stmt);
116615 +}
116616 +
116617 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
116618 +static unsigned int search_interesting_functions(void)
116619 +{
116620 + basic_block bb;
116621 +
116622 + FOR_ALL_BB_FN(bb, cfun) {
116623 + gimple_stmt_iterator gsi;
116624 +
116625 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116626 + gimple stmt = gsi_stmt(gsi);
116627 +
116628 + if (is_size_overflow_asm(stmt))
116629 + continue;
116630 +
116631 + if (is_gimple_call(stmt))
116632 + handle_interesting_function(stmt);
116633 + else if (gimple_code(stmt) == GIMPLE_RETURN)
116634 + handle_interesting_ret(stmt);
116635 + }
116636 + }
116637 + return 0;
116638 +}
116639 +
116640 +/*
116641 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
116642 + * this pass inserts asm stmts to mark the interesting args
116643 + * that the ipa pass will detect and insert the size overflow checks for.
116644 + */
116645 +#if BUILDING_GCC_VERSION >= 4009
116646 +static const struct pass_data insert_size_overflow_asm_pass_data = {
116647 +#else
116648 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
116649 + .pass = {
116650 +#endif
116651 + .type = GIMPLE_PASS,
116652 + .name = "insert_size_overflow_asm",
116653 +#if BUILDING_GCC_VERSION >= 4008
116654 + .optinfo_flags = OPTGROUP_NONE,
116655 +#endif
116656 +#if BUILDING_GCC_VERSION >= 4009
116657 + .has_gate = false,
116658 + .has_execute = true,
116659 +#else
116660 + .gate = NULL,
116661 + .execute = search_interesting_functions,
116662 + .sub = NULL,
116663 + .next = NULL,
116664 + .static_pass_number = 0,
116665 +#endif
116666 + .tv_id = TV_NONE,
116667 + .properties_required = PROP_cfg,
116668 + .properties_provided = 0,
116669 + .properties_destroyed = 0,
116670 + .todo_flags_start = 0,
116671 + .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
116672 +#if BUILDING_GCC_VERSION < 4009
116673 + }
116674 +#endif
116675 +};
116676 +
116677 +#if BUILDING_GCC_VERSION >= 4009
116678 +namespace {
116679 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
116680 +public:
116681 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
116682 + unsigned int execute() { return search_interesting_functions(); }
116683 +};
116684 +}
116685 +#endif
116686 +
116687 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
116688 +{
116689 +#if BUILDING_GCC_VERSION >= 4009
116690 + return new insert_size_overflow_asm_pass();
116691 +#else
116692 + return &insert_size_overflow_asm_pass.pass;
116693 +#endif
116694 +}
116695 +
116696 +// Create the noreturn report_size_overflow() function decl.
116697 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
116698 +{
116699 + tree fntype;
116700 +
116701 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
116702 +
116703 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
116704 + fntype = build_function_type_list(void_type_node,
116705 + const_char_ptr_type_node,
116706 + unsigned_type_node,
116707 + const_char_ptr_type_node,
116708 + const_char_ptr_type_node,
116709 + NULL_TREE);
116710 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
116711 +
116712 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
116713 + TREE_PUBLIC(report_size_overflow_decl) = 1;
116714 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
116715 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
116716 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
116717 +}
116718 +
116719 +static unsigned int dump_functions(void)
116720 +{
116721 + struct cgraph_node *node;
116722 +
116723 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116724 + basic_block bb;
116725 +
116726 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
116727 + current_function_decl = NODE_DECL(node);
116728 +
116729 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
116730 +
116731 + FOR_ALL_BB_FN(bb, cfun) {
116732 + gimple_stmt_iterator si;
116733 +
116734 + fprintf(stderr, "<bb %u>:\n", bb->index);
116735 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
116736 + debug_gimple_stmt(gsi_stmt(si));
116737 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116738 + debug_gimple_stmt(gsi_stmt(si));
116739 + fprintf(stderr, "\n");
116740 + }
116741 +
116742 + fprintf(stderr, "-------------------------------------------------------------------------\n");
116743 +
116744 + pop_cfun();
116745 + current_function_decl = NULL_TREE;
116746 + }
116747 +
116748 + fprintf(stderr, "###############################################################################\n");
116749 +
116750 + return 0;
116751 +}
116752 +
116753 +#if BUILDING_GCC_VERSION >= 4009
116754 +static const struct pass_data dump_pass_data = {
116755 +#else
116756 +static struct ipa_opt_pass_d dump_pass = {
116757 + .pass = {
116758 +#endif
116759 + .type = SIMPLE_IPA_PASS,
116760 + .name = "dump",
116761 +#if BUILDING_GCC_VERSION >= 4008
116762 + .optinfo_flags = OPTGROUP_NONE,
116763 +#endif
116764 +#if BUILDING_GCC_VERSION >= 4009
116765 + .has_gate = false,
116766 + .has_execute = true,
116767 +#else
116768 + .gate = NULL,
116769 + .execute = dump_functions,
116770 + .sub = NULL,
116771 + .next = NULL,
116772 + .static_pass_number = 0,
116773 +#endif
116774 + .tv_id = TV_NONE,
116775 + .properties_required = 0,
116776 + .properties_provided = 0,
116777 + .properties_destroyed = 0,
116778 + .todo_flags_start = 0,
116779 + .todo_flags_finish = 0,
116780 +#if BUILDING_GCC_VERSION < 4009
116781 + },
116782 + .generate_summary = NULL,
116783 + .write_summary = NULL,
116784 + .read_summary = NULL,
116785 +#if BUILDING_GCC_VERSION >= 4006
116786 + .write_optimization_summary = NULL,
116787 + .read_optimization_summary = NULL,
116788 +#endif
116789 + .stmt_fixup = NULL,
116790 + .function_transform_todo_flags_start = 0,
116791 + .function_transform = NULL,
116792 + .variable_transform = NULL,
116793 +#endif
116794 +};
116795 +
116796 +#if BUILDING_GCC_VERSION >= 4009
116797 +namespace {
116798 +class dump_pass : public ipa_opt_pass_d {
116799 +public:
116800 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116801 + unsigned int execute() { return dump_functions(); }
116802 +};
116803 +}
116804 +#endif
116805 +
116806 +static struct opt_pass *make_dump_pass(void)
116807 +{
116808 +#if BUILDING_GCC_VERSION >= 4009
116809 + return new dump_pass();
116810 +#else
116811 + return &dump_pass.pass;
116812 +#endif
116813 +}
116814 +
116815 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116816 +{
116817 + int i;
116818 + const char * const plugin_name = plugin_info->base_name;
116819 + const int argc = plugin_info->argc;
116820 + const struct plugin_argument * const argv = plugin_info->argv;
116821 + bool enable = true;
116822 + struct register_pass_info insert_size_overflow_asm_pass_info;
116823 + struct register_pass_info __unused dump_before_pass_info;
116824 + struct register_pass_info __unused dump_after_pass_info;
116825 + struct register_pass_info ipa_pass_info;
116826 +
116827 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
116828 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
116829 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
116830 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
116831 +
116832 + dump_before_pass_info.pass = make_dump_pass();
116833 + dump_before_pass_info.reference_pass_name = "increase_alignment";
116834 + dump_before_pass_info.ref_pass_instance_number = 1;
116835 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116836 +
116837 + ipa_pass_info.pass = make_ipa_pass();
116838 + ipa_pass_info.reference_pass_name = "increase_alignment";
116839 + ipa_pass_info.ref_pass_instance_number = 1;
116840 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116841 +
116842 + dump_after_pass_info.pass = make_dump_pass();
116843 + dump_after_pass_info.reference_pass_name = "increase_alignment";
116844 + dump_after_pass_info.ref_pass_instance_number = 1;
116845 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116846 +
116847 + if (!plugin_default_version_check(version, &gcc_version)) {
116848 + error(G_("incompatible gcc/plugin versions"));
116849 + return 1;
116850 + }
116851 +
116852 + for (i = 0; i < argc; ++i) {
116853 + if (!strcmp(argv[i].key, "no-size-overflow")) {
116854 + enable = false;
116855 + continue;
116856 + }
116857 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
116858 + }
116859 +
116860 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
116861 + if (enable) {
116862 + register_callback(plugin_name, PLUGIN_START_UNIT, &start_unit_callback, NULL);
116863 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
116864 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
116865 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
116866 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
116867 + }
116868 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
116869 +
116870 + return 0;
116871 +}
116872 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
116873 new file mode 100644
116874 index 0000000..a4f816a
116875 --- /dev/null
116876 +++ b/tools/gcc/stackleak_plugin.c
116877 @@ -0,0 +1,341 @@
116878 +/*
116879 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
116880 + * Licensed under the GPL v2
116881 + *
116882 + * Note: the choice of the license means that the compilation process is
116883 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
116884 + * but for the kernel it doesn't matter since it doesn't link against
116885 + * any of the gcc libraries
116886 + *
116887 + * gcc plugin to help implement various PaX features
116888 + *
116889 + * - track lowest stack pointer
116890 + *
116891 + * TODO:
116892 + * - initialize all local variables
116893 + *
116894 + * BUGS:
116895 + * - none known
116896 + */
116897 +
116898 +#include "gcc-common.h"
116899 +
116900 +int plugin_is_GPL_compatible;
116901 +
116902 +static int track_frame_size = -1;
116903 +static const char track_function[] = "pax_track_stack";
116904 +static const char check_function[] = "pax_check_alloca";
116905 +static bool init_locals;
116906 +
116907 +static struct plugin_info stackleak_plugin_info = {
116908 + .version = "201401260140",
116909 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
116910 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
116911 +};
116912 +
116913 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
116914 +{
116915 + gimple check_alloca;
116916 + tree fntype, fndecl, alloca_size;
116917 +
116918 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
116919 + fndecl = build_fn_decl(check_function, fntype);
116920 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
116921 +
116922 + // insert call to void pax_check_alloca(unsigned long size)
116923 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
116924 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
116925 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
116926 +}
116927 +
116928 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
116929 +{
116930 + gimple track_stack;
116931 + tree fntype, fndecl;
116932 +
116933 + fntype = build_function_type_list(void_type_node, NULL_TREE);
116934 + fndecl = build_fn_decl(track_function, fntype);
116935 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
116936 +
116937 + // insert call to void pax_track_stack(void)
116938 + track_stack = gimple_build_call(fndecl, 0);
116939 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
116940 +}
116941 +
116942 +static bool is_alloca(gimple stmt)
116943 +{
116944 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
116945 + return true;
116946 +
116947 +#if BUILDING_GCC_VERSION >= 4007
116948 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
116949 + return true;
116950 +#endif
116951 +
116952 + return false;
116953 +}
116954 +
116955 +static unsigned int execute_stackleak_tree_instrument(void)
116956 +{
116957 + basic_block bb, entry_bb;
116958 + bool prologue_instrumented = false, is_leaf = true;
116959 +
116960 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
116961 +
116962 + // 1. loop through BBs and GIMPLE statements
116963 + FOR_EACH_BB_FN(bb, cfun) {
116964 + gimple_stmt_iterator gsi;
116965 +
116966 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116967 + gimple stmt;
116968 +
116969 + stmt = gsi_stmt(gsi);
116970 +
116971 + if (is_gimple_call(stmt))
116972 + is_leaf = false;
116973 +
116974 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
116975 + if (!is_alloca(stmt))
116976 + continue;
116977 +
116978 + // 2. insert stack overflow check before each __builtin_alloca call
116979 + stackleak_check_alloca(&gsi);
116980 +
116981 + // 3. insert track call after each __builtin_alloca call
116982 + stackleak_add_instrumentation(&gsi);
116983 + if (bb == entry_bb)
116984 + prologue_instrumented = true;
116985 + }
116986 + }
116987 +
116988 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
116989 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
116990 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
116991 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
116992 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
116993 + return 0;
116994 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
116995 + return 0;
116996 +
116997 + // 4. insert track call at the beginning
116998 + if (!prologue_instrumented) {
116999 + gimple_stmt_iterator gsi;
117000 +
117001 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
117002 + if (dom_info_available_p(CDI_DOMINATORS))
117003 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
117004 + gsi = gsi_start_bb(bb);
117005 + stackleak_add_instrumentation(&gsi);
117006 + }
117007 +
117008 + return 0;
117009 +}
117010 +
117011 +static unsigned int execute_stackleak_final(void)
117012 +{
117013 + rtx insn, next;
117014 +
117015 + if (cfun->calls_alloca)
117016 + return 0;
117017 +
117018 + // keep calls only if function frame is big enough
117019 + if (get_frame_size() >= track_frame_size)
117020 + return 0;
117021 +
117022 + // 1. find pax_track_stack calls
117023 + for (insn = get_insns(); insn; insn = next) {
117024 + // 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))
117025 + rtx body;
117026 +
117027 + next = NEXT_INSN(insn);
117028 + if (!CALL_P(insn))
117029 + continue;
117030 + body = PATTERN(insn);
117031 + if (GET_CODE(body) != CALL)
117032 + continue;
117033 + body = XEXP(body, 0);
117034 + if (GET_CODE(body) != MEM)
117035 + continue;
117036 + body = XEXP(body, 0);
117037 + if (GET_CODE(body) != SYMBOL_REF)
117038 + continue;
117039 + if (strcmp(XSTR(body, 0), track_function))
117040 + continue;
117041 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
117042 + // 2. delete call
117043 + delete_insn_and_edges(insn);
117044 +#if BUILDING_GCC_VERSION >= 4007
117045 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
117046 + insn = next;
117047 + next = NEXT_INSN(insn);
117048 + delete_insn_and_edges(insn);
117049 + }
117050 +#endif
117051 + }
117052 +
117053 +// print_simple_rtl(stderr, get_insns());
117054 +// print_rtl(stderr, get_insns());
117055 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
117056 +
117057 + return 0;
117058 +}
117059 +
117060 +static bool gate_stackleak_track_stack(void)
117061 +{
117062 + return track_frame_size >= 0;
117063 +}
117064 +
117065 +#if BUILDING_GCC_VERSION >= 4009
117066 +static const struct pass_data stackleak_tree_instrument_pass_data = {
117067 +#else
117068 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
117069 + .pass = {
117070 +#endif
117071 + .type = GIMPLE_PASS,
117072 + .name = "stackleak_tree_instrument",
117073 +#if BUILDING_GCC_VERSION >= 4008
117074 + .optinfo_flags = OPTGROUP_NONE,
117075 +#endif
117076 +#if BUILDING_GCC_VERSION >= 4009
117077 + .has_gate = true,
117078 + .has_execute = true,
117079 +#else
117080 + .gate = gate_stackleak_track_stack,
117081 + .execute = execute_stackleak_tree_instrument,
117082 + .sub = NULL,
117083 + .next = NULL,
117084 + .static_pass_number = 0,
117085 +#endif
117086 + .tv_id = TV_NONE,
117087 + .properties_required = PROP_gimple_leh | PROP_cfg,
117088 + .properties_provided = 0,
117089 + .properties_destroyed = 0,
117090 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
117091 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
117092 +#if BUILDING_GCC_VERSION < 4009
117093 + }
117094 +#endif
117095 +};
117096 +
117097 +#if BUILDING_GCC_VERSION >= 4009
117098 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
117099 +#else
117100 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
117101 + .pass = {
117102 +#endif
117103 + .type = RTL_PASS,
117104 + .name = "stackleak_final",
117105 +#if BUILDING_GCC_VERSION >= 4008
117106 + .optinfo_flags = OPTGROUP_NONE,
117107 +#endif
117108 +#if BUILDING_GCC_VERSION >= 4009
117109 + .has_gate = true,
117110 + .has_execute = true,
117111 +#else
117112 + .gate = gate_stackleak_track_stack,
117113 + .execute = execute_stackleak_final,
117114 + .sub = NULL,
117115 + .next = NULL,
117116 + .static_pass_number = 0,
117117 +#endif
117118 + .tv_id = TV_NONE,
117119 + .properties_required = 0,
117120 + .properties_provided = 0,
117121 + .properties_destroyed = 0,
117122 + .todo_flags_start = 0,
117123 + .todo_flags_finish = TODO_dump_func
117124 +#if BUILDING_GCC_VERSION < 4009
117125 + }
117126 +#endif
117127 +};
117128 +
117129 +#if BUILDING_GCC_VERSION >= 4009
117130 +namespace {
117131 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
117132 +public:
117133 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
117134 + bool gate() { return gate_stackleak_track_stack(); }
117135 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
117136 +};
117137 +
117138 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
117139 +public:
117140 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
117141 + bool gate() { return gate_stackleak_track_stack(); }
117142 + unsigned int execute() { return execute_stackleak_final(); }
117143 +};
117144 +}
117145 +#endif
117146 +
117147 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
117148 +{
117149 +#if BUILDING_GCC_VERSION >= 4009
117150 + return new stackleak_tree_instrument_pass();
117151 +#else
117152 + return &stackleak_tree_instrument_pass.pass;
117153 +#endif
117154 +}
117155 +
117156 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
117157 +{
117158 +#if BUILDING_GCC_VERSION >= 4009
117159 + return new stackleak_final_rtl_opt_pass();
117160 +#else
117161 + return &stackleak_final_rtl_opt_pass.pass;
117162 +#endif
117163 +}
117164 +
117165 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117166 +{
117167 + const char * const plugin_name = plugin_info->base_name;
117168 + const int argc = plugin_info->argc;
117169 + const struct plugin_argument * const argv = plugin_info->argv;
117170 + int i;
117171 + struct register_pass_info stackleak_tree_instrument_pass_info;
117172 + struct register_pass_info stackleak_final_pass_info;
117173 +
117174 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
117175 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
117176 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
117177 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
117178 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
117179 +
117180 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
117181 + stackleak_final_pass_info.reference_pass_name = "final";
117182 + stackleak_final_pass_info.ref_pass_instance_number = 1;
117183 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
117184 +
117185 + if (!plugin_default_version_check(version, &gcc_version)) {
117186 + error(G_("incompatible gcc/plugin versions"));
117187 + return 1;
117188 + }
117189 +
117190 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
117191 +
117192 + for (i = 0; i < argc; ++i) {
117193 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
117194 + if (!argv[i].value) {
117195 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117196 + continue;
117197 + }
117198 + track_frame_size = atoi(argv[i].value);
117199 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
117200 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117201 + continue;
117202 + }
117203 + if (!strcmp(argv[i].key, "initialize-locals")) {
117204 + if (argv[i].value) {
117205 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117206 + continue;
117207 + }
117208 + init_locals = true;
117209 + continue;
117210 + }
117211 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117212 + }
117213 +
117214 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
117215 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
117216 +
117217 + return 0;
117218 +}
117219 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
117220 new file mode 100644
117221 index 0000000..796569a
117222 --- /dev/null
117223 +++ b/tools/gcc/structleak_plugin.c
117224 @@ -0,0 +1,273 @@
117225 +/*
117226 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
117227 + * Licensed under the GPL v2
117228 + *
117229 + * Note: the choice of the license means that the compilation process is
117230 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
117231 + * but for the kernel it doesn't matter since it doesn't link against
117232 + * any of the gcc libraries
117233 + *
117234 + * gcc plugin to forcibly initialize certain local variables that could
117235 + * otherwise leak kernel stack to userland if they aren't properly initialized
117236 + * by later code
117237 + *
117238 + * Homepage: http://pax.grsecurity.net/
117239 + *
117240 + * Usage:
117241 + * $ # for 4.5/4.6/C based 4.7
117242 + * $ 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
117243 + * $ # for C++ based 4.7/4.8+
117244 + * $ 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
117245 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
117246 + *
117247 + * TODO: eliminate redundant initializers
117248 + * increase type coverage
117249 + */
117250 +
117251 +#include "gcc-common.h"
117252 +
117253 +// unused C type flag in all versions 4.5-4.9
117254 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
117255 +
117256 +int plugin_is_GPL_compatible;
117257 +
117258 +static struct plugin_info structleak_plugin_info = {
117259 + .version = "201401260140",
117260 + .help = "disable\tdo not activate plugin\n",
117261 +};
117262 +
117263 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117264 +{
117265 + *no_add_attrs = true;
117266 +
117267 + // check for types? for now accept everything linux has to offer
117268 + if (TREE_CODE(*node) != FIELD_DECL)
117269 + return NULL_TREE;
117270 +
117271 + *no_add_attrs = false;
117272 + return NULL_TREE;
117273 +}
117274 +
117275 +static struct attribute_spec user_attr = {
117276 + .name = "user",
117277 + .min_length = 0,
117278 + .max_length = 0,
117279 + .decl_required = false,
117280 + .type_required = false,
117281 + .function_type_required = false,
117282 + .handler = handle_user_attribute,
117283 +#if BUILDING_GCC_VERSION >= 4007
117284 + .affects_type_identity = true
117285 +#endif
117286 +};
117287 +
117288 +static void register_attributes(void *event_data, void *data)
117289 +{
117290 + register_attribute(&user_attr);
117291 +// register_attribute(&force_attr);
117292 +}
117293 +
117294 +static tree get_field_type(tree field)
117295 +{
117296 + return strip_array_types(TREE_TYPE(field));
117297 +}
117298 +
117299 +static bool is_userspace_type(tree type)
117300 +{
117301 + tree field;
117302 +
117303 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
117304 + tree fieldtype = get_field_type(field);
117305 + enum tree_code code = TREE_CODE(fieldtype);
117306 +
117307 + if (code == RECORD_TYPE || code == UNION_TYPE)
117308 + if (is_userspace_type(fieldtype))
117309 + return true;
117310 +
117311 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
117312 + return true;
117313 + }
117314 + return false;
117315 +}
117316 +
117317 +static void finish_type(void *event_data, void *data)
117318 +{
117319 + tree type = (tree)event_data;
117320 +
117321 + if (TYPE_USERSPACE(type))
117322 + return;
117323 +
117324 + if (is_userspace_type(type))
117325 + TYPE_USERSPACE(type) = 1;
117326 +}
117327 +
117328 +static void initialize(tree var)
117329 +{
117330 + basic_block bb;
117331 + gimple_stmt_iterator gsi;
117332 + tree initializer;
117333 + gimple init_stmt;
117334 +
117335 + // this is the original entry bb before the forced split
117336 + // TODO: check further BBs in case more splits occured before us
117337 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
117338 +
117339 + // first check if the variable is already initialized, warn otherwise
117340 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117341 + gimple stmt = gsi_stmt(gsi);
117342 + tree rhs1;
117343 +
117344 + // we're looking for an assignment of a single rhs...
117345 + if (!gimple_assign_single_p(stmt))
117346 + continue;
117347 + rhs1 = gimple_assign_rhs1(stmt);
117348 +#if BUILDING_GCC_VERSION >= 4007
117349 + // ... of a non-clobbering expression...
117350 + if (TREE_CLOBBER_P(rhs1))
117351 + continue;
117352 +#endif
117353 + // ... to our variable...
117354 + if (gimple_get_lhs(stmt) != var)
117355 + continue;
117356 + // if it's an initializer then we're good
117357 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
117358 + return;
117359 + }
117360 +
117361 + // these aren't the 0days you're looking for
117362 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
117363 +
117364 + // build the initializer expression
117365 + initializer = build_constructor(TREE_TYPE(var), NULL);
117366 +
117367 + // build the initializer stmt
117368 + init_stmt = gimple_build_assign(var, initializer);
117369 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
117370 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
117371 + update_stmt(init_stmt);
117372 +}
117373 +
117374 +static unsigned int handle_function(void)
117375 +{
117376 + basic_block bb;
117377 + unsigned int ret = 0;
117378 + tree var;
117379 + unsigned int i;
117380 +
117381 + // split the first bb where we can put the forced initializers
117382 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
117383 + if (dom_info_available_p(CDI_DOMINATORS))
117384 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
117385 +
117386 + // enumarate all local variables and forcibly initialize our targets
117387 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
117388 + tree type = TREE_TYPE(var);
117389 +
117390 + gcc_assert(DECL_P(var));
117391 + if (!auto_var_in_fn_p(var, current_function_decl))
117392 + continue;
117393 +
117394 + // only care about structure types
117395 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
117396 + continue;
117397 +
117398 + // if the type is of interest, examine the variable
117399 + if (TYPE_USERSPACE(type))
117400 + initialize(var);
117401 + }
117402 +
117403 + return ret;
117404 +}
117405 +
117406 +#if BUILDING_GCC_VERSION >= 4009
117407 +static const struct pass_data structleak_pass_data = {
117408 +#else
117409 +static struct gimple_opt_pass structleak_pass = {
117410 + .pass = {
117411 +#endif
117412 + .type = GIMPLE_PASS,
117413 + .name = "structleak",
117414 +#if BUILDING_GCC_VERSION >= 4008
117415 + .optinfo_flags = OPTGROUP_NONE,
117416 +#endif
117417 +#if BUILDING_GCC_VERSION >= 4009
117418 + .has_gate = false,
117419 + .has_execute = true,
117420 +#else
117421 + .gate = NULL,
117422 + .execute = handle_function,
117423 + .sub = NULL,
117424 + .next = NULL,
117425 + .static_pass_number = 0,
117426 +#endif
117427 + .tv_id = TV_NONE,
117428 + .properties_required = PROP_cfg,
117429 + .properties_provided = 0,
117430 + .properties_destroyed = 0,
117431 + .todo_flags_start = 0,
117432 + .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
117433 +#if BUILDING_GCC_VERSION < 4009
117434 + }
117435 +#endif
117436 +};
117437 +
117438 +#if BUILDING_GCC_VERSION >= 4009
117439 +namespace {
117440 +class structleak_pass : public gimple_opt_pass {
117441 +public:
117442 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
117443 + unsigned int execute() { return handle_function(); }
117444 +};
117445 +}
117446 +#endif
117447 +
117448 +static struct opt_pass *make_structleak_pass(void)
117449 +{
117450 +#if BUILDING_GCC_VERSION >= 4009
117451 + return new structleak_pass();
117452 +#else
117453 + return &structleak_pass.pass;
117454 +#endif
117455 +}
117456 +
117457 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117458 +{
117459 + int i;
117460 + const char * const plugin_name = plugin_info->base_name;
117461 + const int argc = plugin_info->argc;
117462 + const struct plugin_argument * const argv = plugin_info->argv;
117463 + bool enable = true;
117464 + struct register_pass_info structleak_pass_info;
117465 +
117466 + structleak_pass_info.pass = make_structleak_pass();
117467 + structleak_pass_info.reference_pass_name = "ssa";
117468 + structleak_pass_info.ref_pass_instance_number = 1;
117469 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117470 +
117471 + if (!plugin_default_version_check(version, &gcc_version)) {
117472 + error(G_("incompatible gcc/plugin versions"));
117473 + return 1;
117474 + }
117475 +
117476 + if (strcmp(lang_hooks.name, "GNU C")) {
117477 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
117478 + enable = false;
117479 + }
117480 +
117481 + for (i = 0; i < argc; ++i) {
117482 + if (!strcmp(argv[i].key, "disable")) {
117483 + enable = false;
117484 + continue;
117485 + }
117486 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117487 + }
117488 +
117489 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
117490 + if (enable) {
117491 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
117492 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
117493 + }
117494 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
117495 +
117496 + return 0;
117497 +}
117498 diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
117499 index 3dba0a4..97175dc 100644
117500 --- a/tools/lib/lk/Makefile
117501 +++ b/tools/lib/lk/Makefile
117502 @@ -13,7 +13,7 @@ LIB_OBJS += $(OUTPUT)debugfs.o
117503
117504 LIBFILE = liblk.a
117505
117506 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
117507 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
117508 EXTLIBS = -lelf -lpthread -lrt -lm
117509 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
117510 ALL_LDFLAGS = $(LDFLAGS)
117511 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
117512 index 6789d78..4afd019e 100644
117513 --- a/tools/perf/util/include/asm/alternative-asm.h
117514 +++ b/tools/perf/util/include/asm/alternative-asm.h
117515 @@ -5,4 +5,7 @@
117516
117517 #define altinstruction_entry #
117518
117519 + .macro pax_force_retaddr rip=0, reload=0
117520 + .endm
117521 +
117522 #endif
117523 diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
117524 index b003ad7..c0a02f8 100644
117525 --- a/tools/perf/util/include/linux/compiler.h
117526 +++ b/tools/perf/util/include/linux/compiler.h
117527 @@ -27,4 +27,12 @@
117528 # define __weak __attribute__((weak))
117529 #endif
117530
117531 +#ifndef __size_overflow
117532 +# define __size_overflow(...)
117533 +#endif
117534 +
117535 +#ifndef __intentional_overflow
117536 +# define __intentional_overflow(...)
117537 +#endif
117538 +
117539 #endif
117540 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
117541 index 4f588bc..d3cfc5c 100644
117542 --- a/virt/kvm/kvm_main.c
117543 +++ b/virt/kvm/kvm_main.c
117544 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
117545
117546 static cpumask_var_t cpus_hardware_enabled;
117547 static int kvm_usage_count = 0;
117548 -static atomic_t hardware_enable_failed;
117549 +static atomic_unchecked_t hardware_enable_failed;
117550
117551 struct kmem_cache *kvm_vcpu_cache;
117552 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
117553
117554 -static __read_mostly struct preempt_ops kvm_preempt_ops;
117555 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
117556 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
117557 +static struct preempt_ops kvm_preempt_ops = {
117558 + .sched_in = kvm_sched_in,
117559 + .sched_out = kvm_sched_out,
117560 +};
117561
117562 struct dentry *kvm_debugfs_dir;
117563
117564 @@ -751,7 +756,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
117565 /* We can read the guest memory with __xxx_user() later on. */
117566 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
117567 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
117568 - !access_ok(VERIFY_WRITE,
117569 + !__access_ok(VERIFY_WRITE,
117570 (void __user *)(unsigned long)mem->userspace_addr,
117571 mem->memory_size)))
117572 goto out;
117573 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
117574
117575 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
117576 {
117577 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
117578 + int r;
117579 + unsigned long addr;
117580
117581 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
117582 + addr = gfn_to_hva(kvm, gfn);
117583 + if (kvm_is_error_hva(addr))
117584 + return -EFAULT;
117585 + r = __clear_user((void __user *)addr + offset, len);
117586 + if (r)
117587 + return -EFAULT;
117588 + mark_page_dirty(kvm, gfn);
117589 + return 0;
117590 }
117591 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
117592
117593 @@ -1872,7 +1885,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
117594 return 0;
117595 }
117596
117597 -static struct file_operations kvm_vcpu_fops = {
117598 +static file_operations_no_const kvm_vcpu_fops __read_only = {
117599 .release = kvm_vcpu_release,
117600 .unlocked_ioctl = kvm_vcpu_ioctl,
117601 #ifdef CONFIG_COMPAT
117602 @@ -2532,7 +2545,7 @@ out:
117603 }
117604 #endif
117605
117606 -static struct file_operations kvm_vm_fops = {
117607 +static file_operations_no_const kvm_vm_fops __read_only = {
117608 .release = kvm_vm_release,
117609 .unlocked_ioctl = kvm_vm_ioctl,
117610 #ifdef CONFIG_COMPAT
117611 @@ -2632,7 +2645,7 @@ out:
117612 return r;
117613 }
117614
117615 -static struct file_operations kvm_chardev_ops = {
117616 +static file_operations_no_const kvm_chardev_ops __read_only = {
117617 .unlocked_ioctl = kvm_dev_ioctl,
117618 .compat_ioctl = kvm_dev_ioctl,
117619 .llseek = noop_llseek,
117620 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
117621
117622 if (r) {
117623 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
117624 - atomic_inc(&hardware_enable_failed);
117625 + atomic_inc_unchecked(&hardware_enable_failed);
117626 printk(KERN_INFO "kvm: enabling virtualization on "
117627 "CPU%d failed\n", cpu);
117628 }
117629 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
117630
117631 kvm_usage_count++;
117632 if (kvm_usage_count == 1) {
117633 - atomic_set(&hardware_enable_failed, 0);
117634 + atomic_set_unchecked(&hardware_enable_failed, 0);
117635 on_each_cpu(hardware_enable_nolock, NULL, 1);
117636
117637 - if (atomic_read(&hardware_enable_failed)) {
117638 + if (atomic_read_unchecked(&hardware_enable_failed)) {
117639 hardware_disable_all_nolock();
117640 r = -EBUSY;
117641 }
117642 @@ -3148,7 +3161,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
117643 kvm_arch_vcpu_put(vcpu);
117644 }
117645
117646 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117647 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117648 struct module *module)
117649 {
117650 int r;
117651 @@ -3195,7 +3208,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117652 if (!vcpu_align)
117653 vcpu_align = __alignof__(struct kvm_vcpu);
117654 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
117655 - 0, NULL);
117656 + SLAB_USERCOPY, NULL);
117657 if (!kvm_vcpu_cache) {
117658 r = -ENOMEM;
117659 goto out_free_3;
117660 @@ -3205,9 +3218,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117661 if (r)
117662 goto out_free;
117663
117664 + pax_open_kernel();
117665 kvm_chardev_ops.owner = module;
117666 kvm_vm_fops.owner = module;
117667 kvm_vcpu_fops.owner = module;
117668 + pax_close_kernel();
117669
117670 r = misc_register(&kvm_dev);
117671 if (r) {
117672 @@ -3217,9 +3232,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117673
117674 register_syscore_ops(&kvm_syscore_ops);
117675
117676 - kvm_preempt_ops.sched_in = kvm_sched_in;
117677 - kvm_preempt_ops.sched_out = kvm_sched_out;
117678 -
117679 r = kvm_init_debug();
117680 if (r) {
117681 printk(KERN_ERR "kvm: create debugfs files failed\n");