]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.1-201212271953.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.1-201212271953.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 74c25c8..deadba2 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,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 @@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56 +ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60 @@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64 +builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70 +clut_vga16.c
71 +common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78 +config.c
79 config.mak
80 config.mak.autogen
81 +config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85 @@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89 +dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93 +exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97 @@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101 +gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108 +hash
109 +hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113 @@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117 -kconfig
118 +kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125 -linux
126 +lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130 @@ -162,14 +180,15 @@ mach-types.h
131 machtypes.h
132 map
133 map_hugetlb
134 -media
135 mconf
136 +mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143 +mkpiggy
144 mkprep
145 mkregtable
146 mktables
147 @@ -186,6 +205,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151 +parse-events*
152 +pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156 @@ -195,6 +216,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160 +pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164 @@ -204,7 +226,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168 +realmode.lds
169 +realmode.relocs
170 recordmcount
171 +regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175 @@ -214,8 +239,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179 +size_overflow_hash.h
180 sImage
181 +slabinfo
182 sm_tbl*
183 +sortextable
184 split-include
185 syscalltab.h
186 tables.c
187 @@ -225,6 +253,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191 +user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195 @@ -236,13 +265,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199 +vdsox32.lds
200 +vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207 +vmlinux.bin.bz2
208 vmlinux.lds
209 +vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213 @@ -250,9 +283,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217 +utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223 +zconf.lex.c
224 zoffset.h
225 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226 index 9776f06..18b1856 100644
227 --- a/Documentation/kernel-parameters.txt
228 +++ b/Documentation/kernel-parameters.txt
229 @@ -905,6 +905,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 gpt [EFI] Forces disk with valid GPT signature but
231 invalid Protective MBR to be treated as GPT.
232
233 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234 + ignore grsecurity's /proc restrictions
235 +
236 hashdist= [KNL,NUMA] Large hashes allocated during boot
237 are distributed across NUMA nodes. Defaults on
238 for 64-bit NUMA, off otherwise.
239 @@ -2082,6 +2085,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
240 the specified number of seconds. This is to be used if
241 your oopses keep scrolling off the screen.
242
243 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
244 + virtualization environments that don't cope well with the
245 + expand down segment used by UDEREF on X86-32 or the frequent
246 + page table updates on X86-64.
247 +
248 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
249 +
250 pcbit= [HW,ISDN]
251
252 pcd. [PARIDE]
253 diff --git a/Makefile b/Makefile
254 index fbf84a4..339f6de 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -575,6 +576,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(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.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -731,7 +786,7 @@ export mod_sign_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -778,6 +833,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -787,7 +844,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -831,6 +888,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -938,6 +996,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -953,7 +1013,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -1013,7 +1073,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
395 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
396 signing_key.priv signing_key.x509 x509.genkey \
397 extra_certificates signing_key.x509.keyid \
398 - signing_key.x509.signer
399 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
400
401 # clean - Delete most, but leave enough to build external modules
402 #
403 @@ -1050,6 +1110,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1210,6 +1271,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1347,17 +1410,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1367,11 +1434,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index 14db93e..65de923 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1304,7 +1304,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589 - if (!vma || addr + len <= vma->vm_start)
590 + if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594 @@ -1340,6 +1340,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598 +#ifdef CONFIG_PAX_RANDMMAP
599 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600 +#endif
601 +
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605 @@ -1347,8 +1351,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610 - len, limit);
611 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612 +
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617 index 0c4132d..88f0d53 100644
618 --- a/arch/alpha/mm/fault.c
619 +++ b/arch/alpha/mm/fault.c
620 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 +/*
626 + * PaX: decide what to do with offenders (regs->pc = fault address)
627 + *
628 + * returns 1 when task should be killed
629 + * 2 when patched PLT trampoline was detected
630 + * 3 when unpatched PLT trampoline was detected
631 + */
632 +static int pax_handle_fetch_fault(struct pt_regs *regs)
633 +{
634 +
635 +#ifdef CONFIG_PAX_EMUPLT
636 + int err;
637 +
638 + do { /* PaX: patched PLT emulation #1 */
639 + unsigned int ldah, ldq, jmp;
640 +
641 + err = get_user(ldah, (unsigned int *)regs->pc);
642 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644 +
645 + if (err)
646 + break;
647 +
648 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650 + jmp == 0x6BFB0000U)
651 + {
652 + unsigned long r27, addr;
653 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655 +
656 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657 + err = get_user(r27, (unsigned long *)addr);
658 + if (err)
659 + break;
660 +
661 + regs->r27 = r27;
662 + regs->pc = r27;
663 + return 2;
664 + }
665 + } while (0);
666 +
667 + do { /* PaX: patched PLT emulation #2 */
668 + unsigned int ldah, lda, br;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
672 + err |= get_user(br, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
679 + (br & 0xFFE00000U) == 0xC3E00000U)
680 + {
681 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684 +
685 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: unpatched PLT emulation */
692 + unsigned int br;
693 +
694 + err = get_user(br, (unsigned int *)regs->pc);
695 +
696 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697 + unsigned int br2, ldq, nop, jmp;
698 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699 +
700 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701 + err = get_user(br2, (unsigned int *)addr);
702 + err |= get_user(ldq, (unsigned int *)(addr+4));
703 + err |= get_user(nop, (unsigned int *)(addr+8));
704 + err |= get_user(jmp, (unsigned int *)(addr+12));
705 + err |= get_user(resolver, (unsigned long *)(addr+16));
706 +
707 + if (err)
708 + break;
709 +
710 + if (br2 == 0xC3600000U &&
711 + ldq == 0xA77B000CU &&
712 + nop == 0x47FF041FU &&
713 + jmp == 0x6B7B0000U)
714 + {
715 + regs->r28 = regs->pc+4;
716 + regs->r27 = addr+16;
717 + regs->pc = resolver;
718 + return 3;
719 + }
720 + }
721 + } while (0);
722 +#endif
723 +
724 + return 1;
725 +}
726 +
727 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728 +{
729 + unsigned long i;
730 +
731 + printk(KERN_ERR "PAX: bytes at PC: ");
732 + for (i = 0; i < 5; i++) {
733 + unsigned int c;
734 + if (get_user(c, (unsigned int *)pc+i))
735 + printk(KERN_CONT "???????? ");
736 + else
737 + printk(KERN_CONT "%08x ", c);
738 + }
739 + printk("\n");
740 +}
741 +#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745 @@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749 - if (!(vma->vm_flags & VM_EXEC))
750 + if (!(vma->vm_flags & VM_EXEC)) {
751 +
752 +#ifdef CONFIG_PAX_PAGEEXEC
753 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754 + goto bad_area;
755 +
756 + up_read(&mm->mmap_sem);
757 + switch (pax_handle_fetch_fault(regs)) {
758 +
759 +#ifdef CONFIG_PAX_EMUPLT
760 + case 2:
761 + case 3:
762 + return;
763 +#endif
764 +
765 + }
766 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767 + do_group_exit(SIGKILL);
768 +#else
769 goto bad_area;
770 +#endif
771 +
772 + }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777 index c79f61f..9ac0642 100644
778 --- a/arch/arm/include/asm/atomic.h
779 +++ b/arch/arm/include/asm/atomic.h
780 @@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784 +#ifdef CONFIG_GENERIC_ATOMIC64
785 +#include <asm-generic/atomic64.h>
786 +#endif
787 +
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792 +#define _ASM_EXTABLE(from, to) \
793 +" .pushsection __ex_table,\"a\"\n"\
794 +" .align 3\n" \
795 +" .long " #from ", " #to"\n" \
796 +" .popsection"
797 +
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805 +{
806 + return v->counter;
807 +}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810 +{
811 + v->counter = i;
812 +}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820 +"1: ldrex %1, [%3]\n"
821 +" adds %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856 +"1: ldrex %1, [%3]\n"
857 +" adds %0, %1, %4\n"
858 +
859 +#ifdef CONFIG_PAX_REFCOUNT
860 +" bvc 3f\n"
861 +" mov %0, %1\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +
879 + smp_mb();
880 +
881 + return result;
882 +}
883 +
884 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885 +{
886 + unsigned long tmp;
887 + int result;
888 +
889 + smp_mb();
890 +
891 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899 +"1: ldrex %1, [%3]\n"
900 +" subs %0, %1, %4\n"
901 +
902 +#ifdef CONFIG_PAX_REFCOUNT
903 +" bvc 3f\n"
904 +"2: bkpt 0xf103\n"
905 +"3:\n"
906 +#endif
907 +
908 +" strex %1, %0, [%3]\n"
909 +" teq %1, #0\n"
910 +" bne 1b"
911 +
912 +#ifdef CONFIG_PAX_REFCOUNT
913 +"\n4:\n"
914 + _ASM_EXTABLE(2b, 4b)
915 +#endif
916 +
917 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918 + : "r" (&v->counter), "Ir" (i)
919 + : "cc");
920 +}
921 +
922 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923 +{
924 + unsigned long tmp;
925 + int result;
926 +
927 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935 -"1: ldrex %0, [%3]\n"
936 -" sub %0, %0, %4\n"
937 +"1: ldrex %1, [%3]\n"
938 +" subs %0, %1, %4\n"
939 +
940 +#ifdef CONFIG_PAX_REFCOUNT
941 +" bvc 3f\n"
942 +" mov %0, %1\n"
943 +"2: bkpt 0xf103\n"
944 +"3:\n"
945 +#endif
946 +
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950 +
951 +#ifdef CONFIG_PAX_REFCOUNT
952 +"\n4:\n"
953 + _ASM_EXTABLE(2b, 4b)
954 +#endif
955 +
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964 +{
965 + unsigned long oldval, res;
966 +
967 + smp_mb();
968 +
969 + do {
970 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971 + "ldrex %1, [%3]\n"
972 + "mov %0, #0\n"
973 + "teq %1, %4\n"
974 + "strexeq %0, %5, [%3]\n"
975 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
977 + : "cc");
978 + } while (res);
979 +
980 + smp_mb();
981 +
982 + return oldval;
983 +}
984 +
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992 +
993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994 +{
995 + return atomic_add_return(i, v);
996 +}
997 +
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000 +{
1001 + (void) atomic_add_return(i, v);
1002 +}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011 +{
1012 + (void) atomic_sub_return(i, v);
1013 +}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022 +{
1023 + return atomic_cmpxchg(v, old, new);
1024 +}
1025 +
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034 +{
1035 + return xchg(&v->counter, new);
1036 +}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045 +{
1046 + atomic_add_unchecked(1, v);
1047 +}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050 +{
1051 + atomic_sub_unchecked(1, v);
1052 +}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056 +{
1057 + return atomic_add_return_unchecked(1, v) == 0;
1058 +}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062 +{
1063 + return atomic_add_return_unchecked(1, v);
1064 +}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068 @@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072 +#ifdef CONFIG_PAX_REFCOUNT
1073 +typedef struct {
1074 + u64 __aligned(8) counter;
1075 +} atomic64_unchecked_t;
1076 +#else
1077 +typedef atomic64_t atomic64_unchecked_t;
1078 +#endif
1079 +
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088 +{
1089 + u64 result;
1090 +
1091 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092 +" ldrexd %0, %H0, [%1]"
1093 + : "=&r" (result)
1094 + : "r" (&v->counter), "Qo" (v->counter)
1095 + );
1096 +
1097 + return result;
1098 +}
1099 +
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108 +{
1109 + u64 tmp;
1110 +
1111 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112 +"1: ldrexd %0, %H0, [%2]\n"
1113 +" strexd %0, %3, %H3, [%2]\n"
1114 +" teq %0, #0\n"
1115 +" bne 1b"
1116 + : "=&r" (tmp), "=Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128 +" adcs %H0, %H0, %H4\n"
1129 +
1130 +#ifdef CONFIG_PAX_REFCOUNT
1131 +" bvc 3f\n"
1132 +"2: bkpt 0xf103\n"
1133 +"3:\n"
1134 +#endif
1135 +
1136 +" strexd %1, %0, %H0, [%3]\n"
1137 +" teq %1, #0\n"
1138 +" bne 1b"
1139 +
1140 +#ifdef CONFIG_PAX_REFCOUNT
1141 +"\n4:\n"
1142 + _ASM_EXTABLE(2b, 4b)
1143 +#endif
1144 +
1145 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146 + : "r" (&v->counter), "r" (i)
1147 + : "cc");
1148 +}
1149 +
1150 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151 +{
1152 + u64 result;
1153 + unsigned long tmp;
1154 +
1155 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156 +"1: ldrexd %0, %H0, [%3]\n"
1157 +" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165 - u64 result;
1166 - unsigned long tmp;
1167 + u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" adds %0, %1, %4\n"
1174 +" adcs %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 +" strexd %1, %0, %H0, [%3]\n"
1185 +" teq %1, #0\n"
1186 +" bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 + : "r" (&v->counter), "r" (i)
1195 + : "cc");
1196 +
1197 + smp_mb();
1198 +
1199 + return result;
1200 +}
1201 +
1202 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203 +{
1204 + u64 result;
1205 + unsigned long tmp;
1206 +
1207 + smp_mb();
1208 +
1209 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217 +" sbcs %H0, %H0, %H4\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +"2: bkpt 0xf103\n"
1222 +"3:\n"
1223 +#endif
1224 +
1225 +" strexd %1, %0, %H0, [%3]\n"
1226 +" teq %1, #0\n"
1227 +" bne 1b"
1228 +
1229 +#ifdef CONFIG_PAX_REFCOUNT
1230 +"\n4:\n"
1231 + _ASM_EXTABLE(2b, 4b)
1232 +#endif
1233 +
1234 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235 + : "r" (&v->counter), "r" (i)
1236 + : "cc");
1237 +}
1238 +
1239 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245 +"1: ldrexd %0, %H0, [%3]\n"
1246 +" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254 - u64 result;
1255 - unsigned long tmp;
1256 + u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261 -"1: ldrexd %0, %H0, [%3]\n"
1262 -" subs %0, %0, %4\n"
1263 -" sbc %H0, %H0, %H4\n"
1264 +"1: ldrexd %1, %H1, [%3]\n"
1265 +" subs %0, %1, %4\n"
1266 +" sbcs %H0, %H1, %H4\n"
1267 +
1268 +#ifdef CONFIG_PAX_REFCOUNT
1269 +" bvc 3f\n"
1270 +" mov %0, %1\n"
1271 +" mov %H0, %H1\n"
1272 +"2: bkpt 0xf103\n"
1273 +"3:\n"
1274 +#endif
1275 +
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279 +
1280 +#ifdef CONFIG_PAX_REFCOUNT
1281 +"\n4:\n"
1282 + _ASM_EXTABLE(2b, 4b)
1283 +#endif
1284 +
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293 +{
1294 + u64 oldval;
1295 + unsigned long res;
1296 +
1297 + smp_mb();
1298 +
1299 + do {
1300 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301 + "ldrexd %1, %H1, [%3]\n"
1302 + "mov %0, #0\n"
1303 + "teq %1, %4\n"
1304 + "teqeq %H1, %H4\n"
1305 + "strexdeq %0, %5, %H5, [%3]"
1306 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307 + : "r" (&ptr->counter), "r" (old), "r" (new)
1308 + : "cc");
1309 + } while (res);
1310 +
1311 + smp_mb();
1312 +
1313 + return oldval;
1314 +}
1315 +
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323 - u64 result;
1324 - unsigned long tmp;
1325 + u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330 -"1: ldrexd %0, %H0, [%3]\n"
1331 -" subs %0, %0, #1\n"
1332 -" sbc %H0, %H0, #0\n"
1333 +"1: ldrexd %1, %H1, [%3]\n"
1334 +" subs %0, %1, #1\n"
1335 +" sbcs %H0, %H1, #0\n"
1336 +
1337 +#ifdef CONFIG_PAX_REFCOUNT
1338 +" bvc 3f\n"
1339 +" mov %0, %1\n"
1340 +" mov %H0, %H1\n"
1341 +"2: bkpt 0xf103\n"
1342 +"3:\n"
1343 +#endif
1344 +
1345 " teq %H0, #0\n"
1346 -" bmi 2f\n"
1347 +" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351 -"2:"
1352 +"4:\n"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 + _ASM_EXTABLE(2b, 4b)
1356 +#endif
1357 +
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365 -" beq 2f\n"
1366 +" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368 -" adc %H0, %H0, %H6\n"
1369 +" adcs %H0, %H0, %H6\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +"2: bkpt 0xf103\n"
1374 +"3:\n"
1375 +#endif
1376 +
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380 -"2:"
1381 +"4:\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 + _ASM_EXTABLE(2b, 4b)
1385 +#endif
1386 +
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405 index 75fe66b..2255c86 100644
1406 --- a/arch/arm/include/asm/cache.h
1407 +++ b/arch/arm/include/asm/cache.h
1408 @@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412 +#include <linux/const.h>
1413 +
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1421 index e1489c5..d418304 100644
1422 --- a/arch/arm/include/asm/cacheflush.h
1423 +++ b/arch/arm/include/asm/cacheflush.h
1424 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1425 void (*dma_unmap_area)(const void *, size_t, int);
1426
1427 void (*dma_flush_range)(const void *, const void *);
1428 -};
1429 +} __no_const;
1430
1431 /*
1432 * Select the calling method
1433 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1434 index 7eb18c1..e38b6d2 100644
1435 --- a/arch/arm/include/asm/cmpxchg.h
1436 +++ b/arch/arm/include/asm/cmpxchg.h
1437 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441 +#define xchg_unchecked(ptr,x) \
1442 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 #include <asm-generic/cmpxchg-local.h>
1445
1446 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1447 index 38050b1..9d90e8b 100644
1448 --- a/arch/arm/include/asm/elf.h
1449 +++ b/arch/arm/include/asm/elf.h
1450 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1451 the loader. We need to make sure that it is out of the way of the program
1452 that it will "exec", and that there is sufficient room for the brk. */
1453
1454 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1455 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1456 +
1457 +#ifdef CONFIG_PAX_ASLR
1458 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1459 +
1460 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1461 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1462 +#endif
1463
1464 /* When the program starts, a1 contains a pointer to a function to be
1465 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1466 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1467 extern void elf_set_personality(const struct elf32_hdr *);
1468 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1469
1470 -struct mm_struct;
1471 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1472 -#define arch_randomize_brk arch_randomize_brk
1473 -
1474 #endif
1475 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1476 index 83eb2f7..ed77159 100644
1477 --- a/arch/arm/include/asm/kmap_types.h
1478 +++ b/arch/arm/include/asm/kmap_types.h
1479 @@ -4,6 +4,6 @@
1480 /*
1481 * This is the "bare minimum". AIO seems to require this.
1482 */
1483 -#define KM_TYPE_NR 16
1484 +#define KM_TYPE_NR 17
1485
1486 #endif
1487 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1488 index 53426c6..c7baff3 100644
1489 --- a/arch/arm/include/asm/outercache.h
1490 +++ b/arch/arm/include/asm/outercache.h
1491 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1492 #endif
1493 void (*set_debug)(unsigned long);
1494 void (*resume)(void);
1495 -};
1496 +} __no_const;
1497
1498 #ifdef CONFIG_OUTER_CACHE
1499
1500 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1501 index 812a494..71fc0b6 100644
1502 --- a/arch/arm/include/asm/page.h
1503 +++ b/arch/arm/include/asm/page.h
1504 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1505 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1506 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1507 unsigned long vaddr, struct vm_area_struct *vma);
1508 -};
1509 +} __no_const;
1510
1511 #ifdef MULTI_USER
1512 extern struct cpu_user_fns cpu_user;
1513 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1514 index 943504f..bf8d667 100644
1515 --- a/arch/arm/include/asm/pgalloc.h
1516 +++ b/arch/arm/include/asm/pgalloc.h
1517 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1518 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1519 }
1520
1521 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1522 +{
1523 + pud_populate(mm, pud, pmd);
1524 +}
1525 +
1526 #else /* !CONFIG_ARM_LPAE */
1527
1528 /*
1529 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1530 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1531 #define pmd_free(mm, pmd) do { } while (0)
1532 #define pud_populate(mm,pmd,pte) BUG()
1533 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1534
1535 #endif /* CONFIG_ARM_LPAE */
1536
1537 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1538 index 8477b4c..801a6a9 100644
1539 --- a/arch/arm/include/asm/thread_info.h
1540 +++ b/arch/arm/include/asm/thread_info.h
1541 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_SYSCALL_TRACE 8
1543 #define TIF_SYSCALL_AUDIT 9
1544 #define TIF_SYSCALL_TRACEPOINT 10
1545 +
1546 +/* within 8 bits of TIF_SYSCALL_TRACE
1547 + to meet flexible second operand requirements
1548 +*/
1549 +#define TIF_GRSEC_SETXID 11
1550 +
1551 #define TIF_USING_IWMMXT 17
1552 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1553 #define TIF_RESTORE_SIGMASK 20
1554 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1556 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1557 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1558 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1559
1560 /* Checks for any syscall work in entry-common.S */
1561 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1562 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1563 + _TIF_GRSEC_SETXID)
1564
1565 /*
1566 * Change these and you break ASM code in entry-common.S
1567 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1568 index 7e1f760..1af891c 100644
1569 --- a/arch/arm/include/asm/uaccess.h
1570 +++ b/arch/arm/include/asm/uaccess.h
1571 @@ -22,6 +22,8 @@
1572 #define VERIFY_READ 0
1573 #define VERIFY_WRITE 1
1574
1575 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1576 +
1577 /*
1578 * The exception table consists of pairs of addresses: the first is the
1579 * address of an instruction that is allowed to fault, and the second is
1580 @@ -418,8 +420,23 @@ do { \
1581
1582
1583 #ifdef CONFIG_MMU
1584 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1585 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1586 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1587 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1588 +
1589 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1590 +{
1591 + if (!__builtin_constant_p(n))
1592 + check_object_size(to, n, false);
1593 + return ___copy_from_user(to, from, n);
1594 +}
1595 +
1596 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1597 +{
1598 + if (!__builtin_constant_p(n))
1599 + check_object_size(from, n, true);
1600 + return ___copy_to_user(to, from, n);
1601 +}
1602 +
1603 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1604 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1605 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1606 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1607
1608 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1609 {
1610 + if ((long)n < 0)
1611 + return n;
1612 +
1613 if (access_ok(VERIFY_READ, from, n))
1614 n = __copy_from_user(to, from, n);
1615 else /* security hole - plug it */
1616 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1617
1618 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1619 {
1620 + if ((long)n < 0)
1621 + return n;
1622 +
1623 if (access_ok(VERIFY_WRITE, to, n))
1624 n = __copy_to_user(to, from, n);
1625 return n;
1626 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1627 index 60d3b73..9168db0 100644
1628 --- a/arch/arm/kernel/armksyms.c
1629 +++ b/arch/arm/kernel/armksyms.c
1630 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1631 #ifdef CONFIG_MMU
1632 EXPORT_SYMBOL(copy_page);
1633
1634 -EXPORT_SYMBOL(__copy_from_user);
1635 -EXPORT_SYMBOL(__copy_to_user);
1636 +EXPORT_SYMBOL(___copy_from_user);
1637 +EXPORT_SYMBOL(___copy_to_user);
1638 EXPORT_SYMBOL(__clear_user);
1639
1640 EXPORT_SYMBOL(__get_user_1);
1641 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1642 index 90084a6..bf4bcfb 100644
1643 --- a/arch/arm/kernel/process.c
1644 +++ b/arch/arm/kernel/process.c
1645 @@ -28,7 +28,6 @@
1646 #include <linux/tick.h>
1647 #include <linux/utsname.h>
1648 #include <linux/uaccess.h>
1649 -#include <linux/random.h>
1650 #include <linux/hw_breakpoint.h>
1651 #include <linux/cpuidle.h>
1652 #include <linux/leds.h>
1653 @@ -256,9 +255,10 @@ void machine_power_off(void)
1654 machine_shutdown();
1655 if (pm_power_off)
1656 pm_power_off();
1657 + BUG();
1658 }
1659
1660 -void machine_restart(char *cmd)
1661 +__noreturn void machine_restart(char *cmd)
1662 {
1663 machine_shutdown();
1664
1665 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
1666 return 0;
1667 }
1668
1669 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1670 -{
1671 - unsigned long range_end = mm->brk + 0x02000000;
1672 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1673 -}
1674 -
1675 #ifdef CONFIG_MMU
1676 /*
1677 * The vectors page is always readable from user space for the
1678 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1679 index 739db3a..7f4a272 100644
1680 --- a/arch/arm/kernel/ptrace.c
1681 +++ b/arch/arm/kernel/ptrace.c
1682 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
1683 PTRACE_SYSCALL_EXIT,
1684 };
1685
1686 +#ifdef CONFIG_GRKERNSEC_SETXID
1687 +extern void gr_delayed_cred_worker(void);
1688 +#endif
1689 +
1690 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1691 enum ptrace_syscall_dir dir)
1692 {
1693 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1694
1695 current_thread_info()->syscall = scno;
1696
1697 +#ifdef CONFIG_GRKERNSEC_SETXID
1698 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1699 + gr_delayed_cred_worker();
1700 +#endif
1701 +
1702 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1703 return scno;
1704
1705 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1706 index da1d1aa..fea3ec9 100644
1707 --- a/arch/arm/kernel/setup.c
1708 +++ b/arch/arm/kernel/setup.c
1709 @@ -105,13 +105,13 @@ struct processor processor __read_mostly;
1710 struct cpu_tlb_fns cpu_tlb __read_mostly;
1711 #endif
1712 #ifdef MULTI_USER
1713 -struct cpu_user_fns cpu_user __read_mostly;
1714 +struct cpu_user_fns cpu_user __read_only;
1715 #endif
1716 #ifdef MULTI_CACHE
1717 -struct cpu_cache_fns cpu_cache __read_mostly;
1718 +struct cpu_cache_fns cpu_cache __read_only;
1719 #endif
1720 #ifdef CONFIG_OUTER_CACHE
1721 -struct outer_cache_fns outer_cache __read_mostly;
1722 +struct outer_cache_fns outer_cache __read_only;
1723 EXPORT_SYMBOL(outer_cache);
1724 #endif
1725
1726 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1727 index b0179b8..b54c6c1 100644
1728 --- a/arch/arm/kernel/traps.c
1729 +++ b/arch/arm/kernel/traps.c
1730 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1731 static int die_owner = -1;
1732 static unsigned int die_nest_count;
1733
1734 +extern void gr_handle_kernel_exploit(void);
1735 +
1736 static unsigned long oops_begin(void)
1737 {
1738 int cpu;
1739 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1740 panic("Fatal exception in interrupt");
1741 if (panic_on_oops)
1742 panic("Fatal exception");
1743 +
1744 + gr_handle_kernel_exploit();
1745 +
1746 if (signr)
1747 do_exit(signr);
1748 }
1749 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1750 index 66a477a..bee61d3 100644
1751 --- a/arch/arm/lib/copy_from_user.S
1752 +++ b/arch/arm/lib/copy_from_user.S
1753 @@ -16,7 +16,7 @@
1754 /*
1755 * Prototype:
1756 *
1757 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1758 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1759 *
1760 * Purpose:
1761 *
1762 @@ -84,11 +84,11 @@
1763
1764 .text
1765
1766 -ENTRY(__copy_from_user)
1767 +ENTRY(___copy_from_user)
1768
1769 #include "copy_template.S"
1770
1771 -ENDPROC(__copy_from_user)
1772 +ENDPROC(___copy_from_user)
1773
1774 .pushsection .fixup,"ax"
1775 .align 0
1776 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1777 index 6ee2f67..d1cce76 100644
1778 --- a/arch/arm/lib/copy_page.S
1779 +++ b/arch/arm/lib/copy_page.S
1780 @@ -10,6 +10,7 @@
1781 * ASM optimised string functions
1782 */
1783 #include <linux/linkage.h>
1784 +#include <linux/const.h>
1785 #include <asm/assembler.h>
1786 #include <asm/asm-offsets.h>
1787 #include <asm/cache.h>
1788 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1789 index d066df6..df28194 100644
1790 --- a/arch/arm/lib/copy_to_user.S
1791 +++ b/arch/arm/lib/copy_to_user.S
1792 @@ -16,7 +16,7 @@
1793 /*
1794 * Prototype:
1795 *
1796 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1797 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1798 *
1799 * Purpose:
1800 *
1801 @@ -88,11 +88,11 @@
1802 .text
1803
1804 ENTRY(__copy_to_user_std)
1805 -WEAK(__copy_to_user)
1806 +WEAK(___copy_to_user)
1807
1808 #include "copy_template.S"
1809
1810 -ENDPROC(__copy_to_user)
1811 +ENDPROC(___copy_to_user)
1812 ENDPROC(__copy_to_user_std)
1813
1814 .pushsection .fixup,"ax"
1815 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1816 index 025f742..8432b08 100644
1817 --- a/arch/arm/lib/uaccess_with_memcpy.c
1818 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1819 @@ -104,7 +104,7 @@ out:
1820 }
1821
1822 unsigned long
1823 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1824 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1825 {
1826 /*
1827 * This test is stubbed out of the main function above to keep
1828 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1829 index 2c6c218..f491e87 100644
1830 --- a/arch/arm/mach-kirkwood/common.c
1831 +++ b/arch/arm/mach-kirkwood/common.c
1832 @@ -150,7 +150,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1833 clk_gate_ops.disable(hw);
1834 }
1835
1836 -static struct clk_ops clk_gate_fn_ops;
1837 +static clk_ops_no_const clk_gate_fn_ops;
1838
1839 static struct clk __init *clk_register_gate_fn(struct device *dev,
1840 const char *name,
1841 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1842 index d95f727..12f10dd 100644
1843 --- a/arch/arm/mach-omap2/board-n8x0.c
1844 +++ b/arch/arm/mach-omap2/board-n8x0.c
1845 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1846 }
1847 #endif
1848
1849 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1850 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1851 .late_init = n8x0_menelaus_late_init,
1852 };
1853
1854 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
1855 index 87cc6d0..fd4f248 100644
1856 --- a/arch/arm/mach-omap2/omap_hwmod.c
1857 +++ b/arch/arm/mach-omap2/omap_hwmod.c
1858 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
1859 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
1860 struct omap_hwmod_rst_info *ohri);
1861 int (*init_clkdm)(struct omap_hwmod *oh);
1862 -};
1863 +} __no_const;
1864
1865 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
1866 -static struct omap_hwmod_soc_ops soc_ops;
1867 +static struct omap_hwmod_soc_ops soc_ops __read_only;
1868
1869 /* omap_hwmod_list contains all registered struct omap_hwmods */
1870 static LIST_HEAD(omap_hwmod_list);
1871 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1872 index 5dbf13f..d908372 100644
1873 --- a/arch/arm/mm/fault.c
1874 +++ b/arch/arm/mm/fault.c
1875 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1876 }
1877 #endif
1878
1879 +#ifdef CONFIG_PAX_PAGEEXEC
1880 + if (fsr & FSR_LNX_PF) {
1881 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1882 + do_group_exit(SIGKILL);
1883 + }
1884 +#endif
1885 +
1886 tsk->thread.address = addr;
1887 tsk->thread.error_code = fsr;
1888 tsk->thread.trap_no = 14;
1889 @@ -398,6 +405,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1890 }
1891 #endif /* CONFIG_MMU */
1892
1893 +#ifdef CONFIG_PAX_PAGEEXEC
1894 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1895 +{
1896 + long i;
1897 +
1898 + printk(KERN_ERR "PAX: bytes at PC: ");
1899 + for (i = 0; i < 20; i++) {
1900 + unsigned char c;
1901 + if (get_user(c, (__force unsigned char __user *)pc+i))
1902 + printk(KERN_CONT "?? ");
1903 + else
1904 + printk(KERN_CONT "%02x ", c);
1905 + }
1906 + printk("\n");
1907 +
1908 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1909 + for (i = -1; i < 20; i++) {
1910 + unsigned long c;
1911 + if (get_user(c, (__force unsigned long __user *)sp+i))
1912 + printk(KERN_CONT "???????? ");
1913 + else
1914 + printk(KERN_CONT "%08lx ", c);
1915 + }
1916 + printk("\n");
1917 +}
1918 +#endif
1919 +
1920 /*
1921 * First Level Translation Fault Handler
1922 *
1923 @@ -575,6 +609,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1924 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1925 struct siginfo info;
1926
1927 +#ifdef CONFIG_PAX_REFCOUNT
1928 + if (fsr_fs(ifsr) == 2) {
1929 + unsigned int bkpt;
1930 +
1931 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1932 + current->thread.error_code = ifsr;
1933 + current->thread.trap_no = 0;
1934 + pax_report_refcount_overflow(regs);
1935 + fixup_exception(regs);
1936 + return;
1937 + }
1938 + }
1939 +#endif
1940 +
1941 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1942 return;
1943
1944 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1945 index ce8cb19..3ec539d 100644
1946 --- a/arch/arm/mm/mmap.c
1947 +++ b/arch/arm/mm/mmap.c
1948 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1949 if (len > TASK_SIZE)
1950 return -ENOMEM;
1951
1952 +#ifdef CONFIG_PAX_RANDMMAP
1953 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1954 +#endif
1955 +
1956 if (addr) {
1957 if (do_align)
1958 addr = COLOUR_ALIGN(addr, pgoff);
1959 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1960 addr = PAGE_ALIGN(addr);
1961
1962 vma = find_vma(mm, addr);
1963 - if (TASK_SIZE - len >= addr &&
1964 - (!vma || addr + len <= vma->vm_start))
1965 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1966 return addr;
1967 }
1968 if (len > mm->cached_hole_size) {
1969 - start_addr = addr = mm->free_area_cache;
1970 + start_addr = addr = mm->free_area_cache;
1971 } else {
1972 - start_addr = addr = mm->mmap_base;
1973 - mm->cached_hole_size = 0;
1974 + start_addr = addr = mm->mmap_base;
1975 + mm->cached_hole_size = 0;
1976 }
1977
1978 full_search:
1979 @@ -124,14 +127,14 @@ full_search:
1980 * Start a new search - just in case we missed
1981 * some holes.
1982 */
1983 - if (start_addr != TASK_UNMAPPED_BASE) {
1984 - start_addr = addr = TASK_UNMAPPED_BASE;
1985 + if (start_addr != mm->mmap_base) {
1986 + start_addr = addr = mm->mmap_base;
1987 mm->cached_hole_size = 0;
1988 goto full_search;
1989 }
1990 return -ENOMEM;
1991 }
1992 - if (!vma || addr + len <= vma->vm_start) {
1993 + if (check_heap_stack_gap(vma, addr, len)) {
1994 /*
1995 * Remember the place where we stopped the search:
1996 */
1997 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1998
1999 if (mmap_is_legacy()) {
2000 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2001 +
2002 +#ifdef CONFIG_PAX_RANDMMAP
2003 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2004 + mm->mmap_base += mm->delta_mmap;
2005 +#endif
2006 +
2007 mm->get_unmapped_area = arch_get_unmapped_area;
2008 mm->unmap_area = arch_unmap_area;
2009 } else {
2010 mm->mmap_base = mmap_base(random_factor);
2011 +
2012 +#ifdef CONFIG_PAX_RANDMMAP
2013 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2014 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2015 +#endif
2016 +
2017 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2018 mm->unmap_area = arch_unmap_area_topdown;
2019 }
2020 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2021 index ec63e4a..62aa5f1d 100644
2022 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2023 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2024 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2025 value in bridge_virt_base */
2026 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2027 const int win);
2028 -};
2029 +} __no_const;
2030
2031 /*
2032 * Information needed to setup one address mapping.
2033 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2034 index f5144cd..71f6d1f 100644
2035 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2036 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2037 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2038 int (*started)(unsigned ch);
2039 int (*flush)(unsigned ch);
2040 int (*stop)(unsigned ch);
2041 -};
2042 +} __no_const;
2043
2044 extern void *samsung_dmadev_get_ops(void);
2045 extern void *s3c_dma_get_ops(void);
2046 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2047 index c3a58a1..78fbf54 100644
2048 --- a/arch/avr32/include/asm/cache.h
2049 +++ b/arch/avr32/include/asm/cache.h
2050 @@ -1,8 +1,10 @@
2051 #ifndef __ASM_AVR32_CACHE_H
2052 #define __ASM_AVR32_CACHE_H
2053
2054 +#include <linux/const.h>
2055 +
2056 #define L1_CACHE_SHIFT 5
2057 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2058 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2059
2060 /*
2061 * Memory returned by kmalloc() may be used for DMA, so we must make
2062 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2063 index e2c3287..6c4f98c 100644
2064 --- a/arch/avr32/include/asm/elf.h
2065 +++ b/arch/avr32/include/asm/elf.h
2066 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2067 the loader. We need to make sure that it is out of the way of the program
2068 that it will "exec", and that there is sufficient room for the brk. */
2069
2070 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2071 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2072
2073 +#ifdef CONFIG_PAX_ASLR
2074 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2075 +
2076 +#define PAX_DELTA_MMAP_LEN 15
2077 +#define PAX_DELTA_STACK_LEN 15
2078 +#endif
2079
2080 /* This yields a mask that user programs can use to figure out what
2081 instruction set this CPU supports. This could be done in user space,
2082 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2083 index 479330b..53717a8 100644
2084 --- a/arch/avr32/include/asm/kmap_types.h
2085 +++ b/arch/avr32/include/asm/kmap_types.h
2086 @@ -2,9 +2,9 @@
2087 #define __ASM_AVR32_KMAP_TYPES_H
2088
2089 #ifdef CONFIG_DEBUG_HIGHMEM
2090 -# define KM_TYPE_NR 29
2091 +# define KM_TYPE_NR 30
2092 #else
2093 -# define KM_TYPE_NR 14
2094 +# define KM_TYPE_NR 15
2095 #endif
2096
2097 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2098 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2099 index b2f2d2d..d1c85cb 100644
2100 --- a/arch/avr32/mm/fault.c
2101 +++ b/arch/avr32/mm/fault.c
2102 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2103
2104 int exception_trace = 1;
2105
2106 +#ifdef CONFIG_PAX_PAGEEXEC
2107 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2108 +{
2109 + unsigned long i;
2110 +
2111 + printk(KERN_ERR "PAX: bytes at PC: ");
2112 + for (i = 0; i < 20; i++) {
2113 + unsigned char c;
2114 + if (get_user(c, (unsigned char *)pc+i))
2115 + printk(KERN_CONT "???????? ");
2116 + else
2117 + printk(KERN_CONT "%02x ", c);
2118 + }
2119 + printk("\n");
2120 +}
2121 +#endif
2122 +
2123 /*
2124 * This routine handles page faults. It determines the address and the
2125 * problem, and then passes it off to one of the appropriate routines.
2126 @@ -174,6 +191,16 @@ bad_area:
2127 up_read(&mm->mmap_sem);
2128
2129 if (user_mode(regs)) {
2130 +
2131 +#ifdef CONFIG_PAX_PAGEEXEC
2132 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2133 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2134 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2135 + do_group_exit(SIGKILL);
2136 + }
2137 + }
2138 +#endif
2139 +
2140 if (exception_trace && printk_ratelimit())
2141 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2142 "sp %08lx ecr %lu\n",
2143 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2144 index 568885a..f8008df 100644
2145 --- a/arch/blackfin/include/asm/cache.h
2146 +++ b/arch/blackfin/include/asm/cache.h
2147 @@ -7,6 +7,7 @@
2148 #ifndef __ARCH_BLACKFIN_CACHE_H
2149 #define __ARCH_BLACKFIN_CACHE_H
2150
2151 +#include <linux/const.h>
2152 #include <linux/linkage.h> /* for asmlinkage */
2153
2154 /*
2155 @@ -14,7 +15,7 @@
2156 * Blackfin loads 32 bytes for cache
2157 */
2158 #define L1_CACHE_SHIFT 5
2159 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2160 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2161 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2162
2163 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2164 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2165 index aea2718..3639a60 100644
2166 --- a/arch/cris/include/arch-v10/arch/cache.h
2167 +++ b/arch/cris/include/arch-v10/arch/cache.h
2168 @@ -1,8 +1,9 @@
2169 #ifndef _ASM_ARCH_CACHE_H
2170 #define _ASM_ARCH_CACHE_H
2171
2172 +#include <linux/const.h>
2173 /* Etrax 100LX have 32-byte cache-lines. */
2174 -#define L1_CACHE_BYTES 32
2175 #define L1_CACHE_SHIFT 5
2176 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2177
2178 #endif /* _ASM_ARCH_CACHE_H */
2179 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2180 index 7caf25d..ee65ac5 100644
2181 --- a/arch/cris/include/arch-v32/arch/cache.h
2182 +++ b/arch/cris/include/arch-v32/arch/cache.h
2183 @@ -1,11 +1,12 @@
2184 #ifndef _ASM_CRIS_ARCH_CACHE_H
2185 #define _ASM_CRIS_ARCH_CACHE_H
2186
2187 +#include <linux/const.h>
2188 #include <arch/hwregs/dma.h>
2189
2190 /* A cache-line is 32 bytes. */
2191 -#define L1_CACHE_BYTES 32
2192 #define L1_CACHE_SHIFT 5
2193 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2194
2195 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2196
2197 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2198 index b86329d..6709906 100644
2199 --- a/arch/frv/include/asm/atomic.h
2200 +++ b/arch/frv/include/asm/atomic.h
2201 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2202 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2203 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2204
2205 +#define atomic64_read_unchecked(v) atomic64_read(v)
2206 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2207 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2208 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2209 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2210 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2211 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2212 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2213 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2214 +
2215 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2216 {
2217 int c, old;
2218 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2219 index 2797163..c2a401d 100644
2220 --- a/arch/frv/include/asm/cache.h
2221 +++ b/arch/frv/include/asm/cache.h
2222 @@ -12,10 +12,11 @@
2223 #ifndef __ASM_CACHE_H
2224 #define __ASM_CACHE_H
2225
2226 +#include <linux/const.h>
2227
2228 /* bytes per L1 cache line */
2229 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2230 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2231 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2232
2233 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2234 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2235 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2236 index 43901f2..0d8b865 100644
2237 --- a/arch/frv/include/asm/kmap_types.h
2238 +++ b/arch/frv/include/asm/kmap_types.h
2239 @@ -2,6 +2,6 @@
2240 #ifndef _ASM_KMAP_TYPES_H
2241 #define _ASM_KMAP_TYPES_H
2242
2243 -#define KM_TYPE_NR 17
2244 +#define KM_TYPE_NR 18
2245
2246 #endif
2247 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2248 index 385fd30..6c3d97e 100644
2249 --- a/arch/frv/mm/elf-fdpic.c
2250 +++ b/arch/frv/mm/elf-fdpic.c
2251 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2252 if (addr) {
2253 addr = PAGE_ALIGN(addr);
2254 vma = find_vma(current->mm, addr);
2255 - if (TASK_SIZE - len >= addr &&
2256 - (!vma || addr + len <= vma->vm_start))
2257 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2258 goto success;
2259 }
2260
2261 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2262 for (; vma; vma = vma->vm_next) {
2263 if (addr > limit)
2264 break;
2265 - if (addr + len <= vma->vm_start)
2266 + if (check_heap_stack_gap(vma, addr, len))
2267 goto success;
2268 addr = vma->vm_end;
2269 }
2270 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2271 for (; vma; vma = vma->vm_next) {
2272 if (addr > limit)
2273 break;
2274 - if (addr + len <= vma->vm_start)
2275 + if (check_heap_stack_gap(vma, addr, len))
2276 goto success;
2277 addr = vma->vm_end;
2278 }
2279 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2280 index f4ca594..adc72fd6 100644
2281 --- a/arch/hexagon/include/asm/cache.h
2282 +++ b/arch/hexagon/include/asm/cache.h
2283 @@ -21,9 +21,11 @@
2284 #ifndef __ASM_CACHE_H
2285 #define __ASM_CACHE_H
2286
2287 +#include <linux/const.h>
2288 +
2289 /* Bytes per L1 cache line */
2290 -#define L1_CACHE_SHIFT (5)
2291 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2292 +#define L1_CACHE_SHIFT 5
2293 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2294
2295 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2296 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2297 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2298 index 6e6fe18..a6ae668 100644
2299 --- a/arch/ia64/include/asm/atomic.h
2300 +++ b/arch/ia64/include/asm/atomic.h
2301 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2302 #define atomic64_inc(v) atomic64_add(1, (v))
2303 #define atomic64_dec(v) atomic64_sub(1, (v))
2304
2305 +#define atomic64_read_unchecked(v) atomic64_read(v)
2306 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2307 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2308 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2309 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2310 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2311 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2312 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2313 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2314 +
2315 /* Atomic operations are already serializing */
2316 #define smp_mb__before_atomic_dec() barrier()
2317 #define smp_mb__after_atomic_dec() barrier()
2318 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2319 index 988254a..e1ee885 100644
2320 --- a/arch/ia64/include/asm/cache.h
2321 +++ b/arch/ia64/include/asm/cache.h
2322 @@ -1,6 +1,7 @@
2323 #ifndef _ASM_IA64_CACHE_H
2324 #define _ASM_IA64_CACHE_H
2325
2326 +#include <linux/const.h>
2327
2328 /*
2329 * Copyright (C) 1998-2000 Hewlett-Packard Co
2330 @@ -9,7 +10,7 @@
2331
2332 /* Bytes per L1 (data) cache line. */
2333 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2334 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2335 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2336
2337 #ifdef CONFIG_SMP
2338 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2339 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2340 index b5298eb..67c6e62 100644
2341 --- a/arch/ia64/include/asm/elf.h
2342 +++ b/arch/ia64/include/asm/elf.h
2343 @@ -42,6 +42,13 @@
2344 */
2345 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2346
2347 +#ifdef CONFIG_PAX_ASLR
2348 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2349 +
2350 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2351 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2352 +#endif
2353 +
2354 #define PT_IA_64_UNWIND 0x70000001
2355
2356 /* IA-64 relocations: */
2357 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2358 index 96a8d92..617a1cf 100644
2359 --- a/arch/ia64/include/asm/pgalloc.h
2360 +++ b/arch/ia64/include/asm/pgalloc.h
2361 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2362 pgd_val(*pgd_entry) = __pa(pud);
2363 }
2364
2365 +static inline void
2366 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2367 +{
2368 + pgd_populate(mm, pgd_entry, pud);
2369 +}
2370 +
2371 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2372 {
2373 return quicklist_alloc(0, GFP_KERNEL, NULL);
2374 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2375 pud_val(*pud_entry) = __pa(pmd);
2376 }
2377
2378 +static inline void
2379 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2380 +{
2381 + pud_populate(mm, pud_entry, pmd);
2382 +}
2383 +
2384 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2385 {
2386 return quicklist_alloc(0, GFP_KERNEL, NULL);
2387 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2388 index 815810c..d60bd4c 100644
2389 --- a/arch/ia64/include/asm/pgtable.h
2390 +++ b/arch/ia64/include/asm/pgtable.h
2391 @@ -12,7 +12,7 @@
2392 * David Mosberger-Tang <davidm@hpl.hp.com>
2393 */
2394
2395 -
2396 +#include <linux/const.h>
2397 #include <asm/mman.h>
2398 #include <asm/page.h>
2399 #include <asm/processor.h>
2400 @@ -142,6 +142,17 @@
2401 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2402 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2403 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2404 +
2405 +#ifdef CONFIG_PAX_PAGEEXEC
2406 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2407 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2408 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2409 +#else
2410 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2411 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2412 +# define PAGE_COPY_NOEXEC PAGE_COPY
2413 +#endif
2414 +
2415 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2416 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2417 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2418 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2419 index 54ff557..70c88b7 100644
2420 --- a/arch/ia64/include/asm/spinlock.h
2421 +++ b/arch/ia64/include/asm/spinlock.h
2422 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2423 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2424
2425 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2426 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2427 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2428 }
2429
2430 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2431 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2432 index 449c8c0..432a3d2 100644
2433 --- a/arch/ia64/include/asm/uaccess.h
2434 +++ b/arch/ia64/include/asm/uaccess.h
2435 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2436 const void *__cu_from = (from); \
2437 long __cu_len = (n); \
2438 \
2439 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2440 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2441 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2442 __cu_len; \
2443 })
2444 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2445 long __cu_len = (n); \
2446 \
2447 __chk_user_ptr(__cu_from); \
2448 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2449 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2450 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2451 __cu_len; \
2452 })
2453 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2454 index 24603be..948052d 100644
2455 --- a/arch/ia64/kernel/module.c
2456 +++ b/arch/ia64/kernel/module.c
2457 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2458 void
2459 module_free (struct module *mod, void *module_region)
2460 {
2461 - if (mod && mod->arch.init_unw_table &&
2462 - module_region == mod->module_init) {
2463 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2464 unw_remove_unwind_table(mod->arch.init_unw_table);
2465 mod->arch.init_unw_table = NULL;
2466 }
2467 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2468 }
2469
2470 static inline int
2471 +in_init_rx (const struct module *mod, uint64_t addr)
2472 +{
2473 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2474 +}
2475 +
2476 +static inline int
2477 +in_init_rw (const struct module *mod, uint64_t addr)
2478 +{
2479 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2480 +}
2481 +
2482 +static inline int
2483 in_init (const struct module *mod, uint64_t addr)
2484 {
2485 - return addr - (uint64_t) mod->module_init < mod->init_size;
2486 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2487 +}
2488 +
2489 +static inline int
2490 +in_core_rx (const struct module *mod, uint64_t addr)
2491 +{
2492 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2493 +}
2494 +
2495 +static inline int
2496 +in_core_rw (const struct module *mod, uint64_t addr)
2497 +{
2498 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2499 }
2500
2501 static inline int
2502 in_core (const struct module *mod, uint64_t addr)
2503 {
2504 - return addr - (uint64_t) mod->module_core < mod->core_size;
2505 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2506 }
2507
2508 static inline int
2509 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2510 break;
2511
2512 case RV_BDREL:
2513 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2514 + if (in_init_rx(mod, val))
2515 + val -= (uint64_t) mod->module_init_rx;
2516 + else if (in_init_rw(mod, val))
2517 + val -= (uint64_t) mod->module_init_rw;
2518 + else if (in_core_rx(mod, val))
2519 + val -= (uint64_t) mod->module_core_rx;
2520 + else if (in_core_rw(mod, val))
2521 + val -= (uint64_t) mod->module_core_rw;
2522 break;
2523
2524 case RV_LTV:
2525 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2526 * addresses have been selected...
2527 */
2528 uint64_t gp;
2529 - if (mod->core_size > MAX_LTOFF)
2530 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2531 /*
2532 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2533 * at the end of the module.
2534 */
2535 - gp = mod->core_size - MAX_LTOFF / 2;
2536 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2537 else
2538 - gp = mod->core_size / 2;
2539 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2540 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2541 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2542 mod->arch.gp = gp;
2543 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2544 }
2545 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2546 index d9439ef..b9a4303 100644
2547 --- a/arch/ia64/kernel/sys_ia64.c
2548 +++ b/arch/ia64/kernel/sys_ia64.c
2549 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2550 if (REGION_NUMBER(addr) == RGN_HPAGE)
2551 addr = 0;
2552 #endif
2553 +
2554 +#ifdef CONFIG_PAX_RANDMMAP
2555 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2556 + addr = mm->free_area_cache;
2557 + else
2558 +#endif
2559 +
2560 if (!addr)
2561 addr = mm->free_area_cache;
2562
2563 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2564 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2565 /* At this point: (!vma || addr < vma->vm_end). */
2566 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2567 - if (start_addr != TASK_UNMAPPED_BASE) {
2568 + if (start_addr != mm->mmap_base) {
2569 /* Start a new search --- just in case we missed some holes. */
2570 - addr = TASK_UNMAPPED_BASE;
2571 + addr = mm->mmap_base;
2572 goto full_search;
2573 }
2574 return -ENOMEM;
2575 }
2576 - if (!vma || addr + len <= vma->vm_start) {
2577 + if (check_heap_stack_gap(vma, addr, len)) {
2578 /* Remember the address where we stopped this search: */
2579 mm->free_area_cache = addr + len;
2580 return addr;
2581 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2582 index 0ccb28f..8992469 100644
2583 --- a/arch/ia64/kernel/vmlinux.lds.S
2584 +++ b/arch/ia64/kernel/vmlinux.lds.S
2585 @@ -198,7 +198,7 @@ SECTIONS {
2586 /* Per-cpu data: */
2587 . = ALIGN(PERCPU_PAGE_SIZE);
2588 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2589 - __phys_per_cpu_start = __per_cpu_load;
2590 + __phys_per_cpu_start = per_cpu_load;
2591 /*
2592 * ensure percpu data fits
2593 * into percpu page size
2594 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2595 index 6cf0341..d352594 100644
2596 --- a/arch/ia64/mm/fault.c
2597 +++ b/arch/ia64/mm/fault.c
2598 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2599 return pte_present(pte);
2600 }
2601
2602 +#ifdef CONFIG_PAX_PAGEEXEC
2603 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2604 +{
2605 + unsigned long i;
2606 +
2607 + printk(KERN_ERR "PAX: bytes at PC: ");
2608 + for (i = 0; i < 8; i++) {
2609 + unsigned int c;
2610 + if (get_user(c, (unsigned int *)pc+i))
2611 + printk(KERN_CONT "???????? ");
2612 + else
2613 + printk(KERN_CONT "%08x ", c);
2614 + }
2615 + printk("\n");
2616 +}
2617 +#endif
2618 +
2619 # define VM_READ_BIT 0
2620 # define VM_WRITE_BIT 1
2621 # define VM_EXEC_BIT 2
2622 @@ -149,8 +166,21 @@ retry:
2623 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2624 goto bad_area;
2625
2626 - if ((vma->vm_flags & mask) != mask)
2627 + if ((vma->vm_flags & mask) != mask) {
2628 +
2629 +#ifdef CONFIG_PAX_PAGEEXEC
2630 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2631 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2632 + goto bad_area;
2633 +
2634 + up_read(&mm->mmap_sem);
2635 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2636 + do_group_exit(SIGKILL);
2637 + }
2638 +#endif
2639 +
2640 goto bad_area;
2641 + }
2642
2643 /*
2644 * If for any reason at all we couldn't handle the fault, make
2645 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2646 index 5ca674b..e0e1b70 100644
2647 --- a/arch/ia64/mm/hugetlbpage.c
2648 +++ b/arch/ia64/mm/hugetlbpage.c
2649 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2650 /* At this point: (!vmm || addr < vmm->vm_end). */
2651 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2652 return -ENOMEM;
2653 - if (!vmm || (addr + len) <= vmm->vm_start)
2654 + if (check_heap_stack_gap(vmm, addr, len))
2655 return addr;
2656 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2657 }
2658 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2659 index 082e383..fb7be80 100644
2660 --- a/arch/ia64/mm/init.c
2661 +++ b/arch/ia64/mm/init.c
2662 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2663 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2664 vma->vm_end = vma->vm_start + PAGE_SIZE;
2665 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2666 +
2667 +#ifdef CONFIG_PAX_PAGEEXEC
2668 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2669 + vma->vm_flags &= ~VM_EXEC;
2670 +
2671 +#ifdef CONFIG_PAX_MPROTECT
2672 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2673 + vma->vm_flags &= ~VM_MAYEXEC;
2674 +#endif
2675 +
2676 + }
2677 +#endif
2678 +
2679 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2680 down_write(&current->mm->mmap_sem);
2681 if (insert_vm_struct(current->mm, vma)) {
2682 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2683 index 40b3ee9..8c2c112 100644
2684 --- a/arch/m32r/include/asm/cache.h
2685 +++ b/arch/m32r/include/asm/cache.h
2686 @@ -1,8 +1,10 @@
2687 #ifndef _ASM_M32R_CACHE_H
2688 #define _ASM_M32R_CACHE_H
2689
2690 +#include <linux/const.h>
2691 +
2692 /* L1 cache line size */
2693 #define L1_CACHE_SHIFT 4
2694 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2695 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2696
2697 #endif /* _ASM_M32R_CACHE_H */
2698 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2699 index 82abd15..d95ae5d 100644
2700 --- a/arch/m32r/lib/usercopy.c
2701 +++ b/arch/m32r/lib/usercopy.c
2702 @@ -14,6 +14,9 @@
2703 unsigned long
2704 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2705 {
2706 + if ((long)n < 0)
2707 + return n;
2708 +
2709 prefetch(from);
2710 if (access_ok(VERIFY_WRITE, to, n))
2711 __copy_user(to,from,n);
2712 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2713 unsigned long
2714 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2715 {
2716 + if ((long)n < 0)
2717 + return n;
2718 +
2719 prefetchw(to);
2720 if (access_ok(VERIFY_READ, from, n))
2721 __copy_user_zeroing(to,from,n);
2722 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2723 index 0395c51..5f26031 100644
2724 --- a/arch/m68k/include/asm/cache.h
2725 +++ b/arch/m68k/include/asm/cache.h
2726 @@ -4,9 +4,11 @@
2727 #ifndef __ARCH_M68K_CACHE_H
2728 #define __ARCH_M68K_CACHE_H
2729
2730 +#include <linux/const.h>
2731 +
2732 /* bytes per L1 cache line */
2733 #define L1_CACHE_SHIFT 4
2734 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2735 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2736
2737 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2738
2739 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2740 index 4efe96a..60e8699 100644
2741 --- a/arch/microblaze/include/asm/cache.h
2742 +++ b/arch/microblaze/include/asm/cache.h
2743 @@ -13,11 +13,12 @@
2744 #ifndef _ASM_MICROBLAZE_CACHE_H
2745 #define _ASM_MICROBLAZE_CACHE_H
2746
2747 +#include <linux/const.h>
2748 #include <asm/registers.h>
2749
2750 #define L1_CACHE_SHIFT 5
2751 /* word-granular cache in microblaze */
2752 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2753 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2754
2755 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2756
2757 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2758 index 01cc6ba..bcb7a5d 100644
2759 --- a/arch/mips/include/asm/atomic.h
2760 +++ b/arch/mips/include/asm/atomic.h
2761 @@ -21,6 +21,10 @@
2762 #include <asm/cmpxchg.h>
2763 #include <asm/war.h>
2764
2765 +#ifdef CONFIG_GENERIC_ATOMIC64
2766 +#include <asm-generic/atomic64.h>
2767 +#endif
2768 +
2769 #define ATOMIC_INIT(i) { (i) }
2770
2771 /*
2772 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2773 */
2774 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2775
2776 +#define atomic64_read_unchecked(v) atomic64_read(v)
2777 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2778 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2779 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2780 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2781 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2782 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2783 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2784 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2785 +
2786 #endif /* CONFIG_64BIT */
2787
2788 /*
2789 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2790 index b4db69f..8f3b093 100644
2791 --- a/arch/mips/include/asm/cache.h
2792 +++ b/arch/mips/include/asm/cache.h
2793 @@ -9,10 +9,11 @@
2794 #ifndef _ASM_CACHE_H
2795 #define _ASM_CACHE_H
2796
2797 +#include <linux/const.h>
2798 #include <kmalloc.h>
2799
2800 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2801 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2802 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2803
2804 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2805 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2806 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2807 index 455c0ac..ad65fbe 100644
2808 --- a/arch/mips/include/asm/elf.h
2809 +++ b/arch/mips/include/asm/elf.h
2810 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2811 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2812 #endif
2813
2814 +#ifdef CONFIG_PAX_ASLR
2815 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2816 +
2817 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2818 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2819 +#endif
2820 +
2821 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2822 struct linux_binprm;
2823 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2824 int uses_interp);
2825
2826 -struct mm_struct;
2827 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2828 -#define arch_randomize_brk arch_randomize_brk
2829 -
2830 #endif /* _ASM_ELF_H */
2831 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2832 index c1f6afa..38cc6e9 100644
2833 --- a/arch/mips/include/asm/exec.h
2834 +++ b/arch/mips/include/asm/exec.h
2835 @@ -12,6 +12,6 @@
2836 #ifndef _ASM_EXEC_H
2837 #define _ASM_EXEC_H
2838
2839 -extern unsigned long arch_align_stack(unsigned long sp);
2840 +#define arch_align_stack(x) ((x) & ~0xfUL)
2841
2842 #endif /* _ASM_EXEC_H */
2843 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2844 index da9bd7d..91aa7ab 100644
2845 --- a/arch/mips/include/asm/page.h
2846 +++ b/arch/mips/include/asm/page.h
2847 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2848 #ifdef CONFIG_CPU_MIPS32
2849 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2850 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2851 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2852 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2853 #else
2854 typedef struct { unsigned long long pte; } pte_t;
2855 #define pte_val(x) ((x).pte)
2856 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2857 index 881d18b..cea38bc 100644
2858 --- a/arch/mips/include/asm/pgalloc.h
2859 +++ b/arch/mips/include/asm/pgalloc.h
2860 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2861 {
2862 set_pud(pud, __pud((unsigned long)pmd));
2863 }
2864 +
2865 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2866 +{
2867 + pud_populate(mm, pud, pmd);
2868 +}
2869 #endif
2870
2871 /*
2872 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2873 index 18806a5..141ffcf 100644
2874 --- a/arch/mips/include/asm/thread_info.h
2875 +++ b/arch/mips/include/asm/thread_info.h
2876 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2877 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2878 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2879 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2880 +/* li takes a 32bit immediate */
2881 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2882 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2883
2884 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
2885 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2886 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2887 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2888 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2889 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2890 +
2891 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2892
2893 /* work to do in syscall_trace_leave() */
2894 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2895 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2896
2897 /* work to do on interrupt/exception return */
2898 #define _TIF_WORK_MASK \
2899 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
2900 /* work to do on any return to u-space */
2901 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
2902 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
2903
2904 #endif /* __KERNEL__ */
2905
2906 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2907 index 9fdd8bc..4bd7f1a 100644
2908 --- a/arch/mips/kernel/binfmt_elfn32.c
2909 +++ b/arch/mips/kernel/binfmt_elfn32.c
2910 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2911 #undef ELF_ET_DYN_BASE
2912 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2913
2914 +#ifdef CONFIG_PAX_ASLR
2915 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2916 +
2917 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2918 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2919 +#endif
2920 +
2921 #include <asm/processor.h>
2922 #include <linux/module.h>
2923 #include <linux/elfcore.h>
2924 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2925 index ff44823..97f8906 100644
2926 --- a/arch/mips/kernel/binfmt_elfo32.c
2927 +++ b/arch/mips/kernel/binfmt_elfo32.c
2928 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2929 #undef ELF_ET_DYN_BASE
2930 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2931
2932 +#ifdef CONFIG_PAX_ASLR
2933 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2934 +
2935 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2936 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2937 +#endif
2938 +
2939 #include <asm/processor.h>
2940
2941 /*
2942 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2943 index e9a5fd7..378809a 100644
2944 --- a/arch/mips/kernel/process.c
2945 +++ b/arch/mips/kernel/process.c
2946 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2947 out:
2948 return pc;
2949 }
2950 -
2951 -/*
2952 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2953 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2954 - */
2955 -unsigned long arch_align_stack(unsigned long sp)
2956 -{
2957 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2958 - sp -= get_random_int() & ~PAGE_MASK;
2959 -
2960 - return sp & ALMASK;
2961 -}
2962 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2963 index 4812c6d..2069554 100644
2964 --- a/arch/mips/kernel/ptrace.c
2965 +++ b/arch/mips/kernel/ptrace.c
2966 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2967 return arch;
2968 }
2969
2970 +#ifdef CONFIG_GRKERNSEC_SETXID
2971 +extern void gr_delayed_cred_worker(void);
2972 +#endif
2973 +
2974 /*
2975 * Notification of system call entry/exit
2976 * - triggered by current->work.syscall_trace
2977 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2978 /* do the secure computing check first */
2979 secure_computing_strict(regs->regs[2]);
2980
2981 +#ifdef CONFIG_GRKERNSEC_SETXID
2982 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2983 + gr_delayed_cred_worker();
2984 +#endif
2985 +
2986 if (!(current->ptrace & PT_PTRACED))
2987 goto out;
2988
2989 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
2990 index 374f66e..1c882a0 100644
2991 --- a/arch/mips/kernel/scall32-o32.S
2992 +++ b/arch/mips/kernel/scall32-o32.S
2993 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
2994
2995 stack_done:
2996 lw t0, TI_FLAGS($28) # syscall tracing enabled?
2997 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
2998 + li t1, _TIF_SYSCALL_WORK
2999 and t0, t1
3000 bnez t0, syscall_trace_entry # -> yes
3001
3002 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3003 index 169de6a..f594a89 100644
3004 --- a/arch/mips/kernel/scall64-64.S
3005 +++ b/arch/mips/kernel/scall64-64.S
3006 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3007
3008 sd a3, PT_R26(sp) # save a3 for syscall restarting
3009
3010 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3011 + li t1, _TIF_SYSCALL_WORK
3012 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3013 and t0, t1, t0
3014 bnez t0, syscall_trace_entry
3015 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3016 index 86ec03f..1235baf 100644
3017 --- a/arch/mips/kernel/scall64-n32.S
3018 +++ b/arch/mips/kernel/scall64-n32.S
3019 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3020
3021 sd a3, PT_R26(sp) # save a3 for syscall restarting
3022
3023 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3024 + li t1, _TIF_SYSCALL_WORK
3025 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3026 and t0, t1, t0
3027 bnez t0, n32_syscall_trace_entry
3028 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3029 index 53c2d72..3734584 100644
3030 --- a/arch/mips/kernel/scall64-o32.S
3031 +++ b/arch/mips/kernel/scall64-o32.S
3032 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3033 PTR 4b, bad_stack
3034 .previous
3035
3036 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3037 + li t1, _TIF_SYSCALL_WORK
3038 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3039 and t0, t1, t0
3040 bnez t0, trace_a_syscall
3041 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3042 index ddcec1e..c7f983e 100644
3043 --- a/arch/mips/mm/fault.c
3044 +++ b/arch/mips/mm/fault.c
3045 @@ -27,6 +27,23 @@
3046 #include <asm/highmem.h> /* For VMALLOC_END */
3047 #include <linux/kdebug.h>
3048
3049 +#ifdef CONFIG_PAX_PAGEEXEC
3050 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3051 +{
3052 + unsigned long i;
3053 +
3054 + printk(KERN_ERR "PAX: bytes at PC: ");
3055 + for (i = 0; i < 5; i++) {
3056 + unsigned int c;
3057 + if (get_user(c, (unsigned int *)pc+i))
3058 + printk(KERN_CONT "???????? ");
3059 + else
3060 + printk(KERN_CONT "%08x ", c);
3061 + }
3062 + printk("\n");
3063 +}
3064 +#endif
3065 +
3066 /*
3067 * This routine handles page faults. It determines the address,
3068 * and the problem, and then passes it off to one of the appropriate
3069 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3070 index 302d779..7d35bf8 100644
3071 --- a/arch/mips/mm/mmap.c
3072 +++ b/arch/mips/mm/mmap.c
3073 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3074 do_color_align = 1;
3075
3076 /* requesting a specific address */
3077 +
3078 +#ifdef CONFIG_PAX_RANDMMAP
3079 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3080 +#endif
3081 +
3082 if (addr) {
3083 if (do_color_align)
3084 addr = COLOUR_ALIGN(addr, pgoff);
3085 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3086 addr = PAGE_ALIGN(addr);
3087
3088 vma = find_vma(mm, addr);
3089 - if (TASK_SIZE - len >= addr &&
3090 - (!vma || addr + len <= vma->vm_start))
3091 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3092 return addr;
3093 }
3094
3095 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3096 /* At this point: (!vma || addr < vma->vm_end). */
3097 if (TASK_SIZE - len < addr)
3098 return -ENOMEM;
3099 - if (!vma || addr + len <= vma->vm_start)
3100 + if (check_heap_stack_gap(vmm, addr, len))
3101 return addr;
3102 addr = vma->vm_end;
3103 if (do_color_align)
3104 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3105 /* make sure it can fit in the remaining address space */
3106 if (likely(addr > len)) {
3107 vma = find_vma(mm, addr - len);
3108 - if (!vma || addr <= vma->vm_start) {
3109 + if (check_heap_stack_gap(vmm, addr - len, len))
3110 /* cache the address as a hint for next time */
3111 return mm->free_area_cache = addr - len;
3112 }
3113 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3114 * return with success:
3115 */
3116 vma = find_vma(mm, addr);
3117 - if (likely(!vma || addr + len <= vma->vm_start)) {
3118 + if (check_heap_stack_gap(vmm, addr, len)) {
3119 /* cache the address as a hint for next time */
3120 return mm->free_area_cache = addr;
3121 }
3122 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3123 mm->unmap_area = arch_unmap_area_topdown;
3124 }
3125 }
3126 -
3127 -static inline unsigned long brk_rnd(void)
3128 -{
3129 - unsigned long rnd = get_random_int();
3130 -
3131 - rnd = rnd << PAGE_SHIFT;
3132 - /* 8MB for 32bit, 256MB for 64bit */
3133 - if (TASK_IS_32BIT_ADDR)
3134 - rnd = rnd & 0x7ffffful;
3135 - else
3136 - rnd = rnd & 0xffffffful;
3137 -
3138 - return rnd;
3139 -}
3140 -
3141 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3142 -{
3143 - unsigned long base = mm->brk;
3144 - unsigned long ret;
3145 -
3146 - ret = PAGE_ALIGN(base + brk_rnd());
3147 -
3148 - if (ret < mm->brk)
3149 - return mm->brk;
3150 -
3151 - return ret;
3152 -}
3153 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3154 index 967d144..db12197 100644
3155 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3156 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3157 @@ -11,12 +11,14 @@
3158 #ifndef _ASM_PROC_CACHE_H
3159 #define _ASM_PROC_CACHE_H
3160
3161 +#include <linux/const.h>
3162 +
3163 /* L1 cache */
3164
3165 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3166 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3167 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3168 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3169 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3170 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3171
3172 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3173 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3174 index bcb5df2..84fabd2 100644
3175 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3176 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3177 @@ -16,13 +16,15 @@
3178 #ifndef _ASM_PROC_CACHE_H
3179 #define _ASM_PROC_CACHE_H
3180
3181 +#include <linux/const.h>
3182 +
3183 /*
3184 * L1 cache
3185 */
3186 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3187 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3188 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3189 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3190 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3191 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3192
3193 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3194 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3195 index 4ce7a01..449202a 100644
3196 --- a/arch/openrisc/include/asm/cache.h
3197 +++ b/arch/openrisc/include/asm/cache.h
3198 @@ -19,11 +19,13 @@
3199 #ifndef __ASM_OPENRISC_CACHE_H
3200 #define __ASM_OPENRISC_CACHE_H
3201
3202 +#include <linux/const.h>
3203 +
3204 /* FIXME: How can we replace these with values from the CPU...
3205 * they shouldn't be hard-coded!
3206 */
3207
3208 -#define L1_CACHE_BYTES 16
3209 #define L1_CACHE_SHIFT 4
3210 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3211
3212 #endif /* __ASM_OPENRISC_CACHE_H */
3213 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3214 index af9cf30..2aae9b2 100644
3215 --- a/arch/parisc/include/asm/atomic.h
3216 +++ b/arch/parisc/include/asm/atomic.h
3217 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3218
3219 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3220
3221 +#define atomic64_read_unchecked(v) atomic64_read(v)
3222 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3223 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3224 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3225 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3226 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3227 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3228 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3229 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3230 +
3231 #endif /* !CONFIG_64BIT */
3232
3233
3234 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3235 index 47f11c7..3420df2 100644
3236 --- a/arch/parisc/include/asm/cache.h
3237 +++ b/arch/parisc/include/asm/cache.h
3238 @@ -5,6 +5,7 @@
3239 #ifndef __ARCH_PARISC_CACHE_H
3240 #define __ARCH_PARISC_CACHE_H
3241
3242 +#include <linux/const.h>
3243
3244 /*
3245 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3246 @@ -15,13 +16,13 @@
3247 * just ruin performance.
3248 */
3249 #ifdef CONFIG_PA20
3250 -#define L1_CACHE_BYTES 64
3251 #define L1_CACHE_SHIFT 6
3252 #else
3253 -#define L1_CACHE_BYTES 32
3254 #define L1_CACHE_SHIFT 5
3255 #endif
3256
3257 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3258 +
3259 #ifndef __ASSEMBLY__
3260
3261 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3262 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3263 index 19f6cb1..6c78cf2 100644
3264 --- a/arch/parisc/include/asm/elf.h
3265 +++ b/arch/parisc/include/asm/elf.h
3266 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3267
3268 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3269
3270 +#ifdef CONFIG_PAX_ASLR
3271 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3272 +
3273 +#define PAX_DELTA_MMAP_LEN 16
3274 +#define PAX_DELTA_STACK_LEN 16
3275 +#endif
3276 +
3277 /* This yields a mask that user programs can use to figure out what
3278 instruction set this CPU supports. This could be done in user space,
3279 but it's not easy, and we've already done it here. */
3280 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3281 index fc987a1..6e068ef 100644
3282 --- a/arch/parisc/include/asm/pgalloc.h
3283 +++ b/arch/parisc/include/asm/pgalloc.h
3284 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3285 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3286 }
3287
3288 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3289 +{
3290 + pgd_populate(mm, pgd, pmd);
3291 +}
3292 +
3293 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3294 {
3295 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3296 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3297 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3298 #define pmd_free(mm, x) do { } while (0)
3299 #define pgd_populate(mm, pmd, pte) BUG()
3300 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3301
3302 #endif
3303
3304 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3305 index ee99f23..802b0a1 100644
3306 --- a/arch/parisc/include/asm/pgtable.h
3307 +++ b/arch/parisc/include/asm/pgtable.h
3308 @@ -212,6 +212,17 @@ struct vm_area_struct;
3309 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3310 #define PAGE_COPY PAGE_EXECREAD
3311 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3312 +
3313 +#ifdef CONFIG_PAX_PAGEEXEC
3314 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3315 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3316 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3317 +#else
3318 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3319 +# define PAGE_COPY_NOEXEC PAGE_COPY
3320 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3321 +#endif
3322 +
3323 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3324 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3325 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3326 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3327 index 4ba2c93..f5e3974 100644
3328 --- a/arch/parisc/include/asm/uaccess.h
3329 +++ b/arch/parisc/include/asm/uaccess.h
3330 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3331 const void __user *from,
3332 unsigned long n)
3333 {
3334 - int sz = __compiletime_object_size(to);
3335 + size_t sz = __compiletime_object_size(to);
3336 int ret = -EFAULT;
3337
3338 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3339 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3340 ret = __copy_from_user(to, from, n);
3341 else
3342 copy_from_user_overflow();
3343 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3344 index 5e34ccf..672bc9c 100644
3345 --- a/arch/parisc/kernel/module.c
3346 +++ b/arch/parisc/kernel/module.c
3347 @@ -98,16 +98,38 @@
3348
3349 /* three functions to determine where in the module core
3350 * or init pieces the location is */
3351 +static inline int in_init_rx(struct module *me, void *loc)
3352 +{
3353 + return (loc >= me->module_init_rx &&
3354 + loc < (me->module_init_rx + me->init_size_rx));
3355 +}
3356 +
3357 +static inline int in_init_rw(struct module *me, void *loc)
3358 +{
3359 + return (loc >= me->module_init_rw &&
3360 + loc < (me->module_init_rw + me->init_size_rw));
3361 +}
3362 +
3363 static inline int in_init(struct module *me, void *loc)
3364 {
3365 - return (loc >= me->module_init &&
3366 - loc <= (me->module_init + me->init_size));
3367 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3368 +}
3369 +
3370 +static inline int in_core_rx(struct module *me, void *loc)
3371 +{
3372 + return (loc >= me->module_core_rx &&
3373 + loc < (me->module_core_rx + me->core_size_rx));
3374 +}
3375 +
3376 +static inline int in_core_rw(struct module *me, void *loc)
3377 +{
3378 + return (loc >= me->module_core_rw &&
3379 + loc < (me->module_core_rw + me->core_size_rw));
3380 }
3381
3382 static inline int in_core(struct module *me, void *loc)
3383 {
3384 - return (loc >= me->module_core &&
3385 - loc <= (me->module_core + me->core_size));
3386 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3387 }
3388
3389 static inline int in_local(struct module *me, void *loc)
3390 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3391 }
3392
3393 /* align things a bit */
3394 - me->core_size = ALIGN(me->core_size, 16);
3395 - me->arch.got_offset = me->core_size;
3396 - me->core_size += gots * sizeof(struct got_entry);
3397 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3398 + me->arch.got_offset = me->core_size_rw;
3399 + me->core_size_rw += gots * sizeof(struct got_entry);
3400
3401 - me->core_size = ALIGN(me->core_size, 16);
3402 - me->arch.fdesc_offset = me->core_size;
3403 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3404 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3405 + me->arch.fdesc_offset = me->core_size_rw;
3406 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3407
3408 me->arch.got_max = gots;
3409 me->arch.fdesc_max = fdescs;
3410 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3411
3412 BUG_ON(value == 0);
3413
3414 - got = me->module_core + me->arch.got_offset;
3415 + got = me->module_core_rw + me->arch.got_offset;
3416 for (i = 0; got[i].addr; i++)
3417 if (got[i].addr == value)
3418 goto out;
3419 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3420 #ifdef CONFIG_64BIT
3421 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3422 {
3423 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3424 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3425
3426 if (!value) {
3427 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3428 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3429
3430 /* Create new one */
3431 fdesc->addr = value;
3432 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3433 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3434 return (Elf_Addr)fdesc;
3435 }
3436 #endif /* CONFIG_64BIT */
3437 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3438
3439 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3440 end = table + sechdrs[me->arch.unwind_section].sh_size;
3441 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3442 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3443
3444 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3445 me->arch.unwind_section, table, end, gp);
3446 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3447 index f76c108..8117482 100644
3448 --- a/arch/parisc/kernel/sys_parisc.c
3449 +++ b/arch/parisc/kernel/sys_parisc.c
3450 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3451 /* At this point: (!vma || addr < vma->vm_end). */
3452 if (TASK_SIZE - len < addr)
3453 return -ENOMEM;
3454 - if (!vma || addr + len <= vma->vm_start)
3455 + if (check_heap_stack_gap(vma, addr, len))
3456 return addr;
3457 addr = vma->vm_end;
3458 }
3459 @@ -81,7 +81,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3460 /* At this point: (!vma || addr < vma->vm_end). */
3461 if (TASK_SIZE - len < addr)
3462 return -ENOMEM;
3463 - if (!vma || addr + len <= vma->vm_start)
3464 + if (check_heap_stack_gap(vma, addr, len))
3465 return addr;
3466 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3467 if (addr < vma->vm_end) /* handle wraparound */
3468 @@ -100,7 +100,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3469 if (flags & MAP_FIXED)
3470 return addr;
3471 if (!addr)
3472 - addr = TASK_UNMAPPED_BASE;
3473 + addr = current->mm->mmap_base;
3474
3475 if (filp) {
3476 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3477 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3478 index 45ba99f..8e22c33 100644
3479 --- a/arch/parisc/kernel/traps.c
3480 +++ b/arch/parisc/kernel/traps.c
3481 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3482
3483 down_read(&current->mm->mmap_sem);
3484 vma = find_vma(current->mm,regs->iaoq[0]);
3485 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3486 - && (vma->vm_flags & VM_EXEC)) {
3487 -
3488 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3489 fault_address = regs->iaoq[0];
3490 fault_space = regs->iasq[0];
3491
3492 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3493 index 18162ce..94de376 100644
3494 --- a/arch/parisc/mm/fault.c
3495 +++ b/arch/parisc/mm/fault.c
3496 @@ -15,6 +15,7 @@
3497 #include <linux/sched.h>
3498 #include <linux/interrupt.h>
3499 #include <linux/module.h>
3500 +#include <linux/unistd.h>
3501
3502 #include <asm/uaccess.h>
3503 #include <asm/traps.h>
3504 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3505 static unsigned long
3506 parisc_acctyp(unsigned long code, unsigned int inst)
3507 {
3508 - if (code == 6 || code == 16)
3509 + if (code == 6 || code == 7 || code == 16)
3510 return VM_EXEC;
3511
3512 switch (inst & 0xf0000000) {
3513 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3514 }
3515 #endif
3516
3517 +#ifdef CONFIG_PAX_PAGEEXEC
3518 +/*
3519 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3520 + *
3521 + * returns 1 when task should be killed
3522 + * 2 when rt_sigreturn trampoline was detected
3523 + * 3 when unpatched PLT trampoline was detected
3524 + */
3525 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3526 +{
3527 +
3528 +#ifdef CONFIG_PAX_EMUPLT
3529 + int err;
3530 +
3531 + do { /* PaX: unpatched PLT emulation */
3532 + unsigned int bl, depwi;
3533 +
3534 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3535 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3536 +
3537 + if (err)
3538 + break;
3539 +
3540 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3541 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3542 +
3543 + err = get_user(ldw, (unsigned int *)addr);
3544 + err |= get_user(bv, (unsigned int *)(addr+4));
3545 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3546 +
3547 + if (err)
3548 + break;
3549 +
3550 + if (ldw == 0x0E801096U &&
3551 + bv == 0xEAC0C000U &&
3552 + ldw2 == 0x0E881095U)
3553 + {
3554 + unsigned int resolver, map;
3555 +
3556 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3557 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3558 + if (err)
3559 + break;
3560 +
3561 + regs->gr[20] = instruction_pointer(regs)+8;
3562 + regs->gr[21] = map;
3563 + regs->gr[22] = resolver;
3564 + regs->iaoq[0] = resolver | 3UL;
3565 + regs->iaoq[1] = regs->iaoq[0] + 4;
3566 + return 3;
3567 + }
3568 + }
3569 + } while (0);
3570 +#endif
3571 +
3572 +#ifdef CONFIG_PAX_EMUTRAMP
3573 +
3574 +#ifndef CONFIG_PAX_EMUSIGRT
3575 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3576 + return 1;
3577 +#endif
3578 +
3579 + do { /* PaX: rt_sigreturn emulation */
3580 + unsigned int ldi1, ldi2, bel, nop;
3581 +
3582 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3583 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3584 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3585 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3586 +
3587 + if (err)
3588 + break;
3589 +
3590 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3591 + ldi2 == 0x3414015AU &&
3592 + bel == 0xE4008200U &&
3593 + nop == 0x08000240U)
3594 + {
3595 + regs->gr[25] = (ldi1 & 2) >> 1;
3596 + regs->gr[20] = __NR_rt_sigreturn;
3597 + regs->gr[31] = regs->iaoq[1] + 16;
3598 + regs->sr[0] = regs->iasq[1];
3599 + regs->iaoq[0] = 0x100UL;
3600 + regs->iaoq[1] = regs->iaoq[0] + 4;
3601 + regs->iasq[0] = regs->sr[2];
3602 + regs->iasq[1] = regs->sr[2];
3603 + return 2;
3604 + }
3605 + } while (0);
3606 +#endif
3607 +
3608 + return 1;
3609 +}
3610 +
3611 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3612 +{
3613 + unsigned long i;
3614 +
3615 + printk(KERN_ERR "PAX: bytes at PC: ");
3616 + for (i = 0; i < 5; i++) {
3617 + unsigned int c;
3618 + if (get_user(c, (unsigned int *)pc+i))
3619 + printk(KERN_CONT "???????? ");
3620 + else
3621 + printk(KERN_CONT "%08x ", c);
3622 + }
3623 + printk("\n");
3624 +}
3625 +#endif
3626 +
3627 int fixup_exception(struct pt_regs *regs)
3628 {
3629 const struct exception_table_entry *fix;
3630 @@ -192,8 +303,33 @@ good_area:
3631
3632 acc_type = parisc_acctyp(code,regs->iir);
3633
3634 - if ((vma->vm_flags & acc_type) != acc_type)
3635 + if ((vma->vm_flags & acc_type) != acc_type) {
3636 +
3637 +#ifdef CONFIG_PAX_PAGEEXEC
3638 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3639 + (address & ~3UL) == instruction_pointer(regs))
3640 + {
3641 + up_read(&mm->mmap_sem);
3642 + switch (pax_handle_fetch_fault(regs)) {
3643 +
3644 +#ifdef CONFIG_PAX_EMUPLT
3645 + case 3:
3646 + return;
3647 +#endif
3648 +
3649 +#ifdef CONFIG_PAX_EMUTRAMP
3650 + case 2:
3651 + return;
3652 +#endif
3653 +
3654 + }
3655 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3656 + do_group_exit(SIGKILL);
3657 + }
3658 +#endif
3659 +
3660 goto bad_area;
3661 + }
3662
3663 /*
3664 * If for any reason at all we couldn't handle the fault, make
3665 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3666 index e3b1d41..8e81edf 100644
3667 --- a/arch/powerpc/include/asm/atomic.h
3668 +++ b/arch/powerpc/include/asm/atomic.h
3669 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3670 return t1;
3671 }
3672
3673 +#define atomic64_read_unchecked(v) atomic64_read(v)
3674 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3675 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3676 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3677 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3678 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3679 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3680 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3681 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3682 +
3683 #endif /* __powerpc64__ */
3684
3685 #endif /* __KERNEL__ */
3686 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3687 index 9e495c9..b6878e5 100644
3688 --- a/arch/powerpc/include/asm/cache.h
3689 +++ b/arch/powerpc/include/asm/cache.h
3690 @@ -3,6 +3,7 @@
3691
3692 #ifdef __KERNEL__
3693
3694 +#include <linux/const.h>
3695
3696 /* bytes per L1 cache line */
3697 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3698 @@ -22,7 +23,7 @@
3699 #define L1_CACHE_SHIFT 7
3700 #endif
3701
3702 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3703 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3704
3705 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3706
3707 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3708 index 6abf0a1..459d0f1 100644
3709 --- a/arch/powerpc/include/asm/elf.h
3710 +++ b/arch/powerpc/include/asm/elf.h
3711 @@ -28,8 +28,19 @@
3712 the loader. We need to make sure that it is out of the way of the program
3713 that it will "exec", and that there is sufficient room for the brk. */
3714
3715 -extern unsigned long randomize_et_dyn(unsigned long base);
3716 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3717 +#define ELF_ET_DYN_BASE (0x20000000)
3718 +
3719 +#ifdef CONFIG_PAX_ASLR
3720 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3721 +
3722 +#ifdef __powerpc64__
3723 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3724 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3725 +#else
3726 +#define PAX_DELTA_MMAP_LEN 15
3727 +#define PAX_DELTA_STACK_LEN 15
3728 +#endif
3729 +#endif
3730
3731 /*
3732 * Our registers are always unsigned longs, whether we're a 32 bit
3733 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3734 (0x7ff >> (PAGE_SHIFT - 12)) : \
3735 (0x3ffff >> (PAGE_SHIFT - 12)))
3736
3737 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3738 -#define arch_randomize_brk arch_randomize_brk
3739 -
3740 -
3741 #ifdef CONFIG_SPU_BASE
3742 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
3743 #define NT_SPU 1
3744 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3745 index 8196e9c..d83a9f3 100644
3746 --- a/arch/powerpc/include/asm/exec.h
3747 +++ b/arch/powerpc/include/asm/exec.h
3748 @@ -4,6 +4,6 @@
3749 #ifndef _ASM_POWERPC_EXEC_H
3750 #define _ASM_POWERPC_EXEC_H
3751
3752 -extern unsigned long arch_align_stack(unsigned long sp);
3753 +#define arch_align_stack(x) ((x) & ~0xfUL)
3754
3755 #endif /* _ASM_POWERPC_EXEC_H */
3756 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3757 index 5acabbd..7ea14fa 100644
3758 --- a/arch/powerpc/include/asm/kmap_types.h
3759 +++ b/arch/powerpc/include/asm/kmap_types.h
3760 @@ -10,7 +10,7 @@
3761 * 2 of the License, or (at your option) any later version.
3762 */
3763
3764 -#define KM_TYPE_NR 16
3765 +#define KM_TYPE_NR 17
3766
3767 #endif /* __KERNEL__ */
3768 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3769 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3770 index 8565c25..2865190 100644
3771 --- a/arch/powerpc/include/asm/mman.h
3772 +++ b/arch/powerpc/include/asm/mman.h
3773 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3774 }
3775 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3776
3777 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3778 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3779 {
3780 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3781 }
3782 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3783 index f072e97..b436dee 100644
3784 --- a/arch/powerpc/include/asm/page.h
3785 +++ b/arch/powerpc/include/asm/page.h
3786 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3787 * and needs to be executable. This means the whole heap ends
3788 * up being executable.
3789 */
3790 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3791 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3792 +#define VM_DATA_DEFAULT_FLAGS32 \
3793 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3794 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3795
3796 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3797 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3798 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3799 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3800 #endif
3801
3802 +#define ktla_ktva(addr) (addr)
3803 +#define ktva_ktla(addr) (addr)
3804 +
3805 /*
3806 * Use the top bit of the higher-level page table entries to indicate whether
3807 * the entries we point to contain hugepages. This works because we know that
3808 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3809 index cd915d6..c10cee8 100644
3810 --- a/arch/powerpc/include/asm/page_64.h
3811 +++ b/arch/powerpc/include/asm/page_64.h
3812 @@ -154,15 +154,18 @@ do { \
3813 * stack by default, so in the absence of a PT_GNU_STACK program header
3814 * we turn execute permission off.
3815 */
3816 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3817 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3818 +#define VM_STACK_DEFAULT_FLAGS32 \
3819 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3820 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3821
3822 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3823 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3824
3825 +#ifndef CONFIG_PAX_PAGEEXEC
3826 #define VM_STACK_DEFAULT_FLAGS \
3827 (is_32bit_task() ? \
3828 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3829 +#endif
3830
3831 #include <asm-generic/getorder.h>
3832
3833 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3834 index 292725c..f87ae14 100644
3835 --- a/arch/powerpc/include/asm/pgalloc-64.h
3836 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3837 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3838 #ifndef CONFIG_PPC_64K_PAGES
3839
3840 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3841 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3842
3843 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3844 {
3845 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3846 pud_set(pud, (unsigned long)pmd);
3847 }
3848
3849 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3850 +{
3851 + pud_populate(mm, pud, pmd);
3852 +}
3853 +
3854 #define pmd_populate(mm, pmd, pte_page) \
3855 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3856 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3857 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3858 #else /* CONFIG_PPC_64K_PAGES */
3859
3860 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3861 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3862
3863 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3864 pte_t *pte)
3865 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3866 index a9cbd3b..3b67efa 100644
3867 --- a/arch/powerpc/include/asm/pgtable.h
3868 +++ b/arch/powerpc/include/asm/pgtable.h
3869 @@ -2,6 +2,7 @@
3870 #define _ASM_POWERPC_PGTABLE_H
3871 #ifdef __KERNEL__
3872
3873 +#include <linux/const.h>
3874 #ifndef __ASSEMBLY__
3875 #include <asm/processor.h> /* For TASK_SIZE */
3876 #include <asm/mmu.h>
3877 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3878 index 4aad413..85d86bf 100644
3879 --- a/arch/powerpc/include/asm/pte-hash32.h
3880 +++ b/arch/powerpc/include/asm/pte-hash32.h
3881 @@ -21,6 +21,7 @@
3882 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3883 #define _PAGE_USER 0x004 /* usermode access allowed */
3884 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3885 +#define _PAGE_EXEC _PAGE_GUARDED
3886 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3887 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3888 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3889 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3890 index d24c141..b60696e 100644
3891 --- a/arch/powerpc/include/asm/reg.h
3892 +++ b/arch/powerpc/include/asm/reg.h
3893 @@ -215,6 +215,7 @@
3894 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3895 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3896 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3897 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3898 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3899 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3900 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3901 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3902 index 406b7b9..af63426 100644
3903 --- a/arch/powerpc/include/asm/thread_info.h
3904 +++ b/arch/powerpc/include/asm/thread_info.h
3905 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
3906 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3907 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3908 #define TIF_SINGLESTEP 8 /* singlestepping active */
3909 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3910 #define TIF_SECCOMP 10 /* secure computing */
3911 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3912 #define TIF_NOERROR 12 /* Force successful syscall return */
3913 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
3914 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3915 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
3916 for stack store? */
3917 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
3918 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3919 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3920
3921 /* as above, but as bit values */
3922 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3923 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
3924 #define _TIF_UPROBE (1<<TIF_UPROBE)
3925 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3926 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
3927 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3928 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3929 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3930 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3931 + _TIF_GRSEC_SETXID)
3932
3933 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3934 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
3935 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3936 index 4db4959..335e00c 100644
3937 --- a/arch/powerpc/include/asm/uaccess.h
3938 +++ b/arch/powerpc/include/asm/uaccess.h
3939 @@ -13,6 +13,8 @@
3940 #define VERIFY_READ 0
3941 #define VERIFY_WRITE 1
3942
3943 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3944 +
3945 /*
3946 * The fs value determines whether argument validity checking should be
3947 * performed or not. If get_fs() == USER_DS, checking is performed, with
3948 @@ -318,52 +320,6 @@ do { \
3949 extern unsigned long __copy_tofrom_user(void __user *to,
3950 const void __user *from, unsigned long size);
3951
3952 -#ifndef __powerpc64__
3953 -
3954 -static inline unsigned long copy_from_user(void *to,
3955 - const void __user *from, unsigned long n)
3956 -{
3957 - unsigned long over;
3958 -
3959 - if (access_ok(VERIFY_READ, from, n))
3960 - return __copy_tofrom_user((__force void __user *)to, from, n);
3961 - if ((unsigned long)from < TASK_SIZE) {
3962 - over = (unsigned long)from + n - TASK_SIZE;
3963 - return __copy_tofrom_user((__force void __user *)to, from,
3964 - n - over) + over;
3965 - }
3966 - return n;
3967 -}
3968 -
3969 -static inline unsigned long copy_to_user(void __user *to,
3970 - const void *from, unsigned long n)
3971 -{
3972 - unsigned long over;
3973 -
3974 - if (access_ok(VERIFY_WRITE, to, n))
3975 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3976 - if ((unsigned long)to < TASK_SIZE) {
3977 - over = (unsigned long)to + n - TASK_SIZE;
3978 - return __copy_tofrom_user(to, (__force void __user *)from,
3979 - n - over) + over;
3980 - }
3981 - return n;
3982 -}
3983 -
3984 -#else /* __powerpc64__ */
3985 -
3986 -#define __copy_in_user(to, from, size) \
3987 - __copy_tofrom_user((to), (from), (size))
3988 -
3989 -extern unsigned long copy_from_user(void *to, const void __user *from,
3990 - unsigned long n);
3991 -extern unsigned long copy_to_user(void __user *to, const void *from,
3992 - unsigned long n);
3993 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3994 - unsigned long n);
3995 -
3996 -#endif /* __powerpc64__ */
3997 -
3998 static inline unsigned long __copy_from_user_inatomic(void *to,
3999 const void __user *from, unsigned long n)
4000 {
4001 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4002 if (ret == 0)
4003 return 0;
4004 }
4005 +
4006 + if (!__builtin_constant_p(n))
4007 + check_object_size(to, n, false);
4008 +
4009 return __copy_tofrom_user((__force void __user *)to, from, n);
4010 }
4011
4012 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4013 if (ret == 0)
4014 return 0;
4015 }
4016 +
4017 + if (!__builtin_constant_p(n))
4018 + check_object_size(from, n, true);
4019 +
4020 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4021 }
4022
4023 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4024 return __copy_to_user_inatomic(to, from, size);
4025 }
4026
4027 +#ifndef __powerpc64__
4028 +
4029 +static inline unsigned long __must_check copy_from_user(void *to,
4030 + const void __user *from, unsigned long n)
4031 +{
4032 + unsigned long over;
4033 +
4034 + if ((long)n < 0)
4035 + return n;
4036 +
4037 + if (access_ok(VERIFY_READ, from, n)) {
4038 + if (!__builtin_constant_p(n))
4039 + check_object_size(to, n, false);
4040 + return __copy_tofrom_user((__force void __user *)to, from, n);
4041 + }
4042 + if ((unsigned long)from < TASK_SIZE) {
4043 + over = (unsigned long)from + n - TASK_SIZE;
4044 + if (!__builtin_constant_p(n - over))
4045 + check_object_size(to, n - over, false);
4046 + return __copy_tofrom_user((__force void __user *)to, from,
4047 + n - over) + over;
4048 + }
4049 + return n;
4050 +}
4051 +
4052 +static inline unsigned long __must_check copy_to_user(void __user *to,
4053 + const void *from, unsigned long n)
4054 +{
4055 + unsigned long over;
4056 +
4057 + if ((long)n < 0)
4058 + return n;
4059 +
4060 + if (access_ok(VERIFY_WRITE, to, n)) {
4061 + if (!__builtin_constant_p(n))
4062 + check_object_size(from, n, true);
4063 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4064 + }
4065 + if ((unsigned long)to < TASK_SIZE) {
4066 + over = (unsigned long)to + n - TASK_SIZE;
4067 + if (!__builtin_constant_p(n))
4068 + check_object_size(from, n - over, true);
4069 + return __copy_tofrom_user(to, (__force void __user *)from,
4070 + n - over) + over;
4071 + }
4072 + return n;
4073 +}
4074 +
4075 +#else /* __powerpc64__ */
4076 +
4077 +#define __copy_in_user(to, from, size) \
4078 + __copy_tofrom_user((to), (from), (size))
4079 +
4080 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4081 +{
4082 + if ((long)n < 0 || n > INT_MAX)
4083 + return n;
4084 +
4085 + if (!__builtin_constant_p(n))
4086 + check_object_size(to, n, false);
4087 +
4088 + if (likely(access_ok(VERIFY_READ, from, n)))
4089 + n = __copy_from_user(to, from, n);
4090 + else
4091 + memset(to, 0, n);
4092 + return n;
4093 +}
4094 +
4095 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4096 +{
4097 + if ((long)n < 0 || n > INT_MAX)
4098 + return n;
4099 +
4100 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4101 + if (!__builtin_constant_p(n))
4102 + check_object_size(from, n, true);
4103 + n = __copy_to_user(to, from, n);
4104 + }
4105 + return n;
4106 +}
4107 +
4108 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4109 + unsigned long n);
4110 +
4111 +#endif /* __powerpc64__ */
4112 +
4113 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4114
4115 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4116 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4117 index 4684e33..acc4d19e 100644
4118 --- a/arch/powerpc/kernel/exceptions-64e.S
4119 +++ b/arch/powerpc/kernel/exceptions-64e.S
4120 @@ -715,6 +715,7 @@ storage_fault_common:
4121 std r14,_DAR(r1)
4122 std r15,_DSISR(r1)
4123 addi r3,r1,STACK_FRAME_OVERHEAD
4124 + bl .save_nvgprs
4125 mr r4,r14
4126 mr r5,r15
4127 ld r14,PACA_EXGEN+EX_R14(r13)
4128 @@ -723,8 +724,7 @@ storage_fault_common:
4129 cmpdi r3,0
4130 bne- 1f
4131 b .ret_from_except_lite
4132 -1: bl .save_nvgprs
4133 - mr r5,r3
4134 +1: mr r5,r3
4135 addi r3,r1,STACK_FRAME_OVERHEAD
4136 ld r4,_DAR(r1)
4137 bl .bad_page_fault
4138 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4139 index 10b658a..e542888 100644
4140 --- a/arch/powerpc/kernel/exceptions-64s.S
4141 +++ b/arch/powerpc/kernel/exceptions-64s.S
4142 @@ -1013,10 +1013,10 @@ handle_page_fault:
4143 11: ld r4,_DAR(r1)
4144 ld r5,_DSISR(r1)
4145 addi r3,r1,STACK_FRAME_OVERHEAD
4146 + bl .save_nvgprs
4147 bl .do_page_fault
4148 cmpdi r3,0
4149 beq+ 12f
4150 - bl .save_nvgprs
4151 mr r5,r3
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153 lwz r4,_DAR(r1)
4154 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4155 index 2e3200c..72095ce 100644
4156 --- a/arch/powerpc/kernel/module_32.c
4157 +++ b/arch/powerpc/kernel/module_32.c
4158 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4159 me->arch.core_plt_section = i;
4160 }
4161 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4162 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4163 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4164 return -ENOEXEC;
4165 }
4166
4167 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4168
4169 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4170 /* Init, or core PLT? */
4171 - if (location >= mod->module_core
4172 - && location < mod->module_core + mod->core_size)
4173 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4174 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4175 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4176 - else
4177 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4178 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4179 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4180 + else {
4181 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4182 + return ~0UL;
4183 + }
4184
4185 /* Find this entry, or if that fails, the next avail. entry */
4186 while (entry->jump[0]) {
4187 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4188 index ba48233..16ac31d 100644
4189 --- a/arch/powerpc/kernel/process.c
4190 +++ b/arch/powerpc/kernel/process.c
4191 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
4192 * Lookup NIP late so we have the best change of getting the
4193 * above info out without failing
4194 */
4195 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4196 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4197 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4198 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4199 #endif
4200 show_stack(current, (unsigned long *) regs->gpr[1]);
4201 if (!user_mode(regs))
4202 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4203 newsp = stack[0];
4204 ip = stack[STACK_FRAME_LR_SAVE];
4205 if (!firstframe || ip != lr) {
4206 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4207 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4208 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4209 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4210 - printk(" (%pS)",
4211 + printk(" (%pA)",
4212 (void *)current->ret_stack[curr_frame].ret);
4213 curr_frame--;
4214 }
4215 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4216 struct pt_regs *regs = (struct pt_regs *)
4217 (sp + STACK_FRAME_OVERHEAD);
4218 lr = regs->link;
4219 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4220 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4221 regs->trap, (void *)regs->nip, (void *)lr);
4222 firstframe = 1;
4223 }
4224 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
4225 mtspr(SPRN_CTRLT, ctrl);
4226 }
4227 #endif /* CONFIG_PPC64 */
4228 -
4229 -unsigned long arch_align_stack(unsigned long sp)
4230 -{
4231 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4232 - sp -= get_random_int() & ~PAGE_MASK;
4233 - return sp & ~0xf;
4234 -}
4235 -
4236 -static inline unsigned long brk_rnd(void)
4237 -{
4238 - unsigned long rnd = 0;
4239 -
4240 - /* 8MB for 32bit, 1GB for 64bit */
4241 - if (is_32bit_task())
4242 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4243 - else
4244 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4245 -
4246 - return rnd << PAGE_SHIFT;
4247 -}
4248 -
4249 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4250 -{
4251 - unsigned long base = mm->brk;
4252 - unsigned long ret;
4253 -
4254 -#ifdef CONFIG_PPC_STD_MMU_64
4255 - /*
4256 - * If we are using 1TB segments and we are allowed to randomise
4257 - * the heap, we can put it above 1TB so it is backed by a 1TB
4258 - * segment. Otherwise the heap will be in the bottom 1TB
4259 - * which always uses 256MB segments and this may result in a
4260 - * performance penalty.
4261 - */
4262 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4263 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4264 -#endif
4265 -
4266 - ret = PAGE_ALIGN(base + brk_rnd());
4267 -
4268 - if (ret < mm->brk)
4269 - return mm->brk;
4270 -
4271 - return ret;
4272 -}
4273 -
4274 -unsigned long randomize_et_dyn(unsigned long base)
4275 -{
4276 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4277 -
4278 - if (ret < base)
4279 - return base;
4280 -
4281 - return ret;
4282 -}
4283 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4284 index 79d8e56..38ffcbb 100644
4285 --- a/arch/powerpc/kernel/ptrace.c
4286 +++ b/arch/powerpc/kernel/ptrace.c
4287 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
4288 return ret;
4289 }
4290
4291 +#ifdef CONFIG_GRKERNSEC_SETXID
4292 +extern void gr_delayed_cred_worker(void);
4293 +#endif
4294 +
4295 /*
4296 * We must return the syscall number to actually look up in the table.
4297 * This can be -1L to skip running any syscall at all.
4298 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4299
4300 secure_computing_strict(regs->gpr[0]);
4301
4302 +#ifdef CONFIG_GRKERNSEC_SETXID
4303 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4304 + gr_delayed_cred_worker();
4305 +#endif
4306 +
4307 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4308 tracehook_report_syscall_entry(regs))
4309 /*
4310 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4311 {
4312 int step;
4313
4314 +#ifdef CONFIG_GRKERNSEC_SETXID
4315 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4316 + gr_delayed_cred_worker();
4317 +#endif
4318 +
4319 audit_syscall_exit(regs);
4320
4321 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4322 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4323 index 804e323..79181c1 100644
4324 --- a/arch/powerpc/kernel/signal_32.c
4325 +++ b/arch/powerpc/kernel/signal_32.c
4326 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4327 /* Save user registers on the stack */
4328 frame = &rt_sf->uc.uc_mcontext;
4329 addr = frame;
4330 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4331 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4332 if (save_user_regs(regs, frame, 0, 1))
4333 goto badframe;
4334 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4335 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4336 index d183f87..1867f1a 100644
4337 --- a/arch/powerpc/kernel/signal_64.c
4338 +++ b/arch/powerpc/kernel/signal_64.c
4339 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4340 current->thread.fpscr.val = 0;
4341
4342 /* Set up to return from userspace. */
4343 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4344 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4345 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4346 } else {
4347 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4348 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4349 index 3251840..3f7c77a 100644
4350 --- a/arch/powerpc/kernel/traps.c
4351 +++ b/arch/powerpc/kernel/traps.c
4352 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4353 return flags;
4354 }
4355
4356 +extern void gr_handle_kernel_exploit(void);
4357 +
4358 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4359 int signr)
4360 {
4361 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4362 panic("Fatal exception in interrupt");
4363 if (panic_on_oops)
4364 panic("Fatal exception");
4365 +
4366 + gr_handle_kernel_exploit();
4367 +
4368 do_exit(signr);
4369 }
4370
4371 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4372 index 1b2076f..835e4be 100644
4373 --- a/arch/powerpc/kernel/vdso.c
4374 +++ b/arch/powerpc/kernel/vdso.c
4375 @@ -34,6 +34,7 @@
4376 #include <asm/firmware.h>
4377 #include <asm/vdso.h>
4378 #include <asm/vdso_datapage.h>
4379 +#include <asm/mman.h>
4380
4381 #include "setup.h"
4382
4383 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4384 vdso_base = VDSO32_MBASE;
4385 #endif
4386
4387 - current->mm->context.vdso_base = 0;
4388 + current->mm->context.vdso_base = ~0UL;
4389
4390 /* vDSO has a problem and was disabled, just don't "enable" it for the
4391 * process
4392 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4393 vdso_base = get_unmapped_area(NULL, vdso_base,
4394 (vdso_pages << PAGE_SHIFT) +
4395 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4396 - 0, 0);
4397 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4398 if (IS_ERR_VALUE(vdso_base)) {
4399 rc = vdso_base;
4400 goto fail_mmapsem;
4401 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4402 index 5eea6f3..5d10396 100644
4403 --- a/arch/powerpc/lib/usercopy_64.c
4404 +++ b/arch/powerpc/lib/usercopy_64.c
4405 @@ -9,22 +9,6 @@
4406 #include <linux/module.h>
4407 #include <asm/uaccess.h>
4408
4409 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4410 -{
4411 - if (likely(access_ok(VERIFY_READ, from, n)))
4412 - n = __copy_from_user(to, from, n);
4413 - else
4414 - memset(to, 0, n);
4415 - return n;
4416 -}
4417 -
4418 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4419 -{
4420 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4421 - n = __copy_to_user(to, from, n);
4422 - return n;
4423 -}
4424 -
4425 unsigned long copy_in_user(void __user *to, const void __user *from,
4426 unsigned long n)
4427 {
4428 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4429 return n;
4430 }
4431
4432 -EXPORT_SYMBOL(copy_from_user);
4433 -EXPORT_SYMBOL(copy_to_user);
4434 EXPORT_SYMBOL(copy_in_user);
4435
4436 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4437 index 0a6b283..7674925 100644
4438 --- a/arch/powerpc/mm/fault.c
4439 +++ b/arch/powerpc/mm/fault.c
4440 @@ -32,6 +32,10 @@
4441 #include <linux/perf_event.h>
4442 #include <linux/magic.h>
4443 #include <linux/ratelimit.h>
4444 +#include <linux/slab.h>
4445 +#include <linux/pagemap.h>
4446 +#include <linux/compiler.h>
4447 +#include <linux/unistd.h>
4448
4449 #include <asm/firmware.h>
4450 #include <asm/page.h>
4451 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4452 }
4453 #endif
4454
4455 +#ifdef CONFIG_PAX_PAGEEXEC
4456 +/*
4457 + * PaX: decide what to do with offenders (regs->nip = fault address)
4458 + *
4459 + * returns 1 when task should be killed
4460 + */
4461 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4462 +{
4463 + return 1;
4464 +}
4465 +
4466 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4467 +{
4468 + unsigned long i;
4469 +
4470 + printk(KERN_ERR "PAX: bytes at PC: ");
4471 + for (i = 0; i < 5; i++) {
4472 + unsigned int c;
4473 + if (get_user(c, (unsigned int __user *)pc+i))
4474 + printk(KERN_CONT "???????? ");
4475 + else
4476 + printk(KERN_CONT "%08x ", c);
4477 + }
4478 + printk("\n");
4479 +}
4480 +#endif
4481 +
4482 /*
4483 * Check whether the instruction at regs->nip is a store using
4484 * an update addressing form which will update r1.
4485 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4486 * indicate errors in DSISR but can validly be set in SRR1.
4487 */
4488 if (trap == 0x400)
4489 - error_code &= 0x48200000;
4490 + error_code &= 0x58200000;
4491 else
4492 is_write = error_code & DSISR_ISSTORE;
4493 #else
4494 @@ -367,7 +398,7 @@ good_area:
4495 * "undefined". Of those that can be set, this is the only
4496 * one which seems bad.
4497 */
4498 - if (error_code & 0x10000000)
4499 + if (error_code & DSISR_GUARDED)
4500 /* Guarded storage error. */
4501 goto bad_area;
4502 #endif /* CONFIG_8xx */
4503 @@ -382,7 +413,7 @@ good_area:
4504 * processors use the same I/D cache coherency mechanism
4505 * as embedded.
4506 */
4507 - if (error_code & DSISR_PROTFAULT)
4508 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4509 goto bad_area;
4510 #endif /* CONFIG_PPC_STD_MMU */
4511
4512 @@ -465,6 +496,23 @@ bad_area:
4513 bad_area_nosemaphore:
4514 /* User mode accesses cause a SIGSEGV */
4515 if (user_mode(regs)) {
4516 +
4517 +#ifdef CONFIG_PAX_PAGEEXEC
4518 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4519 +#ifdef CONFIG_PPC_STD_MMU
4520 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4521 +#else
4522 + if (is_exec && regs->nip == address) {
4523 +#endif
4524 + switch (pax_handle_fetch_fault(regs)) {
4525 + }
4526 +
4527 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4528 + do_group_exit(SIGKILL);
4529 + }
4530 + }
4531 +#endif
4532 +
4533 _exception(SIGSEGV, regs, code, address);
4534 return 0;
4535 }
4536 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4537 index 67a42ed..1c7210c 100644
4538 --- a/arch/powerpc/mm/mmap_64.c
4539 +++ b/arch/powerpc/mm/mmap_64.c
4540 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4541 */
4542 if (mmap_is_legacy()) {
4543 mm->mmap_base = TASK_UNMAPPED_BASE;
4544 +
4545 +#ifdef CONFIG_PAX_RANDMMAP
4546 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4547 + mm->mmap_base += mm->delta_mmap;
4548 +#endif
4549 +
4550 mm->get_unmapped_area = arch_get_unmapped_area;
4551 mm->unmap_area = arch_unmap_area;
4552 } else {
4553 mm->mmap_base = mmap_base();
4554 +
4555 +#ifdef CONFIG_PAX_RANDMMAP
4556 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4557 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4558 +#endif
4559 +
4560 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4561 mm->unmap_area = arch_unmap_area_topdown;
4562 }
4563 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4564 index 5829d2a..b64ed2e 100644
4565 --- a/arch/powerpc/mm/slice.c
4566 +++ b/arch/powerpc/mm/slice.c
4567 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4568 if ((mm->task_size - len) < addr)
4569 return 0;
4570 vma = find_vma(mm, addr);
4571 - return (!vma || (addr + len) <= vma->vm_start);
4572 + return check_heap_stack_gap(vma, addr, len);
4573 }
4574
4575 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4576 @@ -272,7 +272,7 @@ full_search:
4577 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4578 continue;
4579 }
4580 - if (!vma || addr + len <= vma->vm_start) {
4581 + if (check_heap_stack_gap(vma, addr, len)) {
4582 /*
4583 * Remember the place where we stopped the search:
4584 */
4585 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4586 }
4587 }
4588
4589 - addr = mm->mmap_base;
4590 - while (addr > len) {
4591 + if (mm->mmap_base < len)
4592 + addr = -ENOMEM;
4593 + else
4594 + addr = mm->mmap_base - len;
4595 +
4596 + while (!IS_ERR_VALUE(addr)) {
4597 /* Go down by chunk size */
4598 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4599 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4600
4601 /* Check for hit with different page size */
4602 mask = slice_range_to_mask(addr, len);
4603 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4604 * return with success:
4605 */
4606 vma = find_vma(mm, addr);
4607 - if (!vma || (addr + len) <= vma->vm_start) {
4608 + if (check_heap_stack_gap(vma, addr, len)) {
4609 /* remember the address as a hint for next time */
4610 if (use_cache)
4611 mm->free_area_cache = addr;
4612 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4613 mm->cached_hole_size = vma->vm_start - addr;
4614
4615 /* try just below the current vma->vm_start */
4616 - addr = vma->vm_start;
4617 + addr = skip_heap_stack_gap(vma, len);
4618 }
4619
4620 /*
4621 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4622 if (fixed && addr > (mm->task_size - len))
4623 return -EINVAL;
4624
4625 +#ifdef CONFIG_PAX_RANDMMAP
4626 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4627 + addr = 0;
4628 +#endif
4629 +
4630 /* If hint, make sure it matches our alignment restrictions */
4631 if (!fixed && addr) {
4632 addr = _ALIGN_UP(addr, 1ul << pshift);
4633 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4634 index c797832..ce575c8 100644
4635 --- a/arch/s390/include/asm/atomic.h
4636 +++ b/arch/s390/include/asm/atomic.h
4637 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4638 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4639 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4640
4641 +#define atomic64_read_unchecked(v) atomic64_read(v)
4642 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4643 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4644 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4645 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4646 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4647 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4648 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4649 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4650 +
4651 #define smp_mb__before_atomic_dec() smp_mb()
4652 #define smp_mb__after_atomic_dec() smp_mb()
4653 #define smp_mb__before_atomic_inc() smp_mb()
4654 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4655 index 4d7ccac..d03d0ad 100644
4656 --- a/arch/s390/include/asm/cache.h
4657 +++ b/arch/s390/include/asm/cache.h
4658 @@ -9,8 +9,10 @@
4659 #ifndef __ARCH_S390_CACHE_H
4660 #define __ARCH_S390_CACHE_H
4661
4662 -#define L1_CACHE_BYTES 256
4663 +#include <linux/const.h>
4664 +
4665 #define L1_CACHE_SHIFT 8
4666 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4667 #define NET_SKB_PAD 32
4668
4669 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4670 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4671 index 178ff96..8c93bd1 100644
4672 --- a/arch/s390/include/asm/elf.h
4673 +++ b/arch/s390/include/asm/elf.h
4674 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
4675 the loader. We need to make sure that it is out of the way of the program
4676 that it will "exec", and that there is sufficient room for the brk. */
4677
4678 -extern unsigned long randomize_et_dyn(unsigned long base);
4679 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4680 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4681 +
4682 +#ifdef CONFIG_PAX_ASLR
4683 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4684 +
4685 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4686 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4687 +#endif
4688
4689 /* This yields a mask that user programs can use to figure out what
4690 instruction set this CPU supports. */
4691 @@ -210,9 +216,6 @@ struct linux_binprm;
4692 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4693 int arch_setup_additional_pages(struct linux_binprm *, int);
4694
4695 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4696 -#define arch_randomize_brk arch_randomize_brk
4697 -
4698 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
4699
4700 #endif
4701 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4702 index c4a93d6..4d2a9b4 100644
4703 --- a/arch/s390/include/asm/exec.h
4704 +++ b/arch/s390/include/asm/exec.h
4705 @@ -7,6 +7,6 @@
4706 #ifndef __ASM_EXEC_H
4707 #define __ASM_EXEC_H
4708
4709 -extern unsigned long arch_align_stack(unsigned long sp);
4710 +#define arch_align_stack(x) ((x) & ~0xfUL)
4711
4712 #endif /* __ASM_EXEC_H */
4713 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4714 index 34268df..ea97318 100644
4715 --- a/arch/s390/include/asm/uaccess.h
4716 +++ b/arch/s390/include/asm/uaccess.h
4717 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
4718 copy_to_user(void __user *to, const void *from, unsigned long n)
4719 {
4720 might_fault();
4721 +
4722 + if ((long)n < 0)
4723 + return n;
4724 +
4725 if (access_ok(VERIFY_WRITE, to, n))
4726 n = __copy_to_user(to, from, n);
4727 return n;
4728 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4729 static inline unsigned long __must_check
4730 __copy_from_user(void *to, const void __user *from, unsigned long n)
4731 {
4732 + if ((long)n < 0)
4733 + return n;
4734 +
4735 if (__builtin_constant_p(n) && (n <= 256))
4736 return uaccess.copy_from_user_small(n, from, to);
4737 else
4738 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4739 static inline unsigned long __must_check
4740 copy_from_user(void *to, const void __user *from, unsigned long n)
4741 {
4742 - unsigned int sz = __compiletime_object_size(to);
4743 + size_t sz = __compiletime_object_size(to);
4744
4745 might_fault();
4746 - if (unlikely(sz != -1 && sz < n)) {
4747 +
4748 + if ((long)n < 0)
4749 + return n;
4750 +
4751 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4752 copy_from_user_overflow();
4753 return n;
4754 }
4755 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4756 index 4610dea..cf0af21 100644
4757 --- a/arch/s390/kernel/module.c
4758 +++ b/arch/s390/kernel/module.c
4759 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4760
4761 /* Increase core size by size of got & plt and set start
4762 offsets for got and plt. */
4763 - me->core_size = ALIGN(me->core_size, 4);
4764 - me->arch.got_offset = me->core_size;
4765 - me->core_size += me->arch.got_size;
4766 - me->arch.plt_offset = me->core_size;
4767 - me->core_size += me->arch.plt_size;
4768 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4769 + me->arch.got_offset = me->core_size_rw;
4770 + me->core_size_rw += me->arch.got_size;
4771 + me->arch.plt_offset = me->core_size_rx;
4772 + me->core_size_rx += me->arch.plt_size;
4773 return 0;
4774 }
4775
4776 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4777 if (info->got_initialized == 0) {
4778 Elf_Addr *gotent;
4779
4780 - gotent = me->module_core + me->arch.got_offset +
4781 + gotent = me->module_core_rw + me->arch.got_offset +
4782 info->got_offset;
4783 *gotent = val;
4784 info->got_initialized = 1;
4785 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4786 else if (r_type == R_390_GOTENT ||
4787 r_type == R_390_GOTPLTENT)
4788 *(unsigned int *) loc =
4789 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4790 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4791 else if (r_type == R_390_GOT64 ||
4792 r_type == R_390_GOTPLT64)
4793 *(unsigned long *) loc = val;
4794 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4795 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4796 if (info->plt_initialized == 0) {
4797 unsigned int *ip;
4798 - ip = me->module_core + me->arch.plt_offset +
4799 + ip = me->module_core_rx + me->arch.plt_offset +
4800 info->plt_offset;
4801 #ifndef CONFIG_64BIT
4802 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4803 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4804 val - loc + 0xffffUL < 0x1ffffeUL) ||
4805 (r_type == R_390_PLT32DBL &&
4806 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4807 - val = (Elf_Addr) me->module_core +
4808 + val = (Elf_Addr) me->module_core_rx +
4809 me->arch.plt_offset +
4810 info->plt_offset;
4811 val += rela->r_addend - loc;
4812 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4813 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4814 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4815 val = val + rela->r_addend -
4816 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4817 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4818 if (r_type == R_390_GOTOFF16)
4819 *(unsigned short *) loc = val;
4820 else if (r_type == R_390_GOTOFF32)
4821 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4822 break;
4823 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4824 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4825 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4826 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4827 rela->r_addend - loc;
4828 if (r_type == R_390_GOTPC)
4829 *(unsigned int *) loc = val;
4830 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4831 index cd31ad4..201c5a3 100644
4832 --- a/arch/s390/kernel/process.c
4833 +++ b/arch/s390/kernel/process.c
4834 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
4835 }
4836 return 0;
4837 }
4838 -
4839 -unsigned long arch_align_stack(unsigned long sp)
4840 -{
4841 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4842 - sp -= get_random_int() & ~PAGE_MASK;
4843 - return sp & ~0xf;
4844 -}
4845 -
4846 -static inline unsigned long brk_rnd(void)
4847 -{
4848 - /* 8MB for 32bit, 1GB for 64bit */
4849 - if (is_32bit_task())
4850 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4851 - else
4852 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4853 -}
4854 -
4855 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4856 -{
4857 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4858 -
4859 - if (ret < mm->brk)
4860 - return mm->brk;
4861 - return ret;
4862 -}
4863 -
4864 -unsigned long randomize_et_dyn(unsigned long base)
4865 -{
4866 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4867 -
4868 - if (!(current->flags & PF_RANDOMIZE))
4869 - return base;
4870 - if (ret < base)
4871 - return base;
4872 - return ret;
4873 -}
4874 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4875 index c59a5ef..3fae59c 100644
4876 --- a/arch/s390/mm/mmap.c
4877 +++ b/arch/s390/mm/mmap.c
4878 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4879 */
4880 if (mmap_is_legacy()) {
4881 mm->mmap_base = TASK_UNMAPPED_BASE;
4882 +
4883 +#ifdef CONFIG_PAX_RANDMMAP
4884 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4885 + mm->mmap_base += mm->delta_mmap;
4886 +#endif
4887 +
4888 mm->get_unmapped_area = arch_get_unmapped_area;
4889 mm->unmap_area = arch_unmap_area;
4890 } else {
4891 mm->mmap_base = mmap_base();
4892 +
4893 +#ifdef CONFIG_PAX_RANDMMAP
4894 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4895 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4896 +#endif
4897 +
4898 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4899 mm->unmap_area = arch_unmap_area_topdown;
4900 }
4901 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4902 */
4903 if (mmap_is_legacy()) {
4904 mm->mmap_base = TASK_UNMAPPED_BASE;
4905 +
4906 +#ifdef CONFIG_PAX_RANDMMAP
4907 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4908 + mm->mmap_base += mm->delta_mmap;
4909 +#endif
4910 +
4911 mm->get_unmapped_area = s390_get_unmapped_area;
4912 mm->unmap_area = arch_unmap_area;
4913 } else {
4914 mm->mmap_base = mmap_base();
4915 +
4916 +#ifdef CONFIG_PAX_RANDMMAP
4917 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4918 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4919 +#endif
4920 +
4921 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4922 mm->unmap_area = arch_unmap_area_topdown;
4923 }
4924 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4925 index ae3d59f..f65f075 100644
4926 --- a/arch/score/include/asm/cache.h
4927 +++ b/arch/score/include/asm/cache.h
4928 @@ -1,7 +1,9 @@
4929 #ifndef _ASM_SCORE_CACHE_H
4930 #define _ASM_SCORE_CACHE_H
4931
4932 +#include <linux/const.h>
4933 +
4934 #define L1_CACHE_SHIFT 4
4935 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4936 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4937
4938 #endif /* _ASM_SCORE_CACHE_H */
4939 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4940 index f9f3cd5..58ff438 100644
4941 --- a/arch/score/include/asm/exec.h
4942 +++ b/arch/score/include/asm/exec.h
4943 @@ -1,6 +1,6 @@
4944 #ifndef _ASM_SCORE_EXEC_H
4945 #define _ASM_SCORE_EXEC_H
4946
4947 -extern unsigned long arch_align_stack(unsigned long sp);
4948 +#define arch_align_stack(x) (x)
4949
4950 #endif /* _ASM_SCORE_EXEC_H */
4951 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4952 index 637970c..0b6556b 100644
4953 --- a/arch/score/kernel/process.c
4954 +++ b/arch/score/kernel/process.c
4955 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4956
4957 return task_pt_regs(task)->cp0_epc;
4958 }
4959 -
4960 -unsigned long arch_align_stack(unsigned long sp)
4961 -{
4962 - return sp;
4963 -}
4964 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4965 index ef9e555..331bd29 100644
4966 --- a/arch/sh/include/asm/cache.h
4967 +++ b/arch/sh/include/asm/cache.h
4968 @@ -9,10 +9,11 @@
4969 #define __ASM_SH_CACHE_H
4970 #ifdef __KERNEL__
4971
4972 +#include <linux/const.h>
4973 #include <linux/init.h>
4974 #include <cpu/cache.h>
4975
4976 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4977 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4978
4979 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4980
4981 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4982 index afeb710..d1d1289 100644
4983 --- a/arch/sh/mm/mmap.c
4984 +++ b/arch/sh/mm/mmap.c
4985 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4986 addr = PAGE_ALIGN(addr);
4987
4988 vma = find_vma(mm, addr);
4989 - if (TASK_SIZE - len >= addr &&
4990 - (!vma || addr + len <= vma->vm_start))
4991 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4992 return addr;
4993 }
4994
4995 @@ -106,7 +105,7 @@ full_search:
4996 }
4997 return -ENOMEM;
4998 }
4999 - if (likely(!vma || addr + len <= vma->vm_start)) {
5000 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5001 /*
5002 * Remember the place where we stopped the search:
5003 */
5004 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5005 addr = PAGE_ALIGN(addr);
5006
5007 vma = find_vma(mm, addr);
5008 - if (TASK_SIZE - len >= addr &&
5009 - (!vma || addr + len <= vma->vm_start))
5010 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5011 return addr;
5012 }
5013
5014 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5015 /* make sure it can fit in the remaining address space */
5016 if (likely(addr > len)) {
5017 vma = find_vma(mm, addr-len);
5018 - if (!vma || addr <= vma->vm_start) {
5019 + if (check_heap_stack_gap(vma, addr - len, len)) {
5020 /* remember the address as a hint for next time */
5021 return (mm->free_area_cache = addr-len);
5022 }
5023 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5024 if (unlikely(mm->mmap_base < len))
5025 goto bottomup;
5026
5027 - addr = mm->mmap_base-len;
5028 - if (do_colour_align)
5029 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5030 + addr = mm->mmap_base - len;
5031
5032 do {
5033 + if (do_colour_align)
5034 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5035 /*
5036 * Lookup failure means no vma is above this address,
5037 * else if new region fits below vma->vm_start,
5038 * return with success:
5039 */
5040 vma = find_vma(mm, addr);
5041 - if (likely(!vma || addr+len <= vma->vm_start)) {
5042 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5043 /* remember the address as a hint for next time */
5044 return (mm->free_area_cache = addr);
5045 }
5046 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5047 mm->cached_hole_size = vma->vm_start - addr;
5048
5049 /* try just below the current vma->vm_start */
5050 - addr = vma->vm_start-len;
5051 - if (do_colour_align)
5052 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5053 - } while (likely(len < vma->vm_start));
5054 + addr = skip_heap_stack_gap(vma, len);
5055 + } while (!IS_ERR_VALUE(addr));
5056
5057 bottomup:
5058 /*
5059 diff --git a/arch/sparc/crypto/aes_asm.S b/arch/sparc/crypto/aes_asm.S
5060 index 23f6cbb..1cda8aa 100644
5061 --- a/arch/sparc/crypto/aes_asm.S
5062 +++ b/arch/sparc/crypto/aes_asm.S
5063 @@ -1024,7 +1024,11 @@ ENTRY(aes_sparc64_ecb_encrypt_256)
5064 add %o2, 0x20, %o2
5065 brlz,pt %o3, 11f
5066 nop
5067 -10: ldx [%o1 + 0x00], %g3
5068 +10: ldd [%o0 + 0xd0], %f56
5069 + ldd [%o0 + 0xd8], %f58
5070 + ldd [%o0 + 0xe0], %f60
5071 + ldd [%o0 + 0xe8], %f62
5072 + ldx [%o1 + 0x00], %g3
5073 ldx [%o1 + 0x08], %g7
5074 xor %g1, %g3, %g3
5075 xor %g2, %g7, %g7
5076 @@ -1128,9 +1132,9 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
5077 /* %o0=&key[key_len], %o1=input, %o2=output, %o3=len */
5078 ldx [%o0 - 0x10], %g1
5079 subcc %o3, 0x10, %o3
5080 + ldx [%o0 - 0x08], %g2
5081 be 10f
5082 - ldx [%o0 - 0x08], %g2
5083 - sub %o0, 0xf0, %o0
5084 + sub %o0, 0xf0, %o0
5085 1: ldx [%o1 + 0x00], %g3
5086 ldx [%o1 + 0x08], %g7
5087 ldx [%o1 + 0x10], %o4
5088 @@ -1154,7 +1158,11 @@ ENTRY(aes_sparc64_ecb_decrypt_256)
5089 add %o2, 0x20, %o2
5090 brlz,pt %o3, 11f
5091 nop
5092 -10: ldx [%o1 + 0x00], %g3
5093 +10: ldd [%o0 + 0x18], %f56
5094 + ldd [%o0 + 0x10], %f58
5095 + ldd [%o0 + 0x08], %f60
5096 + ldd [%o0 + 0x00], %f62
5097 + ldx [%o1 + 0x00], %g3
5098 ldx [%o1 + 0x08], %g7
5099 xor %g1, %g3, %g3
5100 xor %g2, %g7, %g7
5101 @@ -1511,11 +1519,11 @@ ENTRY(aes_sparc64_ctr_crypt_256)
5102 add %o2, 0x20, %o2
5103 brlz,pt %o3, 11f
5104 nop
5105 - ldd [%o0 + 0xd0], %f56
5106 +10: ldd [%o0 + 0xd0], %f56
5107 ldd [%o0 + 0xd8], %f58
5108 ldd [%o0 + 0xe0], %f60
5109 ldd [%o0 + 0xe8], %f62
5110 -10: xor %g1, %g3, %o5
5111 + xor %g1, %g3, %o5
5112 MOVXTOD_O5_F0
5113 xor %g2, %g7, %o5
5114 MOVXTOD_O5_F2
5115 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5116 index be56a24..443328f 100644
5117 --- a/arch/sparc/include/asm/atomic_64.h
5118 +++ b/arch/sparc/include/asm/atomic_64.h
5119 @@ -14,18 +14,40 @@
5120 #define ATOMIC64_INIT(i) { (i) }
5121
5122 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5123 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5124 +{
5125 + return v->counter;
5126 +}
5127 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5128 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5129 +{
5130 + return v->counter;
5131 +}
5132
5133 #define atomic_set(v, i) (((v)->counter) = i)
5134 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5135 +{
5136 + v->counter = i;
5137 +}
5138 #define atomic64_set(v, i) (((v)->counter) = i)
5139 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5140 +{
5141 + v->counter = i;
5142 +}
5143
5144 extern void atomic_add(int, atomic_t *);
5145 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5146 extern void atomic64_add(long, atomic64_t *);
5147 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5148 extern void atomic_sub(int, atomic_t *);
5149 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5150 extern void atomic64_sub(long, atomic64_t *);
5151 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5152
5153 extern int atomic_add_ret(int, atomic_t *);
5154 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5155 extern long atomic64_add_ret(long, atomic64_t *);
5156 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5157 extern int atomic_sub_ret(int, atomic_t *);
5158 extern long atomic64_sub_ret(long, atomic64_t *);
5159
5160 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5161 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5162
5163 #define atomic_inc_return(v) atomic_add_ret(1, v)
5164 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5165 +{
5166 + return atomic_add_ret_unchecked(1, v);
5167 +}
5168 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5169 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5170 +{
5171 + return atomic64_add_ret_unchecked(1, v);
5172 +}
5173
5174 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5175 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5176
5177 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5178 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5179 +{
5180 + return atomic_add_ret_unchecked(i, v);
5181 +}
5182 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5183 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5184 +{
5185 + return atomic64_add_ret_unchecked(i, v);
5186 +}
5187
5188 /*
5189 * atomic_inc_and_test - increment and test
5190 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5191 * other cases.
5192 */
5193 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5194 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5195 +{
5196 + return atomic_inc_return_unchecked(v) == 0;
5197 +}
5198 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5199
5200 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5201 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5202 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5203
5204 #define atomic_inc(v) atomic_add(1, v)
5205 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5206 +{
5207 + atomic_add_unchecked(1, v);
5208 +}
5209 #define atomic64_inc(v) atomic64_add(1, v)
5210 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5211 +{
5212 + atomic64_add_unchecked(1, v);
5213 +}
5214
5215 #define atomic_dec(v) atomic_sub(1, v)
5216 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5217 +{
5218 + atomic_sub_unchecked(1, v);
5219 +}
5220 #define atomic64_dec(v) atomic64_sub(1, v)
5221 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5222 +{
5223 + atomic64_sub_unchecked(1, v);
5224 +}
5225
5226 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5227 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5228
5229 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5230 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5231 +{
5232 + return cmpxchg(&v->counter, old, new);
5233 +}
5234 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5235 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5236 +{
5237 + return xchg(&v->counter, new);
5238 +}
5239
5240 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5241 {
5242 - int c, old;
5243 + int c, old, new;
5244 c = atomic_read(v);
5245 for (;;) {
5246 - if (unlikely(c == (u)))
5247 + if (unlikely(c == u))
5248 break;
5249 - old = atomic_cmpxchg((v), c, c + (a));
5250 +
5251 + asm volatile("addcc %2, %0, %0\n"
5252 +
5253 +#ifdef CONFIG_PAX_REFCOUNT
5254 + "tvs %%icc, 6\n"
5255 +#endif
5256 +
5257 + : "=r" (new)
5258 + : "0" (c), "ir" (a)
5259 + : "cc");
5260 +
5261 + old = atomic_cmpxchg(v, c, new);
5262 if (likely(old == c))
5263 break;
5264 c = old;
5265 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5266 #define atomic64_cmpxchg(v, o, n) \
5267 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5268 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5269 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5270 +{
5271 + return xchg(&v->counter, new);
5272 +}
5273
5274 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5275 {
5276 - long c, old;
5277 + long c, old, new;
5278 c = atomic64_read(v);
5279 for (;;) {
5280 - if (unlikely(c == (u)))
5281 + if (unlikely(c == u))
5282 break;
5283 - old = atomic64_cmpxchg((v), c, c + (a));
5284 +
5285 + asm volatile("addcc %2, %0, %0\n"
5286 +
5287 +#ifdef CONFIG_PAX_REFCOUNT
5288 + "tvs %%xcc, 6\n"
5289 +#endif
5290 +
5291 + : "=r" (new)
5292 + : "0" (c), "ir" (a)
5293 + : "cc");
5294 +
5295 + old = atomic64_cmpxchg(v, c, new);
5296 if (likely(old == c))
5297 break;
5298 c = old;
5299 }
5300 - return c != (u);
5301 + return c != u;
5302 }
5303
5304 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5305 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5306 index 5bb6991..5c2132e 100644
5307 --- a/arch/sparc/include/asm/cache.h
5308 +++ b/arch/sparc/include/asm/cache.h
5309 @@ -7,10 +7,12 @@
5310 #ifndef _SPARC_CACHE_H
5311 #define _SPARC_CACHE_H
5312
5313 +#include <linux/const.h>
5314 +
5315 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5316
5317 #define L1_CACHE_SHIFT 5
5318 -#define L1_CACHE_BYTES 32
5319 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5320
5321 #ifdef CONFIG_SPARC32
5322 #define SMP_CACHE_BYTES_SHIFT 5
5323 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5324 index ac74a2c..a9e58af 100644
5325 --- a/arch/sparc/include/asm/elf_32.h
5326 +++ b/arch/sparc/include/asm/elf_32.h
5327 @@ -114,6 +114,13 @@ typedef struct {
5328
5329 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5330
5331 +#ifdef CONFIG_PAX_ASLR
5332 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5333 +
5334 +#define PAX_DELTA_MMAP_LEN 16
5335 +#define PAX_DELTA_STACK_LEN 16
5336 +#endif
5337 +
5338 /* This yields a mask that user programs can use to figure out what
5339 instruction set this cpu supports. This can NOT be done in userspace
5340 on Sparc. */
5341 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5342 index 370ca1e..d4f4a98 100644
5343 --- a/arch/sparc/include/asm/elf_64.h
5344 +++ b/arch/sparc/include/asm/elf_64.h
5345 @@ -189,6 +189,13 @@ typedef struct {
5346 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5347 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5348
5349 +#ifdef CONFIG_PAX_ASLR
5350 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5351 +
5352 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5353 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5354 +#endif
5355 +
5356 extern unsigned long sparc64_elf_hwcap;
5357 #define ELF_HWCAP sparc64_elf_hwcap
5358
5359 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5360 index 9b1c36d..209298b 100644
5361 --- a/arch/sparc/include/asm/pgalloc_32.h
5362 +++ b/arch/sparc/include/asm/pgalloc_32.h
5363 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5364 }
5365
5366 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5367 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5368
5369 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5370 unsigned long address)
5371 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5372 index bcfe063..b333142 100644
5373 --- a/arch/sparc/include/asm/pgalloc_64.h
5374 +++ b/arch/sparc/include/asm/pgalloc_64.h
5375 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5376 }
5377
5378 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5379 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5380
5381 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5382 {
5383 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5384 index 6fc1348..390c50a 100644
5385 --- a/arch/sparc/include/asm/pgtable_32.h
5386 +++ b/arch/sparc/include/asm/pgtable_32.h
5387 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5388 #define PAGE_SHARED SRMMU_PAGE_SHARED
5389 #define PAGE_COPY SRMMU_PAGE_COPY
5390 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5391 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5392 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5393 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5394 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5395
5396 /* Top-level page directory - dummy used by init-mm.
5397 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5398
5399 /* xwr */
5400 #define __P000 PAGE_NONE
5401 -#define __P001 PAGE_READONLY
5402 -#define __P010 PAGE_COPY
5403 -#define __P011 PAGE_COPY
5404 +#define __P001 PAGE_READONLY_NOEXEC
5405 +#define __P010 PAGE_COPY_NOEXEC
5406 +#define __P011 PAGE_COPY_NOEXEC
5407 #define __P100 PAGE_READONLY
5408 #define __P101 PAGE_READONLY
5409 #define __P110 PAGE_COPY
5410 #define __P111 PAGE_COPY
5411
5412 #define __S000 PAGE_NONE
5413 -#define __S001 PAGE_READONLY
5414 -#define __S010 PAGE_SHARED
5415 -#define __S011 PAGE_SHARED
5416 +#define __S001 PAGE_READONLY_NOEXEC
5417 +#define __S010 PAGE_SHARED_NOEXEC
5418 +#define __S011 PAGE_SHARED_NOEXEC
5419 #define __S100 PAGE_READONLY
5420 #define __S101 PAGE_READONLY
5421 #define __S110 PAGE_SHARED
5422 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5423 index 79da178..c2eede8 100644
5424 --- a/arch/sparc/include/asm/pgtsrmmu.h
5425 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5426 @@ -115,6 +115,11 @@
5427 SRMMU_EXEC | SRMMU_REF)
5428 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5429 SRMMU_EXEC | SRMMU_REF)
5430 +
5431 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5432 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5433 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5434 +
5435 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5436 SRMMU_DIRTY | SRMMU_REF)
5437
5438 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5439 index 9689176..63c18ea 100644
5440 --- a/arch/sparc/include/asm/spinlock_64.h
5441 +++ b/arch/sparc/include/asm/spinlock_64.h
5442 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5443
5444 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5445
5446 -static void inline arch_read_lock(arch_rwlock_t *lock)
5447 +static inline void arch_read_lock(arch_rwlock_t *lock)
5448 {
5449 unsigned long tmp1, tmp2;
5450
5451 __asm__ __volatile__ (
5452 "1: ldsw [%2], %0\n"
5453 " brlz,pn %0, 2f\n"
5454 -"4: add %0, 1, %1\n"
5455 +"4: addcc %0, 1, %1\n"
5456 +
5457 +#ifdef CONFIG_PAX_REFCOUNT
5458 +" tvs %%icc, 6\n"
5459 +#endif
5460 +
5461 " cas [%2], %0, %1\n"
5462 " cmp %0, %1\n"
5463 " bne,pn %%icc, 1b\n"
5464 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5465 " .previous"
5466 : "=&r" (tmp1), "=&r" (tmp2)
5467 : "r" (lock)
5468 - : "memory");
5469 + : "memory", "cc");
5470 }
5471
5472 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5473 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5474 {
5475 int tmp1, tmp2;
5476
5477 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5478 "1: ldsw [%2], %0\n"
5479 " brlz,a,pn %0, 2f\n"
5480 " mov 0, %0\n"
5481 -" add %0, 1, %1\n"
5482 +" addcc %0, 1, %1\n"
5483 +
5484 +#ifdef CONFIG_PAX_REFCOUNT
5485 +" tvs %%icc, 6\n"
5486 +#endif
5487 +
5488 " cas [%2], %0, %1\n"
5489 " cmp %0, %1\n"
5490 " bne,pn %%icc, 1b\n"
5491 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5492 return tmp1;
5493 }
5494
5495 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5496 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5497 {
5498 unsigned long tmp1, tmp2;
5499
5500 __asm__ __volatile__(
5501 "1: lduw [%2], %0\n"
5502 -" sub %0, 1, %1\n"
5503 +" subcc %0, 1, %1\n"
5504 +
5505 +#ifdef CONFIG_PAX_REFCOUNT
5506 +" tvs %%icc, 6\n"
5507 +#endif
5508 +
5509 " cas [%2], %0, %1\n"
5510 " cmp %0, %1\n"
5511 " bne,pn %%xcc, 1b\n"
5512 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5513 : "memory");
5514 }
5515
5516 -static void inline arch_write_lock(arch_rwlock_t *lock)
5517 +static inline void arch_write_lock(arch_rwlock_t *lock)
5518 {
5519 unsigned long mask, tmp1, tmp2;
5520
5521 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5522 : "memory");
5523 }
5524
5525 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5526 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5527 {
5528 __asm__ __volatile__(
5529 " stw %%g0, [%0]"
5530 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5531 : "memory");
5532 }
5533
5534 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5535 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5536 {
5537 unsigned long mask, tmp1, tmp2, result;
5538
5539 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5540 index 25849ae..924c54b 100644
5541 --- a/arch/sparc/include/asm/thread_info_32.h
5542 +++ b/arch/sparc/include/asm/thread_info_32.h
5543 @@ -49,6 +49,8 @@ struct thread_info {
5544 unsigned long w_saved;
5545
5546 struct restart_block restart_block;
5547 +
5548 + unsigned long lowest_stack;
5549 };
5550
5551 /*
5552 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5553 index a3fe4dc..cae132a 100644
5554 --- a/arch/sparc/include/asm/thread_info_64.h
5555 +++ b/arch/sparc/include/asm/thread_info_64.h
5556 @@ -63,6 +63,8 @@ struct thread_info {
5557 struct pt_regs *kern_una_regs;
5558 unsigned int kern_una_insn;
5559
5560 + unsigned long lowest_stack;
5561 +
5562 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5563 };
5564
5565 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5566 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5567 /* flag bit 6 is available */
5568 #define TIF_32BIT 7 /* 32-bit binary */
5569 -/* flag bit 8 is available */
5570 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5571 #define TIF_SECCOMP 9 /* secure computing */
5572 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5573 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5574 +
5575 /* NOTE: Thread flags >= 12 should be ones we have no interest
5576 * in using in assembly, else we can't use the mask as
5577 * an immediate value in instructions such as andcc.
5578 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5579 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5580 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5581 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5582 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5583
5584 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5585 _TIF_DO_NOTIFY_RESUME_MASK | \
5586 _TIF_NEED_RESCHED)
5587 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5588
5589 +#define _TIF_WORK_SYSCALL \
5590 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5591 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5592 +
5593 +
5594 /*
5595 * Thread-synchronous status.
5596 *
5597 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5598 index 0167d26..9acd8ed 100644
5599 --- a/arch/sparc/include/asm/uaccess.h
5600 +++ b/arch/sparc/include/asm/uaccess.h
5601 @@ -1,5 +1,13 @@
5602 #ifndef ___ASM_SPARC_UACCESS_H
5603 #define ___ASM_SPARC_UACCESS_H
5604 +
5605 +#ifdef __KERNEL__
5606 +#ifndef __ASSEMBLY__
5607 +#include <linux/types.h>
5608 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5609 +#endif
5610 +#endif
5611 +
5612 #if defined(__sparc__) && defined(__arch64__)
5613 #include <asm/uaccess_64.h>
5614 #else
5615 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5616 index 53a28dd..50c38c3 100644
5617 --- a/arch/sparc/include/asm/uaccess_32.h
5618 +++ b/arch/sparc/include/asm/uaccess_32.h
5619 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5620
5621 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5622 {
5623 - if (n && __access_ok((unsigned long) to, n))
5624 + if ((long)n < 0)
5625 + return n;
5626 +
5627 + if (n && __access_ok((unsigned long) to, n)) {
5628 + if (!__builtin_constant_p(n))
5629 + check_object_size(from, n, true);
5630 return __copy_user(to, (__force void __user *) from, n);
5631 - else
5632 + } else
5633 return n;
5634 }
5635
5636 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5637 {
5638 + if ((long)n < 0)
5639 + return n;
5640 +
5641 + if (!__builtin_constant_p(n))
5642 + check_object_size(from, n, true);
5643 +
5644 return __copy_user(to, (__force void __user *) from, n);
5645 }
5646
5647 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5648 {
5649 - if (n && __access_ok((unsigned long) from, n))
5650 + if ((long)n < 0)
5651 + return n;
5652 +
5653 + if (n && __access_ok((unsigned long) from, n)) {
5654 + if (!__builtin_constant_p(n))
5655 + check_object_size(to, n, false);
5656 return __copy_user((__force void __user *) to, from, n);
5657 - else
5658 + } else
5659 return n;
5660 }
5661
5662 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5663 {
5664 + if ((long)n < 0)
5665 + return n;
5666 +
5667 return __copy_user((__force void __user *) to, from, n);
5668 }
5669
5670 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5671 index 73083e1..2bc62a6 100644
5672 --- a/arch/sparc/include/asm/uaccess_64.h
5673 +++ b/arch/sparc/include/asm/uaccess_64.h
5674 @@ -10,6 +10,7 @@
5675 #include <linux/compiler.h>
5676 #include <linux/string.h>
5677 #include <linux/thread_info.h>
5678 +#include <linux/kernel.h>
5679 #include <asm/asi.h>
5680 #include <asm/spitfire.h>
5681 #include <asm-generic/uaccess-unaligned.h>
5682 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5683 static inline unsigned long __must_check
5684 copy_from_user(void *to, const void __user *from, unsigned long size)
5685 {
5686 - unsigned long ret = ___copy_from_user(to, from, size);
5687 + unsigned long ret;
5688
5689 + if ((long)size < 0 || size > INT_MAX)
5690 + return size;
5691 +
5692 + if (!__builtin_constant_p(size))
5693 + check_object_size(to, size, false);
5694 +
5695 + ret = ___copy_from_user(to, from, size);
5696 if (unlikely(ret))
5697 ret = copy_from_user_fixup(to, from, size);
5698
5699 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5700 static inline unsigned long __must_check
5701 copy_to_user(void __user *to, const void *from, unsigned long size)
5702 {
5703 - unsigned long ret = ___copy_to_user(to, from, size);
5704 + unsigned long ret;
5705
5706 + if ((long)size < 0 || size > INT_MAX)
5707 + return size;
5708 +
5709 + if (!__builtin_constant_p(size))
5710 + check_object_size(from, size, true);
5711 +
5712 + ret = ___copy_to_user(to, from, size);
5713 if (unlikely(ret))
5714 ret = copy_to_user_fixup(to, from, size);
5715 return ret;
5716 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5717 index 6cf591b..b49e65a 100644
5718 --- a/arch/sparc/kernel/Makefile
5719 +++ b/arch/sparc/kernel/Makefile
5720 @@ -3,7 +3,7 @@
5721 #
5722
5723 asflags-y := -ansi
5724 -ccflags-y := -Werror
5725 +#ccflags-y := -Werror
5726
5727 extra-y := head_$(BITS).o
5728
5729 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5730 index 487bffb..955a925 100644
5731 --- a/arch/sparc/kernel/process_32.c
5732 +++ b/arch/sparc/kernel/process_32.c
5733 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5734
5735 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5736 r->psr, r->pc, r->npc, r->y, print_tainted());
5737 - printk("PC: <%pS>\n", (void *) r->pc);
5738 + printk("PC: <%pA>\n", (void *) r->pc);
5739 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5740 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5741 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5742 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5743 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5744 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5745 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5746 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5747
5748 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5749 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5750 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5751 rw = (struct reg_window32 *) fp;
5752 pc = rw->ins[7];
5753 printk("[%08lx : ", pc);
5754 - printk("%pS ] ", (void *) pc);
5755 + printk("%pA ] ", (void *) pc);
5756 fp = rw->ins[6];
5757 } while (++count < 16);
5758 printk("\n");
5759 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5760 index c6e0c29..052832b 100644
5761 --- a/arch/sparc/kernel/process_64.c
5762 +++ b/arch/sparc/kernel/process_64.c
5763 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
5764 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5765 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5766 if (regs->tstate & TSTATE_PRIV)
5767 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5768 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5769 }
5770
5771 void show_regs(struct pt_regs *regs)
5772 {
5773 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5774 regs->tpc, regs->tnpc, regs->y, print_tainted());
5775 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5776 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5777 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5778 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5779 regs->u_regs[3]);
5780 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
5781 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5782 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5783 regs->u_regs[15]);
5784 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5785 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5786 show_regwindow(regs);
5787 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5788 }
5789 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
5790 ((tp && tp->task) ? tp->task->pid : -1));
5791
5792 if (gp->tstate & TSTATE_PRIV) {
5793 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5794 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5795 (void *) gp->tpc,
5796 (void *) gp->o7,
5797 (void *) gp->i7,
5798 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5799 index 7ff45e4..a58f271 100644
5800 --- a/arch/sparc/kernel/ptrace_64.c
5801 +++ b/arch/sparc/kernel/ptrace_64.c
5802 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5803 return ret;
5804 }
5805
5806 +#ifdef CONFIG_GRKERNSEC_SETXID
5807 +extern void gr_delayed_cred_worker(void);
5808 +#endif
5809 +
5810 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5811 {
5812 int ret = 0;
5813 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5814 /* do the secure computing check first */
5815 secure_computing_strict(regs->u_regs[UREG_G1]);
5816
5817 +#ifdef CONFIG_GRKERNSEC_SETXID
5818 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5819 + gr_delayed_cred_worker();
5820 +#endif
5821 +
5822 if (test_thread_flag(TIF_SYSCALL_TRACE))
5823 ret = tracehook_report_syscall_entry(regs);
5824
5825 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5826
5827 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5828 {
5829 +#ifdef CONFIG_GRKERNSEC_SETXID
5830 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5831 + gr_delayed_cred_worker();
5832 +#endif
5833 +
5834 audit_syscall_exit(regs);
5835
5836 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5837 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5838 index 0c9b31b..7cb7aee 100644
5839 --- a/arch/sparc/kernel/sys_sparc_32.c
5840 +++ b/arch/sparc/kernel/sys_sparc_32.c
5841 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5842 if (len > TASK_SIZE - PAGE_SIZE)
5843 return -ENOMEM;
5844 if (!addr)
5845 - addr = TASK_UNMAPPED_BASE;
5846 + addr = current->mm->mmap_base;
5847
5848 if (flags & MAP_SHARED)
5849 addr = COLOUR_ALIGN(addr);
5850 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5851 /* At this point: (!vmm || addr < vmm->vm_end). */
5852 if (TASK_SIZE - PAGE_SIZE - len < addr)
5853 return -ENOMEM;
5854 - if (!vmm || addr + len <= vmm->vm_start)
5855 + if (check_heap_stack_gap(vmm, addr, len))
5856 return addr;
5857 addr = vmm->vm_end;
5858 if (flags & MAP_SHARED)
5859 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5860 index 878ef3d..8742f10 100644
5861 --- a/arch/sparc/kernel/sys_sparc_64.c
5862 +++ b/arch/sparc/kernel/sys_sparc_64.c
5863 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5864 /* We do not accept a shared mapping if it would violate
5865 * cache aliasing constraints.
5866 */
5867 - if ((flags & MAP_SHARED) &&
5868 + if ((filp || (flags & MAP_SHARED)) &&
5869 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5870 return -EINVAL;
5871 return addr;
5872 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5873 if (filp || (flags & MAP_SHARED))
5874 do_color_align = 1;
5875
5876 +#ifdef CONFIG_PAX_RANDMMAP
5877 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5878 +#endif
5879 +
5880 if (addr) {
5881 if (do_color_align)
5882 addr = COLOUR_ALIGN(addr, pgoff);
5883 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5884 addr = PAGE_ALIGN(addr);
5885
5886 vma = find_vma(mm, addr);
5887 - if (task_size - len >= addr &&
5888 - (!vma || addr + len <= vma->vm_start))
5889 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5890 return addr;
5891 }
5892
5893 if (len > mm->cached_hole_size) {
5894 - start_addr = addr = mm->free_area_cache;
5895 + start_addr = addr = mm->free_area_cache;
5896 } else {
5897 - start_addr = addr = TASK_UNMAPPED_BASE;
5898 + start_addr = addr = mm->mmap_base;
5899 mm->cached_hole_size = 0;
5900 }
5901
5902 @@ -157,14 +160,14 @@ full_search:
5903 vma = find_vma(mm, VA_EXCLUDE_END);
5904 }
5905 if (unlikely(task_size < addr)) {
5906 - if (start_addr != TASK_UNMAPPED_BASE) {
5907 - start_addr = addr = TASK_UNMAPPED_BASE;
5908 + if (start_addr != mm->mmap_base) {
5909 + start_addr = addr = mm->mmap_base;
5910 mm->cached_hole_size = 0;
5911 goto full_search;
5912 }
5913 return -ENOMEM;
5914 }
5915 - if (likely(!vma || addr + len <= vma->vm_start)) {
5916 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5917 /*
5918 * Remember the place where we stopped the search:
5919 */
5920 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5921 /* We do not accept a shared mapping if it would violate
5922 * cache aliasing constraints.
5923 */
5924 - if ((flags & MAP_SHARED) &&
5925 + if ((filp || (flags & MAP_SHARED)) &&
5926 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5927 return -EINVAL;
5928 return addr;
5929 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5930 addr = PAGE_ALIGN(addr);
5931
5932 vma = find_vma(mm, addr);
5933 - if (task_size - len >= addr &&
5934 - (!vma || addr + len <= vma->vm_start))
5935 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5936 return addr;
5937 }
5938
5939 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5940 /* make sure it can fit in the remaining address space */
5941 if (likely(addr > len)) {
5942 vma = find_vma(mm, addr-len);
5943 - if (!vma || addr <= vma->vm_start) {
5944 + if (check_heap_stack_gap(vma, addr - len, len)) {
5945 /* remember the address as a hint for next time */
5946 return (mm->free_area_cache = addr-len);
5947 }
5948 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5949 if (unlikely(mm->mmap_base < len))
5950 goto bottomup;
5951
5952 - addr = mm->mmap_base-len;
5953 - if (do_color_align)
5954 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5955 + addr = mm->mmap_base - len;
5956
5957 do {
5958 + if (do_color_align)
5959 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5960 /*
5961 * Lookup failure means no vma is above this address,
5962 * else if new region fits below vma->vm_start,
5963 * return with success:
5964 */
5965 vma = find_vma(mm, addr);
5966 - if (likely(!vma || addr+len <= vma->vm_start)) {
5967 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5968 /* remember the address as a hint for next time */
5969 return (mm->free_area_cache = addr);
5970 }
5971 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5972 mm->cached_hole_size = vma->vm_start - addr;
5973
5974 /* try just below the current vma->vm_start */
5975 - addr = vma->vm_start-len;
5976 - if (do_color_align)
5977 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5978 - } while (likely(len < vma->vm_start));
5979 + addr = skip_heap_stack_gap(vma, len);
5980 + } while (!IS_ERR_VALUE(addr));
5981
5982 bottomup:
5983 /*
5984 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5985 gap == RLIM_INFINITY ||
5986 sysctl_legacy_va_layout) {
5987 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5988 +
5989 +#ifdef CONFIG_PAX_RANDMMAP
5990 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5991 + mm->mmap_base += mm->delta_mmap;
5992 +#endif
5993 +
5994 mm->get_unmapped_area = arch_get_unmapped_area;
5995 mm->unmap_area = arch_unmap_area;
5996 } else {
5997 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5998 gap = (task_size / 6 * 5);
5999
6000 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6001 +
6002 +#ifdef CONFIG_PAX_RANDMMAP
6003 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6004 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6005 +#endif
6006 +
6007 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6008 mm->unmap_area = arch_unmap_area_topdown;
6009 }
6010 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6011 index bf23477..b7425a6 100644
6012 --- a/arch/sparc/kernel/syscalls.S
6013 +++ b/arch/sparc/kernel/syscalls.S
6014 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6015 #endif
6016 .align 32
6017 1: ldx [%g6 + TI_FLAGS], %l5
6018 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6019 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6020 be,pt %icc, rtrap
6021 nop
6022 call syscall_trace_leave
6023 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
6024
6025 srl %i5, 0, %o5 ! IEU1
6026 srl %i2, 0, %o2 ! IEU0 Group
6027 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6028 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6029 bne,pn %icc, linux_syscall_trace32 ! CTI
6030 mov %i0, %l5 ! IEU1
6031 call %l7 ! CTI Group brk forced
6032 @@ -212,7 +212,7 @@ linux_sparc_syscall:
6033
6034 mov %i3, %o3 ! IEU1
6035 mov %i4, %o4 ! IEU0 Group
6036 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6037 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6038 bne,pn %icc, linux_syscall_trace ! CTI Group
6039 mov %i0, %l5 ! IEU0
6040 2: call %l7 ! CTI Group brk forced
6041 @@ -228,7 +228,7 @@ ret_sys_call:
6042
6043 cmp %o0, -ERESTART_RESTARTBLOCK
6044 bgeu,pn %xcc, 1f
6045 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6046 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6047 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6048
6049 2:
6050 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6051 index a5785ea..405c5f7 100644
6052 --- a/arch/sparc/kernel/traps_32.c
6053 +++ b/arch/sparc/kernel/traps_32.c
6054 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6055 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6056 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6057
6058 +extern void gr_handle_kernel_exploit(void);
6059 +
6060 void die_if_kernel(char *str, struct pt_regs *regs)
6061 {
6062 static int die_counter;
6063 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6064 count++ < 30 &&
6065 (((unsigned long) rw) >= PAGE_OFFSET) &&
6066 !(((unsigned long) rw) & 0x7)) {
6067 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6068 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6069 (void *) rw->ins[7]);
6070 rw = (struct reg_window32 *)rw->ins[6];
6071 }
6072 }
6073 printk("Instruction DUMP:");
6074 instruction_dump ((unsigned long *) regs->pc);
6075 - if(regs->psr & PSR_PS)
6076 + if(regs->psr & PSR_PS) {
6077 + gr_handle_kernel_exploit();
6078 do_exit(SIGKILL);
6079 + }
6080 do_exit(SIGSEGV);
6081 }
6082
6083 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6084 index b66a779..8e8d66c 100644
6085 --- a/arch/sparc/kernel/traps_64.c
6086 +++ b/arch/sparc/kernel/traps_64.c
6087 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6088 i + 1,
6089 p->trapstack[i].tstate, p->trapstack[i].tpc,
6090 p->trapstack[i].tnpc, p->trapstack[i].tt);
6091 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6092 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6093 }
6094 }
6095
6096 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6097
6098 lvl -= 0x100;
6099 if (regs->tstate & TSTATE_PRIV) {
6100 +
6101 +#ifdef CONFIG_PAX_REFCOUNT
6102 + if (lvl == 6)
6103 + pax_report_refcount_overflow(regs);
6104 +#endif
6105 +
6106 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6107 die_if_kernel(buffer, regs);
6108 }
6109 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6110 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6111 {
6112 char buffer[32];
6113 -
6114 +
6115 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6116 0, lvl, SIGTRAP) == NOTIFY_STOP)
6117 return;
6118
6119 +#ifdef CONFIG_PAX_REFCOUNT
6120 + if (lvl == 6)
6121 + pax_report_refcount_overflow(regs);
6122 +#endif
6123 +
6124 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6125
6126 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6127 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6128 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6129 printk("%s" "ERROR(%d): ",
6130 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6131 - printk("TPC<%pS>\n", (void *) regs->tpc);
6132 + printk("TPC<%pA>\n", (void *) regs->tpc);
6133 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6134 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6135 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6136 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6137 smp_processor_id(),
6138 (type & 0x1) ? 'I' : 'D',
6139 regs->tpc);
6140 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6141 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6142 panic("Irrecoverable Cheetah+ parity error.");
6143 }
6144
6145 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6146 smp_processor_id(),
6147 (type & 0x1) ? 'I' : 'D',
6148 regs->tpc);
6149 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6150 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6151 }
6152
6153 struct sun4v_error_entry {
6154 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6155
6156 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6157 regs->tpc, tl);
6158 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6159 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6160 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6161 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6162 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6163 (void *) regs->u_regs[UREG_I7]);
6164 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6165 "pte[%lx] error[%lx]\n",
6166 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6167
6168 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6169 regs->tpc, tl);
6170 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6171 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6172 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6173 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6174 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6175 (void *) regs->u_regs[UREG_I7]);
6176 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6177 "pte[%lx] error[%lx]\n",
6178 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6179 fp = (unsigned long)sf->fp + STACK_BIAS;
6180 }
6181
6182 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6183 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6184 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6185 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6186 int index = tsk->curr_ret_stack;
6187 if (tsk->ret_stack && index >= graph) {
6188 pc = tsk->ret_stack[index - graph].ret;
6189 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6190 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6191 graph++;
6192 }
6193 }
6194 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6195 return (struct reg_window *) (fp + STACK_BIAS);
6196 }
6197
6198 +extern void gr_handle_kernel_exploit(void);
6199 +
6200 void die_if_kernel(char *str, struct pt_regs *regs)
6201 {
6202 static int die_counter;
6203 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6204 while (rw &&
6205 count++ < 30 &&
6206 kstack_valid(tp, (unsigned long) rw)) {
6207 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6208 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6209 (void *) rw->ins[7]);
6210
6211 rw = kernel_stack_up(rw);
6212 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6213 }
6214 user_instruction_dump ((unsigned int __user *) regs->tpc);
6215 }
6216 - if (regs->tstate & TSTATE_PRIV)
6217 + if (regs->tstate & TSTATE_PRIV) {
6218 + gr_handle_kernel_exploit();
6219 do_exit(SIGKILL);
6220 + }
6221 do_exit(SIGSEGV);
6222 }
6223 EXPORT_SYMBOL(die_if_kernel);
6224 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6225 index 8201c25e..072a2a7 100644
6226 --- a/arch/sparc/kernel/unaligned_64.c
6227 +++ b/arch/sparc/kernel/unaligned_64.c
6228 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
6229 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6230
6231 if (__ratelimit(&ratelimit)) {
6232 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6233 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6234 regs->tpc, (void *) regs->tpc);
6235 }
6236 }
6237 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6238 index 8410065f2..4fd4ca22 100644
6239 --- a/arch/sparc/lib/Makefile
6240 +++ b/arch/sparc/lib/Makefile
6241 @@ -2,7 +2,7 @@
6242 #
6243
6244 asflags-y := -ansi -DST_DIV0=0x02
6245 -ccflags-y := -Werror
6246 +#ccflags-y := -Werror
6247
6248 lib-$(CONFIG_SPARC32) += ashrdi3.o
6249 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6250 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6251 index 85c233d..68500e0 100644
6252 --- a/arch/sparc/lib/atomic_64.S
6253 +++ b/arch/sparc/lib/atomic_64.S
6254 @@ -17,7 +17,12 @@
6255 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6256 BACKOFF_SETUP(%o2)
6257 1: lduw [%o1], %g1
6258 - add %g1, %o0, %g7
6259 + addcc %g1, %o0, %g7
6260 +
6261 +#ifdef CONFIG_PAX_REFCOUNT
6262 + tvs %icc, 6
6263 +#endif
6264 +
6265 cas [%o1], %g1, %g7
6266 cmp %g1, %g7
6267 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6268 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6269 2: BACKOFF_SPIN(%o2, %o3, 1b)
6270 ENDPROC(atomic_add)
6271
6272 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6273 + BACKOFF_SETUP(%o2)
6274 +1: lduw [%o1], %g1
6275 + add %g1, %o0, %g7
6276 + cas [%o1], %g1, %g7
6277 + cmp %g1, %g7
6278 + bne,pn %icc, 2f
6279 + nop
6280 + retl
6281 + nop
6282 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6283 +ENDPROC(atomic_add_unchecked)
6284 +
6285 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6286 BACKOFF_SETUP(%o2)
6287 1: lduw [%o1], %g1
6288 - sub %g1, %o0, %g7
6289 + subcc %g1, %o0, %g7
6290 +
6291 +#ifdef CONFIG_PAX_REFCOUNT
6292 + tvs %icc, 6
6293 +#endif
6294 +
6295 cas [%o1], %g1, %g7
6296 cmp %g1, %g7
6297 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6298 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6299 2: BACKOFF_SPIN(%o2, %o3, 1b)
6300 ENDPROC(atomic_sub)
6301
6302 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6303 + BACKOFF_SETUP(%o2)
6304 +1: lduw [%o1], %g1
6305 + sub %g1, %o0, %g7
6306 + cas [%o1], %g1, %g7
6307 + cmp %g1, %g7
6308 + bne,pn %icc, 2f
6309 + nop
6310 + retl
6311 + nop
6312 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6313 +ENDPROC(atomic_sub_unchecked)
6314 +
6315 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6316 BACKOFF_SETUP(%o2)
6317 1: lduw [%o1], %g1
6318 - add %g1, %o0, %g7
6319 + addcc %g1, %o0, %g7
6320 +
6321 +#ifdef CONFIG_PAX_REFCOUNT
6322 + tvs %icc, 6
6323 +#endif
6324 +
6325 cas [%o1], %g1, %g7
6326 cmp %g1, %g7
6327 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6328 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6329 2: BACKOFF_SPIN(%o2, %o3, 1b)
6330 ENDPROC(atomic_add_ret)
6331
6332 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6333 + BACKOFF_SETUP(%o2)
6334 +1: lduw [%o1], %g1
6335 + addcc %g1, %o0, %g7
6336 + cas [%o1], %g1, %g7
6337 + cmp %g1, %g7
6338 + bne,pn %icc, 2f
6339 + add %g7, %o0, %g7
6340 + sra %g7, 0, %o0
6341 + retl
6342 + nop
6343 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6344 +ENDPROC(atomic_add_ret_unchecked)
6345 +
6346 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6347 BACKOFF_SETUP(%o2)
6348 1: lduw [%o1], %g1
6349 - sub %g1, %o0, %g7
6350 + subcc %g1, %o0, %g7
6351 +
6352 +#ifdef CONFIG_PAX_REFCOUNT
6353 + tvs %icc, 6
6354 +#endif
6355 +
6356 cas [%o1], %g1, %g7
6357 cmp %g1, %g7
6358 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6359 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6360 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6361 BACKOFF_SETUP(%o2)
6362 1: ldx [%o1], %g1
6363 - add %g1, %o0, %g7
6364 + addcc %g1, %o0, %g7
6365 +
6366 +#ifdef CONFIG_PAX_REFCOUNT
6367 + tvs %xcc, 6
6368 +#endif
6369 +
6370 casx [%o1], %g1, %g7
6371 cmp %g1, %g7
6372 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6373 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6374 2: BACKOFF_SPIN(%o2, %o3, 1b)
6375 ENDPROC(atomic64_add)
6376
6377 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6378 + BACKOFF_SETUP(%o2)
6379 +1: ldx [%o1], %g1
6380 + addcc %g1, %o0, %g7
6381 + casx [%o1], %g1, %g7
6382 + cmp %g1, %g7
6383 + bne,pn %xcc, 2f
6384 + nop
6385 + retl
6386 + nop
6387 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6388 +ENDPROC(atomic64_add_unchecked)
6389 +
6390 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6391 BACKOFF_SETUP(%o2)
6392 1: ldx [%o1], %g1
6393 - sub %g1, %o0, %g7
6394 + subcc %g1, %o0, %g7
6395 +
6396 +#ifdef CONFIG_PAX_REFCOUNT
6397 + tvs %xcc, 6
6398 +#endif
6399 +
6400 casx [%o1], %g1, %g7
6401 cmp %g1, %g7
6402 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6403 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6404 2: BACKOFF_SPIN(%o2, %o3, 1b)
6405 ENDPROC(atomic64_sub)
6406
6407 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6408 + BACKOFF_SETUP(%o2)
6409 +1: ldx [%o1], %g1
6410 + subcc %g1, %o0, %g7
6411 + casx [%o1], %g1, %g7
6412 + cmp %g1, %g7
6413 + bne,pn %xcc, 2f
6414 + nop
6415 + retl
6416 + nop
6417 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6418 +ENDPROC(atomic64_sub_unchecked)
6419 +
6420 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6421 BACKOFF_SETUP(%o2)
6422 1: ldx [%o1], %g1
6423 - add %g1, %o0, %g7
6424 + addcc %g1, %o0, %g7
6425 +
6426 +#ifdef CONFIG_PAX_REFCOUNT
6427 + tvs %xcc, 6
6428 +#endif
6429 +
6430 casx [%o1], %g1, %g7
6431 cmp %g1, %g7
6432 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6433 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6434 2: BACKOFF_SPIN(%o2, %o3, 1b)
6435 ENDPROC(atomic64_add_ret)
6436
6437 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6438 + BACKOFF_SETUP(%o2)
6439 +1: ldx [%o1], %g1
6440 + addcc %g1, %o0, %g7
6441 + casx [%o1], %g1, %g7
6442 + cmp %g1, %g7
6443 + bne,pn %xcc, 2f
6444 + add %g7, %o0, %g7
6445 + mov %g7, %o0
6446 + retl
6447 + nop
6448 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6449 +ENDPROC(atomic64_add_ret_unchecked)
6450 +
6451 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6452 BACKOFF_SETUP(%o2)
6453 1: ldx [%o1], %g1
6454 - sub %g1, %o0, %g7
6455 + subcc %g1, %o0, %g7
6456 +
6457 +#ifdef CONFIG_PAX_REFCOUNT
6458 + tvs %xcc, 6
6459 +#endif
6460 +
6461 casx [%o1], %g1, %g7
6462 cmp %g1, %g7
6463 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6464 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6465 index 0c4e35e..745d3e4 100644
6466 --- a/arch/sparc/lib/ksyms.c
6467 +++ b/arch/sparc/lib/ksyms.c
6468 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6469
6470 /* Atomic counter implementation. */
6471 EXPORT_SYMBOL(atomic_add);
6472 +EXPORT_SYMBOL(atomic_add_unchecked);
6473 EXPORT_SYMBOL(atomic_add_ret);
6474 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6475 EXPORT_SYMBOL(atomic_sub);
6476 +EXPORT_SYMBOL(atomic_sub_unchecked);
6477 EXPORT_SYMBOL(atomic_sub_ret);
6478 EXPORT_SYMBOL(atomic64_add);
6479 +EXPORT_SYMBOL(atomic64_add_unchecked);
6480 EXPORT_SYMBOL(atomic64_add_ret);
6481 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6482 EXPORT_SYMBOL(atomic64_sub);
6483 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6484 EXPORT_SYMBOL(atomic64_sub_ret);
6485 EXPORT_SYMBOL(atomic64_dec_if_positive);
6486
6487 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6488 index 30c3ecc..736f015 100644
6489 --- a/arch/sparc/mm/Makefile
6490 +++ b/arch/sparc/mm/Makefile
6491 @@ -2,7 +2,7 @@
6492 #
6493
6494 asflags-y := -ansi
6495 -ccflags-y := -Werror
6496 +#ccflags-y := -Werror
6497
6498 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6499 obj-y += fault_$(BITS).o
6500 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6501 index e98bfda..ea8d221 100644
6502 --- a/arch/sparc/mm/fault_32.c
6503 +++ b/arch/sparc/mm/fault_32.c
6504 @@ -21,6 +21,9 @@
6505 #include <linux/perf_event.h>
6506 #include <linux/interrupt.h>
6507 #include <linux/kdebug.h>
6508 +#include <linux/slab.h>
6509 +#include <linux/pagemap.h>
6510 +#include <linux/compiler.h>
6511
6512 #include <asm/page.h>
6513 #include <asm/pgtable.h>
6514 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6515 return safe_compute_effective_address(regs, insn);
6516 }
6517
6518 +#ifdef CONFIG_PAX_PAGEEXEC
6519 +#ifdef CONFIG_PAX_DLRESOLVE
6520 +static void pax_emuplt_close(struct vm_area_struct *vma)
6521 +{
6522 + vma->vm_mm->call_dl_resolve = 0UL;
6523 +}
6524 +
6525 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6526 +{
6527 + unsigned int *kaddr;
6528 +
6529 + vmf->page = alloc_page(GFP_HIGHUSER);
6530 + if (!vmf->page)
6531 + return VM_FAULT_OOM;
6532 +
6533 + kaddr = kmap(vmf->page);
6534 + memset(kaddr, 0, PAGE_SIZE);
6535 + kaddr[0] = 0x9DE3BFA8U; /* save */
6536 + flush_dcache_page(vmf->page);
6537 + kunmap(vmf->page);
6538 + return VM_FAULT_MAJOR;
6539 +}
6540 +
6541 +static const struct vm_operations_struct pax_vm_ops = {
6542 + .close = pax_emuplt_close,
6543 + .fault = pax_emuplt_fault
6544 +};
6545 +
6546 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6547 +{
6548 + int ret;
6549 +
6550 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6551 + vma->vm_mm = current->mm;
6552 + vma->vm_start = addr;
6553 + vma->vm_end = addr + PAGE_SIZE;
6554 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6555 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6556 + vma->vm_ops = &pax_vm_ops;
6557 +
6558 + ret = insert_vm_struct(current->mm, vma);
6559 + if (ret)
6560 + return ret;
6561 +
6562 + ++current->mm->total_vm;
6563 + return 0;
6564 +}
6565 +#endif
6566 +
6567 +/*
6568 + * PaX: decide what to do with offenders (regs->pc = fault address)
6569 + *
6570 + * returns 1 when task should be killed
6571 + * 2 when patched PLT trampoline was detected
6572 + * 3 when unpatched PLT trampoline was detected
6573 + */
6574 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6575 +{
6576 +
6577 +#ifdef CONFIG_PAX_EMUPLT
6578 + int err;
6579 +
6580 + do { /* PaX: patched PLT emulation #1 */
6581 + unsigned int sethi1, sethi2, jmpl;
6582 +
6583 + err = get_user(sethi1, (unsigned int *)regs->pc);
6584 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6585 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6586 +
6587 + if (err)
6588 + break;
6589 +
6590 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6591 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6592 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6593 + {
6594 + unsigned int addr;
6595 +
6596 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6597 + addr = regs->u_regs[UREG_G1];
6598 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6599 + regs->pc = addr;
6600 + regs->npc = addr+4;
6601 + return 2;
6602 + }
6603 + } while (0);
6604 +
6605 + do { /* PaX: patched PLT emulation #2 */
6606 + unsigned int ba;
6607 +
6608 + err = get_user(ba, (unsigned int *)regs->pc);
6609 +
6610 + if (err)
6611 + break;
6612 +
6613 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6614 + unsigned int addr;
6615 +
6616 + if ((ba & 0xFFC00000U) == 0x30800000U)
6617 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6618 + else
6619 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6620 + regs->pc = addr;
6621 + regs->npc = addr+4;
6622 + return 2;
6623 + }
6624 + } while (0);
6625 +
6626 + do { /* PaX: patched PLT emulation #3 */
6627 + unsigned int sethi, bajmpl, nop;
6628 +
6629 + err = get_user(sethi, (unsigned int *)regs->pc);
6630 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6631 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6632 +
6633 + if (err)
6634 + break;
6635 +
6636 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6637 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6638 + nop == 0x01000000U)
6639 + {
6640 + unsigned int addr;
6641 +
6642 + addr = (sethi & 0x003FFFFFU) << 10;
6643 + regs->u_regs[UREG_G1] = addr;
6644 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6645 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6646 + else
6647 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6648 + regs->pc = addr;
6649 + regs->npc = addr+4;
6650 + return 2;
6651 + }
6652 + } while (0);
6653 +
6654 + do { /* PaX: unpatched PLT emulation step 1 */
6655 + unsigned int sethi, ba, nop;
6656 +
6657 + err = get_user(sethi, (unsigned int *)regs->pc);
6658 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6659 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6660 +
6661 + if (err)
6662 + break;
6663 +
6664 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6665 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6666 + nop == 0x01000000U)
6667 + {
6668 + unsigned int addr, save, call;
6669 +
6670 + if ((ba & 0xFFC00000U) == 0x30800000U)
6671 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6672 + else
6673 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6674 +
6675 + err = get_user(save, (unsigned int *)addr);
6676 + err |= get_user(call, (unsigned int *)(addr+4));
6677 + err |= get_user(nop, (unsigned int *)(addr+8));
6678 + if (err)
6679 + break;
6680 +
6681 +#ifdef CONFIG_PAX_DLRESOLVE
6682 + if (save == 0x9DE3BFA8U &&
6683 + (call & 0xC0000000U) == 0x40000000U &&
6684 + nop == 0x01000000U)
6685 + {
6686 + struct vm_area_struct *vma;
6687 + unsigned long call_dl_resolve;
6688 +
6689 + down_read(&current->mm->mmap_sem);
6690 + call_dl_resolve = current->mm->call_dl_resolve;
6691 + up_read(&current->mm->mmap_sem);
6692 + if (likely(call_dl_resolve))
6693 + goto emulate;
6694 +
6695 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6696 +
6697 + down_write(&current->mm->mmap_sem);
6698 + if (current->mm->call_dl_resolve) {
6699 + call_dl_resolve = current->mm->call_dl_resolve;
6700 + up_write(&current->mm->mmap_sem);
6701 + if (vma)
6702 + kmem_cache_free(vm_area_cachep, vma);
6703 + goto emulate;
6704 + }
6705 +
6706 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6707 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6708 + up_write(&current->mm->mmap_sem);
6709 + if (vma)
6710 + kmem_cache_free(vm_area_cachep, vma);
6711 + return 1;
6712 + }
6713 +
6714 + if (pax_insert_vma(vma, call_dl_resolve)) {
6715 + up_write(&current->mm->mmap_sem);
6716 + kmem_cache_free(vm_area_cachep, vma);
6717 + return 1;
6718 + }
6719 +
6720 + current->mm->call_dl_resolve = call_dl_resolve;
6721 + up_write(&current->mm->mmap_sem);
6722 +
6723 +emulate:
6724 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6725 + regs->pc = call_dl_resolve;
6726 + regs->npc = addr+4;
6727 + return 3;
6728 + }
6729 +#endif
6730 +
6731 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6732 + if ((save & 0xFFC00000U) == 0x05000000U &&
6733 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6734 + nop == 0x01000000U)
6735 + {
6736 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6737 + regs->u_regs[UREG_G2] = addr + 4;
6738 + addr = (save & 0x003FFFFFU) << 10;
6739 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6740 + regs->pc = addr;
6741 + regs->npc = addr+4;
6742 + return 3;
6743 + }
6744 + }
6745 + } while (0);
6746 +
6747 + do { /* PaX: unpatched PLT emulation step 2 */
6748 + unsigned int save, call, nop;
6749 +
6750 + err = get_user(save, (unsigned int *)(regs->pc-4));
6751 + err |= get_user(call, (unsigned int *)regs->pc);
6752 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6753 + if (err)
6754 + break;
6755 +
6756 + if (save == 0x9DE3BFA8U &&
6757 + (call & 0xC0000000U) == 0x40000000U &&
6758 + nop == 0x01000000U)
6759 + {
6760 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6761 +
6762 + regs->u_regs[UREG_RETPC] = regs->pc;
6763 + regs->pc = dl_resolve;
6764 + regs->npc = dl_resolve+4;
6765 + return 3;
6766 + }
6767 + } while (0);
6768 +#endif
6769 +
6770 + return 1;
6771 +}
6772 +
6773 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6774 +{
6775 + unsigned long i;
6776 +
6777 + printk(KERN_ERR "PAX: bytes at PC: ");
6778 + for (i = 0; i < 8; i++) {
6779 + unsigned int c;
6780 + if (get_user(c, (unsigned int *)pc+i))
6781 + printk(KERN_CONT "???????? ");
6782 + else
6783 + printk(KERN_CONT "%08x ", c);
6784 + }
6785 + printk("\n");
6786 +}
6787 +#endif
6788 +
6789 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6790 int text_fault)
6791 {
6792 @@ -230,6 +504,24 @@ good_area:
6793 if (!(vma->vm_flags & VM_WRITE))
6794 goto bad_area;
6795 } else {
6796 +
6797 +#ifdef CONFIG_PAX_PAGEEXEC
6798 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6799 + up_read(&mm->mmap_sem);
6800 + switch (pax_handle_fetch_fault(regs)) {
6801 +
6802 +#ifdef CONFIG_PAX_EMUPLT
6803 + case 2:
6804 + case 3:
6805 + return;
6806 +#endif
6807 +
6808 + }
6809 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6810 + do_group_exit(SIGKILL);
6811 + }
6812 +#endif
6813 +
6814 /* Allow reads even for write-only mappings */
6815 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6816 goto bad_area;
6817 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6818 index 097aee7..5ca6697 100644
6819 --- a/arch/sparc/mm/fault_64.c
6820 +++ b/arch/sparc/mm/fault_64.c
6821 @@ -21,6 +21,9 @@
6822 #include <linux/kprobes.h>
6823 #include <linux/kdebug.h>
6824 #include <linux/percpu.h>
6825 +#include <linux/slab.h>
6826 +#include <linux/pagemap.h>
6827 +#include <linux/compiler.h>
6828
6829 #include <asm/page.h>
6830 #include <asm/pgtable.h>
6831 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6832 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6833 regs->tpc);
6834 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6835 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6836 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6837 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6838 dump_stack();
6839 unhandled_fault(regs->tpc, current, regs);
6840 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6841 show_regs(regs);
6842 }
6843
6844 +#ifdef CONFIG_PAX_PAGEEXEC
6845 +#ifdef CONFIG_PAX_DLRESOLVE
6846 +static void pax_emuplt_close(struct vm_area_struct *vma)
6847 +{
6848 + vma->vm_mm->call_dl_resolve = 0UL;
6849 +}
6850 +
6851 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6852 +{
6853 + unsigned int *kaddr;
6854 +
6855 + vmf->page = alloc_page(GFP_HIGHUSER);
6856 + if (!vmf->page)
6857 + return VM_FAULT_OOM;
6858 +
6859 + kaddr = kmap(vmf->page);
6860 + memset(kaddr, 0, PAGE_SIZE);
6861 + kaddr[0] = 0x9DE3BFA8U; /* save */
6862 + flush_dcache_page(vmf->page);
6863 + kunmap(vmf->page);
6864 + return VM_FAULT_MAJOR;
6865 +}
6866 +
6867 +static const struct vm_operations_struct pax_vm_ops = {
6868 + .close = pax_emuplt_close,
6869 + .fault = pax_emuplt_fault
6870 +};
6871 +
6872 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6873 +{
6874 + int ret;
6875 +
6876 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6877 + vma->vm_mm = current->mm;
6878 + vma->vm_start = addr;
6879 + vma->vm_end = addr + PAGE_SIZE;
6880 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6881 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6882 + vma->vm_ops = &pax_vm_ops;
6883 +
6884 + ret = insert_vm_struct(current->mm, vma);
6885 + if (ret)
6886 + return ret;
6887 +
6888 + ++current->mm->total_vm;
6889 + return 0;
6890 +}
6891 +#endif
6892 +
6893 +/*
6894 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6895 + *
6896 + * returns 1 when task should be killed
6897 + * 2 when patched PLT trampoline was detected
6898 + * 3 when unpatched PLT trampoline was detected
6899 + */
6900 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6901 +{
6902 +
6903 +#ifdef CONFIG_PAX_EMUPLT
6904 + int err;
6905 +
6906 + do { /* PaX: patched PLT emulation #1 */
6907 + unsigned int sethi1, sethi2, jmpl;
6908 +
6909 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6910 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6911 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6912 +
6913 + if (err)
6914 + break;
6915 +
6916 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6917 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6918 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6919 + {
6920 + unsigned long addr;
6921 +
6922 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6923 + addr = regs->u_regs[UREG_G1];
6924 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6925 +
6926 + if (test_thread_flag(TIF_32BIT))
6927 + addr &= 0xFFFFFFFFUL;
6928 +
6929 + regs->tpc = addr;
6930 + regs->tnpc = addr+4;
6931 + return 2;
6932 + }
6933 + } while (0);
6934 +
6935 + do { /* PaX: patched PLT emulation #2 */
6936 + unsigned int ba;
6937 +
6938 + err = get_user(ba, (unsigned int *)regs->tpc);
6939 +
6940 + if (err)
6941 + break;
6942 +
6943 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6944 + unsigned long addr;
6945 +
6946 + if ((ba & 0xFFC00000U) == 0x30800000U)
6947 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6948 + else
6949 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6950 +
6951 + if (test_thread_flag(TIF_32BIT))
6952 + addr &= 0xFFFFFFFFUL;
6953 +
6954 + regs->tpc = addr;
6955 + regs->tnpc = addr+4;
6956 + return 2;
6957 + }
6958 + } while (0);
6959 +
6960 + do { /* PaX: patched PLT emulation #3 */
6961 + unsigned int sethi, bajmpl, nop;
6962 +
6963 + err = get_user(sethi, (unsigned int *)regs->tpc);
6964 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6965 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6966 +
6967 + if (err)
6968 + break;
6969 +
6970 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6971 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6972 + nop == 0x01000000U)
6973 + {
6974 + unsigned long addr;
6975 +
6976 + addr = (sethi & 0x003FFFFFU) << 10;
6977 + regs->u_regs[UREG_G1] = addr;
6978 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6979 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6980 + else
6981 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6982 +
6983 + if (test_thread_flag(TIF_32BIT))
6984 + addr &= 0xFFFFFFFFUL;
6985 +
6986 + regs->tpc = addr;
6987 + regs->tnpc = addr+4;
6988 + return 2;
6989 + }
6990 + } while (0);
6991 +
6992 + do { /* PaX: patched PLT emulation #4 */
6993 + unsigned int sethi, mov1, call, mov2;
6994 +
6995 + err = get_user(sethi, (unsigned int *)regs->tpc);
6996 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6997 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6998 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6999 +
7000 + if (err)
7001 + break;
7002 +
7003 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7004 + mov1 == 0x8210000FU &&
7005 + (call & 0xC0000000U) == 0x40000000U &&
7006 + mov2 == 0x9E100001U)
7007 + {
7008 + unsigned long addr;
7009 +
7010 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7011 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7012 +
7013 + if (test_thread_flag(TIF_32BIT))
7014 + addr &= 0xFFFFFFFFUL;
7015 +
7016 + regs->tpc = addr;
7017 + regs->tnpc = addr+4;
7018 + return 2;
7019 + }
7020 + } while (0);
7021 +
7022 + do { /* PaX: patched PLT emulation #5 */
7023 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7024 +
7025 + err = get_user(sethi, (unsigned int *)regs->tpc);
7026 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7027 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7028 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7029 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7030 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7031 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7032 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7033 +
7034 + if (err)
7035 + break;
7036 +
7037 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7038 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7039 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7040 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7041 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7042 + sllx == 0x83287020U &&
7043 + jmpl == 0x81C04005U &&
7044 + nop == 0x01000000U)
7045 + {
7046 + unsigned long addr;
7047 +
7048 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7049 + regs->u_regs[UREG_G1] <<= 32;
7050 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7051 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7052 + regs->tpc = addr;
7053 + regs->tnpc = addr+4;
7054 + return 2;
7055 + }
7056 + } while (0);
7057 +
7058 + do { /* PaX: patched PLT emulation #6 */
7059 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7060 +
7061 + err = get_user(sethi, (unsigned int *)regs->tpc);
7062 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7063 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7064 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7065 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7066 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7067 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7068 +
7069 + if (err)
7070 + break;
7071 +
7072 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7073 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7074 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7075 + sllx == 0x83287020U &&
7076 + (or & 0xFFFFE000U) == 0x8A116000U &&
7077 + jmpl == 0x81C04005U &&
7078 + nop == 0x01000000U)
7079 + {
7080 + unsigned long addr;
7081 +
7082 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7083 + regs->u_regs[UREG_G1] <<= 32;
7084 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7085 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7086 + regs->tpc = addr;
7087 + regs->tnpc = addr+4;
7088 + return 2;
7089 + }
7090 + } while (0);
7091 +
7092 + do { /* PaX: unpatched PLT emulation step 1 */
7093 + unsigned int sethi, ba, nop;
7094 +
7095 + err = get_user(sethi, (unsigned int *)regs->tpc);
7096 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7097 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7098 +
7099 + if (err)
7100 + break;
7101 +
7102 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7103 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7104 + nop == 0x01000000U)
7105 + {
7106 + unsigned long addr;
7107 + unsigned int save, call;
7108 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7109 +
7110 + if ((ba & 0xFFC00000U) == 0x30800000U)
7111 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7112 + else
7113 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7114 +
7115 + if (test_thread_flag(TIF_32BIT))
7116 + addr &= 0xFFFFFFFFUL;
7117 +
7118 + err = get_user(save, (unsigned int *)addr);
7119 + err |= get_user(call, (unsigned int *)(addr+4));
7120 + err |= get_user(nop, (unsigned int *)(addr+8));
7121 + if (err)
7122 + break;
7123 +
7124 +#ifdef CONFIG_PAX_DLRESOLVE
7125 + if (save == 0x9DE3BFA8U &&
7126 + (call & 0xC0000000U) == 0x40000000U &&
7127 + nop == 0x01000000U)
7128 + {
7129 + struct vm_area_struct *vma;
7130 + unsigned long call_dl_resolve;
7131 +
7132 + down_read(&current->mm->mmap_sem);
7133 + call_dl_resolve = current->mm->call_dl_resolve;
7134 + up_read(&current->mm->mmap_sem);
7135 + if (likely(call_dl_resolve))
7136 + goto emulate;
7137 +
7138 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7139 +
7140 + down_write(&current->mm->mmap_sem);
7141 + if (current->mm->call_dl_resolve) {
7142 + call_dl_resolve = current->mm->call_dl_resolve;
7143 + up_write(&current->mm->mmap_sem);
7144 + if (vma)
7145 + kmem_cache_free(vm_area_cachep, vma);
7146 + goto emulate;
7147 + }
7148 +
7149 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7150 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7151 + up_write(&current->mm->mmap_sem);
7152 + if (vma)
7153 + kmem_cache_free(vm_area_cachep, vma);
7154 + return 1;
7155 + }
7156 +
7157 + if (pax_insert_vma(vma, call_dl_resolve)) {
7158 + up_write(&current->mm->mmap_sem);
7159 + kmem_cache_free(vm_area_cachep, vma);
7160 + return 1;
7161 + }
7162 +
7163 + current->mm->call_dl_resolve = call_dl_resolve;
7164 + up_write(&current->mm->mmap_sem);
7165 +
7166 +emulate:
7167 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7168 + regs->tpc = call_dl_resolve;
7169 + regs->tnpc = addr+4;
7170 + return 3;
7171 + }
7172 +#endif
7173 +
7174 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7175 + if ((save & 0xFFC00000U) == 0x05000000U &&
7176 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7177 + nop == 0x01000000U)
7178 + {
7179 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7180 + regs->u_regs[UREG_G2] = addr + 4;
7181 + addr = (save & 0x003FFFFFU) << 10;
7182 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7183 +
7184 + if (test_thread_flag(TIF_32BIT))
7185 + addr &= 0xFFFFFFFFUL;
7186 +
7187 + regs->tpc = addr;
7188 + regs->tnpc = addr+4;
7189 + return 3;
7190 + }
7191 +
7192 + /* PaX: 64-bit PLT stub */
7193 + err = get_user(sethi1, (unsigned int *)addr);
7194 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7195 + err |= get_user(or1, (unsigned int *)(addr+8));
7196 + err |= get_user(or2, (unsigned int *)(addr+12));
7197 + err |= get_user(sllx, (unsigned int *)(addr+16));
7198 + err |= get_user(add, (unsigned int *)(addr+20));
7199 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7200 + err |= get_user(nop, (unsigned int *)(addr+28));
7201 + if (err)
7202 + break;
7203 +
7204 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7205 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7206 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7207 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7208 + sllx == 0x89293020U &&
7209 + add == 0x8A010005U &&
7210 + jmpl == 0x89C14000U &&
7211 + nop == 0x01000000U)
7212 + {
7213 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7214 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7215 + regs->u_regs[UREG_G4] <<= 32;
7216 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7217 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7218 + regs->u_regs[UREG_G4] = addr + 24;
7219 + addr = regs->u_regs[UREG_G5];
7220 + regs->tpc = addr;
7221 + regs->tnpc = addr+4;
7222 + return 3;
7223 + }
7224 + }
7225 + } while (0);
7226 +
7227 +#ifdef CONFIG_PAX_DLRESOLVE
7228 + do { /* PaX: unpatched PLT emulation step 2 */
7229 + unsigned int save, call, nop;
7230 +
7231 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7232 + err |= get_user(call, (unsigned int *)regs->tpc);
7233 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7234 + if (err)
7235 + break;
7236 +
7237 + if (save == 0x9DE3BFA8U &&
7238 + (call & 0xC0000000U) == 0x40000000U &&
7239 + nop == 0x01000000U)
7240 + {
7241 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7242 +
7243 + if (test_thread_flag(TIF_32BIT))
7244 + dl_resolve &= 0xFFFFFFFFUL;
7245 +
7246 + regs->u_regs[UREG_RETPC] = regs->tpc;
7247 + regs->tpc = dl_resolve;
7248 + regs->tnpc = dl_resolve+4;
7249 + return 3;
7250 + }
7251 + } while (0);
7252 +#endif
7253 +
7254 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7255 + unsigned int sethi, ba, nop;
7256 +
7257 + err = get_user(sethi, (unsigned int *)regs->tpc);
7258 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7259 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7260 +
7261 + if (err)
7262 + break;
7263 +
7264 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7265 + (ba & 0xFFF00000U) == 0x30600000U &&
7266 + nop == 0x01000000U)
7267 + {
7268 + unsigned long addr;
7269 +
7270 + addr = (sethi & 0x003FFFFFU) << 10;
7271 + regs->u_regs[UREG_G1] = addr;
7272 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7273 +
7274 + if (test_thread_flag(TIF_32BIT))
7275 + addr &= 0xFFFFFFFFUL;
7276 +
7277 + regs->tpc = addr;
7278 + regs->tnpc = addr+4;
7279 + return 2;
7280 + }
7281 + } while (0);
7282 +
7283 +#endif
7284 +
7285 + return 1;
7286 +}
7287 +
7288 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7289 +{
7290 + unsigned long i;
7291 +
7292 + printk(KERN_ERR "PAX: bytes at PC: ");
7293 + for (i = 0; i < 8; i++) {
7294 + unsigned int c;
7295 + if (get_user(c, (unsigned int *)pc+i))
7296 + printk(KERN_CONT "???????? ");
7297 + else
7298 + printk(KERN_CONT "%08x ", c);
7299 + }
7300 + printk("\n");
7301 +}
7302 +#endif
7303 +
7304 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7305 {
7306 struct mm_struct *mm = current->mm;
7307 @@ -341,6 +804,29 @@ retry:
7308 if (!vma)
7309 goto bad_area;
7310
7311 +#ifdef CONFIG_PAX_PAGEEXEC
7312 + /* PaX: detect ITLB misses on non-exec pages */
7313 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7314 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7315 + {
7316 + if (address != regs->tpc)
7317 + goto good_area;
7318 +
7319 + up_read(&mm->mmap_sem);
7320 + switch (pax_handle_fetch_fault(regs)) {
7321 +
7322 +#ifdef CONFIG_PAX_EMUPLT
7323 + case 2:
7324 + case 3:
7325 + return;
7326 +#endif
7327 +
7328 + }
7329 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7330 + do_group_exit(SIGKILL);
7331 + }
7332 +#endif
7333 +
7334 /* Pure DTLB misses do not tell us whether the fault causing
7335 * load/store/atomic was a write or not, it only says that there
7336 * was no match. So in such a case we (carefully) read the
7337 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7338 index f76f83d..0f28457 100644
7339 --- a/arch/sparc/mm/hugetlbpage.c
7340 +++ b/arch/sparc/mm/hugetlbpage.c
7341 @@ -67,7 +67,7 @@ full_search:
7342 }
7343 return -ENOMEM;
7344 }
7345 - if (likely(!vma || addr + len <= vma->vm_start)) {
7346 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7347 /*
7348 * Remember the place where we stopped the search:
7349 */
7350 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7351 /* make sure it can fit in the remaining address space */
7352 if (likely(addr > len)) {
7353 vma = find_vma(mm, addr-len);
7354 - if (!vma || addr <= vma->vm_start) {
7355 + if (check_heap_stack_gap(vma, addr - len, len)) {
7356 /* remember the address as a hint for next time */
7357 return (mm->free_area_cache = addr-len);
7358 }
7359 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7360 if (unlikely(mm->mmap_base < len))
7361 goto bottomup;
7362
7363 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7364 + addr = mm->mmap_base - len;
7365
7366 do {
7367 + addr &= HPAGE_MASK;
7368 /*
7369 * Lookup failure means no vma is above this address,
7370 * else if new region fits below vma->vm_start,
7371 * return with success:
7372 */
7373 vma = find_vma(mm, addr);
7374 - if (likely(!vma || addr+len <= vma->vm_start)) {
7375 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7376 /* remember the address as a hint for next time */
7377 return (mm->free_area_cache = addr);
7378 }
7379 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7380 mm->cached_hole_size = vma->vm_start - addr;
7381
7382 /* try just below the current vma->vm_start */
7383 - addr = (vma->vm_start-len) & HPAGE_MASK;
7384 - } while (likely(len < vma->vm_start));
7385 + addr = skip_heap_stack_gap(vma, len);
7386 + } while (!IS_ERR_VALUE(addr));
7387
7388 bottomup:
7389 /*
7390 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7391 if (addr) {
7392 addr = ALIGN(addr, HPAGE_SIZE);
7393 vma = find_vma(mm, addr);
7394 - if (task_size - len >= addr &&
7395 - (!vma || addr + len <= vma->vm_start))
7396 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7397 return addr;
7398 }
7399 if (mm->get_unmapped_area == arch_get_unmapped_area)
7400 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7401 index f4500c6..889656c 100644
7402 --- a/arch/tile/include/asm/atomic_64.h
7403 +++ b/arch/tile/include/asm/atomic_64.h
7404 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7405
7406 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7407
7408 +#define atomic64_read_unchecked(v) atomic64_read(v)
7409 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7410 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7411 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7412 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7413 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7414 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7415 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7416 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7417 +
7418 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7419 #define smp_mb__before_atomic_dec() smp_mb()
7420 #define smp_mb__after_atomic_dec() smp_mb()
7421 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7422 index a9a5299..0fce79e 100644
7423 --- a/arch/tile/include/asm/cache.h
7424 +++ b/arch/tile/include/asm/cache.h
7425 @@ -15,11 +15,12 @@
7426 #ifndef _ASM_TILE_CACHE_H
7427 #define _ASM_TILE_CACHE_H
7428
7429 +#include <linux/const.h>
7430 #include <arch/chip.h>
7431
7432 /* bytes per L1 data cache line */
7433 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7434 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7436
7437 /* bytes per L2 cache line */
7438 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7439 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7440 index 9ab078a..d6635c2 100644
7441 --- a/arch/tile/include/asm/uaccess.h
7442 +++ b/arch/tile/include/asm/uaccess.h
7443 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7444 const void __user *from,
7445 unsigned long n)
7446 {
7447 - int sz = __compiletime_object_size(to);
7448 + size_t sz = __compiletime_object_size(to);
7449
7450 - if (likely(sz == -1 || sz >= n))
7451 + if (likely(sz == (size_t)-1 || sz >= n))
7452 n = _copy_from_user(to, from, n);
7453 else
7454 copy_from_user_overflow();
7455 diff --git a/arch/um/Makefile b/arch/um/Makefile
7456 index 133f7de..1d6f2f1 100644
7457 --- a/arch/um/Makefile
7458 +++ b/arch/um/Makefile
7459 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7460 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7461 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7462
7463 +ifdef CONSTIFY_PLUGIN
7464 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7465 +endif
7466 +
7467 #This will adjust *FLAGS accordingly to the platform.
7468 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7469
7470 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7471 index 19e1bdd..3665b77 100644
7472 --- a/arch/um/include/asm/cache.h
7473 +++ b/arch/um/include/asm/cache.h
7474 @@ -1,6 +1,7 @@
7475 #ifndef __UM_CACHE_H
7476 #define __UM_CACHE_H
7477
7478 +#include <linux/const.h>
7479
7480 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7481 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7482 @@ -12,6 +13,6 @@
7483 # define L1_CACHE_SHIFT 5
7484 #endif
7485
7486 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7487 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7488
7489 #endif
7490 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7491 index 2e0a6b1..a64d0f5 100644
7492 --- a/arch/um/include/asm/kmap_types.h
7493 +++ b/arch/um/include/asm/kmap_types.h
7494 @@ -8,6 +8,6 @@
7495
7496 /* No more #include "asm/arch/kmap_types.h" ! */
7497
7498 -#define KM_TYPE_NR 14
7499 +#define KM_TYPE_NR 15
7500
7501 #endif
7502 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7503 index 5ff53d9..5850cdf 100644
7504 --- a/arch/um/include/asm/page.h
7505 +++ b/arch/um/include/asm/page.h
7506 @@ -14,6 +14,9 @@
7507 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7508 #define PAGE_MASK (~(PAGE_SIZE-1))
7509
7510 +#define ktla_ktva(addr) (addr)
7511 +#define ktva_ktla(addr) (addr)
7512 +
7513 #ifndef __ASSEMBLY__
7514
7515 struct page;
7516 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7517 index 0032f92..cd151e0 100644
7518 --- a/arch/um/include/asm/pgtable-3level.h
7519 +++ b/arch/um/include/asm/pgtable-3level.h
7520 @@ -58,6 +58,7 @@
7521 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7522 #define pud_populate(mm, pud, pmd) \
7523 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7524 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7525
7526 #ifdef CONFIG_64BIT
7527 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7528 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7529 index b6d699c..df7ac1d 100644
7530 --- a/arch/um/kernel/process.c
7531 +++ b/arch/um/kernel/process.c
7532 @@ -387,22 +387,6 @@ int singlestepping(void * t)
7533 return 2;
7534 }
7535
7536 -/*
7537 - * Only x86 and x86_64 have an arch_align_stack().
7538 - * All other arches have "#define arch_align_stack(x) (x)"
7539 - * in their asm/system.h
7540 - * As this is included in UML from asm-um/system-generic.h,
7541 - * we can use it to behave as the subarch does.
7542 - */
7543 -#ifndef arch_align_stack
7544 -unsigned long arch_align_stack(unsigned long sp)
7545 -{
7546 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7547 - sp -= get_random_int() % 8192;
7548 - return sp & ~0xf;
7549 -}
7550 -#endif
7551 -
7552 unsigned long get_wchan(struct task_struct *p)
7553 {
7554 unsigned long stack_page, sp, ip;
7555 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7556 index ad8f795..2c7eec6 100644
7557 --- a/arch/unicore32/include/asm/cache.h
7558 +++ b/arch/unicore32/include/asm/cache.h
7559 @@ -12,8 +12,10 @@
7560 #ifndef __UNICORE_CACHE_H__
7561 #define __UNICORE_CACHE_H__
7562
7563 -#define L1_CACHE_SHIFT (5)
7564 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7565 +#include <linux/const.h>
7566 +
7567 +#define L1_CACHE_SHIFT 5
7568 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7569
7570 /*
7571 * Memory returned by kmalloc() may be used for DMA, so we must make
7572 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7573 index 46c3bff..c2286e7 100644
7574 --- a/arch/x86/Kconfig
7575 +++ b/arch/x86/Kconfig
7576 @@ -241,7 +241,7 @@ config X86_HT
7577
7578 config X86_32_LAZY_GS
7579 def_bool y
7580 - depends on X86_32 && !CC_STACKPROTECTOR
7581 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7582
7583 config ARCH_HWEIGHT_CFLAGS
7584 string
7585 @@ -1056,7 +1056,7 @@ choice
7586
7587 config NOHIGHMEM
7588 bool "off"
7589 - depends on !X86_NUMAQ
7590 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7591 ---help---
7592 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7593 However, the address space of 32-bit x86 processors is only 4
7594 @@ -1093,7 +1093,7 @@ config NOHIGHMEM
7595
7596 config HIGHMEM4G
7597 bool "4GB"
7598 - depends on !X86_NUMAQ
7599 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7600 ---help---
7601 Select this if you have a 32-bit processor and between 1 and 4
7602 gigabytes of physical RAM.
7603 @@ -1147,7 +1147,7 @@ config PAGE_OFFSET
7604 hex
7605 default 0xB0000000 if VMSPLIT_3G_OPT
7606 default 0x80000000 if VMSPLIT_2G
7607 - default 0x78000000 if VMSPLIT_2G_OPT
7608 + default 0x70000000 if VMSPLIT_2G_OPT
7609 default 0x40000000 if VMSPLIT_1G
7610 default 0xC0000000
7611 depends on X86_32
7612 @@ -1548,6 +1548,7 @@ config SECCOMP
7613
7614 config CC_STACKPROTECTOR
7615 bool "Enable -fstack-protector buffer overflow detection"
7616 + depends on X86_64 || !PAX_MEMORY_UDEREF
7617 ---help---
7618 This option turns on the -fstack-protector GCC feature. This
7619 feature puts, at the beginning of functions, a canary value on
7620 @@ -1605,6 +1606,7 @@ config KEXEC_JUMP
7621 config PHYSICAL_START
7622 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7623 default "0x1000000"
7624 + range 0x400000 0x40000000
7625 ---help---
7626 This gives the physical address where the kernel is loaded.
7627
7628 @@ -1668,6 +1670,7 @@ config X86_NEED_RELOCS
7629 config PHYSICAL_ALIGN
7630 hex "Alignment value to which kernel should be aligned" if X86_32
7631 default "0x1000000"
7632 + range 0x400000 0x1000000 if PAX_KERNEXEC
7633 range 0x2000 0x1000000
7634 ---help---
7635 This value puts the alignment restrictions on physical address
7636 @@ -1699,9 +1702,10 @@ config HOTPLUG_CPU
7637 Say N if you want to disable CPU hotplug.
7638
7639 config COMPAT_VDSO
7640 - def_bool y
7641 + def_bool n
7642 prompt "Compat VDSO support"
7643 depends on X86_32 || IA32_EMULATION
7644 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7645 ---help---
7646 Map the 32-bit VDSO to the predictable old-style address too.
7647
7648 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7649 index f3b86d0..17fd30f 100644
7650 --- a/arch/x86/Kconfig.cpu
7651 +++ b/arch/x86/Kconfig.cpu
7652 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7653
7654 config X86_F00F_BUG
7655 def_bool y
7656 - depends on M586MMX || M586TSC || M586 || M486 || M386
7657 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7658
7659 config X86_INVD_BUG
7660 def_bool y
7661 @@ -359,7 +359,7 @@ config X86_POPAD_OK
7662
7663 config X86_ALIGNMENT_16
7664 def_bool y
7665 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7666 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7667
7668 config X86_INTEL_USERCOPY
7669 def_bool y
7670 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
7671 # generates cmov.
7672 config X86_CMOV
7673 def_bool y
7674 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7675 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7676
7677 config X86_MINIMUM_CPU_FAMILY
7678 int
7679 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7680 index b322f12..652d0d9 100644
7681 --- a/arch/x86/Kconfig.debug
7682 +++ b/arch/x86/Kconfig.debug
7683 @@ -84,7 +84,7 @@ config X86_PTDUMP
7684 config DEBUG_RODATA
7685 bool "Write protect kernel read-only data structures"
7686 default y
7687 - depends on DEBUG_KERNEL
7688 + depends on DEBUG_KERNEL && BROKEN
7689 ---help---
7690 Mark the kernel read-only data as write-protected in the pagetables,
7691 in order to catch accidental (and incorrect) writes to such const
7692 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7693
7694 config DEBUG_SET_MODULE_RONX
7695 bool "Set loadable kernel module data as NX and text as RO"
7696 - depends on MODULES
7697 + depends on MODULES && BROKEN
7698 ---help---
7699 This option helps catch unintended modifications to loadable
7700 kernel module's text and read-only data. It also prevents execution
7701 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7702
7703 config DEBUG_STRICT_USER_COPY_CHECKS
7704 bool "Strict copy size checks"
7705 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7706 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7707 ---help---
7708 Enabling this option turns a certain set of sanity checks for user
7709 copy operations into compile time failures.
7710 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7711 index 05afcca..b6ecb51 100644
7712 --- a/arch/x86/Makefile
7713 +++ b/arch/x86/Makefile
7714 @@ -50,6 +50,7 @@ else
7715 UTS_MACHINE := x86_64
7716 CHECKFLAGS += -D__x86_64__ -m64
7717
7718 + biarch := $(call cc-option,-m64)
7719 KBUILD_AFLAGS += -m64
7720 KBUILD_CFLAGS += -m64
7721
7722 @@ -229,3 +230,12 @@ define archhelp
7723 echo ' FDARGS="..." arguments for the booted kernel'
7724 echo ' FDINITRD=file initrd for the booted kernel'
7725 endef
7726 +
7727 +define OLD_LD
7728 +
7729 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7730 +*** Please upgrade your binutils to 2.18 or newer
7731 +endef
7732 +
7733 +archprepare:
7734 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7735 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7736 index ccce0ed..fd9da25 100644
7737 --- a/arch/x86/boot/Makefile
7738 +++ b/arch/x86/boot/Makefile
7739 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7740 $(call cc-option, -fno-stack-protector) \
7741 $(call cc-option, -mpreferred-stack-boundary=2)
7742 KBUILD_CFLAGS += $(call cc-option, -m32)
7743 +ifdef CONSTIFY_PLUGIN
7744 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7745 +endif
7746 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7747 GCOV_PROFILE := n
7748
7749 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7750 index 878e4b9..20537ab 100644
7751 --- a/arch/x86/boot/bitops.h
7752 +++ b/arch/x86/boot/bitops.h
7753 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7754 u8 v;
7755 const u32 *p = (const u32 *)addr;
7756
7757 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7758 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7759 return v;
7760 }
7761
7762 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7763
7764 static inline void set_bit(int nr, void *addr)
7765 {
7766 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7767 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7768 }
7769
7770 #endif /* BOOT_BITOPS_H */
7771 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7772 index 18997e5..83d9c67 100644
7773 --- a/arch/x86/boot/boot.h
7774 +++ b/arch/x86/boot/boot.h
7775 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7776 static inline u16 ds(void)
7777 {
7778 u16 seg;
7779 - asm("movw %%ds,%0" : "=rm" (seg));
7780 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7781 return seg;
7782 }
7783
7784 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7785 static inline int memcmp(const void *s1, const void *s2, size_t len)
7786 {
7787 u8 diff;
7788 - asm("repe; cmpsb; setnz %0"
7789 + asm volatile("repe; cmpsb; setnz %0"
7790 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7791 return diff;
7792 }
7793 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7794 index 8a84501..b2d165f 100644
7795 --- a/arch/x86/boot/compressed/Makefile
7796 +++ b/arch/x86/boot/compressed/Makefile
7797 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7798 KBUILD_CFLAGS += $(cflags-y)
7799 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7800 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7801 +ifdef CONSTIFY_PLUGIN
7802 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7803 +endif
7804
7805 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7806 GCOV_PROFILE := n
7807 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7808 index e87b0ca..2bce457 100644
7809 --- a/arch/x86/boot/compressed/eboot.c
7810 +++ b/arch/x86/boot/compressed/eboot.c
7811 @@ -144,7 +144,6 @@ again:
7812 *addr = max_addr;
7813 }
7814
7815 -free_pool:
7816 efi_call_phys1(sys_table->boottime->free_pool, map);
7817
7818 fail:
7819 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7820 if (i == map_size / desc_size)
7821 status = EFI_NOT_FOUND;
7822
7823 -free_pool:
7824 efi_call_phys1(sys_table->boottime->free_pool, map);
7825 fail:
7826 return status;
7827 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7828 index aa4aaf1..6656f2f 100644
7829 --- a/arch/x86/boot/compressed/head_32.S
7830 +++ b/arch/x86/boot/compressed/head_32.S
7831 @@ -116,7 +116,7 @@ preferred_addr:
7832 notl %eax
7833 andl %eax, %ebx
7834 #else
7835 - movl $LOAD_PHYSICAL_ADDR, %ebx
7836 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7837 #endif
7838
7839 /* Target address to relocate to for decompression */
7840 @@ -202,7 +202,7 @@ relocated:
7841 * and where it was actually loaded.
7842 */
7843 movl %ebp, %ebx
7844 - subl $LOAD_PHYSICAL_ADDR, %ebx
7845 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7846 jz 2f /* Nothing to be done if loaded at compiled addr. */
7847 /*
7848 * Process relocations.
7849 @@ -210,8 +210,7 @@ relocated:
7850
7851 1: subl $4, %edi
7852 movl (%edi), %ecx
7853 - testl %ecx, %ecx
7854 - jz 2f
7855 + jecxz 2f
7856 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7857 jmp 1b
7858 2:
7859 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7860 index 2c4b171..e1fa5b1 100644
7861 --- a/arch/x86/boot/compressed/head_64.S
7862 +++ b/arch/x86/boot/compressed/head_64.S
7863 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7864 notl %eax
7865 andl %eax, %ebx
7866 #else
7867 - movl $LOAD_PHYSICAL_ADDR, %ebx
7868 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7869 #endif
7870
7871 /* Target address to relocate to for decompression */
7872 @@ -273,7 +273,7 @@ preferred_addr:
7873 notq %rax
7874 andq %rax, %rbp
7875 #else
7876 - movq $LOAD_PHYSICAL_ADDR, %rbp
7877 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7878 #endif
7879
7880 /* Target address to relocate to for decompression */
7881 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7882 index 88f7ff6..ed695dd 100644
7883 --- a/arch/x86/boot/compressed/misc.c
7884 +++ b/arch/x86/boot/compressed/misc.c
7885 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7886 case PT_LOAD:
7887 #ifdef CONFIG_RELOCATABLE
7888 dest = output;
7889 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7890 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7891 #else
7892 dest = (void *)(phdr->p_paddr);
7893 #endif
7894 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7895 error("Destination address too large");
7896 #endif
7897 #ifndef CONFIG_RELOCATABLE
7898 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7899 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7900 error("Wrong destination address");
7901 #endif
7902
7903 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7904 index 4d3ff03..e4972ff 100644
7905 --- a/arch/x86/boot/cpucheck.c
7906 +++ b/arch/x86/boot/cpucheck.c
7907 @@ -74,7 +74,7 @@ static int has_fpu(void)
7908 u16 fcw = -1, fsw = -1;
7909 u32 cr0;
7910
7911 - asm("movl %%cr0,%0" : "=r" (cr0));
7912 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7913 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7914 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7915 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7916 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7917 {
7918 u32 f0, f1;
7919
7920 - asm("pushfl ; "
7921 + asm volatile("pushfl ; "
7922 "pushfl ; "
7923 "popl %0 ; "
7924 "movl %0,%1 ; "
7925 @@ -115,7 +115,7 @@ static void get_flags(void)
7926 set_bit(X86_FEATURE_FPU, cpu.flags);
7927
7928 if (has_eflag(X86_EFLAGS_ID)) {
7929 - asm("cpuid"
7930 + asm volatile("cpuid"
7931 : "=a" (max_intel_level),
7932 "=b" (cpu_vendor[0]),
7933 "=d" (cpu_vendor[1]),
7934 @@ -124,7 +124,7 @@ static void get_flags(void)
7935
7936 if (max_intel_level >= 0x00000001 &&
7937 max_intel_level <= 0x0000ffff) {
7938 - asm("cpuid"
7939 + asm volatile("cpuid"
7940 : "=a" (tfms),
7941 "=c" (cpu.flags[4]),
7942 "=d" (cpu.flags[0])
7943 @@ -136,7 +136,7 @@ static void get_flags(void)
7944 cpu.model += ((tfms >> 16) & 0xf) << 4;
7945 }
7946
7947 - asm("cpuid"
7948 + asm volatile("cpuid"
7949 : "=a" (max_amd_level)
7950 : "a" (0x80000000)
7951 : "ebx", "ecx", "edx");
7952 @@ -144,7 +144,7 @@ static void get_flags(void)
7953 if (max_amd_level >= 0x80000001 &&
7954 max_amd_level <= 0x8000ffff) {
7955 u32 eax = 0x80000001;
7956 - asm("cpuid"
7957 + asm volatile("cpuid"
7958 : "+a" (eax),
7959 "=c" (cpu.flags[6]),
7960 "=d" (cpu.flags[1])
7961 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7962 u32 ecx = MSR_K7_HWCR;
7963 u32 eax, edx;
7964
7965 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7966 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7967 eax &= ~(1 << 15);
7968 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7969 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7970
7971 get_flags(); /* Make sure it really did something */
7972 err = check_flags();
7973 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7974 u32 ecx = MSR_VIA_FCR;
7975 u32 eax, edx;
7976
7977 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7978 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7979 eax |= (1<<1)|(1<<7);
7980 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7981 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7982
7983 set_bit(X86_FEATURE_CX8, cpu.flags);
7984 err = check_flags();
7985 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7986 u32 eax, edx;
7987 u32 level = 1;
7988
7989 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7990 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7991 - asm("cpuid"
7992 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7993 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7994 + asm volatile("cpuid"
7995 : "+a" (level), "=d" (cpu.flags[0])
7996 : : "ecx", "ebx");
7997 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7998 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7999
8000 err = check_flags();
8001 }
8002 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8003 index 8c132a6..13e5c96 100644
8004 --- a/arch/x86/boot/header.S
8005 +++ b/arch/x86/boot/header.S
8006 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8007 # single linked list of
8008 # struct setup_data
8009
8010 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8011 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8012
8013 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8014 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8015 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8016 +#else
8017 #define VO_INIT_SIZE (VO__end - VO__text)
8018 +#endif
8019 #if ZO_INIT_SIZE > VO_INIT_SIZE
8020 #define INIT_SIZE ZO_INIT_SIZE
8021 #else
8022 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8023 index db75d07..8e6d0af 100644
8024 --- a/arch/x86/boot/memory.c
8025 +++ b/arch/x86/boot/memory.c
8026 @@ -19,7 +19,7 @@
8027
8028 static int detect_memory_e820(void)
8029 {
8030 - int count = 0;
8031 + unsigned int count = 0;
8032 struct biosregs ireg, oreg;
8033 struct e820entry *desc = boot_params.e820_map;
8034 static struct e820entry buf; /* static so it is zeroed */
8035 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8036 index 11e8c6e..fdbb1ed 100644
8037 --- a/arch/x86/boot/video-vesa.c
8038 +++ b/arch/x86/boot/video-vesa.c
8039 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8040
8041 boot_params.screen_info.vesapm_seg = oreg.es;
8042 boot_params.screen_info.vesapm_off = oreg.di;
8043 + boot_params.screen_info.vesapm_size = oreg.cx;
8044 }
8045
8046 /*
8047 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8048 index 43eda28..5ab5fdb 100644
8049 --- a/arch/x86/boot/video.c
8050 +++ b/arch/x86/boot/video.c
8051 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8052 static unsigned int get_entry(void)
8053 {
8054 char entry_buf[4];
8055 - int i, len = 0;
8056 + unsigned int i, len = 0;
8057 int key;
8058 unsigned int v;
8059
8060 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8061 index 5b577d5..3c1fed4 100644
8062 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8063 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8064 @@ -8,6 +8,8 @@
8065 * including this sentence is retained in full.
8066 */
8067
8068 +#include <asm/alternative-asm.h>
8069 +
8070 .extern crypto_ft_tab
8071 .extern crypto_it_tab
8072 .extern crypto_fl_tab
8073 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8074 je B192; \
8075 leaq 32(r9),r9;
8076
8077 +#define ret pax_force_retaddr 0, 1; ret
8078 +
8079 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8080 movq r1,r2; \
8081 movq r3,r4; \
8082 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8083 index 3470624..201259d 100644
8084 --- a/arch/x86/crypto/aesni-intel_asm.S
8085 +++ b/arch/x86/crypto/aesni-intel_asm.S
8086 @@ -31,6 +31,7 @@
8087
8088 #include <linux/linkage.h>
8089 #include <asm/inst.h>
8090 +#include <asm/alternative-asm.h>
8091
8092 #ifdef __x86_64__
8093 .data
8094 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8095 pop %r14
8096 pop %r13
8097 pop %r12
8098 + pax_force_retaddr 0, 1
8099 ret
8100 +ENDPROC(aesni_gcm_dec)
8101
8102
8103 /*****************************************************************************
8104 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8105 pop %r14
8106 pop %r13
8107 pop %r12
8108 + pax_force_retaddr 0, 1
8109 ret
8110 +ENDPROC(aesni_gcm_enc)
8111
8112 #endif
8113
8114 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8115 pxor %xmm1, %xmm0
8116 movaps %xmm0, (TKEYP)
8117 add $0x10, TKEYP
8118 + pax_force_retaddr_bts
8119 ret
8120
8121 .align 4
8122 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8123 shufps $0b01001110, %xmm2, %xmm1
8124 movaps %xmm1, 0x10(TKEYP)
8125 add $0x20, TKEYP
8126 + pax_force_retaddr_bts
8127 ret
8128
8129 .align 4
8130 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8131
8132 movaps %xmm0, (TKEYP)
8133 add $0x10, TKEYP
8134 + pax_force_retaddr_bts
8135 ret
8136
8137 .align 4
8138 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8139 pxor %xmm1, %xmm2
8140 movaps %xmm2, (TKEYP)
8141 add $0x10, TKEYP
8142 + pax_force_retaddr_bts
8143 ret
8144
8145 /*
8146 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8147 #ifndef __x86_64__
8148 popl KEYP
8149 #endif
8150 + pax_force_retaddr 0, 1
8151 ret
8152 +ENDPROC(aesni_set_key)
8153
8154 /*
8155 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8156 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8157 popl KLEN
8158 popl KEYP
8159 #endif
8160 + pax_force_retaddr 0, 1
8161 ret
8162 +ENDPROC(aesni_enc)
8163
8164 /*
8165 * _aesni_enc1: internal ABI
8166 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8167 AESENC KEY STATE
8168 movaps 0x70(TKEYP), KEY
8169 AESENCLAST KEY STATE
8170 + pax_force_retaddr_bts
8171 ret
8172
8173 /*
8174 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8175 AESENCLAST KEY STATE2
8176 AESENCLAST KEY STATE3
8177 AESENCLAST KEY STATE4
8178 + pax_force_retaddr_bts
8179 ret
8180
8181 /*
8182 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8183 popl KLEN
8184 popl KEYP
8185 #endif
8186 + pax_force_retaddr 0, 1
8187 ret
8188 +ENDPROC(aesni_dec)
8189
8190 /*
8191 * _aesni_dec1: internal ABI
8192 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8193 AESDEC KEY STATE
8194 movaps 0x70(TKEYP), KEY
8195 AESDECLAST KEY STATE
8196 + pax_force_retaddr_bts
8197 ret
8198
8199 /*
8200 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8201 AESDECLAST KEY STATE2
8202 AESDECLAST KEY STATE3
8203 AESDECLAST KEY STATE4
8204 + pax_force_retaddr_bts
8205 ret
8206
8207 /*
8208 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8209 popl KEYP
8210 popl LEN
8211 #endif
8212 + pax_force_retaddr 0, 1
8213 ret
8214 +ENDPROC(aesni_ecb_enc)
8215
8216 /*
8217 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8218 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8219 popl KEYP
8220 popl LEN
8221 #endif
8222 + pax_force_retaddr 0, 1
8223 ret
8224 +ENDPROC(aesni_ecb_dec)
8225
8226 /*
8227 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8228 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8229 popl LEN
8230 popl IVP
8231 #endif
8232 + pax_force_retaddr 0, 1
8233 ret
8234 +ENDPROC(aesni_cbc_enc)
8235
8236 /*
8237 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8238 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8239 popl LEN
8240 popl IVP
8241 #endif
8242 + pax_force_retaddr 0, 1
8243 ret
8244 +ENDPROC(aesni_cbc_dec)
8245
8246 #ifdef __x86_64__
8247 .align 16
8248 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8249 mov $1, TCTR_LOW
8250 MOVQ_R64_XMM TCTR_LOW INC
8251 MOVQ_R64_XMM CTR TCTR_LOW
8252 + pax_force_retaddr_bts
8253 ret
8254
8255 /*
8256 @@ -2554,6 +2582,7 @@ _aesni_inc:
8257 .Linc_low:
8258 movaps CTR, IV
8259 PSHUFB_XMM BSWAP_MASK IV
8260 + pax_force_retaddr_bts
8261 ret
8262
8263 /*
8264 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8265 .Lctr_enc_ret:
8266 movups IV, (IVP)
8267 .Lctr_enc_just_ret:
8268 + pax_force_retaddr 0, 1
8269 ret
8270 +ENDPROC(aesni_ctr_enc)
8271 #endif
8272 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8273 index 391d245..67f35c2 100644
8274 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8275 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8276 @@ -20,6 +20,8 @@
8277 *
8278 */
8279
8280 +#include <asm/alternative-asm.h>
8281 +
8282 .file "blowfish-x86_64-asm.S"
8283 .text
8284
8285 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8286 jnz __enc_xor;
8287
8288 write_block();
8289 + pax_force_retaddr 0, 1
8290 ret;
8291 __enc_xor:
8292 xor_block();
8293 + pax_force_retaddr 0, 1
8294 ret;
8295
8296 .align 8
8297 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8298
8299 movq %r11, %rbp;
8300
8301 + pax_force_retaddr 0, 1
8302 ret;
8303
8304 /**********************************************************************
8305 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8306
8307 popq %rbx;
8308 popq %rbp;
8309 + pax_force_retaddr 0, 1
8310 ret;
8311
8312 __enc_xor4:
8313 @@ -349,6 +355,7 @@ __enc_xor4:
8314
8315 popq %rbx;
8316 popq %rbp;
8317 + pax_force_retaddr 0, 1
8318 ret;
8319
8320 .align 8
8321 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8322 popq %rbx;
8323 popq %rbp;
8324
8325 + pax_force_retaddr 0, 1
8326 ret;
8327
8328 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8329 index 0b33743..7a56206 100644
8330 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8331 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8332 @@ -20,6 +20,8 @@
8333 *
8334 */
8335
8336 +#include <asm/alternative-asm.h>
8337 +
8338 .file "camellia-x86_64-asm_64.S"
8339 .text
8340
8341 @@ -229,12 +231,14 @@ __enc_done:
8342 enc_outunpack(mov, RT1);
8343
8344 movq RRBP, %rbp;
8345 + pax_force_retaddr 0, 1
8346 ret;
8347
8348 __enc_xor:
8349 enc_outunpack(xor, RT1);
8350
8351 movq RRBP, %rbp;
8352 + pax_force_retaddr 0, 1
8353 ret;
8354
8355 .global camellia_dec_blk;
8356 @@ -275,6 +279,7 @@ __dec_rounds16:
8357 dec_outunpack();
8358
8359 movq RRBP, %rbp;
8360 + pax_force_retaddr 0, 1
8361 ret;
8362
8363 /**********************************************************************
8364 @@ -468,6 +473,7 @@ __enc2_done:
8365
8366 movq RRBP, %rbp;
8367 popq %rbx;
8368 + pax_force_retaddr 0, 1
8369 ret;
8370
8371 __enc2_xor:
8372 @@ -475,6 +481,7 @@ __enc2_xor:
8373
8374 movq RRBP, %rbp;
8375 popq %rbx;
8376 + pax_force_retaddr 0, 1
8377 ret;
8378
8379 .global camellia_dec_blk_2way;
8380 @@ -517,4 +524,5 @@ __dec2_rounds16:
8381
8382 movq RRBP, %rbp;
8383 movq RXOR, %rbx;
8384 + pax_force_retaddr 0, 1
8385 ret;
8386 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
8387 index a41a3aa..bdf5753 100644
8388 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
8389 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
8390 @@ -23,6 +23,8 @@
8391 *
8392 */
8393
8394 +#include <asm/alternative-asm.h>
8395 +
8396 .file "cast5-avx-x86_64-asm_64.S"
8397
8398 .extern cast5_s1
8399 @@ -293,6 +295,7 @@ __skip_enc:
8400 leaq 3*(2*4*4)(%r11), %rax;
8401 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
8402
8403 + pax_force_retaddr 0, 1
8404 ret;
8405
8406 __enc_xor16:
8407 @@ -303,6 +306,7 @@ __enc_xor16:
8408 leaq 3*(2*4*4)(%r11), %rax;
8409 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
8410
8411 + pax_force_retaddr 0, 1
8412 ret;
8413
8414 .align 16
8415 @@ -369,6 +373,7 @@ __dec_tail:
8416 leaq 3*(2*4*4)(%r11), %rax;
8417 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
8418
8419 + pax_force_retaddr 0, 1
8420 ret;
8421
8422 __skip_dec:
8423 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
8424 index 218d283..819e6da 100644
8425 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
8426 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
8427 @@ -23,6 +23,8 @@
8428 *
8429 */
8430
8431 +#include <asm/alternative-asm.h>
8432 +
8433 .file "cast6-avx-x86_64-asm_64.S"
8434
8435 .extern cast6_s1
8436 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
8437 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
8438 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
8439
8440 + pax_force_retaddr 0, 1
8441 ret;
8442
8443 __enc_xor8:
8444 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
8445 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
8446
8447 + pax_force_retaddr 0, 1
8448 ret;
8449
8450 .align 16
8451 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
8452 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
8453 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
8454
8455 + pax_force_retaddr 0, 1
8456 ret;
8457 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8458 index 6214a9b..1f4fc9a 100644
8459 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8460 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8461 @@ -1,3 +1,5 @@
8462 +#include <asm/alternative-asm.h>
8463 +
8464 # enter ECRYPT_encrypt_bytes
8465 .text
8466 .p2align 5
8467 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8468 add %r11,%rsp
8469 mov %rdi,%rax
8470 mov %rsi,%rdx
8471 + pax_force_retaddr 0, 1
8472 ret
8473 # bytesatleast65:
8474 ._bytesatleast65:
8475 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8476 add %r11,%rsp
8477 mov %rdi,%rax
8478 mov %rsi,%rdx
8479 + pax_force_retaddr
8480 ret
8481 # enter ECRYPT_ivsetup
8482 .text
8483 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8484 add %r11,%rsp
8485 mov %rdi,%rax
8486 mov %rsi,%rdx
8487 + pax_force_retaddr
8488 ret
8489 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8490 index 504106b..4e50951 100644
8491 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8492 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8493 @@ -24,6 +24,8 @@
8494 *
8495 */
8496
8497 +#include <asm/alternative-asm.h>
8498 +
8499 .file "serpent-avx-x86_64-asm_64.S"
8500 .text
8501
8502 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8503 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8504 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8505
8506 + pax_force_retaddr
8507 ret;
8508
8509 __enc_xor8:
8510 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8511 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8512
8513 + pax_force_retaddr
8514 ret;
8515
8516 .align 8
8517 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8518 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8519 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8520
8521 + pax_force_retaddr
8522 ret;
8523 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8524 index 3ee1ff0..cbc568b 100644
8525 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8526 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8527 @@ -24,6 +24,8 @@
8528 *
8529 */
8530
8531 +#include <asm/alternative-asm.h>
8532 +
8533 .file "serpent-sse2-x86_64-asm_64.S"
8534 .text
8535
8536 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8537 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8538 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8539
8540 + pax_force_retaddr
8541 ret;
8542
8543 __enc_xor8:
8544 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8545 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8546
8547 + pax_force_retaddr
8548 ret;
8549
8550 .align 8
8551 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8552 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8553 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8554
8555 + pax_force_retaddr
8556 ret;
8557 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8558 index 49d6987..df66bd4 100644
8559 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8560 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8561 @@ -28,6 +28,8 @@
8562 * (at your option) any later version.
8563 */
8564
8565 +#include <asm/alternative-asm.h>
8566 +
8567 #define CTX %rdi // arg1
8568 #define BUF %rsi // arg2
8569 #define CNT %rdx // arg3
8570 @@ -104,6 +106,7 @@
8571 pop %r12
8572 pop %rbp
8573 pop %rbx
8574 + pax_force_retaddr 0, 1
8575 ret
8576
8577 .size \name, .-\name
8578 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8579 index 1585abb..4a9af16 100644
8580 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8581 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8582 @@ -23,6 +23,8 @@
8583 *
8584 */
8585
8586 +#include <asm/alternative-asm.h>
8587 +
8588 .file "twofish-avx-x86_64-asm_64.S"
8589 .text
8590
8591 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
8592 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
8593 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
8594
8595 + pax_force_retaddr
8596 ret;
8597
8598 __enc_xor8:
8599 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
8600 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
8601
8602 + pax_force_retaddr
8603 ret;
8604
8605 .align 8
8606 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
8607 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
8608 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
8609
8610 + pax_force_retaddr
8611 ret;
8612 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8613 index 5b012a2..36d5364 100644
8614 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8615 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8616 @@ -20,6 +20,8 @@
8617 *
8618 */
8619
8620 +#include <asm/alternative-asm.h>
8621 +
8622 .file "twofish-x86_64-asm-3way.S"
8623 .text
8624
8625 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8626 popq %r13;
8627 popq %r14;
8628 popq %r15;
8629 + pax_force_retaddr 0, 1
8630 ret;
8631
8632 __enc_xor3:
8633 @@ -271,6 +274,7 @@ __enc_xor3:
8634 popq %r13;
8635 popq %r14;
8636 popq %r15;
8637 + pax_force_retaddr 0, 1
8638 ret;
8639
8640 .global twofish_dec_blk_3way
8641 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8642 popq %r13;
8643 popq %r14;
8644 popq %r15;
8645 + pax_force_retaddr 0, 1
8646 ret;
8647
8648 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8649 index 7bcf3fc..f53832f 100644
8650 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8651 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8652 @@ -21,6 +21,7 @@
8653 .text
8654
8655 #include <asm/asm-offsets.h>
8656 +#include <asm/alternative-asm.h>
8657
8658 #define a_offset 0
8659 #define b_offset 4
8660 @@ -268,6 +269,7 @@ twofish_enc_blk:
8661
8662 popq R1
8663 movq $1,%rax
8664 + pax_force_retaddr 0, 1
8665 ret
8666
8667 twofish_dec_blk:
8668 @@ -319,4 +321,5 @@ twofish_dec_blk:
8669
8670 popq R1
8671 movq $1,%rax
8672 + pax_force_retaddr 0, 1
8673 ret
8674 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8675 index 07b3a68..bd2a388 100644
8676 --- a/arch/x86/ia32/ia32_aout.c
8677 +++ b/arch/x86/ia32/ia32_aout.c
8678 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8679 unsigned long dump_start, dump_size;
8680 struct user32 dump;
8681
8682 + memset(&dump, 0, sizeof(dump));
8683 +
8684 fs = get_fs();
8685 set_fs(KERNEL_DS);
8686 has_dumped = 1;
8687 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8688 index efc6a95..95abfe2 100644
8689 --- a/arch/x86/ia32/ia32_signal.c
8690 +++ b/arch/x86/ia32/ia32_signal.c
8691 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8692 }
8693 seg = get_fs();
8694 set_fs(KERNEL_DS);
8695 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
8696 - (stack_t __force __user *) &uoss, regs->sp);
8697 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
8698 + (stack_t __force_user *) &uoss, regs->sp);
8699 set_fs(seg);
8700 if (ret >= 0 && uoss_ptr) {
8701 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8702 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8703 sp -= frame_size;
8704 /* Align the stack pointer according to the i386 ABI,
8705 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8706 - sp = ((sp + 4) & -16ul) - 4;
8707 + sp = ((sp - 12) & -16ul) - 4;
8708 return (void __user *) sp;
8709 }
8710
8711 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8712 * These are actually not used anymore, but left because some
8713 * gdb versions depend on them as a marker.
8714 */
8715 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
8716 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8717 } put_user_catch(err);
8718
8719 if (err)
8720 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8721 0xb8,
8722 __NR_ia32_rt_sigreturn,
8723 0x80cd,
8724 - 0,
8725 + 0
8726 };
8727
8728 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8729 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8730
8731 if (ka->sa.sa_flags & SA_RESTORER)
8732 restorer = ka->sa.sa_restorer;
8733 + else if (current->mm->context.vdso)
8734 + /* Return stub is in 32bit vsyscall page */
8735 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8736 else
8737 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8738 - rt_sigreturn);
8739 + restorer = &frame->retcode;
8740 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8741
8742 /*
8743 * Not actually used anymore, but left because some gdb
8744 * versions need it.
8745 */
8746 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
8747 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8748 } put_user_catch(err);
8749
8750 err |= copy_siginfo_to_user32(&frame->info, info);
8751 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8752 index 076745f..ae8f6cb 100644
8753 --- a/arch/x86/ia32/ia32entry.S
8754 +++ b/arch/x86/ia32/ia32entry.S
8755 @@ -15,8 +15,10 @@
8756 #include <asm/irqflags.h>
8757 #include <asm/asm.h>
8758 #include <asm/smap.h>
8759 +#include <asm/pgtable.h>
8760 #include <linux/linkage.h>
8761 #include <linux/err.h>
8762 +#include <asm/alternative-asm.h>
8763
8764 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8765 #include <linux/elf-em.h>
8766 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
8767 ENDPROC(native_irq_enable_sysexit)
8768 #endif
8769
8770 + .macro pax_enter_kernel_user
8771 + pax_set_fptr_mask
8772 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8773 + call pax_enter_kernel_user
8774 +#endif
8775 + .endm
8776 +
8777 + .macro pax_exit_kernel_user
8778 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8779 + call pax_exit_kernel_user
8780 +#endif
8781 +#ifdef CONFIG_PAX_RANDKSTACK
8782 + pushq %rax
8783 + pushq %r11
8784 + call pax_randomize_kstack
8785 + popq %r11
8786 + popq %rax
8787 +#endif
8788 + .endm
8789 +
8790 +.macro pax_erase_kstack
8791 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8792 + call pax_erase_kstack
8793 +#endif
8794 +.endm
8795 +
8796 /*
8797 * 32bit SYSENTER instruction entry.
8798 *
8799 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
8800 CFI_REGISTER rsp,rbp
8801 SWAPGS_UNSAFE_STACK
8802 movq PER_CPU_VAR(kernel_stack), %rsp
8803 - addq $(KERNEL_STACK_OFFSET),%rsp
8804 - /*
8805 - * No need to follow this irqs on/off section: the syscall
8806 - * disabled irqs, here we enable it straight after entry:
8807 - */
8808 - ENABLE_INTERRUPTS(CLBR_NONE)
8809 movl %ebp,%ebp /* zero extension */
8810 pushq_cfi $__USER32_DS
8811 /*CFI_REL_OFFSET ss,0*/
8812 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
8813 CFI_REL_OFFSET rsp,0
8814 pushfq_cfi
8815 /*CFI_REL_OFFSET rflags,0*/
8816 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8817 - CFI_REGISTER rip,r10
8818 + orl $X86_EFLAGS_IF,(%rsp)
8819 + GET_THREAD_INFO(%r11)
8820 + movl TI_sysenter_return(%r11), %r11d
8821 + CFI_REGISTER rip,r11
8822 pushq_cfi $__USER32_CS
8823 /*CFI_REL_OFFSET cs,0*/
8824 movl %eax, %eax
8825 - pushq_cfi %r10
8826 + pushq_cfi %r11
8827 CFI_REL_OFFSET rip,0
8828 pushq_cfi %rax
8829 cld
8830 SAVE_ARGS 0,1,0
8831 + pax_enter_kernel_user
8832 +
8833 +#ifdef CONFIG_PAX_RANDKSTACK
8834 + pax_erase_kstack
8835 +#endif
8836 +
8837 + /*
8838 + * No need to follow this irqs on/off section: the syscall
8839 + * disabled irqs, here we enable it straight after entry:
8840 + */
8841 + ENABLE_INTERRUPTS(CLBR_NONE)
8842 /* no need to do an access_ok check here because rbp has been
8843 32bit zero extended */
8844 +
8845 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8846 + mov $PAX_USER_SHADOW_BASE,%r11
8847 + add %r11,%rbp
8848 +#endif
8849 +
8850 ASM_STAC
8851 1: movl (%rbp),%ebp
8852 _ASM_EXTABLE(1b,ia32_badarg)
8853 ASM_CLAC
8854 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8855 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8856 + GET_THREAD_INFO(%r11)
8857 + orl $TS_COMPAT,TI_status(%r11)
8858 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8859 CFI_REMEMBER_STATE
8860 jnz sysenter_tracesys
8861 cmpq $(IA32_NR_syscalls-1),%rax
8862 @@ -162,12 +204,15 @@ sysenter_do_call:
8863 sysenter_dispatch:
8864 call *ia32_sys_call_table(,%rax,8)
8865 movq %rax,RAX-ARGOFFSET(%rsp)
8866 + GET_THREAD_INFO(%r11)
8867 DISABLE_INTERRUPTS(CLBR_NONE)
8868 TRACE_IRQS_OFF
8869 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8870 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8871 jnz sysexit_audit
8872 sysexit_from_sys_call:
8873 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8874 + pax_exit_kernel_user
8875 + pax_erase_kstack
8876 + andl $~TS_COMPAT,TI_status(%r11)
8877 /* clear IF, that popfq doesn't enable interrupts early */
8878 andl $~0x200,EFLAGS-R11(%rsp)
8879 movl RIP-R11(%rsp),%edx /* User %eip */
8880 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
8881 movl %eax,%esi /* 2nd arg: syscall number */
8882 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8883 call __audit_syscall_entry
8884 +
8885 + pax_erase_kstack
8886 +
8887 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8888 cmpq $(IA32_NR_syscalls-1),%rax
8889 ja ia32_badsys
8890 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
8891 .endm
8892
8893 .macro auditsys_exit exit
8894 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8895 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8896 jnz ia32_ret_from_sys_call
8897 TRACE_IRQS_ON
8898 sti
8899 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
8900 1: setbe %al /* 1 if error, 0 if not */
8901 movzbl %al,%edi /* zero-extend that into %edi */
8902 call __audit_syscall_exit
8903 + GET_THREAD_INFO(%r11)
8904 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8905 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8906 cli
8907 TRACE_IRQS_OFF
8908 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8909 + testl %edi,TI_flags(%r11)
8910 jz \exit
8911 CLEAR_RREGS -ARGOFFSET
8912 jmp int_with_check
8913 @@ -237,7 +286,7 @@ sysexit_audit:
8914
8915 sysenter_tracesys:
8916 #ifdef CONFIG_AUDITSYSCALL
8917 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8918 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8919 jz sysenter_auditsys
8920 #endif
8921 SAVE_REST
8922 @@ -249,6 +298,9 @@ sysenter_tracesys:
8923 RESTORE_REST
8924 cmpq $(IA32_NR_syscalls-1),%rax
8925 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8926 +
8927 + pax_erase_kstack
8928 +
8929 jmp sysenter_do_call
8930 CFI_ENDPROC
8931 ENDPROC(ia32_sysenter_target)
8932 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
8933 ENTRY(ia32_cstar_target)
8934 CFI_STARTPROC32 simple
8935 CFI_SIGNAL_FRAME
8936 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8937 + CFI_DEF_CFA rsp,0
8938 CFI_REGISTER rip,rcx
8939 /*CFI_REGISTER rflags,r11*/
8940 SWAPGS_UNSAFE_STACK
8941 movl %esp,%r8d
8942 CFI_REGISTER rsp,r8
8943 movq PER_CPU_VAR(kernel_stack),%rsp
8944 + SAVE_ARGS 8*6,0,0
8945 + pax_enter_kernel_user
8946 +
8947 +#ifdef CONFIG_PAX_RANDKSTACK
8948 + pax_erase_kstack
8949 +#endif
8950 +
8951 /*
8952 * No need to follow this irqs on/off section: the syscall
8953 * disabled irqs and here we enable it straight after entry:
8954 */
8955 ENABLE_INTERRUPTS(CLBR_NONE)
8956 - SAVE_ARGS 8,0,0
8957 movl %eax,%eax /* zero extension */
8958 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8959 movq %rcx,RIP-ARGOFFSET(%rsp)
8960 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
8961 /* no need to do an access_ok check here because r8 has been
8962 32bit zero extended */
8963 /* hardware stack frame is complete now */
8964 +
8965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8966 + mov $PAX_USER_SHADOW_BASE,%r11
8967 + add %r11,%r8
8968 +#endif
8969 +
8970 ASM_STAC
8971 1: movl (%r8),%r9d
8972 _ASM_EXTABLE(1b,ia32_badarg)
8973 ASM_CLAC
8974 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8975 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8976 + GET_THREAD_INFO(%r11)
8977 + orl $TS_COMPAT,TI_status(%r11)
8978 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8979 CFI_REMEMBER_STATE
8980 jnz cstar_tracesys
8981 cmpq $IA32_NR_syscalls-1,%rax
8982 @@ -319,12 +384,15 @@ cstar_do_call:
8983 cstar_dispatch:
8984 call *ia32_sys_call_table(,%rax,8)
8985 movq %rax,RAX-ARGOFFSET(%rsp)
8986 + GET_THREAD_INFO(%r11)
8987 DISABLE_INTERRUPTS(CLBR_NONE)
8988 TRACE_IRQS_OFF
8989 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8990 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8991 jnz sysretl_audit
8992 sysretl_from_sys_call:
8993 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8994 + pax_exit_kernel_user
8995 + pax_erase_kstack
8996 + andl $~TS_COMPAT,TI_status(%r11)
8997 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8998 movl RIP-ARGOFFSET(%rsp),%ecx
8999 CFI_REGISTER rip,rcx
9000 @@ -352,7 +420,7 @@ sysretl_audit:
9001
9002 cstar_tracesys:
9003 #ifdef CONFIG_AUDITSYSCALL
9004 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9005 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9006 jz cstar_auditsys
9007 #endif
9008 xchgl %r9d,%ebp
9009 @@ -366,6 +434,9 @@ cstar_tracesys:
9010 xchgl %ebp,%r9d
9011 cmpq $(IA32_NR_syscalls-1),%rax
9012 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
9013 +
9014 + pax_erase_kstack
9015 +
9016 jmp cstar_do_call
9017 END(ia32_cstar_target)
9018
9019 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
9020 CFI_REL_OFFSET rip,RIP-RIP
9021 PARAVIRT_ADJUST_EXCEPTION_FRAME
9022 SWAPGS
9023 - /*
9024 - * No need to follow this irqs on/off section: the syscall
9025 - * disabled irqs and here we enable it straight after entry:
9026 - */
9027 - ENABLE_INTERRUPTS(CLBR_NONE)
9028 movl %eax,%eax
9029 pushq_cfi %rax
9030 cld
9031 /* note the registers are not zero extended to the sf.
9032 this could be a problem. */
9033 SAVE_ARGS 0,1,0
9034 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9035 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9036 + pax_enter_kernel_user
9037 +
9038 +#ifdef CONFIG_PAX_RANDKSTACK
9039 + pax_erase_kstack
9040 +#endif
9041 +
9042 + /*
9043 + * No need to follow this irqs on/off section: the syscall
9044 + * disabled irqs and here we enable it straight after entry:
9045 + */
9046 + ENABLE_INTERRUPTS(CLBR_NONE)
9047 + GET_THREAD_INFO(%r11)
9048 + orl $TS_COMPAT,TI_status(%r11)
9049 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9050 jnz ia32_tracesys
9051 cmpq $(IA32_NR_syscalls-1),%rax
9052 ja ia32_badsys
9053 @@ -442,6 +520,9 @@ ia32_tracesys:
9054 RESTORE_REST
9055 cmpq $(IA32_NR_syscalls-1),%rax
9056 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
9057 +
9058 + pax_erase_kstack
9059 +
9060 jmp ia32_do_call
9061 END(ia32_syscall)
9062
9063 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9064 index 86d68d1..f9960fe 100644
9065 --- a/arch/x86/ia32/sys_ia32.c
9066 +++ b/arch/x86/ia32/sys_ia32.c
9067 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9068 */
9069 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9070 {
9071 - typeof(ubuf->st_uid) uid = 0;
9072 - typeof(ubuf->st_gid) gid = 0;
9073 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
9074 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
9075 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
9076 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
9077 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9078 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9079 mm_segment_t old_fs = get_fs();
9080
9081 set_fs(KERNEL_DS);
9082 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9083 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9084 set_fs(old_fs);
9085 if (put_compat_timespec(&t, interval))
9086 return -EFAULT;
9087 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9088 mm_segment_t old_fs = get_fs();
9089
9090 set_fs(KERNEL_DS);
9091 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9092 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9093 set_fs(old_fs);
9094 if (!ret) {
9095 switch (_NSIG_WORDS) {
9096 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9097 if (copy_siginfo_from_user32(&info, uinfo))
9098 return -EFAULT;
9099 set_fs(KERNEL_DS);
9100 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9101 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9102 set_fs(old_fs);
9103 return ret;
9104 }
9105 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9106 return -EFAULT;
9107
9108 set_fs(KERNEL_DS);
9109 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9110 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9111 count);
9112 set_fs(old_fs);
9113
9114 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9115 index 372231c..a5aa1a1 100644
9116 --- a/arch/x86/include/asm/alternative-asm.h
9117 +++ b/arch/x86/include/asm/alternative-asm.h
9118 @@ -18,6 +18,45 @@
9119 .endm
9120 #endif
9121
9122 +#ifdef KERNEXEC_PLUGIN
9123 + .macro pax_force_retaddr_bts rip=0
9124 + btsq $63,\rip(%rsp)
9125 + .endm
9126 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9127 + .macro pax_force_retaddr rip=0, reload=0
9128 + btsq $63,\rip(%rsp)
9129 + .endm
9130 + .macro pax_force_fptr ptr
9131 + btsq $63,\ptr
9132 + .endm
9133 + .macro pax_set_fptr_mask
9134 + .endm
9135 +#endif
9136 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9137 + .macro pax_force_retaddr rip=0, reload=0
9138 + .if \reload
9139 + pax_set_fptr_mask
9140 + .endif
9141 + orq %r10,\rip(%rsp)
9142 + .endm
9143 + .macro pax_force_fptr ptr
9144 + orq %r10,\ptr
9145 + .endm
9146 + .macro pax_set_fptr_mask
9147 + movabs $0x8000000000000000,%r10
9148 + .endm
9149 +#endif
9150 +#else
9151 + .macro pax_force_retaddr rip=0, reload=0
9152 + .endm
9153 + .macro pax_force_fptr ptr
9154 + .endm
9155 + .macro pax_force_retaddr_bts rip=0
9156 + .endm
9157 + .macro pax_set_fptr_mask
9158 + .endm
9159 +#endif
9160 +
9161 .macro altinstruction_entry orig alt feature orig_len alt_len
9162 .long \orig - .
9163 .long \alt - .
9164 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9165 index 58ed6d9..f1cbe58 100644
9166 --- a/arch/x86/include/asm/alternative.h
9167 +++ b/arch/x86/include/asm/alternative.h
9168 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9169 ".pushsection .discard,\"aw\",@progbits\n" \
9170 DISCARD_ENTRY(1) \
9171 ".popsection\n" \
9172 - ".pushsection .altinstr_replacement, \"ax\"\n" \
9173 + ".pushsection .altinstr_replacement, \"a\"\n" \
9174 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9175 ".popsection"
9176
9177 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9178 DISCARD_ENTRY(1) \
9179 DISCARD_ENTRY(2) \
9180 ".popsection\n" \
9181 - ".pushsection .altinstr_replacement, \"ax\"\n" \
9182 + ".pushsection .altinstr_replacement, \"a\"\n" \
9183 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9184 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9185 ".popsection"
9186 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9187 index 3388034..ba52312 100644
9188 --- a/arch/x86/include/asm/apic.h
9189 +++ b/arch/x86/include/asm/apic.h
9190 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9191
9192 #ifdef CONFIG_X86_LOCAL_APIC
9193
9194 -extern unsigned int apic_verbosity;
9195 +extern int apic_verbosity;
9196 extern int local_apic_timer_c2_ok;
9197
9198 extern int disable_apic;
9199 @@ -391,7 +391,7 @@ struct apic {
9200 */
9201 int (*x86_32_numa_cpu_node)(int cpu);
9202 #endif
9203 -};
9204 +} __do_const;
9205
9206 /*
9207 * Pointer to the local APIC driver in use on this system (there's
9208 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9209 index 20370c6..a2eb9b0 100644
9210 --- a/arch/x86/include/asm/apm.h
9211 +++ b/arch/x86/include/asm/apm.h
9212 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9213 __asm__ __volatile__(APM_DO_ZERO_SEGS
9214 "pushl %%edi\n\t"
9215 "pushl %%ebp\n\t"
9216 - "lcall *%%cs:apm_bios_entry\n\t"
9217 + "lcall *%%ss:apm_bios_entry\n\t"
9218 "setc %%al\n\t"
9219 "popl %%ebp\n\t"
9220 "popl %%edi\n\t"
9221 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9222 __asm__ __volatile__(APM_DO_ZERO_SEGS
9223 "pushl %%edi\n\t"
9224 "pushl %%ebp\n\t"
9225 - "lcall *%%cs:apm_bios_entry\n\t"
9226 + "lcall *%%ss:apm_bios_entry\n\t"
9227 "setc %%bl\n\t"
9228 "popl %%ebp\n\t"
9229 "popl %%edi\n\t"
9230 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9231 index b6c3b82..b4c077a 100644
9232 --- a/arch/x86/include/asm/atomic.h
9233 +++ b/arch/x86/include/asm/atomic.h
9234 @@ -22,7 +22,18 @@
9235 */
9236 static inline int atomic_read(const atomic_t *v)
9237 {
9238 - return (*(volatile int *)&(v)->counter);
9239 + return (*(volatile const int *)&(v)->counter);
9240 +}
9241 +
9242 +/**
9243 + * atomic_read_unchecked - read atomic variable
9244 + * @v: pointer of type atomic_unchecked_t
9245 + *
9246 + * Atomically reads the value of @v.
9247 + */
9248 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9249 +{
9250 + return (*(volatile const int *)&(v)->counter);
9251 }
9252
9253 /**
9254 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9255 }
9256
9257 /**
9258 + * atomic_set_unchecked - set atomic variable
9259 + * @v: pointer of type atomic_unchecked_t
9260 + * @i: required value
9261 + *
9262 + * Atomically sets the value of @v to @i.
9263 + */
9264 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9265 +{
9266 + v->counter = i;
9267 +}
9268 +
9269 +/**
9270 * atomic_add - add integer to atomic variable
9271 * @i: integer value to add
9272 * @v: pointer of type atomic_t
9273 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9274 */
9275 static inline void atomic_add(int i, atomic_t *v)
9276 {
9277 - asm volatile(LOCK_PREFIX "addl %1,%0"
9278 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9279 +
9280 +#ifdef CONFIG_PAX_REFCOUNT
9281 + "jno 0f\n"
9282 + LOCK_PREFIX "subl %1,%0\n"
9283 + "int $4\n0:\n"
9284 + _ASM_EXTABLE(0b, 0b)
9285 +#endif
9286 +
9287 + : "+m" (v->counter)
9288 + : "ir" (i));
9289 +}
9290 +
9291 +/**
9292 + * atomic_add_unchecked - add integer to atomic variable
9293 + * @i: integer value to add
9294 + * @v: pointer of type atomic_unchecked_t
9295 + *
9296 + * Atomically adds @i to @v.
9297 + */
9298 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9299 +{
9300 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9301 : "+m" (v->counter)
9302 : "ir" (i));
9303 }
9304 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9305 */
9306 static inline void atomic_sub(int i, atomic_t *v)
9307 {
9308 - asm volatile(LOCK_PREFIX "subl %1,%0"
9309 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9310 +
9311 +#ifdef CONFIG_PAX_REFCOUNT
9312 + "jno 0f\n"
9313 + LOCK_PREFIX "addl %1,%0\n"
9314 + "int $4\n0:\n"
9315 + _ASM_EXTABLE(0b, 0b)
9316 +#endif
9317 +
9318 + : "+m" (v->counter)
9319 + : "ir" (i));
9320 +}
9321 +
9322 +/**
9323 + * atomic_sub_unchecked - subtract integer from atomic variable
9324 + * @i: integer value to subtract
9325 + * @v: pointer of type atomic_unchecked_t
9326 + *
9327 + * Atomically subtracts @i from @v.
9328 + */
9329 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9330 +{
9331 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9332 : "+m" (v->counter)
9333 : "ir" (i));
9334 }
9335 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9336 {
9337 unsigned char c;
9338
9339 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9340 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9341 +
9342 +#ifdef CONFIG_PAX_REFCOUNT
9343 + "jno 0f\n"
9344 + LOCK_PREFIX "addl %2,%0\n"
9345 + "int $4\n0:\n"
9346 + _ASM_EXTABLE(0b, 0b)
9347 +#endif
9348 +
9349 + "sete %1\n"
9350 : "+m" (v->counter), "=qm" (c)
9351 : "ir" (i) : "memory");
9352 return c;
9353 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9354 */
9355 static inline void atomic_inc(atomic_t *v)
9356 {
9357 - asm volatile(LOCK_PREFIX "incl %0"
9358 + asm volatile(LOCK_PREFIX "incl %0\n"
9359 +
9360 +#ifdef CONFIG_PAX_REFCOUNT
9361 + "jno 0f\n"
9362 + LOCK_PREFIX "decl %0\n"
9363 + "int $4\n0:\n"
9364 + _ASM_EXTABLE(0b, 0b)
9365 +#endif
9366 +
9367 + : "+m" (v->counter));
9368 +}
9369 +
9370 +/**
9371 + * atomic_inc_unchecked - increment atomic variable
9372 + * @v: pointer of type atomic_unchecked_t
9373 + *
9374 + * Atomically increments @v by 1.
9375 + */
9376 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9377 +{
9378 + asm volatile(LOCK_PREFIX "incl %0\n"
9379 : "+m" (v->counter));
9380 }
9381
9382 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9383 */
9384 static inline void atomic_dec(atomic_t *v)
9385 {
9386 - asm volatile(LOCK_PREFIX "decl %0"
9387 + asm volatile(LOCK_PREFIX "decl %0\n"
9388 +
9389 +#ifdef CONFIG_PAX_REFCOUNT
9390 + "jno 0f\n"
9391 + LOCK_PREFIX "incl %0\n"
9392 + "int $4\n0:\n"
9393 + _ASM_EXTABLE(0b, 0b)
9394 +#endif
9395 +
9396 + : "+m" (v->counter));
9397 +}
9398 +
9399 +/**
9400 + * atomic_dec_unchecked - decrement atomic variable
9401 + * @v: pointer of type atomic_unchecked_t
9402 + *
9403 + * Atomically decrements @v by 1.
9404 + */
9405 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9406 +{
9407 + asm volatile(LOCK_PREFIX "decl %0\n"
9408 : "+m" (v->counter));
9409 }
9410
9411 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9412 {
9413 unsigned char c;
9414
9415 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9416 + asm volatile(LOCK_PREFIX "decl %0\n"
9417 +
9418 +#ifdef CONFIG_PAX_REFCOUNT
9419 + "jno 0f\n"
9420 + LOCK_PREFIX "incl %0\n"
9421 + "int $4\n0:\n"
9422 + _ASM_EXTABLE(0b, 0b)
9423 +#endif
9424 +
9425 + "sete %1\n"
9426 : "+m" (v->counter), "=qm" (c)
9427 : : "memory");
9428 return c != 0;
9429 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9430 {
9431 unsigned char c;
9432
9433 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9434 + asm volatile(LOCK_PREFIX "incl %0\n"
9435 +
9436 +#ifdef CONFIG_PAX_REFCOUNT
9437 + "jno 0f\n"
9438 + LOCK_PREFIX "decl %0\n"
9439 + "int $4\n0:\n"
9440 + _ASM_EXTABLE(0b, 0b)
9441 +#endif
9442 +
9443 + "sete %1\n"
9444 + : "+m" (v->counter), "=qm" (c)
9445 + : : "memory");
9446 + return c != 0;
9447 +}
9448 +
9449 +/**
9450 + * atomic_inc_and_test_unchecked - increment and test
9451 + * @v: pointer of type atomic_unchecked_t
9452 + *
9453 + * Atomically increments @v by 1
9454 + * and returns true if the result is zero, or false for all
9455 + * other cases.
9456 + */
9457 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9458 +{
9459 + unsigned char c;
9460 +
9461 + asm volatile(LOCK_PREFIX "incl %0\n"
9462 + "sete %1\n"
9463 : "+m" (v->counter), "=qm" (c)
9464 : : "memory");
9465 return c != 0;
9466 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9467 {
9468 unsigned char c;
9469
9470 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9471 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9472 +
9473 +#ifdef CONFIG_PAX_REFCOUNT
9474 + "jno 0f\n"
9475 + LOCK_PREFIX "subl %2,%0\n"
9476 + "int $4\n0:\n"
9477 + _ASM_EXTABLE(0b, 0b)
9478 +#endif
9479 +
9480 + "sets %1\n"
9481 : "+m" (v->counter), "=qm" (c)
9482 : "ir" (i) : "memory");
9483 return c;
9484 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9485 goto no_xadd;
9486 #endif
9487 /* Modern 486+ processor */
9488 - return i + xadd(&v->counter, i);
9489 + return i + xadd_check_overflow(&v->counter, i);
9490
9491 #ifdef CONFIG_M386
9492 no_xadd: /* Legacy 386 processor */
9493 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9494 }
9495
9496 /**
9497 + * atomic_add_return_unchecked - add integer and return
9498 + * @i: integer value to add
9499 + * @v: pointer of type atomic_unchecked_t
9500 + *
9501 + * Atomically adds @i to @v and returns @i + @v
9502 + */
9503 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9504 +{
9505 +#ifdef CONFIG_M386
9506 + int __i;
9507 + unsigned long flags;
9508 + if (unlikely(boot_cpu_data.x86 <= 3))
9509 + goto no_xadd;
9510 +#endif
9511 + /* Modern 486+ processor */
9512 + return i + xadd(&v->counter, i);
9513 +
9514 +#ifdef CONFIG_M386
9515 +no_xadd: /* Legacy 386 processor */
9516 + raw_local_irq_save(flags);
9517 + __i = atomic_read_unchecked(v);
9518 + atomic_set_unchecked(v, i + __i);
9519 + raw_local_irq_restore(flags);
9520 + return i + __i;
9521 +#endif
9522 +}
9523 +
9524 +/**
9525 * atomic_sub_return - subtract integer and return
9526 * @v: pointer of type atomic_t
9527 * @i: integer value to subtract
9528 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9529 }
9530
9531 #define atomic_inc_return(v) (atomic_add_return(1, v))
9532 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9533 +{
9534 + return atomic_add_return_unchecked(1, v);
9535 +}
9536 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9537
9538 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9539 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9540 return cmpxchg(&v->counter, old, new);
9541 }
9542
9543 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9544 +{
9545 + return cmpxchg(&v->counter, old, new);
9546 +}
9547 +
9548 static inline int atomic_xchg(atomic_t *v, int new)
9549 {
9550 return xchg(&v->counter, new);
9551 }
9552
9553 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9554 +{
9555 + return xchg(&v->counter, new);
9556 +}
9557 +
9558 /**
9559 * __atomic_add_unless - add unless the number is already a given value
9560 * @v: pointer of type atomic_t
9561 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9562 */
9563 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9564 {
9565 - int c, old;
9566 + int c, old, new;
9567 c = atomic_read(v);
9568 for (;;) {
9569 - if (unlikely(c == (u)))
9570 + if (unlikely(c == u))
9571 break;
9572 - old = atomic_cmpxchg((v), c, c + (a));
9573 +
9574 + asm volatile("addl %2,%0\n"
9575 +
9576 +#ifdef CONFIG_PAX_REFCOUNT
9577 + "jno 0f\n"
9578 + "subl %2,%0\n"
9579 + "int $4\n0:\n"
9580 + _ASM_EXTABLE(0b, 0b)
9581 +#endif
9582 +
9583 + : "=r" (new)
9584 + : "0" (c), "ir" (a));
9585 +
9586 + old = atomic_cmpxchg(v, c, new);
9587 if (likely(old == c))
9588 break;
9589 c = old;
9590 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9591 }
9592
9593 /**
9594 + * atomic_inc_not_zero_hint - increment if not null
9595 + * @v: pointer of type atomic_t
9596 + * @hint: probable value of the atomic before the increment
9597 + *
9598 + * This version of atomic_inc_not_zero() gives a hint of probable
9599 + * value of the atomic. This helps processor to not read the memory
9600 + * before doing the atomic read/modify/write cycle, lowering
9601 + * number of bus transactions on some arches.
9602 + *
9603 + * Returns: 0 if increment was not done, 1 otherwise.
9604 + */
9605 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9606 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9607 +{
9608 + int val, c = hint, new;
9609 +
9610 + /* sanity test, should be removed by compiler if hint is a constant */
9611 + if (!hint)
9612 + return __atomic_add_unless(v, 1, 0);
9613 +
9614 + do {
9615 + asm volatile("incl %0\n"
9616 +
9617 +#ifdef CONFIG_PAX_REFCOUNT
9618 + "jno 0f\n"
9619 + "decl %0\n"
9620 + "int $4\n0:\n"
9621 + _ASM_EXTABLE(0b, 0b)
9622 +#endif
9623 +
9624 + : "=r" (new)
9625 + : "0" (c));
9626 +
9627 + val = atomic_cmpxchg(v, c, new);
9628 + if (val == c)
9629 + return 1;
9630 + c = val;
9631 + } while (c);
9632 +
9633 + return 0;
9634 +}
9635 +
9636 +/**
9637 * atomic_inc_short - increment of a short integer
9638 * @v: pointer to type int
9639 *
9640 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9641 #endif
9642
9643 /* These are x86-specific, used by some header files */
9644 -#define atomic_clear_mask(mask, addr) \
9645 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9646 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9647 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9648 +{
9649 + asm volatile(LOCK_PREFIX "andl %1,%0"
9650 + : "+m" (v->counter)
9651 + : "r" (~(mask))
9652 + : "memory");
9653 +}
9654
9655 -#define atomic_set_mask(mask, addr) \
9656 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9657 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9658 - : "memory")
9659 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9660 +{
9661 + asm volatile(LOCK_PREFIX "andl %1,%0"
9662 + : "+m" (v->counter)
9663 + : "r" (~(mask))
9664 + : "memory");
9665 +}
9666 +
9667 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9668 +{
9669 + asm volatile(LOCK_PREFIX "orl %1,%0"
9670 + : "+m" (v->counter)
9671 + : "r" (mask)
9672 + : "memory");
9673 +}
9674 +
9675 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9676 +{
9677 + asm volatile(LOCK_PREFIX "orl %1,%0"
9678 + : "+m" (v->counter)
9679 + : "r" (mask)
9680 + : "memory");
9681 +}
9682
9683 /* Atomic operations are already serializing on x86 */
9684 #define smp_mb__before_atomic_dec() barrier()
9685 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9686 index b154de7..aadebd8 100644
9687 --- a/arch/x86/include/asm/atomic64_32.h
9688 +++ b/arch/x86/include/asm/atomic64_32.h
9689 @@ -12,6 +12,14 @@ typedef struct {
9690 u64 __aligned(8) counter;
9691 } atomic64_t;
9692
9693 +#ifdef CONFIG_PAX_REFCOUNT
9694 +typedef struct {
9695 + u64 __aligned(8) counter;
9696 +} atomic64_unchecked_t;
9697 +#else
9698 +typedef atomic64_t atomic64_unchecked_t;
9699 +#endif
9700 +
9701 #define ATOMIC64_INIT(val) { (val) }
9702
9703 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9704 @@ -37,21 +45,31 @@ typedef struct {
9705 ATOMIC64_DECL_ONE(sym##_386)
9706
9707 ATOMIC64_DECL_ONE(add_386);
9708 +ATOMIC64_DECL_ONE(add_unchecked_386);
9709 ATOMIC64_DECL_ONE(sub_386);
9710 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9711 ATOMIC64_DECL_ONE(inc_386);
9712 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9713 ATOMIC64_DECL_ONE(dec_386);
9714 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9715 #endif
9716
9717 #define alternative_atomic64(f, out, in...) \
9718 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9719
9720 ATOMIC64_DECL(read);
9721 +ATOMIC64_DECL(read_unchecked);
9722 ATOMIC64_DECL(set);
9723 +ATOMIC64_DECL(set_unchecked);
9724 ATOMIC64_DECL(xchg);
9725 ATOMIC64_DECL(add_return);
9726 +ATOMIC64_DECL(add_return_unchecked);
9727 ATOMIC64_DECL(sub_return);
9728 +ATOMIC64_DECL(sub_return_unchecked);
9729 ATOMIC64_DECL(inc_return);
9730 +ATOMIC64_DECL(inc_return_unchecked);
9731 ATOMIC64_DECL(dec_return);
9732 +ATOMIC64_DECL(dec_return_unchecked);
9733 ATOMIC64_DECL(dec_if_positive);
9734 ATOMIC64_DECL(inc_not_zero);
9735 ATOMIC64_DECL(add_unless);
9736 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9737 }
9738
9739 /**
9740 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9741 + * @p: pointer to type atomic64_unchecked_t
9742 + * @o: expected value
9743 + * @n: new value
9744 + *
9745 + * Atomically sets @v to @n if it was equal to @o and returns
9746 + * the old value.
9747 + */
9748 +
9749 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9750 +{
9751 + return cmpxchg64(&v->counter, o, n);
9752 +}
9753 +
9754 +/**
9755 * atomic64_xchg - xchg atomic64 variable
9756 * @v: pointer to type atomic64_t
9757 * @n: value to assign
9758 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9759 }
9760
9761 /**
9762 + * atomic64_set_unchecked - set atomic64 variable
9763 + * @v: pointer to type atomic64_unchecked_t
9764 + * @n: value to assign
9765 + *
9766 + * Atomically sets the value of @v to @n.
9767 + */
9768 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9769 +{
9770 + unsigned high = (unsigned)(i >> 32);
9771 + unsigned low = (unsigned)i;
9772 + alternative_atomic64(set, /* no output */,
9773 + "S" (v), "b" (low), "c" (high)
9774 + : "eax", "edx", "memory");
9775 +}
9776 +
9777 +/**
9778 * atomic64_read - read atomic64 variable
9779 * @v: pointer to type atomic64_t
9780 *
9781 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9782 }
9783
9784 /**
9785 + * atomic64_read_unchecked - read atomic64 variable
9786 + * @v: pointer to type atomic64_unchecked_t
9787 + *
9788 + * Atomically reads the value of @v and returns it.
9789 + */
9790 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9791 +{
9792 + long long r;
9793 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9794 + return r;
9795 + }
9796 +
9797 +/**
9798 * atomic64_add_return - add and return
9799 * @i: integer value to add
9800 * @v: pointer to type atomic64_t
9801 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9802 return i;
9803 }
9804
9805 +/**
9806 + * atomic64_add_return_unchecked - add and return
9807 + * @i: integer value to add
9808 + * @v: pointer to type atomic64_unchecked_t
9809 + *
9810 + * Atomically adds @i to @v and returns @i + *@v
9811 + */
9812 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9813 +{
9814 + alternative_atomic64(add_return_unchecked,
9815 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9816 + ASM_NO_INPUT_CLOBBER("memory"));
9817 + return i;
9818 +}
9819 +
9820 /*
9821 * Other variants with different arithmetic operators:
9822 */
9823 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9824 return a;
9825 }
9826
9827 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9828 +{
9829 + long long a;
9830 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9831 + "S" (v) : "memory", "ecx");
9832 + return a;
9833 +}
9834 +
9835 static inline long long atomic64_dec_return(atomic64_t *v)
9836 {
9837 long long a;
9838 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9839 }
9840
9841 /**
9842 + * atomic64_add_unchecked - add integer to atomic64 variable
9843 + * @i: integer value to add
9844 + * @v: pointer to type atomic64_unchecked_t
9845 + *
9846 + * Atomically adds @i to @v.
9847 + */
9848 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9849 +{
9850 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9851 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9852 + ASM_NO_INPUT_CLOBBER("memory"));
9853 + return i;
9854 +}
9855 +
9856 +/**
9857 * atomic64_sub - subtract the atomic64 variable
9858 * @i: integer value to subtract
9859 * @v: pointer to type atomic64_t
9860 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9861 index 0e1cbfc..5623683 100644
9862 --- a/arch/x86/include/asm/atomic64_64.h
9863 +++ b/arch/x86/include/asm/atomic64_64.h
9864 @@ -18,7 +18,19 @@
9865 */
9866 static inline long atomic64_read(const atomic64_t *v)
9867 {
9868 - return (*(volatile long *)&(v)->counter);
9869 + return (*(volatile const long *)&(v)->counter);
9870 +}
9871 +
9872 +/**
9873 + * atomic64_read_unchecked - read atomic64 variable
9874 + * @v: pointer of type atomic64_unchecked_t
9875 + *
9876 + * Atomically reads the value of @v.
9877 + * Doesn't imply a read memory barrier.
9878 + */
9879 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9880 +{
9881 + return (*(volatile const long *)&(v)->counter);
9882 }
9883
9884 /**
9885 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9886 }
9887
9888 /**
9889 + * atomic64_set_unchecked - set atomic64 variable
9890 + * @v: pointer to type atomic64_unchecked_t
9891 + * @i: required value
9892 + *
9893 + * Atomically sets the value of @v to @i.
9894 + */
9895 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9896 +{
9897 + v->counter = i;
9898 +}
9899 +
9900 +/**
9901 * atomic64_add - add integer to atomic64 variable
9902 * @i: integer value to add
9903 * @v: pointer to type atomic64_t
9904 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9905 */
9906 static inline void atomic64_add(long i, atomic64_t *v)
9907 {
9908 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9909 +
9910 +#ifdef CONFIG_PAX_REFCOUNT
9911 + "jno 0f\n"
9912 + LOCK_PREFIX "subq %1,%0\n"
9913 + "int $4\n0:\n"
9914 + _ASM_EXTABLE(0b, 0b)
9915 +#endif
9916 +
9917 + : "=m" (v->counter)
9918 + : "er" (i), "m" (v->counter));
9919 +}
9920 +
9921 +/**
9922 + * atomic64_add_unchecked - add integer to atomic64 variable
9923 + * @i: integer value to add
9924 + * @v: pointer to type atomic64_unchecked_t
9925 + *
9926 + * Atomically adds @i to @v.
9927 + */
9928 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9929 +{
9930 asm volatile(LOCK_PREFIX "addq %1,%0"
9931 : "=m" (v->counter)
9932 : "er" (i), "m" (v->counter));
9933 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9934 */
9935 static inline void atomic64_sub(long i, atomic64_t *v)
9936 {
9937 - asm volatile(LOCK_PREFIX "subq %1,%0"
9938 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9939 +
9940 +#ifdef CONFIG_PAX_REFCOUNT
9941 + "jno 0f\n"
9942 + LOCK_PREFIX "addq %1,%0\n"
9943 + "int $4\n0:\n"
9944 + _ASM_EXTABLE(0b, 0b)
9945 +#endif
9946 +
9947 + : "=m" (v->counter)
9948 + : "er" (i), "m" (v->counter));
9949 +}
9950 +
9951 +/**
9952 + * atomic64_sub_unchecked - subtract the atomic64 variable
9953 + * @i: integer value to subtract
9954 + * @v: pointer to type atomic64_unchecked_t
9955 + *
9956 + * Atomically subtracts @i from @v.
9957 + */
9958 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9959 +{
9960 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9961 : "=m" (v->counter)
9962 : "er" (i), "m" (v->counter));
9963 }
9964 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9965 {
9966 unsigned char c;
9967
9968 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9969 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9970 +
9971 +#ifdef CONFIG_PAX_REFCOUNT
9972 + "jno 0f\n"
9973 + LOCK_PREFIX "addq %2,%0\n"
9974 + "int $4\n0:\n"
9975 + _ASM_EXTABLE(0b, 0b)
9976 +#endif
9977 +
9978 + "sete %1\n"
9979 : "=m" (v->counter), "=qm" (c)
9980 : "er" (i), "m" (v->counter) : "memory");
9981 return c;
9982 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9983 */
9984 static inline void atomic64_inc(atomic64_t *v)
9985 {
9986 + asm volatile(LOCK_PREFIX "incq %0\n"
9987 +
9988 +#ifdef CONFIG_PAX_REFCOUNT
9989 + "jno 0f\n"
9990 + LOCK_PREFIX "decq %0\n"
9991 + "int $4\n0:\n"
9992 + _ASM_EXTABLE(0b, 0b)
9993 +#endif
9994 +
9995 + : "=m" (v->counter)
9996 + : "m" (v->counter));
9997 +}
9998 +
9999 +/**
10000 + * atomic64_inc_unchecked - increment atomic64 variable
10001 + * @v: pointer to type atomic64_unchecked_t
10002 + *
10003 + * Atomically increments @v by 1.
10004 + */
10005 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10006 +{
10007 asm volatile(LOCK_PREFIX "incq %0"
10008 : "=m" (v->counter)
10009 : "m" (v->counter));
10010 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
10011 */
10012 static inline void atomic64_dec(atomic64_t *v)
10013 {
10014 - asm volatile(LOCK_PREFIX "decq %0"
10015 + asm volatile(LOCK_PREFIX "decq %0\n"
10016 +
10017 +#ifdef CONFIG_PAX_REFCOUNT
10018 + "jno 0f\n"
10019 + LOCK_PREFIX "incq %0\n"
10020 + "int $4\n0:\n"
10021 + _ASM_EXTABLE(0b, 0b)
10022 +#endif
10023 +
10024 + : "=m" (v->counter)
10025 + : "m" (v->counter));
10026 +}
10027 +
10028 +/**
10029 + * atomic64_dec_unchecked - decrement atomic64 variable
10030 + * @v: pointer to type atomic64_t
10031 + *
10032 + * Atomically decrements @v by 1.
10033 + */
10034 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10035 +{
10036 + asm volatile(LOCK_PREFIX "decq %0\n"
10037 : "=m" (v->counter)
10038 : "m" (v->counter));
10039 }
10040 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
10041 {
10042 unsigned char c;
10043
10044 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
10045 + asm volatile(LOCK_PREFIX "decq %0\n"
10046 +
10047 +#ifdef CONFIG_PAX_REFCOUNT
10048 + "jno 0f\n"
10049 + LOCK_PREFIX "incq %0\n"
10050 + "int $4\n0:\n"
10051 + _ASM_EXTABLE(0b, 0b)
10052 +#endif
10053 +
10054 + "sete %1\n"
10055 : "=m" (v->counter), "=qm" (c)
10056 : "m" (v->counter) : "memory");
10057 return c != 0;
10058 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
10059 {
10060 unsigned char c;
10061
10062 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
10063 + asm volatile(LOCK_PREFIX "incq %0\n"
10064 +
10065 +#ifdef CONFIG_PAX_REFCOUNT
10066 + "jno 0f\n"
10067 + LOCK_PREFIX "decq %0\n"
10068 + "int $4\n0:\n"
10069 + _ASM_EXTABLE(0b, 0b)
10070 +#endif
10071 +
10072 + "sete %1\n"
10073 : "=m" (v->counter), "=qm" (c)
10074 : "m" (v->counter) : "memory");
10075 return c != 0;
10076 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10077 {
10078 unsigned char c;
10079
10080 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
10081 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
10082 +
10083 +#ifdef CONFIG_PAX_REFCOUNT
10084 + "jno 0f\n"
10085 + LOCK_PREFIX "subq %2,%0\n"
10086 + "int $4\n0:\n"
10087 + _ASM_EXTABLE(0b, 0b)
10088 +#endif
10089 +
10090 + "sets %1\n"
10091 : "=m" (v->counter), "=qm" (c)
10092 : "er" (i), "m" (v->counter) : "memory");
10093 return c;
10094 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10095 */
10096 static inline long atomic64_add_return(long i, atomic64_t *v)
10097 {
10098 + return i + xadd_check_overflow(&v->counter, i);
10099 +}
10100 +
10101 +/**
10102 + * atomic64_add_return_unchecked - add and return
10103 + * @i: integer value to add
10104 + * @v: pointer to type atomic64_unchecked_t
10105 + *
10106 + * Atomically adds @i to @v and returns @i + @v
10107 + */
10108 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10109 +{
10110 return i + xadd(&v->counter, i);
10111 }
10112
10113 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10114 }
10115
10116 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10117 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10118 +{
10119 + return atomic64_add_return_unchecked(1, v);
10120 +}
10121 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10122
10123 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10124 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10125 return cmpxchg(&v->counter, old, new);
10126 }
10127
10128 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10129 +{
10130 + return cmpxchg(&v->counter, old, new);
10131 +}
10132 +
10133 static inline long atomic64_xchg(atomic64_t *v, long new)
10134 {
10135 return xchg(&v->counter, new);
10136 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10137 */
10138 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10139 {
10140 - long c, old;
10141 + long c, old, new;
10142 c = atomic64_read(v);
10143 for (;;) {
10144 - if (unlikely(c == (u)))
10145 + if (unlikely(c == u))
10146 break;
10147 - old = atomic64_cmpxchg((v), c, c + (a));
10148 +
10149 + asm volatile("add %2,%0\n"
10150 +
10151 +#ifdef CONFIG_PAX_REFCOUNT
10152 + "jno 0f\n"
10153 + "sub %2,%0\n"
10154 + "int $4\n0:\n"
10155 + _ASM_EXTABLE(0b, 0b)
10156 +#endif
10157 +
10158 + : "=r" (new)
10159 + : "0" (c), "ir" (a));
10160 +
10161 + old = atomic64_cmpxchg(v, c, new);
10162 if (likely(old == c))
10163 break;
10164 c = old;
10165 }
10166 - return c != (u);
10167 + return c != u;
10168 }
10169
10170 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10171 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10172 index 6dfd019..0c6699f 100644
10173 --- a/arch/x86/include/asm/bitops.h
10174 +++ b/arch/x86/include/asm/bitops.h
10175 @@ -40,7 +40,7 @@
10176 * a mask operation on a byte.
10177 */
10178 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10179 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10180 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10181 #define CONST_MASK(nr) (1 << ((nr) & 7))
10182
10183 /**
10184 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10185 index b13fe63..0dab13a 100644
10186 --- a/arch/x86/include/asm/boot.h
10187 +++ b/arch/x86/include/asm/boot.h
10188 @@ -11,10 +11,15 @@
10189 #include <asm/pgtable_types.h>
10190
10191 /* Physical address where kernel should be loaded. */
10192 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10193 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10194 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10195 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10196
10197 +#ifndef __ASSEMBLY__
10198 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10199 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10200 +#endif
10201 +
10202 /* Minimum kernel alignment, as a power of two */
10203 #ifdef CONFIG_X86_64
10204 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10205 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10206 index 48f99f1..d78ebf9 100644
10207 --- a/arch/x86/include/asm/cache.h
10208 +++ b/arch/x86/include/asm/cache.h
10209 @@ -5,12 +5,13 @@
10210
10211 /* L1 cache line size */
10212 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10213 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10214 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10215
10216 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10217 +#define __read_only __attribute__((__section__(".data..read_only")))
10218
10219 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10220 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10221 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10222
10223 #ifdef CONFIG_X86_VSMP
10224 #ifdef CONFIG_SMP
10225 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10226 index 9863ee3..4a1f8e1 100644
10227 --- a/arch/x86/include/asm/cacheflush.h
10228 +++ b/arch/x86/include/asm/cacheflush.h
10229 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10230 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10231
10232 if (pg_flags == _PGMT_DEFAULT)
10233 - return -1;
10234 + return ~0UL;
10235 else if (pg_flags == _PGMT_WC)
10236 return _PAGE_CACHE_WC;
10237 else if (pg_flags == _PGMT_UC_MINUS)
10238 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10239 index 46fc474..b02b0f9 100644
10240 --- a/arch/x86/include/asm/checksum_32.h
10241 +++ b/arch/x86/include/asm/checksum_32.h
10242 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10243 int len, __wsum sum,
10244 int *src_err_ptr, int *dst_err_ptr);
10245
10246 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10247 + int len, __wsum sum,
10248 + int *src_err_ptr, int *dst_err_ptr);
10249 +
10250 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10251 + int len, __wsum sum,
10252 + int *src_err_ptr, int *dst_err_ptr);
10253 +
10254 /*
10255 * Note: when you get a NULL pointer exception here this means someone
10256 * passed in an incorrect kernel address to one of these functions.
10257 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10258 int *err_ptr)
10259 {
10260 might_sleep();
10261 - return csum_partial_copy_generic((__force void *)src, dst,
10262 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10263 len, sum, err_ptr, NULL);
10264 }
10265
10266 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10267 {
10268 might_sleep();
10269 if (access_ok(VERIFY_WRITE, dst, len))
10270 - return csum_partial_copy_generic(src, (__force void *)dst,
10271 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10272 len, sum, NULL, err_ptr);
10273
10274 if (len)
10275 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10276 index 8d871ea..c1a0dc9 100644
10277 --- a/arch/x86/include/asm/cmpxchg.h
10278 +++ b/arch/x86/include/asm/cmpxchg.h
10279 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10280 __compiletime_error("Bad argument size for cmpxchg");
10281 extern void __xadd_wrong_size(void)
10282 __compiletime_error("Bad argument size for xadd");
10283 +extern void __xadd_check_overflow_wrong_size(void)
10284 + __compiletime_error("Bad argument size for xadd_check_overflow");
10285 extern void __add_wrong_size(void)
10286 __compiletime_error("Bad argument size for add");
10287 +extern void __add_check_overflow_wrong_size(void)
10288 + __compiletime_error("Bad argument size for add_check_overflow");
10289
10290 /*
10291 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10292 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10293 __ret; \
10294 })
10295
10296 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10297 + ({ \
10298 + __typeof__ (*(ptr)) __ret = (arg); \
10299 + switch (sizeof(*(ptr))) { \
10300 + case __X86_CASE_L: \
10301 + asm volatile (lock #op "l %0, %1\n" \
10302 + "jno 0f\n" \
10303 + "mov %0,%1\n" \
10304 + "int $4\n0:\n" \
10305 + _ASM_EXTABLE(0b, 0b) \
10306 + : "+r" (__ret), "+m" (*(ptr)) \
10307 + : : "memory", "cc"); \
10308 + break; \
10309 + case __X86_CASE_Q: \
10310 + asm volatile (lock #op "q %q0, %1\n" \
10311 + "jno 0f\n" \
10312 + "mov %0,%1\n" \
10313 + "int $4\n0:\n" \
10314 + _ASM_EXTABLE(0b, 0b) \
10315 + : "+r" (__ret), "+m" (*(ptr)) \
10316 + : : "memory", "cc"); \
10317 + break; \
10318 + default: \
10319 + __ ## op ## _check_overflow_wrong_size(); \
10320 + } \
10321 + __ret; \
10322 + })
10323 +
10324 /*
10325 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10326 * Since this is generally used to protect other memory information, we
10327 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10328 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10329 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10330
10331 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10332 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10333 +
10334 #define __add(ptr, inc, lock) \
10335 ({ \
10336 __typeof__ (*(ptr)) __ret = (inc); \
10337 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10338 index 8c297aa..7a90f03 100644
10339 --- a/arch/x86/include/asm/cpufeature.h
10340 +++ b/arch/x86/include/asm/cpufeature.h
10341 @@ -205,7 +205,7 @@
10342 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10343 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10344 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10345 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10346 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10347 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10348 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10349 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10350 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10351 ".section .discard,\"aw\",@progbits\n"
10352 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10353 ".previous\n"
10354 - ".section .altinstr_replacement,\"ax\"\n"
10355 + ".section .altinstr_replacement,\"a\"\n"
10356 "3: movb $1,%0\n"
10357 "4:\n"
10358 ".previous\n"
10359 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10360 index 8bf1c06..f723dfd 100644
10361 --- a/arch/x86/include/asm/desc.h
10362 +++ b/arch/x86/include/asm/desc.h
10363 @@ -4,6 +4,7 @@
10364 #include <asm/desc_defs.h>
10365 #include <asm/ldt.h>
10366 #include <asm/mmu.h>
10367 +#include <asm/pgtable.h>
10368
10369 #include <linux/smp.h>
10370 #include <linux/percpu.h>
10371 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10372
10373 desc->type = (info->read_exec_only ^ 1) << 1;
10374 desc->type |= info->contents << 2;
10375 + desc->type |= info->seg_not_present ^ 1;
10376
10377 desc->s = 1;
10378 desc->dpl = 0x3;
10379 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10380 }
10381
10382 extern struct desc_ptr idt_descr;
10383 -extern gate_desc idt_table[];
10384 extern struct desc_ptr nmi_idt_descr;
10385 -extern gate_desc nmi_idt_table[];
10386 -
10387 -struct gdt_page {
10388 - struct desc_struct gdt[GDT_ENTRIES];
10389 -} __attribute__((aligned(PAGE_SIZE)));
10390 -
10391 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10392 +extern gate_desc idt_table[256];
10393 +extern gate_desc nmi_idt_table[256];
10394
10395 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10396 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10397 {
10398 - return per_cpu(gdt_page, cpu).gdt;
10399 + return cpu_gdt_table[cpu];
10400 }
10401
10402 #ifdef CONFIG_X86_64
10403 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10404 unsigned long base, unsigned dpl, unsigned flags,
10405 unsigned short seg)
10406 {
10407 - gate->a = (seg << 16) | (base & 0xffff);
10408 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10409 + gate->gate.offset_low = base;
10410 + gate->gate.seg = seg;
10411 + gate->gate.reserved = 0;
10412 + gate->gate.type = type;
10413 + gate->gate.s = 0;
10414 + gate->gate.dpl = dpl;
10415 + gate->gate.p = 1;
10416 + gate->gate.offset_high = base >> 16;
10417 }
10418
10419 #endif
10420 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10421
10422 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10423 {
10424 + pax_open_kernel();
10425 memcpy(&idt[entry], gate, sizeof(*gate));
10426 + pax_close_kernel();
10427 }
10428
10429 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10430 {
10431 + pax_open_kernel();
10432 memcpy(&ldt[entry], desc, 8);
10433 + pax_close_kernel();
10434 }
10435
10436 static inline void
10437 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10438 default: size = sizeof(*gdt); break;
10439 }
10440
10441 + pax_open_kernel();
10442 memcpy(&gdt[entry], desc, size);
10443 + pax_close_kernel();
10444 }
10445
10446 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10447 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10448
10449 static inline void native_load_tr_desc(void)
10450 {
10451 + pax_open_kernel();
10452 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10453 + pax_close_kernel();
10454 }
10455
10456 static inline void native_load_gdt(const struct desc_ptr *dtr)
10457 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10458 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10459 unsigned int i;
10460
10461 + pax_open_kernel();
10462 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10463 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10464 + pax_close_kernel();
10465 }
10466
10467 #define _LDT_empty(info) \
10468 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10469 }
10470
10471 #ifdef CONFIG_X86_64
10472 -static inline void set_nmi_gate(int gate, void *addr)
10473 +static inline void set_nmi_gate(int gate, const void *addr)
10474 {
10475 gate_desc s;
10476
10477 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10478 }
10479 #endif
10480
10481 -static inline void _set_gate(int gate, unsigned type, void *addr,
10482 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10483 unsigned dpl, unsigned ist, unsigned seg)
10484 {
10485 gate_desc s;
10486 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10487 * Pentium F0 0F bugfix can have resulted in the mapped
10488 * IDT being write-protected.
10489 */
10490 -static inline void set_intr_gate(unsigned int n, void *addr)
10491 +static inline void set_intr_gate(unsigned int n, const void *addr)
10492 {
10493 BUG_ON((unsigned)n > 0xFF);
10494 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10495 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10496 /*
10497 * This routine sets up an interrupt gate at directory privilege level 3.
10498 */
10499 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10500 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10501 {
10502 BUG_ON((unsigned)n > 0xFF);
10503 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10504 }
10505
10506 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10507 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10508 {
10509 BUG_ON((unsigned)n > 0xFF);
10510 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10511 }
10512
10513 -static inline void set_trap_gate(unsigned int n, void *addr)
10514 +static inline void set_trap_gate(unsigned int n, const void *addr)
10515 {
10516 BUG_ON((unsigned)n > 0xFF);
10517 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10518 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10519 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10520 {
10521 BUG_ON((unsigned)n > 0xFF);
10522 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10523 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10524 }
10525
10526 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10527 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10528 {
10529 BUG_ON((unsigned)n > 0xFF);
10530 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10531 }
10532
10533 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10534 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10535 {
10536 BUG_ON((unsigned)n > 0xFF);
10537 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10538 }
10539
10540 +#ifdef CONFIG_X86_32
10541 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10542 +{
10543 + struct desc_struct d;
10544 +
10545 + if (likely(limit))
10546 + limit = (limit - 1UL) >> PAGE_SHIFT;
10547 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10548 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10549 +}
10550 +#endif
10551 +
10552 #endif /* _ASM_X86_DESC_H */
10553 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10554 index 278441f..b95a174 100644
10555 --- a/arch/x86/include/asm/desc_defs.h
10556 +++ b/arch/x86/include/asm/desc_defs.h
10557 @@ -31,6 +31,12 @@ struct desc_struct {
10558 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10559 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10560 };
10561 + struct {
10562 + u16 offset_low;
10563 + u16 seg;
10564 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10565 + unsigned offset_high: 16;
10566 + } gate;
10567 };
10568 } __attribute__((packed));
10569
10570 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10571 index 3778256..c5d4fce 100644
10572 --- a/arch/x86/include/asm/e820.h
10573 +++ b/arch/x86/include/asm/e820.h
10574 @@ -69,7 +69,7 @@ struct e820map {
10575 #define ISA_START_ADDRESS 0xa0000
10576 #define ISA_END_ADDRESS 0x100000
10577
10578 -#define BIOS_BEGIN 0x000a0000
10579 +#define BIOS_BEGIN 0x000c0000
10580 #define BIOS_END 0x00100000
10581
10582 #define BIOS_ROM_BASE 0xffe00000
10583 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10584 index 5939f44..f8845f6 100644
10585 --- a/arch/x86/include/asm/elf.h
10586 +++ b/arch/x86/include/asm/elf.h
10587 @@ -243,7 +243,25 @@ extern int force_personality32;
10588 the loader. We need to make sure that it is out of the way of the program
10589 that it will "exec", and that there is sufficient room for the brk. */
10590
10591 +#ifdef CONFIG_PAX_SEGMEXEC
10592 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10593 +#else
10594 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10595 +#endif
10596 +
10597 +#ifdef CONFIG_PAX_ASLR
10598 +#ifdef CONFIG_X86_32
10599 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10600 +
10601 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10602 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10603 +#else
10604 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10605 +
10606 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10607 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10608 +#endif
10609 +#endif
10610
10611 /* This yields a mask that user programs can use to figure out what
10612 instruction set this CPU supports. This could be done in user space,
10613 @@ -296,16 +314,12 @@ do { \
10614
10615 #define ARCH_DLINFO \
10616 do { \
10617 - if (vdso_enabled) \
10618 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10619 - (unsigned long)current->mm->context.vdso); \
10620 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10621 } while (0)
10622
10623 #define ARCH_DLINFO_X32 \
10624 do { \
10625 - if (vdso_enabled) \
10626 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10627 - (unsigned long)current->mm->context.vdso); \
10628 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10629 } while (0)
10630
10631 #define AT_SYSINFO 32
10632 @@ -320,7 +334,7 @@ else \
10633
10634 #endif /* !CONFIG_X86_32 */
10635
10636 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10637 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10638
10639 #define VDSO_ENTRY \
10640 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10641 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10642 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10643 #define compat_arch_setup_additional_pages syscall32_setup_pages
10644
10645 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10646 -#define arch_randomize_brk arch_randomize_brk
10647 -
10648 /*
10649 * True on X86_32 or when emulating IA32 on X86_64
10650 */
10651 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10652 index 75ce3f4..882e801 100644
10653 --- a/arch/x86/include/asm/emergency-restart.h
10654 +++ b/arch/x86/include/asm/emergency-restart.h
10655 @@ -13,6 +13,6 @@ enum reboot_type {
10656
10657 extern enum reboot_type reboot_type;
10658
10659 -extern void machine_emergency_restart(void);
10660 +extern void machine_emergency_restart(void) __noreturn;
10661
10662 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10663 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10664 index 41ab26e..a88c9e6 100644
10665 --- a/arch/x86/include/asm/fpu-internal.h
10666 +++ b/arch/x86/include/asm/fpu-internal.h
10667 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
10668 ({ \
10669 int err; \
10670 asm volatile(ASM_STAC "\n" \
10671 - "1:" #insn "\n\t" \
10672 + "1:" \
10673 + __copyuser_seg \
10674 + #insn "\n\t" \
10675 "2: " ASM_CLAC "\n" \
10676 ".section .fixup,\"ax\"\n" \
10677 "3: movl $-1,%[err]\n" \
10678 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10679 "emms\n\t" /* clear stack tags */
10680 "fildl %P[addr]", /* set F?P to defined value */
10681 X86_FEATURE_FXSAVE_LEAK,
10682 - [addr] "m" (tsk->thread.fpu.has_fpu));
10683 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
10684
10685 return fpu_restore_checking(&tsk->thread.fpu);
10686 }
10687 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10688 index f373046..02653e2 100644
10689 --- a/arch/x86/include/asm/futex.h
10690 +++ b/arch/x86/include/asm/futex.h
10691 @@ -12,6 +12,7 @@
10692 #include <asm/smap.h>
10693
10694 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10695 + typecheck(u32 __user *, uaddr); \
10696 asm volatile("\t" ASM_STAC "\n" \
10697 "1:\t" insn "\n" \
10698 "2:\t" ASM_CLAC "\n" \
10699 @@ -20,15 +21,16 @@
10700 "\tjmp\t2b\n" \
10701 "\t.previous\n" \
10702 _ASM_EXTABLE(1b, 3b) \
10703 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10704 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
10705 : "i" (-EFAULT), "0" (oparg), "1" (0))
10706
10707 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10708 + typecheck(u32 __user *, uaddr); \
10709 asm volatile("\t" ASM_STAC "\n" \
10710 "1:\tmovl %2, %0\n" \
10711 "\tmovl\t%0, %3\n" \
10712 "\t" insn "\n" \
10713 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
10714 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
10715 "\tjnz\t1b\n" \
10716 "3:\t" ASM_CLAC "\n" \
10717 "\t.section .fixup,\"ax\"\n" \
10718 @@ -38,7 +40,7 @@
10719 _ASM_EXTABLE(1b, 4b) \
10720 _ASM_EXTABLE(2b, 4b) \
10721 : "=&a" (oldval), "=&r" (ret), \
10722 - "+m" (*uaddr), "=&r" (tem) \
10723 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10724 : "r" (oparg), "i" (-EFAULT), "1" (0))
10725
10726 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10727 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10728
10729 switch (op) {
10730 case FUTEX_OP_SET:
10731 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10732 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10733 break;
10734 case FUTEX_OP_ADD:
10735 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10736 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10737 uaddr, oparg);
10738 break;
10739 case FUTEX_OP_OR:
10740 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10741 return -EFAULT;
10742
10743 asm volatile("\t" ASM_STAC "\n"
10744 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10745 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10746 "2:\t" ASM_CLAC "\n"
10747 "\t.section .fixup, \"ax\"\n"
10748 "3:\tmov %3, %0\n"
10749 "\tjmp 2b\n"
10750 "\t.previous\n"
10751 _ASM_EXTABLE(1b, 3b)
10752 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10753 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10754 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10755 : "memory"
10756 );
10757 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10758 index eb92a6e..b98b2f4 100644
10759 --- a/arch/x86/include/asm/hw_irq.h
10760 +++ b/arch/x86/include/asm/hw_irq.h
10761 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10762 extern void enable_IO_APIC(void);
10763
10764 /* Statistics */
10765 -extern atomic_t irq_err_count;
10766 -extern atomic_t irq_mis_count;
10767 +extern atomic_unchecked_t irq_err_count;
10768 +extern atomic_unchecked_t irq_mis_count;
10769
10770 /* EISA */
10771 extern void eisa_set_level_irq(unsigned int irq);
10772 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10773 index d8e8eef..99f81ae 100644
10774 --- a/arch/x86/include/asm/io.h
10775 +++ b/arch/x86/include/asm/io.h
10776 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10777
10778 #include <linux/vmalloc.h>
10779
10780 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10781 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10782 +{
10783 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10784 +}
10785 +
10786 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10787 +{
10788 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10789 +}
10790 +
10791 /*
10792 * Convert a virtual cached pointer to an uncached pointer
10793 */
10794 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10795 index bba3cf8..06bc8da 100644
10796 --- a/arch/x86/include/asm/irqflags.h
10797 +++ b/arch/x86/include/asm/irqflags.h
10798 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10799 sti; \
10800 sysexit
10801
10802 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10803 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10804 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10805 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10806 +
10807 #else
10808 #define INTERRUPT_RETURN iret
10809 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10810 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10811 index d3ddd17..c9fb0cc 100644
10812 --- a/arch/x86/include/asm/kprobes.h
10813 +++ b/arch/x86/include/asm/kprobes.h
10814 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
10815 #define RELATIVEJUMP_SIZE 5
10816 #define RELATIVECALL_OPCODE 0xe8
10817 #define RELATIVE_ADDR_SIZE 4
10818 -#define MAX_STACK_SIZE 64
10819 -#define MIN_STACK_SIZE(ADDR) \
10820 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10821 - THREAD_SIZE - (unsigned long)(ADDR))) \
10822 - ? (MAX_STACK_SIZE) \
10823 - : (((unsigned long)current_thread_info()) + \
10824 - THREAD_SIZE - (unsigned long)(ADDR)))
10825 +#define MAX_STACK_SIZE 64UL
10826 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10827
10828 #define flush_insn_slot(p) do { } while (0)
10829
10830 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10831 index b2e11f4..f293e2e 100644
10832 --- a/arch/x86/include/asm/kvm_host.h
10833 +++ b/arch/x86/include/asm/kvm_host.h
10834 @@ -707,7 +707,7 @@ struct kvm_x86_ops {
10835 int (*check_intercept)(struct kvm_vcpu *vcpu,
10836 struct x86_instruction_info *info,
10837 enum x86_intercept_stage stage);
10838 -};
10839 +} __do_const;
10840
10841 struct kvm_arch_async_pf {
10842 u32 token;
10843 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10844 index c8bed0d..85c03fd 100644
10845 --- a/arch/x86/include/asm/local.h
10846 +++ b/arch/x86/include/asm/local.h
10847 @@ -10,33 +10,97 @@ typedef struct {
10848 atomic_long_t a;
10849 } local_t;
10850
10851 +typedef struct {
10852 + atomic_long_unchecked_t a;
10853 +} local_unchecked_t;
10854 +
10855 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
10856
10857 #define local_read(l) atomic_long_read(&(l)->a)
10858 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
10859 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
10860 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
10861
10862 static inline void local_inc(local_t *l)
10863 {
10864 - asm volatile(_ASM_INC "%0"
10865 + asm volatile(_ASM_INC "%0\n"
10866 +
10867 +#ifdef CONFIG_PAX_REFCOUNT
10868 + "jno 0f\n"
10869 + _ASM_DEC "%0\n"
10870 + "int $4\n0:\n"
10871 + _ASM_EXTABLE(0b, 0b)
10872 +#endif
10873 +
10874 + : "+m" (l->a.counter));
10875 +}
10876 +
10877 +static inline void local_inc_unchecked(local_unchecked_t *l)
10878 +{
10879 + asm volatile(_ASM_INC "%0\n"
10880 : "+m" (l->a.counter));
10881 }
10882
10883 static inline void local_dec(local_t *l)
10884 {
10885 - asm volatile(_ASM_DEC "%0"
10886 + asm volatile(_ASM_DEC "%0\n"
10887 +
10888 +#ifdef CONFIG_PAX_REFCOUNT
10889 + "jno 0f\n"
10890 + _ASM_INC "%0\n"
10891 + "int $4\n0:\n"
10892 + _ASM_EXTABLE(0b, 0b)
10893 +#endif
10894 +
10895 + : "+m" (l->a.counter));
10896 +}
10897 +
10898 +static inline void local_dec_unchecked(local_unchecked_t *l)
10899 +{
10900 + asm volatile(_ASM_DEC "%0\n"
10901 : "+m" (l->a.counter));
10902 }
10903
10904 static inline void local_add(long i, local_t *l)
10905 {
10906 - asm volatile(_ASM_ADD "%1,%0"
10907 + asm volatile(_ASM_ADD "%1,%0\n"
10908 +
10909 +#ifdef CONFIG_PAX_REFCOUNT
10910 + "jno 0f\n"
10911 + _ASM_SUB "%1,%0\n"
10912 + "int $4\n0:\n"
10913 + _ASM_EXTABLE(0b, 0b)
10914 +#endif
10915 +
10916 + : "+m" (l->a.counter)
10917 + : "ir" (i));
10918 +}
10919 +
10920 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
10921 +{
10922 + asm volatile(_ASM_ADD "%1,%0\n"
10923 : "+m" (l->a.counter)
10924 : "ir" (i));
10925 }
10926
10927 static inline void local_sub(long i, local_t *l)
10928 {
10929 - asm volatile(_ASM_SUB "%1,%0"
10930 + asm volatile(_ASM_SUB "%1,%0\n"
10931 +
10932 +#ifdef CONFIG_PAX_REFCOUNT
10933 + "jno 0f\n"
10934 + _ASM_ADD "%1,%0\n"
10935 + "int $4\n0:\n"
10936 + _ASM_EXTABLE(0b, 0b)
10937 +#endif
10938 +
10939 + : "+m" (l->a.counter)
10940 + : "ir" (i));
10941 +}
10942 +
10943 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
10944 +{
10945 + asm volatile(_ASM_SUB "%1,%0\n"
10946 : "+m" (l->a.counter)
10947 : "ir" (i));
10948 }
10949 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10950 {
10951 unsigned char c;
10952
10953 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10954 + asm volatile(_ASM_SUB "%2,%0\n"
10955 +
10956 +#ifdef CONFIG_PAX_REFCOUNT
10957 + "jno 0f\n"
10958 + _ASM_ADD "%2,%0\n"
10959 + "int $4\n0:\n"
10960 + _ASM_EXTABLE(0b, 0b)
10961 +#endif
10962 +
10963 + "sete %1\n"
10964 : "+m" (l->a.counter), "=qm" (c)
10965 : "ir" (i) : "memory");
10966 return c;
10967 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
10968 {
10969 unsigned char c;
10970
10971 - asm volatile(_ASM_DEC "%0; sete %1"
10972 + asm volatile(_ASM_DEC "%0\n"
10973 +
10974 +#ifdef CONFIG_PAX_REFCOUNT
10975 + "jno 0f\n"
10976 + _ASM_INC "%0\n"
10977 + "int $4\n0:\n"
10978 + _ASM_EXTABLE(0b, 0b)
10979 +#endif
10980 +
10981 + "sete %1\n"
10982 : "+m" (l->a.counter), "=qm" (c)
10983 : : "memory");
10984 return c != 0;
10985 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
10986 {
10987 unsigned char c;
10988
10989 - asm volatile(_ASM_INC "%0; sete %1"
10990 + asm volatile(_ASM_INC "%0\n"
10991 +
10992 +#ifdef CONFIG_PAX_REFCOUNT
10993 + "jno 0f\n"
10994 + _ASM_DEC "%0\n"
10995 + "int $4\n0:\n"
10996 + _ASM_EXTABLE(0b, 0b)
10997 +#endif
10998 +
10999 + "sete %1\n"
11000 : "+m" (l->a.counter), "=qm" (c)
11001 : : "memory");
11002 return c != 0;
11003 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
11004 {
11005 unsigned char c;
11006
11007 - asm volatile(_ASM_ADD "%2,%0; sets %1"
11008 + asm volatile(_ASM_ADD "%2,%0\n"
11009 +
11010 +#ifdef CONFIG_PAX_REFCOUNT
11011 + "jno 0f\n"
11012 + _ASM_SUB "%2,%0\n"
11013 + "int $4\n0:\n"
11014 + _ASM_EXTABLE(0b, 0b)
11015 +#endif
11016 +
11017 + "sets %1\n"
11018 : "+m" (l->a.counter), "=qm" (c)
11019 : "ir" (i) : "memory");
11020 return c;
11021 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
11022 #endif
11023 /* Modern 486+ processor */
11024 __i = i;
11025 - asm volatile(_ASM_XADD "%0, %1;"
11026 + asm volatile(_ASM_XADD "%0, %1\n"
11027 +
11028 +#ifdef CONFIG_PAX_REFCOUNT
11029 + "jno 0f\n"
11030 + _ASM_MOV "%0,%1\n"
11031 + "int $4\n0:\n"
11032 + _ASM_EXTABLE(0b, 0b)
11033 +#endif
11034 +
11035 : "+r" (i), "+m" (l->a.counter)
11036 : : "memory");
11037 return i + __i;
11038 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
11039 #endif
11040 }
11041
11042 +/**
11043 + * local_add_return_unchecked - add and return
11044 + * @i: integer value to add
11045 + * @l: pointer to type local_unchecked_t
11046 + *
11047 + * Atomically adds @i to @l and returns @i + @l
11048 + */
11049 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
11050 +{
11051 + long __i;
11052 +#ifdef CONFIG_M386
11053 + unsigned long flags;
11054 + if (unlikely(boot_cpu_data.x86 <= 3))
11055 + goto no_xadd;
11056 +#endif
11057 + /* Modern 486+ processor */
11058 + __i = i;
11059 + asm volatile(_ASM_XADD "%0, %1\n"
11060 + : "+r" (i), "+m" (l->a.counter)
11061 + : : "memory");
11062 + return i + __i;
11063 +
11064 +#ifdef CONFIG_M386
11065 +no_xadd: /* Legacy 386 processor */
11066 + local_irq_save(flags);
11067 + __i = local_read_unchecked(l);
11068 + local_set_unchecked(l, i + __i);
11069 + local_irq_restore(flags);
11070 + return i + __i;
11071 +#endif
11072 +}
11073 +
11074 static inline long local_sub_return(long i, local_t *l)
11075 {
11076 return local_add_return(-i, l);
11077 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
11078
11079 #define local_cmpxchg(l, o, n) \
11080 (cmpxchg_local(&((l)->a.counter), (o), (n)))
11081 +#define local_cmpxchg_unchecked(l, o, n) \
11082 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
11083 /* Always has a lock prefix */
11084 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
11085
11086 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
11087 index 593e51d..fa69c9a 100644
11088 --- a/arch/x86/include/asm/mman.h
11089 +++ b/arch/x86/include/asm/mman.h
11090 @@ -5,4 +5,14 @@
11091
11092 #include <asm-generic/mman.h>
11093
11094 +#ifdef __KERNEL__
11095 +#ifndef __ASSEMBLY__
11096 +#ifdef CONFIG_X86_32
11097 +#define arch_mmap_check i386_mmap_check
11098 +int i386_mmap_check(unsigned long addr, unsigned long len,
11099 + unsigned long flags);
11100 +#endif
11101 +#endif
11102 +#endif
11103 +
11104 #endif /* _ASM_X86_MMAN_H */
11105 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
11106 index 5f55e69..e20bfb1 100644
11107 --- a/arch/x86/include/asm/mmu.h
11108 +++ b/arch/x86/include/asm/mmu.h
11109 @@ -9,7 +9,7 @@
11110 * we put the segment information here.
11111 */
11112 typedef struct {
11113 - void *ldt;
11114 + struct desc_struct *ldt;
11115 int size;
11116
11117 #ifdef CONFIG_X86_64
11118 @@ -18,7 +18,19 @@ typedef struct {
11119 #endif
11120
11121 struct mutex lock;
11122 - void *vdso;
11123 + unsigned long vdso;
11124 +
11125 +#ifdef CONFIG_X86_32
11126 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11127 + unsigned long user_cs_base;
11128 + unsigned long user_cs_limit;
11129 +
11130 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11131 + cpumask_t cpu_user_cs_mask;
11132 +#endif
11133 +
11134 +#endif
11135 +#endif
11136 } mm_context_t;
11137
11138 #ifdef CONFIG_SMP
11139 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
11140 index cdbf367..adb37ac 100644
11141 --- a/arch/x86/include/asm/mmu_context.h
11142 +++ b/arch/x86/include/asm/mmu_context.h
11143 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11144
11145 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11146 {
11147 +
11148 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11149 + unsigned int i;
11150 + pgd_t *pgd;
11151 +
11152 + pax_open_kernel();
11153 + pgd = get_cpu_pgd(smp_processor_id());
11154 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11155 + set_pgd_batched(pgd+i, native_make_pgd(0));
11156 + pax_close_kernel();
11157 +#endif
11158 +
11159 #ifdef CONFIG_SMP
11160 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11161 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11162 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11163 struct task_struct *tsk)
11164 {
11165 unsigned cpu = smp_processor_id();
11166 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11167 + int tlbstate = TLBSTATE_OK;
11168 +#endif
11169
11170 if (likely(prev != next)) {
11171 #ifdef CONFIG_SMP
11172 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11173 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11174 +#endif
11175 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11176 this_cpu_write(cpu_tlbstate.active_mm, next);
11177 #endif
11178 cpumask_set_cpu(cpu, mm_cpumask(next));
11179
11180 /* Re-load page tables */
11181 +#ifdef CONFIG_PAX_PER_CPU_PGD
11182 + pax_open_kernel();
11183 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11184 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11185 + pax_close_kernel();
11186 + load_cr3(get_cpu_pgd(cpu));
11187 +#else
11188 load_cr3(next->pgd);
11189 +#endif
11190
11191 /* stop flush ipis for the previous mm */
11192 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11193 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11194 */
11195 if (unlikely(prev->context.ldt != next->context.ldt))
11196 load_LDT_nolock(&next->context);
11197 - }
11198 +
11199 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11200 + if (!(__supported_pte_mask & _PAGE_NX)) {
11201 + smp_mb__before_clear_bit();
11202 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11203 + smp_mb__after_clear_bit();
11204 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11205 + }
11206 +#endif
11207 +
11208 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11209 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11210 + prev->context.user_cs_limit != next->context.user_cs_limit))
11211 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11212 #ifdef CONFIG_SMP
11213 + else if (unlikely(tlbstate != TLBSTATE_OK))
11214 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11215 +#endif
11216 +#endif
11217 +
11218 + }
11219 else {
11220 +
11221 +#ifdef CONFIG_PAX_PER_CPU_PGD
11222 + pax_open_kernel();
11223 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11224 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11225 + pax_close_kernel();
11226 + load_cr3(get_cpu_pgd(cpu));
11227 +#endif
11228 +
11229 +#ifdef CONFIG_SMP
11230 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11231 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11232
11233 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11234 * tlb flush IPI delivery. We must reload CR3
11235 * to make sure to use no freed page tables.
11236 */
11237 +
11238 +#ifndef CONFIG_PAX_PER_CPU_PGD
11239 load_cr3(next->pgd);
11240 +#endif
11241 +
11242 load_LDT_nolock(&next->context);
11243 +
11244 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11245 + if (!(__supported_pte_mask & _PAGE_NX))
11246 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11247 +#endif
11248 +
11249 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11250 +#ifdef CONFIG_PAX_PAGEEXEC
11251 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11252 +#endif
11253 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11254 +#endif
11255 +
11256 }
11257 +#endif
11258 }
11259 -#endif
11260 }
11261
11262 #define activate_mm(prev, next) \
11263 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11264 index 9eae775..c914fea 100644
11265 --- a/arch/x86/include/asm/module.h
11266 +++ b/arch/x86/include/asm/module.h
11267 @@ -5,6 +5,7 @@
11268
11269 #ifdef CONFIG_X86_64
11270 /* X86_64 does not define MODULE_PROC_FAMILY */
11271 +#define MODULE_PROC_FAMILY ""
11272 #elif defined CONFIG_M386
11273 #define MODULE_PROC_FAMILY "386 "
11274 #elif defined CONFIG_M486
11275 @@ -59,8 +60,20 @@
11276 #error unknown processor family
11277 #endif
11278
11279 -#ifdef CONFIG_X86_32
11280 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11281 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11282 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11283 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11284 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11285 +#else
11286 +#define MODULE_PAX_KERNEXEC ""
11287 #endif
11288
11289 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11290 +#define MODULE_PAX_UDEREF "UDEREF "
11291 +#else
11292 +#define MODULE_PAX_UDEREF ""
11293 +#endif
11294 +
11295 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11296 +
11297 #endif /* _ASM_X86_MODULE_H */
11298 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11299 index 320f7bb..e89f8f8 100644
11300 --- a/arch/x86/include/asm/page_64_types.h
11301 +++ b/arch/x86/include/asm/page_64_types.h
11302 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11303
11304 /* duplicated to the one in bootmem.h */
11305 extern unsigned long max_pfn;
11306 -extern unsigned long phys_base;
11307 +extern const unsigned long phys_base;
11308
11309 extern unsigned long __phys_addr(unsigned long);
11310 #define __phys_reloc_hide(x) (x)
11311 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11312 index a0facf3..c017b15 100644
11313 --- a/arch/x86/include/asm/paravirt.h
11314 +++ b/arch/x86/include/asm/paravirt.h
11315 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11316 val);
11317 }
11318
11319 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11320 +{
11321 + pgdval_t val = native_pgd_val(pgd);
11322 +
11323 + if (sizeof(pgdval_t) > sizeof(long))
11324 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11325 + val, (u64)val >> 32);
11326 + else
11327 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11328 + val);
11329 +}
11330 +
11331 static inline void pgd_clear(pgd_t *pgdp)
11332 {
11333 set_pgd(pgdp, __pgd(0));
11334 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11335 pv_mmu_ops.set_fixmap(idx, phys, flags);
11336 }
11337
11338 +#ifdef CONFIG_PAX_KERNEXEC
11339 +static inline unsigned long pax_open_kernel(void)
11340 +{
11341 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11342 +}
11343 +
11344 +static inline unsigned long pax_close_kernel(void)
11345 +{
11346 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11347 +}
11348 +#else
11349 +static inline unsigned long pax_open_kernel(void) { return 0; }
11350 +static inline unsigned long pax_close_kernel(void) { return 0; }
11351 +#endif
11352 +
11353 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11354
11355 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11356 @@ -929,7 +956,7 @@ extern void default_banner(void);
11357
11358 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11359 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11360 -#define PARA_INDIRECT(addr) *%cs:addr
11361 +#define PARA_INDIRECT(addr) *%ss:addr
11362 #endif
11363
11364 #define INTERRUPT_RETURN \
11365 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11366 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11367 CLBR_NONE, \
11368 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11369 +
11370 +#define GET_CR0_INTO_RDI \
11371 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11372 + mov %rax,%rdi
11373 +
11374 +#define SET_RDI_INTO_CR0 \
11375 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11376 +
11377 +#define GET_CR3_INTO_RDI \
11378 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11379 + mov %rax,%rdi
11380 +
11381 +#define SET_RDI_INTO_CR3 \
11382 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11383 +
11384 #endif /* CONFIG_X86_32 */
11385
11386 #endif /* __ASSEMBLY__ */
11387 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11388 index 142236e..6a6b4a6 100644
11389 --- a/arch/x86/include/asm/paravirt_types.h
11390 +++ b/arch/x86/include/asm/paravirt_types.h
11391 @@ -84,20 +84,20 @@ struct pv_init_ops {
11392 */
11393 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11394 unsigned long addr, unsigned len);
11395 -};
11396 +} __no_const;
11397
11398
11399 struct pv_lazy_ops {
11400 /* Set deferred update mode, used for batching operations. */
11401 void (*enter)(void);
11402 void (*leave)(void);
11403 -};
11404 +} __no_const;
11405
11406 struct pv_time_ops {
11407 unsigned long long (*sched_clock)(void);
11408 unsigned long long (*steal_clock)(int cpu);
11409 unsigned long (*get_tsc_khz)(void);
11410 -};
11411 +} __no_const;
11412
11413 struct pv_cpu_ops {
11414 /* hooks for various privileged instructions */
11415 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11416
11417 void (*start_context_switch)(struct task_struct *prev);
11418 void (*end_context_switch)(struct task_struct *next);
11419 -};
11420 +} __no_const;
11421
11422 struct pv_irq_ops {
11423 /*
11424 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11425 unsigned long start_eip,
11426 unsigned long start_esp);
11427 #endif
11428 -};
11429 +} __no_const;
11430
11431 struct pv_mmu_ops {
11432 unsigned long (*read_cr2)(void);
11433 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11434 struct paravirt_callee_save make_pud;
11435
11436 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11437 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11438 #endif /* PAGETABLE_LEVELS == 4 */
11439 #endif /* PAGETABLE_LEVELS >= 3 */
11440
11441 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11442 an mfn. We can tell which is which from the index. */
11443 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11444 phys_addr_t phys, pgprot_t flags);
11445 +
11446 +#ifdef CONFIG_PAX_KERNEXEC
11447 + unsigned long (*pax_open_kernel)(void);
11448 + unsigned long (*pax_close_kernel)(void);
11449 +#endif
11450 +
11451 };
11452
11453 struct arch_spinlock;
11454 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11455 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11456 int (*spin_trylock)(struct arch_spinlock *lock);
11457 void (*spin_unlock)(struct arch_spinlock *lock);
11458 -};
11459 +} __no_const;
11460
11461 /* This contains all the paravirt structures: we get a convenient
11462 * number for each function using the offset which we use to indicate
11463 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11464 index b4389a4..7024269 100644
11465 --- a/arch/x86/include/asm/pgalloc.h
11466 +++ b/arch/x86/include/asm/pgalloc.h
11467 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11468 pmd_t *pmd, pte_t *pte)
11469 {
11470 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11471 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11472 +}
11473 +
11474 +static inline void pmd_populate_user(struct mm_struct *mm,
11475 + pmd_t *pmd, pte_t *pte)
11476 +{
11477 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11478 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11479 }
11480
11481 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11482
11483 #ifdef CONFIG_X86_PAE
11484 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11485 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11486 +{
11487 + pud_populate(mm, pudp, pmd);
11488 +}
11489 #else /* !CONFIG_X86_PAE */
11490 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11491 {
11492 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11493 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11494 }
11495 +
11496 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11497 +{
11498 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11499 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11500 +}
11501 #endif /* CONFIG_X86_PAE */
11502
11503 #if PAGETABLE_LEVELS > 3
11504 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11505 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11506 }
11507
11508 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11509 +{
11510 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11511 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11512 +}
11513 +
11514 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11515 {
11516 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11517 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11518 index f2b489c..4f7e2e5 100644
11519 --- a/arch/x86/include/asm/pgtable-2level.h
11520 +++ b/arch/x86/include/asm/pgtable-2level.h
11521 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11522
11523 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11524 {
11525 + pax_open_kernel();
11526 *pmdp = pmd;
11527 + pax_close_kernel();
11528 }
11529
11530 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11531 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11532 index 4cc9f2b..5fd9226 100644
11533 --- a/arch/x86/include/asm/pgtable-3level.h
11534 +++ b/arch/x86/include/asm/pgtable-3level.h
11535 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11536
11537 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11538 {
11539 + pax_open_kernel();
11540 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11541 + pax_close_kernel();
11542 }
11543
11544 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11545 {
11546 + pax_open_kernel();
11547 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11548 + pax_close_kernel();
11549 }
11550
11551 /*
11552 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11553 index a1f780d..5f38ced4 100644
11554 --- a/arch/x86/include/asm/pgtable.h
11555 +++ b/arch/x86/include/asm/pgtable.h
11556 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11557
11558 #ifndef __PAGETABLE_PUD_FOLDED
11559 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11560 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11561 #define pgd_clear(pgd) native_pgd_clear(pgd)
11562 #endif
11563
11564 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11565
11566 #define arch_end_context_switch(prev) do {} while(0)
11567
11568 +#define pax_open_kernel() native_pax_open_kernel()
11569 +#define pax_close_kernel() native_pax_close_kernel()
11570 #endif /* CONFIG_PARAVIRT */
11571
11572 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11573 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11574 +
11575 +#ifdef CONFIG_PAX_KERNEXEC
11576 +static inline unsigned long native_pax_open_kernel(void)
11577 +{
11578 + unsigned long cr0;
11579 +
11580 + preempt_disable();
11581 + barrier();
11582 + cr0 = read_cr0() ^ X86_CR0_WP;
11583 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11584 + write_cr0(cr0);
11585 + return cr0 ^ X86_CR0_WP;
11586 +}
11587 +
11588 +static inline unsigned long native_pax_close_kernel(void)
11589 +{
11590 + unsigned long cr0;
11591 +
11592 + cr0 = read_cr0() ^ X86_CR0_WP;
11593 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11594 + write_cr0(cr0);
11595 + barrier();
11596 + preempt_enable_no_resched();
11597 + return cr0 ^ X86_CR0_WP;
11598 +}
11599 +#else
11600 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11601 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11602 +#endif
11603 +
11604 /*
11605 * The following only work if pte_present() is true.
11606 * Undefined behaviour if not..
11607 */
11608 +static inline int pte_user(pte_t pte)
11609 +{
11610 + return pte_val(pte) & _PAGE_USER;
11611 +}
11612 +
11613 static inline int pte_dirty(pte_t pte)
11614 {
11615 return pte_flags(pte) & _PAGE_DIRTY;
11616 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11617 return pte_clear_flags(pte, _PAGE_RW);
11618 }
11619
11620 +static inline pte_t pte_mkread(pte_t pte)
11621 +{
11622 + return __pte(pte_val(pte) | _PAGE_USER);
11623 +}
11624 +
11625 static inline pte_t pte_mkexec(pte_t pte)
11626 {
11627 - return pte_clear_flags(pte, _PAGE_NX);
11628 +#ifdef CONFIG_X86_PAE
11629 + if (__supported_pte_mask & _PAGE_NX)
11630 + return pte_clear_flags(pte, _PAGE_NX);
11631 + else
11632 +#endif
11633 + return pte_set_flags(pte, _PAGE_USER);
11634 +}
11635 +
11636 +static inline pte_t pte_exprotect(pte_t pte)
11637 +{
11638 +#ifdef CONFIG_X86_PAE
11639 + if (__supported_pte_mask & _PAGE_NX)
11640 + return pte_set_flags(pte, _PAGE_NX);
11641 + else
11642 +#endif
11643 + return pte_clear_flags(pte, _PAGE_USER);
11644 }
11645
11646 static inline pte_t pte_mkdirty(pte_t pte)
11647 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11648 #endif
11649
11650 #ifndef __ASSEMBLY__
11651 +
11652 +#ifdef CONFIG_PAX_PER_CPU_PGD
11653 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11654 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11655 +{
11656 + return cpu_pgd[cpu];
11657 +}
11658 +#endif
11659 +
11660 #include <linux/mm_types.h>
11661
11662 static inline int pte_none(pte_t pte)
11663 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11664
11665 static inline int pgd_bad(pgd_t pgd)
11666 {
11667 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11668 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11669 }
11670
11671 static inline int pgd_none(pgd_t pgd)
11672 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11673 * pgd_offset() returns a (pgd_t *)
11674 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11675 */
11676 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11677 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11678 +
11679 +#ifdef CONFIG_PAX_PER_CPU_PGD
11680 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11681 +#endif
11682 +
11683 /*
11684 * a shortcut which implies the use of the kernel's pgd, instead
11685 * of a process's
11686 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11687 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11688 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11689
11690 +#ifdef CONFIG_X86_32
11691 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11692 +#else
11693 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11694 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11695 +
11696 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11697 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11698 +#else
11699 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11700 +#endif
11701 +
11702 +#endif
11703 +
11704 #ifndef __ASSEMBLY__
11705
11706 extern int direct_gbpages;
11707 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11708 * dst and src can be on the same page, but the range must not overlap,
11709 * and must not cross a page boundary.
11710 */
11711 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11712 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11713 {
11714 - memcpy(dst, src, count * sizeof(pgd_t));
11715 + pax_open_kernel();
11716 + while (count--)
11717 + *dst++ = *src++;
11718 + pax_close_kernel();
11719 }
11720
11721 +#ifdef CONFIG_PAX_PER_CPU_PGD
11722 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11723 +#endif
11724 +
11725 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11726 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11727 +#else
11728 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11729 +#endif
11730
11731 #include <asm-generic/pgtable.h>
11732 #endif /* __ASSEMBLY__ */
11733 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11734 index 8faa215..a8a17ea 100644
11735 --- a/arch/x86/include/asm/pgtable_32.h
11736 +++ b/arch/x86/include/asm/pgtable_32.h
11737 @@ -25,9 +25,6 @@
11738 struct mm_struct;
11739 struct vm_area_struct;
11740
11741 -extern pgd_t swapper_pg_dir[1024];
11742 -extern pgd_t initial_page_table[1024];
11743 -
11744 static inline void pgtable_cache_init(void) { }
11745 static inline void check_pgt_cache(void) { }
11746 void paging_init(void);
11747 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11748 # include <asm/pgtable-2level.h>
11749 #endif
11750
11751 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11752 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11753 +#ifdef CONFIG_X86_PAE
11754 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11755 +#endif
11756 +
11757 #if defined(CONFIG_HIGHPTE)
11758 #define pte_offset_map(dir, address) \
11759 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11760 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11761 /* Clear a kernel PTE and flush it from the TLB */
11762 #define kpte_clear_flush(ptep, vaddr) \
11763 do { \
11764 + pax_open_kernel(); \
11765 pte_clear(&init_mm, (vaddr), (ptep)); \
11766 + pax_close_kernel(); \
11767 __flush_tlb_one((vaddr)); \
11768 } while (0)
11769
11770 @@ -75,6 +80,9 @@ do { \
11771
11772 #endif /* !__ASSEMBLY__ */
11773
11774 +#define HAVE_ARCH_UNMAPPED_AREA
11775 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11776 +
11777 /*
11778 * kern_addr_valid() is (1) for FLATMEM and (0) for
11779 * SPARSEMEM and DISCONTIGMEM
11780 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11781 index ed5903b..c7fe163 100644
11782 --- a/arch/x86/include/asm/pgtable_32_types.h
11783 +++ b/arch/x86/include/asm/pgtable_32_types.h
11784 @@ -8,7 +8,7 @@
11785 */
11786 #ifdef CONFIG_X86_PAE
11787 # include <asm/pgtable-3level_types.h>
11788 -# define PMD_SIZE (1UL << PMD_SHIFT)
11789 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11790 # define PMD_MASK (~(PMD_SIZE - 1))
11791 #else
11792 # include <asm/pgtable-2level_types.h>
11793 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11794 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11795 #endif
11796
11797 +#ifdef CONFIG_PAX_KERNEXEC
11798 +#ifndef __ASSEMBLY__
11799 +extern unsigned char MODULES_EXEC_VADDR[];
11800 +extern unsigned char MODULES_EXEC_END[];
11801 +#endif
11802 +#include <asm/boot.h>
11803 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11804 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11805 +#else
11806 +#define ktla_ktva(addr) (addr)
11807 +#define ktva_ktla(addr) (addr)
11808 +#endif
11809 +
11810 #define MODULES_VADDR VMALLOC_START
11811 #define MODULES_END VMALLOC_END
11812 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11813 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11814 index 47356f9..deb94a2 100644
11815 --- a/arch/x86/include/asm/pgtable_64.h
11816 +++ b/arch/x86/include/asm/pgtable_64.h
11817 @@ -16,10 +16,14 @@
11818
11819 extern pud_t level3_kernel_pgt[512];
11820 extern pud_t level3_ident_pgt[512];
11821 +extern pud_t level3_vmalloc_start_pgt[512];
11822 +extern pud_t level3_vmalloc_end_pgt[512];
11823 +extern pud_t level3_vmemmap_pgt[512];
11824 +extern pud_t level2_vmemmap_pgt[512];
11825 extern pmd_t level2_kernel_pgt[512];
11826 extern pmd_t level2_fixmap_pgt[512];
11827 -extern pmd_t level2_ident_pgt[512];
11828 -extern pgd_t init_level4_pgt[];
11829 +extern pmd_t level2_ident_pgt[512*2];
11830 +extern pgd_t init_level4_pgt[512];
11831
11832 #define swapper_pg_dir init_level4_pgt
11833
11834 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11835
11836 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11837 {
11838 + pax_open_kernel();
11839 *pmdp = pmd;
11840 + pax_close_kernel();
11841 }
11842
11843 static inline void native_pmd_clear(pmd_t *pmd)
11844 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11845
11846 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11847 {
11848 + pax_open_kernel();
11849 *pudp = pud;
11850 + pax_close_kernel();
11851 }
11852
11853 static inline void native_pud_clear(pud_t *pud)
11854 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11855
11856 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11857 {
11858 + pax_open_kernel();
11859 + *pgdp = pgd;
11860 + pax_close_kernel();
11861 +}
11862 +
11863 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11864 +{
11865 *pgdp = pgd;
11866 }
11867
11868 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11869 index 766ea16..5b96cb3 100644
11870 --- a/arch/x86/include/asm/pgtable_64_types.h
11871 +++ b/arch/x86/include/asm/pgtable_64_types.h
11872 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11873 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11874 #define MODULES_END _AC(0xffffffffff000000, UL)
11875 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11876 +#define MODULES_EXEC_VADDR MODULES_VADDR
11877 +#define MODULES_EXEC_END MODULES_END
11878 +
11879 +#define ktla_ktva(addr) (addr)
11880 +#define ktva_ktla(addr) (addr)
11881
11882 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11883 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11884 index ec8a1fc..7ccb593 100644
11885 --- a/arch/x86/include/asm/pgtable_types.h
11886 +++ b/arch/x86/include/asm/pgtable_types.h
11887 @@ -16,13 +16,12 @@
11888 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11889 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11890 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11891 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11892 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11893 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11894 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11895 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11896 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11897 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11898 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11899 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11900 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11901 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11902
11903 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11904 @@ -40,7 +39,6 @@
11905 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11906 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11907 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11908 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11909 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11910 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11911 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11912 @@ -57,8 +55,10 @@
11913
11914 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11915 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11916 -#else
11917 +#elif defined(CONFIG_KMEMCHECK)
11918 #define _PAGE_NX (_AT(pteval_t, 0))
11919 +#else
11920 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11921 #endif
11922
11923 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11924 @@ -96,6 +96,9 @@
11925 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11926 _PAGE_ACCESSED)
11927
11928 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11929 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11930 +
11931 #define __PAGE_KERNEL_EXEC \
11932 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11933 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11934 @@ -106,7 +109,7 @@
11935 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11936 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11937 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11938 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11939 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11940 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11941 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11942 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11943 @@ -168,8 +171,8 @@
11944 * bits are combined, this will alow user to access the high address mapped
11945 * VDSO in the presence of CONFIG_COMPAT_VDSO
11946 */
11947 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11948 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11949 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11950 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11951 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11952 #endif
11953
11954 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11955 {
11956 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11957 }
11958 +#endif
11959
11960 +#if PAGETABLE_LEVELS == 3
11961 +#include <asm-generic/pgtable-nopud.h>
11962 +#endif
11963 +
11964 +#if PAGETABLE_LEVELS == 2
11965 +#include <asm-generic/pgtable-nopmd.h>
11966 +#endif
11967 +
11968 +#ifndef __ASSEMBLY__
11969 #if PAGETABLE_LEVELS > 3
11970 typedef struct { pudval_t pud; } pud_t;
11971
11972 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11973 return pud.pud;
11974 }
11975 #else
11976 -#include <asm-generic/pgtable-nopud.h>
11977 -
11978 static inline pudval_t native_pud_val(pud_t pud)
11979 {
11980 return native_pgd_val(pud.pgd);
11981 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11982 return pmd.pmd;
11983 }
11984 #else
11985 -#include <asm-generic/pgtable-nopmd.h>
11986 -
11987 static inline pmdval_t native_pmd_val(pmd_t pmd)
11988 {
11989 return native_pgd_val(pmd.pud.pgd);
11990 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11991
11992 extern pteval_t __supported_pte_mask;
11993 extern void set_nx(void);
11994 -extern int nx_enabled;
11995
11996 #define pgprot_writecombine pgprot_writecombine
11997 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11998 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11999 index ad1fc85..0b15fe1 100644
12000 --- a/arch/x86/include/asm/processor.h
12001 +++ b/arch/x86/include/asm/processor.h
12002 @@ -289,7 +289,7 @@ struct tss_struct {
12003
12004 } ____cacheline_aligned;
12005
12006 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
12007 +extern struct tss_struct init_tss[NR_CPUS];
12008
12009 /*
12010 * Save the original ist values for checking stack pointers during debugging
12011 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
12012 */
12013 #define TASK_SIZE PAGE_OFFSET
12014 #define TASK_SIZE_MAX TASK_SIZE
12015 +
12016 +#ifdef CONFIG_PAX_SEGMEXEC
12017 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
12018 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
12019 +#else
12020 #define STACK_TOP TASK_SIZE
12021 -#define STACK_TOP_MAX STACK_TOP
12022 +#endif
12023 +
12024 +#define STACK_TOP_MAX TASK_SIZE
12025
12026 #define INIT_THREAD { \
12027 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
12028 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12029 .vm86_info = NULL, \
12030 .sysenter_cs = __KERNEL_CS, \
12031 .io_bitmap_ptr = NULL, \
12032 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
12033 */
12034 #define INIT_TSS { \
12035 .x86_tss = { \
12036 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
12037 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12038 .ss0 = __KERNEL_DS, \
12039 .ss1 = __KERNEL_CS, \
12040 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
12041 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
12042 extern unsigned long thread_saved_pc(struct task_struct *tsk);
12043
12044 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
12045 -#define KSTK_TOP(info) \
12046 -({ \
12047 - unsigned long *__ptr = (unsigned long *)(info); \
12048 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
12049 -})
12050 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
12051
12052 /*
12053 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
12054 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12055 #define task_pt_regs(task) \
12056 ({ \
12057 struct pt_regs *__regs__; \
12058 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
12059 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
12060 __regs__ - 1; \
12061 })
12062
12063 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12064 /*
12065 * User space process size. 47bits minus one guard page.
12066 */
12067 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
12068 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
12069
12070 /* This decides where the kernel will search for a free chunk of vm
12071 * space during mmap's.
12072 */
12073 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
12074 - 0xc0000000 : 0xFFFFe000)
12075 + 0xc0000000 : 0xFFFFf000)
12076
12077 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
12078 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
12079 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
12080 #define STACK_TOP_MAX TASK_SIZE_MAX
12081
12082 #define INIT_THREAD { \
12083 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12084 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12085 }
12086
12087 #define INIT_TSS { \
12088 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12089 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12090 }
12091
12092 /*
12093 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12094 */
12095 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12096
12097 +#ifdef CONFIG_PAX_SEGMEXEC
12098 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12099 +#endif
12100 +
12101 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12102
12103 /* Get/set a process' ability to use the timestamp counter instruction */
12104 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
12105 #define cpu_has_amd_erratum(x) (false)
12106 #endif /* CONFIG_CPU_SUP_AMD */
12107
12108 -extern unsigned long arch_align_stack(unsigned long sp);
12109 +#define arch_align_stack(x) ((x) & ~0xfUL)
12110 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12111
12112 void default_idle(void);
12113 bool set_pm_idle_to_default(void);
12114
12115 -void stop_this_cpu(void *dummy);
12116 +void stop_this_cpu(void *dummy) __noreturn;
12117
12118 #endif /* _ASM_X86_PROCESSOR_H */
12119 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12120 index 19f16eb..b50624b 100644
12121 --- a/arch/x86/include/asm/ptrace.h
12122 +++ b/arch/x86/include/asm/ptrace.h
12123 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12124 }
12125
12126 /*
12127 - * user_mode_vm(regs) determines whether a register set came from user mode.
12128 + * user_mode(regs) determines whether a register set came from user mode.
12129 * This is true if V8086 mode was enabled OR if the register set was from
12130 * protected mode with RPL-3 CS value. This tricky test checks that with
12131 * one comparison. Many places in the kernel can bypass this full check
12132 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12133 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12134 + * be used.
12135 */
12136 -static inline int user_mode(struct pt_regs *regs)
12137 +static inline int user_mode_novm(struct pt_regs *regs)
12138 {
12139 #ifdef CONFIG_X86_32
12140 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12141 #else
12142 - return !!(regs->cs & 3);
12143 + return !!(regs->cs & SEGMENT_RPL_MASK);
12144 #endif
12145 }
12146
12147 -static inline int user_mode_vm(struct pt_regs *regs)
12148 +static inline int user_mode(struct pt_regs *regs)
12149 {
12150 #ifdef CONFIG_X86_32
12151 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12152 USER_RPL;
12153 #else
12154 - return user_mode(regs);
12155 + return user_mode_novm(regs);
12156 #endif
12157 }
12158
12159 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12160 #ifdef CONFIG_X86_64
12161 static inline bool user_64bit_mode(struct pt_regs *regs)
12162 {
12163 + unsigned long cs = regs->cs & 0xffff;
12164 #ifndef CONFIG_PARAVIRT
12165 /*
12166 * On non-paravirt systems, this is the only long mode CPL 3
12167 * selector. We do not allow long mode selectors in the LDT.
12168 */
12169 - return regs->cs == __USER_CS;
12170 + return cs == __USER_CS;
12171 #else
12172 /* Headers are too twisted for this to go in paravirt.h. */
12173 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12174 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12175 #endif
12176 }
12177 #endif
12178 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12179 index fe1ec5b..dc5c3fe 100644
12180 --- a/arch/x86/include/asm/realmode.h
12181 +++ b/arch/x86/include/asm/realmode.h
12182 @@ -22,16 +22,14 @@ struct real_mode_header {
12183 #endif
12184 /* APM/BIOS reboot */
12185 u32 machine_real_restart_asm;
12186 -#ifdef CONFIG_X86_64
12187 u32 machine_real_restart_seg;
12188 -#endif
12189 };
12190
12191 /* This must match data at trampoline_32/64.S */
12192 struct trampoline_header {
12193 #ifdef CONFIG_X86_32
12194 u32 start;
12195 - u16 gdt_pad;
12196 + u16 boot_cs;
12197 u16 gdt_limit;
12198 u32 gdt_base;
12199 #else
12200 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12201 index a82c4f1..ac45053 100644
12202 --- a/arch/x86/include/asm/reboot.h
12203 +++ b/arch/x86/include/asm/reboot.h
12204 @@ -6,13 +6,13 @@
12205 struct pt_regs;
12206
12207 struct machine_ops {
12208 - void (*restart)(char *cmd);
12209 - void (*halt)(void);
12210 - void (*power_off)(void);
12211 + void (* __noreturn restart)(char *cmd);
12212 + void (* __noreturn halt)(void);
12213 + void (* __noreturn power_off)(void);
12214 void (*shutdown)(void);
12215 void (*crash_shutdown)(struct pt_regs *);
12216 - void (*emergency_restart)(void);
12217 -};
12218 + void (* __noreturn emergency_restart)(void);
12219 +} __no_const;
12220
12221 extern struct machine_ops machine_ops;
12222
12223 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12224 index 2dbe4a7..ce1db00 100644
12225 --- a/arch/x86/include/asm/rwsem.h
12226 +++ b/arch/x86/include/asm/rwsem.h
12227 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12228 {
12229 asm volatile("# beginning down_read\n\t"
12230 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12231 +
12232 +#ifdef CONFIG_PAX_REFCOUNT
12233 + "jno 0f\n"
12234 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12235 + "int $4\n0:\n"
12236 + _ASM_EXTABLE(0b, 0b)
12237 +#endif
12238 +
12239 /* adds 0x00000001 */
12240 " jns 1f\n"
12241 " call call_rwsem_down_read_failed\n"
12242 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12243 "1:\n\t"
12244 " mov %1,%2\n\t"
12245 " add %3,%2\n\t"
12246 +
12247 +#ifdef CONFIG_PAX_REFCOUNT
12248 + "jno 0f\n"
12249 + "sub %3,%2\n"
12250 + "int $4\n0:\n"
12251 + _ASM_EXTABLE(0b, 0b)
12252 +#endif
12253 +
12254 " jle 2f\n\t"
12255 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12256 " jnz 1b\n\t"
12257 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12258 long tmp;
12259 asm volatile("# beginning down_write\n\t"
12260 LOCK_PREFIX " xadd %1,(%2)\n\t"
12261 +
12262 +#ifdef CONFIG_PAX_REFCOUNT
12263 + "jno 0f\n"
12264 + "mov %1,(%2)\n"
12265 + "int $4\n0:\n"
12266 + _ASM_EXTABLE(0b, 0b)
12267 +#endif
12268 +
12269 /* adds 0xffff0001, returns the old value */
12270 " test %1,%1\n\t"
12271 /* was the count 0 before? */
12272 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12273 long tmp;
12274 asm volatile("# beginning __up_read\n\t"
12275 LOCK_PREFIX " xadd %1,(%2)\n\t"
12276 +
12277 +#ifdef CONFIG_PAX_REFCOUNT
12278 + "jno 0f\n"
12279 + "mov %1,(%2)\n"
12280 + "int $4\n0:\n"
12281 + _ASM_EXTABLE(0b, 0b)
12282 +#endif
12283 +
12284 /* subtracts 1, returns the old value */
12285 " jns 1f\n\t"
12286 " call call_rwsem_wake\n" /* expects old value in %edx */
12287 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12288 long tmp;
12289 asm volatile("# beginning __up_write\n\t"
12290 LOCK_PREFIX " xadd %1,(%2)\n\t"
12291 +
12292 +#ifdef CONFIG_PAX_REFCOUNT
12293 + "jno 0f\n"
12294 + "mov %1,(%2)\n"
12295 + "int $4\n0:\n"
12296 + _ASM_EXTABLE(0b, 0b)
12297 +#endif
12298 +
12299 /* subtracts 0xffff0001, returns the old value */
12300 " jns 1f\n\t"
12301 " call call_rwsem_wake\n" /* expects old value in %edx */
12302 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12303 {
12304 asm volatile("# beginning __downgrade_write\n\t"
12305 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12306 +
12307 +#ifdef CONFIG_PAX_REFCOUNT
12308 + "jno 0f\n"
12309 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12310 + "int $4\n0:\n"
12311 + _ASM_EXTABLE(0b, 0b)
12312 +#endif
12313 +
12314 /*
12315 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12316 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12317 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12318 */
12319 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12320 {
12321 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12322 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12323 +
12324 +#ifdef CONFIG_PAX_REFCOUNT
12325 + "jno 0f\n"
12326 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12327 + "int $4\n0:\n"
12328 + _ASM_EXTABLE(0b, 0b)
12329 +#endif
12330 +
12331 : "+m" (sem->count)
12332 : "er" (delta));
12333 }
12334 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12335 */
12336 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12337 {
12338 - return delta + xadd(&sem->count, delta);
12339 + return delta + xadd_check_overflow(&sem->count, delta);
12340 }
12341
12342 #endif /* __KERNEL__ */
12343 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12344 index c48a950..c6d7468 100644
12345 --- a/arch/x86/include/asm/segment.h
12346 +++ b/arch/x86/include/asm/segment.h
12347 @@ -64,10 +64,15 @@
12348 * 26 - ESPFIX small SS
12349 * 27 - per-cpu [ offset to per-cpu data area ]
12350 * 28 - stack_canary-20 [ for stack protector ]
12351 - * 29 - unused
12352 - * 30 - unused
12353 + * 29 - PCI BIOS CS
12354 + * 30 - PCI BIOS DS
12355 * 31 - TSS for double fault handler
12356 */
12357 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12358 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12359 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12360 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12361 +
12362 #define GDT_ENTRY_TLS_MIN 6
12363 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12364
12365 @@ -79,6 +84,8 @@
12366
12367 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12368
12369 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12370 +
12371 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12372
12373 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12374 @@ -104,6 +111,12 @@
12375 #define __KERNEL_STACK_CANARY 0
12376 #endif
12377
12378 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12379 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12380 +
12381 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12382 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12383 +
12384 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12385
12386 /*
12387 @@ -141,7 +154,7 @@
12388 */
12389
12390 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12391 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12392 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12393
12394
12395 #else
12396 @@ -165,6 +178,8 @@
12397 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12398 #define __USER32_DS __USER_DS
12399
12400 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12401 +
12402 #define GDT_ENTRY_TSS 8 /* needs two entries */
12403 #define GDT_ENTRY_LDT 10 /* needs two entries */
12404 #define GDT_ENTRY_TLS_MIN 12
12405 @@ -185,6 +200,7 @@
12406 #endif
12407
12408 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12409 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12410 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12411 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12412 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12413 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12414 {
12415 unsigned long __limit;
12416 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12417 - return __limit + 1;
12418 + return __limit;
12419 }
12420
12421 #endif /* !__ASSEMBLY__ */
12422 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12423 index 4f19a15..9e14f27 100644
12424 --- a/arch/x86/include/asm/smp.h
12425 +++ b/arch/x86/include/asm/smp.h
12426 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12427 /* cpus sharing the last level cache: */
12428 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12429 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12430 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12431 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12432
12433 static inline struct cpumask *cpu_sibling_mask(int cpu)
12434 {
12435 @@ -79,7 +79,7 @@ struct smp_ops {
12436
12437 void (*send_call_func_ipi)(const struct cpumask *mask);
12438 void (*send_call_func_single_ipi)(int cpu);
12439 -};
12440 +} __no_const;
12441
12442 /* Globals due to paravirt */
12443 extern void set_cpu_sibling_map(int cpu);
12444 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12445 extern int safe_smp_processor_id(void);
12446
12447 #elif defined(CONFIG_X86_64_SMP)
12448 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12449 -
12450 -#define stack_smp_processor_id() \
12451 -({ \
12452 - struct thread_info *ti; \
12453 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12454 - ti->cpu; \
12455 -})
12456 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12457 +#define stack_smp_processor_id() raw_smp_processor_id()
12458 #define safe_smp_processor_id() smp_processor_id()
12459
12460 #endif
12461 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12462 index 33692ea..350a534 100644
12463 --- a/arch/x86/include/asm/spinlock.h
12464 +++ b/arch/x86/include/asm/spinlock.h
12465 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12466 static inline void arch_read_lock(arch_rwlock_t *rw)
12467 {
12468 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12469 +
12470 +#ifdef CONFIG_PAX_REFCOUNT
12471 + "jno 0f\n"
12472 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12473 + "int $4\n0:\n"
12474 + _ASM_EXTABLE(0b, 0b)
12475 +#endif
12476 +
12477 "jns 1f\n"
12478 "call __read_lock_failed\n\t"
12479 "1:\n"
12480 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12481 static inline void arch_write_lock(arch_rwlock_t *rw)
12482 {
12483 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12484 +
12485 +#ifdef CONFIG_PAX_REFCOUNT
12486 + "jno 0f\n"
12487 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12488 + "int $4\n0:\n"
12489 + _ASM_EXTABLE(0b, 0b)
12490 +#endif
12491 +
12492 "jz 1f\n"
12493 "call __write_lock_failed\n\t"
12494 "1:\n"
12495 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12496
12497 static inline void arch_read_unlock(arch_rwlock_t *rw)
12498 {
12499 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12500 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12501 +
12502 +#ifdef CONFIG_PAX_REFCOUNT
12503 + "jno 0f\n"
12504 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12505 + "int $4\n0:\n"
12506 + _ASM_EXTABLE(0b, 0b)
12507 +#endif
12508 +
12509 :"+m" (rw->lock) : : "memory");
12510 }
12511
12512 static inline void arch_write_unlock(arch_rwlock_t *rw)
12513 {
12514 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12515 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12516 +
12517 +#ifdef CONFIG_PAX_REFCOUNT
12518 + "jno 0f\n"
12519 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12520 + "int $4\n0:\n"
12521 + _ASM_EXTABLE(0b, 0b)
12522 +#endif
12523 +
12524 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12525 }
12526
12527 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12528 index 6a99859..03cb807 100644
12529 --- a/arch/x86/include/asm/stackprotector.h
12530 +++ b/arch/x86/include/asm/stackprotector.h
12531 @@ -47,7 +47,7 @@
12532 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12533 */
12534 #define GDT_STACK_CANARY_INIT \
12535 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12536 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12537
12538 /*
12539 * Initialize the stackprotector canary value.
12540 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12541
12542 static inline void load_stack_canary_segment(void)
12543 {
12544 -#ifdef CONFIG_X86_32
12545 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12546 asm volatile ("mov %0, %%gs" : : "r" (0));
12547 #endif
12548 }
12549 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12550 index 70bbe39..4ae2bd4 100644
12551 --- a/arch/x86/include/asm/stacktrace.h
12552 +++ b/arch/x86/include/asm/stacktrace.h
12553 @@ -11,28 +11,20 @@
12554
12555 extern int kstack_depth_to_print;
12556
12557 -struct thread_info;
12558 +struct task_struct;
12559 struct stacktrace_ops;
12560
12561 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12562 - unsigned long *stack,
12563 - unsigned long bp,
12564 - const struct stacktrace_ops *ops,
12565 - void *data,
12566 - unsigned long *end,
12567 - int *graph);
12568 +typedef unsigned long walk_stack_t(struct task_struct *task,
12569 + void *stack_start,
12570 + unsigned long *stack,
12571 + unsigned long bp,
12572 + const struct stacktrace_ops *ops,
12573 + void *data,
12574 + unsigned long *end,
12575 + int *graph);
12576
12577 -extern unsigned long
12578 -print_context_stack(struct thread_info *tinfo,
12579 - unsigned long *stack, unsigned long bp,
12580 - const struct stacktrace_ops *ops, void *data,
12581 - unsigned long *end, int *graph);
12582 -
12583 -extern unsigned long
12584 -print_context_stack_bp(struct thread_info *tinfo,
12585 - unsigned long *stack, unsigned long bp,
12586 - const struct stacktrace_ops *ops, void *data,
12587 - unsigned long *end, int *graph);
12588 +extern walk_stack_t print_context_stack;
12589 +extern walk_stack_t print_context_stack_bp;
12590
12591 /* Generic stack tracer with callbacks */
12592
12593 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12594 void (*address)(void *data, unsigned long address, int reliable);
12595 /* On negative return stop dumping */
12596 int (*stack)(void *data, char *name);
12597 - walk_stack_t walk_stack;
12598 + walk_stack_t *walk_stack;
12599 };
12600
12601 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12602 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12603 index 4ec45b3..a4f0a8a 100644
12604 --- a/arch/x86/include/asm/switch_to.h
12605 +++ b/arch/x86/include/asm/switch_to.h
12606 @@ -108,7 +108,7 @@ do { \
12607 "call __switch_to\n\t" \
12608 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12609 __switch_canary \
12610 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12611 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12612 "movq %%rax,%%rdi\n\t" \
12613 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12614 "jnz ret_from_fork\n\t" \
12615 @@ -119,7 +119,7 @@ do { \
12616 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12617 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12618 [_tif_fork] "i" (_TIF_FORK), \
12619 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12620 + [thread_info] "m" (current_tinfo), \
12621 [current_task] "m" (current_task) \
12622 __switch_canary_iparam \
12623 : "memory", "cc" __EXTRA_CLOBBER)
12624 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12625 index 2d946e6..e453ec4 100644
12626 --- a/arch/x86/include/asm/thread_info.h
12627 +++ b/arch/x86/include/asm/thread_info.h
12628 @@ -10,6 +10,7 @@
12629 #include <linux/compiler.h>
12630 #include <asm/page.h>
12631 #include <asm/types.h>
12632 +#include <asm/percpu.h>
12633
12634 /*
12635 * low level task data that entry.S needs immediate access to
12636 @@ -24,7 +25,6 @@ struct exec_domain;
12637 #include <linux/atomic.h>
12638
12639 struct thread_info {
12640 - struct task_struct *task; /* main task structure */
12641 struct exec_domain *exec_domain; /* execution domain */
12642 __u32 flags; /* low level flags */
12643 __u32 status; /* thread synchronous flags */
12644 @@ -34,19 +34,13 @@ struct thread_info {
12645 mm_segment_t addr_limit;
12646 struct restart_block restart_block;
12647 void __user *sysenter_return;
12648 -#ifdef CONFIG_X86_32
12649 - unsigned long previous_esp; /* ESP of the previous stack in
12650 - case of nested (IRQ) stacks
12651 - */
12652 - __u8 supervisor_stack[0];
12653 -#endif
12654 + unsigned long lowest_stack;
12655 unsigned int sig_on_uaccess_error:1;
12656 unsigned int uaccess_err:1; /* uaccess failed */
12657 };
12658
12659 -#define INIT_THREAD_INFO(tsk) \
12660 +#define INIT_THREAD_INFO \
12661 { \
12662 - .task = &tsk, \
12663 .exec_domain = &default_exec_domain, \
12664 .flags = 0, \
12665 .cpu = 0, \
12666 @@ -57,7 +51,7 @@ struct thread_info {
12667 }, \
12668 }
12669
12670 -#define init_thread_info (init_thread_union.thread_info)
12671 +#define init_thread_info (init_thread_union.stack)
12672 #define init_stack (init_thread_union.stack)
12673
12674 #else /* !__ASSEMBLY__ */
12675 @@ -98,6 +92,7 @@ struct thread_info {
12676 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12677 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12678 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12679 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12680
12681 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12682 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12683 @@ -122,17 +117,18 @@ struct thread_info {
12684 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12685 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12686 #define _TIF_X32 (1 << TIF_X32)
12687 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12688
12689 /* work to do in syscall_trace_enter() */
12690 #define _TIF_WORK_SYSCALL_ENTRY \
12691 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12692 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12693 - _TIF_NOHZ)
12694 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
12695
12696 /* work to do in syscall_trace_leave() */
12697 #define _TIF_WORK_SYSCALL_EXIT \
12698 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12699 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
12700 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
12701
12702 /* work to do on interrupt/exception return */
12703 #define _TIF_WORK_MASK \
12704 @@ -143,7 +139,7 @@ struct thread_info {
12705 /* work to do on any return to user space */
12706 #define _TIF_ALLWORK_MASK \
12707 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12708 - _TIF_NOHZ)
12709 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
12710
12711 /* Only used for 64 bit */
12712 #define _TIF_DO_NOTIFY_MASK \
12713 @@ -159,45 +155,40 @@ struct thread_info {
12714
12715 #define PREEMPT_ACTIVE 0x10000000
12716
12717 -#ifdef CONFIG_X86_32
12718 -
12719 -#define STACK_WARN (THREAD_SIZE/8)
12720 -/*
12721 - * macros/functions for gaining access to the thread information structure
12722 - *
12723 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12724 - */
12725 -#ifndef __ASSEMBLY__
12726 -
12727 -
12728 -/* how to get the current stack pointer from C */
12729 -register unsigned long current_stack_pointer asm("esp") __used;
12730 -
12731 -/* how to get the thread information struct from C */
12732 -static inline struct thread_info *current_thread_info(void)
12733 -{
12734 - return (struct thread_info *)
12735 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12736 -}
12737 -
12738 -#else /* !__ASSEMBLY__ */
12739 -
12740 +#ifdef __ASSEMBLY__
12741 /* how to get the thread information struct from ASM */
12742 #define GET_THREAD_INFO(reg) \
12743 - movl $-THREAD_SIZE, reg; \
12744 - andl %esp, reg
12745 + mov PER_CPU_VAR(current_tinfo), reg
12746
12747 /* use this one if reg already contains %esp */
12748 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12749 - andl $-THREAD_SIZE, reg
12750 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12751 +#else
12752 +/* how to get the thread information struct from C */
12753 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12754 +
12755 +static __always_inline struct thread_info *current_thread_info(void)
12756 +{
12757 + return this_cpu_read_stable(current_tinfo);
12758 +}
12759 +#endif
12760 +
12761 +#ifdef CONFIG_X86_32
12762 +
12763 +#define STACK_WARN (THREAD_SIZE/8)
12764 +/*
12765 + * macros/functions for gaining access to the thread information structure
12766 + *
12767 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12768 + */
12769 +#ifndef __ASSEMBLY__
12770 +
12771 +/* how to get the current stack pointer from C */
12772 +register unsigned long current_stack_pointer asm("esp") __used;
12773
12774 #endif
12775
12776 #else /* X86_32 */
12777
12778 -#include <asm/percpu.h>
12779 -#define KERNEL_STACK_OFFSET (5*8)
12780 -
12781 /*
12782 * macros/functions for gaining access to the thread information structure
12783 * preempt_count needs to be 1 initially, until the scheduler is functional.
12784 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12785 #ifndef __ASSEMBLY__
12786 DECLARE_PER_CPU(unsigned long, kernel_stack);
12787
12788 -static inline struct thread_info *current_thread_info(void)
12789 -{
12790 - struct thread_info *ti;
12791 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12792 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12793 - return ti;
12794 -}
12795 -
12796 -#else /* !__ASSEMBLY__ */
12797 -
12798 -/* how to get the thread information struct from ASM */
12799 -#define GET_THREAD_INFO(reg) \
12800 - movq PER_CPU_VAR(kernel_stack),reg ; \
12801 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12802 -
12803 -/*
12804 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12805 - * a certain register (to be used in assembler memory operands).
12806 - */
12807 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12808 -
12809 +/* how to get the current stack pointer from C */
12810 +register unsigned long current_stack_pointer asm("rsp") __used;
12811 #endif
12812
12813 #endif /* !X86_32 */
12814 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
12815 extern void arch_task_cache_init(void);
12816 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12817 extern void arch_release_task_struct(struct task_struct *tsk);
12818 +
12819 +#define __HAVE_THREAD_FUNCTIONS
12820 +#define task_thread_info(task) (&(task)->tinfo)
12821 +#define task_stack_page(task) ((task)->stack)
12822 +#define setup_thread_stack(p, org) do {} while (0)
12823 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12824 +
12825 #endif
12826 #endif /* _ASM_X86_THREAD_INFO_H */
12827 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12828 index 7ccf8d1..7cdca12 100644
12829 --- a/arch/x86/include/asm/uaccess.h
12830 +++ b/arch/x86/include/asm/uaccess.h
12831 @@ -7,6 +7,7 @@
12832 #include <linux/compiler.h>
12833 #include <linux/thread_info.h>
12834 #include <linux/string.h>
12835 +#include <linux/sched.h>
12836 #include <asm/asm.h>
12837 #include <asm/page.h>
12838 #include <asm/smap.h>
12839 @@ -14,6 +15,8 @@
12840 #define VERIFY_READ 0
12841 #define VERIFY_WRITE 1
12842
12843 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12844 +
12845 /*
12846 * The fs value determines whether argument validity checking should be
12847 * performed or not. If get_fs() == USER_DS, checking is performed, with
12848 @@ -29,7 +32,12 @@
12849
12850 #define get_ds() (KERNEL_DS)
12851 #define get_fs() (current_thread_info()->addr_limit)
12852 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12853 +void __set_fs(mm_segment_t x);
12854 +void set_fs(mm_segment_t x);
12855 +#else
12856 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12857 +#endif
12858
12859 #define segment_eq(a, b) ((a).seg == (b).seg)
12860
12861 @@ -77,8 +85,33 @@
12862 * checks that the pointer is in the user space range - after calling
12863 * this function, memory access functions may still return -EFAULT.
12864 */
12865 -#define access_ok(type, addr, size) \
12866 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12867 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12868 +#define access_ok(type, addr, size) \
12869 +({ \
12870 + long __size = size; \
12871 + unsigned long __addr = (unsigned long)addr; \
12872 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12873 + unsigned long __end_ao = __addr + __size - 1; \
12874 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12875 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12876 + while(__addr_ao <= __end_ao) { \
12877 + char __c_ao; \
12878 + __addr_ao += PAGE_SIZE; \
12879 + if (__size > PAGE_SIZE) \
12880 + cond_resched(); \
12881 + if (__get_user(__c_ao, (char __user *)__addr)) \
12882 + break; \
12883 + if (type != VERIFY_WRITE) { \
12884 + __addr = __addr_ao; \
12885 + continue; \
12886 + } \
12887 + if (__put_user(__c_ao, (char __user *)__addr)) \
12888 + break; \
12889 + __addr = __addr_ao; \
12890 + } \
12891 + } \
12892 + __ret_ao; \
12893 +})
12894
12895 /*
12896 * The exception table consists of pairs of addresses relative to the
12897 @@ -189,13 +222,21 @@ extern int __get_user_bad(void);
12898 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12899 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12900
12901 -
12902 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12903 +#define __copyuser_seg "gs;"
12904 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12905 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12906 +#else
12907 +#define __copyuser_seg
12908 +#define __COPYUSER_SET_ES
12909 +#define __COPYUSER_RESTORE_ES
12910 +#endif
12911
12912 #ifdef CONFIG_X86_32
12913 #define __put_user_asm_u64(x, addr, err, errret) \
12914 asm volatile(ASM_STAC "\n" \
12915 - "1: movl %%eax,0(%2)\n" \
12916 - "2: movl %%edx,4(%2)\n" \
12917 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12918 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12919 "3: " ASM_CLAC "\n" \
12920 ".section .fixup,\"ax\"\n" \
12921 "4: movl %3,%0\n" \
12922 @@ -208,8 +249,8 @@ extern int __get_user_bad(void);
12923
12924 #define __put_user_asm_ex_u64(x, addr) \
12925 asm volatile(ASM_STAC "\n" \
12926 - "1: movl %%eax,0(%1)\n" \
12927 - "2: movl %%edx,4(%1)\n" \
12928 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12929 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12930 "3: " ASM_CLAC "\n" \
12931 _ASM_EXTABLE_EX(1b, 2b) \
12932 _ASM_EXTABLE_EX(2b, 3b) \
12933 @@ -261,7 +302,7 @@ extern void __put_user_8(void);
12934 __typeof__(*(ptr)) __pu_val; \
12935 __chk_user_ptr(ptr); \
12936 might_fault(); \
12937 - __pu_val = x; \
12938 + __pu_val = (x); \
12939 switch (sizeof(*(ptr))) { \
12940 case 1: \
12941 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12942 @@ -383,7 +424,7 @@ do { \
12943
12944 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12945 asm volatile(ASM_STAC "\n" \
12946 - "1: mov"itype" %2,%"rtype"1\n" \
12947 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12948 "2: " ASM_CLAC "\n" \
12949 ".section .fixup,\"ax\"\n" \
12950 "3: mov %3,%0\n" \
12951 @@ -391,7 +432,7 @@ do { \
12952 " jmp 2b\n" \
12953 ".previous\n" \
12954 _ASM_EXTABLE(1b, 3b) \
12955 - : "=r" (err), ltype(x) \
12956 + : "=r" (err), ltype (x) \
12957 : "m" (__m(addr)), "i" (errret), "0" (err))
12958
12959 #define __get_user_size_ex(x, ptr, size) \
12960 @@ -416,7 +457,7 @@ do { \
12961 } while (0)
12962
12963 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12964 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12965 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12966 "2:\n" \
12967 _ASM_EXTABLE_EX(1b, 2b) \
12968 : ltype(x) : "m" (__m(addr)))
12969 @@ -433,13 +474,24 @@ do { \
12970 int __gu_err; \
12971 unsigned long __gu_val; \
12972 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12973 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12974 + (x) = (__typeof__(*(ptr)))__gu_val; \
12975 __gu_err; \
12976 })
12977
12978 /* FIXME: this hack is definitely wrong -AK */
12979 struct __large_struct { unsigned long buf[100]; };
12980 -#define __m(x) (*(struct __large_struct __user *)(x))
12981 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12982 +#define ____m(x) \
12983 +({ \
12984 + unsigned long ____x = (unsigned long)(x); \
12985 + if (____x < PAX_USER_SHADOW_BASE) \
12986 + ____x += PAX_USER_SHADOW_BASE; \
12987 + (void __user *)____x; \
12988 +})
12989 +#else
12990 +#define ____m(x) (x)
12991 +#endif
12992 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12993
12994 /*
12995 * Tell gcc we read from memory instead of writing: this is because
12996 @@ -448,7 +500,7 @@ struct __large_struct { unsigned long buf[100]; };
12997 */
12998 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12999 asm volatile(ASM_STAC "\n" \
13000 - "1: mov"itype" %"rtype"1,%2\n" \
13001 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
13002 "2: " ASM_CLAC "\n" \
13003 ".section .fixup,\"ax\"\n" \
13004 "3: mov %3,%0\n" \
13005 @@ -456,10 +508,10 @@ struct __large_struct { unsigned long buf[100]; };
13006 ".previous\n" \
13007 _ASM_EXTABLE(1b, 3b) \
13008 : "=r"(err) \
13009 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
13010 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
13011
13012 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
13013 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
13014 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
13015 "2:\n" \
13016 _ASM_EXTABLE_EX(1b, 2b) \
13017 : : ltype(x), "m" (__m(addr)))
13018 @@ -498,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
13019 * On error, the variable @x is set to zero.
13020 */
13021
13022 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13023 +#define __get_user(x, ptr) get_user((x), (ptr))
13024 +#else
13025 #define __get_user(x, ptr) \
13026 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
13027 +#endif
13028
13029 /**
13030 * __put_user: - Write a simple value into user space, with less checking.
13031 @@ -521,8 +577,12 @@ struct __large_struct { unsigned long buf[100]; };
13032 * Returns zero on success, or -EFAULT on error.
13033 */
13034
13035 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13036 +#define __put_user(x, ptr) put_user((x), (ptr))
13037 +#else
13038 #define __put_user(x, ptr) \
13039 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
13040 +#endif
13041
13042 #define __get_user_unaligned __get_user
13043 #define __put_user_unaligned __put_user
13044 @@ -540,7 +600,7 @@ struct __large_struct { unsigned long buf[100]; };
13045 #define get_user_ex(x, ptr) do { \
13046 unsigned long __gue_val; \
13047 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
13048 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
13049 + (x) = (__typeof__(*(ptr)))__gue_val; \
13050 } while (0)
13051
13052 #ifdef CONFIG_X86_WP_WORKS_OK
13053 @@ -574,8 +634,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
13054 extern __must_check long strlen_user(const char __user *str);
13055 extern __must_check long strnlen_user(const char __user *str, long n);
13056
13057 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13058 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13059 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13060 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13061
13062 /*
13063 * movsl can be slow when source and dest are not both 8-byte aligned
13064 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
13065 index 7f760a9..00f93c0 100644
13066 --- a/arch/x86/include/asm/uaccess_32.h
13067 +++ b/arch/x86/include/asm/uaccess_32.h
13068 @@ -11,15 +11,15 @@
13069 #include <asm/page.h>
13070
13071 unsigned long __must_check __copy_to_user_ll
13072 - (void __user *to, const void *from, unsigned long n);
13073 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
13074 unsigned long __must_check __copy_from_user_ll
13075 - (void *to, const void __user *from, unsigned long n);
13076 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13077 unsigned long __must_check __copy_from_user_ll_nozero
13078 - (void *to, const void __user *from, unsigned long n);
13079 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13080 unsigned long __must_check __copy_from_user_ll_nocache
13081 - (void *to, const void __user *from, unsigned long n);
13082 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13083 unsigned long __must_check __copy_from_user_ll_nocache_nozero
13084 - (void *to, const void __user *from, unsigned long n);
13085 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13086
13087 /**
13088 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13089 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13090 static __always_inline unsigned long __must_check
13091 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13092 {
13093 + if ((long)n < 0)
13094 + return n;
13095 +
13096 if (__builtin_constant_p(n)) {
13097 unsigned long ret;
13098
13099 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13100 return ret;
13101 }
13102 }
13103 + if (!__builtin_constant_p(n))
13104 + check_object_size(from, n, true);
13105 return __copy_to_user_ll(to, from, n);
13106 }
13107
13108 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
13109 __copy_to_user(void __user *to, const void *from, unsigned long n)
13110 {
13111 might_fault();
13112 +
13113 return __copy_to_user_inatomic(to, from, n);
13114 }
13115
13116 static __always_inline unsigned long
13117 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13118 {
13119 + if ((long)n < 0)
13120 + return n;
13121 +
13122 /* Avoid zeroing the tail if the copy fails..
13123 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13124 * but as the zeroing behaviour is only significant when n is not
13125 @@ -137,6 +146,10 @@ static __always_inline unsigned long
13126 __copy_from_user(void *to, const void __user *from, unsigned long n)
13127 {
13128 might_fault();
13129 +
13130 + if ((long)n < 0)
13131 + return n;
13132 +
13133 if (__builtin_constant_p(n)) {
13134 unsigned long ret;
13135
13136 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13137 return ret;
13138 }
13139 }
13140 + if (!__builtin_constant_p(n))
13141 + check_object_size(to, n, false);
13142 return __copy_from_user_ll(to, from, n);
13143 }
13144
13145 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13146 const void __user *from, unsigned long n)
13147 {
13148 might_fault();
13149 +
13150 + if ((long)n < 0)
13151 + return n;
13152 +
13153 if (__builtin_constant_p(n)) {
13154 unsigned long ret;
13155
13156 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13157 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13158 unsigned long n)
13159 {
13160 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13161 + if ((long)n < 0)
13162 + return n;
13163 +
13164 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13165 }
13166
13167 -unsigned long __must_check copy_to_user(void __user *to,
13168 - const void *from, unsigned long n);
13169 -unsigned long __must_check _copy_from_user(void *to,
13170 - const void __user *from,
13171 - unsigned long n);
13172 -
13173 +extern void copy_to_user_overflow(void)
13174 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13175 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13176 +#else
13177 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13178 +#endif
13179 +;
13180
13181 extern void copy_from_user_overflow(void)
13182 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13183 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
13184 #endif
13185 ;
13186
13187 -static inline unsigned long __must_check copy_from_user(void *to,
13188 - const void __user *from,
13189 - unsigned long n)
13190 +/**
13191 + * copy_to_user: - Copy a block of data into user space.
13192 + * @to: Destination address, in user space.
13193 + * @from: Source address, in kernel space.
13194 + * @n: Number of bytes to copy.
13195 + *
13196 + * Context: User context only. This function may sleep.
13197 + *
13198 + * Copy data from kernel space to user space.
13199 + *
13200 + * Returns number of bytes that could not be copied.
13201 + * On success, this will be zero.
13202 + */
13203 +static inline unsigned long __must_check
13204 +copy_to_user(void __user *to, const void *from, unsigned long n)
13205 {
13206 - int sz = __compiletime_object_size(to);
13207 + size_t sz = __compiletime_object_size(from);
13208
13209 - if (likely(sz == -1 || sz >= n))
13210 - n = _copy_from_user(to, from, n);
13211 - else
13212 + if (unlikely(sz != (size_t)-1 && sz < n))
13213 + copy_to_user_overflow();
13214 + else if (access_ok(VERIFY_WRITE, to, n))
13215 + n = __copy_to_user(to, from, n);
13216 + return n;
13217 +}
13218 +
13219 +/**
13220 + * copy_from_user: - Copy a block of data from user space.
13221 + * @to: Destination address, in kernel space.
13222 + * @from: Source address, in user space.
13223 + * @n: Number of bytes to copy.
13224 + *
13225 + * Context: User context only. This function may sleep.
13226 + *
13227 + * Copy data from user space to kernel space.
13228 + *
13229 + * Returns number of bytes that could not be copied.
13230 + * On success, this will be zero.
13231 + *
13232 + * If some data could not be copied, this function will pad the copied
13233 + * data to the requested size using zero bytes.
13234 + */
13235 +static inline unsigned long __must_check
13236 +copy_from_user(void *to, const void __user *from, unsigned long n)
13237 +{
13238 + size_t sz = __compiletime_object_size(to);
13239 +
13240 + if (unlikely(sz != (size_t)-1 && sz < n))
13241 copy_from_user_overflow();
13242 -
13243 + else if (access_ok(VERIFY_READ, from, n))
13244 + n = __copy_from_user(to, from, n);
13245 + else if ((long)n > 0) {
13246 + if (!__builtin_constant_p(n))
13247 + check_object_size(to, n, false);
13248 + memset(to, 0, n);
13249 + }
13250 return n;
13251 }
13252
13253 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13254 index 142810c..4389299 100644
13255 --- a/arch/x86/include/asm/uaccess_64.h
13256 +++ b/arch/x86/include/asm/uaccess_64.h
13257 @@ -10,6 +10,9 @@
13258 #include <asm/alternative.h>
13259 #include <asm/cpufeature.h>
13260 #include <asm/page.h>
13261 +#include <asm/pgtable.h>
13262 +
13263 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13264
13265 /*
13266 * Copy To/From Userspace
13267 @@ -17,13 +20,13 @@
13268
13269 /* Handles exceptions in both to and from, but doesn't do access_ok */
13270 __must_check unsigned long
13271 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13272 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13273 __must_check unsigned long
13274 -copy_user_generic_string(void *to, const void *from, unsigned len);
13275 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13276 __must_check unsigned long
13277 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13278 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13279
13280 -static __always_inline __must_check unsigned long
13281 +static __always_inline __must_check __size_overflow(3) unsigned long
13282 copy_user_generic(void *to, const void *from, unsigned len)
13283 {
13284 unsigned ret;
13285 @@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
13286 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13287 "=d" (len)),
13288 "1" (to), "2" (from), "3" (len)
13289 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13290 + : "memory", "rcx", "r8", "r9", "r11");
13291 return ret;
13292 }
13293
13294 +static __always_inline __must_check unsigned long
13295 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13296 +static __always_inline __must_check unsigned long
13297 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13298 __must_check unsigned long
13299 -_copy_to_user(void __user *to, const void *from, unsigned len);
13300 -__must_check unsigned long
13301 -_copy_from_user(void *to, const void __user *from, unsigned len);
13302 -__must_check unsigned long
13303 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13304 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13305 +
13306 +extern void copy_to_user_overflow(void)
13307 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13308 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13309 +#else
13310 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13311 +#endif
13312 +;
13313 +
13314 +extern void copy_from_user_overflow(void)
13315 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13316 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13317 +#else
13318 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13319 +#endif
13320 +;
13321
13322 static inline unsigned long __must_check copy_from_user(void *to,
13323 const void __user *from,
13324 unsigned long n)
13325 {
13326 - int sz = __compiletime_object_size(to);
13327 -
13328 might_fault();
13329 - if (likely(sz == -1 || sz >= n))
13330 - n = _copy_from_user(to, from, n);
13331 -#ifdef CONFIG_DEBUG_VM
13332 - else
13333 - WARN(1, "Buffer overflow detected!\n");
13334 -#endif
13335 +
13336 + if (access_ok(VERIFY_READ, from, n))
13337 + n = __copy_from_user(to, from, n);
13338 + else if (n < INT_MAX) {
13339 + if (!__builtin_constant_p(n))
13340 + check_object_size(to, n, false);
13341 + memset(to, 0, n);
13342 + }
13343 return n;
13344 }
13345
13346 static __always_inline __must_check
13347 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13348 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13349 {
13350 might_fault();
13351
13352 - return _copy_to_user(dst, src, size);
13353 + if (access_ok(VERIFY_WRITE, dst, size))
13354 + size = __copy_to_user(dst, src, size);
13355 + return size;
13356 }
13357
13358 static __always_inline __must_check
13359 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13360 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13361 {
13362 - int ret = 0;
13363 + size_t sz = __compiletime_object_size(dst);
13364 + unsigned ret = 0;
13365
13366 might_fault();
13367 - if (!__builtin_constant_p(size))
13368 - return copy_user_generic(dst, (__force void *)src, size);
13369 +
13370 + if (size > INT_MAX)
13371 + return size;
13372 +
13373 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13374 + if (!__access_ok(VERIFY_READ, src, size))
13375 + return size;
13376 +#endif
13377 +
13378 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13379 + copy_from_user_overflow();
13380 + return size;
13381 + }
13382 +
13383 + if (!__builtin_constant_p(size)) {
13384 + check_object_size(dst, size, false);
13385 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13386 + }
13387 switch (size) {
13388 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13389 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13390 ret, "b", "b", "=q", 1);
13391 return ret;
13392 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13393 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13394 ret, "w", "w", "=r", 2);
13395 return ret;
13396 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13397 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13398 ret, "l", "k", "=r", 4);
13399 return ret;
13400 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13401 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13402 ret, "q", "", "=r", 8);
13403 return ret;
13404 case 10:
13405 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13406 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13407 ret, "q", "", "=r", 10);
13408 if (unlikely(ret))
13409 return ret;
13410 __get_user_asm(*(u16 *)(8 + (char *)dst),
13411 - (u16 __user *)(8 + (char __user *)src),
13412 + (const u16 __user *)(8 + (const char __user *)src),
13413 ret, "w", "w", "=r", 2);
13414 return ret;
13415 case 16:
13416 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13417 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13418 ret, "q", "", "=r", 16);
13419 if (unlikely(ret))
13420 return ret;
13421 __get_user_asm(*(u64 *)(8 + (char *)dst),
13422 - (u64 __user *)(8 + (char __user *)src),
13423 + (const u64 __user *)(8 + (const char __user *)src),
13424 ret, "q", "", "=r", 8);
13425 return ret;
13426 default:
13427 - return copy_user_generic(dst, (__force void *)src, size);
13428 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13429 }
13430 }
13431
13432 static __always_inline __must_check
13433 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13434 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13435 {
13436 - int ret = 0;
13437 + size_t sz = __compiletime_object_size(src);
13438 + unsigned ret = 0;
13439
13440 might_fault();
13441 - if (!__builtin_constant_p(size))
13442 - return copy_user_generic((__force void *)dst, src, size);
13443 +
13444 + if (size > INT_MAX)
13445 + return size;
13446 +
13447 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13448 + if (!__access_ok(VERIFY_WRITE, dst, size))
13449 + return size;
13450 +#endif
13451 +
13452 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13453 + copy_to_user_overflow();
13454 + return size;
13455 + }
13456 +
13457 + if (!__builtin_constant_p(size)) {
13458 + check_object_size(src, size, true);
13459 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13460 + }
13461 switch (size) {
13462 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13463 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13464 ret, "b", "b", "iq", 1);
13465 return ret;
13466 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13467 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13468 ret, "w", "w", "ir", 2);
13469 return ret;
13470 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13471 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13472 ret, "l", "k", "ir", 4);
13473 return ret;
13474 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13475 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13476 ret, "q", "", "er", 8);
13477 return ret;
13478 case 10:
13479 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13480 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13481 ret, "q", "", "er", 10);
13482 if (unlikely(ret))
13483 return ret;
13484 asm("":::"memory");
13485 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13486 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13487 ret, "w", "w", "ir", 2);
13488 return ret;
13489 case 16:
13490 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13491 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13492 ret, "q", "", "er", 16);
13493 if (unlikely(ret))
13494 return ret;
13495 asm("":::"memory");
13496 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13497 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13498 ret, "q", "", "er", 8);
13499 return ret;
13500 default:
13501 - return copy_user_generic((__force void *)dst, src, size);
13502 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13503 }
13504 }
13505
13506 static __always_inline __must_check
13507 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13508 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13509 {
13510 - int ret = 0;
13511 + unsigned ret = 0;
13512
13513 might_fault();
13514 +
13515 + if (size > INT_MAX)
13516 + return size;
13517 +
13518 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13519 + if (!__access_ok(VERIFY_READ, src, size))
13520 + return size;
13521 + if (!__access_ok(VERIFY_WRITE, dst, size))
13522 + return size;
13523 +#endif
13524 +
13525 if (!__builtin_constant_p(size))
13526 - return copy_user_generic((__force void *)dst,
13527 - (__force void *)src, size);
13528 + return copy_user_generic((__force_kernel void *)____m(dst),
13529 + (__force_kernel const void *)____m(src), size);
13530 switch (size) {
13531 case 1: {
13532 u8 tmp;
13533 - __get_user_asm(tmp, (u8 __user *)src,
13534 + __get_user_asm(tmp, (const u8 __user *)src,
13535 ret, "b", "b", "=q", 1);
13536 if (likely(!ret))
13537 __put_user_asm(tmp, (u8 __user *)dst,
13538 @@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13539 }
13540 case 2: {
13541 u16 tmp;
13542 - __get_user_asm(tmp, (u16 __user *)src,
13543 + __get_user_asm(tmp, (const u16 __user *)src,
13544 ret, "w", "w", "=r", 2);
13545 if (likely(!ret))
13546 __put_user_asm(tmp, (u16 __user *)dst,
13547 @@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13548
13549 case 4: {
13550 u32 tmp;
13551 - __get_user_asm(tmp, (u32 __user *)src,
13552 + __get_user_asm(tmp, (const u32 __user *)src,
13553 ret, "l", "k", "=r", 4);
13554 if (likely(!ret))
13555 __put_user_asm(tmp, (u32 __user *)dst,
13556 @@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13557 }
13558 case 8: {
13559 u64 tmp;
13560 - __get_user_asm(tmp, (u64 __user *)src,
13561 + __get_user_asm(tmp, (const u64 __user *)src,
13562 ret, "q", "", "=r", 8);
13563 if (likely(!ret))
13564 __put_user_asm(tmp, (u64 __user *)dst,
13565 @@ -212,41 +278,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13566 return ret;
13567 }
13568 default:
13569 - return copy_user_generic((__force void *)dst,
13570 - (__force void *)src, size);
13571 + return copy_user_generic((__force_kernel void *)____m(dst),
13572 + (__force_kernel const void *)____m(src), size);
13573 }
13574 }
13575
13576 static __must_check __always_inline int
13577 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13578 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13579 {
13580 - return copy_user_generic(dst, (__force const void *)src, size);
13581 + if (size > INT_MAX)
13582 + return size;
13583 +
13584 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13585 + if (!__access_ok(VERIFY_READ, src, size))
13586 + return size;
13587 +#endif
13588 +
13589 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
13590 }
13591
13592 -static __must_check __always_inline int
13593 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13594 +static __must_check __always_inline unsigned long
13595 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13596 {
13597 - return copy_user_generic((__force void *)dst, src, size);
13598 + if (size > INT_MAX)
13599 + return size;
13600 +
13601 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13602 + if (!__access_ok(VERIFY_WRITE, dst, size))
13603 + return size;
13604 +#endif
13605 +
13606 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
13607 }
13608
13609 -extern long __copy_user_nocache(void *dst, const void __user *src,
13610 - unsigned size, int zerorest);
13611 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13612 + unsigned long size, int zerorest) __size_overflow(3);
13613
13614 -static inline int
13615 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13616 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13617 {
13618 might_sleep();
13619 +
13620 + if (size > INT_MAX)
13621 + return size;
13622 +
13623 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13624 + if (!__access_ok(VERIFY_READ, src, size))
13625 + return size;
13626 +#endif
13627 +
13628 return __copy_user_nocache(dst, src, size, 1);
13629 }
13630
13631 -static inline int
13632 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13633 - unsigned size)
13634 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13635 + unsigned long size)
13636 {
13637 + if (size > INT_MAX)
13638 + return size;
13639 +
13640 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13641 + if (!__access_ok(VERIFY_READ, src, size))
13642 + return size;
13643 +#endif
13644 +
13645 return __copy_user_nocache(dst, src, size, 0);
13646 }
13647
13648 -unsigned long
13649 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13650 +extern unsigned long
13651 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13652
13653 #endif /* _ASM_X86_UACCESS_64_H */
13654 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13655 index 5b238981..77fdd78 100644
13656 --- a/arch/x86/include/asm/word-at-a-time.h
13657 +++ b/arch/x86/include/asm/word-at-a-time.h
13658 @@ -11,7 +11,7 @@
13659 * and shift, for example.
13660 */
13661 struct word_at_a_time {
13662 - const unsigned long one_bits, high_bits;
13663 + unsigned long one_bits, high_bits;
13664 };
13665
13666 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13667 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13668 index 5769349..d49a4dd 100644
13669 --- a/arch/x86/include/asm/x86_init.h
13670 +++ b/arch/x86/include/asm/x86_init.h
13671 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13672 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13673 void (*find_smp_config)(void);
13674 void (*get_smp_config)(unsigned int early);
13675 -};
13676 +} __no_const;
13677
13678 /**
13679 * struct x86_init_resources - platform specific resource related ops
13680 @@ -43,7 +43,7 @@ struct x86_init_resources {
13681 void (*probe_roms)(void);
13682 void (*reserve_resources)(void);
13683 char *(*memory_setup)(void);
13684 -};
13685 +} __no_const;
13686
13687 /**
13688 * struct x86_init_irqs - platform specific interrupt setup
13689 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13690 void (*pre_vector_init)(void);
13691 void (*intr_init)(void);
13692 void (*trap_init)(void);
13693 -};
13694 +} __no_const;
13695
13696 /**
13697 * struct x86_init_oem - oem platform specific customizing functions
13698 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13699 struct x86_init_oem {
13700 void (*arch_setup)(void);
13701 void (*banner)(void);
13702 -};
13703 +} __no_const;
13704
13705 /**
13706 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13707 @@ -77,7 +77,7 @@ struct x86_init_oem {
13708 */
13709 struct x86_init_mapping {
13710 void (*pagetable_reserve)(u64 start, u64 end);
13711 -};
13712 +} __no_const;
13713
13714 /**
13715 * struct x86_init_paging - platform specific paging functions
13716 @@ -88,7 +88,7 @@ struct x86_init_mapping {
13717 */
13718 struct x86_init_paging {
13719 void (*pagetable_init)(void);
13720 -};
13721 +} __no_const;
13722
13723 /**
13724 * struct x86_init_timers - platform specific timer setup
13725 @@ -103,7 +103,7 @@ struct x86_init_timers {
13726 void (*tsc_pre_init)(void);
13727 void (*timer_init)(void);
13728 void (*wallclock_init)(void);
13729 -};
13730 +} __no_const;
13731
13732 /**
13733 * struct x86_init_iommu - platform specific iommu setup
13734 @@ -111,7 +111,7 @@ struct x86_init_timers {
13735 */
13736 struct x86_init_iommu {
13737 int (*iommu_init)(void);
13738 -};
13739 +} __no_const;
13740
13741 /**
13742 * struct x86_init_pci - platform specific pci init functions
13743 @@ -125,7 +125,7 @@ struct x86_init_pci {
13744 int (*init)(void);
13745 void (*init_irq)(void);
13746 void (*fixup_irqs)(void);
13747 -};
13748 +} __no_const;
13749
13750 /**
13751 * struct x86_init_ops - functions for platform specific setup
13752 @@ -141,7 +141,7 @@ struct x86_init_ops {
13753 struct x86_init_timers timers;
13754 struct x86_init_iommu iommu;
13755 struct x86_init_pci pci;
13756 -};
13757 +} __no_const;
13758
13759 /**
13760 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13761 @@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
13762 void (*setup_percpu_clockev)(void);
13763 void (*early_percpu_clock_init)(void);
13764 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13765 -};
13766 +} __no_const;
13767
13768 /**
13769 * struct x86_platform_ops - platform specific runtime functions
13770 @@ -178,7 +178,7 @@ struct x86_platform_ops {
13771 void (*save_sched_clock_state)(void);
13772 void (*restore_sched_clock_state)(void);
13773 void (*apic_post_init)(void);
13774 -};
13775 +} __no_const;
13776
13777 struct pci_dev;
13778
13779 @@ -187,14 +187,14 @@ struct x86_msi_ops {
13780 void (*teardown_msi_irq)(unsigned int irq);
13781 void (*teardown_msi_irqs)(struct pci_dev *dev);
13782 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13783 -};
13784 +} __no_const;
13785
13786 struct x86_io_apic_ops {
13787 void (*init) (void);
13788 unsigned int (*read) (unsigned int apic, unsigned int reg);
13789 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13790 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13791 -};
13792 +} __no_const;
13793
13794 extern struct x86_init_ops x86_init;
13795 extern struct x86_cpuinit_ops x86_cpuinit;
13796 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13797 index 0415cda..b43d877 100644
13798 --- a/arch/x86/include/asm/xsave.h
13799 +++ b/arch/x86/include/asm/xsave.h
13800 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13801 return -EFAULT;
13802
13803 __asm__ __volatile__(ASM_STAC "\n"
13804 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
13805 + "1:"
13806 + __copyuser_seg
13807 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
13808 "2: " ASM_CLAC "\n"
13809 ".section .fixup,\"ax\"\n"
13810 "3: movl $-1,%[err]\n"
13811 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13812 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13813 {
13814 int err;
13815 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13816 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13817 u32 lmask = mask;
13818 u32 hmask = mask >> 32;
13819
13820 __asm__ __volatile__(ASM_STAC "\n"
13821 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13822 + "1:"
13823 + __copyuser_seg
13824 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13825 "2: " ASM_CLAC "\n"
13826 ".section .fixup,\"ax\"\n"
13827 "3: movl $-1,%[err]\n"
13828 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
13829 index 91ce48f..a48ea05 100644
13830 --- a/arch/x86/kernel/Makefile
13831 +++ b/arch/x86/kernel/Makefile
13832 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
13833 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
13834 obj-$(CONFIG_IRQ_WORK) += irq_work.o
13835 obj-y += probe_roms.o
13836 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
13837 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
13838 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
13839 obj-y += syscall_$(BITS).o
13840 obj-$(CONFIG_X86_64) += vsyscall_64.o
13841 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13842 index 11676cf..a8cf3ec 100644
13843 --- a/arch/x86/kernel/acpi/sleep.c
13844 +++ b/arch/x86/kernel/acpi/sleep.c
13845 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
13846 #else /* CONFIG_64BIT */
13847 #ifdef CONFIG_SMP
13848 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13849 +
13850 + pax_open_kernel();
13851 early_gdt_descr.address =
13852 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13853 + pax_close_kernel();
13854 +
13855 initial_gs = per_cpu_offset(smp_processor_id());
13856 #endif
13857 initial_code = (unsigned long)wakeup_long64;
13858 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13859 index 13ab720..95d5442 100644
13860 --- a/arch/x86/kernel/acpi/wakeup_32.S
13861 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13862 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13863 # and restore the stack ... but you need gdt for this to work
13864 movl saved_context_esp, %esp
13865
13866 - movl %cs:saved_magic, %eax
13867 - cmpl $0x12345678, %eax
13868 + cmpl $0x12345678, saved_magic
13869 jne bogus_magic
13870
13871 # jump to place where we left off
13872 - movl saved_eip, %eax
13873 - jmp *%eax
13874 + jmp *(saved_eip)
13875
13876 bogus_magic:
13877 jmp bogus_magic
13878 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13879 index ef5ccca..bd83949 100644
13880 --- a/arch/x86/kernel/alternative.c
13881 +++ b/arch/x86/kernel/alternative.c
13882 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13883 */
13884 for (a = start; a < end; a++) {
13885 instr = (u8 *)&a->instr_offset + a->instr_offset;
13886 +
13887 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13888 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13889 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13890 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13891 +#endif
13892 +
13893 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13894 BUG_ON(a->replacementlen > a->instrlen);
13895 BUG_ON(a->instrlen > sizeof(insnbuf));
13896 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13897 for (poff = start; poff < end; poff++) {
13898 u8 *ptr = (u8 *)poff + *poff;
13899
13900 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13901 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13902 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13903 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13904 +#endif
13905 +
13906 if (!*poff || ptr < text || ptr >= text_end)
13907 continue;
13908 /* turn DS segment override prefix into lock prefix */
13909 - if (*ptr == 0x3e)
13910 + if (*ktla_ktva(ptr) == 0x3e)
13911 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13912 }
13913 mutex_unlock(&text_mutex);
13914 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13915 for (poff = start; poff < end; poff++) {
13916 u8 *ptr = (u8 *)poff + *poff;
13917
13918 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13919 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13920 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13921 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13922 +#endif
13923 +
13924 if (!*poff || ptr < text || ptr >= text_end)
13925 continue;
13926 /* turn lock prefix into DS segment override prefix */
13927 - if (*ptr == 0xf0)
13928 + if (*ktla_ktva(ptr) == 0xf0)
13929 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13930 }
13931 mutex_unlock(&text_mutex);
13932 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13933
13934 BUG_ON(p->len > MAX_PATCH_LEN);
13935 /* prep the buffer with the original instructions */
13936 - memcpy(insnbuf, p->instr, p->len);
13937 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13938 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13939 (unsigned long)p->instr, p->len);
13940
13941 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
13942 if (!uniproc_patched || num_possible_cpus() == 1)
13943 free_init_pages("SMP alternatives",
13944 (unsigned long)__smp_locks,
13945 - (unsigned long)__smp_locks_end);
13946 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13947 #endif
13948
13949 apply_paravirt(__parainstructions, __parainstructions_end);
13950 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
13951 * instructions. And on the local CPU you need to be protected again NMI or MCE
13952 * handlers seeing an inconsistent instruction while you patch.
13953 */
13954 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13955 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13956 size_t len)
13957 {
13958 unsigned long flags;
13959 local_irq_save(flags);
13960 - memcpy(addr, opcode, len);
13961 +
13962 + pax_open_kernel();
13963 + memcpy(ktla_ktva(addr), opcode, len);
13964 sync_core();
13965 + pax_close_kernel();
13966 +
13967 local_irq_restore(flags);
13968 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13969 that causes hangs on some VIA CPUs. */
13970 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13971 */
13972 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13973 {
13974 - unsigned long flags;
13975 - char *vaddr;
13976 + unsigned char *vaddr = ktla_ktva(addr);
13977 struct page *pages[2];
13978 - int i;
13979 + size_t i;
13980
13981 if (!core_kernel_text((unsigned long)addr)) {
13982 - pages[0] = vmalloc_to_page(addr);
13983 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13984 + pages[0] = vmalloc_to_page(vaddr);
13985 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13986 } else {
13987 - pages[0] = virt_to_page(addr);
13988 + pages[0] = virt_to_page(vaddr);
13989 WARN_ON(!PageReserved(pages[0]));
13990 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13991 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13992 }
13993 BUG_ON(!pages[0]);
13994 - local_irq_save(flags);
13995 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13996 - if (pages[1])
13997 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13998 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13999 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14000 - clear_fixmap(FIX_TEXT_POKE0);
14001 - if (pages[1])
14002 - clear_fixmap(FIX_TEXT_POKE1);
14003 - local_flush_tlb();
14004 - sync_core();
14005 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
14006 - that causes hangs on some VIA CPUs. */
14007 + text_poke_early(addr, opcode, len);
14008 for (i = 0; i < len; i++)
14009 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14010 - local_irq_restore(flags);
14011 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14012 return addr;
14013 }
14014
14015 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14016 index b17416e..be6e5dc 100644
14017 --- a/arch/x86/kernel/apic/apic.c
14018 +++ b/arch/x86/kernel/apic/apic.c
14019 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14020 /*
14021 * Debug level, exported for io_apic.c
14022 */
14023 -unsigned int apic_verbosity;
14024 +int apic_verbosity;
14025
14026 int pic_mode;
14027
14028 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14029 apic_write(APIC_ESR, 0);
14030 v1 = apic_read(APIC_ESR);
14031 ack_APIC_irq();
14032 - atomic_inc(&irq_err_count);
14033 + atomic_inc_unchecked(&irq_err_count);
14034
14035 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14036 smp_processor_id(), v0 , v1);
14037 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14038 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14039 /* Should happen once for each apic */
14040 WARN_ON((*drv)->eoi_write == eoi_write);
14041 - (*drv)->eoi_write = eoi_write;
14042 + pax_open_kernel();
14043 + *(void **)&(*drv)->eoi_write = eoi_write;
14044 + pax_close_kernel();
14045 }
14046 }
14047
14048 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14049 index 1817fa9..7bff097 100644
14050 --- a/arch/x86/kernel/apic/io_apic.c
14051 +++ b/arch/x86/kernel/apic/io_apic.c
14052 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14053 }
14054 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14055
14056 -void lock_vector_lock(void)
14057 +void lock_vector_lock(void) __acquires(vector_lock)
14058 {
14059 /* Used to the online set of cpus does not change
14060 * during assign_irq_vector.
14061 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
14062 raw_spin_lock(&vector_lock);
14063 }
14064
14065 -void unlock_vector_lock(void)
14066 +void unlock_vector_lock(void) __releases(vector_lock)
14067 {
14068 raw_spin_unlock(&vector_lock);
14069 }
14070 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
14071 ack_APIC_irq();
14072 }
14073
14074 -atomic_t irq_mis_count;
14075 +atomic_unchecked_t irq_mis_count;
14076
14077 #ifdef CONFIG_GENERIC_PENDING_IRQ
14078 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14079 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
14080 * at the cpu.
14081 */
14082 if (!(v & (1 << (i & 0x1f)))) {
14083 - atomic_inc(&irq_mis_count);
14084 + atomic_inc_unchecked(&irq_mis_count);
14085
14086 eoi_ioapic_irq(irq, cfg);
14087 }
14088 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14089 index d65464e..1035d31 100644
14090 --- a/arch/x86/kernel/apm_32.c
14091 +++ b/arch/x86/kernel/apm_32.c
14092 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14093 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14094 * even though they are called in protected mode.
14095 */
14096 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14097 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14098 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14099
14100 static const char driver_version[] = "1.16ac"; /* no spaces */
14101 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14102 BUG_ON(cpu != 0);
14103 gdt = get_cpu_gdt_table(cpu);
14104 save_desc_40 = gdt[0x40 / 8];
14105 +
14106 + pax_open_kernel();
14107 gdt[0x40 / 8] = bad_bios_desc;
14108 + pax_close_kernel();
14109
14110 apm_irq_save(flags);
14111 APM_DO_SAVE_SEGS;
14112 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14113 &call->esi);
14114 APM_DO_RESTORE_SEGS;
14115 apm_irq_restore(flags);
14116 +
14117 + pax_open_kernel();
14118 gdt[0x40 / 8] = save_desc_40;
14119 + pax_close_kernel();
14120 +
14121 put_cpu();
14122
14123 return call->eax & 0xff;
14124 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14125 BUG_ON(cpu != 0);
14126 gdt = get_cpu_gdt_table(cpu);
14127 save_desc_40 = gdt[0x40 / 8];
14128 +
14129 + pax_open_kernel();
14130 gdt[0x40 / 8] = bad_bios_desc;
14131 + pax_close_kernel();
14132
14133 apm_irq_save(flags);
14134 APM_DO_SAVE_SEGS;
14135 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14136 &call->eax);
14137 APM_DO_RESTORE_SEGS;
14138 apm_irq_restore(flags);
14139 +
14140 + pax_open_kernel();
14141 gdt[0x40 / 8] = save_desc_40;
14142 + pax_close_kernel();
14143 +
14144 put_cpu();
14145 return error;
14146 }
14147 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14148 * code to that CPU.
14149 */
14150 gdt = get_cpu_gdt_table(0);
14151 +
14152 + pax_open_kernel();
14153 set_desc_base(&gdt[APM_CS >> 3],
14154 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14155 set_desc_base(&gdt[APM_CS_16 >> 3],
14156 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14157 set_desc_base(&gdt[APM_DS >> 3],
14158 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14159 + pax_close_kernel();
14160
14161 proc_create("apm", 0, NULL, &apm_file_ops);
14162
14163 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14164 index 2861082..6d4718e 100644
14165 --- a/arch/x86/kernel/asm-offsets.c
14166 +++ b/arch/x86/kernel/asm-offsets.c
14167 @@ -33,6 +33,8 @@ void common(void) {
14168 OFFSET(TI_status, thread_info, status);
14169 OFFSET(TI_addr_limit, thread_info, addr_limit);
14170 OFFSET(TI_preempt_count, thread_info, preempt_count);
14171 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14172 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14173
14174 BLANK();
14175 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14176 @@ -53,8 +55,26 @@ void common(void) {
14177 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14178 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14179 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14180 +
14181 +#ifdef CONFIG_PAX_KERNEXEC
14182 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14183 #endif
14184
14185 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14186 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14187 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14188 +#ifdef CONFIG_X86_64
14189 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14190 +#endif
14191 +#endif
14192 +
14193 +#endif
14194 +
14195 + BLANK();
14196 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14197 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14198 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14199 +
14200 #ifdef CONFIG_XEN
14201 BLANK();
14202 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14203 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14204 index 1b4754f..fbb4227 100644
14205 --- a/arch/x86/kernel/asm-offsets_64.c
14206 +++ b/arch/x86/kernel/asm-offsets_64.c
14207 @@ -76,6 +76,7 @@ int main(void)
14208 BLANK();
14209 #undef ENTRY
14210
14211 + DEFINE(TSS_size, sizeof(struct tss_struct));
14212 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14213 BLANK();
14214
14215 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14216 index a0e067d..9c7db16 100644
14217 --- a/arch/x86/kernel/cpu/Makefile
14218 +++ b/arch/x86/kernel/cpu/Makefile
14219 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14220 CFLAGS_REMOVE_perf_event.o = -pg
14221 endif
14222
14223 -# Make sure load_percpu_segment has no stackprotector
14224 -nostackp := $(call cc-option, -fno-stack-protector)
14225 -CFLAGS_common.o := $(nostackp)
14226 -
14227 obj-y := intel_cacheinfo.o scattered.o topology.o
14228 obj-y += proc.o capflags.o powerflags.o common.o
14229 obj-y += vmware.o hypervisor.o mshyperv.o
14230 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14231 index 1b7d165..b9e2627 100644
14232 --- a/arch/x86/kernel/cpu/amd.c
14233 +++ b/arch/x86/kernel/cpu/amd.c
14234 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14235 unsigned int size)
14236 {
14237 /* AMD errata T13 (order #21922) */
14238 - if ((c->x86 == 6)) {
14239 + if (c->x86 == 6) {
14240 /* Duron Rev A0 */
14241 if (c->x86_model == 3 && c->x86_mask == 0)
14242 size = 64;
14243 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14244 index 7505f7b..d59dac0 100644
14245 --- a/arch/x86/kernel/cpu/common.c
14246 +++ b/arch/x86/kernel/cpu/common.c
14247 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14248
14249 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14250
14251 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14252 -#ifdef CONFIG_X86_64
14253 - /*
14254 - * We need valid kernel segments for data and code in long mode too
14255 - * IRET will check the segment types kkeil 2000/10/28
14256 - * Also sysret mandates a special GDT layout
14257 - *
14258 - * TLS descriptors are currently at a different place compared to i386.
14259 - * Hopefully nobody expects them at a fixed place (Wine?)
14260 - */
14261 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14262 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14263 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14264 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14265 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14266 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14267 -#else
14268 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14269 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14270 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14271 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14272 - /*
14273 - * Segments used for calling PnP BIOS have byte granularity.
14274 - * They code segments and data segments have fixed 64k limits,
14275 - * the transfer segment sizes are set at run time.
14276 - */
14277 - /* 32-bit code */
14278 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14279 - /* 16-bit code */
14280 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14281 - /* 16-bit data */
14282 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14283 - /* 16-bit data */
14284 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14285 - /* 16-bit data */
14286 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14287 - /*
14288 - * The APM segments have byte granularity and their bases
14289 - * are set at run time. All have 64k limits.
14290 - */
14291 - /* 32-bit code */
14292 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14293 - /* 16-bit code */
14294 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14295 - /* data */
14296 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14297 -
14298 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14299 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14300 - GDT_STACK_CANARY_INIT
14301 -#endif
14302 -} };
14303 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14304 -
14305 static int __init x86_xsave_setup(char *s)
14306 {
14307 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14308 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
14309 {
14310 struct desc_ptr gdt_descr;
14311
14312 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14313 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14314 gdt_descr.size = GDT_SIZE - 1;
14315 load_gdt(&gdt_descr);
14316 /* Reload the per-cpu base */
14317 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14318 /* Filter out anything that depends on CPUID levels we don't have */
14319 filter_cpuid_features(c, true);
14320
14321 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14322 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14323 +#endif
14324 +
14325 /* If the model name is still unset, do table lookup. */
14326 if (!c->x86_model_id[0]) {
14327 const char *p;
14328 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
14329 }
14330 __setup("clearcpuid=", setup_disablecpuid);
14331
14332 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14333 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14334 +
14335 #ifdef CONFIG_X86_64
14336 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14337 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14338 - (unsigned long) nmi_idt_table };
14339 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14340
14341 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14342 irq_stack_union) __aligned(PAGE_SIZE);
14343 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14344 EXPORT_PER_CPU_SYMBOL(current_task);
14345
14346 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14347 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14348 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14349 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14350
14351 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14352 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14353 {
14354 memset(regs, 0, sizeof(struct pt_regs));
14355 regs->fs = __KERNEL_PERCPU;
14356 - regs->gs = __KERNEL_STACK_CANARY;
14357 + savesegment(gs, regs->gs);
14358
14359 return regs;
14360 }
14361 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
14362 int i;
14363
14364 cpu = stack_smp_processor_id();
14365 - t = &per_cpu(init_tss, cpu);
14366 + t = init_tss + cpu;
14367 oist = &per_cpu(orig_ist, cpu);
14368
14369 #ifdef CONFIG_NUMA
14370 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
14371 switch_to_new_gdt(cpu);
14372 loadsegment(fs, 0);
14373
14374 - load_idt((const struct desc_ptr *)&idt_descr);
14375 + load_idt(&idt_descr);
14376
14377 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14378 syscall_init();
14379 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
14380 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14381 barrier();
14382
14383 - x86_configure_nx();
14384 if (cpu != 0)
14385 enable_x2apic();
14386
14387 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
14388 {
14389 int cpu = smp_processor_id();
14390 struct task_struct *curr = current;
14391 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14392 + struct tss_struct *t = init_tss + cpu;
14393 struct thread_struct *thread = &curr->thread;
14394
14395 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14396 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14397 index 198e019..867575e 100644
14398 --- a/arch/x86/kernel/cpu/intel.c
14399 +++ b/arch/x86/kernel/cpu/intel.c
14400 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14401 * Update the IDT descriptor and reload the IDT so that
14402 * it uses the read-only mapped virtual address.
14403 */
14404 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14405 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14406 load_idt(&idt_descr);
14407 }
14408 #endif
14409 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14410 index 46cbf86..8f8d94c 100644
14411 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14412 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14413 @@ -45,6 +45,7 @@
14414 #include <asm/processor.h>
14415 #include <asm/mce.h>
14416 #include <asm/msr.h>
14417 +#include <asm/local.h>
14418
14419 #include "mce-internal.h"
14420
14421 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
14422 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14423 m->cs, m->ip);
14424
14425 - if (m->cs == __KERNEL_CS)
14426 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14427 print_symbol("{%s}", m->ip);
14428 pr_cont("\n");
14429 }
14430 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
14431
14432 #define PANIC_TIMEOUT 5 /* 5 seconds */
14433
14434 -static atomic_t mce_paniced;
14435 +static atomic_unchecked_t mce_paniced;
14436
14437 static int fake_panic;
14438 -static atomic_t mce_fake_paniced;
14439 +static atomic_unchecked_t mce_fake_paniced;
14440
14441 /* Panic in progress. Enable interrupts and wait for final IPI */
14442 static void wait_for_panic(void)
14443 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14444 /*
14445 * Make sure only one CPU runs in machine check panic
14446 */
14447 - if (atomic_inc_return(&mce_paniced) > 1)
14448 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14449 wait_for_panic();
14450 barrier();
14451
14452 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14453 console_verbose();
14454 } else {
14455 /* Don't log too much for fake panic */
14456 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14457 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14458 return;
14459 }
14460 /* First print corrected ones that are still unlogged */
14461 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
14462 * might have been modified by someone else.
14463 */
14464 rmb();
14465 - if (atomic_read(&mce_paniced))
14466 + if (atomic_read_unchecked(&mce_paniced))
14467 wait_for_panic();
14468 if (!monarch_timeout)
14469 goto out;
14470 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14471 }
14472
14473 /* Call the installed machine check handler for this CPU setup. */
14474 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14475 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14476 unexpected_machine_check;
14477
14478 /*
14479 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14480 return;
14481 }
14482
14483 + pax_open_kernel();
14484 machine_check_vector = do_machine_check;
14485 + pax_close_kernel();
14486
14487 __mcheck_cpu_init_generic();
14488 __mcheck_cpu_init_vendor(c);
14489 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14490 */
14491
14492 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14493 -static int mce_chrdev_open_count; /* #times opened */
14494 +static local_t mce_chrdev_open_count; /* #times opened */
14495 static int mce_chrdev_open_exclu; /* already open exclusive? */
14496
14497 static int mce_chrdev_open(struct inode *inode, struct file *file)
14498 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14499 spin_lock(&mce_chrdev_state_lock);
14500
14501 if (mce_chrdev_open_exclu ||
14502 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14503 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14504 spin_unlock(&mce_chrdev_state_lock);
14505
14506 return -EBUSY;
14507 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14508
14509 if (file->f_flags & O_EXCL)
14510 mce_chrdev_open_exclu = 1;
14511 - mce_chrdev_open_count++;
14512 + local_inc(&mce_chrdev_open_count);
14513
14514 spin_unlock(&mce_chrdev_state_lock);
14515
14516 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14517 {
14518 spin_lock(&mce_chrdev_state_lock);
14519
14520 - mce_chrdev_open_count--;
14521 + local_dec(&mce_chrdev_open_count);
14522 mce_chrdev_open_exclu = 0;
14523
14524 spin_unlock(&mce_chrdev_state_lock);
14525 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
14526 static void mce_reset(void)
14527 {
14528 cpu_missing = 0;
14529 - atomic_set(&mce_fake_paniced, 0);
14530 + atomic_set_unchecked(&mce_fake_paniced, 0);
14531 atomic_set(&mce_executing, 0);
14532 atomic_set(&mce_callin, 0);
14533 atomic_set(&global_nwo, 0);
14534 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14535 index 2d5454c..51987eb 100644
14536 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14537 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14538 @@ -11,6 +11,7 @@
14539 #include <asm/processor.h>
14540 #include <asm/mce.h>
14541 #include <asm/msr.h>
14542 +#include <asm/pgtable.h>
14543
14544 /* By default disabled */
14545 int mce_p5_enabled __read_mostly;
14546 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14547 if (!cpu_has(c, X86_FEATURE_MCE))
14548 return;
14549
14550 + pax_open_kernel();
14551 machine_check_vector = pentium_machine_check;
14552 + pax_close_kernel();
14553 /* Make sure the vector pointer is visible before we enable MCEs: */
14554 wmb();
14555
14556 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14557 index 2d7998f..17c9de1 100644
14558 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14559 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14560 @@ -10,6 +10,7 @@
14561 #include <asm/processor.h>
14562 #include <asm/mce.h>
14563 #include <asm/msr.h>
14564 +#include <asm/pgtable.h>
14565
14566 /* Machine check handler for WinChip C6: */
14567 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14568 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14569 {
14570 u32 lo, hi;
14571
14572 + pax_open_kernel();
14573 machine_check_vector = winchip_machine_check;
14574 + pax_close_kernel();
14575 /* Make sure the vector pointer is visible before we enable MCEs: */
14576 wmb();
14577
14578 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14579 index 6b96110..0da73eb 100644
14580 --- a/arch/x86/kernel/cpu/mtrr/main.c
14581 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14582 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14583 u64 size_or_mask, size_and_mask;
14584 static bool mtrr_aps_delayed_init;
14585
14586 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14587 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14588
14589 const struct mtrr_ops *mtrr_if;
14590
14591 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14592 index df5e41f..816c719 100644
14593 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14594 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14595 @@ -25,7 +25,7 @@ struct mtrr_ops {
14596 int (*validate_add_page)(unsigned long base, unsigned long size,
14597 unsigned int type);
14598 int (*have_wrcomb)(void);
14599 -};
14600 +} __do_const;
14601
14602 extern int generic_get_free_region(unsigned long base, unsigned long size,
14603 int replace_reg);
14604 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14605 index 4a3374e..1ca3ecb 100644
14606 --- a/arch/x86/kernel/cpu/perf_event.c
14607 +++ b/arch/x86/kernel/cpu/perf_event.c
14608 @@ -1765,7 +1765,7 @@ static unsigned long get_segment_base(unsigned int segment)
14609 if (idx > GDT_ENTRIES)
14610 return 0;
14611
14612 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14613 + desc = get_cpu_gdt_table(smp_processor_id());
14614 }
14615
14616 return get_desc_base(desc + idx);
14617 @@ -1855,7 +1855,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14618 break;
14619
14620 perf_callchain_store(entry, frame.return_address);
14621 - fp = frame.next_frame;
14622 + fp = (const void __force_user *)frame.next_frame;
14623 }
14624 }
14625
14626 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14627 index 324bb52..1a93d85 100644
14628 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14629 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14630 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
14631 * v2 and above have a perf capabilities MSR
14632 */
14633 if (version > 1) {
14634 - u64 capabilities;
14635 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14636
14637 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14638 - x86_pmu.intel_cap.capabilities = capabilities;
14639 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14640 + x86_pmu.intel_cap.capabilities = capabilities;
14641 }
14642
14643 intel_ds_init();
14644 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14645 index 13ad899..f642b9a 100644
14646 --- a/arch/x86/kernel/crash.c
14647 +++ b/arch/x86/kernel/crash.c
14648 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14649 {
14650 #ifdef CONFIG_X86_32
14651 struct pt_regs fixed_regs;
14652 -#endif
14653
14654 -#ifdef CONFIG_X86_32
14655 - if (!user_mode_vm(regs)) {
14656 + if (!user_mode(regs)) {
14657 crash_fixup_ss_esp(&fixed_regs, regs);
14658 regs = &fixed_regs;
14659 }
14660 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14661 index 37250fe..bf2ec74 100644
14662 --- a/arch/x86/kernel/doublefault_32.c
14663 +++ b/arch/x86/kernel/doublefault_32.c
14664 @@ -11,7 +11,7 @@
14665
14666 #define DOUBLEFAULT_STACKSIZE (1024)
14667 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14668 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14669 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14670
14671 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14672
14673 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14674 unsigned long gdt, tss;
14675
14676 store_gdt(&gdt_desc);
14677 - gdt = gdt_desc.address;
14678 + gdt = (unsigned long)gdt_desc.address;
14679
14680 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14681
14682 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14683 /* 0x2 bit is always set */
14684 .flags = X86_EFLAGS_SF | 0x2,
14685 .sp = STACK_START,
14686 - .es = __USER_DS,
14687 + .es = __KERNEL_DS,
14688 .cs = __KERNEL_CS,
14689 .ss = __KERNEL_DS,
14690 - .ds = __USER_DS,
14691 + .ds = __KERNEL_DS,
14692 .fs = __KERNEL_PERCPU,
14693
14694 .__cr3 = __pa_nodebug(swapper_pg_dir),
14695 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14696 index ae42418b..787c16b 100644
14697 --- a/arch/x86/kernel/dumpstack.c
14698 +++ b/arch/x86/kernel/dumpstack.c
14699 @@ -2,6 +2,9 @@
14700 * Copyright (C) 1991, 1992 Linus Torvalds
14701 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14702 */
14703 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14704 +#define __INCLUDED_BY_HIDESYM 1
14705 +#endif
14706 #include <linux/kallsyms.h>
14707 #include <linux/kprobes.h>
14708 #include <linux/uaccess.h>
14709 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14710 static void
14711 print_ftrace_graph_addr(unsigned long addr, void *data,
14712 const struct stacktrace_ops *ops,
14713 - struct thread_info *tinfo, int *graph)
14714 + struct task_struct *task, int *graph)
14715 {
14716 - struct task_struct *task;
14717 unsigned long ret_addr;
14718 int index;
14719
14720 if (addr != (unsigned long)return_to_handler)
14721 return;
14722
14723 - task = tinfo->task;
14724 index = task->curr_ret_stack;
14725
14726 if (!task->ret_stack || index < *graph)
14727 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14728 static inline void
14729 print_ftrace_graph_addr(unsigned long addr, void *data,
14730 const struct stacktrace_ops *ops,
14731 - struct thread_info *tinfo, int *graph)
14732 + struct task_struct *task, int *graph)
14733 { }
14734 #endif
14735
14736 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14737 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14738 */
14739
14740 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14741 - void *p, unsigned int size, void *end)
14742 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14743 {
14744 - void *t = tinfo;
14745 if (end) {
14746 if (p < end && p >= (end-THREAD_SIZE))
14747 return 1;
14748 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14749 }
14750
14751 unsigned long
14752 -print_context_stack(struct thread_info *tinfo,
14753 +print_context_stack(struct task_struct *task, void *stack_start,
14754 unsigned long *stack, unsigned long bp,
14755 const struct stacktrace_ops *ops, void *data,
14756 unsigned long *end, int *graph)
14757 {
14758 struct stack_frame *frame = (struct stack_frame *)bp;
14759
14760 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14761 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14762 unsigned long addr;
14763
14764 addr = *stack;
14765 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14766 } else {
14767 ops->address(data, addr, 0);
14768 }
14769 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14770 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14771 }
14772 stack++;
14773 }
14774 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14775 EXPORT_SYMBOL_GPL(print_context_stack);
14776
14777 unsigned long
14778 -print_context_stack_bp(struct thread_info *tinfo,
14779 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14780 unsigned long *stack, unsigned long bp,
14781 const struct stacktrace_ops *ops, void *data,
14782 unsigned long *end, int *graph)
14783 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14784 struct stack_frame *frame = (struct stack_frame *)bp;
14785 unsigned long *ret_addr = &frame->return_address;
14786
14787 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14788 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14789 unsigned long addr = *ret_addr;
14790
14791 if (!__kernel_text_address(addr))
14792 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14793 ops->address(data, addr, 1);
14794 frame = frame->next_frame;
14795 ret_addr = &frame->return_address;
14796 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14797 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14798 }
14799
14800 return (unsigned long)frame;
14801 @@ -189,7 +188,7 @@ void dump_stack(void)
14802
14803 bp = stack_frame(current, NULL);
14804 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14805 - current->pid, current->comm, print_tainted(),
14806 + task_pid_nr(current), current->comm, print_tainted(),
14807 init_utsname()->release,
14808 (int)strcspn(init_utsname()->version, " "),
14809 init_utsname()->version);
14810 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14811 }
14812 EXPORT_SYMBOL_GPL(oops_begin);
14813
14814 +extern void gr_handle_kernel_exploit(void);
14815 +
14816 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14817 {
14818 if (regs && kexec_should_crash(current))
14819 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14820 panic("Fatal exception in interrupt");
14821 if (panic_on_oops)
14822 panic("Fatal exception");
14823 - do_exit(signr);
14824 +
14825 + gr_handle_kernel_exploit();
14826 +
14827 + do_group_exit(signr);
14828 }
14829
14830 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14831 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14832 print_modules();
14833 show_regs(regs);
14834 #ifdef CONFIG_X86_32
14835 - if (user_mode_vm(regs)) {
14836 + if (user_mode(regs)) {
14837 sp = regs->sp;
14838 ss = regs->ss & 0xffff;
14839 } else {
14840 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14841 unsigned long flags = oops_begin();
14842 int sig = SIGSEGV;
14843
14844 - if (!user_mode_vm(regs))
14845 + if (!user_mode(regs))
14846 report_bug(regs->ip, regs);
14847
14848 if (__die(str, regs, err))
14849 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14850 index 1038a41..db2c12b 100644
14851 --- a/arch/x86/kernel/dumpstack_32.c
14852 +++ b/arch/x86/kernel/dumpstack_32.c
14853 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14854 bp = stack_frame(task, regs);
14855
14856 for (;;) {
14857 - struct thread_info *context;
14858 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14859
14860 - context = (struct thread_info *)
14861 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14862 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14863 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14864
14865 - stack = (unsigned long *)context->previous_esp;
14866 - if (!stack)
14867 + if (stack_start == task_stack_page(task))
14868 break;
14869 + stack = *(unsigned long **)stack_start;
14870 if (ops->stack(data, "IRQ") < 0)
14871 break;
14872 touch_nmi_watchdog();
14873 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14874 {
14875 int i;
14876
14877 - __show_regs(regs, !user_mode_vm(regs));
14878 + __show_regs(regs, !user_mode(regs));
14879
14880 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14881 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14882 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14883 * When in-kernel, we also print out the stack and code at the
14884 * time of the fault..
14885 */
14886 - if (!user_mode_vm(regs)) {
14887 + if (!user_mode(regs)) {
14888 unsigned int code_prologue = code_bytes * 43 / 64;
14889 unsigned int code_len = code_bytes;
14890 unsigned char c;
14891 u8 *ip;
14892 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
14893
14894 pr_emerg("Stack:\n");
14895 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14896
14897 pr_emerg("Code:");
14898
14899 - ip = (u8 *)regs->ip - code_prologue;
14900 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14901 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14902 /* try starting at IP */
14903 - ip = (u8 *)regs->ip;
14904 + ip = (u8 *)regs->ip + cs_base;
14905 code_len = code_len - code_prologue + 1;
14906 }
14907 for (i = 0; i < code_len; i++, ip++) {
14908 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14909 pr_cont(" Bad EIP value.");
14910 break;
14911 }
14912 - if (ip == (u8 *)regs->ip)
14913 + if (ip == (u8 *)regs->ip + cs_base)
14914 pr_cont(" <%02x>", c);
14915 else
14916 pr_cont(" %02x", c);
14917 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14918 {
14919 unsigned short ud2;
14920
14921 + ip = ktla_ktva(ip);
14922 if (ip < PAGE_OFFSET)
14923 return 0;
14924 if (probe_kernel_address((unsigned short *)ip, ud2))
14925 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14926
14927 return ud2 == 0x0b0f;
14928 }
14929 +
14930 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14931 +void pax_check_alloca(unsigned long size)
14932 +{
14933 + unsigned long sp = (unsigned long)&sp, stack_left;
14934 +
14935 + /* all kernel stacks are of the same size */
14936 + stack_left = sp & (THREAD_SIZE - 1);
14937 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14938 +}
14939 +EXPORT_SYMBOL(pax_check_alloca);
14940 +#endif
14941 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14942 index b653675..51cc8c0 100644
14943 --- a/arch/x86/kernel/dumpstack_64.c
14944 +++ b/arch/x86/kernel/dumpstack_64.c
14945 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14946 unsigned long *irq_stack_end =
14947 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14948 unsigned used = 0;
14949 - struct thread_info *tinfo;
14950 int graph = 0;
14951 unsigned long dummy;
14952 + void *stack_start;
14953
14954 if (!task)
14955 task = current;
14956 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14957 * current stack address. If the stacks consist of nested
14958 * exceptions
14959 */
14960 - tinfo = task_thread_info(task);
14961 for (;;) {
14962 char *id;
14963 unsigned long *estack_end;
14964 +
14965 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14966 &used, &id);
14967
14968 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14969 if (ops->stack(data, id) < 0)
14970 break;
14971
14972 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14973 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14974 data, estack_end, &graph);
14975 ops->stack(data, "<EOE>");
14976 /*
14977 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14978 * second-to-last pointer (index -2 to end) in the
14979 * exception stack:
14980 */
14981 + if ((u16)estack_end[-1] != __KERNEL_DS)
14982 + goto out;
14983 stack = (unsigned long *) estack_end[-2];
14984 continue;
14985 }
14986 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14987 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14988 if (ops->stack(data, "IRQ") < 0)
14989 break;
14990 - bp = ops->walk_stack(tinfo, stack, bp,
14991 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14992 ops, data, irq_stack_end, &graph);
14993 /*
14994 * We link to the next stack (which would be
14995 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14996 /*
14997 * This handles the process stack:
14998 */
14999 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
15000 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15001 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15002 +out:
15003 put_cpu();
15004 }
15005 EXPORT_SYMBOL(dump_trace);
15006 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
15007 {
15008 int i;
15009 unsigned long sp;
15010 - const int cpu = smp_processor_id();
15011 + const int cpu = raw_smp_processor_id();
15012 struct task_struct *cur = current;
15013
15014 sp = regs->sp;
15015 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
15016
15017 return ud2 == 0x0b0f;
15018 }
15019 +
15020 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15021 +void pax_check_alloca(unsigned long size)
15022 +{
15023 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
15024 + unsigned cpu, used;
15025 + char *id;
15026 +
15027 + /* check the process stack first */
15028 + stack_start = (unsigned long)task_stack_page(current);
15029 + stack_end = stack_start + THREAD_SIZE;
15030 + if (likely(stack_start <= sp && sp < stack_end)) {
15031 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
15032 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15033 + return;
15034 + }
15035 +
15036 + cpu = get_cpu();
15037 +
15038 + /* check the irq stacks */
15039 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
15040 + stack_start = stack_end - IRQ_STACK_SIZE;
15041 + if (stack_start <= sp && sp < stack_end) {
15042 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
15043 + put_cpu();
15044 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15045 + return;
15046 + }
15047 +
15048 + /* check the exception stacks */
15049 + used = 0;
15050 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
15051 + stack_start = stack_end - EXCEPTION_STKSZ;
15052 + if (stack_end && stack_start <= sp && sp < stack_end) {
15053 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
15054 + put_cpu();
15055 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15056 + return;
15057 + }
15058 +
15059 + put_cpu();
15060 +
15061 + /* unknown stack */
15062 + BUG();
15063 +}
15064 +EXPORT_SYMBOL(pax_check_alloca);
15065 +#endif
15066 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
15067 index 9b9f18b..9fcaa04 100644
15068 --- a/arch/x86/kernel/early_printk.c
15069 +++ b/arch/x86/kernel/early_printk.c
15070 @@ -7,6 +7,7 @@
15071 #include <linux/pci_regs.h>
15072 #include <linux/pci_ids.h>
15073 #include <linux/errno.h>
15074 +#include <linux/sched.h>
15075 #include <asm/io.h>
15076 #include <asm/processor.h>
15077 #include <asm/fcntl.h>
15078 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15079 index 88b725a..3efabf6 100644
15080 --- a/arch/x86/kernel/entry_32.S
15081 +++ b/arch/x86/kernel/entry_32.S
15082 @@ -177,13 +177,153 @@
15083 /*CFI_REL_OFFSET gs, PT_GS*/
15084 .endm
15085 .macro SET_KERNEL_GS reg
15086 +
15087 +#ifdef CONFIG_CC_STACKPROTECTOR
15088 movl $(__KERNEL_STACK_CANARY), \reg
15089 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15090 + movl $(__USER_DS), \reg
15091 +#else
15092 + xorl \reg, \reg
15093 +#endif
15094 +
15095 movl \reg, %gs
15096 .endm
15097
15098 #endif /* CONFIG_X86_32_LAZY_GS */
15099
15100 -.macro SAVE_ALL
15101 +.macro pax_enter_kernel
15102 +#ifdef CONFIG_PAX_KERNEXEC
15103 + call pax_enter_kernel
15104 +#endif
15105 +.endm
15106 +
15107 +.macro pax_exit_kernel
15108 +#ifdef CONFIG_PAX_KERNEXEC
15109 + call pax_exit_kernel
15110 +#endif
15111 +.endm
15112 +
15113 +#ifdef CONFIG_PAX_KERNEXEC
15114 +ENTRY(pax_enter_kernel)
15115 +#ifdef CONFIG_PARAVIRT
15116 + pushl %eax
15117 + pushl %ecx
15118 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15119 + mov %eax, %esi
15120 +#else
15121 + mov %cr0, %esi
15122 +#endif
15123 + bts $16, %esi
15124 + jnc 1f
15125 + mov %cs, %esi
15126 + cmp $__KERNEL_CS, %esi
15127 + jz 3f
15128 + ljmp $__KERNEL_CS, $3f
15129 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15130 +2:
15131 +#ifdef CONFIG_PARAVIRT
15132 + mov %esi, %eax
15133 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15134 +#else
15135 + mov %esi, %cr0
15136 +#endif
15137 +3:
15138 +#ifdef CONFIG_PARAVIRT
15139 + popl %ecx
15140 + popl %eax
15141 +#endif
15142 + ret
15143 +ENDPROC(pax_enter_kernel)
15144 +
15145 +ENTRY(pax_exit_kernel)
15146 +#ifdef CONFIG_PARAVIRT
15147 + pushl %eax
15148 + pushl %ecx
15149 +#endif
15150 + mov %cs, %esi
15151 + cmp $__KERNEXEC_KERNEL_CS, %esi
15152 + jnz 2f
15153 +#ifdef CONFIG_PARAVIRT
15154 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15155 + mov %eax, %esi
15156 +#else
15157 + mov %cr0, %esi
15158 +#endif
15159 + btr $16, %esi
15160 + ljmp $__KERNEL_CS, $1f
15161 +1:
15162 +#ifdef CONFIG_PARAVIRT
15163 + mov %esi, %eax
15164 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15165 +#else
15166 + mov %esi, %cr0
15167 +#endif
15168 +2:
15169 +#ifdef CONFIG_PARAVIRT
15170 + popl %ecx
15171 + popl %eax
15172 +#endif
15173 + ret
15174 +ENDPROC(pax_exit_kernel)
15175 +#endif
15176 +
15177 +.macro pax_erase_kstack
15178 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15179 + call pax_erase_kstack
15180 +#endif
15181 +.endm
15182 +
15183 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15184 +/*
15185 + * ebp: thread_info
15186 + */
15187 +ENTRY(pax_erase_kstack)
15188 + pushl %edi
15189 + pushl %ecx
15190 + pushl %eax
15191 +
15192 + mov TI_lowest_stack(%ebp), %edi
15193 + mov $-0xBEEF, %eax
15194 + std
15195 +
15196 +1: mov %edi, %ecx
15197 + and $THREAD_SIZE_asm - 1, %ecx
15198 + shr $2, %ecx
15199 + repne scasl
15200 + jecxz 2f
15201 +
15202 + cmp $2*16, %ecx
15203 + jc 2f
15204 +
15205 + mov $2*16, %ecx
15206 + repe scasl
15207 + jecxz 2f
15208 + jne 1b
15209 +
15210 +2: cld
15211 + mov %esp, %ecx
15212 + sub %edi, %ecx
15213 +
15214 + cmp $THREAD_SIZE_asm, %ecx
15215 + jb 3f
15216 + ud2
15217 +3:
15218 +
15219 + shr $2, %ecx
15220 + rep stosl
15221 +
15222 + mov TI_task_thread_sp0(%ebp), %edi
15223 + sub $128, %edi
15224 + mov %edi, TI_lowest_stack(%ebp)
15225 +
15226 + popl %eax
15227 + popl %ecx
15228 + popl %edi
15229 + ret
15230 +ENDPROC(pax_erase_kstack)
15231 +#endif
15232 +
15233 +.macro __SAVE_ALL _DS
15234 cld
15235 PUSH_GS
15236 pushl_cfi %fs
15237 @@ -206,7 +346,7 @@
15238 CFI_REL_OFFSET ecx, 0
15239 pushl_cfi %ebx
15240 CFI_REL_OFFSET ebx, 0
15241 - movl $(__USER_DS), %edx
15242 + movl $\_DS, %edx
15243 movl %edx, %ds
15244 movl %edx, %es
15245 movl $(__KERNEL_PERCPU), %edx
15246 @@ -214,6 +354,15 @@
15247 SET_KERNEL_GS %edx
15248 .endm
15249
15250 +.macro SAVE_ALL
15251 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15252 + __SAVE_ALL __KERNEL_DS
15253 + pax_enter_kernel
15254 +#else
15255 + __SAVE_ALL __USER_DS
15256 +#endif
15257 +.endm
15258 +
15259 .macro RESTORE_INT_REGS
15260 popl_cfi %ebx
15261 CFI_RESTORE ebx
15262 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
15263 popfl_cfi
15264 jmp syscall_exit
15265 CFI_ENDPROC
15266 -END(ret_from_fork)
15267 +ENDPROC(ret_from_fork)
15268
15269 ENTRY(ret_from_kernel_thread)
15270 CFI_STARTPROC
15271 @@ -344,7 +493,15 @@ ret_from_intr:
15272 andl $SEGMENT_RPL_MASK, %eax
15273 #endif
15274 cmpl $USER_RPL, %eax
15275 +
15276 +#ifdef CONFIG_PAX_KERNEXEC
15277 + jae resume_userspace
15278 +
15279 + pax_exit_kernel
15280 + jmp resume_kernel
15281 +#else
15282 jb resume_kernel # not returning to v8086 or userspace
15283 +#endif
15284
15285 ENTRY(resume_userspace)
15286 LOCKDEP_SYS_EXIT
15287 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
15288 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15289 # int/exception return?
15290 jne work_pending
15291 - jmp restore_all
15292 -END(ret_from_exception)
15293 + jmp restore_all_pax
15294 +ENDPROC(ret_from_exception)
15295
15296 #ifdef CONFIG_PREEMPT
15297 ENTRY(resume_kernel)
15298 @@ -372,7 +529,7 @@ need_resched:
15299 jz restore_all
15300 call preempt_schedule_irq
15301 jmp need_resched
15302 -END(resume_kernel)
15303 +ENDPROC(resume_kernel)
15304 #endif
15305 CFI_ENDPROC
15306 /*
15307 @@ -406,30 +563,45 @@ sysenter_past_esp:
15308 /*CFI_REL_OFFSET cs, 0*/
15309 /*
15310 * Push current_thread_info()->sysenter_return to the stack.
15311 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15312 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15313 */
15314 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15315 + pushl_cfi $0
15316 CFI_REL_OFFSET eip, 0
15317
15318 pushl_cfi %eax
15319 SAVE_ALL
15320 + GET_THREAD_INFO(%ebp)
15321 + movl TI_sysenter_return(%ebp),%ebp
15322 + movl %ebp,PT_EIP(%esp)
15323 ENABLE_INTERRUPTS(CLBR_NONE)
15324
15325 /*
15326 * Load the potential sixth argument from user stack.
15327 * Careful about security.
15328 */
15329 + movl PT_OLDESP(%esp),%ebp
15330 +
15331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15332 + mov PT_OLDSS(%esp),%ds
15333 +1: movl %ds:(%ebp),%ebp
15334 + push %ss
15335 + pop %ds
15336 +#else
15337 cmpl $__PAGE_OFFSET-3,%ebp
15338 jae syscall_fault
15339 ASM_STAC
15340 1: movl (%ebp),%ebp
15341 ASM_CLAC
15342 +#endif
15343 +
15344 movl %ebp,PT_EBP(%esp)
15345 _ASM_EXTABLE(1b,syscall_fault)
15346
15347 GET_THREAD_INFO(%ebp)
15348
15349 +#ifdef CONFIG_PAX_RANDKSTACK
15350 + pax_erase_kstack
15351 +#endif
15352 +
15353 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15354 jnz sysenter_audit
15355 sysenter_do_call:
15356 @@ -444,12 +616,24 @@ sysenter_do_call:
15357 testl $_TIF_ALLWORK_MASK, %ecx
15358 jne sysexit_audit
15359 sysenter_exit:
15360 +
15361 +#ifdef CONFIG_PAX_RANDKSTACK
15362 + pushl_cfi %eax
15363 + movl %esp, %eax
15364 + call pax_randomize_kstack
15365 + popl_cfi %eax
15366 +#endif
15367 +
15368 + pax_erase_kstack
15369 +
15370 /* if something modifies registers it must also disable sysexit */
15371 movl PT_EIP(%esp), %edx
15372 movl PT_OLDESP(%esp), %ecx
15373 xorl %ebp,%ebp
15374 TRACE_IRQS_ON
15375 1: mov PT_FS(%esp), %fs
15376 +2: mov PT_DS(%esp), %ds
15377 +3: mov PT_ES(%esp), %es
15378 PTGS_TO_GS
15379 ENABLE_INTERRUPTS_SYSEXIT
15380
15381 @@ -466,6 +650,9 @@ sysenter_audit:
15382 movl %eax,%edx /* 2nd arg: syscall number */
15383 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15384 call __audit_syscall_entry
15385 +
15386 + pax_erase_kstack
15387 +
15388 pushl_cfi %ebx
15389 movl PT_EAX(%esp),%eax /* reload syscall number */
15390 jmp sysenter_do_call
15391 @@ -491,10 +678,16 @@ sysexit_audit:
15392
15393 CFI_ENDPROC
15394 .pushsection .fixup,"ax"
15395 -2: movl $0,PT_FS(%esp)
15396 +4: movl $0,PT_FS(%esp)
15397 + jmp 1b
15398 +5: movl $0,PT_DS(%esp)
15399 + jmp 1b
15400 +6: movl $0,PT_ES(%esp)
15401 jmp 1b
15402 .popsection
15403 - _ASM_EXTABLE(1b,2b)
15404 + _ASM_EXTABLE(1b,4b)
15405 + _ASM_EXTABLE(2b,5b)
15406 + _ASM_EXTABLE(3b,6b)
15407 PTGS_TO_GS_EX
15408 ENDPROC(ia32_sysenter_target)
15409
15410 @@ -509,6 +702,11 @@ ENTRY(system_call)
15411 pushl_cfi %eax # save orig_eax
15412 SAVE_ALL
15413 GET_THREAD_INFO(%ebp)
15414 +
15415 +#ifdef CONFIG_PAX_RANDKSTACK
15416 + pax_erase_kstack
15417 +#endif
15418 +
15419 # system call tracing in operation / emulation
15420 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15421 jnz syscall_trace_entry
15422 @@ -527,6 +725,15 @@ syscall_exit:
15423 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15424 jne syscall_exit_work
15425
15426 +restore_all_pax:
15427 +
15428 +#ifdef CONFIG_PAX_RANDKSTACK
15429 + movl %esp, %eax
15430 + call pax_randomize_kstack
15431 +#endif
15432 +
15433 + pax_erase_kstack
15434 +
15435 restore_all:
15436 TRACE_IRQS_IRET
15437 restore_all_notrace:
15438 @@ -583,14 +790,34 @@ ldt_ss:
15439 * compensating for the offset by changing to the ESPFIX segment with
15440 * a base address that matches for the difference.
15441 */
15442 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15443 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15444 mov %esp, %edx /* load kernel esp */
15445 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15446 mov %dx, %ax /* eax: new kernel esp */
15447 sub %eax, %edx /* offset (low word is 0) */
15448 +#ifdef CONFIG_SMP
15449 + movl PER_CPU_VAR(cpu_number), %ebx
15450 + shll $PAGE_SHIFT_asm, %ebx
15451 + addl $cpu_gdt_table, %ebx
15452 +#else
15453 + movl $cpu_gdt_table, %ebx
15454 +#endif
15455 shr $16, %edx
15456 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15457 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15458 +
15459 +#ifdef CONFIG_PAX_KERNEXEC
15460 + mov %cr0, %esi
15461 + btr $16, %esi
15462 + mov %esi, %cr0
15463 +#endif
15464 +
15465 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15466 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15467 +
15468 +#ifdef CONFIG_PAX_KERNEXEC
15469 + bts $16, %esi
15470 + mov %esi, %cr0
15471 +#endif
15472 +
15473 pushl_cfi $__ESPFIX_SS
15474 pushl_cfi %eax /* new kernel esp */
15475 /* Disable interrupts, but do not irqtrace this section: we
15476 @@ -619,20 +846,18 @@ work_resched:
15477 movl TI_flags(%ebp), %ecx
15478 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15479 # than syscall tracing?
15480 - jz restore_all
15481 + jz restore_all_pax
15482 testb $_TIF_NEED_RESCHED, %cl
15483 jnz work_resched
15484
15485 work_notifysig: # deal with pending signals and
15486 # notify-resume requests
15487 + movl %esp, %eax
15488 #ifdef CONFIG_VM86
15489 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15490 - movl %esp, %eax
15491 jne work_notifysig_v86 # returning to kernel-space or
15492 # vm86-space
15493 1:
15494 -#else
15495 - movl %esp, %eax
15496 #endif
15497 TRACE_IRQS_ON
15498 ENABLE_INTERRUPTS(CLBR_NONE)
15499 @@ -653,7 +878,7 @@ work_notifysig_v86:
15500 movl %eax, %esp
15501 jmp 1b
15502 #endif
15503 -END(work_pending)
15504 +ENDPROC(work_pending)
15505
15506 # perform syscall exit tracing
15507 ALIGN
15508 @@ -661,11 +886,14 @@ syscall_trace_entry:
15509 movl $-ENOSYS,PT_EAX(%esp)
15510 movl %esp, %eax
15511 call syscall_trace_enter
15512 +
15513 + pax_erase_kstack
15514 +
15515 /* What it returned is what we'll actually use. */
15516 cmpl $(NR_syscalls), %eax
15517 jnae syscall_call
15518 jmp syscall_exit
15519 -END(syscall_trace_entry)
15520 +ENDPROC(syscall_trace_entry)
15521
15522 # perform syscall exit tracing
15523 ALIGN
15524 @@ -678,21 +906,25 @@ syscall_exit_work:
15525 movl %esp, %eax
15526 call syscall_trace_leave
15527 jmp resume_userspace
15528 -END(syscall_exit_work)
15529 +ENDPROC(syscall_exit_work)
15530 CFI_ENDPROC
15531
15532 RING0_INT_FRAME # can't unwind into user space anyway
15533 syscall_fault:
15534 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15535 + push %ss
15536 + pop %ds
15537 +#endif
15538 ASM_CLAC
15539 GET_THREAD_INFO(%ebp)
15540 movl $-EFAULT,PT_EAX(%esp)
15541 jmp resume_userspace
15542 -END(syscall_fault)
15543 +ENDPROC(syscall_fault)
15544
15545 syscall_badsys:
15546 movl $-ENOSYS,PT_EAX(%esp)
15547 jmp resume_userspace
15548 -END(syscall_badsys)
15549 +ENDPROC(syscall_badsys)
15550 CFI_ENDPROC
15551 /*
15552 * End of kprobes section
15553 @@ -763,6 +995,36 @@ ENTRY(ptregs_clone)
15554 CFI_ENDPROC
15555 ENDPROC(ptregs_clone)
15556
15557 + ALIGN;
15558 +ENTRY(kernel_execve)
15559 + CFI_STARTPROC
15560 + pushl_cfi %ebp
15561 + sub $PT_OLDSS+4,%esp
15562 + pushl_cfi %edi
15563 + pushl_cfi %ecx
15564 + pushl_cfi %eax
15565 + lea 3*4(%esp),%edi
15566 + mov $PT_OLDSS/4+1,%ecx
15567 + xorl %eax,%eax
15568 + rep stosl
15569 + popl_cfi %eax
15570 + popl_cfi %ecx
15571 + popl_cfi %edi
15572 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15573 + pushl_cfi %esp
15574 + call sys_execve
15575 + add $4,%esp
15576 + CFI_ADJUST_CFA_OFFSET -4
15577 + GET_THREAD_INFO(%ebp)
15578 + test %eax,%eax
15579 + jz syscall_exit
15580 + add $PT_OLDSS+4,%esp
15581 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15582 + popl_cfi %ebp
15583 + ret
15584 + CFI_ENDPROC
15585 +ENDPROC(kernel_execve)
15586 +
15587 .macro FIXUP_ESPFIX_STACK
15588 /*
15589 * Switch back for ESPFIX stack to the normal zerobased stack
15590 @@ -772,8 +1034,15 @@ ENDPROC(ptregs_clone)
15591 * normal stack and adjusts ESP with the matching offset.
15592 */
15593 /* fixup the stack */
15594 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15595 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15596 +#ifdef CONFIG_SMP
15597 + movl PER_CPU_VAR(cpu_number), %ebx
15598 + shll $PAGE_SHIFT_asm, %ebx
15599 + addl $cpu_gdt_table, %ebx
15600 +#else
15601 + movl $cpu_gdt_table, %ebx
15602 +#endif
15603 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15604 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15605 shl $16, %eax
15606 addl %esp, %eax /* the adjusted stack pointer */
15607 pushl_cfi $__KERNEL_DS
15608 @@ -826,7 +1095,7 @@ vector=vector+1
15609 .endr
15610 2: jmp common_interrupt
15611 .endr
15612 -END(irq_entries_start)
15613 +ENDPROC(irq_entries_start)
15614
15615 .previous
15616 END(interrupt)
15617 @@ -877,7 +1146,7 @@ ENTRY(coprocessor_error)
15618 pushl_cfi $do_coprocessor_error
15619 jmp error_code
15620 CFI_ENDPROC
15621 -END(coprocessor_error)
15622 +ENDPROC(coprocessor_error)
15623
15624 ENTRY(simd_coprocessor_error)
15625 RING0_INT_FRAME
15626 @@ -899,7 +1168,7 @@ ENTRY(simd_coprocessor_error)
15627 #endif
15628 jmp error_code
15629 CFI_ENDPROC
15630 -END(simd_coprocessor_error)
15631 +ENDPROC(simd_coprocessor_error)
15632
15633 ENTRY(device_not_available)
15634 RING0_INT_FRAME
15635 @@ -908,18 +1177,18 @@ ENTRY(device_not_available)
15636 pushl_cfi $do_device_not_available
15637 jmp error_code
15638 CFI_ENDPROC
15639 -END(device_not_available)
15640 +ENDPROC(device_not_available)
15641
15642 #ifdef CONFIG_PARAVIRT
15643 ENTRY(native_iret)
15644 iret
15645 _ASM_EXTABLE(native_iret, iret_exc)
15646 -END(native_iret)
15647 +ENDPROC(native_iret)
15648
15649 ENTRY(native_irq_enable_sysexit)
15650 sti
15651 sysexit
15652 -END(native_irq_enable_sysexit)
15653 +ENDPROC(native_irq_enable_sysexit)
15654 #endif
15655
15656 ENTRY(overflow)
15657 @@ -929,7 +1198,7 @@ ENTRY(overflow)
15658 pushl_cfi $do_overflow
15659 jmp error_code
15660 CFI_ENDPROC
15661 -END(overflow)
15662 +ENDPROC(overflow)
15663
15664 ENTRY(bounds)
15665 RING0_INT_FRAME
15666 @@ -938,7 +1207,7 @@ ENTRY(bounds)
15667 pushl_cfi $do_bounds
15668 jmp error_code
15669 CFI_ENDPROC
15670 -END(bounds)
15671 +ENDPROC(bounds)
15672
15673 ENTRY(invalid_op)
15674 RING0_INT_FRAME
15675 @@ -947,7 +1216,7 @@ ENTRY(invalid_op)
15676 pushl_cfi $do_invalid_op
15677 jmp error_code
15678 CFI_ENDPROC
15679 -END(invalid_op)
15680 +ENDPROC(invalid_op)
15681
15682 ENTRY(coprocessor_segment_overrun)
15683 RING0_INT_FRAME
15684 @@ -956,7 +1225,7 @@ ENTRY(coprocessor_segment_overrun)
15685 pushl_cfi $do_coprocessor_segment_overrun
15686 jmp error_code
15687 CFI_ENDPROC
15688 -END(coprocessor_segment_overrun)
15689 +ENDPROC(coprocessor_segment_overrun)
15690
15691 ENTRY(invalid_TSS)
15692 RING0_EC_FRAME
15693 @@ -964,7 +1233,7 @@ ENTRY(invalid_TSS)
15694 pushl_cfi $do_invalid_TSS
15695 jmp error_code
15696 CFI_ENDPROC
15697 -END(invalid_TSS)
15698 +ENDPROC(invalid_TSS)
15699
15700 ENTRY(segment_not_present)
15701 RING0_EC_FRAME
15702 @@ -972,7 +1241,7 @@ ENTRY(segment_not_present)
15703 pushl_cfi $do_segment_not_present
15704 jmp error_code
15705 CFI_ENDPROC
15706 -END(segment_not_present)
15707 +ENDPROC(segment_not_present)
15708
15709 ENTRY(stack_segment)
15710 RING0_EC_FRAME
15711 @@ -980,7 +1249,7 @@ ENTRY(stack_segment)
15712 pushl_cfi $do_stack_segment
15713 jmp error_code
15714 CFI_ENDPROC
15715 -END(stack_segment)
15716 +ENDPROC(stack_segment)
15717
15718 ENTRY(alignment_check)
15719 RING0_EC_FRAME
15720 @@ -988,7 +1257,7 @@ ENTRY(alignment_check)
15721 pushl_cfi $do_alignment_check
15722 jmp error_code
15723 CFI_ENDPROC
15724 -END(alignment_check)
15725 +ENDPROC(alignment_check)
15726
15727 ENTRY(divide_error)
15728 RING0_INT_FRAME
15729 @@ -997,7 +1266,7 @@ ENTRY(divide_error)
15730 pushl_cfi $do_divide_error
15731 jmp error_code
15732 CFI_ENDPROC
15733 -END(divide_error)
15734 +ENDPROC(divide_error)
15735
15736 #ifdef CONFIG_X86_MCE
15737 ENTRY(machine_check)
15738 @@ -1007,7 +1276,7 @@ ENTRY(machine_check)
15739 pushl_cfi machine_check_vector
15740 jmp error_code
15741 CFI_ENDPROC
15742 -END(machine_check)
15743 +ENDPROC(machine_check)
15744 #endif
15745
15746 ENTRY(spurious_interrupt_bug)
15747 @@ -1017,7 +1286,7 @@ ENTRY(spurious_interrupt_bug)
15748 pushl_cfi $do_spurious_interrupt_bug
15749 jmp error_code
15750 CFI_ENDPROC
15751 -END(spurious_interrupt_bug)
15752 +ENDPROC(spurious_interrupt_bug)
15753 /*
15754 * End of kprobes section
15755 */
15756 @@ -1121,7 +1390,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15757
15758 ENTRY(mcount)
15759 ret
15760 -END(mcount)
15761 +ENDPROC(mcount)
15762
15763 ENTRY(ftrace_caller)
15764 cmpl $0, function_trace_stop
15765 @@ -1154,7 +1423,7 @@ ftrace_graph_call:
15766 .globl ftrace_stub
15767 ftrace_stub:
15768 ret
15769 -END(ftrace_caller)
15770 +ENDPROC(ftrace_caller)
15771
15772 ENTRY(ftrace_regs_caller)
15773 pushf /* push flags before compare (in cs location) */
15774 @@ -1255,7 +1524,7 @@ trace:
15775 popl %ecx
15776 popl %eax
15777 jmp ftrace_stub
15778 -END(mcount)
15779 +ENDPROC(mcount)
15780 #endif /* CONFIG_DYNAMIC_FTRACE */
15781 #endif /* CONFIG_FUNCTION_TRACER */
15782
15783 @@ -1273,7 +1542,7 @@ ENTRY(ftrace_graph_caller)
15784 popl %ecx
15785 popl %eax
15786 ret
15787 -END(ftrace_graph_caller)
15788 +ENDPROC(ftrace_graph_caller)
15789
15790 .globl return_to_handler
15791 return_to_handler:
15792 @@ -1329,15 +1598,18 @@ error_code:
15793 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15794 REG_TO_PTGS %ecx
15795 SET_KERNEL_GS %ecx
15796 - movl $(__USER_DS), %ecx
15797 + movl $(__KERNEL_DS), %ecx
15798 movl %ecx, %ds
15799 movl %ecx, %es
15800 +
15801 + pax_enter_kernel
15802 +
15803 TRACE_IRQS_OFF
15804 movl %esp,%eax # pt_regs pointer
15805 call *%edi
15806 jmp ret_from_exception
15807 CFI_ENDPROC
15808 -END(page_fault)
15809 +ENDPROC(page_fault)
15810
15811 /*
15812 * Debug traps and NMI can happen at the one SYSENTER instruction
15813 @@ -1380,7 +1652,7 @@ debug_stack_correct:
15814 call do_debug
15815 jmp ret_from_exception
15816 CFI_ENDPROC
15817 -END(debug)
15818 +ENDPROC(debug)
15819
15820 /*
15821 * NMI is doubly nasty. It can happen _while_ we're handling
15822 @@ -1418,6 +1690,9 @@ nmi_stack_correct:
15823 xorl %edx,%edx # zero error code
15824 movl %esp,%eax # pt_regs pointer
15825 call do_nmi
15826 +
15827 + pax_exit_kernel
15828 +
15829 jmp restore_all_notrace
15830 CFI_ENDPROC
15831
15832 @@ -1454,12 +1729,15 @@ nmi_espfix_stack:
15833 FIXUP_ESPFIX_STACK # %eax == %esp
15834 xorl %edx,%edx # zero error code
15835 call do_nmi
15836 +
15837 + pax_exit_kernel
15838 +
15839 RESTORE_REGS
15840 lss 12+4(%esp), %esp # back to espfix stack
15841 CFI_ADJUST_CFA_OFFSET -24
15842 jmp irq_return
15843 CFI_ENDPROC
15844 -END(nmi)
15845 +ENDPROC(nmi)
15846
15847 ENTRY(int3)
15848 RING0_INT_FRAME
15849 @@ -1472,14 +1750,14 @@ ENTRY(int3)
15850 call do_int3
15851 jmp ret_from_exception
15852 CFI_ENDPROC
15853 -END(int3)
15854 +ENDPROC(int3)
15855
15856 ENTRY(general_protection)
15857 RING0_EC_FRAME
15858 pushl_cfi $do_general_protection
15859 jmp error_code
15860 CFI_ENDPROC
15861 -END(general_protection)
15862 +ENDPROC(general_protection)
15863
15864 #ifdef CONFIG_KVM_GUEST
15865 ENTRY(async_page_fault)
15866 @@ -1488,7 +1766,7 @@ ENTRY(async_page_fault)
15867 pushl_cfi $do_async_page_fault
15868 jmp error_code
15869 CFI_ENDPROC
15870 -END(async_page_fault)
15871 +ENDPROC(async_page_fault)
15872 #endif
15873
15874 /*
15875 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15876 index 1328fe4..cb03298 100644
15877 --- a/arch/x86/kernel/entry_64.S
15878 +++ b/arch/x86/kernel/entry_64.S
15879 @@ -59,6 +59,8 @@
15880 #include <asm/rcu.h>
15881 #include <asm/smap.h>
15882 #include <linux/err.h>
15883 +#include <asm/pgtable.h>
15884 +#include <asm/alternative-asm.h>
15885
15886 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15887 #include <linux/elf-em.h>
15888 @@ -80,8 +82,9 @@
15889 #ifdef CONFIG_DYNAMIC_FTRACE
15890
15891 ENTRY(function_hook)
15892 + pax_force_retaddr
15893 retq
15894 -END(function_hook)
15895 +ENDPROC(function_hook)
15896
15897 /* skip is set if stack has been adjusted */
15898 .macro ftrace_caller_setup skip=0
15899 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
15900 #endif
15901
15902 GLOBAL(ftrace_stub)
15903 + pax_force_retaddr
15904 retq
15905 -END(ftrace_caller)
15906 +ENDPROC(ftrace_caller)
15907
15908 ENTRY(ftrace_regs_caller)
15909 /* Save the current flags before compare (in SS location)*/
15910 @@ -191,7 +195,7 @@ ftrace_restore_flags:
15911 popfq
15912 jmp ftrace_stub
15913
15914 -END(ftrace_regs_caller)
15915 +ENDPROC(ftrace_regs_caller)
15916
15917
15918 #else /* ! CONFIG_DYNAMIC_FTRACE */
15919 @@ -212,6 +216,7 @@ ENTRY(function_hook)
15920 #endif
15921
15922 GLOBAL(ftrace_stub)
15923 + pax_force_retaddr
15924 retq
15925
15926 trace:
15927 @@ -225,12 +230,13 @@ trace:
15928 #endif
15929 subq $MCOUNT_INSN_SIZE, %rdi
15930
15931 + pax_force_fptr ftrace_trace_function
15932 call *ftrace_trace_function
15933
15934 MCOUNT_RESTORE_FRAME
15935
15936 jmp ftrace_stub
15937 -END(function_hook)
15938 +ENDPROC(function_hook)
15939 #endif /* CONFIG_DYNAMIC_FTRACE */
15940 #endif /* CONFIG_FUNCTION_TRACER */
15941
15942 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
15943
15944 MCOUNT_RESTORE_FRAME
15945
15946 + pax_force_retaddr
15947 retq
15948 -END(ftrace_graph_caller)
15949 +ENDPROC(ftrace_graph_caller)
15950
15951 GLOBAL(return_to_handler)
15952 subq $24, %rsp
15953 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
15954 movq 8(%rsp), %rdx
15955 movq (%rsp), %rax
15956 addq $24, %rsp
15957 + pax_force_fptr %rdi
15958 jmp *%rdi
15959 +ENDPROC(return_to_handler)
15960 #endif
15961
15962
15963 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
15964 ENDPROC(native_usergs_sysret64)
15965 #endif /* CONFIG_PARAVIRT */
15966
15967 + .macro ljmpq sel, off
15968 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15969 + .byte 0x48; ljmp *1234f(%rip)
15970 + .pushsection .rodata
15971 + .align 16
15972 + 1234: .quad \off; .word \sel
15973 + .popsection
15974 +#else
15975 + pushq $\sel
15976 + pushq $\off
15977 + lretq
15978 +#endif
15979 + .endm
15980 +
15981 + .macro pax_enter_kernel
15982 + pax_set_fptr_mask
15983 +#ifdef CONFIG_PAX_KERNEXEC
15984 + call pax_enter_kernel
15985 +#endif
15986 + .endm
15987 +
15988 + .macro pax_exit_kernel
15989 +#ifdef CONFIG_PAX_KERNEXEC
15990 + call pax_exit_kernel
15991 +#endif
15992 + .endm
15993 +
15994 +#ifdef CONFIG_PAX_KERNEXEC
15995 +ENTRY(pax_enter_kernel)
15996 + pushq %rdi
15997 +
15998 +#ifdef CONFIG_PARAVIRT
15999 + PV_SAVE_REGS(CLBR_RDI)
16000 +#endif
16001 +
16002 + GET_CR0_INTO_RDI
16003 + bts $16,%rdi
16004 + jnc 3f
16005 + mov %cs,%edi
16006 + cmp $__KERNEL_CS,%edi
16007 + jnz 2f
16008 +1:
16009 +
16010 +#ifdef CONFIG_PARAVIRT
16011 + PV_RESTORE_REGS(CLBR_RDI)
16012 +#endif
16013 +
16014 + popq %rdi
16015 + pax_force_retaddr
16016 + retq
16017 +
16018 +2: ljmpq __KERNEL_CS,1f
16019 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
16020 +4: SET_RDI_INTO_CR0
16021 + jmp 1b
16022 +ENDPROC(pax_enter_kernel)
16023 +
16024 +ENTRY(pax_exit_kernel)
16025 + pushq %rdi
16026 +
16027 +#ifdef CONFIG_PARAVIRT
16028 + PV_SAVE_REGS(CLBR_RDI)
16029 +#endif
16030 +
16031 + mov %cs,%rdi
16032 + cmp $__KERNEXEC_KERNEL_CS,%edi
16033 + jz 2f
16034 +1:
16035 +
16036 +#ifdef CONFIG_PARAVIRT
16037 + PV_RESTORE_REGS(CLBR_RDI);
16038 +#endif
16039 +
16040 + popq %rdi
16041 + pax_force_retaddr
16042 + retq
16043 +
16044 +2: GET_CR0_INTO_RDI
16045 + btr $16,%rdi
16046 + ljmpq __KERNEL_CS,3f
16047 +3: SET_RDI_INTO_CR0
16048 + jmp 1b
16049 +ENDPROC(pax_exit_kernel)
16050 +#endif
16051 +
16052 + .macro pax_enter_kernel_user
16053 + pax_set_fptr_mask
16054 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16055 + call pax_enter_kernel_user
16056 +#endif
16057 + .endm
16058 +
16059 + .macro pax_exit_kernel_user
16060 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16061 + call pax_exit_kernel_user
16062 +#endif
16063 +#ifdef CONFIG_PAX_RANDKSTACK
16064 + pushq %rax
16065 + call pax_randomize_kstack
16066 + popq %rax
16067 +#endif
16068 + .endm
16069 +
16070 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16071 +ENTRY(pax_enter_kernel_user)
16072 + pushq %rdi
16073 + pushq %rbx
16074 +
16075 +#ifdef CONFIG_PARAVIRT
16076 + PV_SAVE_REGS(CLBR_RDI)
16077 +#endif
16078 +
16079 + GET_CR3_INTO_RDI
16080 + mov %rdi,%rbx
16081 + add $__START_KERNEL_map,%rbx
16082 + sub phys_base(%rip),%rbx
16083 +
16084 +#ifdef CONFIG_PARAVIRT
16085 + pushq %rdi
16086 + cmpl $0, pv_info+PARAVIRT_enabled
16087 + jz 1f
16088 + i = 0
16089 + .rept USER_PGD_PTRS
16090 + mov i*8(%rbx),%rsi
16091 + mov $0,%sil
16092 + lea i*8(%rbx),%rdi
16093 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16094 + i = i + 1
16095 + .endr
16096 + jmp 2f
16097 +1:
16098 +#endif
16099 +
16100 + i = 0
16101 + .rept USER_PGD_PTRS
16102 + movb $0,i*8(%rbx)
16103 + i = i + 1
16104 + .endr
16105 +
16106 +#ifdef CONFIG_PARAVIRT
16107 +2: popq %rdi
16108 +#endif
16109 + SET_RDI_INTO_CR3
16110 +
16111 +#ifdef CONFIG_PAX_KERNEXEC
16112 + GET_CR0_INTO_RDI
16113 + bts $16,%rdi
16114 + SET_RDI_INTO_CR0
16115 +#endif
16116 +
16117 +#ifdef CONFIG_PARAVIRT
16118 + PV_RESTORE_REGS(CLBR_RDI)
16119 +#endif
16120 +
16121 + popq %rbx
16122 + popq %rdi
16123 + pax_force_retaddr
16124 + retq
16125 +ENDPROC(pax_enter_kernel_user)
16126 +
16127 +ENTRY(pax_exit_kernel_user)
16128 + push %rdi
16129 +
16130 +#ifdef CONFIG_PARAVIRT
16131 + pushq %rbx
16132 + PV_SAVE_REGS(CLBR_RDI)
16133 +#endif
16134 +
16135 +#ifdef CONFIG_PAX_KERNEXEC
16136 + GET_CR0_INTO_RDI
16137 + btr $16,%rdi
16138 + SET_RDI_INTO_CR0
16139 +#endif
16140 +
16141 + GET_CR3_INTO_RDI
16142 + add $__START_KERNEL_map,%rdi
16143 + sub phys_base(%rip),%rdi
16144 +
16145 +#ifdef CONFIG_PARAVIRT
16146 + cmpl $0, pv_info+PARAVIRT_enabled
16147 + jz 1f
16148 + mov %rdi,%rbx
16149 + i = 0
16150 + .rept USER_PGD_PTRS
16151 + mov i*8(%rbx),%rsi
16152 + mov $0x67,%sil
16153 + lea i*8(%rbx),%rdi
16154 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16155 + i = i + 1
16156 + .endr
16157 + jmp 2f
16158 +1:
16159 +#endif
16160 +
16161 + i = 0
16162 + .rept USER_PGD_PTRS
16163 + movb $0x67,i*8(%rdi)
16164 + i = i + 1
16165 + .endr
16166 +
16167 +#ifdef CONFIG_PARAVIRT
16168 +2: PV_RESTORE_REGS(CLBR_RDI)
16169 + popq %rbx
16170 +#endif
16171 +
16172 + popq %rdi
16173 + pax_force_retaddr
16174 + retq
16175 +ENDPROC(pax_exit_kernel_user)
16176 +#endif
16177 +
16178 +.macro pax_erase_kstack
16179 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16180 + call pax_erase_kstack
16181 +#endif
16182 +.endm
16183 +
16184 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16185 +ENTRY(pax_erase_kstack)
16186 + pushq %rdi
16187 + pushq %rcx
16188 + pushq %rax
16189 + pushq %r11
16190 +
16191 + GET_THREAD_INFO(%r11)
16192 + mov TI_lowest_stack(%r11), %rdi
16193 + mov $-0xBEEF, %rax
16194 + std
16195 +
16196 +1: mov %edi, %ecx
16197 + and $THREAD_SIZE_asm - 1, %ecx
16198 + shr $3, %ecx
16199 + repne scasq
16200 + jecxz 2f
16201 +
16202 + cmp $2*8, %ecx
16203 + jc 2f
16204 +
16205 + mov $2*8, %ecx
16206 + repe scasq
16207 + jecxz 2f
16208 + jne 1b
16209 +
16210 +2: cld
16211 + mov %esp, %ecx
16212 + sub %edi, %ecx
16213 +
16214 + cmp $THREAD_SIZE_asm, %rcx
16215 + jb 3f
16216 + ud2
16217 +3:
16218 +
16219 + shr $3, %ecx
16220 + rep stosq
16221 +
16222 + mov TI_task_thread_sp0(%r11), %rdi
16223 + sub $256, %rdi
16224 + mov %rdi, TI_lowest_stack(%r11)
16225 +
16226 + popq %r11
16227 + popq %rax
16228 + popq %rcx
16229 + popq %rdi
16230 + pax_force_retaddr
16231 + ret
16232 +ENDPROC(pax_erase_kstack)
16233 +#endif
16234
16235 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16236 #ifdef CONFIG_TRACE_IRQFLAGS
16237 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
16238 .endm
16239
16240 .macro UNFAKE_STACK_FRAME
16241 - addq $8*6, %rsp
16242 - CFI_ADJUST_CFA_OFFSET -(6*8)
16243 + addq $8*6 + ARG_SKIP, %rsp
16244 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16245 .endm
16246
16247 /*
16248 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
16249 movq %rsp, %rsi
16250
16251 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16252 - testl $3, CS-RBP(%rsi)
16253 + testb $3, CS-RBP(%rsi)
16254 je 1f
16255 SWAPGS
16256 /*
16257 @@ -498,9 +774,10 @@ ENTRY(save_rest)
16258 movq_cfi r15, R15+16
16259 movq %r11, 8(%rsp) /* return address */
16260 FIXUP_TOP_OF_STACK %r11, 16
16261 + pax_force_retaddr
16262 ret
16263 CFI_ENDPROC
16264 -END(save_rest)
16265 +ENDPROC(save_rest)
16266
16267 /* save complete stack frame */
16268 .pushsection .kprobes.text, "ax"
16269 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
16270 js 1f /* negative -> in kernel */
16271 SWAPGS
16272 xorl %ebx,%ebx
16273 -1: ret
16274 +1: pax_force_retaddr_bts
16275 + ret
16276 CFI_ENDPROC
16277 -END(save_paranoid)
16278 +ENDPROC(save_paranoid)
16279 .popsection
16280
16281 /*
16282 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
16283
16284 RESTORE_REST
16285
16286 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16287 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16288 jz 1f
16289
16290 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16291 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
16292 RESTORE_REST
16293 jmp int_ret_from_sys_call
16294 CFI_ENDPROC
16295 -END(ret_from_fork)
16296 +ENDPROC(ret_from_fork)
16297
16298 /*
16299 * System call entry. Up to 6 arguments in registers are supported.
16300 @@ -608,7 +886,7 @@ END(ret_from_fork)
16301 ENTRY(system_call)
16302 CFI_STARTPROC simple
16303 CFI_SIGNAL_FRAME
16304 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16305 + CFI_DEF_CFA rsp,0
16306 CFI_REGISTER rip,rcx
16307 /*CFI_REGISTER rflags,r11*/
16308 SWAPGS_UNSAFE_STACK
16309 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
16310
16311 movq %rsp,PER_CPU_VAR(old_rsp)
16312 movq PER_CPU_VAR(kernel_stack),%rsp
16313 + SAVE_ARGS 8*6,0
16314 + pax_enter_kernel_user
16315 +
16316 +#ifdef CONFIG_PAX_RANDKSTACK
16317 + pax_erase_kstack
16318 +#endif
16319 +
16320 /*
16321 * No need to follow this irqs off/on section - it's straight
16322 * and short:
16323 */
16324 ENABLE_INTERRUPTS(CLBR_NONE)
16325 - SAVE_ARGS 8,0
16326 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16327 movq %rcx,RIP-ARGOFFSET(%rsp)
16328 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16329 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16330 + GET_THREAD_INFO(%rcx)
16331 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16332 jnz tracesys
16333 system_call_fastpath:
16334 #if __SYSCALL_MASK == ~0
16335 @@ -640,7 +925,7 @@ system_call_fastpath:
16336 cmpl $__NR_syscall_max,%eax
16337 #endif
16338 ja badsys
16339 - movq %r10,%rcx
16340 + movq R10-ARGOFFSET(%rsp),%rcx
16341 call *sys_call_table(,%rax,8) # XXX: rip relative
16342 movq %rax,RAX-ARGOFFSET(%rsp)
16343 /*
16344 @@ -654,10 +939,13 @@ sysret_check:
16345 LOCKDEP_SYS_EXIT
16346 DISABLE_INTERRUPTS(CLBR_NONE)
16347 TRACE_IRQS_OFF
16348 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16349 + GET_THREAD_INFO(%rcx)
16350 + movl TI_flags(%rcx),%edx
16351 andl %edi,%edx
16352 jnz sysret_careful
16353 CFI_REMEMBER_STATE
16354 + pax_exit_kernel_user
16355 + pax_erase_kstack
16356 /*
16357 * sysretq will re-enable interrupts:
16358 */
16359 @@ -709,14 +997,18 @@ badsys:
16360 * jump back to the normal fast path.
16361 */
16362 auditsys:
16363 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16364 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16365 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16366 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16367 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16368 movq %rax,%rsi /* 2nd arg: syscall number */
16369 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16370 call __audit_syscall_entry
16371 +
16372 + pax_erase_kstack
16373 +
16374 LOAD_ARGS 0 /* reload call-clobbered registers */
16375 + pax_set_fptr_mask
16376 jmp system_call_fastpath
16377
16378 /*
16379 @@ -737,7 +1029,7 @@ sysret_audit:
16380 /* Do syscall tracing */
16381 tracesys:
16382 #ifdef CONFIG_AUDITSYSCALL
16383 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16384 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16385 jz auditsys
16386 #endif
16387 SAVE_REST
16388 @@ -745,12 +1037,16 @@ tracesys:
16389 FIXUP_TOP_OF_STACK %rdi
16390 movq %rsp,%rdi
16391 call syscall_trace_enter
16392 +
16393 + pax_erase_kstack
16394 +
16395 /*
16396 * Reload arg registers from stack in case ptrace changed them.
16397 * We don't reload %rax because syscall_trace_enter() returned
16398 * the value it wants us to use in the table lookup.
16399 */
16400 LOAD_ARGS ARGOFFSET, 1
16401 + pax_set_fptr_mask
16402 RESTORE_REST
16403 #if __SYSCALL_MASK == ~0
16404 cmpq $__NR_syscall_max,%rax
16405 @@ -759,7 +1055,7 @@ tracesys:
16406 cmpl $__NR_syscall_max,%eax
16407 #endif
16408 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16409 - movq %r10,%rcx /* fixup for C */
16410 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16411 call *sys_call_table(,%rax,8)
16412 movq %rax,RAX-ARGOFFSET(%rsp)
16413 /* Use IRET because user could have changed frame */
16414 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
16415 andl %edi,%edx
16416 jnz int_careful
16417 andl $~TS_COMPAT,TI_status(%rcx)
16418 - jmp retint_swapgs
16419 + pax_exit_kernel_user
16420 + pax_erase_kstack
16421 + jmp retint_swapgs_pax
16422
16423 /* Either reschedule or signal or syscall exit tracking needed. */
16424 /* First do a reschedule test. */
16425 @@ -826,7 +1124,7 @@ int_restore_rest:
16426 TRACE_IRQS_OFF
16427 jmp int_with_check
16428 CFI_ENDPROC
16429 -END(system_call)
16430 +ENDPROC(system_call)
16431
16432 /*
16433 * Certain special system calls that need to save a complete full stack frame.
16434 @@ -842,7 +1140,7 @@ ENTRY(\label)
16435 call \func
16436 jmp ptregscall_common
16437 CFI_ENDPROC
16438 -END(\label)
16439 +ENDPROC(\label)
16440 .endm
16441
16442 PTREGSCALL stub_clone, sys_clone, %r8
16443 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
16444 movq_cfi_restore R12+8, r12
16445 movq_cfi_restore RBP+8, rbp
16446 movq_cfi_restore RBX+8, rbx
16447 + pax_force_retaddr
16448 ret $REST_SKIP /* pop extended registers */
16449 CFI_ENDPROC
16450 -END(ptregscall_common)
16451 +ENDPROC(ptregscall_common)
16452
16453 ENTRY(stub_execve)
16454 CFI_STARTPROC
16455 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
16456 RESTORE_REST
16457 jmp int_ret_from_sys_call
16458 CFI_ENDPROC
16459 -END(stub_execve)
16460 +ENDPROC(stub_execve)
16461
16462 /*
16463 * sigreturn is special because it needs to restore all registers on return.
16464 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
16465 RESTORE_REST
16466 jmp int_ret_from_sys_call
16467 CFI_ENDPROC
16468 -END(stub_rt_sigreturn)
16469 +ENDPROC(stub_rt_sigreturn)
16470
16471 #ifdef CONFIG_X86_X32_ABI
16472 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16473 @@ -962,7 +1261,7 @@ vector=vector+1
16474 2: jmp common_interrupt
16475 .endr
16476 CFI_ENDPROC
16477 -END(irq_entries_start)
16478 +ENDPROC(irq_entries_start)
16479
16480 .previous
16481 END(interrupt)
16482 @@ -982,6 +1281,16 @@ END(interrupt)
16483 subq $ORIG_RAX-RBP, %rsp
16484 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16485 SAVE_ARGS_IRQ
16486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16487 + testb $3, CS(%rdi)
16488 + jnz 1f
16489 + pax_enter_kernel
16490 + jmp 2f
16491 +1: pax_enter_kernel_user
16492 +2:
16493 +#else
16494 + pax_enter_kernel
16495 +#endif
16496 call \func
16497 .endm
16498
16499 @@ -1014,7 +1323,7 @@ ret_from_intr:
16500
16501 exit_intr:
16502 GET_THREAD_INFO(%rcx)
16503 - testl $3,CS-ARGOFFSET(%rsp)
16504 + testb $3,CS-ARGOFFSET(%rsp)
16505 je retint_kernel
16506
16507 /* Interrupt came from user space */
16508 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
16509 * The iretq could re-enable interrupts:
16510 */
16511 DISABLE_INTERRUPTS(CLBR_ANY)
16512 + pax_exit_kernel_user
16513 +retint_swapgs_pax:
16514 TRACE_IRQS_IRETQ
16515 SWAPGS
16516 jmp restore_args
16517
16518 retint_restore_args: /* return to kernel space */
16519 DISABLE_INTERRUPTS(CLBR_ANY)
16520 + pax_exit_kernel
16521 + pax_force_retaddr (RIP-ARGOFFSET)
16522 /*
16523 * The iretq could re-enable interrupts:
16524 */
16525 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
16526 #endif
16527
16528 CFI_ENDPROC
16529 -END(common_interrupt)
16530 +ENDPROC(common_interrupt)
16531 /*
16532 * End of kprobes section
16533 */
16534 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
16535 interrupt \do_sym
16536 jmp ret_from_intr
16537 CFI_ENDPROC
16538 -END(\sym)
16539 +ENDPROC(\sym)
16540 .endm
16541
16542 #ifdef CONFIG_SMP
16543 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
16544 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16545 call error_entry
16546 DEFAULT_FRAME 0
16547 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16548 + testb $3, CS(%rsp)
16549 + jnz 1f
16550 + pax_enter_kernel
16551 + jmp 2f
16552 +1: pax_enter_kernel_user
16553 +2:
16554 +#else
16555 + pax_enter_kernel
16556 +#endif
16557 movq %rsp,%rdi /* pt_regs pointer */
16558 xorl %esi,%esi /* no error code */
16559 call \do_sym
16560 jmp error_exit /* %ebx: no swapgs flag */
16561 CFI_ENDPROC
16562 -END(\sym)
16563 +ENDPROC(\sym)
16564 .endm
16565
16566 .macro paranoidzeroentry sym do_sym
16567 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
16568 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16569 call save_paranoid
16570 TRACE_IRQS_OFF
16571 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16572 + testb $3, CS(%rsp)
16573 + jnz 1f
16574 + pax_enter_kernel
16575 + jmp 2f
16576 +1: pax_enter_kernel_user
16577 +2:
16578 +#else
16579 + pax_enter_kernel
16580 +#endif
16581 movq %rsp,%rdi /* pt_regs pointer */
16582 xorl %esi,%esi /* no error code */
16583 call \do_sym
16584 jmp paranoid_exit /* %ebx: no swapgs flag */
16585 CFI_ENDPROC
16586 -END(\sym)
16587 +ENDPROC(\sym)
16588 .endm
16589
16590 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16591 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16592 .macro paranoidzeroentry_ist sym do_sym ist
16593 ENTRY(\sym)
16594 INTR_FRAME
16595 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
16596 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16597 call save_paranoid
16598 TRACE_IRQS_OFF_DEBUG
16599 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16600 + testb $3, CS(%rsp)
16601 + jnz 1f
16602 + pax_enter_kernel
16603 + jmp 2f
16604 +1: pax_enter_kernel_user
16605 +2:
16606 +#else
16607 + pax_enter_kernel
16608 +#endif
16609 movq %rsp,%rdi /* pt_regs pointer */
16610 xorl %esi,%esi /* no error code */
16611 +#ifdef CONFIG_SMP
16612 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16613 + lea init_tss(%r12), %r12
16614 +#else
16615 + lea init_tss(%rip), %r12
16616 +#endif
16617 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16618 call \do_sym
16619 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16620 jmp paranoid_exit /* %ebx: no swapgs flag */
16621 CFI_ENDPROC
16622 -END(\sym)
16623 +ENDPROC(\sym)
16624 .endm
16625
16626 .macro errorentry sym do_sym
16627 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
16628 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16629 call error_entry
16630 DEFAULT_FRAME 0
16631 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16632 + testb $3, CS(%rsp)
16633 + jnz 1f
16634 + pax_enter_kernel
16635 + jmp 2f
16636 +1: pax_enter_kernel_user
16637 +2:
16638 +#else
16639 + pax_enter_kernel
16640 +#endif
16641 movq %rsp,%rdi /* pt_regs pointer */
16642 movq ORIG_RAX(%rsp),%rsi /* get error code */
16643 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16644 call \do_sym
16645 jmp error_exit /* %ebx: no swapgs flag */
16646 CFI_ENDPROC
16647 -END(\sym)
16648 +ENDPROC(\sym)
16649 .endm
16650
16651 /* error code is on the stack already */
16652 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
16653 call save_paranoid
16654 DEFAULT_FRAME 0
16655 TRACE_IRQS_OFF
16656 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16657 + testb $3, CS(%rsp)
16658 + jnz 1f
16659 + pax_enter_kernel
16660 + jmp 2f
16661 +1: pax_enter_kernel_user
16662 +2:
16663 +#else
16664 + pax_enter_kernel
16665 +#endif
16666 movq %rsp,%rdi /* pt_regs pointer */
16667 movq ORIG_RAX(%rsp),%rsi /* get error code */
16668 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16669 call \do_sym
16670 jmp paranoid_exit /* %ebx: no swapgs flag */
16671 CFI_ENDPROC
16672 -END(\sym)
16673 +ENDPROC(\sym)
16674 .endm
16675
16676 zeroentry divide_error do_divide_error
16677 @@ -1310,9 +1679,10 @@ gs_change:
16678 2: mfence /* workaround */
16679 SWAPGS
16680 popfq_cfi
16681 + pax_force_retaddr
16682 ret
16683 CFI_ENDPROC
16684 -END(native_load_gs_index)
16685 +ENDPROC(native_load_gs_index)
16686
16687 _ASM_EXTABLE(gs_change,bad_gs)
16688 .section .fixup,"ax"
16689 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
16690 CFI_DEF_CFA_REGISTER rsp
16691 CFI_ADJUST_CFA_OFFSET -8
16692 decl PER_CPU_VAR(irq_count)
16693 + pax_force_retaddr
16694 ret
16695 CFI_ENDPROC
16696 -END(call_softirq)
16697 +ENDPROC(call_softirq)
16698
16699 #ifdef CONFIG_XEN
16700 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16701 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16702 decl PER_CPU_VAR(irq_count)
16703 jmp error_exit
16704 CFI_ENDPROC
16705 -END(xen_do_hypervisor_callback)
16706 +ENDPROC(xen_do_hypervisor_callback)
16707
16708 /*
16709 * Hypervisor uses this for application faults while it executes.
16710 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
16711 SAVE_ALL
16712 jmp error_exit
16713 CFI_ENDPROC
16714 -END(xen_failsafe_callback)
16715 +ENDPROC(xen_failsafe_callback)
16716
16717 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16718 xen_hvm_callback_vector xen_evtchn_do_upcall
16719 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
16720 TRACE_IRQS_OFF_DEBUG
16721 testl %ebx,%ebx /* swapgs needed? */
16722 jnz paranoid_restore
16723 - testl $3,CS(%rsp)
16724 + testb $3,CS(%rsp)
16725 jnz paranoid_userspace
16726 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16727 + pax_exit_kernel
16728 + TRACE_IRQS_IRETQ 0
16729 + SWAPGS_UNSAFE_STACK
16730 + RESTORE_ALL 8
16731 + pax_force_retaddr_bts
16732 + jmp irq_return
16733 +#endif
16734 paranoid_swapgs:
16735 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16736 + pax_exit_kernel_user
16737 +#else
16738 + pax_exit_kernel
16739 +#endif
16740 TRACE_IRQS_IRETQ 0
16741 SWAPGS_UNSAFE_STACK
16742 RESTORE_ALL 8
16743 jmp irq_return
16744 paranoid_restore:
16745 + pax_exit_kernel
16746 TRACE_IRQS_IRETQ_DEBUG 0
16747 RESTORE_ALL 8
16748 + pax_force_retaddr_bts
16749 jmp irq_return
16750 paranoid_userspace:
16751 GET_THREAD_INFO(%rcx)
16752 @@ -1526,7 +1912,7 @@ paranoid_schedule:
16753 TRACE_IRQS_OFF
16754 jmp paranoid_userspace
16755 CFI_ENDPROC
16756 -END(paranoid_exit)
16757 +ENDPROC(paranoid_exit)
16758
16759 /*
16760 * Exception entry point. This expects an error code/orig_rax on the stack.
16761 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
16762 movq_cfi r14, R14+8
16763 movq_cfi r15, R15+8
16764 xorl %ebx,%ebx
16765 - testl $3,CS+8(%rsp)
16766 + testb $3,CS+8(%rsp)
16767 je error_kernelspace
16768 error_swapgs:
16769 SWAPGS
16770 error_sti:
16771 TRACE_IRQS_OFF
16772 + pax_force_retaddr_bts
16773 ret
16774
16775 /*
16776 @@ -1585,7 +1972,7 @@ bstep_iret:
16777 movq %rcx,RIP+8(%rsp)
16778 jmp error_swapgs
16779 CFI_ENDPROC
16780 -END(error_entry)
16781 +ENDPROC(error_entry)
16782
16783
16784 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16785 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
16786 jnz retint_careful
16787 jmp retint_swapgs
16788 CFI_ENDPROC
16789 -END(error_exit)
16790 +ENDPROC(error_exit)
16791
16792 /*
16793 * Test if a given stack is an NMI stack or not.
16794 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
16795 * If %cs was not the kernel segment, then the NMI triggered in user
16796 * space, which means it is definitely not nested.
16797 */
16798 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16799 + je 1f
16800 cmpl $__KERNEL_CS, 16(%rsp)
16801 jne first_nmi
16802 -
16803 +1:
16804 /*
16805 * Check the special variable on the stack to see if NMIs are
16806 * executing.
16807 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
16808 */
16809 movq %cr2, %r12
16810
16811 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16812 + testb $3, CS(%rsp)
16813 + jnz 1f
16814 + pax_enter_kernel
16815 + jmp 2f
16816 +1: pax_enter_kernel_user
16817 +2:
16818 +#else
16819 + pax_enter_kernel
16820 +#endif
16821 +
16822 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16823 movq %rsp,%rdi
16824 movq $-1,%rsi
16825 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
16826 testl %ebx,%ebx /* swapgs needed? */
16827 jnz nmi_restore
16828 nmi_swapgs:
16829 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16830 + pax_exit_kernel_user
16831 +#else
16832 + pax_exit_kernel
16833 +#endif
16834 SWAPGS_UNSAFE_STACK
16835 + RESTORE_ALL 8
16836 + /* Clear the NMI executing stack variable */
16837 + movq $0, 10*8(%rsp)
16838 + jmp irq_return
16839 nmi_restore:
16840 + pax_exit_kernel
16841 RESTORE_ALL 8
16842 + pax_force_retaddr_bts
16843 /* Clear the NMI executing stack variable */
16844 movq $0, 10*8(%rsp)
16845 jmp irq_return
16846 CFI_ENDPROC
16847 -END(nmi)
16848 +ENDPROC(nmi)
16849
16850 ENTRY(ignore_sysret)
16851 CFI_STARTPROC
16852 mov $-ENOSYS,%eax
16853 sysret
16854 CFI_ENDPROC
16855 -END(ignore_sysret)
16856 +ENDPROC(ignore_sysret)
16857
16858 /*
16859 * End of kprobes section
16860 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16861 index 1d41402..af9a46a 100644
16862 --- a/arch/x86/kernel/ftrace.c
16863 +++ b/arch/x86/kernel/ftrace.c
16864 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16865 {
16866 unsigned char replaced[MCOUNT_INSN_SIZE];
16867
16868 + ip = ktla_ktva(ip);
16869 +
16870 /*
16871 * Note: Due to modules and __init, code can
16872 * disappear and change, we need to protect against faulting
16873 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16874 unsigned char old[MCOUNT_INSN_SIZE], *new;
16875 int ret;
16876
16877 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16878 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16879 new = ftrace_call_replace(ip, (unsigned long)func);
16880
16881 /* See comment above by declaration of modifying_ftrace_code */
16882 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16883 /* Also update the regs callback function */
16884 if (!ret) {
16885 ip = (unsigned long)(&ftrace_regs_call);
16886 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
16887 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
16888 new = ftrace_call_replace(ip, (unsigned long)func);
16889 ret = ftrace_modify_code(ip, old, new);
16890 }
16891 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
16892 * kernel identity mapping to modify code.
16893 */
16894 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
16895 - ip = (unsigned long)__va(__pa(ip));
16896 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
16897
16898 return probe_kernel_write((void *)ip, val, size);
16899 }
16900 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
16901 unsigned char replaced[MCOUNT_INSN_SIZE];
16902 unsigned char brk = BREAKPOINT_INSTRUCTION;
16903
16904 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
16905 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
16906 return -EFAULT;
16907
16908 /* Make sure it is what we expect it to be */
16909 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16910 return ret;
16911
16912 fail_update:
16913 - probe_kernel_write((void *)ip, &old_code[0], 1);
16914 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
16915 goto out;
16916 }
16917
16918 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16919 {
16920 unsigned char code[MCOUNT_INSN_SIZE];
16921
16922 + ip = ktla_ktva(ip);
16923 +
16924 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16925 return -EFAULT;
16926
16927 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16928 index c18f59d..9c0c9f6 100644
16929 --- a/arch/x86/kernel/head32.c
16930 +++ b/arch/x86/kernel/head32.c
16931 @@ -18,6 +18,7 @@
16932 #include <asm/io_apic.h>
16933 #include <asm/bios_ebda.h>
16934 #include <asm/tlbflush.h>
16935 +#include <asm/boot.h>
16936
16937 static void __init i386_default_early_setup(void)
16938 {
16939 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16940
16941 void __init i386_start_kernel(void)
16942 {
16943 - memblock_reserve(__pa_symbol(&_text),
16944 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16945 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16946
16947 #ifdef CONFIG_BLK_DEV_INITRD
16948 /* Reserve INITRD */
16949 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16950 index 4dac2f6..bc6a335 100644
16951 --- a/arch/x86/kernel/head_32.S
16952 +++ b/arch/x86/kernel/head_32.S
16953 @@ -26,6 +26,12 @@
16954 /* Physical address */
16955 #define pa(X) ((X) - __PAGE_OFFSET)
16956
16957 +#ifdef CONFIG_PAX_KERNEXEC
16958 +#define ta(X) (X)
16959 +#else
16960 +#define ta(X) ((X) - __PAGE_OFFSET)
16961 +#endif
16962 +
16963 /*
16964 * References to members of the new_cpu_data structure.
16965 */
16966 @@ -55,11 +61,7 @@
16967 * and small than max_low_pfn, otherwise will waste some page table entries
16968 */
16969
16970 -#if PTRS_PER_PMD > 1
16971 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16972 -#else
16973 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16974 -#endif
16975 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16976
16977 /* Number of possible pages in the lowmem region */
16978 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16979 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16980 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16981
16982 /*
16983 + * Real beginning of normal "text" segment
16984 + */
16985 +ENTRY(stext)
16986 +ENTRY(_stext)
16987 +
16988 +/*
16989 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16990 * %esi points to the real-mode code as a 32-bit pointer.
16991 * CS and DS must be 4 GB flat segments, but we don't depend on
16992 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16993 * can.
16994 */
16995 __HEAD
16996 +
16997 +#ifdef CONFIG_PAX_KERNEXEC
16998 + jmp startup_32
16999 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
17000 +.fill PAGE_SIZE-5,1,0xcc
17001 +#endif
17002 +
17003 ENTRY(startup_32)
17004 movl pa(stack_start),%ecx
17005
17006 @@ -106,6 +121,59 @@ ENTRY(startup_32)
17007 2:
17008 leal -__PAGE_OFFSET(%ecx),%esp
17009
17010 +#ifdef CONFIG_SMP
17011 + movl $pa(cpu_gdt_table),%edi
17012 + movl $__per_cpu_load,%eax
17013 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
17014 + rorl $16,%eax
17015 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
17016 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
17017 + movl $__per_cpu_end - 1,%eax
17018 + subl $__per_cpu_start,%eax
17019 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
17020 +#endif
17021 +
17022 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17023 + movl $NR_CPUS,%ecx
17024 + movl $pa(cpu_gdt_table),%edi
17025 +1:
17026 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
17027 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
17028 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
17029 + addl $PAGE_SIZE_asm,%edi
17030 + loop 1b
17031 +#endif
17032 +
17033 +#ifdef CONFIG_PAX_KERNEXEC
17034 + movl $pa(boot_gdt),%edi
17035 + movl $__LOAD_PHYSICAL_ADDR,%eax
17036 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
17037 + rorl $16,%eax
17038 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
17039 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
17040 + rorl $16,%eax
17041 +
17042 + ljmp $(__BOOT_CS),$1f
17043 +1:
17044 +
17045 + movl $NR_CPUS,%ecx
17046 + movl $pa(cpu_gdt_table),%edi
17047 + addl $__PAGE_OFFSET,%eax
17048 +1:
17049 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
17050 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
17051 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
17052 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
17053 + rorl $16,%eax
17054 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
17055 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
17056 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
17057 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
17058 + rorl $16,%eax
17059 + addl $PAGE_SIZE_asm,%edi
17060 + loop 1b
17061 +#endif
17062 +
17063 /*
17064 * Clear BSS first so that there are no surprises...
17065 */
17066 @@ -196,8 +264,11 @@ ENTRY(startup_32)
17067 movl %eax, pa(max_pfn_mapped)
17068
17069 /* Do early initialization of the fixmap area */
17070 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17071 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
17072 +#ifdef CONFIG_COMPAT_VDSO
17073 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
17074 +#else
17075 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
17076 +#endif
17077 #else /* Not PAE */
17078
17079 page_pde_offset = (__PAGE_OFFSET >> 20);
17080 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17081 movl %eax, pa(max_pfn_mapped)
17082
17083 /* Do early initialization of the fixmap area */
17084 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17085 - movl %eax,pa(initial_page_table+0xffc)
17086 +#ifdef CONFIG_COMPAT_VDSO
17087 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17088 +#else
17089 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17090 +#endif
17091 #endif
17092
17093 #ifdef CONFIG_PARAVIRT
17094 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17095 cmpl $num_subarch_entries, %eax
17096 jae bad_subarch
17097
17098 - movl pa(subarch_entries)(,%eax,4), %eax
17099 - subl $__PAGE_OFFSET, %eax
17100 - jmp *%eax
17101 + jmp *pa(subarch_entries)(,%eax,4)
17102
17103 bad_subarch:
17104 WEAK(lguest_entry)
17105 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17106 __INITDATA
17107
17108 subarch_entries:
17109 - .long default_entry /* normal x86/PC */
17110 - .long lguest_entry /* lguest hypervisor */
17111 - .long xen_entry /* Xen hypervisor */
17112 - .long default_entry /* Moorestown MID */
17113 + .long ta(default_entry) /* normal x86/PC */
17114 + .long ta(lguest_entry) /* lguest hypervisor */
17115 + .long ta(xen_entry) /* Xen hypervisor */
17116 + .long ta(default_entry) /* Moorestown MID */
17117 num_subarch_entries = (. - subarch_entries) / 4
17118 .previous
17119 #else
17120 @@ -316,6 +388,7 @@ default_entry:
17121 movl pa(mmu_cr4_features),%eax
17122 movl %eax,%cr4
17123
17124 +#ifdef CONFIG_X86_PAE
17125 testb $X86_CR4_PAE, %al # check if PAE is enabled
17126 jz 6f
17127
17128 @@ -344,6 +417,9 @@ default_entry:
17129 /* Make changes effective */
17130 wrmsr
17131
17132 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17133 +#endif
17134 +
17135 6:
17136
17137 /*
17138 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
17139 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17140 movl %eax,%ss # after changing gdt.
17141
17142 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17143 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17144 movl %eax,%ds
17145 movl %eax,%es
17146
17147 movl $(__KERNEL_PERCPU), %eax
17148 movl %eax,%fs # set this cpu's percpu
17149
17150 +#ifdef CONFIG_CC_STACKPROTECTOR
17151 movl $(__KERNEL_STACK_CANARY),%eax
17152 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17153 + movl $(__USER_DS),%eax
17154 +#else
17155 + xorl %eax,%eax
17156 +#endif
17157 movl %eax,%gs
17158
17159 xorl %eax,%eax # Clear LDT
17160 @@ -526,8 +608,11 @@ setup_once:
17161 * relocation. Manually set base address in stack canary
17162 * segment descriptor.
17163 */
17164 - movl $gdt_page,%eax
17165 + movl $cpu_gdt_table,%eax
17166 movl $stack_canary,%ecx
17167 +#ifdef CONFIG_SMP
17168 + addl $__per_cpu_load,%ecx
17169 +#endif
17170 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17171 shrl $16, %ecx
17172 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17173 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
17174 /* This is global to keep gas from relaxing the jumps */
17175 ENTRY(early_idt_handler)
17176 cld
17177 - cmpl $2,%ss:early_recursion_flag
17178 + cmpl $1,%ss:early_recursion_flag
17179 je hlt_loop
17180 incl %ss:early_recursion_flag
17181
17182 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
17183 pushl (20+6*4)(%esp) /* trapno */
17184 pushl $fault_msg
17185 call printk
17186 -#endif
17187 call dump_stack
17188 +#endif
17189 hlt_loop:
17190 hlt
17191 jmp hlt_loop
17192 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
17193 /* This is the default interrupt "handler" :-) */
17194 ALIGN
17195 ignore_int:
17196 - cld
17197 #ifdef CONFIG_PRINTK
17198 + cmpl $2,%ss:early_recursion_flag
17199 + je hlt_loop
17200 + incl %ss:early_recursion_flag
17201 + cld
17202 pushl %eax
17203 pushl %ecx
17204 pushl %edx
17205 @@ -626,9 +714,6 @@ ignore_int:
17206 movl $(__KERNEL_DS),%eax
17207 movl %eax,%ds
17208 movl %eax,%es
17209 - cmpl $2,early_recursion_flag
17210 - je hlt_loop
17211 - incl early_recursion_flag
17212 pushl 16(%esp)
17213 pushl 24(%esp)
17214 pushl 32(%esp)
17215 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
17216 /*
17217 * BSS section
17218 */
17219 -__PAGE_ALIGNED_BSS
17220 - .align PAGE_SIZE
17221 #ifdef CONFIG_X86_PAE
17222 +.section .initial_pg_pmd,"a",@progbits
17223 initial_pg_pmd:
17224 .fill 1024*KPMDS,4,0
17225 #else
17226 +.section .initial_page_table,"a",@progbits
17227 ENTRY(initial_page_table)
17228 .fill 1024,4,0
17229 #endif
17230 +.section .initial_pg_fixmap,"a",@progbits
17231 initial_pg_fixmap:
17232 .fill 1024,4,0
17233 +.section .empty_zero_page,"a",@progbits
17234 ENTRY(empty_zero_page)
17235 .fill 4096,1,0
17236 +.section .swapper_pg_dir,"a",@progbits
17237 ENTRY(swapper_pg_dir)
17238 +#ifdef CONFIG_X86_PAE
17239 + .fill 4,8,0
17240 +#else
17241 .fill 1024,4,0
17242 +#endif
17243 +
17244 +/*
17245 + * The IDT has to be page-aligned to simplify the Pentium
17246 + * F0 0F bug workaround.. We have a special link segment
17247 + * for this.
17248 + */
17249 +.section .idt,"a",@progbits
17250 +ENTRY(idt_table)
17251 + .fill 256,8,0
17252
17253 /*
17254 * This starts the data section.
17255 */
17256 #ifdef CONFIG_X86_PAE
17257 -__PAGE_ALIGNED_DATA
17258 - /* Page-aligned for the benefit of paravirt? */
17259 - .align PAGE_SIZE
17260 +.section .initial_page_table,"a",@progbits
17261 ENTRY(initial_page_table)
17262 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17263 # if KPMDS == 3
17264 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
17265 # error "Kernel PMDs should be 1, 2 or 3"
17266 # endif
17267 .align PAGE_SIZE /* needs to be page-sized too */
17268 +
17269 +#ifdef CONFIG_PAX_PER_CPU_PGD
17270 +ENTRY(cpu_pgd)
17271 + .rept NR_CPUS
17272 + .fill 4,8,0
17273 + .endr
17274 +#endif
17275 +
17276 #endif
17277
17278 .data
17279 .balign 4
17280 ENTRY(stack_start)
17281 - .long init_thread_union+THREAD_SIZE
17282 + .long init_thread_union+THREAD_SIZE-8
17283
17284 __INITRODATA
17285 int_msg:
17286 @@ -736,7 +843,7 @@ fault_msg:
17287 * segment size, and 32-bit linear address value:
17288 */
17289
17290 - .data
17291 +.section .rodata,"a",@progbits
17292 .globl boot_gdt_descr
17293 .globl idt_descr
17294
17295 @@ -745,7 +852,7 @@ fault_msg:
17296 .word 0 # 32 bit align gdt_desc.address
17297 boot_gdt_descr:
17298 .word __BOOT_DS+7
17299 - .long boot_gdt - __PAGE_OFFSET
17300 + .long pa(boot_gdt)
17301
17302 .word 0 # 32-bit align idt_desc.address
17303 idt_descr:
17304 @@ -756,7 +863,7 @@ idt_descr:
17305 .word 0 # 32 bit align gdt_desc.address
17306 ENTRY(early_gdt_descr)
17307 .word GDT_ENTRIES*8-1
17308 - .long gdt_page /* Overwritten for secondary CPUs */
17309 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17310
17311 /*
17312 * The boot_gdt must mirror the equivalent in setup.S and is
17313 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
17314 .align L1_CACHE_BYTES
17315 ENTRY(boot_gdt)
17316 .fill GDT_ENTRY_BOOT_CS,8,0
17317 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17318 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17319 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17320 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17321 +
17322 + .align PAGE_SIZE_asm
17323 +ENTRY(cpu_gdt_table)
17324 + .rept NR_CPUS
17325 + .quad 0x0000000000000000 /* NULL descriptor */
17326 + .quad 0x0000000000000000 /* 0x0b reserved */
17327 + .quad 0x0000000000000000 /* 0x13 reserved */
17328 + .quad 0x0000000000000000 /* 0x1b reserved */
17329 +
17330 +#ifdef CONFIG_PAX_KERNEXEC
17331 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17332 +#else
17333 + .quad 0x0000000000000000 /* 0x20 unused */
17334 +#endif
17335 +
17336 + .quad 0x0000000000000000 /* 0x28 unused */
17337 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17338 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17339 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17340 + .quad 0x0000000000000000 /* 0x4b reserved */
17341 + .quad 0x0000000000000000 /* 0x53 reserved */
17342 + .quad 0x0000000000000000 /* 0x5b reserved */
17343 +
17344 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17345 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17346 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17347 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17348 +
17349 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17350 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17351 +
17352 + /*
17353 + * Segments used for calling PnP BIOS have byte granularity.
17354 + * The code segments and data segments have fixed 64k limits,
17355 + * the transfer segment sizes are set at run time.
17356 + */
17357 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17358 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17359 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17360 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17361 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17362 +
17363 + /*
17364 + * The APM segments have byte granularity and their bases
17365 + * are set at run time. All have 64k limits.
17366 + */
17367 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17368 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17369 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17370 +
17371 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17372 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17373 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17374 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17375 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17376 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17377 +
17378 + /* Be sure this is zeroed to avoid false validations in Xen */
17379 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17380 + .endr
17381 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17382 index 94bf9cc..400455a 100644
17383 --- a/arch/x86/kernel/head_64.S
17384 +++ b/arch/x86/kernel/head_64.S
17385 @@ -20,6 +20,8 @@
17386 #include <asm/processor-flags.h>
17387 #include <asm/percpu.h>
17388 #include <asm/nops.h>
17389 +#include <asm/cpufeature.h>
17390 +#include <asm/alternative-asm.h>
17391
17392 #ifdef CONFIG_PARAVIRT
17393 #include <asm/asm-offsets.h>
17394 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17395 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17396 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17397 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17398 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17399 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17400 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17401 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17402 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17403 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17404
17405 .text
17406 __HEAD
17407 @@ -88,35 +96,23 @@ startup_64:
17408 */
17409 addq %rbp, init_level4_pgt + 0(%rip)
17410 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17411 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17412 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17413 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17414 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17415
17416 addq %rbp, level3_ident_pgt + 0(%rip)
17417 +#ifndef CONFIG_XEN
17418 + addq %rbp, level3_ident_pgt + 8(%rip)
17419 +#endif
17420
17421 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17422 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17423 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17424 +
17425 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17426 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17427
17428 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17429 -
17430 - /* Add an Identity mapping if I am above 1G */
17431 - leaq _text(%rip), %rdi
17432 - andq $PMD_PAGE_MASK, %rdi
17433 -
17434 - movq %rdi, %rax
17435 - shrq $PUD_SHIFT, %rax
17436 - andq $(PTRS_PER_PUD - 1), %rax
17437 - jz ident_complete
17438 -
17439 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17440 - leaq level3_ident_pgt(%rip), %rbx
17441 - movq %rdx, 0(%rbx, %rax, 8)
17442 -
17443 - movq %rdi, %rax
17444 - shrq $PMD_SHIFT, %rax
17445 - andq $(PTRS_PER_PMD - 1), %rax
17446 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17447 - leaq level2_spare_pgt(%rip), %rbx
17448 - movq %rdx, 0(%rbx, %rax, 8)
17449 -ident_complete:
17450 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17451
17452 /*
17453 * Fixup the kernel text+data virtual addresses. Note that
17454 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17455 * after the boot processor executes this code.
17456 */
17457
17458 - /* Enable PAE mode and PGE */
17459 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17460 + /* Enable PAE mode and PSE/PGE */
17461 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17462 movq %rax, %cr4
17463
17464 /* Setup early boot stage 4 level pagetables. */
17465 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17466 movl $MSR_EFER, %ecx
17467 rdmsr
17468 btsl $_EFER_SCE, %eax /* Enable System Call */
17469 - btl $20,%edi /* No Execute supported? */
17470 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17471 jnc 1f
17472 btsl $_EFER_NX, %eax
17473 + leaq init_level4_pgt(%rip), %rdi
17474 +#ifndef CONFIG_EFI
17475 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17476 +#endif
17477 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17478 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17479 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17480 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17481 1: wrmsr /* Make changes effective */
17482
17483 /* Setup cr0 */
17484 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17485 * jump. In addition we need to ensure %cs is set so we make this
17486 * a far return.
17487 */
17488 + pax_set_fptr_mask
17489 movq initial_code(%rip),%rax
17490 pushq $0 # fake return address to stop unwinder
17491 pushq $__KERNEL_CS # set correct cs
17492 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17493 bad_address:
17494 jmp bad_address
17495
17496 - .section ".init.text","ax"
17497 + __INIT
17498 .globl early_idt_handlers
17499 early_idt_handlers:
17500 # 104(%rsp) %rflags
17501 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17502 addq $16,%rsp # drop vector number and error code
17503 decl early_recursion_flag(%rip)
17504 INTERRUPT_RETURN
17505 + .previous
17506
17507 + __INITDATA
17508 .balign 4
17509 early_recursion_flag:
17510 .long 0
17511 + .previous
17512
17513 + .section .rodata,"a",@progbits
17514 #ifdef CONFIG_EARLY_PRINTK
17515 early_idt_msg:
17516 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17517 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17518 #endif /* CONFIG_EARLY_PRINTK */
17519 .previous
17520
17521 + .section .rodata,"a",@progbits
17522 #define NEXT_PAGE(name) \
17523 .balign PAGE_SIZE; \
17524 ENTRY(name)
17525 @@ -372,7 +382,6 @@ ENTRY(name)
17526 i = i + 1 ; \
17527 .endr
17528
17529 - .data
17530 /*
17531 * This default setting generates an ident mapping at address 0x100000
17532 * and a mapping for the kernel that precisely maps virtual address
17533 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17534 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17535 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17536 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17537 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17538 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17539 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17540 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17541 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17542 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17543 .org init_level4_pgt + L4_START_KERNEL*8, 0
17544 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17545 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17546
17547 +#ifdef CONFIG_PAX_PER_CPU_PGD
17548 +NEXT_PAGE(cpu_pgd)
17549 + .rept NR_CPUS
17550 + .fill 512,8,0
17551 + .endr
17552 +#endif
17553 +
17554 NEXT_PAGE(level3_ident_pgt)
17555 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17556 +#ifdef CONFIG_XEN
17557 .fill 511,8,0
17558 +#else
17559 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17560 + .fill 510,8,0
17561 +#endif
17562 +
17563 +NEXT_PAGE(level3_vmalloc_start_pgt)
17564 + .fill 512,8,0
17565 +
17566 +NEXT_PAGE(level3_vmalloc_end_pgt)
17567 + .fill 512,8,0
17568 +
17569 +NEXT_PAGE(level3_vmemmap_pgt)
17570 + .fill L3_VMEMMAP_START,8,0
17571 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17572
17573 NEXT_PAGE(level3_kernel_pgt)
17574 .fill L3_START_KERNEL,8,0
17575 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17576 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17577 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17578
17579 +NEXT_PAGE(level2_vmemmap_pgt)
17580 + .fill 512,8,0
17581 +
17582 NEXT_PAGE(level2_fixmap_pgt)
17583 - .fill 506,8,0
17584 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17585 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17586 - .fill 5,8,0
17587 + .fill 507,8,0
17588 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17589 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17590 + .fill 4,8,0
17591
17592 -NEXT_PAGE(level1_fixmap_pgt)
17593 +NEXT_PAGE(level1_vsyscall_pgt)
17594 .fill 512,8,0
17595
17596 -NEXT_PAGE(level2_ident_pgt)
17597 - /* Since I easily can, map the first 1G.
17598 + /* Since I easily can, map the first 2G.
17599 * Don't set NX because code runs from these pages.
17600 */
17601 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17602 +NEXT_PAGE(level2_ident_pgt)
17603 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17604
17605 NEXT_PAGE(level2_kernel_pgt)
17606 /*
17607 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17608 * If you want to increase this then increase MODULES_VADDR
17609 * too.)
17610 */
17611 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17612 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17613 -
17614 -NEXT_PAGE(level2_spare_pgt)
17615 - .fill 512, 8, 0
17616 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17617
17618 #undef PMDS
17619 #undef NEXT_PAGE
17620
17621 - .data
17622 + .align PAGE_SIZE
17623 +ENTRY(cpu_gdt_table)
17624 + .rept NR_CPUS
17625 + .quad 0x0000000000000000 /* NULL descriptor */
17626 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17627 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17628 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17629 + .quad 0x00cffb000000ffff /* __USER32_CS */
17630 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17631 + .quad 0x00affb000000ffff /* __USER_CS */
17632 +
17633 +#ifdef CONFIG_PAX_KERNEXEC
17634 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17635 +#else
17636 + .quad 0x0 /* unused */
17637 +#endif
17638 +
17639 + .quad 0,0 /* TSS */
17640 + .quad 0,0 /* LDT */
17641 + .quad 0,0,0 /* three TLS descriptors */
17642 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17643 + /* asm/segment.h:GDT_ENTRIES must match this */
17644 +
17645 + /* zero the remaining page */
17646 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17647 + .endr
17648 +
17649 .align 16
17650 .globl early_gdt_descr
17651 early_gdt_descr:
17652 .word GDT_ENTRIES*8-1
17653 early_gdt_descr_base:
17654 - .quad INIT_PER_CPU_VAR(gdt_page)
17655 + .quad cpu_gdt_table
17656
17657 ENTRY(phys_base)
17658 /* This must match the first entry in level2_kernel_pgt */
17659 .quad 0x0000000000000000
17660
17661 #include "../../x86/xen/xen-head.S"
17662 -
17663 - .section .bss, "aw", @nobits
17664 +
17665 + .section .rodata,"a",@progbits
17666 .align L1_CACHE_BYTES
17667 ENTRY(idt_table)
17668 - .skip IDT_ENTRIES * 16
17669 + .fill 512,8,0
17670
17671 .align L1_CACHE_BYTES
17672 ENTRY(nmi_idt_table)
17673 - .skip IDT_ENTRIES * 16
17674 + .fill 512,8,0
17675
17676 __PAGE_ALIGNED_BSS
17677 .align PAGE_SIZE
17678 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17679 index 9c3bd4a..e1d9b35 100644
17680 --- a/arch/x86/kernel/i386_ksyms_32.c
17681 +++ b/arch/x86/kernel/i386_ksyms_32.c
17682 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17683 EXPORT_SYMBOL(cmpxchg8b_emu);
17684 #endif
17685
17686 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17687 +
17688 /* Networking helper routines. */
17689 EXPORT_SYMBOL(csum_partial_copy_generic);
17690 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17691 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17692
17693 EXPORT_SYMBOL(__get_user_1);
17694 EXPORT_SYMBOL(__get_user_2);
17695 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17696
17697 EXPORT_SYMBOL(csum_partial);
17698 EXPORT_SYMBOL(empty_zero_page);
17699 +
17700 +#ifdef CONFIG_PAX_KERNEXEC
17701 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17702 +#endif
17703 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17704 index 675a050..95febfd 100644
17705 --- a/arch/x86/kernel/i387.c
17706 +++ b/arch/x86/kernel/i387.c
17707 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17708 static inline bool interrupted_user_mode(void)
17709 {
17710 struct pt_regs *regs = get_irq_regs();
17711 - return regs && user_mode_vm(regs);
17712 + return regs && user_mode(regs);
17713 }
17714
17715 /*
17716 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17717 index 9a5c460..dc4374d 100644
17718 --- a/arch/x86/kernel/i8259.c
17719 +++ b/arch/x86/kernel/i8259.c
17720 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17721 "spurious 8259A interrupt: IRQ%d.\n", irq);
17722 spurious_irq_mask |= irqmask;
17723 }
17724 - atomic_inc(&irq_err_count);
17725 + atomic_inc_unchecked(&irq_err_count);
17726 /*
17727 * Theoretically we do not have to handle this IRQ,
17728 * but in Linux this does not cause problems and is
17729 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17730 index 8c96897..be66bfa 100644
17731 --- a/arch/x86/kernel/ioport.c
17732 +++ b/arch/x86/kernel/ioport.c
17733 @@ -6,6 +6,7 @@
17734 #include <linux/sched.h>
17735 #include <linux/kernel.h>
17736 #include <linux/capability.h>
17737 +#include <linux/security.h>
17738 #include <linux/errno.h>
17739 #include <linux/types.h>
17740 #include <linux/ioport.h>
17741 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17742
17743 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17744 return -EINVAL;
17745 +#ifdef CONFIG_GRKERNSEC_IO
17746 + if (turn_on && grsec_disable_privio) {
17747 + gr_handle_ioperm();
17748 + return -EPERM;
17749 + }
17750 +#endif
17751 if (turn_on && !capable(CAP_SYS_RAWIO))
17752 return -EPERM;
17753
17754 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17755 * because the ->io_bitmap_max value must match the bitmap
17756 * contents:
17757 */
17758 - tss = &per_cpu(init_tss, get_cpu());
17759 + tss = init_tss + get_cpu();
17760
17761 if (turn_on)
17762 bitmap_clear(t->io_bitmap_ptr, from, num);
17763 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17764 return -EINVAL;
17765 /* Trying to gain more privileges? */
17766 if (level > old) {
17767 +#ifdef CONFIG_GRKERNSEC_IO
17768 + if (grsec_disable_privio) {
17769 + gr_handle_iopl();
17770 + return -EPERM;
17771 + }
17772 +#endif
17773 if (!capable(CAP_SYS_RAWIO))
17774 return -EPERM;
17775 }
17776 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17777 index e4595f1..ee3bfb8 100644
17778 --- a/arch/x86/kernel/irq.c
17779 +++ b/arch/x86/kernel/irq.c
17780 @@ -18,7 +18,7 @@
17781 #include <asm/mce.h>
17782 #include <asm/hw_irq.h>
17783
17784 -atomic_t irq_err_count;
17785 +atomic_unchecked_t irq_err_count;
17786
17787 /* Function pointer for generic interrupt vector handling */
17788 void (*x86_platform_ipi_callback)(void) = NULL;
17789 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17790 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17791 seq_printf(p, " Machine check polls\n");
17792 #endif
17793 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17794 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17795 #if defined(CONFIG_X86_IO_APIC)
17796 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17797 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17798 #endif
17799 return 0;
17800 }
17801 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17802
17803 u64 arch_irq_stat(void)
17804 {
17805 - u64 sum = atomic_read(&irq_err_count);
17806 + u64 sum = atomic_read_unchecked(&irq_err_count);
17807
17808 #ifdef CONFIG_X86_IO_APIC
17809 - sum += atomic_read(&irq_mis_count);
17810 + sum += atomic_read_unchecked(&irq_mis_count);
17811 #endif
17812 return sum;
17813 }
17814 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17815 index 344faf8..355f60d 100644
17816 --- a/arch/x86/kernel/irq_32.c
17817 +++ b/arch/x86/kernel/irq_32.c
17818 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17819 __asm__ __volatile__("andl %%esp,%0" :
17820 "=r" (sp) : "0" (THREAD_SIZE - 1));
17821
17822 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17823 + return sp < STACK_WARN;
17824 }
17825
17826 static void print_stack_overflow(void)
17827 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17828 * per-CPU IRQ handling contexts (thread information and stack)
17829 */
17830 union irq_ctx {
17831 - struct thread_info tinfo;
17832 - u32 stack[THREAD_SIZE/sizeof(u32)];
17833 + unsigned long previous_esp;
17834 + u32 stack[THREAD_SIZE/sizeof(u32)];
17835 } __attribute__((aligned(THREAD_SIZE)));
17836
17837 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17838 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17839 static inline int
17840 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17841 {
17842 - union irq_ctx *curctx, *irqctx;
17843 + union irq_ctx *irqctx;
17844 u32 *isp, arg1, arg2;
17845
17846 - curctx = (union irq_ctx *) current_thread_info();
17847 irqctx = __this_cpu_read(hardirq_ctx);
17848
17849 /*
17850 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17851 * handler) we can't do that and just have to keep using the
17852 * current stack (which is the irq stack already after all)
17853 */
17854 - if (unlikely(curctx == irqctx))
17855 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17856 return 0;
17857
17858 /* build the stack frame on the IRQ stack */
17859 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17860 - irqctx->tinfo.task = curctx->tinfo.task;
17861 - irqctx->tinfo.previous_esp = current_stack_pointer;
17862 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17863 + irqctx->previous_esp = current_stack_pointer;
17864
17865 - /* Copy the preempt_count so that the [soft]irq checks work. */
17866 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17867 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17868 + __set_fs(MAKE_MM_SEG(0));
17869 +#endif
17870
17871 if (unlikely(overflow))
17872 call_on_stack(print_stack_overflow, isp);
17873 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17874 : "0" (irq), "1" (desc), "2" (isp),
17875 "D" (desc->handle_irq)
17876 : "memory", "cc", "ecx");
17877 +
17878 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17879 + __set_fs(current_thread_info()->addr_limit);
17880 +#endif
17881 +
17882 return 1;
17883 }
17884
17885 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17886 */
17887 void __cpuinit irq_ctx_init(int cpu)
17888 {
17889 - union irq_ctx *irqctx;
17890 -
17891 if (per_cpu(hardirq_ctx, cpu))
17892 return;
17893
17894 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17895 - THREADINFO_GFP,
17896 - THREAD_SIZE_ORDER));
17897 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17898 - irqctx->tinfo.cpu = cpu;
17899 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17900 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17901 -
17902 - per_cpu(hardirq_ctx, cpu) = irqctx;
17903 -
17904 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17905 - THREADINFO_GFP,
17906 - THREAD_SIZE_ORDER));
17907 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17908 - irqctx->tinfo.cpu = cpu;
17909 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17910 -
17911 - per_cpu(softirq_ctx, cpu) = irqctx;
17912 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17913 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17914 +
17915 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17916 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17917
17918 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17919 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17920 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17921 asmlinkage void do_softirq(void)
17922 {
17923 unsigned long flags;
17924 - struct thread_info *curctx;
17925 union irq_ctx *irqctx;
17926 u32 *isp;
17927
17928 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17929 local_irq_save(flags);
17930
17931 if (local_softirq_pending()) {
17932 - curctx = current_thread_info();
17933 irqctx = __this_cpu_read(softirq_ctx);
17934 - irqctx->tinfo.task = curctx->task;
17935 - irqctx->tinfo.previous_esp = current_stack_pointer;
17936 + irqctx->previous_esp = current_stack_pointer;
17937
17938 /* build the stack frame on the softirq stack */
17939 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17940 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17941 +
17942 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17943 + __set_fs(MAKE_MM_SEG(0));
17944 +#endif
17945
17946 call_on_stack(__do_softirq, isp);
17947 +
17948 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17949 + __set_fs(current_thread_info()->addr_limit);
17950 +#endif
17951 +
17952 /*
17953 * Shouldn't happen, we returned above if in_interrupt():
17954 */
17955 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17956 if (unlikely(!desc))
17957 return false;
17958
17959 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17960 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17961 if (unlikely(overflow))
17962 print_stack_overflow();
17963 desc->handle_irq(irq, desc);
17964 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17965 index d04d3ec..ea4b374 100644
17966 --- a/arch/x86/kernel/irq_64.c
17967 +++ b/arch/x86/kernel/irq_64.c
17968 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17969 u64 estack_top, estack_bottom;
17970 u64 curbase = (u64)task_stack_page(current);
17971
17972 - if (user_mode_vm(regs))
17973 + if (user_mode(regs))
17974 return;
17975
17976 if (regs->sp >= curbase + sizeof(struct thread_info) +
17977 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17978 index dc1404b..bbc43e7 100644
17979 --- a/arch/x86/kernel/kdebugfs.c
17980 +++ b/arch/x86/kernel/kdebugfs.c
17981 @@ -27,7 +27,7 @@ struct setup_data_node {
17982 u32 len;
17983 };
17984
17985 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17986 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17987 size_t count, loff_t *ppos)
17988 {
17989 struct setup_data_node *node = file->private_data;
17990 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17991 index 836f832..a8bda67 100644
17992 --- a/arch/x86/kernel/kgdb.c
17993 +++ b/arch/x86/kernel/kgdb.c
17994 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17995 #ifdef CONFIG_X86_32
17996 switch (regno) {
17997 case GDB_SS:
17998 - if (!user_mode_vm(regs))
17999 + if (!user_mode(regs))
18000 *(unsigned long *)mem = __KERNEL_DS;
18001 break;
18002 case GDB_SP:
18003 - if (!user_mode_vm(regs))
18004 + if (!user_mode(regs))
18005 *(unsigned long *)mem = kernel_stack_pointer(regs);
18006 break;
18007 case GDB_GS:
18008 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
18009 bp->attr.bp_addr = breakinfo[breakno].addr;
18010 bp->attr.bp_len = breakinfo[breakno].len;
18011 bp->attr.bp_type = breakinfo[breakno].type;
18012 - info->address = breakinfo[breakno].addr;
18013 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
18014 + info->address = ktla_ktva(breakinfo[breakno].addr);
18015 + else
18016 + info->address = breakinfo[breakno].addr;
18017 info->len = breakinfo[breakno].len;
18018 info->type = breakinfo[breakno].type;
18019 val = arch_install_hw_breakpoint(bp);
18020 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
18021 case 'k':
18022 /* clear the trace bit */
18023 linux_regs->flags &= ~X86_EFLAGS_TF;
18024 - atomic_set(&kgdb_cpu_doing_single_step, -1);
18025 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
18026
18027 /* set the trace bit if we're stepping */
18028 if (remcomInBuffer[0] == 's') {
18029 linux_regs->flags |= X86_EFLAGS_TF;
18030 - atomic_set(&kgdb_cpu_doing_single_step,
18031 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
18032 raw_smp_processor_id());
18033 }
18034
18035 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
18036
18037 switch (cmd) {
18038 case DIE_DEBUG:
18039 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
18040 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
18041 if (user_mode(regs))
18042 return single_step_cont(regs, args);
18043 break;
18044 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
18045 #endif /* CONFIG_DEBUG_RODATA */
18046
18047 bpt->type = BP_BREAKPOINT;
18048 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
18049 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
18050 BREAK_INSTR_SIZE);
18051 if (err)
18052 return err;
18053 - err = probe_kernel_write((char *)bpt->bpt_addr,
18054 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
18055 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
18056 #ifdef CONFIG_DEBUG_RODATA
18057 if (!err)
18058 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
18059 return -EBUSY;
18060 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
18061 BREAK_INSTR_SIZE);
18062 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
18063 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
18064 if (err)
18065 return err;
18066 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
18067 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
18068 if (mutex_is_locked(&text_mutex))
18069 goto knl_write;
18070 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
18071 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
18072 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
18073 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
18074 goto knl_write;
18075 return err;
18076 knl_write:
18077 #endif /* CONFIG_DEBUG_RODATA */
18078 - return probe_kernel_write((char *)bpt->bpt_addr,
18079 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
18080 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
18081 }
18082
18083 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
18084 index c5e410e..ed5a7f0 100644
18085 --- a/arch/x86/kernel/kprobes-opt.c
18086 +++ b/arch/x86/kernel/kprobes-opt.c
18087 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18088 * Verify if the address gap is in 2GB range, because this uses
18089 * a relative jump.
18090 */
18091 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
18092 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
18093 if (abs(rel) > 0x7fffffff)
18094 return -ERANGE;
18095
18096 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18097 op->optinsn.size = ret;
18098
18099 /* Copy arch-dep-instance from template */
18100 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
18101 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
18102
18103 /* Set probe information */
18104 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
18105
18106 /* Set probe function call */
18107 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
18108 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
18109
18110 /* Set returning jmp instruction at the tail of out-of-line buffer */
18111 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
18112 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
18113 (u8 *)op->kp.addr + op->optinsn.size);
18114
18115 flush_icache_range((unsigned long) buf,
18116 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
18117 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
18118
18119 /* Backup instructions which will be replaced by jump address */
18120 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
18121 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
18122 RELATIVE_ADDR_SIZE);
18123
18124 insn_buf[0] = RELATIVEJUMP_OPCODE;
18125 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
18126 /* This kprobe is really able to run optimized path. */
18127 op = container_of(p, struct optimized_kprobe, kp);
18128 /* Detour through copied instructions */
18129 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
18130 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
18131 if (!reenter)
18132 reset_current_kprobe();
18133 preempt_enable_no_resched();
18134 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
18135 index 57916c0..9e0b9d0 100644
18136 --- a/arch/x86/kernel/kprobes.c
18137 +++ b/arch/x86/kernel/kprobes.c
18138 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
18139 s32 raddr;
18140 } __attribute__((packed)) *insn;
18141
18142 - insn = (struct __arch_relative_insn *)from;
18143 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
18144 +
18145 + pax_open_kernel();
18146 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18147 insn->op = op;
18148 + pax_close_kernel();
18149 }
18150
18151 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18152 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
18153 kprobe_opcode_t opcode;
18154 kprobe_opcode_t *orig_opcodes = opcodes;
18155
18156 - if (search_exception_tables((unsigned long)opcodes))
18157 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18158 return 0; /* Page fault may occur on this address. */
18159
18160 retry:
18161 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
18162 * for the first byte, we can recover the original instruction
18163 * from it and kp->opcode.
18164 */
18165 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
18166 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
18167 buf[0] = kp->opcode;
18168 - return (unsigned long)buf;
18169 + return ktva_ktla((unsigned long)buf);
18170 }
18171
18172 /*
18173 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18174 /* Another subsystem puts a breakpoint, failed to recover */
18175 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18176 return 0;
18177 + pax_open_kernel();
18178 memcpy(dest, insn.kaddr, insn.length);
18179 + pax_close_kernel();
18180
18181 #ifdef CONFIG_X86_64
18182 if (insn_rip_relative(&insn)) {
18183 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18184 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18185 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18186 disp = (u8 *) dest + insn_offset_displacement(&insn);
18187 + pax_open_kernel();
18188 *(s32 *) disp = (s32) newdisp;
18189 + pax_close_kernel();
18190 }
18191 #endif
18192 return insn.length;
18193 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18194 * nor set current_kprobe, because it doesn't use single
18195 * stepping.
18196 */
18197 - regs->ip = (unsigned long)p->ainsn.insn;
18198 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18199 preempt_enable_no_resched();
18200 return;
18201 }
18202 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18203 regs->flags &= ~X86_EFLAGS_IF;
18204 /* single step inline if the instruction is an int3 */
18205 if (p->opcode == BREAKPOINT_INSTRUCTION)
18206 - regs->ip = (unsigned long)p->addr;
18207 + regs->ip = ktla_ktva((unsigned long)p->addr);
18208 else
18209 - regs->ip = (unsigned long)p->ainsn.insn;
18210 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18211 }
18212
18213 /*
18214 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18215 setup_singlestep(p, regs, kcb, 0);
18216 return 1;
18217 }
18218 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18219 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18220 /*
18221 * The breakpoint instruction was removed right
18222 * after we hit it. Another cpu has removed
18223 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18224 " movq %rax, 152(%rsp)\n"
18225 RESTORE_REGS_STRING
18226 " popfq\n"
18227 +#ifdef KERNEXEC_PLUGIN
18228 + " btsq $63,(%rsp)\n"
18229 +#endif
18230 #else
18231 " pushf\n"
18232 SAVE_REGS_STRING
18233 @@ -788,7 +798,7 @@ static void __kprobes
18234 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18235 {
18236 unsigned long *tos = stack_addr(regs);
18237 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18238 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18239 unsigned long orig_ip = (unsigned long)p->addr;
18240 kprobe_opcode_t *insn = p->ainsn.insn;
18241
18242 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18243 struct die_args *args = data;
18244 int ret = NOTIFY_DONE;
18245
18246 - if (args->regs && user_mode_vm(args->regs))
18247 + if (args->regs && user_mode(args->regs))
18248 return ret;
18249
18250 switch (val) {
18251 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18252 index ebc9873..1b9724b 100644
18253 --- a/arch/x86/kernel/ldt.c
18254 +++ b/arch/x86/kernel/ldt.c
18255 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18256 if (reload) {
18257 #ifdef CONFIG_SMP
18258 preempt_disable();
18259 - load_LDT(pc);
18260 + load_LDT_nolock(pc);
18261 if (!cpumask_equal(mm_cpumask(current->mm),
18262 cpumask_of(smp_processor_id())))
18263 smp_call_function(flush_ldt, current->mm, 1);
18264 preempt_enable();
18265 #else
18266 - load_LDT(pc);
18267 + load_LDT_nolock(pc);
18268 #endif
18269 }
18270 if (oldsize) {
18271 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18272 return err;
18273
18274 for (i = 0; i < old->size; i++)
18275 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18276 + write_ldt_entry(new->ldt, i, old->ldt + i);
18277 return 0;
18278 }
18279
18280 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18281 retval = copy_ldt(&mm->context, &old_mm->context);
18282 mutex_unlock(&old_mm->context.lock);
18283 }
18284 +
18285 + if (tsk == current) {
18286 + mm->context.vdso = 0;
18287 +
18288 +#ifdef CONFIG_X86_32
18289 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18290 + mm->context.user_cs_base = 0UL;
18291 + mm->context.user_cs_limit = ~0UL;
18292 +
18293 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18294 + cpus_clear(mm->context.cpu_user_cs_mask);
18295 +#endif
18296 +
18297 +#endif
18298 +#endif
18299 +
18300 + }
18301 +
18302 return retval;
18303 }
18304
18305 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18306 }
18307 }
18308
18309 +#ifdef CONFIG_PAX_SEGMEXEC
18310 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18311 + error = -EINVAL;
18312 + goto out_unlock;
18313 + }
18314 +#endif
18315 +
18316 fill_ldt(&ldt, &ldt_info);
18317 if (oldmode)
18318 ldt.avl = 0;
18319 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18320 index 5b19e4d..6476a76 100644
18321 --- a/arch/x86/kernel/machine_kexec_32.c
18322 +++ b/arch/x86/kernel/machine_kexec_32.c
18323 @@ -26,7 +26,7 @@
18324 #include <asm/cacheflush.h>
18325 #include <asm/debugreg.h>
18326
18327 -static void set_idt(void *newidt, __u16 limit)
18328 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18329 {
18330 struct desc_ptr curidt;
18331
18332 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18333 }
18334
18335
18336 -static void set_gdt(void *newgdt, __u16 limit)
18337 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18338 {
18339 struct desc_ptr curgdt;
18340
18341 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18342 }
18343
18344 control_page = page_address(image->control_code_page);
18345 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18346 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18347
18348 relocate_kernel_ptr = control_page;
18349 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18350 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18351 index 3544aed..01ddc1c 100644
18352 --- a/arch/x86/kernel/microcode_intel.c
18353 +++ b/arch/x86/kernel/microcode_intel.c
18354 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
18355
18356 static int get_ucode_user(void *to, const void *from, size_t n)
18357 {
18358 - return copy_from_user(to, from, n);
18359 + return copy_from_user(to, (const void __force_user *)from, n);
18360 }
18361
18362 static enum ucode_state
18363 request_microcode_user(int cpu, const void __user *buf, size_t size)
18364 {
18365 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18366 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18367 }
18368
18369 static void microcode_fini_cpu(int cpu)
18370 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18371 index 216a4d7..b328f09 100644
18372 --- a/arch/x86/kernel/module.c
18373 +++ b/arch/x86/kernel/module.c
18374 @@ -43,15 +43,60 @@ do { \
18375 } while (0)
18376 #endif
18377
18378 -void *module_alloc(unsigned long size)
18379 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18380 {
18381 - if (PAGE_ALIGN(size) > MODULES_LEN)
18382 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18383 return NULL;
18384 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18385 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18386 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18387 -1, __builtin_return_address(0));
18388 }
18389
18390 +void *module_alloc(unsigned long size)
18391 +{
18392 +
18393 +#ifdef CONFIG_PAX_KERNEXEC
18394 + return __module_alloc(size, PAGE_KERNEL);
18395 +#else
18396 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18397 +#endif
18398 +
18399 +}
18400 +
18401 +#ifdef CONFIG_PAX_KERNEXEC
18402 +#ifdef CONFIG_X86_32
18403 +void *module_alloc_exec(unsigned long size)
18404 +{
18405 + struct vm_struct *area;
18406 +
18407 + if (size == 0)
18408 + return NULL;
18409 +
18410 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18411 + return area ? area->addr : NULL;
18412 +}
18413 +EXPORT_SYMBOL(module_alloc_exec);
18414 +
18415 +void module_free_exec(struct module *mod, void *module_region)
18416 +{
18417 + vunmap(module_region);
18418 +}
18419 +EXPORT_SYMBOL(module_free_exec);
18420 +#else
18421 +void module_free_exec(struct module *mod, void *module_region)
18422 +{
18423 + module_free(mod, module_region);
18424 +}
18425 +EXPORT_SYMBOL(module_free_exec);
18426 +
18427 +void *module_alloc_exec(unsigned long size)
18428 +{
18429 + return __module_alloc(size, PAGE_KERNEL_RX);
18430 +}
18431 +EXPORT_SYMBOL(module_alloc_exec);
18432 +#endif
18433 +#endif
18434 +
18435 #ifdef CONFIG_X86_32
18436 int apply_relocate(Elf32_Shdr *sechdrs,
18437 const char *strtab,
18438 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18439 unsigned int i;
18440 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18441 Elf32_Sym *sym;
18442 - uint32_t *location;
18443 + uint32_t *plocation, location;
18444
18445 DEBUGP("Applying relocate section %u to %u\n",
18446 relsec, sechdrs[relsec].sh_info);
18447 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18448 /* This is where to make the change */
18449 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18450 - + rel[i].r_offset;
18451 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18452 + location = (uint32_t)plocation;
18453 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18454 + plocation = ktla_ktva((void *)plocation);
18455 /* This is the symbol it is referring to. Note that all
18456 undefined symbols have been resolved. */
18457 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18458 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18459 switch (ELF32_R_TYPE(rel[i].r_info)) {
18460 case R_386_32:
18461 /* We add the value into the location given */
18462 - *location += sym->st_value;
18463 + pax_open_kernel();
18464 + *plocation += sym->st_value;
18465 + pax_close_kernel();
18466 break;
18467 case R_386_PC32:
18468 /* Add the value, subtract its position */
18469 - *location += sym->st_value - (uint32_t)location;
18470 + pax_open_kernel();
18471 + *plocation += sym->st_value - location;
18472 + pax_close_kernel();
18473 break;
18474 default:
18475 pr_err("%s: Unknown relocation: %u\n",
18476 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18477 case R_X86_64_NONE:
18478 break;
18479 case R_X86_64_64:
18480 + pax_open_kernel();
18481 *(u64 *)loc = val;
18482 + pax_close_kernel();
18483 break;
18484 case R_X86_64_32:
18485 + pax_open_kernel();
18486 *(u32 *)loc = val;
18487 + pax_close_kernel();
18488 if (val != *(u32 *)loc)
18489 goto overflow;
18490 break;
18491 case R_X86_64_32S:
18492 + pax_open_kernel();
18493 *(s32 *)loc = val;
18494 + pax_close_kernel();
18495 if ((s64)val != *(s32 *)loc)
18496 goto overflow;
18497 break;
18498 case R_X86_64_PC32:
18499 val -= (u64)loc;
18500 + pax_open_kernel();
18501 *(u32 *)loc = val;
18502 + pax_close_kernel();
18503 +
18504 #if 0
18505 if ((s64)val != *(s32 *)loc)
18506 goto overflow;
18507 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18508 index f84f5c5..e27e54b 100644
18509 --- a/arch/x86/kernel/nmi.c
18510 +++ b/arch/x86/kernel/nmi.c
18511 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18512 dotraplinkage notrace __kprobes void
18513 do_nmi(struct pt_regs *regs, long error_code)
18514 {
18515 +
18516 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18517 + if (!user_mode(regs)) {
18518 + unsigned long cs = regs->cs & 0xFFFF;
18519 + unsigned long ip = ktva_ktla(regs->ip);
18520 +
18521 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18522 + regs->ip = ip;
18523 + }
18524 +#endif
18525 +
18526 nmi_nesting_preprocess(regs);
18527
18528 nmi_enter();
18529 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18530 index 676b8c7..870ba04 100644
18531 --- a/arch/x86/kernel/paravirt-spinlocks.c
18532 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18533 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18534 arch_spin_lock(lock);
18535 }
18536
18537 -struct pv_lock_ops pv_lock_ops = {
18538 +struct pv_lock_ops pv_lock_ops __read_only = {
18539 #ifdef CONFIG_SMP
18540 .spin_is_locked = __ticket_spin_is_locked,
18541 .spin_is_contended = __ticket_spin_is_contended,
18542 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18543 index 17fff18..7bb2088 100644
18544 --- a/arch/x86/kernel/paravirt.c
18545 +++ b/arch/x86/kernel/paravirt.c
18546 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18547 {
18548 return x;
18549 }
18550 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18551 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18552 +#endif
18553
18554 void __init default_banner(void)
18555 {
18556 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18557 if (opfunc == NULL)
18558 /* If there's no function, patch it with a ud2a (BUG) */
18559 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18560 - else if (opfunc == _paravirt_nop)
18561 + else if (opfunc == (void *)_paravirt_nop)
18562 /* If the operation is a nop, then nop the callsite */
18563 ret = paravirt_patch_nop();
18564
18565 /* identity functions just return their single argument */
18566 - else if (opfunc == _paravirt_ident_32)
18567 + else if (opfunc == (void *)_paravirt_ident_32)
18568 ret = paravirt_patch_ident_32(insnbuf, len);
18569 - else if (opfunc == _paravirt_ident_64)
18570 + else if (opfunc == (void *)_paravirt_ident_64)
18571 ret = paravirt_patch_ident_64(insnbuf, len);
18572 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18573 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18574 + ret = paravirt_patch_ident_64(insnbuf, len);
18575 +#endif
18576
18577 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18578 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18579 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18580 if (insn_len > len || start == NULL)
18581 insn_len = len;
18582 else
18583 - memcpy(insnbuf, start, insn_len);
18584 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18585
18586 return insn_len;
18587 }
18588 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18589 preempt_enable();
18590 }
18591
18592 -struct pv_info pv_info = {
18593 +struct pv_info pv_info __read_only = {
18594 .name = "bare hardware",
18595 .paravirt_enabled = 0,
18596 .kernel_rpl = 0,
18597 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18598 #endif
18599 };
18600
18601 -struct pv_init_ops pv_init_ops = {
18602 +struct pv_init_ops pv_init_ops __read_only = {
18603 .patch = native_patch,
18604 };
18605
18606 -struct pv_time_ops pv_time_ops = {
18607 +struct pv_time_ops pv_time_ops __read_only = {
18608 .sched_clock = native_sched_clock,
18609 .steal_clock = native_steal_clock,
18610 };
18611
18612 -struct pv_irq_ops pv_irq_ops = {
18613 +struct pv_irq_ops pv_irq_ops __read_only = {
18614 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18615 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18616 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18617 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18618 #endif
18619 };
18620
18621 -struct pv_cpu_ops pv_cpu_ops = {
18622 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18623 .cpuid = native_cpuid,
18624 .get_debugreg = native_get_debugreg,
18625 .set_debugreg = native_set_debugreg,
18626 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18627 .end_context_switch = paravirt_nop,
18628 };
18629
18630 -struct pv_apic_ops pv_apic_ops = {
18631 +struct pv_apic_ops pv_apic_ops __read_only = {
18632 #ifdef CONFIG_X86_LOCAL_APIC
18633 .startup_ipi_hook = paravirt_nop,
18634 #endif
18635 };
18636
18637 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18638 +#ifdef CONFIG_X86_32
18639 +#ifdef CONFIG_X86_PAE
18640 +/* 64-bit pagetable entries */
18641 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18642 +#else
18643 /* 32-bit pagetable entries */
18644 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18645 +#endif
18646 #else
18647 /* 64-bit pagetable entries */
18648 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18649 #endif
18650
18651 -struct pv_mmu_ops pv_mmu_ops = {
18652 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18653
18654 .read_cr2 = native_read_cr2,
18655 .write_cr2 = native_write_cr2,
18656 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18657 .make_pud = PTE_IDENT,
18658
18659 .set_pgd = native_set_pgd,
18660 + .set_pgd_batched = native_set_pgd_batched,
18661 #endif
18662 #endif /* PAGETABLE_LEVELS >= 3 */
18663
18664 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18665 },
18666
18667 .set_fixmap = native_set_fixmap,
18668 +
18669 +#ifdef CONFIG_PAX_KERNEXEC
18670 + .pax_open_kernel = native_pax_open_kernel,
18671 + .pax_close_kernel = native_pax_close_kernel,
18672 +#endif
18673 +
18674 };
18675
18676 EXPORT_SYMBOL_GPL(pv_time_ops);
18677 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18678 index 35ccf75..7a15747 100644
18679 --- a/arch/x86/kernel/pci-iommu_table.c
18680 +++ b/arch/x86/kernel/pci-iommu_table.c
18681 @@ -2,7 +2,7 @@
18682 #include <asm/iommu_table.h>
18683 #include <linux/string.h>
18684 #include <linux/kallsyms.h>
18685 -
18686 +#include <linux/sched.h>
18687
18688 #define DEBUG 1
18689
18690 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18691 index b644e1c..4a6d379 100644
18692 --- a/arch/x86/kernel/process.c
18693 +++ b/arch/x86/kernel/process.c
18694 @@ -36,7 +36,8 @@
18695 * section. Since TSS's are completely CPU-local, we want them
18696 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18697 */
18698 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18699 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18700 +EXPORT_SYMBOL(init_tss);
18701
18702 #ifdef CONFIG_X86_64
18703 static DEFINE_PER_CPU(unsigned char, is_idle);
18704 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18705 task_xstate_cachep =
18706 kmem_cache_create("task_xstate", xstate_size,
18707 __alignof__(union thread_xstate),
18708 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18709 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18710 }
18711
18712 /*
18713 @@ -105,7 +106,7 @@ void exit_thread(void)
18714 unsigned long *bp = t->io_bitmap_ptr;
18715
18716 if (bp) {
18717 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18718 + struct tss_struct *tss = init_tss + get_cpu();
18719
18720 t->io_bitmap_ptr = NULL;
18721 clear_thread_flag(TIF_IO_BITMAP);
18722 @@ -136,7 +137,7 @@ void show_regs_common(void)
18723 board = dmi_get_system_info(DMI_BOARD_NAME);
18724
18725 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18726 - current->pid, current->comm, print_tainted(),
18727 + task_pid_nr(current), current->comm, print_tainted(),
18728 init_utsname()->release,
18729 (int)strcspn(init_utsname()->version, " "),
18730 init_utsname()->version,
18731 @@ -149,6 +150,9 @@ void flush_thread(void)
18732 {
18733 struct task_struct *tsk = current;
18734
18735 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18736 + loadsegment(gs, 0);
18737 +#endif
18738 flush_ptrace_hw_breakpoint(tsk);
18739 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18740 drop_init_fpu(tsk);
18741 @@ -336,7 +340,7 @@ static void __exit_idle(void)
18742 void exit_idle(void)
18743 {
18744 /* idle loop has pid 0 */
18745 - if (current->pid)
18746 + if (task_pid_nr(current))
18747 return;
18748 __exit_idle();
18749 }
18750 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
18751
18752 return ret;
18753 }
18754 -void stop_this_cpu(void *dummy)
18755 +__noreturn void stop_this_cpu(void *dummy)
18756 {
18757 local_irq_disable();
18758 /*
18759 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
18760 }
18761 early_param("idle", idle_setup);
18762
18763 -unsigned long arch_align_stack(unsigned long sp)
18764 +#ifdef CONFIG_PAX_RANDKSTACK
18765 +void pax_randomize_kstack(struct pt_regs *regs)
18766 {
18767 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18768 - sp -= get_random_int() % 8192;
18769 - return sp & ~0xf;
18770 -}
18771 + struct thread_struct *thread = &current->thread;
18772 + unsigned long time;
18773
18774 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18775 -{
18776 - unsigned long range_end = mm->brk + 0x02000000;
18777 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18778 -}
18779 + if (!randomize_va_space)
18780 + return;
18781 +
18782 + if (v8086_mode(regs))
18783 + return;
18784
18785 + rdtscl(time);
18786 +
18787 + /* P4 seems to return a 0 LSB, ignore it */
18788 +#ifdef CONFIG_MPENTIUM4
18789 + time &= 0x3EUL;
18790 + time <<= 2;
18791 +#elif defined(CONFIG_X86_64)
18792 + time &= 0xFUL;
18793 + time <<= 4;
18794 +#else
18795 + time &= 0x1FUL;
18796 + time <<= 3;
18797 +#endif
18798 +
18799 + thread->sp0 ^= time;
18800 + load_sp0(init_tss + smp_processor_id(), thread);
18801 +
18802 +#ifdef CONFIG_X86_64
18803 + this_cpu_write(kernel_stack, thread->sp0);
18804 +#endif
18805 +}
18806 +#endif
18807 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18808 index 44e0bff..5ceb99c 100644
18809 --- a/arch/x86/kernel/process_32.c
18810 +++ b/arch/x86/kernel/process_32.c
18811 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
18812 unsigned long thread_saved_pc(struct task_struct *tsk)
18813 {
18814 return ((unsigned long *)tsk->thread.sp)[3];
18815 +//XXX return tsk->thread.eip;
18816 }
18817
18818 void __show_regs(struct pt_regs *regs, int all)
18819 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
18820 unsigned long sp;
18821 unsigned short ss, gs;
18822
18823 - if (user_mode_vm(regs)) {
18824 + if (user_mode(regs)) {
18825 sp = regs->sp;
18826 ss = regs->ss & 0xffff;
18827 - gs = get_user_gs(regs);
18828 } else {
18829 sp = kernel_stack_pointer(regs);
18830 savesegment(ss, ss);
18831 - savesegment(gs, gs);
18832 }
18833 + gs = get_user_gs(regs);
18834
18835 show_regs_common();
18836
18837 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
18838 (u16)regs->cs, regs->ip, regs->flags,
18839 - smp_processor_id());
18840 + raw_smp_processor_id());
18841 print_symbol("EIP is at %s\n", regs->ip);
18842
18843 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
18844 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18845 unsigned long arg,
18846 struct task_struct *p, struct pt_regs *regs)
18847 {
18848 - struct pt_regs *childregs = task_pt_regs(p);
18849 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18850 struct task_struct *tsk;
18851 int err;
18852
18853 p->thread.sp = (unsigned long) childregs;
18854 p->thread.sp0 = (unsigned long) (childregs+1);
18855 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18856
18857 if (unlikely(!regs)) {
18858 /* kernel thread */
18859 memset(childregs, 0, sizeof(struct pt_regs));
18860 p->thread.ip = (unsigned long) ret_from_kernel_thread;
18861 - task_user_gs(p) = __KERNEL_STACK_CANARY;
18862 - childregs->ds = __USER_DS;
18863 - childregs->es = __USER_DS;
18864 + savesegment(gs, childregs->gs);
18865 + childregs->ds = __KERNEL_DS;
18866 + childregs->es = __KERNEL_DS;
18867 childregs->fs = __KERNEL_PERCPU;
18868 childregs->bx = sp; /* function */
18869 childregs->bp = arg;
18870 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18871 struct thread_struct *prev = &prev_p->thread,
18872 *next = &next_p->thread;
18873 int cpu = smp_processor_id();
18874 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18875 + struct tss_struct *tss = init_tss + cpu;
18876 fpu_switch_t fpu;
18877
18878 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18879 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18880 */
18881 lazy_save_gs(prev->gs);
18882
18883 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18884 + __set_fs(task_thread_info(next_p)->addr_limit);
18885 +#endif
18886 +
18887 /*
18888 * Load the per-thread Thread-Local Storage descriptor.
18889 */
18890 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18891 */
18892 arch_end_context_switch(next_p);
18893
18894 + this_cpu_write(current_task, next_p);
18895 + this_cpu_write(current_tinfo, &next_p->tinfo);
18896 +
18897 /*
18898 * Restore %gs if needed (which is common)
18899 */
18900 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18901
18902 switch_fpu_finish(next_p, fpu);
18903
18904 - this_cpu_write(current_task, next_p);
18905 -
18906 return prev_p;
18907 }
18908
18909 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
18910 } while (count++ < 16);
18911 return 0;
18912 }
18913 -
18914 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18915 index 16c6365..5d32218 100644
18916 --- a/arch/x86/kernel/process_64.c
18917 +++ b/arch/x86/kernel/process_64.c
18918 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18919 struct pt_regs *childregs;
18920 struct task_struct *me = current;
18921
18922 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
18923 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
18924 childregs = task_pt_regs(p);
18925 p->thread.sp = (unsigned long) childregs;
18926 p->thread.usersp = me->thread.usersp;
18927 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18928 set_tsk_thread_flag(p, TIF_FORK);
18929 p->fpu_counter = 0;
18930 p->thread.io_bitmap_ptr = NULL;
18931 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18932 struct thread_struct *prev = &prev_p->thread;
18933 struct thread_struct *next = &next_p->thread;
18934 int cpu = smp_processor_id();
18935 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18936 + struct tss_struct *tss = init_tss + cpu;
18937 unsigned fsindex, gsindex;
18938 fpu_switch_t fpu;
18939
18940 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18941 prev->usersp = this_cpu_read(old_rsp);
18942 this_cpu_write(old_rsp, next->usersp);
18943 this_cpu_write(current_task, next_p);
18944 + this_cpu_write(current_tinfo, &next_p->tinfo);
18945
18946 - this_cpu_write(kernel_stack,
18947 - (unsigned long)task_stack_page(next_p) +
18948 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18949 + this_cpu_write(kernel_stack, next->sp0);
18950
18951 /*
18952 * Now maybe reload the debug registers and handle I/O bitmaps
18953 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
18954 if (!p || p == current || p->state == TASK_RUNNING)
18955 return 0;
18956 stack = (unsigned long)task_stack_page(p);
18957 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18958 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18959 return 0;
18960 fp = *(u64 *)(p->thread.sp);
18961 do {
18962 - if (fp < (unsigned long)stack ||
18963 - fp >= (unsigned long)stack+THREAD_SIZE)
18964 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18965 return 0;
18966 ip = *(u64 *)(fp+8);
18967 if (!in_sched_functions(ip))
18968 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18969 index 974b67e..561fcd7 100644
18970 --- a/arch/x86/kernel/ptrace.c
18971 +++ b/arch/x86/kernel/ptrace.c
18972 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
18973 {
18974 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
18975 unsigned long sp = (unsigned long)&regs->sp;
18976 - struct thread_info *tinfo;
18977
18978 - if (context == (sp & ~(THREAD_SIZE - 1)))
18979 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
18980 return sp;
18981
18982 - tinfo = (struct thread_info *)context;
18983 - if (tinfo->previous_esp)
18984 - return tinfo->previous_esp;
18985 + sp = *(unsigned long *)context;
18986 + if (sp)
18987 + return sp;
18988
18989 return (unsigned long)regs;
18990 }
18991 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
18992 unsigned long addr, unsigned long data)
18993 {
18994 int ret;
18995 - unsigned long __user *datap = (unsigned long __user *)data;
18996 + unsigned long __user *datap = (__force unsigned long __user *)data;
18997
18998 switch (request) {
18999 /* read the word at location addr in the USER area. */
19000 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
19001 if ((int) addr < 0)
19002 return -EIO;
19003 ret = do_get_thread_area(child, addr,
19004 - (struct user_desc __user *)data);
19005 + (__force struct user_desc __user *) data);
19006 break;
19007
19008 case PTRACE_SET_THREAD_AREA:
19009 if ((int) addr < 0)
19010 return -EIO;
19011 ret = do_set_thread_area(child, addr,
19012 - (struct user_desc __user *)data, 0);
19013 + (__force struct user_desc __user *) data, 0);
19014 break;
19015 #endif
19016
19017 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
19018 memset(info, 0, sizeof(*info));
19019 info->si_signo = SIGTRAP;
19020 info->si_code = si_code;
19021 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
19022 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
19023 }
19024
19025 void user_single_step_siginfo(struct task_struct *tsk,
19026 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
19027 # define IS_IA32 0
19028 #endif
19029
19030 +#ifdef CONFIG_GRKERNSEC_SETXID
19031 +extern void gr_delayed_cred_worker(void);
19032 +#endif
19033 +
19034 /*
19035 * We must return the syscall number to actually look up in the table.
19036 * This can be -1L to skip running any syscall at all.
19037 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
19038
19039 rcu_user_exit();
19040
19041 +#ifdef CONFIG_GRKERNSEC_SETXID
19042 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
19043 + gr_delayed_cred_worker();
19044 +#endif
19045 +
19046 /*
19047 * If we stepped into a sysenter/syscall insn, it trapped in
19048 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
19049 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
19050 */
19051 rcu_user_exit();
19052
19053 +#ifdef CONFIG_GRKERNSEC_SETXID
19054 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
19055 + gr_delayed_cred_worker();
19056 +#endif
19057 +
19058 audit_syscall_exit(regs);
19059
19060 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
19061 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
19062 index 42eb330..139955c 100644
19063 --- a/arch/x86/kernel/pvclock.c
19064 +++ b/arch/x86/kernel/pvclock.c
19065 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
19066 return pv_tsc_khz;
19067 }
19068
19069 -static atomic64_t last_value = ATOMIC64_INIT(0);
19070 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
19071
19072 void pvclock_resume(void)
19073 {
19074 - atomic64_set(&last_value, 0);
19075 + atomic64_set_unchecked(&last_value, 0);
19076 }
19077
19078 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19079 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19080 * updating at the same time, and one of them could be slightly behind,
19081 * making the assumption that last_value always go forward fail to hold.
19082 */
19083 - last = atomic64_read(&last_value);
19084 + last = atomic64_read_unchecked(&last_value);
19085 do {
19086 if (ret < last)
19087 return last;
19088 - last = atomic64_cmpxchg(&last_value, last, ret);
19089 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
19090 } while (unlikely(last != ret));
19091
19092 return ret;
19093 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
19094 index 4e8ba39..e0186b3 100644
19095 --- a/arch/x86/kernel/reboot.c
19096 +++ b/arch/x86/kernel/reboot.c
19097 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
19098 EXPORT_SYMBOL(pm_power_off);
19099
19100 static const struct desc_ptr no_idt = {};
19101 -static int reboot_mode;
19102 +static unsigned short reboot_mode;
19103 enum reboot_type reboot_type = BOOT_ACPI;
19104 int reboot_force;
19105
19106 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
19107
19108 void __noreturn machine_real_restart(unsigned int type)
19109 {
19110 +
19111 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19112 + struct desc_struct *gdt;
19113 +#endif
19114 +
19115 local_irq_disable();
19116
19117 /*
19118 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
19119
19120 /* Jump to the identity-mapped low memory code */
19121 #ifdef CONFIG_X86_32
19122 - asm volatile("jmpl *%0" : :
19123 +
19124 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
19125 + gdt = get_cpu_gdt_table(smp_processor_id());
19126 + pax_open_kernel();
19127 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19128 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
19129 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
19130 + loadsegment(ds, __KERNEL_DS);
19131 + loadsegment(es, __KERNEL_DS);
19132 + loadsegment(ss, __KERNEL_DS);
19133 +#endif
19134 +#ifdef CONFIG_PAX_KERNEXEC
19135 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
19136 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
19137 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
19138 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
19139 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
19140 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
19141 +#endif
19142 + pax_close_kernel();
19143 +#endif
19144 +
19145 + asm volatile("ljmpl *%0" : :
19146 "rm" (real_mode_header->machine_real_restart_asm),
19147 "a" (type));
19148 #else
19149 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
19150 * try to force a triple fault and then cycle between hitting the keyboard
19151 * controller and doing that
19152 */
19153 -static void native_machine_emergency_restart(void)
19154 +static void __noreturn native_machine_emergency_restart(void)
19155 {
19156 int i;
19157 int attempt = 0;
19158 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
19159 #endif
19160 }
19161
19162 -static void __machine_emergency_restart(int emergency)
19163 +static void __noreturn __machine_emergency_restart(int emergency)
19164 {
19165 reboot_emergency = emergency;
19166 machine_ops.emergency_restart();
19167 }
19168
19169 -static void native_machine_restart(char *__unused)
19170 +static void __noreturn native_machine_restart(char *__unused)
19171 {
19172 pr_notice("machine restart\n");
19173
19174 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
19175 __machine_emergency_restart(0);
19176 }
19177
19178 -static void native_machine_halt(void)
19179 +static void __noreturn native_machine_halt(void)
19180 {
19181 /* Stop other cpus and apics */
19182 machine_shutdown();
19183 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
19184 stop_this_cpu(NULL);
19185 }
19186
19187 -static void native_machine_power_off(void)
19188 +static void __noreturn native_machine_power_off(void)
19189 {
19190 if (pm_power_off) {
19191 if (!reboot_force)
19192 @@ -688,6 +715,7 @@ static void native_machine_power_off(void)
19193 }
19194 /* A fallback in case there is no PM info available */
19195 tboot_shutdown(TB_SHUTDOWN_HALT);
19196 + unreachable();
19197 }
19198
19199 struct machine_ops machine_ops = {
19200 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19201 index 7a6f3b3..bed145d7 100644
19202 --- a/arch/x86/kernel/relocate_kernel_64.S
19203 +++ b/arch/x86/kernel/relocate_kernel_64.S
19204 @@ -11,6 +11,7 @@
19205 #include <asm/kexec.h>
19206 #include <asm/processor-flags.h>
19207 #include <asm/pgtable_types.h>
19208 +#include <asm/alternative-asm.h>
19209
19210 /*
19211 * Must be relocatable PIC code callable as a C function
19212 @@ -160,13 +161,14 @@ identity_mapped:
19213 xorq %rbp, %rbp
19214 xorq %r8, %r8
19215 xorq %r9, %r9
19216 - xorq %r10, %r9
19217 + xorq %r10, %r10
19218 xorq %r11, %r11
19219 xorq %r12, %r12
19220 xorq %r13, %r13
19221 xorq %r14, %r14
19222 xorq %r15, %r15
19223
19224 + pax_force_retaddr 0, 1
19225 ret
19226
19227 1:
19228 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19229 index ca45696..6384a09 100644
19230 --- a/arch/x86/kernel/setup.c
19231 +++ b/arch/x86/kernel/setup.c
19232 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
19233
19234 switch (data->type) {
19235 case SETUP_E820_EXT:
19236 - parse_e820_ext(data);
19237 + parse_e820_ext((struct setup_data __force_kernel *)data);
19238 break;
19239 case SETUP_DTB:
19240 add_dtb(pa_data);
19241 @@ -633,7 +633,7 @@ static void __init trim_bios_range(void)
19242 * area (640->1Mb) as ram even though it is not.
19243 * take them out.
19244 */
19245 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19246 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19247 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19248 }
19249
19250 @@ -756,14 +756,14 @@ void __init setup_arch(char **cmdline_p)
19251
19252 if (!boot_params.hdr.root_flags)
19253 root_mountflags &= ~MS_RDONLY;
19254 - init_mm.start_code = (unsigned long) _text;
19255 - init_mm.end_code = (unsigned long) _etext;
19256 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19257 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19258 init_mm.end_data = (unsigned long) _edata;
19259 init_mm.brk = _brk_end;
19260
19261 - code_resource.start = virt_to_phys(_text);
19262 - code_resource.end = virt_to_phys(_etext)-1;
19263 - data_resource.start = virt_to_phys(_etext);
19264 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19265 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19266 + data_resource.start = virt_to_phys(_sdata);
19267 data_resource.end = virt_to_phys(_edata)-1;
19268 bss_resource.start = virt_to_phys(&__bss_start);
19269 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19270 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19271 index 5cdff03..5810740 100644
19272 --- a/arch/x86/kernel/setup_percpu.c
19273 +++ b/arch/x86/kernel/setup_percpu.c
19274 @@ -21,19 +21,17 @@
19275 #include <asm/cpu.h>
19276 #include <asm/stackprotector.h>
19277
19278 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19279 +#ifdef CONFIG_SMP
19280 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19281 EXPORT_PER_CPU_SYMBOL(cpu_number);
19282 +#endif
19283
19284 -#ifdef CONFIG_X86_64
19285 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19286 -#else
19287 -#define BOOT_PERCPU_OFFSET 0
19288 -#endif
19289
19290 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19291 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19292
19293 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19294 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19295 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19296 };
19297 EXPORT_SYMBOL(__per_cpu_offset);
19298 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19299 {
19300 #ifdef CONFIG_X86_32
19301 struct desc_struct gdt;
19302 + unsigned long base = per_cpu_offset(cpu);
19303
19304 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19305 - 0x2 | DESCTYPE_S, 0x8);
19306 - gdt.s = 1;
19307 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19308 + 0x83 | DESCTYPE_S, 0xC);
19309 write_gdt_entry(get_cpu_gdt_table(cpu),
19310 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19311 #endif
19312 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19313 /* alrighty, percpu areas up and running */
19314 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19315 for_each_possible_cpu(cpu) {
19316 +#ifdef CONFIG_CC_STACKPROTECTOR
19317 +#ifdef CONFIG_X86_32
19318 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19319 +#endif
19320 +#endif
19321 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19322 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19323 per_cpu(cpu_number, cpu) = cpu;
19324 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19325 */
19326 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19327 #endif
19328 +#ifdef CONFIG_CC_STACKPROTECTOR
19329 +#ifdef CONFIG_X86_32
19330 + if (!cpu)
19331 + per_cpu(stack_canary.canary, cpu) = canary;
19332 +#endif
19333 +#endif
19334 /*
19335 * Up to this point, the boot CPU has been using .init.data
19336 * area. Reload any changed state for the boot CPU.
19337 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19338 index 70b27ee..fcf827f 100644
19339 --- a/arch/x86/kernel/signal.c
19340 +++ b/arch/x86/kernel/signal.c
19341 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
19342 * Align the stack pointer according to the i386 ABI,
19343 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19344 */
19345 - sp = ((sp + 4) & -16ul) - 4;
19346 + sp = ((sp - 12) & -16ul) - 4;
19347 #else /* !CONFIG_X86_32 */
19348 sp = round_down(sp, 16) - 8;
19349 #endif
19350 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19351 }
19352
19353 if (current->mm->context.vdso)
19354 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19355 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19356 else
19357 - restorer = &frame->retcode;
19358 + restorer = (void __user *)&frame->retcode;
19359 if (ka->sa.sa_flags & SA_RESTORER)
19360 restorer = ka->sa.sa_restorer;
19361
19362 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19363 * reasons and because gdb uses it as a signature to notice
19364 * signal handler stack frames.
19365 */
19366 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19367 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19368
19369 if (err)
19370 return -EFAULT;
19371 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19372 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
19373
19374 /* Set up to return from userspace. */
19375 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19376 + if (current->mm->context.vdso)
19377 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19378 + else
19379 + restorer = (void __user *)&frame->retcode;
19380 if (ka->sa.sa_flags & SA_RESTORER)
19381 restorer = ka->sa.sa_restorer;
19382 put_user_ex(restorer, &frame->pretcode);
19383 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19384 * reasons and because gdb uses it as a signature to notice
19385 * signal handler stack frames.
19386 */
19387 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19388 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19389 } put_user_catch(err);
19390
19391 err |= copy_siginfo_to_user(&frame->info, info);
19392 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19393 index f3e2ec8..ad5287a 100644
19394 --- a/arch/x86/kernel/smpboot.c
19395 +++ b/arch/x86/kernel/smpboot.c
19396 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19397 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19398 (THREAD_SIZE + task_stack_page(idle))) - 1);
19399 per_cpu(current_task, cpu) = idle;
19400 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19401
19402 #ifdef CONFIG_X86_32
19403 /* Stack for startup_32 can be just as for start_secondary onwards */
19404 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19405 #else
19406 clear_tsk_thread_flag(idle, TIF_FORK);
19407 initial_gs = per_cpu_offset(cpu);
19408 - per_cpu(kernel_stack, cpu) =
19409 - (unsigned long)task_stack_page(idle) -
19410 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19411 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19412 #endif
19413 +
19414 + pax_open_kernel();
19415 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19416 + pax_close_kernel();
19417 +
19418 initial_code = (unsigned long)start_secondary;
19419 stack_start = idle->thread.sp;
19420
19421 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19422 /* the FPU context is blank, nobody can own it */
19423 __cpu_disable_lazy_restore(cpu);
19424
19425 +#ifdef CONFIG_PAX_PER_CPU_PGD
19426 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19427 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19428 + KERNEL_PGD_PTRS);
19429 +#endif
19430 +
19431 + /* the FPU context is blank, nobody can own it */
19432 + __cpu_disable_lazy_restore(cpu);
19433 +
19434 err = do_boot_cpu(apicid, cpu, tidle);
19435 if (err) {
19436 pr_debug("do_boot_cpu failed %d\n", err);
19437 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19438 index cd3b243..4ba27a4 100644
19439 --- a/arch/x86/kernel/step.c
19440 +++ b/arch/x86/kernel/step.c
19441 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19442 struct desc_struct *desc;
19443 unsigned long base;
19444
19445 - seg &= ~7UL;
19446 + seg >>= 3;
19447
19448 mutex_lock(&child->mm->context.lock);
19449 - if (unlikely((seg >> 3) >= child->mm->context.size))
19450 + if (unlikely(seg >= child->mm->context.size))
19451 addr = -1L; /* bogus selector, access would fault */
19452 else {
19453 desc = child->mm->context.ldt + seg;
19454 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19455 addr += base;
19456 }
19457 mutex_unlock(&child->mm->context.lock);
19458 - }
19459 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19460 + addr = ktla_ktva(addr);
19461
19462 return addr;
19463 }
19464 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19465 unsigned char opcode[15];
19466 unsigned long addr = convert_ip_to_linear(child, regs);
19467
19468 + if (addr == -EINVAL)
19469 + return 0;
19470 +
19471 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19472 for (i = 0; i < copied; i++) {
19473 switch (opcode[i]) {
19474 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19475 new file mode 100644
19476 index 0000000..db6b9ed
19477 --- /dev/null
19478 +++ b/arch/x86/kernel/sys_i386_32.c
19479 @@ -0,0 +1,247 @@
19480 +/*
19481 + * This file contains various random system calls that
19482 + * have a non-standard calling sequence on the Linux/i386
19483 + * platform.
19484 + */
19485 +
19486 +#include <linux/errno.h>
19487 +#include <linux/sched.h>
19488 +#include <linux/mm.h>
19489 +#include <linux/fs.h>
19490 +#include <linux/smp.h>
19491 +#include <linux/sem.h>
19492 +#include <linux/msg.h>
19493 +#include <linux/shm.h>
19494 +#include <linux/stat.h>
19495 +#include <linux/syscalls.h>
19496 +#include <linux/mman.h>
19497 +#include <linux/file.h>
19498 +#include <linux/utsname.h>
19499 +#include <linux/ipc.h>
19500 +
19501 +#include <linux/uaccess.h>
19502 +#include <linux/unistd.h>
19503 +
19504 +#include <asm/syscalls.h>
19505 +
19506 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19507 +{
19508 + unsigned long pax_task_size = TASK_SIZE;
19509 +
19510 +#ifdef CONFIG_PAX_SEGMEXEC
19511 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19512 + pax_task_size = SEGMEXEC_TASK_SIZE;
19513 +#endif
19514 +
19515 + if (len > pax_task_size || addr > pax_task_size - len)
19516 + return -EINVAL;
19517 +
19518 + return 0;
19519 +}
19520 +
19521 +unsigned long
19522 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19523 + unsigned long len, unsigned long pgoff, unsigned long flags)
19524 +{
19525 + struct mm_struct *mm = current->mm;
19526 + struct vm_area_struct *vma;
19527 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19528 +
19529 +#ifdef CONFIG_PAX_SEGMEXEC
19530 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19531 + pax_task_size = SEGMEXEC_TASK_SIZE;
19532 +#endif
19533 +
19534 + pax_task_size -= PAGE_SIZE;
19535 +
19536 + if (len > pax_task_size)
19537 + return -ENOMEM;
19538 +
19539 + if (flags & MAP_FIXED)
19540 + return addr;
19541 +
19542 +#ifdef CONFIG_PAX_RANDMMAP
19543 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19544 +#endif
19545 +
19546 + if (addr) {
19547 + addr = PAGE_ALIGN(addr);
19548 + if (pax_task_size - len >= addr) {
19549 + vma = find_vma(mm, addr);
19550 + if (check_heap_stack_gap(vma, addr, len))
19551 + return addr;
19552 + }
19553 + }
19554 + if (len > mm->cached_hole_size) {
19555 + start_addr = addr = mm->free_area_cache;
19556 + } else {
19557 + start_addr = addr = mm->mmap_base;
19558 + mm->cached_hole_size = 0;
19559 + }
19560 +
19561 +#ifdef CONFIG_PAX_PAGEEXEC
19562 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19563 + start_addr = 0x00110000UL;
19564 +
19565 +#ifdef CONFIG_PAX_RANDMMAP
19566 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19567 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19568 +#endif
19569 +
19570 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19571 + start_addr = addr = mm->mmap_base;
19572 + else
19573 + addr = start_addr;
19574 + }
19575 +#endif
19576 +
19577 +full_search:
19578 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19579 + /* At this point: (!vma || addr < vma->vm_end). */
19580 + if (pax_task_size - len < addr) {
19581 + /*
19582 + * Start a new search - just in case we missed
19583 + * some holes.
19584 + */
19585 + if (start_addr != mm->mmap_base) {
19586 + start_addr = addr = mm->mmap_base;
19587 + mm->cached_hole_size = 0;
19588 + goto full_search;
19589 + }
19590 + return -ENOMEM;
19591 + }
19592 + if (check_heap_stack_gap(vma, addr, len))
19593 + break;
19594 + if (addr + mm->cached_hole_size < vma->vm_start)
19595 + mm->cached_hole_size = vma->vm_start - addr;
19596 + addr = vma->vm_end;
19597 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19598 + start_addr = addr = mm->mmap_base;
19599 + mm->cached_hole_size = 0;
19600 + goto full_search;
19601 + }
19602 + }
19603 +
19604 + /*
19605 + * Remember the place where we stopped the search:
19606 + */
19607 + mm->free_area_cache = addr + len;
19608 + return addr;
19609 +}
19610 +
19611 +unsigned long
19612 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19613 + const unsigned long len, const unsigned long pgoff,
19614 + const unsigned long flags)
19615 +{
19616 + struct vm_area_struct *vma;
19617 + struct mm_struct *mm = current->mm;
19618 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19619 +
19620 +#ifdef CONFIG_PAX_SEGMEXEC
19621 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19622 + pax_task_size = SEGMEXEC_TASK_SIZE;
19623 +#endif
19624 +
19625 + pax_task_size -= PAGE_SIZE;
19626 +
19627 + /* requested length too big for entire address space */
19628 + if (len > pax_task_size)
19629 + return -ENOMEM;
19630 +
19631 + if (flags & MAP_FIXED)
19632 + return addr;
19633 +
19634 +#ifdef CONFIG_PAX_PAGEEXEC
19635 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19636 + goto bottomup;
19637 +#endif
19638 +
19639 +#ifdef CONFIG_PAX_RANDMMAP
19640 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19641 +#endif
19642 +
19643 + /* requesting a specific address */
19644 + if (addr) {
19645 + addr = PAGE_ALIGN(addr);
19646 + if (pax_task_size - len >= addr) {
19647 + vma = find_vma(mm, addr);
19648 + if (check_heap_stack_gap(vma, addr, len))
19649 + return addr;
19650 + }
19651 + }
19652 +
19653 + /* check if free_area_cache is useful for us */
19654 + if (len <= mm->cached_hole_size) {
19655 + mm->cached_hole_size = 0;
19656 + mm->free_area_cache = mm->mmap_base;
19657 + }
19658 +
19659 + /* either no address requested or can't fit in requested address hole */
19660 + addr = mm->free_area_cache;
19661 +
19662 + /* make sure it can fit in the remaining address space */
19663 + if (addr > len) {
19664 + vma = find_vma(mm, addr-len);
19665 + if (check_heap_stack_gap(vma, addr - len, len))
19666 + /* remember the address as a hint for next time */
19667 + return (mm->free_area_cache = addr-len);
19668 + }
19669 +
19670 + if (mm->mmap_base < len)
19671 + goto bottomup;
19672 +
19673 + addr = mm->mmap_base-len;
19674 +
19675 + do {
19676 + /*
19677 + * Lookup failure means no vma is above this address,
19678 + * else if new region fits below vma->vm_start,
19679 + * return with success:
19680 + */
19681 + vma = find_vma(mm, addr);
19682 + if (check_heap_stack_gap(vma, addr, len))
19683 + /* remember the address as a hint for next time */
19684 + return (mm->free_area_cache = addr);
19685 +
19686 + /* remember the largest hole we saw so far */
19687 + if (addr + mm->cached_hole_size < vma->vm_start)
19688 + mm->cached_hole_size = vma->vm_start - addr;
19689 +
19690 + /* try just below the current vma->vm_start */
19691 + addr = skip_heap_stack_gap(vma, len);
19692 + } while (!IS_ERR_VALUE(addr));
19693 +
19694 +bottomup:
19695 + /*
19696 + * A failed mmap() very likely causes application failure,
19697 + * so fall back to the bottom-up function here. This scenario
19698 + * can happen with large stack limits and large mmap()
19699 + * allocations.
19700 + */
19701 +
19702 +#ifdef CONFIG_PAX_SEGMEXEC
19703 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19704 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19705 + else
19706 +#endif
19707 +
19708 + mm->mmap_base = TASK_UNMAPPED_BASE;
19709 +
19710 +#ifdef CONFIG_PAX_RANDMMAP
19711 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19712 + mm->mmap_base += mm->delta_mmap;
19713 +#endif
19714 +
19715 + mm->free_area_cache = mm->mmap_base;
19716 + mm->cached_hole_size = ~0UL;
19717 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19718 + /*
19719 + * Restore the topdown base:
19720 + */
19721 + mm->mmap_base = base;
19722 + mm->free_area_cache = base;
19723 + mm->cached_hole_size = ~0UL;
19724 +
19725 + return addr;
19726 +}
19727 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19728 index b4d3c39..82bb73b 100644
19729 --- a/arch/x86/kernel/sys_x86_64.c
19730 +++ b/arch/x86/kernel/sys_x86_64.c
19731 @@ -95,8 +95,8 @@ out:
19732 return error;
19733 }
19734
19735 -static void find_start_end(unsigned long flags, unsigned long *begin,
19736 - unsigned long *end)
19737 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19738 + unsigned long *begin, unsigned long *end)
19739 {
19740 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19741 unsigned long new_begin;
19742 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19743 *begin = new_begin;
19744 }
19745 } else {
19746 - *begin = TASK_UNMAPPED_BASE;
19747 + *begin = mm->mmap_base;
19748 *end = TASK_SIZE;
19749 }
19750 }
19751 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19752 if (flags & MAP_FIXED)
19753 return addr;
19754
19755 - find_start_end(flags, &begin, &end);
19756 + find_start_end(mm, flags, &begin, &end);
19757
19758 if (len > end)
19759 return -ENOMEM;
19760
19761 +#ifdef CONFIG_PAX_RANDMMAP
19762 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19763 +#endif
19764 +
19765 if (addr) {
19766 addr = PAGE_ALIGN(addr);
19767 vma = find_vma(mm, addr);
19768 - if (end - len >= addr &&
19769 - (!vma || addr + len <= vma->vm_start))
19770 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19771 return addr;
19772 }
19773 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19774 @@ -172,7 +175,7 @@ full_search:
19775 }
19776 return -ENOMEM;
19777 }
19778 - if (!vma || addr + len <= vma->vm_start) {
19779 + if (check_heap_stack_gap(vma, addr, len)) {
19780 /*
19781 * Remember the place where we stopped the search:
19782 */
19783 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19784 {
19785 struct vm_area_struct *vma;
19786 struct mm_struct *mm = current->mm;
19787 - unsigned long addr = addr0, start_addr;
19788 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19789
19790 /* requested length too big for entire address space */
19791 if (len > TASK_SIZE)
19792 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19793 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19794 goto bottomup;
19795
19796 +#ifdef CONFIG_PAX_RANDMMAP
19797 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19798 +#endif
19799 +
19800 /* requesting a specific address */
19801 if (addr) {
19802 addr = PAGE_ALIGN(addr);
19803 - vma = find_vma(mm, addr);
19804 - if (TASK_SIZE - len >= addr &&
19805 - (!vma || addr + len <= vma->vm_start))
19806 - return addr;
19807 + if (TASK_SIZE - len >= addr) {
19808 + vma = find_vma(mm, addr);
19809 + if (check_heap_stack_gap(vma, addr, len))
19810 + return addr;
19811 + }
19812 }
19813
19814 /* check if free_area_cache is useful for us */
19815 @@ -240,7 +248,7 @@ try_again:
19816 * return with success:
19817 */
19818 vma = find_vma(mm, addr);
19819 - if (!vma || addr+len <= vma->vm_start)
19820 + if (check_heap_stack_gap(vma, addr, len))
19821 /* remember the address as a hint for next time */
19822 return mm->free_area_cache = addr;
19823
19824 @@ -249,8 +257,8 @@ try_again:
19825 mm->cached_hole_size = vma->vm_start - addr;
19826
19827 /* try just below the current vma->vm_start */
19828 - addr = vma->vm_start-len;
19829 - } while (len < vma->vm_start);
19830 + addr = skip_heap_stack_gap(vma, len);
19831 + } while (!IS_ERR_VALUE(addr));
19832
19833 fail:
19834 /*
19835 @@ -270,13 +278,21 @@ bottomup:
19836 * can happen with large stack limits and large mmap()
19837 * allocations.
19838 */
19839 + mm->mmap_base = TASK_UNMAPPED_BASE;
19840 +
19841 +#ifdef CONFIG_PAX_RANDMMAP
19842 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19843 + mm->mmap_base += mm->delta_mmap;
19844 +#endif
19845 +
19846 + mm->free_area_cache = mm->mmap_base;
19847 mm->cached_hole_size = ~0UL;
19848 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19849 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19850 /*
19851 * Restore the topdown base:
19852 */
19853 - mm->free_area_cache = mm->mmap_base;
19854 + mm->mmap_base = base;
19855 + mm->free_area_cache = base;
19856 mm->cached_hole_size = ~0UL;
19857
19858 return addr;
19859 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19860 index f84fe00..93fe08f 100644
19861 --- a/arch/x86/kernel/tboot.c
19862 +++ b/arch/x86/kernel/tboot.c
19863 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19864
19865 void tboot_shutdown(u32 shutdown_type)
19866 {
19867 - void (*shutdown)(void);
19868 + void (* __noreturn shutdown)(void);
19869
19870 if (!tboot_enabled())
19871 return;
19872 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19873
19874 switch_to_tboot_pt();
19875
19876 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19877 + shutdown = (void *)tboot->shutdown_entry;
19878 shutdown();
19879
19880 /* should not reach here */
19881 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19882 return 0;
19883 }
19884
19885 -static atomic_t ap_wfs_count;
19886 +static atomic_unchecked_t ap_wfs_count;
19887
19888 static int tboot_wait_for_aps(int num_aps)
19889 {
19890 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19891 {
19892 switch (action) {
19893 case CPU_DYING:
19894 - atomic_inc(&ap_wfs_count);
19895 + atomic_inc_unchecked(&ap_wfs_count);
19896 if (num_online_cpus() == 1)
19897 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19898 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19899 return NOTIFY_BAD;
19900 break;
19901 }
19902 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19903
19904 tboot_create_trampoline();
19905
19906 - atomic_set(&ap_wfs_count, 0);
19907 + atomic_set_unchecked(&ap_wfs_count, 0);
19908 register_hotcpu_notifier(&tboot_cpu_notifier);
19909
19910 acpi_os_set_prepare_sleep(&tboot_sleep);
19911 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19912 index 24d3c91..d06b473 100644
19913 --- a/arch/x86/kernel/time.c
19914 +++ b/arch/x86/kernel/time.c
19915 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19916 {
19917 unsigned long pc = instruction_pointer(regs);
19918
19919 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19920 + if (!user_mode(regs) && in_lock_functions(pc)) {
19921 #ifdef CONFIG_FRAME_POINTER
19922 - return *(unsigned long *)(regs->bp + sizeof(long));
19923 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19924 #else
19925 unsigned long *sp =
19926 (unsigned long *)kernel_stack_pointer(regs);
19927 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19928 * or above a saved flags. Eflags has bits 22-31 zero,
19929 * kernel addresses don't.
19930 */
19931 +
19932 +#ifdef CONFIG_PAX_KERNEXEC
19933 + return ktla_ktva(sp[0]);
19934 +#else
19935 if (sp[0] >> 22)
19936 return sp[0];
19937 if (sp[1] >> 22)
19938 return sp[1];
19939 #endif
19940 +
19941 +#endif
19942 }
19943 return pc;
19944 }
19945 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19946 index 9d9d2f9..cad418a 100644
19947 --- a/arch/x86/kernel/tls.c
19948 +++ b/arch/x86/kernel/tls.c
19949 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19950 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19951 return -EINVAL;
19952
19953 +#ifdef CONFIG_PAX_SEGMEXEC
19954 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19955 + return -EINVAL;
19956 +#endif
19957 +
19958 set_tls_desc(p, idx, &info, 1);
19959
19960 return 0;
19961 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19962
19963 if (kbuf)
19964 info = kbuf;
19965 - else if (__copy_from_user(infobuf, ubuf, count))
19966 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19967 return -EFAULT;
19968 else
19969 info = infobuf;
19970 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19971 index 8276dc6..4ca48a2 100644
19972 --- a/arch/x86/kernel/traps.c
19973 +++ b/arch/x86/kernel/traps.c
19974 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
19975
19976 /* Do we ignore FPU interrupts ? */
19977 char ignore_fpu_irq;
19978 -
19979 -/*
19980 - * The IDT has to be page-aligned to simplify the Pentium
19981 - * F0 0F bug workaround.
19982 - */
19983 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19984 #endif
19985
19986 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19987 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19988 }
19989
19990 static int __kprobes
19991 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
19992 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
19993 struct pt_regs *regs, long error_code)
19994 {
19995 #ifdef CONFIG_X86_32
19996 - if (regs->flags & X86_VM_MASK) {
19997 + if (v8086_mode(regs)) {
19998 /*
19999 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
20000 * On nmi (interrupt 2), do_trap should not be called.
20001 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
20002 return -1;
20003 }
20004 #endif
20005 - if (!user_mode(regs)) {
20006 + if (!user_mode_novm(regs)) {
20007 if (!fixup_exception(regs)) {
20008 tsk->thread.error_code = error_code;
20009 tsk->thread.trap_nr = trapnr;
20010 +
20011 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20012 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
20013 + str = "PAX: suspicious stack segment fault";
20014 +#endif
20015 +
20016 die(str, regs, error_code);
20017 }
20018 +
20019 +#ifdef CONFIG_PAX_REFCOUNT
20020 + if (trapnr == 4)
20021 + pax_report_refcount_overflow(regs);
20022 +#endif
20023 +
20024 return 0;
20025 }
20026
20027 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
20028 }
20029
20030 static void __kprobes
20031 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20032 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
20033 long error_code, siginfo_t *info)
20034 {
20035 struct task_struct *tsk = current;
20036 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20037 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
20038 printk_ratelimit()) {
20039 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
20040 - tsk->comm, tsk->pid, str,
20041 + tsk->comm, task_pid_nr(tsk), str,
20042 regs->ip, regs->sp, error_code);
20043 print_vma_addr(" in ", regs->ip);
20044 pr_cont("\n");
20045 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
20046 conditional_sti(regs);
20047
20048 #ifdef CONFIG_X86_32
20049 - if (regs->flags & X86_VM_MASK) {
20050 + if (v8086_mode(regs)) {
20051 local_irq_enable();
20052 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
20053 goto exit;
20054 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
20055 #endif
20056
20057 tsk = current;
20058 - if (!user_mode(regs)) {
20059 + if (!user_mode_novm(regs)) {
20060 if (fixup_exception(regs))
20061 goto exit;
20062
20063 tsk->thread.error_code = error_code;
20064 tsk->thread.trap_nr = X86_TRAP_GP;
20065 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
20066 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
20067 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
20068 +
20069 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20070 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20071 + die("PAX: suspicious general protection fault", regs, error_code);
20072 + else
20073 +#endif
20074 +
20075 die("general protection fault", regs, error_code);
20076 + }
20077 goto exit;
20078 }
20079
20080 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20081 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20082 + struct mm_struct *mm = tsk->mm;
20083 + unsigned long limit;
20084 +
20085 + down_write(&mm->mmap_sem);
20086 + limit = mm->context.user_cs_limit;
20087 + if (limit < TASK_SIZE) {
20088 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20089 + up_write(&mm->mmap_sem);
20090 + return;
20091 + }
20092 + up_write(&mm->mmap_sem);
20093 + }
20094 +#endif
20095 +
20096 tsk->thread.error_code = error_code;
20097 tsk->thread.trap_nr = X86_TRAP_GP;
20098
20099 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20100 /* It's safe to allow irq's after DR6 has been saved */
20101 preempt_conditional_sti(regs);
20102
20103 - if (regs->flags & X86_VM_MASK) {
20104 + if (v8086_mode(regs)) {
20105 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
20106 X86_TRAP_DB);
20107 preempt_conditional_cli(regs);
20108 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20109 * We already checked v86 mode above, so we can check for kernel mode
20110 * by just checking the CPL of CS.
20111 */
20112 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
20113 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
20114 tsk->thread.debugreg6 &= ~DR_STEP;
20115 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
20116 regs->flags &= ~X86_EFLAGS_TF;
20117 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
20118 return;
20119 conditional_sti(regs);
20120
20121 - if (!user_mode_vm(regs))
20122 + if (!user_mode(regs))
20123 {
20124 if (!fixup_exception(regs)) {
20125 task->thread.error_code = error_code;
20126 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
20127 index aafa555..a04691a 100644
20128 --- a/arch/x86/kernel/uprobes.c
20129 +++ b/arch/x86/kernel/uprobes.c
20130 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
20131 int ret = NOTIFY_DONE;
20132
20133 /* We are only interested in userspace traps */
20134 - if (regs && !user_mode_vm(regs))
20135 + if (regs && !user_mode(regs))
20136 return NOTIFY_DONE;
20137
20138 switch (val) {
20139 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20140 index b9242ba..50c5edd 100644
20141 --- a/arch/x86/kernel/verify_cpu.S
20142 +++ b/arch/x86/kernel/verify_cpu.S
20143 @@ -20,6 +20,7 @@
20144 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20145 * arch/x86/kernel/trampoline_64.S: secondary processor verification
20146 * arch/x86/kernel/head_32.S: processor startup
20147 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20148 *
20149 * verify_cpu, returns the status of longmode and SSE in register %eax.
20150 * 0: Success 1: Failure
20151 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20152 index 5c9687b..5f857d3 100644
20153 --- a/arch/x86/kernel/vm86_32.c
20154 +++ b/arch/x86/kernel/vm86_32.c
20155 @@ -43,6 +43,7 @@
20156 #include <linux/ptrace.h>
20157 #include <linux/audit.h>
20158 #include <linux/stddef.h>
20159 +#include <linux/grsecurity.h>
20160
20161 #include <asm/uaccess.h>
20162 #include <asm/io.h>
20163 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20164 do_exit(SIGSEGV);
20165 }
20166
20167 - tss = &per_cpu(init_tss, get_cpu());
20168 + tss = init_tss + get_cpu();
20169 current->thread.sp0 = current->thread.saved_sp0;
20170 current->thread.sysenter_cs = __KERNEL_CS;
20171 load_sp0(tss, &current->thread);
20172 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20173 struct task_struct *tsk;
20174 int tmp, ret = -EPERM;
20175
20176 +#ifdef CONFIG_GRKERNSEC_VM86
20177 + if (!capable(CAP_SYS_RAWIO)) {
20178 + gr_handle_vm86();
20179 + goto out;
20180 + }
20181 +#endif
20182 +
20183 tsk = current;
20184 if (tsk->thread.saved_sp0)
20185 goto out;
20186 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20187 int tmp, ret;
20188 struct vm86plus_struct __user *v86;
20189
20190 +#ifdef CONFIG_GRKERNSEC_VM86
20191 + if (!capable(CAP_SYS_RAWIO)) {
20192 + gr_handle_vm86();
20193 + ret = -EPERM;
20194 + goto out;
20195 + }
20196 +#endif
20197 +
20198 tsk = current;
20199 switch (cmd) {
20200 case VM86_REQUEST_IRQ:
20201 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20202 tsk->thread.saved_fs = info->regs32->fs;
20203 tsk->thread.saved_gs = get_user_gs(info->regs32);
20204
20205 - tss = &per_cpu(init_tss, get_cpu());
20206 + tss = init_tss + get_cpu();
20207 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20208 if (cpu_has_sep)
20209 tsk->thread.sysenter_cs = 0;
20210 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20211 goto cannot_handle;
20212 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20213 goto cannot_handle;
20214 - intr_ptr = (unsigned long __user *) (i << 2);
20215 + intr_ptr = (__force unsigned long __user *) (i << 2);
20216 if (get_user(segoffs, intr_ptr))
20217 goto cannot_handle;
20218 if ((segoffs >> 16) == BIOSSEG)
20219 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20220 index 22a1530..8fbaaad 100644
20221 --- a/arch/x86/kernel/vmlinux.lds.S
20222 +++ b/arch/x86/kernel/vmlinux.lds.S
20223 @@ -26,6 +26,13 @@
20224 #include <asm/page_types.h>
20225 #include <asm/cache.h>
20226 #include <asm/boot.h>
20227 +#include <asm/segment.h>
20228 +
20229 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20230 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20231 +#else
20232 +#define __KERNEL_TEXT_OFFSET 0
20233 +#endif
20234
20235 #undef i386 /* in case the preprocessor is a 32bit one */
20236
20237 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20238
20239 PHDRS {
20240 text PT_LOAD FLAGS(5); /* R_E */
20241 +#ifdef CONFIG_X86_32
20242 + module PT_LOAD FLAGS(5); /* R_E */
20243 +#endif
20244 +#ifdef CONFIG_XEN
20245 + rodata PT_LOAD FLAGS(5); /* R_E */
20246 +#else
20247 + rodata PT_LOAD FLAGS(4); /* R__ */
20248 +#endif
20249 data PT_LOAD FLAGS(6); /* RW_ */
20250 -#ifdef CONFIG_X86_64
20251 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20252 #ifdef CONFIG_SMP
20253 percpu PT_LOAD FLAGS(6); /* RW_ */
20254 #endif
20255 + text.init PT_LOAD FLAGS(5); /* R_E */
20256 + text.exit PT_LOAD FLAGS(5); /* R_E */
20257 init PT_LOAD FLAGS(7); /* RWE */
20258 -#endif
20259 note PT_NOTE FLAGS(0); /* ___ */
20260 }
20261
20262 SECTIONS
20263 {
20264 #ifdef CONFIG_X86_32
20265 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20266 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20267 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20268 #else
20269 - . = __START_KERNEL;
20270 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20271 + . = __START_KERNEL;
20272 #endif
20273
20274 /* Text and read-only data */
20275 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20276 - _text = .;
20277 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20278 /* bootstrapping code */
20279 +#ifdef CONFIG_X86_32
20280 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20281 +#else
20282 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20283 +#endif
20284 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20285 + _text = .;
20286 HEAD_TEXT
20287 #ifdef CONFIG_X86_32
20288 . = ALIGN(PAGE_SIZE);
20289 @@ -108,13 +128,48 @@ SECTIONS
20290 IRQENTRY_TEXT
20291 *(.fixup)
20292 *(.gnu.warning)
20293 - /* End of text section */
20294 - _etext = .;
20295 } :text = 0x9090
20296
20297 - NOTES :text :note
20298 + . += __KERNEL_TEXT_OFFSET;
20299
20300 - EXCEPTION_TABLE(16) :text = 0x9090
20301 +#ifdef CONFIG_X86_32
20302 + . = ALIGN(PAGE_SIZE);
20303 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20304 +
20305 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20306 + MODULES_EXEC_VADDR = .;
20307 + BYTE(0)
20308 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20309 + . = ALIGN(HPAGE_SIZE) - 1;
20310 + MODULES_EXEC_END = .;
20311 +#endif
20312 +
20313 + } :module
20314 +#endif
20315 +
20316 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20317 + /* End of text section */
20318 + BYTE(0)
20319 + _etext = . - __KERNEL_TEXT_OFFSET;
20320 + }
20321 +
20322 +#ifdef CONFIG_X86_32
20323 + . = ALIGN(PAGE_SIZE);
20324 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20325 + *(.idt)
20326 + . = ALIGN(PAGE_SIZE);
20327 + *(.empty_zero_page)
20328 + *(.initial_pg_fixmap)
20329 + *(.initial_pg_pmd)
20330 + *(.initial_page_table)
20331 + *(.swapper_pg_dir)
20332 + } :rodata
20333 +#endif
20334 +
20335 + . = ALIGN(PAGE_SIZE);
20336 + NOTES :rodata :note
20337 +
20338 + EXCEPTION_TABLE(16) :rodata
20339
20340 #if defined(CONFIG_DEBUG_RODATA)
20341 /* .text should occupy whole number of pages */
20342 @@ -126,16 +181,20 @@ SECTIONS
20343
20344 /* Data */
20345 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20346 +
20347 +#ifdef CONFIG_PAX_KERNEXEC
20348 + . = ALIGN(HPAGE_SIZE);
20349 +#else
20350 + . = ALIGN(PAGE_SIZE);
20351 +#endif
20352 +
20353 /* Start of data section */
20354 _sdata = .;
20355
20356 /* init_task */
20357 INIT_TASK_DATA(THREAD_SIZE)
20358
20359 -#ifdef CONFIG_X86_32
20360 - /* 32 bit has nosave before _edata */
20361 NOSAVE_DATA
20362 -#endif
20363
20364 PAGE_ALIGNED_DATA(PAGE_SIZE)
20365
20366 @@ -176,12 +235,19 @@ SECTIONS
20367 #endif /* CONFIG_X86_64 */
20368
20369 /* Init code and data - will be freed after init */
20370 - . = ALIGN(PAGE_SIZE);
20371 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20372 + BYTE(0)
20373 +
20374 +#ifdef CONFIG_PAX_KERNEXEC
20375 + . = ALIGN(HPAGE_SIZE);
20376 +#else
20377 + . = ALIGN(PAGE_SIZE);
20378 +#endif
20379 +
20380 __init_begin = .; /* paired with __init_end */
20381 - }
20382 + } :init.begin
20383
20384 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20385 +#ifdef CONFIG_SMP
20386 /*
20387 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20388 * output PHDR, so the next output section - .init.text - should
20389 @@ -190,12 +256,27 @@ SECTIONS
20390 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20391 #endif
20392
20393 - INIT_TEXT_SECTION(PAGE_SIZE)
20394 -#ifdef CONFIG_X86_64
20395 - :init
20396 -#endif
20397 + . = ALIGN(PAGE_SIZE);
20398 + init_begin = .;
20399 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20400 + VMLINUX_SYMBOL(_sinittext) = .;
20401 + INIT_TEXT
20402 + VMLINUX_SYMBOL(_einittext) = .;
20403 + . = ALIGN(PAGE_SIZE);
20404 + } :text.init
20405
20406 - INIT_DATA_SECTION(16)
20407 + /*
20408 + * .exit.text is discard at runtime, not link time, to deal with
20409 + * references from .altinstructions and .eh_frame
20410 + */
20411 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20412 + EXIT_TEXT
20413 + . = ALIGN(16);
20414 + } :text.exit
20415 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20416 +
20417 + . = ALIGN(PAGE_SIZE);
20418 + INIT_DATA_SECTION(16) :init
20419
20420 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20421 __x86_cpu_dev_start = .;
20422 @@ -257,19 +338,12 @@ SECTIONS
20423 }
20424
20425 . = ALIGN(8);
20426 - /*
20427 - * .exit.text is discard at runtime, not link time, to deal with
20428 - * references from .altinstructions and .eh_frame
20429 - */
20430 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20431 - EXIT_TEXT
20432 - }
20433
20434 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20435 EXIT_DATA
20436 }
20437
20438 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20439 +#ifndef CONFIG_SMP
20440 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20441 #endif
20442
20443 @@ -288,16 +362,10 @@ SECTIONS
20444 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20445 __smp_locks = .;
20446 *(.smp_locks)
20447 - . = ALIGN(PAGE_SIZE);
20448 __smp_locks_end = .;
20449 + . = ALIGN(PAGE_SIZE);
20450 }
20451
20452 -#ifdef CONFIG_X86_64
20453 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20454 - NOSAVE_DATA
20455 - }
20456 -#endif
20457 -
20458 /* BSS */
20459 . = ALIGN(PAGE_SIZE);
20460 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20461 @@ -313,6 +381,7 @@ SECTIONS
20462 __brk_base = .;
20463 . += 64 * 1024; /* 64k alignment slop space */
20464 *(.brk_reservation) /* areas brk users have reserved */
20465 + . = ALIGN(HPAGE_SIZE);
20466 __brk_limit = .;
20467 }
20468
20469 @@ -339,13 +408,12 @@ SECTIONS
20470 * for the boot processor.
20471 */
20472 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20473 -INIT_PER_CPU(gdt_page);
20474 INIT_PER_CPU(irq_stack_union);
20475
20476 /*
20477 * Build-time check on the image size:
20478 */
20479 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20480 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20481 "kernel image bigger than KERNEL_IMAGE_SIZE");
20482
20483 #ifdef CONFIG_SMP
20484 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20485 index 992f890..fc38904 100644
20486 --- a/arch/x86/kernel/vsmp_64.c
20487 +++ b/arch/x86/kernel/vsmp_64.c
20488 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20489 static void vsmp_apic_post_init(void)
20490 {
20491 /* need to update phys_pkg_id */
20492 - apic->phys_pkg_id = apicid_phys_pkg_id;
20493 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20494 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20495 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20496 }
20497
20498 void __init vsmp_init(void)
20499 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20500 index 3a3e8c9..1af9465 100644
20501 --- a/arch/x86/kernel/vsyscall_64.c
20502 +++ b/arch/x86/kernel/vsyscall_64.c
20503 @@ -56,15 +56,13 @@
20504 DEFINE_VVAR(int, vgetcpu_mode);
20505 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20506
20507 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20508 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20509
20510 static int __init vsyscall_setup(char *str)
20511 {
20512 if (str) {
20513 if (!strcmp("emulate", str))
20514 vsyscall_mode = EMULATE;
20515 - else if (!strcmp("native", str))
20516 - vsyscall_mode = NATIVE;
20517 else if (!strcmp("none", str))
20518 vsyscall_mode = NONE;
20519 else
20520 @@ -315,8 +313,7 @@ done:
20521 return true;
20522
20523 sigsegv:
20524 - force_sig(SIGSEGV, current);
20525 - return true;
20526 + do_group_exit(SIGKILL);
20527 }
20528
20529 /*
20530 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
20531 extern char __vvar_page;
20532 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20533
20534 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20535 - vsyscall_mode == NATIVE
20536 - ? PAGE_KERNEL_VSYSCALL
20537 - : PAGE_KERNEL_VVAR);
20538 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20539 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20540 (unsigned long)VSYSCALL_START);
20541
20542 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20543 index 1330dd1..d220b99 100644
20544 --- a/arch/x86/kernel/x8664_ksyms_64.c
20545 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20546 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20547 EXPORT_SYMBOL(copy_user_generic_unrolled);
20548 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20549 EXPORT_SYMBOL(__copy_user_nocache);
20550 -EXPORT_SYMBOL(_copy_from_user);
20551 -EXPORT_SYMBOL(_copy_to_user);
20552
20553 EXPORT_SYMBOL(copy_page);
20554 EXPORT_SYMBOL(clear_page);
20555 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20556 index ada87a3..afea76d 100644
20557 --- a/arch/x86/kernel/xsave.c
20558 +++ b/arch/x86/kernel/xsave.c
20559 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
20560 {
20561 int err;
20562
20563 + buf = (struct xsave_struct __user *)____m(buf);
20564 if (use_xsave())
20565 err = xsave_user(buf);
20566 else if (use_fxsr())
20567 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
20568 */
20569 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
20570 {
20571 + buf = (void __user *)____m(buf);
20572 if (use_xsave()) {
20573 if ((unsigned long)buf % 64 || fx_only) {
20574 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
20575 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20576 index ec79e77..420f5cc 100644
20577 --- a/arch/x86/kvm/cpuid.c
20578 +++ b/arch/x86/kvm/cpuid.c
20579 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20580 struct kvm_cpuid2 *cpuid,
20581 struct kvm_cpuid_entry2 __user *entries)
20582 {
20583 - int r;
20584 + int r, i;
20585
20586 r = -E2BIG;
20587 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20588 goto out;
20589 r = -EFAULT;
20590 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20591 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20592 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20593 goto out;
20594 + for (i = 0; i < cpuid->nent; ++i) {
20595 + struct kvm_cpuid_entry2 cpuid_entry;
20596 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20597 + goto out;
20598 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20599 + }
20600 vcpu->arch.cpuid_nent = cpuid->nent;
20601 kvm_apic_set_version(vcpu);
20602 kvm_x86_ops->cpuid_update(vcpu);
20603 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20604 struct kvm_cpuid2 *cpuid,
20605 struct kvm_cpuid_entry2 __user *entries)
20606 {
20607 - int r;
20608 + int r, i;
20609
20610 r = -E2BIG;
20611 if (cpuid->nent < vcpu->arch.cpuid_nent)
20612 goto out;
20613 r = -EFAULT;
20614 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20615 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20616 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20617 goto out;
20618 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20619 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20620 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20621 + goto out;
20622 + }
20623 return 0;
20624
20625 out:
20626 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20627 index bba39bf..296540a 100644
20628 --- a/arch/x86/kvm/emulate.c
20629 +++ b/arch/x86/kvm/emulate.c
20630 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
20631
20632 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20633 do { \
20634 + unsigned long _tmp; \
20635 __asm__ __volatile__ ( \
20636 _PRE_EFLAGS("0", "4", "2") \
20637 _op _suffix " %"_x"3,%1; " \
20638 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
20639 /* Raw emulation: instruction has two explicit operands. */
20640 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20641 do { \
20642 - unsigned long _tmp; \
20643 - \
20644 switch ((ctxt)->dst.bytes) { \
20645 case 2: \
20646 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20647 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
20648
20649 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20650 do { \
20651 - unsigned long _tmp; \
20652 switch ((ctxt)->dst.bytes) { \
20653 case 1: \
20654 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20655 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20656 index 43e9fad..3b7c059 100644
20657 --- a/arch/x86/kvm/lapic.c
20658 +++ b/arch/x86/kvm/lapic.c
20659 @@ -55,7 +55,7 @@
20660 #define APIC_BUS_CYCLE_NS 1
20661
20662 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20663 -#define apic_debug(fmt, arg...)
20664 +#define apic_debug(fmt, arg...) do {} while (0)
20665
20666 #define APIC_LVT_NUM 6
20667 /* 14 is the version for Xeon and Pentium 8.4.8*/
20668 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20669 index 714e2c0..3f7a086 100644
20670 --- a/arch/x86/kvm/paging_tmpl.h
20671 +++ b/arch/x86/kvm/paging_tmpl.h
20672 @@ -208,7 +208,7 @@ retry_walk:
20673 if (unlikely(kvm_is_error_hva(host_addr)))
20674 goto error;
20675
20676 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20677 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20678 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20679 goto error;
20680 walker->ptep_user[walker->level - 1] = ptep_user;
20681 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20682 index d017df3..61ae42e 100644
20683 --- a/arch/x86/kvm/svm.c
20684 +++ b/arch/x86/kvm/svm.c
20685 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20686 int cpu = raw_smp_processor_id();
20687
20688 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20689 +
20690 + pax_open_kernel();
20691 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20692 + pax_close_kernel();
20693 +
20694 load_TR_desc();
20695 }
20696
20697 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20698 #endif
20699 #endif
20700
20701 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20702 + __set_fs(current_thread_info()->addr_limit);
20703 +#endif
20704 +
20705 reload_tss(vcpu);
20706
20707 local_irq_disable();
20708 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20709 index f858159..4ab7dba 100644
20710 --- a/arch/x86/kvm/vmx.c
20711 +++ b/arch/x86/kvm/vmx.c
20712 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
20713 struct desc_struct *descs;
20714
20715 descs = (void *)gdt->address;
20716 +
20717 + pax_open_kernel();
20718 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20719 + pax_close_kernel();
20720 +
20721 load_TR_desc();
20722 }
20723
20724 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20725 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20726 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20727
20728 +#ifdef CONFIG_PAX_PER_CPU_PGD
20729 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20730 +#endif
20731 +
20732 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20733 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20734 vmx->loaded_vmcs->cpu = cpu;
20735 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
20736 if (!cpu_has_vmx_flexpriority())
20737 flexpriority_enabled = 0;
20738
20739 - if (!cpu_has_vmx_tpr_shadow())
20740 - kvm_x86_ops->update_cr8_intercept = NULL;
20741 + if (!cpu_has_vmx_tpr_shadow()) {
20742 + pax_open_kernel();
20743 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20744 + pax_close_kernel();
20745 + }
20746
20747 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20748 kvm_disable_largepages();
20749 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
20750
20751 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
20752 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20753 +
20754 +#ifndef CONFIG_PAX_PER_CPU_PGD
20755 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20756 +#endif
20757
20758 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20759 #ifdef CONFIG_X86_64
20760 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
20761 native_store_idt(&dt);
20762 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20763
20764 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
20765 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
20766
20767 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20768 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20769 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20770 "jmp 2f \n\t"
20771 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
20772 "2: "
20773 +
20774 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20775 + "ljmp %[cs],$3f\n\t"
20776 + "3: "
20777 +#endif
20778 +
20779 /* Save guest registers, load host registers, keep flags */
20780 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
20781 "pop %0 \n\t"
20782 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20783 #endif
20784 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20785 [wordsize]"i"(sizeof(ulong))
20786 +
20787 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20788 + ,[cs]"i"(__KERNEL_CS)
20789 +#endif
20790 +
20791 : "cc", "memory"
20792 #ifdef CONFIG_X86_64
20793 , "rax", "rbx", "rdi", "rsi"
20794 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20795 if (debugctlmsr)
20796 update_debugctlmsr(debugctlmsr);
20797
20798 -#ifndef CONFIG_X86_64
20799 +#ifdef CONFIG_X86_32
20800 /*
20801 * The sysexit path does not restore ds/es, so we must set them to
20802 * a reasonable value ourselves.
20803 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20804 * may be executed in interrupt context, which saves and restore segments
20805 * around it, nullifying its effect.
20806 */
20807 - loadsegment(ds, __USER_DS);
20808 - loadsegment(es, __USER_DS);
20809 + loadsegment(ds, __KERNEL_DS);
20810 + loadsegment(es, __KERNEL_DS);
20811 + loadsegment(ss, __KERNEL_DS);
20812 +
20813 +#ifdef CONFIG_PAX_KERNEXEC
20814 + loadsegment(fs, __KERNEL_PERCPU);
20815 +#endif
20816 +
20817 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20818 + __set_fs(current_thread_info()->addr_limit);
20819 +#endif
20820 +
20821 #endif
20822
20823 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20824 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20825 index 4f76417..93429b5 100644
20826 --- a/arch/x86/kvm/x86.c
20827 +++ b/arch/x86/kvm/x86.c
20828 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20829 {
20830 struct kvm *kvm = vcpu->kvm;
20831 int lm = is_long_mode(vcpu);
20832 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20833 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20834 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20835 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20836 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20837 : kvm->arch.xen_hvm_config.blob_size_32;
20838 u32 page_num = data & ~PAGE_MASK;
20839 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20840 if (n < msr_list.nmsrs)
20841 goto out;
20842 r = -EFAULT;
20843 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20844 + goto out;
20845 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20846 num_msrs_to_save * sizeof(u32)))
20847 goto out;
20848 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20849 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20850 struct kvm_interrupt *irq)
20851 {
20852 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
20853 + if (irq->irq >= KVM_NR_INTERRUPTS)
20854 return -EINVAL;
20855 if (irqchip_in_kernel(vcpu->kvm))
20856 return -ENXIO;
20857 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
20858 kvm_mmu_set_mmio_spte_mask(mask);
20859 }
20860
20861 -int kvm_arch_init(void *opaque)
20862 +int kvm_arch_init(const void *opaque)
20863 {
20864 int r;
20865 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20866 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20867 index 642d880..cc9ebac 100644
20868 --- a/arch/x86/lguest/boot.c
20869 +++ b/arch/x86/lguest/boot.c
20870 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20871
20872 static void set_lguest_basic_apic_ops(void)
20873 {
20874 - apic->read = lguest_apic_read;
20875 - apic->write = lguest_apic_write;
20876 - apic->icr_read = lguest_apic_icr_read;
20877 - apic->icr_write = lguest_apic_icr_write;
20878 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20879 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20880 + *(void **)&apic->read = lguest_apic_read;
20881 + *(void **)&apic->write = lguest_apic_write;
20882 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20883 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20884 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20885 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20886 };
20887 #endif
20888
20889 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20890 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20891 * Launcher to reboot us.
20892 */
20893 -static void lguest_restart(char *reason)
20894 +static __noreturn void lguest_restart(char *reason)
20895 {
20896 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20897 + BUG();
20898 }
20899
20900 /*G:050
20901 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20902 index 00933d5..3a64af9 100644
20903 --- a/arch/x86/lib/atomic64_386_32.S
20904 +++ b/arch/x86/lib/atomic64_386_32.S
20905 @@ -48,6 +48,10 @@ BEGIN(read)
20906 movl (v), %eax
20907 movl 4(v), %edx
20908 RET_ENDP
20909 +BEGIN(read_unchecked)
20910 + movl (v), %eax
20911 + movl 4(v), %edx
20912 +RET_ENDP
20913 #undef v
20914
20915 #define v %esi
20916 @@ -55,6 +59,10 @@ BEGIN(set)
20917 movl %ebx, (v)
20918 movl %ecx, 4(v)
20919 RET_ENDP
20920 +BEGIN(set_unchecked)
20921 + movl %ebx, (v)
20922 + movl %ecx, 4(v)
20923 +RET_ENDP
20924 #undef v
20925
20926 #define v %esi
20927 @@ -70,6 +78,20 @@ RET_ENDP
20928 BEGIN(add)
20929 addl %eax, (v)
20930 adcl %edx, 4(v)
20931 +
20932 +#ifdef CONFIG_PAX_REFCOUNT
20933 + jno 0f
20934 + subl %eax, (v)
20935 + sbbl %edx, 4(v)
20936 + int $4
20937 +0:
20938 + _ASM_EXTABLE(0b, 0b)
20939 +#endif
20940 +
20941 +RET_ENDP
20942 +BEGIN(add_unchecked)
20943 + addl %eax, (v)
20944 + adcl %edx, 4(v)
20945 RET_ENDP
20946 #undef v
20947
20948 @@ -77,6 +99,24 @@ RET_ENDP
20949 BEGIN(add_return)
20950 addl (v), %eax
20951 adcl 4(v), %edx
20952 +
20953 +#ifdef CONFIG_PAX_REFCOUNT
20954 + into
20955 +1234:
20956 + _ASM_EXTABLE(1234b, 2f)
20957 +#endif
20958 +
20959 + movl %eax, (v)
20960 + movl %edx, 4(v)
20961 +
20962 +#ifdef CONFIG_PAX_REFCOUNT
20963 +2:
20964 +#endif
20965 +
20966 +RET_ENDP
20967 +BEGIN(add_return_unchecked)
20968 + addl (v), %eax
20969 + adcl 4(v), %edx
20970 movl %eax, (v)
20971 movl %edx, 4(v)
20972 RET_ENDP
20973 @@ -86,6 +126,20 @@ RET_ENDP
20974 BEGIN(sub)
20975 subl %eax, (v)
20976 sbbl %edx, 4(v)
20977 +
20978 +#ifdef CONFIG_PAX_REFCOUNT
20979 + jno 0f
20980 + addl %eax, (v)
20981 + adcl %edx, 4(v)
20982 + int $4
20983 +0:
20984 + _ASM_EXTABLE(0b, 0b)
20985 +#endif
20986 +
20987 +RET_ENDP
20988 +BEGIN(sub_unchecked)
20989 + subl %eax, (v)
20990 + sbbl %edx, 4(v)
20991 RET_ENDP
20992 #undef v
20993
20994 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20995 sbbl $0, %edx
20996 addl (v), %eax
20997 adcl 4(v), %edx
20998 +
20999 +#ifdef CONFIG_PAX_REFCOUNT
21000 + into
21001 +1234:
21002 + _ASM_EXTABLE(1234b, 2f)
21003 +#endif
21004 +
21005 + movl %eax, (v)
21006 + movl %edx, 4(v)
21007 +
21008 +#ifdef CONFIG_PAX_REFCOUNT
21009 +2:
21010 +#endif
21011 +
21012 +RET_ENDP
21013 +BEGIN(sub_return_unchecked)
21014 + negl %edx
21015 + negl %eax
21016 + sbbl $0, %edx
21017 + addl (v), %eax
21018 + adcl 4(v), %edx
21019 movl %eax, (v)
21020 movl %edx, 4(v)
21021 RET_ENDP
21022 @@ -105,6 +180,20 @@ RET_ENDP
21023 BEGIN(inc)
21024 addl $1, (v)
21025 adcl $0, 4(v)
21026 +
21027 +#ifdef CONFIG_PAX_REFCOUNT
21028 + jno 0f
21029 + subl $1, (v)
21030 + sbbl $0, 4(v)
21031 + int $4
21032 +0:
21033 + _ASM_EXTABLE(0b, 0b)
21034 +#endif
21035 +
21036 +RET_ENDP
21037 +BEGIN(inc_unchecked)
21038 + addl $1, (v)
21039 + adcl $0, 4(v)
21040 RET_ENDP
21041 #undef v
21042
21043 @@ -114,6 +203,26 @@ BEGIN(inc_return)
21044 movl 4(v), %edx
21045 addl $1, %eax
21046 adcl $0, %edx
21047 +
21048 +#ifdef CONFIG_PAX_REFCOUNT
21049 + into
21050 +1234:
21051 + _ASM_EXTABLE(1234b, 2f)
21052 +#endif
21053 +
21054 + movl %eax, (v)
21055 + movl %edx, 4(v)
21056 +
21057 +#ifdef CONFIG_PAX_REFCOUNT
21058 +2:
21059 +#endif
21060 +
21061 +RET_ENDP
21062 +BEGIN(inc_return_unchecked)
21063 + movl (v), %eax
21064 + movl 4(v), %edx
21065 + addl $1, %eax
21066 + adcl $0, %edx
21067 movl %eax, (v)
21068 movl %edx, 4(v)
21069 RET_ENDP
21070 @@ -123,6 +232,20 @@ RET_ENDP
21071 BEGIN(dec)
21072 subl $1, (v)
21073 sbbl $0, 4(v)
21074 +
21075 +#ifdef CONFIG_PAX_REFCOUNT
21076 + jno 0f
21077 + addl $1, (v)
21078 + adcl $0, 4(v)
21079 + int $4
21080 +0:
21081 + _ASM_EXTABLE(0b, 0b)
21082 +#endif
21083 +
21084 +RET_ENDP
21085 +BEGIN(dec_unchecked)
21086 + subl $1, (v)
21087 + sbbl $0, 4(v)
21088 RET_ENDP
21089 #undef v
21090
21091 @@ -132,6 +255,26 @@ BEGIN(dec_return)
21092 movl 4(v), %edx
21093 subl $1, %eax
21094 sbbl $0, %edx
21095 +
21096 +#ifdef CONFIG_PAX_REFCOUNT
21097 + into
21098 +1234:
21099 + _ASM_EXTABLE(1234b, 2f)
21100 +#endif
21101 +
21102 + movl %eax, (v)
21103 + movl %edx, 4(v)
21104 +
21105 +#ifdef CONFIG_PAX_REFCOUNT
21106 +2:
21107 +#endif
21108 +
21109 +RET_ENDP
21110 +BEGIN(dec_return_unchecked)
21111 + movl (v), %eax
21112 + movl 4(v), %edx
21113 + subl $1, %eax
21114 + sbbl $0, %edx
21115 movl %eax, (v)
21116 movl %edx, 4(v)
21117 RET_ENDP
21118 @@ -143,6 +286,13 @@ BEGIN(add_unless)
21119 adcl %edx, %edi
21120 addl (v), %eax
21121 adcl 4(v), %edx
21122 +
21123 +#ifdef CONFIG_PAX_REFCOUNT
21124 + into
21125 +1234:
21126 + _ASM_EXTABLE(1234b, 2f)
21127 +#endif
21128 +
21129 cmpl %eax, %ecx
21130 je 3f
21131 1:
21132 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
21133 1:
21134 addl $1, %eax
21135 adcl $0, %edx
21136 +
21137 +#ifdef CONFIG_PAX_REFCOUNT
21138 + into
21139 +1234:
21140 + _ASM_EXTABLE(1234b, 2f)
21141 +#endif
21142 +
21143 movl %eax, (v)
21144 movl %edx, 4(v)
21145 movl $1, %eax
21146 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21147 movl 4(v), %edx
21148 subl $1, %eax
21149 sbbl $0, %edx
21150 +
21151 +#ifdef CONFIG_PAX_REFCOUNT
21152 + into
21153 +1234:
21154 + _ASM_EXTABLE(1234b, 1f)
21155 +#endif
21156 +
21157 js 1f
21158 movl %eax, (v)
21159 movl %edx, 4(v)
21160 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21161 index f5cc9eb..51fa319 100644
21162 --- a/arch/x86/lib/atomic64_cx8_32.S
21163 +++ b/arch/x86/lib/atomic64_cx8_32.S
21164 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21165 CFI_STARTPROC
21166
21167 read64 %ecx
21168 + pax_force_retaddr
21169 ret
21170 CFI_ENDPROC
21171 ENDPROC(atomic64_read_cx8)
21172
21173 +ENTRY(atomic64_read_unchecked_cx8)
21174 + CFI_STARTPROC
21175 +
21176 + read64 %ecx
21177 + pax_force_retaddr
21178 + ret
21179 + CFI_ENDPROC
21180 +ENDPROC(atomic64_read_unchecked_cx8)
21181 +
21182 ENTRY(atomic64_set_cx8)
21183 CFI_STARTPROC
21184
21185 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21186 cmpxchg8b (%esi)
21187 jne 1b
21188
21189 + pax_force_retaddr
21190 ret
21191 CFI_ENDPROC
21192 ENDPROC(atomic64_set_cx8)
21193
21194 +ENTRY(atomic64_set_unchecked_cx8)
21195 + CFI_STARTPROC
21196 +
21197 +1:
21198 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21199 + * are atomic on 586 and newer */
21200 + cmpxchg8b (%esi)
21201 + jne 1b
21202 +
21203 + pax_force_retaddr
21204 + ret
21205 + CFI_ENDPROC
21206 +ENDPROC(atomic64_set_unchecked_cx8)
21207 +
21208 ENTRY(atomic64_xchg_cx8)
21209 CFI_STARTPROC
21210
21211 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21212 cmpxchg8b (%esi)
21213 jne 1b
21214
21215 + pax_force_retaddr
21216 ret
21217 CFI_ENDPROC
21218 ENDPROC(atomic64_xchg_cx8)
21219
21220 -.macro addsub_return func ins insc
21221 -ENTRY(atomic64_\func\()_return_cx8)
21222 +.macro addsub_return func ins insc unchecked=""
21223 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21224 CFI_STARTPROC
21225 SAVE ebp
21226 SAVE ebx
21227 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21228 movl %edx, %ecx
21229 \ins\()l %esi, %ebx
21230 \insc\()l %edi, %ecx
21231 +
21232 +.ifb \unchecked
21233 +#ifdef CONFIG_PAX_REFCOUNT
21234 + into
21235 +2:
21236 + _ASM_EXTABLE(2b, 3f)
21237 +#endif
21238 +.endif
21239 +
21240 LOCK_PREFIX
21241 cmpxchg8b (%ebp)
21242 jne 1b
21243 -
21244 -10:
21245 movl %ebx, %eax
21246 movl %ecx, %edx
21247 +
21248 +.ifb \unchecked
21249 +#ifdef CONFIG_PAX_REFCOUNT
21250 +3:
21251 +#endif
21252 +.endif
21253 +
21254 RESTORE edi
21255 RESTORE esi
21256 RESTORE ebx
21257 RESTORE ebp
21258 + pax_force_retaddr
21259 ret
21260 CFI_ENDPROC
21261 -ENDPROC(atomic64_\func\()_return_cx8)
21262 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21263 .endm
21264
21265 addsub_return add add adc
21266 addsub_return sub sub sbb
21267 +addsub_return add add adc _unchecked
21268 +addsub_return sub sub sbb _unchecked
21269
21270 -.macro incdec_return func ins insc
21271 -ENTRY(atomic64_\func\()_return_cx8)
21272 +.macro incdec_return func ins insc unchecked=""
21273 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21274 CFI_STARTPROC
21275 SAVE ebx
21276
21277 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21278 movl %edx, %ecx
21279 \ins\()l $1, %ebx
21280 \insc\()l $0, %ecx
21281 +
21282 +.ifb \unchecked
21283 +#ifdef CONFIG_PAX_REFCOUNT
21284 + into
21285 +2:
21286 + _ASM_EXTABLE(2b, 3f)
21287 +#endif
21288 +.endif
21289 +
21290 LOCK_PREFIX
21291 cmpxchg8b (%esi)
21292 jne 1b
21293
21294 -10:
21295 movl %ebx, %eax
21296 movl %ecx, %edx
21297 +
21298 +.ifb \unchecked
21299 +#ifdef CONFIG_PAX_REFCOUNT
21300 +3:
21301 +#endif
21302 +.endif
21303 +
21304 RESTORE ebx
21305 + pax_force_retaddr
21306 ret
21307 CFI_ENDPROC
21308 -ENDPROC(atomic64_\func\()_return_cx8)
21309 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21310 .endm
21311
21312 incdec_return inc add adc
21313 incdec_return dec sub sbb
21314 +incdec_return inc add adc _unchecked
21315 +incdec_return dec sub sbb _unchecked
21316
21317 ENTRY(atomic64_dec_if_positive_cx8)
21318 CFI_STARTPROC
21319 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21320 movl %edx, %ecx
21321 subl $1, %ebx
21322 sbb $0, %ecx
21323 +
21324 +#ifdef CONFIG_PAX_REFCOUNT
21325 + into
21326 +1234:
21327 + _ASM_EXTABLE(1234b, 2f)
21328 +#endif
21329 +
21330 js 2f
21331 LOCK_PREFIX
21332 cmpxchg8b (%esi)
21333 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21334 movl %ebx, %eax
21335 movl %ecx, %edx
21336 RESTORE ebx
21337 + pax_force_retaddr
21338 ret
21339 CFI_ENDPROC
21340 ENDPROC(atomic64_dec_if_positive_cx8)
21341 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21342 movl %edx, %ecx
21343 addl %ebp, %ebx
21344 adcl %edi, %ecx
21345 +
21346 +#ifdef CONFIG_PAX_REFCOUNT
21347 + into
21348 +1234:
21349 + _ASM_EXTABLE(1234b, 3f)
21350 +#endif
21351 +
21352 LOCK_PREFIX
21353 cmpxchg8b (%esi)
21354 jne 1b
21355 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21356 CFI_ADJUST_CFA_OFFSET -8
21357 RESTORE ebx
21358 RESTORE ebp
21359 + pax_force_retaddr
21360 ret
21361 4:
21362 cmpl %edx, 4(%esp)
21363 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21364 xorl %ecx, %ecx
21365 addl $1, %ebx
21366 adcl %edx, %ecx
21367 +
21368 +#ifdef CONFIG_PAX_REFCOUNT
21369 + into
21370 +1234:
21371 + _ASM_EXTABLE(1234b, 3f)
21372 +#endif
21373 +
21374 LOCK_PREFIX
21375 cmpxchg8b (%esi)
21376 jne 1b
21377 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21378 movl $1, %eax
21379 3:
21380 RESTORE ebx
21381 + pax_force_retaddr
21382 ret
21383 CFI_ENDPROC
21384 ENDPROC(atomic64_inc_not_zero_cx8)
21385 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21386 index 2af5df3..62b1a5a 100644
21387 --- a/arch/x86/lib/checksum_32.S
21388 +++ b/arch/x86/lib/checksum_32.S
21389 @@ -29,7 +29,8 @@
21390 #include <asm/dwarf2.h>
21391 #include <asm/errno.h>
21392 #include <asm/asm.h>
21393 -
21394 +#include <asm/segment.h>
21395 +
21396 /*
21397 * computes a partial checksum, e.g. for TCP/UDP fragments
21398 */
21399 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21400
21401 #define ARGBASE 16
21402 #define FP 12
21403 -
21404 -ENTRY(csum_partial_copy_generic)
21405 +
21406 +ENTRY(csum_partial_copy_generic_to_user)
21407 CFI_STARTPROC
21408 +
21409 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21410 + pushl_cfi %gs
21411 + popl_cfi %es
21412 + jmp csum_partial_copy_generic
21413 +#endif
21414 +
21415 +ENTRY(csum_partial_copy_generic_from_user)
21416 +
21417 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21418 + pushl_cfi %gs
21419 + popl_cfi %ds
21420 +#endif
21421 +
21422 +ENTRY(csum_partial_copy_generic)
21423 subl $4,%esp
21424 CFI_ADJUST_CFA_OFFSET 4
21425 pushl_cfi %edi
21426 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21427 jmp 4f
21428 SRC(1: movw (%esi), %bx )
21429 addl $2, %esi
21430 -DST( movw %bx, (%edi) )
21431 +DST( movw %bx, %es:(%edi) )
21432 addl $2, %edi
21433 addw %bx, %ax
21434 adcl $0, %eax
21435 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21436 SRC(1: movl (%esi), %ebx )
21437 SRC( movl 4(%esi), %edx )
21438 adcl %ebx, %eax
21439 -DST( movl %ebx, (%edi) )
21440 +DST( movl %ebx, %es:(%edi) )
21441 adcl %edx, %eax
21442 -DST( movl %edx, 4(%edi) )
21443 +DST( movl %edx, %es:4(%edi) )
21444
21445 SRC( movl 8(%esi), %ebx )
21446 SRC( movl 12(%esi), %edx )
21447 adcl %ebx, %eax
21448 -DST( movl %ebx, 8(%edi) )
21449 +DST( movl %ebx, %es:8(%edi) )
21450 adcl %edx, %eax
21451 -DST( movl %edx, 12(%edi) )
21452 +DST( movl %edx, %es:12(%edi) )
21453
21454 SRC( movl 16(%esi), %ebx )
21455 SRC( movl 20(%esi), %edx )
21456 adcl %ebx, %eax
21457 -DST( movl %ebx, 16(%edi) )
21458 +DST( movl %ebx, %es:16(%edi) )
21459 adcl %edx, %eax
21460 -DST( movl %edx, 20(%edi) )
21461 +DST( movl %edx, %es:20(%edi) )
21462
21463 SRC( movl 24(%esi), %ebx )
21464 SRC( movl 28(%esi), %edx )
21465 adcl %ebx, %eax
21466 -DST( movl %ebx, 24(%edi) )
21467 +DST( movl %ebx, %es:24(%edi) )
21468 adcl %edx, %eax
21469 -DST( movl %edx, 28(%edi) )
21470 +DST( movl %edx, %es:28(%edi) )
21471
21472 lea 32(%esi), %esi
21473 lea 32(%edi), %edi
21474 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21475 shrl $2, %edx # This clears CF
21476 SRC(3: movl (%esi), %ebx )
21477 adcl %ebx, %eax
21478 -DST( movl %ebx, (%edi) )
21479 +DST( movl %ebx, %es:(%edi) )
21480 lea 4(%esi), %esi
21481 lea 4(%edi), %edi
21482 dec %edx
21483 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21484 jb 5f
21485 SRC( movw (%esi), %cx )
21486 leal 2(%esi), %esi
21487 -DST( movw %cx, (%edi) )
21488 +DST( movw %cx, %es:(%edi) )
21489 leal 2(%edi), %edi
21490 je 6f
21491 shll $16,%ecx
21492 SRC(5: movb (%esi), %cl )
21493 -DST( movb %cl, (%edi) )
21494 +DST( movb %cl, %es:(%edi) )
21495 6: addl %ecx, %eax
21496 adcl $0, %eax
21497 7:
21498 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21499
21500 6001:
21501 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21502 - movl $-EFAULT, (%ebx)
21503 + movl $-EFAULT, %ss:(%ebx)
21504
21505 # zero the complete destination - computing the rest
21506 # is too much work
21507 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21508
21509 6002:
21510 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21511 - movl $-EFAULT,(%ebx)
21512 + movl $-EFAULT,%ss:(%ebx)
21513 jmp 5000b
21514
21515 .previous
21516
21517 + pushl_cfi %ss
21518 + popl_cfi %ds
21519 + pushl_cfi %ss
21520 + popl_cfi %es
21521 popl_cfi %ebx
21522 CFI_RESTORE ebx
21523 popl_cfi %esi
21524 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21525 popl_cfi %ecx # equivalent to addl $4,%esp
21526 ret
21527 CFI_ENDPROC
21528 -ENDPROC(csum_partial_copy_generic)
21529 +ENDPROC(csum_partial_copy_generic_to_user)
21530
21531 #else
21532
21533 /* Version for PentiumII/PPro */
21534
21535 #define ROUND1(x) \
21536 + nop; nop; nop; \
21537 SRC(movl x(%esi), %ebx ) ; \
21538 addl %ebx, %eax ; \
21539 - DST(movl %ebx, x(%edi) ) ;
21540 + DST(movl %ebx, %es:x(%edi)) ;
21541
21542 #define ROUND(x) \
21543 + nop; nop; nop; \
21544 SRC(movl x(%esi), %ebx ) ; \
21545 adcl %ebx, %eax ; \
21546 - DST(movl %ebx, x(%edi) ) ;
21547 + DST(movl %ebx, %es:x(%edi)) ;
21548
21549 #define ARGBASE 12
21550 -
21551 -ENTRY(csum_partial_copy_generic)
21552 +
21553 +ENTRY(csum_partial_copy_generic_to_user)
21554 CFI_STARTPROC
21555 +
21556 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21557 + pushl_cfi %gs
21558 + popl_cfi %es
21559 + jmp csum_partial_copy_generic
21560 +#endif
21561 +
21562 +ENTRY(csum_partial_copy_generic_from_user)
21563 +
21564 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21565 + pushl_cfi %gs
21566 + popl_cfi %ds
21567 +#endif
21568 +
21569 +ENTRY(csum_partial_copy_generic)
21570 pushl_cfi %ebx
21571 CFI_REL_OFFSET ebx, 0
21572 pushl_cfi %edi
21573 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21574 subl %ebx, %edi
21575 lea -1(%esi),%edx
21576 andl $-32,%edx
21577 - lea 3f(%ebx,%ebx), %ebx
21578 + lea 3f(%ebx,%ebx,2), %ebx
21579 testl %esi, %esi
21580 jmp *%ebx
21581 1: addl $64,%esi
21582 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21583 jb 5f
21584 SRC( movw (%esi), %dx )
21585 leal 2(%esi), %esi
21586 -DST( movw %dx, (%edi) )
21587 +DST( movw %dx, %es:(%edi) )
21588 leal 2(%edi), %edi
21589 je 6f
21590 shll $16,%edx
21591 5:
21592 SRC( movb (%esi), %dl )
21593 -DST( movb %dl, (%edi) )
21594 +DST( movb %dl, %es:(%edi) )
21595 6: addl %edx, %eax
21596 adcl $0, %eax
21597 7:
21598 .section .fixup, "ax"
21599 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21600 - movl $-EFAULT, (%ebx)
21601 + movl $-EFAULT, %ss:(%ebx)
21602 # zero the complete destination (computing the rest is too much work)
21603 movl ARGBASE+8(%esp),%edi # dst
21604 movl ARGBASE+12(%esp),%ecx # len
21605 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21606 rep; stosb
21607 jmp 7b
21608 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21609 - movl $-EFAULT, (%ebx)
21610 + movl $-EFAULT, %ss:(%ebx)
21611 jmp 7b
21612 .previous
21613
21614 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21615 + pushl_cfi %ss
21616 + popl_cfi %ds
21617 + pushl_cfi %ss
21618 + popl_cfi %es
21619 +#endif
21620 +
21621 popl_cfi %esi
21622 CFI_RESTORE esi
21623 popl_cfi %edi
21624 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21625 CFI_RESTORE ebx
21626 ret
21627 CFI_ENDPROC
21628 -ENDPROC(csum_partial_copy_generic)
21629 +ENDPROC(csum_partial_copy_generic_to_user)
21630
21631 #undef ROUND
21632 #undef ROUND1
21633 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21634 index f2145cf..cea889d 100644
21635 --- a/arch/x86/lib/clear_page_64.S
21636 +++ b/arch/x86/lib/clear_page_64.S
21637 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21638 movl $4096/8,%ecx
21639 xorl %eax,%eax
21640 rep stosq
21641 + pax_force_retaddr
21642 ret
21643 CFI_ENDPROC
21644 ENDPROC(clear_page_c)
21645 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21646 movl $4096,%ecx
21647 xorl %eax,%eax
21648 rep stosb
21649 + pax_force_retaddr
21650 ret
21651 CFI_ENDPROC
21652 ENDPROC(clear_page_c_e)
21653 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21654 leaq 64(%rdi),%rdi
21655 jnz .Lloop
21656 nop
21657 + pax_force_retaddr
21658 ret
21659 CFI_ENDPROC
21660 .Lclear_page_end:
21661 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21662
21663 #include <asm/cpufeature.h>
21664
21665 - .section .altinstr_replacement,"ax"
21666 + .section .altinstr_replacement,"a"
21667 1: .byte 0xeb /* jmp <disp8> */
21668 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21669 2: .byte 0xeb /* jmp <disp8> */
21670 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21671 index 1e572c5..2a162cd 100644
21672 --- a/arch/x86/lib/cmpxchg16b_emu.S
21673 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21674 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21675
21676 popf
21677 mov $1, %al
21678 + pax_force_retaddr
21679 ret
21680
21681 not_same:
21682 popf
21683 xor %al,%al
21684 + pax_force_retaddr
21685 ret
21686
21687 CFI_ENDPROC
21688 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21689 index 6b34d04..dccb07f 100644
21690 --- a/arch/x86/lib/copy_page_64.S
21691 +++ b/arch/x86/lib/copy_page_64.S
21692 @@ -9,6 +9,7 @@ copy_page_c:
21693 CFI_STARTPROC
21694 movl $4096/8,%ecx
21695 rep movsq
21696 + pax_force_retaddr
21697 ret
21698 CFI_ENDPROC
21699 ENDPROC(copy_page_c)
21700 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21701
21702 ENTRY(copy_page)
21703 CFI_STARTPROC
21704 - subq $2*8,%rsp
21705 - CFI_ADJUST_CFA_OFFSET 2*8
21706 + subq $3*8,%rsp
21707 + CFI_ADJUST_CFA_OFFSET 3*8
21708 movq %rbx,(%rsp)
21709 CFI_REL_OFFSET rbx, 0
21710 movq %r12,1*8(%rsp)
21711 CFI_REL_OFFSET r12, 1*8
21712 + movq %r13,2*8(%rsp)
21713 + CFI_REL_OFFSET r13, 2*8
21714
21715 movl $(4096/64)-5,%ecx
21716 .p2align 4
21717 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21718 movq 16 (%rsi), %rdx
21719 movq 24 (%rsi), %r8
21720 movq 32 (%rsi), %r9
21721 - movq 40 (%rsi), %r10
21722 + movq 40 (%rsi), %r13
21723 movq 48 (%rsi), %r11
21724 movq 56 (%rsi), %r12
21725
21726 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21727 movq %rdx, 16 (%rdi)
21728 movq %r8, 24 (%rdi)
21729 movq %r9, 32 (%rdi)
21730 - movq %r10, 40 (%rdi)
21731 + movq %r13, 40 (%rdi)
21732 movq %r11, 48 (%rdi)
21733 movq %r12, 56 (%rdi)
21734
21735 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21736 movq 16 (%rsi), %rdx
21737 movq 24 (%rsi), %r8
21738 movq 32 (%rsi), %r9
21739 - movq 40 (%rsi), %r10
21740 + movq 40 (%rsi), %r13
21741 movq 48 (%rsi), %r11
21742 movq 56 (%rsi), %r12
21743
21744 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21745 movq %rdx, 16 (%rdi)
21746 movq %r8, 24 (%rdi)
21747 movq %r9, 32 (%rdi)
21748 - movq %r10, 40 (%rdi)
21749 + movq %r13, 40 (%rdi)
21750 movq %r11, 48 (%rdi)
21751 movq %r12, 56 (%rdi)
21752
21753 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21754 CFI_RESTORE rbx
21755 movq 1*8(%rsp),%r12
21756 CFI_RESTORE r12
21757 - addq $2*8,%rsp
21758 - CFI_ADJUST_CFA_OFFSET -2*8
21759 + movq 2*8(%rsp),%r13
21760 + CFI_RESTORE r13
21761 + addq $3*8,%rsp
21762 + CFI_ADJUST_CFA_OFFSET -3*8
21763 + pax_force_retaddr
21764 ret
21765 .Lcopy_page_end:
21766 CFI_ENDPROC
21767 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21768
21769 #include <asm/cpufeature.h>
21770
21771 - .section .altinstr_replacement,"ax"
21772 + .section .altinstr_replacement,"a"
21773 1: .byte 0xeb /* jmp <disp8> */
21774 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21775 2:
21776 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21777 index a30ca15..d25fab6 100644
21778 --- a/arch/x86/lib/copy_user_64.S
21779 +++ b/arch/x86/lib/copy_user_64.S
21780 @@ -18,6 +18,7 @@
21781 #include <asm/alternative-asm.h>
21782 #include <asm/asm.h>
21783 #include <asm/smap.h>
21784 +#include <asm/pgtable.h>
21785
21786 /*
21787 * By placing feature2 after feature1 in altinstructions section, we logically
21788 @@ -31,7 +32,7 @@
21789 .byte 0xe9 /* 32bit jump */
21790 .long \orig-1f /* by default jump to orig */
21791 1:
21792 - .section .altinstr_replacement,"ax"
21793 + .section .altinstr_replacement,"a"
21794 2: .byte 0xe9 /* near jump with 32bit immediate */
21795 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21796 3: .byte 0xe9 /* near jump with 32bit immediate */
21797 @@ -70,47 +71,20 @@
21798 #endif
21799 .endm
21800
21801 -/* Standard copy_to_user with segment limit checking */
21802 -ENTRY(_copy_to_user)
21803 - CFI_STARTPROC
21804 - GET_THREAD_INFO(%rax)
21805 - movq %rdi,%rcx
21806 - addq %rdx,%rcx
21807 - jc bad_to_user
21808 - cmpq TI_addr_limit(%rax),%rcx
21809 - ja bad_to_user
21810 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21811 - copy_user_generic_unrolled,copy_user_generic_string, \
21812 - copy_user_enhanced_fast_string
21813 - CFI_ENDPROC
21814 -ENDPROC(_copy_to_user)
21815 -
21816 -/* Standard copy_from_user with segment limit checking */
21817 -ENTRY(_copy_from_user)
21818 - CFI_STARTPROC
21819 - GET_THREAD_INFO(%rax)
21820 - movq %rsi,%rcx
21821 - addq %rdx,%rcx
21822 - jc bad_from_user
21823 - cmpq TI_addr_limit(%rax),%rcx
21824 - ja bad_from_user
21825 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21826 - copy_user_generic_unrolled,copy_user_generic_string, \
21827 - copy_user_enhanced_fast_string
21828 - CFI_ENDPROC
21829 -ENDPROC(_copy_from_user)
21830 -
21831 .section .fixup,"ax"
21832 /* must zero dest */
21833 ENTRY(bad_from_user)
21834 bad_from_user:
21835 CFI_STARTPROC
21836 + testl %edx,%edx
21837 + js bad_to_user
21838 movl %edx,%ecx
21839 xorl %eax,%eax
21840 rep
21841 stosb
21842 bad_to_user:
21843 movl %edx,%eax
21844 + pax_force_retaddr
21845 ret
21846 CFI_ENDPROC
21847 ENDPROC(bad_from_user)
21848 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21849 jz 17f
21850 1: movq (%rsi),%r8
21851 2: movq 1*8(%rsi),%r9
21852 -3: movq 2*8(%rsi),%r10
21853 +3: movq 2*8(%rsi),%rax
21854 4: movq 3*8(%rsi),%r11
21855 5: movq %r8,(%rdi)
21856 6: movq %r9,1*8(%rdi)
21857 -7: movq %r10,2*8(%rdi)
21858 +7: movq %rax,2*8(%rdi)
21859 8: movq %r11,3*8(%rdi)
21860 9: movq 4*8(%rsi),%r8
21861 10: movq 5*8(%rsi),%r9
21862 -11: movq 6*8(%rsi),%r10
21863 +11: movq 6*8(%rsi),%rax
21864 12: movq 7*8(%rsi),%r11
21865 13: movq %r8,4*8(%rdi)
21866 14: movq %r9,5*8(%rdi)
21867 -15: movq %r10,6*8(%rdi)
21868 +15: movq %rax,6*8(%rdi)
21869 16: movq %r11,7*8(%rdi)
21870 leaq 64(%rsi),%rsi
21871 leaq 64(%rdi),%rdi
21872 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
21873 jnz 21b
21874 23: xor %eax,%eax
21875 ASM_CLAC
21876 + pax_force_retaddr
21877 ret
21878
21879 .section .fixup,"ax"
21880 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21881 movsb
21882 4: xorl %eax,%eax
21883 ASM_CLAC
21884 + pax_force_retaddr
21885 ret
21886
21887 .section .fixup,"ax"
21888 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
21889 movsb
21890 2: xorl %eax,%eax
21891 ASM_CLAC
21892 + pax_force_retaddr
21893 ret
21894
21895 .section .fixup,"ax"
21896 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21897 index 6a4f43c..f5f9e26 100644
21898 --- a/arch/x86/lib/copy_user_nocache_64.S
21899 +++ b/arch/x86/lib/copy_user_nocache_64.S
21900 @@ -8,6 +8,7 @@
21901
21902 #include <linux/linkage.h>
21903 #include <asm/dwarf2.h>
21904 +#include <asm/alternative-asm.h>
21905
21906 #define FIX_ALIGNMENT 1
21907
21908 @@ -16,6 +17,7 @@
21909 #include <asm/thread_info.h>
21910 #include <asm/asm.h>
21911 #include <asm/smap.h>
21912 +#include <asm/pgtable.h>
21913
21914 .macro ALIGN_DESTINATION
21915 #ifdef FIX_ALIGNMENT
21916 @@ -49,6 +51,15 @@
21917 */
21918 ENTRY(__copy_user_nocache)
21919 CFI_STARTPROC
21920 +
21921 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21922 + mov $PAX_USER_SHADOW_BASE,%rcx
21923 + cmp %rcx,%rsi
21924 + jae 1f
21925 + add %rcx,%rsi
21926 +1:
21927 +#endif
21928 +
21929 ASM_STAC
21930 cmpl $8,%edx
21931 jb 20f /* less then 8 bytes, go to byte copy loop */
21932 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21933 jz 17f
21934 1: movq (%rsi),%r8
21935 2: movq 1*8(%rsi),%r9
21936 -3: movq 2*8(%rsi),%r10
21937 +3: movq 2*8(%rsi),%rax
21938 4: movq 3*8(%rsi),%r11
21939 5: movnti %r8,(%rdi)
21940 6: movnti %r9,1*8(%rdi)
21941 -7: movnti %r10,2*8(%rdi)
21942 +7: movnti %rax,2*8(%rdi)
21943 8: movnti %r11,3*8(%rdi)
21944 9: movq 4*8(%rsi),%r8
21945 10: movq 5*8(%rsi),%r9
21946 -11: movq 6*8(%rsi),%r10
21947 +11: movq 6*8(%rsi),%rax
21948 12: movq 7*8(%rsi),%r11
21949 13: movnti %r8,4*8(%rdi)
21950 14: movnti %r9,5*8(%rdi)
21951 -15: movnti %r10,6*8(%rdi)
21952 +15: movnti %rax,6*8(%rdi)
21953 16: movnti %r11,7*8(%rdi)
21954 leaq 64(%rsi),%rsi
21955 leaq 64(%rdi),%rdi
21956 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
21957 23: xorl %eax,%eax
21958 ASM_CLAC
21959 sfence
21960 + pax_force_retaddr
21961 ret
21962
21963 .section .fixup,"ax"
21964 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21965 index 2419d5f..953ee51 100644
21966 --- a/arch/x86/lib/csum-copy_64.S
21967 +++ b/arch/x86/lib/csum-copy_64.S
21968 @@ -9,6 +9,7 @@
21969 #include <asm/dwarf2.h>
21970 #include <asm/errno.h>
21971 #include <asm/asm.h>
21972 +#include <asm/alternative-asm.h>
21973
21974 /*
21975 * Checksum copy with exception handling.
21976 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21977 CFI_RESTORE rbp
21978 addq $7*8, %rsp
21979 CFI_ADJUST_CFA_OFFSET -7*8
21980 + pax_force_retaddr 0, 1
21981 ret
21982 CFI_RESTORE_STATE
21983
21984 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21985 index 25b7ae8..169fafc 100644
21986 --- a/arch/x86/lib/csum-wrappers_64.c
21987 +++ b/arch/x86/lib/csum-wrappers_64.c
21988 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21989 len -= 2;
21990 }
21991 }
21992 - isum = csum_partial_copy_generic((__force const void *)src,
21993 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
21994 dst, len, isum, errp, NULL);
21995 if (unlikely(*errp))
21996 goto out_err;
21997 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21998 }
21999
22000 *errp = 0;
22001 - return csum_partial_copy_generic(src, (void __force *)dst,
22002 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
22003 len, isum, NULL, errp);
22004 }
22005 EXPORT_SYMBOL(csum_partial_copy_to_user);
22006 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
22007 index 156b9c8..b144132 100644
22008 --- a/arch/x86/lib/getuser.S
22009 +++ b/arch/x86/lib/getuser.S
22010 @@ -34,17 +34,40 @@
22011 #include <asm/thread_info.h>
22012 #include <asm/asm.h>
22013 #include <asm/smap.h>
22014 +#include <asm/segment.h>
22015 +#include <asm/pgtable.h>
22016 +#include <asm/alternative-asm.h>
22017 +
22018 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22019 +#define __copyuser_seg gs;
22020 +#else
22021 +#define __copyuser_seg
22022 +#endif
22023
22024 .text
22025 ENTRY(__get_user_1)
22026 CFI_STARTPROC
22027 +
22028 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22029 GET_THREAD_INFO(%_ASM_DX)
22030 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22031 jae bad_get_user
22032 ASM_STAC
22033 -1: movzb (%_ASM_AX),%edx
22034 +
22035 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22036 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22037 + cmp %_ASM_DX,%_ASM_AX
22038 + jae 1234f
22039 + add %_ASM_DX,%_ASM_AX
22040 +1234:
22041 +#endif
22042 +
22043 +#endif
22044 +
22045 +1: __copyuser_seg movzb (%_ASM_AX),%edx
22046 xor %eax,%eax
22047 ASM_CLAC
22048 + pax_force_retaddr
22049 ret
22050 CFI_ENDPROC
22051 ENDPROC(__get_user_1)
22052 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
22053 ENTRY(__get_user_2)
22054 CFI_STARTPROC
22055 add $1,%_ASM_AX
22056 +
22057 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22058 jc bad_get_user
22059 GET_THREAD_INFO(%_ASM_DX)
22060 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22061 jae bad_get_user
22062 ASM_STAC
22063 -2: movzwl -1(%_ASM_AX),%edx
22064 +
22065 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22066 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22067 + cmp %_ASM_DX,%_ASM_AX
22068 + jae 1234f
22069 + add %_ASM_DX,%_ASM_AX
22070 +1234:
22071 +#endif
22072 +
22073 +#endif
22074 +
22075 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22076 xor %eax,%eax
22077 ASM_CLAC
22078 + pax_force_retaddr
22079 ret
22080 CFI_ENDPROC
22081 ENDPROC(__get_user_2)
22082 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
22083 ENTRY(__get_user_4)
22084 CFI_STARTPROC
22085 add $3,%_ASM_AX
22086 +
22087 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22088 jc bad_get_user
22089 GET_THREAD_INFO(%_ASM_DX)
22090 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22091 jae bad_get_user
22092 ASM_STAC
22093 -3: mov -3(%_ASM_AX),%edx
22094 +
22095 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22096 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22097 + cmp %_ASM_DX,%_ASM_AX
22098 + jae 1234f
22099 + add %_ASM_DX,%_ASM_AX
22100 +1234:
22101 +#endif
22102 +
22103 +#endif
22104 +
22105 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
22106 xor %eax,%eax
22107 ASM_CLAC
22108 + pax_force_retaddr
22109 ret
22110 CFI_ENDPROC
22111 ENDPROC(__get_user_4)
22112 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
22113 GET_THREAD_INFO(%_ASM_DX)
22114 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22115 jae bad_get_user
22116 +
22117 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22118 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22119 + cmp %_ASM_DX,%_ASM_AX
22120 + jae 1234f
22121 + add %_ASM_DX,%_ASM_AX
22122 +1234:
22123 +#endif
22124 +
22125 ASM_STAC
22126 4: movq -7(%_ASM_AX),%_ASM_DX
22127 xor %eax,%eax
22128 ASM_CLAC
22129 + pax_force_retaddr
22130 ret
22131 CFI_ENDPROC
22132 ENDPROC(__get_user_8)
22133 @@ -101,6 +162,7 @@ bad_get_user:
22134 xor %edx,%edx
22135 mov $(-EFAULT),%_ASM_AX
22136 ASM_CLAC
22137 + pax_force_retaddr
22138 ret
22139 CFI_ENDPROC
22140 END(bad_get_user)
22141 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
22142 index 54fcffe..7be149e 100644
22143 --- a/arch/x86/lib/insn.c
22144 +++ b/arch/x86/lib/insn.c
22145 @@ -20,8 +20,10 @@
22146
22147 #ifdef __KERNEL__
22148 #include <linux/string.h>
22149 +#include <asm/pgtable_types.h>
22150 #else
22151 #include <string.h>
22152 +#define ktla_ktva(addr) addr
22153 #endif
22154 #include <asm/inat.h>
22155 #include <asm/insn.h>
22156 @@ -53,8 +55,8 @@
22157 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22158 {
22159 memset(insn, 0, sizeof(*insn));
22160 - insn->kaddr = kaddr;
22161 - insn->next_byte = kaddr;
22162 + insn->kaddr = ktla_ktva(kaddr);
22163 + insn->next_byte = ktla_ktva(kaddr);
22164 insn->x86_64 = x86_64 ? 1 : 0;
22165 insn->opnd_bytes = 4;
22166 if (x86_64)
22167 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22168 index 05a95e7..326f2fa 100644
22169 --- a/arch/x86/lib/iomap_copy_64.S
22170 +++ b/arch/x86/lib/iomap_copy_64.S
22171 @@ -17,6 +17,7 @@
22172
22173 #include <linux/linkage.h>
22174 #include <asm/dwarf2.h>
22175 +#include <asm/alternative-asm.h>
22176
22177 /*
22178 * override generic version in lib/iomap_copy.c
22179 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22180 CFI_STARTPROC
22181 movl %edx,%ecx
22182 rep movsd
22183 + pax_force_retaddr
22184 ret
22185 CFI_ENDPROC
22186 ENDPROC(__iowrite32_copy)
22187 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22188 index 1c273be..da9cc0e 100644
22189 --- a/arch/x86/lib/memcpy_64.S
22190 +++ b/arch/x86/lib/memcpy_64.S
22191 @@ -33,6 +33,7 @@
22192 rep movsq
22193 movl %edx, %ecx
22194 rep movsb
22195 + pax_force_retaddr
22196 ret
22197 .Lmemcpy_e:
22198 .previous
22199 @@ -49,6 +50,7 @@
22200 movq %rdi, %rax
22201 movq %rdx, %rcx
22202 rep movsb
22203 + pax_force_retaddr
22204 ret
22205 .Lmemcpy_e_e:
22206 .previous
22207 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22208 */
22209 movq 0*8(%rsi), %r8
22210 movq 1*8(%rsi), %r9
22211 - movq 2*8(%rsi), %r10
22212 + movq 2*8(%rsi), %rcx
22213 movq 3*8(%rsi), %r11
22214 leaq 4*8(%rsi), %rsi
22215
22216 movq %r8, 0*8(%rdi)
22217 movq %r9, 1*8(%rdi)
22218 - movq %r10, 2*8(%rdi)
22219 + movq %rcx, 2*8(%rdi)
22220 movq %r11, 3*8(%rdi)
22221 leaq 4*8(%rdi), %rdi
22222 jae .Lcopy_forward_loop
22223 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22224 subq $0x20, %rdx
22225 movq -1*8(%rsi), %r8
22226 movq -2*8(%rsi), %r9
22227 - movq -3*8(%rsi), %r10
22228 + movq -3*8(%rsi), %rcx
22229 movq -4*8(%rsi), %r11
22230 leaq -4*8(%rsi), %rsi
22231 movq %r8, -1*8(%rdi)
22232 movq %r9, -2*8(%rdi)
22233 - movq %r10, -3*8(%rdi)
22234 + movq %rcx, -3*8(%rdi)
22235 movq %r11, -4*8(%rdi)
22236 leaq -4*8(%rdi), %rdi
22237 jae .Lcopy_backward_loop
22238 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22239 */
22240 movq 0*8(%rsi), %r8
22241 movq 1*8(%rsi), %r9
22242 - movq -2*8(%rsi, %rdx), %r10
22243 + movq -2*8(%rsi, %rdx), %rcx
22244 movq -1*8(%rsi, %rdx), %r11
22245 movq %r8, 0*8(%rdi)
22246 movq %r9, 1*8(%rdi)
22247 - movq %r10, -2*8(%rdi, %rdx)
22248 + movq %rcx, -2*8(%rdi, %rdx)
22249 movq %r11, -1*8(%rdi, %rdx)
22250 + pax_force_retaddr
22251 retq
22252 .p2align 4
22253 .Lless_16bytes:
22254 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22255 movq -1*8(%rsi, %rdx), %r9
22256 movq %r8, 0*8(%rdi)
22257 movq %r9, -1*8(%rdi, %rdx)
22258 + pax_force_retaddr
22259 retq
22260 .p2align 4
22261 .Lless_8bytes:
22262 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22263 movl -4(%rsi, %rdx), %r8d
22264 movl %ecx, (%rdi)
22265 movl %r8d, -4(%rdi, %rdx)
22266 + pax_force_retaddr
22267 retq
22268 .p2align 4
22269 .Lless_3bytes:
22270 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22271 movb %cl, (%rdi)
22272
22273 .Lend:
22274 + pax_force_retaddr
22275 retq
22276 CFI_ENDPROC
22277 ENDPROC(memcpy)
22278 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22279 index ee16461..c39c199 100644
22280 --- a/arch/x86/lib/memmove_64.S
22281 +++ b/arch/x86/lib/memmove_64.S
22282 @@ -61,13 +61,13 @@ ENTRY(memmove)
22283 5:
22284 sub $0x20, %rdx
22285 movq 0*8(%rsi), %r11
22286 - movq 1*8(%rsi), %r10
22287 + movq 1*8(%rsi), %rcx
22288 movq 2*8(%rsi), %r9
22289 movq 3*8(%rsi), %r8
22290 leaq 4*8(%rsi), %rsi
22291
22292 movq %r11, 0*8(%rdi)
22293 - movq %r10, 1*8(%rdi)
22294 + movq %rcx, 1*8(%rdi)
22295 movq %r9, 2*8(%rdi)
22296 movq %r8, 3*8(%rdi)
22297 leaq 4*8(%rdi), %rdi
22298 @@ -81,10 +81,10 @@ ENTRY(memmove)
22299 4:
22300 movq %rdx, %rcx
22301 movq -8(%rsi, %rdx), %r11
22302 - lea -8(%rdi, %rdx), %r10
22303 + lea -8(%rdi, %rdx), %r9
22304 shrq $3, %rcx
22305 rep movsq
22306 - movq %r11, (%r10)
22307 + movq %r11, (%r9)
22308 jmp 13f
22309 .Lmemmove_end_forward:
22310
22311 @@ -95,14 +95,14 @@ ENTRY(memmove)
22312 7:
22313 movq %rdx, %rcx
22314 movq (%rsi), %r11
22315 - movq %rdi, %r10
22316 + movq %rdi, %r9
22317 leaq -8(%rsi, %rdx), %rsi
22318 leaq -8(%rdi, %rdx), %rdi
22319 shrq $3, %rcx
22320 std
22321 rep movsq
22322 cld
22323 - movq %r11, (%r10)
22324 + movq %r11, (%r9)
22325 jmp 13f
22326
22327 /*
22328 @@ -127,13 +127,13 @@ ENTRY(memmove)
22329 8:
22330 subq $0x20, %rdx
22331 movq -1*8(%rsi), %r11
22332 - movq -2*8(%rsi), %r10
22333 + movq -2*8(%rsi), %rcx
22334 movq -3*8(%rsi), %r9
22335 movq -4*8(%rsi), %r8
22336 leaq -4*8(%rsi), %rsi
22337
22338 movq %r11, -1*8(%rdi)
22339 - movq %r10, -2*8(%rdi)
22340 + movq %rcx, -2*8(%rdi)
22341 movq %r9, -3*8(%rdi)
22342 movq %r8, -4*8(%rdi)
22343 leaq -4*8(%rdi), %rdi
22344 @@ -151,11 +151,11 @@ ENTRY(memmove)
22345 * Move data from 16 bytes to 31 bytes.
22346 */
22347 movq 0*8(%rsi), %r11
22348 - movq 1*8(%rsi), %r10
22349 + movq 1*8(%rsi), %rcx
22350 movq -2*8(%rsi, %rdx), %r9
22351 movq -1*8(%rsi, %rdx), %r8
22352 movq %r11, 0*8(%rdi)
22353 - movq %r10, 1*8(%rdi)
22354 + movq %rcx, 1*8(%rdi)
22355 movq %r9, -2*8(%rdi, %rdx)
22356 movq %r8, -1*8(%rdi, %rdx)
22357 jmp 13f
22358 @@ -167,9 +167,9 @@ ENTRY(memmove)
22359 * Move data from 8 bytes to 15 bytes.
22360 */
22361 movq 0*8(%rsi), %r11
22362 - movq -1*8(%rsi, %rdx), %r10
22363 + movq -1*8(%rsi, %rdx), %r9
22364 movq %r11, 0*8(%rdi)
22365 - movq %r10, -1*8(%rdi, %rdx)
22366 + movq %r9, -1*8(%rdi, %rdx)
22367 jmp 13f
22368 10:
22369 cmpq $4, %rdx
22370 @@ -178,9 +178,9 @@ ENTRY(memmove)
22371 * Move data from 4 bytes to 7 bytes.
22372 */
22373 movl (%rsi), %r11d
22374 - movl -4(%rsi, %rdx), %r10d
22375 + movl -4(%rsi, %rdx), %r9d
22376 movl %r11d, (%rdi)
22377 - movl %r10d, -4(%rdi, %rdx)
22378 + movl %r9d, -4(%rdi, %rdx)
22379 jmp 13f
22380 11:
22381 cmp $2, %rdx
22382 @@ -189,9 +189,9 @@ ENTRY(memmove)
22383 * Move data from 2 bytes to 3 bytes.
22384 */
22385 movw (%rsi), %r11w
22386 - movw -2(%rsi, %rdx), %r10w
22387 + movw -2(%rsi, %rdx), %r9w
22388 movw %r11w, (%rdi)
22389 - movw %r10w, -2(%rdi, %rdx)
22390 + movw %r9w, -2(%rdi, %rdx)
22391 jmp 13f
22392 12:
22393 cmp $1, %rdx
22394 @@ -202,6 +202,7 @@ ENTRY(memmove)
22395 movb (%rsi), %r11b
22396 movb %r11b, (%rdi)
22397 13:
22398 + pax_force_retaddr
22399 retq
22400 CFI_ENDPROC
22401
22402 @@ -210,6 +211,7 @@ ENTRY(memmove)
22403 /* Forward moving data. */
22404 movq %rdx, %rcx
22405 rep movsb
22406 + pax_force_retaddr
22407 retq
22408 .Lmemmove_end_forward_efs:
22409 .previous
22410 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22411 index 2dcb380..963660a 100644
22412 --- a/arch/x86/lib/memset_64.S
22413 +++ b/arch/x86/lib/memset_64.S
22414 @@ -30,6 +30,7 @@
22415 movl %edx,%ecx
22416 rep stosb
22417 movq %r9,%rax
22418 + pax_force_retaddr
22419 ret
22420 .Lmemset_e:
22421 .previous
22422 @@ -52,6 +53,7 @@
22423 movq %rdx,%rcx
22424 rep stosb
22425 movq %r9,%rax
22426 + pax_force_retaddr
22427 ret
22428 .Lmemset_e_e:
22429 .previous
22430 @@ -59,7 +61,7 @@
22431 ENTRY(memset)
22432 ENTRY(__memset)
22433 CFI_STARTPROC
22434 - movq %rdi,%r10
22435 + movq %rdi,%r11
22436
22437 /* expand byte value */
22438 movzbl %sil,%ecx
22439 @@ -117,7 +119,8 @@ ENTRY(__memset)
22440 jnz .Lloop_1
22441
22442 .Lende:
22443 - movq %r10,%rax
22444 + movq %r11,%rax
22445 + pax_force_retaddr
22446 ret
22447
22448 CFI_RESTORE_STATE
22449 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22450 index c9f2d9b..e7fd2c0 100644
22451 --- a/arch/x86/lib/mmx_32.c
22452 +++ b/arch/x86/lib/mmx_32.c
22453 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22454 {
22455 void *p;
22456 int i;
22457 + unsigned long cr0;
22458
22459 if (unlikely(in_interrupt()))
22460 return __memcpy(to, from, len);
22461 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22462 kernel_fpu_begin();
22463
22464 __asm__ __volatile__ (
22465 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22466 - " prefetch 64(%0)\n"
22467 - " prefetch 128(%0)\n"
22468 - " prefetch 192(%0)\n"
22469 - " prefetch 256(%0)\n"
22470 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22471 + " prefetch 64(%1)\n"
22472 + " prefetch 128(%1)\n"
22473 + " prefetch 192(%1)\n"
22474 + " prefetch 256(%1)\n"
22475 "2: \n"
22476 ".section .fixup, \"ax\"\n"
22477 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22478 + "3: \n"
22479 +
22480 +#ifdef CONFIG_PAX_KERNEXEC
22481 + " movl %%cr0, %0\n"
22482 + " movl %0, %%eax\n"
22483 + " andl $0xFFFEFFFF, %%eax\n"
22484 + " movl %%eax, %%cr0\n"
22485 +#endif
22486 +
22487 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22488 +
22489 +#ifdef CONFIG_PAX_KERNEXEC
22490 + " movl %0, %%cr0\n"
22491 +#endif
22492 +
22493 " jmp 2b\n"
22494 ".previous\n"
22495 _ASM_EXTABLE(1b, 3b)
22496 - : : "r" (from));
22497 + : "=&r" (cr0) : "r" (from) : "ax");
22498
22499 for ( ; i > 5; i--) {
22500 __asm__ __volatile__ (
22501 - "1: prefetch 320(%0)\n"
22502 - "2: movq (%0), %%mm0\n"
22503 - " movq 8(%0), %%mm1\n"
22504 - " movq 16(%0), %%mm2\n"
22505 - " movq 24(%0), %%mm3\n"
22506 - " movq %%mm0, (%1)\n"
22507 - " movq %%mm1, 8(%1)\n"
22508 - " movq %%mm2, 16(%1)\n"
22509 - " movq %%mm3, 24(%1)\n"
22510 - " movq 32(%0), %%mm0\n"
22511 - " movq 40(%0), %%mm1\n"
22512 - " movq 48(%0), %%mm2\n"
22513 - " movq 56(%0), %%mm3\n"
22514 - " movq %%mm0, 32(%1)\n"
22515 - " movq %%mm1, 40(%1)\n"
22516 - " movq %%mm2, 48(%1)\n"
22517 - " movq %%mm3, 56(%1)\n"
22518 + "1: prefetch 320(%1)\n"
22519 + "2: movq (%1), %%mm0\n"
22520 + " movq 8(%1), %%mm1\n"
22521 + " movq 16(%1), %%mm2\n"
22522 + " movq 24(%1), %%mm3\n"
22523 + " movq %%mm0, (%2)\n"
22524 + " movq %%mm1, 8(%2)\n"
22525 + " movq %%mm2, 16(%2)\n"
22526 + " movq %%mm3, 24(%2)\n"
22527 + " movq 32(%1), %%mm0\n"
22528 + " movq 40(%1), %%mm1\n"
22529 + " movq 48(%1), %%mm2\n"
22530 + " movq 56(%1), %%mm3\n"
22531 + " movq %%mm0, 32(%2)\n"
22532 + " movq %%mm1, 40(%2)\n"
22533 + " movq %%mm2, 48(%2)\n"
22534 + " movq %%mm3, 56(%2)\n"
22535 ".section .fixup, \"ax\"\n"
22536 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22537 + "3:\n"
22538 +
22539 +#ifdef CONFIG_PAX_KERNEXEC
22540 + " movl %%cr0, %0\n"
22541 + " movl %0, %%eax\n"
22542 + " andl $0xFFFEFFFF, %%eax\n"
22543 + " movl %%eax, %%cr0\n"
22544 +#endif
22545 +
22546 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22547 +
22548 +#ifdef CONFIG_PAX_KERNEXEC
22549 + " movl %0, %%cr0\n"
22550 +#endif
22551 +
22552 " jmp 2b\n"
22553 ".previous\n"
22554 _ASM_EXTABLE(1b, 3b)
22555 - : : "r" (from), "r" (to) : "memory");
22556 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22557
22558 from += 64;
22559 to += 64;
22560 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22561 static void fast_copy_page(void *to, void *from)
22562 {
22563 int i;
22564 + unsigned long cr0;
22565
22566 kernel_fpu_begin();
22567
22568 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22569 * but that is for later. -AV
22570 */
22571 __asm__ __volatile__(
22572 - "1: prefetch (%0)\n"
22573 - " prefetch 64(%0)\n"
22574 - " prefetch 128(%0)\n"
22575 - " prefetch 192(%0)\n"
22576 - " prefetch 256(%0)\n"
22577 + "1: prefetch (%1)\n"
22578 + " prefetch 64(%1)\n"
22579 + " prefetch 128(%1)\n"
22580 + " prefetch 192(%1)\n"
22581 + " prefetch 256(%1)\n"
22582 "2: \n"
22583 ".section .fixup, \"ax\"\n"
22584 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22585 + "3: \n"
22586 +
22587 +#ifdef CONFIG_PAX_KERNEXEC
22588 + " movl %%cr0, %0\n"
22589 + " movl %0, %%eax\n"
22590 + " andl $0xFFFEFFFF, %%eax\n"
22591 + " movl %%eax, %%cr0\n"
22592 +#endif
22593 +
22594 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22595 +
22596 +#ifdef CONFIG_PAX_KERNEXEC
22597 + " movl %0, %%cr0\n"
22598 +#endif
22599 +
22600 " jmp 2b\n"
22601 ".previous\n"
22602 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22603 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22604
22605 for (i = 0; i < (4096-320)/64; i++) {
22606 __asm__ __volatile__ (
22607 - "1: prefetch 320(%0)\n"
22608 - "2: movq (%0), %%mm0\n"
22609 - " movntq %%mm0, (%1)\n"
22610 - " movq 8(%0), %%mm1\n"
22611 - " movntq %%mm1, 8(%1)\n"
22612 - " movq 16(%0), %%mm2\n"
22613 - " movntq %%mm2, 16(%1)\n"
22614 - " movq 24(%0), %%mm3\n"
22615 - " movntq %%mm3, 24(%1)\n"
22616 - " movq 32(%0), %%mm4\n"
22617 - " movntq %%mm4, 32(%1)\n"
22618 - " movq 40(%0), %%mm5\n"
22619 - " movntq %%mm5, 40(%1)\n"
22620 - " movq 48(%0), %%mm6\n"
22621 - " movntq %%mm6, 48(%1)\n"
22622 - " movq 56(%0), %%mm7\n"
22623 - " movntq %%mm7, 56(%1)\n"
22624 + "1: prefetch 320(%1)\n"
22625 + "2: movq (%1), %%mm0\n"
22626 + " movntq %%mm0, (%2)\n"
22627 + " movq 8(%1), %%mm1\n"
22628 + " movntq %%mm1, 8(%2)\n"
22629 + " movq 16(%1), %%mm2\n"
22630 + " movntq %%mm2, 16(%2)\n"
22631 + " movq 24(%1), %%mm3\n"
22632 + " movntq %%mm3, 24(%2)\n"
22633 + " movq 32(%1), %%mm4\n"
22634 + " movntq %%mm4, 32(%2)\n"
22635 + " movq 40(%1), %%mm5\n"
22636 + " movntq %%mm5, 40(%2)\n"
22637 + " movq 48(%1), %%mm6\n"
22638 + " movntq %%mm6, 48(%2)\n"
22639 + " movq 56(%1), %%mm7\n"
22640 + " movntq %%mm7, 56(%2)\n"
22641 ".section .fixup, \"ax\"\n"
22642 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22643 + "3:\n"
22644 +
22645 +#ifdef CONFIG_PAX_KERNEXEC
22646 + " movl %%cr0, %0\n"
22647 + " movl %0, %%eax\n"
22648 + " andl $0xFFFEFFFF, %%eax\n"
22649 + " movl %%eax, %%cr0\n"
22650 +#endif
22651 +
22652 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22653 +
22654 +#ifdef CONFIG_PAX_KERNEXEC
22655 + " movl %0, %%cr0\n"
22656 +#endif
22657 +
22658 " jmp 2b\n"
22659 ".previous\n"
22660 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22661 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22662
22663 from += 64;
22664 to += 64;
22665 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22666 static void fast_copy_page(void *to, void *from)
22667 {
22668 int i;
22669 + unsigned long cr0;
22670
22671 kernel_fpu_begin();
22672
22673 __asm__ __volatile__ (
22674 - "1: prefetch (%0)\n"
22675 - " prefetch 64(%0)\n"
22676 - " prefetch 128(%0)\n"
22677 - " prefetch 192(%0)\n"
22678 - " prefetch 256(%0)\n"
22679 + "1: prefetch (%1)\n"
22680 + " prefetch 64(%1)\n"
22681 + " prefetch 128(%1)\n"
22682 + " prefetch 192(%1)\n"
22683 + " prefetch 256(%1)\n"
22684 "2: \n"
22685 ".section .fixup, \"ax\"\n"
22686 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22687 + "3: \n"
22688 +
22689 +#ifdef CONFIG_PAX_KERNEXEC
22690 + " movl %%cr0, %0\n"
22691 + " movl %0, %%eax\n"
22692 + " andl $0xFFFEFFFF, %%eax\n"
22693 + " movl %%eax, %%cr0\n"
22694 +#endif
22695 +
22696 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22697 +
22698 +#ifdef CONFIG_PAX_KERNEXEC
22699 + " movl %0, %%cr0\n"
22700 +#endif
22701 +
22702 " jmp 2b\n"
22703 ".previous\n"
22704 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22705 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22706
22707 for (i = 0; i < 4096/64; i++) {
22708 __asm__ __volatile__ (
22709 - "1: prefetch 320(%0)\n"
22710 - "2: movq (%0), %%mm0\n"
22711 - " movq 8(%0), %%mm1\n"
22712 - " movq 16(%0), %%mm2\n"
22713 - " movq 24(%0), %%mm3\n"
22714 - " movq %%mm0, (%1)\n"
22715 - " movq %%mm1, 8(%1)\n"
22716 - " movq %%mm2, 16(%1)\n"
22717 - " movq %%mm3, 24(%1)\n"
22718 - " movq 32(%0), %%mm0\n"
22719 - " movq 40(%0), %%mm1\n"
22720 - " movq 48(%0), %%mm2\n"
22721 - " movq 56(%0), %%mm3\n"
22722 - " movq %%mm0, 32(%1)\n"
22723 - " movq %%mm1, 40(%1)\n"
22724 - " movq %%mm2, 48(%1)\n"
22725 - " movq %%mm3, 56(%1)\n"
22726 + "1: prefetch 320(%1)\n"
22727 + "2: movq (%1), %%mm0\n"
22728 + " movq 8(%1), %%mm1\n"
22729 + " movq 16(%1), %%mm2\n"
22730 + " movq 24(%1), %%mm3\n"
22731 + " movq %%mm0, (%2)\n"
22732 + " movq %%mm1, 8(%2)\n"
22733 + " movq %%mm2, 16(%2)\n"
22734 + " movq %%mm3, 24(%2)\n"
22735 + " movq 32(%1), %%mm0\n"
22736 + " movq 40(%1), %%mm1\n"
22737 + " movq 48(%1), %%mm2\n"
22738 + " movq 56(%1), %%mm3\n"
22739 + " movq %%mm0, 32(%2)\n"
22740 + " movq %%mm1, 40(%2)\n"
22741 + " movq %%mm2, 48(%2)\n"
22742 + " movq %%mm3, 56(%2)\n"
22743 ".section .fixup, \"ax\"\n"
22744 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22745 + "3:\n"
22746 +
22747 +#ifdef CONFIG_PAX_KERNEXEC
22748 + " movl %%cr0, %0\n"
22749 + " movl %0, %%eax\n"
22750 + " andl $0xFFFEFFFF, %%eax\n"
22751 + " movl %%eax, %%cr0\n"
22752 +#endif
22753 +
22754 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22755 +
22756 +#ifdef CONFIG_PAX_KERNEXEC
22757 + " movl %0, %%cr0\n"
22758 +#endif
22759 +
22760 " jmp 2b\n"
22761 ".previous\n"
22762 _ASM_EXTABLE(1b, 3b)
22763 - : : "r" (from), "r" (to) : "memory");
22764 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22765
22766 from += 64;
22767 to += 64;
22768 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22769 index f6d13ee..aca5f0b 100644
22770 --- a/arch/x86/lib/msr-reg.S
22771 +++ b/arch/x86/lib/msr-reg.S
22772 @@ -3,6 +3,7 @@
22773 #include <asm/dwarf2.h>
22774 #include <asm/asm.h>
22775 #include <asm/msr.h>
22776 +#include <asm/alternative-asm.h>
22777
22778 #ifdef CONFIG_X86_64
22779 /*
22780 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22781 CFI_STARTPROC
22782 pushq_cfi %rbx
22783 pushq_cfi %rbp
22784 - movq %rdi, %r10 /* Save pointer */
22785 + movq %rdi, %r9 /* Save pointer */
22786 xorl %r11d, %r11d /* Return value */
22787 movl (%rdi), %eax
22788 movl 4(%rdi), %ecx
22789 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22790 movl 28(%rdi), %edi
22791 CFI_REMEMBER_STATE
22792 1: \op
22793 -2: movl %eax, (%r10)
22794 +2: movl %eax, (%r9)
22795 movl %r11d, %eax /* Return value */
22796 - movl %ecx, 4(%r10)
22797 - movl %edx, 8(%r10)
22798 - movl %ebx, 12(%r10)
22799 - movl %ebp, 20(%r10)
22800 - movl %esi, 24(%r10)
22801 - movl %edi, 28(%r10)
22802 + movl %ecx, 4(%r9)
22803 + movl %edx, 8(%r9)
22804 + movl %ebx, 12(%r9)
22805 + movl %ebp, 20(%r9)
22806 + movl %esi, 24(%r9)
22807 + movl %edi, 28(%r9)
22808 popq_cfi %rbp
22809 popq_cfi %rbx
22810 + pax_force_retaddr
22811 ret
22812 3:
22813 CFI_RESTORE_STATE
22814 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22815 index fc6ba17..04471c5 100644
22816 --- a/arch/x86/lib/putuser.S
22817 +++ b/arch/x86/lib/putuser.S
22818 @@ -16,7 +16,9 @@
22819 #include <asm/errno.h>
22820 #include <asm/asm.h>
22821 #include <asm/smap.h>
22822 -
22823 +#include <asm/segment.h>
22824 +#include <asm/pgtable.h>
22825 +#include <asm/alternative-asm.h>
22826
22827 /*
22828 * __put_user_X
22829 @@ -30,57 +32,125 @@
22830 * as they get called from within inline assembly.
22831 */
22832
22833 -#define ENTER CFI_STARTPROC ; \
22834 - GET_THREAD_INFO(%_ASM_BX)
22835 -#define EXIT ASM_CLAC ; \
22836 - ret ; \
22837 +#define ENTER CFI_STARTPROC
22838 +#define EXIT ASM_CLAC ; \
22839 + pax_force_retaddr ; \
22840 + ret ; \
22841 CFI_ENDPROC
22842
22843 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22844 +#define _DEST %_ASM_CX,%_ASM_BX
22845 +#else
22846 +#define _DEST %_ASM_CX
22847 +#endif
22848 +
22849 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22850 +#define __copyuser_seg gs;
22851 +#else
22852 +#define __copyuser_seg
22853 +#endif
22854 +
22855 .text
22856 ENTRY(__put_user_1)
22857 ENTER
22858 +
22859 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22860 + GET_THREAD_INFO(%_ASM_BX)
22861 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22862 jae bad_put_user
22863 ASM_STAC
22864 -1: movb %al,(%_ASM_CX)
22865 +
22866 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22867 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22868 + cmp %_ASM_BX,%_ASM_CX
22869 + jb 1234f
22870 + xor %ebx,%ebx
22871 +1234:
22872 +#endif
22873 +
22874 +#endif
22875 +
22876 +1: __copyuser_seg movb %al,(_DEST)
22877 xor %eax,%eax
22878 EXIT
22879 ENDPROC(__put_user_1)
22880
22881 ENTRY(__put_user_2)
22882 ENTER
22883 +
22884 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22885 + GET_THREAD_INFO(%_ASM_BX)
22886 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22887 sub $1,%_ASM_BX
22888 cmp %_ASM_BX,%_ASM_CX
22889 jae bad_put_user
22890 ASM_STAC
22891 -2: movw %ax,(%_ASM_CX)
22892 +
22893 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22894 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22895 + cmp %_ASM_BX,%_ASM_CX
22896 + jb 1234f
22897 + xor %ebx,%ebx
22898 +1234:
22899 +#endif
22900 +
22901 +#endif
22902 +
22903 +2: __copyuser_seg movw %ax,(_DEST)
22904 xor %eax,%eax
22905 EXIT
22906 ENDPROC(__put_user_2)
22907
22908 ENTRY(__put_user_4)
22909 ENTER
22910 +
22911 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22912 + GET_THREAD_INFO(%_ASM_BX)
22913 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22914 sub $3,%_ASM_BX
22915 cmp %_ASM_BX,%_ASM_CX
22916 jae bad_put_user
22917 ASM_STAC
22918 -3: movl %eax,(%_ASM_CX)
22919 +
22920 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22921 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22922 + cmp %_ASM_BX,%_ASM_CX
22923 + jb 1234f
22924 + xor %ebx,%ebx
22925 +1234:
22926 +#endif
22927 +
22928 +#endif
22929 +
22930 +3: __copyuser_seg movl %eax,(_DEST)
22931 xor %eax,%eax
22932 EXIT
22933 ENDPROC(__put_user_4)
22934
22935 ENTRY(__put_user_8)
22936 ENTER
22937 +
22938 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22939 + GET_THREAD_INFO(%_ASM_BX)
22940 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22941 sub $7,%_ASM_BX
22942 cmp %_ASM_BX,%_ASM_CX
22943 jae bad_put_user
22944 ASM_STAC
22945 -4: mov %_ASM_AX,(%_ASM_CX)
22946 +
22947 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22948 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22949 + cmp %_ASM_BX,%_ASM_CX
22950 + jb 1234f
22951 + xor %ebx,%ebx
22952 +1234:
22953 +#endif
22954 +
22955 +#endif
22956 +
22957 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22958 #ifdef CONFIG_X86_32
22959 -5: movl %edx,4(%_ASM_CX)
22960 +5: __copyuser_seg movl %edx,4(_DEST)
22961 #endif
22962 xor %eax,%eax
22963 EXIT
22964 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22965 index 1cad221..de671ee 100644
22966 --- a/arch/x86/lib/rwlock.S
22967 +++ b/arch/x86/lib/rwlock.S
22968 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22969 FRAME
22970 0: LOCK_PREFIX
22971 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22972 +
22973 +#ifdef CONFIG_PAX_REFCOUNT
22974 + jno 1234f
22975 + LOCK_PREFIX
22976 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22977 + int $4
22978 +1234:
22979 + _ASM_EXTABLE(1234b, 1234b)
22980 +#endif
22981 +
22982 1: rep; nop
22983 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22984 jne 1b
22985 LOCK_PREFIX
22986 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22987 +
22988 +#ifdef CONFIG_PAX_REFCOUNT
22989 + jno 1234f
22990 + LOCK_PREFIX
22991 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22992 + int $4
22993 +1234:
22994 + _ASM_EXTABLE(1234b, 1234b)
22995 +#endif
22996 +
22997 jnz 0b
22998 ENDFRAME
22999 + pax_force_retaddr
23000 ret
23001 CFI_ENDPROC
23002 END(__write_lock_failed)
23003 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
23004 FRAME
23005 0: LOCK_PREFIX
23006 READ_LOCK_SIZE(inc) (%__lock_ptr)
23007 +
23008 +#ifdef CONFIG_PAX_REFCOUNT
23009 + jno 1234f
23010 + LOCK_PREFIX
23011 + READ_LOCK_SIZE(dec) (%__lock_ptr)
23012 + int $4
23013 +1234:
23014 + _ASM_EXTABLE(1234b, 1234b)
23015 +#endif
23016 +
23017 1: rep; nop
23018 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
23019 js 1b
23020 LOCK_PREFIX
23021 READ_LOCK_SIZE(dec) (%__lock_ptr)
23022 +
23023 +#ifdef CONFIG_PAX_REFCOUNT
23024 + jno 1234f
23025 + LOCK_PREFIX
23026 + READ_LOCK_SIZE(inc) (%__lock_ptr)
23027 + int $4
23028 +1234:
23029 + _ASM_EXTABLE(1234b, 1234b)
23030 +#endif
23031 +
23032 js 0b
23033 ENDFRAME
23034 + pax_force_retaddr
23035 ret
23036 CFI_ENDPROC
23037 END(__read_lock_failed)
23038 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
23039 index 5dff5f0..cadebf4 100644
23040 --- a/arch/x86/lib/rwsem.S
23041 +++ b/arch/x86/lib/rwsem.S
23042 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
23043 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23044 CFI_RESTORE __ASM_REG(dx)
23045 restore_common_regs
23046 + pax_force_retaddr
23047 ret
23048 CFI_ENDPROC
23049 ENDPROC(call_rwsem_down_read_failed)
23050 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
23051 movq %rax,%rdi
23052 call rwsem_down_write_failed
23053 restore_common_regs
23054 + pax_force_retaddr
23055 ret
23056 CFI_ENDPROC
23057 ENDPROC(call_rwsem_down_write_failed)
23058 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
23059 movq %rax,%rdi
23060 call rwsem_wake
23061 restore_common_regs
23062 -1: ret
23063 +1: pax_force_retaddr
23064 + ret
23065 CFI_ENDPROC
23066 ENDPROC(call_rwsem_wake)
23067
23068 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
23069 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23070 CFI_RESTORE __ASM_REG(dx)
23071 restore_common_regs
23072 + pax_force_retaddr
23073 ret
23074 CFI_ENDPROC
23075 ENDPROC(call_rwsem_downgrade_wake)
23076 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
23077 index a63efd6..ccecad8 100644
23078 --- a/arch/x86/lib/thunk_64.S
23079 +++ b/arch/x86/lib/thunk_64.S
23080 @@ -8,6 +8,7 @@
23081 #include <linux/linkage.h>
23082 #include <asm/dwarf2.h>
23083 #include <asm/calling.h>
23084 +#include <asm/alternative-asm.h>
23085
23086 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23087 .macro THUNK name, func, put_ret_addr_in_rdi=0
23088 @@ -41,5 +42,6 @@
23089 SAVE_ARGS
23090 restore:
23091 RESTORE_ARGS
23092 + pax_force_retaddr
23093 ret
23094 CFI_ENDPROC
23095 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23096 index 98f6d6b6..d27f045 100644
23097 --- a/arch/x86/lib/usercopy_32.c
23098 +++ b/arch/x86/lib/usercopy_32.c
23099 @@ -42,11 +42,13 @@ do { \
23100 int __d0; \
23101 might_fault(); \
23102 __asm__ __volatile__( \
23103 + __COPYUSER_SET_ES \
23104 ASM_STAC "\n" \
23105 "0: rep; stosl\n" \
23106 " movl %2,%0\n" \
23107 "1: rep; stosb\n" \
23108 "2: " ASM_CLAC "\n" \
23109 + __COPYUSER_RESTORE_ES \
23110 ".section .fixup,\"ax\"\n" \
23111 "3: lea 0(%2,%0,4),%0\n" \
23112 " jmp 2b\n" \
23113 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
23114
23115 #ifdef CONFIG_X86_INTEL_USERCOPY
23116 static unsigned long
23117 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
23118 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23119 {
23120 int d0, d1;
23121 __asm__ __volatile__(
23122 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23123 " .align 2,0x90\n"
23124 "3: movl 0(%4), %%eax\n"
23125 "4: movl 4(%4), %%edx\n"
23126 - "5: movl %%eax, 0(%3)\n"
23127 - "6: movl %%edx, 4(%3)\n"
23128 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23129 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23130 "7: movl 8(%4), %%eax\n"
23131 "8: movl 12(%4),%%edx\n"
23132 - "9: movl %%eax, 8(%3)\n"
23133 - "10: movl %%edx, 12(%3)\n"
23134 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23135 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23136 "11: movl 16(%4), %%eax\n"
23137 "12: movl 20(%4), %%edx\n"
23138 - "13: movl %%eax, 16(%3)\n"
23139 - "14: movl %%edx, 20(%3)\n"
23140 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23141 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23142 "15: movl 24(%4), %%eax\n"
23143 "16: movl 28(%4), %%edx\n"
23144 - "17: movl %%eax, 24(%3)\n"
23145 - "18: movl %%edx, 28(%3)\n"
23146 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23147 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23148 "19: movl 32(%4), %%eax\n"
23149 "20: movl 36(%4), %%edx\n"
23150 - "21: movl %%eax, 32(%3)\n"
23151 - "22: movl %%edx, 36(%3)\n"
23152 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23153 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23154 "23: movl 40(%4), %%eax\n"
23155 "24: movl 44(%4), %%edx\n"
23156 - "25: movl %%eax, 40(%3)\n"
23157 - "26: movl %%edx, 44(%3)\n"
23158 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23159 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23160 "27: movl 48(%4), %%eax\n"
23161 "28: movl 52(%4), %%edx\n"
23162 - "29: movl %%eax, 48(%3)\n"
23163 - "30: movl %%edx, 52(%3)\n"
23164 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23165 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23166 "31: movl 56(%4), %%eax\n"
23167 "32: movl 60(%4), %%edx\n"
23168 - "33: movl %%eax, 56(%3)\n"
23169 - "34: movl %%edx, 60(%3)\n"
23170 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23171 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23172 " addl $-64, %0\n"
23173 " addl $64, %4\n"
23174 " addl $64, %3\n"
23175 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23176 " shrl $2, %0\n"
23177 " andl $3, %%eax\n"
23178 " cld\n"
23179 + __COPYUSER_SET_ES
23180 "99: rep; movsl\n"
23181 "36: movl %%eax, %0\n"
23182 "37: rep; movsb\n"
23183 "100:\n"
23184 + __COPYUSER_RESTORE_ES
23185 ".section .fixup,\"ax\"\n"
23186 "101: lea 0(%%eax,%0,4),%0\n"
23187 " jmp 100b\n"
23188 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23189 }
23190
23191 static unsigned long
23192 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23193 +{
23194 + int d0, d1;
23195 + __asm__ __volatile__(
23196 + " .align 2,0x90\n"
23197 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23198 + " cmpl $67, %0\n"
23199 + " jbe 3f\n"
23200 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23201 + " .align 2,0x90\n"
23202 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23203 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23204 + "5: movl %%eax, 0(%3)\n"
23205 + "6: movl %%edx, 4(%3)\n"
23206 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23207 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23208 + "9: movl %%eax, 8(%3)\n"
23209 + "10: movl %%edx, 12(%3)\n"
23210 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23211 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23212 + "13: movl %%eax, 16(%3)\n"
23213 + "14: movl %%edx, 20(%3)\n"
23214 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23215 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23216 + "17: movl %%eax, 24(%3)\n"
23217 + "18: movl %%edx, 28(%3)\n"
23218 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23219 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23220 + "21: movl %%eax, 32(%3)\n"
23221 + "22: movl %%edx, 36(%3)\n"
23222 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23223 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23224 + "25: movl %%eax, 40(%3)\n"
23225 + "26: movl %%edx, 44(%3)\n"
23226 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23227 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23228 + "29: movl %%eax, 48(%3)\n"
23229 + "30: movl %%edx, 52(%3)\n"
23230 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23231 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23232 + "33: movl %%eax, 56(%3)\n"
23233 + "34: movl %%edx, 60(%3)\n"
23234 + " addl $-64, %0\n"
23235 + " addl $64, %4\n"
23236 + " addl $64, %3\n"
23237 + " cmpl $63, %0\n"
23238 + " ja 1b\n"
23239 + "35: movl %0, %%eax\n"
23240 + " shrl $2, %0\n"
23241 + " andl $3, %%eax\n"
23242 + " cld\n"
23243 + "99: rep; "__copyuser_seg" movsl\n"
23244 + "36: movl %%eax, %0\n"
23245 + "37: rep; "__copyuser_seg" movsb\n"
23246 + "100:\n"
23247 + ".section .fixup,\"ax\"\n"
23248 + "101: lea 0(%%eax,%0,4),%0\n"
23249 + " jmp 100b\n"
23250 + ".previous\n"
23251 + _ASM_EXTABLE(1b,100b)
23252 + _ASM_EXTABLE(2b,100b)
23253 + _ASM_EXTABLE(3b,100b)
23254 + _ASM_EXTABLE(4b,100b)
23255 + _ASM_EXTABLE(5b,100b)
23256 + _ASM_EXTABLE(6b,100b)
23257 + _ASM_EXTABLE(7b,100b)
23258 + _ASM_EXTABLE(8b,100b)
23259 + _ASM_EXTABLE(9b,100b)
23260 + _ASM_EXTABLE(10b,100b)
23261 + _ASM_EXTABLE(11b,100b)
23262 + _ASM_EXTABLE(12b,100b)
23263 + _ASM_EXTABLE(13b,100b)
23264 + _ASM_EXTABLE(14b,100b)
23265 + _ASM_EXTABLE(15b,100b)
23266 + _ASM_EXTABLE(16b,100b)
23267 + _ASM_EXTABLE(17b,100b)
23268 + _ASM_EXTABLE(18b,100b)
23269 + _ASM_EXTABLE(19b,100b)
23270 + _ASM_EXTABLE(20b,100b)
23271 + _ASM_EXTABLE(21b,100b)
23272 + _ASM_EXTABLE(22b,100b)
23273 + _ASM_EXTABLE(23b,100b)
23274 + _ASM_EXTABLE(24b,100b)
23275 + _ASM_EXTABLE(25b,100b)
23276 + _ASM_EXTABLE(26b,100b)
23277 + _ASM_EXTABLE(27b,100b)
23278 + _ASM_EXTABLE(28b,100b)
23279 + _ASM_EXTABLE(29b,100b)
23280 + _ASM_EXTABLE(30b,100b)
23281 + _ASM_EXTABLE(31b,100b)
23282 + _ASM_EXTABLE(32b,100b)
23283 + _ASM_EXTABLE(33b,100b)
23284 + _ASM_EXTABLE(34b,100b)
23285 + _ASM_EXTABLE(35b,100b)
23286 + _ASM_EXTABLE(36b,100b)
23287 + _ASM_EXTABLE(37b,100b)
23288 + _ASM_EXTABLE(99b,101b)
23289 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23290 + : "1"(to), "2"(from), "0"(size)
23291 + : "eax", "edx", "memory");
23292 + return size;
23293 +}
23294 +
23295 +static unsigned long __size_overflow(3)
23296 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23297 {
23298 int d0, d1;
23299 __asm__ __volatile__(
23300 " .align 2,0x90\n"
23301 - "0: movl 32(%4), %%eax\n"
23302 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23303 " cmpl $67, %0\n"
23304 " jbe 2f\n"
23305 - "1: movl 64(%4), %%eax\n"
23306 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23307 " .align 2,0x90\n"
23308 - "2: movl 0(%4), %%eax\n"
23309 - "21: movl 4(%4), %%edx\n"
23310 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23311 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23312 " movl %%eax, 0(%3)\n"
23313 " movl %%edx, 4(%3)\n"
23314 - "3: movl 8(%4), %%eax\n"
23315 - "31: movl 12(%4),%%edx\n"
23316 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23317 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23318 " movl %%eax, 8(%3)\n"
23319 " movl %%edx, 12(%3)\n"
23320 - "4: movl 16(%4), %%eax\n"
23321 - "41: movl 20(%4), %%edx\n"
23322 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23323 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23324 " movl %%eax, 16(%3)\n"
23325 " movl %%edx, 20(%3)\n"
23326 - "10: movl 24(%4), %%eax\n"
23327 - "51: movl 28(%4), %%edx\n"
23328 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23329 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23330 " movl %%eax, 24(%3)\n"
23331 " movl %%edx, 28(%3)\n"
23332 - "11: movl 32(%4), %%eax\n"
23333 - "61: movl 36(%4), %%edx\n"
23334 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23335 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23336 " movl %%eax, 32(%3)\n"
23337 " movl %%edx, 36(%3)\n"
23338 - "12: movl 40(%4), %%eax\n"
23339 - "71: movl 44(%4), %%edx\n"
23340 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23341 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23342 " movl %%eax, 40(%3)\n"
23343 " movl %%edx, 44(%3)\n"
23344 - "13: movl 48(%4), %%eax\n"
23345 - "81: movl 52(%4), %%edx\n"
23346 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23347 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23348 " movl %%eax, 48(%3)\n"
23349 " movl %%edx, 52(%3)\n"
23350 - "14: movl 56(%4), %%eax\n"
23351 - "91: movl 60(%4), %%edx\n"
23352 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23353 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23354 " movl %%eax, 56(%3)\n"
23355 " movl %%edx, 60(%3)\n"
23356 " addl $-64, %0\n"
23357 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23358 " shrl $2, %0\n"
23359 " andl $3, %%eax\n"
23360 " cld\n"
23361 - "6: rep; movsl\n"
23362 + "6: rep; "__copyuser_seg" movsl\n"
23363 " movl %%eax,%0\n"
23364 - "7: rep; movsb\n"
23365 + "7: rep; "__copyuser_seg" movsb\n"
23366 "8:\n"
23367 ".section .fixup,\"ax\"\n"
23368 "9: lea 0(%%eax,%0,4),%0\n"
23369 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23370 * hyoshiok@miraclelinux.com
23371 */
23372
23373 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23374 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23375 const void __user *from, unsigned long size)
23376 {
23377 int d0, d1;
23378
23379 __asm__ __volatile__(
23380 " .align 2,0x90\n"
23381 - "0: movl 32(%4), %%eax\n"
23382 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23383 " cmpl $67, %0\n"
23384 " jbe 2f\n"
23385 - "1: movl 64(%4), %%eax\n"
23386 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23387 " .align 2,0x90\n"
23388 - "2: movl 0(%4), %%eax\n"
23389 - "21: movl 4(%4), %%edx\n"
23390 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23391 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23392 " movnti %%eax, 0(%3)\n"
23393 " movnti %%edx, 4(%3)\n"
23394 - "3: movl 8(%4), %%eax\n"
23395 - "31: movl 12(%4),%%edx\n"
23396 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23397 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23398 " movnti %%eax, 8(%3)\n"
23399 " movnti %%edx, 12(%3)\n"
23400 - "4: movl 16(%4), %%eax\n"
23401 - "41: movl 20(%4), %%edx\n"
23402 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23403 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23404 " movnti %%eax, 16(%3)\n"
23405 " movnti %%edx, 20(%3)\n"
23406 - "10: movl 24(%4), %%eax\n"
23407 - "51: movl 28(%4), %%edx\n"
23408 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23409 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23410 " movnti %%eax, 24(%3)\n"
23411 " movnti %%edx, 28(%3)\n"
23412 - "11: movl 32(%4), %%eax\n"
23413 - "61: movl 36(%4), %%edx\n"
23414 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23415 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23416 " movnti %%eax, 32(%3)\n"
23417 " movnti %%edx, 36(%3)\n"
23418 - "12: movl 40(%4), %%eax\n"
23419 - "71: movl 44(%4), %%edx\n"
23420 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23421 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23422 " movnti %%eax, 40(%3)\n"
23423 " movnti %%edx, 44(%3)\n"
23424 - "13: movl 48(%4), %%eax\n"
23425 - "81: movl 52(%4), %%edx\n"
23426 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23427 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23428 " movnti %%eax, 48(%3)\n"
23429 " movnti %%edx, 52(%3)\n"
23430 - "14: movl 56(%4), %%eax\n"
23431 - "91: movl 60(%4), %%edx\n"
23432 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23433 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23434 " movnti %%eax, 56(%3)\n"
23435 " movnti %%edx, 60(%3)\n"
23436 " addl $-64, %0\n"
23437 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23438 " shrl $2, %0\n"
23439 " andl $3, %%eax\n"
23440 " cld\n"
23441 - "6: rep; movsl\n"
23442 + "6: rep; "__copyuser_seg" movsl\n"
23443 " movl %%eax,%0\n"
23444 - "7: rep; movsb\n"
23445 + "7: rep; "__copyuser_seg" movsb\n"
23446 "8:\n"
23447 ".section .fixup,\"ax\"\n"
23448 "9: lea 0(%%eax,%0,4),%0\n"
23449 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23450 return size;
23451 }
23452
23453 -static unsigned long __copy_user_intel_nocache(void *to,
23454 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23455 const void __user *from, unsigned long size)
23456 {
23457 int d0, d1;
23458
23459 __asm__ __volatile__(
23460 " .align 2,0x90\n"
23461 - "0: movl 32(%4), %%eax\n"
23462 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23463 " cmpl $67, %0\n"
23464 " jbe 2f\n"
23465 - "1: movl 64(%4), %%eax\n"
23466 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23467 " .align 2,0x90\n"
23468 - "2: movl 0(%4), %%eax\n"
23469 - "21: movl 4(%4), %%edx\n"
23470 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23471 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23472 " movnti %%eax, 0(%3)\n"
23473 " movnti %%edx, 4(%3)\n"
23474 - "3: movl 8(%4), %%eax\n"
23475 - "31: movl 12(%4),%%edx\n"
23476 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23477 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23478 " movnti %%eax, 8(%3)\n"
23479 " movnti %%edx, 12(%3)\n"
23480 - "4: movl 16(%4), %%eax\n"
23481 - "41: movl 20(%4), %%edx\n"
23482 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23483 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23484 " movnti %%eax, 16(%3)\n"
23485 " movnti %%edx, 20(%3)\n"
23486 - "10: movl 24(%4), %%eax\n"
23487 - "51: movl 28(%4), %%edx\n"
23488 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23489 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23490 " movnti %%eax, 24(%3)\n"
23491 " movnti %%edx, 28(%3)\n"
23492 - "11: movl 32(%4), %%eax\n"
23493 - "61: movl 36(%4), %%edx\n"
23494 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23495 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23496 " movnti %%eax, 32(%3)\n"
23497 " movnti %%edx, 36(%3)\n"
23498 - "12: movl 40(%4), %%eax\n"
23499 - "71: movl 44(%4), %%edx\n"
23500 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23501 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23502 " movnti %%eax, 40(%3)\n"
23503 " movnti %%edx, 44(%3)\n"
23504 - "13: movl 48(%4), %%eax\n"
23505 - "81: movl 52(%4), %%edx\n"
23506 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23507 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23508 " movnti %%eax, 48(%3)\n"
23509 " movnti %%edx, 52(%3)\n"
23510 - "14: movl 56(%4), %%eax\n"
23511 - "91: movl 60(%4), %%edx\n"
23512 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23513 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23514 " movnti %%eax, 56(%3)\n"
23515 " movnti %%edx, 60(%3)\n"
23516 " addl $-64, %0\n"
23517 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23518 " shrl $2, %0\n"
23519 " andl $3, %%eax\n"
23520 " cld\n"
23521 - "6: rep; movsl\n"
23522 + "6: rep; "__copyuser_seg" movsl\n"
23523 " movl %%eax,%0\n"
23524 - "7: rep; movsb\n"
23525 + "7: rep; "__copyuser_seg" movsb\n"
23526 "8:\n"
23527 ".section .fixup,\"ax\"\n"
23528 "9: lea 0(%%eax,%0,4),%0\n"
23529 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23530 */
23531 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23532 unsigned long size);
23533 -unsigned long __copy_user_intel(void __user *to, const void *from,
23534 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23535 + unsigned long size);
23536 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23537 unsigned long size);
23538 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23539 const void __user *from, unsigned long size);
23540 #endif /* CONFIG_X86_INTEL_USERCOPY */
23541
23542 /* Generic arbitrary sized copy. */
23543 -#define __copy_user(to, from, size) \
23544 +#define __copy_user(to, from, size, prefix, set, restore) \
23545 do { \
23546 int __d0, __d1, __d2; \
23547 __asm__ __volatile__( \
23548 + set \
23549 " cmp $7,%0\n" \
23550 " jbe 1f\n" \
23551 " movl %1,%0\n" \
23552 " negl %0\n" \
23553 " andl $7,%0\n" \
23554 " subl %0,%3\n" \
23555 - "4: rep; movsb\n" \
23556 + "4: rep; "prefix"movsb\n" \
23557 " movl %3,%0\n" \
23558 " shrl $2,%0\n" \
23559 " andl $3,%3\n" \
23560 " .align 2,0x90\n" \
23561 - "0: rep; movsl\n" \
23562 + "0: rep; "prefix"movsl\n" \
23563 " movl %3,%0\n" \
23564 - "1: rep; movsb\n" \
23565 + "1: rep; "prefix"movsb\n" \
23566 "2:\n" \
23567 + restore \
23568 ".section .fixup,\"ax\"\n" \
23569 "5: addl %3,%0\n" \
23570 " jmp 2b\n" \
23571 @@ -538,14 +650,14 @@ do { \
23572 " negl %0\n" \
23573 " andl $7,%0\n" \
23574 " subl %0,%3\n" \
23575 - "4: rep; movsb\n" \
23576 + "4: rep; "__copyuser_seg"movsb\n" \
23577 " movl %3,%0\n" \
23578 " shrl $2,%0\n" \
23579 " andl $3,%3\n" \
23580 " .align 2,0x90\n" \
23581 - "0: rep; movsl\n" \
23582 + "0: rep; "__copyuser_seg"movsl\n" \
23583 " movl %3,%0\n" \
23584 - "1: rep; movsb\n" \
23585 + "1: rep; "__copyuser_seg"movsb\n" \
23586 "2:\n" \
23587 ".section .fixup,\"ax\"\n" \
23588 "5: addl %3,%0\n" \
23589 @@ -629,9 +741,9 @@ survive:
23590 #endif
23591 stac();
23592 if (movsl_is_ok(to, from, n))
23593 - __copy_user(to, from, n);
23594 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23595 else
23596 - n = __copy_user_intel(to, from, n);
23597 + n = __generic_copy_to_user_intel(to, from, n);
23598 clac();
23599 return n;
23600 }
23601 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23602 {
23603 stac();
23604 if (movsl_is_ok(to, from, n))
23605 - __copy_user(to, from, n);
23606 + __copy_user(to, from, n, __copyuser_seg, "", "");
23607 else
23608 - n = __copy_user_intel((void __user *)to,
23609 - (const void *)from, n);
23610 + n = __generic_copy_from_user_intel(to, from, n);
23611 clac();
23612 return n;
23613 }
23614 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23615 if (n > 64 && cpu_has_xmm2)
23616 n = __copy_user_intel_nocache(to, from, n);
23617 else
23618 - __copy_user(to, from, n);
23619 + __copy_user(to, from, n, __copyuser_seg, "", "");
23620 #else
23621 - __copy_user(to, from, n);
23622 + __copy_user(to, from, n, __copyuser_seg, "", "");
23623 #endif
23624 clac();
23625 return n;
23626 }
23627 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23628
23629 -/**
23630 - * copy_to_user: - Copy a block of data into user space.
23631 - * @to: Destination address, in user space.
23632 - * @from: Source address, in kernel space.
23633 - * @n: Number of bytes to copy.
23634 - *
23635 - * Context: User context only. This function may sleep.
23636 - *
23637 - * Copy data from kernel space to user space.
23638 - *
23639 - * Returns number of bytes that could not be copied.
23640 - * On success, this will be zero.
23641 - */
23642 -unsigned long
23643 -copy_to_user(void __user *to, const void *from, unsigned long n)
23644 -{
23645 - if (access_ok(VERIFY_WRITE, to, n))
23646 - n = __copy_to_user(to, from, n);
23647 - return n;
23648 -}
23649 -EXPORT_SYMBOL(copy_to_user);
23650 -
23651 -/**
23652 - * copy_from_user: - Copy a block of data from user space.
23653 - * @to: Destination address, in kernel space.
23654 - * @from: Source address, in user space.
23655 - * @n: Number of bytes to copy.
23656 - *
23657 - * Context: User context only. This function may sleep.
23658 - *
23659 - * Copy data from user space to kernel space.
23660 - *
23661 - * Returns number of bytes that could not be copied.
23662 - * On success, this will be zero.
23663 - *
23664 - * If some data could not be copied, this function will pad the copied
23665 - * data to the requested size using zero bytes.
23666 - */
23667 -unsigned long
23668 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23669 -{
23670 - if (access_ok(VERIFY_READ, from, n))
23671 - n = __copy_from_user(to, from, n);
23672 - else
23673 - memset(to, 0, n);
23674 - return n;
23675 -}
23676 -EXPORT_SYMBOL(_copy_from_user);
23677 -
23678 void copy_from_user_overflow(void)
23679 {
23680 WARN(1, "Buffer overflow detected!\n");
23681 }
23682 EXPORT_SYMBOL(copy_from_user_overflow);
23683 +
23684 +void copy_to_user_overflow(void)
23685 +{
23686 + WARN(1, "Buffer overflow detected!\n");
23687 +}
23688 +EXPORT_SYMBOL(copy_to_user_overflow);
23689 +
23690 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23691 +void __set_fs(mm_segment_t x)
23692 +{
23693 + switch (x.seg) {
23694 + case 0:
23695 + loadsegment(gs, 0);
23696 + break;
23697 + case TASK_SIZE_MAX:
23698 + loadsegment(gs, __USER_DS);
23699 + break;
23700 + case -1UL:
23701 + loadsegment(gs, __KERNEL_DS);
23702 + break;
23703 + default:
23704 + BUG();
23705 + }
23706 + return;
23707 +}
23708 +EXPORT_SYMBOL(__set_fs);
23709 +
23710 +void set_fs(mm_segment_t x)
23711 +{
23712 + current_thread_info()->addr_limit = x;
23713 + __set_fs(x);
23714 +}
23715 +EXPORT_SYMBOL(set_fs);
23716 +#endif
23717 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23718 index 05928aa..b33dea1 100644
23719 --- a/arch/x86/lib/usercopy_64.c
23720 +++ b/arch/x86/lib/usercopy_64.c
23721 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23722 _ASM_EXTABLE(0b,3b)
23723 _ASM_EXTABLE(1b,2b)
23724 : [size8] "=&c"(size), [dst] "=&D" (__d0)
23725 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
23726 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
23727 [zero] "r" (0UL), [eight] "r" (8UL));
23728 clac();
23729 return size;
23730 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
23731 }
23732 EXPORT_SYMBOL(clear_user);
23733
23734 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23735 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23736 {
23737 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23738 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23739 - }
23740 - return len;
23741 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
23742 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
23743 + return len;
23744 }
23745 EXPORT_SYMBOL(copy_in_user);
23746
23747 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
23748 * it is not necessary to optimize tail handling.
23749 */
23750 unsigned long
23751 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23752 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23753 {
23754 char c;
23755 unsigned zero_len;
23756 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23757 clac();
23758 return len;
23759 }
23760 +
23761 +void copy_from_user_overflow(void)
23762 +{
23763 + WARN(1, "Buffer overflow detected!\n");
23764 +}
23765 +EXPORT_SYMBOL(copy_from_user_overflow);
23766 +
23767 +void copy_to_user_overflow(void)
23768 +{
23769 + WARN(1, "Buffer overflow detected!\n");
23770 +}
23771 +EXPORT_SYMBOL(copy_to_user_overflow);
23772 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23773 index 903ec1e..c4166b2 100644
23774 --- a/arch/x86/mm/extable.c
23775 +++ b/arch/x86/mm/extable.c
23776 @@ -6,12 +6,24 @@
23777 static inline unsigned long
23778 ex_insn_addr(const struct exception_table_entry *x)
23779 {
23780 - return (unsigned long)&x->insn + x->insn;
23781 + unsigned long reloc = 0;
23782 +
23783 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23784 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23785 +#endif
23786 +
23787 + return (unsigned long)&x->insn + x->insn + reloc;
23788 }
23789 static inline unsigned long
23790 ex_fixup_addr(const struct exception_table_entry *x)
23791 {
23792 - return (unsigned long)&x->fixup + x->fixup;
23793 + unsigned long reloc = 0;
23794 +
23795 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23796 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23797 +#endif
23798 +
23799 + return (unsigned long)&x->fixup + x->fixup + reloc;
23800 }
23801
23802 int fixup_exception(struct pt_regs *regs)
23803 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23804 unsigned long new_ip;
23805
23806 #ifdef CONFIG_PNPBIOS
23807 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23808 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23809 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23810 extern u32 pnp_bios_is_utter_crap;
23811 pnp_bios_is_utter_crap = 1;
23812 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23813 i += 4;
23814 p->fixup -= i;
23815 i += 4;
23816 +
23817 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23818 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23819 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23820 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23821 +#endif
23822 +
23823 }
23824 }
23825
23826 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23827 index 8e13ecb..831f2d0 100644
23828 --- a/arch/x86/mm/fault.c
23829 +++ b/arch/x86/mm/fault.c
23830 @@ -13,12 +13,19 @@
23831 #include <linux/perf_event.h> /* perf_sw_event */
23832 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23833 #include <linux/prefetch.h> /* prefetchw */
23834 +#include <linux/unistd.h>
23835 +#include <linux/compiler.h>
23836
23837 #include <asm/traps.h> /* dotraplinkage, ... */
23838 #include <asm/pgalloc.h> /* pgd_*(), ... */
23839 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23840 #include <asm/fixmap.h> /* VSYSCALL_START */
23841 #include <asm/rcu.h> /* exception_enter(), ... */
23842 +#include <asm/tlbflush.h>
23843 +
23844 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23845 +#include <asm/stacktrace.h>
23846 +#endif
23847
23848 /*
23849 * Page fault error code bits:
23850 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23851 int ret = 0;
23852
23853 /* kprobe_running() needs smp_processor_id() */
23854 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23855 + if (kprobes_built_in() && !user_mode(regs)) {
23856 preempt_disable();
23857 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23858 ret = 1;
23859 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23860 return !instr_lo || (instr_lo>>1) == 1;
23861 case 0x00:
23862 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23863 - if (probe_kernel_address(instr, opcode))
23864 + if (user_mode(regs)) {
23865 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23866 + return 0;
23867 + } else if (probe_kernel_address(instr, opcode))
23868 return 0;
23869
23870 *prefetch = (instr_lo == 0xF) &&
23871 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23872 while (instr < max_instr) {
23873 unsigned char opcode;
23874
23875 - if (probe_kernel_address(instr, opcode))
23876 + if (user_mode(regs)) {
23877 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23878 + break;
23879 + } else if (probe_kernel_address(instr, opcode))
23880 break;
23881
23882 instr++;
23883 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23884 force_sig_info(si_signo, &info, tsk);
23885 }
23886
23887 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23888 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23889 +#endif
23890 +
23891 +#ifdef CONFIG_PAX_EMUTRAMP
23892 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23893 +#endif
23894 +
23895 +#ifdef CONFIG_PAX_PAGEEXEC
23896 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23897 +{
23898 + pgd_t *pgd;
23899 + pud_t *pud;
23900 + pmd_t *pmd;
23901 +
23902 + pgd = pgd_offset(mm, address);
23903 + if (!pgd_present(*pgd))
23904 + return NULL;
23905 + pud = pud_offset(pgd, address);
23906 + if (!pud_present(*pud))
23907 + return NULL;
23908 + pmd = pmd_offset(pud, address);
23909 + if (!pmd_present(*pmd))
23910 + return NULL;
23911 + return pmd;
23912 +}
23913 +#endif
23914 +
23915 DEFINE_SPINLOCK(pgd_lock);
23916 LIST_HEAD(pgd_list);
23917
23918 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
23919 for (address = VMALLOC_START & PMD_MASK;
23920 address >= TASK_SIZE && address < FIXADDR_TOP;
23921 address += PMD_SIZE) {
23922 +
23923 +#ifdef CONFIG_PAX_PER_CPU_PGD
23924 + unsigned long cpu;
23925 +#else
23926 struct page *page;
23927 +#endif
23928
23929 spin_lock(&pgd_lock);
23930 +
23931 +#ifdef CONFIG_PAX_PER_CPU_PGD
23932 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23933 + pgd_t *pgd = get_cpu_pgd(cpu);
23934 + pmd_t *ret;
23935 +#else
23936 list_for_each_entry(page, &pgd_list, lru) {
23937 + pgd_t *pgd = page_address(page);
23938 spinlock_t *pgt_lock;
23939 pmd_t *ret;
23940
23941 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
23942 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23943
23944 spin_lock(pgt_lock);
23945 - ret = vmalloc_sync_one(page_address(page), address);
23946 +#endif
23947 +
23948 + ret = vmalloc_sync_one(pgd, address);
23949 +
23950 +#ifndef CONFIG_PAX_PER_CPU_PGD
23951 spin_unlock(pgt_lock);
23952 +#endif
23953
23954 if (!ret)
23955 break;
23956 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23957 * an interrupt in the middle of a task switch..
23958 */
23959 pgd_paddr = read_cr3();
23960 +
23961 +#ifdef CONFIG_PAX_PER_CPU_PGD
23962 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23963 +#endif
23964 +
23965 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23966 if (!pmd_k)
23967 return -1;
23968 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23969 * happen within a race in page table update. In the later
23970 * case just flush:
23971 */
23972 +
23973 +#ifdef CONFIG_PAX_PER_CPU_PGD
23974 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23975 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23976 +#else
23977 pgd = pgd_offset(current->active_mm, address);
23978 +#endif
23979 +
23980 pgd_ref = pgd_offset_k(address);
23981 if (pgd_none(*pgd_ref))
23982 return -1;
23983 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23984 static int is_errata100(struct pt_regs *regs, unsigned long address)
23985 {
23986 #ifdef CONFIG_X86_64
23987 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23988 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23989 return 1;
23990 #endif
23991 return 0;
23992 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23993 }
23994
23995 static const char nx_warning[] = KERN_CRIT
23996 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23997 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23998
23999 static void
24000 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
24001 @@ -577,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
24002 if (!oops_may_print())
24003 return;
24004
24005 - if (error_code & PF_INSTR) {
24006 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
24007 unsigned int level;
24008
24009 pte_t *pte = lookup_address(address, &level);
24010
24011 if (pte && pte_present(*pte) && !pte_exec(*pte))
24012 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
24013 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
24014 }
24015
24016 +#ifdef CONFIG_PAX_KERNEXEC
24017 + if (init_mm.start_code <= address && address < init_mm.end_code) {
24018 + if (current->signal->curr_ip)
24019 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24020 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
24021 + else
24022 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24023 + current->comm, task_pid_nr(current), current_uid(), current_euid());
24024 + }
24025 +#endif
24026 +
24027 printk(KERN_ALERT "BUG: unable to handle kernel ");
24028 if (address < PAGE_SIZE)
24029 printk(KERN_CONT "NULL pointer dereference");
24030 @@ -749,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
24031 }
24032 #endif
24033
24034 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24035 + if (pax_is_fetch_fault(regs, error_code, address)) {
24036 +
24037 +#ifdef CONFIG_PAX_EMUTRAMP
24038 + switch (pax_handle_fetch_fault(regs)) {
24039 + case 2:
24040 + return;
24041 + }
24042 +#endif
24043 +
24044 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24045 + do_group_exit(SIGKILL);
24046 + }
24047 +#endif
24048 +
24049 if (unlikely(show_unhandled_signals))
24050 show_signal_msg(regs, error_code, address, tsk);
24051
24052 @@ -845,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
24053 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
24054 printk(KERN_ERR
24055 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
24056 - tsk->comm, tsk->pid, address);
24057 + tsk->comm, task_pid_nr(tsk), address);
24058 code = BUS_MCEERR_AR;
24059 }
24060 #endif
24061 @@ -901,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24062 return 1;
24063 }
24064
24065 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24066 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24067 +{
24068 + pte_t *pte;
24069 + pmd_t *pmd;
24070 + spinlock_t *ptl;
24071 + unsigned char pte_mask;
24072 +
24073 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24074 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
24075 + return 0;
24076 +
24077 + /* PaX: it's our fault, let's handle it if we can */
24078 +
24079 + /* PaX: take a look at read faults before acquiring any locks */
24080 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24081 + /* instruction fetch attempt from a protected page in user mode */
24082 + up_read(&mm->mmap_sem);
24083 +
24084 +#ifdef CONFIG_PAX_EMUTRAMP
24085 + switch (pax_handle_fetch_fault(regs)) {
24086 + case 2:
24087 + return 1;
24088 + }
24089 +#endif
24090 +
24091 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24092 + do_group_exit(SIGKILL);
24093 + }
24094 +
24095 + pmd = pax_get_pmd(mm, address);
24096 + if (unlikely(!pmd))
24097 + return 0;
24098 +
24099 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24100 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24101 + pte_unmap_unlock(pte, ptl);
24102 + return 0;
24103 + }
24104 +
24105 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24106 + /* write attempt to a protected page in user mode */
24107 + pte_unmap_unlock(pte, ptl);
24108 + return 0;
24109 + }
24110 +
24111 +#ifdef CONFIG_SMP
24112 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24113 +#else
24114 + if (likely(address > get_limit(regs->cs)))
24115 +#endif
24116 + {
24117 + set_pte(pte, pte_mkread(*pte));
24118 + __flush_tlb_one(address);
24119 + pte_unmap_unlock(pte, ptl);
24120 + up_read(&mm->mmap_sem);
24121 + return 1;
24122 + }
24123 +
24124 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24125 +
24126 + /*
24127 + * PaX: fill DTLB with user rights and retry
24128 + */
24129 + __asm__ __volatile__ (
24130 + "orb %2,(%1)\n"
24131 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24132 +/*
24133 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24134 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24135 + * page fault when examined during a TLB load attempt. this is true not only
24136 + * for PTEs holding a non-present entry but also present entries that will
24137 + * raise a page fault (such as those set up by PaX, or the copy-on-write
24138 + * mechanism). in effect it means that we do *not* need to flush the TLBs
24139 + * for our target pages since their PTEs are simply not in the TLBs at all.
24140 +
24141 + * the best thing in omitting it is that we gain around 15-20% speed in the
24142 + * fast path of the page fault handler and can get rid of tracing since we
24143 + * can no longer flush unintended entries.
24144 + */
24145 + "invlpg (%0)\n"
24146 +#endif
24147 + __copyuser_seg"testb $0,(%0)\n"
24148 + "xorb %3,(%1)\n"
24149 + :
24150 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24151 + : "memory", "cc");
24152 + pte_unmap_unlock(pte, ptl);
24153 + up_read(&mm->mmap_sem);
24154 + return 1;
24155 +}
24156 +#endif
24157 +
24158 /*
24159 * Handle a spurious fault caused by a stale TLB entry.
24160 *
24161 @@ -973,6 +1162,9 @@ int show_unhandled_signals = 1;
24162 static inline int
24163 access_error(unsigned long error_code, struct vm_area_struct *vma)
24164 {
24165 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24166 + return 1;
24167 +
24168 if (error_code & PF_WRITE) {
24169 /* write, present and write, not present: */
24170 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24171 @@ -1001,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
24172 if (error_code & PF_USER)
24173 return false;
24174
24175 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
24176 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
24177 return false;
24178
24179 return true;
24180 @@ -1017,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
24181 {
24182 struct vm_area_struct *vma;
24183 struct task_struct *tsk;
24184 - unsigned long address;
24185 struct mm_struct *mm;
24186 int fault;
24187 int write = error_code & PF_WRITE;
24188 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24189 (write ? FAULT_FLAG_WRITE : 0);
24190
24191 - tsk = current;
24192 - mm = tsk->mm;
24193 -
24194 /* Get the faulting address: */
24195 - address = read_cr2();
24196 + unsigned long address = read_cr2();
24197 +
24198 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24199 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24200 + if (!search_exception_tables(regs->ip)) {
24201 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24202 + bad_area_nosemaphore(regs, error_code, address);
24203 + return;
24204 + }
24205 + if (address < PAX_USER_SHADOW_BASE) {
24206 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24207 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24208 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24209 + } else
24210 + address -= PAX_USER_SHADOW_BASE;
24211 + }
24212 +#endif
24213 +
24214 + tsk = current;
24215 + mm = tsk->mm;
24216
24217 /*
24218 * Detect and handle instructions that would cause a page fault for
24219 @@ -1089,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
24220 * User-mode registers count as a user access even for any
24221 * potential system fault or CPU buglet:
24222 */
24223 - if (user_mode_vm(regs)) {
24224 + if (user_mode(regs)) {
24225 local_irq_enable();
24226 error_code |= PF_USER;
24227 } else {
24228 @@ -1151,6 +1358,11 @@ retry:
24229 might_sleep();
24230 }
24231
24232 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24233 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24234 + return;
24235 +#endif
24236 +
24237 vma = find_vma(mm, address);
24238 if (unlikely(!vma)) {
24239 bad_area(regs, error_code, address);
24240 @@ -1162,18 +1374,24 @@ retry:
24241 bad_area(regs, error_code, address);
24242 return;
24243 }
24244 - if (error_code & PF_USER) {
24245 - /*
24246 - * Accessing the stack below %sp is always a bug.
24247 - * The large cushion allows instructions like enter
24248 - * and pusha to work. ("enter $65535, $31" pushes
24249 - * 32 pointers and then decrements %sp by 65535.)
24250 - */
24251 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24252 - bad_area(regs, error_code, address);
24253 - return;
24254 - }
24255 + /*
24256 + * Accessing the stack below %sp is always a bug.
24257 + * The large cushion allows instructions like enter
24258 + * and pusha to work. ("enter $65535, $31" pushes
24259 + * 32 pointers and then decrements %sp by 65535.)
24260 + */
24261 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24262 + bad_area(regs, error_code, address);
24263 + return;
24264 }
24265 +
24266 +#ifdef CONFIG_PAX_SEGMEXEC
24267 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24268 + bad_area(regs, error_code, address);
24269 + return;
24270 + }
24271 +#endif
24272 +
24273 if (unlikely(expand_stack(vma, address))) {
24274 bad_area(regs, error_code, address);
24275 return;
24276 @@ -1237,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24277 __do_page_fault(regs, error_code);
24278 exception_exit(regs);
24279 }
24280 +
24281 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24282 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24283 +{
24284 + struct mm_struct *mm = current->mm;
24285 + unsigned long ip = regs->ip;
24286 +
24287 + if (v8086_mode(regs))
24288 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24289 +
24290 +#ifdef CONFIG_PAX_PAGEEXEC
24291 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24292 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24293 + return true;
24294 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24295 + return true;
24296 + return false;
24297 + }
24298 +#endif
24299 +
24300 +#ifdef CONFIG_PAX_SEGMEXEC
24301 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24302 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24303 + return true;
24304 + return false;
24305 + }
24306 +#endif
24307 +
24308 + return false;
24309 +}
24310 +#endif
24311 +
24312 +#ifdef CONFIG_PAX_EMUTRAMP
24313 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24314 +{
24315 + int err;
24316 +
24317 + do { /* PaX: libffi trampoline emulation */
24318 + unsigned char mov, jmp;
24319 + unsigned int addr1, addr2;
24320 +
24321 +#ifdef CONFIG_X86_64
24322 + if ((regs->ip + 9) >> 32)
24323 + break;
24324 +#endif
24325 +
24326 + err = get_user(mov, (unsigned char __user *)regs->ip);
24327 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24328 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24329 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24330 +
24331 + if (err)
24332 + break;
24333 +
24334 + if (mov == 0xB8 && jmp == 0xE9) {
24335 + regs->ax = addr1;
24336 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24337 + return 2;
24338 + }
24339 + } while (0);
24340 +
24341 + do { /* PaX: gcc trampoline emulation #1 */
24342 + unsigned char mov1, mov2;
24343 + unsigned short jmp;
24344 + unsigned int addr1, addr2;
24345 +
24346 +#ifdef CONFIG_X86_64
24347 + if ((regs->ip + 11) >> 32)
24348 + break;
24349 +#endif
24350 +
24351 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24352 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24353 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24354 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24355 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24356 +
24357 + if (err)
24358 + break;
24359 +
24360 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24361 + regs->cx = addr1;
24362 + regs->ax = addr2;
24363 + regs->ip = addr2;
24364 + return 2;
24365 + }
24366 + } while (0);
24367 +
24368 + do { /* PaX: gcc trampoline emulation #2 */
24369 + unsigned char mov, jmp;
24370 + unsigned int addr1, addr2;
24371 +
24372 +#ifdef CONFIG_X86_64
24373 + if ((regs->ip + 9) >> 32)
24374 + break;
24375 +#endif
24376 +
24377 + err = get_user(mov, (unsigned char __user *)regs->ip);
24378 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24379 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24380 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24381 +
24382 + if (err)
24383 + break;
24384 +
24385 + if (mov == 0xB9 && jmp == 0xE9) {
24386 + regs->cx = addr1;
24387 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24388 + return 2;
24389 + }
24390 + } while (0);
24391 +
24392 + return 1; /* PaX in action */
24393 +}
24394 +
24395 +#ifdef CONFIG_X86_64
24396 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24397 +{
24398 + int err;
24399 +
24400 + do { /* PaX: libffi trampoline emulation */
24401 + unsigned short mov1, mov2, jmp1;
24402 + unsigned char stcclc, jmp2;
24403 + unsigned long addr1, addr2;
24404 +
24405 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24406 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24407 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24408 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24409 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24410 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24411 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24412 +
24413 + if (err)
24414 + break;
24415 +
24416 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24417 + regs->r11 = addr1;
24418 + regs->r10 = addr2;
24419 + if (stcclc == 0xF8)
24420 + regs->flags &= ~X86_EFLAGS_CF;
24421 + else
24422 + regs->flags |= X86_EFLAGS_CF;
24423 + regs->ip = addr1;
24424 + return 2;
24425 + }
24426 + } while (0);
24427 +
24428 + do { /* PaX: gcc trampoline emulation #1 */
24429 + unsigned short mov1, mov2, jmp1;
24430 + unsigned char jmp2;
24431 + unsigned int addr1;
24432 + unsigned long addr2;
24433 +
24434 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24435 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24436 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24437 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24438 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24439 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24440 +
24441 + if (err)
24442 + break;
24443 +
24444 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24445 + regs->r11 = addr1;
24446 + regs->r10 = addr2;
24447 + regs->ip = addr1;
24448 + return 2;
24449 + }
24450 + } while (0);
24451 +
24452 + do { /* PaX: gcc trampoline emulation #2 */
24453 + unsigned short mov1, mov2, jmp1;
24454 + unsigned char jmp2;
24455 + unsigned long addr1, addr2;
24456 +
24457 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24458 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24459 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24460 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24461 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24462 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24463 +
24464 + if (err)
24465 + break;
24466 +
24467 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24468 + regs->r11 = addr1;
24469 + regs->r10 = addr2;
24470 + regs->ip = addr1;
24471 + return 2;
24472 + }
24473 + } while (0);
24474 +
24475 + return 1; /* PaX in action */
24476 +}
24477 +#endif
24478 +
24479 +/*
24480 + * PaX: decide what to do with offenders (regs->ip = fault address)
24481 + *
24482 + * returns 1 when task should be killed
24483 + * 2 when gcc trampoline was detected
24484 + */
24485 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24486 +{
24487 + if (v8086_mode(regs))
24488 + return 1;
24489 +
24490 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24491 + return 1;
24492 +
24493 +#ifdef CONFIG_X86_32
24494 + return pax_handle_fetch_fault_32(regs);
24495 +#else
24496 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24497 + return pax_handle_fetch_fault_32(regs);
24498 + else
24499 + return pax_handle_fetch_fault_64(regs);
24500 +#endif
24501 +}
24502 +#endif
24503 +
24504 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24505 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24506 +{
24507 + long i;
24508 +
24509 + printk(KERN_ERR "PAX: bytes at PC: ");
24510 + for (i = 0; i < 20; i++) {
24511 + unsigned char c;
24512 + if (get_user(c, (unsigned char __force_user *)pc+i))
24513 + printk(KERN_CONT "?? ");
24514 + else
24515 + printk(KERN_CONT "%02x ", c);
24516 + }
24517 + printk("\n");
24518 +
24519 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24520 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24521 + unsigned long c;
24522 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24523 +#ifdef CONFIG_X86_32
24524 + printk(KERN_CONT "???????? ");
24525 +#else
24526 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24527 + printk(KERN_CONT "???????? ???????? ");
24528 + else
24529 + printk(KERN_CONT "???????????????? ");
24530 +#endif
24531 + } else {
24532 +#ifdef CONFIG_X86_64
24533 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24534 + printk(KERN_CONT "%08x ", (unsigned int)c);
24535 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24536 + } else
24537 +#endif
24538 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24539 + }
24540 + }
24541 + printk("\n");
24542 +}
24543 +#endif
24544 +
24545 +/**
24546 + * probe_kernel_write(): safely attempt to write to a location
24547 + * @dst: address to write to
24548 + * @src: pointer to the data that shall be written
24549 + * @size: size of the data chunk
24550 + *
24551 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24552 + * happens, handle that and return -EFAULT.
24553 + */
24554 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24555 +{
24556 + long ret;
24557 + mm_segment_t old_fs = get_fs();
24558 +
24559 + set_fs(KERNEL_DS);
24560 + pagefault_disable();
24561 + pax_open_kernel();
24562 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24563 + pax_close_kernel();
24564 + pagefault_enable();
24565 + set_fs(old_fs);
24566 +
24567 + return ret ? -EFAULT : 0;
24568 +}
24569 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24570 index dd74e46..7d26398 100644
24571 --- a/arch/x86/mm/gup.c
24572 +++ b/arch/x86/mm/gup.c
24573 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24574 addr = start;
24575 len = (unsigned long) nr_pages << PAGE_SHIFT;
24576 end = start + len;
24577 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24578 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24579 (void __user *)start, len)))
24580 return 0;
24581
24582 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24583 index 6f31ee5..8ee4164 100644
24584 --- a/arch/x86/mm/highmem_32.c
24585 +++ b/arch/x86/mm/highmem_32.c
24586 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24587 idx = type + KM_TYPE_NR*smp_processor_id();
24588 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24589 BUG_ON(!pte_none(*(kmap_pte-idx)));
24590 +
24591 + pax_open_kernel();
24592 set_pte(kmap_pte-idx, mk_pte(page, prot));
24593 + pax_close_kernel();
24594 +
24595 arch_flush_lazy_mmu_mode();
24596
24597 return (void *)vaddr;
24598 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24599 index 937bff5..d777418 100644
24600 --- a/arch/x86/mm/hugetlbpage.c
24601 +++ b/arch/x86/mm/hugetlbpage.c
24602 @@ -276,13 +276,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24603 struct hstate *h = hstate_file(file);
24604 struct mm_struct *mm = current->mm;
24605 struct vm_area_struct *vma;
24606 - unsigned long start_addr;
24607 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24608 +
24609 +#ifdef CONFIG_PAX_SEGMEXEC
24610 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24611 + pax_task_size = SEGMEXEC_TASK_SIZE;
24612 +#endif
24613 +
24614 + pax_task_size -= PAGE_SIZE;
24615
24616 if (len > mm->cached_hole_size) {
24617 - start_addr = mm->free_area_cache;
24618 + start_addr = mm->free_area_cache;
24619 } else {
24620 - start_addr = TASK_UNMAPPED_BASE;
24621 - mm->cached_hole_size = 0;
24622 + start_addr = mm->mmap_base;
24623 + mm->cached_hole_size = 0;
24624 }
24625
24626 full_search:
24627 @@ -290,26 +297,27 @@ full_search:
24628
24629 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24630 /* At this point: (!vma || addr < vma->vm_end). */
24631 - if (TASK_SIZE - len < addr) {
24632 + if (pax_task_size - len < addr) {
24633 /*
24634 * Start a new search - just in case we missed
24635 * some holes.
24636 */
24637 - if (start_addr != TASK_UNMAPPED_BASE) {
24638 - start_addr = TASK_UNMAPPED_BASE;
24639 + if (start_addr != mm->mmap_base) {
24640 + start_addr = mm->mmap_base;
24641 mm->cached_hole_size = 0;
24642 goto full_search;
24643 }
24644 return -ENOMEM;
24645 }
24646 - if (!vma || addr + len <= vma->vm_start) {
24647 - mm->free_area_cache = addr + len;
24648 - return addr;
24649 - }
24650 + if (check_heap_stack_gap(vma, addr, len))
24651 + break;
24652 if (addr + mm->cached_hole_size < vma->vm_start)
24653 mm->cached_hole_size = vma->vm_start - addr;
24654 addr = ALIGN(vma->vm_end, huge_page_size(h));
24655 }
24656 +
24657 + mm->free_area_cache = addr + len;
24658 + return addr;
24659 }
24660
24661 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24662 @@ -320,9 +328,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24663 struct mm_struct *mm = current->mm;
24664 struct vm_area_struct *vma;
24665 unsigned long base = mm->mmap_base;
24666 - unsigned long addr = addr0;
24667 + unsigned long addr;
24668 unsigned long largest_hole = mm->cached_hole_size;
24669 - unsigned long start_addr;
24670
24671 /* don't allow allocations above current base */
24672 if (mm->free_area_cache > base)
24673 @@ -332,16 +339,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24674 largest_hole = 0;
24675 mm->free_area_cache = base;
24676 }
24677 -try_again:
24678 - start_addr = mm->free_area_cache;
24679
24680 /* make sure it can fit in the remaining address space */
24681 if (mm->free_area_cache < len)
24682 goto fail;
24683
24684 /* either no address requested or can't fit in requested address hole */
24685 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24686 + addr = mm->free_area_cache - len;
24687 do {
24688 + addr &= huge_page_mask(h);
24689 /*
24690 * Lookup failure means no vma is above this address,
24691 * i.e. return with success:
24692 @@ -350,10 +356,10 @@ try_again:
24693 if (!vma)
24694 return addr;
24695
24696 - if (addr + len <= vma->vm_start) {
24697 + if (check_heap_stack_gap(vma, addr, len)) {
24698 /* remember the address as a hint for next time */
24699 - mm->cached_hole_size = largest_hole;
24700 - return (mm->free_area_cache = addr);
24701 + mm->cached_hole_size = largest_hole;
24702 + return (mm->free_area_cache = addr);
24703 } else if (mm->free_area_cache == vma->vm_end) {
24704 /* pull free_area_cache down to the first hole */
24705 mm->free_area_cache = vma->vm_start;
24706 @@ -362,29 +368,34 @@ try_again:
24707
24708 /* remember the largest hole we saw so far */
24709 if (addr + largest_hole < vma->vm_start)
24710 - largest_hole = vma->vm_start - addr;
24711 + largest_hole = vma->vm_start - addr;
24712
24713 /* try just below the current vma->vm_start */
24714 - addr = (vma->vm_start - len) & huge_page_mask(h);
24715 - } while (len <= vma->vm_start);
24716 + addr = skip_heap_stack_gap(vma, len);
24717 + } while (!IS_ERR_VALUE(addr));
24718
24719 fail:
24720 /*
24721 - * if hint left us with no space for the requested
24722 - * mapping then try again:
24723 - */
24724 - if (start_addr != base) {
24725 - mm->free_area_cache = base;
24726 - largest_hole = 0;
24727 - goto try_again;
24728 - }
24729 - /*
24730 * A failed mmap() very likely causes application failure,
24731 * so fall back to the bottom-up function here. This scenario
24732 * can happen with large stack limits and large mmap()
24733 * allocations.
24734 */
24735 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24736 +
24737 +#ifdef CONFIG_PAX_SEGMEXEC
24738 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24739 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24740 + else
24741 +#endif
24742 +
24743 + mm->mmap_base = TASK_UNMAPPED_BASE;
24744 +
24745 +#ifdef CONFIG_PAX_RANDMMAP
24746 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24747 + mm->mmap_base += mm->delta_mmap;
24748 +#endif
24749 +
24750 + mm->free_area_cache = mm->mmap_base;
24751 mm->cached_hole_size = ~0UL;
24752 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24753 len, pgoff, flags);
24754 @@ -392,6 +403,7 @@ fail:
24755 /*
24756 * Restore the topdown base:
24757 */
24758 + mm->mmap_base = base;
24759 mm->free_area_cache = base;
24760 mm->cached_hole_size = ~0UL;
24761
24762 @@ -405,10 +417,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24763 struct hstate *h = hstate_file(file);
24764 struct mm_struct *mm = current->mm;
24765 struct vm_area_struct *vma;
24766 + unsigned long pax_task_size = TASK_SIZE;
24767
24768 if (len & ~huge_page_mask(h))
24769 return -EINVAL;
24770 - if (len > TASK_SIZE)
24771 +
24772 +#ifdef CONFIG_PAX_SEGMEXEC
24773 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24774 + pax_task_size = SEGMEXEC_TASK_SIZE;
24775 +#endif
24776 +
24777 + pax_task_size -= PAGE_SIZE;
24778 +
24779 + if (len > pax_task_size)
24780 return -ENOMEM;
24781
24782 if (flags & MAP_FIXED) {
24783 @@ -420,8 +441,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24784 if (addr) {
24785 addr = ALIGN(addr, huge_page_size(h));
24786 vma = find_vma(mm, addr);
24787 - if (TASK_SIZE - len >= addr &&
24788 - (!vma || addr + len <= vma->vm_start))
24789 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24790 return addr;
24791 }
24792 if (mm->get_unmapped_area == arch_get_unmapped_area)
24793 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24794 index d7aea41..0fc945b 100644
24795 --- a/arch/x86/mm/init.c
24796 +++ b/arch/x86/mm/init.c
24797 @@ -4,6 +4,7 @@
24798 #include <linux/swap.h>
24799 #include <linux/memblock.h>
24800 #include <linux/bootmem.h> /* for max_low_pfn */
24801 +#include <linux/tboot.h>
24802
24803 #include <asm/cacheflush.h>
24804 #include <asm/e820.h>
24805 @@ -16,6 +17,8 @@
24806 #include <asm/tlb.h>
24807 #include <asm/proto.h>
24808 #include <asm/dma.h> /* for MAX_DMA_PFN */
24809 +#include <asm/desc.h>
24810 +#include <asm/bios_ebda.h>
24811
24812 unsigned long __initdata pgt_buf_start;
24813 unsigned long __meminitdata pgt_buf_end;
24814 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24815 {
24816 int i;
24817 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24818 - unsigned long start = 0, good_end;
24819 + unsigned long start = 0x100000, good_end;
24820 phys_addr_t base;
24821
24822 for (i = 0; i < nr_range; i++) {
24823 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24824 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24825 * mmio resources as well as potential bios/acpi data regions.
24826 */
24827 +
24828 +#ifdef CONFIG_GRKERNSEC_KMEM
24829 +static unsigned int ebda_start __read_only;
24830 +static unsigned int ebda_end __read_only;
24831 +#endif
24832 +
24833 int devmem_is_allowed(unsigned long pagenr)
24834 {
24835 - if (pagenr < 256)
24836 +#ifdef CONFIG_GRKERNSEC_KMEM
24837 + /* allow BDA */
24838 + if (!pagenr)
24839 return 1;
24840 + /* allow EBDA */
24841 + if (pagenr >= ebda_start && pagenr < ebda_end)
24842 + return 1;
24843 + /* if tboot is in use, allow access to its hardcoded serial log range */
24844 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24845 + return 1;
24846 +#else
24847 + if (!pagenr)
24848 + return 1;
24849 +#ifdef CONFIG_VM86
24850 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24851 + return 1;
24852 +#endif
24853 +#endif
24854 +
24855 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24856 + return 1;
24857 +#ifdef CONFIG_GRKERNSEC_KMEM
24858 + /* throw out everything else below 1MB */
24859 + if (pagenr <= 256)
24860 + return 0;
24861 +#endif
24862 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24863 return 0;
24864 if (!page_is_ram(pagenr))
24865 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24866 #endif
24867 }
24868
24869 +#ifdef CONFIG_GRKERNSEC_KMEM
24870 +static inline void gr_init_ebda(void)
24871 +{
24872 + unsigned int ebda_addr;
24873 + unsigned int ebda_size = 0;
24874 +
24875 + ebda_addr = get_bios_ebda();
24876 + if (ebda_addr) {
24877 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24878 + ebda_size <<= 10;
24879 + }
24880 + if (ebda_addr && ebda_size) {
24881 + ebda_start = ebda_addr >> PAGE_SHIFT;
24882 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24883 + } else {
24884 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24885 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24886 + }
24887 +}
24888 +#else
24889 +static inline void gr_init_ebda(void) { }
24890 +#endif
24891 +
24892 void free_initmem(void)
24893 {
24894 +#ifdef CONFIG_PAX_KERNEXEC
24895 +#ifdef CONFIG_X86_32
24896 + /* PaX: limit KERNEL_CS to actual size */
24897 + unsigned long addr, limit;
24898 + struct desc_struct d;
24899 + int cpu;
24900 +#else
24901 + pgd_t *pgd;
24902 + pud_t *pud;
24903 + pmd_t *pmd;
24904 + unsigned long addr, end;
24905 +#endif
24906 +#endif
24907 +
24908 + gr_init_ebda();
24909 +
24910 +#ifdef CONFIG_PAX_KERNEXEC
24911 +#ifdef CONFIG_X86_32
24912 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24913 + limit = (limit - 1UL) >> PAGE_SHIFT;
24914 +
24915 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24916 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24917 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24918 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24919 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24920 + }
24921 +
24922 + /* PaX: make KERNEL_CS read-only */
24923 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24924 + if (!paravirt_enabled())
24925 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24926 +/*
24927 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24928 + pgd = pgd_offset_k(addr);
24929 + pud = pud_offset(pgd, addr);
24930 + pmd = pmd_offset(pud, addr);
24931 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24932 + }
24933 +*/
24934 +#ifdef CONFIG_X86_PAE
24935 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24936 +/*
24937 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24938 + pgd = pgd_offset_k(addr);
24939 + pud = pud_offset(pgd, addr);
24940 + pmd = pmd_offset(pud, addr);
24941 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24942 + }
24943 +*/
24944 +#endif
24945 +
24946 +#ifdef CONFIG_MODULES
24947 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24948 +#endif
24949 +
24950 +#else
24951 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24952 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24953 + pgd = pgd_offset_k(addr);
24954 + pud = pud_offset(pgd, addr);
24955 + pmd = pmd_offset(pud, addr);
24956 + if (!pmd_present(*pmd))
24957 + continue;
24958 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24959 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24960 + else
24961 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24962 + }
24963 +
24964 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24965 + end = addr + KERNEL_IMAGE_SIZE;
24966 + for (; addr < end; addr += PMD_SIZE) {
24967 + pgd = pgd_offset_k(addr);
24968 + pud = pud_offset(pgd, addr);
24969 + pmd = pmd_offset(pud, addr);
24970 + if (!pmd_present(*pmd))
24971 + continue;
24972 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24973 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24974 + }
24975 +#endif
24976 +
24977 + flush_tlb_all();
24978 +#endif
24979 +
24980 free_init_pages("unused kernel memory",
24981 (unsigned long)(&__init_begin),
24982 (unsigned long)(&__init_end));
24983 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24984 index 11a5800..4bd9977 100644
24985 --- a/arch/x86/mm/init_32.c
24986 +++ b/arch/x86/mm/init_32.c
24987 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24988 }
24989
24990 /*
24991 - * Creates a middle page table and puts a pointer to it in the
24992 - * given global directory entry. This only returns the gd entry
24993 - * in non-PAE compilation mode, since the middle layer is folded.
24994 - */
24995 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24996 -{
24997 - pud_t *pud;
24998 - pmd_t *pmd_table;
24999 -
25000 -#ifdef CONFIG_X86_PAE
25001 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
25002 - if (after_bootmem)
25003 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
25004 - else
25005 - pmd_table = (pmd_t *)alloc_low_page();
25006 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
25007 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
25008 - pud = pud_offset(pgd, 0);
25009 - BUG_ON(pmd_table != pmd_offset(pud, 0));
25010 -
25011 - return pmd_table;
25012 - }
25013 -#endif
25014 - pud = pud_offset(pgd, 0);
25015 - pmd_table = pmd_offset(pud, 0);
25016 -
25017 - return pmd_table;
25018 -}
25019 -
25020 -/*
25021 * Create a page table and place a pointer to it in a middle page
25022 * directory entry:
25023 */
25024 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
25025 page_table = (pte_t *)alloc_low_page();
25026
25027 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
25028 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25029 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
25030 +#else
25031 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
25032 +#endif
25033 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
25034 }
25035
25036 return pte_offset_kernel(pmd, 0);
25037 }
25038
25039 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
25040 +{
25041 + pud_t *pud;
25042 + pmd_t *pmd_table;
25043 +
25044 + pud = pud_offset(pgd, 0);
25045 + pmd_table = pmd_offset(pud, 0);
25046 +
25047 + return pmd_table;
25048 +}
25049 +
25050 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
25051 {
25052 int pgd_idx = pgd_index(vaddr);
25053 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25054 int pgd_idx, pmd_idx;
25055 unsigned long vaddr;
25056 pgd_t *pgd;
25057 + pud_t *pud;
25058 pmd_t *pmd;
25059 pte_t *pte = NULL;
25060
25061 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25062 pgd = pgd_base + pgd_idx;
25063
25064 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
25065 - pmd = one_md_table_init(pgd);
25066 - pmd = pmd + pmd_index(vaddr);
25067 + pud = pud_offset(pgd, vaddr);
25068 + pmd = pmd_offset(pud, vaddr);
25069 +
25070 +#ifdef CONFIG_X86_PAE
25071 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25072 +#endif
25073 +
25074 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
25075 pmd++, pmd_idx++) {
25076 pte = page_table_kmap_check(one_page_table_init(pmd),
25077 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25078 }
25079 }
25080
25081 -static inline int is_kernel_text(unsigned long addr)
25082 +static inline int is_kernel_text(unsigned long start, unsigned long end)
25083 {
25084 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
25085 - return 1;
25086 - return 0;
25087 + if ((start > ktla_ktva((unsigned long)_etext) ||
25088 + end <= ktla_ktva((unsigned long)_stext)) &&
25089 + (start > ktla_ktva((unsigned long)_einittext) ||
25090 + end <= ktla_ktva((unsigned long)_sinittext)) &&
25091 +
25092 +#ifdef CONFIG_ACPI_SLEEP
25093 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
25094 +#endif
25095 +
25096 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
25097 + return 0;
25098 + return 1;
25099 }
25100
25101 /*
25102 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
25103 unsigned long last_map_addr = end;
25104 unsigned long start_pfn, end_pfn;
25105 pgd_t *pgd_base = swapper_pg_dir;
25106 - int pgd_idx, pmd_idx, pte_ofs;
25107 + unsigned int pgd_idx, pmd_idx, pte_ofs;
25108 unsigned long pfn;
25109 pgd_t *pgd;
25110 + pud_t *pud;
25111 pmd_t *pmd;
25112 pte_t *pte;
25113 unsigned pages_2m, pages_4k;
25114 @@ -280,8 +281,13 @@ repeat:
25115 pfn = start_pfn;
25116 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25117 pgd = pgd_base + pgd_idx;
25118 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25119 - pmd = one_md_table_init(pgd);
25120 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25121 + pud = pud_offset(pgd, 0);
25122 + pmd = pmd_offset(pud, 0);
25123 +
25124 +#ifdef CONFIG_X86_PAE
25125 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25126 +#endif
25127
25128 if (pfn >= end_pfn)
25129 continue;
25130 @@ -293,14 +299,13 @@ repeat:
25131 #endif
25132 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25133 pmd++, pmd_idx++) {
25134 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25135 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25136
25137 /*
25138 * Map with big pages if possible, otherwise
25139 * create normal page tables:
25140 */
25141 if (use_pse) {
25142 - unsigned int addr2;
25143 pgprot_t prot = PAGE_KERNEL_LARGE;
25144 /*
25145 * first pass will use the same initial
25146 @@ -310,11 +315,7 @@ repeat:
25147 __pgprot(PTE_IDENT_ATTR |
25148 _PAGE_PSE);
25149
25150 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25151 - PAGE_OFFSET + PAGE_SIZE-1;
25152 -
25153 - if (is_kernel_text(addr) ||
25154 - is_kernel_text(addr2))
25155 + if (is_kernel_text(address, address + PMD_SIZE))
25156 prot = PAGE_KERNEL_LARGE_EXEC;
25157
25158 pages_2m++;
25159 @@ -331,7 +332,7 @@ repeat:
25160 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25161 pte += pte_ofs;
25162 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25163 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25164 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25165 pgprot_t prot = PAGE_KERNEL;
25166 /*
25167 * first pass will use the same initial
25168 @@ -339,7 +340,7 @@ repeat:
25169 */
25170 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25171
25172 - if (is_kernel_text(addr))
25173 + if (is_kernel_text(address, address + PAGE_SIZE))
25174 prot = PAGE_KERNEL_EXEC;
25175
25176 pages_4k++;
25177 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
25178
25179 pud = pud_offset(pgd, va);
25180 pmd = pmd_offset(pud, va);
25181 - if (!pmd_present(*pmd))
25182 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25183 break;
25184
25185 pte = pte_offset_kernel(pmd, va);
25186 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
25187
25188 static void __init pagetable_init(void)
25189 {
25190 - pgd_t *pgd_base = swapper_pg_dir;
25191 -
25192 - permanent_kmaps_init(pgd_base);
25193 + permanent_kmaps_init(swapper_pg_dir);
25194 }
25195
25196 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25197 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25198 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25199
25200 /* user-defined highmem size */
25201 @@ -731,6 +730,12 @@ void __init mem_init(void)
25202
25203 pci_iommu_alloc();
25204
25205 +#ifdef CONFIG_PAX_PER_CPU_PGD
25206 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25207 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25208 + KERNEL_PGD_PTRS);
25209 +#endif
25210 +
25211 #ifdef CONFIG_FLATMEM
25212 BUG_ON(!mem_map);
25213 #endif
25214 @@ -757,7 +762,7 @@ void __init mem_init(void)
25215 reservedpages++;
25216
25217 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25218 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25219 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25220 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25221
25222 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25223 @@ -798,10 +803,10 @@ void __init mem_init(void)
25224 ((unsigned long)&__init_end -
25225 (unsigned long)&__init_begin) >> 10,
25226
25227 - (unsigned long)&_etext, (unsigned long)&_edata,
25228 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25229 + (unsigned long)&_sdata, (unsigned long)&_edata,
25230 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25231
25232 - (unsigned long)&_text, (unsigned long)&_etext,
25233 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25234 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25235
25236 /*
25237 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
25238 if (!kernel_set_to_readonly)
25239 return;
25240
25241 + start = ktla_ktva(start);
25242 pr_debug("Set kernel text: %lx - %lx for read write\n",
25243 start, start+size);
25244
25245 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
25246 if (!kernel_set_to_readonly)
25247 return;
25248
25249 + start = ktla_ktva(start);
25250 pr_debug("Set kernel text: %lx - %lx for read only\n",
25251 start, start+size);
25252
25253 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
25254 unsigned long start = PFN_ALIGN(_text);
25255 unsigned long size = PFN_ALIGN(_etext) - start;
25256
25257 + start = ktla_ktva(start);
25258 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25259 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25260 size >> 10);
25261 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25262 index 3baff25..8b37564 100644
25263 --- a/arch/x86/mm/init_64.c
25264 +++ b/arch/x86/mm/init_64.c
25265 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25266 * around without checking the pgd every time.
25267 */
25268
25269 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25270 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25271 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25272
25273 int force_personality32;
25274 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25275
25276 for (address = start; address <= end; address += PGDIR_SIZE) {
25277 const pgd_t *pgd_ref = pgd_offset_k(address);
25278 +
25279 +#ifdef CONFIG_PAX_PER_CPU_PGD
25280 + unsigned long cpu;
25281 +#else
25282 struct page *page;
25283 +#endif
25284
25285 if (pgd_none(*pgd_ref))
25286 continue;
25287
25288 spin_lock(&pgd_lock);
25289 +
25290 +#ifdef CONFIG_PAX_PER_CPU_PGD
25291 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25292 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25293 +#else
25294 list_for_each_entry(page, &pgd_list, lru) {
25295 pgd_t *pgd;
25296 spinlock_t *pgt_lock;
25297 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25298 /* the pgt_lock only for Xen */
25299 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25300 spin_lock(pgt_lock);
25301 +#endif
25302
25303 if (pgd_none(*pgd))
25304 set_pgd(pgd, *pgd_ref);
25305 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25306 BUG_ON(pgd_page_vaddr(*pgd)
25307 != pgd_page_vaddr(*pgd_ref));
25308
25309 +#ifndef CONFIG_PAX_PER_CPU_PGD
25310 spin_unlock(pgt_lock);
25311 +#endif
25312 +
25313 }
25314 spin_unlock(&pgd_lock);
25315 }
25316 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25317 {
25318 if (pgd_none(*pgd)) {
25319 pud_t *pud = (pud_t *)spp_getpage();
25320 - pgd_populate(&init_mm, pgd, pud);
25321 + pgd_populate_kernel(&init_mm, pgd, pud);
25322 if (pud != pud_offset(pgd, 0))
25323 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25324 pud, pud_offset(pgd, 0));
25325 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25326 {
25327 if (pud_none(*pud)) {
25328 pmd_t *pmd = (pmd_t *) spp_getpage();
25329 - pud_populate(&init_mm, pud, pmd);
25330 + pud_populate_kernel(&init_mm, pud, pmd);
25331 if (pmd != pmd_offset(pud, 0))
25332 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25333 pmd, pmd_offset(pud, 0));
25334 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25335 pmd = fill_pmd(pud, vaddr);
25336 pte = fill_pte(pmd, vaddr);
25337
25338 + pax_open_kernel();
25339 set_pte(pte, new_pte);
25340 + pax_close_kernel();
25341
25342 /*
25343 * It's enough to flush this one mapping.
25344 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25345 pgd = pgd_offset_k((unsigned long)__va(phys));
25346 if (pgd_none(*pgd)) {
25347 pud = (pud_t *) spp_getpage();
25348 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25349 - _PAGE_USER));
25350 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25351 }
25352 pud = pud_offset(pgd, (unsigned long)__va(phys));
25353 if (pud_none(*pud)) {
25354 pmd = (pmd_t *) spp_getpage();
25355 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25356 - _PAGE_USER));
25357 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25358 }
25359 pmd = pmd_offset(pud, phys);
25360 BUG_ON(!pmd_none(*pmd));
25361 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25362 if (pfn >= pgt_buf_top)
25363 panic("alloc_low_page: ran out of memory");
25364
25365 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25366 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25367 clear_page(adr);
25368 *phys = pfn * PAGE_SIZE;
25369 return adr;
25370 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25371
25372 phys = __pa(virt);
25373 left = phys & (PAGE_SIZE - 1);
25374 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25375 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25376 adr = (void *)(((unsigned long)adr) | left);
25377
25378 return adr;
25379 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25380 unmap_low_page(pmd);
25381
25382 spin_lock(&init_mm.page_table_lock);
25383 - pud_populate(&init_mm, pud, __va(pmd_phys));
25384 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25385 spin_unlock(&init_mm.page_table_lock);
25386 }
25387 __flush_tlb_all();
25388 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25389 unmap_low_page(pud);
25390
25391 spin_lock(&init_mm.page_table_lock);
25392 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25393 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25394 spin_unlock(&init_mm.page_table_lock);
25395 pgd_changed = true;
25396 }
25397 @@ -691,6 +705,12 @@ void __init mem_init(void)
25398
25399 pci_iommu_alloc();
25400
25401 +#ifdef CONFIG_PAX_PER_CPU_PGD
25402 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25403 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25404 + KERNEL_PGD_PTRS);
25405 +#endif
25406 +
25407 /* clear_bss() already clear the empty_zero_page */
25408
25409 reservedpages = 0;
25410 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25411 static struct vm_area_struct gate_vma = {
25412 .vm_start = VSYSCALL_START,
25413 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25414 - .vm_page_prot = PAGE_READONLY_EXEC,
25415 - .vm_flags = VM_READ | VM_EXEC
25416 + .vm_page_prot = PAGE_READONLY,
25417 + .vm_flags = VM_READ
25418 };
25419
25420 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25421 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25422
25423 const char *arch_vma_name(struct vm_area_struct *vma)
25424 {
25425 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25426 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25427 return "[vdso]";
25428 if (vma == &gate_vma)
25429 return "[vsyscall]";
25430 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25431 index 7b179b4..6bd1777 100644
25432 --- a/arch/x86/mm/iomap_32.c
25433 +++ b/arch/x86/mm/iomap_32.c
25434 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25435 type = kmap_atomic_idx_push();
25436 idx = type + KM_TYPE_NR * smp_processor_id();
25437 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25438 +
25439 + pax_open_kernel();
25440 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25441 + pax_close_kernel();
25442 +
25443 arch_flush_lazy_mmu_mode();
25444
25445 return (void *)vaddr;
25446 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25447 index 78fe3f1..8293b6f 100644
25448 --- a/arch/x86/mm/ioremap.c
25449 +++ b/arch/x86/mm/ioremap.c
25450 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25451 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25452 int is_ram = page_is_ram(pfn);
25453
25454 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25455 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25456 return NULL;
25457 WARN_ON_ONCE(is_ram);
25458 }
25459 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25460
25461 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25462 if (page_is_ram(start >> PAGE_SHIFT))
25463 +#ifdef CONFIG_HIGHMEM
25464 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25465 +#endif
25466 return __va(phys);
25467
25468 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25469 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25470 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25471
25472 static __initdata int after_paging_init;
25473 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25474 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25475
25476 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25477 {
25478 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25479 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25480
25481 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25482 - memset(bm_pte, 0, sizeof(bm_pte));
25483 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25484 + pmd_populate_user(&init_mm, pmd, bm_pte);
25485
25486 /*
25487 * The boot-ioremap range spans multiple pmds, for which
25488 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25489 index d87dd6d..bf3fa66 100644
25490 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25491 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25492 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25493 * memory (e.g. tracked pages)? For now, we need this to avoid
25494 * invoking kmemcheck for PnP BIOS calls.
25495 */
25496 - if (regs->flags & X86_VM_MASK)
25497 + if (v8086_mode(regs))
25498 return false;
25499 - if (regs->cs != __KERNEL_CS)
25500 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25501 return false;
25502
25503 pte = kmemcheck_pte_lookup(address);
25504 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25505 index 845df68..1d8d29f 100644
25506 --- a/arch/x86/mm/mmap.c
25507 +++ b/arch/x86/mm/mmap.c
25508 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25509 * Leave an at least ~128 MB hole with possible stack randomization.
25510 */
25511 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25512 -#define MAX_GAP (TASK_SIZE/6*5)
25513 +#define MAX_GAP (pax_task_size/6*5)
25514
25515 static int mmap_is_legacy(void)
25516 {
25517 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25518 return rnd << PAGE_SHIFT;
25519 }
25520
25521 -static unsigned long mmap_base(void)
25522 +static unsigned long mmap_base(struct mm_struct *mm)
25523 {
25524 unsigned long gap = rlimit(RLIMIT_STACK);
25525 + unsigned long pax_task_size = TASK_SIZE;
25526 +
25527 +#ifdef CONFIG_PAX_SEGMEXEC
25528 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25529 + pax_task_size = SEGMEXEC_TASK_SIZE;
25530 +#endif
25531
25532 if (gap < MIN_GAP)
25533 gap = MIN_GAP;
25534 else if (gap > MAX_GAP)
25535 gap = MAX_GAP;
25536
25537 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25538 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25539 }
25540
25541 /*
25542 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25543 * does, but not when emulating X86_32
25544 */
25545 -static unsigned long mmap_legacy_base(void)
25546 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25547 {
25548 - if (mmap_is_ia32())
25549 + if (mmap_is_ia32()) {
25550 +
25551 +#ifdef CONFIG_PAX_SEGMEXEC
25552 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25553 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25554 + else
25555 +#endif
25556 +
25557 return TASK_UNMAPPED_BASE;
25558 - else
25559 + } else
25560 return TASK_UNMAPPED_BASE + mmap_rnd();
25561 }
25562
25563 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25564 void arch_pick_mmap_layout(struct mm_struct *mm)
25565 {
25566 if (mmap_is_legacy()) {
25567 - mm->mmap_base = mmap_legacy_base();
25568 + mm->mmap_base = mmap_legacy_base(mm);
25569 +
25570 +#ifdef CONFIG_PAX_RANDMMAP
25571 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25572 + mm->mmap_base += mm->delta_mmap;
25573 +#endif
25574 +
25575 mm->get_unmapped_area = arch_get_unmapped_area;
25576 mm->unmap_area = arch_unmap_area;
25577 } else {
25578 - mm->mmap_base = mmap_base();
25579 + mm->mmap_base = mmap_base(mm);
25580 +
25581 +#ifdef CONFIG_PAX_RANDMMAP
25582 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25583 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25584 +#endif
25585 +
25586 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25587 mm->unmap_area = arch_unmap_area_topdown;
25588 }
25589 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25590 index dc0b727..dc9d71a 100644
25591 --- a/arch/x86/mm/mmio-mod.c
25592 +++ b/arch/x86/mm/mmio-mod.c
25593 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25594 break;
25595 default:
25596 {
25597 - unsigned char *ip = (unsigned char *)instptr;
25598 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25599 my_trace->opcode = MMIO_UNKNOWN_OP;
25600 my_trace->width = 0;
25601 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25602 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25603 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25604 void __iomem *addr)
25605 {
25606 - static atomic_t next_id;
25607 + static atomic_unchecked_t next_id;
25608 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25609 /* These are page-unaligned. */
25610 struct mmiotrace_map map = {
25611 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25612 .private = trace
25613 },
25614 .phys = offset,
25615 - .id = atomic_inc_return(&next_id)
25616 + .id = atomic_inc_return_unchecked(&next_id)
25617 };
25618 map.map_id = trace->id;
25619
25620 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25621 index b008656..773eac2 100644
25622 --- a/arch/x86/mm/pageattr-test.c
25623 +++ b/arch/x86/mm/pageattr-test.c
25624 @@ -36,7 +36,7 @@ enum {
25625
25626 static int pte_testbit(pte_t pte)
25627 {
25628 - return pte_flags(pte) & _PAGE_UNUSED1;
25629 + return pte_flags(pte) & _PAGE_CPA_TEST;
25630 }
25631
25632 struct split_state {
25633 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25634 index a718e0d..77419bc 100644
25635 --- a/arch/x86/mm/pageattr.c
25636 +++ b/arch/x86/mm/pageattr.c
25637 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25638 */
25639 #ifdef CONFIG_PCI_BIOS
25640 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25641 - pgprot_val(forbidden) |= _PAGE_NX;
25642 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25643 #endif
25644
25645 /*
25646 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25647 * Does not cover __inittext since that is gone later on. On
25648 * 64bit we do not enforce !NX on the low mapping
25649 */
25650 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25651 - pgprot_val(forbidden) |= _PAGE_NX;
25652 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25653 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25654
25655 +#ifdef CONFIG_DEBUG_RODATA
25656 /*
25657 * The .rodata section needs to be read-only. Using the pfn
25658 * catches all aliases.
25659 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25660 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25661 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25662 pgprot_val(forbidden) |= _PAGE_RW;
25663 +#endif
25664
25665 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25666 /*
25667 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25668 }
25669 #endif
25670
25671 +#ifdef CONFIG_PAX_KERNEXEC
25672 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
25673 + pgprot_val(forbidden) |= _PAGE_RW;
25674 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25675 + }
25676 +#endif
25677 +
25678 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25679
25680 return prot;
25681 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25682 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25683 {
25684 /* change init_mm */
25685 + pax_open_kernel();
25686 set_pte_atomic(kpte, pte);
25687 +
25688 #ifdef CONFIG_X86_32
25689 if (!SHARED_KERNEL_PMD) {
25690 +
25691 +#ifdef CONFIG_PAX_PER_CPU_PGD
25692 + unsigned long cpu;
25693 +#else
25694 struct page *page;
25695 +#endif
25696
25697 +#ifdef CONFIG_PAX_PER_CPU_PGD
25698 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25699 + pgd_t *pgd = get_cpu_pgd(cpu);
25700 +#else
25701 list_for_each_entry(page, &pgd_list, lru) {
25702 - pgd_t *pgd;
25703 + pgd_t *pgd = (pgd_t *)page_address(page);
25704 +#endif
25705 +
25706 pud_t *pud;
25707 pmd_t *pmd;
25708
25709 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25710 + pgd += pgd_index(address);
25711 pud = pud_offset(pgd, address);
25712 pmd = pmd_offset(pud, address);
25713 set_pte_atomic((pte_t *)pmd, pte);
25714 }
25715 }
25716 #endif
25717 + pax_close_kernel();
25718 }
25719
25720 static int
25721 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25722 index 0eb572e..92f5c1e 100644
25723 --- a/arch/x86/mm/pat.c
25724 +++ b/arch/x86/mm/pat.c
25725 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25726
25727 if (!entry) {
25728 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25729 - current->comm, current->pid, start, end - 1);
25730 + current->comm, task_pid_nr(current), start, end - 1);
25731 return -EINVAL;
25732 }
25733
25734 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25735
25736 while (cursor < to) {
25737 if (!devmem_is_allowed(pfn)) {
25738 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25739 - current->comm, from, to - 1);
25740 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25741 + current->comm, from, to - 1, cursor);
25742 return 0;
25743 }
25744 cursor += PAGE_SIZE;
25745 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25746 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25747 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25748 "for [mem %#010Lx-%#010Lx]\n",
25749 - current->comm, current->pid,
25750 + current->comm, task_pid_nr(current),
25751 cattr_name(flags),
25752 base, (unsigned long long)(base + size-1));
25753 return -EINVAL;
25754 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25755 flags = lookup_memtype(paddr);
25756 if (want_flags != flags) {
25757 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25758 - current->comm, current->pid,
25759 + current->comm, task_pid_nr(current),
25760 cattr_name(want_flags),
25761 (unsigned long long)paddr,
25762 (unsigned long long)(paddr + size - 1),
25763 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25764 free_memtype(paddr, paddr + size);
25765 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25766 " for [mem %#010Lx-%#010Lx], got %s\n",
25767 - current->comm, current->pid,
25768 + current->comm, task_pid_nr(current),
25769 cattr_name(want_flags),
25770 (unsigned long long)paddr,
25771 (unsigned long long)(paddr + size - 1),
25772 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25773 index 9f0614d..92ae64a 100644
25774 --- a/arch/x86/mm/pf_in.c
25775 +++ b/arch/x86/mm/pf_in.c
25776 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25777 int i;
25778 enum reason_type rv = OTHERS;
25779
25780 - p = (unsigned char *)ins_addr;
25781 + p = (unsigned char *)ktla_ktva(ins_addr);
25782 p += skip_prefix(p, &prf);
25783 p += get_opcode(p, &opcode);
25784
25785 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25786 struct prefix_bits prf;
25787 int i;
25788
25789 - p = (unsigned char *)ins_addr;
25790 + p = (unsigned char *)ktla_ktva(ins_addr);
25791 p += skip_prefix(p, &prf);
25792 p += get_opcode(p, &opcode);
25793
25794 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25795 struct prefix_bits prf;
25796 int i;
25797
25798 - p = (unsigned char *)ins_addr;
25799 + p = (unsigned char *)ktla_ktva(ins_addr);
25800 p += skip_prefix(p, &prf);
25801 p += get_opcode(p, &opcode);
25802
25803 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25804 struct prefix_bits prf;
25805 int i;
25806
25807 - p = (unsigned char *)ins_addr;
25808 + p = (unsigned char *)ktla_ktva(ins_addr);
25809 p += skip_prefix(p, &prf);
25810 p += get_opcode(p, &opcode);
25811 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25812 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25813 struct prefix_bits prf;
25814 int i;
25815
25816 - p = (unsigned char *)ins_addr;
25817 + p = (unsigned char *)ktla_ktva(ins_addr);
25818 p += skip_prefix(p, &prf);
25819 p += get_opcode(p, &opcode);
25820 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25821 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25822 index 8573b83..4f3ed7e 100644
25823 --- a/arch/x86/mm/pgtable.c
25824 +++ b/arch/x86/mm/pgtable.c
25825 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25826 list_del(&page->lru);
25827 }
25828
25829 -#define UNSHARED_PTRS_PER_PGD \
25830 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25831 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25832 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25833
25834 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25835 +{
25836 + unsigned int count = USER_PGD_PTRS;
25837
25838 + while (count--)
25839 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25840 +}
25841 +#endif
25842 +
25843 +#ifdef CONFIG_PAX_PER_CPU_PGD
25844 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25845 +{
25846 + unsigned int count = USER_PGD_PTRS;
25847 +
25848 + while (count--) {
25849 + pgd_t pgd;
25850 +
25851 +#ifdef CONFIG_X86_64
25852 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25853 +#else
25854 + pgd = *src++;
25855 +#endif
25856 +
25857 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25858 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25859 +#endif
25860 +
25861 + *dst++ = pgd;
25862 + }
25863 +
25864 +}
25865 +#endif
25866 +
25867 +#ifdef CONFIG_X86_64
25868 +#define pxd_t pud_t
25869 +#define pyd_t pgd_t
25870 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25871 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25872 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25873 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25874 +#define PYD_SIZE PGDIR_SIZE
25875 +#else
25876 +#define pxd_t pmd_t
25877 +#define pyd_t pud_t
25878 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25879 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25880 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25881 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25882 +#define PYD_SIZE PUD_SIZE
25883 +#endif
25884 +
25885 +#ifdef CONFIG_PAX_PER_CPU_PGD
25886 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25887 +static inline void pgd_dtor(pgd_t *pgd) {}
25888 +#else
25889 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25890 {
25891 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25892 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25893 pgd_list_del(pgd);
25894 spin_unlock(&pgd_lock);
25895 }
25896 +#endif
25897
25898 /*
25899 * List of all pgd's needed for non-PAE so it can invalidate entries
25900 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25901 * -- wli
25902 */
25903
25904 -#ifdef CONFIG_X86_PAE
25905 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25906 /*
25907 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25908 * updating the top-level pagetable entries to guarantee the
25909 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25910 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25911 * and initialize the kernel pmds here.
25912 */
25913 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25914 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25915
25916 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25917 {
25918 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25919 */
25920 flush_tlb_mm(mm);
25921 }
25922 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25923 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25924 #else /* !CONFIG_X86_PAE */
25925
25926 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25927 -#define PREALLOCATED_PMDS 0
25928 +#define PREALLOCATED_PXDS 0
25929
25930 #endif /* CONFIG_X86_PAE */
25931
25932 -static void free_pmds(pmd_t *pmds[])
25933 +static void free_pxds(pxd_t *pxds[])
25934 {
25935 int i;
25936
25937 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25938 - if (pmds[i])
25939 - free_page((unsigned long)pmds[i]);
25940 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25941 + if (pxds[i])
25942 + free_page((unsigned long)pxds[i]);
25943 }
25944
25945 -static int preallocate_pmds(pmd_t *pmds[])
25946 +static int preallocate_pxds(pxd_t *pxds[])
25947 {
25948 int i;
25949 bool failed = false;
25950
25951 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25952 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25953 - if (pmd == NULL)
25954 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25955 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25956 + if (pxd == NULL)
25957 failed = true;
25958 - pmds[i] = pmd;
25959 + pxds[i] = pxd;
25960 }
25961
25962 if (failed) {
25963 - free_pmds(pmds);
25964 + free_pxds(pxds);
25965 return -ENOMEM;
25966 }
25967
25968 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25969 * preallocate which never got a corresponding vma will need to be
25970 * freed manually.
25971 */
25972 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25973 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25974 {
25975 int i;
25976
25977 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25978 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25979 pgd_t pgd = pgdp[i];
25980
25981 if (pgd_val(pgd) != 0) {
25982 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25983 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25984
25985 - pgdp[i] = native_make_pgd(0);
25986 + set_pgd(pgdp + i, native_make_pgd(0));
25987
25988 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25989 - pmd_free(mm, pmd);
25990 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25991 + pxd_free(mm, pxd);
25992 }
25993 }
25994 }
25995
25996 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25997 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25998 {
25999 - pud_t *pud;
26000 + pyd_t *pyd;
26001 unsigned long addr;
26002 int i;
26003
26004 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
26005 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
26006 return;
26007
26008 - pud = pud_offset(pgd, 0);
26009 +#ifdef CONFIG_X86_64
26010 + pyd = pyd_offset(mm, 0L);
26011 +#else
26012 + pyd = pyd_offset(pgd, 0L);
26013 +#endif
26014
26015 - for (addr = i = 0; i < PREALLOCATED_PMDS;
26016 - i++, pud++, addr += PUD_SIZE) {
26017 - pmd_t *pmd = pmds[i];
26018 + for (addr = i = 0; i < PREALLOCATED_PXDS;
26019 + i++, pyd++, addr += PYD_SIZE) {
26020 + pxd_t *pxd = pxds[i];
26021
26022 if (i >= KERNEL_PGD_BOUNDARY)
26023 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
26024 - sizeof(pmd_t) * PTRS_PER_PMD);
26025 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
26026 + sizeof(pxd_t) * PTRS_PER_PMD);
26027
26028 - pud_populate(mm, pud, pmd);
26029 + pyd_populate(mm, pyd, pxd);
26030 }
26031 }
26032
26033 pgd_t *pgd_alloc(struct mm_struct *mm)
26034 {
26035 pgd_t *pgd;
26036 - pmd_t *pmds[PREALLOCATED_PMDS];
26037 + pxd_t *pxds[PREALLOCATED_PXDS];
26038
26039 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
26040
26041 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
26042
26043 mm->pgd = pgd;
26044
26045 - if (preallocate_pmds(pmds) != 0)
26046 + if (preallocate_pxds(pxds) != 0)
26047 goto out_free_pgd;
26048
26049 if (paravirt_pgd_alloc(mm) != 0)
26050 - goto out_free_pmds;
26051 + goto out_free_pxds;
26052
26053 /*
26054 * Make sure that pre-populating the pmds is atomic with
26055 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
26056 spin_lock(&pgd_lock);
26057
26058 pgd_ctor(mm, pgd);
26059 - pgd_prepopulate_pmd(mm, pgd, pmds);
26060 + pgd_prepopulate_pxd(mm, pgd, pxds);
26061
26062 spin_unlock(&pgd_lock);
26063
26064 return pgd;
26065
26066 -out_free_pmds:
26067 - free_pmds(pmds);
26068 +out_free_pxds:
26069 + free_pxds(pxds);
26070 out_free_pgd:
26071 free_page((unsigned long)pgd);
26072 out:
26073 @@ -295,7 +356,7 @@ out:
26074
26075 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
26076 {
26077 - pgd_mop_up_pmds(mm, pgd);
26078 + pgd_mop_up_pxds(mm, pgd);
26079 pgd_dtor(pgd);
26080 paravirt_pgd_free(mm, pgd);
26081 free_page((unsigned long)pgd);
26082 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
26083 index a69bcb8..19068ab 100644
26084 --- a/arch/x86/mm/pgtable_32.c
26085 +++ b/arch/x86/mm/pgtable_32.c
26086 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
26087 return;
26088 }
26089 pte = pte_offset_kernel(pmd, vaddr);
26090 +
26091 + pax_open_kernel();
26092 if (pte_val(pteval))
26093 set_pte_at(&init_mm, vaddr, pte, pteval);
26094 else
26095 pte_clear(&init_mm, vaddr, pte);
26096 + pax_close_kernel();
26097
26098 /*
26099 * It's enough to flush this one mapping.
26100 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
26101 index 410531d..0f16030 100644
26102 --- a/arch/x86/mm/setup_nx.c
26103 +++ b/arch/x86/mm/setup_nx.c
26104 @@ -5,8 +5,10 @@
26105 #include <asm/pgtable.h>
26106 #include <asm/proto.h>
26107
26108 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26109 static int disable_nx __cpuinitdata;
26110
26111 +#ifndef CONFIG_PAX_PAGEEXEC
26112 /*
26113 * noexec = on|off
26114 *
26115 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
26116 return 0;
26117 }
26118 early_param("noexec", noexec_setup);
26119 +#endif
26120 +
26121 +#endif
26122
26123 void __cpuinit x86_configure_nx(void)
26124 {
26125 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26126 if (cpu_has_nx && !disable_nx)
26127 __supported_pte_mask |= _PAGE_NX;
26128 else
26129 +#endif
26130 __supported_pte_mask &= ~_PAGE_NX;
26131 }
26132
26133 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26134 index 60f926c..a710970 100644
26135 --- a/arch/x86/mm/tlb.c
26136 +++ b/arch/x86/mm/tlb.c
26137 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
26138 BUG();
26139 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
26140 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
26141 +
26142 +#ifndef CONFIG_PAX_PER_CPU_PGD
26143 load_cr3(swapper_pg_dir);
26144 +#endif
26145 +
26146 }
26147 }
26148 EXPORT_SYMBOL_GPL(leave_mm);
26149 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
26150 index 877b9a1..a8ecf42 100644
26151 --- a/arch/x86/net/bpf_jit.S
26152 +++ b/arch/x86/net/bpf_jit.S
26153 @@ -9,6 +9,7 @@
26154 */
26155 #include <linux/linkage.h>
26156 #include <asm/dwarf2.h>
26157 +#include <asm/alternative-asm.h>
26158
26159 /*
26160 * Calling convention :
26161 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
26162 jle bpf_slow_path_word
26163 mov (SKBDATA,%rsi),%eax
26164 bswap %eax /* ntohl() */
26165 + pax_force_retaddr
26166 ret
26167
26168 sk_load_half:
26169 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
26170 jle bpf_slow_path_half
26171 movzwl (SKBDATA,%rsi),%eax
26172 rol $8,%ax # ntohs()
26173 + pax_force_retaddr
26174 ret
26175
26176 sk_load_byte:
26177 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
26178 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26179 jle bpf_slow_path_byte
26180 movzbl (SKBDATA,%rsi),%eax
26181 + pax_force_retaddr
26182 ret
26183
26184 /**
26185 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
26186 movzbl (SKBDATA,%rsi),%ebx
26187 and $15,%bl
26188 shl $2,%bl
26189 + pax_force_retaddr
26190 ret
26191
26192 /* rsi contains offset and can be scratched */
26193 @@ -109,6 +114,7 @@ bpf_slow_path_word:
26194 js bpf_error
26195 mov -12(%rbp),%eax
26196 bswap %eax
26197 + pax_force_retaddr
26198 ret
26199
26200 bpf_slow_path_half:
26201 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26202 mov -12(%rbp),%ax
26203 rol $8,%ax
26204 movzwl %ax,%eax
26205 + pax_force_retaddr
26206 ret
26207
26208 bpf_slow_path_byte:
26209 bpf_slow_path_common(1)
26210 js bpf_error
26211 movzbl -12(%rbp),%eax
26212 + pax_force_retaddr
26213 ret
26214
26215 bpf_slow_path_byte_msh:
26216 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26217 and $15,%al
26218 shl $2,%al
26219 xchg %eax,%ebx
26220 + pax_force_retaddr
26221 ret
26222
26223 #define sk_negative_common(SIZE) \
26224 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26225 sk_negative_common(4)
26226 mov (%rax), %eax
26227 bswap %eax
26228 + pax_force_retaddr
26229 ret
26230
26231 bpf_slow_path_half_neg:
26232 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26233 mov (%rax),%ax
26234 rol $8,%ax
26235 movzwl %ax,%eax
26236 + pax_force_retaddr
26237 ret
26238
26239 bpf_slow_path_byte_neg:
26240 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26241 .globl sk_load_byte_negative_offset
26242 sk_negative_common(1)
26243 movzbl (%rax), %eax
26244 + pax_force_retaddr
26245 ret
26246
26247 bpf_slow_path_byte_msh_neg:
26248 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26249 and $15,%al
26250 shl $2,%al
26251 xchg %eax,%ebx
26252 + pax_force_retaddr
26253 ret
26254
26255 bpf_error:
26256 @@ -197,4 +210,5 @@ bpf_error:
26257 xor %eax,%eax
26258 mov -8(%rbp),%rbx
26259 leaveq
26260 + pax_force_retaddr
26261 ret
26262 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26263 index 520d2bd..b895ef4 100644
26264 --- a/arch/x86/net/bpf_jit_comp.c
26265 +++ b/arch/x86/net/bpf_jit_comp.c
26266 @@ -11,6 +11,7 @@
26267 #include <asm/cacheflush.h>
26268 #include <linux/netdevice.h>
26269 #include <linux/filter.h>
26270 +#include <linux/random.h>
26271
26272 /*
26273 * Conventions :
26274 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
26275 return ptr + len;
26276 }
26277
26278 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26279 +#define MAX_INSTR_CODE_SIZE 96
26280 +#else
26281 +#define MAX_INSTR_CODE_SIZE 64
26282 +#endif
26283 +
26284 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
26285
26286 #define EMIT1(b1) EMIT(b1, 1)
26287 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
26288 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
26289 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
26290 +
26291 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26292 +/* original constant will appear in ecx */
26293 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
26294 +do { \
26295 + /* mov ecx, randkey */ \
26296 + EMIT1(0xb9); \
26297 + EMIT(_key, 4); \
26298 + /* xor ecx, randkey ^ off */ \
26299 + EMIT2(0x81, 0xf1); \
26300 + EMIT((_key) ^ (_off), 4); \
26301 +} while (0)
26302 +
26303 +#define EMIT1_off32(b1, _off) \
26304 +do { \
26305 + switch (b1) { \
26306 + case 0x05: /* add eax, imm32 */ \
26307 + case 0x2d: /* sub eax, imm32 */ \
26308 + case 0x25: /* and eax, imm32 */ \
26309 + case 0x0d: /* or eax, imm32 */ \
26310 + case 0xb8: /* mov eax, imm32 */ \
26311 + case 0x3d: /* cmp eax, imm32 */ \
26312 + case 0xa9: /* test eax, imm32 */ \
26313 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26314 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
26315 + break; \
26316 + case 0xbb: /* mov ebx, imm32 */ \
26317 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26318 + /* mov ebx, ecx */ \
26319 + EMIT2(0x89, 0xcb); \
26320 + break; \
26321 + case 0xbe: /* mov esi, imm32 */ \
26322 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26323 + /* mov esi, ecx */ \
26324 + EMIT2(0x89, 0xce); \
26325 + break; \
26326 + case 0xe9: /* jmp rel imm32 */ \
26327 + EMIT1(b1); \
26328 + EMIT(_off, 4); \
26329 + /* prevent fall-through, we're not called if off = 0 */ \
26330 + EMIT(0xcccccccc, 4); \
26331 + EMIT(0xcccccccc, 4); \
26332 + break; \
26333 + default: \
26334 + EMIT1(b1); \
26335 + EMIT(_off, 4); \
26336 + } \
26337 +} while (0)
26338 +
26339 +#define EMIT2_off32(b1, b2, _off) \
26340 +do { \
26341 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
26342 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
26343 + EMIT(randkey, 4); \
26344 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
26345 + EMIT((_off) - randkey, 4); \
26346 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
26347 + DILUTE_CONST_SEQUENCE(_off, randkey); \
26348 + /* imul eax, ecx */ \
26349 + EMIT3(0x0f, 0xaf, 0xc1); \
26350 + } else { \
26351 + EMIT2(b1, b2); \
26352 + EMIT(_off, 4); \
26353 + } \
26354 +} while (0)
26355 +#else
26356 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
26357 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
26358 +#endif
26359
26360 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
26361 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
26362 @@ -89,6 +164,24 @@ do { \
26363 #define X86_JBE 0x76
26364 #define X86_JA 0x77
26365
26366 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26367 +#define APPEND_FLOW_VERIFY() \
26368 +do { \
26369 + /* mov ecx, randkey */ \
26370 + EMIT1(0xb9); \
26371 + EMIT(randkey, 4); \
26372 + /* cmp ecx, randkey */ \
26373 + EMIT2(0x81, 0xf9); \
26374 + EMIT(randkey, 4); \
26375 + /* jz after 8 int 3s */ \
26376 + EMIT2(0x74, 0x08); \
26377 + EMIT(0xcccccccc, 4); \
26378 + EMIT(0xcccccccc, 4); \
26379 +} while (0)
26380 +#else
26381 +#define APPEND_FLOW_VERIFY() do { } while (0)
26382 +#endif
26383 +
26384 #define EMIT_COND_JMP(op, offset) \
26385 do { \
26386 if (is_near(offset)) \
26387 @@ -96,6 +189,7 @@ do { \
26388 else { \
26389 EMIT2(0x0f, op + 0x10); \
26390 EMIT(offset, 4); /* jxx .+off32 */ \
26391 + APPEND_FLOW_VERIFY(); \
26392 } \
26393 } while (0)
26394
26395 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
26396 set_fs(old_fs);
26397 }
26398
26399 +struct bpf_jit_work {
26400 + struct work_struct work;
26401 + void *image;
26402 +};
26403 +
26404 #define CHOOSE_LOAD_FUNC(K, func) \
26405 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26406
26407 void bpf_jit_compile(struct sk_filter *fp)
26408 {
26409 - u8 temp[64];
26410 + u8 temp[MAX_INSTR_CODE_SIZE];
26411 u8 *prog;
26412 unsigned int proglen, oldproglen = 0;
26413 int ilen, i;
26414 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
26415 unsigned int *addrs;
26416 const struct sock_filter *filter = fp->insns;
26417 int flen = fp->len;
26418 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26419 + unsigned int randkey;
26420 +#endif
26421
26422 if (!bpf_jit_enable)
26423 return;
26424 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
26425 if (addrs == NULL)
26426 return;
26427
26428 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26429 + if (!fp->work)
26430 + goto out;
26431 +
26432 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26433 + randkey = get_random_int();
26434 +#endif
26435 +
26436 /* Before first pass, make a rough estimation of addrs[]
26437 - * each bpf instruction is translated to less than 64 bytes
26438 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
26439 */
26440 for (proglen = 0, i = 0; i < flen; i++) {
26441 - proglen += 64;
26442 + proglen += MAX_INSTR_CODE_SIZE;
26443 addrs[i] = proglen;
26444 }
26445 cleanup_addr = proglen; /* epilogue address */
26446 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
26447 case BPF_S_ALU_MUL_K: /* A *= K */
26448 if (is_imm8(K))
26449 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
26450 - else {
26451 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
26452 - EMIT(K, 4);
26453 - }
26454 + else
26455 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
26456 break;
26457 case BPF_S_ALU_DIV_X: /* A /= X; */
26458 seen |= SEEN_XREG;
26459 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
26460 break;
26461 case BPF_S_ALU_MOD_K: /* A %= K; */
26462 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
26463 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26464 + DILUTE_CONST_SEQUENCE(K, randkey);
26465 +#else
26466 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
26467 +#endif
26468 EMIT2(0xf7, 0xf1); /* div %ecx */
26469 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
26470 break;
26471 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
26472 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
26473 + DILUTE_CONST_SEQUENCE(K, randkey);
26474 + // imul rax, rcx
26475 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
26476 +#else
26477 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
26478 EMIT(K, 4);
26479 +#endif
26480 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
26481 break;
26482 case BPF_S_ALU_AND_X:
26483 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
26484 if (is_imm8(K)) {
26485 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
26486 } else {
26487 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
26488 - EMIT(K, 4);
26489 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
26490 }
26491 } else {
26492 EMIT2(0x89,0xde); /* mov %ebx,%esi */
26493 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26494 break;
26495 default:
26496 /* hmm, too complex filter, give up with jit compiler */
26497 - goto out;
26498 + goto error;
26499 }
26500 ilen = prog - temp;
26501 if (image) {
26502 if (unlikely(proglen + ilen > oldproglen)) {
26503 pr_err("bpb_jit_compile fatal error\n");
26504 - kfree(addrs);
26505 - module_free(NULL, image);
26506 - return;
26507 + module_free_exec(NULL, image);
26508 + goto error;
26509 }
26510 + pax_open_kernel();
26511 memcpy(image + proglen, temp, ilen);
26512 + pax_close_kernel();
26513 }
26514 proglen += ilen;
26515 addrs[i] = proglen;
26516 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26517 break;
26518 }
26519 if (proglen == oldproglen) {
26520 - image = module_alloc(max_t(unsigned int,
26521 - proglen,
26522 - sizeof(struct work_struct)));
26523 + image = module_alloc_exec(proglen);
26524 if (!image)
26525 - goto out;
26526 + goto error;
26527 }
26528 oldproglen = proglen;
26529 }
26530 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26531 bpf_flush_icache(image, image + proglen);
26532
26533 fp->bpf_func = (void *)image;
26534 - }
26535 + } else
26536 +error:
26537 + kfree(fp->work);
26538 +
26539 out:
26540 kfree(addrs);
26541 return;
26542 @@ -686,18 +805,20 @@ out:
26543
26544 static void jit_free_defer(struct work_struct *arg)
26545 {
26546 - module_free(NULL, arg);
26547 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26548 + kfree(arg);
26549 }
26550
26551 /* run from softirq, we must use a work_struct to call
26552 - * module_free() from process context
26553 + * module_free_exec() from process context
26554 */
26555 void bpf_jit_free(struct sk_filter *fp)
26556 {
26557 if (fp->bpf_func != sk_run_filter) {
26558 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26559 + struct work_struct *work = &fp->work->work;
26560
26561 INIT_WORK(work, jit_free_defer);
26562 + fp->work->image = fp->bpf_func;
26563 schedule_work(work);
26564 }
26565 }
26566 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26567 index d6aa6e8..266395a 100644
26568 --- a/arch/x86/oprofile/backtrace.c
26569 +++ b/arch/x86/oprofile/backtrace.c
26570 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26571 struct stack_frame_ia32 *fp;
26572 unsigned long bytes;
26573
26574 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26575 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26576 if (bytes != sizeof(bufhead))
26577 return NULL;
26578
26579 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26580 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26581
26582 oprofile_add_trace(bufhead[0].return_address);
26583
26584 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26585 struct stack_frame bufhead[2];
26586 unsigned long bytes;
26587
26588 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26589 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26590 if (bytes != sizeof(bufhead))
26591 return NULL;
26592
26593 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26594 {
26595 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26596
26597 - if (!user_mode_vm(regs)) {
26598 + if (!user_mode(regs)) {
26599 unsigned long stack = kernel_stack_pointer(regs);
26600 if (depth)
26601 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26602 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26603 index e14a2ff..3fd6b58 100644
26604 --- a/arch/x86/pci/mrst.c
26605 +++ b/arch/x86/pci/mrst.c
26606 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26607 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26608 pci_mmcfg_late_init();
26609 pcibios_enable_irq = mrst_pci_irq_enable;
26610 - pci_root_ops = pci_mrst_ops;
26611 + pax_open_kernel();
26612 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26613 + pax_close_kernel();
26614 pci_soc_mode = 1;
26615 /* Continue with standard init */
26616 return 1;
26617 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26618 index da8fe05..7ee6704 100644
26619 --- a/arch/x86/pci/pcbios.c
26620 +++ b/arch/x86/pci/pcbios.c
26621 @@ -79,50 +79,93 @@ union bios32 {
26622 static struct {
26623 unsigned long address;
26624 unsigned short segment;
26625 -} bios32_indirect = { 0, __KERNEL_CS };
26626 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26627
26628 /*
26629 * Returns the entry point for the given service, NULL on error
26630 */
26631
26632 -static unsigned long bios32_service(unsigned long service)
26633 +static unsigned long __devinit bios32_service(unsigned long service)
26634 {
26635 unsigned char return_code; /* %al */
26636 unsigned long address; /* %ebx */
26637 unsigned long length; /* %ecx */
26638 unsigned long entry; /* %edx */
26639 unsigned long flags;
26640 + struct desc_struct d, *gdt;
26641
26642 local_irq_save(flags);
26643 - __asm__("lcall *(%%edi); cld"
26644 +
26645 + gdt = get_cpu_gdt_table(smp_processor_id());
26646 +
26647 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26648 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26649 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26650 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26651 +
26652 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26653 : "=a" (return_code),
26654 "=b" (address),
26655 "=c" (length),
26656 "=d" (entry)
26657 : "0" (service),
26658 "1" (0),
26659 - "D" (&bios32_indirect));
26660 + "D" (&bios32_indirect),
26661 + "r"(__PCIBIOS_DS)
26662 + : "memory");
26663 +
26664 + pax_open_kernel();
26665 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26666 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26667 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26668 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26669 + pax_close_kernel();
26670 +
26671 local_irq_restore(flags);
26672
26673 switch (return_code) {
26674 - case 0:
26675 - return address + entry;
26676 - case 0x80: /* Not present */
26677 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26678 - return 0;
26679 - default: /* Shouldn't happen */
26680 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26681 - service, return_code);
26682 + case 0: {
26683 + int cpu;
26684 + unsigned char flags;
26685 +
26686 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26687 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26688 + printk(KERN_WARNING "bios32_service: not valid\n");
26689 return 0;
26690 + }
26691 + address = address + PAGE_OFFSET;
26692 + length += 16UL; /* some BIOSs underreport this... */
26693 + flags = 4;
26694 + if (length >= 64*1024*1024) {
26695 + length >>= PAGE_SHIFT;
26696 + flags |= 8;
26697 + }
26698 +
26699 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26700 + gdt = get_cpu_gdt_table(cpu);
26701 + pack_descriptor(&d, address, length, 0x9b, flags);
26702 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26703 + pack_descriptor(&d, address, length, 0x93, flags);
26704 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26705 + }
26706 + return entry;
26707 + }
26708 + case 0x80: /* Not present */
26709 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26710 + return 0;
26711 + default: /* Shouldn't happen */
26712 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26713 + service, return_code);
26714 + return 0;
26715 }
26716 }
26717
26718 static struct {
26719 unsigned long address;
26720 unsigned short segment;
26721 -} pci_indirect = { 0, __KERNEL_CS };
26722 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26723
26724 -static int pci_bios_present;
26725 +static int pci_bios_present __read_only;
26726
26727 static int __devinit check_pcibios(void)
26728 {
26729 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26730 unsigned long flags, pcibios_entry;
26731
26732 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26733 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26734 + pci_indirect.address = pcibios_entry;
26735
26736 local_irq_save(flags);
26737 - __asm__(
26738 - "lcall *(%%edi); cld\n\t"
26739 + __asm__("movw %w6, %%ds\n\t"
26740 + "lcall *%%ss:(%%edi); cld\n\t"
26741 + "push %%ss\n\t"
26742 + "pop %%ds\n\t"
26743 "jc 1f\n\t"
26744 "xor %%ah, %%ah\n"
26745 "1:"
26746 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26747 "=b" (ebx),
26748 "=c" (ecx)
26749 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26750 - "D" (&pci_indirect)
26751 + "D" (&pci_indirect),
26752 + "r" (__PCIBIOS_DS)
26753 : "memory");
26754 local_irq_restore(flags);
26755
26756 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26757
26758 switch (len) {
26759 case 1:
26760 - __asm__("lcall *(%%esi); cld\n\t"
26761 + __asm__("movw %w6, %%ds\n\t"
26762 + "lcall *%%ss:(%%esi); cld\n\t"
26763 + "push %%ss\n\t"
26764 + "pop %%ds\n\t"
26765 "jc 1f\n\t"
26766 "xor %%ah, %%ah\n"
26767 "1:"
26768 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26769 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26770 "b" (bx),
26771 "D" ((long)reg),
26772 - "S" (&pci_indirect));
26773 + "S" (&pci_indirect),
26774 + "r" (__PCIBIOS_DS));
26775 /*
26776 * Zero-extend the result beyond 8 bits, do not trust the
26777 * BIOS having done it:
26778 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26779 *value &= 0xff;
26780 break;
26781 case 2:
26782 - __asm__("lcall *(%%esi); cld\n\t"
26783 + __asm__("movw %w6, %%ds\n\t"
26784 + "lcall *%%ss:(%%esi); cld\n\t"
26785 + "push %%ss\n\t"
26786 + "pop %%ds\n\t"
26787 "jc 1f\n\t"
26788 "xor %%ah, %%ah\n"
26789 "1:"
26790 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26791 : "1" (PCIBIOS_READ_CONFIG_WORD),
26792 "b" (bx),
26793 "D" ((long)reg),
26794 - "S" (&pci_indirect));
26795 + "S" (&pci_indirect),
26796 + "r" (__PCIBIOS_DS));
26797 /*
26798 * Zero-extend the result beyond 16 bits, do not trust the
26799 * BIOS having done it:
26800 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26801 *value &= 0xffff;
26802 break;
26803 case 4:
26804 - __asm__("lcall *(%%esi); cld\n\t"
26805 + __asm__("movw %w6, %%ds\n\t"
26806 + "lcall *%%ss:(%%esi); cld\n\t"
26807 + "push %%ss\n\t"
26808 + "pop %%ds\n\t"
26809 "jc 1f\n\t"
26810 "xor %%ah, %%ah\n"
26811 "1:"
26812 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26813 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26814 "b" (bx),
26815 "D" ((long)reg),
26816 - "S" (&pci_indirect));
26817 + "S" (&pci_indirect),
26818 + "r" (__PCIBIOS_DS));
26819 break;
26820 }
26821
26822 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26823
26824 switch (len) {
26825 case 1:
26826 - __asm__("lcall *(%%esi); cld\n\t"
26827 + __asm__("movw %w6, %%ds\n\t"
26828 + "lcall *%%ss:(%%esi); cld\n\t"
26829 + "push %%ss\n\t"
26830 + "pop %%ds\n\t"
26831 "jc 1f\n\t"
26832 "xor %%ah, %%ah\n"
26833 "1:"
26834 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26835 "c" (value),
26836 "b" (bx),
26837 "D" ((long)reg),
26838 - "S" (&pci_indirect));
26839 + "S" (&pci_indirect),
26840 + "r" (__PCIBIOS_DS));
26841 break;
26842 case 2:
26843 - __asm__("lcall *(%%esi); cld\n\t"
26844 + __asm__("movw %w6, %%ds\n\t"
26845 + "lcall *%%ss:(%%esi); cld\n\t"
26846 + "push %%ss\n\t"
26847 + "pop %%ds\n\t"
26848 "jc 1f\n\t"
26849 "xor %%ah, %%ah\n"
26850 "1:"
26851 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26852 "c" (value),
26853 "b" (bx),
26854 "D" ((long)reg),
26855 - "S" (&pci_indirect));
26856 + "S" (&pci_indirect),
26857 + "r" (__PCIBIOS_DS));
26858 break;
26859 case 4:
26860 - __asm__("lcall *(%%esi); cld\n\t"
26861 + __asm__("movw %w6, %%ds\n\t"
26862 + "lcall *%%ss:(%%esi); cld\n\t"
26863 + "push %%ss\n\t"
26864 + "pop %%ds\n\t"
26865 "jc 1f\n\t"
26866 "xor %%ah, %%ah\n"
26867 "1:"
26868 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26869 "c" (value),
26870 "b" (bx),
26871 "D" ((long)reg),
26872 - "S" (&pci_indirect));
26873 + "S" (&pci_indirect),
26874 + "r" (__PCIBIOS_DS));
26875 break;
26876 }
26877
26878 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26879
26880 DBG("PCI: Fetching IRQ routing table... ");
26881 __asm__("push %%es\n\t"
26882 + "movw %w8, %%ds\n\t"
26883 "push %%ds\n\t"
26884 "pop %%es\n\t"
26885 - "lcall *(%%esi); cld\n\t"
26886 + "lcall *%%ss:(%%esi); cld\n\t"
26887 "pop %%es\n\t"
26888 + "push %%ss\n\t"
26889 + "pop %%ds\n"
26890 "jc 1f\n\t"
26891 "xor %%ah, %%ah\n"
26892 "1:"
26893 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26894 "1" (0),
26895 "D" ((long) &opt),
26896 "S" (&pci_indirect),
26897 - "m" (opt)
26898 + "m" (opt),
26899 + "r" (__PCIBIOS_DS)
26900 : "memory");
26901 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26902 if (ret & 0xff00)
26903 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26904 {
26905 int ret;
26906
26907 - __asm__("lcall *(%%esi); cld\n\t"
26908 + __asm__("movw %w5, %%ds\n\t"
26909 + "lcall *%%ss:(%%esi); cld\n\t"
26910 + "push %%ss\n\t"
26911 + "pop %%ds\n"
26912 "jc 1f\n\t"
26913 "xor %%ah, %%ah\n"
26914 "1:"
26915 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26916 : "0" (PCIBIOS_SET_PCI_HW_INT),
26917 "b" ((dev->bus->number << 8) | dev->devfn),
26918 "c" ((irq << 8) | (pin + 10)),
26919 - "S" (&pci_indirect));
26920 + "S" (&pci_indirect),
26921 + "r" (__PCIBIOS_DS));
26922 return !(ret & 0xff00);
26923 }
26924 EXPORT_SYMBOL(pcibios_set_irq_routing);
26925 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26926 index 40e4469..1ab536e 100644
26927 --- a/arch/x86/platform/efi/efi_32.c
26928 +++ b/arch/x86/platform/efi/efi_32.c
26929 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26930 {
26931 struct desc_ptr gdt_descr;
26932
26933 +#ifdef CONFIG_PAX_KERNEXEC
26934 + struct desc_struct d;
26935 +#endif
26936 +
26937 local_irq_save(efi_rt_eflags);
26938
26939 load_cr3(initial_page_table);
26940 __flush_tlb_all();
26941
26942 +#ifdef CONFIG_PAX_KERNEXEC
26943 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26944 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26945 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26946 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26947 +#endif
26948 +
26949 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26950 gdt_descr.size = GDT_SIZE - 1;
26951 load_gdt(&gdt_descr);
26952 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26953 {
26954 struct desc_ptr gdt_descr;
26955
26956 +#ifdef CONFIG_PAX_KERNEXEC
26957 + struct desc_struct d;
26958 +
26959 + memset(&d, 0, sizeof d);
26960 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26961 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26962 +#endif
26963 +
26964 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26965 gdt_descr.size = GDT_SIZE - 1;
26966 load_gdt(&gdt_descr);
26967 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26968 index fbe66e6..eae5e38 100644
26969 --- a/arch/x86/platform/efi/efi_stub_32.S
26970 +++ b/arch/x86/platform/efi/efi_stub_32.S
26971 @@ -6,7 +6,9 @@
26972 */
26973
26974 #include <linux/linkage.h>
26975 +#include <linux/init.h>
26976 #include <asm/page_types.h>
26977 +#include <asm/segment.h>
26978
26979 /*
26980 * efi_call_phys(void *, ...) is a function with variable parameters.
26981 @@ -20,7 +22,7 @@
26982 * service functions will comply with gcc calling convention, too.
26983 */
26984
26985 -.text
26986 +__INIT
26987 ENTRY(efi_call_phys)
26988 /*
26989 * 0. The function can only be called in Linux kernel. So CS has been
26990 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26991 * The mapping of lower virtual memory has been created in prelog and
26992 * epilog.
26993 */
26994 - movl $1f, %edx
26995 - subl $__PAGE_OFFSET, %edx
26996 - jmp *%edx
26997 +#ifdef CONFIG_PAX_KERNEXEC
26998 + movl $(__KERNEXEC_EFI_DS), %edx
26999 + mov %edx, %ds
27000 + mov %edx, %es
27001 + mov %edx, %ss
27002 + addl $2f,(1f)
27003 + ljmp *(1f)
27004 +
27005 +__INITDATA
27006 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
27007 +.previous
27008 +
27009 +2:
27010 + subl $2b,(1b)
27011 +#else
27012 + jmp 1f-__PAGE_OFFSET
27013 1:
27014 +#endif
27015
27016 /*
27017 * 2. Now on the top of stack is the return
27018 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
27019 * parameter 2, ..., param n. To make things easy, we save the return
27020 * address of efi_call_phys in a global variable.
27021 */
27022 - popl %edx
27023 - movl %edx, saved_return_addr
27024 - /* get the function pointer into ECX*/
27025 - popl %ecx
27026 - movl %ecx, efi_rt_function_ptr
27027 - movl $2f, %edx
27028 - subl $__PAGE_OFFSET, %edx
27029 - pushl %edx
27030 + popl (saved_return_addr)
27031 + popl (efi_rt_function_ptr)
27032
27033 /*
27034 * 3. Clear PG bit in %CR0.
27035 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
27036 /*
27037 * 5. Call the physical function.
27038 */
27039 - jmp *%ecx
27040 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
27041
27042 -2:
27043 /*
27044 * 6. After EFI runtime service returns, control will return to
27045 * following instruction. We'd better readjust stack pointer first.
27046 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
27047 movl %cr0, %edx
27048 orl $0x80000000, %edx
27049 movl %edx, %cr0
27050 - jmp 1f
27051 -1:
27052 +
27053 /*
27054 * 8. Now restore the virtual mode from flat mode by
27055 * adding EIP with PAGE_OFFSET.
27056 */
27057 - movl $1f, %edx
27058 - jmp *%edx
27059 +#ifdef CONFIG_PAX_KERNEXEC
27060 + movl $(__KERNEL_DS), %edx
27061 + mov %edx, %ds
27062 + mov %edx, %es
27063 + mov %edx, %ss
27064 + ljmp $(__KERNEL_CS),$1f
27065 +#else
27066 + jmp 1f+__PAGE_OFFSET
27067 +#endif
27068 1:
27069
27070 /*
27071 * 9. Balance the stack. And because EAX contain the return value,
27072 * we'd better not clobber it.
27073 */
27074 - leal efi_rt_function_ptr, %edx
27075 - movl (%edx), %ecx
27076 - pushl %ecx
27077 + pushl (efi_rt_function_ptr)
27078
27079 /*
27080 - * 10. Push the saved return address onto the stack and return.
27081 + * 10. Return to the saved return address.
27082 */
27083 - leal saved_return_addr, %edx
27084 - movl (%edx), %ecx
27085 - pushl %ecx
27086 - ret
27087 + jmpl *(saved_return_addr)
27088 ENDPROC(efi_call_phys)
27089 .previous
27090
27091 -.data
27092 +__INITDATA
27093 saved_return_addr:
27094 .long 0
27095 efi_rt_function_ptr:
27096 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
27097 index 4c07cca..2c8427d 100644
27098 --- a/arch/x86/platform/efi/efi_stub_64.S
27099 +++ b/arch/x86/platform/efi/efi_stub_64.S
27100 @@ -7,6 +7,7 @@
27101 */
27102
27103 #include <linux/linkage.h>
27104 +#include <asm/alternative-asm.h>
27105
27106 #define SAVE_XMM \
27107 mov %rsp, %rax; \
27108 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
27109 call *%rdi
27110 addq $32, %rsp
27111 RESTORE_XMM
27112 + pax_force_retaddr 0, 1
27113 ret
27114 ENDPROC(efi_call0)
27115
27116 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
27117 call *%rdi
27118 addq $32, %rsp
27119 RESTORE_XMM
27120 + pax_force_retaddr 0, 1
27121 ret
27122 ENDPROC(efi_call1)
27123
27124 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
27125 call *%rdi
27126 addq $32, %rsp
27127 RESTORE_XMM
27128 + pax_force_retaddr 0, 1
27129 ret
27130 ENDPROC(efi_call2)
27131
27132 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
27133 call *%rdi
27134 addq $32, %rsp
27135 RESTORE_XMM
27136 + pax_force_retaddr 0, 1
27137 ret
27138 ENDPROC(efi_call3)
27139
27140 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
27141 call *%rdi
27142 addq $32, %rsp
27143 RESTORE_XMM
27144 + pax_force_retaddr 0, 1
27145 ret
27146 ENDPROC(efi_call4)
27147
27148 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
27149 call *%rdi
27150 addq $48, %rsp
27151 RESTORE_XMM
27152 + pax_force_retaddr 0, 1
27153 ret
27154 ENDPROC(efi_call5)
27155
27156 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
27157 call *%rdi
27158 addq $48, %rsp
27159 RESTORE_XMM
27160 + pax_force_retaddr 0, 1
27161 ret
27162 ENDPROC(efi_call6)
27163 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
27164 index fd41a92..9c33628 100644
27165 --- a/arch/x86/platform/mrst/mrst.c
27166 +++ b/arch/x86/platform/mrst/mrst.c
27167 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
27168 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
27169 int sfi_mrtc_num;
27170
27171 -static void mrst_power_off(void)
27172 +static __noreturn void mrst_power_off(void)
27173 {
27174 + BUG();
27175 }
27176
27177 -static void mrst_reboot(void)
27178 +static __noreturn void mrst_reboot(void)
27179 {
27180 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27181 + BUG();
27182 }
27183
27184 /* parse all the mtimer info to a static mtimer array */
27185 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27186 index 218cdb1..c1178eb 100644
27187 --- a/arch/x86/power/cpu.c
27188 +++ b/arch/x86/power/cpu.c
27189 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
27190 static void fix_processor_context(void)
27191 {
27192 int cpu = smp_processor_id();
27193 - struct tss_struct *t = &per_cpu(init_tss, cpu);
27194 + struct tss_struct *t = init_tss + cpu;
27195
27196 set_tss_desc(cpu, t); /*
27197 * This just modifies memory; should not be
27198 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
27199 */
27200
27201 #ifdef CONFIG_X86_64
27202 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27203 -
27204 syscall_init(); /* This sets MSR_*STAR and related */
27205 #endif
27206 load_TR_desc(); /* This does ltr */
27207 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
27208 index cbca565..bae7133 100644
27209 --- a/arch/x86/realmode/init.c
27210 +++ b/arch/x86/realmode/init.c
27211 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
27212 __va(real_mode_header->trampoline_header);
27213
27214 #ifdef CONFIG_X86_32
27215 - trampoline_header->start = __pa(startup_32_smp);
27216 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
27217 +
27218 +#ifdef CONFIG_PAX_KERNEXEC
27219 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
27220 +#endif
27221 +
27222 + trampoline_header->boot_cs = __BOOT_CS;
27223 trampoline_header->gdt_limit = __BOOT_DS + 7;
27224 trampoline_header->gdt_base = __pa(boot_gdt);
27225 #else
27226 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
27227 index 8869287..d577672 100644
27228 --- a/arch/x86/realmode/rm/Makefile
27229 +++ b/arch/x86/realmode/rm/Makefile
27230 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
27231 $(call cc-option, -fno-unit-at-a-time)) \
27232 $(call cc-option, -fno-stack-protector) \
27233 $(call cc-option, -mpreferred-stack-boundary=2)
27234 +ifdef CONSTIFY_PLUGIN
27235 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
27236 +endif
27237 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
27238 GCOV_PROFILE := n
27239 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
27240 index a28221d..93c40f1 100644
27241 --- a/arch/x86/realmode/rm/header.S
27242 +++ b/arch/x86/realmode/rm/header.S
27243 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
27244 #endif
27245 /* APM/BIOS reboot */
27246 .long pa_machine_real_restart_asm
27247 -#ifdef CONFIG_X86_64
27248 +#ifdef CONFIG_X86_32
27249 + .long __KERNEL_CS
27250 +#else
27251 .long __KERNEL32_CS
27252 #endif
27253 END(real_mode_header)
27254 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
27255 index c1b2791..f9e31c7 100644
27256 --- a/arch/x86/realmode/rm/trampoline_32.S
27257 +++ b/arch/x86/realmode/rm/trampoline_32.S
27258 @@ -25,6 +25,12 @@
27259 #include <asm/page_types.h>
27260 #include "realmode.h"
27261
27262 +#ifdef CONFIG_PAX_KERNEXEC
27263 +#define ta(X) (X)
27264 +#else
27265 +#define ta(X) (pa_ ## X)
27266 +#endif
27267 +
27268 .text
27269 .code16
27270
27271 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
27272
27273 cli # We should be safe anyway
27274
27275 - movl tr_start, %eax # where we need to go
27276 -
27277 movl $0xA5A5A5A5, trampoline_status
27278 # write marker for master knows we're running
27279
27280 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
27281 movw $1, %dx # protected mode (PE) bit
27282 lmsw %dx # into protected mode
27283
27284 - ljmpl $__BOOT_CS, $pa_startup_32
27285 + ljmpl *(trampoline_header)
27286
27287 .section ".text32","ax"
27288 .code32
27289 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
27290 .balign 8
27291 GLOBAL(trampoline_header)
27292 tr_start: .space 4
27293 - tr_gdt_pad: .space 2
27294 + tr_boot_cs: .space 2
27295 tr_gdt: .space 6
27296 END(trampoline_header)
27297
27298 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
27299 index bb360dc..3e5945f 100644
27300 --- a/arch/x86/realmode/rm/trampoline_64.S
27301 +++ b/arch/x86/realmode/rm/trampoline_64.S
27302 @@ -107,7 +107,7 @@ ENTRY(startup_32)
27303 wrmsr
27304
27305 # Enable paging and in turn activate Long Mode
27306 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
27307 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
27308 movl %eax, %cr0
27309
27310 /*
27311 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
27312 index 5a1847d..deccb30 100644
27313 --- a/arch/x86/tools/relocs.c
27314 +++ b/arch/x86/tools/relocs.c
27315 @@ -12,10 +12,13 @@
27316 #include <regex.h>
27317 #include <tools/le_byteshift.h>
27318
27319 +#include "../../../include/generated/autoconf.h"
27320 +
27321 static void die(char *fmt, ...);
27322
27323 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27324 static Elf32_Ehdr ehdr;
27325 +static Elf32_Phdr *phdr;
27326 static unsigned long reloc_count, reloc_idx;
27327 static unsigned long *relocs;
27328 static unsigned long reloc16_count, reloc16_idx;
27329 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
27330 }
27331 }
27332
27333 +static void read_phdrs(FILE *fp)
27334 +{
27335 + unsigned int i;
27336 +
27337 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
27338 + if (!phdr) {
27339 + die("Unable to allocate %d program headers\n",
27340 + ehdr.e_phnum);
27341 + }
27342 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
27343 + die("Seek to %d failed: %s\n",
27344 + ehdr.e_phoff, strerror(errno));
27345 + }
27346 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
27347 + die("Cannot read ELF program headers: %s\n",
27348 + strerror(errno));
27349 + }
27350 + for(i = 0; i < ehdr.e_phnum; i++) {
27351 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
27352 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
27353 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
27354 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
27355 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
27356 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
27357 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
27358 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
27359 + }
27360 +
27361 +}
27362 +
27363 static void read_shdrs(FILE *fp)
27364 {
27365 - int i;
27366 + unsigned int i;
27367 Elf32_Shdr shdr;
27368
27369 secs = calloc(ehdr.e_shnum, sizeof(struct section));
27370 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
27371
27372 static void read_strtabs(FILE *fp)
27373 {
27374 - int i;
27375 + unsigned int i;
27376 for (i = 0; i < ehdr.e_shnum; i++) {
27377 struct section *sec = &secs[i];
27378 if (sec->shdr.sh_type != SHT_STRTAB) {
27379 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
27380
27381 static void read_symtabs(FILE *fp)
27382 {
27383 - int i,j;
27384 + unsigned int i,j;
27385 for (i = 0; i < ehdr.e_shnum; i++) {
27386 struct section *sec = &secs[i];
27387 if (sec->shdr.sh_type != SHT_SYMTAB) {
27388 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
27389 }
27390
27391
27392 -static void read_relocs(FILE *fp)
27393 +static void read_relocs(FILE *fp, int use_real_mode)
27394 {
27395 - int i,j;
27396 + unsigned int i,j;
27397 + uint32_t base;
27398 +
27399 for (i = 0; i < ehdr.e_shnum; i++) {
27400 struct section *sec = &secs[i];
27401 if (sec->shdr.sh_type != SHT_REL) {
27402 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27403 die("Cannot read symbol table: %s\n",
27404 strerror(errno));
27405 }
27406 + base = 0;
27407 +
27408 +#ifdef CONFIG_X86_32
27409 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27410 + if (phdr[j].p_type != PT_LOAD )
27411 + continue;
27412 + 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)
27413 + continue;
27414 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27415 + break;
27416 + }
27417 +#endif
27418 +
27419 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27420 Elf32_Rel *rel = &sec->reltab[j];
27421 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27422 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27423 rel->r_info = elf32_to_cpu(rel->r_info);
27424 }
27425 }
27426 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27427
27428 static void print_absolute_symbols(void)
27429 {
27430 - int i;
27431 + unsigned int i;
27432 printf("Absolute symbols\n");
27433 printf(" Num: Value Size Type Bind Visibility Name\n");
27434 for (i = 0; i < ehdr.e_shnum; i++) {
27435 struct section *sec = &secs[i];
27436 char *sym_strtab;
27437 - int j;
27438 + unsigned int j;
27439
27440 if (sec->shdr.sh_type != SHT_SYMTAB) {
27441 continue;
27442 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27443
27444 static void print_absolute_relocs(void)
27445 {
27446 - int i, printed = 0;
27447 + unsigned int i, printed = 0;
27448
27449 for (i = 0; i < ehdr.e_shnum; i++) {
27450 struct section *sec = &secs[i];
27451 struct section *sec_applies, *sec_symtab;
27452 char *sym_strtab;
27453 Elf32_Sym *sh_symtab;
27454 - int j;
27455 + unsigned int j;
27456 if (sec->shdr.sh_type != SHT_REL) {
27457 continue;
27458 }
27459 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27460 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27461 int use_real_mode)
27462 {
27463 - int i;
27464 + unsigned int i;
27465 /* Walk through the relocations */
27466 for (i = 0; i < ehdr.e_shnum; i++) {
27467 char *sym_strtab;
27468 Elf32_Sym *sh_symtab;
27469 struct section *sec_applies, *sec_symtab;
27470 - int j;
27471 + unsigned int j;
27472 struct section *sec = &secs[i];
27473
27474 if (sec->shdr.sh_type != SHT_REL) {
27475 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27476 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27477 r_type = ELF32_R_TYPE(rel->r_info);
27478
27479 + if (!use_real_mode) {
27480 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27481 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27482 + continue;
27483 +
27484 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27485 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27486 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27487 + continue;
27488 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27489 + continue;
27490 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27491 + continue;
27492 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27493 + continue;
27494 +#endif
27495 + }
27496 +
27497 shn_abs = sym->st_shndx == SHN_ABS;
27498
27499 switch (r_type) {
27500 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27501
27502 static void emit_relocs(int as_text, int use_real_mode)
27503 {
27504 - int i;
27505 + unsigned int i;
27506 /* Count how many relocations I have and allocate space for them. */
27507 reloc_count = 0;
27508 walk_relocs(count_reloc, use_real_mode);
27509 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27510 fname, strerror(errno));
27511 }
27512 read_ehdr(fp);
27513 + read_phdrs(fp);
27514 read_shdrs(fp);
27515 read_strtabs(fp);
27516 read_symtabs(fp);
27517 - read_relocs(fp);
27518 + read_relocs(fp, use_real_mode);
27519 if (show_absolute_syms) {
27520 print_absolute_symbols();
27521 return 0;
27522 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27523 index fd14be1..e3c79c0 100644
27524 --- a/arch/x86/vdso/Makefile
27525 +++ b/arch/x86/vdso/Makefile
27526 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27527 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27528 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27529
27530 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27531 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27532 GCOV_PROFILE := n
27533
27534 #
27535 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27536 index 0faad64..39ef157 100644
27537 --- a/arch/x86/vdso/vdso32-setup.c
27538 +++ b/arch/x86/vdso/vdso32-setup.c
27539 @@ -25,6 +25,7 @@
27540 #include <asm/tlbflush.h>
27541 #include <asm/vdso.h>
27542 #include <asm/proto.h>
27543 +#include <asm/mman.h>
27544
27545 enum {
27546 VDSO_DISABLED = 0,
27547 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27548 void enable_sep_cpu(void)
27549 {
27550 int cpu = get_cpu();
27551 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27552 + struct tss_struct *tss = init_tss + cpu;
27553
27554 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27555 put_cpu();
27556 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27557 gate_vma.vm_start = FIXADDR_USER_START;
27558 gate_vma.vm_end = FIXADDR_USER_END;
27559 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27560 - gate_vma.vm_page_prot = __P101;
27561 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27562
27563 return 0;
27564 }
27565 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27566 if (compat)
27567 addr = VDSO_HIGH_BASE;
27568 else {
27569 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27570 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27571 if (IS_ERR_VALUE(addr)) {
27572 ret = addr;
27573 goto up_fail;
27574 }
27575 }
27576
27577 - current->mm->context.vdso = (void *)addr;
27578 + current->mm->context.vdso = addr;
27579
27580 if (compat_uses_vma || !compat) {
27581 /*
27582 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27583 }
27584
27585 current_thread_info()->sysenter_return =
27586 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27587 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27588
27589 up_fail:
27590 if (ret)
27591 - current->mm->context.vdso = NULL;
27592 + current->mm->context.vdso = 0;
27593
27594 up_write(&mm->mmap_sem);
27595
27596 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27597
27598 const char *arch_vma_name(struct vm_area_struct *vma)
27599 {
27600 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27601 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27602 return "[vdso]";
27603 +
27604 +#ifdef CONFIG_PAX_SEGMEXEC
27605 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27606 + return "[vdso]";
27607 +#endif
27608 +
27609 return NULL;
27610 }
27611
27612 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27613 * Check to see if the corresponding task was created in compat vdso
27614 * mode.
27615 */
27616 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27617 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27618 return &gate_vma;
27619 return NULL;
27620 }
27621 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27622 index 00aaf04..4a26505 100644
27623 --- a/arch/x86/vdso/vma.c
27624 +++ b/arch/x86/vdso/vma.c
27625 @@ -16,8 +16,6 @@
27626 #include <asm/vdso.h>
27627 #include <asm/page.h>
27628
27629 -unsigned int __read_mostly vdso_enabled = 1;
27630 -
27631 extern char vdso_start[], vdso_end[];
27632 extern unsigned short vdso_sync_cpuid;
27633
27634 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27635 * unaligned here as a result of stack start randomization.
27636 */
27637 addr = PAGE_ALIGN(addr);
27638 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27639
27640 return addr;
27641 }
27642 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27643 unsigned size)
27644 {
27645 struct mm_struct *mm = current->mm;
27646 - unsigned long addr;
27647 + unsigned long addr = 0;
27648 int ret;
27649
27650 - if (!vdso_enabled)
27651 - return 0;
27652 -
27653 down_write(&mm->mmap_sem);
27654 +
27655 +#ifdef CONFIG_PAX_RANDMMAP
27656 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27657 +#endif
27658 +
27659 addr = vdso_addr(mm->start_stack, size);
27660 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27661 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27662 if (IS_ERR_VALUE(addr)) {
27663 ret = addr;
27664 goto up_fail;
27665 }
27666
27667 - current->mm->context.vdso = (void *)addr;
27668 + mm->context.vdso = addr;
27669
27670 ret = install_special_mapping(mm, addr, size,
27671 VM_READ|VM_EXEC|
27672 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27673 pages);
27674 - if (ret) {
27675 - current->mm->context.vdso = NULL;
27676 - goto up_fail;
27677 - }
27678 + if (ret)
27679 + mm->context.vdso = 0;
27680
27681 up_fail:
27682 up_write(&mm->mmap_sem);
27683 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27684 vdsox32_size);
27685 }
27686 #endif
27687 -
27688 -static __init int vdso_setup(char *s)
27689 -{
27690 - vdso_enabled = simple_strtoul(s, NULL, 0);
27691 - return 0;
27692 -}
27693 -__setup("vdso=", vdso_setup);
27694 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27695 index 586d838..38cb3ff 100644
27696 --- a/arch/x86/xen/enlighten.c
27697 +++ b/arch/x86/xen/enlighten.c
27698 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27699
27700 struct shared_info xen_dummy_shared_info;
27701
27702 -void *xen_initial_gdt;
27703 -
27704 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27705 __read_mostly int xen_have_vector_callback;
27706 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27707 @@ -918,21 +916,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27708
27709 static void set_xen_basic_apic_ops(void)
27710 {
27711 - apic->read = xen_apic_read;
27712 - apic->write = xen_apic_write;
27713 - apic->icr_read = xen_apic_icr_read;
27714 - apic->icr_write = xen_apic_icr_write;
27715 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27716 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27717 - apic->set_apic_id = xen_set_apic_id;
27718 - apic->get_apic_id = xen_get_apic_id;
27719 + *(void **)&apic->read = xen_apic_read;
27720 + *(void **)&apic->write = xen_apic_write;
27721 + *(void **)&apic->icr_read = xen_apic_icr_read;
27722 + *(void **)&apic->icr_write = xen_apic_icr_write;
27723 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27724 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27725 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27726 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27727
27728 #ifdef CONFIG_SMP
27729 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27730 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27731 - apic->send_IPI_mask = xen_send_IPI_mask;
27732 - apic->send_IPI_all = xen_send_IPI_all;
27733 - apic->send_IPI_self = xen_send_IPI_self;
27734 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27735 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27736 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27737 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27738 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27739 #endif
27740 }
27741
27742 @@ -1222,30 +1220,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27743 #endif
27744 };
27745
27746 -static void xen_reboot(int reason)
27747 +static __noreturn void xen_reboot(int reason)
27748 {
27749 struct sched_shutdown r = { .reason = reason };
27750
27751 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27752 - BUG();
27753 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27754 + BUG();
27755 }
27756
27757 -static void xen_restart(char *msg)
27758 +static __noreturn void xen_restart(char *msg)
27759 {
27760 xen_reboot(SHUTDOWN_reboot);
27761 }
27762
27763 -static void xen_emergency_restart(void)
27764 +static __noreturn void xen_emergency_restart(void)
27765 {
27766 xen_reboot(SHUTDOWN_reboot);
27767 }
27768
27769 -static void xen_machine_halt(void)
27770 +static __noreturn void xen_machine_halt(void)
27771 {
27772 xen_reboot(SHUTDOWN_poweroff);
27773 }
27774
27775 -static void xen_machine_power_off(void)
27776 +static __noreturn void xen_machine_power_off(void)
27777 {
27778 if (pm_power_off)
27779 pm_power_off();
27780 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27781 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27782
27783 /* Work out if we support NX */
27784 - x86_configure_nx();
27785 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27786 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27787 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27788 + unsigned l, h;
27789 +
27790 + __supported_pte_mask |= _PAGE_NX;
27791 + rdmsr(MSR_EFER, l, h);
27792 + l |= EFER_NX;
27793 + wrmsr(MSR_EFER, l, h);
27794 + }
27795 +#endif
27796
27797 xen_setup_features();
27798
27799 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27800
27801 machine_ops = xen_machine_ops;
27802
27803 - /*
27804 - * The only reliable way to retain the initial address of the
27805 - * percpu gdt_page is to remember it here, so we can go and
27806 - * mark it RW later, when the initial percpu area is freed.
27807 - */
27808 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27809 -
27810 xen_smp_init();
27811
27812 #ifdef CONFIG_ACPI_NUMA
27813 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27814 index dcf5f2d..d804c25 100644
27815 --- a/arch/x86/xen/mmu.c
27816 +++ b/arch/x86/xen/mmu.c
27817 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
27818 /* L3_k[510] -> level2_kernel_pgt
27819 * L3_i[511] -> level2_fixmap_pgt */
27820 convert_pfn_mfn(level3_kernel_pgt);
27821 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27822 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27823 + convert_pfn_mfn(level3_vmemmap_pgt);
27824
27825 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
27826 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27827 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
27828 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27829 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27830 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27831 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27832 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27833 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27834 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27835 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
27836 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27837 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27838 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27839
27840 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
27841 pv_mmu_ops.set_pud = xen_set_pud;
27842 #if PAGETABLE_LEVELS == 4
27843 pv_mmu_ops.set_pgd = xen_set_pgd;
27844 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27845 #endif
27846
27847 /* This will work as long as patching hasn't happened yet
27848 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27849 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27850 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27851 .set_pgd = xen_set_pgd_hyper,
27852 + .set_pgd_batched = xen_set_pgd_hyper,
27853
27854 .alloc_pud = xen_alloc_pmd_init,
27855 .release_pud = xen_release_pmd_init,
27856 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27857 index 353c50f..5b7cb95 100644
27858 --- a/arch/x86/xen/smp.c
27859 +++ b/arch/x86/xen/smp.c
27860 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27861 {
27862 BUG_ON(smp_processor_id() != 0);
27863 native_smp_prepare_boot_cpu();
27864 -
27865 - /* We've switched to the "real" per-cpu gdt, so make sure the
27866 - old memory can be recycled */
27867 - make_lowmem_page_readwrite(xen_initial_gdt);
27868 -
27869 xen_filter_cpu_maps();
27870 xen_setup_vcpu_info_placement();
27871 }
27872 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27873 gdt = get_cpu_gdt_table(cpu);
27874
27875 ctxt->flags = VGCF_IN_KERNEL;
27876 - ctxt->user_regs.ds = __USER_DS;
27877 - ctxt->user_regs.es = __USER_DS;
27878 + ctxt->user_regs.ds = __KERNEL_DS;
27879 + ctxt->user_regs.es = __KERNEL_DS;
27880 ctxt->user_regs.ss = __KERNEL_DS;
27881 #ifdef CONFIG_X86_32
27882 ctxt->user_regs.fs = __KERNEL_PERCPU;
27883 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27884 + savesegment(gs, ctxt->user_regs.gs);
27885 #else
27886 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27887 #endif
27888 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27889 int rc;
27890
27891 per_cpu(current_task, cpu) = idle;
27892 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27893 #ifdef CONFIG_X86_32
27894 irq_ctx_init(cpu);
27895 #else
27896 clear_tsk_thread_flag(idle, TIF_FORK);
27897 - per_cpu(kernel_stack, cpu) =
27898 - (unsigned long)task_stack_page(idle) -
27899 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27900 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27901 #endif
27902 xen_setup_runstate_info(cpu);
27903 xen_setup_timer(cpu);
27904 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27905 index f9643fc..602e8af 100644
27906 --- a/arch/x86/xen/xen-asm_32.S
27907 +++ b/arch/x86/xen/xen-asm_32.S
27908 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27909 ESP_OFFSET=4 # bytes pushed onto stack
27910
27911 /*
27912 - * Store vcpu_info pointer for easy access. Do it this way to
27913 - * avoid having to reload %fs
27914 + * Store vcpu_info pointer for easy access.
27915 */
27916 #ifdef CONFIG_SMP
27917 - GET_THREAD_INFO(%eax)
27918 - movl TI_cpu(%eax), %eax
27919 - movl __per_cpu_offset(,%eax,4), %eax
27920 - mov xen_vcpu(%eax), %eax
27921 + push %fs
27922 + mov $(__KERNEL_PERCPU), %eax
27923 + mov %eax, %fs
27924 + mov PER_CPU_VAR(xen_vcpu), %eax
27925 + pop %fs
27926 #else
27927 movl xen_vcpu, %eax
27928 #endif
27929 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27930 index 7faed58..ba4427c 100644
27931 --- a/arch/x86/xen/xen-head.S
27932 +++ b/arch/x86/xen/xen-head.S
27933 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27934 #ifdef CONFIG_X86_32
27935 mov %esi,xen_start_info
27936 mov $init_thread_union+THREAD_SIZE,%esp
27937 +#ifdef CONFIG_SMP
27938 + movl $cpu_gdt_table,%edi
27939 + movl $__per_cpu_load,%eax
27940 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27941 + rorl $16,%eax
27942 + movb %al,__KERNEL_PERCPU + 4(%edi)
27943 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27944 + movl $__per_cpu_end - 1,%eax
27945 + subl $__per_cpu_start,%eax
27946 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27947 +#endif
27948 #else
27949 mov %rsi,xen_start_info
27950 mov $init_thread_union+THREAD_SIZE,%rsp
27951 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27952 index a95b417..b6dbd0b 100644
27953 --- a/arch/x86/xen/xen-ops.h
27954 +++ b/arch/x86/xen/xen-ops.h
27955 @@ -10,8 +10,6 @@
27956 extern const char xen_hypervisor_callback[];
27957 extern const char xen_failsafe_callback[];
27958
27959 -extern void *xen_initial_gdt;
27960 -
27961 struct trap_info;
27962 void xen_copy_trap_info(struct trap_info *traps);
27963
27964 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27965 index 525bd3d..ef888b1 100644
27966 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27967 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27968 @@ -119,9 +119,9 @@
27969 ----------------------------------------------------------------------*/
27970
27971 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27972 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27973 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27974 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27975 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27976
27977 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27978 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27979 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27980 index 2f33760..835e50a 100644
27981 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27982 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27983 @@ -11,6 +11,7 @@
27984 #ifndef _XTENSA_CORE_H
27985 #define _XTENSA_CORE_H
27986
27987 +#include <linux/const.h>
27988
27989 /****************************************************************************
27990 Parameters Useful for Any Code, USER or PRIVILEGED
27991 @@ -112,9 +113,9 @@
27992 ----------------------------------------------------------------------*/
27993
27994 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27995 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27996 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27997 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27998 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27999
28000 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
28001 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
28002 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
28003 index af00795..2bb8105 100644
28004 --- a/arch/xtensa/variants/s6000/include/variant/core.h
28005 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
28006 @@ -11,6 +11,7 @@
28007 #ifndef _XTENSA_CORE_CONFIGURATION_H
28008 #define _XTENSA_CORE_CONFIGURATION_H
28009
28010 +#include <linux/const.h>
28011
28012 /****************************************************************************
28013 Parameters Useful for Any Code, USER or PRIVILEGED
28014 @@ -118,9 +119,9 @@
28015 ----------------------------------------------------------------------*/
28016
28017 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
28018 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
28019 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
28020 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
28021 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
28022
28023 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
28024 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
28025 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
28026 index 58916af..9cb880b 100644
28027 --- a/block/blk-iopoll.c
28028 +++ b/block/blk-iopoll.c
28029 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
28030 }
28031 EXPORT_SYMBOL(blk_iopoll_complete);
28032
28033 -static void blk_iopoll_softirq(struct softirq_action *h)
28034 +static void blk_iopoll_softirq(void)
28035 {
28036 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
28037 int rearm = 0, budget = blk_iopoll_budget;
28038 diff --git a/block/blk-map.c b/block/blk-map.c
28039 index 623e1cd..ca1e109 100644
28040 --- a/block/blk-map.c
28041 +++ b/block/blk-map.c
28042 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
28043 if (!len || !kbuf)
28044 return -EINVAL;
28045
28046 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
28047 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
28048 if (do_copy)
28049 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
28050 else
28051 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
28052 index 467c8de..4bddc6d 100644
28053 --- a/block/blk-softirq.c
28054 +++ b/block/blk-softirq.c
28055 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
28056 * Softirq action handler - move entries to local list and loop over them
28057 * while passing them to the queue registered handler.
28058 */
28059 -static void blk_done_softirq(struct softirq_action *h)
28060 +static void blk_done_softirq(void)
28061 {
28062 struct list_head *cpu_list, local_list;
28063
28064 diff --git a/block/bsg.c b/block/bsg.c
28065 index ff64ae3..593560c 100644
28066 --- a/block/bsg.c
28067 +++ b/block/bsg.c
28068 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
28069 struct sg_io_v4 *hdr, struct bsg_device *bd,
28070 fmode_t has_write_perm)
28071 {
28072 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28073 + unsigned char *cmdptr;
28074 +
28075 if (hdr->request_len > BLK_MAX_CDB) {
28076 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
28077 if (!rq->cmd)
28078 return -ENOMEM;
28079 - }
28080 + cmdptr = rq->cmd;
28081 + } else
28082 + cmdptr = tmpcmd;
28083
28084 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
28085 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
28086 hdr->request_len))
28087 return -EFAULT;
28088
28089 + if (cmdptr != rq->cmd)
28090 + memcpy(rq->cmd, cmdptr, hdr->request_len);
28091 +
28092 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
28093 if (blk_verify_command(rq->cmd, has_write_perm))
28094 return -EPERM;
28095 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
28096 index 7c668c8..db3521c 100644
28097 --- a/block/compat_ioctl.c
28098 +++ b/block/compat_ioctl.c
28099 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
28100 err |= __get_user(f->spec1, &uf->spec1);
28101 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
28102 err |= __get_user(name, &uf->name);
28103 - f->name = compat_ptr(name);
28104 + f->name = (void __force_kernel *)compat_ptr(name);
28105 if (err) {
28106 err = -EFAULT;
28107 goto out;
28108 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
28109 index 6296b40..417c00f 100644
28110 --- a/block/partitions/efi.c
28111 +++ b/block/partitions/efi.c
28112 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
28113 if (!gpt)
28114 return NULL;
28115
28116 + if (!le32_to_cpu(gpt->num_partition_entries))
28117 + return NULL;
28118 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
28119 + if (!pte)
28120 + return NULL;
28121 +
28122 count = le32_to_cpu(gpt->num_partition_entries) *
28123 le32_to_cpu(gpt->sizeof_partition_entry);
28124 - if (!count)
28125 - return NULL;
28126 - pte = kzalloc(count, GFP_KERNEL);
28127 - if (!pte)
28128 - return NULL;
28129 -
28130 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
28131 (u8 *) pte,
28132 count) < count) {
28133 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
28134 index 9a87daa..fb17486 100644
28135 --- a/block/scsi_ioctl.c
28136 +++ b/block/scsi_ioctl.c
28137 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
28138 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
28139 struct sg_io_hdr *hdr, fmode_t mode)
28140 {
28141 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
28142 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28143 + unsigned char *cmdptr;
28144 +
28145 + if (rq->cmd != rq->__cmd)
28146 + cmdptr = rq->cmd;
28147 + else
28148 + cmdptr = tmpcmd;
28149 +
28150 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
28151 return -EFAULT;
28152 +
28153 + if (cmdptr != rq->cmd)
28154 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
28155 +
28156 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
28157 return -EPERM;
28158
28159 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28160 int err;
28161 unsigned int in_len, out_len, bytes, opcode, cmdlen;
28162 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
28163 + unsigned char tmpcmd[sizeof(rq->__cmd)];
28164 + unsigned char *cmdptr;
28165
28166 if (!sic)
28167 return -EINVAL;
28168 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
28169 */
28170 err = -EFAULT;
28171 rq->cmd_len = cmdlen;
28172 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
28173 +
28174 + if (rq->cmd != rq->__cmd)
28175 + cmdptr = rq->cmd;
28176 + else
28177 + cmdptr = tmpcmd;
28178 +
28179 + if (copy_from_user(cmdptr, sic->data, cmdlen))
28180 goto error;
28181
28182 + if (rq->cmd != cmdptr)
28183 + memcpy(rq->cmd, cmdptr, cmdlen);
28184 +
28185 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
28186 goto error;
28187
28188 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
28189 index 7bdd61b..afec999 100644
28190 --- a/crypto/cryptd.c
28191 +++ b/crypto/cryptd.c
28192 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
28193
28194 struct cryptd_blkcipher_request_ctx {
28195 crypto_completion_t complete;
28196 -};
28197 +} __no_const;
28198
28199 struct cryptd_hash_ctx {
28200 struct crypto_shash *child;
28201 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
28202
28203 struct cryptd_aead_request_ctx {
28204 crypto_completion_t complete;
28205 -};
28206 +} __no_const;
28207
28208 static void cryptd_queue_worker(struct work_struct *work);
28209
28210 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
28211 index e6defd8..c26a225 100644
28212 --- a/drivers/acpi/apei/cper.c
28213 +++ b/drivers/acpi/apei/cper.c
28214 @@ -38,12 +38,12 @@
28215 */
28216 u64 cper_next_record_id(void)
28217 {
28218 - static atomic64_t seq;
28219 + static atomic64_unchecked_t seq;
28220
28221 - if (!atomic64_read(&seq))
28222 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
28223 + if (!atomic64_read_unchecked(&seq))
28224 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
28225
28226 - return atomic64_inc_return(&seq);
28227 + return atomic64_inc_return_unchecked(&seq);
28228 }
28229 EXPORT_SYMBOL_GPL(cper_next_record_id);
28230
28231 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
28232 index 7586544..636a2f0 100644
28233 --- a/drivers/acpi/ec_sys.c
28234 +++ b/drivers/acpi/ec_sys.c
28235 @@ -12,6 +12,7 @@
28236 #include <linux/acpi.h>
28237 #include <linux/debugfs.h>
28238 #include <linux/module.h>
28239 +#include <linux/uaccess.h>
28240 #include "internal.h"
28241
28242 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
28243 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28244 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
28245 */
28246 unsigned int size = EC_SPACE_SIZE;
28247 - u8 *data = (u8 *) buf;
28248 + u8 data;
28249 loff_t init_off = *off;
28250 int err = 0;
28251
28252 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
28253 size = count;
28254
28255 while (size) {
28256 - err = ec_read(*off, &data[*off - init_off]);
28257 + err = ec_read(*off, &data);
28258 if (err)
28259 return err;
28260 + if (put_user(data, &buf[*off - init_off]))
28261 + return -EFAULT;
28262 *off += 1;
28263 size--;
28264 }
28265 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28266
28267 unsigned int size = count;
28268 loff_t init_off = *off;
28269 - u8 *data = (u8 *) buf;
28270 int err = 0;
28271
28272 if (*off >= EC_SPACE_SIZE)
28273 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28274 }
28275
28276 while (size) {
28277 - u8 byte_write = data[*off - init_off];
28278 + u8 byte_write;
28279 + if (get_user(byte_write, &buf[*off - init_off]))
28280 + return -EFAULT;
28281 err = ec_write(*off, byte_write);
28282 if (err)
28283 return err;
28284 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28285 index 27adb09..1ed412d 100644
28286 --- a/drivers/acpi/proc.c
28287 +++ b/drivers/acpi/proc.c
28288 @@ -360,19 +360,13 @@ acpi_system_write_wakeup_device(struct file *file,
28289 size_t count, loff_t * ppos)
28290 {
28291 struct list_head *node, *next;
28292 - char strbuf[5];
28293 - char str[5] = "";
28294 - unsigned int len = count;
28295 + char strbuf[5] = {0};
28296
28297 - if (len > 4)
28298 - len = 4;
28299 - if (len < 0)
28300 + if (count > 4)
28301 + count = 4;
28302 + if (copy_from_user(strbuf, buffer, count))
28303 return -EFAULT;
28304 -
28305 - if (copy_from_user(strbuf, buffer, len))
28306 - return -EFAULT;
28307 - strbuf[len] = '\0';
28308 - sscanf(strbuf, "%s", str);
28309 + strbuf[count] = '\0';
28310
28311 mutex_lock(&acpi_device_lock);
28312 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28313 @@ -381,7 +375,7 @@ acpi_system_write_wakeup_device(struct file *file,
28314 if (!dev->wakeup.flags.valid)
28315 continue;
28316
28317 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
28318 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28319 if (device_can_wakeup(&dev->dev)) {
28320 bool enable = !device_may_wakeup(&dev->dev);
28321 device_set_wakeup_enable(&dev->dev, enable);
28322 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28323 index bd4e5dc..0497b66 100644
28324 --- a/drivers/acpi/processor_driver.c
28325 +++ b/drivers/acpi/processor_driver.c
28326 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28327 return 0;
28328 #endif
28329
28330 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28331 + BUG_ON(pr->id >= nr_cpu_ids);
28332
28333 /*
28334 * Buggy BIOS check
28335 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28336 index f46fbd3..b8341f3 100644
28337 --- a/drivers/ata/libata-core.c
28338 +++ b/drivers/ata/libata-core.c
28339 @@ -4774,7 +4774,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28340 struct ata_port *ap;
28341 unsigned int tag;
28342
28343 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28344 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28345 ap = qc->ap;
28346
28347 qc->flags = 0;
28348 @@ -4790,7 +4790,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28349 struct ata_port *ap;
28350 struct ata_link *link;
28351
28352 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28353 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28354 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28355 ap = qc->ap;
28356 link = qc->dev->link;
28357 @@ -5886,6 +5886,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28358 return;
28359
28360 spin_lock(&lock);
28361 + pax_open_kernel();
28362
28363 for (cur = ops->inherits; cur; cur = cur->inherits) {
28364 void **inherit = (void **)cur;
28365 @@ -5899,8 +5900,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28366 if (IS_ERR(*pp))
28367 *pp = NULL;
28368
28369 - ops->inherits = NULL;
28370 + *(struct ata_port_operations **)&ops->inherits = NULL;
28371
28372 + pax_close_kernel();
28373 spin_unlock(&lock);
28374 }
28375
28376 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28377 index 371fd2c..0836c78 100644
28378 --- a/drivers/ata/pata_arasan_cf.c
28379 +++ b/drivers/ata/pata_arasan_cf.c
28380 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28381 /* Handle platform specific quirks */
28382 if (pdata->quirk) {
28383 if (pdata->quirk & CF_BROKEN_PIO) {
28384 - ap->ops->set_piomode = NULL;
28385 + pax_open_kernel();
28386 + *(void **)&ap->ops->set_piomode = NULL;
28387 + pax_close_kernel();
28388 ap->pio_mask = 0;
28389 }
28390 if (pdata->quirk & CF_BROKEN_MWDMA)
28391 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28392 index f9b983a..887b9d8 100644
28393 --- a/drivers/atm/adummy.c
28394 +++ b/drivers/atm/adummy.c
28395 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28396 vcc->pop(vcc, skb);
28397 else
28398 dev_kfree_skb_any(skb);
28399 - atomic_inc(&vcc->stats->tx);
28400 + atomic_inc_unchecked(&vcc->stats->tx);
28401
28402 return 0;
28403 }
28404 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28405 index ff7bb8a..568fc0b 100644
28406 --- a/drivers/atm/ambassador.c
28407 +++ b/drivers/atm/ambassador.c
28408 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28409 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28410
28411 // VC layer stats
28412 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28413 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28414
28415 // free the descriptor
28416 kfree (tx_descr);
28417 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28418 dump_skb ("<<<", vc, skb);
28419
28420 // VC layer stats
28421 - atomic_inc(&atm_vcc->stats->rx);
28422 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28423 __net_timestamp(skb);
28424 // end of our responsibility
28425 atm_vcc->push (atm_vcc, skb);
28426 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28427 } else {
28428 PRINTK (KERN_INFO, "dropped over-size frame");
28429 // should we count this?
28430 - atomic_inc(&atm_vcc->stats->rx_drop);
28431 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28432 }
28433
28434 } else {
28435 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28436 }
28437
28438 if (check_area (skb->data, skb->len)) {
28439 - atomic_inc(&atm_vcc->stats->tx_err);
28440 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28441 return -ENOMEM; // ?
28442 }
28443
28444 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28445 index b22d71c..d6e1049 100644
28446 --- a/drivers/atm/atmtcp.c
28447 +++ b/drivers/atm/atmtcp.c
28448 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28449 if (vcc->pop) vcc->pop(vcc,skb);
28450 else dev_kfree_skb(skb);
28451 if (dev_data) return 0;
28452 - atomic_inc(&vcc->stats->tx_err);
28453 + atomic_inc_unchecked(&vcc->stats->tx_err);
28454 return -ENOLINK;
28455 }
28456 size = skb->len+sizeof(struct atmtcp_hdr);
28457 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28458 if (!new_skb) {
28459 if (vcc->pop) vcc->pop(vcc,skb);
28460 else dev_kfree_skb(skb);
28461 - atomic_inc(&vcc->stats->tx_err);
28462 + atomic_inc_unchecked(&vcc->stats->tx_err);
28463 return -ENOBUFS;
28464 }
28465 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28466 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28467 if (vcc->pop) vcc->pop(vcc,skb);
28468 else dev_kfree_skb(skb);
28469 out_vcc->push(out_vcc,new_skb);
28470 - atomic_inc(&vcc->stats->tx);
28471 - atomic_inc(&out_vcc->stats->rx);
28472 + atomic_inc_unchecked(&vcc->stats->tx);
28473 + atomic_inc_unchecked(&out_vcc->stats->rx);
28474 return 0;
28475 }
28476
28477 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28478 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28479 read_unlock(&vcc_sklist_lock);
28480 if (!out_vcc) {
28481 - atomic_inc(&vcc->stats->tx_err);
28482 + atomic_inc_unchecked(&vcc->stats->tx_err);
28483 goto done;
28484 }
28485 skb_pull(skb,sizeof(struct atmtcp_hdr));
28486 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28487 __net_timestamp(new_skb);
28488 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28489 out_vcc->push(out_vcc,new_skb);
28490 - atomic_inc(&vcc->stats->tx);
28491 - atomic_inc(&out_vcc->stats->rx);
28492 + atomic_inc_unchecked(&vcc->stats->tx);
28493 + atomic_inc_unchecked(&out_vcc->stats->rx);
28494 done:
28495 if (vcc->pop) vcc->pop(vcc,skb);
28496 else dev_kfree_skb(skb);
28497 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28498 index 81e44f7..498ea36 100644
28499 --- a/drivers/atm/eni.c
28500 +++ b/drivers/atm/eni.c
28501 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28502 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28503 vcc->dev->number);
28504 length = 0;
28505 - atomic_inc(&vcc->stats->rx_err);
28506 + atomic_inc_unchecked(&vcc->stats->rx_err);
28507 }
28508 else {
28509 length = ATM_CELL_SIZE-1; /* no HEC */
28510 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28511 size);
28512 }
28513 eff = length = 0;
28514 - atomic_inc(&vcc->stats->rx_err);
28515 + atomic_inc_unchecked(&vcc->stats->rx_err);
28516 }
28517 else {
28518 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28519 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28520 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28521 vcc->dev->number,vcc->vci,length,size << 2,descr);
28522 length = eff = 0;
28523 - atomic_inc(&vcc->stats->rx_err);
28524 + atomic_inc_unchecked(&vcc->stats->rx_err);
28525 }
28526 }
28527 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28528 @@ -767,7 +767,7 @@ rx_dequeued++;
28529 vcc->push(vcc,skb);
28530 pushed++;
28531 }
28532 - atomic_inc(&vcc->stats->rx);
28533 + atomic_inc_unchecked(&vcc->stats->rx);
28534 }
28535 wake_up(&eni_dev->rx_wait);
28536 }
28537 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28538 PCI_DMA_TODEVICE);
28539 if (vcc->pop) vcc->pop(vcc,skb);
28540 else dev_kfree_skb_irq(skb);
28541 - atomic_inc(&vcc->stats->tx);
28542 + atomic_inc_unchecked(&vcc->stats->tx);
28543 wake_up(&eni_dev->tx_wait);
28544 dma_complete++;
28545 }
28546 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28547 index 86fed1b..6dc4721 100644
28548 --- a/drivers/atm/firestream.c
28549 +++ b/drivers/atm/firestream.c
28550 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28551 }
28552 }
28553
28554 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28555 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28556
28557 fs_dprintk (FS_DEBUG_TXMEM, "i");
28558 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28559 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28560 #endif
28561 skb_put (skb, qe->p1 & 0xffff);
28562 ATM_SKB(skb)->vcc = atm_vcc;
28563 - atomic_inc(&atm_vcc->stats->rx);
28564 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28565 __net_timestamp(skb);
28566 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28567 atm_vcc->push (atm_vcc, skb);
28568 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28569 kfree (pe);
28570 }
28571 if (atm_vcc)
28572 - atomic_inc(&atm_vcc->stats->rx_drop);
28573 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28574 break;
28575 case 0x1f: /* Reassembly abort: no buffers. */
28576 /* Silently increment error counter. */
28577 if (atm_vcc)
28578 - atomic_inc(&atm_vcc->stats->rx_drop);
28579 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28580 break;
28581 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28582 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28583 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28584 index 361f5ae..7fc552d 100644
28585 --- a/drivers/atm/fore200e.c
28586 +++ b/drivers/atm/fore200e.c
28587 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28588 #endif
28589 /* check error condition */
28590 if (*entry->status & STATUS_ERROR)
28591 - atomic_inc(&vcc->stats->tx_err);
28592 + atomic_inc_unchecked(&vcc->stats->tx_err);
28593 else
28594 - atomic_inc(&vcc->stats->tx);
28595 + atomic_inc_unchecked(&vcc->stats->tx);
28596 }
28597 }
28598
28599 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28600 if (skb == NULL) {
28601 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28602
28603 - atomic_inc(&vcc->stats->rx_drop);
28604 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28605 return -ENOMEM;
28606 }
28607
28608 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28609
28610 dev_kfree_skb_any(skb);
28611
28612 - atomic_inc(&vcc->stats->rx_drop);
28613 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28614 return -ENOMEM;
28615 }
28616
28617 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28618
28619 vcc->push(vcc, skb);
28620 - atomic_inc(&vcc->stats->rx);
28621 + atomic_inc_unchecked(&vcc->stats->rx);
28622
28623 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28624
28625 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28626 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28627 fore200e->atm_dev->number,
28628 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28629 - atomic_inc(&vcc->stats->rx_err);
28630 + atomic_inc_unchecked(&vcc->stats->rx_err);
28631 }
28632 }
28633
28634 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28635 goto retry_here;
28636 }
28637
28638 - atomic_inc(&vcc->stats->tx_err);
28639 + atomic_inc_unchecked(&vcc->stats->tx_err);
28640
28641 fore200e->tx_sat++;
28642 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28643 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28644 index b182c2f..1c6fa8a 100644
28645 --- a/drivers/atm/he.c
28646 +++ b/drivers/atm/he.c
28647 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28648
28649 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28650 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28651 - atomic_inc(&vcc->stats->rx_drop);
28652 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28653 goto return_host_buffers;
28654 }
28655
28656 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28657 RBRQ_LEN_ERR(he_dev->rbrq_head)
28658 ? "LEN_ERR" : "",
28659 vcc->vpi, vcc->vci);
28660 - atomic_inc(&vcc->stats->rx_err);
28661 + atomic_inc_unchecked(&vcc->stats->rx_err);
28662 goto return_host_buffers;
28663 }
28664
28665 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28666 vcc->push(vcc, skb);
28667 spin_lock(&he_dev->global_lock);
28668
28669 - atomic_inc(&vcc->stats->rx);
28670 + atomic_inc_unchecked(&vcc->stats->rx);
28671
28672 return_host_buffers:
28673 ++pdus_assembled;
28674 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28675 tpd->vcc->pop(tpd->vcc, tpd->skb);
28676 else
28677 dev_kfree_skb_any(tpd->skb);
28678 - atomic_inc(&tpd->vcc->stats->tx_err);
28679 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28680 }
28681 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28682 return;
28683 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28684 vcc->pop(vcc, skb);
28685 else
28686 dev_kfree_skb_any(skb);
28687 - atomic_inc(&vcc->stats->tx_err);
28688 + atomic_inc_unchecked(&vcc->stats->tx_err);
28689 return -EINVAL;
28690 }
28691
28692 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28693 vcc->pop(vcc, skb);
28694 else
28695 dev_kfree_skb_any(skb);
28696 - atomic_inc(&vcc->stats->tx_err);
28697 + atomic_inc_unchecked(&vcc->stats->tx_err);
28698 return -EINVAL;
28699 }
28700 #endif
28701 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28702 vcc->pop(vcc, skb);
28703 else
28704 dev_kfree_skb_any(skb);
28705 - atomic_inc(&vcc->stats->tx_err);
28706 + atomic_inc_unchecked(&vcc->stats->tx_err);
28707 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28708 return -ENOMEM;
28709 }
28710 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28711 vcc->pop(vcc, skb);
28712 else
28713 dev_kfree_skb_any(skb);
28714 - atomic_inc(&vcc->stats->tx_err);
28715 + atomic_inc_unchecked(&vcc->stats->tx_err);
28716 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28717 return -ENOMEM;
28718 }
28719 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28720 __enqueue_tpd(he_dev, tpd, cid);
28721 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28722
28723 - atomic_inc(&vcc->stats->tx);
28724 + atomic_inc_unchecked(&vcc->stats->tx);
28725
28726 return 0;
28727 }
28728 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28729 index 7d01c2a..4e3ac01 100644
28730 --- a/drivers/atm/horizon.c
28731 +++ b/drivers/atm/horizon.c
28732 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28733 {
28734 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28735 // VC layer stats
28736 - atomic_inc(&vcc->stats->rx);
28737 + atomic_inc_unchecked(&vcc->stats->rx);
28738 __net_timestamp(skb);
28739 // end of our responsibility
28740 vcc->push (vcc, skb);
28741 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28742 dev->tx_iovec = NULL;
28743
28744 // VC layer stats
28745 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28746 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28747
28748 // free the skb
28749 hrz_kfree_skb (skb);
28750 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28751 index 8974bd2..b856f85 100644
28752 --- a/drivers/atm/idt77252.c
28753 +++ b/drivers/atm/idt77252.c
28754 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28755 else
28756 dev_kfree_skb(skb);
28757
28758 - atomic_inc(&vcc->stats->tx);
28759 + atomic_inc_unchecked(&vcc->stats->tx);
28760 }
28761
28762 atomic_dec(&scq->used);
28763 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28764 if ((sb = dev_alloc_skb(64)) == NULL) {
28765 printk("%s: Can't allocate buffers for aal0.\n",
28766 card->name);
28767 - atomic_add(i, &vcc->stats->rx_drop);
28768 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28769 break;
28770 }
28771 if (!atm_charge(vcc, sb->truesize)) {
28772 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28773 card->name);
28774 - atomic_add(i - 1, &vcc->stats->rx_drop);
28775 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28776 dev_kfree_skb(sb);
28777 break;
28778 }
28779 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28780 ATM_SKB(sb)->vcc = vcc;
28781 __net_timestamp(sb);
28782 vcc->push(vcc, sb);
28783 - atomic_inc(&vcc->stats->rx);
28784 + atomic_inc_unchecked(&vcc->stats->rx);
28785
28786 cell += ATM_CELL_PAYLOAD;
28787 }
28788 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28789 "(CDC: %08x)\n",
28790 card->name, len, rpp->len, readl(SAR_REG_CDC));
28791 recycle_rx_pool_skb(card, rpp);
28792 - atomic_inc(&vcc->stats->rx_err);
28793 + atomic_inc_unchecked(&vcc->stats->rx_err);
28794 return;
28795 }
28796 if (stat & SAR_RSQE_CRC) {
28797 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28798 recycle_rx_pool_skb(card, rpp);
28799 - atomic_inc(&vcc->stats->rx_err);
28800 + atomic_inc_unchecked(&vcc->stats->rx_err);
28801 return;
28802 }
28803 if (skb_queue_len(&rpp->queue) > 1) {
28804 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28805 RXPRINTK("%s: Can't alloc RX skb.\n",
28806 card->name);
28807 recycle_rx_pool_skb(card, rpp);
28808 - atomic_inc(&vcc->stats->rx_err);
28809 + atomic_inc_unchecked(&vcc->stats->rx_err);
28810 return;
28811 }
28812 if (!atm_charge(vcc, skb->truesize)) {
28813 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28814 __net_timestamp(skb);
28815
28816 vcc->push(vcc, skb);
28817 - atomic_inc(&vcc->stats->rx);
28818 + atomic_inc_unchecked(&vcc->stats->rx);
28819
28820 return;
28821 }
28822 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28823 __net_timestamp(skb);
28824
28825 vcc->push(vcc, skb);
28826 - atomic_inc(&vcc->stats->rx);
28827 + atomic_inc_unchecked(&vcc->stats->rx);
28828
28829 if (skb->truesize > SAR_FB_SIZE_3)
28830 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28831 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28832 if (vcc->qos.aal != ATM_AAL0) {
28833 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28834 card->name, vpi, vci);
28835 - atomic_inc(&vcc->stats->rx_drop);
28836 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28837 goto drop;
28838 }
28839
28840 if ((sb = dev_alloc_skb(64)) == NULL) {
28841 printk("%s: Can't allocate buffers for AAL0.\n",
28842 card->name);
28843 - atomic_inc(&vcc->stats->rx_err);
28844 + atomic_inc_unchecked(&vcc->stats->rx_err);
28845 goto drop;
28846 }
28847
28848 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28849 ATM_SKB(sb)->vcc = vcc;
28850 __net_timestamp(sb);
28851 vcc->push(vcc, sb);
28852 - atomic_inc(&vcc->stats->rx);
28853 + atomic_inc_unchecked(&vcc->stats->rx);
28854
28855 drop:
28856 skb_pull(queue, 64);
28857 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28858
28859 if (vc == NULL) {
28860 printk("%s: NULL connection in send().\n", card->name);
28861 - atomic_inc(&vcc->stats->tx_err);
28862 + atomic_inc_unchecked(&vcc->stats->tx_err);
28863 dev_kfree_skb(skb);
28864 return -EINVAL;
28865 }
28866 if (!test_bit(VCF_TX, &vc->flags)) {
28867 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28868 - atomic_inc(&vcc->stats->tx_err);
28869 + atomic_inc_unchecked(&vcc->stats->tx_err);
28870 dev_kfree_skb(skb);
28871 return -EINVAL;
28872 }
28873 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28874 break;
28875 default:
28876 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28877 - atomic_inc(&vcc->stats->tx_err);
28878 + atomic_inc_unchecked(&vcc->stats->tx_err);
28879 dev_kfree_skb(skb);
28880 return -EINVAL;
28881 }
28882
28883 if (skb_shinfo(skb)->nr_frags != 0) {
28884 printk("%s: No scatter-gather yet.\n", card->name);
28885 - atomic_inc(&vcc->stats->tx_err);
28886 + atomic_inc_unchecked(&vcc->stats->tx_err);
28887 dev_kfree_skb(skb);
28888 return -EINVAL;
28889 }
28890 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28891
28892 err = queue_skb(card, vc, skb, oam);
28893 if (err) {
28894 - atomic_inc(&vcc->stats->tx_err);
28895 + atomic_inc_unchecked(&vcc->stats->tx_err);
28896 dev_kfree_skb(skb);
28897 return err;
28898 }
28899 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28900 skb = dev_alloc_skb(64);
28901 if (!skb) {
28902 printk("%s: Out of memory in send_oam().\n", card->name);
28903 - atomic_inc(&vcc->stats->tx_err);
28904 + atomic_inc_unchecked(&vcc->stats->tx_err);
28905 return -ENOMEM;
28906 }
28907 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28908 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28909 index 96cce6d..62c3ec5 100644
28910 --- a/drivers/atm/iphase.c
28911 +++ b/drivers/atm/iphase.c
28912 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28913 status = (u_short) (buf_desc_ptr->desc_mode);
28914 if (status & (RX_CER | RX_PTE | RX_OFL))
28915 {
28916 - atomic_inc(&vcc->stats->rx_err);
28917 + atomic_inc_unchecked(&vcc->stats->rx_err);
28918 IF_ERR(printk("IA: bad packet, dropping it");)
28919 if (status & RX_CER) {
28920 IF_ERR(printk(" cause: packet CRC error\n");)
28921 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28922 len = dma_addr - buf_addr;
28923 if (len > iadev->rx_buf_sz) {
28924 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28925 - atomic_inc(&vcc->stats->rx_err);
28926 + atomic_inc_unchecked(&vcc->stats->rx_err);
28927 goto out_free_desc;
28928 }
28929
28930 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28931 ia_vcc = INPH_IA_VCC(vcc);
28932 if (ia_vcc == NULL)
28933 {
28934 - atomic_inc(&vcc->stats->rx_err);
28935 + atomic_inc_unchecked(&vcc->stats->rx_err);
28936 atm_return(vcc, skb->truesize);
28937 dev_kfree_skb_any(skb);
28938 goto INCR_DLE;
28939 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28940 if ((length > iadev->rx_buf_sz) || (length >
28941 (skb->len - sizeof(struct cpcs_trailer))))
28942 {
28943 - atomic_inc(&vcc->stats->rx_err);
28944 + atomic_inc_unchecked(&vcc->stats->rx_err);
28945 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28946 length, skb->len);)
28947 atm_return(vcc, skb->truesize);
28948 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28949
28950 IF_RX(printk("rx_dle_intr: skb push");)
28951 vcc->push(vcc,skb);
28952 - atomic_inc(&vcc->stats->rx);
28953 + atomic_inc_unchecked(&vcc->stats->rx);
28954 iadev->rx_pkt_cnt++;
28955 }
28956 INCR_DLE:
28957 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28958 {
28959 struct k_sonet_stats *stats;
28960 stats = &PRIV(_ia_dev[board])->sonet_stats;
28961 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28962 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28963 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28964 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28965 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28966 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28967 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28968 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28969 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28970 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28971 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28972 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28973 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28974 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28975 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28976 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28977 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28978 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28979 }
28980 ia_cmds.status = 0;
28981 break;
28982 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28983 if ((desc == 0) || (desc > iadev->num_tx_desc))
28984 {
28985 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28986 - atomic_inc(&vcc->stats->tx);
28987 + atomic_inc_unchecked(&vcc->stats->tx);
28988 if (vcc->pop)
28989 vcc->pop(vcc, skb);
28990 else
28991 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28992 ATM_DESC(skb) = vcc->vci;
28993 skb_queue_tail(&iadev->tx_dma_q, skb);
28994
28995 - atomic_inc(&vcc->stats->tx);
28996 + atomic_inc_unchecked(&vcc->stats->tx);
28997 iadev->tx_pkt_cnt++;
28998 /* Increment transaction counter */
28999 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
29000
29001 #if 0
29002 /* add flow control logic */
29003 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
29004 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
29005 if (iavcc->vc_desc_cnt > 10) {
29006 vcc->tx_quota = vcc->tx_quota * 3 / 4;
29007 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
29008 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
29009 index 68c7588..7036683 100644
29010 --- a/drivers/atm/lanai.c
29011 +++ b/drivers/atm/lanai.c
29012 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
29013 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
29014 lanai_endtx(lanai, lvcc);
29015 lanai_free_skb(lvcc->tx.atmvcc, skb);
29016 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
29017 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
29018 }
29019
29020 /* Try to fill the buffer - don't call unless there is backlog */
29021 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
29022 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
29023 __net_timestamp(skb);
29024 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
29025 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
29026 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
29027 out:
29028 lvcc->rx.buf.ptr = end;
29029 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
29030 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29031 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
29032 "vcc %d\n", lanai->number, (unsigned int) s, vci);
29033 lanai->stats.service_rxnotaal5++;
29034 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29035 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29036 return 0;
29037 }
29038 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
29039 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29040 int bytes;
29041 read_unlock(&vcc_sklist_lock);
29042 DPRINTK("got trashed rx pdu on vci %d\n", vci);
29043 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29044 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29045 lvcc->stats.x.aal5.service_trash++;
29046 bytes = (SERVICE_GET_END(s) * 16) -
29047 (((unsigned long) lvcc->rx.buf.ptr) -
29048 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29049 }
29050 if (s & SERVICE_STREAM) {
29051 read_unlock(&vcc_sklist_lock);
29052 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29053 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29054 lvcc->stats.x.aal5.service_stream++;
29055 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
29056 "PDU on VCI %d!\n", lanai->number, vci);
29057 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29058 return 0;
29059 }
29060 DPRINTK("got rx crc error on vci %d\n", vci);
29061 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29062 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29063 lvcc->stats.x.aal5.service_rxcrc++;
29064 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
29065 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
29066 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
29067 index 1c70c45..300718d 100644
29068 --- a/drivers/atm/nicstar.c
29069 +++ b/drivers/atm/nicstar.c
29070 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29071 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
29072 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
29073 card->index);
29074 - atomic_inc(&vcc->stats->tx_err);
29075 + atomic_inc_unchecked(&vcc->stats->tx_err);
29076 dev_kfree_skb_any(skb);
29077 return -EINVAL;
29078 }
29079 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29080 if (!vc->tx) {
29081 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
29082 card->index);
29083 - atomic_inc(&vcc->stats->tx_err);
29084 + atomic_inc_unchecked(&vcc->stats->tx_err);
29085 dev_kfree_skb_any(skb);
29086 return -EINVAL;
29087 }
29088 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29089 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
29090 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
29091 card->index);
29092 - atomic_inc(&vcc->stats->tx_err);
29093 + atomic_inc_unchecked(&vcc->stats->tx_err);
29094 dev_kfree_skb_any(skb);
29095 return -EINVAL;
29096 }
29097
29098 if (skb_shinfo(skb)->nr_frags != 0) {
29099 printk("nicstar%d: No scatter-gather yet.\n", card->index);
29100 - atomic_inc(&vcc->stats->tx_err);
29101 + atomic_inc_unchecked(&vcc->stats->tx_err);
29102 dev_kfree_skb_any(skb);
29103 return -EINVAL;
29104 }
29105 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29106 }
29107
29108 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
29109 - atomic_inc(&vcc->stats->tx_err);
29110 + atomic_inc_unchecked(&vcc->stats->tx_err);
29111 dev_kfree_skb_any(skb);
29112 return -EIO;
29113 }
29114 - atomic_inc(&vcc->stats->tx);
29115 + atomic_inc_unchecked(&vcc->stats->tx);
29116
29117 return 0;
29118 }
29119 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29120 printk
29121 ("nicstar%d: Can't allocate buffers for aal0.\n",
29122 card->index);
29123 - atomic_add(i, &vcc->stats->rx_drop);
29124 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
29125 break;
29126 }
29127 if (!atm_charge(vcc, sb->truesize)) {
29128 RXPRINTK
29129 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
29130 card->index);
29131 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
29132 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
29133 dev_kfree_skb_any(sb);
29134 break;
29135 }
29136 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29137 ATM_SKB(sb)->vcc = vcc;
29138 __net_timestamp(sb);
29139 vcc->push(vcc, sb);
29140 - atomic_inc(&vcc->stats->rx);
29141 + atomic_inc_unchecked(&vcc->stats->rx);
29142 cell += ATM_CELL_PAYLOAD;
29143 }
29144
29145 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29146 if (iovb == NULL) {
29147 printk("nicstar%d: Out of iovec buffers.\n",
29148 card->index);
29149 - atomic_inc(&vcc->stats->rx_drop);
29150 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29151 recycle_rx_buf(card, skb);
29152 return;
29153 }
29154 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29155 small or large buffer itself. */
29156 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
29157 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
29158 - atomic_inc(&vcc->stats->rx_err);
29159 + atomic_inc_unchecked(&vcc->stats->rx_err);
29160 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29161 NS_MAX_IOVECS);
29162 NS_PRV_IOVCNT(iovb) = 0;
29163 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29164 ("nicstar%d: Expected a small buffer, and this is not one.\n",
29165 card->index);
29166 which_list(card, skb);
29167 - atomic_inc(&vcc->stats->rx_err);
29168 + atomic_inc_unchecked(&vcc->stats->rx_err);
29169 recycle_rx_buf(card, skb);
29170 vc->rx_iov = NULL;
29171 recycle_iov_buf(card, iovb);
29172 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29173 ("nicstar%d: Expected a large buffer, and this is not one.\n",
29174 card->index);
29175 which_list(card, skb);
29176 - atomic_inc(&vcc->stats->rx_err);
29177 + atomic_inc_unchecked(&vcc->stats->rx_err);
29178 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29179 NS_PRV_IOVCNT(iovb));
29180 vc->rx_iov = NULL;
29181 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29182 printk(" - PDU size mismatch.\n");
29183 else
29184 printk(".\n");
29185 - atomic_inc(&vcc->stats->rx_err);
29186 + atomic_inc_unchecked(&vcc->stats->rx_err);
29187 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
29188 NS_PRV_IOVCNT(iovb));
29189 vc->rx_iov = NULL;
29190 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29191 /* skb points to a small buffer */
29192 if (!atm_charge(vcc, skb->truesize)) {
29193 push_rxbufs(card, skb);
29194 - atomic_inc(&vcc->stats->rx_drop);
29195 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29196 } else {
29197 skb_put(skb, len);
29198 dequeue_sm_buf(card, skb);
29199 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29200 ATM_SKB(skb)->vcc = vcc;
29201 __net_timestamp(skb);
29202 vcc->push(vcc, skb);
29203 - atomic_inc(&vcc->stats->rx);
29204 + atomic_inc_unchecked(&vcc->stats->rx);
29205 }
29206 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
29207 struct sk_buff *sb;
29208 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29209 if (len <= NS_SMBUFSIZE) {
29210 if (!atm_charge(vcc, sb->truesize)) {
29211 push_rxbufs(card, sb);
29212 - atomic_inc(&vcc->stats->rx_drop);
29213 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29214 } else {
29215 skb_put(sb, len);
29216 dequeue_sm_buf(card, sb);
29217 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29218 ATM_SKB(sb)->vcc = vcc;
29219 __net_timestamp(sb);
29220 vcc->push(vcc, sb);
29221 - atomic_inc(&vcc->stats->rx);
29222 + atomic_inc_unchecked(&vcc->stats->rx);
29223 }
29224
29225 push_rxbufs(card, skb);
29226 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29227
29228 if (!atm_charge(vcc, skb->truesize)) {
29229 push_rxbufs(card, skb);
29230 - atomic_inc(&vcc->stats->rx_drop);
29231 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29232 } else {
29233 dequeue_lg_buf(card, skb);
29234 #ifdef NS_USE_DESTRUCTORS
29235 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29236 ATM_SKB(skb)->vcc = vcc;
29237 __net_timestamp(skb);
29238 vcc->push(vcc, skb);
29239 - atomic_inc(&vcc->stats->rx);
29240 + atomic_inc_unchecked(&vcc->stats->rx);
29241 }
29242
29243 push_rxbufs(card, sb);
29244 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29245 printk
29246 ("nicstar%d: Out of huge buffers.\n",
29247 card->index);
29248 - atomic_inc(&vcc->stats->rx_drop);
29249 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29250 recycle_iovec_rx_bufs(card,
29251 (struct iovec *)
29252 iovb->data,
29253 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29254 card->hbpool.count++;
29255 } else
29256 dev_kfree_skb_any(hb);
29257 - atomic_inc(&vcc->stats->rx_drop);
29258 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29259 } else {
29260 /* Copy the small buffer to the huge buffer */
29261 sb = (struct sk_buff *)iov->iov_base;
29262 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29263 #endif /* NS_USE_DESTRUCTORS */
29264 __net_timestamp(hb);
29265 vcc->push(vcc, hb);
29266 - atomic_inc(&vcc->stats->rx);
29267 + atomic_inc_unchecked(&vcc->stats->rx);
29268 }
29269 }
29270
29271 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29272 index 9851093..adb2b1e 100644
29273 --- a/drivers/atm/solos-pci.c
29274 +++ b/drivers/atm/solos-pci.c
29275 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29276 }
29277 atm_charge(vcc, skb->truesize);
29278 vcc->push(vcc, skb);
29279 - atomic_inc(&vcc->stats->rx);
29280 + atomic_inc_unchecked(&vcc->stats->rx);
29281 break;
29282
29283 case PKT_STATUS:
29284 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29285 vcc = SKB_CB(oldskb)->vcc;
29286
29287 if (vcc) {
29288 - atomic_inc(&vcc->stats->tx);
29289 + atomic_inc_unchecked(&vcc->stats->tx);
29290 solos_pop(vcc, oldskb);
29291 } else
29292 dev_kfree_skb_irq(oldskb);
29293 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29294 index 0215934..ce9f5b1 100644
29295 --- a/drivers/atm/suni.c
29296 +++ b/drivers/atm/suni.c
29297 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29298
29299
29300 #define ADD_LIMITED(s,v) \
29301 - atomic_add((v),&stats->s); \
29302 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29303 + atomic_add_unchecked((v),&stats->s); \
29304 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29305
29306
29307 static void suni_hz(unsigned long from_timer)
29308 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29309 index 5120a96..e2572bd 100644
29310 --- a/drivers/atm/uPD98402.c
29311 +++ b/drivers/atm/uPD98402.c
29312 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29313 struct sonet_stats tmp;
29314 int error = 0;
29315
29316 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29317 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29318 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29319 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29320 if (zero && !error) {
29321 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29322
29323
29324 #define ADD_LIMITED(s,v) \
29325 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29326 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29327 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29328 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29329 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29330 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29331
29332
29333 static void stat_event(struct atm_dev *dev)
29334 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29335 if (reason & uPD98402_INT_PFM) stat_event(dev);
29336 if (reason & uPD98402_INT_PCO) {
29337 (void) GET(PCOCR); /* clear interrupt cause */
29338 - atomic_add(GET(HECCT),
29339 + atomic_add_unchecked(GET(HECCT),
29340 &PRIV(dev)->sonet_stats.uncorr_hcs);
29341 }
29342 if ((reason & uPD98402_INT_RFO) &&
29343 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29344 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29345 uPD98402_INT_LOS),PIMR); /* enable them */
29346 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29347 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29348 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29349 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29350 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29351 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29352 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29353 return 0;
29354 }
29355
29356 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29357 index abe4e20..83c4727 100644
29358 --- a/drivers/atm/zatm.c
29359 +++ b/drivers/atm/zatm.c
29360 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29361 }
29362 if (!size) {
29363 dev_kfree_skb_irq(skb);
29364 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29365 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29366 continue;
29367 }
29368 if (!atm_charge(vcc,skb->truesize)) {
29369 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29370 skb->len = size;
29371 ATM_SKB(skb)->vcc = vcc;
29372 vcc->push(vcc,skb);
29373 - atomic_inc(&vcc->stats->rx);
29374 + atomic_inc_unchecked(&vcc->stats->rx);
29375 }
29376 zout(pos & 0xffff,MTA(mbx));
29377 #if 0 /* probably a stupid idea */
29378 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29379 skb_queue_head(&zatm_vcc->backlog,skb);
29380 break;
29381 }
29382 - atomic_inc(&vcc->stats->tx);
29383 + atomic_inc_unchecked(&vcc->stats->tx);
29384 wake_up(&zatm_vcc->tx_wait);
29385 }
29386
29387 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29388 index 147d1a4..d0fd4b0 100644
29389 --- a/drivers/base/devtmpfs.c
29390 +++ b/drivers/base/devtmpfs.c
29391 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29392 if (!thread)
29393 return 0;
29394
29395 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29396 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29397 if (err)
29398 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29399 else
29400 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29401 index e6ee5e8..98ad7fc 100644
29402 --- a/drivers/base/power/wakeup.c
29403 +++ b/drivers/base/power/wakeup.c
29404 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29405 * They need to be modified together atomically, so it's better to use one
29406 * atomic variable to hold them both.
29407 */
29408 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29409 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29410
29411 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29412 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29413
29414 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29415 {
29416 - unsigned int comb = atomic_read(&combined_event_count);
29417 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29418
29419 *cnt = (comb >> IN_PROGRESS_BITS);
29420 *inpr = comb & MAX_IN_PROGRESS;
29421 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29422 ws->start_prevent_time = ws->last_time;
29423
29424 /* Increment the counter of events in progress. */
29425 - cec = atomic_inc_return(&combined_event_count);
29426 + cec = atomic_inc_return_unchecked(&combined_event_count);
29427
29428 trace_wakeup_source_activate(ws->name, cec);
29429 }
29430 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29431 * Increment the counter of registered wakeup events and decrement the
29432 * couter of wakeup events in progress simultaneously.
29433 */
29434 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29435 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29436 trace_wakeup_source_deactivate(ws->name, cec);
29437
29438 split_counters(&cnt, &inpr);
29439 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29440 index ca83f96..69d4ea9 100644
29441 --- a/drivers/block/cciss.c
29442 +++ b/drivers/block/cciss.c
29443 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29444 int err;
29445 u32 cp;
29446
29447 + memset(&arg64, 0, sizeof(arg64));
29448 +
29449 err = 0;
29450 err |=
29451 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29452 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29453 while (!list_empty(&h->reqQ)) {
29454 c = list_entry(h->reqQ.next, CommandList_struct, list);
29455 /* can't do anything if fifo is full */
29456 - if ((h->access.fifo_full(h))) {
29457 + if ((h->access->fifo_full(h))) {
29458 dev_warn(&h->pdev->dev, "fifo full\n");
29459 break;
29460 }
29461 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29462 h->Qdepth--;
29463
29464 /* Tell the controller execute command */
29465 - h->access.submit_command(h, c);
29466 + h->access->submit_command(h, c);
29467
29468 /* Put job onto the completed Q */
29469 addQ(&h->cmpQ, c);
29470 @@ -3443,17 +3445,17 @@ startio:
29471
29472 static inline unsigned long get_next_completion(ctlr_info_t *h)
29473 {
29474 - return h->access.command_completed(h);
29475 + return h->access->command_completed(h);
29476 }
29477
29478 static inline int interrupt_pending(ctlr_info_t *h)
29479 {
29480 - return h->access.intr_pending(h);
29481 + return h->access->intr_pending(h);
29482 }
29483
29484 static inline long interrupt_not_for_us(ctlr_info_t *h)
29485 {
29486 - return ((h->access.intr_pending(h) == 0) ||
29487 + return ((h->access->intr_pending(h) == 0) ||
29488 (h->interrupts_enabled == 0));
29489 }
29490
29491 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29492 u32 a;
29493
29494 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29495 - return h->access.command_completed(h);
29496 + return h->access->command_completed(h);
29497
29498 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29499 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29500 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29501 trans_support & CFGTBL_Trans_use_short_tags);
29502
29503 /* Change the access methods to the performant access methods */
29504 - h->access = SA5_performant_access;
29505 + h->access = &SA5_performant_access;
29506 h->transMethod = CFGTBL_Trans_Performant;
29507
29508 return;
29509 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29510 if (prod_index < 0)
29511 return -ENODEV;
29512 h->product_name = products[prod_index].product_name;
29513 - h->access = *(products[prod_index].access);
29514 + h->access = products[prod_index].access;
29515
29516 if (cciss_board_disabled(h)) {
29517 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29518 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29519 }
29520
29521 /* make sure the board interrupts are off */
29522 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29523 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29524 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29525 if (rc)
29526 goto clean2;
29527 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29528 * fake ones to scoop up any residual completions.
29529 */
29530 spin_lock_irqsave(&h->lock, flags);
29531 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29532 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29533 spin_unlock_irqrestore(&h->lock, flags);
29534 free_irq(h->intr[h->intr_mode], h);
29535 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29536 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29537 dev_info(&h->pdev->dev, "Board READY.\n");
29538 dev_info(&h->pdev->dev,
29539 "Waiting for stale completions to drain.\n");
29540 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29541 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29542 msleep(10000);
29543 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29544 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29545
29546 rc = controller_reset_failed(h->cfgtable);
29547 if (rc)
29548 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29549 cciss_scsi_setup(h);
29550
29551 /* Turn the interrupts on so we can service requests */
29552 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29553 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29554
29555 /* Get the firmware version */
29556 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29557 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29558 kfree(flush_buf);
29559 if (return_code != IO_OK)
29560 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29561 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29562 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29563 free_irq(h->intr[h->intr_mode], h);
29564 }
29565
29566 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29567 index 7fda30e..eb5dfe0 100644
29568 --- a/drivers/block/cciss.h
29569 +++ b/drivers/block/cciss.h
29570 @@ -101,7 +101,7 @@ struct ctlr_info
29571 /* information about each logical volume */
29572 drive_info_struct *drv[CISS_MAX_LUN];
29573
29574 - struct access_method access;
29575 + struct access_method *access;
29576
29577 /* queue and queue Info */
29578 struct list_head reqQ;
29579 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29580 index 9125bbe..eede5c8 100644
29581 --- a/drivers/block/cpqarray.c
29582 +++ b/drivers/block/cpqarray.c
29583 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29584 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29585 goto Enomem4;
29586 }
29587 - hba[i]->access.set_intr_mask(hba[i], 0);
29588 + hba[i]->access->set_intr_mask(hba[i], 0);
29589 if (request_irq(hba[i]->intr, do_ida_intr,
29590 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29591 {
29592 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29593 add_timer(&hba[i]->timer);
29594
29595 /* Enable IRQ now that spinlock and rate limit timer are set up */
29596 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29597 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29598
29599 for(j=0; j<NWD; j++) {
29600 struct gendisk *disk = ida_gendisk[i][j];
29601 @@ -694,7 +694,7 @@ DBGINFO(
29602 for(i=0; i<NR_PRODUCTS; i++) {
29603 if (board_id == products[i].board_id) {
29604 c->product_name = products[i].product_name;
29605 - c->access = *(products[i].access);
29606 + c->access = products[i].access;
29607 break;
29608 }
29609 }
29610 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29611 hba[ctlr]->intr = intr;
29612 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29613 hba[ctlr]->product_name = products[j].product_name;
29614 - hba[ctlr]->access = *(products[j].access);
29615 + hba[ctlr]->access = products[j].access;
29616 hba[ctlr]->ctlr = ctlr;
29617 hba[ctlr]->board_id = board_id;
29618 hba[ctlr]->pci_dev = NULL; /* not PCI */
29619 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29620
29621 while((c = h->reqQ) != NULL) {
29622 /* Can't do anything if we're busy */
29623 - if (h->access.fifo_full(h) == 0)
29624 + if (h->access->fifo_full(h) == 0)
29625 return;
29626
29627 /* Get the first entry from the request Q */
29628 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29629 h->Qdepth--;
29630
29631 /* Tell the controller to do our bidding */
29632 - h->access.submit_command(h, c);
29633 + h->access->submit_command(h, c);
29634
29635 /* Get onto the completion Q */
29636 addQ(&h->cmpQ, c);
29637 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29638 unsigned long flags;
29639 __u32 a,a1;
29640
29641 - istat = h->access.intr_pending(h);
29642 + istat = h->access->intr_pending(h);
29643 /* Is this interrupt for us? */
29644 if (istat == 0)
29645 return IRQ_NONE;
29646 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29647 */
29648 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29649 if (istat & FIFO_NOT_EMPTY) {
29650 - while((a = h->access.command_completed(h))) {
29651 + while((a = h->access->command_completed(h))) {
29652 a1 = a; a &= ~3;
29653 if ((c = h->cmpQ) == NULL)
29654 {
29655 @@ -1449,11 +1449,11 @@ static int sendcmd(
29656 /*
29657 * Disable interrupt
29658 */
29659 - info_p->access.set_intr_mask(info_p, 0);
29660 + info_p->access->set_intr_mask(info_p, 0);
29661 /* Make sure there is room in the command FIFO */
29662 /* Actually it should be completely empty at this time. */
29663 for (i = 200000; i > 0; i--) {
29664 - temp = info_p->access.fifo_full(info_p);
29665 + temp = info_p->access->fifo_full(info_p);
29666 if (temp != 0) {
29667 break;
29668 }
29669 @@ -1466,7 +1466,7 @@ DBG(
29670 /*
29671 * Send the cmd
29672 */
29673 - info_p->access.submit_command(info_p, c);
29674 + info_p->access->submit_command(info_p, c);
29675 complete = pollcomplete(ctlr);
29676
29677 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29678 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29679 * we check the new geometry. Then turn interrupts back on when
29680 * we're done.
29681 */
29682 - host->access.set_intr_mask(host, 0);
29683 + host->access->set_intr_mask(host, 0);
29684 getgeometry(ctlr);
29685 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29686 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29687
29688 for(i=0; i<NWD; i++) {
29689 struct gendisk *disk = ida_gendisk[ctlr][i];
29690 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29691 /* Wait (up to 2 seconds) for a command to complete */
29692
29693 for (i = 200000; i > 0; i--) {
29694 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29695 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29696 if (done == 0) {
29697 udelay(10); /* a short fixed delay */
29698 } else
29699 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29700 index be73e9d..7fbf140 100644
29701 --- a/drivers/block/cpqarray.h
29702 +++ b/drivers/block/cpqarray.h
29703 @@ -99,7 +99,7 @@ struct ctlr_info {
29704 drv_info_t drv[NWD];
29705 struct proc_dir_entry *proc;
29706
29707 - struct access_method access;
29708 + struct access_method *access;
29709
29710 cmdlist_t *reqQ;
29711 cmdlist_t *cmpQ;
29712 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29713 index b953cc7..e3dc580 100644
29714 --- a/drivers/block/drbd/drbd_int.h
29715 +++ b/drivers/block/drbd/drbd_int.h
29716 @@ -735,7 +735,7 @@ struct drbd_request;
29717 struct drbd_epoch {
29718 struct list_head list;
29719 unsigned int barrier_nr;
29720 - atomic_t epoch_size; /* increased on every request added. */
29721 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29722 atomic_t active; /* increased on every req. added, and dec on every finished. */
29723 unsigned long flags;
29724 };
29725 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29726 void *int_dig_in;
29727 void *int_dig_vv;
29728 wait_queue_head_t seq_wait;
29729 - atomic_t packet_seq;
29730 + atomic_unchecked_t packet_seq;
29731 unsigned int peer_seq;
29732 spinlock_t peer_seq_lock;
29733 unsigned int minor;
29734 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29735
29736 static inline void drbd_tcp_cork(struct socket *sock)
29737 {
29738 - int __user val = 1;
29739 + int val = 1;
29740 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29741 - (char __user *)&val, sizeof(val));
29742 + (char __force_user *)&val, sizeof(val));
29743 }
29744
29745 static inline void drbd_tcp_uncork(struct socket *sock)
29746 {
29747 - int __user val = 0;
29748 + int val = 0;
29749 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29750 - (char __user *)&val, sizeof(val));
29751 + (char __force_user *)&val, sizeof(val));
29752 }
29753
29754 static inline void drbd_tcp_nodelay(struct socket *sock)
29755 {
29756 - int __user val = 1;
29757 + int val = 1;
29758 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29759 - (char __user *)&val, sizeof(val));
29760 + (char __force_user *)&val, sizeof(val));
29761 }
29762
29763 static inline void drbd_tcp_quickack(struct socket *sock)
29764 {
29765 - int __user val = 2;
29766 + int val = 2;
29767 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29768 - (char __user *)&val, sizeof(val));
29769 + (char __force_user *)&val, sizeof(val));
29770 }
29771
29772 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29773 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29774 index f55683a..2101b96 100644
29775 --- a/drivers/block/drbd/drbd_main.c
29776 +++ b/drivers/block/drbd/drbd_main.c
29777 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29778 p.sector = sector;
29779 p.block_id = block_id;
29780 p.blksize = blksize;
29781 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29782 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29783
29784 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29785 return false;
29786 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29787
29788 p.sector = cpu_to_be64(req->sector);
29789 p.block_id = (unsigned long)req;
29790 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29791 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29792
29793 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29794
29795 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29796 atomic_set(&mdev->unacked_cnt, 0);
29797 atomic_set(&mdev->local_cnt, 0);
29798 atomic_set(&mdev->net_cnt, 0);
29799 - atomic_set(&mdev->packet_seq, 0);
29800 + atomic_set_unchecked(&mdev->packet_seq, 0);
29801 atomic_set(&mdev->pp_in_use, 0);
29802 atomic_set(&mdev->pp_in_use_by_net, 0);
29803 atomic_set(&mdev->rs_sect_in, 0);
29804 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29805 mdev->receiver.t_state);
29806
29807 /* no need to lock it, I'm the only thread alive */
29808 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29809 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29810 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29811 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29812 mdev->al_writ_cnt =
29813 mdev->bm_writ_cnt =
29814 mdev->read_cnt =
29815 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29816 index edb490a..ecd69da 100644
29817 --- a/drivers/block/drbd/drbd_nl.c
29818 +++ b/drivers/block/drbd/drbd_nl.c
29819 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29820 module_put(THIS_MODULE);
29821 }
29822
29823 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29824 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29825
29826 static unsigned short *
29827 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29828 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29829 cn_reply->id.idx = CN_IDX_DRBD;
29830 cn_reply->id.val = CN_VAL_DRBD;
29831
29832 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29833 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29834 cn_reply->ack = 0; /* not used here. */
29835 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29836 (int)((char *)tl - (char *)reply->tag_list);
29837 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29838 cn_reply->id.idx = CN_IDX_DRBD;
29839 cn_reply->id.val = CN_VAL_DRBD;
29840
29841 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29842 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29843 cn_reply->ack = 0; /* not used here. */
29844 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29845 (int)((char *)tl - (char *)reply->tag_list);
29846 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29847 cn_reply->id.idx = CN_IDX_DRBD;
29848 cn_reply->id.val = CN_VAL_DRBD;
29849
29850 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29851 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29852 cn_reply->ack = 0; // not used here.
29853 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29854 (int)((char*)tl - (char*)reply->tag_list);
29855 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29856 cn_reply->id.idx = CN_IDX_DRBD;
29857 cn_reply->id.val = CN_VAL_DRBD;
29858
29859 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29860 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29861 cn_reply->ack = 0; /* not used here. */
29862 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29863 (int)((char *)tl - (char *)reply->tag_list);
29864 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29865 index c74ca2d..860c819 100644
29866 --- a/drivers/block/drbd/drbd_receiver.c
29867 +++ b/drivers/block/drbd/drbd_receiver.c
29868 @@ -898,7 +898,7 @@ retry:
29869 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29870 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29871
29872 - atomic_set(&mdev->packet_seq, 0);
29873 + atomic_set_unchecked(&mdev->packet_seq, 0);
29874 mdev->peer_seq = 0;
29875
29876 if (drbd_send_protocol(mdev) == -1)
29877 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29878 do {
29879 next_epoch = NULL;
29880
29881 - epoch_size = atomic_read(&epoch->epoch_size);
29882 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29883
29884 switch (ev & ~EV_CLEANUP) {
29885 case EV_PUT:
29886 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29887 rv = FE_DESTROYED;
29888 } else {
29889 epoch->flags = 0;
29890 - atomic_set(&epoch->epoch_size, 0);
29891 + atomic_set_unchecked(&epoch->epoch_size, 0);
29892 /* atomic_set(&epoch->active, 0); is already zero */
29893 if (rv == FE_STILL_LIVE)
29894 rv = FE_RECYCLED;
29895 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29896 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29897 drbd_flush(mdev);
29898
29899 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29900 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29901 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29902 if (epoch)
29903 break;
29904 }
29905
29906 epoch = mdev->current_epoch;
29907 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29908 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29909
29910 D_ASSERT(atomic_read(&epoch->active) == 0);
29911 D_ASSERT(epoch->flags == 0);
29912 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29913 }
29914
29915 epoch->flags = 0;
29916 - atomic_set(&epoch->epoch_size, 0);
29917 + atomic_set_unchecked(&epoch->epoch_size, 0);
29918 atomic_set(&epoch->active, 0);
29919
29920 spin_lock(&mdev->epoch_lock);
29921 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29922 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29923 list_add(&epoch->list, &mdev->current_epoch->list);
29924 mdev->current_epoch = epoch;
29925 mdev->epochs++;
29926 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29927 spin_unlock(&mdev->peer_seq_lock);
29928
29929 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29930 - atomic_inc(&mdev->current_epoch->epoch_size);
29931 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29932 return drbd_drain_block(mdev, data_size);
29933 }
29934
29935 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29936
29937 spin_lock(&mdev->epoch_lock);
29938 e->epoch = mdev->current_epoch;
29939 - atomic_inc(&e->epoch->epoch_size);
29940 + atomic_inc_unchecked(&e->epoch->epoch_size);
29941 atomic_inc(&e->epoch->active);
29942 spin_unlock(&mdev->epoch_lock);
29943
29944 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29945 D_ASSERT(list_empty(&mdev->done_ee));
29946
29947 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29948 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29949 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29950 D_ASSERT(list_empty(&mdev->current_epoch->list));
29951 }
29952
29953 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29954 index 54046e5..7759c55 100644
29955 --- a/drivers/block/loop.c
29956 +++ b/drivers/block/loop.c
29957 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29958 mm_segment_t old_fs = get_fs();
29959
29960 set_fs(get_ds());
29961 - bw = file->f_op->write(file, buf, len, &pos);
29962 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29963 set_fs(old_fs);
29964 if (likely(bw == len))
29965 return 0;
29966 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29967 index 72bedad..8181ce1 100644
29968 --- a/drivers/char/Kconfig
29969 +++ b/drivers/char/Kconfig
29970 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29971
29972 config DEVKMEM
29973 bool "/dev/kmem virtual device support"
29974 - default y
29975 + default n
29976 + depends on !GRKERNSEC_KMEM
29977 help
29978 Say Y here if you want to support the /dev/kmem device. The
29979 /dev/kmem device is rarely used, but can be used for certain
29980 @@ -581,6 +582,7 @@ config DEVPORT
29981 bool
29982 depends on !M68K
29983 depends on ISA || PCI
29984 + depends on !GRKERNSEC_KMEM
29985 default y
29986
29987 source "drivers/s390/char/Kconfig"
29988 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29989 index 2e04433..22afc64 100644
29990 --- a/drivers/char/agp/frontend.c
29991 +++ b/drivers/char/agp/frontend.c
29992 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29993 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29994 return -EFAULT;
29995
29996 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29997 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29998 return -EFAULT;
29999
30000 client = agp_find_client_by_pid(reserve.pid);
30001 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
30002 index 21cb980..f15107c 100644
30003 --- a/drivers/char/genrtc.c
30004 +++ b/drivers/char/genrtc.c
30005 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
30006 switch (cmd) {
30007
30008 case RTC_PLL_GET:
30009 + memset(&pll, 0, sizeof(pll));
30010 if (get_rtc_pll(&pll))
30011 return -EINVAL;
30012 else
30013 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
30014 index dfd7876..c0b0885 100644
30015 --- a/drivers/char/hpet.c
30016 +++ b/drivers/char/hpet.c
30017 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
30018 }
30019
30020 static int
30021 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
30022 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
30023 struct hpet_info *info)
30024 {
30025 struct hpet_timer __iomem *timer;
30026 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
30027 index a0c84bb..9edcf60 100644
30028 --- a/drivers/char/ipmi/ipmi_msghandler.c
30029 +++ b/drivers/char/ipmi/ipmi_msghandler.c
30030 @@ -420,7 +420,7 @@ struct ipmi_smi {
30031 struct proc_dir_entry *proc_dir;
30032 char proc_dir_name[10];
30033
30034 - atomic_t stats[IPMI_NUM_STATS];
30035 + atomic_unchecked_t stats[IPMI_NUM_STATS];
30036
30037 /*
30038 * run_to_completion duplicate of smb_info, smi_info
30039 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
30040
30041
30042 #define ipmi_inc_stat(intf, stat) \
30043 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
30044 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
30045 #define ipmi_get_stat(intf, stat) \
30046 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
30047 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
30048
30049 static int is_lan_addr(struct ipmi_addr *addr)
30050 {
30051 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
30052 INIT_LIST_HEAD(&intf->cmd_rcvrs);
30053 init_waitqueue_head(&intf->waitq);
30054 for (i = 0; i < IPMI_NUM_STATS; i++)
30055 - atomic_set(&intf->stats[i], 0);
30056 + atomic_set_unchecked(&intf->stats[i], 0);
30057
30058 intf->proc_dir = NULL;
30059
30060 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
30061 index 32a6c7e..f6966a9 100644
30062 --- a/drivers/char/ipmi/ipmi_si_intf.c
30063 +++ b/drivers/char/ipmi/ipmi_si_intf.c
30064 @@ -275,7 +275,7 @@ struct smi_info {
30065 unsigned char slave_addr;
30066
30067 /* Counters and things for the proc filesystem. */
30068 - atomic_t stats[SI_NUM_STATS];
30069 + atomic_unchecked_t stats[SI_NUM_STATS];
30070
30071 struct task_struct *thread;
30072
30073 @@ -284,9 +284,9 @@ struct smi_info {
30074 };
30075
30076 #define smi_inc_stat(smi, stat) \
30077 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
30078 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
30079 #define smi_get_stat(smi, stat) \
30080 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
30081 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
30082
30083 #define SI_MAX_PARMS 4
30084
30085 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
30086 atomic_set(&new_smi->req_events, 0);
30087 new_smi->run_to_completion = 0;
30088 for (i = 0; i < SI_NUM_STATS; i++)
30089 - atomic_set(&new_smi->stats[i], 0);
30090 + atomic_set_unchecked(&new_smi->stats[i], 0);
30091
30092 new_smi->interrupt_disabled = 1;
30093 atomic_set(&new_smi->stop_operation, 0);
30094 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
30095 index 0537903..121c699 100644
30096 --- a/drivers/char/mem.c
30097 +++ b/drivers/char/mem.c
30098 @@ -18,6 +18,7 @@
30099 #include <linux/raw.h>
30100 #include <linux/tty.h>
30101 #include <linux/capability.h>
30102 +#include <linux/security.h>
30103 #include <linux/ptrace.h>
30104 #include <linux/device.h>
30105 #include <linux/highmem.h>
30106 @@ -37,6 +38,10 @@
30107
30108 #define DEVPORT_MINOR 4
30109
30110 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30111 +extern const struct file_operations grsec_fops;
30112 +#endif
30113 +
30114 static inline unsigned long size_inside_page(unsigned long start,
30115 unsigned long size)
30116 {
30117 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30118
30119 while (cursor < to) {
30120 if (!devmem_is_allowed(pfn)) {
30121 +#ifdef CONFIG_GRKERNSEC_KMEM
30122 + gr_handle_mem_readwrite(from, to);
30123 +#else
30124 printk(KERN_INFO
30125 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
30126 current->comm, from, to);
30127 +#endif
30128 return 0;
30129 }
30130 cursor += PAGE_SIZE;
30131 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30132 }
30133 return 1;
30134 }
30135 +#elif defined(CONFIG_GRKERNSEC_KMEM)
30136 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30137 +{
30138 + return 0;
30139 +}
30140 #else
30141 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
30142 {
30143 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30144
30145 while (count > 0) {
30146 unsigned long remaining;
30147 + char *temp;
30148
30149 sz = size_inside_page(p, count);
30150
30151 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
30152 if (!ptr)
30153 return -EFAULT;
30154
30155 - remaining = copy_to_user(buf, ptr, sz);
30156 +#ifdef CONFIG_PAX_USERCOPY
30157 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30158 + if (!temp) {
30159 + unxlate_dev_mem_ptr(p, ptr);
30160 + return -ENOMEM;
30161 + }
30162 + memcpy(temp, ptr, sz);
30163 +#else
30164 + temp = ptr;
30165 +#endif
30166 +
30167 + remaining = copy_to_user(buf, temp, sz);
30168 +
30169 +#ifdef CONFIG_PAX_USERCOPY
30170 + kfree(temp);
30171 +#endif
30172 +
30173 unxlate_dev_mem_ptr(p, ptr);
30174 if (remaining)
30175 return -EFAULT;
30176 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30177 size_t count, loff_t *ppos)
30178 {
30179 unsigned long p = *ppos;
30180 - ssize_t low_count, read, sz;
30181 + ssize_t low_count, read, sz, err = 0;
30182 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30183 - int err = 0;
30184
30185 read = 0;
30186 if (p < (unsigned long) high_memory) {
30187 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30188 }
30189 #endif
30190 while (low_count > 0) {
30191 + char *temp;
30192 +
30193 sz = size_inside_page(p, low_count);
30194
30195 /*
30196 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30197 */
30198 kbuf = xlate_dev_kmem_ptr((char *)p);
30199
30200 - if (copy_to_user(buf, kbuf, sz))
30201 +#ifdef CONFIG_PAX_USERCOPY
30202 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
30203 + if (!temp)
30204 + return -ENOMEM;
30205 + memcpy(temp, kbuf, sz);
30206 +#else
30207 + temp = kbuf;
30208 +#endif
30209 +
30210 + err = copy_to_user(buf, temp, sz);
30211 +
30212 +#ifdef CONFIG_PAX_USERCOPY
30213 + kfree(temp);
30214 +#endif
30215 +
30216 + if (err)
30217 return -EFAULT;
30218 buf += sz;
30219 p += sz;
30220 @@ -833,6 +880,9 @@ static const struct memdev {
30221 #ifdef CONFIG_CRASH_DUMP
30222 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30223 #endif
30224 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30225 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30226 +#endif
30227 };
30228
30229 static int memory_open(struct inode *inode, struct file *filp)
30230 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30231 index 9df78e2..01ba9ae 100644
30232 --- a/drivers/char/nvram.c
30233 +++ b/drivers/char/nvram.c
30234 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30235
30236 spin_unlock_irq(&rtc_lock);
30237
30238 - if (copy_to_user(buf, contents, tmp - contents))
30239 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30240 return -EFAULT;
30241
30242 *ppos = i;
30243 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
30244 index 21721d2..4e98777 100644
30245 --- a/drivers/char/pcmcia/synclink_cs.c
30246 +++ b/drivers/char/pcmcia/synclink_cs.c
30247 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30248
30249 if (debug_level >= DEBUG_LEVEL_INFO)
30250 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
30251 - __FILE__,__LINE__, info->device_name, port->count);
30252 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
30253
30254 - WARN_ON(!port->count);
30255 + WARN_ON(!atomic_read(&port->count));
30256
30257 if (tty_port_close_start(port, tty, filp) == 0)
30258 goto cleanup;
30259 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
30260 cleanup:
30261 if (debug_level >= DEBUG_LEVEL_INFO)
30262 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
30263 - tty->driver->name, port->count);
30264 + tty->driver->name, atomic_read(&port->count));
30265 }
30266
30267 /* Wait until the transmitter is empty.
30268 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30269
30270 if (debug_level >= DEBUG_LEVEL_INFO)
30271 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
30272 - __FILE__,__LINE__,tty->driver->name, port->count);
30273 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
30274
30275 /* If port is closing, signal caller to try again */
30276 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
30277 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
30278 goto cleanup;
30279 }
30280 spin_lock(&port->lock);
30281 - port->count++;
30282 + atomic_inc(&port->count);
30283 spin_unlock(&port->lock);
30284 spin_unlock_irqrestore(&info->netlock, flags);
30285
30286 - if (port->count == 1) {
30287 + if (atomic_read(&port->count) == 1) {
30288 /* 1st open on this device, init hardware */
30289 retval = startup(info, tty);
30290 if (retval < 0)
30291 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
30292 unsigned short new_crctype;
30293
30294 /* return error if TTY interface open */
30295 - if (info->port.count)
30296 + if (atomic_read(&info->port.count))
30297 return -EBUSY;
30298
30299 switch (encoding)
30300 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
30301
30302 /* arbitrate between network and tty opens */
30303 spin_lock_irqsave(&info->netlock, flags);
30304 - if (info->port.count != 0 || info->netcount != 0) {
30305 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
30306 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
30307 spin_unlock_irqrestore(&info->netlock, flags);
30308 return -EBUSY;
30309 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
30310 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
30311
30312 /* return error if TTY interface open */
30313 - if (info->port.count)
30314 + if (atomic_read(&info->port.count))
30315 return -EBUSY;
30316
30317 if (cmd != SIOCWANDEV)
30318 diff --git a/drivers/char/random.c b/drivers/char/random.c
30319 index b86eae9..3f539ae 100644
30320 --- a/drivers/char/random.c
30321 +++ b/drivers/char/random.c
30322 @@ -272,8 +272,13 @@
30323 /*
30324 * Configuration information
30325 */
30326 +#ifdef CONFIG_GRKERNSEC_RANDNET
30327 +#define INPUT_POOL_WORDS 512
30328 +#define OUTPUT_POOL_WORDS 128
30329 +#else
30330 #define INPUT_POOL_WORDS 128
30331 #define OUTPUT_POOL_WORDS 32
30332 +#endif
30333 #define SEC_XFER_SIZE 512
30334 #define EXTRACT_SIZE 10
30335
30336 @@ -313,10 +318,17 @@ static struct poolinfo {
30337 int poolwords;
30338 int tap1, tap2, tap3, tap4, tap5;
30339 } poolinfo_table[] = {
30340 +#ifdef CONFIG_GRKERNSEC_RANDNET
30341 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30342 + { 512, 411, 308, 208, 104, 1 },
30343 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30344 + { 128, 103, 76, 51, 25, 1 },
30345 +#else
30346 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30347 { 128, 103, 76, 51, 25, 1 },
30348 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30349 { 32, 26, 20, 14, 7, 1 },
30350 +#endif
30351 #if 0
30352 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30353 { 2048, 1638, 1231, 819, 411, 1 },
30354 @@ -437,6 +449,7 @@ struct entropy_store {
30355 int entropy_count;
30356 int entropy_total;
30357 unsigned int initialized:1;
30358 + bool last_data_init;
30359 __u8 last_data[EXTRACT_SIZE];
30360 };
30361
30362 @@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
30363 input_rotate += i ? 7 : 14;
30364 }
30365
30366 - ACCESS_ONCE(r->input_rotate) = input_rotate;
30367 - ACCESS_ONCE(r->add_ptr) = i;
30368 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
30369 + ACCESS_ONCE_RW(r->add_ptr) = i;
30370 smp_wmb();
30371
30372 if (out)
30373 @@ -799,6 +812,17 @@ void add_disk_randomness(struct gendisk *disk)
30374 }
30375 #endif
30376
30377 +#ifdef CONFIG_PAX_LATENT_ENTROPY
30378 +u64 latent_entropy;
30379 +
30380 +__init void transfer_latent_entropy(void)
30381 +{
30382 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30383 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
30384 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
30385 +}
30386 +#endif
30387 +
30388 /*********************************************************************
30389 *
30390 * Entropy extraction routines
30391 @@ -957,6 +981,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
30392 ssize_t ret = 0, i;
30393 __u8 tmp[EXTRACT_SIZE];
30394
30395 + /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
30396 + if (fips_enabled && !r->last_data_init)
30397 + nbytes += EXTRACT_SIZE;
30398 +
30399 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
30400 xfer_secondary_pool(r, nbytes);
30401 nbytes = account(r, nbytes, min, reserved);
30402 @@ -967,6 +995,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
30403 if (fips_enabled) {
30404 unsigned long flags;
30405
30406 +
30407 + /* prime last_data value if need be, per fips 140-2 */
30408 + if (!r->last_data_init) {
30409 + spin_lock_irqsave(&r->lock, flags);
30410 + memcpy(r->last_data, tmp, EXTRACT_SIZE);
30411 + r->last_data_init = true;
30412 + nbytes -= EXTRACT_SIZE;
30413 + spin_unlock_irqrestore(&r->lock, flags);
30414 + extract_buf(r, tmp);
30415 + }
30416 +
30417 spin_lock_irqsave(&r->lock, flags);
30418 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
30419 panic("Hardware RNG duplicated output!\n");
30420 @@ -1008,7 +1047,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30421
30422 extract_buf(r, tmp);
30423 i = min_t(int, nbytes, EXTRACT_SIZE);
30424 - if (copy_to_user(buf, tmp, i)) {
30425 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30426 ret = -EFAULT;
30427 break;
30428 }
30429 @@ -1086,6 +1125,7 @@ static void init_std_data(struct entropy_store *r)
30430
30431 r->entropy_count = 0;
30432 r->entropy_total = 0;
30433 + r->last_data_init = false;
30434 mix_pool_bytes(r, &now, sizeof(now), NULL);
30435 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
30436 if (!arch_get_random_long(&rv))
30437 @@ -1342,7 +1382,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30438 #include <linux/sysctl.h>
30439
30440 static int min_read_thresh = 8, min_write_thresh;
30441 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30442 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30443 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30444 static char sysctl_bootid[16];
30445
30446 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30447 index 9b4f011..b7e0a1a 100644
30448 --- a/drivers/char/sonypi.c
30449 +++ b/drivers/char/sonypi.c
30450 @@ -54,6 +54,7 @@
30451
30452 #include <asm/uaccess.h>
30453 #include <asm/io.h>
30454 +#include <asm/local.h>
30455
30456 #include <linux/sonypi.h>
30457
30458 @@ -490,7 +491,7 @@ static struct sonypi_device {
30459 spinlock_t fifo_lock;
30460 wait_queue_head_t fifo_proc_list;
30461 struct fasync_struct *fifo_async;
30462 - int open_count;
30463 + local_t open_count;
30464 int model;
30465 struct input_dev *input_jog_dev;
30466 struct input_dev *input_key_dev;
30467 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30468 static int sonypi_misc_release(struct inode *inode, struct file *file)
30469 {
30470 mutex_lock(&sonypi_device.lock);
30471 - sonypi_device.open_count--;
30472 + local_dec(&sonypi_device.open_count);
30473 mutex_unlock(&sonypi_device.lock);
30474 return 0;
30475 }
30476 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30477 {
30478 mutex_lock(&sonypi_device.lock);
30479 /* Flush input queue on first open */
30480 - if (!sonypi_device.open_count)
30481 + if (!local_read(&sonypi_device.open_count))
30482 kfifo_reset(&sonypi_device.fifo);
30483 - sonypi_device.open_count++;
30484 + local_inc(&sonypi_device.open_count);
30485 mutex_unlock(&sonypi_device.lock);
30486
30487 return 0;
30488 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30489 index 93211df..c7805f7 100644
30490 --- a/drivers/char/tpm/tpm.c
30491 +++ b/drivers/char/tpm/tpm.c
30492 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30493 chip->vendor.req_complete_val)
30494 goto out_recv;
30495
30496 - if ((status == chip->vendor.req_canceled)) {
30497 + if (status == chip->vendor.req_canceled) {
30498 dev_err(chip->dev, "Operation Canceled\n");
30499 rc = -ECANCELED;
30500 goto out;
30501 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
30502 index 56051d0..11cf3b7 100644
30503 --- a/drivers/char/tpm/tpm_acpi.c
30504 +++ b/drivers/char/tpm/tpm_acpi.c
30505 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
30506 virt = acpi_os_map_memory(start, len);
30507 if (!virt) {
30508 kfree(log->bios_event_log);
30509 + log->bios_event_log = NULL;
30510 printk("%s: ERROR - Unable to map memory\n", __func__);
30511 return -EIO;
30512 }
30513
30514 - memcpy_fromio(log->bios_event_log, virt, len);
30515 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
30516
30517 acpi_os_unmap_memory(virt, len);
30518 return 0;
30519 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
30520 index 84ddc55..1d32f1e 100644
30521 --- a/drivers/char/tpm/tpm_eventlog.c
30522 +++ b/drivers/char/tpm/tpm_eventlog.c
30523 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30524 event = addr;
30525
30526 if ((event->event_type == 0 && event->event_size == 0) ||
30527 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30528 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30529 return NULL;
30530
30531 return addr;
30532 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30533 return NULL;
30534
30535 if ((event->event_type == 0 && event->event_size == 0) ||
30536 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30537 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30538 return NULL;
30539
30540 (*pos)++;
30541 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30542 int i;
30543
30544 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30545 - seq_putc(m, data[i]);
30546 + if (!seq_putc(m, data[i]))
30547 + return -EFAULT;
30548
30549 return 0;
30550 }
30551 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30552 index 8ab9c3d..c3e65d3 100644
30553 --- a/drivers/char/virtio_console.c
30554 +++ b/drivers/char/virtio_console.c
30555 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30556 if (to_user) {
30557 ssize_t ret;
30558
30559 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30560 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30561 if (ret)
30562 return -EFAULT;
30563 } else {
30564 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30565 if (!port_has_data(port) && !port->host_connected)
30566 return 0;
30567
30568 - return fill_readbuf(port, ubuf, count, true);
30569 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30570 }
30571
30572 static int wait_port_writable(struct port *port, bool nonblock)
30573 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30574 index e164c55..3aabb50 100644
30575 --- a/drivers/edac/edac_pci_sysfs.c
30576 +++ b/drivers/edac/edac_pci_sysfs.c
30577 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30578 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30579 static int edac_pci_poll_msec = 1000; /* one second workq period */
30580
30581 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30582 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30583 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30584 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30585
30586 static struct kobject *edac_pci_top_main_kobj;
30587 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30588 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30589 edac_printk(KERN_CRIT, EDAC_PCI,
30590 "Signaled System Error on %s\n",
30591 pci_name(dev));
30592 - atomic_inc(&pci_nonparity_count);
30593 + atomic_inc_unchecked(&pci_nonparity_count);
30594 }
30595
30596 if (status & (PCI_STATUS_PARITY)) {
30597 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30598 "Master Data Parity Error on %s\n",
30599 pci_name(dev));
30600
30601 - atomic_inc(&pci_parity_count);
30602 + atomic_inc_unchecked(&pci_parity_count);
30603 }
30604
30605 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30606 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30607 "Detected Parity Error on %s\n",
30608 pci_name(dev));
30609
30610 - atomic_inc(&pci_parity_count);
30611 + atomic_inc_unchecked(&pci_parity_count);
30612 }
30613 }
30614
30615 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30616 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30617 "Signaled System Error on %s\n",
30618 pci_name(dev));
30619 - atomic_inc(&pci_nonparity_count);
30620 + atomic_inc_unchecked(&pci_nonparity_count);
30621 }
30622
30623 if (status & (PCI_STATUS_PARITY)) {
30624 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30625 "Master Data Parity Error on "
30626 "%s\n", pci_name(dev));
30627
30628 - atomic_inc(&pci_parity_count);
30629 + atomic_inc_unchecked(&pci_parity_count);
30630 }
30631
30632 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30633 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30634 "Detected Parity Error on %s\n",
30635 pci_name(dev));
30636
30637 - atomic_inc(&pci_parity_count);
30638 + atomic_inc_unchecked(&pci_parity_count);
30639 }
30640 }
30641 }
30642 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30643 if (!check_pci_errors)
30644 return;
30645
30646 - before_count = atomic_read(&pci_parity_count);
30647 + before_count = atomic_read_unchecked(&pci_parity_count);
30648
30649 /* scan all PCI devices looking for a Parity Error on devices and
30650 * bridges.
30651 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30652 /* Only if operator has selected panic on PCI Error */
30653 if (edac_pci_get_panic_on_pe()) {
30654 /* If the count is different 'after' from 'before' */
30655 - if (before_count != atomic_read(&pci_parity_count))
30656 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30657 panic("EDAC: PCI Parity Error");
30658 }
30659 }
30660 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30661 index 8c87a5e..a19cbd7 100644
30662 --- a/drivers/edac/mce_amd.h
30663 +++ b/drivers/edac/mce_amd.h
30664 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30665 struct amd_decoder_ops {
30666 bool (*dc_mce)(u16, u8);
30667 bool (*ic_mce)(u16, u8);
30668 -};
30669 +} __no_const;
30670
30671 void amd_report_gart_errors(bool);
30672 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30673 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30674 index 57ea7f4..789e3c3 100644
30675 --- a/drivers/firewire/core-card.c
30676 +++ b/drivers/firewire/core-card.c
30677 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30678
30679 void fw_core_remove_card(struct fw_card *card)
30680 {
30681 - struct fw_card_driver dummy_driver = dummy_driver_template;
30682 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30683
30684 card->driver->update_phy_reg(card, 4,
30685 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30686 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30687 index f8d2287..5aaf4db 100644
30688 --- a/drivers/firewire/core-cdev.c
30689 +++ b/drivers/firewire/core-cdev.c
30690 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30691 int ret;
30692
30693 if ((request->channels == 0 && request->bandwidth == 0) ||
30694 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30695 - request->bandwidth < 0)
30696 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30697 return -EINVAL;
30698
30699 r = kmalloc(sizeof(*r), GFP_KERNEL);
30700 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30701 index 28a94c7..58da63a 100644
30702 --- a/drivers/firewire/core-transaction.c
30703 +++ b/drivers/firewire/core-transaction.c
30704 @@ -38,6 +38,7 @@
30705 #include <linux/timer.h>
30706 #include <linux/types.h>
30707 #include <linux/workqueue.h>
30708 +#include <linux/sched.h>
30709
30710 #include <asm/byteorder.h>
30711
30712 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30713 index 515a42c..5ecf3ba 100644
30714 --- a/drivers/firewire/core.h
30715 +++ b/drivers/firewire/core.h
30716 @@ -111,6 +111,7 @@ struct fw_card_driver {
30717
30718 int (*stop_iso)(struct fw_iso_context *ctx);
30719 };
30720 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30721
30722 void fw_card_initialize(struct fw_card *card,
30723 const struct fw_card_driver *driver, struct device *device);
30724 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30725 index b298158..7ed8432 100644
30726 --- a/drivers/firmware/dmi_scan.c
30727 +++ b/drivers/firmware/dmi_scan.c
30728 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30729 }
30730 }
30731 else {
30732 - /*
30733 - * no iounmap() for that ioremap(); it would be a no-op, but
30734 - * it's so early in setup that sucker gets confused into doing
30735 - * what it shouldn't if we actually call it.
30736 - */
30737 p = dmi_ioremap(0xF0000, 0x10000);
30738 if (p == NULL)
30739 goto error;
30740 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30741 if (buf == NULL)
30742 return -1;
30743
30744 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30745 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30746
30747 iounmap(buf);
30748 return 0;
30749 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30750 index 82d5c20..44a7177 100644
30751 --- a/drivers/gpio/gpio-vr41xx.c
30752 +++ b/drivers/gpio/gpio-vr41xx.c
30753 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30754 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30755 maskl, pendl, maskh, pendh);
30756
30757 - atomic_inc(&irq_err_count);
30758 + atomic_inc_unchecked(&irq_err_count);
30759
30760 return -EINVAL;
30761 }
30762 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30763 index 1227adf..f2301c2 100644
30764 --- a/drivers/gpu/drm/drm_crtc_helper.c
30765 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30766 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30767 struct drm_crtc *tmp;
30768 int crtc_mask = 1;
30769
30770 - WARN(!crtc, "checking null crtc?\n");
30771 + BUG_ON(!crtc);
30772
30773 dev = crtc->dev;
30774
30775 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30776 index be174ca..0bcbb71 100644
30777 --- a/drivers/gpu/drm/drm_drv.c
30778 +++ b/drivers/gpu/drm/drm_drv.c
30779 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30780 /**
30781 * Copy and IOCTL return string to user space
30782 */
30783 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30784 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30785 {
30786 int len;
30787
30788 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30789 return -ENODEV;
30790
30791 atomic_inc(&dev->ioctl_count);
30792 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30793 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30794 ++file_priv->ioctl_count;
30795
30796 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30797 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30798 index 133b413..fd68225 100644
30799 --- a/drivers/gpu/drm/drm_fops.c
30800 +++ b/drivers/gpu/drm/drm_fops.c
30801 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30802 }
30803
30804 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30805 - atomic_set(&dev->counts[i], 0);
30806 + atomic_set_unchecked(&dev->counts[i], 0);
30807
30808 dev->sigdata.lock = NULL;
30809
30810 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
30811 if (drm_device_is_unplugged(dev))
30812 return -ENODEV;
30813
30814 - if (!dev->open_count++)
30815 + if (local_inc_return(&dev->open_count) == 1)
30816 need_setup = 1;
30817 mutex_lock(&dev->struct_mutex);
30818 old_mapping = dev->dev_mapping;
30819 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
30820 retcode = drm_open_helper(inode, filp, dev);
30821 if (retcode)
30822 goto err_undo;
30823 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30824 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30825 if (need_setup) {
30826 retcode = drm_setup(dev);
30827 if (retcode)
30828 @@ -164,7 +164,7 @@ err_undo:
30829 iput(container_of(dev->dev_mapping, struct inode, i_data));
30830 dev->dev_mapping = old_mapping;
30831 mutex_unlock(&dev->struct_mutex);
30832 - dev->open_count--;
30833 + local_dec(&dev->open_count);
30834 return retcode;
30835 }
30836 EXPORT_SYMBOL(drm_open);
30837 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
30838
30839 mutex_lock(&drm_global_mutex);
30840
30841 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30842 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30843
30844 if (dev->driver->preclose)
30845 dev->driver->preclose(dev, file_priv);
30846 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
30847 * Begin inline drm_release
30848 */
30849
30850 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30851 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30852 task_pid_nr(current),
30853 (long)old_encode_dev(file_priv->minor->device),
30854 - dev->open_count);
30855 + local_read(&dev->open_count));
30856
30857 /* Release any auth tokens that might point to this file_priv,
30858 (do that under the drm_global_mutex) */
30859 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
30860 * End inline drm_release
30861 */
30862
30863 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30864 - if (!--dev->open_count) {
30865 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30866 + if (local_dec_and_test(&dev->open_count)) {
30867 if (atomic_read(&dev->ioctl_count)) {
30868 DRM_ERROR("Device busy: %d\n",
30869 atomic_read(&dev->ioctl_count));
30870 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30871 index f731116..629842c 100644
30872 --- a/drivers/gpu/drm/drm_global.c
30873 +++ b/drivers/gpu/drm/drm_global.c
30874 @@ -36,7 +36,7 @@
30875 struct drm_global_item {
30876 struct mutex mutex;
30877 void *object;
30878 - int refcount;
30879 + atomic_t refcount;
30880 };
30881
30882 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30883 @@ -49,7 +49,7 @@ void drm_global_init(void)
30884 struct drm_global_item *item = &glob[i];
30885 mutex_init(&item->mutex);
30886 item->object = NULL;
30887 - item->refcount = 0;
30888 + atomic_set(&item->refcount, 0);
30889 }
30890 }
30891
30892 @@ -59,7 +59,7 @@ void drm_global_release(void)
30893 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30894 struct drm_global_item *item = &glob[i];
30895 BUG_ON(item->object != NULL);
30896 - BUG_ON(item->refcount != 0);
30897 + BUG_ON(atomic_read(&item->refcount) != 0);
30898 }
30899 }
30900
30901 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30902 void *object;
30903
30904 mutex_lock(&item->mutex);
30905 - if (item->refcount == 0) {
30906 + if (atomic_read(&item->refcount) == 0) {
30907 item->object = kzalloc(ref->size, GFP_KERNEL);
30908 if (unlikely(item->object == NULL)) {
30909 ret = -ENOMEM;
30910 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30911 goto out_err;
30912
30913 }
30914 - ++item->refcount;
30915 + atomic_inc(&item->refcount);
30916 ref->object = item->object;
30917 object = item->object;
30918 mutex_unlock(&item->mutex);
30919 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30920 struct drm_global_item *item = &glob[ref->global_type];
30921
30922 mutex_lock(&item->mutex);
30923 - BUG_ON(item->refcount == 0);
30924 + BUG_ON(atomic_read(&item->refcount) == 0);
30925 BUG_ON(ref->object != item->object);
30926 - if (--item->refcount == 0) {
30927 + if (atomic_dec_and_test(&item->refcount)) {
30928 ref->release(ref);
30929 item->object = NULL;
30930 }
30931 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30932 index d4b20ce..77a8d41 100644
30933 --- a/drivers/gpu/drm/drm_info.c
30934 +++ b/drivers/gpu/drm/drm_info.c
30935 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30936 struct drm_local_map *map;
30937 struct drm_map_list *r_list;
30938
30939 - /* Hardcoded from _DRM_FRAME_BUFFER,
30940 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30941 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30942 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30943 + static const char * const types[] = {
30944 + [_DRM_FRAME_BUFFER] = "FB",
30945 + [_DRM_REGISTERS] = "REG",
30946 + [_DRM_SHM] = "SHM",
30947 + [_DRM_AGP] = "AGP",
30948 + [_DRM_SCATTER_GATHER] = "SG",
30949 + [_DRM_CONSISTENT] = "PCI",
30950 + [_DRM_GEM] = "GEM" };
30951 const char *type;
30952 int i;
30953
30954 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30955 map = r_list->map;
30956 if (!map)
30957 continue;
30958 - if (map->type < 0 || map->type > 5)
30959 + if (map->type >= ARRAY_SIZE(types))
30960 type = "??";
30961 else
30962 type = types[map->type];
30963 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30964 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30965 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30966 vma->vm_flags & VM_IO ? 'i' : '-',
30967 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30968 + 0);
30969 +#else
30970 vma->vm_pgoff);
30971 +#endif
30972
30973 #if defined(__i386__)
30974 pgprot = pgprot_val(vma->vm_page_prot);
30975 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30976 index 2f4c434..764794b 100644
30977 --- a/drivers/gpu/drm/drm_ioc32.c
30978 +++ b/drivers/gpu/drm/drm_ioc32.c
30979 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30980 request = compat_alloc_user_space(nbytes);
30981 if (!access_ok(VERIFY_WRITE, request, nbytes))
30982 return -EFAULT;
30983 - list = (struct drm_buf_desc *) (request + 1);
30984 + list = (struct drm_buf_desc __user *) (request + 1);
30985
30986 if (__put_user(count, &request->count)
30987 || __put_user(list, &request->list))
30988 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30989 request = compat_alloc_user_space(nbytes);
30990 if (!access_ok(VERIFY_WRITE, request, nbytes))
30991 return -EFAULT;
30992 - list = (struct drm_buf_pub *) (request + 1);
30993 + list = (struct drm_buf_pub __user *) (request + 1);
30994
30995 if (__put_user(count, &request->count)
30996 || __put_user(list, &request->list))
30997 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30998 index 23dd975..63e9801 100644
30999 --- a/drivers/gpu/drm/drm_ioctl.c
31000 +++ b/drivers/gpu/drm/drm_ioctl.c
31001 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
31002 stats->data[i].value =
31003 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
31004 else
31005 - stats->data[i].value = atomic_read(&dev->counts[i]);
31006 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
31007 stats->data[i].type = dev->types[i];
31008 }
31009
31010 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
31011 index d752c96..fe08455 100644
31012 --- a/drivers/gpu/drm/drm_lock.c
31013 +++ b/drivers/gpu/drm/drm_lock.c
31014 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
31015 if (drm_lock_take(&master->lock, lock->context)) {
31016 master->lock.file_priv = file_priv;
31017 master->lock.lock_time = jiffies;
31018 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
31019 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
31020 break; /* Got lock */
31021 }
31022
31023 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
31024 return -EINVAL;
31025 }
31026
31027 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
31028 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
31029
31030 if (drm_lock_free(&master->lock, lock->context)) {
31031 /* FIXME: Should really bail out here. */
31032 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
31033 index c236fd2..6b5f2e7 100644
31034 --- a/drivers/gpu/drm/drm_stub.c
31035 +++ b/drivers/gpu/drm/drm_stub.c
31036 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
31037
31038 drm_device_set_unplugged(dev);
31039
31040 - if (dev->open_count == 0) {
31041 + if (local_read(&dev->open_count) == 0) {
31042 drm_put_dev(dev);
31043 }
31044 mutex_unlock(&drm_global_mutex);
31045 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
31046 index 004ecdf..db1f6e0 100644
31047 --- a/drivers/gpu/drm/i810/i810_dma.c
31048 +++ b/drivers/gpu/drm/i810/i810_dma.c
31049 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
31050 dma->buflist[vertex->idx],
31051 vertex->discard, vertex->used);
31052
31053 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
31054 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
31055 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
31056 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
31057 sarea_priv->last_enqueue = dev_priv->counter - 1;
31058 sarea_priv->last_dispatch = (int)hw_status[5];
31059
31060 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
31061 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
31062 mc->last_render);
31063
31064 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
31065 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
31066 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
31067 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
31068 sarea_priv->last_enqueue = dev_priv->counter - 1;
31069 sarea_priv->last_dispatch = (int)hw_status[5];
31070
31071 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
31072 index 6e0acad..93c8289 100644
31073 --- a/drivers/gpu/drm/i810/i810_drv.h
31074 +++ b/drivers/gpu/drm/i810/i810_drv.h
31075 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
31076 int page_flipping;
31077
31078 wait_queue_head_t irq_queue;
31079 - atomic_t irq_received;
31080 - atomic_t irq_emitted;
31081 + atomic_unchecked_t irq_received;
31082 + atomic_unchecked_t irq_emitted;
31083
31084 int front_offset;
31085 } drm_i810_private_t;
31086 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
31087 index dde8b50..da88e32 100644
31088 --- a/drivers/gpu/drm/i915/i915_debugfs.c
31089 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
31090 @@ -495,7 +495,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
31091 I915_READ(GTIMR));
31092 }
31093 seq_printf(m, "Interrupts received: %d\n",
31094 - atomic_read(&dev_priv->irq_received));
31095 + atomic_read_unchecked(&dev_priv->irq_received));
31096 for_each_ring(ring, dev_priv, i) {
31097 if (IS_GEN6(dev) || IS_GEN7(dev)) {
31098 seq_printf(m,
31099 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
31100 index 61ae104..f8a4bc1 100644
31101 --- a/drivers/gpu/drm/i915/i915_dma.c
31102 +++ b/drivers/gpu/drm/i915/i915_dma.c
31103 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
31104 bool can_switch;
31105
31106 spin_lock(&dev->count_lock);
31107 - can_switch = (dev->open_count == 0);
31108 + can_switch = (local_read(&dev->open_count) == 0);
31109 spin_unlock(&dev->count_lock);
31110 return can_switch;
31111 }
31112 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
31113 index f511fa2..4c11773 100644
31114 --- a/drivers/gpu/drm/i915/i915_drv.h
31115 +++ b/drivers/gpu/drm/i915/i915_drv.h
31116 @@ -274,12 +274,12 @@ struct drm_i915_display_funcs {
31117 /* render clock increase/decrease */
31118 /* display clock increase/decrease */
31119 /* pll clock increase/decrease */
31120 -};
31121 +} __no_const;
31122
31123 struct drm_i915_gt_funcs {
31124 void (*force_wake_get)(struct drm_i915_private *dev_priv);
31125 void (*force_wake_put)(struct drm_i915_private *dev_priv);
31126 -};
31127 +} __no_const;
31128
31129 #define DEV_INFO_FLAGS \
31130 DEV_INFO_FLAG(is_mobile) DEV_INFO_SEP \
31131 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
31132
31133 struct resource mch_res;
31134
31135 - atomic_t irq_received;
31136 + atomic_unchecked_t irq_received;
31137
31138 /* protects the irq masks */
31139 spinlock_t irq_lock;
31140 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
31141 * will be page flipped away on the next vblank. When it
31142 * reaches 0, dev_priv->pending_flip_queue will be woken up.
31143 */
31144 - atomic_t pending_flip;
31145 + atomic_unchecked_t pending_flip;
31146 };
31147
31148 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
31149 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
31150 struct drm_i915_private *dev_priv, unsigned port);
31151 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
31152 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
31153 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31154 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31155 {
31156 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
31157 }
31158 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31159 index 3eea143..a0b77db 100644
31160 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31161 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31162 @@ -660,7 +660,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
31163 i915_gem_clflush_object(obj);
31164
31165 if (obj->base.pending_write_domain)
31166 - flips |= atomic_read(&obj->pending_flip);
31167 + flips |= atomic_read_unchecked(&obj->pending_flip);
31168
31169 flush_domains |= obj->base.write_domain;
31170 }
31171 @@ -691,9 +691,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
31172
31173 static int
31174 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
31175 - int count)
31176 + unsigned int count)
31177 {
31178 - int i;
31179 + unsigned int i;
31180
31181 for (i = 0; i < count; i++) {
31182 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
31183 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
31184 index 32e1bda..9b2ca91 100644
31185 --- a/drivers/gpu/drm/i915/i915_irq.c
31186 +++ b/drivers/gpu/drm/i915/i915_irq.c
31187 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
31188 u32 pipe_stats[I915_MAX_PIPES];
31189 bool blc_event;
31190
31191 - atomic_inc(&dev_priv->irq_received);
31192 + atomic_inc_unchecked(&dev_priv->irq_received);
31193
31194 while (true) {
31195 iir = I915_READ(VLV_IIR);
31196 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
31197 irqreturn_t ret = IRQ_NONE;
31198 int i;
31199
31200 - atomic_inc(&dev_priv->irq_received);
31201 + atomic_inc_unchecked(&dev_priv->irq_received);
31202
31203 /* disable master interrupt before clearing iir */
31204 de_ier = I915_READ(DEIER);
31205 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
31206 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
31207 u32 hotplug_mask;
31208
31209 - atomic_inc(&dev_priv->irq_received);
31210 + atomic_inc_unchecked(&dev_priv->irq_received);
31211
31212 /* disable master interrupt before clearing iir */
31213 de_ier = I915_READ(DEIER);
31214 @@ -1760,7 +1760,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31215 {
31216 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31217
31218 - atomic_set(&dev_priv->irq_received, 0);
31219 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31220
31221 I915_WRITE(HWSTAM, 0xeffe);
31222
31223 @@ -1786,7 +1786,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
31224 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31225 int pipe;
31226
31227 - atomic_set(&dev_priv->irq_received, 0);
31228 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31229
31230 /* VLV magic */
31231 I915_WRITE(VLV_IMR, 0);
31232 @@ -2091,7 +2091,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
31233 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31234 int pipe;
31235
31236 - atomic_set(&dev_priv->irq_received, 0);
31237 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31238
31239 for_each_pipe(pipe)
31240 I915_WRITE(PIPESTAT(pipe), 0);
31241 @@ -2142,7 +2142,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
31242 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
31243 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
31244
31245 - atomic_inc(&dev_priv->irq_received);
31246 + atomic_inc_unchecked(&dev_priv->irq_received);
31247
31248 iir = I915_READ16(IIR);
31249 if (iir == 0)
31250 @@ -2227,7 +2227,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
31251 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31252 int pipe;
31253
31254 - atomic_set(&dev_priv->irq_received, 0);
31255 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31256
31257 if (I915_HAS_HOTPLUG(dev)) {
31258 I915_WRITE(PORT_HOTPLUG_EN, 0);
31259 @@ -2322,7 +2322,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
31260 };
31261 int pipe, ret = IRQ_NONE;
31262
31263 - atomic_inc(&dev_priv->irq_received);
31264 + atomic_inc_unchecked(&dev_priv->irq_received);
31265
31266 iir = I915_READ(IIR);
31267 do {
31268 @@ -2448,7 +2448,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
31269 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31270 int pipe;
31271
31272 - atomic_set(&dev_priv->irq_received, 0);
31273 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31274
31275 I915_WRITE(PORT_HOTPLUG_EN, 0);
31276 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
31277 @@ -2555,7 +2555,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
31278 int irq_received;
31279 int ret = IRQ_NONE, pipe;
31280
31281 - atomic_inc(&dev_priv->irq_received);
31282 + atomic_inc_unchecked(&dev_priv->irq_received);
31283
31284 iir = I915_READ(IIR);
31285
31286 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31287 index b426d44..1b9038d 100644
31288 --- a/drivers/gpu/drm/i915/intel_display.c
31289 +++ b/drivers/gpu/drm/i915/intel_display.c
31290 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
31291
31292 wait_event(dev_priv->pending_flip_queue,
31293 atomic_read(&dev_priv->mm.wedged) ||
31294 - atomic_read(&obj->pending_flip) == 0);
31295 + atomic_read_unchecked(&obj->pending_flip) == 0);
31296
31297 /* Big Hammer, we also need to ensure that any pending
31298 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31299 @@ -6236,8 +6236,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31300
31301 obj = work->old_fb_obj;
31302
31303 - atomic_clear_mask(1 << intel_crtc->plane,
31304 - &obj->pending_flip.counter);
31305 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
31306
31307 wake_up(&dev_priv->pending_flip_queue);
31308 schedule_work(&work->work);
31309 @@ -6583,7 +6582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31310 /* Block clients from rendering to the new back buffer until
31311 * the flip occurs and the object is no longer visible.
31312 */
31313 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31314 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31315
31316 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31317 if (ret)
31318 @@ -6598,7 +6597,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31319 return 0;
31320
31321 cleanup_pending:
31322 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31323 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31324 drm_gem_object_unreference(&work->old_fb_obj->base);
31325 drm_gem_object_unreference(&obj->base);
31326 mutex_unlock(&dev->struct_mutex);
31327 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31328 index 54558a0..2d97005 100644
31329 --- a/drivers/gpu/drm/mga/mga_drv.h
31330 +++ b/drivers/gpu/drm/mga/mga_drv.h
31331 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31332 u32 clear_cmd;
31333 u32 maccess;
31334
31335 - atomic_t vbl_received; /**< Number of vblanks received. */
31336 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31337 wait_queue_head_t fence_queue;
31338 - atomic_t last_fence_retired;
31339 + atomic_unchecked_t last_fence_retired;
31340 u32 next_fence_to_post;
31341
31342 unsigned int fb_cpp;
31343 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31344 index 598c281..60d590e 100644
31345 --- a/drivers/gpu/drm/mga/mga_irq.c
31346 +++ b/drivers/gpu/drm/mga/mga_irq.c
31347 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31348 if (crtc != 0)
31349 return 0;
31350
31351 - return atomic_read(&dev_priv->vbl_received);
31352 + return atomic_read_unchecked(&dev_priv->vbl_received);
31353 }
31354
31355
31356 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31357 /* VBLANK interrupt */
31358 if (status & MGA_VLINEPEN) {
31359 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31360 - atomic_inc(&dev_priv->vbl_received);
31361 + atomic_inc_unchecked(&dev_priv->vbl_received);
31362 drm_handle_vblank(dev, 0);
31363 handled = 1;
31364 }
31365 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31366 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31367 MGA_WRITE(MGA_PRIMEND, prim_end);
31368
31369 - atomic_inc(&dev_priv->last_fence_retired);
31370 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31371 DRM_WAKEUP(&dev_priv->fence_queue);
31372 handled = 1;
31373 }
31374 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31375 * using fences.
31376 */
31377 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31378 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31379 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31380 - *sequence) <= (1 << 23)));
31381
31382 *sequence = cur_fence;
31383 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31384 index 09fdef2..57f5c3b 100644
31385 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31386 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31387 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31388 struct bit_table {
31389 const char id;
31390 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31391 -};
31392 +} __no_const;
31393
31394 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31395
31396 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
31397 index a101699..a163f0a 100644
31398 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
31399 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
31400 @@ -80,7 +80,7 @@ struct nouveau_drm {
31401 struct drm_global_reference mem_global_ref;
31402 struct ttm_bo_global_ref bo_global_ref;
31403 struct ttm_bo_device bdev;
31404 - atomic_t validate_sequence;
31405 + atomic_unchecked_t validate_sequence;
31406 int (*move)(struct nouveau_channel *,
31407 struct ttm_buffer_object *,
31408 struct ttm_mem_reg *, struct ttm_mem_reg *);
31409 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
31410 index bedafd1..ca5330a 100644
31411 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
31412 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
31413 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
31414 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
31415 struct nouveau_channel *);
31416 u32 (*read)(struct nouveau_channel *);
31417 -};
31418 +} __no_const;
31419
31420 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
31421
31422 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31423 index 5e2f521..0d21436 100644
31424 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31425 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31426 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31427 int trycnt = 0;
31428 int ret, i;
31429
31430 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
31431 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
31432 retry:
31433 if (++trycnt > 100000) {
31434 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
31435 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
31436 index 6f0ac64..9c2dfb4 100644
31437 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
31438 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
31439 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31440 bool can_switch;
31441
31442 spin_lock(&dev->count_lock);
31443 - can_switch = (dev->open_count == 0);
31444 + can_switch = (local_read(&dev->open_count) == 0);
31445 spin_unlock(&dev->count_lock);
31446 return can_switch;
31447 }
31448 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
31449 index 9f6f55c..30e3a29 100644
31450 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
31451 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
31452 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
31453 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
31454 evo->object->oclass->ofuncs =
31455 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
31456 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
31457 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
31458 - evo->object->oclass->ofuncs->rd08 =
31459 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
31460 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
31461 + *(void**)&evo->object->oclass->ofuncs->rd08 =
31462 ioremap(pci_resource_start(dev->pdev, 0) +
31463 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
31464 return 0;
31465 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31466 index b562b59..9d725a8 100644
31467 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31468 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31469 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31470 }
31471
31472 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
31473 - struct dp_train_func func = {
31474 + static struct dp_train_func func = {
31475 .link_set = nv50_sor_dp_link_set,
31476 .train_set = nv50_sor_dp_train_set,
31477 .train_adj = nv50_sor_dp_train_adj
31478 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31479 index c402fca..f1d694b 100644
31480 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31481 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31482 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31483 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31484
31485 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
31486 - struct dp_train_func func = {
31487 + static struct dp_train_func func = {
31488 .link_set = nvd0_sor_dp_link_set,
31489 .train_set = nvd0_sor_dp_train_set,
31490 .train_adj = nvd0_sor_dp_train_adj
31491 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31492 index d4660cf..70dbe65 100644
31493 --- a/drivers/gpu/drm/r128/r128_cce.c
31494 +++ b/drivers/gpu/drm/r128/r128_cce.c
31495 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31496
31497 /* GH: Simple idle check.
31498 */
31499 - atomic_set(&dev_priv->idle_count, 0);
31500 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31501
31502 /* We don't support anything other than bus-mastering ring mode,
31503 * but the ring can be in either AGP or PCI space for the ring
31504 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31505 index 930c71b..499aded 100644
31506 --- a/drivers/gpu/drm/r128/r128_drv.h
31507 +++ b/drivers/gpu/drm/r128/r128_drv.h
31508 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31509 int is_pci;
31510 unsigned long cce_buffers_offset;
31511
31512 - atomic_t idle_count;
31513 + atomic_unchecked_t idle_count;
31514
31515 int page_flipping;
31516 int current_page;
31517 u32 crtc_offset;
31518 u32 crtc_offset_cntl;
31519
31520 - atomic_t vbl_received;
31521 + atomic_unchecked_t vbl_received;
31522
31523 u32 color_fmt;
31524 unsigned int front_offset;
31525 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31526 index 2ea4f09..d391371 100644
31527 --- a/drivers/gpu/drm/r128/r128_irq.c
31528 +++ b/drivers/gpu/drm/r128/r128_irq.c
31529 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31530 if (crtc != 0)
31531 return 0;
31532
31533 - return atomic_read(&dev_priv->vbl_received);
31534 + return atomic_read_unchecked(&dev_priv->vbl_received);
31535 }
31536
31537 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31538 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31539 /* VBLANK interrupt */
31540 if (status & R128_CRTC_VBLANK_INT) {
31541 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31542 - atomic_inc(&dev_priv->vbl_received);
31543 + atomic_inc_unchecked(&dev_priv->vbl_received);
31544 drm_handle_vblank(dev, 0);
31545 return IRQ_HANDLED;
31546 }
31547 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31548 index 19bb7e6..de7e2a2 100644
31549 --- a/drivers/gpu/drm/r128/r128_state.c
31550 +++ b/drivers/gpu/drm/r128/r128_state.c
31551 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31552
31553 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31554 {
31555 - if (atomic_read(&dev_priv->idle_count) == 0)
31556 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31557 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31558 else
31559 - atomic_set(&dev_priv->idle_count, 0);
31560 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31561 }
31562
31563 #endif
31564 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31565 index 5a82b6b..9e69c73 100644
31566 --- a/drivers/gpu/drm/radeon/mkregtable.c
31567 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31568 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31569 regex_t mask_rex;
31570 regmatch_t match[4];
31571 char buf[1024];
31572 - size_t end;
31573 + long end;
31574 int len;
31575 int done = 0;
31576 int r;
31577 unsigned o;
31578 struct offset *offset;
31579 char last_reg_s[10];
31580 - int last_reg;
31581 + unsigned long last_reg;
31582
31583 if (regcomp
31584 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31585 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31586 index 8c42d54..5ef3789 100644
31587 --- a/drivers/gpu/drm/radeon/radeon.h
31588 +++ b/drivers/gpu/drm/radeon/radeon.h
31589 @@ -728,7 +728,7 @@ struct r600_blit_cp_primitives {
31590 int x2, int y2);
31591 void (*draw_auto)(struct radeon_device *rdev);
31592 void (*set_default_state)(struct radeon_device *rdev);
31593 -};
31594 +} __no_const;
31595
31596 struct r600_blit {
31597 struct radeon_bo *shader_obj;
31598 @@ -1248,7 +1248,7 @@ struct radeon_asic {
31599 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31600 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31601 } pflip;
31602 -};
31603 +} __no_const;
31604
31605 /*
31606 * Asic structures
31607 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31608 index e2f5f88..82f22da 100644
31609 --- a/drivers/gpu/drm/radeon/radeon_device.c
31610 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31611 @@ -940,7 +940,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31612 bool can_switch;
31613
31614 spin_lock(&dev->count_lock);
31615 - can_switch = (dev->open_count == 0);
31616 + can_switch = (local_read(&dev->open_count) == 0);
31617 spin_unlock(&dev->count_lock);
31618 return can_switch;
31619 }
31620 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31621 index a1b59ca..86f2d44 100644
31622 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31623 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31624 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31625
31626 /* SW interrupt */
31627 wait_queue_head_t swi_queue;
31628 - atomic_t swi_emitted;
31629 + atomic_unchecked_t swi_emitted;
31630 int vblank_crtc;
31631 uint32_t irq_enable_reg;
31632 uint32_t r500_disp_irq_reg;
31633 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31634 index c180df8..cd80dd2d 100644
31635 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31636 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31637 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31638 request = compat_alloc_user_space(sizeof(*request));
31639 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31640 || __put_user(req32.param, &request->param)
31641 - || __put_user((void __user *)(unsigned long)req32.value,
31642 + || __put_user((unsigned long)req32.value,
31643 &request->value))
31644 return -EFAULT;
31645
31646 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31647 index e771033..a0bc6b3 100644
31648 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31649 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31650 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31651 unsigned int ret;
31652 RING_LOCALS;
31653
31654 - atomic_inc(&dev_priv->swi_emitted);
31655 - ret = atomic_read(&dev_priv->swi_emitted);
31656 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31657 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31658
31659 BEGIN_RING(4);
31660 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31661 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31662 drm_radeon_private_t *dev_priv =
31663 (drm_radeon_private_t *) dev->dev_private;
31664
31665 - atomic_set(&dev_priv->swi_emitted, 0);
31666 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31667 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31668
31669 dev->max_vblank_count = 0x001fffff;
31670 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31671 index 8e9057b..af6dacb 100644
31672 --- a/drivers/gpu/drm/radeon/radeon_state.c
31673 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31674 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31675 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31676 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31677
31678 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31679 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31680 sarea_priv->nbox * sizeof(depth_boxes[0])))
31681 return -EFAULT;
31682
31683 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31684 {
31685 drm_radeon_private_t *dev_priv = dev->dev_private;
31686 drm_radeon_getparam_t *param = data;
31687 - int value;
31688 + int value = 0;
31689
31690 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31691
31692 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31693 index 5ebe1b3..1ed9426 100644
31694 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31695 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31696 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31697 }
31698 if (unlikely(ttm_vm_ops == NULL)) {
31699 ttm_vm_ops = vma->vm_ops;
31700 - radeon_ttm_vm_ops = *ttm_vm_ops;
31701 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31702 + pax_open_kernel();
31703 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31704 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31705 + pax_close_kernel();
31706 }
31707 vma->vm_ops = &radeon_ttm_vm_ops;
31708 return 0;
31709 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31710 index 5706d2a..17aedaa 100644
31711 --- a/drivers/gpu/drm/radeon/rs690.c
31712 +++ b/drivers/gpu/drm/radeon/rs690.c
31713 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31714 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31715 rdev->pm.sideport_bandwidth.full)
31716 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31717 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31718 + read_delay_latency.full = dfixed_const(800 * 1000);
31719 read_delay_latency.full = dfixed_div(read_delay_latency,
31720 rdev->pm.igp_sideport_mclk);
31721 + a.full = dfixed_const(370);
31722 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31723 } else {
31724 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31725 rdev->pm.k8_bandwidth.full)
31726 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31727 index bd2a3b4..122d9ad 100644
31728 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31729 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31730 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31731 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31732 struct shrink_control *sc)
31733 {
31734 - static atomic_t start_pool = ATOMIC_INIT(0);
31735 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31736 unsigned i;
31737 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31738 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31739 struct ttm_page_pool *pool;
31740 int shrink_pages = sc->nr_to_scan;
31741
31742 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31743 index 893a650..6190d3b 100644
31744 --- a/drivers/gpu/drm/via/via_drv.h
31745 +++ b/drivers/gpu/drm/via/via_drv.h
31746 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31747 typedef uint32_t maskarray_t[5];
31748
31749 typedef struct drm_via_irq {
31750 - atomic_t irq_received;
31751 + atomic_unchecked_t irq_received;
31752 uint32_t pending_mask;
31753 uint32_t enable_mask;
31754 wait_queue_head_t irq_queue;
31755 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31756 struct timeval last_vblank;
31757 int last_vblank_valid;
31758 unsigned usec_per_vblank;
31759 - atomic_t vbl_received;
31760 + atomic_unchecked_t vbl_received;
31761 drm_via_state_t hc_state;
31762 char pci_buf[VIA_PCI_BUF_SIZE];
31763 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31764 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31765 index ac98964..5dbf512 100644
31766 --- a/drivers/gpu/drm/via/via_irq.c
31767 +++ b/drivers/gpu/drm/via/via_irq.c
31768 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31769 if (crtc != 0)
31770 return 0;
31771
31772 - return atomic_read(&dev_priv->vbl_received);
31773 + return atomic_read_unchecked(&dev_priv->vbl_received);
31774 }
31775
31776 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31777 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31778
31779 status = VIA_READ(VIA_REG_INTERRUPT);
31780 if (status & VIA_IRQ_VBLANK_PENDING) {
31781 - atomic_inc(&dev_priv->vbl_received);
31782 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31783 + atomic_inc_unchecked(&dev_priv->vbl_received);
31784 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31785 do_gettimeofday(&cur_vblank);
31786 if (dev_priv->last_vblank_valid) {
31787 dev_priv->usec_per_vblank =
31788 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31789 dev_priv->last_vblank = cur_vblank;
31790 dev_priv->last_vblank_valid = 1;
31791 }
31792 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31793 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31794 DRM_DEBUG("US per vblank is: %u\n",
31795 dev_priv->usec_per_vblank);
31796 }
31797 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31798
31799 for (i = 0; i < dev_priv->num_irqs; ++i) {
31800 if (status & cur_irq->pending_mask) {
31801 - atomic_inc(&cur_irq->irq_received);
31802 + atomic_inc_unchecked(&cur_irq->irq_received);
31803 DRM_WAKEUP(&cur_irq->irq_queue);
31804 handled = 1;
31805 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31806 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31807 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31808 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31809 masks[irq][4]));
31810 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31811 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31812 } else {
31813 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31814 (((cur_irq_sequence =
31815 - atomic_read(&cur_irq->irq_received)) -
31816 + atomic_read_unchecked(&cur_irq->irq_received)) -
31817 *sequence) <= (1 << 23)));
31818 }
31819 *sequence = cur_irq_sequence;
31820 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31821 }
31822
31823 for (i = 0; i < dev_priv->num_irqs; ++i) {
31824 - atomic_set(&cur_irq->irq_received, 0);
31825 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31826 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31827 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31828 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31829 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31830 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31831 case VIA_IRQ_RELATIVE:
31832 irqwait->request.sequence +=
31833 - atomic_read(&cur_irq->irq_received);
31834 + atomic_read_unchecked(&cur_irq->irq_received);
31835 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31836 case VIA_IRQ_ABSOLUTE:
31837 break;
31838 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31839 index 88a179e..57fe50481c 100644
31840 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31841 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31842 @@ -263,7 +263,7 @@ struct vmw_private {
31843 * Fencing and IRQs.
31844 */
31845
31846 - atomic_t marker_seq;
31847 + atomic_unchecked_t marker_seq;
31848 wait_queue_head_t fence_queue;
31849 wait_queue_head_t fifo_queue;
31850 int fence_queue_waiters; /* Protected by hw_mutex */
31851 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31852 index 3eb1486..0a47ee9 100644
31853 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31854 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31855 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31856 (unsigned int) min,
31857 (unsigned int) fifo->capabilities);
31858
31859 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31860 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31861 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31862 vmw_marker_queue_init(&fifo->marker_queue);
31863 return vmw_fifo_send_fence(dev_priv, &dummy);
31864 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31865 if (reserveable)
31866 iowrite32(bytes, fifo_mem +
31867 SVGA_FIFO_RESERVED);
31868 - return fifo_mem + (next_cmd >> 2);
31869 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31870 } else {
31871 need_bounce = true;
31872 }
31873 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31874
31875 fm = vmw_fifo_reserve(dev_priv, bytes);
31876 if (unlikely(fm == NULL)) {
31877 - *seqno = atomic_read(&dev_priv->marker_seq);
31878 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31879 ret = -ENOMEM;
31880 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31881 false, 3*HZ);
31882 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31883 }
31884
31885 do {
31886 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31887 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31888 } while (*seqno == 0);
31889
31890 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31891 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31892 index 4640adb..e1384ed 100644
31893 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31894 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31895 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31896 * emitted. Then the fence is stale and signaled.
31897 */
31898
31899 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31900 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31901 > VMW_FENCE_WRAP);
31902
31903 return ret;
31904 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31905
31906 if (fifo_idle)
31907 down_read(&fifo_state->rwsem);
31908 - signal_seq = atomic_read(&dev_priv->marker_seq);
31909 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31910 ret = 0;
31911
31912 for (;;) {
31913 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31914 index 8a8725c..afed796 100644
31915 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31916 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31917 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31918 while (!vmw_lag_lt(queue, us)) {
31919 spin_lock(&queue->lock);
31920 if (list_empty(&queue->head))
31921 - seqno = atomic_read(&dev_priv->marker_seq);
31922 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31923 else {
31924 marker = list_first_entry(&queue->head,
31925 struct vmw_marker, head);
31926 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31927 index f4109fd..7c62889 100644
31928 --- a/drivers/hid/hid-core.c
31929 +++ b/drivers/hid/hid-core.c
31930 @@ -2200,7 +2200,7 @@ static bool hid_ignore(struct hid_device *hdev)
31931
31932 int hid_add_device(struct hid_device *hdev)
31933 {
31934 - static atomic_t id = ATOMIC_INIT(0);
31935 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31936 int ret;
31937
31938 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31939 @@ -2235,7 +2235,7 @@ int hid_add_device(struct hid_device *hdev)
31940 /* XXX hack, any other cleaner solution after the driver core
31941 * is converted to allow more than 20 bytes as the device name? */
31942 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31943 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31944 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31945
31946 hid_debug_register(hdev, dev_name(&hdev->dev));
31947 ret = device_add(&hdev->dev);
31948 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31949 index eec3291..8ed706b 100644
31950 --- a/drivers/hid/hid-wiimote-debug.c
31951 +++ b/drivers/hid/hid-wiimote-debug.c
31952 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31953 else if (size == 0)
31954 return -EIO;
31955
31956 - if (copy_to_user(u, buf, size))
31957 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31958 return -EFAULT;
31959
31960 *off += size;
31961 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31962 index 14599e2..711c965 100644
31963 --- a/drivers/hid/usbhid/hiddev.c
31964 +++ b/drivers/hid/usbhid/hiddev.c
31965 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31966 break;
31967
31968 case HIDIOCAPPLICATION:
31969 - if (arg < 0 || arg >= hid->maxapplication)
31970 + if (arg >= hid->maxapplication)
31971 break;
31972
31973 for (i = 0; i < hid->maxcollection; i++)
31974 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31975 index f4c3d28..82f45a9 100644
31976 --- a/drivers/hv/channel.c
31977 +++ b/drivers/hv/channel.c
31978 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31979 int ret = 0;
31980 int t;
31981
31982 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31983 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31984 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31985 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31986
31987 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31988 if (ret)
31989 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31990 index 3648f8f..30ef30d 100644
31991 --- a/drivers/hv/hv.c
31992 +++ b/drivers/hv/hv.c
31993 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31994 u64 output_address = (output) ? virt_to_phys(output) : 0;
31995 u32 output_address_hi = output_address >> 32;
31996 u32 output_address_lo = output_address & 0xFFFFFFFF;
31997 - void *hypercall_page = hv_context.hypercall_page;
31998 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31999
32000 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
32001 "=a"(hv_status_lo) : "d" (control_hi),
32002 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
32003 index d8d1fad..b91caf7 100644
32004 --- a/drivers/hv/hyperv_vmbus.h
32005 +++ b/drivers/hv/hyperv_vmbus.h
32006 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
32007 struct vmbus_connection {
32008 enum vmbus_connect_state conn_state;
32009
32010 - atomic_t next_gpadl_handle;
32011 + atomic_unchecked_t next_gpadl_handle;
32012
32013 /*
32014 * Represents channel interrupts. Each bit position represents a
32015 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
32016 index 8e1a9ec..4687821 100644
32017 --- a/drivers/hv/vmbus_drv.c
32018 +++ b/drivers/hv/vmbus_drv.c
32019 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
32020 {
32021 int ret = 0;
32022
32023 - static atomic_t device_num = ATOMIC_INIT(0);
32024 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
32025
32026 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
32027 - atomic_inc_return(&device_num));
32028 + atomic_inc_return_unchecked(&device_num));
32029
32030 child_device_obj->device.bus = &hv_bus;
32031 child_device_obj->device.parent = &hv_acpi_dev->dev;
32032 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
32033 index 07a0c1a..0cac334 100644
32034 --- a/drivers/hwmon/sht15.c
32035 +++ b/drivers/hwmon/sht15.c
32036 @@ -169,7 +169,7 @@ struct sht15_data {
32037 int supply_uV;
32038 bool supply_uV_valid;
32039 struct work_struct update_supply_work;
32040 - atomic_t interrupt_handled;
32041 + atomic_unchecked_t interrupt_handled;
32042 };
32043
32044 /**
32045 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
32046 return ret;
32047
32048 gpio_direction_input(data->pdata->gpio_data);
32049 - atomic_set(&data->interrupt_handled, 0);
32050 + atomic_set_unchecked(&data->interrupt_handled, 0);
32051
32052 enable_irq(gpio_to_irq(data->pdata->gpio_data));
32053 if (gpio_get_value(data->pdata->gpio_data) == 0) {
32054 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
32055 /* Only relevant if the interrupt hasn't occurred. */
32056 - if (!atomic_read(&data->interrupt_handled))
32057 + if (!atomic_read_unchecked(&data->interrupt_handled))
32058 schedule_work(&data->read_work);
32059 }
32060 ret = wait_event_timeout(data->wait_queue,
32061 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
32062
32063 /* First disable the interrupt */
32064 disable_irq_nosync(irq);
32065 - atomic_inc(&data->interrupt_handled);
32066 + atomic_inc_unchecked(&data->interrupt_handled);
32067 /* Then schedule a reading work struct */
32068 if (data->state != SHT15_READING_NOTHING)
32069 schedule_work(&data->read_work);
32070 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
32071 * If not, then start the interrupt again - care here as could
32072 * have gone low in meantime so verify it hasn't!
32073 */
32074 - atomic_set(&data->interrupt_handled, 0);
32075 + atomic_set_unchecked(&data->interrupt_handled, 0);
32076 enable_irq(gpio_to_irq(data->pdata->gpio_data));
32077 /* If still not occurred or another handler was scheduled */
32078 if (gpio_get_value(data->pdata->gpio_data)
32079 - || atomic_read(&data->interrupt_handled))
32080 + || atomic_read_unchecked(&data->interrupt_handled))
32081 return;
32082 }
32083
32084 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
32085 index 378fcb5..5e91fa8 100644
32086 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
32087 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
32088 @@ -43,7 +43,7 @@
32089 extern struct i2c_adapter amd756_smbus;
32090
32091 static struct i2c_adapter *s4882_adapter;
32092 -static struct i2c_algorithm *s4882_algo;
32093 +static i2c_algorithm_no_const *s4882_algo;
32094
32095 /* Wrapper access functions for multiplexed SMBus */
32096 static DEFINE_MUTEX(amd756_lock);
32097 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
32098 index 29015eb..af2d8e9 100644
32099 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
32100 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
32101 @@ -41,7 +41,7 @@
32102 extern struct i2c_adapter *nforce2_smbus;
32103
32104 static struct i2c_adapter *s4985_adapter;
32105 -static struct i2c_algorithm *s4985_algo;
32106 +static i2c_algorithm_no_const *s4985_algo;
32107
32108 /* Wrapper access functions for multiplexed SMBus */
32109 static DEFINE_MUTEX(nforce2_lock);
32110 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
32111 index d94e0ce..7055125 100644
32112 --- a/drivers/i2c/i2c-mux.c
32113 +++ b/drivers/i2c/i2c-mux.c
32114 @@ -30,7 +30,7 @@
32115 /* multiplexer per channel data */
32116 struct i2c_mux_priv {
32117 struct i2c_adapter adap;
32118 - struct i2c_algorithm algo;
32119 + i2c_algorithm_no_const algo;
32120
32121 struct i2c_adapter *parent;
32122 void *mux_priv; /* the mux chip/device */
32123 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32124 index 8126824..55a2798 100644
32125 --- a/drivers/ide/ide-cd.c
32126 +++ b/drivers/ide/ide-cd.c
32127 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32128 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32129 if ((unsigned long)buf & alignment
32130 || blk_rq_bytes(rq) & q->dma_pad_mask
32131 - || object_is_on_stack(buf))
32132 + || object_starts_on_stack(buf))
32133 drive->dma = 0;
32134 }
32135 }
32136 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32137 index 394fea2..c833880 100644
32138 --- a/drivers/infiniband/core/cm.c
32139 +++ b/drivers/infiniband/core/cm.c
32140 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32141
32142 struct cm_counter_group {
32143 struct kobject obj;
32144 - atomic_long_t counter[CM_ATTR_COUNT];
32145 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32146 };
32147
32148 struct cm_counter_attribute {
32149 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32150 struct ib_mad_send_buf *msg = NULL;
32151 int ret;
32152
32153 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32154 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32155 counter[CM_REQ_COUNTER]);
32156
32157 /* Quick state check to discard duplicate REQs. */
32158 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32159 if (!cm_id_priv)
32160 return;
32161
32162 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32163 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32164 counter[CM_REP_COUNTER]);
32165 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32166 if (ret)
32167 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32168 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32169 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32170 spin_unlock_irq(&cm_id_priv->lock);
32171 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32172 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32173 counter[CM_RTU_COUNTER]);
32174 goto out;
32175 }
32176 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32177 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32178 dreq_msg->local_comm_id);
32179 if (!cm_id_priv) {
32180 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32181 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32182 counter[CM_DREQ_COUNTER]);
32183 cm_issue_drep(work->port, work->mad_recv_wc);
32184 return -EINVAL;
32185 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32186 case IB_CM_MRA_REP_RCVD:
32187 break;
32188 case IB_CM_TIMEWAIT:
32189 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32190 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32191 counter[CM_DREQ_COUNTER]);
32192 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32193 goto unlock;
32194 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32195 cm_free_msg(msg);
32196 goto deref;
32197 case IB_CM_DREQ_RCVD:
32198 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32199 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32200 counter[CM_DREQ_COUNTER]);
32201 goto unlock;
32202 default:
32203 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32204 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32205 cm_id_priv->msg, timeout)) {
32206 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32207 - atomic_long_inc(&work->port->
32208 + atomic_long_inc_unchecked(&work->port->
32209 counter_group[CM_RECV_DUPLICATES].
32210 counter[CM_MRA_COUNTER]);
32211 goto out;
32212 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32213 break;
32214 case IB_CM_MRA_REQ_RCVD:
32215 case IB_CM_MRA_REP_RCVD:
32216 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32217 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32218 counter[CM_MRA_COUNTER]);
32219 /* fall through */
32220 default:
32221 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32222 case IB_CM_LAP_IDLE:
32223 break;
32224 case IB_CM_MRA_LAP_SENT:
32225 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32226 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32227 counter[CM_LAP_COUNTER]);
32228 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32229 goto unlock;
32230 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32231 cm_free_msg(msg);
32232 goto deref;
32233 case IB_CM_LAP_RCVD:
32234 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32235 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32236 counter[CM_LAP_COUNTER]);
32237 goto unlock;
32238 default:
32239 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32240 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32241 if (cur_cm_id_priv) {
32242 spin_unlock_irq(&cm.lock);
32243 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32244 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32245 counter[CM_SIDR_REQ_COUNTER]);
32246 goto out; /* Duplicate message. */
32247 }
32248 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32249 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32250 msg->retries = 1;
32251
32252 - atomic_long_add(1 + msg->retries,
32253 + atomic_long_add_unchecked(1 + msg->retries,
32254 &port->counter_group[CM_XMIT].counter[attr_index]);
32255 if (msg->retries)
32256 - atomic_long_add(msg->retries,
32257 + atomic_long_add_unchecked(msg->retries,
32258 &port->counter_group[CM_XMIT_RETRIES].
32259 counter[attr_index]);
32260
32261 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32262 }
32263
32264 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32265 - atomic_long_inc(&port->counter_group[CM_RECV].
32266 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32267 counter[attr_id - CM_ATTR_ID_OFFSET]);
32268
32269 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32270 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32271 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32272
32273 return sprintf(buf, "%ld\n",
32274 - atomic_long_read(&group->counter[cm_attr->index]));
32275 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32276 }
32277
32278 static const struct sysfs_ops cm_counter_ops = {
32279 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32280 index 176c8f9..2627b62 100644
32281 --- a/drivers/infiniband/core/fmr_pool.c
32282 +++ b/drivers/infiniband/core/fmr_pool.c
32283 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32284
32285 struct task_struct *thread;
32286
32287 - atomic_t req_ser;
32288 - atomic_t flush_ser;
32289 + atomic_unchecked_t req_ser;
32290 + atomic_unchecked_t flush_ser;
32291
32292 wait_queue_head_t force_wait;
32293 };
32294 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32295 struct ib_fmr_pool *pool = pool_ptr;
32296
32297 do {
32298 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32299 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32300 ib_fmr_batch_release(pool);
32301
32302 - atomic_inc(&pool->flush_ser);
32303 + atomic_inc_unchecked(&pool->flush_ser);
32304 wake_up_interruptible(&pool->force_wait);
32305
32306 if (pool->flush_function)
32307 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32308 }
32309
32310 set_current_state(TASK_INTERRUPTIBLE);
32311 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32312 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32313 !kthread_should_stop())
32314 schedule();
32315 __set_current_state(TASK_RUNNING);
32316 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32317 pool->dirty_watermark = params->dirty_watermark;
32318 pool->dirty_len = 0;
32319 spin_lock_init(&pool->pool_lock);
32320 - atomic_set(&pool->req_ser, 0);
32321 - atomic_set(&pool->flush_ser, 0);
32322 + atomic_set_unchecked(&pool->req_ser, 0);
32323 + atomic_set_unchecked(&pool->flush_ser, 0);
32324 init_waitqueue_head(&pool->force_wait);
32325
32326 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32327 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32328 }
32329 spin_unlock_irq(&pool->pool_lock);
32330
32331 - serial = atomic_inc_return(&pool->req_ser);
32332 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32333 wake_up_process(pool->thread);
32334
32335 if (wait_event_interruptible(pool->force_wait,
32336 - atomic_read(&pool->flush_ser) - serial >= 0))
32337 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32338 return -EINTR;
32339
32340 return 0;
32341 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32342 } else {
32343 list_add_tail(&fmr->list, &pool->dirty_list);
32344 if (++pool->dirty_len >= pool->dirty_watermark) {
32345 - atomic_inc(&pool->req_ser);
32346 + atomic_inc_unchecked(&pool->req_ser);
32347 wake_up_process(pool->thread);
32348 }
32349 }
32350 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32351 index afd8179..598063f 100644
32352 --- a/drivers/infiniband/hw/cxgb4/mem.c
32353 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32354 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32355 int err;
32356 struct fw_ri_tpte tpt;
32357 u32 stag_idx;
32358 - static atomic_t key;
32359 + static atomic_unchecked_t key;
32360
32361 if (c4iw_fatal_error(rdev))
32362 return -EIO;
32363 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32364 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32365 rdev->stats.stag.max = rdev->stats.stag.cur;
32366 mutex_unlock(&rdev->stats.lock);
32367 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32368 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32369 }
32370 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32371 __func__, stag_state, type, pdid, stag_idx);
32372 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32373 index 79b3dbc..96e5fcc 100644
32374 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32375 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32376 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32377 struct ib_atomic_eth *ateth;
32378 struct ipath_ack_entry *e;
32379 u64 vaddr;
32380 - atomic64_t *maddr;
32381 + atomic64_unchecked_t *maddr;
32382 u64 sdata;
32383 u32 rkey;
32384 u8 next;
32385 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32386 IB_ACCESS_REMOTE_ATOMIC)))
32387 goto nack_acc_unlck;
32388 /* Perform atomic OP and save result. */
32389 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32390 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32391 sdata = be64_to_cpu(ateth->swap_data);
32392 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32393 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32394 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32395 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32396 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32397 be64_to_cpu(ateth->compare_data),
32398 sdata);
32399 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32400 index 1f95bba..9530f87 100644
32401 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32402 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32403 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32404 unsigned long flags;
32405 struct ib_wc wc;
32406 u64 sdata;
32407 - atomic64_t *maddr;
32408 + atomic64_unchecked_t *maddr;
32409 enum ib_wc_status send_status;
32410
32411 /*
32412 @@ -382,11 +382,11 @@ again:
32413 IB_ACCESS_REMOTE_ATOMIC)))
32414 goto acc_err;
32415 /* Perform atomic OP and save result. */
32416 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32417 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32418 sdata = wqe->wr.wr.atomic.compare_add;
32419 *(u64 *) sqp->s_sge.sge.vaddr =
32420 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32421 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32422 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32423 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32424 sdata, wqe->wr.wr.atomic.swap);
32425 goto send_comp;
32426 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32427 index 748db2d..5f75cc3 100644
32428 --- a/drivers/infiniband/hw/nes/nes.c
32429 +++ b/drivers/infiniband/hw/nes/nes.c
32430 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32431 LIST_HEAD(nes_adapter_list);
32432 static LIST_HEAD(nes_dev_list);
32433
32434 -atomic_t qps_destroyed;
32435 +atomic_unchecked_t qps_destroyed;
32436
32437 static unsigned int ee_flsh_adapter;
32438 static unsigned int sysfs_nonidx_addr;
32439 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32440 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32441 struct nes_adapter *nesadapter = nesdev->nesadapter;
32442
32443 - atomic_inc(&qps_destroyed);
32444 + atomic_inc_unchecked(&qps_destroyed);
32445
32446 /* Free the control structures */
32447
32448 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32449 index 5cac29e..c471744 100644
32450 --- a/drivers/infiniband/hw/nes/nes.h
32451 +++ b/drivers/infiniband/hw/nes/nes.h
32452 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
32453 extern unsigned int wqm_quanta;
32454 extern struct list_head nes_adapter_list;
32455
32456 -extern atomic_t cm_connects;
32457 -extern atomic_t cm_accepts;
32458 -extern atomic_t cm_disconnects;
32459 -extern atomic_t cm_closes;
32460 -extern atomic_t cm_connecteds;
32461 -extern atomic_t cm_connect_reqs;
32462 -extern atomic_t cm_rejects;
32463 -extern atomic_t mod_qp_timouts;
32464 -extern atomic_t qps_created;
32465 -extern atomic_t qps_destroyed;
32466 -extern atomic_t sw_qps_destroyed;
32467 +extern atomic_unchecked_t cm_connects;
32468 +extern atomic_unchecked_t cm_accepts;
32469 +extern atomic_unchecked_t cm_disconnects;
32470 +extern atomic_unchecked_t cm_closes;
32471 +extern atomic_unchecked_t cm_connecteds;
32472 +extern atomic_unchecked_t cm_connect_reqs;
32473 +extern atomic_unchecked_t cm_rejects;
32474 +extern atomic_unchecked_t mod_qp_timouts;
32475 +extern atomic_unchecked_t qps_created;
32476 +extern atomic_unchecked_t qps_destroyed;
32477 +extern atomic_unchecked_t sw_qps_destroyed;
32478 extern u32 mh_detected;
32479 extern u32 mh_pauses_sent;
32480 extern u32 cm_packets_sent;
32481 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
32482 extern u32 cm_packets_received;
32483 extern u32 cm_packets_dropped;
32484 extern u32 cm_packets_retrans;
32485 -extern atomic_t cm_listens_created;
32486 -extern atomic_t cm_listens_destroyed;
32487 +extern atomic_unchecked_t cm_listens_created;
32488 +extern atomic_unchecked_t cm_listens_destroyed;
32489 extern u32 cm_backlog_drops;
32490 -extern atomic_t cm_loopbacks;
32491 -extern atomic_t cm_nodes_created;
32492 -extern atomic_t cm_nodes_destroyed;
32493 -extern atomic_t cm_accel_dropped_pkts;
32494 -extern atomic_t cm_resets_recvd;
32495 -extern atomic_t pau_qps_created;
32496 -extern atomic_t pau_qps_destroyed;
32497 +extern atomic_unchecked_t cm_loopbacks;
32498 +extern atomic_unchecked_t cm_nodes_created;
32499 +extern atomic_unchecked_t cm_nodes_destroyed;
32500 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32501 +extern atomic_unchecked_t cm_resets_recvd;
32502 +extern atomic_unchecked_t pau_qps_created;
32503 +extern atomic_unchecked_t pau_qps_destroyed;
32504
32505 extern u32 int_mod_timer_init;
32506 extern u32 int_mod_cq_depth_256;
32507 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32508 index cfaacaf..fa0722e 100644
32509 --- a/drivers/infiniband/hw/nes/nes_cm.c
32510 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32511 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32512 u32 cm_packets_retrans;
32513 u32 cm_packets_created;
32514 u32 cm_packets_received;
32515 -atomic_t cm_listens_created;
32516 -atomic_t cm_listens_destroyed;
32517 +atomic_unchecked_t cm_listens_created;
32518 +atomic_unchecked_t cm_listens_destroyed;
32519 u32 cm_backlog_drops;
32520 -atomic_t cm_loopbacks;
32521 -atomic_t cm_nodes_created;
32522 -atomic_t cm_nodes_destroyed;
32523 -atomic_t cm_accel_dropped_pkts;
32524 -atomic_t cm_resets_recvd;
32525 +atomic_unchecked_t cm_loopbacks;
32526 +atomic_unchecked_t cm_nodes_created;
32527 +atomic_unchecked_t cm_nodes_destroyed;
32528 +atomic_unchecked_t cm_accel_dropped_pkts;
32529 +atomic_unchecked_t cm_resets_recvd;
32530
32531 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32532 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32533 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32534
32535 static struct nes_cm_core *g_cm_core;
32536
32537 -atomic_t cm_connects;
32538 -atomic_t cm_accepts;
32539 -atomic_t cm_disconnects;
32540 -atomic_t cm_closes;
32541 -atomic_t cm_connecteds;
32542 -atomic_t cm_connect_reqs;
32543 -atomic_t cm_rejects;
32544 +atomic_unchecked_t cm_connects;
32545 +atomic_unchecked_t cm_accepts;
32546 +atomic_unchecked_t cm_disconnects;
32547 +atomic_unchecked_t cm_closes;
32548 +atomic_unchecked_t cm_connecteds;
32549 +atomic_unchecked_t cm_connect_reqs;
32550 +atomic_unchecked_t cm_rejects;
32551
32552 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32553 {
32554 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32555 kfree(listener);
32556 listener = NULL;
32557 ret = 0;
32558 - atomic_inc(&cm_listens_destroyed);
32559 + atomic_inc_unchecked(&cm_listens_destroyed);
32560 } else {
32561 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32562 }
32563 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32564 cm_node->rem_mac);
32565
32566 add_hte_node(cm_core, cm_node);
32567 - atomic_inc(&cm_nodes_created);
32568 + atomic_inc_unchecked(&cm_nodes_created);
32569
32570 return cm_node;
32571 }
32572 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32573 }
32574
32575 atomic_dec(&cm_core->node_cnt);
32576 - atomic_inc(&cm_nodes_destroyed);
32577 + atomic_inc_unchecked(&cm_nodes_destroyed);
32578 nesqp = cm_node->nesqp;
32579 if (nesqp) {
32580 nesqp->cm_node = NULL;
32581 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32582
32583 static void drop_packet(struct sk_buff *skb)
32584 {
32585 - atomic_inc(&cm_accel_dropped_pkts);
32586 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32587 dev_kfree_skb_any(skb);
32588 }
32589
32590 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32591 {
32592
32593 int reset = 0; /* whether to send reset in case of err.. */
32594 - atomic_inc(&cm_resets_recvd);
32595 + atomic_inc_unchecked(&cm_resets_recvd);
32596 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32597 " refcnt=%d\n", cm_node, cm_node->state,
32598 atomic_read(&cm_node->ref_count));
32599 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32600 rem_ref_cm_node(cm_node->cm_core, cm_node);
32601 return NULL;
32602 }
32603 - atomic_inc(&cm_loopbacks);
32604 + atomic_inc_unchecked(&cm_loopbacks);
32605 loopbackremotenode->loopbackpartner = cm_node;
32606 loopbackremotenode->tcp_cntxt.rcv_wscale =
32607 NES_CM_DEFAULT_RCV_WND_SCALE;
32608 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32609 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32610 else {
32611 rem_ref_cm_node(cm_core, cm_node);
32612 - atomic_inc(&cm_accel_dropped_pkts);
32613 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32614 dev_kfree_skb_any(skb);
32615 }
32616 break;
32617 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32618
32619 if ((cm_id) && (cm_id->event_handler)) {
32620 if (issue_disconn) {
32621 - atomic_inc(&cm_disconnects);
32622 + atomic_inc_unchecked(&cm_disconnects);
32623 cm_event.event = IW_CM_EVENT_DISCONNECT;
32624 cm_event.status = disconn_status;
32625 cm_event.local_addr = cm_id->local_addr;
32626 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32627 }
32628
32629 if (issue_close) {
32630 - atomic_inc(&cm_closes);
32631 + atomic_inc_unchecked(&cm_closes);
32632 nes_disconnect(nesqp, 1);
32633
32634 cm_id->provider_data = nesqp;
32635 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32636
32637 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32638 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32639 - atomic_inc(&cm_accepts);
32640 + atomic_inc_unchecked(&cm_accepts);
32641
32642 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32643 netdev_refcnt_read(nesvnic->netdev));
32644 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32645 struct nes_cm_core *cm_core;
32646 u8 *start_buff;
32647
32648 - atomic_inc(&cm_rejects);
32649 + atomic_inc_unchecked(&cm_rejects);
32650 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32651 loopback = cm_node->loopbackpartner;
32652 cm_core = cm_node->cm_core;
32653 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32654 ntohl(cm_id->local_addr.sin_addr.s_addr),
32655 ntohs(cm_id->local_addr.sin_port));
32656
32657 - atomic_inc(&cm_connects);
32658 + atomic_inc_unchecked(&cm_connects);
32659 nesqp->active_conn = 1;
32660
32661 /* cache the cm_id in the qp */
32662 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32663 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32664 return err;
32665 }
32666 - atomic_inc(&cm_listens_created);
32667 + atomic_inc_unchecked(&cm_listens_created);
32668 }
32669
32670 cm_id->add_ref(cm_id);
32671 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32672
32673 if (nesqp->destroyed)
32674 return;
32675 - atomic_inc(&cm_connecteds);
32676 + atomic_inc_unchecked(&cm_connecteds);
32677 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32678 " local port 0x%04X. jiffies = %lu.\n",
32679 nesqp->hwqp.qp_id,
32680 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32681
32682 cm_id->add_ref(cm_id);
32683 ret = cm_id->event_handler(cm_id, &cm_event);
32684 - atomic_inc(&cm_closes);
32685 + atomic_inc_unchecked(&cm_closes);
32686 cm_event.event = IW_CM_EVENT_CLOSE;
32687 cm_event.status = 0;
32688 cm_event.provider_data = cm_id->provider_data;
32689 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32690 return;
32691 cm_id = cm_node->cm_id;
32692
32693 - atomic_inc(&cm_connect_reqs);
32694 + atomic_inc_unchecked(&cm_connect_reqs);
32695 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32696 cm_node, cm_id, jiffies);
32697
32698 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32699 return;
32700 cm_id = cm_node->cm_id;
32701
32702 - atomic_inc(&cm_connect_reqs);
32703 + atomic_inc_unchecked(&cm_connect_reqs);
32704 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32705 cm_node, cm_id, jiffies);
32706
32707 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32708 index 3ba7be3..c81f6ff 100644
32709 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32710 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32711 @@ -40,8 +40,8 @@
32712 #include "nes.h"
32713 #include "nes_mgt.h"
32714
32715 -atomic_t pau_qps_created;
32716 -atomic_t pau_qps_destroyed;
32717 +atomic_unchecked_t pau_qps_created;
32718 +atomic_unchecked_t pau_qps_destroyed;
32719
32720 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32721 {
32722 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32723 {
32724 struct sk_buff *skb;
32725 unsigned long flags;
32726 - atomic_inc(&pau_qps_destroyed);
32727 + atomic_inc_unchecked(&pau_qps_destroyed);
32728
32729 /* Free packets that have not yet been forwarded */
32730 /* Lock is acquired by skb_dequeue when removing the skb */
32731 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32732 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32733 skb_queue_head_init(&nesqp->pau_list);
32734 spin_lock_init(&nesqp->pau_lock);
32735 - atomic_inc(&pau_qps_created);
32736 + atomic_inc_unchecked(&pau_qps_created);
32737 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32738 }
32739
32740 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32741 index 0564be7..f68b0f1 100644
32742 --- a/drivers/infiniband/hw/nes/nes_nic.c
32743 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32744 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32745 target_stat_values[++index] = mh_detected;
32746 target_stat_values[++index] = mh_pauses_sent;
32747 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32748 - target_stat_values[++index] = atomic_read(&cm_connects);
32749 - target_stat_values[++index] = atomic_read(&cm_accepts);
32750 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32751 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32752 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32753 - target_stat_values[++index] = atomic_read(&cm_rejects);
32754 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32755 - target_stat_values[++index] = atomic_read(&qps_created);
32756 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32757 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32758 - target_stat_values[++index] = atomic_read(&cm_closes);
32759 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32760 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32761 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32762 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32763 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32764 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32765 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32766 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32767 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32768 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32769 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32770 target_stat_values[++index] = cm_packets_sent;
32771 target_stat_values[++index] = cm_packets_bounced;
32772 target_stat_values[++index] = cm_packets_created;
32773 target_stat_values[++index] = cm_packets_received;
32774 target_stat_values[++index] = cm_packets_dropped;
32775 target_stat_values[++index] = cm_packets_retrans;
32776 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32777 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32778 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32779 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32780 target_stat_values[++index] = cm_backlog_drops;
32781 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32782 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32783 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32784 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32785 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32786 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32787 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32788 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32789 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32790 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32791 target_stat_values[++index] = nesadapter->free_4kpbl;
32792 target_stat_values[++index] = nesadapter->free_256pbl;
32793 target_stat_values[++index] = int_mod_timer_init;
32794 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32795 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32796 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32797 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32798 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32799 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32800 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32801 }
32802
32803 /**
32804 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32805 index cd0ecb2..7099ff0 100644
32806 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32807 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32808 @@ -46,9 +46,9 @@
32809
32810 #include <rdma/ib_umem.h>
32811
32812 -atomic_t mod_qp_timouts;
32813 -atomic_t qps_created;
32814 -atomic_t sw_qps_destroyed;
32815 +atomic_unchecked_t mod_qp_timouts;
32816 +atomic_unchecked_t qps_created;
32817 +atomic_unchecked_t sw_qps_destroyed;
32818
32819 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32820
32821 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32822 if (init_attr->create_flags)
32823 return ERR_PTR(-EINVAL);
32824
32825 - atomic_inc(&qps_created);
32826 + atomic_inc_unchecked(&qps_created);
32827 switch (init_attr->qp_type) {
32828 case IB_QPT_RC:
32829 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32830 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32831 struct iw_cm_event cm_event;
32832 int ret = 0;
32833
32834 - atomic_inc(&sw_qps_destroyed);
32835 + atomic_inc_unchecked(&sw_qps_destroyed);
32836 nesqp->destroyed = 1;
32837
32838 /* Blow away the connection if it exists. */
32839 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32840 index 4d11575..3e890e5 100644
32841 --- a/drivers/infiniband/hw/qib/qib.h
32842 +++ b/drivers/infiniband/hw/qib/qib.h
32843 @@ -51,6 +51,7 @@
32844 #include <linux/completion.h>
32845 #include <linux/kref.h>
32846 #include <linux/sched.h>
32847 +#include <linux/slab.h>
32848
32849 #include "qib_common.h"
32850 #include "qib_verbs.h"
32851 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32852 index da739d9..da1c7f4 100644
32853 --- a/drivers/input/gameport/gameport.c
32854 +++ b/drivers/input/gameport/gameport.c
32855 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32856 */
32857 static void gameport_init_port(struct gameport *gameport)
32858 {
32859 - static atomic_t gameport_no = ATOMIC_INIT(0);
32860 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32861
32862 __module_get(THIS_MODULE);
32863
32864 mutex_init(&gameport->drv_mutex);
32865 device_initialize(&gameport->dev);
32866 dev_set_name(&gameport->dev, "gameport%lu",
32867 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32868 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32869 gameport->dev.bus = &gameport_bus;
32870 gameport->dev.release = gameport_release_port;
32871 if (gameport->parent)
32872 diff --git a/drivers/input/input.c b/drivers/input/input.c
32873 index 53a0dde..abffda7 100644
32874 --- a/drivers/input/input.c
32875 +++ b/drivers/input/input.c
32876 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32877 */
32878 int input_register_device(struct input_dev *dev)
32879 {
32880 - static atomic_t input_no = ATOMIC_INIT(0);
32881 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32882 struct input_handler *handler;
32883 unsigned int packet_size;
32884 const char *path;
32885 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
32886 dev->setkeycode = input_default_setkeycode;
32887
32888 dev_set_name(&dev->dev, "input%ld",
32889 - (unsigned long) atomic_inc_return(&input_no) - 1);
32890 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32891
32892 error = device_add(&dev->dev);
32893 if (error)
32894 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32895 index 04c69af..5f92d00 100644
32896 --- a/drivers/input/joystick/sidewinder.c
32897 +++ b/drivers/input/joystick/sidewinder.c
32898 @@ -30,6 +30,7 @@
32899 #include <linux/kernel.h>
32900 #include <linux/module.h>
32901 #include <linux/slab.h>
32902 +#include <linux/sched.h>
32903 #include <linux/init.h>
32904 #include <linux/input.h>
32905 #include <linux/gameport.h>
32906 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32907 index 83811e4..0822b90 100644
32908 --- a/drivers/input/joystick/xpad.c
32909 +++ b/drivers/input/joystick/xpad.c
32910 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32911
32912 static int xpad_led_probe(struct usb_xpad *xpad)
32913 {
32914 - static atomic_t led_seq = ATOMIC_INIT(0);
32915 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32916 long led_no;
32917 struct xpad_led *led;
32918 struct led_classdev *led_cdev;
32919 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32920 if (!led)
32921 return -ENOMEM;
32922
32923 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32924 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32925
32926 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32927 led->xpad = xpad;
32928 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32929 index 4c842c3..590b0bf 100644
32930 --- a/drivers/input/mousedev.c
32931 +++ b/drivers/input/mousedev.c
32932 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32933
32934 spin_unlock_irq(&client->packet_lock);
32935
32936 - if (copy_to_user(buffer, data, count))
32937 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32938 return -EFAULT;
32939
32940 return count;
32941 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32942 index d0f7533..fb8215b 100644
32943 --- a/drivers/input/serio/serio.c
32944 +++ b/drivers/input/serio/serio.c
32945 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32946 */
32947 static void serio_init_port(struct serio *serio)
32948 {
32949 - static atomic_t serio_no = ATOMIC_INIT(0);
32950 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32951
32952 __module_get(THIS_MODULE);
32953
32954 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32955 mutex_init(&serio->drv_mutex);
32956 device_initialize(&serio->dev);
32957 dev_set_name(&serio->dev, "serio%ld",
32958 - (long)atomic_inc_return(&serio_no) - 1);
32959 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32960 serio->dev.bus = &serio_bus;
32961 serio->dev.release = serio_release_port;
32962 serio->dev.groups = serio_device_attr_groups;
32963 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32964 index c679867..6e2e34d 100644
32965 --- a/drivers/isdn/capi/capi.c
32966 +++ b/drivers/isdn/capi/capi.c
32967 @@ -83,8 +83,8 @@ struct capiminor {
32968
32969 struct capi20_appl *ap;
32970 u32 ncci;
32971 - atomic_t datahandle;
32972 - atomic_t msgid;
32973 + atomic_unchecked_t datahandle;
32974 + atomic_unchecked_t msgid;
32975
32976 struct tty_port port;
32977 int ttyinstop;
32978 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32979 capimsg_setu16(s, 2, mp->ap->applid);
32980 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32981 capimsg_setu8 (s, 5, CAPI_RESP);
32982 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32983 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32984 capimsg_setu32(s, 8, mp->ncci);
32985 capimsg_setu16(s, 12, datahandle);
32986 }
32987 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
32988 mp->outbytes -= len;
32989 spin_unlock_bh(&mp->outlock);
32990
32991 - datahandle = atomic_inc_return(&mp->datahandle);
32992 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32993 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32994 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32995 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32996 capimsg_setu16(skb->data, 2, mp->ap->applid);
32997 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32998 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32999 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33000 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33001 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33002 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33003 capimsg_setu16(skb->data, 16, len); /* Data length */
33004 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33005 index 67abf3f..076b3a6 100644
33006 --- a/drivers/isdn/gigaset/interface.c
33007 +++ b/drivers/isdn/gigaset/interface.c
33008 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33009 }
33010 tty->driver_data = cs;
33011
33012 - ++cs->port.count;
33013 + atomic_inc(&cs->port.count);
33014
33015 - if (cs->port.count == 1) {
33016 + if (atomic_read(&cs->port.count) == 1) {
33017 tty_port_tty_set(&cs->port, tty);
33018 tty->low_latency = 1;
33019 }
33020 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33021
33022 if (!cs->connected)
33023 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33024 - else if (!cs->port.count)
33025 + else if (!atomic_read(&cs->port.count))
33026 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33027 - else if (!--cs->port.count)
33028 + else if (!atomic_dec_return(&cs->port.count))
33029 tty_port_tty_set(&cs->port, NULL);
33030
33031 mutex_unlock(&cs->mutex);
33032 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33033 index 821f7ac..28d4030 100644
33034 --- a/drivers/isdn/hardware/avm/b1.c
33035 +++ b/drivers/isdn/hardware/avm/b1.c
33036 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33037 }
33038 if (left) {
33039 if (t4file->user) {
33040 - if (copy_from_user(buf, dp, left))
33041 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33042 return -EFAULT;
33043 } else {
33044 memcpy(buf, dp, left);
33045 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33046 }
33047 if (left) {
33048 if (config->user) {
33049 - if (copy_from_user(buf, dp, left))
33050 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33051 return -EFAULT;
33052 } else {
33053 memcpy(buf, dp, left);
33054 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33055 index dd6b53a..19d9ee6 100644
33056 --- a/drivers/isdn/hardware/eicon/divasync.h
33057 +++ b/drivers/isdn/hardware/eicon/divasync.h
33058 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33059 } diva_didd_add_adapter_t;
33060 typedef struct _diva_didd_remove_adapter {
33061 IDI_CALL p_request;
33062 -} diva_didd_remove_adapter_t;
33063 +} __no_const diva_didd_remove_adapter_t;
33064 typedef struct _diva_didd_read_adapter_array {
33065 void *buffer;
33066 dword length;
33067 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33068 index d303e65..28bcb7b 100644
33069 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33070 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33071 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33072 typedef struct _diva_os_idi_adapter_interface {
33073 diva_init_card_proc_t cleanup_adapter_proc;
33074 diva_cmd_card_proc_t cmd_proc;
33075 -} diva_os_idi_adapter_interface_t;
33076 +} __no_const diva_os_idi_adapter_interface_t;
33077
33078 typedef struct _diva_os_xdi_adapter {
33079 struct list_head link;
33080 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33081 index b817809..409caff 100644
33082 --- a/drivers/isdn/i4l/isdn_tty.c
33083 +++ b/drivers/isdn/i4l/isdn_tty.c
33084 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33085
33086 #ifdef ISDN_DEBUG_MODEM_OPEN
33087 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33088 - port->count);
33089 + atomic_read(&port->count));
33090 #endif
33091 - port->count++;
33092 + atomic_inc(&port->count);
33093 port->tty = tty;
33094 /*
33095 * Start up serial port
33096 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33097 #endif
33098 return;
33099 }
33100 - if ((tty->count == 1) && (port->count != 1)) {
33101 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33102 /*
33103 * Uh, oh. tty->count is 1, which means that the tty
33104 * structure will be freed. Info->count should always
33105 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33106 * serial port won't be shutdown.
33107 */
33108 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33109 - "info->count is %d\n", port->count);
33110 - port->count = 1;
33111 + "info->count is %d\n", atomic_read(&port->count));
33112 + atomic_set(&port->count, 1);
33113 }
33114 - if (--port->count < 0) {
33115 + if (atomic_dec_return(&port->count) < 0) {
33116 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33117 - info->line, port->count);
33118 - port->count = 0;
33119 + info->line, atomic_read(&port->count));
33120 + atomic_set(&port->count, 0);
33121 }
33122 - if (port->count) {
33123 + if (atomic_read(&port->count)) {
33124 #ifdef ISDN_DEBUG_MODEM_OPEN
33125 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33126 #endif
33127 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33128 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33129 return;
33130 isdn_tty_shutdown(info);
33131 - port->count = 0;
33132 + atomic_set(&port->count, 0);
33133 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33134 port->tty = NULL;
33135 wake_up_interruptible(&port->open_wait);
33136 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33137 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33138 modem_info *info = &dev->mdm.info[i];
33139
33140 - if (info->port.count == 0)
33141 + if (atomic_read(&info->port.count) == 0)
33142 continue;
33143 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33144 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33145 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33146 index e74df7c..03a03ba 100644
33147 --- a/drivers/isdn/icn/icn.c
33148 +++ b/drivers/isdn/icn/icn.c
33149 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33150 if (count > len)
33151 count = len;
33152 if (user) {
33153 - if (copy_from_user(msg, buf, count))
33154 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33155 return -EFAULT;
33156 } else
33157 memcpy(msg, buf, count);
33158 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33159 index b5fdcb7..5b6c59f 100644
33160 --- a/drivers/lguest/core.c
33161 +++ b/drivers/lguest/core.c
33162 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33163 * it's worked so far. The end address needs +1 because __get_vm_area
33164 * allocates an extra guard page, so we need space for that.
33165 */
33166 +
33167 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33168 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33169 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33170 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33171 +#else
33172 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33173 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33174 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33175 +#endif
33176 +
33177 if (!switcher_vma) {
33178 err = -ENOMEM;
33179 printk("lguest: could not map switcher pages high\n");
33180 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33181 * Now the Switcher is mapped at the right address, we can't fail!
33182 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33183 */
33184 - memcpy(switcher_vma->addr, start_switcher_text,
33185 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33186 end_switcher_text - start_switcher_text);
33187
33188 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33189 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33190 index 4af12e1..0e89afe 100644
33191 --- a/drivers/lguest/x86/core.c
33192 +++ b/drivers/lguest/x86/core.c
33193 @@ -59,7 +59,7 @@ static struct {
33194 /* Offset from where switcher.S was compiled to where we've copied it */
33195 static unsigned long switcher_offset(void)
33196 {
33197 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33198 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33199 }
33200
33201 /* This cpu's struct lguest_pages. */
33202 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33203 * These copies are pretty cheap, so we do them unconditionally: */
33204 /* Save the current Host top-level page directory.
33205 */
33206 +
33207 +#ifdef CONFIG_PAX_PER_CPU_PGD
33208 + pages->state.host_cr3 = read_cr3();
33209 +#else
33210 pages->state.host_cr3 = __pa(current->mm->pgd);
33211 +#endif
33212 +
33213 /*
33214 * Set up the Guest's page tables to see this CPU's pages (and no
33215 * other CPU's pages).
33216 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
33217 * compiled-in switcher code and the high-mapped copy we just made.
33218 */
33219 for (i = 0; i < IDT_ENTRIES; i++)
33220 - default_idt_entries[i] += switcher_offset();
33221 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33222
33223 /*
33224 * Set up the Switcher's per-cpu areas.
33225 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
33226 * it will be undisturbed when we switch. To change %cs and jump we
33227 * need this structure to feed to Intel's "lcall" instruction.
33228 */
33229 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33230 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33231 lguest_entry.segment = LGUEST_CS;
33232
33233 /*
33234 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33235 index 40634b0..4f5855e 100644
33236 --- a/drivers/lguest/x86/switcher_32.S
33237 +++ b/drivers/lguest/x86/switcher_32.S
33238 @@ -87,6 +87,7 @@
33239 #include <asm/page.h>
33240 #include <asm/segment.h>
33241 #include <asm/lguest.h>
33242 +#include <asm/processor-flags.h>
33243
33244 // We mark the start of the code to copy
33245 // It's placed in .text tho it's never run here
33246 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33247 // Changes type when we load it: damn Intel!
33248 // For after we switch over our page tables
33249 // That entry will be read-only: we'd crash.
33250 +
33251 +#ifdef CONFIG_PAX_KERNEXEC
33252 + mov %cr0, %edx
33253 + xor $X86_CR0_WP, %edx
33254 + mov %edx, %cr0
33255 +#endif
33256 +
33257 movl $(GDT_ENTRY_TSS*8), %edx
33258 ltr %dx
33259
33260 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33261 // Let's clear it again for our return.
33262 // The GDT descriptor of the Host
33263 // Points to the table after two "size" bytes
33264 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33265 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33266 // Clear "used" from type field (byte 5, bit 2)
33267 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33268 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33269 +
33270 +#ifdef CONFIG_PAX_KERNEXEC
33271 + mov %cr0, %eax
33272 + xor $X86_CR0_WP, %eax
33273 + mov %eax, %cr0
33274 +#endif
33275
33276 // Once our page table's switched, the Guest is live!
33277 // The Host fades as we run this final step.
33278 @@ -295,13 +309,12 @@ deliver_to_host:
33279 // I consulted gcc, and it gave
33280 // These instructions, which I gladly credit:
33281 leal (%edx,%ebx,8), %eax
33282 - movzwl (%eax),%edx
33283 - movl 4(%eax), %eax
33284 - xorw %ax, %ax
33285 - orl %eax, %edx
33286 + movl 4(%eax), %edx
33287 + movw (%eax), %dx
33288 // Now the address of the handler's in %edx
33289 // We call it now: its "iret" drops us home.
33290 - jmp *%edx
33291 + ljmp $__KERNEL_CS, $1f
33292 +1: jmp *%edx
33293
33294 // Every interrupt can come to us here
33295 // But we must truly tell each apart.
33296 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33297 index 7155945..4bcc562 100644
33298 --- a/drivers/md/bitmap.c
33299 +++ b/drivers/md/bitmap.c
33300 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33301 chunk_kb ? "KB" : "B");
33302 if (bitmap->storage.file) {
33303 seq_printf(seq, ", file: ");
33304 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33305 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33306 }
33307
33308 seq_printf(seq, "\n");
33309 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33310 index afd9598..528d8f9 100644
33311 --- a/drivers/md/dm-ioctl.c
33312 +++ b/drivers/md/dm-ioctl.c
33313 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33314 cmd == DM_LIST_VERSIONS_CMD)
33315 return 0;
33316
33317 - if ((cmd == DM_DEV_CREATE_CMD)) {
33318 + if (cmd == DM_DEV_CREATE_CMD) {
33319 if (!*param->name) {
33320 DMWARN("name not supplied when creating device");
33321 return -EINVAL;
33322 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33323 index fd61f98..8050783 100644
33324 --- a/drivers/md/dm-raid1.c
33325 +++ b/drivers/md/dm-raid1.c
33326 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33327
33328 struct mirror {
33329 struct mirror_set *ms;
33330 - atomic_t error_count;
33331 + atomic_unchecked_t error_count;
33332 unsigned long error_type;
33333 struct dm_dev *dev;
33334 sector_t offset;
33335 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33336 struct mirror *m;
33337
33338 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33339 - if (!atomic_read(&m->error_count))
33340 + if (!atomic_read_unchecked(&m->error_count))
33341 return m;
33342
33343 return NULL;
33344 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33345 * simple way to tell if a device has encountered
33346 * errors.
33347 */
33348 - atomic_inc(&m->error_count);
33349 + atomic_inc_unchecked(&m->error_count);
33350
33351 if (test_and_set_bit(error_type, &m->error_type))
33352 return;
33353 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33354 struct mirror *m = get_default_mirror(ms);
33355
33356 do {
33357 - if (likely(!atomic_read(&m->error_count)))
33358 + if (likely(!atomic_read_unchecked(&m->error_count)))
33359 return m;
33360
33361 if (m-- == ms->mirror)
33362 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33363 {
33364 struct mirror *default_mirror = get_default_mirror(m->ms);
33365
33366 - return !atomic_read(&default_mirror->error_count);
33367 + return !atomic_read_unchecked(&default_mirror->error_count);
33368 }
33369
33370 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33371 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33372 */
33373 if (likely(region_in_sync(ms, region, 1)))
33374 m = choose_mirror(ms, bio->bi_sector);
33375 - else if (m && atomic_read(&m->error_count))
33376 + else if (m && atomic_read_unchecked(&m->error_count))
33377 m = NULL;
33378
33379 if (likely(m))
33380 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33381 }
33382
33383 ms->mirror[mirror].ms = ms;
33384 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33385 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33386 ms->mirror[mirror].error_type = 0;
33387 ms->mirror[mirror].offset = offset;
33388
33389 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33390 */
33391 static char device_status_char(struct mirror *m)
33392 {
33393 - if (!atomic_read(&(m->error_count)))
33394 + if (!atomic_read_unchecked(&(m->error_count)))
33395 return 'A';
33396
33397 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33398 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33399 index e2f87653..f279abe 100644
33400 --- a/drivers/md/dm-stripe.c
33401 +++ b/drivers/md/dm-stripe.c
33402 @@ -20,7 +20,7 @@ struct stripe {
33403 struct dm_dev *dev;
33404 sector_t physical_start;
33405
33406 - atomic_t error_count;
33407 + atomic_unchecked_t error_count;
33408 };
33409
33410 struct stripe_c {
33411 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33412 kfree(sc);
33413 return r;
33414 }
33415 - atomic_set(&(sc->stripe[i].error_count), 0);
33416 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33417 }
33418
33419 ti->private = sc;
33420 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33421 DMEMIT("%d ", sc->stripes);
33422 for (i = 0; i < sc->stripes; i++) {
33423 DMEMIT("%s ", sc->stripe[i].dev->name);
33424 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33425 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33426 'D' : 'A';
33427 }
33428 buffer[i] = '\0';
33429 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33430 */
33431 for (i = 0; i < sc->stripes; i++)
33432 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33433 - atomic_inc(&(sc->stripe[i].error_count));
33434 - if (atomic_read(&(sc->stripe[i].error_count)) <
33435 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33436 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33437 DM_IO_ERROR_THRESHOLD)
33438 schedule_work(&sc->trigger_event);
33439 }
33440 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33441 index 100368e..64262ce 100644
33442 --- a/drivers/md/dm-table.c
33443 +++ b/drivers/md/dm-table.c
33444 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33445 if (!dev_size)
33446 return 0;
33447
33448 - if ((start >= dev_size) || (start + len > dev_size)) {
33449 + if ((start >= dev_size) || (len > dev_size - start)) {
33450 DMWARN("%s: %s too small for target: "
33451 "start=%llu, len=%llu, dev_size=%llu",
33452 dm_device_name(ti->table->md), bdevname(bdev, b),
33453 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33454 index 693e149..b7e0fde 100644
33455 --- a/drivers/md/dm-thin-metadata.c
33456 +++ b/drivers/md/dm-thin-metadata.c
33457 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33458 {
33459 pmd->info.tm = pmd->tm;
33460 pmd->info.levels = 2;
33461 - pmd->info.value_type.context = pmd->data_sm;
33462 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33463 pmd->info.value_type.size = sizeof(__le64);
33464 pmd->info.value_type.inc = data_block_inc;
33465 pmd->info.value_type.dec = data_block_dec;
33466 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33467
33468 pmd->bl_info.tm = pmd->tm;
33469 pmd->bl_info.levels = 1;
33470 - pmd->bl_info.value_type.context = pmd->data_sm;
33471 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33472 pmd->bl_info.value_type.size = sizeof(__le64);
33473 pmd->bl_info.value_type.inc = data_block_inc;
33474 pmd->bl_info.value_type.dec = data_block_dec;
33475 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33476 index 77e6eff..913d695 100644
33477 --- a/drivers/md/dm.c
33478 +++ b/drivers/md/dm.c
33479 @@ -182,9 +182,9 @@ struct mapped_device {
33480 /*
33481 * Event handling.
33482 */
33483 - atomic_t event_nr;
33484 + atomic_unchecked_t event_nr;
33485 wait_queue_head_t eventq;
33486 - atomic_t uevent_seq;
33487 + atomic_unchecked_t uevent_seq;
33488 struct list_head uevent_list;
33489 spinlock_t uevent_lock; /* Protect access to uevent_list */
33490
33491 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
33492 rwlock_init(&md->map_lock);
33493 atomic_set(&md->holders, 1);
33494 atomic_set(&md->open_count, 0);
33495 - atomic_set(&md->event_nr, 0);
33496 - atomic_set(&md->uevent_seq, 0);
33497 + atomic_set_unchecked(&md->event_nr, 0);
33498 + atomic_set_unchecked(&md->uevent_seq, 0);
33499 INIT_LIST_HEAD(&md->uevent_list);
33500 spin_lock_init(&md->uevent_lock);
33501
33502 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
33503
33504 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33505
33506 - atomic_inc(&md->event_nr);
33507 + atomic_inc_unchecked(&md->event_nr);
33508 wake_up(&md->eventq);
33509 }
33510
33511 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33512
33513 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33514 {
33515 - return atomic_add_return(1, &md->uevent_seq);
33516 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33517 }
33518
33519 uint32_t dm_get_event_nr(struct mapped_device *md)
33520 {
33521 - return atomic_read(&md->event_nr);
33522 + return atomic_read_unchecked(&md->event_nr);
33523 }
33524
33525 int dm_wait_event(struct mapped_device *md, int event_nr)
33526 {
33527 return wait_event_interruptible(md->eventq,
33528 - (event_nr != atomic_read(&md->event_nr)));
33529 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33530 }
33531
33532 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33533 diff --git a/drivers/md/md.c b/drivers/md/md.c
33534 index 6120071..31d9be2 100644
33535 --- a/drivers/md/md.c
33536 +++ b/drivers/md/md.c
33537 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33538 * start build, activate spare
33539 */
33540 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33541 -static atomic_t md_event_count;
33542 +static atomic_unchecked_t md_event_count;
33543 void md_new_event(struct mddev *mddev)
33544 {
33545 - atomic_inc(&md_event_count);
33546 + atomic_inc_unchecked(&md_event_count);
33547 wake_up(&md_event_waiters);
33548 }
33549 EXPORT_SYMBOL_GPL(md_new_event);
33550 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33551 */
33552 static void md_new_event_inintr(struct mddev *mddev)
33553 {
33554 - atomic_inc(&md_event_count);
33555 + atomic_inc_unchecked(&md_event_count);
33556 wake_up(&md_event_waiters);
33557 }
33558
33559 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33560 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33561 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33562 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33563 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33564 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33565
33566 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33567 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33568 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33569 else
33570 sb->resync_offset = cpu_to_le64(0);
33571
33572 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33573 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33574
33575 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33576 sb->size = cpu_to_le64(mddev->dev_sectors);
33577 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33578 static ssize_t
33579 errors_show(struct md_rdev *rdev, char *page)
33580 {
33581 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33582 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33583 }
33584
33585 static ssize_t
33586 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33587 char *e;
33588 unsigned long n = simple_strtoul(buf, &e, 10);
33589 if (*buf && (*e == 0 || *e == '\n')) {
33590 - atomic_set(&rdev->corrected_errors, n);
33591 + atomic_set_unchecked(&rdev->corrected_errors, n);
33592 return len;
33593 }
33594 return -EINVAL;
33595 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
33596 rdev->sb_loaded = 0;
33597 rdev->bb_page = NULL;
33598 atomic_set(&rdev->nr_pending, 0);
33599 - atomic_set(&rdev->read_errors, 0);
33600 - atomic_set(&rdev->corrected_errors, 0);
33601 + atomic_set_unchecked(&rdev->read_errors, 0);
33602 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33603
33604 INIT_LIST_HEAD(&rdev->same_set);
33605 init_waitqueue_head(&rdev->blocked_wait);
33606 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33607
33608 spin_unlock(&pers_lock);
33609 seq_printf(seq, "\n");
33610 - seq->poll_event = atomic_read(&md_event_count);
33611 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33612 return 0;
33613 }
33614 if (v == (void*)2) {
33615 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33616 return error;
33617
33618 seq = file->private_data;
33619 - seq->poll_event = atomic_read(&md_event_count);
33620 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33621 return error;
33622 }
33623
33624 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33625 /* always allow read */
33626 mask = POLLIN | POLLRDNORM;
33627
33628 - if (seq->poll_event != atomic_read(&md_event_count))
33629 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33630 mask |= POLLERR | POLLPRI;
33631 return mask;
33632 }
33633 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33634 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33635 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33636 (int)part_stat_read(&disk->part0, sectors[1]) -
33637 - atomic_read(&disk->sync_io);
33638 + atomic_read_unchecked(&disk->sync_io);
33639 /* sync IO will cause sync_io to increase before the disk_stats
33640 * as sync_io is counted when a request starts, and
33641 * disk_stats is counted when it completes.
33642 diff --git a/drivers/md/md.h b/drivers/md/md.h
33643 index af443ab..0f93be3 100644
33644 --- a/drivers/md/md.h
33645 +++ b/drivers/md/md.h
33646 @@ -94,13 +94,13 @@ struct md_rdev {
33647 * only maintained for arrays that
33648 * support hot removal
33649 */
33650 - atomic_t read_errors; /* number of consecutive read errors that
33651 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33652 * we have tried to ignore.
33653 */
33654 struct timespec last_read_error; /* monotonic time since our
33655 * last read error
33656 */
33657 - atomic_t corrected_errors; /* number of corrected read errors,
33658 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33659 * for reporting to userspace and storing
33660 * in superblock.
33661 */
33662 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33663
33664 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33665 {
33666 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33667 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33668 }
33669
33670 struct md_personality
33671 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33672 index f6d29e6..7917f5e 100644
33673 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33674 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33675 @@ -22,7 +22,7 @@
33676 * Space map interface.
33677 */
33678 struct sm_disk {
33679 - struct dm_space_map sm;
33680 + dm_space_map_no_const sm;
33681
33682 struct ll_disk ll;
33683 struct ll_disk old_ll;
33684 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33685 index e89ae5e..062e4c2 100644
33686 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33687 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33688 @@ -43,7 +43,7 @@ struct block_op {
33689 };
33690
33691 struct sm_metadata {
33692 - struct dm_space_map sm;
33693 + dm_space_map_no_const sm;
33694
33695 struct ll_disk ll;
33696 struct ll_disk old_ll;
33697 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33698 index 1cbfc6b..56e1dbb 100644
33699 --- a/drivers/md/persistent-data/dm-space-map.h
33700 +++ b/drivers/md/persistent-data/dm-space-map.h
33701 @@ -60,6 +60,7 @@ struct dm_space_map {
33702 int (*root_size)(struct dm_space_map *sm, size_t *result);
33703 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33704 };
33705 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33706
33707 /*----------------------------------------------------------------*/
33708
33709 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33710 index a0f7309..5599dbc 100644
33711 --- a/drivers/md/raid1.c
33712 +++ b/drivers/md/raid1.c
33713 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33714 if (r1_sync_page_io(rdev, sect, s,
33715 bio->bi_io_vec[idx].bv_page,
33716 READ) != 0)
33717 - atomic_add(s, &rdev->corrected_errors);
33718 + atomic_add_unchecked(s, &rdev->corrected_errors);
33719 }
33720 sectors -= s;
33721 sect += s;
33722 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33723 test_bit(In_sync, &rdev->flags)) {
33724 if (r1_sync_page_io(rdev, sect, s,
33725 conf->tmppage, READ)) {
33726 - atomic_add(s, &rdev->corrected_errors);
33727 + atomic_add_unchecked(s, &rdev->corrected_errors);
33728 printk(KERN_INFO
33729 "md/raid1:%s: read error corrected "
33730 "(%d sectors at %llu on %s)\n",
33731 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33732 index c9acbd7..386cd3e 100644
33733 --- a/drivers/md/raid10.c
33734 +++ b/drivers/md/raid10.c
33735 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
33736 /* The write handler will notice the lack of
33737 * R10BIO_Uptodate and record any errors etc
33738 */
33739 - atomic_add(r10_bio->sectors,
33740 + atomic_add_unchecked(r10_bio->sectors,
33741 &conf->mirrors[d].rdev->corrected_errors);
33742
33743 /* for reconstruct, we always reschedule after a read.
33744 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33745 {
33746 struct timespec cur_time_mon;
33747 unsigned long hours_since_last;
33748 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33749 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33750
33751 ktime_get_ts(&cur_time_mon);
33752
33753 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33754 * overflowing the shift of read_errors by hours_since_last.
33755 */
33756 if (hours_since_last >= 8 * sizeof(read_errors))
33757 - atomic_set(&rdev->read_errors, 0);
33758 + atomic_set_unchecked(&rdev->read_errors, 0);
33759 else
33760 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33761 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33762 }
33763
33764 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33765 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33766 return;
33767
33768 check_decay_read_errors(mddev, rdev);
33769 - atomic_inc(&rdev->read_errors);
33770 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33771 + atomic_inc_unchecked(&rdev->read_errors);
33772 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33773 char b[BDEVNAME_SIZE];
33774 bdevname(rdev->bdev, b);
33775
33776 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33777 "md/raid10:%s: %s: Raid device exceeded "
33778 "read_error threshold [cur %d:max %d]\n",
33779 mdname(mddev), b,
33780 - atomic_read(&rdev->read_errors), max_read_errors);
33781 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33782 printk(KERN_NOTICE
33783 "md/raid10:%s: %s: Failing raid device\n",
33784 mdname(mddev), b);
33785 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33786 sect +
33787 choose_data_offset(r10_bio, rdev)),
33788 bdevname(rdev->bdev, b));
33789 - atomic_add(s, &rdev->corrected_errors);
33790 + atomic_add_unchecked(s, &rdev->corrected_errors);
33791 }
33792
33793 rdev_dec_pending(rdev, mddev);
33794 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33795 index a450268..c4168a9 100644
33796 --- a/drivers/md/raid5.c
33797 +++ b/drivers/md/raid5.c
33798 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33799 mdname(conf->mddev), STRIPE_SECTORS,
33800 (unsigned long long)s,
33801 bdevname(rdev->bdev, b));
33802 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33803 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33804 clear_bit(R5_ReadError, &sh->dev[i].flags);
33805 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33806 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33807 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33808
33809 - if (atomic_read(&rdev->read_errors))
33810 - atomic_set(&rdev->read_errors, 0);
33811 + if (atomic_read_unchecked(&rdev->read_errors))
33812 + atomic_set_unchecked(&rdev->read_errors, 0);
33813 } else {
33814 const char *bdn = bdevname(rdev->bdev, b);
33815 int retry = 0;
33816 int set_bad = 0;
33817
33818 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33819 - atomic_inc(&rdev->read_errors);
33820 + atomic_inc_unchecked(&rdev->read_errors);
33821 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33822 printk_ratelimited(
33823 KERN_WARNING
33824 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33825 mdname(conf->mddev),
33826 (unsigned long long)s,
33827 bdn);
33828 - } else if (atomic_read(&rdev->read_errors)
33829 + } else if (atomic_read_unchecked(&rdev->read_errors)
33830 > conf->max_nr_stripes)
33831 printk(KERN_WARNING
33832 "md/raid:%s: Too many read errors, failing device %s.\n",
33833 diff --git a/drivers/media/dvb-core/dvb_demux.h b/drivers/media/dvb-core/dvb_demux.h
33834 index fa7188a..04a045e 100644
33835 --- a/drivers/media/dvb-core/dvb_demux.h
33836 +++ b/drivers/media/dvb-core/dvb_demux.h
33837 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33838 union {
33839 dmx_ts_cb ts;
33840 dmx_section_cb sec;
33841 - } cb;
33842 + } __no_const cb;
33843
33844 struct dvb_demux *demux;
33845 void *priv;
33846 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
33847 index d33101a..6b13069 100644
33848 --- a/drivers/media/dvb-core/dvbdev.c
33849 +++ b/drivers/media/dvb-core/dvbdev.c
33850 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33851 const struct dvb_device *template, void *priv, int type)
33852 {
33853 struct dvb_device *dvbdev;
33854 - struct file_operations *dvbdevfops;
33855 + file_operations_no_const *dvbdevfops;
33856 struct device *clsdev;
33857 int minor;
33858 int id;
33859 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
33860 index 404f63a..4796533 100644
33861 --- a/drivers/media/dvb-frontends/dib3000.h
33862 +++ b/drivers/media/dvb-frontends/dib3000.h
33863 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33864 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33865 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33866 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33867 -};
33868 +} __no_const;
33869
33870 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33871 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33872 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
33873 index 3aa6856..435ad25 100644
33874 --- a/drivers/media/pci/cx88/cx88-alsa.c
33875 +++ b/drivers/media/pci/cx88/cx88-alsa.c
33876 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33877 * Only boards with eeprom and byte 1 at eeprom=1 have it
33878 */
33879
33880 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
33881 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
33882 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33883 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33884 {0, }
33885 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
33886 index feff57e..66a2c67 100644
33887 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
33888 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
33889 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33890 .subvendor = _subvend, .subdevice = _subdev, \
33891 .driver_data = (unsigned long)&_driverdata }
33892
33893 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33894 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33895 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33896 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33897 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33898 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
33899 index 96a13ed..6df45b4 100644
33900 --- a/drivers/media/pci/ngene/ngene-cards.c
33901 +++ b/drivers/media/pci/ngene/ngene-cards.c
33902 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
33903
33904 /****************************************************************************/
33905
33906 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33907 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33908 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33909 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33910 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33911 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
33912 index a3b1a34..71ce0e3 100644
33913 --- a/drivers/media/platform/omap/omap_vout.c
33914 +++ b/drivers/media/platform/omap/omap_vout.c
33915 @@ -65,7 +65,6 @@ enum omap_vout_channels {
33916 OMAP_VIDEO2,
33917 };
33918
33919 -static struct videobuf_queue_ops video_vbq_ops;
33920 /* Variables configurable through module params*/
33921 static u32 video1_numbuffers = 3;
33922 static u32 video2_numbuffers = 3;
33923 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
33924 {
33925 struct videobuf_queue *q;
33926 struct omap_vout_device *vout = NULL;
33927 + static struct videobuf_queue_ops video_vbq_ops = {
33928 + .buf_setup = omap_vout_buffer_setup,
33929 + .buf_prepare = omap_vout_buffer_prepare,
33930 + .buf_release = omap_vout_buffer_release,
33931 + .buf_queue = omap_vout_buffer_queue,
33932 + };
33933
33934 vout = video_drvdata(file);
33935 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33936 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
33937 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33938
33939 q = &vout->vbq;
33940 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33941 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33942 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33943 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33944 spin_lock_init(&vout->vbq_lock);
33945
33946 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33947 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
33948 index 02194c0..091733b 100644
33949 --- a/drivers/media/platform/timblogiw.c
33950 +++ b/drivers/media/platform/timblogiw.c
33951 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33952
33953 /* Platform device functions */
33954
33955 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33956 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33957 .vidioc_querycap = timblogiw_querycap,
33958 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33959 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33960 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33961 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33962 };
33963
33964 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33965 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33966 .owner = THIS_MODULE,
33967 .open = timblogiw_open,
33968 .release = timblogiw_close,
33969 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33970 index 697a421..16c5a5f 100644
33971 --- a/drivers/media/radio/radio-cadet.c
33972 +++ b/drivers/media/radio/radio-cadet.c
33973 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33974 unsigned char readbuf[RDS_BUFFER];
33975 int i = 0;
33976
33977 + if (count > RDS_BUFFER)
33978 + return -EFAULT;
33979 mutex_lock(&dev->lock);
33980 if (dev->rdsstat == 0)
33981 cadet_start_rds(dev);
33982 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33983 while (i < count && dev->rdsin != dev->rdsout)
33984 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33985
33986 - if (i && copy_to_user(data, readbuf, i))
33987 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33988 i = -EFAULT;
33989 unlock:
33990 mutex_unlock(&dev->lock);
33991 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
33992 index 4ea43a9..66f4a8f 100644
33993 --- a/drivers/media/radio/radio-tea5777.h
33994 +++ b/drivers/media/radio/radio-tea5777.h
33995 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
33996
33997 struct radio_tea5777 {
33998 struct v4l2_device *v4l2_dev;
33999 - struct v4l2_file_operations fops;
34000 + v4l2_file_operations_no_const fops;
34001 struct video_device vd; /* video device */
34002 bool has_am; /* Device can tune to AM freqs */
34003 bool write_before_read; /* must write before read quirk */
34004 diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
34005 index 66a56ef..d139911 100644
34006 --- a/drivers/media/usb/au0828/au0828.h
34007 +++ b/drivers/media/usb/au0828/au0828.h
34008 @@ -191,7 +191,7 @@ struct au0828_dev {
34009
34010 /* I2C */
34011 struct i2c_adapter i2c_adap;
34012 - struct i2c_algorithm i2c_algo;
34013 + i2c_algorithm_no_const i2c_algo;
34014 struct i2c_client i2c_client;
34015 u32 i2c_rc;
34016
34017 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
34018 index 3940bb0..fb3952a 100644
34019 --- a/drivers/media/usb/dvb-usb/cxusb.c
34020 +++ b/drivers/media/usb/dvb-usb/cxusb.c
34021 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34022
34023 struct dib0700_adapter_state {
34024 int (*set_param_save) (struct dvb_frontend *);
34025 -};
34026 +} __no_const;
34027
34028 static int dib7070_set_param_override(struct dvb_frontend *fe)
34029 {
34030 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
34031 index 9382895..ac8093c 100644
34032 --- a/drivers/media/usb/dvb-usb/dw2102.c
34033 +++ b/drivers/media/usb/dvb-usb/dw2102.c
34034 @@ -95,7 +95,7 @@ struct su3000_state {
34035
34036 struct s6x0_state {
34037 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34038 -};
34039 +} __no_const;
34040
34041 /* debug */
34042 static int dvb_usb_dw2102_debug;
34043 diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
34044 index 036952f..80d356d 100644
34045 --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
34046 +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
34047 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34048
34049 /* I2C stuff */
34050 struct i2c_adapter i2c_adap;
34051 - struct i2c_algorithm i2c_algo;
34052 + i2c_algorithm_no_const i2c_algo;
34053 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34054 int i2c_cx25840_hack_state;
34055 int i2c_linked;
34056 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34057 index fb69baa..cf7ad22 100644
34058 --- a/drivers/message/fusion/mptbase.c
34059 +++ b/drivers/message/fusion/mptbase.c
34060 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34061 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34062 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34063
34064 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34065 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34066 +#else
34067 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34068 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34069 +#endif
34070 +
34071 /*
34072 * Rounding UP to nearest 4-kB boundary here...
34073 */
34074 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34075 index 551262e..7551198 100644
34076 --- a/drivers/message/fusion/mptsas.c
34077 +++ b/drivers/message/fusion/mptsas.c
34078 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34079 return 0;
34080 }
34081
34082 +static inline void
34083 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34084 +{
34085 + if (phy_info->port_details) {
34086 + phy_info->port_details->rphy = rphy;
34087 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34088 + ioc->name, rphy));
34089 + }
34090 +
34091 + if (rphy) {
34092 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34093 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34094 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34095 + ioc->name, rphy, rphy->dev.release));
34096 + }
34097 +}
34098 +
34099 /* no mutex */
34100 static void
34101 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34102 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34103 return NULL;
34104 }
34105
34106 -static inline void
34107 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34108 -{
34109 - if (phy_info->port_details) {
34110 - phy_info->port_details->rphy = rphy;
34111 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34112 - ioc->name, rphy));
34113 - }
34114 -
34115 - if (rphy) {
34116 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34117 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34118 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34119 - ioc->name, rphy, rphy->dev.release));
34120 - }
34121 -}
34122 -
34123 static inline struct sas_port *
34124 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34125 {
34126 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34127 index 0c3ced7..1fe34ec 100644
34128 --- a/drivers/message/fusion/mptscsih.c
34129 +++ b/drivers/message/fusion/mptscsih.c
34130 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34131
34132 h = shost_priv(SChost);
34133
34134 - if (h) {
34135 - if (h->info_kbuf == NULL)
34136 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34137 - return h->info_kbuf;
34138 - h->info_kbuf[0] = '\0';
34139 + if (!h)
34140 + return NULL;
34141
34142 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34143 - h->info_kbuf[size-1] = '\0';
34144 - }
34145 + if (h->info_kbuf == NULL)
34146 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34147 + return h->info_kbuf;
34148 + h->info_kbuf[0] = '\0';
34149 +
34150 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34151 + h->info_kbuf[size-1] = '\0';
34152
34153 return h->info_kbuf;
34154 }
34155 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34156 index 8001aa6..b137580 100644
34157 --- a/drivers/message/i2o/i2o_proc.c
34158 +++ b/drivers/message/i2o/i2o_proc.c
34159 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34160 "Array Controller Device"
34161 };
34162
34163 -static char *chtostr(char *tmp, u8 *chars, int n)
34164 -{
34165 - tmp[0] = 0;
34166 - return strncat(tmp, (char *)chars, n);
34167 -}
34168 -
34169 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34170 char *group)
34171 {
34172 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34173 } *result;
34174
34175 i2o_exec_execute_ddm_table ddm_table;
34176 - char tmp[28 + 1];
34177
34178 result = kmalloc(sizeof(*result), GFP_KERNEL);
34179 if (!result)
34180 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34181
34182 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34183 seq_printf(seq, "%-#8x", ddm_table.module_id);
34184 - seq_printf(seq, "%-29s",
34185 - chtostr(tmp, ddm_table.module_name_version, 28));
34186 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34187 seq_printf(seq, "%9d ", ddm_table.data_size);
34188 seq_printf(seq, "%8d", ddm_table.code_size);
34189
34190 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34191
34192 i2o_driver_result_table *result;
34193 i2o_driver_store_table *dst;
34194 - char tmp[28 + 1];
34195
34196 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34197 if (result == NULL)
34198 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34199
34200 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34201 seq_printf(seq, "%-#8x", dst->module_id);
34202 - seq_printf(seq, "%-29s",
34203 - chtostr(tmp, dst->module_name_version, 28));
34204 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34205 + seq_printf(seq, "%-.28s", dst->module_name_version);
34206 + seq_printf(seq, "%-.8s", dst->date);
34207 seq_printf(seq, "%8d ", dst->module_size);
34208 seq_printf(seq, "%8d ", dst->mpb_size);
34209 seq_printf(seq, "0x%04x", dst->module_flags);
34210 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34211 // == (allow) 512d bytes (max)
34212 static u16 *work16 = (u16 *) work32;
34213 int token;
34214 - char tmp[16 + 1];
34215
34216 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34217
34218 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34219 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34220 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34221 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34222 - seq_printf(seq, "Vendor info : %s\n",
34223 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34224 - seq_printf(seq, "Product info : %s\n",
34225 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34226 - seq_printf(seq, "Description : %s\n",
34227 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34228 - seq_printf(seq, "Product rev. : %s\n",
34229 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34230 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34231 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34232 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34233 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34234
34235 seq_printf(seq, "Serial number : ");
34236 print_serial_number(seq, (u8 *) (work32 + 16),
34237 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34238 u8 pad[256]; // allow up to 256 byte (max) serial number
34239 } result;
34240
34241 - char tmp[24 + 1];
34242 -
34243 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34244
34245 if (token < 0) {
34246 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34247 }
34248
34249 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34250 - seq_printf(seq, "Module name : %s\n",
34251 - chtostr(tmp, result.module_name, 24));
34252 - seq_printf(seq, "Module revision : %s\n",
34253 - chtostr(tmp, result.module_rev, 8));
34254 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34255 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34256
34257 seq_printf(seq, "Serial number : ");
34258 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34259 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34260 u8 instance_number[4];
34261 } result;
34262
34263 - char tmp[64 + 1];
34264 -
34265 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34266
34267 if (token < 0) {
34268 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34269 return 0;
34270 }
34271
34272 - seq_printf(seq, "Device name : %s\n",
34273 - chtostr(tmp, result.device_name, 64));
34274 - seq_printf(seq, "Service name : %s\n",
34275 - chtostr(tmp, result.service_name, 64));
34276 - seq_printf(seq, "Physical name : %s\n",
34277 - chtostr(tmp, result.physical_location, 64));
34278 - seq_printf(seq, "Instance number : %s\n",
34279 - chtostr(tmp, result.instance_number, 4));
34280 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34281 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34282 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34283 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34284
34285 return 0;
34286 }
34287 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34288 index a8c08f3..155fe3d 100644
34289 --- a/drivers/message/i2o/iop.c
34290 +++ b/drivers/message/i2o/iop.c
34291 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34292
34293 spin_lock_irqsave(&c->context_list_lock, flags);
34294
34295 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34296 - atomic_inc(&c->context_list_counter);
34297 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34298 + atomic_inc_unchecked(&c->context_list_counter);
34299
34300 - entry->context = atomic_read(&c->context_list_counter);
34301 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34302
34303 list_add(&entry->list, &c->context_list);
34304
34305 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34306
34307 #if BITS_PER_LONG == 64
34308 spin_lock_init(&c->context_list_lock);
34309 - atomic_set(&c->context_list_counter, 0);
34310 + atomic_set_unchecked(&c->context_list_counter, 0);
34311 INIT_LIST_HEAD(&c->context_list);
34312 #endif
34313
34314 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34315 index 7ce65f4..e66e9bc 100644
34316 --- a/drivers/mfd/abx500-core.c
34317 +++ b/drivers/mfd/abx500-core.c
34318 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34319
34320 struct abx500_device_entry {
34321 struct list_head list;
34322 - struct abx500_ops ops;
34323 + abx500_ops_no_const ops;
34324 struct device *dev;
34325 };
34326
34327 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34328 index 965c480..71f2db9 100644
34329 --- a/drivers/mfd/janz-cmodio.c
34330 +++ b/drivers/mfd/janz-cmodio.c
34331 @@ -13,6 +13,7 @@
34332
34333 #include <linux/kernel.h>
34334 #include <linux/module.h>
34335 +#include <linux/slab.h>
34336 #include <linux/init.h>
34337 #include <linux/pci.h>
34338 #include <linux/interrupt.h>
34339 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
34340 index 3aa9a96..59cf685 100644
34341 --- a/drivers/misc/kgdbts.c
34342 +++ b/drivers/misc/kgdbts.c
34343 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
34344 char before[BREAK_INSTR_SIZE];
34345 char after[BREAK_INSTR_SIZE];
34346
34347 - probe_kernel_read(before, (char *)kgdbts_break_test,
34348 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
34349 BREAK_INSTR_SIZE);
34350 init_simple_test();
34351 ts.tst = plant_and_detach_test;
34352 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
34353 /* Activate test with initial breakpoint */
34354 if (!is_early)
34355 kgdb_breakpoint();
34356 - probe_kernel_read(after, (char *)kgdbts_break_test,
34357 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
34358 BREAK_INSTR_SIZE);
34359 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
34360 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
34361 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34362 index 4a87e5c..76bdf5c 100644
34363 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34364 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34365 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34366 * the lid is closed. This leads to interrupts as soon as a little move
34367 * is done.
34368 */
34369 - atomic_inc(&lis3->count);
34370 + atomic_inc_unchecked(&lis3->count);
34371
34372 wake_up_interruptible(&lis3->misc_wait);
34373 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34374 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34375 if (lis3->pm_dev)
34376 pm_runtime_get_sync(lis3->pm_dev);
34377
34378 - atomic_set(&lis3->count, 0);
34379 + atomic_set_unchecked(&lis3->count, 0);
34380 return 0;
34381 }
34382
34383 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34384 add_wait_queue(&lis3->misc_wait, &wait);
34385 while (true) {
34386 set_current_state(TASK_INTERRUPTIBLE);
34387 - data = atomic_xchg(&lis3->count, 0);
34388 + data = atomic_xchg_unchecked(&lis3->count, 0);
34389 if (data)
34390 break;
34391
34392 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34393 struct lis3lv02d, miscdev);
34394
34395 poll_wait(file, &lis3->misc_wait, wait);
34396 - if (atomic_read(&lis3->count))
34397 + if (atomic_read_unchecked(&lis3->count))
34398 return POLLIN | POLLRDNORM;
34399 return 0;
34400 }
34401 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34402 index c439c82..1f20f57 100644
34403 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34404 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34405 @@ -297,7 +297,7 @@ struct lis3lv02d {
34406 struct input_polled_dev *idev; /* input device */
34407 struct platform_device *pdev; /* platform device */
34408 struct regulator_bulk_data regulators[2];
34409 - atomic_t count; /* interrupt count after last read */
34410 + atomic_unchecked_t count; /* interrupt count after last read */
34411 union axis_conversion ac; /* hw -> logical axis */
34412 int mapped_btns[3];
34413
34414 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34415 index 2f30bad..c4c13d0 100644
34416 --- a/drivers/misc/sgi-gru/gruhandles.c
34417 +++ b/drivers/misc/sgi-gru/gruhandles.c
34418 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34419 unsigned long nsec;
34420
34421 nsec = CLKS2NSEC(clks);
34422 - atomic_long_inc(&mcs_op_statistics[op].count);
34423 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34424 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34425 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34426 if (mcs_op_statistics[op].max < nsec)
34427 mcs_op_statistics[op].max = nsec;
34428 }
34429 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34430 index 950dbe9..eeef0f8 100644
34431 --- a/drivers/misc/sgi-gru/gruprocfs.c
34432 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34433 @@ -32,9 +32,9 @@
34434
34435 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34436
34437 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34438 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34439 {
34440 - unsigned long val = atomic_long_read(v);
34441 + unsigned long val = atomic_long_read_unchecked(v);
34442
34443 seq_printf(s, "%16lu %s\n", val, id);
34444 }
34445 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34446
34447 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34448 for (op = 0; op < mcsop_last; op++) {
34449 - count = atomic_long_read(&mcs_op_statistics[op].count);
34450 - total = atomic_long_read(&mcs_op_statistics[op].total);
34451 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34452 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34453 max = mcs_op_statistics[op].max;
34454 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34455 count ? total / count : 0, max);
34456 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34457 index 5c3ce24..4915ccb 100644
34458 --- a/drivers/misc/sgi-gru/grutables.h
34459 +++ b/drivers/misc/sgi-gru/grutables.h
34460 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34461 * GRU statistics.
34462 */
34463 struct gru_stats_s {
34464 - atomic_long_t vdata_alloc;
34465 - atomic_long_t vdata_free;
34466 - atomic_long_t gts_alloc;
34467 - atomic_long_t gts_free;
34468 - atomic_long_t gms_alloc;
34469 - atomic_long_t gms_free;
34470 - atomic_long_t gts_double_allocate;
34471 - atomic_long_t assign_context;
34472 - atomic_long_t assign_context_failed;
34473 - atomic_long_t free_context;
34474 - atomic_long_t load_user_context;
34475 - atomic_long_t load_kernel_context;
34476 - atomic_long_t lock_kernel_context;
34477 - atomic_long_t unlock_kernel_context;
34478 - atomic_long_t steal_user_context;
34479 - atomic_long_t steal_kernel_context;
34480 - atomic_long_t steal_context_failed;
34481 - atomic_long_t nopfn;
34482 - atomic_long_t asid_new;
34483 - atomic_long_t asid_next;
34484 - atomic_long_t asid_wrap;
34485 - atomic_long_t asid_reuse;
34486 - atomic_long_t intr;
34487 - atomic_long_t intr_cbr;
34488 - atomic_long_t intr_tfh;
34489 - atomic_long_t intr_spurious;
34490 - atomic_long_t intr_mm_lock_failed;
34491 - atomic_long_t call_os;
34492 - atomic_long_t call_os_wait_queue;
34493 - atomic_long_t user_flush_tlb;
34494 - atomic_long_t user_unload_context;
34495 - atomic_long_t user_exception;
34496 - atomic_long_t set_context_option;
34497 - atomic_long_t check_context_retarget_intr;
34498 - atomic_long_t check_context_unload;
34499 - atomic_long_t tlb_dropin;
34500 - atomic_long_t tlb_preload_page;
34501 - atomic_long_t tlb_dropin_fail_no_asid;
34502 - atomic_long_t tlb_dropin_fail_upm;
34503 - atomic_long_t tlb_dropin_fail_invalid;
34504 - atomic_long_t tlb_dropin_fail_range_active;
34505 - atomic_long_t tlb_dropin_fail_idle;
34506 - atomic_long_t tlb_dropin_fail_fmm;
34507 - atomic_long_t tlb_dropin_fail_no_exception;
34508 - atomic_long_t tfh_stale_on_fault;
34509 - atomic_long_t mmu_invalidate_range;
34510 - atomic_long_t mmu_invalidate_page;
34511 - atomic_long_t flush_tlb;
34512 - atomic_long_t flush_tlb_gru;
34513 - atomic_long_t flush_tlb_gru_tgh;
34514 - atomic_long_t flush_tlb_gru_zero_asid;
34515 + atomic_long_unchecked_t vdata_alloc;
34516 + atomic_long_unchecked_t vdata_free;
34517 + atomic_long_unchecked_t gts_alloc;
34518 + atomic_long_unchecked_t gts_free;
34519 + atomic_long_unchecked_t gms_alloc;
34520 + atomic_long_unchecked_t gms_free;
34521 + atomic_long_unchecked_t gts_double_allocate;
34522 + atomic_long_unchecked_t assign_context;
34523 + atomic_long_unchecked_t assign_context_failed;
34524 + atomic_long_unchecked_t free_context;
34525 + atomic_long_unchecked_t load_user_context;
34526 + atomic_long_unchecked_t load_kernel_context;
34527 + atomic_long_unchecked_t lock_kernel_context;
34528 + atomic_long_unchecked_t unlock_kernel_context;
34529 + atomic_long_unchecked_t steal_user_context;
34530 + atomic_long_unchecked_t steal_kernel_context;
34531 + atomic_long_unchecked_t steal_context_failed;
34532 + atomic_long_unchecked_t nopfn;
34533 + atomic_long_unchecked_t asid_new;
34534 + atomic_long_unchecked_t asid_next;
34535 + atomic_long_unchecked_t asid_wrap;
34536 + atomic_long_unchecked_t asid_reuse;
34537 + atomic_long_unchecked_t intr;
34538 + atomic_long_unchecked_t intr_cbr;
34539 + atomic_long_unchecked_t intr_tfh;
34540 + atomic_long_unchecked_t intr_spurious;
34541 + atomic_long_unchecked_t intr_mm_lock_failed;
34542 + atomic_long_unchecked_t call_os;
34543 + atomic_long_unchecked_t call_os_wait_queue;
34544 + atomic_long_unchecked_t user_flush_tlb;
34545 + atomic_long_unchecked_t user_unload_context;
34546 + atomic_long_unchecked_t user_exception;
34547 + atomic_long_unchecked_t set_context_option;
34548 + atomic_long_unchecked_t check_context_retarget_intr;
34549 + atomic_long_unchecked_t check_context_unload;
34550 + atomic_long_unchecked_t tlb_dropin;
34551 + atomic_long_unchecked_t tlb_preload_page;
34552 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34553 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34554 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34555 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34556 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34557 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34558 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34559 + atomic_long_unchecked_t tfh_stale_on_fault;
34560 + atomic_long_unchecked_t mmu_invalidate_range;
34561 + atomic_long_unchecked_t mmu_invalidate_page;
34562 + atomic_long_unchecked_t flush_tlb;
34563 + atomic_long_unchecked_t flush_tlb_gru;
34564 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34565 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34566
34567 - atomic_long_t copy_gpa;
34568 - atomic_long_t read_gpa;
34569 + atomic_long_unchecked_t copy_gpa;
34570 + atomic_long_unchecked_t read_gpa;
34571
34572 - atomic_long_t mesq_receive;
34573 - atomic_long_t mesq_receive_none;
34574 - atomic_long_t mesq_send;
34575 - atomic_long_t mesq_send_failed;
34576 - atomic_long_t mesq_noop;
34577 - atomic_long_t mesq_send_unexpected_error;
34578 - atomic_long_t mesq_send_lb_overflow;
34579 - atomic_long_t mesq_send_qlimit_reached;
34580 - atomic_long_t mesq_send_amo_nacked;
34581 - atomic_long_t mesq_send_put_nacked;
34582 - atomic_long_t mesq_page_overflow;
34583 - atomic_long_t mesq_qf_locked;
34584 - atomic_long_t mesq_qf_noop_not_full;
34585 - atomic_long_t mesq_qf_switch_head_failed;
34586 - atomic_long_t mesq_qf_unexpected_error;
34587 - atomic_long_t mesq_noop_unexpected_error;
34588 - atomic_long_t mesq_noop_lb_overflow;
34589 - atomic_long_t mesq_noop_qlimit_reached;
34590 - atomic_long_t mesq_noop_amo_nacked;
34591 - atomic_long_t mesq_noop_put_nacked;
34592 - atomic_long_t mesq_noop_page_overflow;
34593 + atomic_long_unchecked_t mesq_receive;
34594 + atomic_long_unchecked_t mesq_receive_none;
34595 + atomic_long_unchecked_t mesq_send;
34596 + atomic_long_unchecked_t mesq_send_failed;
34597 + atomic_long_unchecked_t mesq_noop;
34598 + atomic_long_unchecked_t mesq_send_unexpected_error;
34599 + atomic_long_unchecked_t mesq_send_lb_overflow;
34600 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34601 + atomic_long_unchecked_t mesq_send_amo_nacked;
34602 + atomic_long_unchecked_t mesq_send_put_nacked;
34603 + atomic_long_unchecked_t mesq_page_overflow;
34604 + atomic_long_unchecked_t mesq_qf_locked;
34605 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34606 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34607 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34608 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34609 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34610 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34611 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34612 + atomic_long_unchecked_t mesq_noop_put_nacked;
34613 + atomic_long_unchecked_t mesq_noop_page_overflow;
34614
34615 };
34616
34617 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34618 tghop_invalidate, mcsop_last};
34619
34620 struct mcs_op_statistic {
34621 - atomic_long_t count;
34622 - atomic_long_t total;
34623 + atomic_long_unchecked_t count;
34624 + atomic_long_unchecked_t total;
34625 unsigned long max;
34626 };
34627
34628 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34629
34630 #define STAT(id) do { \
34631 if (gru_options & OPT_STATS) \
34632 - atomic_long_inc(&gru_stats.id); \
34633 + atomic_long_inc_unchecked(&gru_stats.id); \
34634 } while (0)
34635
34636 #ifdef CONFIG_SGI_GRU_DEBUG
34637 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34638 index c862cd4..0d176fe 100644
34639 --- a/drivers/misc/sgi-xp/xp.h
34640 +++ b/drivers/misc/sgi-xp/xp.h
34641 @@ -288,7 +288,7 @@ struct xpc_interface {
34642 xpc_notify_func, void *);
34643 void (*received) (short, int, void *);
34644 enum xp_retval (*partid_to_nasids) (short, void *);
34645 -};
34646 +} __no_const;
34647
34648 extern struct xpc_interface xpc_interface;
34649
34650 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34651 index b94d5f7..7f494c5 100644
34652 --- a/drivers/misc/sgi-xp/xpc.h
34653 +++ b/drivers/misc/sgi-xp/xpc.h
34654 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34655 void (*received_payload) (struct xpc_channel *, void *);
34656 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34657 };
34658 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34659
34660 /* struct xpc_partition act_state values (for XPC HB) */
34661
34662 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34663 /* found in xpc_main.c */
34664 extern struct device *xpc_part;
34665 extern struct device *xpc_chan;
34666 -extern struct xpc_arch_operations xpc_arch_ops;
34667 +extern xpc_arch_operations_no_const xpc_arch_ops;
34668 extern int xpc_disengage_timelimit;
34669 extern int xpc_disengage_timedout;
34670 extern int xpc_activate_IRQ_rcvd;
34671 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34672 index 8d082b4..aa749ae 100644
34673 --- a/drivers/misc/sgi-xp/xpc_main.c
34674 +++ b/drivers/misc/sgi-xp/xpc_main.c
34675 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34676 .notifier_call = xpc_system_die,
34677 };
34678
34679 -struct xpc_arch_operations xpc_arch_ops;
34680 +xpc_arch_operations_no_const xpc_arch_ops;
34681
34682 /*
34683 * Timer function to enforce the timelimit on the partition disengage.
34684 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
34685 index a0e1720..ee63d0b 100644
34686 --- a/drivers/mmc/core/mmc_ops.c
34687 +++ b/drivers/mmc/core/mmc_ops.c
34688 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
34689 void *data_buf;
34690 int is_on_stack;
34691
34692 - is_on_stack = object_is_on_stack(buf);
34693 + is_on_stack = object_starts_on_stack(buf);
34694 if (is_on_stack) {
34695 /*
34696 * dma onto stack is unsafe/nonportable, but callers to this
34697 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34698 index a4eb8b5..8c0628f 100644
34699 --- a/drivers/mtd/devices/doc2000.c
34700 +++ b/drivers/mtd/devices/doc2000.c
34701 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34702
34703 /* The ECC will not be calculated correctly if less than 512 is written */
34704 /* DBB-
34705 - if (len != 0x200 && eccbuf)
34706 + if (len != 0x200)
34707 printk(KERN_WARNING
34708 "ECC needs a full sector write (adr: %lx size %lx)\n",
34709 (long) to, (long) len);
34710 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34711 index e706a23..b3d262f 100644
34712 --- a/drivers/mtd/nand/denali.c
34713 +++ b/drivers/mtd/nand/denali.c
34714 @@ -26,6 +26,7 @@
34715 #include <linux/pci.h>
34716 #include <linux/mtd/mtd.h>
34717 #include <linux/module.h>
34718 +#include <linux/slab.h>
34719
34720 #include "denali.h"
34721
34722 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34723 index 51b9d6a..52af9a7 100644
34724 --- a/drivers/mtd/nftlmount.c
34725 +++ b/drivers/mtd/nftlmount.c
34726 @@ -24,6 +24,7 @@
34727 #include <asm/errno.h>
34728 #include <linux/delay.h>
34729 #include <linux/slab.h>
34730 +#include <linux/sched.h>
34731 #include <linux/mtd/mtd.h>
34732 #include <linux/mtd/nand.h>
34733 #include <linux/mtd/nftl.h>
34734 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34735 index acf2fe4..25cf8fd 100644
34736 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34737 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34738 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34739
34740 int (*wait_comp)(struct bnx2x *bp,
34741 struct bnx2x_rx_mode_ramrod_params *p);
34742 -};
34743 +} __no_const;
34744
34745 /********************** Set multicast group ***********************************/
34746
34747 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34748 index d9308c32..d87b824 100644
34749 --- a/drivers/net/ethernet/broadcom/tg3.h
34750 +++ b/drivers/net/ethernet/broadcom/tg3.h
34751 @@ -140,6 +140,7 @@
34752 #define CHIPREV_ID_5750_A0 0x4000
34753 #define CHIPREV_ID_5750_A1 0x4001
34754 #define CHIPREV_ID_5750_A3 0x4003
34755 +#define CHIPREV_ID_5750_C1 0x4201
34756 #define CHIPREV_ID_5750_C2 0x4202
34757 #define CHIPREV_ID_5752_A0_HW 0x5000
34758 #define CHIPREV_ID_5752_A0 0x6000
34759 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34760 index 8cffcdf..aadf043 100644
34761 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34762 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34763 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34764 */
34765 struct l2t_skb_cb {
34766 arp_failure_handler_func arp_failure_handler;
34767 -};
34768 +} __no_const;
34769
34770 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34771
34772 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34773 index f879e92..726f20f 100644
34774 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34775 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34776 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34777 for (i=0; i<ETH_ALEN; i++) {
34778 tmp.addr[i] = dev->dev_addr[i];
34779 }
34780 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34781 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34782 break;
34783
34784 case DE4X5_SET_HWADDR: /* Set the hardware address */
34785 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34786 spin_lock_irqsave(&lp->lock, flags);
34787 memcpy(&statbuf, &lp->pktStats, ioc->len);
34788 spin_unlock_irqrestore(&lp->lock, flags);
34789 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34790 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34791 return -EFAULT;
34792 break;
34793 }
34794 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34795 index 75d45f8..3d9c55b 100644
34796 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34797 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34798 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34799 struct uli_phy_ops {
34800 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34801 u16 (*read)(struct uli526x_board_info *, u8, u8);
34802 - } phy;
34803 + } __no_const phy;
34804 struct net_device *next_dev; /* next device */
34805 struct pci_dev *pdev; /* PCI device */
34806 spinlock_t lock;
34807 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34808 index d1b6cc5..cde0d97 100644
34809 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34810 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34811 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34812
34813 if (wrapped)
34814 newacc += 65536;
34815 - ACCESS_ONCE(*acc) = newacc;
34816 + ACCESS_ONCE_RW(*acc) = newacc;
34817 }
34818
34819 void be_parse_stats(struct be_adapter *adapter)
34820 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34821 index 74d749e..eefb1bd 100644
34822 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34823 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34824 @@ -31,6 +31,8 @@
34825 #include <linux/netdevice.h>
34826 #include <linux/phy.h>
34827 #include <linux/platform_device.h>
34828 +#include <linux/interrupt.h>
34829 +#include <linux/irqreturn.h>
34830 #include <net/ip.h>
34831
34832 #include "ftgmac100.h"
34833 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34834 index b901a01..1ff32ee 100644
34835 --- a/drivers/net/ethernet/faraday/ftmac100.c
34836 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34837 @@ -31,6 +31,8 @@
34838 #include <linux/module.h>
34839 #include <linux/netdevice.h>
34840 #include <linux/platform_device.h>
34841 +#include <linux/interrupt.h>
34842 +#include <linux/irqreturn.h>
34843
34844 #include "ftmac100.h"
34845
34846 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34847 index d37bfd9..5e13032 100644
34848 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34849 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34850 @@ -799,6 +799,7 @@ struct e1000_mac_operations {
34851 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34852 s32 (*read_mac_addr)(struct e1000_hw *);
34853 };
34854 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34855
34856 /*
34857 * When to use various PHY register access functions:
34858 @@ -839,6 +840,7 @@ struct e1000_phy_operations {
34859 void (*power_up)(struct e1000_hw *);
34860 void (*power_down)(struct e1000_hw *);
34861 };
34862 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34863
34864 /* Function pointers for the NVM. */
34865 struct e1000_nvm_operations {
34866 @@ -851,9 +853,10 @@ struct e1000_nvm_operations {
34867 s32 (*validate)(struct e1000_hw *);
34868 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34869 };
34870 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34871
34872 struct e1000_mac_info {
34873 - struct e1000_mac_operations ops;
34874 + e1000_mac_operations_no_const ops;
34875 u8 addr[ETH_ALEN];
34876 u8 perm_addr[ETH_ALEN];
34877
34878 @@ -894,7 +897,7 @@ struct e1000_mac_info {
34879 };
34880
34881 struct e1000_phy_info {
34882 - struct e1000_phy_operations ops;
34883 + e1000_phy_operations_no_const ops;
34884
34885 enum e1000_phy_type type;
34886
34887 @@ -928,7 +931,7 @@ struct e1000_phy_info {
34888 };
34889
34890 struct e1000_nvm_info {
34891 - struct e1000_nvm_operations ops;
34892 + e1000_nvm_operations_no_const ops;
34893
34894 enum e1000_nvm_type type;
34895 enum e1000_nvm_override override;
34896 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34897 index c2a51dc..c2bd262 100644
34898 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34899 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34900 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
34901 void (*release_swfw_sync)(struct e1000_hw *, u16);
34902
34903 };
34904 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34905
34906 struct e1000_phy_operations {
34907 s32 (*acquire)(struct e1000_hw *);
34908 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
34909 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34910 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34911 };
34912 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34913
34914 struct e1000_nvm_operations {
34915 s32 (*acquire)(struct e1000_hw *);
34916 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34917 s32 (*validate)(struct e1000_hw *);
34918 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34919 };
34920 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34921
34922 struct e1000_info {
34923 s32 (*get_invariants)(struct e1000_hw *);
34924 @@ -364,7 +367,7 @@ struct e1000_info {
34925 extern const struct e1000_info e1000_82575_info;
34926
34927 struct e1000_mac_info {
34928 - struct e1000_mac_operations ops;
34929 + e1000_mac_operations_no_const ops;
34930
34931 u8 addr[6];
34932 u8 perm_addr[6];
34933 @@ -402,7 +405,7 @@ struct e1000_mac_info {
34934 };
34935
34936 struct e1000_phy_info {
34937 - struct e1000_phy_operations ops;
34938 + e1000_phy_operations_no_const ops;
34939
34940 enum e1000_phy_type type;
34941
34942 @@ -437,7 +440,7 @@ struct e1000_phy_info {
34943 };
34944
34945 struct e1000_nvm_info {
34946 - struct e1000_nvm_operations ops;
34947 + e1000_nvm_operations_no_const ops;
34948 enum e1000_nvm_type type;
34949 enum e1000_nvm_override override;
34950
34951 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34952 s32 (*check_for_ack)(struct e1000_hw *, u16);
34953 s32 (*check_for_rst)(struct e1000_hw *, u16);
34954 };
34955 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34956
34957 struct e1000_mbx_stats {
34958 u32 msgs_tx;
34959 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34960 };
34961
34962 struct e1000_mbx_info {
34963 - struct e1000_mbx_operations ops;
34964 + e1000_mbx_operations_no_const ops;
34965 struct e1000_mbx_stats stats;
34966 u32 timeout;
34967 u32 usec_delay;
34968 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34969 index 57db3c6..aa825fc 100644
34970 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34971 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34972 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34973 s32 (*read_mac_addr)(struct e1000_hw *);
34974 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34975 };
34976 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34977
34978 struct e1000_mac_info {
34979 - struct e1000_mac_operations ops;
34980 + e1000_mac_operations_no_const ops;
34981 u8 addr[6];
34982 u8 perm_addr[6];
34983
34984 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34985 s32 (*check_for_ack)(struct e1000_hw *);
34986 s32 (*check_for_rst)(struct e1000_hw *);
34987 };
34988 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34989
34990 struct e1000_mbx_stats {
34991 u32 msgs_tx;
34992 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34993 };
34994
34995 struct e1000_mbx_info {
34996 - struct e1000_mbx_operations ops;
34997 + e1000_mbx_operations_no_const ops;
34998 struct e1000_mbx_stats stats;
34999 u32 timeout;
35000 u32 usec_delay;
35001 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35002 index d929131..aed108f 100644
35003 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35004 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35005 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35006 /* store the new cycle speed */
35007 adapter->cycle_speed = cycle_speed;
35008
35009 - ACCESS_ONCE(adapter->base_incval) = incval;
35010 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35011 smp_mb();
35012
35013 /* grab the ptp lock */
35014 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35015 index 0722f33..771758a 100644
35016 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35017 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35018 @@ -2800,6 +2800,7 @@ struct ixgbe_eeprom_operations {
35019 s32 (*update_checksum)(struct ixgbe_hw *);
35020 u16 (*calc_checksum)(struct ixgbe_hw *);
35021 };
35022 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35023
35024 struct ixgbe_mac_operations {
35025 s32 (*init_hw)(struct ixgbe_hw *);
35026 @@ -2866,6 +2867,7 @@ struct ixgbe_mac_operations {
35027 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35028 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35029 };
35030 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35031
35032 struct ixgbe_phy_operations {
35033 s32 (*identify)(struct ixgbe_hw *);
35034 @@ -2885,9 +2887,10 @@ struct ixgbe_phy_operations {
35035 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35036 s32 (*check_overtemp)(struct ixgbe_hw *);
35037 };
35038 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35039
35040 struct ixgbe_eeprom_info {
35041 - struct ixgbe_eeprom_operations ops;
35042 + ixgbe_eeprom_operations_no_const ops;
35043 enum ixgbe_eeprom_type type;
35044 u32 semaphore_delay;
35045 u16 word_size;
35046 @@ -2897,7 +2900,7 @@ struct ixgbe_eeprom_info {
35047
35048 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35049 struct ixgbe_mac_info {
35050 - struct ixgbe_mac_operations ops;
35051 + ixgbe_mac_operations_no_const ops;
35052 enum ixgbe_mac_type type;
35053 u8 addr[ETH_ALEN];
35054 u8 perm_addr[ETH_ALEN];
35055 @@ -2927,7 +2930,7 @@ struct ixgbe_mac_info {
35056 };
35057
35058 struct ixgbe_phy_info {
35059 - struct ixgbe_phy_operations ops;
35060 + ixgbe_phy_operations_no_const ops;
35061 struct mdio_if_info mdio;
35062 enum ixgbe_phy_type type;
35063 u32 id;
35064 @@ -2955,6 +2958,7 @@ struct ixgbe_mbx_operations {
35065 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35066 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35067 };
35068 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35069
35070 struct ixgbe_mbx_stats {
35071 u32 msgs_tx;
35072 @@ -2966,7 +2970,7 @@ struct ixgbe_mbx_stats {
35073 };
35074
35075 struct ixgbe_mbx_info {
35076 - struct ixgbe_mbx_operations ops;
35077 + ixgbe_mbx_operations_no_const ops;
35078 struct ixgbe_mbx_stats stats;
35079 u32 timeout;
35080 u32 usec_delay;
35081 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35082 index 47f11a5..c817d97 100644
35083 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35084 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35085 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35086 s32 (*clear_vfta)(struct ixgbe_hw *);
35087 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35088 };
35089 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35090
35091 enum ixgbe_mac_type {
35092 ixgbe_mac_unknown = 0,
35093 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35094 };
35095
35096 struct ixgbe_mac_info {
35097 - struct ixgbe_mac_operations ops;
35098 + ixgbe_mac_operations_no_const ops;
35099 u8 addr[6];
35100 u8 perm_addr[6];
35101
35102 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35103 s32 (*check_for_ack)(struct ixgbe_hw *);
35104 s32 (*check_for_rst)(struct ixgbe_hw *);
35105 };
35106 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35107
35108 struct ixgbe_mbx_stats {
35109 u32 msgs_tx;
35110 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35111 };
35112
35113 struct ixgbe_mbx_info {
35114 - struct ixgbe_mbx_operations ops;
35115 + ixgbe_mbx_operations_no_const ops;
35116 struct ixgbe_mbx_stats stats;
35117 u32 timeout;
35118 u32 udelay;
35119 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35120 index 9e0c1ee..8471f77 100644
35121 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35122 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35123 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35124 void (*link_down)(struct __vxge_hw_device *devh);
35125 void (*crit_err)(struct __vxge_hw_device *devh,
35126 enum vxge_hw_event type, u64 ext_data);
35127 -};
35128 +} __no_const;
35129
35130 /*
35131 * struct __vxge_hw_blockpool_entry - Block private data structure
35132 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35133 index 4a518a3..936b334 100644
35134 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35135 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35136 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35137 struct vxge_hw_mempool_dma *dma_object,
35138 u32 index,
35139 u32 is_last);
35140 -};
35141 +} __no_const;
35142
35143 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35144 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35145 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35146 index 927aa33..a6c2518 100644
35147 --- a/drivers/net/ethernet/realtek/r8169.c
35148 +++ b/drivers/net/ethernet/realtek/r8169.c
35149 @@ -747,22 +747,22 @@ struct rtl8169_private {
35150 struct mdio_ops {
35151 void (*write)(struct rtl8169_private *, int, int);
35152 int (*read)(struct rtl8169_private *, int);
35153 - } mdio_ops;
35154 + } __no_const mdio_ops;
35155
35156 struct pll_power_ops {
35157 void (*down)(struct rtl8169_private *);
35158 void (*up)(struct rtl8169_private *);
35159 - } pll_power_ops;
35160 + } __no_const pll_power_ops;
35161
35162 struct jumbo_ops {
35163 void (*enable)(struct rtl8169_private *);
35164 void (*disable)(struct rtl8169_private *);
35165 - } jumbo_ops;
35166 + } __no_const jumbo_ops;
35167
35168 struct csi_ops {
35169 void (*write)(struct rtl8169_private *, int, int);
35170 u32 (*read)(struct rtl8169_private *, int);
35171 - } csi_ops;
35172 + } __no_const csi_ops;
35173
35174 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35175 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35176 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
35177 index 0767043f..08c2553 100644
35178 --- a/drivers/net/ethernet/sfc/ptp.c
35179 +++ b/drivers/net/ethernet/sfc/ptp.c
35180 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
35181 (u32)((u64)ptp->start.dma_addr >> 32));
35182
35183 /* Clear flag that signals MC ready */
35184 - ACCESS_ONCE(*start) = 0;
35185 + ACCESS_ONCE_RW(*start) = 0;
35186 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
35187 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
35188
35189 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35190 index 0c74a70..3bc6f68 100644
35191 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35192 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35193 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35194
35195 writel(value, ioaddr + MMC_CNTRL);
35196
35197 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35198 - MMC_CNTRL, value);
35199 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35200 +// MMC_CNTRL, value);
35201 }
35202
35203 /* To mask all all interrupts.*/
35204 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35205 index 5fd6f46..ee1f265 100644
35206 --- a/drivers/net/hyperv/hyperv_net.h
35207 +++ b/drivers/net/hyperv/hyperv_net.h
35208 @@ -101,7 +101,7 @@ struct rndis_device {
35209
35210 enum rndis_device_state state;
35211 bool link_state;
35212 - atomic_t new_req_id;
35213 + atomic_unchecked_t new_req_id;
35214
35215 spinlock_t request_lock;
35216 struct list_head req_list;
35217 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35218 index 928148c..d83298e 100644
35219 --- a/drivers/net/hyperv/rndis_filter.c
35220 +++ b/drivers/net/hyperv/rndis_filter.c
35221 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35222 * template
35223 */
35224 set = &rndis_msg->msg.set_req;
35225 - set->req_id = atomic_inc_return(&dev->new_req_id);
35226 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35227
35228 /* Add to the request list */
35229 spin_lock_irqsave(&dev->request_lock, flags);
35230 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35231
35232 /* Setup the rndis set */
35233 halt = &request->request_msg.msg.halt_req;
35234 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35235 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35236
35237 /* Ignore return since this msg is optional. */
35238 rndis_filter_send_request(dev, request);
35239 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
35240 index 7d39add..037e1da 100644
35241 --- a/drivers/net/ieee802154/fakehard.c
35242 +++ b/drivers/net/ieee802154/fakehard.c
35243 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
35244 phy->transmit_power = 0xbf;
35245
35246 dev->netdev_ops = &fake_ops;
35247 - dev->ml_priv = &fake_mlme;
35248 + dev->ml_priv = (void *)&fake_mlme;
35249
35250 priv = netdev_priv(dev);
35251 priv->phy = phy;
35252 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35253 index daec9b0..6428fcb 100644
35254 --- a/drivers/net/phy/mdio-bitbang.c
35255 +++ b/drivers/net/phy/mdio-bitbang.c
35256 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35257 struct mdiobb_ctrl *ctrl = bus->priv;
35258
35259 module_put(ctrl->ops->owner);
35260 + mdiobus_unregister(bus);
35261 mdiobus_free(bus);
35262 }
35263 EXPORT_SYMBOL(free_mdio_bitbang);
35264 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35265 index eb3f5ce..d773730 100644
35266 --- a/drivers/net/ppp/ppp_generic.c
35267 +++ b/drivers/net/ppp/ppp_generic.c
35268 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35269 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35270 struct ppp_stats stats;
35271 struct ppp_comp_stats cstats;
35272 - char *vers;
35273
35274 switch (cmd) {
35275 case SIOCGPPPSTATS:
35276 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35277 break;
35278
35279 case SIOCGPPPVER:
35280 - vers = PPP_VERSION;
35281 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35282 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35283 break;
35284 err = 0;
35285 break;
35286 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35287 index 0873cdc..ddb178e 100644
35288 --- a/drivers/net/tun.c
35289 +++ b/drivers/net/tun.c
35290 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35291 }
35292
35293 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35294 - unsigned long arg, int ifreq_len)
35295 + unsigned long arg, size_t ifreq_len)
35296 {
35297 struct tun_file *tfile = file->private_data;
35298 struct tun_struct *tun;
35299 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35300 int vnet_hdr_sz;
35301 int ret;
35302
35303 + if (ifreq_len > sizeof ifr)
35304 + return -EFAULT;
35305 +
35306 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35307 if (copy_from_user(&ifr, argp, ifreq_len))
35308 return -EFAULT;
35309 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35310 index 605a4ba..a883dd1 100644
35311 --- a/drivers/net/usb/hso.c
35312 +++ b/drivers/net/usb/hso.c
35313 @@ -71,7 +71,7 @@
35314 #include <asm/byteorder.h>
35315 #include <linux/serial_core.h>
35316 #include <linux/serial.h>
35317 -
35318 +#include <asm/local.h>
35319
35320 #define MOD_AUTHOR "Option Wireless"
35321 #define MOD_DESCRIPTION "USB High Speed Option driver"
35322 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35323 struct urb *urb;
35324
35325 urb = serial->rx_urb[0];
35326 - if (serial->port.count > 0) {
35327 + if (atomic_read(&serial->port.count) > 0) {
35328 count = put_rxbuf_data(urb, serial);
35329 if (count == -1)
35330 return;
35331 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35332 DUMP1(urb->transfer_buffer, urb->actual_length);
35333
35334 /* Anyone listening? */
35335 - if (serial->port.count == 0)
35336 + if (atomic_read(&serial->port.count) == 0)
35337 return;
35338
35339 if (status == 0) {
35340 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35341 tty_port_tty_set(&serial->port, tty);
35342
35343 /* check for port already opened, if not set the termios */
35344 - serial->port.count++;
35345 - if (serial->port.count == 1) {
35346 + if (atomic_inc_return(&serial->port.count) == 1) {
35347 serial->rx_state = RX_IDLE;
35348 /* Force default termio settings */
35349 _hso_serial_set_termios(tty, NULL);
35350 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35351 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35352 if (result) {
35353 hso_stop_serial_device(serial->parent);
35354 - serial->port.count--;
35355 + atomic_dec(&serial->port.count);
35356 kref_put(&serial->parent->ref, hso_serial_ref_free);
35357 }
35358 } else {
35359 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35360
35361 /* reset the rts and dtr */
35362 /* do the actual close */
35363 - serial->port.count--;
35364 + atomic_dec(&serial->port.count);
35365
35366 - if (serial->port.count <= 0) {
35367 - serial->port.count = 0;
35368 + if (atomic_read(&serial->port.count) <= 0) {
35369 + atomic_set(&serial->port.count, 0);
35370 tty_port_tty_set(&serial->port, NULL);
35371 if (!usb_gone)
35372 hso_stop_serial_device(serial->parent);
35373 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35374
35375 /* the actual setup */
35376 spin_lock_irqsave(&serial->serial_lock, flags);
35377 - if (serial->port.count)
35378 + if (atomic_read(&serial->port.count))
35379 _hso_serial_set_termios(tty, old);
35380 else
35381 tty->termios = *old;
35382 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
35383 D1("Pending read interrupt on port %d\n", i);
35384 spin_lock(&serial->serial_lock);
35385 if (serial->rx_state == RX_IDLE &&
35386 - serial->port.count > 0) {
35387 + atomic_read(&serial->port.count) > 0) {
35388 /* Setup and send a ctrl req read on
35389 * port i */
35390 if (!serial->rx_urb_filled[0]) {
35391 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
35392 /* Start all serial ports */
35393 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35394 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35395 - if (dev2ser(serial_table[i])->port.count) {
35396 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35397 result =
35398 hso_start_serial_device(serial_table[i], GFP_NOIO);
35399 hso_kick_transmit(dev2ser(serial_table[i]));
35400 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35401 index 4521342..9f0a994d 100644
35402 --- a/drivers/net/wireless/ath/ath.h
35403 +++ b/drivers/net/wireless/ath/ath.h
35404 @@ -119,6 +119,7 @@ struct ath_ops {
35405 void (*write_flush) (void *);
35406 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35407 };
35408 +typedef struct ath_ops __no_const ath_ops_no_const;
35409
35410 struct ath_common;
35411 struct ath_bus_ops;
35412 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35413 index 8d78253..bebbb68 100644
35414 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35415 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35416 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35417 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35418 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35419
35420 - ACCESS_ONCE(ads->ds_link) = i->link;
35421 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35422 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35423 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35424
35425 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35426 ctl6 = SM(i->keytype, AR_EncrType);
35427 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35428
35429 if ((i->is_first || i->is_last) &&
35430 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35431 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35432 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35433 | set11nTries(i->rates, 1)
35434 | set11nTries(i->rates, 2)
35435 | set11nTries(i->rates, 3)
35436 | (i->dur_update ? AR_DurUpdateEna : 0)
35437 | SM(0, AR_BurstDur);
35438
35439 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35440 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35441 | set11nRate(i->rates, 1)
35442 | set11nRate(i->rates, 2)
35443 | set11nRate(i->rates, 3);
35444 } else {
35445 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35446 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35447 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35448 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35449 }
35450
35451 if (!i->is_first) {
35452 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35453 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35454 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35455 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35456 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35457 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35458 return;
35459 }
35460
35461 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35462 break;
35463 }
35464
35465 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35466 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35467 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35468 | SM(i->txpower, AR_XmitPower)
35469 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35470 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35471 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35472 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35473
35474 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35475 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35476 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35477 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35478
35479 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35480 return;
35481
35482 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35483 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35484 | set11nPktDurRTSCTS(i->rates, 1);
35485
35486 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35487 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35488 | set11nPktDurRTSCTS(i->rates, 3);
35489
35490 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35491 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35492 | set11nRateFlags(i->rates, 1)
35493 | set11nRateFlags(i->rates, 2)
35494 | set11nRateFlags(i->rates, 3)
35495 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35496 index 301bf72..3f5654f 100644
35497 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35498 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35499 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35500 (i->qcu << AR_TxQcuNum_S) | desc_len;
35501
35502 checksum += val;
35503 - ACCESS_ONCE(ads->info) = val;
35504 + ACCESS_ONCE_RW(ads->info) = val;
35505
35506 checksum += i->link;
35507 - ACCESS_ONCE(ads->link) = i->link;
35508 + ACCESS_ONCE_RW(ads->link) = i->link;
35509
35510 checksum += i->buf_addr[0];
35511 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35512 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35513 checksum += i->buf_addr[1];
35514 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35515 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35516 checksum += i->buf_addr[2];
35517 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35518 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35519 checksum += i->buf_addr[3];
35520 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35521 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35522
35523 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35524 - ACCESS_ONCE(ads->ctl3) = val;
35525 + ACCESS_ONCE_RW(ads->ctl3) = val;
35526 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35527 - ACCESS_ONCE(ads->ctl5) = val;
35528 + ACCESS_ONCE_RW(ads->ctl5) = val;
35529 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35530 - ACCESS_ONCE(ads->ctl7) = val;
35531 + ACCESS_ONCE_RW(ads->ctl7) = val;
35532 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35533 - ACCESS_ONCE(ads->ctl9) = val;
35534 + ACCESS_ONCE_RW(ads->ctl9) = val;
35535
35536 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35537 - ACCESS_ONCE(ads->ctl10) = checksum;
35538 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35539
35540 if (i->is_first || i->is_last) {
35541 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35542 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35543 | set11nTries(i->rates, 1)
35544 | set11nTries(i->rates, 2)
35545 | set11nTries(i->rates, 3)
35546 | (i->dur_update ? AR_DurUpdateEna : 0)
35547 | SM(0, AR_BurstDur);
35548
35549 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35550 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35551 | set11nRate(i->rates, 1)
35552 | set11nRate(i->rates, 2)
35553 | set11nRate(i->rates, 3);
35554 } else {
35555 - ACCESS_ONCE(ads->ctl13) = 0;
35556 - ACCESS_ONCE(ads->ctl14) = 0;
35557 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35558 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35559 }
35560
35561 ads->ctl20 = 0;
35562 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35563
35564 ctl17 = SM(i->keytype, AR_EncrType);
35565 if (!i->is_first) {
35566 - ACCESS_ONCE(ads->ctl11) = 0;
35567 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35568 - ACCESS_ONCE(ads->ctl15) = 0;
35569 - ACCESS_ONCE(ads->ctl16) = 0;
35570 - ACCESS_ONCE(ads->ctl17) = ctl17;
35571 - ACCESS_ONCE(ads->ctl18) = 0;
35572 - ACCESS_ONCE(ads->ctl19) = 0;
35573 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35574 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35575 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35576 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35577 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35578 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35579 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35580 return;
35581 }
35582
35583 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35584 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35585 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35586 | SM(i->txpower, AR_XmitPower)
35587 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35588 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35589 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35590 ctl12 |= SM(val, AR_PAPRDChainMask);
35591
35592 - ACCESS_ONCE(ads->ctl12) = ctl12;
35593 - ACCESS_ONCE(ads->ctl17) = ctl17;
35594 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35595 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35596
35597 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35598 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35599 | set11nPktDurRTSCTS(i->rates, 1);
35600
35601 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35602 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35603 | set11nPktDurRTSCTS(i->rates, 3);
35604
35605 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35606 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35607 | set11nRateFlags(i->rates, 1)
35608 | set11nRateFlags(i->rates, 2)
35609 | set11nRateFlags(i->rates, 3)
35610 | SM(i->rtscts_rate, AR_RTSCTSRate);
35611
35612 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35613 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35614 }
35615
35616 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35617 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35618 index dbc1b7a..addccc0 100644
35619 --- a/drivers/net/wireless/ath/ath9k/hw.h
35620 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35621 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
35622
35623 /* ANI */
35624 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35625 -};
35626 +} __no_const;
35627
35628 /**
35629 * struct ath_hw_ops - callbacks used by hardware code and driver code
35630 @@ -687,7 +687,7 @@ struct ath_hw_ops {
35631 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35632 struct ath_hw_antcomb_conf *antconf);
35633 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
35634 -};
35635 +} __no_const;
35636
35637 struct ath_nf_limits {
35638 s16 max;
35639 @@ -707,7 +707,7 @@ enum ath_cal_list {
35640 #define AH_FASTCC 0x4
35641
35642 struct ath_hw {
35643 - struct ath_ops reg_ops;
35644 + ath_ops_no_const reg_ops;
35645
35646 struct ieee80211_hw *hw;
35647 struct ath_common common;
35648 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35649 index af00e2c..ab04d34 100644
35650 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35651 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35652 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35653 void (*carrsuppr)(struct brcms_phy *);
35654 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35655 void (*detach)(struct brcms_phy *);
35656 -};
35657 +} __no_const;
35658
35659 struct brcms_phy {
35660 struct brcms_phy_pub pubpi_ro;
35661 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35662 index e252acb..6ad1e65 100644
35663 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35664 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35665 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35666 */
35667 if (il3945_mod_params.disable_hw_scan) {
35668 D_INFO("Disabling hw_scan\n");
35669 - il3945_mac_ops.hw_scan = NULL;
35670 + pax_open_kernel();
35671 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35672 + pax_close_kernel();
35673 }
35674
35675 D_INFO("*** LOAD DRIVER ***\n");
35676 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35677 index 1a98fa3..51e6661 100644
35678 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35679 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35680 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35681 {
35682 struct iwl_priv *priv = file->private_data;
35683 char buf[64];
35684 - int buf_size;
35685 + size_t buf_size;
35686 u32 offset, len;
35687
35688 memset(buf, 0, sizeof(buf));
35689 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35690 struct iwl_priv *priv = file->private_data;
35691
35692 char buf[8];
35693 - int buf_size;
35694 + size_t buf_size;
35695 u32 reset_flag;
35696
35697 memset(buf, 0, sizeof(buf));
35698 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35699 {
35700 struct iwl_priv *priv = file->private_data;
35701 char buf[8];
35702 - int buf_size;
35703 + size_t buf_size;
35704 int ht40;
35705
35706 memset(buf, 0, sizeof(buf));
35707 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35708 {
35709 struct iwl_priv *priv = file->private_data;
35710 char buf[8];
35711 - int buf_size;
35712 + size_t buf_size;
35713 int value;
35714
35715 memset(buf, 0, sizeof(buf));
35716 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35717 {
35718 struct iwl_priv *priv = file->private_data;
35719 char buf[8];
35720 - int buf_size;
35721 + size_t buf_size;
35722 int clear;
35723
35724 memset(buf, 0, sizeof(buf));
35725 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35726 {
35727 struct iwl_priv *priv = file->private_data;
35728 char buf[8];
35729 - int buf_size;
35730 + size_t buf_size;
35731 int trace;
35732
35733 memset(buf, 0, sizeof(buf));
35734 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35735 {
35736 struct iwl_priv *priv = file->private_data;
35737 char buf[8];
35738 - int buf_size;
35739 + size_t buf_size;
35740 int missed;
35741
35742 memset(buf, 0, sizeof(buf));
35743 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35744
35745 struct iwl_priv *priv = file->private_data;
35746 char buf[8];
35747 - int buf_size;
35748 + size_t buf_size;
35749 int plcp;
35750
35751 memset(buf, 0, sizeof(buf));
35752 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35753
35754 struct iwl_priv *priv = file->private_data;
35755 char buf[8];
35756 - int buf_size;
35757 + size_t buf_size;
35758 int flush;
35759
35760 memset(buf, 0, sizeof(buf));
35761 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35762
35763 struct iwl_priv *priv = file->private_data;
35764 char buf[8];
35765 - int buf_size;
35766 + size_t buf_size;
35767 int rts;
35768
35769 if (!priv->cfg->ht_params)
35770 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35771 {
35772 struct iwl_priv *priv = file->private_data;
35773 char buf[8];
35774 - int buf_size;
35775 + size_t buf_size;
35776
35777 memset(buf, 0, sizeof(buf));
35778 buf_size = min(count, sizeof(buf) - 1);
35779 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35780 struct iwl_priv *priv = file->private_data;
35781 u32 event_log_flag;
35782 char buf[8];
35783 - int buf_size;
35784 + size_t buf_size;
35785
35786 /* check that the interface is up */
35787 if (!iwl_is_ready(priv))
35788 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35789 struct iwl_priv *priv = file->private_data;
35790 char buf[8];
35791 u32 calib_disabled;
35792 - int buf_size;
35793 + size_t buf_size;
35794
35795 memset(buf, 0, sizeof(buf));
35796 buf_size = min(count, sizeof(buf) - 1);
35797 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35798 index fe0fffd..b4c5724 100644
35799 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35800 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35801 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35802 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35803
35804 char buf[8];
35805 - int buf_size;
35806 + size_t buf_size;
35807 u32 reset_flag;
35808
35809 memset(buf, 0, sizeof(buf));
35810 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35811 {
35812 struct iwl_trans *trans = file->private_data;
35813 char buf[8];
35814 - int buf_size;
35815 + size_t buf_size;
35816 int csr;
35817
35818 memset(buf, 0, sizeof(buf));
35819 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35820 index 429ca32..f86236b 100644
35821 --- a/drivers/net/wireless/mac80211_hwsim.c
35822 +++ b/drivers/net/wireless/mac80211_hwsim.c
35823 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
35824 return -EINVAL;
35825
35826 if (fake_hw_scan) {
35827 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35828 - mac80211_hwsim_ops.sw_scan_start = NULL;
35829 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35830 + pax_open_kernel();
35831 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35832 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35833 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35834 + pax_close_kernel();
35835 }
35836
35837 spin_lock_init(&hwsim_radio_lock);
35838 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35839 index c2d0ab1..fb9afe2 100644
35840 --- a/drivers/net/wireless/mwifiex/main.h
35841 +++ b/drivers/net/wireless/mwifiex/main.h
35842 @@ -603,7 +603,7 @@ struct mwifiex_if_ops {
35843 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35844 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35845 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35846 -};
35847 +} __no_const;
35848
35849 struct mwifiex_adapter {
35850 u8 iface_type;
35851 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35852 index bd1f0cb..db85ab0 100644
35853 --- a/drivers/net/wireless/rndis_wlan.c
35854 +++ b/drivers/net/wireless/rndis_wlan.c
35855 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35856
35857 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35858
35859 - if (rts_threshold < 0 || rts_threshold > 2347)
35860 + if (rts_threshold > 2347)
35861 rts_threshold = 2347;
35862
35863 tmp = cpu_to_le32(rts_threshold);
35864 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35865 index 0751b35..246ba3e 100644
35866 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35867 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35868 @@ -398,7 +398,7 @@ struct rt2x00_intf {
35869 * for hardware which doesn't support hardware
35870 * sequence counting.
35871 */
35872 - atomic_t seqno;
35873 + atomic_unchecked_t seqno;
35874 };
35875
35876 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35877 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35878 index e488b94..14b6a0c 100644
35879 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35880 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35881 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35882 * sequence counter given by mac80211.
35883 */
35884 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35885 - seqno = atomic_add_return(0x10, &intf->seqno);
35886 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35887 else
35888 - seqno = atomic_read(&intf->seqno);
35889 + seqno = atomic_read_unchecked(&intf->seqno);
35890
35891 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35892 hdr->seq_ctrl |= cpu_to_le16(seqno);
35893 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35894 index fd02060..74ee481 100644
35895 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35896 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35897 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35898 void (*reset)(struct wl1251 *wl);
35899 void (*enable_irq)(struct wl1251 *wl);
35900 void (*disable_irq)(struct wl1251 *wl);
35901 -};
35902 +} __no_const;
35903
35904 struct wl1251 {
35905 struct ieee80211_hw *hw;
35906 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35907 index 68584aa..10fc178 100644
35908 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
35909 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35910 @@ -88,7 +88,7 @@ struct wlcore_ops {
35911 struct ieee80211_sta *sta,
35912 struct ieee80211_key_conf *key_conf);
35913 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
35914 -};
35915 +} __no_const;
35916
35917 enum wlcore_partitions {
35918 PART_DOWN,
35919 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35920 index d93b2b6..ae50401 100644
35921 --- a/drivers/oprofile/buffer_sync.c
35922 +++ b/drivers/oprofile/buffer_sync.c
35923 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35924 if (cookie == NO_COOKIE)
35925 offset = pc;
35926 if (cookie == INVALID_COOKIE) {
35927 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35928 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35929 offset = pc;
35930 }
35931 if (cookie != last_cookie) {
35932 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35933 /* add userspace sample */
35934
35935 if (!mm) {
35936 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35937 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35938 return 0;
35939 }
35940
35941 cookie = lookup_dcookie(mm, s->eip, &offset);
35942
35943 if (cookie == INVALID_COOKIE) {
35944 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35945 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35946 return 0;
35947 }
35948
35949 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
35950 /* ignore backtraces if failed to add a sample */
35951 if (state == sb_bt_start) {
35952 state = sb_bt_ignore;
35953 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35954 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35955 }
35956 }
35957 release_mm(mm);
35958 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35959 index c0cc4e7..44d4e54 100644
35960 --- a/drivers/oprofile/event_buffer.c
35961 +++ b/drivers/oprofile/event_buffer.c
35962 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35963 }
35964
35965 if (buffer_pos == buffer_size) {
35966 - atomic_inc(&oprofile_stats.event_lost_overflow);
35967 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35968 return;
35969 }
35970
35971 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35972 index ed2c3ec..deda85a 100644
35973 --- a/drivers/oprofile/oprof.c
35974 +++ b/drivers/oprofile/oprof.c
35975 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35976 if (oprofile_ops.switch_events())
35977 return;
35978
35979 - atomic_inc(&oprofile_stats.multiplex_counter);
35980 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35981 start_switch_worker();
35982 }
35983
35984 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35985 index 917d28e..d62d981 100644
35986 --- a/drivers/oprofile/oprofile_stats.c
35987 +++ b/drivers/oprofile/oprofile_stats.c
35988 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35989 cpu_buf->sample_invalid_eip = 0;
35990 }
35991
35992 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35993 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35994 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35995 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35996 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35997 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35998 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35999 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36000 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36001 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36002 }
36003
36004
36005 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36006 index 38b6fc0..b5cbfce 100644
36007 --- a/drivers/oprofile/oprofile_stats.h
36008 +++ b/drivers/oprofile/oprofile_stats.h
36009 @@ -13,11 +13,11 @@
36010 #include <linux/atomic.h>
36011
36012 struct oprofile_stat_struct {
36013 - atomic_t sample_lost_no_mm;
36014 - atomic_t sample_lost_no_mapping;
36015 - atomic_t bt_lost_no_mapping;
36016 - atomic_t event_lost_overflow;
36017 - atomic_t multiplex_counter;
36018 + atomic_unchecked_t sample_lost_no_mm;
36019 + atomic_unchecked_t sample_lost_no_mapping;
36020 + atomic_unchecked_t bt_lost_no_mapping;
36021 + atomic_unchecked_t event_lost_overflow;
36022 + atomic_unchecked_t multiplex_counter;
36023 };
36024
36025 extern struct oprofile_stat_struct oprofile_stats;
36026 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36027 index 849357c..b83c1e0 100644
36028 --- a/drivers/oprofile/oprofilefs.c
36029 +++ b/drivers/oprofile/oprofilefs.c
36030 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36031
36032
36033 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36034 - char const *name, atomic_t *val)
36035 + char const *name, atomic_unchecked_t *val)
36036 {
36037 return __oprofilefs_create_file(sb, root, name,
36038 &atomic_ro_fops, 0444, val);
36039 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36040 index 3f56bc0..707d642 100644
36041 --- a/drivers/parport/procfs.c
36042 +++ b/drivers/parport/procfs.c
36043 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36044
36045 *ppos += len;
36046
36047 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36048 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36049 }
36050
36051 #ifdef CONFIG_PARPORT_1284
36052 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36053
36054 *ppos += len;
36055
36056 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36057 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36058 }
36059 #endif /* IEEE1284.3 support. */
36060
36061 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36062 index 9fff878..ad0ad53 100644
36063 --- a/drivers/pci/hotplug/cpci_hotplug.h
36064 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36065 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36066 int (*hardware_test) (struct slot* slot, u32 value);
36067 u8 (*get_power) (struct slot* slot);
36068 int (*set_power) (struct slot* slot, int value);
36069 -};
36070 +} __no_const;
36071
36072 struct cpci_hp_controller {
36073 unsigned int irq;
36074 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36075 index 76ba8a1..20ca857 100644
36076 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36077 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36078 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36079
36080 void compaq_nvram_init (void __iomem *rom_start)
36081 {
36082 +
36083 +#ifndef CONFIG_PAX_KERNEXEC
36084 if (rom_start) {
36085 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36086 }
36087 +#endif
36088 +
36089 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36090
36091 /* initialize our int15 lock */
36092 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36093 index 213753b..b4abaac 100644
36094 --- a/drivers/pci/pcie/aspm.c
36095 +++ b/drivers/pci/pcie/aspm.c
36096 @@ -27,9 +27,9 @@
36097 #define MODULE_PARAM_PREFIX "pcie_aspm."
36098
36099 /* Note: those are not register definitions */
36100 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36101 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36102 -#define ASPM_STATE_L1 (4) /* L1 state */
36103 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36104 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36105 +#define ASPM_STATE_L1 (4U) /* L1 state */
36106 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36107 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36108
36109 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36110 index ec909af..e7517f3 100644
36111 --- a/drivers/pci/probe.c
36112 +++ b/drivers/pci/probe.c
36113 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36114 struct pci_bus_region region;
36115 bool bar_too_big = false, bar_disabled = false;
36116
36117 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36118 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36119
36120 /* No printks while decoding is disabled! */
36121 if (!dev->mmio_always_on) {
36122 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36123 index 9b8505c..f00870a 100644
36124 --- a/drivers/pci/proc.c
36125 +++ b/drivers/pci/proc.c
36126 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36127 static int __init pci_proc_init(void)
36128 {
36129 struct pci_dev *dev = NULL;
36130 +
36131 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36132 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36133 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36134 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36135 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36136 +#endif
36137 +#else
36138 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36139 +#endif
36140 proc_create("devices", 0, proc_bus_pci_dir,
36141 &proc_bus_pci_dev_operations);
36142 proc_initialized = 1;
36143 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36144 index 75dd651..2af4c9a 100644
36145 --- a/drivers/platform/x86/thinkpad_acpi.c
36146 +++ b/drivers/platform/x86/thinkpad_acpi.c
36147 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36148 return 0;
36149 }
36150
36151 -void static hotkey_mask_warn_incomplete_mask(void)
36152 +static void hotkey_mask_warn_incomplete_mask(void)
36153 {
36154 /* log only what the user can fix... */
36155 const u32 wantedmask = hotkey_driver_mask &
36156 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36157 }
36158 }
36159
36160 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36161 - struct tp_nvram_state *newn,
36162 - const u32 event_mask)
36163 -{
36164 -
36165 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36166 do { \
36167 if ((event_mask & (1 << __scancode)) && \
36168 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36169 tpacpi_hotkey_send_key(__scancode); \
36170 } while (0)
36171
36172 - void issue_volchange(const unsigned int oldvol,
36173 - const unsigned int newvol)
36174 - {
36175 - unsigned int i = oldvol;
36176 +static void issue_volchange(const unsigned int oldvol,
36177 + const unsigned int newvol,
36178 + const u32 event_mask)
36179 +{
36180 + unsigned int i = oldvol;
36181
36182 - while (i > newvol) {
36183 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36184 - i--;
36185 - }
36186 - while (i < newvol) {
36187 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36188 - i++;
36189 - }
36190 + while (i > newvol) {
36191 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36192 + i--;
36193 }
36194 + while (i < newvol) {
36195 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36196 + i++;
36197 + }
36198 +}
36199
36200 - void issue_brightnesschange(const unsigned int oldbrt,
36201 - const unsigned int newbrt)
36202 - {
36203 - unsigned int i = oldbrt;
36204 +static void issue_brightnesschange(const unsigned int oldbrt,
36205 + const unsigned int newbrt,
36206 + const u32 event_mask)
36207 +{
36208 + unsigned int i = oldbrt;
36209
36210 - while (i > newbrt) {
36211 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36212 - i--;
36213 - }
36214 - while (i < newbrt) {
36215 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36216 - i++;
36217 - }
36218 + while (i > newbrt) {
36219 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36220 + i--;
36221 + }
36222 + while (i < newbrt) {
36223 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36224 + i++;
36225 }
36226 +}
36227
36228 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36229 + struct tp_nvram_state *newn,
36230 + const u32 event_mask)
36231 +{
36232 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36233 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36234 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36235 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36236 oldn->volume_level != newn->volume_level) {
36237 /* recently muted, or repeated mute keypress, or
36238 * multiple presses ending in mute */
36239 - issue_volchange(oldn->volume_level, newn->volume_level);
36240 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36241 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36242 }
36243 } else {
36244 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36245 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36246 }
36247 if (oldn->volume_level != newn->volume_level) {
36248 - issue_volchange(oldn->volume_level, newn->volume_level);
36249 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36250 } else if (oldn->volume_toggle != newn->volume_toggle) {
36251 /* repeated vol up/down keypress at end of scale ? */
36252 if (newn->volume_level == 0)
36253 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36254 /* handle brightness */
36255 if (oldn->brightness_level != newn->brightness_level) {
36256 issue_brightnesschange(oldn->brightness_level,
36257 - newn->brightness_level);
36258 + newn->brightness_level,
36259 + event_mask);
36260 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36261 /* repeated key presses that didn't change state */
36262 if (newn->brightness_level == 0)
36263 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36264 && !tp_features.bright_unkfw)
36265 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36266 }
36267 +}
36268
36269 #undef TPACPI_COMPARE_KEY
36270 #undef TPACPI_MAY_SEND_KEY
36271 -}
36272
36273 /*
36274 * Polling driver
36275 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36276 index 769d265..a3a05ca 100644
36277 --- a/drivers/pnp/pnpbios/bioscalls.c
36278 +++ b/drivers/pnp/pnpbios/bioscalls.c
36279 @@ -58,7 +58,7 @@ do { \
36280 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36281 } while(0)
36282
36283 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36284 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36285 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36286
36287 /*
36288 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36289
36290 cpu = get_cpu();
36291 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36292 +
36293 + pax_open_kernel();
36294 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36295 + pax_close_kernel();
36296
36297 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36298 spin_lock_irqsave(&pnp_bios_lock, flags);
36299 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36300 :"memory");
36301 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36302
36303 + pax_open_kernel();
36304 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36305 + pax_close_kernel();
36306 +
36307 put_cpu();
36308
36309 /* If we get here and this is set then the PnP BIOS faulted on us. */
36310 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36311 return status;
36312 }
36313
36314 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36315 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36316 {
36317 int i;
36318
36319 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36320 pnp_bios_callpoint.offset = header->fields.pm16offset;
36321 pnp_bios_callpoint.segment = PNP_CS16;
36322
36323 + pax_open_kernel();
36324 +
36325 for_each_possible_cpu(i) {
36326 struct desc_struct *gdt = get_cpu_gdt_table(i);
36327 if (!gdt)
36328 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36329 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36330 (unsigned long)__va(header->fields.pm16dseg));
36331 }
36332 +
36333 + pax_close_kernel();
36334 }
36335 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36336 index b0ecacb..7c9da2e 100644
36337 --- a/drivers/pnp/resource.c
36338 +++ b/drivers/pnp/resource.c
36339 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36340 return 1;
36341
36342 /* check if the resource is valid */
36343 - if (*irq < 0 || *irq > 15)
36344 + if (*irq > 15)
36345 return 0;
36346
36347 /* check if the resource is reserved */
36348 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36349 return 1;
36350
36351 /* check if the resource is valid */
36352 - if (*dma < 0 || *dma == 4 || *dma > 7)
36353 + if (*dma == 4 || *dma > 7)
36354 return 0;
36355
36356 /* check if the resource is reserved */
36357 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36358 index 5860d4d..d90d268 100644
36359 --- a/drivers/power/bq27x00_battery.c
36360 +++ b/drivers/power/bq27x00_battery.c
36361 @@ -80,7 +80,7 @@
36362 struct bq27x00_device_info;
36363 struct bq27x00_access_methods {
36364 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36365 -};
36366 +} __no_const;
36367
36368 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36369
36370 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36371 index 8d53174..04c65de 100644
36372 --- a/drivers/regulator/max8660.c
36373 +++ b/drivers/regulator/max8660.c
36374 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36375 max8660->shadow_regs[MAX8660_OVER1] = 5;
36376 } else {
36377 /* Otherwise devices can be toggled via software */
36378 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36379 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36380 + pax_open_kernel();
36381 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36382 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36383 + pax_close_kernel();
36384 }
36385
36386 /*
36387 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36388 index 1fa6381..f58834e 100644
36389 --- a/drivers/regulator/mc13892-regulator.c
36390 +++ b/drivers/regulator/mc13892-regulator.c
36391 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36392 }
36393 mc13xxx_unlock(mc13892);
36394
36395 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36396 + pax_open_kernel();
36397 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36398 = mc13892_vcam_set_mode;
36399 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36400 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36401 = mc13892_vcam_get_mode;
36402 + pax_close_kernel();
36403
36404 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36405 ARRAY_SIZE(mc13892_regulators));
36406 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36407 index cace6d3..f623fda 100644
36408 --- a/drivers/rtc/rtc-dev.c
36409 +++ b/drivers/rtc/rtc-dev.c
36410 @@ -14,6 +14,7 @@
36411 #include <linux/module.h>
36412 #include <linux/rtc.h>
36413 #include <linux/sched.h>
36414 +#include <linux/grsecurity.h>
36415 #include "rtc-core.h"
36416
36417 static dev_t rtc_devt;
36418 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36419 if (copy_from_user(&tm, uarg, sizeof(tm)))
36420 return -EFAULT;
36421
36422 + gr_log_timechange();
36423 +
36424 return rtc_set_time(rtc, &tm);
36425
36426 case RTC_PIE_ON:
36427 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36428 index 9e933a8..4f969f7 100644
36429 --- a/drivers/scsi/aacraid/aacraid.h
36430 +++ b/drivers/scsi/aacraid/aacraid.h
36431 @@ -503,7 +503,7 @@ struct adapter_ops
36432 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36433 /* Administrative operations */
36434 int (*adapter_comm)(struct aac_dev * dev, int comm);
36435 -};
36436 +} __no_const;
36437
36438 /*
36439 * Define which interrupt handler needs to be installed
36440 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36441 index 4ad7e36..d004679 100644
36442 --- a/drivers/scsi/bfa/bfa.h
36443 +++ b/drivers/scsi/bfa/bfa.h
36444 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36445 u32 *end);
36446 int cpe_vec_q0;
36447 int rme_vec_q0;
36448 -};
36449 +} __no_const;
36450 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36451
36452 struct bfa_faa_cbfn_s {
36453 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36454 index 27b5609..e08d9c4 100644
36455 --- a/drivers/scsi/bfa/bfa_fcpim.c
36456 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36457 @@ -3731,7 +3731,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36458
36459 bfa_iotag_attach(fcp);
36460
36461 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36462 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36463 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36464 (fcp->num_itns * sizeof(struct bfa_itn_s));
36465 memset(fcp->itn_arr, 0,
36466 @@ -3799,7 +3799,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36467 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36468 {
36469 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36470 - struct bfa_itn_s *itn;
36471 + bfa_itn_s_no_const *itn;
36472
36473 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36474 itn->isr = isr;
36475 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36476 index e693af6..4faba24 100644
36477 --- a/drivers/scsi/bfa/bfa_fcpim.h
36478 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36479 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36480 struct bfa_itn_s {
36481 bfa_isr_func_t isr;
36482 };
36483 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36484
36485 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36486 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36487 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
36488 struct list_head iotag_tio_free_q; /* free IO resources */
36489 struct list_head iotag_unused_q; /* unused IO resources*/
36490 struct bfa_iotag_s *iotag_arr;
36491 - struct bfa_itn_s *itn_arr;
36492 + bfa_itn_s_no_const *itn_arr;
36493 int max_ioim_reqs;
36494 int num_ioim_reqs;
36495 int num_fwtio_reqs;
36496 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36497 index 23a90e7..9cf04ee 100644
36498 --- a/drivers/scsi/bfa/bfa_ioc.h
36499 +++ b/drivers/scsi/bfa/bfa_ioc.h
36500 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36501 bfa_ioc_disable_cbfn_t disable_cbfn;
36502 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36503 bfa_ioc_reset_cbfn_t reset_cbfn;
36504 -};
36505 +} __no_const;
36506
36507 /*
36508 * IOC event notification mechanism.
36509 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36510 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36511 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36512 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36513 -};
36514 +} __no_const;
36515
36516 /*
36517 * Queue element to wait for room in request queue. FIFO order is
36518 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36519 index 593085a..47aa999 100644
36520 --- a/drivers/scsi/hosts.c
36521 +++ b/drivers/scsi/hosts.c
36522 @@ -42,7 +42,7 @@
36523 #include "scsi_logging.h"
36524
36525
36526 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36527 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36528
36529
36530 static void scsi_host_cls_release(struct device *dev)
36531 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36532 * subtract one because we increment first then return, but we need to
36533 * know what the next host number was before increment
36534 */
36535 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36536 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36537 shost->dma_channel = 0xff;
36538
36539 /* These three are default values which can be overridden */
36540 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36541 index 4217e49..9c77e3e 100644
36542 --- a/drivers/scsi/hpsa.c
36543 +++ b/drivers/scsi/hpsa.c
36544 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36545 unsigned long flags;
36546
36547 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36548 - return h->access.command_completed(h, q);
36549 + return h->access->command_completed(h, q);
36550
36551 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36552 a = rq->head[rq->current_entry];
36553 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
36554 while (!list_empty(&h->reqQ)) {
36555 c = list_entry(h->reqQ.next, struct CommandList, list);
36556 /* can't do anything if fifo is full */
36557 - if ((h->access.fifo_full(h))) {
36558 + if ((h->access->fifo_full(h))) {
36559 dev_warn(&h->pdev->dev, "fifo full\n");
36560 break;
36561 }
36562 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
36563
36564 /* Tell the controller execute command */
36565 spin_unlock_irqrestore(&h->lock, flags);
36566 - h->access.submit_command(h, c);
36567 + h->access->submit_command(h, c);
36568 spin_lock_irqsave(&h->lock, flags);
36569 }
36570 spin_unlock_irqrestore(&h->lock, flags);
36571 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
36572
36573 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36574 {
36575 - return h->access.command_completed(h, q);
36576 + return h->access->command_completed(h, q);
36577 }
36578
36579 static inline bool interrupt_pending(struct ctlr_info *h)
36580 {
36581 - return h->access.intr_pending(h);
36582 + return h->access->intr_pending(h);
36583 }
36584
36585 static inline long interrupt_not_for_us(struct ctlr_info *h)
36586 {
36587 - return (h->access.intr_pending(h) == 0) ||
36588 + return (h->access->intr_pending(h) == 0) ||
36589 (h->interrupts_enabled == 0);
36590 }
36591
36592 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36593 if (prod_index < 0)
36594 return -ENODEV;
36595 h->product_name = products[prod_index].product_name;
36596 - h->access = *(products[prod_index].access);
36597 + h->access = products[prod_index].access;
36598
36599 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36600 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36601 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36602
36603 assert_spin_locked(&lockup_detector_lock);
36604 remove_ctlr_from_lockup_detector_list(h);
36605 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36606 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36607 spin_lock_irqsave(&h->lock, flags);
36608 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36609 spin_unlock_irqrestore(&h->lock, flags);
36610 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
36611 }
36612
36613 /* make sure the board interrupts are off */
36614 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36615 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36616
36617 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36618 goto clean2;
36619 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
36620 * fake ones to scoop up any residual completions.
36621 */
36622 spin_lock_irqsave(&h->lock, flags);
36623 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36624 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36625 spin_unlock_irqrestore(&h->lock, flags);
36626 free_irqs(h);
36627 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36628 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
36629 dev_info(&h->pdev->dev, "Board READY.\n");
36630 dev_info(&h->pdev->dev,
36631 "Waiting for stale completions to drain.\n");
36632 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36633 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36634 msleep(10000);
36635 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36636 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36637
36638 rc = controller_reset_failed(h->cfgtable);
36639 if (rc)
36640 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
36641 }
36642
36643 /* Turn the interrupts on so we can service requests */
36644 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36645 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36646
36647 hpsa_hba_inquiry(h);
36648 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36649 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36650 * To write all data in the battery backed cache to disks
36651 */
36652 hpsa_flush_cache(h);
36653 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36654 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36655 hpsa_free_irqs_and_disable_msix(h);
36656 }
36657
36658 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36659 return;
36660 }
36661 /* Change the access methods to the performant access methods */
36662 - h->access = SA5_performant_access;
36663 + h->access = &SA5_performant_access;
36664 h->transMethod = CFGTBL_Trans_Performant;
36665 }
36666
36667 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36668 index 9816479..c5d4e97 100644
36669 --- a/drivers/scsi/hpsa.h
36670 +++ b/drivers/scsi/hpsa.h
36671 @@ -79,7 +79,7 @@ struct ctlr_info {
36672 unsigned int msix_vector;
36673 unsigned int msi_vector;
36674 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36675 - struct access_method access;
36676 + struct access_method *access;
36677
36678 /* queue and queue Info */
36679 struct list_head reqQ;
36680 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36681 index f2df059..a3a9930 100644
36682 --- a/drivers/scsi/ips.h
36683 +++ b/drivers/scsi/ips.h
36684 @@ -1027,7 +1027,7 @@ typedef struct {
36685 int (*intr)(struct ips_ha *);
36686 void (*enableint)(struct ips_ha *);
36687 uint32_t (*statupd)(struct ips_ha *);
36688 -} ips_hw_func_t;
36689 +} __no_const ips_hw_func_t;
36690
36691 typedef struct ips_ha {
36692 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36693 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36694 index c772d8d..35c362c 100644
36695 --- a/drivers/scsi/libfc/fc_exch.c
36696 +++ b/drivers/scsi/libfc/fc_exch.c
36697 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36698 u16 pool_max_index;
36699
36700 struct {
36701 - atomic_t no_free_exch;
36702 - atomic_t no_free_exch_xid;
36703 - atomic_t xid_not_found;
36704 - atomic_t xid_busy;
36705 - atomic_t seq_not_found;
36706 - atomic_t non_bls_resp;
36707 + atomic_unchecked_t no_free_exch;
36708 + atomic_unchecked_t no_free_exch_xid;
36709 + atomic_unchecked_t xid_not_found;
36710 + atomic_unchecked_t xid_busy;
36711 + atomic_unchecked_t seq_not_found;
36712 + atomic_unchecked_t non_bls_resp;
36713 } stats;
36714 };
36715
36716 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36717 /* allocate memory for exchange */
36718 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36719 if (!ep) {
36720 - atomic_inc(&mp->stats.no_free_exch);
36721 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36722 goto out;
36723 }
36724 memset(ep, 0, sizeof(*ep));
36725 @@ -786,7 +786,7 @@ out:
36726 return ep;
36727 err:
36728 spin_unlock_bh(&pool->lock);
36729 - atomic_inc(&mp->stats.no_free_exch_xid);
36730 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36731 mempool_free(ep, mp->ep_pool);
36732 return NULL;
36733 }
36734 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36735 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36736 ep = fc_exch_find(mp, xid);
36737 if (!ep) {
36738 - atomic_inc(&mp->stats.xid_not_found);
36739 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36740 reject = FC_RJT_OX_ID;
36741 goto out;
36742 }
36743 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36744 ep = fc_exch_find(mp, xid);
36745 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36746 if (ep) {
36747 - atomic_inc(&mp->stats.xid_busy);
36748 + atomic_inc_unchecked(&mp->stats.xid_busy);
36749 reject = FC_RJT_RX_ID;
36750 goto rel;
36751 }
36752 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36753 }
36754 xid = ep->xid; /* get our XID */
36755 } else if (!ep) {
36756 - atomic_inc(&mp->stats.xid_not_found);
36757 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36758 reject = FC_RJT_RX_ID; /* XID not found */
36759 goto out;
36760 }
36761 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36762 } else {
36763 sp = &ep->seq;
36764 if (sp->id != fh->fh_seq_id) {
36765 - atomic_inc(&mp->stats.seq_not_found);
36766 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36767 if (f_ctl & FC_FC_END_SEQ) {
36768 /*
36769 * Update sequence_id based on incoming last
36770 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36771
36772 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36773 if (!ep) {
36774 - atomic_inc(&mp->stats.xid_not_found);
36775 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36776 goto out;
36777 }
36778 if (ep->esb_stat & ESB_ST_COMPLETE) {
36779 - atomic_inc(&mp->stats.xid_not_found);
36780 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36781 goto rel;
36782 }
36783 if (ep->rxid == FC_XID_UNKNOWN)
36784 ep->rxid = ntohs(fh->fh_rx_id);
36785 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36786 - atomic_inc(&mp->stats.xid_not_found);
36787 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36788 goto rel;
36789 }
36790 if (ep->did != ntoh24(fh->fh_s_id) &&
36791 ep->did != FC_FID_FLOGI) {
36792 - atomic_inc(&mp->stats.xid_not_found);
36793 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36794 goto rel;
36795 }
36796 sof = fr_sof(fp);
36797 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36798 sp->ssb_stat |= SSB_ST_RESP;
36799 sp->id = fh->fh_seq_id;
36800 } else if (sp->id != fh->fh_seq_id) {
36801 - atomic_inc(&mp->stats.seq_not_found);
36802 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36803 goto rel;
36804 }
36805
36806 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36807 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36808
36809 if (!sp)
36810 - atomic_inc(&mp->stats.xid_not_found);
36811 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36812 else
36813 - atomic_inc(&mp->stats.non_bls_resp);
36814 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36815
36816 fc_frame_free(fp);
36817 }
36818 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36819
36820 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36821 mp = ema->mp;
36822 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36823 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36824 st->fc_no_free_exch_xid +=
36825 - atomic_read(&mp->stats.no_free_exch_xid);
36826 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36827 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36828 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36829 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36830 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36831 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36832 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36833 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36834 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36835 }
36836 }
36837 EXPORT_SYMBOL(fc_exch_update_stats);
36838 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36839 index bdb81cd..d3c7c2c 100644
36840 --- a/drivers/scsi/libsas/sas_ata.c
36841 +++ b/drivers/scsi/libsas/sas_ata.c
36842 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36843 .postreset = ata_std_postreset,
36844 .error_handler = ata_std_error_handler,
36845 .post_internal_cmd = sas_ata_post_internal,
36846 - .qc_defer = ata_std_qc_defer,
36847 + .qc_defer = ata_std_qc_defer,
36848 .qc_prep = ata_noop_qc_prep,
36849 .qc_issue = sas_ata_qc_issue,
36850 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36851 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36852 index 69b5993..1ac9dce 100644
36853 --- a/drivers/scsi/lpfc/lpfc.h
36854 +++ b/drivers/scsi/lpfc/lpfc.h
36855 @@ -424,7 +424,7 @@ struct lpfc_vport {
36856 struct dentry *debug_nodelist;
36857 struct dentry *vport_debugfs_root;
36858 struct lpfc_debugfs_trc *disc_trc;
36859 - atomic_t disc_trc_cnt;
36860 + atomic_unchecked_t disc_trc_cnt;
36861 #endif
36862 uint8_t stat_data_enabled;
36863 uint8_t stat_data_blocked;
36864 @@ -840,8 +840,8 @@ struct lpfc_hba {
36865 struct timer_list fabric_block_timer;
36866 unsigned long bit_flags;
36867 #define FABRIC_COMANDS_BLOCKED 0
36868 - atomic_t num_rsrc_err;
36869 - atomic_t num_cmd_success;
36870 + atomic_unchecked_t num_rsrc_err;
36871 + atomic_unchecked_t num_cmd_success;
36872 unsigned long last_rsrc_error_time;
36873 unsigned long last_ramp_down_time;
36874 unsigned long last_ramp_up_time;
36875 @@ -877,7 +877,7 @@ struct lpfc_hba {
36876
36877 struct dentry *debug_slow_ring_trc;
36878 struct lpfc_debugfs_trc *slow_ring_trc;
36879 - atomic_t slow_ring_trc_cnt;
36880 + atomic_unchecked_t slow_ring_trc_cnt;
36881 /* iDiag debugfs sub-directory */
36882 struct dentry *idiag_root;
36883 struct dentry *idiag_pci_cfg;
36884 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36885 index f63f5ff..de29189 100644
36886 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36887 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36888 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36889
36890 #include <linux/debugfs.h>
36891
36892 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36893 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36894 static unsigned long lpfc_debugfs_start_time = 0L;
36895
36896 /* iDiag */
36897 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36898 lpfc_debugfs_enable = 0;
36899
36900 len = 0;
36901 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36902 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36903 (lpfc_debugfs_max_disc_trc - 1);
36904 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36905 dtp = vport->disc_trc + i;
36906 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36907 lpfc_debugfs_enable = 0;
36908
36909 len = 0;
36910 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36911 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36912 (lpfc_debugfs_max_slow_ring_trc - 1);
36913 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36914 dtp = phba->slow_ring_trc + i;
36915 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36916 !vport || !vport->disc_trc)
36917 return;
36918
36919 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36920 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36921 (lpfc_debugfs_max_disc_trc - 1);
36922 dtp = vport->disc_trc + index;
36923 dtp->fmt = fmt;
36924 dtp->data1 = data1;
36925 dtp->data2 = data2;
36926 dtp->data3 = data3;
36927 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36928 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36929 dtp->jif = jiffies;
36930 #endif
36931 return;
36932 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36933 !phba || !phba->slow_ring_trc)
36934 return;
36935
36936 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36937 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36938 (lpfc_debugfs_max_slow_ring_trc - 1);
36939 dtp = phba->slow_ring_trc + index;
36940 dtp->fmt = fmt;
36941 dtp->data1 = data1;
36942 dtp->data2 = data2;
36943 dtp->data3 = data3;
36944 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36945 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36946 dtp->jif = jiffies;
36947 #endif
36948 return;
36949 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36950 "slow_ring buffer\n");
36951 goto debug_failed;
36952 }
36953 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36954 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36955 memset(phba->slow_ring_trc, 0,
36956 (sizeof(struct lpfc_debugfs_trc) *
36957 lpfc_debugfs_max_slow_ring_trc));
36958 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36959 "buffer\n");
36960 goto debug_failed;
36961 }
36962 - atomic_set(&vport->disc_trc_cnt, 0);
36963 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36964
36965 snprintf(name, sizeof(name), "discovery_trace");
36966 vport->debug_disc_trc =
36967 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36968 index 7dc4218..3436f08 100644
36969 --- a/drivers/scsi/lpfc/lpfc_init.c
36970 +++ b/drivers/scsi/lpfc/lpfc_init.c
36971 @@ -10589,8 +10589,10 @@ lpfc_init(void)
36972 "misc_register returned with status %d", error);
36973
36974 if (lpfc_enable_npiv) {
36975 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36976 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36977 + pax_open_kernel();
36978 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36979 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36980 + pax_close_kernel();
36981 }
36982 lpfc_transport_template =
36983 fc_attach_transport(&lpfc_transport_functions);
36984 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36985 index 7f45ac9..cf62eda 100644
36986 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36987 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36988 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36989 uint32_t evt_posted;
36990
36991 spin_lock_irqsave(&phba->hbalock, flags);
36992 - atomic_inc(&phba->num_rsrc_err);
36993 + atomic_inc_unchecked(&phba->num_rsrc_err);
36994 phba->last_rsrc_error_time = jiffies;
36995
36996 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36997 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36998 unsigned long flags;
36999 struct lpfc_hba *phba = vport->phba;
37000 uint32_t evt_posted;
37001 - atomic_inc(&phba->num_cmd_success);
37002 + atomic_inc_unchecked(&phba->num_cmd_success);
37003
37004 if (vport->cfg_lun_queue_depth <= queue_depth)
37005 return;
37006 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37007 unsigned long num_rsrc_err, num_cmd_success;
37008 int i;
37009
37010 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37011 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37012 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37013 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37014
37015 /*
37016 * The error and success command counters are global per
37017 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37018 }
37019 }
37020 lpfc_destroy_vport_work_array(phba, vports);
37021 - atomic_set(&phba->num_rsrc_err, 0);
37022 - atomic_set(&phba->num_cmd_success, 0);
37023 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37024 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37025 }
37026
37027 /**
37028 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37029 }
37030 }
37031 lpfc_destroy_vport_work_array(phba, vports);
37032 - atomic_set(&phba->num_rsrc_err, 0);
37033 - atomic_set(&phba->num_cmd_success, 0);
37034 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37035 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37036 }
37037
37038 /**
37039 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37040 index af763ea..41904f7 100644
37041 --- a/drivers/scsi/pmcraid.c
37042 +++ b/drivers/scsi/pmcraid.c
37043 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37044 res->scsi_dev = scsi_dev;
37045 scsi_dev->hostdata = res;
37046 res->change_detected = 0;
37047 - atomic_set(&res->read_failures, 0);
37048 - atomic_set(&res->write_failures, 0);
37049 + atomic_set_unchecked(&res->read_failures, 0);
37050 + atomic_set_unchecked(&res->write_failures, 0);
37051 rc = 0;
37052 }
37053 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37054 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37055
37056 /* If this was a SCSI read/write command keep count of errors */
37057 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37058 - atomic_inc(&res->read_failures);
37059 + atomic_inc_unchecked(&res->read_failures);
37060 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37061 - atomic_inc(&res->write_failures);
37062 + atomic_inc_unchecked(&res->write_failures);
37063
37064 if (!RES_IS_GSCSI(res->cfg_entry) &&
37065 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37066 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37067 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37068 * hrrq_id assigned here in queuecommand
37069 */
37070 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37071 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37072 pinstance->num_hrrq;
37073 cmd->cmd_done = pmcraid_io_done;
37074
37075 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37076 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37077 * hrrq_id assigned here in queuecommand
37078 */
37079 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37080 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37081 pinstance->num_hrrq;
37082
37083 if (request_size) {
37084 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37085
37086 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37087 /* add resources only after host is added into system */
37088 - if (!atomic_read(&pinstance->expose_resources))
37089 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37090 return;
37091
37092 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37093 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37094 init_waitqueue_head(&pinstance->reset_wait_q);
37095
37096 atomic_set(&pinstance->outstanding_cmds, 0);
37097 - atomic_set(&pinstance->last_message_id, 0);
37098 - atomic_set(&pinstance->expose_resources, 0);
37099 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37100 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37101
37102 INIT_LIST_HEAD(&pinstance->free_res_q);
37103 INIT_LIST_HEAD(&pinstance->used_res_q);
37104 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37105 /* Schedule worker thread to handle CCN and take care of adding and
37106 * removing devices to OS
37107 */
37108 - atomic_set(&pinstance->expose_resources, 1);
37109 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37110 schedule_work(&pinstance->worker_q);
37111 return rc;
37112
37113 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37114 index e1d150f..6c6df44 100644
37115 --- a/drivers/scsi/pmcraid.h
37116 +++ b/drivers/scsi/pmcraid.h
37117 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37118 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37119
37120 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37121 - atomic_t last_message_id;
37122 + atomic_unchecked_t last_message_id;
37123
37124 /* configuration table */
37125 struct pmcraid_config_table *cfg_table;
37126 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37127 atomic_t outstanding_cmds;
37128
37129 /* should add/delete resources to mid-layer now ?*/
37130 - atomic_t expose_resources;
37131 + atomic_unchecked_t expose_resources;
37132
37133
37134
37135 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37136 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37137 };
37138 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37139 - atomic_t read_failures; /* count of failed READ commands */
37140 - atomic_t write_failures; /* count of failed WRITE commands */
37141 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37142 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37143
37144 /* To indicate add/delete/modify during CCN */
37145 u8 change_detected;
37146 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37147 index 1c28215..86991a1 100644
37148 --- a/drivers/scsi/qla2xxx/qla_attr.c
37149 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37150 @@ -1970,7 +1970,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37151 return 0;
37152 }
37153
37154 -struct fc_function_template qla2xxx_transport_functions = {
37155 +fc_function_template_no_const qla2xxx_transport_functions = {
37156
37157 .show_host_node_name = 1,
37158 .show_host_port_name = 1,
37159 @@ -2017,7 +2017,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37160 .bsg_timeout = qla24xx_bsg_timeout,
37161 };
37162
37163 -struct fc_function_template qla2xxx_transport_vport_functions = {
37164 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37165
37166 .show_host_node_name = 1,
37167 .show_host_port_name = 1,
37168 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37169 index a9725bf..18eeb73 100644
37170 --- a/drivers/scsi/qla2xxx/qla_def.h
37171 +++ b/drivers/scsi/qla2xxx/qla_def.h
37172 @@ -2385,7 +2385,7 @@ struct isp_operations {
37173 int (*start_scsi) (srb_t *);
37174 int (*abort_isp) (struct scsi_qla_host *);
37175 int (*iospace_config)(struct qla_hw_data*);
37176 -};
37177 +} __no_const;
37178
37179 /* MSI-X Support *************************************************************/
37180
37181 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37182 index 6acb397..d86e3e0 100644
37183 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37184 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37185 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37186 struct device_attribute;
37187 extern struct device_attribute *qla2x00_host_attrs[];
37188 struct fc_function_template;
37189 -extern struct fc_function_template qla2xxx_transport_functions;
37190 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37191 +extern fc_function_template_no_const qla2xxx_transport_functions;
37192 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37193 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37194 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37195 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37196 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37197 index 329d553..f20d31d 100644
37198 --- a/drivers/scsi/qla4xxx/ql4_def.h
37199 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37200 @@ -273,7 +273,7 @@ struct ddb_entry {
37201 * (4000 only) */
37202 atomic_t relogin_timer; /* Max Time to wait for
37203 * relogin to complete */
37204 - atomic_t relogin_retry_count; /* Num of times relogin has been
37205 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37206 * retried */
37207 uint32_t default_time2wait; /* Default Min time between
37208 * relogins (+aens) */
37209 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37210 index fbc546e..c7d1b48 100644
37211 --- a/drivers/scsi/qla4xxx/ql4_os.c
37212 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37213 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37214 */
37215 if (!iscsi_is_session_online(cls_sess)) {
37216 /* Reset retry relogin timer */
37217 - atomic_inc(&ddb_entry->relogin_retry_count);
37218 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37219 DEBUG2(ql4_printk(KERN_INFO, ha,
37220 "%s: index[%d] relogin timed out-retrying"
37221 " relogin (%d), retry (%d)\n", __func__,
37222 ddb_entry->fw_ddb_index,
37223 - atomic_read(&ddb_entry->relogin_retry_count),
37224 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37225 ddb_entry->default_time2wait + 4));
37226 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37227 atomic_set(&ddb_entry->retry_relogin_timer,
37228 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37229
37230 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37231 atomic_set(&ddb_entry->relogin_timer, 0);
37232 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37233 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37234 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37235 ddb_entry->default_relogin_timeout =
37236 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37237 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37238 index 2c0d0ec..4e8681a 100644
37239 --- a/drivers/scsi/scsi.c
37240 +++ b/drivers/scsi/scsi.c
37241 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37242 unsigned long timeout;
37243 int rtn = 0;
37244
37245 - atomic_inc(&cmd->device->iorequest_cnt);
37246 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37247
37248 /* check if the device is still usable */
37249 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37250 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37251 index 9032e91..7a805d0 100644
37252 --- a/drivers/scsi/scsi_lib.c
37253 +++ b/drivers/scsi/scsi_lib.c
37254 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37255 shost = sdev->host;
37256 scsi_init_cmd_errh(cmd);
37257 cmd->result = DID_NO_CONNECT << 16;
37258 - atomic_inc(&cmd->device->iorequest_cnt);
37259 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37260
37261 /*
37262 * SCSI request completion path will do scsi_device_unbusy(),
37263 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
37264
37265 INIT_LIST_HEAD(&cmd->eh_entry);
37266
37267 - atomic_inc(&cmd->device->iodone_cnt);
37268 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37269 if (cmd->result)
37270 - atomic_inc(&cmd->device->ioerr_cnt);
37271 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37272
37273 disposition = scsi_decide_disposition(cmd);
37274 if (disposition != SUCCESS &&
37275 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37276 index ce5224c..8c6d071 100644
37277 --- a/drivers/scsi/scsi_sysfs.c
37278 +++ b/drivers/scsi/scsi_sysfs.c
37279 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37280 char *buf) \
37281 { \
37282 struct scsi_device *sdev = to_scsi_device(dev); \
37283 - unsigned long long count = atomic_read(&sdev->field); \
37284 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37285 return snprintf(buf, 20, "0x%llx\n", count); \
37286 } \
37287 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37288 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37289 index 84a1fdf..693b0d6 100644
37290 --- a/drivers/scsi/scsi_tgt_lib.c
37291 +++ b/drivers/scsi/scsi_tgt_lib.c
37292 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37293 int err;
37294
37295 dprintk("%lx %u\n", uaddr, len);
37296 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37297 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37298 if (err) {
37299 /*
37300 * TODO: need to fixup sg_tablesize, max_segment_size,
37301 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37302 index e894ca7..de9d7660 100644
37303 --- a/drivers/scsi/scsi_transport_fc.c
37304 +++ b/drivers/scsi/scsi_transport_fc.c
37305 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37306 * Netlink Infrastructure
37307 */
37308
37309 -static atomic_t fc_event_seq;
37310 +static atomic_unchecked_t fc_event_seq;
37311
37312 /**
37313 * fc_get_event_number - Obtain the next sequential FC event number
37314 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37315 u32
37316 fc_get_event_number(void)
37317 {
37318 - return atomic_add_return(1, &fc_event_seq);
37319 + return atomic_add_return_unchecked(1, &fc_event_seq);
37320 }
37321 EXPORT_SYMBOL(fc_get_event_number);
37322
37323 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37324 {
37325 int error;
37326
37327 - atomic_set(&fc_event_seq, 0);
37328 + atomic_set_unchecked(&fc_event_seq, 0);
37329
37330 error = transport_class_register(&fc_host_class);
37331 if (error)
37332 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37333 char *cp;
37334
37335 *val = simple_strtoul(buf, &cp, 0);
37336 - if ((*cp && (*cp != '\n')) || (*val < 0))
37337 + if (*cp && (*cp != '\n'))
37338 return -EINVAL;
37339 /*
37340 * Check for overflow; dev_loss_tmo is u32
37341 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37342 index 31969f2..2b348f0 100644
37343 --- a/drivers/scsi/scsi_transport_iscsi.c
37344 +++ b/drivers/scsi/scsi_transport_iscsi.c
37345 @@ -79,7 +79,7 @@ struct iscsi_internal {
37346 struct transport_container session_cont;
37347 };
37348
37349 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37350 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37351 static struct workqueue_struct *iscsi_eh_timer_workq;
37352
37353 static DEFINE_IDA(iscsi_sess_ida);
37354 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37355 int err;
37356
37357 ihost = shost->shost_data;
37358 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37359 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37360
37361 if (target_id == ISCSI_MAX_TARGET) {
37362 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37363 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37364 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37365 ISCSI_TRANSPORT_VERSION);
37366
37367 - atomic_set(&iscsi_session_nr, 0);
37368 + atomic_set_unchecked(&iscsi_session_nr, 0);
37369
37370 err = class_register(&iscsi_transport_class);
37371 if (err)
37372 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37373 index 21a045e..ec89e03 100644
37374 --- a/drivers/scsi/scsi_transport_srp.c
37375 +++ b/drivers/scsi/scsi_transport_srp.c
37376 @@ -33,7 +33,7 @@
37377 #include "scsi_transport_srp_internal.h"
37378
37379 struct srp_host_attrs {
37380 - atomic_t next_port_id;
37381 + atomic_unchecked_t next_port_id;
37382 };
37383 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37384
37385 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37386 struct Scsi_Host *shost = dev_to_shost(dev);
37387 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37388
37389 - atomic_set(&srp_host->next_port_id, 0);
37390 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37391 return 0;
37392 }
37393
37394 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37395 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37396 rport->roles = ids->roles;
37397
37398 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37399 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37400 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37401
37402 transport_setup_device(&rport->dev);
37403 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37404 index 352bc77..c049b14 100644
37405 --- a/drivers/scsi/sd.c
37406 +++ b/drivers/scsi/sd.c
37407 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
37408 sdkp->disk = gd;
37409 sdkp->index = index;
37410 atomic_set(&sdkp->openers, 0);
37411 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37412 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37413
37414 if (!sdp->request_queue->rq_timeout) {
37415 if (sdp->type != TYPE_MOD)
37416 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37417 index be2c9a6..275525c 100644
37418 --- a/drivers/scsi/sg.c
37419 +++ b/drivers/scsi/sg.c
37420 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37421 sdp->disk->disk_name,
37422 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37423 NULL,
37424 - (char *)arg);
37425 + (char __user *)arg);
37426 case BLKTRACESTART:
37427 return blk_trace_startstop(sdp->device->request_queue, 1);
37428 case BLKTRACESTOP:
37429 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37430 index 84c2861..ece0a31 100644
37431 --- a/drivers/spi/spi.c
37432 +++ b/drivers/spi/spi.c
37433 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37434 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37435
37436 /* portable code must never pass more than 32 bytes */
37437 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37438 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37439
37440 static u8 *buf;
37441
37442 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37443 index 34afc16..ffe44dd 100644
37444 --- a/drivers/staging/octeon/ethernet-rx.c
37445 +++ b/drivers/staging/octeon/ethernet-rx.c
37446 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37447 /* Increment RX stats for virtual ports */
37448 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37449 #ifdef CONFIG_64BIT
37450 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37451 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37452 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37453 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37454 #else
37455 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37456 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37457 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37458 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37459 #endif
37460 }
37461 netif_receive_skb(skb);
37462 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37463 dev->name);
37464 */
37465 #ifdef CONFIG_64BIT
37466 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37467 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37468 #else
37469 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37470 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37471 #endif
37472 dev_kfree_skb_irq(skb);
37473 }
37474 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37475 index 683bedc..86dba9a 100644
37476 --- a/drivers/staging/octeon/ethernet.c
37477 +++ b/drivers/staging/octeon/ethernet.c
37478 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37479 * since the RX tasklet also increments it.
37480 */
37481 #ifdef CONFIG_64BIT
37482 - atomic64_add(rx_status.dropped_packets,
37483 - (atomic64_t *)&priv->stats.rx_dropped);
37484 + atomic64_add_unchecked(rx_status.dropped_packets,
37485 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37486 #else
37487 - atomic_add(rx_status.dropped_packets,
37488 - (atomic_t *)&priv->stats.rx_dropped);
37489 + atomic_add_unchecked(rx_status.dropped_packets,
37490 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37491 #endif
37492 }
37493
37494 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
37495 index a2b7e03..aaf3630 100644
37496 --- a/drivers/staging/ramster/tmem.c
37497 +++ b/drivers/staging/ramster/tmem.c
37498 @@ -50,25 +50,25 @@
37499 * A tmem host implementation must use this function to register callbacks
37500 * for memory allocation.
37501 */
37502 -static struct tmem_hostops tmem_hostops;
37503 +static struct tmem_hostops *tmem_hostops;
37504
37505 static void tmem_objnode_tree_init(void);
37506
37507 void tmem_register_hostops(struct tmem_hostops *m)
37508 {
37509 tmem_objnode_tree_init();
37510 - tmem_hostops = *m;
37511 + tmem_hostops = m;
37512 }
37513
37514 /*
37515 * A tmem host implementation must use this function to register
37516 * callbacks for a page-accessible memory (PAM) implementation.
37517 */
37518 -static struct tmem_pamops tmem_pamops;
37519 +static struct tmem_pamops *tmem_pamops;
37520
37521 void tmem_register_pamops(struct tmem_pamops *m)
37522 {
37523 - tmem_pamops = *m;
37524 + tmem_pamops = m;
37525 }
37526
37527 /*
37528 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
37529 obj->pampd_count = 0;
37530 #ifdef CONFIG_RAMSTER
37531 if (tmem_pamops.new_obj != NULL)
37532 - (*tmem_pamops.new_obj)(obj);
37533 + (tmem_pamops->new_obj)(obj);
37534 #endif
37535 SET_SENTINEL(obj, OBJ);
37536
37537 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
37538 rbnode = rb_next(rbnode);
37539 tmem_pampd_destroy_all_in_obj(obj, true);
37540 tmem_obj_free(obj, hb);
37541 - (*tmem_hostops.obj_free)(obj, pool);
37542 + (tmem_hostops->obj_free)(obj, pool);
37543 }
37544 spin_unlock(&hb->lock);
37545 }
37546 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
37547 ASSERT_SENTINEL(obj, OBJ);
37548 BUG_ON(obj->pool == NULL);
37549 ASSERT_SENTINEL(obj->pool, POOL);
37550 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
37551 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
37552 if (unlikely(objnode == NULL))
37553 goto out;
37554 objnode->obj = obj;
37555 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
37556 ASSERT_SENTINEL(pool, POOL);
37557 objnode->obj->objnode_count--;
37558 objnode->obj = NULL;
37559 - (*tmem_hostops.objnode_free)(objnode, pool);
37560 + (tmem_hostops->objnode_free)(objnode, pool);
37561 }
37562
37563 /*
37564 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
37565 void *old_pampd = *(void **)slot;
37566 *(void **)slot = new_pampd;
37567 if (!no_free)
37568 - (*tmem_pamops.free)(old_pampd, obj->pool,
37569 + (tmem_pamops->free)(old_pampd, obj->pool,
37570 NULL, 0, false);
37571 ret = new_pampd;
37572 }
37573 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
37574 if (objnode->slots[i]) {
37575 if (ht == 1) {
37576 obj->pampd_count--;
37577 - (*tmem_pamops.free)(objnode->slots[i],
37578 + (tmem_pamops->free)(objnode->slots[i],
37579 obj->pool, NULL, 0, true);
37580 objnode->slots[i] = NULL;
37581 continue;
37582 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
37583 return;
37584 if (obj->objnode_tree_height == 0) {
37585 obj->pampd_count--;
37586 - (*tmem_pamops.free)(obj->objnode_tree_root,
37587 + (tmem_pamops->free)(obj->objnode_tree_root,
37588 obj->pool, NULL, 0, true);
37589 } else {
37590 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
37591 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
37592 obj->objnode_tree_root = NULL;
37593 #ifdef CONFIG_RAMSTER
37594 if (tmem_pamops.free_obj != NULL)
37595 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
37596 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
37597 #endif
37598 }
37599
37600 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37601 /* if found, is a dup put, flush the old one */
37602 pampd_del = tmem_pampd_delete_from_obj(obj, index);
37603 BUG_ON(pampd_del != pampd);
37604 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
37605 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
37606 if (obj->pampd_count == 0) {
37607 objnew = obj;
37608 objfound = NULL;
37609 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37610 pampd = NULL;
37611 }
37612 } else {
37613 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
37614 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
37615 if (unlikely(obj == NULL)) {
37616 ret = -ENOMEM;
37617 goto out;
37618 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37619 if (unlikely(ret == -ENOMEM))
37620 /* may have partially built objnode tree ("stump") */
37621 goto delete_and_free;
37622 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
37623 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
37624 goto out;
37625
37626 delete_and_free:
37627 (void)tmem_pampd_delete_from_obj(obj, index);
37628 if (pampd)
37629 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
37630 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
37631 if (objnew) {
37632 tmem_obj_free(objnew, hb);
37633 - (*tmem_hostops.obj_free)(objnew, pool);
37634 + (tmem_hostops->obj_free)(objnew, pool);
37635 }
37636 out:
37637 spin_unlock(&hb->lock);
37638 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
37639 if (pampd != NULL) {
37640 BUG_ON(obj == NULL);
37641 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
37642 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
37643 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
37644 } else if (delete) {
37645 BUG_ON(obj == NULL);
37646 (void)tmem_pampd_delete_from_obj(obj, index);
37647 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
37648 int ret = 0;
37649
37650 if (!is_ephemeral(pool))
37651 - new_pampd = (*tmem_pamops.repatriate_preload)(
37652 + new_pampd = (tmem_pamops->repatriate_preload)(
37653 old_pampd, pool, oidp, index, &intransit);
37654 if (intransit)
37655 ret = -EAGAIN;
37656 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
37657 /* must release the hb->lock else repatriate can't sleep */
37658 spin_unlock(&hb->lock);
37659 if (!intransit)
37660 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
37661 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
37662 oidp, index, free, data);
37663 if (ret == -EAGAIN) {
37664 /* rare I think, but should cond_resched()??? */
37665 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
37666 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
37667 /* if we bug here, pamops wasn't properly set up for ramster */
37668 BUG_ON(tmem_pamops.replace_in_obj == NULL);
37669 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
37670 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
37671 out:
37672 spin_unlock(&hb->lock);
37673 return ret;
37674 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
37675 if (free) {
37676 if (obj->pampd_count == 0) {
37677 tmem_obj_free(obj, hb);
37678 - (*tmem_hostops.obj_free)(obj, pool);
37679 + (tmem_hostops->obj_free)(obj, pool);
37680 obj = NULL;
37681 }
37682 }
37683 if (free)
37684 - ret = (*tmem_pamops.get_data_and_free)(
37685 + ret = (tmem_pamops->get_data_and_free)(
37686 data, sizep, raw, pampd, pool, oidp, index);
37687 else
37688 - ret = (*tmem_pamops.get_data)(
37689 + ret = (tmem_pamops->get_data)(
37690 data, sizep, raw, pampd, pool, oidp, index);
37691 if (ret < 0)
37692 goto out;
37693 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
37694 pampd = tmem_pampd_delete_from_obj(obj, index);
37695 if (pampd == NULL)
37696 goto out;
37697 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
37698 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
37699 if (obj->pampd_count == 0) {
37700 tmem_obj_free(obj, hb);
37701 - (*tmem_hostops.obj_free)(obj, pool);
37702 + (tmem_hostops->obj_free)(obj, pool);
37703 }
37704 ret = 0;
37705
37706 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
37707 goto out;
37708 tmem_pampd_destroy_all_in_obj(obj, false);
37709 tmem_obj_free(obj, hb);
37710 - (*tmem_hostops.obj_free)(obj, pool);
37711 + (tmem_hostops->obj_free)(obj, pool);
37712 ret = 0;
37713
37714 out:
37715 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37716 index dc23395..cf7e9b1 100644
37717 --- a/drivers/staging/rtl8712/rtl871x_io.h
37718 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37719 @@ -108,7 +108,7 @@ struct _io_ops {
37720 u8 *pmem);
37721 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37722 u8 *pmem);
37723 -};
37724 +} __no_const;
37725
37726 struct io_req {
37727 struct list_head list;
37728 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37729 index 180c963..1f18377 100644
37730 --- a/drivers/staging/sbe-2t3e3/netdev.c
37731 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37732 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37733 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37734
37735 if (rlen)
37736 - if (copy_to_user(data, &resp, rlen))
37737 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37738 return -EFAULT;
37739
37740 return 0;
37741 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37742 index 5d89c0f..9261317 100644
37743 --- a/drivers/staging/usbip/usbip_common.h
37744 +++ b/drivers/staging/usbip/usbip_common.h
37745 @@ -289,7 +289,7 @@ struct usbip_device {
37746 void (*shutdown)(struct usbip_device *);
37747 void (*reset)(struct usbip_device *);
37748 void (*unusable)(struct usbip_device *);
37749 - } eh_ops;
37750 + } __no_const eh_ops;
37751 };
37752
37753 #define kthread_get_run(threadfn, data, namefmt, ...) \
37754 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37755 index c66b8b3..a4a035b 100644
37756 --- a/drivers/staging/usbip/vhci.h
37757 +++ b/drivers/staging/usbip/vhci.h
37758 @@ -83,7 +83,7 @@ struct vhci_hcd {
37759 unsigned resuming:1;
37760 unsigned long re_timeout;
37761
37762 - atomic_t seqnum;
37763 + atomic_unchecked_t seqnum;
37764
37765 /*
37766 * NOTE:
37767 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37768 index 620d1be..1cd6711 100644
37769 --- a/drivers/staging/usbip/vhci_hcd.c
37770 +++ b/drivers/staging/usbip/vhci_hcd.c
37771 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37772 return;
37773 }
37774
37775 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37776 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37777 if (priv->seqnum == 0xffff)
37778 dev_info(&urb->dev->dev, "seqnum max\n");
37779
37780 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37781 return -ENOMEM;
37782 }
37783
37784 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37785 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37786 if (unlink->seqnum == 0xffff)
37787 pr_info("seqnum max\n");
37788
37789 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
37790 vdev->rhport = rhport;
37791 }
37792
37793 - atomic_set(&vhci->seqnum, 0);
37794 + atomic_set_unchecked(&vhci->seqnum, 0);
37795 spin_lock_init(&vhci->lock);
37796
37797 hcd->power_budget = 0; /* no limit */
37798 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37799 index f0eaf04..5a82e06 100644
37800 --- a/drivers/staging/usbip/vhci_rx.c
37801 +++ b/drivers/staging/usbip/vhci_rx.c
37802 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37803 if (!urb) {
37804 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37805 pr_info("max seqnum %d\n",
37806 - atomic_read(&the_controller->seqnum));
37807 + atomic_read_unchecked(&the_controller->seqnum));
37808 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37809 return;
37810 }
37811 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37812 index 67b1b88..6392fe9 100644
37813 --- a/drivers/staging/vt6655/hostap.c
37814 +++ b/drivers/staging/vt6655/hostap.c
37815 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37816 *
37817 */
37818
37819 +static net_device_ops_no_const apdev_netdev_ops;
37820 +
37821 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37822 {
37823 PSDevice apdev_priv;
37824 struct net_device *dev = pDevice->dev;
37825 int ret;
37826 - const struct net_device_ops apdev_netdev_ops = {
37827 - .ndo_start_xmit = pDevice->tx_80211,
37828 - };
37829
37830 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37831
37832 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37833 *apdev_priv = *pDevice;
37834 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37835
37836 + /* only half broken now */
37837 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37838 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37839
37840 pDevice->apdev->type = ARPHRD_IEEE80211;
37841 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37842 index 0a73d40..6fda560 100644
37843 --- a/drivers/staging/vt6656/hostap.c
37844 +++ b/drivers/staging/vt6656/hostap.c
37845 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37846 *
37847 */
37848
37849 +static net_device_ops_no_const apdev_netdev_ops;
37850 +
37851 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37852 {
37853 PSDevice apdev_priv;
37854 struct net_device *dev = pDevice->dev;
37855 int ret;
37856 - const struct net_device_ops apdev_netdev_ops = {
37857 - .ndo_start_xmit = pDevice->tx_80211,
37858 - };
37859
37860 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37861
37862 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37863 *apdev_priv = *pDevice;
37864 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37865
37866 + /* only half broken now */
37867 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37868 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37869
37870 pDevice->apdev->type = ARPHRD_IEEE80211;
37871 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37872 index f180c3d..4b9ecfc 100644
37873 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37874 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37875 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37876
37877 struct usbctlx_completor {
37878 int (*complete) (struct usbctlx_completor *);
37879 -};
37880 +} __no_const;
37881
37882 static int
37883 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37884 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37885 index 56c8e60..1920c63 100644
37886 --- a/drivers/staging/zcache/tmem.c
37887 +++ b/drivers/staging/zcache/tmem.c
37888 @@ -39,7 +39,7 @@
37889 * A tmem host implementation must use this function to register callbacks
37890 * for memory allocation.
37891 */
37892 -static struct tmem_hostops tmem_hostops;
37893 +static tmem_hostops_no_const tmem_hostops;
37894
37895 static void tmem_objnode_tree_init(void);
37896
37897 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37898 * A tmem host implementation must use this function to register
37899 * callbacks for a page-accessible memory (PAM) implementation
37900 */
37901 -static struct tmem_pamops tmem_pamops;
37902 +static tmem_pamops_no_const tmem_pamops;
37903
37904 void tmem_register_pamops(struct tmem_pamops *m)
37905 {
37906 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37907 index 0d4aa82..f7832d4 100644
37908 --- a/drivers/staging/zcache/tmem.h
37909 +++ b/drivers/staging/zcache/tmem.h
37910 @@ -180,6 +180,7 @@ struct tmem_pamops {
37911 void (*new_obj)(struct tmem_obj *);
37912 int (*replace_in_obj)(void *, struct tmem_obj *);
37913 };
37914 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37915 extern void tmem_register_pamops(struct tmem_pamops *m);
37916
37917 /* memory allocation methods provided by the host implementation */
37918 @@ -189,6 +190,7 @@ struct tmem_hostops {
37919 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37920 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37921 };
37922 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37923 extern void tmem_register_hostops(struct tmem_hostops *m);
37924
37925 /* core tmem accessor functions */
37926 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37927 index dcecbfb..4fad7d5 100644
37928 --- a/drivers/target/target_core_transport.c
37929 +++ b/drivers/target/target_core_transport.c
37930 @@ -1087,7 +1087,7 @@ struct se_device *transport_add_device_to_core_hba(
37931 spin_lock_init(&dev->se_port_lock);
37932 spin_lock_init(&dev->se_tmr_lock);
37933 spin_lock_init(&dev->qf_cmd_lock);
37934 - atomic_set(&dev->dev_ordered_id, 0);
37935 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37936
37937 se_dev_set_default_attribs(dev, dev_limits);
37938
37939 @@ -1277,7 +1277,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37940 * Used to determine when ORDERED commands should go from
37941 * Dormant to Active status.
37942 */
37943 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37944 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37945 smp_mb__after_atomic_inc();
37946 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37947 cmd->se_ordered_id, cmd->sam_task_attr,
37948 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37949 index 0a6a0bc..5501b06 100644
37950 --- a/drivers/tty/cyclades.c
37951 +++ b/drivers/tty/cyclades.c
37952 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37953 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37954 info->port.count);
37955 #endif
37956 - info->port.count++;
37957 + atomic_inc(&info->port.count);
37958 #ifdef CY_DEBUG_COUNT
37959 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37960 - current->pid, info->port.count);
37961 + current->pid, atomic_read(&info->port.count));
37962 #endif
37963
37964 /*
37965 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37966 for (j = 0; j < cy_card[i].nports; j++) {
37967 info = &cy_card[i].ports[j];
37968
37969 - if (info->port.count) {
37970 + if (atomic_read(&info->port.count)) {
37971 /* XXX is the ldisc num worth this? */
37972 struct tty_struct *tty;
37973 struct tty_ldisc *ld;
37974 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37975 index 13ee53b..418d164 100644
37976 --- a/drivers/tty/hvc/hvc_console.c
37977 +++ b/drivers/tty/hvc/hvc_console.c
37978 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37979
37980 spin_lock_irqsave(&hp->port.lock, flags);
37981 /* Check and then increment for fast path open. */
37982 - if (hp->port.count++ > 0) {
37983 + if (atomic_inc_return(&hp->port.count) > 1) {
37984 spin_unlock_irqrestore(&hp->port.lock, flags);
37985 hvc_kick();
37986 return 0;
37987 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37988
37989 spin_lock_irqsave(&hp->port.lock, flags);
37990
37991 - if (--hp->port.count == 0) {
37992 + if (atomic_dec_return(&hp->port.count) == 0) {
37993 spin_unlock_irqrestore(&hp->port.lock, flags);
37994 /* We are done with the tty pointer now. */
37995 tty_port_tty_set(&hp->port, NULL);
37996 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37997 */
37998 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37999 } else {
38000 - if (hp->port.count < 0)
38001 + if (atomic_read(&hp->port.count) < 0)
38002 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38003 - hp->vtermno, hp->port.count);
38004 + hp->vtermno, atomic_read(&hp->port.count));
38005 spin_unlock_irqrestore(&hp->port.lock, flags);
38006 }
38007 }
38008 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
38009 * open->hangup case this can be called after the final close so prevent
38010 * that from happening for now.
38011 */
38012 - if (hp->port.count <= 0) {
38013 + if (atomic_read(&hp->port.count) <= 0) {
38014 spin_unlock_irqrestore(&hp->port.lock, flags);
38015 return;
38016 }
38017
38018 - hp->port.count = 0;
38019 + atomic_set(&hp->port.count, 0);
38020 spin_unlock_irqrestore(&hp->port.lock, flags);
38021 tty_port_tty_set(&hp->port, NULL);
38022
38023 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38024 return -EPIPE;
38025
38026 /* FIXME what's this (unprotected) check for? */
38027 - if (hp->port.count <= 0)
38028 + if (atomic_read(&hp->port.count) <= 0)
38029 return -EIO;
38030
38031 spin_lock_irqsave(&hp->lock, flags);
38032 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38033 index cab5c7a..4cc66ea 100644
38034 --- a/drivers/tty/hvc/hvcs.c
38035 +++ b/drivers/tty/hvc/hvcs.c
38036 @@ -83,6 +83,7 @@
38037 #include <asm/hvcserver.h>
38038 #include <asm/uaccess.h>
38039 #include <asm/vio.h>
38040 +#include <asm/local.h>
38041
38042 /*
38043 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38044 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38045
38046 spin_lock_irqsave(&hvcsd->lock, flags);
38047
38048 - if (hvcsd->port.count > 0) {
38049 + if (atomic_read(&hvcsd->port.count) > 0) {
38050 spin_unlock_irqrestore(&hvcsd->lock, flags);
38051 printk(KERN_INFO "HVCS: vterm state unchanged. "
38052 "The hvcs device node is still in use.\n");
38053 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
38054 }
38055 }
38056
38057 - hvcsd->port.count = 0;
38058 + atomic_set(&hvcsd->port.count, 0);
38059 hvcsd->port.tty = tty;
38060 tty->driver_data = hvcsd;
38061
38062 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38063 unsigned long flags;
38064
38065 spin_lock_irqsave(&hvcsd->lock, flags);
38066 - hvcsd->port.count++;
38067 + atomic_inc(&hvcsd->port.count);
38068 hvcsd->todo_mask |= HVCS_SCHED_READ;
38069 spin_unlock_irqrestore(&hvcsd->lock, flags);
38070
38071 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38072 hvcsd = tty->driver_data;
38073
38074 spin_lock_irqsave(&hvcsd->lock, flags);
38075 - if (--hvcsd->port.count == 0) {
38076 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38077
38078 vio_disable_interrupts(hvcsd->vdev);
38079
38080 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38081
38082 free_irq(irq, hvcsd);
38083 return;
38084 - } else if (hvcsd->port.count < 0) {
38085 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38086 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38087 " is missmanaged.\n",
38088 - hvcsd->vdev->unit_address, hvcsd->port.count);
38089 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38090 }
38091
38092 spin_unlock_irqrestore(&hvcsd->lock, flags);
38093 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38094
38095 spin_lock_irqsave(&hvcsd->lock, flags);
38096 /* Preserve this so that we know how many kref refs to put */
38097 - temp_open_count = hvcsd->port.count;
38098 + temp_open_count = atomic_read(&hvcsd->port.count);
38099
38100 /*
38101 * Don't kref put inside the spinlock because the destruction
38102 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38103 tty->driver_data = NULL;
38104 hvcsd->port.tty = NULL;
38105
38106 - hvcsd->port.count = 0;
38107 + atomic_set(&hvcsd->port.count, 0);
38108
38109 /* This will drop any buffered data on the floor which is OK in a hangup
38110 * scenario. */
38111 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
38112 * the middle of a write operation? This is a crummy place to do this
38113 * but we want to keep it all in the spinlock.
38114 */
38115 - if (hvcsd->port.count <= 0) {
38116 + if (atomic_read(&hvcsd->port.count) <= 0) {
38117 spin_unlock_irqrestore(&hvcsd->lock, flags);
38118 return -ENODEV;
38119 }
38120 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38121 {
38122 struct hvcs_struct *hvcsd = tty->driver_data;
38123
38124 - if (!hvcsd || hvcsd->port.count <= 0)
38125 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38126 return 0;
38127
38128 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38129 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38130 index 160f0ad..588b853 100644
38131 --- a/drivers/tty/ipwireless/tty.c
38132 +++ b/drivers/tty/ipwireless/tty.c
38133 @@ -29,6 +29,7 @@
38134 #include <linux/tty_driver.h>
38135 #include <linux/tty_flip.h>
38136 #include <linux/uaccess.h>
38137 +#include <asm/local.h>
38138
38139 #include "tty.h"
38140 #include "network.h"
38141 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38142 mutex_unlock(&tty->ipw_tty_mutex);
38143 return -ENODEV;
38144 }
38145 - if (tty->port.count == 0)
38146 + if (atomic_read(&tty->port.count) == 0)
38147 tty->tx_bytes_queued = 0;
38148
38149 - tty->port.count++;
38150 + atomic_inc(&tty->port.count);
38151
38152 tty->port.tty = linux_tty;
38153 linux_tty->driver_data = tty;
38154 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38155
38156 static void do_ipw_close(struct ipw_tty *tty)
38157 {
38158 - tty->port.count--;
38159 -
38160 - if (tty->port.count == 0) {
38161 + if (atomic_dec_return(&tty->port.count) == 0) {
38162 struct tty_struct *linux_tty = tty->port.tty;
38163
38164 if (linux_tty != NULL) {
38165 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38166 return;
38167
38168 mutex_lock(&tty->ipw_tty_mutex);
38169 - if (tty->port.count == 0) {
38170 + if (atomic_read(&tty->port.count) == 0) {
38171 mutex_unlock(&tty->ipw_tty_mutex);
38172 return;
38173 }
38174 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38175 return;
38176 }
38177
38178 - if (!tty->port.count) {
38179 + if (!atomic_read(&tty->port.count)) {
38180 mutex_unlock(&tty->ipw_tty_mutex);
38181 return;
38182 }
38183 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38184 return -ENODEV;
38185
38186 mutex_lock(&tty->ipw_tty_mutex);
38187 - if (!tty->port.count) {
38188 + if (!atomic_read(&tty->port.count)) {
38189 mutex_unlock(&tty->ipw_tty_mutex);
38190 return -EINVAL;
38191 }
38192 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38193 if (!tty)
38194 return -ENODEV;
38195
38196 - if (!tty->port.count)
38197 + if (!atomic_read(&tty->port.count))
38198 return -EINVAL;
38199
38200 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38201 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38202 if (!tty)
38203 return 0;
38204
38205 - if (!tty->port.count)
38206 + if (!atomic_read(&tty->port.count))
38207 return 0;
38208
38209 return tty->tx_bytes_queued;
38210 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38211 if (!tty)
38212 return -ENODEV;
38213
38214 - if (!tty->port.count)
38215 + if (!atomic_read(&tty->port.count))
38216 return -EINVAL;
38217
38218 return get_control_lines(tty);
38219 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38220 if (!tty)
38221 return -ENODEV;
38222
38223 - if (!tty->port.count)
38224 + if (!atomic_read(&tty->port.count))
38225 return -EINVAL;
38226
38227 return set_control_lines(tty, set, clear);
38228 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38229 if (!tty)
38230 return -ENODEV;
38231
38232 - if (!tty->port.count)
38233 + if (!atomic_read(&tty->port.count))
38234 return -EINVAL;
38235
38236 /* FIXME: Exactly how is the tty object locked here .. */
38237 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38238 * are gone */
38239 mutex_lock(&ttyj->ipw_tty_mutex);
38240 }
38241 - while (ttyj->port.count)
38242 + while (atomic_read(&ttyj->port.count))
38243 do_ipw_close(ttyj);
38244 ipwireless_disassociate_network_ttys(network,
38245 ttyj->channel_idx);
38246 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38247 index 56e616b..9d9f10a 100644
38248 --- a/drivers/tty/moxa.c
38249 +++ b/drivers/tty/moxa.c
38250 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38251 }
38252
38253 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38254 - ch->port.count++;
38255 + atomic_inc(&ch->port.count);
38256 tty->driver_data = ch;
38257 tty_port_tty_set(&ch->port, tty);
38258 mutex_lock(&ch->port.mutex);
38259 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38260 index 1e8e8ce..a9efc93 100644
38261 --- a/drivers/tty/n_gsm.c
38262 +++ b/drivers/tty/n_gsm.c
38263 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38264 kref_init(&dlci->ref);
38265 mutex_init(&dlci->mutex);
38266 dlci->fifo = &dlci->_fifo;
38267 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38268 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38269 kfree(dlci);
38270 return NULL;
38271 }
38272 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38273 struct gsm_dlci *dlci = tty->driver_data;
38274 struct tty_port *port = &dlci->port;
38275
38276 - port->count++;
38277 + atomic_inc(&port->count);
38278 dlci_get(dlci);
38279 dlci_get(dlci->gsm->dlci[0]);
38280 mux_get(dlci->gsm);
38281 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38282 index 8c0b7b4..e88f052 100644
38283 --- a/drivers/tty/n_tty.c
38284 +++ b/drivers/tty/n_tty.c
38285 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38286 {
38287 *ops = tty_ldisc_N_TTY;
38288 ops->owner = NULL;
38289 - ops->refcount = ops->flags = 0;
38290 + atomic_set(&ops->refcount, 0);
38291 + ops->flags = 0;
38292 }
38293 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38294 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38295 index a82b399..331a220 100644
38296 --- a/drivers/tty/pty.c
38297 +++ b/drivers/tty/pty.c
38298 @@ -728,8 +728,10 @@ static void __init unix98_pty_init(void)
38299 panic("Couldn't register Unix98 pts driver");
38300
38301 /* Now create the /dev/ptmx special device */
38302 + pax_open_kernel();
38303 tty_default_fops(&ptmx_fops);
38304 - ptmx_fops.open = ptmx_open;
38305 + *(void **)&ptmx_fops.open = ptmx_open;
38306 + pax_close_kernel();
38307
38308 cdev_init(&ptmx_cdev, &ptmx_fops);
38309 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38310 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38311 index 9700d34..df7520c 100644
38312 --- a/drivers/tty/rocket.c
38313 +++ b/drivers/tty/rocket.c
38314 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38315 tty->driver_data = info;
38316 tty_port_tty_set(port, tty);
38317
38318 - if (port->count++ == 0) {
38319 + if (atomic_inc_return(&port->count) == 1) {
38320 atomic_inc(&rp_num_ports_open);
38321
38322 #ifdef ROCKET_DEBUG_OPEN
38323 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38324 #endif
38325 }
38326 #ifdef ROCKET_DEBUG_OPEN
38327 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38328 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38329 #endif
38330
38331 /*
38332 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38333 spin_unlock_irqrestore(&info->port.lock, flags);
38334 return;
38335 }
38336 - if (info->port.count)
38337 + if (atomic_read(&info->port.count))
38338 atomic_dec(&rp_num_ports_open);
38339 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38340 spin_unlock_irqrestore(&info->port.lock, flags);
38341 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38342 index 1002054..dd644a8 100644
38343 --- a/drivers/tty/serial/kgdboc.c
38344 +++ b/drivers/tty/serial/kgdboc.c
38345 @@ -24,8 +24,9 @@
38346 #define MAX_CONFIG_LEN 40
38347
38348 static struct kgdb_io kgdboc_io_ops;
38349 +static struct kgdb_io kgdboc_io_ops_console;
38350
38351 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38352 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38353 static int configured = -1;
38354
38355 static char config[MAX_CONFIG_LEN];
38356 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
38357 kgdboc_unregister_kbd();
38358 if (configured == 1)
38359 kgdb_unregister_io_module(&kgdboc_io_ops);
38360 + else if (configured == 2)
38361 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38362 }
38363
38364 static int configure_kgdboc(void)
38365 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
38366 int err;
38367 char *cptr = config;
38368 struct console *cons;
38369 + int is_console = 0;
38370
38371 err = kgdboc_option_setup(config);
38372 if (err || !strlen(config) || isspace(config[0]))
38373 goto noconfig;
38374
38375 err = -ENODEV;
38376 - kgdboc_io_ops.is_console = 0;
38377 kgdb_tty_driver = NULL;
38378
38379 kgdboc_use_kms = 0;
38380 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
38381 int idx;
38382 if (cons->device && cons->device(cons, &idx) == p &&
38383 idx == tty_line) {
38384 - kgdboc_io_ops.is_console = 1;
38385 + is_console = 1;
38386 break;
38387 }
38388 cons = cons->next;
38389 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
38390 kgdb_tty_line = tty_line;
38391
38392 do_register:
38393 - err = kgdb_register_io_module(&kgdboc_io_ops);
38394 + if (is_console) {
38395 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38396 + configured = 2;
38397 + } else {
38398 + err = kgdb_register_io_module(&kgdboc_io_ops);
38399 + configured = 1;
38400 + }
38401 if (err)
38402 goto noconfig;
38403
38404 @@ -205,8 +214,6 @@ do_register:
38405 if (err)
38406 goto nmi_con_failed;
38407
38408 - configured = 1;
38409 -
38410 return 0;
38411
38412 nmi_con_failed:
38413 @@ -223,7 +230,7 @@ noconfig:
38414 static int __init init_kgdboc(void)
38415 {
38416 /* Already configured? */
38417 - if (configured == 1)
38418 + if (configured >= 1)
38419 return 0;
38420
38421 return configure_kgdboc();
38422 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38423 if (config[len - 1] == '\n')
38424 config[len - 1] = '\0';
38425
38426 - if (configured == 1)
38427 + if (configured >= 1)
38428 cleanup_kgdboc();
38429
38430 /* Go and configure with the new params. */
38431 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
38432 .post_exception = kgdboc_post_exp_handler,
38433 };
38434
38435 +static struct kgdb_io kgdboc_io_ops_console = {
38436 + .name = "kgdboc",
38437 + .read_char = kgdboc_get_char,
38438 + .write_char = kgdboc_put_char,
38439 + .pre_exception = kgdboc_pre_exp_handler,
38440 + .post_exception = kgdboc_post_exp_handler,
38441 + .is_console = 1
38442 +};
38443 +
38444 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38445 /* This is only available if kgdboc is a built in for early debugging */
38446 static int __init kgdboc_early_init(char *opt)
38447 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38448 index 0fcfd98..8244fce 100644
38449 --- a/drivers/tty/serial/serial_core.c
38450 +++ b/drivers/tty/serial/serial_core.c
38451 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
38452 uart_flush_buffer(tty);
38453 uart_shutdown(tty, state);
38454 spin_lock_irqsave(&port->lock, flags);
38455 - port->count = 0;
38456 + atomic_set(&port->count, 0);
38457 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38458 spin_unlock_irqrestore(&port->lock, flags);
38459 tty_port_tty_set(port, NULL);
38460 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38461 goto end;
38462 }
38463
38464 - port->count++;
38465 + atomic_inc(&port->count);
38466 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38467 retval = -ENXIO;
38468 goto err_dec_count;
38469 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38470 /*
38471 * Make sure the device is in D0 state.
38472 */
38473 - if (port->count == 1)
38474 + if (atomic_read(&port->count) == 1)
38475 uart_change_pm(state, 0);
38476
38477 /*
38478 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38479 end:
38480 return retval;
38481 err_dec_count:
38482 - port->count--;
38483 + atomic_inc(&port->count);
38484 mutex_unlock(&port->mutex);
38485 goto end;
38486 }
38487 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38488 index 70e3a52..5742052 100644
38489 --- a/drivers/tty/synclink.c
38490 +++ b/drivers/tty/synclink.c
38491 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38492
38493 if (debug_level >= DEBUG_LEVEL_INFO)
38494 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38495 - __FILE__,__LINE__, info->device_name, info->port.count);
38496 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38497
38498 if (tty_port_close_start(&info->port, tty, filp) == 0)
38499 goto cleanup;
38500 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38501 cleanup:
38502 if (debug_level >= DEBUG_LEVEL_INFO)
38503 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38504 - tty->driver->name, info->port.count);
38505 + tty->driver->name, atomic_read(&info->port.count));
38506
38507 } /* end of mgsl_close() */
38508
38509 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38510
38511 mgsl_flush_buffer(tty);
38512 shutdown(info);
38513 -
38514 - info->port.count = 0;
38515 +
38516 + atomic_set(&info->port.count, 0);
38517 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38518 info->port.tty = NULL;
38519
38520 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38521
38522 if (debug_level >= DEBUG_LEVEL_INFO)
38523 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38524 - __FILE__,__LINE__, tty->driver->name, port->count );
38525 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38526
38527 spin_lock_irqsave(&info->irq_spinlock, flags);
38528 if (!tty_hung_up_p(filp)) {
38529 extra_count = true;
38530 - port->count--;
38531 + atomic_dec(&port->count);
38532 }
38533 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38534 port->blocked_open++;
38535 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38536
38537 if (debug_level >= DEBUG_LEVEL_INFO)
38538 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38539 - __FILE__,__LINE__, tty->driver->name, port->count );
38540 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38541
38542 tty_unlock(tty);
38543 schedule();
38544 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38545
38546 /* FIXME: Racy on hangup during close wait */
38547 if (extra_count)
38548 - port->count++;
38549 + atomic_inc(&port->count);
38550 port->blocked_open--;
38551
38552 if (debug_level >= DEBUG_LEVEL_INFO)
38553 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38554 - __FILE__,__LINE__, tty->driver->name, port->count );
38555 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38556
38557 if (!retval)
38558 port->flags |= ASYNC_NORMAL_ACTIVE;
38559 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38560
38561 if (debug_level >= DEBUG_LEVEL_INFO)
38562 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38563 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38564 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38565
38566 /* If port is closing, signal caller to try again */
38567 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38568 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38569 spin_unlock_irqrestore(&info->netlock, flags);
38570 goto cleanup;
38571 }
38572 - info->port.count++;
38573 + atomic_inc(&info->port.count);
38574 spin_unlock_irqrestore(&info->netlock, flags);
38575
38576 - if (info->port.count == 1) {
38577 + if (atomic_read(&info->port.count) == 1) {
38578 /* 1st open on this device, init hardware */
38579 retval = startup(info);
38580 if (retval < 0)
38581 @@ -3451,8 +3451,8 @@ cleanup:
38582 if (retval) {
38583 if (tty->count == 1)
38584 info->port.tty = NULL; /* tty layer will release tty struct */
38585 - if(info->port.count)
38586 - info->port.count--;
38587 + if (atomic_read(&info->port.count))
38588 + atomic_dec(&info->port.count);
38589 }
38590
38591 return retval;
38592 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38593 unsigned short new_crctype;
38594
38595 /* return error if TTY interface open */
38596 - if (info->port.count)
38597 + if (atomic_read(&info->port.count))
38598 return -EBUSY;
38599
38600 switch (encoding)
38601 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
38602
38603 /* arbitrate between network and tty opens */
38604 spin_lock_irqsave(&info->netlock, flags);
38605 - if (info->port.count != 0 || info->netcount != 0) {
38606 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38607 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38608 spin_unlock_irqrestore(&info->netlock, flags);
38609 return -EBUSY;
38610 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38611 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38612
38613 /* return error if TTY interface open */
38614 - if (info->port.count)
38615 + if (atomic_read(&info->port.count))
38616 return -EBUSY;
38617
38618 if (cmd != SIOCWANDEV)
38619 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38620 index b38e954..ce45b38 100644
38621 --- a/drivers/tty/synclink_gt.c
38622 +++ b/drivers/tty/synclink_gt.c
38623 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38624 tty->driver_data = info;
38625 info->port.tty = tty;
38626
38627 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38628 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38629
38630 /* If port is closing, signal caller to try again */
38631 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38632 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38633 mutex_unlock(&info->port.mutex);
38634 goto cleanup;
38635 }
38636 - info->port.count++;
38637 + atomic_inc(&info->port.count);
38638 spin_unlock_irqrestore(&info->netlock, flags);
38639
38640 - if (info->port.count == 1) {
38641 + if (atomic_read(&info->port.count) == 1) {
38642 /* 1st open on this device, init hardware */
38643 retval = startup(info);
38644 if (retval < 0) {
38645 @@ -716,8 +716,8 @@ cleanup:
38646 if (retval) {
38647 if (tty->count == 1)
38648 info->port.tty = NULL; /* tty layer will release tty struct */
38649 - if(info->port.count)
38650 - info->port.count--;
38651 + if(atomic_read(&info->port.count))
38652 + atomic_dec(&info->port.count);
38653 }
38654
38655 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38656 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38657
38658 if (sanity_check(info, tty->name, "close"))
38659 return;
38660 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38661 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38662
38663 if (tty_port_close_start(&info->port, tty, filp) == 0)
38664 goto cleanup;
38665 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38666 tty_port_close_end(&info->port, tty);
38667 info->port.tty = NULL;
38668 cleanup:
38669 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38670 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38671 }
38672
38673 static void hangup(struct tty_struct *tty)
38674 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38675 shutdown(info);
38676
38677 spin_lock_irqsave(&info->port.lock, flags);
38678 - info->port.count = 0;
38679 + atomic_set(&info->port.count, 0);
38680 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38681 info->port.tty = NULL;
38682 spin_unlock_irqrestore(&info->port.lock, flags);
38683 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38684 unsigned short new_crctype;
38685
38686 /* return error if TTY interface open */
38687 - if (info->port.count)
38688 + if (atomic_read(&info->port.count))
38689 return -EBUSY;
38690
38691 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38692 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38693
38694 /* arbitrate between network and tty opens */
38695 spin_lock_irqsave(&info->netlock, flags);
38696 - if (info->port.count != 0 || info->netcount != 0) {
38697 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38698 DBGINFO(("%s hdlc_open busy\n", dev->name));
38699 spin_unlock_irqrestore(&info->netlock, flags);
38700 return -EBUSY;
38701 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38702 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38703
38704 /* return error if TTY interface open */
38705 - if (info->port.count)
38706 + if (atomic_read(&info->port.count))
38707 return -EBUSY;
38708
38709 if (cmd != SIOCWANDEV)
38710 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38711 if (port == NULL)
38712 continue;
38713 spin_lock(&port->lock);
38714 - if ((port->port.count || port->netcount) &&
38715 + if ((atomic_read(&port->port.count) || port->netcount) &&
38716 port->pending_bh && !port->bh_running &&
38717 !port->bh_requested) {
38718 DBGISR(("%s bh queued\n", port->device_name));
38719 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38720 spin_lock_irqsave(&info->lock, flags);
38721 if (!tty_hung_up_p(filp)) {
38722 extra_count = true;
38723 - port->count--;
38724 + atomic_dec(&port->count);
38725 }
38726 spin_unlock_irqrestore(&info->lock, flags);
38727 port->blocked_open++;
38728 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38729 remove_wait_queue(&port->open_wait, &wait);
38730
38731 if (extra_count)
38732 - port->count++;
38733 + atomic_inc(&port->count);
38734 port->blocked_open--;
38735
38736 if (!retval)
38737 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38738 index f17d9f3..27a041b 100644
38739 --- a/drivers/tty/synclinkmp.c
38740 +++ b/drivers/tty/synclinkmp.c
38741 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38742
38743 if (debug_level >= DEBUG_LEVEL_INFO)
38744 printk("%s(%d):%s open(), old ref count = %d\n",
38745 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38746 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38747
38748 /* If port is closing, signal caller to try again */
38749 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38750 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38751 spin_unlock_irqrestore(&info->netlock, flags);
38752 goto cleanup;
38753 }
38754 - info->port.count++;
38755 + atomic_inc(&info->port.count);
38756 spin_unlock_irqrestore(&info->netlock, flags);
38757
38758 - if (info->port.count == 1) {
38759 + if (atomic_read(&info->port.count) == 1) {
38760 /* 1st open on this device, init hardware */
38761 retval = startup(info);
38762 if (retval < 0)
38763 @@ -797,8 +797,8 @@ cleanup:
38764 if (retval) {
38765 if (tty->count == 1)
38766 info->port.tty = NULL; /* tty layer will release tty struct */
38767 - if(info->port.count)
38768 - info->port.count--;
38769 + if(atomic_read(&info->port.count))
38770 + atomic_dec(&info->port.count);
38771 }
38772
38773 return retval;
38774 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38775
38776 if (debug_level >= DEBUG_LEVEL_INFO)
38777 printk("%s(%d):%s close() entry, count=%d\n",
38778 - __FILE__,__LINE__, info->device_name, info->port.count);
38779 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38780
38781 if (tty_port_close_start(&info->port, tty, filp) == 0)
38782 goto cleanup;
38783 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38784 cleanup:
38785 if (debug_level >= DEBUG_LEVEL_INFO)
38786 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38787 - tty->driver->name, info->port.count);
38788 + tty->driver->name, atomic_read(&info->port.count));
38789 }
38790
38791 /* Called by tty_hangup() when a hangup is signaled.
38792 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
38793 shutdown(info);
38794
38795 spin_lock_irqsave(&info->port.lock, flags);
38796 - info->port.count = 0;
38797 + atomic_set(&info->port.count, 0);
38798 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38799 info->port.tty = NULL;
38800 spin_unlock_irqrestore(&info->port.lock, flags);
38801 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38802 unsigned short new_crctype;
38803
38804 /* return error if TTY interface open */
38805 - if (info->port.count)
38806 + if (atomic_read(&info->port.count))
38807 return -EBUSY;
38808
38809 switch (encoding)
38810 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
38811
38812 /* arbitrate between network and tty opens */
38813 spin_lock_irqsave(&info->netlock, flags);
38814 - if (info->port.count != 0 || info->netcount != 0) {
38815 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38816 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38817 spin_unlock_irqrestore(&info->netlock, flags);
38818 return -EBUSY;
38819 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38820 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38821
38822 /* return error if TTY interface open */
38823 - if (info->port.count)
38824 + if (atomic_read(&info->port.count))
38825 return -EBUSY;
38826
38827 if (cmd != SIOCWANDEV)
38828 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38829 * do not request bottom half processing if the
38830 * device is not open in a normal mode.
38831 */
38832 - if ( port && (port->port.count || port->netcount) &&
38833 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38834 port->pending_bh && !port->bh_running &&
38835 !port->bh_requested ) {
38836 if ( debug_level >= DEBUG_LEVEL_ISR )
38837 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38838
38839 if (debug_level >= DEBUG_LEVEL_INFO)
38840 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38841 - __FILE__,__LINE__, tty->driver->name, port->count );
38842 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38843
38844 spin_lock_irqsave(&info->lock, flags);
38845 if (!tty_hung_up_p(filp)) {
38846 extra_count = true;
38847 - port->count--;
38848 + atomic_dec(&port->count);
38849 }
38850 spin_unlock_irqrestore(&info->lock, flags);
38851 port->blocked_open++;
38852 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38853
38854 if (debug_level >= DEBUG_LEVEL_INFO)
38855 printk("%s(%d):%s block_til_ready() count=%d\n",
38856 - __FILE__,__LINE__, tty->driver->name, port->count );
38857 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38858
38859 tty_unlock(tty);
38860 schedule();
38861 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38862 remove_wait_queue(&port->open_wait, &wait);
38863
38864 if (extra_count)
38865 - port->count++;
38866 + atomic_inc(&port->count);
38867 port->blocked_open--;
38868
38869 if (debug_level >= DEBUG_LEVEL_INFO)
38870 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38871 - __FILE__,__LINE__, tty->driver->name, port->count );
38872 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38873
38874 if (!retval)
38875 port->flags |= ASYNC_NORMAL_ACTIVE;
38876 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38877 index 16ee6ce..bfcac57 100644
38878 --- a/drivers/tty/sysrq.c
38879 +++ b/drivers/tty/sysrq.c
38880 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38881 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38882 size_t count, loff_t *ppos)
38883 {
38884 - if (count) {
38885 + if (count && capable(CAP_SYS_ADMIN)) {
38886 char c;
38887
38888 if (get_user(c, buf))
38889 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38890 index 2ea176b..2877bc8 100644
38891 --- a/drivers/tty/tty_io.c
38892 +++ b/drivers/tty/tty_io.c
38893 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38894
38895 void tty_default_fops(struct file_operations *fops)
38896 {
38897 - *fops = tty_fops;
38898 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38899 }
38900
38901 /*
38902 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38903 index 0f2a2c5..471e228 100644
38904 --- a/drivers/tty/tty_ldisc.c
38905 +++ b/drivers/tty/tty_ldisc.c
38906 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38907 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38908 struct tty_ldisc_ops *ldo = ld->ops;
38909
38910 - ldo->refcount--;
38911 + atomic_dec(&ldo->refcount);
38912 module_put(ldo->owner);
38913 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38914
38915 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38916 spin_lock_irqsave(&tty_ldisc_lock, flags);
38917 tty_ldiscs[disc] = new_ldisc;
38918 new_ldisc->num = disc;
38919 - new_ldisc->refcount = 0;
38920 + atomic_set(&new_ldisc->refcount, 0);
38921 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38922
38923 return ret;
38924 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38925 return -EINVAL;
38926
38927 spin_lock_irqsave(&tty_ldisc_lock, flags);
38928 - if (tty_ldiscs[disc]->refcount)
38929 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38930 ret = -EBUSY;
38931 else
38932 tty_ldiscs[disc] = NULL;
38933 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38934 if (ldops) {
38935 ret = ERR_PTR(-EAGAIN);
38936 if (try_module_get(ldops->owner)) {
38937 - ldops->refcount++;
38938 + atomic_inc(&ldops->refcount);
38939 ret = ldops;
38940 }
38941 }
38942 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38943 unsigned long flags;
38944
38945 spin_lock_irqsave(&tty_ldisc_lock, flags);
38946 - ldops->refcount--;
38947 + atomic_dec(&ldops->refcount);
38948 module_put(ldops->owner);
38949 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38950 }
38951 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38952 index d7bdd8d..feaef30 100644
38953 --- a/drivers/tty/tty_port.c
38954 +++ b/drivers/tty/tty_port.c
38955 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
38956 unsigned long flags;
38957
38958 spin_lock_irqsave(&port->lock, flags);
38959 - port->count = 0;
38960 + atomic_set(&port->count, 0);
38961 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38962 if (port->tty) {
38963 set_bit(TTY_IO_ERROR, &port->tty->flags);
38964 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38965 /* The port lock protects the port counts */
38966 spin_lock_irqsave(&port->lock, flags);
38967 if (!tty_hung_up_p(filp))
38968 - port->count--;
38969 + atomic_dec(&port->count);
38970 port->blocked_open++;
38971 spin_unlock_irqrestore(&port->lock, flags);
38972
38973 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38974 we must not mess that up further */
38975 spin_lock_irqsave(&port->lock, flags);
38976 if (!tty_hung_up_p(filp))
38977 - port->count++;
38978 + atomic_inc(&port->count);
38979 port->blocked_open--;
38980 if (retval == 0)
38981 port->flags |= ASYNC_NORMAL_ACTIVE;
38982 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
38983 return 0;
38984 }
38985
38986 - if (tty->count == 1 && port->count != 1) {
38987 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38988 printk(KERN_WARNING
38989 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38990 - port->count);
38991 - port->count = 1;
38992 + atomic_read(&port->count));
38993 + atomic_set(&port->count, 1);
38994 }
38995 - if (--port->count < 0) {
38996 + if (atomic_dec_return(&port->count) < 0) {
38997 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38998 - port->count);
38999 - port->count = 0;
39000 + atomic_read(&port->count));
39001 + atomic_set(&port->count, 0);
39002 }
39003
39004 - if (port->count) {
39005 + if (atomic_read(&port->count)) {
39006 spin_unlock_irqrestore(&port->lock, flags);
39007 if (port->ops->drop)
39008 port->ops->drop(port);
39009 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39010 {
39011 spin_lock_irq(&port->lock);
39012 if (!tty_hung_up_p(filp))
39013 - ++port->count;
39014 + atomic_inc(&port->count);
39015 spin_unlock_irq(&port->lock);
39016 tty_port_tty_set(port, tty);
39017
39018 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39019 index 681765b..d3ccdf2 100644
39020 --- a/drivers/tty/vt/keyboard.c
39021 +++ b/drivers/tty/vt/keyboard.c
39022 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39023 kbd->kbdmode == VC_OFF) &&
39024 value != KVAL(K_SAK))
39025 return; /* SAK is allowed even in raw mode */
39026 +
39027 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39028 + {
39029 + void *func = fn_handler[value];
39030 + if (func == fn_show_state || func == fn_show_ptregs ||
39031 + func == fn_show_mem)
39032 + return;
39033 + }
39034 +#endif
39035 +
39036 fn_handler[value](vc);
39037 }
39038
39039 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39040 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39041 return -EFAULT;
39042
39043 - if (!capable(CAP_SYS_TTY_CONFIG))
39044 - perm = 0;
39045 -
39046 switch (cmd) {
39047 case KDGKBENT:
39048 /* Ensure another thread doesn't free it under us */
39049 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39050 spin_unlock_irqrestore(&kbd_event_lock, flags);
39051 return put_user(val, &user_kbe->kb_value);
39052 case KDSKBENT:
39053 + if (!capable(CAP_SYS_TTY_CONFIG))
39054 + perm = 0;
39055 +
39056 if (!perm)
39057 return -EPERM;
39058 if (!i && v == K_NOSUCHMAP) {
39059 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39060 int i, j, k;
39061 int ret;
39062
39063 - if (!capable(CAP_SYS_TTY_CONFIG))
39064 - perm = 0;
39065 -
39066 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39067 if (!kbs) {
39068 ret = -ENOMEM;
39069 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39070 kfree(kbs);
39071 return ((p && *p) ? -EOVERFLOW : 0);
39072 case KDSKBSENT:
39073 + if (!capable(CAP_SYS_TTY_CONFIG))
39074 + perm = 0;
39075 +
39076 if (!perm) {
39077 ret = -EPERM;
39078 goto reterr;
39079 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39080 index 5110f36..8dc0a74 100644
39081 --- a/drivers/uio/uio.c
39082 +++ b/drivers/uio/uio.c
39083 @@ -25,6 +25,7 @@
39084 #include <linux/kobject.h>
39085 #include <linux/cdev.h>
39086 #include <linux/uio_driver.h>
39087 +#include <asm/local.h>
39088
39089 #define UIO_MAX_DEVICES (1U << MINORBITS)
39090
39091 @@ -32,10 +33,10 @@ struct uio_device {
39092 struct module *owner;
39093 struct device *dev;
39094 int minor;
39095 - atomic_t event;
39096 + atomic_unchecked_t event;
39097 struct fasync_struct *async_queue;
39098 wait_queue_head_t wait;
39099 - int vma_count;
39100 + local_t vma_count;
39101 struct uio_info *info;
39102 struct kobject *map_dir;
39103 struct kobject *portio_dir;
39104 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39105 struct device_attribute *attr, char *buf)
39106 {
39107 struct uio_device *idev = dev_get_drvdata(dev);
39108 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39109 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39110 }
39111
39112 static struct device_attribute uio_class_attributes[] = {
39113 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39114 {
39115 struct uio_device *idev = info->uio_dev;
39116
39117 - atomic_inc(&idev->event);
39118 + atomic_inc_unchecked(&idev->event);
39119 wake_up_interruptible(&idev->wait);
39120 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39121 }
39122 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39123 }
39124
39125 listener->dev = idev;
39126 - listener->event_count = atomic_read(&idev->event);
39127 + listener->event_count = atomic_read_unchecked(&idev->event);
39128 filep->private_data = listener;
39129
39130 if (idev->info->open) {
39131 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39132 return -EIO;
39133
39134 poll_wait(filep, &idev->wait, wait);
39135 - if (listener->event_count != atomic_read(&idev->event))
39136 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39137 return POLLIN | POLLRDNORM;
39138 return 0;
39139 }
39140 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39141 do {
39142 set_current_state(TASK_INTERRUPTIBLE);
39143
39144 - event_count = atomic_read(&idev->event);
39145 + event_count = atomic_read_unchecked(&idev->event);
39146 if (event_count != listener->event_count) {
39147 if (copy_to_user(buf, &event_count, count))
39148 retval = -EFAULT;
39149 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39150 static void uio_vma_open(struct vm_area_struct *vma)
39151 {
39152 struct uio_device *idev = vma->vm_private_data;
39153 - idev->vma_count++;
39154 + local_inc(&idev->vma_count);
39155 }
39156
39157 static void uio_vma_close(struct vm_area_struct *vma)
39158 {
39159 struct uio_device *idev = vma->vm_private_data;
39160 - idev->vma_count--;
39161 + local_dec(&idev->vma_count);
39162 }
39163
39164 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39165 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
39166 idev->owner = owner;
39167 idev->info = info;
39168 init_waitqueue_head(&idev->wait);
39169 - atomic_set(&idev->event, 0);
39170 + atomic_set_unchecked(&idev->event, 0);
39171
39172 ret = uio_get_minor(idev);
39173 if (ret)
39174 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39175 index b7eb86a..36d28af 100644
39176 --- a/drivers/usb/atm/cxacru.c
39177 +++ b/drivers/usb/atm/cxacru.c
39178 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39179 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39180 if (ret < 2)
39181 return -EINVAL;
39182 - if (index < 0 || index > 0x7f)
39183 + if (index > 0x7f)
39184 return -EINVAL;
39185 pos += tmp;
39186
39187 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39188 index 35f10bf..6a38a0b 100644
39189 --- a/drivers/usb/atm/usbatm.c
39190 +++ b/drivers/usb/atm/usbatm.c
39191 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39192 if (printk_ratelimit())
39193 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39194 __func__, vpi, vci);
39195 - atomic_inc(&vcc->stats->rx_err);
39196 + atomic_inc_unchecked(&vcc->stats->rx_err);
39197 return;
39198 }
39199
39200 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39201 if (length > ATM_MAX_AAL5_PDU) {
39202 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39203 __func__, length, vcc);
39204 - atomic_inc(&vcc->stats->rx_err);
39205 + atomic_inc_unchecked(&vcc->stats->rx_err);
39206 goto out;
39207 }
39208
39209 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39210 if (sarb->len < pdu_length) {
39211 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39212 __func__, pdu_length, sarb->len, vcc);
39213 - atomic_inc(&vcc->stats->rx_err);
39214 + atomic_inc_unchecked(&vcc->stats->rx_err);
39215 goto out;
39216 }
39217
39218 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39219 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39220 __func__, vcc);
39221 - atomic_inc(&vcc->stats->rx_err);
39222 + atomic_inc_unchecked(&vcc->stats->rx_err);
39223 goto out;
39224 }
39225
39226 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39227 if (printk_ratelimit())
39228 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39229 __func__, length);
39230 - atomic_inc(&vcc->stats->rx_drop);
39231 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39232 goto out;
39233 }
39234
39235 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39236
39237 vcc->push(vcc, skb);
39238
39239 - atomic_inc(&vcc->stats->rx);
39240 + atomic_inc_unchecked(&vcc->stats->rx);
39241 out:
39242 skb_trim(sarb, 0);
39243 }
39244 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
39245 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39246
39247 usbatm_pop(vcc, skb);
39248 - atomic_inc(&vcc->stats->tx);
39249 + atomic_inc_unchecked(&vcc->stats->tx);
39250
39251 skb = skb_dequeue(&instance->sndqueue);
39252 }
39253 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39254 if (!left--)
39255 return sprintf(page,
39256 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39257 - atomic_read(&atm_dev->stats.aal5.tx),
39258 - atomic_read(&atm_dev->stats.aal5.tx_err),
39259 - atomic_read(&atm_dev->stats.aal5.rx),
39260 - atomic_read(&atm_dev->stats.aal5.rx_err),
39261 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39262 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39263 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39264 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39265 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39266 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39267
39268 if (!left--) {
39269 if (instance->disconnected)
39270 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39271 index f460de3..95ba1f6 100644
39272 --- a/drivers/usb/core/devices.c
39273 +++ b/drivers/usb/core/devices.c
39274 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39275 * time it gets called.
39276 */
39277 static struct device_connect_event {
39278 - atomic_t count;
39279 + atomic_unchecked_t count;
39280 wait_queue_head_t wait;
39281 } device_event = {
39282 .count = ATOMIC_INIT(1),
39283 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39284
39285 void usbfs_conn_disc_event(void)
39286 {
39287 - atomic_add(2, &device_event.count);
39288 + atomic_add_unchecked(2, &device_event.count);
39289 wake_up(&device_event.wait);
39290 }
39291
39292 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
39293
39294 poll_wait(file, &device_event.wait, wait);
39295
39296 - event_count = atomic_read(&device_event.count);
39297 + event_count = atomic_read_unchecked(&device_event.count);
39298 if (file->f_version != event_count) {
39299 file->f_version = event_count;
39300 return POLLIN | POLLRDNORM;
39301 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
39302 index f034716..aed0368 100644
39303 --- a/drivers/usb/core/hcd.c
39304 +++ b/drivers/usb/core/hcd.c
39305 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39306 */
39307 usb_get_urb(urb);
39308 atomic_inc(&urb->use_count);
39309 - atomic_inc(&urb->dev->urbnum);
39310 + atomic_inc_unchecked(&urb->dev->urbnum);
39311 usbmon_urb_submit(&hcd->self, urb);
39312
39313 /* NOTE requirements on root-hub callers (usbfs and the hub
39314 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
39315 urb->hcpriv = NULL;
39316 INIT_LIST_HEAD(&urb->urb_list);
39317 atomic_dec(&urb->use_count);
39318 - atomic_dec(&urb->dev->urbnum);
39319 + atomic_dec_unchecked(&urb->dev->urbnum);
39320 if (atomic_read(&urb->reject))
39321 wake_up(&usb_kill_urb_queue);
39322 usb_put_urb(urb);
39323 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
39324 index 818e4a0..0fc9589 100644
39325 --- a/drivers/usb/core/sysfs.c
39326 +++ b/drivers/usb/core/sysfs.c
39327 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
39328 struct usb_device *udev;
39329
39330 udev = to_usb_device(dev);
39331 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
39332 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
39333 }
39334 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
39335
39336 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
39337 index cd8fb44..17fbe0c 100644
39338 --- a/drivers/usb/core/usb.c
39339 +++ b/drivers/usb/core/usb.c
39340 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
39341 set_dev_node(&dev->dev, dev_to_node(bus->controller));
39342 dev->state = USB_STATE_ATTACHED;
39343 dev->lpm_disable_count = 1;
39344 - atomic_set(&dev->urbnum, 0);
39345 + atomic_set_unchecked(&dev->urbnum, 0);
39346
39347 INIT_LIST_HEAD(&dev->ep0.urb_list);
39348 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
39349 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39350 index 4bfa78a..902bfbd 100644
39351 --- a/drivers/usb/early/ehci-dbgp.c
39352 +++ b/drivers/usb/early/ehci-dbgp.c
39353 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39354
39355 #ifdef CONFIG_KGDB
39356 static struct kgdb_io kgdbdbgp_io_ops;
39357 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39358 +static struct kgdb_io kgdbdbgp_io_ops_console;
39359 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39360 #else
39361 #define dbgp_kgdb_mode (0)
39362 #endif
39363 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39364 .write_char = kgdbdbgp_write_char,
39365 };
39366
39367 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39368 + .name = "kgdbdbgp",
39369 + .read_char = kgdbdbgp_read_char,
39370 + .write_char = kgdbdbgp_write_char,
39371 + .is_console = 1
39372 +};
39373 +
39374 static int kgdbdbgp_wait_time;
39375
39376 static int __init kgdbdbgp_parse_config(char *str)
39377 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39378 ptr++;
39379 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39380 }
39381 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39382 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39383 + if (early_dbgp_console.index != -1)
39384 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39385 + else
39386 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39387
39388 return 0;
39389 }
39390 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39391 index f173952..83d6ec0 100644
39392 --- a/drivers/usb/gadget/u_serial.c
39393 +++ b/drivers/usb/gadget/u_serial.c
39394 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39395 spin_lock_irq(&port->port_lock);
39396
39397 /* already open? Great. */
39398 - if (port->port.count) {
39399 + if (atomic_read(&port->port.count)) {
39400 status = 0;
39401 - port->port.count++;
39402 + atomic_inc(&port->port.count);
39403
39404 /* currently opening/closing? wait ... */
39405 } else if (port->openclose) {
39406 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39407 tty->driver_data = port;
39408 port->port.tty = tty;
39409
39410 - port->port.count = 1;
39411 + atomic_set(&port->port.count, 1);
39412 port->openclose = false;
39413
39414 /* if connected, start the I/O stream */
39415 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39416
39417 spin_lock_irq(&port->port_lock);
39418
39419 - if (port->port.count != 1) {
39420 - if (port->port.count == 0)
39421 + if (atomic_read(&port->port.count) != 1) {
39422 + if (atomic_read(&port->port.count) == 0)
39423 WARN_ON(1);
39424 else
39425 - --port->port.count;
39426 + atomic_dec(&port->port.count);
39427 goto exit;
39428 }
39429
39430 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39431 * and sleep if necessary
39432 */
39433 port->openclose = true;
39434 - port->port.count = 0;
39435 + atomic_set(&port->port.count, 0);
39436
39437 gser = port->port_usb;
39438 if (gser && gser->disconnect)
39439 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
39440 int cond;
39441
39442 spin_lock_irq(&port->port_lock);
39443 - cond = (port->port.count == 0) && !port->openclose;
39444 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39445 spin_unlock_irq(&port->port_lock);
39446 return cond;
39447 }
39448 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39449 /* if it's already open, start I/O ... and notify the serial
39450 * protocol about open/close status (connect/disconnect).
39451 */
39452 - if (port->port.count) {
39453 + if (atomic_read(&port->port.count)) {
39454 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39455 gs_start_io(port);
39456 if (gser->connect)
39457 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
39458
39459 port->port_usb = NULL;
39460 gser->ioport = NULL;
39461 - if (port->port.count > 0 || port->openclose) {
39462 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39463 wake_up_interruptible(&port->drain_wait);
39464 if (port->port.tty)
39465 tty_hangup(port->port.tty);
39466 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
39467
39468 /* finally, free any unused/unusable I/O buffers */
39469 spin_lock_irqsave(&port->port_lock, flags);
39470 - if (port->port.count == 0 && !port->openclose)
39471 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39472 gs_buf_free(&port->port_write_buf);
39473 gs_free_requests(gser->out, &port->read_pool, NULL);
39474 gs_free_requests(gser->out, &port->read_queue, NULL);
39475 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39476 index 5f3bcd3..bfca43f 100644
39477 --- a/drivers/usb/serial/console.c
39478 +++ b/drivers/usb/serial/console.c
39479 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
39480
39481 info->port = port;
39482
39483 - ++port->port.count;
39484 + atomic_inc(&port->port.count);
39485 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39486 if (serial->type->set_termios) {
39487 /*
39488 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
39489 }
39490 /* Now that any required fake tty operations are completed restore
39491 * the tty port count */
39492 - --port->port.count;
39493 + atomic_dec(&port->port.count);
39494 /* The console is special in terms of closing the device so
39495 * indicate this port is now acting as a system console. */
39496 port->port.console = 1;
39497 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
39498 free_tty:
39499 kfree(tty);
39500 reset_open_count:
39501 - port->port.count = 0;
39502 + atomic_set(&port->port.count, 0);
39503 usb_autopm_put_interface(serial->interface);
39504 error_get_interface:
39505 usb_serial_put(serial);
39506 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39507 index d6bea3e..60b250e 100644
39508 --- a/drivers/usb/wusbcore/wa-hc.h
39509 +++ b/drivers/usb/wusbcore/wa-hc.h
39510 @@ -192,7 +192,7 @@ struct wahc {
39511 struct list_head xfer_delayed_list;
39512 spinlock_t xfer_list_lock;
39513 struct work_struct xfer_work;
39514 - atomic_t xfer_id_count;
39515 + atomic_unchecked_t xfer_id_count;
39516 };
39517
39518
39519 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39520 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39521 spin_lock_init(&wa->xfer_list_lock);
39522 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39523 - atomic_set(&wa->xfer_id_count, 1);
39524 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39525 }
39526
39527 /**
39528 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39529 index 57c01ab..8a05959 100644
39530 --- a/drivers/usb/wusbcore/wa-xfer.c
39531 +++ b/drivers/usb/wusbcore/wa-xfer.c
39532 @@ -296,7 +296,7 @@ out:
39533 */
39534 static void wa_xfer_id_init(struct wa_xfer *xfer)
39535 {
39536 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39537 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39538 }
39539
39540 /*
39541 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39542 index dedaf81..b0f11ab 100644
39543 --- a/drivers/vhost/vhost.c
39544 +++ b/drivers/vhost/vhost.c
39545 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39546 return 0;
39547 }
39548
39549 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39550 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39551 {
39552 struct file *eventfp, *filep = NULL;
39553 bool pollstart = false, pollstop = false;
39554 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39555 index 0fefa84..7a9d581 100644
39556 --- a/drivers/video/aty/aty128fb.c
39557 +++ b/drivers/video/aty/aty128fb.c
39558 @@ -149,7 +149,7 @@ enum {
39559 };
39560
39561 /* Must match above enum */
39562 -static char * const r128_family[] __devinitconst = {
39563 +static const char * const r128_family[] __devinitconst = {
39564 "AGP",
39565 "PCI",
39566 "PRO AGP",
39567 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39568 index 5c3960d..15cf8fc 100644
39569 --- a/drivers/video/fbcmap.c
39570 +++ b/drivers/video/fbcmap.c
39571 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39572 rc = -ENODEV;
39573 goto out;
39574 }
39575 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39576 - !info->fbops->fb_setcmap)) {
39577 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39578 rc = -EINVAL;
39579 goto out1;
39580 }
39581 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39582 index 3ff0105..7589d98 100644
39583 --- a/drivers/video/fbmem.c
39584 +++ b/drivers/video/fbmem.c
39585 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39586 image->dx += image->width + 8;
39587 }
39588 } else if (rotate == FB_ROTATE_UD) {
39589 - for (x = 0; x < num && image->dx >= 0; x++) {
39590 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39591 info->fbops->fb_imageblit(info, image);
39592 image->dx -= image->width + 8;
39593 }
39594 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39595 image->dy += image->height + 8;
39596 }
39597 } else if (rotate == FB_ROTATE_CCW) {
39598 - for (x = 0; x < num && image->dy >= 0; x++) {
39599 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39600 info->fbops->fb_imageblit(info, image);
39601 image->dy -= image->height + 8;
39602 }
39603 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39604 return -EFAULT;
39605 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39606 return -EINVAL;
39607 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39608 + if (con2fb.framebuffer >= FB_MAX)
39609 return -EINVAL;
39610 if (!registered_fb[con2fb.framebuffer])
39611 request_module("fb%d", con2fb.framebuffer);
39612 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39613 index 7672d2e..b56437f 100644
39614 --- a/drivers/video/i810/i810_accel.c
39615 +++ b/drivers/video/i810/i810_accel.c
39616 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39617 }
39618 }
39619 printk("ringbuffer lockup!!!\n");
39620 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39621 i810_report_error(mmio);
39622 par->dev_flags |= LOCKUP;
39623 info->pixmap.scan_align = 1;
39624 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39625 index 3c14e43..eafa544 100644
39626 --- a/drivers/video/logo/logo_linux_clut224.ppm
39627 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39628 @@ -1,1604 +1,1123 @@
39629 P3
39630 -# Standard 224-color Linux logo
39631 80 80
39632 255
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 6 6 6 6 6 6 10 10 10 10 10 10
39643 - 10 10 10 6 6 6 6 6 6 6 6 6
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 0 0 0 0 0 0 0 0 0
39655 - 0 0 0 0 0 0 0 0 0 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 6 6 6 10 10 10 14 14 14
39662 - 22 22 22 26 26 26 30 30 30 34 34 34
39663 - 30 30 30 30 30 30 26 26 26 18 18 18
39664 - 14 14 14 10 10 10 6 6 6 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 0 0 0 0 0 0 0 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 0 0 0 0 0 0 0 0 0 0
39673 - 0 0 0 0 0 0 0 0 0 0 0 0
39674 - 0 0 0 0 0 1 0 0 1 0 0 0
39675 - 0 0 0 0 0 0 0 0 0 0 0 0
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 0 0 0 0 0 0 0 0 0 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 0 0 0
39681 - 6 6 6 14 14 14 26 26 26 42 42 42
39682 - 54 54 54 66 66 66 78 78 78 78 78 78
39683 - 78 78 78 74 74 74 66 66 66 54 54 54
39684 - 42 42 42 26 26 26 18 18 18 10 10 10
39685 - 6 6 6 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 1 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 10 10 10
39701 - 22 22 22 42 42 42 66 66 66 86 86 86
39702 - 66 66 66 38 38 38 38 38 38 22 22 22
39703 - 26 26 26 34 34 34 54 54 54 66 66 66
39704 - 86 86 86 70 70 70 46 46 46 26 26 26
39705 - 14 14 14 6 6 6 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 1 0 0 1 0 0 1 0 0 0
39715 - 0 0 0 0 0 0 0 0 0 0 0 0
39716 - 0 0 0 0 0 0 0 0 0 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 10 10 10 26 26 26
39721 - 50 50 50 82 82 82 58 58 58 6 6 6
39722 - 2 2 6 2 2 6 2 2 6 2 2 6
39723 - 2 2 6 2 2 6 2 2 6 2 2 6
39724 - 6 6 6 54 54 54 86 86 86 66 66 66
39725 - 38 38 38 18 18 18 6 6 6 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 6 6 6 22 22 22 50 50 50
39741 - 78 78 78 34 34 34 2 2 6 2 2 6
39742 - 2 2 6 2 2 6 2 2 6 2 2 6
39743 - 2 2 6 2 2 6 2 2 6 2 2 6
39744 - 2 2 6 2 2 6 6 6 6 70 70 70
39745 - 78 78 78 46 46 46 22 22 22 6 6 6
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 1 0 0 1 0 0 1 0 0 0
39755 - 0 0 0 0 0 0 0 0 0 0 0 0
39756 - 0 0 0 0 0 0 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 6 6 6 18 18 18 42 42 42 82 82 82
39761 - 26 26 26 2 2 6 2 2 6 2 2 6
39762 - 2 2 6 2 2 6 2 2 6 2 2 6
39763 - 2 2 6 2 2 6 2 2 6 14 14 14
39764 - 46 46 46 34 34 34 6 6 6 2 2 6
39765 - 42 42 42 78 78 78 42 42 42 18 18 18
39766 - 6 6 6 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 1 0 0 0 0 0 1 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 10 10 10 30 30 30 66 66 66 58 58 58
39781 - 2 2 6 2 2 6 2 2 6 2 2 6
39782 - 2 2 6 2 2 6 2 2 6 2 2 6
39783 - 2 2 6 2 2 6 2 2 6 26 26 26
39784 - 86 86 86 101 101 101 46 46 46 10 10 10
39785 - 2 2 6 58 58 58 70 70 70 34 34 34
39786 - 10 10 10 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 1 0 0 1 0 0 1 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 14 14 14 42 42 42 86 86 86 10 10 10
39801 - 2 2 6 2 2 6 2 2 6 2 2 6
39802 - 2 2 6 2 2 6 2 2 6 2 2 6
39803 - 2 2 6 2 2 6 2 2 6 30 30 30
39804 - 94 94 94 94 94 94 58 58 58 26 26 26
39805 - 2 2 6 6 6 6 78 78 78 54 54 54
39806 - 22 22 22 6 6 6 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 6 6 6
39820 - 22 22 22 62 62 62 62 62 62 2 2 6
39821 - 2 2 6 2 2 6 2 2 6 2 2 6
39822 - 2 2 6 2 2 6 2 2 6 2 2 6
39823 - 2 2 6 2 2 6 2 2 6 26 26 26
39824 - 54 54 54 38 38 38 18 18 18 10 10 10
39825 - 2 2 6 2 2 6 34 34 34 82 82 82
39826 - 38 38 38 14 14 14 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 0 0 0 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 0 0 0 0 0 0 0 0 0 0 0 0
39834 - 0 0 0 0 0 1 0 0 1 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 6 6 6
39840 - 30 30 30 78 78 78 30 30 30 2 2 6
39841 - 2 2 6 2 2 6 2 2 6 2 2 6
39842 - 2 2 6 2 2 6 2 2 6 2 2 6
39843 - 2 2 6 2 2 6 2 2 6 10 10 10
39844 - 10 10 10 2 2 6 2 2 6 2 2 6
39845 - 2 2 6 2 2 6 2 2 6 78 78 78
39846 - 50 50 50 18 18 18 6 6 6 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 0 0 0
39854 - 0 0 1 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 10 10 10
39860 - 38 38 38 86 86 86 14 14 14 2 2 6
39861 - 2 2 6 2 2 6 2 2 6 2 2 6
39862 - 2 2 6 2 2 6 2 2 6 2 2 6
39863 - 2 2 6 2 2 6 2 2 6 2 2 6
39864 - 2 2 6 2 2 6 2 2 6 2 2 6
39865 - 2 2 6 2 2 6 2 2 6 54 54 54
39866 - 66 66 66 26 26 26 6 6 6 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 0 0 0
39874 - 0 0 0 0 0 1 0 0 1 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 14 14 14
39880 - 42 42 42 82 82 82 2 2 6 2 2 6
39881 - 2 2 6 6 6 6 10 10 10 2 2 6
39882 - 2 2 6 2 2 6 2 2 6 2 2 6
39883 - 2 2 6 2 2 6 2 2 6 6 6 6
39884 - 14 14 14 10 10 10 2 2 6 2 2 6
39885 - 2 2 6 2 2 6 2 2 6 18 18 18
39886 - 82 82 82 34 34 34 10 10 10 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 0 0 0
39894 - 0 0 1 0 0 0 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 0 0 0 14 14 14
39900 - 46 46 46 86 86 86 2 2 6 2 2 6
39901 - 6 6 6 6 6 6 22 22 22 34 34 34
39902 - 6 6 6 2 2 6 2 2 6 2 2 6
39903 - 2 2 6 2 2 6 18 18 18 34 34 34
39904 - 10 10 10 50 50 50 22 22 22 2 2 6
39905 - 2 2 6 2 2 6 2 2 6 10 10 10
39906 - 86 86 86 42 42 42 14 14 14 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 0 0 0
39913 - 0 0 0 0 0 0 0 0 0 0 0 0
39914 - 0 0 1 0 0 1 0 0 1 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 0 14 14 14
39920 - 46 46 46 86 86 86 2 2 6 2 2 6
39921 - 38 38 38 116 116 116 94 94 94 22 22 22
39922 - 22 22 22 2 2 6 2 2 6 2 2 6
39923 - 14 14 14 86 86 86 138 138 138 162 162 162
39924 -154 154 154 38 38 38 26 26 26 6 6 6
39925 - 2 2 6 2 2 6 2 2 6 2 2 6
39926 - 86 86 86 46 46 46 14 14 14 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 0 0 0
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 0 14 14 14
39940 - 46 46 46 86 86 86 2 2 6 14 14 14
39941 -134 134 134 198 198 198 195 195 195 116 116 116
39942 - 10 10 10 2 2 6 2 2 6 6 6 6
39943 -101 98 89 187 187 187 210 210 210 218 218 218
39944 -214 214 214 134 134 134 14 14 14 6 6 6
39945 - 2 2 6 2 2 6 2 2 6 2 2 6
39946 - 86 86 86 50 50 50 18 18 18 6 6 6
39947 - 0 0 0 0 0 0 0 0 0 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 0 0 0 0 0 1 0 0 0
39954 - 0 0 1 0 0 1 0 0 1 0 0 0
39955 - 0 0 0 0 0 0 0 0 0 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 0 0 0 0 0 0 0 14 14 14
39960 - 46 46 46 86 86 86 2 2 6 54 54 54
39961 -218 218 218 195 195 195 226 226 226 246 246 246
39962 - 58 58 58 2 2 6 2 2 6 30 30 30
39963 -210 210 210 253 253 253 174 174 174 123 123 123
39964 -221 221 221 234 234 234 74 74 74 2 2 6
39965 - 2 2 6 2 2 6 2 2 6 2 2 6
39966 - 70 70 70 58 58 58 22 22 22 6 6 6
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 0 0 0
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 14 14 14
39980 - 46 46 46 82 82 82 2 2 6 106 106 106
39981 -170 170 170 26 26 26 86 86 86 226 226 226
39982 -123 123 123 10 10 10 14 14 14 46 46 46
39983 -231 231 231 190 190 190 6 6 6 70 70 70
39984 - 90 90 90 238 238 238 158 158 158 2 2 6
39985 - 2 2 6 2 2 6 2 2 6 2 2 6
39986 - 70 70 70 58 58 58 22 22 22 6 6 6
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 1 0 0 0
39994 - 0 0 1 0 0 1 0 0 1 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 14 14 14
40000 - 42 42 42 86 86 86 6 6 6 116 116 116
40001 -106 106 106 6 6 6 70 70 70 149 149 149
40002 -128 128 128 18 18 18 38 38 38 54 54 54
40003 -221 221 221 106 106 106 2 2 6 14 14 14
40004 - 46 46 46 190 190 190 198 198 198 2 2 6
40005 - 2 2 6 2 2 6 2 2 6 2 2 6
40006 - 74 74 74 62 62 62 22 22 22 6 6 6
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 1 0 0 0
40014 - 0 0 1 0 0 0 0 0 1 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 14 14 14
40020 - 42 42 42 94 94 94 14 14 14 101 101 101
40021 -128 128 128 2 2 6 18 18 18 116 116 116
40022 -118 98 46 121 92 8 121 92 8 98 78 10
40023 -162 162 162 106 106 106 2 2 6 2 2 6
40024 - 2 2 6 195 195 195 195 195 195 6 6 6
40025 - 2 2 6 2 2 6 2 2 6 2 2 6
40026 - 74 74 74 62 62 62 22 22 22 6 6 6
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 1 0 0 1
40034 - 0 0 1 0 0 0 0 0 1 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 10 10 10
40040 - 38 38 38 90 90 90 14 14 14 58 58 58
40041 -210 210 210 26 26 26 54 38 6 154 114 10
40042 -226 170 11 236 186 11 225 175 15 184 144 12
40043 -215 174 15 175 146 61 37 26 9 2 2 6
40044 - 70 70 70 246 246 246 138 138 138 2 2 6
40045 - 2 2 6 2 2 6 2 2 6 2 2 6
40046 - 70 70 70 66 66 66 26 26 26 6 6 6
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 10 10 10
40060 - 38 38 38 86 86 86 14 14 14 10 10 10
40061 -195 195 195 188 164 115 192 133 9 225 175 15
40062 -239 182 13 234 190 10 232 195 16 232 200 30
40063 -245 207 45 241 208 19 232 195 16 184 144 12
40064 -218 194 134 211 206 186 42 42 42 2 2 6
40065 - 2 2 6 2 2 6 2 2 6 2 2 6
40066 - 50 50 50 74 74 74 30 30 30 6 6 6
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 10 10 10
40080 - 34 34 34 86 86 86 14 14 14 2 2 6
40081 -121 87 25 192 133 9 219 162 10 239 182 13
40082 -236 186 11 232 195 16 241 208 19 244 214 54
40083 -246 218 60 246 218 38 246 215 20 241 208 19
40084 -241 208 19 226 184 13 121 87 25 2 2 6
40085 - 2 2 6 2 2 6 2 2 6 2 2 6
40086 - 50 50 50 82 82 82 34 34 34 10 10 10
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 0 0 0
40094 - 0 0 0 0 0 0 0 0 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 0 0 0 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 10 10 10
40100 - 34 34 34 82 82 82 30 30 30 61 42 6
40101 -180 123 7 206 145 10 230 174 11 239 182 13
40102 -234 190 10 238 202 15 241 208 19 246 218 74
40103 -246 218 38 246 215 20 246 215 20 246 215 20
40104 -226 184 13 215 174 15 184 144 12 6 6 6
40105 - 2 2 6 2 2 6 2 2 6 2 2 6
40106 - 26 26 26 94 94 94 42 42 42 14 14 14
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 0 0 0 0 0 0 0 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 10 10 10
40120 - 30 30 30 78 78 78 50 50 50 104 69 6
40121 -192 133 9 216 158 10 236 178 12 236 186 11
40122 -232 195 16 241 208 19 244 214 54 245 215 43
40123 -246 215 20 246 215 20 241 208 19 198 155 10
40124 -200 144 11 216 158 10 156 118 10 2 2 6
40125 - 2 2 6 2 2 6 2 2 6 2 2 6
40126 - 6 6 6 90 90 90 54 54 54 18 18 18
40127 - 6 6 6 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 0 0 0 0 0 0 0 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 10 10 10
40140 - 30 30 30 78 78 78 46 46 46 22 22 22
40141 -137 92 6 210 162 10 239 182 13 238 190 10
40142 -238 202 15 241 208 19 246 215 20 246 215 20
40143 -241 208 19 203 166 17 185 133 11 210 150 10
40144 -216 158 10 210 150 10 102 78 10 2 2 6
40145 - 6 6 6 54 54 54 14 14 14 2 2 6
40146 - 2 2 6 62 62 62 74 74 74 30 30 30
40147 - 10 10 10 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 0 0 0
40154 - 0 0 0 0 0 0 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 10 10 10
40160 - 34 34 34 78 78 78 50 50 50 6 6 6
40161 - 94 70 30 139 102 15 190 146 13 226 184 13
40162 -232 200 30 232 195 16 215 174 15 190 146 13
40163 -168 122 10 192 133 9 210 150 10 213 154 11
40164 -202 150 34 182 157 106 101 98 89 2 2 6
40165 - 2 2 6 78 78 78 116 116 116 58 58 58
40166 - 2 2 6 22 22 22 90 90 90 46 46 46
40167 - 18 18 18 6 6 6 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 0 0 0
40174 - 0 0 0 0 0 0 0 0 0 0 0 0
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 10 10 10
40180 - 38 38 38 86 86 86 50 50 50 6 6 6
40181 -128 128 128 174 154 114 156 107 11 168 122 10
40182 -198 155 10 184 144 12 197 138 11 200 144 11
40183 -206 145 10 206 145 10 197 138 11 188 164 115
40184 -195 195 195 198 198 198 174 174 174 14 14 14
40185 - 2 2 6 22 22 22 116 116 116 116 116 116
40186 - 22 22 22 2 2 6 74 74 74 70 70 70
40187 - 30 30 30 10 10 10 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 0 0 0
40194 - 0 0 0 0 0 0 0 0 0 0 0 0
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 6 6 6 18 18 18
40200 - 50 50 50 101 101 101 26 26 26 10 10 10
40201 -138 138 138 190 190 190 174 154 114 156 107 11
40202 -197 138 11 200 144 11 197 138 11 192 133 9
40203 -180 123 7 190 142 34 190 178 144 187 187 187
40204 -202 202 202 221 221 221 214 214 214 66 66 66
40205 - 2 2 6 2 2 6 50 50 50 62 62 62
40206 - 6 6 6 2 2 6 10 10 10 90 90 90
40207 - 50 50 50 18 18 18 6 6 6 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 0 0 0
40214 - 0 0 0 0 0 0 0 0 0 0 0 0
40215 - 0 0 0 0 0 0 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 0 0 0 0 0 0
40218 - 0 0 0 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 10 10 10 34 34 34
40220 - 74 74 74 74 74 74 2 2 6 6 6 6
40221 -144 144 144 198 198 198 190 190 190 178 166 146
40222 -154 121 60 156 107 11 156 107 11 168 124 44
40223 -174 154 114 187 187 187 190 190 190 210 210 210
40224 -246 246 246 253 253 253 253 253 253 182 182 182
40225 - 6 6 6 2 2 6 2 2 6 2 2 6
40226 - 2 2 6 2 2 6 2 2 6 62 62 62
40227 - 74 74 74 34 34 34 14 14 14 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 0 0 0
40234 - 0 0 0 0 0 0 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 10 10 10 22 22 22 54 54 54
40240 - 94 94 94 18 18 18 2 2 6 46 46 46
40241 -234 234 234 221 221 221 190 190 190 190 190 190
40242 -190 190 190 187 187 187 187 187 187 190 190 190
40243 -190 190 190 195 195 195 214 214 214 242 242 242
40244 -253 253 253 253 253 253 253 253 253 253 253 253
40245 - 82 82 82 2 2 6 2 2 6 2 2 6
40246 - 2 2 6 2 2 6 2 2 6 14 14 14
40247 - 86 86 86 54 54 54 22 22 22 6 6 6
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 0 0 0 0 0 0 0 0 0 0
40255 - 0 0 0 0 0 0 0 0 0 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 6 6 6 18 18 18 46 46 46 90 90 90
40260 - 46 46 46 18 18 18 6 6 6 182 182 182
40261 -253 253 253 246 246 246 206 206 206 190 190 190
40262 -190 190 190 190 190 190 190 190 190 190 190 190
40263 -206 206 206 231 231 231 250 250 250 253 253 253
40264 -253 253 253 253 253 253 253 253 253 253 253 253
40265 -202 202 202 14 14 14 2 2 6 2 2 6
40266 - 2 2 6 2 2 6 2 2 6 2 2 6
40267 - 42 42 42 86 86 86 42 42 42 18 18 18
40268 - 6 6 6 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 0 0 0 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 0 0 0
40274 - 0 0 0 0 0 0 0 0 0 0 0 0
40275 - 0 0 0 0 0 0 0 0 0 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 6 6 6
40279 - 14 14 14 38 38 38 74 74 74 66 66 66
40280 - 2 2 6 6 6 6 90 90 90 250 250 250
40281 -253 253 253 253 253 253 238 238 238 198 198 198
40282 -190 190 190 190 190 190 195 195 195 221 221 221
40283 -246 246 246 253 253 253 253 253 253 253 253 253
40284 -253 253 253 253 253 253 253 253 253 253 253 253
40285 -253 253 253 82 82 82 2 2 6 2 2 6
40286 - 2 2 6 2 2 6 2 2 6 2 2 6
40287 - 2 2 6 78 78 78 70 70 70 34 34 34
40288 - 14 14 14 6 6 6 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
40294 - 0 0 0 0 0 0 0 0 0 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 14 14 14
40299 - 34 34 34 66 66 66 78 78 78 6 6 6
40300 - 2 2 6 18 18 18 218 218 218 253 253 253
40301 -253 253 253 253 253 253 253 253 253 246 246 246
40302 -226 226 226 231 231 231 246 246 246 253 253 253
40303 -253 253 253 253 253 253 253 253 253 253 253 253
40304 -253 253 253 253 253 253 253 253 253 253 253 253
40305 -253 253 253 178 178 178 2 2 6 2 2 6
40306 - 2 2 6 2 2 6 2 2 6 2 2 6
40307 - 2 2 6 18 18 18 90 90 90 62 62 62
40308 - 30 30 30 10 10 10 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 0 0 0 0 0 0 0 0 0 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 10 10 10 26 26 26
40319 - 58 58 58 90 90 90 18 18 18 2 2 6
40320 - 2 2 6 110 110 110 253 253 253 253 253 253
40321 -253 253 253 253 253 253 253 253 253 253 253 253
40322 -250 250 250 253 253 253 253 253 253 253 253 253
40323 -253 253 253 253 253 253 253 253 253 253 253 253
40324 -253 253 253 253 253 253 253 253 253 253 253 253
40325 -253 253 253 231 231 231 18 18 18 2 2 6
40326 - 2 2 6 2 2 6 2 2 6 2 2 6
40327 - 2 2 6 2 2 6 18 18 18 94 94 94
40328 - 54 54 54 26 26 26 10 10 10 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 6 6 6 22 22 22 50 50 50
40339 - 90 90 90 26 26 26 2 2 6 2 2 6
40340 - 14 14 14 195 195 195 250 250 250 253 253 253
40341 -253 253 253 253 253 253 253 253 253 253 253 253
40342 -253 253 253 253 253 253 253 253 253 253 253 253
40343 -253 253 253 253 253 253 253 253 253 253 253 253
40344 -253 253 253 253 253 253 253 253 253 253 253 253
40345 -250 250 250 242 242 242 54 54 54 2 2 6
40346 - 2 2 6 2 2 6 2 2 6 2 2 6
40347 - 2 2 6 2 2 6 2 2 6 38 38 38
40348 - 86 86 86 50 50 50 22 22 22 6 6 6
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 0 0 0
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 6 6 6 14 14 14 38 38 38 82 82 82
40359 - 34 34 34 2 2 6 2 2 6 2 2 6
40360 - 42 42 42 195 195 195 246 246 246 253 253 253
40361 -253 253 253 253 253 253 253 253 253 250 250 250
40362 -242 242 242 242 242 242 250 250 250 253 253 253
40363 -253 253 253 253 253 253 253 253 253 253 253 253
40364 -253 253 253 250 250 250 246 246 246 238 238 238
40365 -226 226 226 231 231 231 101 101 101 6 6 6
40366 - 2 2 6 2 2 6 2 2 6 2 2 6
40367 - 2 2 6 2 2 6 2 2 6 2 2 6
40368 - 38 38 38 82 82 82 42 42 42 14 14 14
40369 - 6 6 6 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 10 10 10 26 26 26 62 62 62 66 66 66
40379 - 2 2 6 2 2 6 2 2 6 6 6 6
40380 - 70 70 70 170 170 170 206 206 206 234 234 234
40381 -246 246 246 250 250 250 250 250 250 238 238 238
40382 -226 226 226 231 231 231 238 238 238 250 250 250
40383 -250 250 250 250 250 250 246 246 246 231 231 231
40384 -214 214 214 206 206 206 202 202 202 202 202 202
40385 -198 198 198 202 202 202 182 182 182 18 18 18
40386 - 2 2 6 2 2 6 2 2 6 2 2 6
40387 - 2 2 6 2 2 6 2 2 6 2 2 6
40388 - 2 2 6 62 62 62 66 66 66 30 30 30
40389 - 10 10 10 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 14 14 14 42 42 42 82 82 82 18 18 18
40399 - 2 2 6 2 2 6 2 2 6 10 10 10
40400 - 94 94 94 182 182 182 218 218 218 242 242 242
40401 -250 250 250 253 253 253 253 253 253 250 250 250
40402 -234 234 234 253 253 253 253 253 253 253 253 253
40403 -253 253 253 253 253 253 253 253 253 246 246 246
40404 -238 238 238 226 226 226 210 210 210 202 202 202
40405 -195 195 195 195 195 195 210 210 210 158 158 158
40406 - 6 6 6 14 14 14 50 50 50 14 14 14
40407 - 2 2 6 2 2 6 2 2 6 2 2 6
40408 - 2 2 6 6 6 6 86 86 86 46 46 46
40409 - 18 18 18 6 6 6 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 0 0 0 0 0 0
40411 - 0 0 0 0 0 0 0 0 0 0 0 0
40412 - 0 0 0 0 0 0 0 0 0 0 0 0
40413 - 0 0 0 0 0 0 0 0 0 0 0 0
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 6 6 6
40418 - 22 22 22 54 54 54 70 70 70 2 2 6
40419 - 2 2 6 10 10 10 2 2 6 22 22 22
40420 -166 166 166 231 231 231 250 250 250 253 253 253
40421 -253 253 253 253 253 253 253 253 253 250 250 250
40422 -242 242 242 253 253 253 253 253 253 253 253 253
40423 -253 253 253 253 253 253 253 253 253 253 253 253
40424 -253 253 253 253 253 253 253 253 253 246 246 246
40425 -231 231 231 206 206 206 198 198 198 226 226 226
40426 - 94 94 94 2 2 6 6 6 6 38 38 38
40427 - 30 30 30 2 2 6 2 2 6 2 2 6
40428 - 2 2 6 2 2 6 62 62 62 66 66 66
40429 - 26 26 26 10 10 10 0 0 0 0 0 0
40430 - 0 0 0 0 0 0 0 0 0 0 0 0
40431 - 0 0 0 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 0 0 0 0 0 0 0 0 0
40433 - 0 0 0 0 0 0 0 0 0 0 0 0
40434 - 0 0 0 0 0 0 0 0 0 0 0 0
40435 - 0 0 0 0 0 0 0 0 0 0 0 0
40436 - 0 0 0 0 0 0 0 0 0 0 0 0
40437 - 0 0 0 0 0 0 0 0 0 10 10 10
40438 - 30 30 30 74 74 74 50 50 50 2 2 6
40439 - 26 26 26 26 26 26 2 2 6 106 106 106
40440 -238 238 238 253 253 253 253 253 253 253 253 253
40441 -253 253 253 253 253 253 253 253 253 253 253 253
40442 -253 253 253 253 253 253 253 253 253 253 253 253
40443 -253 253 253 253 253 253 253 253 253 253 253 253
40444 -253 253 253 253 253 253 253 253 253 253 253 253
40445 -253 253 253 246 246 246 218 218 218 202 202 202
40446 -210 210 210 14 14 14 2 2 6 2 2 6
40447 - 30 30 30 22 22 22 2 2 6 2 2 6
40448 - 2 2 6 2 2 6 18 18 18 86 86 86
40449 - 42 42 42 14 14 14 0 0 0 0 0 0
40450 - 0 0 0 0 0 0 0 0 0 0 0 0
40451 - 0 0 0 0 0 0 0 0 0 0 0 0
40452 - 0 0 0 0 0 0 0 0 0 0 0 0
40453 - 0 0 0 0 0 0 0 0 0 0 0 0
40454 - 0 0 0 0 0 0 0 0 0 0 0 0
40455 - 0 0 0 0 0 0 0 0 0 0 0 0
40456 - 0 0 0 0 0 0 0 0 0 0 0 0
40457 - 0 0 0 0 0 0 0 0 0 14 14 14
40458 - 42 42 42 90 90 90 22 22 22 2 2 6
40459 - 42 42 42 2 2 6 18 18 18 218 218 218
40460 -253 253 253 253 253 253 253 253 253 253 253 253
40461 -253 253 253 253 253 253 253 253 253 253 253 253
40462 -253 253 253 253 253 253 253 253 253 253 253 253
40463 -253 253 253 253 253 253 253 253 253 253 253 253
40464 -253 253 253 253 253 253 253 253 253 253 253 253
40465 -253 253 253 253 253 253 250 250 250 221 221 221
40466 -218 218 218 101 101 101 2 2 6 14 14 14
40467 - 18 18 18 38 38 38 10 10 10 2 2 6
40468 - 2 2 6 2 2 6 2 2 6 78 78 78
40469 - 58 58 58 22 22 22 6 6 6 0 0 0
40470 - 0 0 0 0 0 0 0 0 0 0 0 0
40471 - 0 0 0 0 0 0 0 0 0 0 0 0
40472 - 0 0 0 0 0 0 0 0 0 0 0 0
40473 - 0 0 0 0 0 0 0 0 0 0 0 0
40474 - 0 0 0 0 0 0 0 0 0 0 0 0
40475 - 0 0 0 0 0 0 0 0 0 0 0 0
40476 - 0 0 0 0 0 0 0 0 0 0 0 0
40477 - 0 0 0 0 0 0 6 6 6 18 18 18
40478 - 54 54 54 82 82 82 2 2 6 26 26 26
40479 - 22 22 22 2 2 6 123 123 123 253 253 253
40480 -253 253 253 253 253 253 253 253 253 253 253 253
40481 -253 253 253 253 253 253 253 253 253 253 253 253
40482 -253 253 253 253 253 253 253 253 253 253 253 253
40483 -253 253 253 253 253 253 253 253 253 253 253 253
40484 -253 253 253 253 253 253 253 253 253 253 253 253
40485 -253 253 253 253 253 253 253 253 253 250 250 250
40486 -238 238 238 198 198 198 6 6 6 38 38 38
40487 - 58 58 58 26 26 26 38 38 38 2 2 6
40488 - 2 2 6 2 2 6 2 2 6 46 46 46
40489 - 78 78 78 30 30 30 10 10 10 0 0 0
40490 - 0 0 0 0 0 0 0 0 0 0 0 0
40491 - 0 0 0 0 0 0 0 0 0 0 0 0
40492 - 0 0 0 0 0 0 0 0 0 0 0 0
40493 - 0 0 0 0 0 0 0 0 0 0 0 0
40494 - 0 0 0 0 0 0 0 0 0 0 0 0
40495 - 0 0 0 0 0 0 0 0 0 0 0 0
40496 - 0 0 0 0 0 0 0 0 0 0 0 0
40497 - 0 0 0 0 0 0 10 10 10 30 30 30
40498 - 74 74 74 58 58 58 2 2 6 42 42 42
40499 - 2 2 6 22 22 22 231 231 231 253 253 253
40500 -253 253 253 253 253 253 253 253 253 253 253 253
40501 -253 253 253 253 253 253 253 253 253 250 250 250
40502 -253 253 253 253 253 253 253 253 253 253 253 253
40503 -253 253 253 253 253 253 253 253 253 253 253 253
40504 -253 253 253 253 253 253 253 253 253 253 253 253
40505 -253 253 253 253 253 253 253 253 253 253 253 253
40506 -253 253 253 246 246 246 46 46 46 38 38 38
40507 - 42 42 42 14 14 14 38 38 38 14 14 14
40508 - 2 2 6 2 2 6 2 2 6 6 6 6
40509 - 86 86 86 46 46 46 14 14 14 0 0 0
40510 - 0 0 0 0 0 0 0 0 0 0 0 0
40511 - 0 0 0 0 0 0 0 0 0 0 0 0
40512 - 0 0 0 0 0 0 0 0 0 0 0 0
40513 - 0 0 0 0 0 0 0 0 0 0 0 0
40514 - 0 0 0 0 0 0 0 0 0 0 0 0
40515 - 0 0 0 0 0 0 0 0 0 0 0 0
40516 - 0 0 0 0 0 0 0 0 0 0 0 0
40517 - 0 0 0 6 6 6 14 14 14 42 42 42
40518 - 90 90 90 18 18 18 18 18 18 26 26 26
40519 - 2 2 6 116 116 116 253 253 253 253 253 253
40520 -253 253 253 253 253 253 253 253 253 253 253 253
40521 -253 253 253 253 253 253 250 250 250 238 238 238
40522 -253 253 253 253 253 253 253 253 253 253 253 253
40523 -253 253 253 253 253 253 253 253 253 253 253 253
40524 -253 253 253 253 253 253 253 253 253 253 253 253
40525 -253 253 253 253 253 253 253 253 253 253 253 253
40526 -253 253 253 253 253 253 94 94 94 6 6 6
40527 - 2 2 6 2 2 6 10 10 10 34 34 34
40528 - 2 2 6 2 2 6 2 2 6 2 2 6
40529 - 74 74 74 58 58 58 22 22 22 6 6 6
40530 - 0 0 0 0 0 0 0 0 0 0 0 0
40531 - 0 0 0 0 0 0 0 0 0 0 0 0
40532 - 0 0 0 0 0 0 0 0 0 0 0 0
40533 - 0 0 0 0 0 0 0 0 0 0 0 0
40534 - 0 0 0 0 0 0 0 0 0 0 0 0
40535 - 0 0 0 0 0 0 0 0 0 0 0 0
40536 - 0 0 0 0 0 0 0 0 0 0 0 0
40537 - 0 0 0 10 10 10 26 26 26 66 66 66
40538 - 82 82 82 2 2 6 38 38 38 6 6 6
40539 - 14 14 14 210 210 210 253 253 253 253 253 253
40540 -253 253 253 253 253 253 253 253 253 253 253 253
40541 -253 253 253 253 253 253 246 246 246 242 242 242
40542 -253 253 253 253 253 253 253 253 253 253 253 253
40543 -253 253 253 253 253 253 253 253 253 253 253 253
40544 -253 253 253 253 253 253 253 253 253 253 253 253
40545 -253 253 253 253 253 253 253 253 253 253 253 253
40546 -253 253 253 253 253 253 144 144 144 2 2 6
40547 - 2 2 6 2 2 6 2 2 6 46 46 46
40548 - 2 2 6 2 2 6 2 2 6 2 2 6
40549 - 42 42 42 74 74 74 30 30 30 10 10 10
40550 - 0 0 0 0 0 0 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 0 0 0 0 0 0
40552 - 0 0 0 0 0 0 0 0 0 0 0 0
40553 - 0 0 0 0 0 0 0 0 0 0 0 0
40554 - 0 0 0 0 0 0 0 0 0 0 0 0
40555 - 0 0 0 0 0 0 0 0 0 0 0 0
40556 - 0 0 0 0 0 0 0 0 0 0 0 0
40557 - 6 6 6 14 14 14 42 42 42 90 90 90
40558 - 26 26 26 6 6 6 42 42 42 2 2 6
40559 - 74 74 74 250 250 250 253 253 253 253 253 253
40560 -253 253 253 253 253 253 253 253 253 253 253 253
40561 -253 253 253 253 253 253 242 242 242 242 242 242
40562 -253 253 253 253 253 253 253 253 253 253 253 253
40563 -253 253 253 253 253 253 253 253 253 253 253 253
40564 -253 253 253 253 253 253 253 253 253 253 253 253
40565 -253 253 253 253 253 253 253 253 253 253 253 253
40566 -253 253 253 253 253 253 182 182 182 2 2 6
40567 - 2 2 6 2 2 6 2 2 6 46 46 46
40568 - 2 2 6 2 2 6 2 2 6 2 2 6
40569 - 10 10 10 86 86 86 38 38 38 10 10 10
40570 - 0 0 0 0 0 0 0 0 0 0 0 0
40571 - 0 0 0 0 0 0 0 0 0 0 0 0
40572 - 0 0 0 0 0 0 0 0 0 0 0 0
40573 - 0 0 0 0 0 0 0 0 0 0 0 0
40574 - 0 0 0 0 0 0 0 0 0 0 0 0
40575 - 0 0 0 0 0 0 0 0 0 0 0 0
40576 - 0 0 0 0 0 0 0 0 0 0 0 0
40577 - 10 10 10 26 26 26 66 66 66 82 82 82
40578 - 2 2 6 22 22 22 18 18 18 2 2 6
40579 -149 149 149 253 253 253 253 253 253 253 253 253
40580 -253 253 253 253 253 253 253 253 253 253 253 253
40581 -253 253 253 253 253 253 234 234 234 242 242 242
40582 -253 253 253 253 253 253 253 253 253 253 253 253
40583 -253 253 253 253 253 253 253 253 253 253 253 253
40584 -253 253 253 253 253 253 253 253 253 253 253 253
40585 -253 253 253 253 253 253 253 253 253 253 253 253
40586 -253 253 253 253 253 253 206 206 206 2 2 6
40587 - 2 2 6 2 2 6 2 2 6 38 38 38
40588 - 2 2 6 2 2 6 2 2 6 2 2 6
40589 - 6 6 6 86 86 86 46 46 46 14 14 14
40590 - 0 0 0 0 0 0 0 0 0 0 0 0
40591 - 0 0 0 0 0 0 0 0 0 0 0 0
40592 - 0 0 0 0 0 0 0 0 0 0 0 0
40593 - 0 0 0 0 0 0 0 0 0 0 0 0
40594 - 0 0 0 0 0 0 0 0 0 0 0 0
40595 - 0 0 0 0 0 0 0 0 0 0 0 0
40596 - 0 0 0 0 0 0 0 0 0 6 6 6
40597 - 18 18 18 46 46 46 86 86 86 18 18 18
40598 - 2 2 6 34 34 34 10 10 10 6 6 6
40599 -210 210 210 253 253 253 253 253 253 253 253 253
40600 -253 253 253 253 253 253 253 253 253 253 253 253
40601 -253 253 253 253 253 253 234 234 234 242 242 242
40602 -253 253 253 253 253 253 253 253 253 253 253 253
40603 -253 253 253 253 253 253 253 253 253 253 253 253
40604 -253 253 253 253 253 253 253 253 253 253 253 253
40605 -253 253 253 253 253 253 253 253 253 253 253 253
40606 -253 253 253 253 253 253 221 221 221 6 6 6
40607 - 2 2 6 2 2 6 6 6 6 30 30 30
40608 - 2 2 6 2 2 6 2 2 6 2 2 6
40609 - 2 2 6 82 82 82 54 54 54 18 18 18
40610 - 6 6 6 0 0 0 0 0 0 0 0 0
40611 - 0 0 0 0 0 0 0 0 0 0 0 0
40612 - 0 0 0 0 0 0 0 0 0 0 0 0
40613 - 0 0 0 0 0 0 0 0 0 0 0 0
40614 - 0 0 0 0 0 0 0 0 0 0 0 0
40615 - 0 0 0 0 0 0 0 0 0 0 0 0
40616 - 0 0 0 0 0 0 0 0 0 10 10 10
40617 - 26 26 26 66 66 66 62 62 62 2 2 6
40618 - 2 2 6 38 38 38 10 10 10 26 26 26
40619 -238 238 238 253 253 253 253 253 253 253 253 253
40620 -253 253 253 253 253 253 253 253 253 253 253 253
40621 -253 253 253 253 253 253 231 231 231 238 238 238
40622 -253 253 253 253 253 253 253 253 253 253 253 253
40623 -253 253 253 253 253 253 253 253 253 253 253 253
40624 -253 253 253 253 253 253 253 253 253 253 253 253
40625 -253 253 253 253 253 253 253 253 253 253 253 253
40626 -253 253 253 253 253 253 231 231 231 6 6 6
40627 - 2 2 6 2 2 6 10 10 10 30 30 30
40628 - 2 2 6 2 2 6 2 2 6 2 2 6
40629 - 2 2 6 66 66 66 58 58 58 22 22 22
40630 - 6 6 6 0 0 0 0 0 0 0 0 0
40631 - 0 0 0 0 0 0 0 0 0 0 0 0
40632 - 0 0 0 0 0 0 0 0 0 0 0 0
40633 - 0 0 0 0 0 0 0 0 0 0 0 0
40634 - 0 0 0 0 0 0 0 0 0 0 0 0
40635 - 0 0 0 0 0 0 0 0 0 0 0 0
40636 - 0 0 0 0 0 0 0 0 0 10 10 10
40637 - 38 38 38 78 78 78 6 6 6 2 2 6
40638 - 2 2 6 46 46 46 14 14 14 42 42 42
40639 -246 246 246 253 253 253 253 253 253 253 253 253
40640 -253 253 253 253 253 253 253 253 253 253 253 253
40641 -253 253 253 253 253 253 231 231 231 242 242 242
40642 -253 253 253 253 253 253 253 253 253 253 253 253
40643 -253 253 253 253 253 253 253 253 253 253 253 253
40644 -253 253 253 253 253 253 253 253 253 253 253 253
40645 -253 253 253 253 253 253 253 253 253 253 253 253
40646 -253 253 253 253 253 253 234 234 234 10 10 10
40647 - 2 2 6 2 2 6 22 22 22 14 14 14
40648 - 2 2 6 2 2 6 2 2 6 2 2 6
40649 - 2 2 6 66 66 66 62 62 62 22 22 22
40650 - 6 6 6 0 0 0 0 0 0 0 0 0
40651 - 0 0 0 0 0 0 0 0 0 0 0 0
40652 - 0 0 0 0 0 0 0 0 0 0 0 0
40653 - 0 0 0 0 0 0 0 0 0 0 0 0
40654 - 0 0 0 0 0 0 0 0 0 0 0 0
40655 - 0 0 0 0 0 0 0 0 0 0 0 0
40656 - 0 0 0 0 0 0 6 6 6 18 18 18
40657 - 50 50 50 74 74 74 2 2 6 2 2 6
40658 - 14 14 14 70 70 70 34 34 34 62 62 62
40659 -250 250 250 253 253 253 253 253 253 253 253 253
40660 -253 253 253 253 253 253 253 253 253 253 253 253
40661 -253 253 253 253 253 253 231 231 231 246 246 246
40662 -253 253 253 253 253 253 253 253 253 253 253 253
40663 -253 253 253 253 253 253 253 253 253 253 253 253
40664 -253 253 253 253 253 253 253 253 253 253 253 253
40665 -253 253 253 253 253 253 253 253 253 253 253 253
40666 -253 253 253 253 253 253 234 234 234 14 14 14
40667 - 2 2 6 2 2 6 30 30 30 2 2 6
40668 - 2 2 6 2 2 6 2 2 6 2 2 6
40669 - 2 2 6 66 66 66 62 62 62 22 22 22
40670 - 6 6 6 0 0 0 0 0 0 0 0 0
40671 - 0 0 0 0 0 0 0 0 0 0 0 0
40672 - 0 0 0 0 0 0 0 0 0 0 0 0
40673 - 0 0 0 0 0 0 0 0 0 0 0 0
40674 - 0 0 0 0 0 0 0 0 0 0 0 0
40675 - 0 0 0 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 6 6 6 18 18 18
40677 - 54 54 54 62 62 62 2 2 6 2 2 6
40678 - 2 2 6 30 30 30 46 46 46 70 70 70
40679 -250 250 250 253 253 253 253 253 253 253 253 253
40680 -253 253 253 253 253 253 253 253 253 253 253 253
40681 -253 253 253 253 253 253 231 231 231 246 246 246
40682 -253 253 253 253 253 253 253 253 253 253 253 253
40683 -253 253 253 253 253 253 253 253 253 253 253 253
40684 -253 253 253 253 253 253 253 253 253 253 253 253
40685 -253 253 253 253 253 253 253 253 253 253 253 253
40686 -253 253 253 253 253 253 226 226 226 10 10 10
40687 - 2 2 6 6 6 6 30 30 30 2 2 6
40688 - 2 2 6 2 2 6 2 2 6 2 2 6
40689 - 2 2 6 66 66 66 58 58 58 22 22 22
40690 - 6 6 6 0 0 0 0 0 0 0 0 0
40691 - 0 0 0 0 0 0 0 0 0 0 0 0
40692 - 0 0 0 0 0 0 0 0 0 0 0 0
40693 - 0 0 0 0 0 0 0 0 0 0 0 0
40694 - 0 0 0 0 0 0 0 0 0 0 0 0
40695 - 0 0 0 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 6 6 6 22 22 22
40697 - 58 58 58 62 62 62 2 2 6 2 2 6
40698 - 2 2 6 2 2 6 30 30 30 78 78 78
40699 -250 250 250 253 253 253 253 253 253 253 253 253
40700 -253 253 253 253 253 253 253 253 253 253 253 253
40701 -253 253 253 253 253 253 231 231 231 246 246 246
40702 -253 253 253 253 253 253 253 253 253 253 253 253
40703 -253 253 253 253 253 253 253 253 253 253 253 253
40704 -253 253 253 253 253 253 253 253 253 253 253 253
40705 -253 253 253 253 253 253 253 253 253 253 253 253
40706 -253 253 253 253 253 253 206 206 206 2 2 6
40707 - 22 22 22 34 34 34 18 14 6 22 22 22
40708 - 26 26 26 18 18 18 6 6 6 2 2 6
40709 - 2 2 6 82 82 82 54 54 54 18 18 18
40710 - 6 6 6 0 0 0 0 0 0 0 0 0
40711 - 0 0 0 0 0 0 0 0 0 0 0 0
40712 - 0 0 0 0 0 0 0 0 0 0 0 0
40713 - 0 0 0 0 0 0 0 0 0 0 0 0
40714 - 0 0 0 0 0 0 0 0 0 0 0 0
40715 - 0 0 0 0 0 0 0 0 0 0 0 0
40716 - 0 0 0 0 0 0 6 6 6 26 26 26
40717 - 62 62 62 106 106 106 74 54 14 185 133 11
40718 -210 162 10 121 92 8 6 6 6 62 62 62
40719 -238 238 238 253 253 253 253 253 253 253 253 253
40720 -253 253 253 253 253 253 253 253 253 253 253 253
40721 -253 253 253 253 253 253 231 231 231 246 246 246
40722 -253 253 253 253 253 253 253 253 253 253 253 253
40723 -253 253 253 253 253 253 253 253 253 253 253 253
40724 -253 253 253 253 253 253 253 253 253 253 253 253
40725 -253 253 253 253 253 253 253 253 253 253 253 253
40726 -253 253 253 253 253 253 158 158 158 18 18 18
40727 - 14 14 14 2 2 6 2 2 6 2 2 6
40728 - 6 6 6 18 18 18 66 66 66 38 38 38
40729 - 6 6 6 94 94 94 50 50 50 18 18 18
40730 - 6 6 6 0 0 0 0 0 0 0 0 0
40731 - 0 0 0 0 0 0 0 0 0 0 0 0
40732 - 0 0 0 0 0 0 0 0 0 0 0 0
40733 - 0 0 0 0 0 0 0 0 0 0 0 0
40734 - 0 0 0 0 0 0 0 0 0 0 0 0
40735 - 0 0 0 0 0 0 0 0 0 6 6 6
40736 - 10 10 10 10 10 10 18 18 18 38 38 38
40737 - 78 78 78 142 134 106 216 158 10 242 186 14
40738 -246 190 14 246 190 14 156 118 10 10 10 10
40739 - 90 90 90 238 238 238 253 253 253 253 253 253
40740 -253 253 253 253 253 253 253 253 253 253 253 253
40741 -253 253 253 253 253 253 231 231 231 250 250 250
40742 -253 253 253 253 253 253 253 253 253 253 253 253
40743 -253 253 253 253 253 253 253 253 253 253 253 253
40744 -253 253 253 253 253 253 253 253 253 253 253 253
40745 -253 253 253 253 253 253 253 253 253 246 230 190
40746 -238 204 91 238 204 91 181 142 44 37 26 9
40747 - 2 2 6 2 2 6 2 2 6 2 2 6
40748 - 2 2 6 2 2 6 38 38 38 46 46 46
40749 - 26 26 26 106 106 106 54 54 54 18 18 18
40750 - 6 6 6 0 0 0 0 0 0 0 0 0
40751 - 0 0 0 0 0 0 0 0 0 0 0 0
40752 - 0 0 0 0 0 0 0 0 0 0 0 0
40753 - 0 0 0 0 0 0 0 0 0 0 0 0
40754 - 0 0 0 0 0 0 0 0 0 0 0 0
40755 - 0 0 0 6 6 6 14 14 14 22 22 22
40756 - 30 30 30 38 38 38 50 50 50 70 70 70
40757 -106 106 106 190 142 34 226 170 11 242 186 14
40758 -246 190 14 246 190 14 246 190 14 154 114 10
40759 - 6 6 6 74 74 74 226 226 226 253 253 253
40760 -253 253 253 253 253 253 253 253 253 253 253 253
40761 -253 253 253 253 253 253 231 231 231 250 250 250
40762 -253 253 253 253 253 253 253 253 253 253 253 253
40763 -253 253 253 253 253 253 253 253 253 253 253 253
40764 -253 253 253 253 253 253 253 253 253 253 253 253
40765 -253 253 253 253 253 253 253 253 253 228 184 62
40766 -241 196 14 241 208 19 232 195 16 38 30 10
40767 - 2 2 6 2 2 6 2 2 6 2 2 6
40768 - 2 2 6 6 6 6 30 30 30 26 26 26
40769 -203 166 17 154 142 90 66 66 66 26 26 26
40770 - 6 6 6 0 0 0 0 0 0 0 0 0
40771 - 0 0 0 0 0 0 0 0 0 0 0 0
40772 - 0 0 0 0 0 0 0 0 0 0 0 0
40773 - 0 0 0 0 0 0 0 0 0 0 0 0
40774 - 0 0 0 0 0 0 0 0 0 0 0 0
40775 - 6 6 6 18 18 18 38 38 38 58 58 58
40776 - 78 78 78 86 86 86 101 101 101 123 123 123
40777 -175 146 61 210 150 10 234 174 13 246 186 14
40778 -246 190 14 246 190 14 246 190 14 238 190 10
40779 -102 78 10 2 2 6 46 46 46 198 198 198
40780 -253 253 253 253 253 253 253 253 253 253 253 253
40781 -253 253 253 253 253 253 234 234 234 242 242 242
40782 -253 253 253 253 253 253 253 253 253 253 253 253
40783 -253 253 253 253 253 253 253 253 253 253 253 253
40784 -253 253 253 253 253 253 253 253 253 253 253 253
40785 -253 253 253 253 253 253 253 253 253 224 178 62
40786 -242 186 14 241 196 14 210 166 10 22 18 6
40787 - 2 2 6 2 2 6 2 2 6 2 2 6
40788 - 2 2 6 2 2 6 6 6 6 121 92 8
40789 -238 202 15 232 195 16 82 82 82 34 34 34
40790 - 10 10 10 0 0 0 0 0 0 0 0 0
40791 - 0 0 0 0 0 0 0 0 0 0 0 0
40792 - 0 0 0 0 0 0 0 0 0 0 0 0
40793 - 0 0 0 0 0 0 0 0 0 0 0 0
40794 - 0 0 0 0 0 0 0 0 0 0 0 0
40795 - 14 14 14 38 38 38 70 70 70 154 122 46
40796 -190 142 34 200 144 11 197 138 11 197 138 11
40797 -213 154 11 226 170 11 242 186 14 246 190 14
40798 -246 190 14 246 190 14 246 190 14 246 190 14
40799 -225 175 15 46 32 6 2 2 6 22 22 22
40800 -158 158 158 250 250 250 253 253 253 253 253 253
40801 -253 253 253 253 253 253 253 253 253 253 253 253
40802 -253 253 253 253 253 253 253 253 253 253 253 253
40803 -253 253 253 253 253 253 253 253 253 253 253 253
40804 -253 253 253 253 253 253 253 253 253 253 253 253
40805 -253 253 253 250 250 250 242 242 242 224 178 62
40806 -239 182 13 236 186 11 213 154 11 46 32 6
40807 - 2 2 6 2 2 6 2 2 6 2 2 6
40808 - 2 2 6 2 2 6 61 42 6 225 175 15
40809 -238 190 10 236 186 11 112 100 78 42 42 42
40810 - 14 14 14 0 0 0 0 0 0 0 0 0
40811 - 0 0 0 0 0 0 0 0 0 0 0 0
40812 - 0 0 0 0 0 0 0 0 0 0 0 0
40813 - 0 0 0 0 0 0 0 0 0 0 0 0
40814 - 0 0 0 0 0 0 0 0 0 6 6 6
40815 - 22 22 22 54 54 54 154 122 46 213 154 11
40816 -226 170 11 230 174 11 226 170 11 226 170 11
40817 -236 178 12 242 186 14 246 190 14 246 190 14
40818 -246 190 14 246 190 14 246 190 14 246 190 14
40819 -241 196 14 184 144 12 10 10 10 2 2 6
40820 - 6 6 6 116 116 116 242 242 242 253 253 253
40821 -253 253 253 253 253 253 253 253 253 253 253 253
40822 -253 253 253 253 253 253 253 253 253 253 253 253
40823 -253 253 253 253 253 253 253 253 253 253 253 253
40824 -253 253 253 253 253 253 253 253 253 253 253 253
40825 -253 253 253 231 231 231 198 198 198 214 170 54
40826 -236 178 12 236 178 12 210 150 10 137 92 6
40827 - 18 14 6 2 2 6 2 2 6 2 2 6
40828 - 6 6 6 70 47 6 200 144 11 236 178 12
40829 -239 182 13 239 182 13 124 112 88 58 58 58
40830 - 22 22 22 6 6 6 0 0 0 0 0 0
40831 - 0 0 0 0 0 0 0 0 0 0 0 0
40832 - 0 0 0 0 0 0 0 0 0 0 0 0
40833 - 0 0 0 0 0 0 0 0 0 0 0 0
40834 - 0 0 0 0 0 0 0 0 0 10 10 10
40835 - 30 30 30 70 70 70 180 133 36 226 170 11
40836 -239 182 13 242 186 14 242 186 14 246 186 14
40837 -246 190 14 246 190 14 246 190 14 246 190 14
40838 -246 190 14 246 190 14 246 190 14 246 190 14
40839 -246 190 14 232 195 16 98 70 6 2 2 6
40840 - 2 2 6 2 2 6 66 66 66 221 221 221
40841 -253 253 253 253 253 253 253 253 253 253 253 253
40842 -253 253 253 253 253 253 253 253 253 253 253 253
40843 -253 253 253 253 253 253 253 253 253 253 253 253
40844 -253 253 253 253 253 253 253 253 253 253 253 253
40845 -253 253 253 206 206 206 198 198 198 214 166 58
40846 -230 174 11 230 174 11 216 158 10 192 133 9
40847 -163 110 8 116 81 8 102 78 10 116 81 8
40848 -167 114 7 197 138 11 226 170 11 239 182 13
40849 -242 186 14 242 186 14 162 146 94 78 78 78
40850 - 34 34 34 14 14 14 6 6 6 0 0 0
40851 - 0 0 0 0 0 0 0 0 0 0 0 0
40852 - 0 0 0 0 0 0 0 0 0 0 0 0
40853 - 0 0 0 0 0 0 0 0 0 0 0 0
40854 - 0 0 0 0 0 0 0 0 0 6 6 6
40855 - 30 30 30 78 78 78 190 142 34 226 170 11
40856 -239 182 13 246 190 14 246 190 14 246 190 14
40857 -246 190 14 246 190 14 246 190 14 246 190 14
40858 -246 190 14 246 190 14 246 190 14 246 190 14
40859 -246 190 14 241 196 14 203 166 17 22 18 6
40860 - 2 2 6 2 2 6 2 2 6 38 38 38
40861 -218 218 218 253 253 253 253 253 253 253 253 253
40862 -253 253 253 253 253 253 253 253 253 253 253 253
40863 -253 253 253 253 253 253 253 253 253 253 253 253
40864 -253 253 253 253 253 253 253 253 253 253 253 253
40865 -250 250 250 206 206 206 198 198 198 202 162 69
40866 -226 170 11 236 178 12 224 166 10 210 150 10
40867 -200 144 11 197 138 11 192 133 9 197 138 11
40868 -210 150 10 226 170 11 242 186 14 246 190 14
40869 -246 190 14 246 186 14 225 175 15 124 112 88
40870 - 62 62 62 30 30 30 14 14 14 6 6 6
40871 - 0 0 0 0 0 0 0 0 0 0 0 0
40872 - 0 0 0 0 0 0 0 0 0 0 0 0
40873 - 0 0 0 0 0 0 0 0 0 0 0 0
40874 - 0 0 0 0 0 0 0 0 0 10 10 10
40875 - 30 30 30 78 78 78 174 135 50 224 166 10
40876 -239 182 13 246 190 14 246 190 14 246 190 14
40877 -246 190 14 246 190 14 246 190 14 246 190 14
40878 -246 190 14 246 190 14 246 190 14 246 190 14
40879 -246 190 14 246 190 14 241 196 14 139 102 15
40880 - 2 2 6 2 2 6 2 2 6 2 2 6
40881 - 78 78 78 250 250 250 253 253 253 253 253 253
40882 -253 253 253 253 253 253 253 253 253 253 253 253
40883 -253 253 253 253 253 253 253 253 253 253 253 253
40884 -253 253 253 253 253 253 253 253 253 253 253 253
40885 -250 250 250 214 214 214 198 198 198 190 150 46
40886 -219 162 10 236 178 12 234 174 13 224 166 10
40887 -216 158 10 213 154 11 213 154 11 216 158 10
40888 -226 170 11 239 182 13 246 190 14 246 190 14
40889 -246 190 14 246 190 14 242 186 14 206 162 42
40890 -101 101 101 58 58 58 30 30 30 14 14 14
40891 - 6 6 6 0 0 0 0 0 0 0 0 0
40892 - 0 0 0 0 0 0 0 0 0 0 0 0
40893 - 0 0 0 0 0 0 0 0 0 0 0 0
40894 - 0 0 0 0 0 0 0 0 0 10 10 10
40895 - 30 30 30 74 74 74 174 135 50 216 158 10
40896 -236 178 12 246 190 14 246 190 14 246 190 14
40897 -246 190 14 246 190 14 246 190 14 246 190 14
40898 -246 190 14 246 190 14 246 190 14 246 190 14
40899 -246 190 14 246 190 14 241 196 14 226 184 13
40900 - 61 42 6 2 2 6 2 2 6 2 2 6
40901 - 22 22 22 238 238 238 253 253 253 253 253 253
40902 -253 253 253 253 253 253 253 253 253 253 253 253
40903 -253 253 253 253 253 253 253 253 253 253 253 253
40904 -253 253 253 253 253 253 253 253 253 253 253 253
40905 -253 253 253 226 226 226 187 187 187 180 133 36
40906 -216 158 10 236 178 12 239 182 13 236 178 12
40907 -230 174 11 226 170 11 226 170 11 230 174 11
40908 -236 178 12 242 186 14 246 190 14 246 190 14
40909 -246 190 14 246 190 14 246 186 14 239 182 13
40910 -206 162 42 106 106 106 66 66 66 34 34 34
40911 - 14 14 14 6 6 6 0 0 0 0 0 0
40912 - 0 0 0 0 0 0 0 0 0 0 0 0
40913 - 0 0 0 0 0 0 0 0 0 0 0 0
40914 - 0 0 0 0 0 0 0 0 0 6 6 6
40915 - 26 26 26 70 70 70 163 133 67 213 154 11
40916 -236 178 12 246 190 14 246 190 14 246 190 14
40917 -246 190 14 246 190 14 246 190 14 246 190 14
40918 -246 190 14 246 190 14 246 190 14 246 190 14
40919 -246 190 14 246 190 14 246 190 14 241 196 14
40920 -190 146 13 18 14 6 2 2 6 2 2 6
40921 - 46 46 46 246 246 246 253 253 253 253 253 253
40922 -253 253 253 253 253 253 253 253 253 253 253 253
40923 -253 253 253 253 253 253 253 253 253 253 253 253
40924 -253 253 253 253 253 253 253 253 253 253 253 253
40925 -253 253 253 221 221 221 86 86 86 156 107 11
40926 -216 158 10 236 178 12 242 186 14 246 186 14
40927 -242 186 14 239 182 13 239 182 13 242 186 14
40928 -242 186 14 246 186 14 246 190 14 246 190 14
40929 -246 190 14 246 190 14 246 190 14 246 190 14
40930 -242 186 14 225 175 15 142 122 72 66 66 66
40931 - 30 30 30 10 10 10 0 0 0 0 0 0
40932 - 0 0 0 0 0 0 0 0 0 0 0 0
40933 - 0 0 0 0 0 0 0 0 0 0 0 0
40934 - 0 0 0 0 0 0 0 0 0 6 6 6
40935 - 26 26 26 70 70 70 163 133 67 210 150 10
40936 -236 178 12 246 190 14 246 190 14 246 190 14
40937 -246 190 14 246 190 14 246 190 14 246 190 14
40938 -246 190 14 246 190 14 246 190 14 246 190 14
40939 -246 190 14 246 190 14 246 190 14 246 190 14
40940 -232 195 16 121 92 8 34 34 34 106 106 106
40941 -221 221 221 253 253 253 253 253 253 253 253 253
40942 -253 253 253 253 253 253 253 253 253 253 253 253
40943 -253 253 253 253 253 253 253 253 253 253 253 253
40944 -253 253 253 253 253 253 253 253 253 253 253 253
40945 -242 242 242 82 82 82 18 14 6 163 110 8
40946 -216 158 10 236 178 12 242 186 14 246 190 14
40947 -246 190 14 246 190 14 246 190 14 246 190 14
40948 -246 190 14 246 190 14 246 190 14 246 190 14
40949 -246 190 14 246 190 14 246 190 14 246 190 14
40950 -246 190 14 246 190 14 242 186 14 163 133 67
40951 - 46 46 46 18 18 18 6 6 6 0 0 0
40952 - 0 0 0 0 0 0 0 0 0 0 0 0
40953 - 0 0 0 0 0 0 0 0 0 0 0 0
40954 - 0 0 0 0 0 0 0 0 0 10 10 10
40955 - 30 30 30 78 78 78 163 133 67 210 150 10
40956 -236 178 12 246 186 14 246 190 14 246 190 14
40957 -246 190 14 246 190 14 246 190 14 246 190 14
40958 -246 190 14 246 190 14 246 190 14 246 190 14
40959 -246 190 14 246 190 14 246 190 14 246 190 14
40960 -241 196 14 215 174 15 190 178 144 253 253 253
40961 -253 253 253 253 253 253 253 253 253 253 253 253
40962 -253 253 253 253 253 253 253 253 253 253 253 253
40963 -253 253 253 253 253 253 253 253 253 253 253 253
40964 -253 253 253 253 253 253 253 253 253 218 218 218
40965 - 58 58 58 2 2 6 22 18 6 167 114 7
40966 -216 158 10 236 178 12 246 186 14 246 190 14
40967 -246 190 14 246 190 14 246 190 14 246 190 14
40968 -246 190 14 246 190 14 246 190 14 246 190 14
40969 -246 190 14 246 190 14 246 190 14 246 190 14
40970 -246 190 14 246 186 14 242 186 14 190 150 46
40971 - 54 54 54 22 22 22 6 6 6 0 0 0
40972 - 0 0 0 0 0 0 0 0 0 0 0 0
40973 - 0 0 0 0 0 0 0 0 0 0 0 0
40974 - 0 0 0 0 0 0 0 0 0 14 14 14
40975 - 38 38 38 86 86 86 180 133 36 213 154 11
40976 -236 178 12 246 186 14 246 190 14 246 190 14
40977 -246 190 14 246 190 14 246 190 14 246 190 14
40978 -246 190 14 246 190 14 246 190 14 246 190 14
40979 -246 190 14 246 190 14 246 190 14 246 190 14
40980 -246 190 14 232 195 16 190 146 13 214 214 214
40981 -253 253 253 253 253 253 253 253 253 253 253 253
40982 -253 253 253 253 253 253 253 253 253 253 253 253
40983 -253 253 253 253 253 253 253 253 253 253 253 253
40984 -253 253 253 250 250 250 170 170 170 26 26 26
40985 - 2 2 6 2 2 6 37 26 9 163 110 8
40986 -219 162 10 239 182 13 246 186 14 246 190 14
40987 -246 190 14 246 190 14 246 190 14 246 190 14
40988 -246 190 14 246 190 14 246 190 14 246 190 14
40989 -246 190 14 246 190 14 246 190 14 246 190 14
40990 -246 186 14 236 178 12 224 166 10 142 122 72
40991 - 46 46 46 18 18 18 6 6 6 0 0 0
40992 - 0 0 0 0 0 0 0 0 0 0 0 0
40993 - 0 0 0 0 0 0 0 0 0 0 0 0
40994 - 0 0 0 0 0 0 6 6 6 18 18 18
40995 - 50 50 50 109 106 95 192 133 9 224 166 10
40996 -242 186 14 246 190 14 246 190 14 246 190 14
40997 -246 190 14 246 190 14 246 190 14 246 190 14
40998 -246 190 14 246 190 14 246 190 14 246 190 14
40999 -246 190 14 246 190 14 246 190 14 246 190 14
41000 -242 186 14 226 184 13 210 162 10 142 110 46
41001 -226 226 226 253 253 253 253 253 253 253 253 253
41002 -253 253 253 253 253 253 253 253 253 253 253 253
41003 -253 253 253 253 253 253 253 253 253 253 253 253
41004 -198 198 198 66 66 66 2 2 6 2 2 6
41005 - 2 2 6 2 2 6 50 34 6 156 107 11
41006 -219 162 10 239 182 13 246 186 14 246 190 14
41007 -246 190 14 246 190 14 246 190 14 246 190 14
41008 -246 190 14 246 190 14 246 190 14 246 190 14
41009 -246 190 14 246 190 14 246 190 14 242 186 14
41010 -234 174 13 213 154 11 154 122 46 66 66 66
41011 - 30 30 30 10 10 10 0 0 0 0 0 0
41012 - 0 0 0 0 0 0 0 0 0 0 0 0
41013 - 0 0 0 0 0 0 0 0 0 0 0 0
41014 - 0 0 0 0 0 0 6 6 6 22 22 22
41015 - 58 58 58 154 121 60 206 145 10 234 174 13
41016 -242 186 14 246 186 14 246 190 14 246 190 14
41017 -246 190 14 246 190 14 246 190 14 246 190 14
41018 -246 190 14 246 190 14 246 190 14 246 190 14
41019 -246 190 14 246 190 14 246 190 14 246 190 14
41020 -246 186 14 236 178 12 210 162 10 163 110 8
41021 - 61 42 6 138 138 138 218 218 218 250 250 250
41022 -253 253 253 253 253 253 253 253 253 250 250 250
41023 -242 242 242 210 210 210 144 144 144 66 66 66
41024 - 6 6 6 2 2 6 2 2 6 2 2 6
41025 - 2 2 6 2 2 6 61 42 6 163 110 8
41026 -216 158 10 236 178 12 246 190 14 246 190 14
41027 -246 190 14 246 190 14 246 190 14 246 190 14
41028 -246 190 14 246 190 14 246 190 14 246 190 14
41029 -246 190 14 239 182 13 230 174 11 216 158 10
41030 -190 142 34 124 112 88 70 70 70 38 38 38
41031 - 18 18 18 6 6 6 0 0 0 0 0 0
41032 - 0 0 0 0 0 0 0 0 0 0 0 0
41033 - 0 0 0 0 0 0 0 0 0 0 0 0
41034 - 0 0 0 0 0 0 6 6 6 22 22 22
41035 - 62 62 62 168 124 44 206 145 10 224 166 10
41036 -236 178 12 239 182 13 242 186 14 242 186 14
41037 -246 186 14 246 190 14 246 190 14 246 190 14
41038 -246 190 14 246 190 14 246 190 14 246 190 14
41039 -246 190 14 246 190 14 246 190 14 246 190 14
41040 -246 190 14 236 178 12 216 158 10 175 118 6
41041 - 80 54 7 2 2 6 6 6 6 30 30 30
41042 - 54 54 54 62 62 62 50 50 50 38 38 38
41043 - 14 14 14 2 2 6 2 2 6 2 2 6
41044 - 2 2 6 2 2 6 2 2 6 2 2 6
41045 - 2 2 6 6 6 6 80 54 7 167 114 7
41046 -213 154 11 236 178 12 246 190 14 246 190 14
41047 -246 190 14 246 190 14 246 190 14 246 190 14
41048 -246 190 14 242 186 14 239 182 13 239 182 13
41049 -230 174 11 210 150 10 174 135 50 124 112 88
41050 - 82 82 82 54 54 54 34 34 34 18 18 18
41051 - 6 6 6 0 0 0 0 0 0 0 0 0
41052 - 0 0 0 0 0 0 0 0 0 0 0 0
41053 - 0 0 0 0 0 0 0 0 0 0 0 0
41054 - 0 0 0 0 0 0 6 6 6 18 18 18
41055 - 50 50 50 158 118 36 192 133 9 200 144 11
41056 -216 158 10 219 162 10 224 166 10 226 170 11
41057 -230 174 11 236 178 12 239 182 13 239 182 13
41058 -242 186 14 246 186 14 246 190 14 246 190 14
41059 -246 190 14 246 190 14 246 190 14 246 190 14
41060 -246 186 14 230 174 11 210 150 10 163 110 8
41061 -104 69 6 10 10 10 2 2 6 2 2 6
41062 - 2 2 6 2 2 6 2 2 6 2 2 6
41063 - 2 2 6 2 2 6 2 2 6 2 2 6
41064 - 2 2 6 2 2 6 2 2 6 2 2 6
41065 - 2 2 6 6 6 6 91 60 6 167 114 7
41066 -206 145 10 230 174 11 242 186 14 246 190 14
41067 -246 190 14 246 190 14 246 186 14 242 186 14
41068 -239 182 13 230 174 11 224 166 10 213 154 11
41069 -180 133 36 124 112 88 86 86 86 58 58 58
41070 - 38 38 38 22 22 22 10 10 10 6 6 6
41071 - 0 0 0 0 0 0 0 0 0 0 0 0
41072 - 0 0 0 0 0 0 0 0 0 0 0 0
41073 - 0 0 0 0 0 0 0 0 0 0 0 0
41074 - 0 0 0 0 0 0 0 0 0 14 14 14
41075 - 34 34 34 70 70 70 138 110 50 158 118 36
41076 -167 114 7 180 123 7 192 133 9 197 138 11
41077 -200 144 11 206 145 10 213 154 11 219 162 10
41078 -224 166 10 230 174 11 239 182 13 242 186 14
41079 -246 186 14 246 186 14 246 186 14 246 186 14
41080 -239 182 13 216 158 10 185 133 11 152 99 6
41081 -104 69 6 18 14 6 2 2 6 2 2 6
41082 - 2 2 6 2 2 6 2 2 6 2 2 6
41083 - 2 2 6 2 2 6 2 2 6 2 2 6
41084 - 2 2 6 2 2 6 2 2 6 2 2 6
41085 - 2 2 6 6 6 6 80 54 7 152 99 6
41086 -192 133 9 219 162 10 236 178 12 239 182 13
41087 -246 186 14 242 186 14 239 182 13 236 178 12
41088 -224 166 10 206 145 10 192 133 9 154 121 60
41089 - 94 94 94 62 62 62 42 42 42 22 22 22
41090 - 14 14 14 6 6 6 0 0 0 0 0 0
41091 - 0 0 0 0 0 0 0 0 0 0 0 0
41092 - 0 0 0 0 0 0 0 0 0 0 0 0
41093 - 0 0 0 0 0 0 0 0 0 0 0 0
41094 - 0 0 0 0 0 0 0 0 0 6 6 6
41095 - 18 18 18 34 34 34 58 58 58 78 78 78
41096 -101 98 89 124 112 88 142 110 46 156 107 11
41097 -163 110 8 167 114 7 175 118 6 180 123 7
41098 -185 133 11 197 138 11 210 150 10 219 162 10
41099 -226 170 11 236 178 12 236 178 12 234 174 13
41100 -219 162 10 197 138 11 163 110 8 130 83 6
41101 - 91 60 6 10 10 10 2 2 6 2 2 6
41102 - 18 18 18 38 38 38 38 38 38 38 38 38
41103 - 38 38 38 38 38 38 38 38 38 38 38 38
41104 - 38 38 38 38 38 38 26 26 26 2 2 6
41105 - 2 2 6 6 6 6 70 47 6 137 92 6
41106 -175 118 6 200 144 11 219 162 10 230 174 11
41107 -234 174 13 230 174 11 219 162 10 210 150 10
41108 -192 133 9 163 110 8 124 112 88 82 82 82
41109 - 50 50 50 30 30 30 14 14 14 6 6 6
41110 - 0 0 0 0 0 0 0 0 0 0 0 0
41111 - 0 0 0 0 0 0 0 0 0 0 0 0
41112 - 0 0 0 0 0 0 0 0 0 0 0 0
41113 - 0 0 0 0 0 0 0 0 0 0 0 0
41114 - 0 0 0 0 0 0 0 0 0 0 0 0
41115 - 6 6 6 14 14 14 22 22 22 34 34 34
41116 - 42 42 42 58 58 58 74 74 74 86 86 86
41117 -101 98 89 122 102 70 130 98 46 121 87 25
41118 -137 92 6 152 99 6 163 110 8 180 123 7
41119 -185 133 11 197 138 11 206 145 10 200 144 11
41120 -180 123 7 156 107 11 130 83 6 104 69 6
41121 - 50 34 6 54 54 54 110 110 110 101 98 89
41122 - 86 86 86 82 82 82 78 78 78 78 78 78
41123 - 78 78 78 78 78 78 78 78 78 78 78 78
41124 - 78 78 78 82 82 82 86 86 86 94 94 94
41125 -106 106 106 101 101 101 86 66 34 124 80 6
41126 -156 107 11 180 123 7 192 133 9 200 144 11
41127 -206 145 10 200 144 11 192 133 9 175 118 6
41128 -139 102 15 109 106 95 70 70 70 42 42 42
41129 - 22 22 22 10 10 10 0 0 0 0 0 0
41130 - 0 0 0 0 0 0 0 0 0 0 0 0
41131 - 0 0 0 0 0 0 0 0 0 0 0 0
41132 - 0 0 0 0 0 0 0 0 0 0 0 0
41133 - 0 0 0 0 0 0 0 0 0 0 0 0
41134 - 0 0 0 0 0 0 0 0 0 0 0 0
41135 - 0 0 0 0 0 0 6 6 6 10 10 10
41136 - 14 14 14 22 22 22 30 30 30 38 38 38
41137 - 50 50 50 62 62 62 74 74 74 90 90 90
41138 -101 98 89 112 100 78 121 87 25 124 80 6
41139 -137 92 6 152 99 6 152 99 6 152 99 6
41140 -138 86 6 124 80 6 98 70 6 86 66 30
41141 -101 98 89 82 82 82 58 58 58 46 46 46
41142 - 38 38 38 34 34 34 34 34 34 34 34 34
41143 - 34 34 34 34 34 34 34 34 34 34 34 34
41144 - 34 34 34 34 34 34 38 38 38 42 42 42
41145 - 54 54 54 82 82 82 94 86 76 91 60 6
41146 -134 86 6 156 107 11 167 114 7 175 118 6
41147 -175 118 6 167 114 7 152 99 6 121 87 25
41148 -101 98 89 62 62 62 34 34 34 18 18 18
41149 - 6 6 6 0 0 0 0 0 0 0 0 0
41150 - 0 0 0 0 0 0 0 0 0 0 0 0
41151 - 0 0 0 0 0 0 0 0 0 0 0 0
41152 - 0 0 0 0 0 0 0 0 0 0 0 0
41153 - 0 0 0 0 0 0 0 0 0 0 0 0
41154 - 0 0 0 0 0 0 0 0 0 0 0 0
41155 - 0 0 0 0 0 0 0 0 0 0 0 0
41156 - 0 0 0 6 6 6 6 6 6 10 10 10
41157 - 18 18 18 22 22 22 30 30 30 42 42 42
41158 - 50 50 50 66 66 66 86 86 86 101 98 89
41159 -106 86 58 98 70 6 104 69 6 104 69 6
41160 -104 69 6 91 60 6 82 62 34 90 90 90
41161 - 62 62 62 38 38 38 22 22 22 14 14 14
41162 - 10 10 10 10 10 10 10 10 10 10 10 10
41163 - 10 10 10 10 10 10 6 6 6 10 10 10
41164 - 10 10 10 10 10 10 10 10 10 14 14 14
41165 - 22 22 22 42 42 42 70 70 70 89 81 66
41166 - 80 54 7 104 69 6 124 80 6 137 92 6
41167 -134 86 6 116 81 8 100 82 52 86 86 86
41168 - 58 58 58 30 30 30 14 14 14 6 6 6
41169 - 0 0 0 0 0 0 0 0 0 0 0 0
41170 - 0 0 0 0 0 0 0 0 0 0 0 0
41171 - 0 0 0 0 0 0 0 0 0 0 0 0
41172 - 0 0 0 0 0 0 0 0 0 0 0 0
41173 - 0 0 0 0 0 0 0 0 0 0 0 0
41174 - 0 0 0 0 0 0 0 0 0 0 0 0
41175 - 0 0 0 0 0 0 0 0 0 0 0 0
41176 - 0 0 0 0 0 0 0 0 0 0 0 0
41177 - 0 0 0 6 6 6 10 10 10 14 14 14
41178 - 18 18 18 26 26 26 38 38 38 54 54 54
41179 - 70 70 70 86 86 86 94 86 76 89 81 66
41180 - 89 81 66 86 86 86 74 74 74 50 50 50
41181 - 30 30 30 14 14 14 6 6 6 0 0 0
41182 - 0 0 0 0 0 0 0 0 0 0 0 0
41183 - 0 0 0 0 0 0 0 0 0 0 0 0
41184 - 0 0 0 0 0 0 0 0 0 0 0 0
41185 - 6 6 6 18 18 18 34 34 34 58 58 58
41186 - 82 82 82 89 81 66 89 81 66 89 81 66
41187 - 94 86 66 94 86 76 74 74 74 50 50 50
41188 - 26 26 26 14 14 14 6 6 6 0 0 0
41189 - 0 0 0 0 0 0 0 0 0 0 0 0
41190 - 0 0 0 0 0 0 0 0 0 0 0 0
41191 - 0 0 0 0 0 0 0 0 0 0 0 0
41192 - 0 0 0 0 0 0 0 0 0 0 0 0
41193 - 0 0 0 0 0 0 0 0 0 0 0 0
41194 - 0 0 0 0 0 0 0 0 0 0 0 0
41195 - 0 0 0 0 0 0 0 0 0 0 0 0
41196 - 0 0 0 0 0 0 0 0 0 0 0 0
41197 - 0 0 0 0 0 0 0 0 0 0 0 0
41198 - 6 6 6 6 6 6 14 14 14 18 18 18
41199 - 30 30 30 38 38 38 46 46 46 54 54 54
41200 - 50 50 50 42 42 42 30 30 30 18 18 18
41201 - 10 10 10 0 0 0 0 0 0 0 0 0
41202 - 0 0 0 0 0 0 0 0 0 0 0 0
41203 - 0 0 0 0 0 0 0 0 0 0 0 0
41204 - 0 0 0 0 0 0 0 0 0 0 0 0
41205 - 0 0 0 6 6 6 14 14 14 26 26 26
41206 - 38 38 38 50 50 50 58 58 58 58 58 58
41207 - 54 54 54 42 42 42 30 30 30 18 18 18
41208 - 10 10 10 0 0 0 0 0 0 0 0 0
41209 - 0 0 0 0 0 0 0 0 0 0 0 0
41210 - 0 0 0 0 0 0 0 0 0 0 0 0
41211 - 0 0 0 0 0 0 0 0 0 0 0 0
41212 - 0 0 0 0 0 0 0 0 0 0 0 0
41213 - 0 0 0 0 0 0 0 0 0 0 0 0
41214 - 0 0 0 0 0 0 0 0 0 0 0 0
41215 - 0 0 0 0 0 0 0 0 0 0 0 0
41216 - 0 0 0 0 0 0 0 0 0 0 0 0
41217 - 0 0 0 0 0 0 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 6 6 6
41219 - 6 6 6 10 10 10 14 14 14 18 18 18
41220 - 18 18 18 14 14 14 10 10 10 6 6 6
41221 - 0 0 0 0 0 0 0 0 0 0 0 0
41222 - 0 0 0 0 0 0 0 0 0 0 0 0
41223 - 0 0 0 0 0 0 0 0 0 0 0 0
41224 - 0 0 0 0 0 0 0 0 0 0 0 0
41225 - 0 0 0 0 0 0 0 0 0 6 6 6
41226 - 14 14 14 18 18 18 22 22 22 22 22 22
41227 - 18 18 18 14 14 14 10 10 10 6 6 6
41228 - 0 0 0 0 0 0 0 0 0 0 0 0
41229 - 0 0 0 0 0 0 0 0 0 0 0 0
41230 - 0 0 0 0 0 0 0 0 0 0 0 0
41231 - 0 0 0 0 0 0 0 0 0 0 0 0
41232 - 0 0 0 0 0 0 0 0 0 0 0 0
41233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246 +4 4 4 4 4 4
41247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41260 +4 4 4 4 4 4
41261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274 +4 4 4 4 4 4
41275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4
41289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 4 4 4
41303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4
41317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41322 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41327 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4
41331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41336 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41337 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41341 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41342 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41343 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41350 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41351 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41355 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41356 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41357 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41363 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41364 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41365 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41368 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41369 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41370 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41371 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41372 +4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41376 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41377 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41378 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41379 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41380 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41382 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41383 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41384 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41385 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4
41387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41390 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41391 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41392 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41393 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41394 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41395 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41396 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41397 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41398 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41399 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41400 +4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41404 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41405 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41406 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41407 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41408 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41409 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41410 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41411 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41412 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41413 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41414 +4 4 4 4 4 4
41415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41417 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41418 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41419 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41420 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41421 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41422 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41423 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41424 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41425 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41426 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41427 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41428 +4 4 4 4 4 4
41429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41431 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41432 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41433 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41434 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41435 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41436 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41437 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41438 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41439 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41440 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41441 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41442 +4 4 4 4 4 4
41443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41446 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41447 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41448 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41449 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41450 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41451 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41452 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41453 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41454 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41455 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41456 +4 4 4 4 4 4
41457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41459 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41460 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41461 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41462 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41463 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41464 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41465 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41466 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41467 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41468 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41469 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41470 +4 4 4 4 4 4
41471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41472 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41473 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41474 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41475 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41476 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41477 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41478 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41479 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41480 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41481 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41482 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41483 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41484 +0 0 0 4 4 4
41485 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41486 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41487 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41488 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41489 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41490 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41491 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41492 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41493 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41494 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41495 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41496 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41497 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41498 +2 0 0 0 0 0
41499 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41500 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41501 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41502 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41503 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41504 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41505 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41506 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41507 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41508 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41509 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41510 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41511 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41512 +37 38 37 0 0 0
41513 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41514 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41515 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41516 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41517 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41518 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41519 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41520 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41521 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41522 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41523 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41524 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41525 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41526 +85 115 134 4 0 0
41527 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41528 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41529 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41530 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41531 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41532 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41533 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41534 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41535 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41536 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41537 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41538 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41539 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41540 +60 73 81 4 0 0
41541 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41542 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41543 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41544 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41545 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41546 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41547 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41548 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41549 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41550 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41551 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41552 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41553 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41554 +16 19 21 4 0 0
41555 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41556 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41557 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41558 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41559 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41560 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41561 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41562 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41563 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41564 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41565 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41566 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41567 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41568 +4 0 0 4 3 3
41569 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41570 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41571 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41573 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41574 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41575 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41576 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41577 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41578 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41579 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41580 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41581 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41582 +3 2 2 4 4 4
41583 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41584 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41585 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41586 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41587 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41588 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41589 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41590 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41591 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41592 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41593 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41594 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41595 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41596 +4 4 4 4 4 4
41597 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41598 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41599 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41600 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41601 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41602 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41603 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41604 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41605 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41606 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41607 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41608 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41609 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41610 +4 4 4 4 4 4
41611 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41612 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41613 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41614 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41615 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41616 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41617 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41618 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41619 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41620 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41621 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41622 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41623 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41624 +5 5 5 5 5 5
41625 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41626 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41627 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41628 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41629 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41630 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41631 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41632 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41633 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41634 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41635 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41636 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41637 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41638 +5 5 5 4 4 4
41639 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41640 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41641 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41642 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41643 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41644 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41645 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41646 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41647 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41648 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41649 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41650 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41652 +4 4 4 4 4 4
41653 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41654 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41655 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41656 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41657 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41658 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41659 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41660 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41661 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41662 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41663 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41664 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41666 +4 4 4 4 4 4
41667 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41668 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41669 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41670 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41671 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41672 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41673 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41674 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41675 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41676 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41677 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41680 +4 4 4 4 4 4
41681 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41682 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41683 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41684 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41685 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41686 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41687 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41688 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41689 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41690 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41691 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41694 +4 4 4 4 4 4
41695 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41696 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41697 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41698 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41699 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41700 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41701 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41702 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41703 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41704 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41705 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41708 +4 4 4 4 4 4
41709 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41710 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41711 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41712 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41713 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41714 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41715 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41716 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41717 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41718 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41719 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41722 +4 4 4 4 4 4
41723 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41724 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41725 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41726 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41727 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41728 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41729 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41730 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41731 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41732 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41733 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41736 +4 4 4 4 4 4
41737 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41738 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41739 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41740 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41741 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41742 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41743 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41744 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41745 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41746 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41747 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41750 +4 4 4 4 4 4
41751 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41752 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41753 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41754 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41755 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41756 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41757 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41758 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41759 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41760 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41761 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41764 +4 4 4 4 4 4
41765 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41766 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41767 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41768 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41769 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41770 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41771 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41772 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41773 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41774 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41775 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41778 +4 4 4 4 4 4
41779 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41780 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41781 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41782 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41783 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41784 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41785 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41786 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41787 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41788 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41789 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41792 +4 4 4 4 4 4
41793 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41794 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41795 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41796 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41797 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41798 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41799 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41800 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41801 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41802 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41803 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41806 +4 4 4 4 4 4
41807 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41808 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41809 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41810 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41811 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41812 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41813 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41814 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41815 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41816 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41817 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41820 +4 4 4 4 4 4
41821 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41822 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41823 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41824 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41825 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41826 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41827 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41828 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41829 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41830 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41831 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41834 +4 4 4 4 4 4
41835 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41836 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41837 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41838 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41839 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41840 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41841 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41842 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41843 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41844 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41845 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41848 +4 4 4 4 4 4
41849 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41850 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41851 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41852 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41853 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41854 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41855 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41856 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41857 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41858 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41859 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41862 +4 4 4 4 4 4
41863 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41864 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41865 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41866 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41867 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41868 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41869 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41870 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41871 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41872 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41873 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41876 +4 4 4 4 4 4
41877 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41878 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41879 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41880 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41881 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41882 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41883 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41884 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41885 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41886 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41887 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41890 +4 4 4 4 4 4
41891 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41892 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41893 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41894 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41895 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41896 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41897 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41898 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41899 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41900 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41901 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41904 +4 4 4 4 4 4
41905 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41906 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41907 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41908 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41909 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41910 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41911 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41912 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41913 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41914 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41915 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41918 +4 4 4 4 4 4
41919 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41920 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41921 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41922 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41923 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41924 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41925 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41926 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41927 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41928 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41929 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41932 +4 4 4 4 4 4
41933 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41934 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41935 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41936 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41937 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41938 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41939 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41940 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41941 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41942 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41943 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41946 +4 4 4 4 4 4
41947 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41948 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41949 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41950 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41951 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41952 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41953 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41954 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41955 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41956 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41957 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41960 +4 4 4 4 4 4
41961 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41962 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41963 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41964 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41965 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41966 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41967 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41968 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41969 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41970 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41971 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41974 +4 4 4 4 4 4
41975 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41976 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41977 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41978 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41979 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41980 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41981 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41982 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41983 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41984 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41985 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41988 +4 4 4 4 4 4
41989 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41990 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41991 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41992 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41993 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41994 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41995 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41996 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41997 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41998 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41999 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42002 +4 4 4 4 4 4
42003 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42004 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42005 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42006 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42007 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42008 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42009 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42010 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42011 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42012 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42013 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42016 +4 4 4 4 4 4
42017 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42018 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42019 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42020 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42021 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42022 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42023 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42024 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42025 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42026 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42027 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42030 +4 4 4 4 4 4
42031 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42032 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42033 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42034 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42035 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42036 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42037 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42038 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42039 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42040 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42041 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42044 +4 4 4 4 4 4
42045 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42046 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42047 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42048 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42049 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42050 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42051 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42052 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42053 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42054 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42058 +4 4 4 4 4 4
42059 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42060 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42061 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42062 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42063 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42064 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42065 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42066 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42067 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42068 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42072 +4 4 4 4 4 4
42073 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42074 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42075 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42076 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42077 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42078 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42079 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42080 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42081 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42082 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42086 +4 4 4 4 4 4
42087 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42088 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42089 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42090 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42091 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42092 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42093 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42094 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42095 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42096 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42100 +4 4 4 4 4 4
42101 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42102 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42103 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42104 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42105 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42106 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42107 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42108 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42109 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42114 +4 4 4 4 4 4
42115 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42116 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42117 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42118 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42119 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42120 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42121 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42122 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42123 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42128 +4 4 4 4 4 4
42129 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42130 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42131 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42132 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42133 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42134 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42135 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42136 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42137 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42142 +4 4 4 4 4 4
42143 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42144 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42145 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42146 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42147 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42148 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42149 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42150 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42156 +4 4 4 4 4 4
42157 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42158 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42159 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42160 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42161 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42162 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42163 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42164 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42170 +4 4 4 4 4 4
42171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42172 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42173 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42174 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42175 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42176 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42177 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42178 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42184 +4 4 4 4 4 4
42185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42186 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42187 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42188 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42189 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42190 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42191 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42192 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4
42199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42200 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42201 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42202 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42203 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42204 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42205 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42206 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4
42213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42215 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42216 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42217 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42218 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42219 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42220 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42230 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42231 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42232 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42233 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42245 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42246 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42247 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42254 +4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42258 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42259 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42260 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42261 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42268 +4 4 4 4 4 4
42269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42272 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42273 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42274 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42275 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42282 +4 4 4 4 4 4
42283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42287 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42288 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42289 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42296 +4 4 4 4 4 4
42297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42301 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42302 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42303 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42310 +4 4 4 4 4 4
42311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42315 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42316 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42317 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42324 +4 4 4 4 4 4
42325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42329 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42330 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42338 +4 4 4 4 4 4
42339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42343 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42344 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42352 +4 4 4 4 4 4
42353 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42354 index 86d449e..af6a7f7 100644
42355 --- a/drivers/video/udlfb.c
42356 +++ b/drivers/video/udlfb.c
42357 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42358 dlfb_urb_completion(urb);
42359
42360 error:
42361 - atomic_add(bytes_sent, &dev->bytes_sent);
42362 - atomic_add(bytes_identical, &dev->bytes_identical);
42363 - atomic_add(width*height*2, &dev->bytes_rendered);
42364 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42365 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42366 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42367 end_cycles = get_cycles();
42368 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42369 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42370 >> 10)), /* Kcycles */
42371 &dev->cpu_kcycles_used);
42372
42373 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42374 dlfb_urb_completion(urb);
42375
42376 error:
42377 - atomic_add(bytes_sent, &dev->bytes_sent);
42378 - atomic_add(bytes_identical, &dev->bytes_identical);
42379 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42380 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42381 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42382 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42383 end_cycles = get_cycles();
42384 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42385 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42386 >> 10)), /* Kcycles */
42387 &dev->cpu_kcycles_used);
42388 }
42389 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42390 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42391 struct dlfb_data *dev = fb_info->par;
42392 return snprintf(buf, PAGE_SIZE, "%u\n",
42393 - atomic_read(&dev->bytes_rendered));
42394 + atomic_read_unchecked(&dev->bytes_rendered));
42395 }
42396
42397 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42398 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42399 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42400 struct dlfb_data *dev = fb_info->par;
42401 return snprintf(buf, PAGE_SIZE, "%u\n",
42402 - atomic_read(&dev->bytes_identical));
42403 + atomic_read_unchecked(&dev->bytes_identical));
42404 }
42405
42406 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42407 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42408 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42409 struct dlfb_data *dev = fb_info->par;
42410 return snprintf(buf, PAGE_SIZE, "%u\n",
42411 - atomic_read(&dev->bytes_sent));
42412 + atomic_read_unchecked(&dev->bytes_sent));
42413 }
42414
42415 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42416 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42417 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42418 struct dlfb_data *dev = fb_info->par;
42419 return snprintf(buf, PAGE_SIZE, "%u\n",
42420 - atomic_read(&dev->cpu_kcycles_used));
42421 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42422 }
42423
42424 static ssize_t edid_show(
42425 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42426 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42427 struct dlfb_data *dev = fb_info->par;
42428
42429 - atomic_set(&dev->bytes_rendered, 0);
42430 - atomic_set(&dev->bytes_identical, 0);
42431 - atomic_set(&dev->bytes_sent, 0);
42432 - atomic_set(&dev->cpu_kcycles_used, 0);
42433 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42434 + atomic_set_unchecked(&dev->bytes_identical, 0);
42435 + atomic_set_unchecked(&dev->bytes_sent, 0);
42436 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42437
42438 return count;
42439 }
42440 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42441 index 2f8f82d..191de37 100644
42442 --- a/drivers/video/uvesafb.c
42443 +++ b/drivers/video/uvesafb.c
42444 @@ -19,6 +19,7 @@
42445 #include <linux/io.h>
42446 #include <linux/mutex.h>
42447 #include <linux/slab.h>
42448 +#include <linux/moduleloader.h>
42449 #include <video/edid.h>
42450 #include <video/uvesafb.h>
42451 #ifdef CONFIG_X86
42452 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42453 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42454 par->pmi_setpal = par->ypan = 0;
42455 } else {
42456 +
42457 +#ifdef CONFIG_PAX_KERNEXEC
42458 +#ifdef CONFIG_MODULES
42459 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42460 +#endif
42461 + if (!par->pmi_code) {
42462 + par->pmi_setpal = par->ypan = 0;
42463 + return 0;
42464 + }
42465 +#endif
42466 +
42467 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42468 + task->t.regs.edi);
42469 +
42470 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42471 + pax_open_kernel();
42472 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42473 + pax_close_kernel();
42474 +
42475 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42476 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42477 +#else
42478 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42479 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42480 +#endif
42481 +
42482 printk(KERN_INFO "uvesafb: protected mode interface info at "
42483 "%04x:%04x\n",
42484 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42485 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42486 par->ypan = ypan;
42487
42488 if (par->pmi_setpal || par->ypan) {
42489 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42490 if (__supported_pte_mask & _PAGE_NX) {
42491 par->pmi_setpal = par->ypan = 0;
42492 printk(KERN_WARNING "uvesafb: NX protection is actively."
42493 "We have better not to use the PMI.\n");
42494 - } else {
42495 + } else
42496 +#endif
42497 uvesafb_vbe_getpmi(task, par);
42498 - }
42499 }
42500 #else
42501 /* The protected mode interface is not available on non-x86. */
42502 @@ -1838,6 +1862,11 @@ out:
42503 if (par->vbe_modes)
42504 kfree(par->vbe_modes);
42505
42506 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42507 + if (par->pmi_code)
42508 + module_free_exec(NULL, par->pmi_code);
42509 +#endif
42510 +
42511 framebuffer_release(info);
42512 return err;
42513 }
42514 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
42515 kfree(par->vbe_state_orig);
42516 if (par->vbe_state_saved)
42517 kfree(par->vbe_state_saved);
42518 +
42519 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42520 + if (par->pmi_code)
42521 + module_free_exec(NULL, par->pmi_code);
42522 +#endif
42523 +
42524 }
42525
42526 framebuffer_release(info);
42527 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42528 index 501b340..86bd4cf 100644
42529 --- a/drivers/video/vesafb.c
42530 +++ b/drivers/video/vesafb.c
42531 @@ -9,6 +9,7 @@
42532 */
42533
42534 #include <linux/module.h>
42535 +#include <linux/moduleloader.h>
42536 #include <linux/kernel.h>
42537 #include <linux/errno.h>
42538 #include <linux/string.h>
42539 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42540 static int vram_total __initdata; /* Set total amount of memory */
42541 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42542 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42543 -static void (*pmi_start)(void) __read_mostly;
42544 -static void (*pmi_pal) (void) __read_mostly;
42545 +static void (*pmi_start)(void) __read_only;
42546 +static void (*pmi_pal) (void) __read_only;
42547 static int depth __read_mostly;
42548 static int vga_compat __read_mostly;
42549 /* --------------------------------------------------------------------- */
42550 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42551 unsigned int size_vmode;
42552 unsigned int size_remap;
42553 unsigned int size_total;
42554 + void *pmi_code = NULL;
42555
42556 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42557 return -ENODEV;
42558 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42559 size_remap = size_total;
42560 vesafb_fix.smem_len = size_remap;
42561
42562 -#ifndef __i386__
42563 - screen_info.vesapm_seg = 0;
42564 -#endif
42565 -
42566 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42567 printk(KERN_WARNING
42568 "vesafb: cannot reserve video memory at 0x%lx\n",
42569 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42570 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42571 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42572
42573 +#ifdef __i386__
42574 +
42575 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42576 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42577 + if (!pmi_code)
42578 +#elif !defined(CONFIG_PAX_KERNEXEC)
42579 + if (0)
42580 +#endif
42581 +
42582 +#endif
42583 + screen_info.vesapm_seg = 0;
42584 +
42585 if (screen_info.vesapm_seg) {
42586 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42587 - screen_info.vesapm_seg,screen_info.vesapm_off);
42588 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42589 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42590 }
42591
42592 if (screen_info.vesapm_seg < 0xc000)
42593 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42594
42595 if (ypan || pmi_setpal) {
42596 unsigned short *pmi_base;
42597 +
42598 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42599 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42600 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42601 +
42602 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42603 + pax_open_kernel();
42604 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42605 +#else
42606 + pmi_code = pmi_base;
42607 +#endif
42608 +
42609 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42610 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42611 +
42612 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42613 + pmi_start = ktva_ktla(pmi_start);
42614 + pmi_pal = ktva_ktla(pmi_pal);
42615 + pax_close_kernel();
42616 +#endif
42617 +
42618 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42619 if (pmi_base[3]) {
42620 printk(KERN_INFO "vesafb: pmi: ports = ");
42621 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42622 info->node, info->fix.id);
42623 return 0;
42624 err:
42625 +
42626 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42627 + module_free_exec(NULL, pmi_code);
42628 +#endif
42629 +
42630 if (info->screen_base)
42631 iounmap(info->screen_base);
42632 framebuffer_release(info);
42633 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42634 index 88714ae..16c2e11 100644
42635 --- a/drivers/video/via/via_clock.h
42636 +++ b/drivers/video/via/via_clock.h
42637 @@ -56,7 +56,7 @@ struct via_clock {
42638
42639 void (*set_engine_pll_state)(u8 state);
42640 void (*set_engine_pll)(struct via_pll_config config);
42641 -};
42642 +} __no_const;
42643
42644
42645 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42646 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42647 index 6b1b7e1..b2fa4d5 100644
42648 --- a/drivers/virtio/virtio_mmio.c
42649 +++ b/drivers/virtio/virtio_mmio.c
42650 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
42651
42652 resources[0].end = memparse(device, &str) - 1;
42653
42654 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42655 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42656 &base, &resources[1].start, &consumed,
42657 &vm_cmdline_id, &consumed);
42658
42659 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42660 index e56c934..fc22f4b 100644
42661 --- a/drivers/xen/xen-pciback/conf_space.h
42662 +++ b/drivers/xen/xen-pciback/conf_space.h
42663 @@ -44,15 +44,15 @@ struct config_field {
42664 struct {
42665 conf_dword_write write;
42666 conf_dword_read read;
42667 - } dw;
42668 + } __no_const dw;
42669 struct {
42670 conf_word_write write;
42671 conf_word_read read;
42672 - } w;
42673 + } __no_const w;
42674 struct {
42675 conf_byte_write write;
42676 conf_byte_read read;
42677 - } b;
42678 + } __no_const b;
42679 } u;
42680 struct list_head list;
42681 };
42682 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
42683 index fef20db..d28b1ab 100644
42684 --- a/drivers/xen/xenfs/xenstored.c
42685 +++ b/drivers/xen/xenfs/xenstored.c
42686 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
42687 static int xsd_kva_open(struct inode *inode, struct file *file)
42688 {
42689 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
42690 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42691 + NULL);
42692 +#else
42693 xen_store_interface);
42694 +#endif
42695 +
42696 if (!file->private_data)
42697 return -ENOMEM;
42698 return 0;
42699 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42700 index 890bed5..17ae73e 100644
42701 --- a/fs/9p/vfs_inode.c
42702 +++ b/fs/9p/vfs_inode.c
42703 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42704 void
42705 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42706 {
42707 - char *s = nd_get_link(nd);
42708 + const char *s = nd_get_link(nd);
42709
42710 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42711 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42712 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42713 index 0efd152..b5802ad 100644
42714 --- a/fs/Kconfig.binfmt
42715 +++ b/fs/Kconfig.binfmt
42716 @@ -89,7 +89,7 @@ config HAVE_AOUT
42717
42718 config BINFMT_AOUT
42719 tristate "Kernel support for a.out and ECOFF binaries"
42720 - depends on HAVE_AOUT
42721 + depends on HAVE_AOUT && BROKEN
42722 ---help---
42723 A.out (Assembler.OUTput) is a set of formats for libraries and
42724 executables used in the earliest versions of UNIX. Linux used
42725 diff --git a/fs/aio.c b/fs/aio.c
42726 index 71f613c..9d01f1f 100644
42727 --- a/fs/aio.c
42728 +++ b/fs/aio.c
42729 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42730 size += sizeof(struct io_event) * nr_events;
42731 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42732
42733 - if (nr_pages < 0)
42734 + if (nr_pages <= 0)
42735 return -EINVAL;
42736
42737 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42738 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42739 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42740 {
42741 ssize_t ret;
42742 + struct iovec iovstack;
42743
42744 #ifdef CONFIG_COMPAT
42745 if (compat)
42746 ret = compat_rw_copy_check_uvector(type,
42747 (struct compat_iovec __user *)kiocb->ki_buf,
42748 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42749 + kiocb->ki_nbytes, 1, &iovstack,
42750 &kiocb->ki_iovec);
42751 else
42752 #endif
42753 ret = rw_copy_check_uvector(type,
42754 (struct iovec __user *)kiocb->ki_buf,
42755 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42756 + kiocb->ki_nbytes, 1, &iovstack,
42757 &kiocb->ki_iovec);
42758 if (ret < 0)
42759 goto out;
42760 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42761 if (ret < 0)
42762 goto out;
42763
42764 + if (kiocb->ki_iovec == &iovstack) {
42765 + kiocb->ki_inline_vec = iovstack;
42766 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42767 + }
42768 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42769 kiocb->ki_cur_seg = 0;
42770 /* ki_nbytes/left now reflect bytes instead of segs */
42771 diff --git a/fs/attr.c b/fs/attr.c
42772 index cce7df5..eaa2731 100644
42773 --- a/fs/attr.c
42774 +++ b/fs/attr.c
42775 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42776 unsigned long limit;
42777
42778 limit = rlimit(RLIMIT_FSIZE);
42779 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42780 if (limit != RLIM_INFINITY && offset > limit)
42781 goto out_sig;
42782 if (offset > inode->i_sb->s_maxbytes)
42783 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42784 index dce436e..55e670d 100644
42785 --- a/fs/autofs4/waitq.c
42786 +++ b/fs/autofs4/waitq.c
42787 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42788 {
42789 unsigned long sigpipe, flags;
42790 mm_segment_t fs;
42791 - const char *data = (const char *)addr;
42792 + const char __user *data = (const char __force_user *)addr;
42793 ssize_t wr = 0;
42794
42795 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42796 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42797 return 1;
42798 }
42799
42800 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42801 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42802 +#endif
42803 +
42804 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42805 enum autofs_notify notify)
42806 {
42807 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42808
42809 /* If this is a direct mount request create a dummy name */
42810 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42811 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42812 + /* this name does get written to userland via autofs4_write() */
42813 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42814 +#else
42815 qstr.len = sprintf(name, "%p", dentry);
42816 +#endif
42817 else {
42818 qstr.len = autofs4_getpath(sbi, dentry, &name);
42819 if (!qstr.len) {
42820 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42821 index 2b3bda8..6a2d4be 100644
42822 --- a/fs/befs/linuxvfs.c
42823 +++ b/fs/befs/linuxvfs.c
42824 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42825 {
42826 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42827 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42828 - char *link = nd_get_link(nd);
42829 + const char *link = nd_get_link(nd);
42830 if (!IS_ERR(link))
42831 kfree(link);
42832 }
42833 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42834 index 0e7a6f8..332b1ca 100644
42835 --- a/fs/binfmt_aout.c
42836 +++ b/fs/binfmt_aout.c
42837 @@ -16,6 +16,7 @@
42838 #include <linux/string.h>
42839 #include <linux/fs.h>
42840 #include <linux/file.h>
42841 +#include <linux/security.h>
42842 #include <linux/stat.h>
42843 #include <linux/fcntl.h>
42844 #include <linux/ptrace.h>
42845 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42846 #endif
42847 # define START_STACK(u) ((void __user *)u.start_stack)
42848
42849 + memset(&dump, 0, sizeof(dump));
42850 +
42851 fs = get_fs();
42852 set_fs(KERNEL_DS);
42853 has_dumped = 1;
42854 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42855
42856 /* If the size of the dump file exceeds the rlimit, then see what would happen
42857 if we wrote the stack, but not the data area. */
42858 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42859 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42860 dump.u_dsize = 0;
42861
42862 /* Make sure we have enough room to write the stack and data areas. */
42863 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42864 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42865 dump.u_ssize = 0;
42866
42867 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42868 rlim = rlimit(RLIMIT_DATA);
42869 if (rlim >= RLIM_INFINITY)
42870 rlim = ~0;
42871 +
42872 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42873 if (ex.a_data + ex.a_bss > rlim)
42874 return -ENOMEM;
42875
42876 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42877
42878 install_exec_creds(bprm);
42879
42880 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42881 + current->mm->pax_flags = 0UL;
42882 +#endif
42883 +
42884 +#ifdef CONFIG_PAX_PAGEEXEC
42885 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42886 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42887 +
42888 +#ifdef CONFIG_PAX_EMUTRAMP
42889 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42890 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42891 +#endif
42892 +
42893 +#ifdef CONFIG_PAX_MPROTECT
42894 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42895 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42896 +#endif
42897 +
42898 + }
42899 +#endif
42900 +
42901 if (N_MAGIC(ex) == OMAGIC) {
42902 unsigned long text_addr, map_size;
42903 loff_t pos;
42904 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42905 }
42906
42907 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42908 - PROT_READ | PROT_WRITE | PROT_EXEC,
42909 + PROT_READ | PROT_WRITE,
42910 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42911 fd_offset + ex.a_text);
42912 if (error != N_DATADDR(ex)) {
42913 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42914 index fbd9f60..d4edac0 100644
42915 --- a/fs/binfmt_elf.c
42916 +++ b/fs/binfmt_elf.c
42917 @@ -33,6 +33,7 @@
42918 #include <linux/elf.h>
42919 #include <linux/utsname.h>
42920 #include <linux/coredump.h>
42921 +#include <linux/xattr.h>
42922 #include <asm/uaccess.h>
42923 #include <asm/param.h>
42924 #include <asm/page.h>
42925 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42926 #define elf_core_dump NULL
42927 #endif
42928
42929 +#ifdef CONFIG_PAX_MPROTECT
42930 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42931 +#endif
42932 +
42933 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42934 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42935 #else
42936 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
42937 .load_binary = load_elf_binary,
42938 .load_shlib = load_elf_library,
42939 .core_dump = elf_core_dump,
42940 +
42941 +#ifdef CONFIG_PAX_MPROTECT
42942 + .handle_mprotect= elf_handle_mprotect,
42943 +#endif
42944 +
42945 .min_coredump = ELF_EXEC_PAGESIZE,
42946 };
42947
42948 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
42949
42950 static int set_brk(unsigned long start, unsigned long end)
42951 {
42952 + unsigned long e = end;
42953 +
42954 start = ELF_PAGEALIGN(start);
42955 end = ELF_PAGEALIGN(end);
42956 if (end > start) {
42957 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
42958 if (BAD_ADDR(addr))
42959 return addr;
42960 }
42961 - current->mm->start_brk = current->mm->brk = end;
42962 + current->mm->start_brk = current->mm->brk = e;
42963 return 0;
42964 }
42965
42966 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42967 elf_addr_t __user *u_rand_bytes;
42968 const char *k_platform = ELF_PLATFORM;
42969 const char *k_base_platform = ELF_BASE_PLATFORM;
42970 - unsigned char k_rand_bytes[16];
42971 + u32 k_rand_bytes[4];
42972 int items;
42973 elf_addr_t *elf_info;
42974 int ei_index = 0;
42975 const struct cred *cred = current_cred();
42976 struct vm_area_struct *vma;
42977 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42978
42979 /*
42980 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42981 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42982 * Generate 16 random bytes for userspace PRNG seeding.
42983 */
42984 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42985 - u_rand_bytes = (elf_addr_t __user *)
42986 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42987 + srandom32(k_rand_bytes[0] ^ random32());
42988 + srandom32(k_rand_bytes[1] ^ random32());
42989 + srandom32(k_rand_bytes[2] ^ random32());
42990 + srandom32(k_rand_bytes[3] ^ random32());
42991 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42992 + u_rand_bytes = (elf_addr_t __user *) p;
42993 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42994 return -EFAULT;
42995
42996 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42997 return -EFAULT;
42998 current->mm->env_end = p;
42999
43000 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43001 +
43002 /* Put the elf_info on the stack in the right place. */
43003 sp = (elf_addr_t __user *)envp + 1;
43004 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43005 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43006 return -EFAULT;
43007 return 0;
43008 }
43009 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43010 an ELF header */
43011
43012 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43013 - struct file *interpreter, unsigned long *interp_map_addr,
43014 - unsigned long no_base)
43015 + struct file *interpreter, unsigned long no_base)
43016 {
43017 struct elf_phdr *elf_phdata;
43018 struct elf_phdr *eppnt;
43019 - unsigned long load_addr = 0;
43020 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43021 int load_addr_set = 0;
43022 unsigned long last_bss = 0, elf_bss = 0;
43023 - unsigned long error = ~0UL;
43024 + unsigned long error = -EINVAL;
43025 unsigned long total_size;
43026 int retval, i, size;
43027
43028 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43029 goto out_close;
43030 }
43031
43032 +#ifdef CONFIG_PAX_SEGMEXEC
43033 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43034 + pax_task_size = SEGMEXEC_TASK_SIZE;
43035 +#endif
43036 +
43037 eppnt = elf_phdata;
43038 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43039 if (eppnt->p_type == PT_LOAD) {
43040 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43041 map_addr = elf_map(interpreter, load_addr + vaddr,
43042 eppnt, elf_prot, elf_type, total_size);
43043 total_size = 0;
43044 - if (!*interp_map_addr)
43045 - *interp_map_addr = map_addr;
43046 error = map_addr;
43047 if (BAD_ADDR(map_addr))
43048 goto out_close;
43049 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43050 k = load_addr + eppnt->p_vaddr;
43051 if (BAD_ADDR(k) ||
43052 eppnt->p_filesz > eppnt->p_memsz ||
43053 - eppnt->p_memsz > TASK_SIZE ||
43054 - TASK_SIZE - eppnt->p_memsz < k) {
43055 + eppnt->p_memsz > pax_task_size ||
43056 + pax_task_size - eppnt->p_memsz < k) {
43057 error = -ENOMEM;
43058 goto out_close;
43059 }
43060 @@ -530,6 +551,315 @@ out:
43061 return error;
43062 }
43063
43064 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43065 +#ifdef CONFIG_PAX_SOFTMODE
43066 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43067 +{
43068 + unsigned long pax_flags = 0UL;
43069 +
43070 +#ifdef CONFIG_PAX_PAGEEXEC
43071 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43072 + pax_flags |= MF_PAX_PAGEEXEC;
43073 +#endif
43074 +
43075 +#ifdef CONFIG_PAX_SEGMEXEC
43076 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43077 + pax_flags |= MF_PAX_SEGMEXEC;
43078 +#endif
43079 +
43080 +#ifdef CONFIG_PAX_EMUTRAMP
43081 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43082 + pax_flags |= MF_PAX_EMUTRAMP;
43083 +#endif
43084 +
43085 +#ifdef CONFIG_PAX_MPROTECT
43086 + if (elf_phdata->p_flags & PF_MPROTECT)
43087 + pax_flags |= MF_PAX_MPROTECT;
43088 +#endif
43089 +
43090 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43091 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43092 + pax_flags |= MF_PAX_RANDMMAP;
43093 +#endif
43094 +
43095 + return pax_flags;
43096 +}
43097 +#endif
43098 +
43099 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43100 +{
43101 + unsigned long pax_flags = 0UL;
43102 +
43103 +#ifdef CONFIG_PAX_PAGEEXEC
43104 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43105 + pax_flags |= MF_PAX_PAGEEXEC;
43106 +#endif
43107 +
43108 +#ifdef CONFIG_PAX_SEGMEXEC
43109 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43110 + pax_flags |= MF_PAX_SEGMEXEC;
43111 +#endif
43112 +
43113 +#ifdef CONFIG_PAX_EMUTRAMP
43114 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43115 + pax_flags |= MF_PAX_EMUTRAMP;
43116 +#endif
43117 +
43118 +#ifdef CONFIG_PAX_MPROTECT
43119 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43120 + pax_flags |= MF_PAX_MPROTECT;
43121 +#endif
43122 +
43123 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43124 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43125 + pax_flags |= MF_PAX_RANDMMAP;
43126 +#endif
43127 +
43128 + return pax_flags;
43129 +}
43130 +#endif
43131 +
43132 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43133 +#ifdef CONFIG_PAX_SOFTMODE
43134 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43135 +{
43136 + unsigned long pax_flags = 0UL;
43137 +
43138 +#ifdef CONFIG_PAX_PAGEEXEC
43139 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43140 + pax_flags |= MF_PAX_PAGEEXEC;
43141 +#endif
43142 +
43143 +#ifdef CONFIG_PAX_SEGMEXEC
43144 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43145 + pax_flags |= MF_PAX_SEGMEXEC;
43146 +#endif
43147 +
43148 +#ifdef CONFIG_PAX_EMUTRAMP
43149 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43150 + pax_flags |= MF_PAX_EMUTRAMP;
43151 +#endif
43152 +
43153 +#ifdef CONFIG_PAX_MPROTECT
43154 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43155 + pax_flags |= MF_PAX_MPROTECT;
43156 +#endif
43157 +
43158 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43159 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43160 + pax_flags |= MF_PAX_RANDMMAP;
43161 +#endif
43162 +
43163 + return pax_flags;
43164 +}
43165 +#endif
43166 +
43167 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43168 +{
43169 + unsigned long pax_flags = 0UL;
43170 +
43171 +#ifdef CONFIG_PAX_PAGEEXEC
43172 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43173 + pax_flags |= MF_PAX_PAGEEXEC;
43174 +#endif
43175 +
43176 +#ifdef CONFIG_PAX_SEGMEXEC
43177 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43178 + pax_flags |= MF_PAX_SEGMEXEC;
43179 +#endif
43180 +
43181 +#ifdef CONFIG_PAX_EMUTRAMP
43182 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43183 + pax_flags |= MF_PAX_EMUTRAMP;
43184 +#endif
43185 +
43186 +#ifdef CONFIG_PAX_MPROTECT
43187 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43188 + pax_flags |= MF_PAX_MPROTECT;
43189 +#endif
43190 +
43191 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43192 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43193 + pax_flags |= MF_PAX_RANDMMAP;
43194 +#endif
43195 +
43196 + return pax_flags;
43197 +}
43198 +#endif
43199 +
43200 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43201 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43202 +{
43203 + unsigned long pax_flags = 0UL;
43204 +
43205 +#ifdef CONFIG_PAX_EI_PAX
43206 +
43207 +#ifdef CONFIG_PAX_PAGEEXEC
43208 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43209 + pax_flags |= MF_PAX_PAGEEXEC;
43210 +#endif
43211 +
43212 +#ifdef CONFIG_PAX_SEGMEXEC
43213 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43214 + pax_flags |= MF_PAX_SEGMEXEC;
43215 +#endif
43216 +
43217 +#ifdef CONFIG_PAX_EMUTRAMP
43218 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43219 + pax_flags |= MF_PAX_EMUTRAMP;
43220 +#endif
43221 +
43222 +#ifdef CONFIG_PAX_MPROTECT
43223 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43224 + pax_flags |= MF_PAX_MPROTECT;
43225 +#endif
43226 +
43227 +#ifdef CONFIG_PAX_ASLR
43228 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43229 + pax_flags |= MF_PAX_RANDMMAP;
43230 +#endif
43231 +
43232 +#else
43233 +
43234 +#ifdef CONFIG_PAX_PAGEEXEC
43235 + pax_flags |= MF_PAX_PAGEEXEC;
43236 +#endif
43237 +
43238 +#ifdef CONFIG_PAX_SEGMEXEC
43239 + pax_flags |= MF_PAX_SEGMEXEC;
43240 +#endif
43241 +
43242 +#ifdef CONFIG_PAX_MPROTECT
43243 + pax_flags |= MF_PAX_MPROTECT;
43244 +#endif
43245 +
43246 +#ifdef CONFIG_PAX_RANDMMAP
43247 + if (randomize_va_space)
43248 + pax_flags |= MF_PAX_RANDMMAP;
43249 +#endif
43250 +
43251 +#endif
43252 +
43253 + return pax_flags;
43254 +}
43255 +
43256 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43257 +{
43258 +
43259 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43260 + unsigned long i;
43261 +
43262 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43263 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43264 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43265 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43266 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43267 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43268 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43269 + return ~0UL;
43270 +
43271 +#ifdef CONFIG_PAX_SOFTMODE
43272 + if (pax_softmode)
43273 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43274 + else
43275 +#endif
43276 +
43277 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43278 + break;
43279 + }
43280 +#endif
43281 +
43282 + return ~0UL;
43283 +}
43284 +
43285 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43286 +{
43287 +
43288 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43289 + ssize_t xattr_size, i;
43290 + unsigned char xattr_value[5];
43291 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43292 +
43293 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43294 + if (xattr_size <= 0 || xattr_size > 5)
43295 + return ~0UL;
43296 +
43297 + for (i = 0; i < xattr_size; i++)
43298 + switch (xattr_value[i]) {
43299 + default:
43300 + return ~0UL;
43301 +
43302 +#define parse_flag(option1, option2, flag) \
43303 + case option1: \
43304 + if (pax_flags_hardmode & MF_PAX_##flag) \
43305 + return ~0UL; \
43306 + pax_flags_hardmode |= MF_PAX_##flag; \
43307 + break; \
43308 + case option2: \
43309 + if (pax_flags_softmode & MF_PAX_##flag) \
43310 + return ~0UL; \
43311 + pax_flags_softmode |= MF_PAX_##flag; \
43312 + break;
43313 +
43314 + parse_flag('p', 'P', PAGEEXEC);
43315 + parse_flag('e', 'E', EMUTRAMP);
43316 + parse_flag('m', 'M', MPROTECT);
43317 + parse_flag('r', 'R', RANDMMAP);
43318 + parse_flag('s', 'S', SEGMEXEC);
43319 +
43320 +#undef parse_flag
43321 + }
43322 +
43323 + if (pax_flags_hardmode & pax_flags_softmode)
43324 + return ~0UL;
43325 +
43326 +#ifdef CONFIG_PAX_SOFTMODE
43327 + if (pax_softmode)
43328 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43329 + else
43330 +#endif
43331 +
43332 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43333 +#else
43334 + return ~0UL;
43335 +#endif
43336 +
43337 +}
43338 +
43339 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43340 +{
43341 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43342 +
43343 + pax_flags = pax_parse_ei_pax(elf_ex);
43344 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43345 + xattr_pax_flags = pax_parse_xattr_pax(file);
43346 +
43347 + if (pt_pax_flags == ~0UL)
43348 + pt_pax_flags = xattr_pax_flags;
43349 + else if (xattr_pax_flags == ~0UL)
43350 + xattr_pax_flags = pt_pax_flags;
43351 + if (pt_pax_flags != xattr_pax_flags)
43352 + return -EINVAL;
43353 + if (pt_pax_flags != ~0UL)
43354 + pax_flags = pt_pax_flags;
43355 +
43356 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43357 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43358 + if ((__supported_pte_mask & _PAGE_NX))
43359 + pax_flags &= ~MF_PAX_SEGMEXEC;
43360 + else
43361 + pax_flags &= ~MF_PAX_PAGEEXEC;
43362 + }
43363 +#endif
43364 +
43365 + if (0 > pax_check_flags(&pax_flags))
43366 + return -EINVAL;
43367 +
43368 + current->mm->pax_flags = pax_flags;
43369 + return 0;
43370 +}
43371 +#endif
43372 +
43373 /*
43374 * These are the functions used to load ELF style executables and shared
43375 * libraries. There is no binary dependent code anywhere else.
43376 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43377 {
43378 unsigned int random_variable = 0;
43379
43380 +#ifdef CONFIG_PAX_RANDUSTACK
43381 + if (randomize_va_space)
43382 + return stack_top - current->mm->delta_stack;
43383 +#endif
43384 +
43385 if ((current->flags & PF_RANDOMIZE) &&
43386 !(current->personality & ADDR_NO_RANDOMIZE)) {
43387 random_variable = get_random_int() & STACK_RND_MASK;
43388 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43389 unsigned long load_addr = 0, load_bias = 0;
43390 int load_addr_set = 0;
43391 char * elf_interpreter = NULL;
43392 - unsigned long error;
43393 + unsigned long error = 0;
43394 struct elf_phdr *elf_ppnt, *elf_phdata;
43395 unsigned long elf_bss, elf_brk;
43396 int retval, i;
43397 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43398 unsigned long start_code, end_code, start_data, end_data;
43399 unsigned long reloc_func_desc __maybe_unused = 0;
43400 int executable_stack = EXSTACK_DEFAULT;
43401 - unsigned long def_flags = 0;
43402 struct {
43403 struct elfhdr elf_ex;
43404 struct elfhdr interp_elf_ex;
43405 } *loc;
43406 + unsigned long pax_task_size = TASK_SIZE;
43407
43408 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43409 if (!loc) {
43410 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43411 goto out_free_dentry;
43412
43413 /* OK, This is the point of no return */
43414 - current->mm->def_flags = def_flags;
43415 +
43416 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43417 + current->mm->pax_flags = 0UL;
43418 +#endif
43419 +
43420 +#ifdef CONFIG_PAX_DLRESOLVE
43421 + current->mm->call_dl_resolve = 0UL;
43422 +#endif
43423 +
43424 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43425 + current->mm->call_syscall = 0UL;
43426 +#endif
43427 +
43428 +#ifdef CONFIG_PAX_ASLR
43429 + current->mm->delta_mmap = 0UL;
43430 + current->mm->delta_stack = 0UL;
43431 +#endif
43432 +
43433 + current->mm->def_flags = 0;
43434 +
43435 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43436 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43437 + send_sig(SIGKILL, current, 0);
43438 + goto out_free_dentry;
43439 + }
43440 +#endif
43441 +
43442 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43443 + pax_set_initial_flags(bprm);
43444 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43445 + if (pax_set_initial_flags_func)
43446 + (pax_set_initial_flags_func)(bprm);
43447 +#endif
43448 +
43449 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43450 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43451 + current->mm->context.user_cs_limit = PAGE_SIZE;
43452 + current->mm->def_flags |= VM_PAGEEXEC;
43453 + }
43454 +#endif
43455 +
43456 +#ifdef CONFIG_PAX_SEGMEXEC
43457 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43458 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43459 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43460 + pax_task_size = SEGMEXEC_TASK_SIZE;
43461 + current->mm->def_flags |= VM_NOHUGEPAGE;
43462 + }
43463 +#endif
43464 +
43465 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43466 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43467 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43468 + put_cpu();
43469 + }
43470 +#endif
43471
43472 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43473 may depend on the personality. */
43474 SET_PERSONALITY(loc->elf_ex);
43475 +
43476 +#ifdef CONFIG_PAX_ASLR
43477 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43478 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43479 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43480 + }
43481 +#endif
43482 +
43483 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43484 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43485 + executable_stack = EXSTACK_DISABLE_X;
43486 + current->personality &= ~READ_IMPLIES_EXEC;
43487 + } else
43488 +#endif
43489 +
43490 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43491 current->personality |= READ_IMPLIES_EXEC;
43492
43493 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43494 #else
43495 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43496 #endif
43497 +
43498 +#ifdef CONFIG_PAX_RANDMMAP
43499 + /* PaX: randomize base address at the default exe base if requested */
43500 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43501 +#ifdef CONFIG_SPARC64
43502 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43503 +#else
43504 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43505 +#endif
43506 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43507 + elf_flags |= MAP_FIXED;
43508 + }
43509 +#endif
43510 +
43511 }
43512
43513 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43514 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43515 * allowed task size. Note that p_filesz must always be
43516 * <= p_memsz so it is only necessary to check p_memsz.
43517 */
43518 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43519 - elf_ppnt->p_memsz > TASK_SIZE ||
43520 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43521 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43522 + elf_ppnt->p_memsz > pax_task_size ||
43523 + pax_task_size - elf_ppnt->p_memsz < k) {
43524 /* set_brk can never work. Avoid overflows. */
43525 send_sig(SIGKILL, current, 0);
43526 retval = -EINVAL;
43527 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43528 goto out_free_dentry;
43529 }
43530 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43531 - send_sig(SIGSEGV, current, 0);
43532 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43533 - goto out_free_dentry;
43534 + /*
43535 + * This bss-zeroing can fail if the ELF
43536 + * file specifies odd protections. So
43537 + * we don't check the return value
43538 + */
43539 }
43540
43541 +#ifdef CONFIG_PAX_RANDMMAP
43542 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43543 + unsigned long start, size;
43544 +
43545 + start = ELF_PAGEALIGN(elf_brk);
43546 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43547 + down_read(&current->mm->mmap_sem);
43548 + retval = -ENOMEM;
43549 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43550 + unsigned long prot = PROT_NONE;
43551 +
43552 + up_read(&current->mm->mmap_sem);
43553 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43554 +// if (current->personality & ADDR_NO_RANDOMIZE)
43555 +// prot = PROT_READ;
43556 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43557 + retval = IS_ERR_VALUE(start) ? start : 0;
43558 + } else
43559 + up_read(&current->mm->mmap_sem);
43560 + if (retval == 0)
43561 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43562 + if (retval < 0) {
43563 + send_sig(SIGKILL, current, 0);
43564 + goto out_free_dentry;
43565 + }
43566 + }
43567 +#endif
43568 +
43569 if (elf_interpreter) {
43570 - unsigned long interp_map_addr = 0;
43571 -
43572 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43573 interpreter,
43574 - &interp_map_addr,
43575 load_bias);
43576 if (!IS_ERR((void *)elf_entry)) {
43577 /*
43578 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43579 * Decide what to dump of a segment, part, all or none.
43580 */
43581 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43582 - unsigned long mm_flags)
43583 + unsigned long mm_flags, long signr)
43584 {
43585 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43586
43587 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43588 if (vma->vm_file == NULL)
43589 return 0;
43590
43591 - if (FILTER(MAPPED_PRIVATE))
43592 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43593 goto whole;
43594
43595 /*
43596 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43597 {
43598 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43599 int i = 0;
43600 - do
43601 + do {
43602 i += 2;
43603 - while (auxv[i - 2] != AT_NULL);
43604 + } while (auxv[i - 2] != AT_NULL);
43605 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43606 }
43607
43608 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43609 }
43610
43611 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43612 - unsigned long mm_flags)
43613 + struct coredump_params *cprm)
43614 {
43615 struct vm_area_struct *vma;
43616 size_t size = 0;
43617
43618 for (vma = first_vma(current, gate_vma); vma != NULL;
43619 vma = next_vma(vma, gate_vma))
43620 - size += vma_dump_size(vma, mm_flags);
43621 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43622 return size;
43623 }
43624
43625 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43626
43627 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43628
43629 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43630 + offset += elf_core_vma_data_size(gate_vma, cprm);
43631 offset += elf_core_extra_data_size();
43632 e_shoff = offset;
43633
43634 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43635 offset = dataoff;
43636
43637 size += sizeof(*elf);
43638 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43639 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43640 goto end_coredump;
43641
43642 size += sizeof(*phdr4note);
43643 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43644 if (size > cprm->limit
43645 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43646 goto end_coredump;
43647 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43648 phdr.p_offset = offset;
43649 phdr.p_vaddr = vma->vm_start;
43650 phdr.p_paddr = 0;
43651 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43652 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43653 phdr.p_memsz = vma->vm_end - vma->vm_start;
43654 offset += phdr.p_filesz;
43655 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43656 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43657 phdr.p_align = ELF_EXEC_PAGESIZE;
43658
43659 size += sizeof(phdr);
43660 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43661 if (size > cprm->limit
43662 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43663 goto end_coredump;
43664 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43665 unsigned long addr;
43666 unsigned long end;
43667
43668 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43669 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
43670
43671 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43672 struct page *page;
43673 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43674 page = get_dump_page(addr);
43675 if (page) {
43676 void *kaddr = kmap(page);
43677 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43678 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43679 !dump_write(cprm->file, kaddr,
43680 PAGE_SIZE);
43681 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43682
43683 if (e_phnum == PN_XNUM) {
43684 size += sizeof(*shdr4extnum);
43685 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43686 if (size > cprm->limit
43687 || !dump_write(cprm->file, shdr4extnum,
43688 sizeof(*shdr4extnum)))
43689 @@ -2216,6 +2667,97 @@ out:
43690
43691 #endif /* CONFIG_ELF_CORE */
43692
43693 +#ifdef CONFIG_PAX_MPROTECT
43694 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43695 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43696 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43697 + *
43698 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43699 + * basis because we want to allow the common case and not the special ones.
43700 + */
43701 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43702 +{
43703 + struct elfhdr elf_h;
43704 + struct elf_phdr elf_p;
43705 + unsigned long i;
43706 + unsigned long oldflags;
43707 + bool is_textrel_rw, is_textrel_rx, is_relro;
43708 +
43709 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43710 + return;
43711 +
43712 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43713 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43714 +
43715 +#ifdef CONFIG_PAX_ELFRELOCS
43716 + /* possible TEXTREL */
43717 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43718 + is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
43719 +#else
43720 + is_textrel_rw = false;
43721 + is_textrel_rx = false;
43722 +#endif
43723 +
43724 + /* possible RELRO */
43725 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43726 +
43727 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43728 + return;
43729 +
43730 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43731 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43732 +
43733 +#ifdef CONFIG_PAX_ETEXECRELOCS
43734 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43735 +#else
43736 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43737 +#endif
43738 +
43739 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43740 + !elf_check_arch(&elf_h) ||
43741 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43742 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43743 + return;
43744 +
43745 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43746 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43747 + return;
43748 + switch (elf_p.p_type) {
43749 + case PT_DYNAMIC:
43750 + if (!is_textrel_rw && !is_textrel_rx)
43751 + continue;
43752 + i = 0UL;
43753 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43754 + elf_dyn dyn;
43755 +
43756 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43757 + return;
43758 + if (dyn.d_tag == DT_NULL)
43759 + return;
43760 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43761 + gr_log_textrel(vma);
43762 + if (is_textrel_rw)
43763 + vma->vm_flags |= VM_MAYWRITE;
43764 + else
43765 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43766 + vma->vm_flags &= ~VM_MAYWRITE;
43767 + return;
43768 + }
43769 + i++;
43770 + }
43771 + return;
43772 +
43773 + case PT_GNU_RELRO:
43774 + if (!is_relro)
43775 + continue;
43776 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43777 + vma->vm_flags &= ~VM_MAYWRITE;
43778 + return;
43779 + }
43780 + }
43781 +}
43782 +#endif
43783 +
43784 static int __init init_elf_binfmt(void)
43785 {
43786 register_binfmt(&elf_format);
43787 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43788 index e280352..7b2f231 100644
43789 --- a/fs/binfmt_flat.c
43790 +++ b/fs/binfmt_flat.c
43791 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43792 realdatastart = (unsigned long) -ENOMEM;
43793 printk("Unable to allocate RAM for process data, errno %d\n",
43794 (int)-realdatastart);
43795 + down_write(&current->mm->mmap_sem);
43796 vm_munmap(textpos, text_len);
43797 + up_write(&current->mm->mmap_sem);
43798 ret = realdatastart;
43799 goto err;
43800 }
43801 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43802 }
43803 if (IS_ERR_VALUE(result)) {
43804 printk("Unable to read data+bss, errno %d\n", (int)-result);
43805 + down_write(&current->mm->mmap_sem);
43806 vm_munmap(textpos, text_len);
43807 vm_munmap(realdatastart, len);
43808 + up_write(&current->mm->mmap_sem);
43809 ret = result;
43810 goto err;
43811 }
43812 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43813 }
43814 if (IS_ERR_VALUE(result)) {
43815 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43816 + down_write(&current->mm->mmap_sem);
43817 vm_munmap(textpos, text_len + data_len + extra +
43818 MAX_SHARED_LIBS * sizeof(unsigned long));
43819 + up_write(&current->mm->mmap_sem);
43820 ret = result;
43821 goto err;
43822 }
43823 diff --git a/fs/bio.c b/fs/bio.c
43824 index b96fc6c..431d628 100644
43825 --- a/fs/bio.c
43826 +++ b/fs/bio.c
43827 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43828 /*
43829 * Overflow, abort
43830 */
43831 - if (end < start)
43832 + if (end < start || end - start > INT_MAX - nr_pages)
43833 return ERR_PTR(-EINVAL);
43834
43835 nr_pages += end - start;
43836 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43837 /*
43838 * Overflow, abort
43839 */
43840 - if (end < start)
43841 + if (end < start || end - start > INT_MAX - nr_pages)
43842 return ERR_PTR(-EINVAL);
43843
43844 nr_pages += end - start;
43845 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43846 const int read = bio_data_dir(bio) == READ;
43847 struct bio_map_data *bmd = bio->bi_private;
43848 int i;
43849 - char *p = bmd->sgvecs[0].iov_base;
43850 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43851
43852 __bio_for_each_segment(bvec, bio, i, 0) {
43853 char *addr = page_address(bvec->bv_page);
43854 diff --git a/fs/block_dev.c b/fs/block_dev.c
43855 index ab3a456..7da538b 100644
43856 --- a/fs/block_dev.c
43857 +++ b/fs/block_dev.c
43858 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43859 else if (bdev->bd_contains == bdev)
43860 return true; /* is a whole device which isn't held */
43861
43862 - else if (whole->bd_holder == bd_may_claim)
43863 + else if (whole->bd_holder == (void *)bd_may_claim)
43864 return true; /* is a partition of a device that is being partitioned */
43865 else if (whole->bd_holder != NULL)
43866 return false; /* is a partition of a held device */
43867 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43868 index 5a3e45d..ad19cc3 100644
43869 --- a/fs/btrfs/check-integrity.c
43870 +++ b/fs/btrfs/check-integrity.c
43871 @@ -156,7 +156,7 @@ struct btrfsic_block {
43872 union {
43873 bio_end_io_t *bio;
43874 bh_end_io_t *bh;
43875 - } orig_bio_bh_end_io;
43876 + } __no_const orig_bio_bh_end_io;
43877 int submit_bio_bh_rw;
43878 u64 flush_gen; /* only valid if !never_written */
43879 };
43880 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43881 index cdfb4c4..da736d4 100644
43882 --- a/fs/btrfs/ctree.c
43883 +++ b/fs/btrfs/ctree.c
43884 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43885 free_extent_buffer(buf);
43886 add_root_to_dirty_list(root);
43887 } else {
43888 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43889 - parent_start = parent->start;
43890 - else
43891 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43892 + if (parent)
43893 + parent_start = parent->start;
43894 + else
43895 + parent_start = 0;
43896 + } else
43897 parent_start = 0;
43898
43899 WARN_ON(trans->transid != btrfs_header_generation(parent));
43900 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43901 index 95542a1..95a8727 100644
43902 --- a/fs/btrfs/inode.c
43903 +++ b/fs/btrfs/inode.c
43904 @@ -7243,7 +7243,7 @@ fail:
43905 return -ENOMEM;
43906 }
43907
43908 -static int btrfs_getattr(struct vfsmount *mnt,
43909 +int btrfs_getattr(struct vfsmount *mnt,
43910 struct dentry *dentry, struct kstat *stat)
43911 {
43912 struct inode *inode = dentry->d_inode;
43913 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43914 return 0;
43915 }
43916
43917 +EXPORT_SYMBOL(btrfs_getattr);
43918 +
43919 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43920 +{
43921 + return BTRFS_I(inode)->root->anon_dev;
43922 +}
43923 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43924 +
43925 /*
43926 * If a file is moved, it will inherit the cow and compression flags of the new
43927 * directory.
43928 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43929 index 8fcf9a5..a200000 100644
43930 --- a/fs/btrfs/ioctl.c
43931 +++ b/fs/btrfs/ioctl.c
43932 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43933 for (i = 0; i < num_types; i++) {
43934 struct btrfs_space_info *tmp;
43935
43936 + /* Don't copy in more than we allocated */
43937 if (!slot_count)
43938 break;
43939
43940 + slot_count--;
43941 +
43942 info = NULL;
43943 rcu_read_lock();
43944 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43945 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43946 memcpy(dest, &space, sizeof(space));
43947 dest++;
43948 space_args.total_spaces++;
43949 - slot_count--;
43950 }
43951 - if (!slot_count)
43952 - break;
43953 }
43954 up_read(&info->groups_sem);
43955 }
43956 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43957 index 776f0aa..3aad281 100644
43958 --- a/fs/btrfs/relocation.c
43959 +++ b/fs/btrfs/relocation.c
43960 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43961 }
43962 spin_unlock(&rc->reloc_root_tree.lock);
43963
43964 - BUG_ON((struct btrfs_root *)node->data != root);
43965 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43966
43967 if (!del) {
43968 spin_lock(&rc->reloc_root_tree.lock);
43969 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43970 index 622f469..e8d2d55 100644
43971 --- a/fs/cachefiles/bind.c
43972 +++ b/fs/cachefiles/bind.c
43973 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43974 args);
43975
43976 /* start by checking things over */
43977 - ASSERT(cache->fstop_percent >= 0 &&
43978 - cache->fstop_percent < cache->fcull_percent &&
43979 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43980 cache->fcull_percent < cache->frun_percent &&
43981 cache->frun_percent < 100);
43982
43983 - ASSERT(cache->bstop_percent >= 0 &&
43984 - cache->bstop_percent < cache->bcull_percent &&
43985 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43986 cache->bcull_percent < cache->brun_percent &&
43987 cache->brun_percent < 100);
43988
43989 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43990 index 0a1467b..6a53245 100644
43991 --- a/fs/cachefiles/daemon.c
43992 +++ b/fs/cachefiles/daemon.c
43993 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43994 if (n > buflen)
43995 return -EMSGSIZE;
43996
43997 - if (copy_to_user(_buffer, buffer, n) != 0)
43998 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43999 return -EFAULT;
44000
44001 return n;
44002 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44003 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44004 return -EIO;
44005
44006 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44007 + if (datalen > PAGE_SIZE - 1)
44008 return -EOPNOTSUPP;
44009
44010 /* drag the command string into the kernel so we can parse it */
44011 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44012 if (args[0] != '%' || args[1] != '\0')
44013 return -EINVAL;
44014
44015 - if (fstop < 0 || fstop >= cache->fcull_percent)
44016 + if (fstop >= cache->fcull_percent)
44017 return cachefiles_daemon_range_error(cache, args);
44018
44019 cache->fstop_percent = fstop;
44020 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44021 if (args[0] != '%' || args[1] != '\0')
44022 return -EINVAL;
44023
44024 - if (bstop < 0 || bstop >= cache->bcull_percent)
44025 + if (bstop >= cache->bcull_percent)
44026 return cachefiles_daemon_range_error(cache, args);
44027
44028 cache->bstop_percent = bstop;
44029 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44030 index bd6bc1b..b627b53 100644
44031 --- a/fs/cachefiles/internal.h
44032 +++ b/fs/cachefiles/internal.h
44033 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44034 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44035 struct rb_root active_nodes; /* active nodes (can't be culled) */
44036 rwlock_t active_lock; /* lock for active_nodes */
44037 - atomic_t gravecounter; /* graveyard uniquifier */
44038 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44039 unsigned frun_percent; /* when to stop culling (% files) */
44040 unsigned fcull_percent; /* when to start culling (% files) */
44041 unsigned fstop_percent; /* when to stop allocating (% files) */
44042 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44043 * proc.c
44044 */
44045 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44046 -extern atomic_t cachefiles_lookup_histogram[HZ];
44047 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44048 -extern atomic_t cachefiles_create_histogram[HZ];
44049 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44050 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44051 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44052
44053 extern int __init cachefiles_proc_init(void);
44054 extern void cachefiles_proc_cleanup(void);
44055 static inline
44056 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44057 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44058 {
44059 unsigned long jif = jiffies - start_jif;
44060 if (jif >= HZ)
44061 jif = HZ - 1;
44062 - atomic_inc(&histogram[jif]);
44063 + atomic_inc_unchecked(&histogram[jif]);
44064 }
44065
44066 #else
44067 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44068 index b0b5f7c..039bb26 100644
44069 --- a/fs/cachefiles/namei.c
44070 +++ b/fs/cachefiles/namei.c
44071 @@ -318,7 +318,7 @@ try_again:
44072 /* first step is to make up a grave dentry in the graveyard */
44073 sprintf(nbuffer, "%08x%08x",
44074 (uint32_t) get_seconds(),
44075 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44076 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44077
44078 /* do the multiway lock magic */
44079 trap = lock_rename(cache->graveyard, dir);
44080 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44081 index eccd339..4c1d995 100644
44082 --- a/fs/cachefiles/proc.c
44083 +++ b/fs/cachefiles/proc.c
44084 @@ -14,9 +14,9 @@
44085 #include <linux/seq_file.h>
44086 #include "internal.h"
44087
44088 -atomic_t cachefiles_lookup_histogram[HZ];
44089 -atomic_t cachefiles_mkdir_histogram[HZ];
44090 -atomic_t cachefiles_create_histogram[HZ];
44091 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44092 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44093 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44094
44095 /*
44096 * display the latency histogram
44097 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44098 return 0;
44099 default:
44100 index = (unsigned long) v - 3;
44101 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44102 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44103 - z = atomic_read(&cachefiles_create_histogram[index]);
44104 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44105 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44106 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44107 if (x == 0 && y == 0 && z == 0)
44108 return 0;
44109
44110 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44111 index c994691..2a1537f 100644
44112 --- a/fs/cachefiles/rdwr.c
44113 +++ b/fs/cachefiles/rdwr.c
44114 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44115 old_fs = get_fs();
44116 set_fs(KERNEL_DS);
44117 ret = file->f_op->write(
44118 - file, (const void __user *) data, len, &pos);
44119 + file, (const void __force_user *) data, len, &pos);
44120 set_fs(old_fs);
44121 kunmap(page);
44122 if (ret != len)
44123 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44124 index e5b7731..b9c59fb 100644
44125 --- a/fs/ceph/dir.c
44126 +++ b/fs/ceph/dir.c
44127 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44128 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44129 struct ceph_mds_client *mdsc = fsc->mdsc;
44130 unsigned frag = fpos_frag(filp->f_pos);
44131 - int off = fpos_off(filp->f_pos);
44132 + unsigned int off = fpos_off(filp->f_pos);
44133 int err;
44134 u32 ftype;
44135 struct ceph_mds_reply_info_parsed *rinfo;
44136 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44137 index d9ea6ed..1e6c8ac 100644
44138 --- a/fs/cifs/cifs_debug.c
44139 +++ b/fs/cifs/cifs_debug.c
44140 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44141
44142 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44143 #ifdef CONFIG_CIFS_STATS2
44144 - atomic_set(&totBufAllocCount, 0);
44145 - atomic_set(&totSmBufAllocCount, 0);
44146 + atomic_set_unchecked(&totBufAllocCount, 0);
44147 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44148 #endif /* CONFIG_CIFS_STATS2 */
44149 spin_lock(&cifs_tcp_ses_lock);
44150 list_for_each(tmp1, &cifs_tcp_ses_list) {
44151 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44152 tcon = list_entry(tmp3,
44153 struct cifs_tcon,
44154 tcon_list);
44155 - atomic_set(&tcon->num_smbs_sent, 0);
44156 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44157 if (server->ops->clear_stats)
44158 server->ops->clear_stats(tcon);
44159 }
44160 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44161 smBufAllocCount.counter, cifs_min_small);
44162 #ifdef CONFIG_CIFS_STATS2
44163 seq_printf(m, "Total Large %d Small %d Allocations\n",
44164 - atomic_read(&totBufAllocCount),
44165 - atomic_read(&totSmBufAllocCount));
44166 + atomic_read_unchecked(&totBufAllocCount),
44167 + atomic_read_unchecked(&totSmBufAllocCount));
44168 #endif /* CONFIG_CIFS_STATS2 */
44169
44170 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44171 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44172 if (tcon->need_reconnect)
44173 seq_puts(m, "\tDISCONNECTED ");
44174 seq_printf(m, "\nSMBs: %d",
44175 - atomic_read(&tcon->num_smbs_sent));
44176 + atomic_read_unchecked(&tcon->num_smbs_sent));
44177 if (server->ops->print_stats)
44178 server->ops->print_stats(m, tcon);
44179 }
44180 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44181 index e7931cc..76a1ab9 100644
44182 --- a/fs/cifs/cifsfs.c
44183 +++ b/fs/cifs/cifsfs.c
44184 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
44185 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44186 cifs_req_cachep = kmem_cache_create("cifs_request",
44187 CIFSMaxBufSize + max_hdr_size, 0,
44188 - SLAB_HWCACHE_ALIGN, NULL);
44189 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44190 if (cifs_req_cachep == NULL)
44191 return -ENOMEM;
44192
44193 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
44194 efficient to alloc 1 per page off the slab compared to 17K (5page)
44195 alloc of large cifs buffers even when page debugging is on */
44196 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44197 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44198 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44199 NULL);
44200 if (cifs_sm_req_cachep == NULL) {
44201 mempool_destroy(cifs_req_poolp);
44202 @@ -1111,8 +1111,8 @@ init_cifs(void)
44203 atomic_set(&bufAllocCount, 0);
44204 atomic_set(&smBufAllocCount, 0);
44205 #ifdef CONFIG_CIFS_STATS2
44206 - atomic_set(&totBufAllocCount, 0);
44207 - atomic_set(&totSmBufAllocCount, 0);
44208 + atomic_set_unchecked(&totBufAllocCount, 0);
44209 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44210 #endif /* CONFIG_CIFS_STATS2 */
44211
44212 atomic_set(&midCount, 0);
44213 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44214 index f5af252..489b5f2 100644
44215 --- a/fs/cifs/cifsglob.h
44216 +++ b/fs/cifs/cifsglob.h
44217 @@ -751,35 +751,35 @@ struct cifs_tcon {
44218 __u16 Flags; /* optional support bits */
44219 enum statusEnum tidStatus;
44220 #ifdef CONFIG_CIFS_STATS
44221 - atomic_t num_smbs_sent;
44222 + atomic_unchecked_t num_smbs_sent;
44223 union {
44224 struct {
44225 - atomic_t num_writes;
44226 - atomic_t num_reads;
44227 - atomic_t num_flushes;
44228 - atomic_t num_oplock_brks;
44229 - atomic_t num_opens;
44230 - atomic_t num_closes;
44231 - atomic_t num_deletes;
44232 - atomic_t num_mkdirs;
44233 - atomic_t num_posixopens;
44234 - atomic_t num_posixmkdirs;
44235 - atomic_t num_rmdirs;
44236 - atomic_t num_renames;
44237 - atomic_t num_t2renames;
44238 - atomic_t num_ffirst;
44239 - atomic_t num_fnext;
44240 - atomic_t num_fclose;
44241 - atomic_t num_hardlinks;
44242 - atomic_t num_symlinks;
44243 - atomic_t num_locks;
44244 - atomic_t num_acl_get;
44245 - atomic_t num_acl_set;
44246 + atomic_unchecked_t num_writes;
44247 + atomic_unchecked_t num_reads;
44248 + atomic_unchecked_t num_flushes;
44249 + atomic_unchecked_t num_oplock_brks;
44250 + atomic_unchecked_t num_opens;
44251 + atomic_unchecked_t num_closes;
44252 + atomic_unchecked_t num_deletes;
44253 + atomic_unchecked_t num_mkdirs;
44254 + atomic_unchecked_t num_posixopens;
44255 + atomic_unchecked_t num_posixmkdirs;
44256 + atomic_unchecked_t num_rmdirs;
44257 + atomic_unchecked_t num_renames;
44258 + atomic_unchecked_t num_t2renames;
44259 + atomic_unchecked_t num_ffirst;
44260 + atomic_unchecked_t num_fnext;
44261 + atomic_unchecked_t num_fclose;
44262 + atomic_unchecked_t num_hardlinks;
44263 + atomic_unchecked_t num_symlinks;
44264 + atomic_unchecked_t num_locks;
44265 + atomic_unchecked_t num_acl_get;
44266 + atomic_unchecked_t num_acl_set;
44267 } cifs_stats;
44268 #ifdef CONFIG_CIFS_SMB2
44269 struct {
44270 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44271 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44272 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44273 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44274 } smb2_stats;
44275 #endif /* CONFIG_CIFS_SMB2 */
44276 } stats;
44277 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44278 }
44279
44280 #ifdef CONFIG_CIFS_STATS
44281 -#define cifs_stats_inc atomic_inc
44282 +#define cifs_stats_inc atomic_inc_unchecked
44283
44284 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44285 unsigned int bytes)
44286 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44287 /* Various Debug counters */
44288 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44289 #ifdef CONFIG_CIFS_STATS2
44290 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44291 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44292 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44293 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44294 #endif
44295 GLOBAL_EXTERN atomic_t smBufAllocCount;
44296 GLOBAL_EXTERN atomic_t midCount;
44297 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44298 index 51dc2fb..1e12a33 100644
44299 --- a/fs/cifs/link.c
44300 +++ b/fs/cifs/link.c
44301 @@ -616,7 +616,7 @@ symlink_exit:
44302
44303 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44304 {
44305 - char *p = nd_get_link(nd);
44306 + const char *p = nd_get_link(nd);
44307 if (!IS_ERR(p))
44308 kfree(p);
44309 }
44310 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44311 index 3a00c0d..42d901c 100644
44312 --- a/fs/cifs/misc.c
44313 +++ b/fs/cifs/misc.c
44314 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44315 memset(ret_buf, 0, buf_size + 3);
44316 atomic_inc(&bufAllocCount);
44317 #ifdef CONFIG_CIFS_STATS2
44318 - atomic_inc(&totBufAllocCount);
44319 + atomic_inc_unchecked(&totBufAllocCount);
44320 #endif /* CONFIG_CIFS_STATS2 */
44321 }
44322
44323 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44324 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44325 atomic_inc(&smBufAllocCount);
44326 #ifdef CONFIG_CIFS_STATS2
44327 - atomic_inc(&totSmBufAllocCount);
44328 + atomic_inc_unchecked(&totSmBufAllocCount);
44329 #endif /* CONFIG_CIFS_STATS2 */
44330
44331 }
44332 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44333 index 34cea27..3fbdf6f 100644
44334 --- a/fs/cifs/smb1ops.c
44335 +++ b/fs/cifs/smb1ops.c
44336 @@ -610,27 +610,27 @@ static void
44337 cifs_clear_stats(struct cifs_tcon *tcon)
44338 {
44339 #ifdef CONFIG_CIFS_STATS
44340 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44341 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44342 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44343 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44344 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44345 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44346 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44347 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44348 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44349 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44350 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44351 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44352 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44353 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44354 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44355 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44356 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44357 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44358 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44359 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44360 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44361 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44362 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44363 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44364 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44365 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44366 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44367 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44368 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44369 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44370 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44371 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44372 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44373 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44374 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44375 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44376 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44377 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44378 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44379 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44380 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44381 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44382 #endif
44383 }
44384
44385 @@ -639,36 +639,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44386 {
44387 #ifdef CONFIG_CIFS_STATS
44388 seq_printf(m, " Oplocks breaks: %d",
44389 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44390 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44391 seq_printf(m, "\nReads: %d Bytes: %llu",
44392 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44393 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44394 (long long)(tcon->bytes_read));
44395 seq_printf(m, "\nWrites: %d Bytes: %llu",
44396 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44397 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44398 (long long)(tcon->bytes_written));
44399 seq_printf(m, "\nFlushes: %d",
44400 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44401 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44402 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44403 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44404 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44405 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44406 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44407 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44408 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44409 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44410 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44411 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44412 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44413 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44414 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44415 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44416 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44417 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44418 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44419 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44420 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44421 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44422 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44423 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44424 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44425 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44426 seq_printf(m, "\nRenames: %d T2 Renames %d",
44427 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44428 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44429 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44430 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44431 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44432 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44433 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44434 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44435 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44436 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44437 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44438 #endif
44439 }
44440
44441 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44442 index 4d9dbe0..0af4601 100644
44443 --- a/fs/cifs/smb2ops.c
44444 +++ b/fs/cifs/smb2ops.c
44445 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44446 #ifdef CONFIG_CIFS_STATS
44447 int i;
44448 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44449 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44450 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44451 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44452 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44453 }
44454 #endif
44455 }
44456 @@ -301,66 +301,66 @@ static void
44457 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44458 {
44459 #ifdef CONFIG_CIFS_STATS
44460 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44461 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44462 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44463 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44464 seq_printf(m, "\nNegotiates: %d sent %d failed",
44465 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44466 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44467 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44468 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44469 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44470 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44471 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44472 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44473 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44474 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44475 seq_printf(m, "\nLogoffs: %d sent %d failed",
44476 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44477 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44478 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44479 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44480 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44481 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44482 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44483 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44484 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44485 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44486 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44487 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44488 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44489 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44490 seq_printf(m, "\nCreates: %d sent %d failed",
44491 - atomic_read(&sent[SMB2_CREATE_HE]),
44492 - atomic_read(&failed[SMB2_CREATE_HE]));
44493 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44494 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44495 seq_printf(m, "\nCloses: %d sent %d failed",
44496 - atomic_read(&sent[SMB2_CLOSE_HE]),
44497 - atomic_read(&failed[SMB2_CLOSE_HE]));
44498 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44499 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44500 seq_printf(m, "\nFlushes: %d sent %d failed",
44501 - atomic_read(&sent[SMB2_FLUSH_HE]),
44502 - atomic_read(&failed[SMB2_FLUSH_HE]));
44503 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44504 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44505 seq_printf(m, "\nReads: %d sent %d failed",
44506 - atomic_read(&sent[SMB2_READ_HE]),
44507 - atomic_read(&failed[SMB2_READ_HE]));
44508 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44509 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44510 seq_printf(m, "\nWrites: %d sent %d failed",
44511 - atomic_read(&sent[SMB2_WRITE_HE]),
44512 - atomic_read(&failed[SMB2_WRITE_HE]));
44513 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44514 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44515 seq_printf(m, "\nLocks: %d sent %d failed",
44516 - atomic_read(&sent[SMB2_LOCK_HE]),
44517 - atomic_read(&failed[SMB2_LOCK_HE]));
44518 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44519 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44520 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44521 - atomic_read(&sent[SMB2_IOCTL_HE]),
44522 - atomic_read(&failed[SMB2_IOCTL_HE]));
44523 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44524 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44525 seq_printf(m, "\nCancels: %d sent %d failed",
44526 - atomic_read(&sent[SMB2_CANCEL_HE]),
44527 - atomic_read(&failed[SMB2_CANCEL_HE]));
44528 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44529 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44530 seq_printf(m, "\nEchos: %d sent %d failed",
44531 - atomic_read(&sent[SMB2_ECHO_HE]),
44532 - atomic_read(&failed[SMB2_ECHO_HE]));
44533 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44534 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44535 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44536 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44537 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44538 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44539 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44540 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44541 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44542 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44543 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44544 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44545 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44546 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44547 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44548 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44549 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44550 seq_printf(m, "\nSetInfos: %d sent %d failed",
44551 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44552 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44553 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44554 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44555 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44556 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44557 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44558 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44559 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44560 #endif
44561 }
44562
44563 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44564 index 958ae0e..505c9d0 100644
44565 --- a/fs/coda/cache.c
44566 +++ b/fs/coda/cache.c
44567 @@ -24,7 +24,7 @@
44568 #include "coda_linux.h"
44569 #include "coda_cache.h"
44570
44571 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44572 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44573
44574 /* replace or extend an acl cache hit */
44575 void coda_cache_enter(struct inode *inode, int mask)
44576 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44577 struct coda_inode_info *cii = ITOC(inode);
44578
44579 spin_lock(&cii->c_lock);
44580 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44581 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44582 if (cii->c_uid != current_fsuid()) {
44583 cii->c_uid = current_fsuid();
44584 cii->c_cached_perm = mask;
44585 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44586 {
44587 struct coda_inode_info *cii = ITOC(inode);
44588 spin_lock(&cii->c_lock);
44589 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44590 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44591 spin_unlock(&cii->c_lock);
44592 }
44593
44594 /* remove all acl caches */
44595 void coda_cache_clear_all(struct super_block *sb)
44596 {
44597 - atomic_inc(&permission_epoch);
44598 + atomic_inc_unchecked(&permission_epoch);
44599 }
44600
44601
44602 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44603 spin_lock(&cii->c_lock);
44604 hit = (mask & cii->c_cached_perm) == mask &&
44605 cii->c_uid == current_fsuid() &&
44606 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44607 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44608 spin_unlock(&cii->c_lock);
44609
44610 return hit;
44611 diff --git a/fs/compat.c b/fs/compat.c
44612 index 015e1e1..5ce8e54 100644
44613 --- a/fs/compat.c
44614 +++ b/fs/compat.c
44615 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44616
44617 set_fs(KERNEL_DS);
44618 /* The __user pointer cast is valid because of the set_fs() */
44619 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44620 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44621 set_fs(oldfs);
44622 /* truncating is ok because it's a user address */
44623 if (!ret)
44624 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44625 goto out;
44626
44627 ret = -EINVAL;
44628 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44629 + if (nr_segs > UIO_MAXIOV)
44630 goto out;
44631 if (nr_segs > fast_segs) {
44632 ret = -ENOMEM;
44633 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44634
44635 struct compat_readdir_callback {
44636 struct compat_old_linux_dirent __user *dirent;
44637 + struct file * file;
44638 int result;
44639 };
44640
44641 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44642 buf->result = -EOVERFLOW;
44643 return -EOVERFLOW;
44644 }
44645 +
44646 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44647 + return 0;
44648 +
44649 buf->result++;
44650 dirent = buf->dirent;
44651 if (!access_ok(VERIFY_WRITE, dirent,
44652 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44653
44654 buf.result = 0;
44655 buf.dirent = dirent;
44656 + buf.file = f.file;
44657
44658 error = vfs_readdir(f.file, compat_fillonedir, &buf);
44659 if (buf.result)
44660 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
44661 struct compat_getdents_callback {
44662 struct compat_linux_dirent __user *current_dir;
44663 struct compat_linux_dirent __user *previous;
44664 + struct file * file;
44665 int count;
44666 int error;
44667 };
44668 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44669 buf->error = -EOVERFLOW;
44670 return -EOVERFLOW;
44671 }
44672 +
44673 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44674 + return 0;
44675 +
44676 dirent = buf->previous;
44677 if (dirent) {
44678 if (__put_user(offset, &dirent->d_off))
44679 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44680 buf.previous = NULL;
44681 buf.count = count;
44682 buf.error = 0;
44683 + buf.file = f.file;
44684
44685 error = vfs_readdir(f.file, compat_filldir, &buf);
44686 if (error >= 0)
44687 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44688 struct compat_getdents_callback64 {
44689 struct linux_dirent64 __user *current_dir;
44690 struct linux_dirent64 __user *previous;
44691 + struct file * file;
44692 int count;
44693 int error;
44694 };
44695 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44696 buf->error = -EINVAL; /* only used if we fail.. */
44697 if (reclen > buf->count)
44698 return -EINVAL;
44699 +
44700 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44701 + return 0;
44702 +
44703 dirent = buf->previous;
44704
44705 if (dirent) {
44706 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44707 buf.previous = NULL;
44708 buf.count = count;
44709 buf.error = 0;
44710 + buf.file = f.file;
44711
44712 error = vfs_readdir(f.file, compat_filldir64, &buf);
44713 if (error >= 0)
44714 error = buf.error;
44715 lastdirent = buf.previous;
44716 if (lastdirent) {
44717 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
44718 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
44719 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44720 error = -EFAULT;
44721 else
44722 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44723 index a81147e..20bf2b5 100644
44724 --- a/fs/compat_binfmt_elf.c
44725 +++ b/fs/compat_binfmt_elf.c
44726 @@ -30,11 +30,13 @@
44727 #undef elf_phdr
44728 #undef elf_shdr
44729 #undef elf_note
44730 +#undef elf_dyn
44731 #undef elf_addr_t
44732 #define elfhdr elf32_hdr
44733 #define elf_phdr elf32_phdr
44734 #define elf_shdr elf32_shdr
44735 #define elf_note elf32_note
44736 +#define elf_dyn Elf32_Dyn
44737 #define elf_addr_t Elf32_Addr
44738
44739 /*
44740 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44741 index 4c6285f..b7a2411 100644
44742 --- a/fs/compat_ioctl.c
44743 +++ b/fs/compat_ioctl.c
44744 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44745 return -EFAULT;
44746 if (__get_user(udata, &ss32->iomem_base))
44747 return -EFAULT;
44748 - ss.iomem_base = compat_ptr(udata);
44749 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44750 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44751 __get_user(ss.port_high, &ss32->port_high))
44752 return -EFAULT;
44753 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44754 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44755 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44756 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44757 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44758 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44759 return -EFAULT;
44760
44761 return ioctl_preallocate(file, p);
44762 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44763 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44764 {
44765 unsigned int a, b;
44766 - a = *(unsigned int *)p;
44767 - b = *(unsigned int *)q;
44768 + a = *(const unsigned int *)p;
44769 + b = *(const unsigned int *)q;
44770 if (a > b)
44771 return 1;
44772 if (a < b)
44773 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44774 index 7414ae2..d98ad6d 100644
44775 --- a/fs/configfs/dir.c
44776 +++ b/fs/configfs/dir.c
44777 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44778 }
44779 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44780 struct configfs_dirent *next;
44781 - const char * name;
44782 + const unsigned char * name;
44783 + char d_name[sizeof(next->s_dentry->d_iname)];
44784 int len;
44785 struct inode *inode = NULL;
44786
44787 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44788 continue;
44789
44790 name = configfs_get_name(next);
44791 - len = strlen(name);
44792 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44793 + len = next->s_dentry->d_name.len;
44794 + memcpy(d_name, name, len);
44795 + name = d_name;
44796 + } else
44797 + len = strlen(name);
44798
44799 /*
44800 * We'll have a dentry and an inode for
44801 diff --git a/fs/coredump.c b/fs/coredump.c
44802 index ce47379..68c8e43 100644
44803 --- a/fs/coredump.c
44804 +++ b/fs/coredump.c
44805 @@ -52,7 +52,7 @@ struct core_name {
44806 char *corename;
44807 int used, size;
44808 };
44809 -static atomic_t call_count = ATOMIC_INIT(1);
44810 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44811
44812 /* The maximal length of core_pattern is also specified in sysctl.c */
44813
44814 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
44815 {
44816 char *old_corename = cn->corename;
44817
44818 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44819 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44820 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44821
44822 if (!cn->corename) {
44823 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
44824 int pid_in_pattern = 0;
44825 int err = 0;
44826
44827 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44828 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44829 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44830 cn->used = 0;
44831
44832 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
44833 pipe = file->f_path.dentry->d_inode->i_pipe;
44834
44835 pipe_lock(pipe);
44836 - pipe->readers++;
44837 - pipe->writers--;
44838 + atomic_inc(&pipe->readers);
44839 + atomic_dec(&pipe->writers);
44840
44841 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44842 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44843 wake_up_interruptible_sync(&pipe->wait);
44844 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44845 pipe_wait(pipe);
44846 }
44847
44848 - pipe->readers--;
44849 - pipe->writers++;
44850 + atomic_dec(&pipe->readers);
44851 + atomic_inc(&pipe->writers);
44852 pipe_unlock(pipe);
44853
44854 }
44855 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44856 int ispipe;
44857 struct files_struct *displaced;
44858 bool need_nonrelative = false;
44859 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44860 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44861 + long signr = siginfo->si_signo;
44862 struct coredump_params cprm = {
44863 .siginfo = siginfo,
44864 .regs = regs,
44865 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44866 .mm_flags = mm->flags,
44867 };
44868
44869 - audit_core_dumps(siginfo->si_signo);
44870 + audit_core_dumps(signr);
44871 +
44872 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44873 + gr_handle_brute_attach(cprm.mm_flags);
44874
44875 binfmt = mm->binfmt;
44876 if (!binfmt || !binfmt->core_dump)
44877 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44878 need_nonrelative = true;
44879 }
44880
44881 - retval = coredump_wait(siginfo->si_signo, &core_state);
44882 + retval = coredump_wait(signr, &core_state);
44883 if (retval < 0)
44884 goto fail_creds;
44885
44886 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44887 }
44888 cprm.limit = RLIM_INFINITY;
44889
44890 - dump_count = atomic_inc_return(&core_dump_count);
44891 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44892 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44893 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44894 task_tgid_vnr(current), current->comm);
44895 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
44896 } else {
44897 struct inode *inode;
44898
44899 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44900 +
44901 if (cprm.limit < binfmt->min_coredump)
44902 goto fail_unlock;
44903
44904 @@ -640,7 +646,7 @@ close_fail:
44905 filp_close(cprm.file, NULL);
44906 fail_dropcount:
44907 if (ispipe)
44908 - atomic_dec(&core_dump_count);
44909 + atomic_dec_unchecked(&core_dump_count);
44910 fail_unlock:
44911 kfree(cn.corename);
44912 fail_corename:
44913 @@ -659,7 +665,7 @@ fail:
44914 */
44915 int dump_write(struct file *file, const void *addr, int nr)
44916 {
44917 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44918 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44919 }
44920 EXPORT_SYMBOL(dump_write);
44921
44922 diff --git a/fs/dcache.c b/fs/dcache.c
44923 index 3a463d0..9f345c8 100644
44924 --- a/fs/dcache.c
44925 +++ b/fs/dcache.c
44926 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44927 mempages -= reserve;
44928
44929 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44930 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44931 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44932
44933 dcache_init();
44934 inode_init();
44935 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44936 index b607d92..41fda09 100644
44937 --- a/fs/debugfs/inode.c
44938 +++ b/fs/debugfs/inode.c
44939 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44940 */
44941 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44942 {
44943 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44944 + return __create_file(name, S_IFDIR | S_IRWXU,
44945 +#else
44946 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44947 +#endif
44948 parent, NULL, NULL);
44949 }
44950 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44951 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44952 index cc7709e..7e7211f 100644
44953 --- a/fs/ecryptfs/inode.c
44954 +++ b/fs/ecryptfs/inode.c
44955 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44956 old_fs = get_fs();
44957 set_fs(get_ds());
44958 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44959 - (char __user *)lower_buf,
44960 + (char __force_user *)lower_buf,
44961 PATH_MAX);
44962 set_fs(old_fs);
44963 if (rc < 0)
44964 @@ -706,7 +706,7 @@ out:
44965 static void
44966 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44967 {
44968 - char *buf = nd_get_link(nd);
44969 + const char *buf = nd_get_link(nd);
44970 if (!IS_ERR(buf)) {
44971 /* Free the char* */
44972 kfree(buf);
44973 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44974 index 412e6ed..4292d22 100644
44975 --- a/fs/ecryptfs/miscdev.c
44976 +++ b/fs/ecryptfs/miscdev.c
44977 @@ -315,7 +315,7 @@ check_list:
44978 goto out_unlock_msg_ctx;
44979 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44980 if (msg_ctx->msg) {
44981 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44982 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44983 goto out_unlock_msg_ctx;
44984 i += packet_length_size;
44985 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44986 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44987 index b2a34a1..162fa69 100644
44988 --- a/fs/ecryptfs/read_write.c
44989 +++ b/fs/ecryptfs/read_write.c
44990 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44991 return -EIO;
44992 fs_save = get_fs();
44993 set_fs(get_ds());
44994 - rc = vfs_write(lower_file, data, size, &offset);
44995 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44996 set_fs(fs_save);
44997 mark_inode_dirty_sync(ecryptfs_inode);
44998 return rc;
44999 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
45000 return -EIO;
45001 fs_save = get_fs();
45002 set_fs(get_ds());
45003 - rc = vfs_read(lower_file, data, size, &offset);
45004 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
45005 set_fs(fs_save);
45006 return rc;
45007 }
45008 diff --git a/fs/exec.c b/fs/exec.c
45009 index 0039055..ffc560c 100644
45010 --- a/fs/exec.c
45011 +++ b/fs/exec.c
45012 @@ -55,6 +55,16 @@
45013 #include <linux/pipe_fs_i.h>
45014 #include <linux/oom.h>
45015 #include <linux/compat.h>
45016 +#include <linux/random.h>
45017 +#include <linux/seq_file.h>
45018 +#include <linux/coredump.h>
45019 +
45020 +#ifdef CONFIG_PAX_REFCOUNT
45021 +#include <linux/kallsyms.h>
45022 +#include <linux/kdebug.h>
45023 +#endif
45024 +
45025 +#include <trace/events/fs.h>
45026
45027 #include <asm/uaccess.h>
45028 #include <asm/mmu_context.h>
45029 @@ -66,6 +76,18 @@
45030
45031 #include <trace/events/sched.h>
45032
45033 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45034 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
45035 +{
45036 + 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");
45037 +}
45038 +#endif
45039 +
45040 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
45041 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
45042 +EXPORT_SYMBOL(pax_set_initial_flags_func);
45043 +#endif
45044 +
45045 int suid_dumpable = 0;
45046
45047 static LIST_HEAD(formats);
45048 @@ -180,18 +202,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45049 int write)
45050 {
45051 struct page *page;
45052 - int ret;
45053
45054 -#ifdef CONFIG_STACK_GROWSUP
45055 - if (write) {
45056 - ret = expand_downwards(bprm->vma, pos);
45057 - if (ret < 0)
45058 - return NULL;
45059 - }
45060 -#endif
45061 - ret = get_user_pages(current, bprm->mm, pos,
45062 - 1, write, 1, &page, NULL);
45063 - if (ret <= 0)
45064 + if (0 > expand_downwards(bprm->vma, pos))
45065 + return NULL;
45066 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45067 return NULL;
45068
45069 if (write) {
45070 @@ -207,6 +221,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45071 if (size <= ARG_MAX)
45072 return page;
45073
45074 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45075 + // only allow 512KB for argv+env on suid/sgid binaries
45076 + // to prevent easy ASLR exhaustion
45077 + if (((bprm->cred->euid != current_euid()) ||
45078 + (bprm->cred->egid != current_egid())) &&
45079 + (size > (512 * 1024))) {
45080 + put_page(page);
45081 + return NULL;
45082 + }
45083 +#endif
45084 +
45085 /*
45086 * Limit to 1/4-th the stack size for the argv+env strings.
45087 * This ensures that:
45088 @@ -266,6 +291,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45089 vma->vm_end = STACK_TOP_MAX;
45090 vma->vm_start = vma->vm_end - PAGE_SIZE;
45091 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45092 +
45093 +#ifdef CONFIG_PAX_SEGMEXEC
45094 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45095 +#endif
45096 +
45097 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45098 INIT_LIST_HEAD(&vma->anon_vma_chain);
45099
45100 @@ -276,6 +306,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45101 mm->stack_vm = mm->total_vm = 1;
45102 up_write(&mm->mmap_sem);
45103 bprm->p = vma->vm_end - sizeof(void *);
45104 +
45105 +#ifdef CONFIG_PAX_RANDUSTACK
45106 + if (randomize_va_space)
45107 + bprm->p ^= random32() & ~PAGE_MASK;
45108 +#endif
45109 +
45110 return 0;
45111 err:
45112 up_write(&mm->mmap_sem);
45113 @@ -384,19 +420,7 @@ err:
45114 return err;
45115 }
45116
45117 -struct user_arg_ptr {
45118 -#ifdef CONFIG_COMPAT
45119 - bool is_compat;
45120 -#endif
45121 - union {
45122 - const char __user *const __user *native;
45123 -#ifdef CONFIG_COMPAT
45124 - const compat_uptr_t __user *compat;
45125 -#endif
45126 - } ptr;
45127 -};
45128 -
45129 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45130 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45131 {
45132 const char __user *native;
45133
45134 @@ -405,14 +429,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45135 compat_uptr_t compat;
45136
45137 if (get_user(compat, argv.ptr.compat + nr))
45138 - return ERR_PTR(-EFAULT);
45139 + return (const char __force_user *)ERR_PTR(-EFAULT);
45140
45141 return compat_ptr(compat);
45142 }
45143 #endif
45144
45145 if (get_user(native, argv.ptr.native + nr))
45146 - return ERR_PTR(-EFAULT);
45147 + return (const char __force_user *)ERR_PTR(-EFAULT);
45148
45149 return native;
45150 }
45151 @@ -431,7 +455,7 @@ static int count(struct user_arg_ptr argv, int max)
45152 if (!p)
45153 break;
45154
45155 - if (IS_ERR(p))
45156 + if (IS_ERR((const char __force_kernel *)p))
45157 return -EFAULT;
45158
45159 if (i++ >= max)
45160 @@ -465,7 +489,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45161
45162 ret = -EFAULT;
45163 str = get_user_arg_ptr(argv, argc);
45164 - if (IS_ERR(str))
45165 + if (IS_ERR((const char __force_kernel *)str))
45166 goto out;
45167
45168 len = strnlen_user(str, MAX_ARG_STRLEN);
45169 @@ -547,7 +571,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45170 int r;
45171 mm_segment_t oldfs = get_fs();
45172 struct user_arg_ptr argv = {
45173 - .ptr.native = (const char __user *const __user *)__argv,
45174 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45175 };
45176
45177 set_fs(KERNEL_DS);
45178 @@ -582,7 +606,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45179 unsigned long new_end = old_end - shift;
45180 struct mmu_gather tlb;
45181
45182 - BUG_ON(new_start > new_end);
45183 + if (new_start >= new_end || new_start < mmap_min_addr)
45184 + return -ENOMEM;
45185
45186 /*
45187 * ensure there are no vmas between where we want to go
45188 @@ -591,6 +616,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45189 if (vma != find_vma(mm, new_start))
45190 return -EFAULT;
45191
45192 +#ifdef CONFIG_PAX_SEGMEXEC
45193 + BUG_ON(pax_find_mirror_vma(vma));
45194 +#endif
45195 +
45196 /*
45197 * cover the whole range: [new_start, old_end)
45198 */
45199 @@ -671,10 +700,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45200 stack_top = arch_align_stack(stack_top);
45201 stack_top = PAGE_ALIGN(stack_top);
45202
45203 - if (unlikely(stack_top < mmap_min_addr) ||
45204 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45205 - return -ENOMEM;
45206 -
45207 stack_shift = vma->vm_end - stack_top;
45208
45209 bprm->p -= stack_shift;
45210 @@ -686,8 +711,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45211 bprm->exec -= stack_shift;
45212
45213 down_write(&mm->mmap_sem);
45214 +
45215 + /* Move stack pages down in memory. */
45216 + if (stack_shift) {
45217 + ret = shift_arg_pages(vma, stack_shift);
45218 + if (ret)
45219 + goto out_unlock;
45220 + }
45221 +
45222 vm_flags = VM_STACK_FLAGS;
45223
45224 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45225 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45226 + vm_flags &= ~VM_EXEC;
45227 +
45228 +#ifdef CONFIG_PAX_MPROTECT
45229 + if (mm->pax_flags & MF_PAX_MPROTECT)
45230 + vm_flags &= ~VM_MAYEXEC;
45231 +#endif
45232 +
45233 + }
45234 +#endif
45235 +
45236 /*
45237 * Adjust stack execute permissions; explicitly enable for
45238 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45239 @@ -706,13 +751,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45240 goto out_unlock;
45241 BUG_ON(prev != vma);
45242
45243 - /* Move stack pages down in memory. */
45244 - if (stack_shift) {
45245 - ret = shift_arg_pages(vma, stack_shift);
45246 - if (ret)
45247 - goto out_unlock;
45248 - }
45249 -
45250 /* mprotect_fixup is overkill to remove the temporary stack flags */
45251 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45252
45253 @@ -771,6 +809,8 @@ struct file *open_exec(const char *name)
45254
45255 fsnotify_open(file);
45256
45257 + trace_open_exec(name);
45258 +
45259 err = deny_write_access(file);
45260 if (err)
45261 goto exit;
45262 @@ -794,7 +834,7 @@ int kernel_read(struct file *file, loff_t offset,
45263 old_fs = get_fs();
45264 set_fs(get_ds());
45265 /* The cast to a user pointer is valid due to the set_fs() */
45266 - result = vfs_read(file, (void __user *)addr, count, &pos);
45267 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45268 set_fs(old_fs);
45269 return result;
45270 }
45271 @@ -1231,7 +1271,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45272 }
45273 rcu_read_unlock();
45274
45275 - if (p->fs->users > n_fs) {
45276 + if (atomic_read(&p->fs->users) > n_fs) {
45277 bprm->unsafe |= LSM_UNSAFE_SHARE;
45278 } else {
45279 res = -EAGAIN;
45280 @@ -1434,6 +1474,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45281
45282 EXPORT_SYMBOL(search_binary_handler);
45283
45284 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45285 +static DEFINE_PER_CPU(u64, exec_counter);
45286 +static int __init init_exec_counters(void)
45287 +{
45288 + unsigned int cpu;
45289 +
45290 + for_each_possible_cpu(cpu) {
45291 + per_cpu(exec_counter, cpu) = (u64)cpu;
45292 + }
45293 +
45294 + return 0;
45295 +}
45296 +early_initcall(init_exec_counters);
45297 +static inline void increment_exec_counter(void)
45298 +{
45299 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45300 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45301 +}
45302 +#else
45303 +static inline void increment_exec_counter(void) {}
45304 +#endif
45305 +
45306 /*
45307 * sys_execve() executes a new program.
45308 */
45309 @@ -1442,6 +1504,11 @@ static int do_execve_common(const char *filename,
45310 struct user_arg_ptr envp,
45311 struct pt_regs *regs)
45312 {
45313 +#ifdef CONFIG_GRKERNSEC
45314 + struct file *old_exec_file;
45315 + struct acl_subject_label *old_acl;
45316 + struct rlimit old_rlim[RLIM_NLIMITS];
45317 +#endif
45318 struct linux_binprm *bprm;
45319 struct file *file;
45320 struct files_struct *displaced;
45321 @@ -1449,6 +1516,8 @@ static int do_execve_common(const char *filename,
45322 int retval;
45323 const struct cred *cred = current_cred();
45324
45325 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45326 +
45327 /*
45328 * We move the actual failure in case of RLIMIT_NPROC excess from
45329 * set*uid() to execve() because too many poorly written programs
45330 @@ -1489,12 +1558,27 @@ static int do_execve_common(const char *filename,
45331 if (IS_ERR(file))
45332 goto out_unmark;
45333
45334 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45335 + retval = -EPERM;
45336 + goto out_file;
45337 + }
45338 +
45339 sched_exec();
45340
45341 bprm->file = file;
45342 bprm->filename = filename;
45343 bprm->interp = filename;
45344
45345 + if (gr_process_user_ban()) {
45346 + retval = -EPERM;
45347 + goto out_file;
45348 + }
45349 +
45350 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45351 + retval = -EACCES;
45352 + goto out_file;
45353 + }
45354 +
45355 retval = bprm_mm_init(bprm);
45356 if (retval)
45357 goto out_file;
45358 @@ -1511,24 +1595,65 @@ static int do_execve_common(const char *filename,
45359 if (retval < 0)
45360 goto out;
45361
45362 +#ifdef CONFIG_GRKERNSEC
45363 + old_acl = current->acl;
45364 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45365 + old_exec_file = current->exec_file;
45366 + get_file(file);
45367 + current->exec_file = file;
45368 +#endif
45369 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45370 + /* limit suid stack to 8MB
45371 + we saved the old limits above and will restore them if this exec fails
45372 + */
45373 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45374 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45375 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45376 +#endif
45377 +
45378 + if (!gr_tpe_allow(file)) {
45379 + retval = -EACCES;
45380 + goto out_fail;
45381 + }
45382 +
45383 + if (gr_check_crash_exec(file)) {
45384 + retval = -EACCES;
45385 + goto out_fail;
45386 + }
45387 +
45388 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45389 + bprm->unsafe);
45390 + if (retval < 0)
45391 + goto out_fail;
45392 +
45393 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45394 if (retval < 0)
45395 - goto out;
45396 + goto out_fail;
45397
45398 bprm->exec = bprm->p;
45399 retval = copy_strings(bprm->envc, envp, bprm);
45400 if (retval < 0)
45401 - goto out;
45402 + goto out_fail;
45403
45404 retval = copy_strings(bprm->argc, argv, bprm);
45405 if (retval < 0)
45406 - goto out;
45407 + goto out_fail;
45408 +
45409 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45410 +
45411 + gr_handle_exec_args(bprm, argv);
45412
45413 retval = search_binary_handler(bprm,regs);
45414 if (retval < 0)
45415 - goto out;
45416 + goto out_fail;
45417 +#ifdef CONFIG_GRKERNSEC
45418 + if (old_exec_file)
45419 + fput(old_exec_file);
45420 +#endif
45421
45422 /* execve succeeded */
45423 +
45424 + increment_exec_counter();
45425 current->fs->in_exec = 0;
45426 current->in_execve = 0;
45427 acct_update_integrals(current);
45428 @@ -1537,6 +1662,14 @@ static int do_execve_common(const char *filename,
45429 put_files_struct(displaced);
45430 return retval;
45431
45432 +out_fail:
45433 +#ifdef CONFIG_GRKERNSEC
45434 + current->acl = old_acl;
45435 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45436 + fput(current->exec_file);
45437 + current->exec_file = old_exec_file;
45438 +#endif
45439 +
45440 out:
45441 if (bprm->mm) {
45442 acct_arg_size(bprm, 0);
45443 @@ -1712,3 +1845,253 @@ int kernel_execve(const char *filename,
45444 ret_from_kernel_execve(p);
45445 }
45446 #endif
45447 +
45448 +int pax_check_flags(unsigned long *flags)
45449 +{
45450 + int retval = 0;
45451 +
45452 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45453 + if (*flags & MF_PAX_SEGMEXEC)
45454 + {
45455 + *flags &= ~MF_PAX_SEGMEXEC;
45456 + retval = -EINVAL;
45457 + }
45458 +#endif
45459 +
45460 + if ((*flags & MF_PAX_PAGEEXEC)
45461 +
45462 +#ifdef CONFIG_PAX_PAGEEXEC
45463 + && (*flags & MF_PAX_SEGMEXEC)
45464 +#endif
45465 +
45466 + )
45467 + {
45468 + *flags &= ~MF_PAX_PAGEEXEC;
45469 + retval = -EINVAL;
45470 + }
45471 +
45472 + if ((*flags & MF_PAX_MPROTECT)
45473 +
45474 +#ifdef CONFIG_PAX_MPROTECT
45475 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45476 +#endif
45477 +
45478 + )
45479 + {
45480 + *flags &= ~MF_PAX_MPROTECT;
45481 + retval = -EINVAL;
45482 + }
45483 +
45484 + if ((*flags & MF_PAX_EMUTRAMP)
45485 +
45486 +#ifdef CONFIG_PAX_EMUTRAMP
45487 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45488 +#endif
45489 +
45490 + )
45491 + {
45492 + *flags &= ~MF_PAX_EMUTRAMP;
45493 + retval = -EINVAL;
45494 + }
45495 +
45496 + return retval;
45497 +}
45498 +
45499 +EXPORT_SYMBOL(pax_check_flags);
45500 +
45501 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45502 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45503 +{
45504 + struct task_struct *tsk = current;
45505 + struct mm_struct *mm = current->mm;
45506 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45507 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45508 + char *path_exec = NULL;
45509 + char *path_fault = NULL;
45510 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45511 + siginfo_t info = { };
45512 +
45513 + if (buffer_exec && buffer_fault) {
45514 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45515 +
45516 + down_read(&mm->mmap_sem);
45517 + vma = mm->mmap;
45518 + while (vma && (!vma_exec || !vma_fault)) {
45519 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
45520 + vma_exec = vma;
45521 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45522 + vma_fault = vma;
45523 + vma = vma->vm_next;
45524 + }
45525 + if (vma_exec) {
45526 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45527 + if (IS_ERR(path_exec))
45528 + path_exec = "<path too long>";
45529 + else {
45530 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45531 + if (path_exec) {
45532 + *path_exec = 0;
45533 + path_exec = buffer_exec;
45534 + } else
45535 + path_exec = "<path too long>";
45536 + }
45537 + }
45538 + if (vma_fault) {
45539 + start = vma_fault->vm_start;
45540 + end = vma_fault->vm_end;
45541 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45542 + if (vma_fault->vm_file) {
45543 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45544 + if (IS_ERR(path_fault))
45545 + path_fault = "<path too long>";
45546 + else {
45547 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45548 + if (path_fault) {
45549 + *path_fault = 0;
45550 + path_fault = buffer_fault;
45551 + } else
45552 + path_fault = "<path too long>";
45553 + }
45554 + } else
45555 + path_fault = "<anonymous mapping>";
45556 + }
45557 + up_read(&mm->mmap_sem);
45558 + }
45559 + if (tsk->signal->curr_ip)
45560 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45561 + else
45562 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45563 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45564 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45565 + task_uid(tsk), task_euid(tsk), pc, sp);
45566 + free_page((unsigned long)buffer_exec);
45567 + free_page((unsigned long)buffer_fault);
45568 + pax_report_insns(regs, pc, sp);
45569 + info.si_signo = SIGKILL;
45570 + info.si_errno = 0;
45571 + info.si_code = SI_KERNEL;
45572 + info.si_pid = 0;
45573 + info.si_uid = 0;
45574 + do_coredump(&info, regs);
45575 +}
45576 +#endif
45577 +
45578 +#ifdef CONFIG_PAX_REFCOUNT
45579 +void pax_report_refcount_overflow(struct pt_regs *regs)
45580 +{
45581 + if (current->signal->curr_ip)
45582 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45583 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45584 + else
45585 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45586 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45587 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45588 + show_regs(regs);
45589 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45590 +}
45591 +#endif
45592 +
45593 +#ifdef CONFIG_PAX_USERCOPY
45594 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45595 +static noinline int check_stack_object(const void *obj, unsigned long len)
45596 +{
45597 + const void * const stack = task_stack_page(current);
45598 + const void * const stackend = stack + THREAD_SIZE;
45599 +
45600 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45601 + const void *frame = NULL;
45602 + const void *oldframe;
45603 +#endif
45604 +
45605 + if (obj + len < obj)
45606 + return -1;
45607 +
45608 + if (obj + len <= stack || stackend <= obj)
45609 + return 0;
45610 +
45611 + if (obj < stack || stackend < obj + len)
45612 + return -1;
45613 +
45614 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45615 + oldframe = __builtin_frame_address(1);
45616 + if (oldframe)
45617 + frame = __builtin_frame_address(2);
45618 + /*
45619 + low ----------------------------------------------> high
45620 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45621 + ^----------------^
45622 + allow copies only within here
45623 + */
45624 + while (stack <= frame && frame < stackend) {
45625 + /* if obj + len extends past the last frame, this
45626 + check won't pass and the next frame will be 0,
45627 + causing us to bail out and correctly report
45628 + the copy as invalid
45629 + */
45630 + if (obj + len <= frame)
45631 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45632 + oldframe = frame;
45633 + frame = *(const void * const *)frame;
45634 + }
45635 + return -1;
45636 +#else
45637 + return 1;
45638 +#endif
45639 +}
45640 +
45641 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45642 +{
45643 + if (current->signal->curr_ip)
45644 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45645 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45646 + else
45647 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45648 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45649 + dump_stack();
45650 + gr_handle_kernel_exploit();
45651 + do_group_exit(SIGKILL);
45652 +}
45653 +#endif
45654 +
45655 +void check_object_size(const void *ptr, unsigned long n, bool to)
45656 +{
45657 +
45658 +#ifdef CONFIG_PAX_USERCOPY
45659 + const char *type;
45660 +
45661 + if (!n)
45662 + return;
45663 +
45664 + type = check_heap_object(ptr, n, to);
45665 + if (!type) {
45666 + if (check_stack_object(ptr, n) != -1)
45667 + return;
45668 + type = "<process stack>";
45669 + }
45670 +
45671 + pax_report_usercopy(ptr, n, to, type);
45672 +#endif
45673 +
45674 +}
45675 +EXPORT_SYMBOL(check_object_size);
45676 +
45677 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45678 +void pax_track_stack(void)
45679 +{
45680 + unsigned long sp = (unsigned long)&sp;
45681 + if (sp < current_thread_info()->lowest_stack &&
45682 + sp > (unsigned long)task_stack_page(current))
45683 + current_thread_info()->lowest_stack = sp;
45684 +}
45685 +EXPORT_SYMBOL(pax_track_stack);
45686 +#endif
45687 +
45688 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45689 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45690 +{
45691 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45692 + dump_stack();
45693 + do_group_exit(SIGKILL);
45694 +}
45695 +EXPORT_SYMBOL(report_size_overflow);
45696 +#endif
45697 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45698 index 2616d0e..2ffdec9 100644
45699 --- a/fs/ext2/balloc.c
45700 +++ b/fs/ext2/balloc.c
45701 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45702
45703 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45704 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45705 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45706 + if (free_blocks < root_blocks + 1 &&
45707 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45708 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45709 - !in_group_p (sbi->s_resgid))) {
45710 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45711 return 0;
45712 }
45713 return 1;
45714 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45715 index 22548f5..41521d8 100644
45716 --- a/fs/ext3/balloc.c
45717 +++ b/fs/ext3/balloc.c
45718 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45719
45720 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45721 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45722 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45723 + if (free_blocks < root_blocks + 1 &&
45724 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45725 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45726 - !in_group_p (sbi->s_resgid))) {
45727 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45728 return 0;
45729 }
45730 return 1;
45731 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45732 index cf18217..8f6b9c3 100644
45733 --- a/fs/ext4/balloc.c
45734 +++ b/fs/ext4/balloc.c
45735 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45736 /* Hm, nope. Are (enough) root reserved clusters available? */
45737 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45738 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45739 - capable(CAP_SYS_RESOURCE) ||
45740 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45741 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45742 + capable_nolog(CAP_SYS_RESOURCE)) {
45743
45744 if (free_clusters >= (nclusters + dirty_clusters))
45745 return 1;
45746 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45747 index 3c20de1..6ff2460 100644
45748 --- a/fs/ext4/ext4.h
45749 +++ b/fs/ext4/ext4.h
45750 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
45751 unsigned long s_mb_last_start;
45752
45753 /* stats for buddy allocator */
45754 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45755 - atomic_t s_bal_success; /* we found long enough chunks */
45756 - atomic_t s_bal_allocated; /* in blocks */
45757 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45758 - atomic_t s_bal_goals; /* goal hits */
45759 - atomic_t s_bal_breaks; /* too long searches */
45760 - atomic_t s_bal_2orders; /* 2^order hits */
45761 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45762 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45763 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45764 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45765 + atomic_unchecked_t s_bal_goals; /* goal hits */
45766 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45767 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45768 spinlock_t s_bal_lock;
45769 unsigned long s_mb_buddies_generated;
45770 unsigned long long s_mb_generation_time;
45771 - atomic_t s_mb_lost_chunks;
45772 - atomic_t s_mb_preallocated;
45773 - atomic_t s_mb_discarded;
45774 + atomic_unchecked_t s_mb_lost_chunks;
45775 + atomic_unchecked_t s_mb_preallocated;
45776 + atomic_unchecked_t s_mb_discarded;
45777 atomic_t s_lock_busy;
45778
45779 /* locality groups */
45780 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
45781 index 3a100e7..c7efa88 100644
45782 --- a/fs/ext4/ialloc.c
45783 +++ b/fs/ext4/ialloc.c
45784 @@ -762,7 +762,6 @@ got:
45785
45786 BUFFER_TRACE(block_bitmap_bh, "dirty block bitmap");
45787 err = ext4_handle_dirty_metadata(handle, NULL, block_bitmap_bh);
45788 - brelse(block_bitmap_bh);
45789
45790 /* recheck and clear flag under lock if we still need to */
45791 ext4_lock_group(sb, group);
45792 @@ -775,6 +774,7 @@ got:
45793 ext4_group_desc_csum_set(sb, group, gdp);
45794 }
45795 ext4_unlock_group(sb, group);
45796 + brelse(block_bitmap_bh);
45797
45798 if (err)
45799 goto fail;
45800 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
45801 index b3c243b..772c318 100644
45802 --- a/fs/ext4/inode.c
45803 +++ b/fs/ext4/inode.c
45804 @@ -1503,6 +1503,7 @@ static void ext4_da_block_invalidatepages(struct mpage_da_data *mpd)
45805
45806 index = mpd->first_page;
45807 end = mpd->next_page - 1;
45808 + pagevec_init(&pvec, 0);
45809 while (index <= end) {
45810 nr_pages = pagevec_lookup(&pvec, mapping, index, PAGEVEC_SIZE);
45811 if (nr_pages == 0)
45812 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45813 index 526e553..3f2de85 100644
45814 --- a/fs/ext4/mballoc.c
45815 +++ b/fs/ext4/mballoc.c
45816 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45817 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45818
45819 if (EXT4_SB(sb)->s_mb_stats)
45820 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45821 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45822
45823 break;
45824 }
45825 @@ -2044,7 +2044,7 @@ repeat:
45826 ac->ac_status = AC_STATUS_CONTINUE;
45827 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45828 cr = 3;
45829 - atomic_inc(&sbi->s_mb_lost_chunks);
45830 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45831 goto repeat;
45832 }
45833 }
45834 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
45835 if (sbi->s_mb_stats) {
45836 ext4_msg(sb, KERN_INFO,
45837 "mballoc: %u blocks %u reqs (%u success)",
45838 - atomic_read(&sbi->s_bal_allocated),
45839 - atomic_read(&sbi->s_bal_reqs),
45840 - atomic_read(&sbi->s_bal_success));
45841 + atomic_read_unchecked(&sbi->s_bal_allocated),
45842 + atomic_read_unchecked(&sbi->s_bal_reqs),
45843 + atomic_read_unchecked(&sbi->s_bal_success));
45844 ext4_msg(sb, KERN_INFO,
45845 "mballoc: %u extents scanned, %u goal hits, "
45846 "%u 2^N hits, %u breaks, %u lost",
45847 - atomic_read(&sbi->s_bal_ex_scanned),
45848 - atomic_read(&sbi->s_bal_goals),
45849 - atomic_read(&sbi->s_bal_2orders),
45850 - atomic_read(&sbi->s_bal_breaks),
45851 - atomic_read(&sbi->s_mb_lost_chunks));
45852 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45853 + atomic_read_unchecked(&sbi->s_bal_goals),
45854 + atomic_read_unchecked(&sbi->s_bal_2orders),
45855 + atomic_read_unchecked(&sbi->s_bal_breaks),
45856 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45857 ext4_msg(sb, KERN_INFO,
45858 "mballoc: %lu generated and it took %Lu",
45859 sbi->s_mb_buddies_generated,
45860 sbi->s_mb_generation_time);
45861 ext4_msg(sb, KERN_INFO,
45862 "mballoc: %u preallocated, %u discarded",
45863 - atomic_read(&sbi->s_mb_preallocated),
45864 - atomic_read(&sbi->s_mb_discarded));
45865 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45866 + atomic_read_unchecked(&sbi->s_mb_discarded));
45867 }
45868
45869 free_percpu(sbi->s_locality_groups);
45870 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45871 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45872
45873 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45874 - atomic_inc(&sbi->s_bal_reqs);
45875 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45876 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45877 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45878 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45879 - atomic_inc(&sbi->s_bal_success);
45880 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45881 + atomic_inc_unchecked(&sbi->s_bal_success);
45882 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45883 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45884 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45885 - atomic_inc(&sbi->s_bal_goals);
45886 + atomic_inc_unchecked(&sbi->s_bal_goals);
45887 if (ac->ac_found > sbi->s_mb_max_to_scan)
45888 - atomic_inc(&sbi->s_bal_breaks);
45889 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45890 }
45891
45892 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45893 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45894 trace_ext4_mb_new_inode_pa(ac, pa);
45895
45896 ext4_mb_use_inode_pa(ac, pa);
45897 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45898 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45899
45900 ei = EXT4_I(ac->ac_inode);
45901 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45902 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45903 trace_ext4_mb_new_group_pa(ac, pa);
45904
45905 ext4_mb_use_group_pa(ac, pa);
45906 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45907 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45908
45909 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45910 lg = ac->ac_lg;
45911 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45912 * from the bitmap and continue.
45913 */
45914 }
45915 - atomic_add(free, &sbi->s_mb_discarded);
45916 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45917
45918 return err;
45919 }
45920 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45921 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45922 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45923 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45924 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45925 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45926 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45927
45928 return 0;
45929 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
45930 index 80928f7..c3f2b1f 100644
45931 --- a/fs/ext4/super.c
45932 +++ b/fs/ext4/super.c
45933 @@ -3202,7 +3202,6 @@ int ext4_calculate_overhead(struct super_block *sb)
45934 ext4_fsblk_t overhead = 0;
45935 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
45936
45937 - memset(buf, 0, PAGE_SIZE);
45938 if (!buf)
45939 return -ENOMEM;
45940
45941 diff --git a/fs/fcntl.c b/fs/fcntl.c
45942 index 71a600a..20d87b1 100644
45943 --- a/fs/fcntl.c
45944 +++ b/fs/fcntl.c
45945 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45946 if (err)
45947 return err;
45948
45949 + if (gr_handle_chroot_fowner(pid, type))
45950 + return -ENOENT;
45951 + if (gr_check_protected_task_fowner(pid, type))
45952 + return -EACCES;
45953 +
45954 f_modown(filp, pid, type, force);
45955 return 0;
45956 }
45957 diff --git a/fs/fifo.c b/fs/fifo.c
45958 index cf6f434..3d7942c 100644
45959 --- a/fs/fifo.c
45960 +++ b/fs/fifo.c
45961 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45962 */
45963 filp->f_op = &read_pipefifo_fops;
45964 pipe->r_counter++;
45965 - if (pipe->readers++ == 0)
45966 + if (atomic_inc_return(&pipe->readers) == 1)
45967 wake_up_partner(inode);
45968
45969 - if (!pipe->writers) {
45970 + if (!atomic_read(&pipe->writers)) {
45971 if ((filp->f_flags & O_NONBLOCK)) {
45972 /* suppress POLLHUP until we have
45973 * seen a writer */
45974 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45975 * errno=ENXIO when there is no process reading the FIFO.
45976 */
45977 ret = -ENXIO;
45978 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45979 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45980 goto err;
45981
45982 filp->f_op = &write_pipefifo_fops;
45983 pipe->w_counter++;
45984 - if (!pipe->writers++)
45985 + if (atomic_inc_return(&pipe->writers) == 1)
45986 wake_up_partner(inode);
45987
45988 - if (!pipe->readers) {
45989 + if (!atomic_read(&pipe->readers)) {
45990 if (wait_for_partner(inode, &pipe->r_counter))
45991 goto err_wr;
45992 }
45993 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45994 */
45995 filp->f_op = &rdwr_pipefifo_fops;
45996
45997 - pipe->readers++;
45998 - pipe->writers++;
45999 + atomic_inc(&pipe->readers);
46000 + atomic_inc(&pipe->writers);
46001 pipe->r_counter++;
46002 pipe->w_counter++;
46003 - if (pipe->readers == 1 || pipe->writers == 1)
46004 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46005 wake_up_partner(inode);
46006 break;
46007
46008 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46009 return 0;
46010
46011 err_rd:
46012 - if (!--pipe->readers)
46013 + if (atomic_dec_and_test(&pipe->readers))
46014 wake_up_interruptible(&pipe->wait);
46015 ret = -ERESTARTSYS;
46016 goto err;
46017
46018 err_wr:
46019 - if (!--pipe->writers)
46020 + if (atomic_dec_and_test(&pipe->writers))
46021 wake_up_interruptible(&pipe->wait);
46022 ret = -ERESTARTSYS;
46023 goto err;
46024
46025 err:
46026 - if (!pipe->readers && !pipe->writers)
46027 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46028 free_pipe_info(inode);
46029
46030 err_nocleanup:
46031 diff --git a/fs/file.c b/fs/file.c
46032 index eff2316..8c8930c 100644
46033 --- a/fs/file.c
46034 +++ b/fs/file.c
46035 @@ -16,6 +16,7 @@
46036 #include <linux/slab.h>
46037 #include <linux/vmalloc.h>
46038 #include <linux/file.h>
46039 +#include <linux/security.h>
46040 #include <linux/fdtable.h>
46041 #include <linux/bitops.h>
46042 #include <linux/interrupt.h>
46043 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
46044 if (!file)
46045 return __close_fd(files, fd);
46046
46047 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
46048 if (fd >= rlimit(RLIMIT_NOFILE))
46049 return -EBADF;
46050
46051 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
46052 if (unlikely(oldfd == newfd))
46053 return -EINVAL;
46054
46055 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
46056 if (newfd >= rlimit(RLIMIT_NOFILE))
46057 return -EBADF;
46058
46059 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
46060 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
46061 {
46062 int err;
46063 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
46064 if (from >= rlimit(RLIMIT_NOFILE))
46065 return -EINVAL;
46066 err = alloc_fd(from, flags);
46067 diff --git a/fs/filesystems.c b/fs/filesystems.c
46068 index da165f6..3671bdb 100644
46069 --- a/fs/filesystems.c
46070 +++ b/fs/filesystems.c
46071 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46072 int len = dot ? dot - name : strlen(name);
46073
46074 fs = __get_fs_type(name, len);
46075 +
46076 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46077 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46078 +#else
46079 if (!fs && (request_module("%.*s", len, name) == 0))
46080 +#endif
46081 fs = __get_fs_type(name, len);
46082
46083 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46084 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46085 index 5df4775..f656176 100644
46086 --- a/fs/fs_struct.c
46087 +++ b/fs/fs_struct.c
46088 @@ -4,6 +4,7 @@
46089 #include <linux/path.h>
46090 #include <linux/slab.h>
46091 #include <linux/fs_struct.h>
46092 +#include <linux/grsecurity.h>
46093 #include "internal.h"
46094
46095 /*
46096 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46097 write_seqcount_begin(&fs->seq);
46098 old_root = fs->root;
46099 fs->root = *path;
46100 + gr_set_chroot_entries(current, path);
46101 write_seqcount_end(&fs->seq);
46102 spin_unlock(&fs->lock);
46103 if (old_root.dentry)
46104 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46105 return 1;
46106 }
46107
46108 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46109 +{
46110 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46111 + return 0;
46112 + *p = *new;
46113 +
46114 + /* This function is only called from pivot_root(). Leave our
46115 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46116 + pivoted root isn't treated as a chroot
46117 + */
46118 + //gr_set_chroot_entries(task, new);
46119 +
46120 + return 1;
46121 +}
46122 +
46123 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46124 {
46125 struct task_struct *g, *p;
46126 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46127 int hits = 0;
46128 spin_lock(&fs->lock);
46129 write_seqcount_begin(&fs->seq);
46130 - hits += replace_path(&fs->root, old_root, new_root);
46131 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46132 hits += replace_path(&fs->pwd, old_root, new_root);
46133 write_seqcount_end(&fs->seq);
46134 while (hits--) {
46135 @@ -94,12 +111,15 @@ void exit_fs(struct task_struct *tsk)
46136 {
46137 struct fs_struct *fs = tsk->fs;
46138
46139 + gr_put_exec_file(tsk);
46140 +
46141 if (fs) {
46142 int kill;
46143 task_lock(tsk);
46144 spin_lock(&fs->lock);
46145 tsk->fs = NULL;
46146 - kill = !--fs->users;
46147 + gr_clear_chroot_entries(tsk);
46148 + kill = !atomic_dec_return(&fs->users);
46149 spin_unlock(&fs->lock);
46150 task_unlock(tsk);
46151 if (kill)
46152 @@ -112,7 +132,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46153 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46154 /* We don't need to lock fs - think why ;-) */
46155 if (fs) {
46156 - fs->users = 1;
46157 + atomic_set(&fs->users, 1);
46158 fs->in_exec = 0;
46159 spin_lock_init(&fs->lock);
46160 seqcount_init(&fs->seq);
46161 @@ -121,6 +141,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46162 spin_lock(&old->lock);
46163 fs->root = old->root;
46164 path_get(&fs->root);
46165 + /* instead of calling gr_set_chroot_entries here,
46166 + we call it from every caller of this function
46167 + */
46168 fs->pwd = old->pwd;
46169 path_get(&fs->pwd);
46170 spin_unlock(&old->lock);
46171 @@ -139,8 +162,9 @@ int unshare_fs_struct(void)
46172
46173 task_lock(current);
46174 spin_lock(&fs->lock);
46175 - kill = !--fs->users;
46176 + kill = !atomic_dec_return(&fs->users);
46177 current->fs = new_fs;
46178 + gr_set_chroot_entries(current, &new_fs->root);
46179 spin_unlock(&fs->lock);
46180 task_unlock(current);
46181
46182 @@ -153,13 +177,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46183
46184 int current_umask(void)
46185 {
46186 - return current->fs->umask;
46187 + return current->fs->umask | gr_acl_umask();
46188 }
46189 EXPORT_SYMBOL(current_umask);
46190
46191 /* to be mentioned only in INIT_TASK */
46192 struct fs_struct init_fs = {
46193 - .users = 1,
46194 + .users = ATOMIC_INIT(1),
46195 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46196 .seq = SEQCNT_ZERO,
46197 .umask = 0022,
46198 @@ -169,18 +193,21 @@ void daemonize_fs_struct(void)
46199 {
46200 struct fs_struct *fs = current->fs;
46201
46202 + gr_put_exec_file(current);
46203 +
46204 if (fs) {
46205 int kill;
46206
46207 task_lock(current);
46208
46209 spin_lock(&init_fs.lock);
46210 - init_fs.users++;
46211 + atomic_inc(&init_fs.users);
46212 spin_unlock(&init_fs.lock);
46213
46214 spin_lock(&fs->lock);
46215 current->fs = &init_fs;
46216 - kill = !--fs->users;
46217 + gr_set_chroot_entries(current, &current->fs->root);
46218 + kill = !atomic_dec_return(&fs->users);
46219 spin_unlock(&fs->lock);
46220
46221 task_unlock(current);
46222 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46223 index 9905350..02eaec4 100644
46224 --- a/fs/fscache/cookie.c
46225 +++ b/fs/fscache/cookie.c
46226 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46227 parent ? (char *) parent->def->name : "<no-parent>",
46228 def->name, netfs_data);
46229
46230 - fscache_stat(&fscache_n_acquires);
46231 + fscache_stat_unchecked(&fscache_n_acquires);
46232
46233 /* if there's no parent cookie, then we don't create one here either */
46234 if (!parent) {
46235 - fscache_stat(&fscache_n_acquires_null);
46236 + fscache_stat_unchecked(&fscache_n_acquires_null);
46237 _leave(" [no parent]");
46238 return NULL;
46239 }
46240 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46241 /* allocate and initialise a cookie */
46242 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46243 if (!cookie) {
46244 - fscache_stat(&fscache_n_acquires_oom);
46245 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46246 _leave(" [ENOMEM]");
46247 return NULL;
46248 }
46249 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46250
46251 switch (cookie->def->type) {
46252 case FSCACHE_COOKIE_TYPE_INDEX:
46253 - fscache_stat(&fscache_n_cookie_index);
46254 + fscache_stat_unchecked(&fscache_n_cookie_index);
46255 break;
46256 case FSCACHE_COOKIE_TYPE_DATAFILE:
46257 - fscache_stat(&fscache_n_cookie_data);
46258 + fscache_stat_unchecked(&fscache_n_cookie_data);
46259 break;
46260 default:
46261 - fscache_stat(&fscache_n_cookie_special);
46262 + fscache_stat_unchecked(&fscache_n_cookie_special);
46263 break;
46264 }
46265
46266 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46267 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46268 atomic_dec(&parent->n_children);
46269 __fscache_cookie_put(cookie);
46270 - fscache_stat(&fscache_n_acquires_nobufs);
46271 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46272 _leave(" = NULL");
46273 return NULL;
46274 }
46275 }
46276
46277 - fscache_stat(&fscache_n_acquires_ok);
46278 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46279 _leave(" = %p", cookie);
46280 return cookie;
46281 }
46282 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46283 cache = fscache_select_cache_for_object(cookie->parent);
46284 if (!cache) {
46285 up_read(&fscache_addremove_sem);
46286 - fscache_stat(&fscache_n_acquires_no_cache);
46287 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46288 _leave(" = -ENOMEDIUM [no cache]");
46289 return -ENOMEDIUM;
46290 }
46291 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46292 object = cache->ops->alloc_object(cache, cookie);
46293 fscache_stat_d(&fscache_n_cop_alloc_object);
46294 if (IS_ERR(object)) {
46295 - fscache_stat(&fscache_n_object_no_alloc);
46296 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46297 ret = PTR_ERR(object);
46298 goto error;
46299 }
46300
46301 - fscache_stat(&fscache_n_object_alloc);
46302 + fscache_stat_unchecked(&fscache_n_object_alloc);
46303
46304 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46305
46306 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46307 struct fscache_object *object;
46308 struct hlist_node *_p;
46309
46310 - fscache_stat(&fscache_n_updates);
46311 + fscache_stat_unchecked(&fscache_n_updates);
46312
46313 if (!cookie) {
46314 - fscache_stat(&fscache_n_updates_null);
46315 + fscache_stat_unchecked(&fscache_n_updates_null);
46316 _leave(" [no cookie]");
46317 return;
46318 }
46319 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46320 struct fscache_object *object;
46321 unsigned long event;
46322
46323 - fscache_stat(&fscache_n_relinquishes);
46324 + fscache_stat_unchecked(&fscache_n_relinquishes);
46325 if (retire)
46326 - fscache_stat(&fscache_n_relinquishes_retire);
46327 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46328
46329 if (!cookie) {
46330 - fscache_stat(&fscache_n_relinquishes_null);
46331 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46332 _leave(" [no cookie]");
46333 return;
46334 }
46335 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46336
46337 /* wait for the cookie to finish being instantiated (or to fail) */
46338 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46339 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46340 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46341 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46342 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46343 }
46344 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46345 index f6aad48..88dcf26 100644
46346 --- a/fs/fscache/internal.h
46347 +++ b/fs/fscache/internal.h
46348 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46349 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46350 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46351
46352 -extern atomic_t fscache_n_op_pend;
46353 -extern atomic_t fscache_n_op_run;
46354 -extern atomic_t fscache_n_op_enqueue;
46355 -extern atomic_t fscache_n_op_deferred_release;
46356 -extern atomic_t fscache_n_op_release;
46357 -extern atomic_t fscache_n_op_gc;
46358 -extern atomic_t fscache_n_op_cancelled;
46359 -extern atomic_t fscache_n_op_rejected;
46360 +extern atomic_unchecked_t fscache_n_op_pend;
46361 +extern atomic_unchecked_t fscache_n_op_run;
46362 +extern atomic_unchecked_t fscache_n_op_enqueue;
46363 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46364 +extern atomic_unchecked_t fscache_n_op_release;
46365 +extern atomic_unchecked_t fscache_n_op_gc;
46366 +extern atomic_unchecked_t fscache_n_op_cancelled;
46367 +extern atomic_unchecked_t fscache_n_op_rejected;
46368
46369 -extern atomic_t fscache_n_attr_changed;
46370 -extern atomic_t fscache_n_attr_changed_ok;
46371 -extern atomic_t fscache_n_attr_changed_nobufs;
46372 -extern atomic_t fscache_n_attr_changed_nomem;
46373 -extern atomic_t fscache_n_attr_changed_calls;
46374 +extern atomic_unchecked_t fscache_n_attr_changed;
46375 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46376 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46377 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46378 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46379
46380 -extern atomic_t fscache_n_allocs;
46381 -extern atomic_t fscache_n_allocs_ok;
46382 -extern atomic_t fscache_n_allocs_wait;
46383 -extern atomic_t fscache_n_allocs_nobufs;
46384 -extern atomic_t fscache_n_allocs_intr;
46385 -extern atomic_t fscache_n_allocs_object_dead;
46386 -extern atomic_t fscache_n_alloc_ops;
46387 -extern atomic_t fscache_n_alloc_op_waits;
46388 +extern atomic_unchecked_t fscache_n_allocs;
46389 +extern atomic_unchecked_t fscache_n_allocs_ok;
46390 +extern atomic_unchecked_t fscache_n_allocs_wait;
46391 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46392 +extern atomic_unchecked_t fscache_n_allocs_intr;
46393 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46394 +extern atomic_unchecked_t fscache_n_alloc_ops;
46395 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46396
46397 -extern atomic_t fscache_n_retrievals;
46398 -extern atomic_t fscache_n_retrievals_ok;
46399 -extern atomic_t fscache_n_retrievals_wait;
46400 -extern atomic_t fscache_n_retrievals_nodata;
46401 -extern atomic_t fscache_n_retrievals_nobufs;
46402 -extern atomic_t fscache_n_retrievals_intr;
46403 -extern atomic_t fscache_n_retrievals_nomem;
46404 -extern atomic_t fscache_n_retrievals_object_dead;
46405 -extern atomic_t fscache_n_retrieval_ops;
46406 -extern atomic_t fscache_n_retrieval_op_waits;
46407 +extern atomic_unchecked_t fscache_n_retrievals;
46408 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46409 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46410 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46411 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46412 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46413 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46414 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46415 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46416 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46417
46418 -extern atomic_t fscache_n_stores;
46419 -extern atomic_t fscache_n_stores_ok;
46420 -extern atomic_t fscache_n_stores_again;
46421 -extern atomic_t fscache_n_stores_nobufs;
46422 -extern atomic_t fscache_n_stores_oom;
46423 -extern atomic_t fscache_n_store_ops;
46424 -extern atomic_t fscache_n_store_calls;
46425 -extern atomic_t fscache_n_store_pages;
46426 -extern atomic_t fscache_n_store_radix_deletes;
46427 -extern atomic_t fscache_n_store_pages_over_limit;
46428 +extern atomic_unchecked_t fscache_n_stores;
46429 +extern atomic_unchecked_t fscache_n_stores_ok;
46430 +extern atomic_unchecked_t fscache_n_stores_again;
46431 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46432 +extern atomic_unchecked_t fscache_n_stores_oom;
46433 +extern atomic_unchecked_t fscache_n_store_ops;
46434 +extern atomic_unchecked_t fscache_n_store_calls;
46435 +extern atomic_unchecked_t fscache_n_store_pages;
46436 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46437 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46438
46439 -extern atomic_t fscache_n_store_vmscan_not_storing;
46440 -extern atomic_t fscache_n_store_vmscan_gone;
46441 -extern atomic_t fscache_n_store_vmscan_busy;
46442 -extern atomic_t fscache_n_store_vmscan_cancelled;
46443 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46444 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46445 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46446 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46447
46448 -extern atomic_t fscache_n_marks;
46449 -extern atomic_t fscache_n_uncaches;
46450 +extern atomic_unchecked_t fscache_n_marks;
46451 +extern atomic_unchecked_t fscache_n_uncaches;
46452
46453 -extern atomic_t fscache_n_acquires;
46454 -extern atomic_t fscache_n_acquires_null;
46455 -extern atomic_t fscache_n_acquires_no_cache;
46456 -extern atomic_t fscache_n_acquires_ok;
46457 -extern atomic_t fscache_n_acquires_nobufs;
46458 -extern atomic_t fscache_n_acquires_oom;
46459 +extern atomic_unchecked_t fscache_n_acquires;
46460 +extern atomic_unchecked_t fscache_n_acquires_null;
46461 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46462 +extern atomic_unchecked_t fscache_n_acquires_ok;
46463 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46464 +extern atomic_unchecked_t fscache_n_acquires_oom;
46465
46466 -extern atomic_t fscache_n_updates;
46467 -extern atomic_t fscache_n_updates_null;
46468 -extern atomic_t fscache_n_updates_run;
46469 +extern atomic_unchecked_t fscache_n_updates;
46470 +extern atomic_unchecked_t fscache_n_updates_null;
46471 +extern atomic_unchecked_t fscache_n_updates_run;
46472
46473 -extern atomic_t fscache_n_relinquishes;
46474 -extern atomic_t fscache_n_relinquishes_null;
46475 -extern atomic_t fscache_n_relinquishes_waitcrt;
46476 -extern atomic_t fscache_n_relinquishes_retire;
46477 +extern atomic_unchecked_t fscache_n_relinquishes;
46478 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46479 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46480 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46481
46482 -extern atomic_t fscache_n_cookie_index;
46483 -extern atomic_t fscache_n_cookie_data;
46484 -extern atomic_t fscache_n_cookie_special;
46485 +extern atomic_unchecked_t fscache_n_cookie_index;
46486 +extern atomic_unchecked_t fscache_n_cookie_data;
46487 +extern atomic_unchecked_t fscache_n_cookie_special;
46488
46489 -extern atomic_t fscache_n_object_alloc;
46490 -extern atomic_t fscache_n_object_no_alloc;
46491 -extern atomic_t fscache_n_object_lookups;
46492 -extern atomic_t fscache_n_object_lookups_negative;
46493 -extern atomic_t fscache_n_object_lookups_positive;
46494 -extern atomic_t fscache_n_object_lookups_timed_out;
46495 -extern atomic_t fscache_n_object_created;
46496 -extern atomic_t fscache_n_object_avail;
46497 -extern atomic_t fscache_n_object_dead;
46498 +extern atomic_unchecked_t fscache_n_object_alloc;
46499 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46500 +extern atomic_unchecked_t fscache_n_object_lookups;
46501 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46502 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46503 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46504 +extern atomic_unchecked_t fscache_n_object_created;
46505 +extern atomic_unchecked_t fscache_n_object_avail;
46506 +extern atomic_unchecked_t fscache_n_object_dead;
46507
46508 -extern atomic_t fscache_n_checkaux_none;
46509 -extern atomic_t fscache_n_checkaux_okay;
46510 -extern atomic_t fscache_n_checkaux_update;
46511 -extern atomic_t fscache_n_checkaux_obsolete;
46512 +extern atomic_unchecked_t fscache_n_checkaux_none;
46513 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46514 +extern atomic_unchecked_t fscache_n_checkaux_update;
46515 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46516
46517 extern atomic_t fscache_n_cop_alloc_object;
46518 extern atomic_t fscache_n_cop_lookup_object;
46519 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46520 atomic_inc(stat);
46521 }
46522
46523 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46524 +{
46525 + atomic_inc_unchecked(stat);
46526 +}
46527 +
46528 static inline void fscache_stat_d(atomic_t *stat)
46529 {
46530 atomic_dec(stat);
46531 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46532
46533 #define __fscache_stat(stat) (NULL)
46534 #define fscache_stat(stat) do {} while (0)
46535 +#define fscache_stat_unchecked(stat) do {} while (0)
46536 #define fscache_stat_d(stat) do {} while (0)
46537 #endif
46538
46539 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46540 index b6b897c..0ffff9c 100644
46541 --- a/fs/fscache/object.c
46542 +++ b/fs/fscache/object.c
46543 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46544 /* update the object metadata on disk */
46545 case FSCACHE_OBJECT_UPDATING:
46546 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46547 - fscache_stat(&fscache_n_updates_run);
46548 + fscache_stat_unchecked(&fscache_n_updates_run);
46549 fscache_stat(&fscache_n_cop_update_object);
46550 object->cache->ops->update_object(object);
46551 fscache_stat_d(&fscache_n_cop_update_object);
46552 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46553 spin_lock(&object->lock);
46554 object->state = FSCACHE_OBJECT_DEAD;
46555 spin_unlock(&object->lock);
46556 - fscache_stat(&fscache_n_object_dead);
46557 + fscache_stat_unchecked(&fscache_n_object_dead);
46558 goto terminal_transit;
46559
46560 /* handle the parent cache of this object being withdrawn from
46561 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46562 spin_lock(&object->lock);
46563 object->state = FSCACHE_OBJECT_DEAD;
46564 spin_unlock(&object->lock);
46565 - fscache_stat(&fscache_n_object_dead);
46566 + fscache_stat_unchecked(&fscache_n_object_dead);
46567 goto terminal_transit;
46568
46569 /* complain about the object being woken up once it is
46570 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46571 parent->cookie->def->name, cookie->def->name,
46572 object->cache->tag->name);
46573
46574 - fscache_stat(&fscache_n_object_lookups);
46575 + fscache_stat_unchecked(&fscache_n_object_lookups);
46576 fscache_stat(&fscache_n_cop_lookup_object);
46577 ret = object->cache->ops->lookup_object(object);
46578 fscache_stat_d(&fscache_n_cop_lookup_object);
46579 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46580 if (ret == -ETIMEDOUT) {
46581 /* probably stuck behind another object, so move this one to
46582 * the back of the queue */
46583 - fscache_stat(&fscache_n_object_lookups_timed_out);
46584 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46585 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46586 }
46587
46588 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46589
46590 spin_lock(&object->lock);
46591 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46592 - fscache_stat(&fscache_n_object_lookups_negative);
46593 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46594
46595 /* transit here to allow write requests to begin stacking up
46596 * and read requests to begin returning ENODATA */
46597 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46598 * result, in which case there may be data available */
46599 spin_lock(&object->lock);
46600 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46601 - fscache_stat(&fscache_n_object_lookups_positive);
46602 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46603
46604 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46605
46606 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46607 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46608 } else {
46609 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46610 - fscache_stat(&fscache_n_object_created);
46611 + fscache_stat_unchecked(&fscache_n_object_created);
46612
46613 object->state = FSCACHE_OBJECT_AVAILABLE;
46614 spin_unlock(&object->lock);
46615 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46616 fscache_enqueue_dependents(object);
46617
46618 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46619 - fscache_stat(&fscache_n_object_avail);
46620 + fscache_stat_unchecked(&fscache_n_object_avail);
46621
46622 _leave("");
46623 }
46624 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46625 enum fscache_checkaux result;
46626
46627 if (!object->cookie->def->check_aux) {
46628 - fscache_stat(&fscache_n_checkaux_none);
46629 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46630 return FSCACHE_CHECKAUX_OKAY;
46631 }
46632
46633 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46634 switch (result) {
46635 /* entry okay as is */
46636 case FSCACHE_CHECKAUX_OKAY:
46637 - fscache_stat(&fscache_n_checkaux_okay);
46638 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46639 break;
46640
46641 /* entry requires update */
46642 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46643 - fscache_stat(&fscache_n_checkaux_update);
46644 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46645 break;
46646
46647 /* entry requires deletion */
46648 case FSCACHE_CHECKAUX_OBSOLETE:
46649 - fscache_stat(&fscache_n_checkaux_obsolete);
46650 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46651 break;
46652
46653 default:
46654 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46655 index 30afdfa..2256596 100644
46656 --- a/fs/fscache/operation.c
46657 +++ b/fs/fscache/operation.c
46658 @@ -17,7 +17,7 @@
46659 #include <linux/slab.h>
46660 #include "internal.h"
46661
46662 -atomic_t fscache_op_debug_id;
46663 +atomic_unchecked_t fscache_op_debug_id;
46664 EXPORT_SYMBOL(fscache_op_debug_id);
46665
46666 /**
46667 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46668 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46669 ASSERTCMP(atomic_read(&op->usage), >, 0);
46670
46671 - fscache_stat(&fscache_n_op_enqueue);
46672 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46673 switch (op->flags & FSCACHE_OP_TYPE) {
46674 case FSCACHE_OP_ASYNC:
46675 _debug("queue async");
46676 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46677 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46678 if (op->processor)
46679 fscache_enqueue_operation(op);
46680 - fscache_stat(&fscache_n_op_run);
46681 + fscache_stat_unchecked(&fscache_n_op_run);
46682 }
46683
46684 /*
46685 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46686 if (object->n_ops > 1) {
46687 atomic_inc(&op->usage);
46688 list_add_tail(&op->pend_link, &object->pending_ops);
46689 - fscache_stat(&fscache_n_op_pend);
46690 + fscache_stat_unchecked(&fscache_n_op_pend);
46691 } else if (!list_empty(&object->pending_ops)) {
46692 atomic_inc(&op->usage);
46693 list_add_tail(&op->pend_link, &object->pending_ops);
46694 - fscache_stat(&fscache_n_op_pend);
46695 + fscache_stat_unchecked(&fscache_n_op_pend);
46696 fscache_start_operations(object);
46697 } else {
46698 ASSERTCMP(object->n_in_progress, ==, 0);
46699 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46700 object->n_exclusive++; /* reads and writes must wait */
46701 atomic_inc(&op->usage);
46702 list_add_tail(&op->pend_link, &object->pending_ops);
46703 - fscache_stat(&fscache_n_op_pend);
46704 + fscache_stat_unchecked(&fscache_n_op_pend);
46705 ret = 0;
46706 } else {
46707 /* not allowed to submit ops in any other state */
46708 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46709 if (object->n_exclusive > 0) {
46710 atomic_inc(&op->usage);
46711 list_add_tail(&op->pend_link, &object->pending_ops);
46712 - fscache_stat(&fscache_n_op_pend);
46713 + fscache_stat_unchecked(&fscache_n_op_pend);
46714 } else if (!list_empty(&object->pending_ops)) {
46715 atomic_inc(&op->usage);
46716 list_add_tail(&op->pend_link, &object->pending_ops);
46717 - fscache_stat(&fscache_n_op_pend);
46718 + fscache_stat_unchecked(&fscache_n_op_pend);
46719 fscache_start_operations(object);
46720 } else {
46721 ASSERTCMP(object->n_exclusive, ==, 0);
46722 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46723 object->n_ops++;
46724 atomic_inc(&op->usage);
46725 list_add_tail(&op->pend_link, &object->pending_ops);
46726 - fscache_stat(&fscache_n_op_pend);
46727 + fscache_stat_unchecked(&fscache_n_op_pend);
46728 ret = 0;
46729 } else if (object->state == FSCACHE_OBJECT_DYING ||
46730 object->state == FSCACHE_OBJECT_LC_DYING ||
46731 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46732 - fscache_stat(&fscache_n_op_rejected);
46733 + fscache_stat_unchecked(&fscache_n_op_rejected);
46734 ret = -ENOBUFS;
46735 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46736 fscache_report_unexpected_submission(object, op, ostate);
46737 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46738
46739 ret = -EBUSY;
46740 if (!list_empty(&op->pend_link)) {
46741 - fscache_stat(&fscache_n_op_cancelled);
46742 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46743 list_del_init(&op->pend_link);
46744 object->n_ops--;
46745 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46746 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46747 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46748 BUG();
46749
46750 - fscache_stat(&fscache_n_op_release);
46751 + fscache_stat_unchecked(&fscache_n_op_release);
46752
46753 if (op->release) {
46754 op->release(op);
46755 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46756 * lock, and defer it otherwise */
46757 if (!spin_trylock(&object->lock)) {
46758 _debug("defer put");
46759 - fscache_stat(&fscache_n_op_deferred_release);
46760 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46761
46762 cache = object->cache;
46763 spin_lock(&cache->op_gc_list_lock);
46764 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46765
46766 _debug("GC DEFERRED REL OBJ%x OP%x",
46767 object->debug_id, op->debug_id);
46768 - fscache_stat(&fscache_n_op_gc);
46769 + fscache_stat_unchecked(&fscache_n_op_gc);
46770
46771 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46772
46773 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46774 index 3f7a59b..cf196cc 100644
46775 --- a/fs/fscache/page.c
46776 +++ b/fs/fscache/page.c
46777 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46778 val = radix_tree_lookup(&cookie->stores, page->index);
46779 if (!val) {
46780 rcu_read_unlock();
46781 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46782 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46783 __fscache_uncache_page(cookie, page);
46784 return true;
46785 }
46786 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46787 spin_unlock(&cookie->stores_lock);
46788
46789 if (xpage) {
46790 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46791 - fscache_stat(&fscache_n_store_radix_deletes);
46792 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46793 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46794 ASSERTCMP(xpage, ==, page);
46795 } else {
46796 - fscache_stat(&fscache_n_store_vmscan_gone);
46797 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46798 }
46799
46800 wake_up_bit(&cookie->flags, 0);
46801 @@ -107,7 +107,7 @@ page_busy:
46802 /* we might want to wait here, but that could deadlock the allocator as
46803 * the work threads writing to the cache may all end up sleeping
46804 * on memory allocation */
46805 - fscache_stat(&fscache_n_store_vmscan_busy);
46806 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46807 return false;
46808 }
46809 EXPORT_SYMBOL(__fscache_maybe_release_page);
46810 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46811 FSCACHE_COOKIE_STORING_TAG);
46812 if (!radix_tree_tag_get(&cookie->stores, page->index,
46813 FSCACHE_COOKIE_PENDING_TAG)) {
46814 - fscache_stat(&fscache_n_store_radix_deletes);
46815 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46816 xpage = radix_tree_delete(&cookie->stores, page->index);
46817 }
46818 spin_unlock(&cookie->stores_lock);
46819 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46820
46821 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46822
46823 - fscache_stat(&fscache_n_attr_changed_calls);
46824 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46825
46826 if (fscache_object_is_active(object)) {
46827 fscache_stat(&fscache_n_cop_attr_changed);
46828 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46829
46830 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46831
46832 - fscache_stat(&fscache_n_attr_changed);
46833 + fscache_stat_unchecked(&fscache_n_attr_changed);
46834
46835 op = kzalloc(sizeof(*op), GFP_KERNEL);
46836 if (!op) {
46837 - fscache_stat(&fscache_n_attr_changed_nomem);
46838 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46839 _leave(" = -ENOMEM");
46840 return -ENOMEM;
46841 }
46842 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46843 if (fscache_submit_exclusive_op(object, op) < 0)
46844 goto nobufs;
46845 spin_unlock(&cookie->lock);
46846 - fscache_stat(&fscache_n_attr_changed_ok);
46847 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46848 fscache_put_operation(op);
46849 _leave(" = 0");
46850 return 0;
46851 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46852 nobufs:
46853 spin_unlock(&cookie->lock);
46854 kfree(op);
46855 - fscache_stat(&fscache_n_attr_changed_nobufs);
46856 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46857 _leave(" = %d", -ENOBUFS);
46858 return -ENOBUFS;
46859 }
46860 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46861 /* allocate a retrieval operation and attempt to submit it */
46862 op = kzalloc(sizeof(*op), GFP_NOIO);
46863 if (!op) {
46864 - fscache_stat(&fscache_n_retrievals_nomem);
46865 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46866 return NULL;
46867 }
46868
46869 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46870 return 0;
46871 }
46872
46873 - fscache_stat(&fscache_n_retrievals_wait);
46874 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46875
46876 jif = jiffies;
46877 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46878 fscache_wait_bit_interruptible,
46879 TASK_INTERRUPTIBLE) != 0) {
46880 - fscache_stat(&fscache_n_retrievals_intr);
46881 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46882 _leave(" = -ERESTARTSYS");
46883 return -ERESTARTSYS;
46884 }
46885 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46886 */
46887 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46888 struct fscache_retrieval *op,
46889 - atomic_t *stat_op_waits,
46890 - atomic_t *stat_object_dead)
46891 + atomic_unchecked_t *stat_op_waits,
46892 + atomic_unchecked_t *stat_object_dead)
46893 {
46894 int ret;
46895
46896 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46897 goto check_if_dead;
46898
46899 _debug(">>> WT");
46900 - fscache_stat(stat_op_waits);
46901 + fscache_stat_unchecked(stat_op_waits);
46902 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46903 fscache_wait_bit_interruptible,
46904 TASK_INTERRUPTIBLE) < 0) {
46905 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46906
46907 check_if_dead:
46908 if (unlikely(fscache_object_is_dead(object))) {
46909 - fscache_stat(stat_object_dead);
46910 + fscache_stat_unchecked(stat_object_dead);
46911 return -ENOBUFS;
46912 }
46913 return 0;
46914 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46915
46916 _enter("%p,%p,,,", cookie, page);
46917
46918 - fscache_stat(&fscache_n_retrievals);
46919 + fscache_stat_unchecked(&fscache_n_retrievals);
46920
46921 if (hlist_empty(&cookie->backing_objects))
46922 goto nobufs;
46923 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46924 goto nobufs_unlock;
46925 spin_unlock(&cookie->lock);
46926
46927 - fscache_stat(&fscache_n_retrieval_ops);
46928 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46929
46930 /* pin the netfs read context in case we need to do the actual netfs
46931 * read because we've encountered a cache read failure */
46932 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46933
46934 error:
46935 if (ret == -ENOMEM)
46936 - fscache_stat(&fscache_n_retrievals_nomem);
46937 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46938 else if (ret == -ERESTARTSYS)
46939 - fscache_stat(&fscache_n_retrievals_intr);
46940 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46941 else if (ret == -ENODATA)
46942 - fscache_stat(&fscache_n_retrievals_nodata);
46943 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46944 else if (ret < 0)
46945 - fscache_stat(&fscache_n_retrievals_nobufs);
46946 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46947 else
46948 - fscache_stat(&fscache_n_retrievals_ok);
46949 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46950
46951 fscache_put_retrieval(op);
46952 _leave(" = %d", ret);
46953 @@ -429,7 +429,7 @@ nobufs_unlock:
46954 spin_unlock(&cookie->lock);
46955 kfree(op);
46956 nobufs:
46957 - fscache_stat(&fscache_n_retrievals_nobufs);
46958 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46959 _leave(" = -ENOBUFS");
46960 return -ENOBUFS;
46961 }
46962 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46963
46964 _enter("%p,,%d,,,", cookie, *nr_pages);
46965
46966 - fscache_stat(&fscache_n_retrievals);
46967 + fscache_stat_unchecked(&fscache_n_retrievals);
46968
46969 if (hlist_empty(&cookie->backing_objects))
46970 goto nobufs;
46971 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46972 goto nobufs_unlock;
46973 spin_unlock(&cookie->lock);
46974
46975 - fscache_stat(&fscache_n_retrieval_ops);
46976 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46977
46978 /* pin the netfs read context in case we need to do the actual netfs
46979 * read because we've encountered a cache read failure */
46980 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46981
46982 error:
46983 if (ret == -ENOMEM)
46984 - fscache_stat(&fscache_n_retrievals_nomem);
46985 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46986 else if (ret == -ERESTARTSYS)
46987 - fscache_stat(&fscache_n_retrievals_intr);
46988 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46989 else if (ret == -ENODATA)
46990 - fscache_stat(&fscache_n_retrievals_nodata);
46991 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46992 else if (ret < 0)
46993 - fscache_stat(&fscache_n_retrievals_nobufs);
46994 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46995 else
46996 - fscache_stat(&fscache_n_retrievals_ok);
46997 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46998
46999 fscache_put_retrieval(op);
47000 _leave(" = %d", ret);
47001 @@ -545,7 +545,7 @@ nobufs_unlock:
47002 spin_unlock(&cookie->lock);
47003 kfree(op);
47004 nobufs:
47005 - fscache_stat(&fscache_n_retrievals_nobufs);
47006 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47007 _leave(" = -ENOBUFS");
47008 return -ENOBUFS;
47009 }
47010 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47011
47012 _enter("%p,%p,,,", cookie, page);
47013
47014 - fscache_stat(&fscache_n_allocs);
47015 + fscache_stat_unchecked(&fscache_n_allocs);
47016
47017 if (hlist_empty(&cookie->backing_objects))
47018 goto nobufs;
47019 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47020 goto nobufs_unlock;
47021 spin_unlock(&cookie->lock);
47022
47023 - fscache_stat(&fscache_n_alloc_ops);
47024 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47025
47026 ret = fscache_wait_for_retrieval_activation(
47027 object, op,
47028 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47029
47030 error:
47031 if (ret == -ERESTARTSYS)
47032 - fscache_stat(&fscache_n_allocs_intr);
47033 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47034 else if (ret < 0)
47035 - fscache_stat(&fscache_n_allocs_nobufs);
47036 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47037 else
47038 - fscache_stat(&fscache_n_allocs_ok);
47039 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47040
47041 fscache_put_retrieval(op);
47042 _leave(" = %d", ret);
47043 @@ -625,7 +625,7 @@ nobufs_unlock:
47044 spin_unlock(&cookie->lock);
47045 kfree(op);
47046 nobufs:
47047 - fscache_stat(&fscache_n_allocs_nobufs);
47048 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47049 _leave(" = -ENOBUFS");
47050 return -ENOBUFS;
47051 }
47052 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47053
47054 spin_lock(&cookie->stores_lock);
47055
47056 - fscache_stat(&fscache_n_store_calls);
47057 + fscache_stat_unchecked(&fscache_n_store_calls);
47058
47059 /* find a page to store */
47060 page = NULL;
47061 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47062 page = results[0];
47063 _debug("gang %d [%lx]", n, page->index);
47064 if (page->index > op->store_limit) {
47065 - fscache_stat(&fscache_n_store_pages_over_limit);
47066 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47067 goto superseded;
47068 }
47069
47070 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47071 spin_unlock(&cookie->stores_lock);
47072 spin_unlock(&object->lock);
47073
47074 - fscache_stat(&fscache_n_store_pages);
47075 + fscache_stat_unchecked(&fscache_n_store_pages);
47076 fscache_stat(&fscache_n_cop_write_page);
47077 ret = object->cache->ops->write_page(op, page);
47078 fscache_stat_d(&fscache_n_cop_write_page);
47079 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47080 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47081 ASSERT(PageFsCache(page));
47082
47083 - fscache_stat(&fscache_n_stores);
47084 + fscache_stat_unchecked(&fscache_n_stores);
47085
47086 op = kzalloc(sizeof(*op), GFP_NOIO);
47087 if (!op)
47088 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47089 spin_unlock(&cookie->stores_lock);
47090 spin_unlock(&object->lock);
47091
47092 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47093 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47094 op->store_limit = object->store_limit;
47095
47096 if (fscache_submit_op(object, &op->op) < 0)
47097 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47098
47099 spin_unlock(&cookie->lock);
47100 radix_tree_preload_end();
47101 - fscache_stat(&fscache_n_store_ops);
47102 - fscache_stat(&fscache_n_stores_ok);
47103 + fscache_stat_unchecked(&fscache_n_store_ops);
47104 + fscache_stat_unchecked(&fscache_n_stores_ok);
47105
47106 /* the work queue now carries its own ref on the object */
47107 fscache_put_operation(&op->op);
47108 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47109 return 0;
47110
47111 already_queued:
47112 - fscache_stat(&fscache_n_stores_again);
47113 + fscache_stat_unchecked(&fscache_n_stores_again);
47114 already_pending:
47115 spin_unlock(&cookie->stores_lock);
47116 spin_unlock(&object->lock);
47117 spin_unlock(&cookie->lock);
47118 radix_tree_preload_end();
47119 kfree(op);
47120 - fscache_stat(&fscache_n_stores_ok);
47121 + fscache_stat_unchecked(&fscache_n_stores_ok);
47122 _leave(" = 0");
47123 return 0;
47124
47125 @@ -851,14 +851,14 @@ nobufs:
47126 spin_unlock(&cookie->lock);
47127 radix_tree_preload_end();
47128 kfree(op);
47129 - fscache_stat(&fscache_n_stores_nobufs);
47130 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47131 _leave(" = -ENOBUFS");
47132 return -ENOBUFS;
47133
47134 nomem_free:
47135 kfree(op);
47136 nomem:
47137 - fscache_stat(&fscache_n_stores_oom);
47138 + fscache_stat_unchecked(&fscache_n_stores_oom);
47139 _leave(" = -ENOMEM");
47140 return -ENOMEM;
47141 }
47142 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47143 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47144 ASSERTCMP(page, !=, NULL);
47145
47146 - fscache_stat(&fscache_n_uncaches);
47147 + fscache_stat_unchecked(&fscache_n_uncaches);
47148
47149 /* cache withdrawal may beat us to it */
47150 if (!PageFsCache(page))
47151 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47152 unsigned long loop;
47153
47154 #ifdef CONFIG_FSCACHE_STATS
47155 - atomic_add(pagevec->nr, &fscache_n_marks);
47156 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47157 #endif
47158
47159 for (loop = 0; loop < pagevec->nr; loop++) {
47160 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47161 index 4765190..2a067f2 100644
47162 --- a/fs/fscache/stats.c
47163 +++ b/fs/fscache/stats.c
47164 @@ -18,95 +18,95 @@
47165 /*
47166 * operation counters
47167 */
47168 -atomic_t fscache_n_op_pend;
47169 -atomic_t fscache_n_op_run;
47170 -atomic_t fscache_n_op_enqueue;
47171 -atomic_t fscache_n_op_requeue;
47172 -atomic_t fscache_n_op_deferred_release;
47173 -atomic_t fscache_n_op_release;
47174 -atomic_t fscache_n_op_gc;
47175 -atomic_t fscache_n_op_cancelled;
47176 -atomic_t fscache_n_op_rejected;
47177 +atomic_unchecked_t fscache_n_op_pend;
47178 +atomic_unchecked_t fscache_n_op_run;
47179 +atomic_unchecked_t fscache_n_op_enqueue;
47180 +atomic_unchecked_t fscache_n_op_requeue;
47181 +atomic_unchecked_t fscache_n_op_deferred_release;
47182 +atomic_unchecked_t fscache_n_op_release;
47183 +atomic_unchecked_t fscache_n_op_gc;
47184 +atomic_unchecked_t fscache_n_op_cancelled;
47185 +atomic_unchecked_t fscache_n_op_rejected;
47186
47187 -atomic_t fscache_n_attr_changed;
47188 -atomic_t fscache_n_attr_changed_ok;
47189 -atomic_t fscache_n_attr_changed_nobufs;
47190 -atomic_t fscache_n_attr_changed_nomem;
47191 -atomic_t fscache_n_attr_changed_calls;
47192 +atomic_unchecked_t fscache_n_attr_changed;
47193 +atomic_unchecked_t fscache_n_attr_changed_ok;
47194 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47195 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47196 +atomic_unchecked_t fscache_n_attr_changed_calls;
47197
47198 -atomic_t fscache_n_allocs;
47199 -atomic_t fscache_n_allocs_ok;
47200 -atomic_t fscache_n_allocs_wait;
47201 -atomic_t fscache_n_allocs_nobufs;
47202 -atomic_t fscache_n_allocs_intr;
47203 -atomic_t fscache_n_allocs_object_dead;
47204 -atomic_t fscache_n_alloc_ops;
47205 -atomic_t fscache_n_alloc_op_waits;
47206 +atomic_unchecked_t fscache_n_allocs;
47207 +atomic_unchecked_t fscache_n_allocs_ok;
47208 +atomic_unchecked_t fscache_n_allocs_wait;
47209 +atomic_unchecked_t fscache_n_allocs_nobufs;
47210 +atomic_unchecked_t fscache_n_allocs_intr;
47211 +atomic_unchecked_t fscache_n_allocs_object_dead;
47212 +atomic_unchecked_t fscache_n_alloc_ops;
47213 +atomic_unchecked_t fscache_n_alloc_op_waits;
47214
47215 -atomic_t fscache_n_retrievals;
47216 -atomic_t fscache_n_retrievals_ok;
47217 -atomic_t fscache_n_retrievals_wait;
47218 -atomic_t fscache_n_retrievals_nodata;
47219 -atomic_t fscache_n_retrievals_nobufs;
47220 -atomic_t fscache_n_retrievals_intr;
47221 -atomic_t fscache_n_retrievals_nomem;
47222 -atomic_t fscache_n_retrievals_object_dead;
47223 -atomic_t fscache_n_retrieval_ops;
47224 -atomic_t fscache_n_retrieval_op_waits;
47225 +atomic_unchecked_t fscache_n_retrievals;
47226 +atomic_unchecked_t fscache_n_retrievals_ok;
47227 +atomic_unchecked_t fscache_n_retrievals_wait;
47228 +atomic_unchecked_t fscache_n_retrievals_nodata;
47229 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47230 +atomic_unchecked_t fscache_n_retrievals_intr;
47231 +atomic_unchecked_t fscache_n_retrievals_nomem;
47232 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47233 +atomic_unchecked_t fscache_n_retrieval_ops;
47234 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47235
47236 -atomic_t fscache_n_stores;
47237 -atomic_t fscache_n_stores_ok;
47238 -atomic_t fscache_n_stores_again;
47239 -atomic_t fscache_n_stores_nobufs;
47240 -atomic_t fscache_n_stores_oom;
47241 -atomic_t fscache_n_store_ops;
47242 -atomic_t fscache_n_store_calls;
47243 -atomic_t fscache_n_store_pages;
47244 -atomic_t fscache_n_store_radix_deletes;
47245 -atomic_t fscache_n_store_pages_over_limit;
47246 +atomic_unchecked_t fscache_n_stores;
47247 +atomic_unchecked_t fscache_n_stores_ok;
47248 +atomic_unchecked_t fscache_n_stores_again;
47249 +atomic_unchecked_t fscache_n_stores_nobufs;
47250 +atomic_unchecked_t fscache_n_stores_oom;
47251 +atomic_unchecked_t fscache_n_store_ops;
47252 +atomic_unchecked_t fscache_n_store_calls;
47253 +atomic_unchecked_t fscache_n_store_pages;
47254 +atomic_unchecked_t fscache_n_store_radix_deletes;
47255 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47256
47257 -atomic_t fscache_n_store_vmscan_not_storing;
47258 -atomic_t fscache_n_store_vmscan_gone;
47259 -atomic_t fscache_n_store_vmscan_busy;
47260 -atomic_t fscache_n_store_vmscan_cancelled;
47261 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47262 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47263 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47264 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47265
47266 -atomic_t fscache_n_marks;
47267 -atomic_t fscache_n_uncaches;
47268 +atomic_unchecked_t fscache_n_marks;
47269 +atomic_unchecked_t fscache_n_uncaches;
47270
47271 -atomic_t fscache_n_acquires;
47272 -atomic_t fscache_n_acquires_null;
47273 -atomic_t fscache_n_acquires_no_cache;
47274 -atomic_t fscache_n_acquires_ok;
47275 -atomic_t fscache_n_acquires_nobufs;
47276 -atomic_t fscache_n_acquires_oom;
47277 +atomic_unchecked_t fscache_n_acquires;
47278 +atomic_unchecked_t fscache_n_acquires_null;
47279 +atomic_unchecked_t fscache_n_acquires_no_cache;
47280 +atomic_unchecked_t fscache_n_acquires_ok;
47281 +atomic_unchecked_t fscache_n_acquires_nobufs;
47282 +atomic_unchecked_t fscache_n_acquires_oom;
47283
47284 -atomic_t fscache_n_updates;
47285 -atomic_t fscache_n_updates_null;
47286 -atomic_t fscache_n_updates_run;
47287 +atomic_unchecked_t fscache_n_updates;
47288 +atomic_unchecked_t fscache_n_updates_null;
47289 +atomic_unchecked_t fscache_n_updates_run;
47290
47291 -atomic_t fscache_n_relinquishes;
47292 -atomic_t fscache_n_relinquishes_null;
47293 -atomic_t fscache_n_relinquishes_waitcrt;
47294 -atomic_t fscache_n_relinquishes_retire;
47295 +atomic_unchecked_t fscache_n_relinquishes;
47296 +atomic_unchecked_t fscache_n_relinquishes_null;
47297 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47298 +atomic_unchecked_t fscache_n_relinquishes_retire;
47299
47300 -atomic_t fscache_n_cookie_index;
47301 -atomic_t fscache_n_cookie_data;
47302 -atomic_t fscache_n_cookie_special;
47303 +atomic_unchecked_t fscache_n_cookie_index;
47304 +atomic_unchecked_t fscache_n_cookie_data;
47305 +atomic_unchecked_t fscache_n_cookie_special;
47306
47307 -atomic_t fscache_n_object_alloc;
47308 -atomic_t fscache_n_object_no_alloc;
47309 -atomic_t fscache_n_object_lookups;
47310 -atomic_t fscache_n_object_lookups_negative;
47311 -atomic_t fscache_n_object_lookups_positive;
47312 -atomic_t fscache_n_object_lookups_timed_out;
47313 -atomic_t fscache_n_object_created;
47314 -atomic_t fscache_n_object_avail;
47315 -atomic_t fscache_n_object_dead;
47316 +atomic_unchecked_t fscache_n_object_alloc;
47317 +atomic_unchecked_t fscache_n_object_no_alloc;
47318 +atomic_unchecked_t fscache_n_object_lookups;
47319 +atomic_unchecked_t fscache_n_object_lookups_negative;
47320 +atomic_unchecked_t fscache_n_object_lookups_positive;
47321 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47322 +atomic_unchecked_t fscache_n_object_created;
47323 +atomic_unchecked_t fscache_n_object_avail;
47324 +atomic_unchecked_t fscache_n_object_dead;
47325
47326 -atomic_t fscache_n_checkaux_none;
47327 -atomic_t fscache_n_checkaux_okay;
47328 -atomic_t fscache_n_checkaux_update;
47329 -atomic_t fscache_n_checkaux_obsolete;
47330 +atomic_unchecked_t fscache_n_checkaux_none;
47331 +atomic_unchecked_t fscache_n_checkaux_okay;
47332 +atomic_unchecked_t fscache_n_checkaux_update;
47333 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47334
47335 atomic_t fscache_n_cop_alloc_object;
47336 atomic_t fscache_n_cop_lookup_object;
47337 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47338 seq_puts(m, "FS-Cache statistics\n");
47339
47340 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47341 - atomic_read(&fscache_n_cookie_index),
47342 - atomic_read(&fscache_n_cookie_data),
47343 - atomic_read(&fscache_n_cookie_special));
47344 + atomic_read_unchecked(&fscache_n_cookie_index),
47345 + atomic_read_unchecked(&fscache_n_cookie_data),
47346 + atomic_read_unchecked(&fscache_n_cookie_special));
47347
47348 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47349 - atomic_read(&fscache_n_object_alloc),
47350 - atomic_read(&fscache_n_object_no_alloc),
47351 - atomic_read(&fscache_n_object_avail),
47352 - atomic_read(&fscache_n_object_dead));
47353 + atomic_read_unchecked(&fscache_n_object_alloc),
47354 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47355 + atomic_read_unchecked(&fscache_n_object_avail),
47356 + atomic_read_unchecked(&fscache_n_object_dead));
47357 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47358 - atomic_read(&fscache_n_checkaux_none),
47359 - atomic_read(&fscache_n_checkaux_okay),
47360 - atomic_read(&fscache_n_checkaux_update),
47361 - atomic_read(&fscache_n_checkaux_obsolete));
47362 + atomic_read_unchecked(&fscache_n_checkaux_none),
47363 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47364 + atomic_read_unchecked(&fscache_n_checkaux_update),
47365 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47366
47367 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47368 - atomic_read(&fscache_n_marks),
47369 - atomic_read(&fscache_n_uncaches));
47370 + atomic_read_unchecked(&fscache_n_marks),
47371 + atomic_read_unchecked(&fscache_n_uncaches));
47372
47373 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47374 " oom=%u\n",
47375 - atomic_read(&fscache_n_acquires),
47376 - atomic_read(&fscache_n_acquires_null),
47377 - atomic_read(&fscache_n_acquires_no_cache),
47378 - atomic_read(&fscache_n_acquires_ok),
47379 - atomic_read(&fscache_n_acquires_nobufs),
47380 - atomic_read(&fscache_n_acquires_oom));
47381 + atomic_read_unchecked(&fscache_n_acquires),
47382 + atomic_read_unchecked(&fscache_n_acquires_null),
47383 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47384 + atomic_read_unchecked(&fscache_n_acquires_ok),
47385 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47386 + atomic_read_unchecked(&fscache_n_acquires_oom));
47387
47388 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47389 - atomic_read(&fscache_n_object_lookups),
47390 - atomic_read(&fscache_n_object_lookups_negative),
47391 - atomic_read(&fscache_n_object_lookups_positive),
47392 - atomic_read(&fscache_n_object_created),
47393 - atomic_read(&fscache_n_object_lookups_timed_out));
47394 + atomic_read_unchecked(&fscache_n_object_lookups),
47395 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47396 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47397 + atomic_read_unchecked(&fscache_n_object_created),
47398 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47399
47400 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47401 - atomic_read(&fscache_n_updates),
47402 - atomic_read(&fscache_n_updates_null),
47403 - atomic_read(&fscache_n_updates_run));
47404 + atomic_read_unchecked(&fscache_n_updates),
47405 + atomic_read_unchecked(&fscache_n_updates_null),
47406 + atomic_read_unchecked(&fscache_n_updates_run));
47407
47408 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47409 - atomic_read(&fscache_n_relinquishes),
47410 - atomic_read(&fscache_n_relinquishes_null),
47411 - atomic_read(&fscache_n_relinquishes_waitcrt),
47412 - atomic_read(&fscache_n_relinquishes_retire));
47413 + atomic_read_unchecked(&fscache_n_relinquishes),
47414 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47415 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47416 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47417
47418 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47419 - atomic_read(&fscache_n_attr_changed),
47420 - atomic_read(&fscache_n_attr_changed_ok),
47421 - atomic_read(&fscache_n_attr_changed_nobufs),
47422 - atomic_read(&fscache_n_attr_changed_nomem),
47423 - atomic_read(&fscache_n_attr_changed_calls));
47424 + atomic_read_unchecked(&fscache_n_attr_changed),
47425 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47426 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47427 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47428 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47429
47430 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47431 - atomic_read(&fscache_n_allocs),
47432 - atomic_read(&fscache_n_allocs_ok),
47433 - atomic_read(&fscache_n_allocs_wait),
47434 - atomic_read(&fscache_n_allocs_nobufs),
47435 - atomic_read(&fscache_n_allocs_intr));
47436 + atomic_read_unchecked(&fscache_n_allocs),
47437 + atomic_read_unchecked(&fscache_n_allocs_ok),
47438 + atomic_read_unchecked(&fscache_n_allocs_wait),
47439 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47440 + atomic_read_unchecked(&fscache_n_allocs_intr));
47441 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47442 - atomic_read(&fscache_n_alloc_ops),
47443 - atomic_read(&fscache_n_alloc_op_waits),
47444 - atomic_read(&fscache_n_allocs_object_dead));
47445 + atomic_read_unchecked(&fscache_n_alloc_ops),
47446 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47447 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47448
47449 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47450 " int=%u oom=%u\n",
47451 - atomic_read(&fscache_n_retrievals),
47452 - atomic_read(&fscache_n_retrievals_ok),
47453 - atomic_read(&fscache_n_retrievals_wait),
47454 - atomic_read(&fscache_n_retrievals_nodata),
47455 - atomic_read(&fscache_n_retrievals_nobufs),
47456 - atomic_read(&fscache_n_retrievals_intr),
47457 - atomic_read(&fscache_n_retrievals_nomem));
47458 + atomic_read_unchecked(&fscache_n_retrievals),
47459 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47460 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47461 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47462 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47463 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47464 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47465 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47466 - atomic_read(&fscache_n_retrieval_ops),
47467 - atomic_read(&fscache_n_retrieval_op_waits),
47468 - atomic_read(&fscache_n_retrievals_object_dead));
47469 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47470 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47471 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47472
47473 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47474 - atomic_read(&fscache_n_stores),
47475 - atomic_read(&fscache_n_stores_ok),
47476 - atomic_read(&fscache_n_stores_again),
47477 - atomic_read(&fscache_n_stores_nobufs),
47478 - atomic_read(&fscache_n_stores_oom));
47479 + atomic_read_unchecked(&fscache_n_stores),
47480 + atomic_read_unchecked(&fscache_n_stores_ok),
47481 + atomic_read_unchecked(&fscache_n_stores_again),
47482 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47483 + atomic_read_unchecked(&fscache_n_stores_oom));
47484 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47485 - atomic_read(&fscache_n_store_ops),
47486 - atomic_read(&fscache_n_store_calls),
47487 - atomic_read(&fscache_n_store_pages),
47488 - atomic_read(&fscache_n_store_radix_deletes),
47489 - atomic_read(&fscache_n_store_pages_over_limit));
47490 + atomic_read_unchecked(&fscache_n_store_ops),
47491 + atomic_read_unchecked(&fscache_n_store_calls),
47492 + atomic_read_unchecked(&fscache_n_store_pages),
47493 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47494 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47495
47496 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47497 - atomic_read(&fscache_n_store_vmscan_not_storing),
47498 - atomic_read(&fscache_n_store_vmscan_gone),
47499 - atomic_read(&fscache_n_store_vmscan_busy),
47500 - atomic_read(&fscache_n_store_vmscan_cancelled));
47501 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47502 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47503 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47504 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47505
47506 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47507 - atomic_read(&fscache_n_op_pend),
47508 - atomic_read(&fscache_n_op_run),
47509 - atomic_read(&fscache_n_op_enqueue),
47510 - atomic_read(&fscache_n_op_cancelled),
47511 - atomic_read(&fscache_n_op_rejected));
47512 + atomic_read_unchecked(&fscache_n_op_pend),
47513 + atomic_read_unchecked(&fscache_n_op_run),
47514 + atomic_read_unchecked(&fscache_n_op_enqueue),
47515 + atomic_read_unchecked(&fscache_n_op_cancelled),
47516 + atomic_read_unchecked(&fscache_n_op_rejected));
47517 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47518 - atomic_read(&fscache_n_op_deferred_release),
47519 - atomic_read(&fscache_n_op_release),
47520 - atomic_read(&fscache_n_op_gc));
47521 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47522 + atomic_read_unchecked(&fscache_n_op_release),
47523 + atomic_read_unchecked(&fscache_n_op_gc));
47524
47525 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47526 atomic_read(&fscache_n_cop_alloc_object),
47527 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47528 index ee8d550..7189d8c 100644
47529 --- a/fs/fuse/cuse.c
47530 +++ b/fs/fuse/cuse.c
47531 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47532 INIT_LIST_HEAD(&cuse_conntbl[i]);
47533
47534 /* inherit and extend fuse_dev_operations */
47535 - cuse_channel_fops = fuse_dev_operations;
47536 - cuse_channel_fops.owner = THIS_MODULE;
47537 - cuse_channel_fops.open = cuse_channel_open;
47538 - cuse_channel_fops.release = cuse_channel_release;
47539 + pax_open_kernel();
47540 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47541 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47542 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47543 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47544 + pax_close_kernel();
47545
47546 cuse_class = class_create(THIS_MODULE, "cuse");
47547 if (IS_ERR(cuse_class))
47548 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47549 index 8c23fa7..0e3aac7 100644
47550 --- a/fs/fuse/dev.c
47551 +++ b/fs/fuse/dev.c
47552 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47553 ret = 0;
47554 pipe_lock(pipe);
47555
47556 - if (!pipe->readers) {
47557 + if (!atomic_read(&pipe->readers)) {
47558 send_sig(SIGPIPE, current, 0);
47559 if (!ret)
47560 ret = -EPIPE;
47561 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47562 index 324bc08..4fdd56e 100644
47563 --- a/fs/fuse/dir.c
47564 +++ b/fs/fuse/dir.c
47565 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47566 return link;
47567 }
47568
47569 -static void free_link(char *link)
47570 +static void free_link(const char *link)
47571 {
47572 if (!IS_ERR(link))
47573 free_page((unsigned long) link);
47574 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47575 index 381893c..3793318 100644
47576 --- a/fs/gfs2/inode.c
47577 +++ b/fs/gfs2/inode.c
47578 @@ -1490,7 +1490,7 @@ out:
47579
47580 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47581 {
47582 - char *s = nd_get_link(nd);
47583 + const char *s = nd_get_link(nd);
47584 if (!IS_ERR(s))
47585 kfree(s);
47586 }
47587 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47588 index c5bc355..5a513bb 100644
47589 --- a/fs/hugetlbfs/inode.c
47590 +++ b/fs/hugetlbfs/inode.c
47591 @@ -923,7 +923,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47592 .kill_sb = kill_litter_super,
47593 };
47594
47595 -static struct vfsmount *hugetlbfs_vfsmount;
47596 +struct vfsmount *hugetlbfs_vfsmount;
47597
47598 static int can_do_hugetlb_shm(void)
47599 {
47600 diff --git a/fs/inode.c b/fs/inode.c
47601 index 64999f1..8fad608 100644
47602 --- a/fs/inode.c
47603 +++ b/fs/inode.c
47604 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
47605
47606 #ifdef CONFIG_SMP
47607 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47608 - static atomic_t shared_last_ino;
47609 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47610 + static atomic_unchecked_t shared_last_ino;
47611 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47612
47613 res = next - LAST_INO_BATCH;
47614 }
47615 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47616 index 4a6cf28..d3a29d3 100644
47617 --- a/fs/jffs2/erase.c
47618 +++ b/fs/jffs2/erase.c
47619 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47620 struct jffs2_unknown_node marker = {
47621 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47622 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47623 - .totlen = cpu_to_je32(c->cleanmarker_size)
47624 + .totlen = cpu_to_je32(c->cleanmarker_size),
47625 + .hdr_crc = cpu_to_je32(0)
47626 };
47627
47628 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47629 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47630 index a6597d6..41b30ec 100644
47631 --- a/fs/jffs2/wbuf.c
47632 +++ b/fs/jffs2/wbuf.c
47633 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47634 {
47635 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47636 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47637 - .totlen = constant_cpu_to_je32(8)
47638 + .totlen = constant_cpu_to_je32(8),
47639 + .hdr_crc = constant_cpu_to_je32(0)
47640 };
47641
47642 /*
47643 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47644 index 1a543be..d803c40 100644
47645 --- a/fs/jfs/super.c
47646 +++ b/fs/jfs/super.c
47647 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
47648
47649 jfs_inode_cachep =
47650 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47651 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47652 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47653 init_once);
47654 if (jfs_inode_cachep == NULL)
47655 return -ENOMEM;
47656 diff --git a/fs/libfs.c b/fs/libfs.c
47657 index 7cc37ca..b3e3eec 100644
47658 --- a/fs/libfs.c
47659 +++ b/fs/libfs.c
47660 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47661
47662 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47663 struct dentry *next;
47664 + char d_name[sizeof(next->d_iname)];
47665 + const unsigned char *name;
47666 +
47667 next = list_entry(p, struct dentry, d_u.d_child);
47668 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47669 if (!simple_positive(next)) {
47670 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47671
47672 spin_unlock(&next->d_lock);
47673 spin_unlock(&dentry->d_lock);
47674 - if (filldir(dirent, next->d_name.name,
47675 + name = next->d_name.name;
47676 + if (name == next->d_iname) {
47677 + memcpy(d_name, name, next->d_name.len);
47678 + name = d_name;
47679 + }
47680 + if (filldir(dirent, name,
47681 next->d_name.len, filp->f_pos,
47682 next->d_inode->i_ino,
47683 dt_type(next->d_inode)) < 0)
47684 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47685 index 05d2912..760abfa 100644
47686 --- a/fs/lockd/clntproc.c
47687 +++ b/fs/lockd/clntproc.c
47688 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47689 /*
47690 * Cookie counter for NLM requests
47691 */
47692 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47693 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47694
47695 void nlmclnt_next_cookie(struct nlm_cookie *c)
47696 {
47697 - u32 cookie = atomic_inc_return(&nlm_cookie);
47698 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47699
47700 memcpy(c->data, &cookie, 4);
47701 c->len=4;
47702 diff --git a/fs/locks.c b/fs/locks.c
47703 index a94e331..060bce3 100644
47704 --- a/fs/locks.c
47705 +++ b/fs/locks.c
47706 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
47707 return;
47708
47709 if (filp->f_op && filp->f_op->flock) {
47710 - struct file_lock fl = {
47711 + struct file_lock flock = {
47712 .fl_pid = current->tgid,
47713 .fl_file = filp,
47714 .fl_flags = FL_FLOCK,
47715 .fl_type = F_UNLCK,
47716 .fl_end = OFFSET_MAX,
47717 };
47718 - filp->f_op->flock(filp, F_SETLKW, &fl);
47719 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47720 - fl.fl_ops->fl_release_private(&fl);
47721 + filp->f_op->flock(filp, F_SETLKW, &flock);
47722 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47723 + flock.fl_ops->fl_release_private(&flock);
47724 }
47725
47726 lock_flocks();
47727 diff --git a/fs/namei.c b/fs/namei.c
47728 index 5f4cdf3..959a013 100644
47729 --- a/fs/namei.c
47730 +++ b/fs/namei.c
47731 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
47732 if (ret != -EACCES)
47733 return ret;
47734
47735 +#ifdef CONFIG_GRKERNSEC
47736 + /* we'll block if we have to log due to a denied capability use */
47737 + if (mask & MAY_NOT_BLOCK)
47738 + return -ECHILD;
47739 +#endif
47740 +
47741 if (S_ISDIR(inode->i_mode)) {
47742 /* DACs are overridable for directories */
47743 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47744 - return 0;
47745 if (!(mask & MAY_WRITE))
47746 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47747 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47748 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47749 return 0;
47750 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47751 + return 0;
47752 return -EACCES;
47753 }
47754 /*
47755 + * Searching includes executable on directories, else just read.
47756 + */
47757 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47758 + if (mask == MAY_READ)
47759 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47760 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47761 + return 0;
47762 +
47763 + /*
47764 * Read/write DACs are always overridable.
47765 * Executable DACs are overridable when there is
47766 * at least one exec bit set.
47767 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
47768 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47769 return 0;
47770
47771 - /*
47772 - * Searching includes executable on directories, else just read.
47773 - */
47774 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47775 - if (mask == MAY_READ)
47776 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47777 - return 0;
47778 -
47779 return -EACCES;
47780 }
47781
47782 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47783 {
47784 struct dentry *dentry = link->dentry;
47785 int error;
47786 - char *s;
47787 + const char *s;
47788
47789 BUG_ON(nd->flags & LOOKUP_RCU);
47790
47791 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47792 if (error)
47793 goto out_put_nd_path;
47794
47795 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47796 + dentry->d_inode, dentry, nd->path.mnt)) {
47797 + error = -EACCES;
47798 + goto out_put_nd_path;
47799 + }
47800 +
47801 nd->last_type = LAST_BIND;
47802 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47803 error = PTR_ERR(*p);
47804 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47805 break;
47806 res = walk_component(nd, path, &nd->last,
47807 nd->last_type, LOOKUP_FOLLOW);
47808 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47809 + res = -EACCES;
47810 put_link(nd, &link, cookie);
47811 } while (res > 0);
47812
47813 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
47814 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
47815 {
47816 unsigned long a, b, adata, bdata, mask, hash, len;
47817 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47818 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47819
47820 hash = a = 0;
47821 len = -sizeof(unsigned long);
47822 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
47823 if (err)
47824 break;
47825 err = lookup_last(nd, &path);
47826 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47827 + err = -EACCES;
47828 put_link(nd, &link, cookie);
47829 }
47830 }
47831 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
47832 if (!err)
47833 err = complete_walk(nd);
47834
47835 + if (!(nd->flags & LOOKUP_PARENT)) {
47836 +#ifdef CONFIG_GRKERNSEC
47837 + if (flags & LOOKUP_RCU) {
47838 + if (!err)
47839 + path_put(&nd->path);
47840 + err = -ECHILD;
47841 + } else
47842 +#endif
47843 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47844 + if (!err)
47845 + path_put(&nd->path);
47846 + err = -ENOENT;
47847 + }
47848 + }
47849 +
47850 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47851 if (!nd->inode->i_op->lookup) {
47852 path_put(&nd->path);
47853 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
47854 retval = path_lookupat(dfd, name->name,
47855 flags | LOOKUP_REVAL, nd);
47856
47857 - if (likely(!retval))
47858 + if (likely(!retval)) {
47859 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
47860 +#ifdef CONFIG_GRKERNSEC
47861 + if (flags & LOOKUP_RCU)
47862 + return -ECHILD;
47863 +#endif
47864 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47865 + return -ENOENT;
47866 + }
47867 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
47868 + }
47869 return retval;
47870 }
47871
47872 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47873 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47874 return -EPERM;
47875
47876 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47877 + return -EPERM;
47878 + if (gr_handle_rawio(inode))
47879 + return -EPERM;
47880 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47881 + return -EACCES;
47882 +
47883 return 0;
47884 }
47885
47886 @@ -2623,7 +2672,7 @@ looked_up:
47887 * cleared otherwise prior to returning.
47888 */
47889 static int lookup_open(struct nameidata *nd, struct path *path,
47890 - struct file *file,
47891 + struct path *link, struct file *file,
47892 const struct open_flags *op,
47893 bool got_write, int *opened)
47894 {
47895 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47896 /* Negative dentry, just create the file */
47897 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47898 umode_t mode = op->mode;
47899 +
47900 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47901 + error = -EACCES;
47902 + goto out_dput;
47903 + }
47904 +
47905 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47906 + error = -EACCES;
47907 + goto out_dput;
47908 + }
47909 +
47910 if (!IS_POSIXACL(dir->d_inode))
47911 mode &= ~current_umask();
47912 /*
47913 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47914 nd->flags & LOOKUP_EXCL);
47915 if (error)
47916 goto out_dput;
47917 + else
47918 + gr_handle_create(dentry, nd->path.mnt);
47919 }
47920 out_no_open:
47921 path->dentry = dentry;
47922 @@ -2693,7 +2755,7 @@ out_dput:
47923 /*
47924 * Handle the last step of open()
47925 */
47926 -static int do_last(struct nameidata *nd, struct path *path,
47927 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47928 struct file *file, const struct open_flags *op,
47929 int *opened, struct filename *name)
47930 {
47931 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47932 error = complete_walk(nd);
47933 if (error)
47934 return error;
47935 +#ifdef CONFIG_GRKERNSEC
47936 + if (nd->flags & LOOKUP_RCU) {
47937 + error = -ECHILD;
47938 + goto out;
47939 + }
47940 +#endif
47941 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47942 + error = -ENOENT;
47943 + goto out;
47944 + }
47945 audit_inode(name, nd->path.dentry, 0);
47946 if (open_flag & O_CREAT) {
47947 error = -EISDIR;
47948 goto out;
47949 }
47950 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47951 + error = -EACCES;
47952 + goto out;
47953 + }
47954 goto finish_open;
47955 case LAST_BIND:
47956 error = complete_walk(nd);
47957 if (error)
47958 return error;
47959 +#ifdef CONFIG_GRKERNSEC
47960 + if (nd->flags & LOOKUP_RCU) {
47961 + error = -ECHILD;
47962 + goto out;
47963 + }
47964 +#endif
47965 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47966 + error = -ENOENT;
47967 + goto out;
47968 + }
47969 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47970 + error = -EACCES;
47971 + goto out;
47972 + }
47973 audit_inode(name, dir, 0);
47974 goto finish_open;
47975 }
47976 @@ -2780,7 +2870,7 @@ retry_lookup:
47977 */
47978 }
47979 mutex_lock(&dir->d_inode->i_mutex);
47980 - error = lookup_open(nd, path, file, op, got_write, opened);
47981 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47982 mutex_unlock(&dir->d_inode->i_mutex);
47983
47984 if (error <= 0) {
47985 @@ -2804,11 +2894,28 @@ retry_lookup:
47986 goto finish_open_created;
47987 }
47988
47989 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47990 + error = -ENOENT;
47991 + goto exit_dput;
47992 + }
47993 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47994 + error = -EACCES;
47995 + goto exit_dput;
47996 + }
47997 +
47998 /*
47999 * create/update audit record if it already exists.
48000 */
48001 - if (path->dentry->d_inode)
48002 + if (path->dentry->d_inode) {
48003 + /* only check if O_CREAT is specified, all other checks need to go
48004 + into may_open */
48005 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48006 + error = -EACCES;
48007 + goto exit_dput;
48008 + }
48009 +
48010 audit_inode(name, path->dentry, 0);
48011 + }
48012
48013 /*
48014 * If atomic_open() acquired write access it is dropped now due to
48015 @@ -2849,6 +2956,11 @@ finish_lookup:
48016 }
48017 }
48018 BUG_ON(inode != path->dentry->d_inode);
48019 + /* if we're resolving a symlink to another symlink */
48020 + if (link && gr_handle_symlink_owner(link, inode)) {
48021 + error = -EACCES;
48022 + goto out;
48023 + }
48024 return 1;
48025 }
48026
48027 @@ -2858,7 +2970,6 @@ finish_lookup:
48028 save_parent.dentry = nd->path.dentry;
48029 save_parent.mnt = mntget(path->mnt);
48030 nd->path.dentry = path->dentry;
48031 -
48032 }
48033 nd->inode = inode;
48034 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48035 @@ -2867,6 +2978,22 @@ finish_lookup:
48036 path_put(&save_parent);
48037 return error;
48038 }
48039 +
48040 +#ifdef CONFIG_GRKERNSEC
48041 + if (nd->flags & LOOKUP_RCU) {
48042 + error = -ECHILD;
48043 + goto out;
48044 + }
48045 +#endif
48046 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48047 + error = -ENOENT;
48048 + goto out;
48049 + }
48050 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48051 + error = -EACCES;
48052 + goto out;
48053 + }
48054 +
48055 error = -EISDIR;
48056 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48057 goto out;
48058 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
48059 if (unlikely(error))
48060 goto out;
48061
48062 - error = do_last(nd, &path, file, op, &opened, pathname);
48063 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48064 while (unlikely(error > 0)) { /* trailing symlink */
48065 struct path link = path;
48066 void *cookie;
48067 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
48068 error = follow_link(&link, nd, &cookie);
48069 if (unlikely(error))
48070 break;
48071 - error = do_last(nd, &path, file, op, &opened, pathname);
48072 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
48073 put_link(nd, &link, cookie);
48074 }
48075 out:
48076 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48077 goto unlock;
48078
48079 error = -EEXIST;
48080 - if (dentry->d_inode)
48081 + if (dentry->d_inode) {
48082 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48083 + error = -ENOENT;
48084 + }
48085 goto fail;
48086 + }
48087 /*
48088 * Special case - lookup gave negative, but... we had foo/bar/
48089 * From the vfs_mknod() POV we just have a negative dentry -
48090 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48091 }
48092 EXPORT_SYMBOL(user_path_create);
48093
48094 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
48095 +{
48096 + struct filename *tmp = getname(pathname);
48097 + struct dentry *res;
48098 + if (IS_ERR(tmp))
48099 + return ERR_CAST(tmp);
48100 + res = kern_path_create(dfd, tmp->name, path, is_dir);
48101 + if (IS_ERR(res))
48102 + putname(tmp);
48103 + else
48104 + *to = tmp;
48105 + return res;
48106 +}
48107 +
48108 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48109 {
48110 int error = may_create(dir, dentry);
48111 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48112
48113 if (!IS_POSIXACL(path.dentry->d_inode))
48114 mode &= ~current_umask();
48115 +
48116 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48117 + error = -EPERM;
48118 + goto out;
48119 + }
48120 +
48121 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48122 + error = -EACCES;
48123 + goto out;
48124 + }
48125 +
48126 error = security_path_mknod(&path, dentry, mode, dev);
48127 if (error)
48128 goto out;
48129 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48130 break;
48131 }
48132 out:
48133 + if (!error)
48134 + gr_handle_create(dentry, path.mnt);
48135 done_path_create(&path, dentry);
48136 return error;
48137 }
48138 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48139
48140 if (!IS_POSIXACL(path.dentry->d_inode))
48141 mode &= ~current_umask();
48142 +
48143 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48144 + error = -EACCES;
48145 + goto out;
48146 + }
48147 +
48148 error = security_path_mkdir(&path, dentry, mode);
48149 if (!error)
48150 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48151 + if (!error)
48152 + gr_handle_create(dentry, path.mnt);
48153 +out:
48154 done_path_create(&path, dentry);
48155 return error;
48156 }
48157 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48158 struct filename *name;
48159 struct dentry *dentry;
48160 struct nameidata nd;
48161 + ino_t saved_ino = 0;
48162 + dev_t saved_dev = 0;
48163
48164 name = user_path_parent(dfd, pathname, &nd);
48165 if (IS_ERR(name))
48166 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48167 error = -ENOENT;
48168 goto exit3;
48169 }
48170 +
48171 + saved_ino = dentry->d_inode->i_ino;
48172 + saved_dev = gr_get_dev_from_dentry(dentry);
48173 +
48174 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48175 + error = -EACCES;
48176 + goto exit3;
48177 + }
48178 +
48179 error = security_path_rmdir(&nd.path, dentry);
48180 if (error)
48181 goto exit3;
48182 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48183 + if (!error && (saved_dev || saved_ino))
48184 + gr_handle_delete(saved_ino, saved_dev);
48185 exit3:
48186 dput(dentry);
48187 exit2:
48188 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48189 struct dentry *dentry;
48190 struct nameidata nd;
48191 struct inode *inode = NULL;
48192 + ino_t saved_ino = 0;
48193 + dev_t saved_dev = 0;
48194
48195 name = user_path_parent(dfd, pathname, &nd);
48196 if (IS_ERR(name))
48197 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48198 if (!inode)
48199 goto slashes;
48200 ihold(inode);
48201 +
48202 + if (inode->i_nlink <= 1) {
48203 + saved_ino = inode->i_ino;
48204 + saved_dev = gr_get_dev_from_dentry(dentry);
48205 + }
48206 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48207 + error = -EACCES;
48208 + goto exit2;
48209 + }
48210 +
48211 error = security_path_unlink(&nd.path, dentry);
48212 if (error)
48213 goto exit2;
48214 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48215 + if (!error && (saved_ino || saved_dev))
48216 + gr_handle_delete(saved_ino, saved_dev);
48217 exit2:
48218 dput(dentry);
48219 }
48220 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48221 if (IS_ERR(dentry))
48222 goto out_putname;
48223
48224 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48225 + error = -EACCES;
48226 + goto out;
48227 + }
48228 +
48229 error = security_path_symlink(&path, dentry, from->name);
48230 if (!error)
48231 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
48232 + if (!error)
48233 + gr_handle_create(dentry, path.mnt);
48234 +out:
48235 done_path_create(&path, dentry);
48236 out_putname:
48237 putname(from);
48238 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48239 {
48240 struct dentry *new_dentry;
48241 struct path old_path, new_path;
48242 + struct filename *to = NULL;
48243 int how = 0;
48244 int error;
48245
48246 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48247 if (error)
48248 return error;
48249
48250 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48251 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48252 error = PTR_ERR(new_dentry);
48253 if (IS_ERR(new_dentry))
48254 goto out;
48255 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48256 error = may_linkat(&old_path);
48257 if (unlikely(error))
48258 goto out_dput;
48259 +
48260 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48261 + old_path.dentry->d_inode,
48262 + old_path.dentry->d_inode->i_mode, to)) {
48263 + error = -EACCES;
48264 + goto out_dput;
48265 + }
48266 +
48267 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48268 + old_path.dentry, old_path.mnt, to)) {
48269 + error = -EACCES;
48270 + goto out_dput;
48271 + }
48272 +
48273 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48274 if (error)
48275 goto out_dput;
48276 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48277 + if (!error)
48278 + gr_handle_create(new_dentry, new_path.mnt);
48279 out_dput:
48280 + putname(to);
48281 done_path_create(&new_path, new_dentry);
48282 out:
48283 path_put(&old_path);
48284 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48285 if (new_dentry == trap)
48286 goto exit5;
48287
48288 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48289 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48290 + to);
48291 + if (error)
48292 + goto exit5;
48293 +
48294 error = security_path_rename(&oldnd.path, old_dentry,
48295 &newnd.path, new_dentry);
48296 if (error)
48297 goto exit5;
48298 error = vfs_rename(old_dir->d_inode, old_dentry,
48299 new_dir->d_inode, new_dentry);
48300 + if (!error)
48301 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48302 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48303 exit5:
48304 dput(new_dentry);
48305 exit4:
48306 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48307
48308 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48309 {
48310 + char tmpbuf[64];
48311 + const char *newlink;
48312 int len;
48313
48314 len = PTR_ERR(link);
48315 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48316 len = strlen(link);
48317 if (len > (unsigned) buflen)
48318 len = buflen;
48319 - if (copy_to_user(buffer, link, len))
48320 +
48321 + if (len < sizeof(tmpbuf)) {
48322 + memcpy(tmpbuf, link, len);
48323 + newlink = tmpbuf;
48324 + } else
48325 + newlink = link;
48326 +
48327 + if (copy_to_user(buffer, newlink, len))
48328 len = -EFAULT;
48329 out:
48330 return len;
48331 diff --git a/fs/namespace.c b/fs/namespace.c
48332 index 2496062..e26f6d6 100644
48333 --- a/fs/namespace.c
48334 +++ b/fs/namespace.c
48335 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48336 if (!(sb->s_flags & MS_RDONLY))
48337 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48338 up_write(&sb->s_umount);
48339 +
48340 + gr_log_remount(mnt->mnt_devname, retval);
48341 +
48342 return retval;
48343 }
48344
48345 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48346 br_write_unlock(&vfsmount_lock);
48347 up_write(&namespace_sem);
48348 release_mounts(&umount_list);
48349 +
48350 + gr_log_unmount(mnt->mnt_devname, retval);
48351 +
48352 return retval;
48353 }
48354
48355 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
48356 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48357 MS_STRICTATIME);
48358
48359 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48360 + retval = -EPERM;
48361 + goto dput_out;
48362 + }
48363 +
48364 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48365 + retval = -EPERM;
48366 + goto dput_out;
48367 + }
48368 +
48369 if (flags & MS_REMOUNT)
48370 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48371 data_page);
48372 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
48373 dev_name, data_page);
48374 dput_out:
48375 path_put(&path);
48376 +
48377 + gr_log_mount(dev_name, dir_name, retval);
48378 +
48379 return retval;
48380 }
48381
48382 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48383 if (error)
48384 goto out2;
48385
48386 + if (gr_handle_chroot_pivot()) {
48387 + error = -EPERM;
48388 + goto out2;
48389 + }
48390 +
48391 get_fs_root(current->fs, &root);
48392 error = lock_mount(&old);
48393 if (error)
48394 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48395 index 6fa01ae..2790820 100644
48396 --- a/fs/nfs/inode.c
48397 +++ b/fs/nfs/inode.c
48398 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48399 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48400 }
48401
48402 -static atomic_long_t nfs_attr_generation_counter;
48403 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48404
48405 static unsigned long nfs_read_attr_generation_counter(void)
48406 {
48407 - return atomic_long_read(&nfs_attr_generation_counter);
48408 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48409 }
48410
48411 unsigned long nfs_inc_attr_generation_counter(void)
48412 {
48413 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48414 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48415 }
48416
48417 void nfs_fattr_init(struct nfs_fattr *fattr)
48418 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48419 index c120b48..8ac4140 100644
48420 --- a/fs/nfsd/vfs.c
48421 +++ b/fs/nfsd/vfs.c
48422 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48423 } else {
48424 oldfs = get_fs();
48425 set_fs(KERNEL_DS);
48426 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48427 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48428 set_fs(oldfs);
48429 }
48430
48431 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48432
48433 /* Write the data. */
48434 oldfs = get_fs(); set_fs(KERNEL_DS);
48435 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48436 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48437 set_fs(oldfs);
48438 if (host_err < 0)
48439 goto out_nfserr;
48440 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48441 */
48442
48443 oldfs = get_fs(); set_fs(KERNEL_DS);
48444 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
48445 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48446 set_fs(oldfs);
48447
48448 if (host_err < 0)
48449 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48450 index 6fcaeb8..9d16d04 100644
48451 --- a/fs/notify/fanotify/fanotify_user.c
48452 +++ b/fs/notify/fanotify/fanotify_user.c
48453 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48454
48455 fd = fanotify_event_metadata.fd;
48456 ret = -EFAULT;
48457 - if (copy_to_user(buf, &fanotify_event_metadata,
48458 - fanotify_event_metadata.event_len))
48459 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48460 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
48461 goto out_close_fd;
48462
48463 ret = prepare_for_access_response(group, event, fd);
48464 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48465 index c887b13..0fdf472 100644
48466 --- a/fs/notify/notification.c
48467 +++ b/fs/notify/notification.c
48468 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48469 * get set to 0 so it will never get 'freed'
48470 */
48471 static struct fsnotify_event *q_overflow_event;
48472 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48473 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48474
48475 /**
48476 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48477 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48478 */
48479 u32 fsnotify_get_cookie(void)
48480 {
48481 - return atomic_inc_return(&fsnotify_sync_cookie);
48482 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48483 }
48484 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48485
48486 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48487 index 99e3610..02c1068 100644
48488 --- a/fs/ntfs/dir.c
48489 +++ b/fs/ntfs/dir.c
48490 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48491 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48492 ~(s64)(ndir->itype.index.block_size - 1)));
48493 /* Bounds checks. */
48494 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48495 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48496 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48497 "inode 0x%lx or driver bug.", vdir->i_ino);
48498 goto err_out;
48499 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48500 index 1ecf464..e1ff8bf 100644
48501 --- a/fs/ntfs/file.c
48502 +++ b/fs/ntfs/file.c
48503 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48504 #endif /* NTFS_RW */
48505 };
48506
48507 -const struct file_operations ntfs_empty_file_ops = {};
48508 +const struct file_operations ntfs_empty_file_ops __read_only;
48509
48510 -const struct inode_operations ntfs_empty_inode_ops = {};
48511 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48512 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48513 index a9f78c7..ed8a381 100644
48514 --- a/fs/ocfs2/localalloc.c
48515 +++ b/fs/ocfs2/localalloc.c
48516 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48517 goto bail;
48518 }
48519
48520 - atomic_inc(&osb->alloc_stats.moves);
48521 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48522
48523 bail:
48524 if (handle)
48525 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48526 index d355e6e..578d905 100644
48527 --- a/fs/ocfs2/ocfs2.h
48528 +++ b/fs/ocfs2/ocfs2.h
48529 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48530
48531 struct ocfs2_alloc_stats
48532 {
48533 - atomic_t moves;
48534 - atomic_t local_data;
48535 - atomic_t bitmap_data;
48536 - atomic_t bg_allocs;
48537 - atomic_t bg_extends;
48538 + atomic_unchecked_t moves;
48539 + atomic_unchecked_t local_data;
48540 + atomic_unchecked_t bitmap_data;
48541 + atomic_unchecked_t bg_allocs;
48542 + atomic_unchecked_t bg_extends;
48543 };
48544
48545 enum ocfs2_local_alloc_state
48546 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48547 index f169da4..9112253 100644
48548 --- a/fs/ocfs2/suballoc.c
48549 +++ b/fs/ocfs2/suballoc.c
48550 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48551 mlog_errno(status);
48552 goto bail;
48553 }
48554 - atomic_inc(&osb->alloc_stats.bg_extends);
48555 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48556
48557 /* You should never ask for this much metadata */
48558 BUG_ON(bits_wanted >
48559 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48560 mlog_errno(status);
48561 goto bail;
48562 }
48563 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48564 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48565
48566 *suballoc_loc = res.sr_bg_blkno;
48567 *suballoc_bit_start = res.sr_bit_offset;
48568 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48569 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48570 res->sr_bits);
48571
48572 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48573 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48574
48575 BUG_ON(res->sr_bits != 1);
48576
48577 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48578 mlog_errno(status);
48579 goto bail;
48580 }
48581 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48582 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48583
48584 BUG_ON(res.sr_bits != 1);
48585
48586 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48587 cluster_start,
48588 num_clusters);
48589 if (!status)
48590 - atomic_inc(&osb->alloc_stats.local_data);
48591 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48592 } else {
48593 if (min_clusters > (osb->bitmap_cpg - 1)) {
48594 /* The only paths asking for contiguousness
48595 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48596 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48597 res.sr_bg_blkno,
48598 res.sr_bit_offset);
48599 - atomic_inc(&osb->alloc_stats.bitmap_data);
48600 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48601 *num_clusters = res.sr_bits;
48602 }
48603 }
48604 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48605 index 0e91ec2..f4b3fc6 100644
48606 --- a/fs/ocfs2/super.c
48607 +++ b/fs/ocfs2/super.c
48608 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48609 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48610 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48611 "Stats",
48612 - atomic_read(&osb->alloc_stats.bitmap_data),
48613 - atomic_read(&osb->alloc_stats.local_data),
48614 - atomic_read(&osb->alloc_stats.bg_allocs),
48615 - atomic_read(&osb->alloc_stats.moves),
48616 - atomic_read(&osb->alloc_stats.bg_extends));
48617 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48618 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48619 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48620 + atomic_read_unchecked(&osb->alloc_stats.moves),
48621 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48622
48623 out += snprintf(buf + out, len - out,
48624 "%10s => State: %u Descriptor: %llu Size: %u bits "
48625 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48626 spin_lock_init(&osb->osb_xattr_lock);
48627 ocfs2_init_steal_slots(osb);
48628
48629 - atomic_set(&osb->alloc_stats.moves, 0);
48630 - atomic_set(&osb->alloc_stats.local_data, 0);
48631 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48632 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48633 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48634 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48635 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48636 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48637 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48638 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48639
48640 /* Copy the blockcheck stats from the superblock probe */
48641 osb->osb_ecc_stats = *stats;
48642 diff --git a/fs/open.c b/fs/open.c
48643 index 59071f5..c6229a0 100644
48644 --- a/fs/open.c
48645 +++ b/fs/open.c
48646 @@ -31,6 +31,8 @@
48647 #include <linux/ima.h>
48648 #include <linux/dnotify.h>
48649
48650 +#define CREATE_TRACE_POINTS
48651 +#include <trace/events/fs.h>
48652 #include "internal.h"
48653
48654 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48655 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48656 error = locks_verify_truncate(inode, NULL, length);
48657 if (!error)
48658 error = security_path_truncate(&path);
48659 +
48660 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48661 + error = -EACCES;
48662 +
48663 if (!error)
48664 error = do_truncate(path.dentry, length, 0, NULL);
48665
48666 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48667 if (__mnt_is_readonly(path.mnt))
48668 res = -EROFS;
48669
48670 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48671 + res = -EACCES;
48672 +
48673 out_path_release:
48674 path_put(&path);
48675 out:
48676 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48677 if (error)
48678 goto dput_and_out;
48679
48680 + gr_log_chdir(path.dentry, path.mnt);
48681 +
48682 set_fs_pwd(current->fs, &path);
48683
48684 dput_and_out:
48685 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48686 goto out_putf;
48687
48688 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48689 +
48690 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
48691 + error = -EPERM;
48692 +
48693 + if (!error)
48694 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
48695 +
48696 if (!error)
48697 set_fs_pwd(current->fs, &f.file->f_path);
48698 out_putf:
48699 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48700 if (error)
48701 goto dput_and_out;
48702
48703 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48704 + goto dput_and_out;
48705 +
48706 set_fs_root(current->fs, &path);
48707 +
48708 + gr_handle_chroot_chdir(&path);
48709 +
48710 error = 0;
48711 dput_and_out:
48712 path_put(&path);
48713 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
48714 if (error)
48715 return error;
48716 mutex_lock(&inode->i_mutex);
48717 +
48718 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48719 + error = -EACCES;
48720 + goto out_unlock;
48721 + }
48722 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48723 + error = -EACCES;
48724 + goto out_unlock;
48725 + }
48726 +
48727 error = security_path_chmod(path, mode);
48728 if (error)
48729 goto out_unlock;
48730 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48731 uid = make_kuid(current_user_ns(), user);
48732 gid = make_kgid(current_user_ns(), group);
48733
48734 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48735 + return -EACCES;
48736 +
48737 newattrs.ia_valid = ATTR_CTIME;
48738 if (user != (uid_t) -1) {
48739 if (!uid_valid(uid))
48740 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48741 } else {
48742 fsnotify_open(f);
48743 fd_install(fd, f);
48744 + trace_do_sys_open(tmp->name, flags, mode);
48745 }
48746 }
48747 putname(tmp);
48748 diff --git a/fs/pipe.c b/fs/pipe.c
48749 index bd3479d..fb92c4d 100644
48750 --- a/fs/pipe.c
48751 +++ b/fs/pipe.c
48752 @@ -438,9 +438,9 @@ redo:
48753 }
48754 if (bufs) /* More to do? */
48755 continue;
48756 - if (!pipe->writers)
48757 + if (!atomic_read(&pipe->writers))
48758 break;
48759 - if (!pipe->waiting_writers) {
48760 + if (!atomic_read(&pipe->waiting_writers)) {
48761 /* syscall merging: Usually we must not sleep
48762 * if O_NONBLOCK is set, or if we got some data.
48763 * But if a writer sleeps in kernel space, then
48764 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48765 mutex_lock(&inode->i_mutex);
48766 pipe = inode->i_pipe;
48767
48768 - if (!pipe->readers) {
48769 + if (!atomic_read(&pipe->readers)) {
48770 send_sig(SIGPIPE, current, 0);
48771 ret = -EPIPE;
48772 goto out;
48773 @@ -553,7 +553,7 @@ redo1:
48774 for (;;) {
48775 int bufs;
48776
48777 - if (!pipe->readers) {
48778 + if (!atomic_read(&pipe->readers)) {
48779 send_sig(SIGPIPE, current, 0);
48780 if (!ret)
48781 ret = -EPIPE;
48782 @@ -644,9 +644,9 @@ redo2:
48783 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48784 do_wakeup = 0;
48785 }
48786 - pipe->waiting_writers++;
48787 + atomic_inc(&pipe->waiting_writers);
48788 pipe_wait(pipe);
48789 - pipe->waiting_writers--;
48790 + atomic_dec(&pipe->waiting_writers);
48791 }
48792 out:
48793 mutex_unlock(&inode->i_mutex);
48794 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48795 mask = 0;
48796 if (filp->f_mode & FMODE_READ) {
48797 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48798 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48799 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48800 mask |= POLLHUP;
48801 }
48802
48803 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48804 * Most Unices do not set POLLERR for FIFOs but on Linux they
48805 * behave exactly like pipes for poll().
48806 */
48807 - if (!pipe->readers)
48808 + if (!atomic_read(&pipe->readers))
48809 mask |= POLLERR;
48810 }
48811
48812 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48813
48814 mutex_lock(&inode->i_mutex);
48815 pipe = inode->i_pipe;
48816 - pipe->readers -= decr;
48817 - pipe->writers -= decw;
48818 + atomic_sub(decr, &pipe->readers);
48819 + atomic_sub(decw, &pipe->writers);
48820
48821 - if (!pipe->readers && !pipe->writers) {
48822 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48823 free_pipe_info(inode);
48824 } else {
48825 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48826 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48827
48828 if (inode->i_pipe) {
48829 ret = 0;
48830 - inode->i_pipe->readers++;
48831 + atomic_inc(&inode->i_pipe->readers);
48832 }
48833
48834 mutex_unlock(&inode->i_mutex);
48835 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48836
48837 if (inode->i_pipe) {
48838 ret = 0;
48839 - inode->i_pipe->writers++;
48840 + atomic_inc(&inode->i_pipe->writers);
48841 }
48842
48843 mutex_unlock(&inode->i_mutex);
48844 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48845 if (inode->i_pipe) {
48846 ret = 0;
48847 if (filp->f_mode & FMODE_READ)
48848 - inode->i_pipe->readers++;
48849 + atomic_inc(&inode->i_pipe->readers);
48850 if (filp->f_mode & FMODE_WRITE)
48851 - inode->i_pipe->writers++;
48852 + atomic_inc(&inode->i_pipe->writers);
48853 }
48854
48855 mutex_unlock(&inode->i_mutex);
48856 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48857 inode->i_pipe = NULL;
48858 }
48859
48860 -static struct vfsmount *pipe_mnt __read_mostly;
48861 +struct vfsmount *pipe_mnt __read_mostly;
48862
48863 /*
48864 * pipefs_dname() is called from d_path().
48865 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48866 goto fail_iput;
48867 inode->i_pipe = pipe;
48868
48869 - pipe->readers = pipe->writers = 1;
48870 + atomic_set(&pipe->readers, 1);
48871 + atomic_set(&pipe->writers, 1);
48872 inode->i_fop = &rdwr_pipefifo_fops;
48873
48874 /*
48875 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48876 index 15af622..0e9f4467 100644
48877 --- a/fs/proc/Kconfig
48878 +++ b/fs/proc/Kconfig
48879 @@ -30,12 +30,12 @@ config PROC_FS
48880
48881 config PROC_KCORE
48882 bool "/proc/kcore support" if !ARM
48883 - depends on PROC_FS && MMU
48884 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48885
48886 config PROC_VMCORE
48887 bool "/proc/vmcore support"
48888 - depends on PROC_FS && CRASH_DUMP
48889 - default y
48890 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48891 + default n
48892 help
48893 Exports the dump image of crashed kernel in ELF format.
48894
48895 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48896 limited in memory.
48897
48898 config PROC_PAGE_MONITOR
48899 - default y
48900 - depends on PROC_FS && MMU
48901 + default n
48902 + depends on PROC_FS && MMU && !GRKERNSEC
48903 bool "Enable /proc page monitoring" if EXPERT
48904 help
48905 Various /proc files exist to monitor process memory utilization:
48906 diff --git a/fs/proc/array.c b/fs/proc/array.c
48907 index c1c207c..01ce725 100644
48908 --- a/fs/proc/array.c
48909 +++ b/fs/proc/array.c
48910 @@ -60,6 +60,7 @@
48911 #include <linux/tty.h>
48912 #include <linux/string.h>
48913 #include <linux/mman.h>
48914 +#include <linux/grsecurity.h>
48915 #include <linux/proc_fs.h>
48916 #include <linux/ioport.h>
48917 #include <linux/uaccess.h>
48918 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48919 seq_putc(m, '\n');
48920 }
48921
48922 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48923 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48924 +{
48925 + if (p->mm)
48926 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48927 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48928 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48929 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48930 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48931 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48932 + else
48933 + seq_printf(m, "PaX:\t-----\n");
48934 +}
48935 +#endif
48936 +
48937 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48938 struct pid *pid, struct task_struct *task)
48939 {
48940 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48941 task_cpus_allowed(m, task);
48942 cpuset_task_status_allowed(m, task);
48943 task_context_switch_counts(m, task);
48944 +
48945 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48946 + task_pax(m, task);
48947 +#endif
48948 +
48949 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48950 + task_grsec_rbac(m, task);
48951 +#endif
48952 +
48953 return 0;
48954 }
48955
48956 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48957 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48958 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48959 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48960 +#endif
48961 +
48962 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48963 struct pid *pid, struct task_struct *task, int whole)
48964 {
48965 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48966 char tcomm[sizeof(task->comm)];
48967 unsigned long flags;
48968
48969 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48970 + if (current->exec_id != m->exec_id) {
48971 + gr_log_badprocpid("stat");
48972 + return 0;
48973 + }
48974 +#endif
48975 +
48976 state = *get_task_state(task);
48977 vsize = eip = esp = 0;
48978 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48979 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48980 gtime = task->gtime;
48981 }
48982
48983 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48984 + if (PAX_RAND_FLAGS(mm)) {
48985 + eip = 0;
48986 + esp = 0;
48987 + wchan = 0;
48988 + }
48989 +#endif
48990 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48991 + wchan = 0;
48992 + eip =0;
48993 + esp =0;
48994 +#endif
48995 +
48996 /* scale priority and nice values from timeslices to -20..20 */
48997 /* to make it look like a "normal" Unix priority/nice value */
48998 priority = task_prio(task);
48999 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49000 seq_put_decimal_ull(m, ' ', vsize);
49001 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49002 seq_put_decimal_ull(m, ' ', rsslim);
49003 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49004 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49005 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49006 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49007 +#else
49008 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49009 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49010 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49011 +#endif
49012 seq_put_decimal_ull(m, ' ', esp);
49013 seq_put_decimal_ull(m, ' ', eip);
49014 /* The signal information here is obsolete.
49015 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49016 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49017 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49018
49019 - if (mm && permitted) {
49020 + if (mm && permitted
49021 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49022 + && !PAX_RAND_FLAGS(mm)
49023 +#endif
49024 + ) {
49025 seq_put_decimal_ull(m, ' ', mm->start_data);
49026 seq_put_decimal_ull(m, ' ', mm->end_data);
49027 seq_put_decimal_ull(m, ' ', mm->start_brk);
49028 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49029 struct pid *pid, struct task_struct *task)
49030 {
49031 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49032 - struct mm_struct *mm = get_task_mm(task);
49033 + struct mm_struct *mm;
49034
49035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49036 + if (current->exec_id != m->exec_id) {
49037 + gr_log_badprocpid("statm");
49038 + return 0;
49039 + }
49040 +#endif
49041 + mm = get_task_mm(task);
49042 if (mm) {
49043 size = task_statm(mm, &shared, &text, &data, &resident);
49044 mmput(mm);
49045 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49046 return 0;
49047 }
49048
49049 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49050 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49051 +{
49052 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49053 +}
49054 +#endif
49055 +
49056 #ifdef CONFIG_CHECKPOINT_RESTORE
49057 static struct pid *
49058 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49059 diff --git a/fs/proc/base.c b/fs/proc/base.c
49060 index 9e28356..c485b3c 100644
49061 --- a/fs/proc/base.c
49062 +++ b/fs/proc/base.c
49063 @@ -111,6 +111,14 @@ struct pid_entry {
49064 union proc_op op;
49065 };
49066
49067 +struct getdents_callback {
49068 + struct linux_dirent __user * current_dir;
49069 + struct linux_dirent __user * previous;
49070 + struct file * file;
49071 + int count;
49072 + int error;
49073 +};
49074 +
49075 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49076 .name = (NAME), \
49077 .len = sizeof(NAME) - 1, \
49078 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49079 if (!mm->arg_end)
49080 goto out_mm; /* Shh! No looking before we're done */
49081
49082 + if (gr_acl_handle_procpidmem(task))
49083 + goto out_mm;
49084 +
49085 len = mm->arg_end - mm->arg_start;
49086
49087 if (len > PAGE_SIZE)
49088 @@ -235,12 +246,28 @@ out:
49089 return res;
49090 }
49091
49092 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49093 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49094 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49095 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49096 +#endif
49097 +
49098 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49099 {
49100 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49101 int res = PTR_ERR(mm);
49102 if (mm && !IS_ERR(mm)) {
49103 unsigned int nwords = 0;
49104 +
49105 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49106 + /* allow if we're currently ptracing this task */
49107 + if (PAX_RAND_FLAGS(mm) &&
49108 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49109 + mmput(mm);
49110 + return 0;
49111 + }
49112 +#endif
49113 +
49114 do {
49115 nwords += 2;
49116 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49117 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49118 }
49119
49120
49121 -#ifdef CONFIG_KALLSYMS
49122 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49123 /*
49124 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49125 * Returns the resolved symbol. If that fails, simply return the address.
49126 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
49127 mutex_unlock(&task->signal->cred_guard_mutex);
49128 }
49129
49130 -#ifdef CONFIG_STACKTRACE
49131 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49132
49133 #define MAX_STACK_TRACE_DEPTH 64
49134
49135 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49136 return count;
49137 }
49138
49139 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49140 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49141 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49142 {
49143 long nr;
49144 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49145 /************************************************************************/
49146
49147 /* permission checks */
49148 -static int proc_fd_access_allowed(struct inode *inode)
49149 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49150 {
49151 struct task_struct *task;
49152 int allowed = 0;
49153 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49154 */
49155 task = get_proc_task(inode);
49156 if (task) {
49157 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49158 + if (log)
49159 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49160 + else
49161 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49162 put_task_struct(task);
49163 }
49164 return allowed;
49165 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49166 struct task_struct *task,
49167 int hide_pid_min)
49168 {
49169 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49170 + return false;
49171 +
49172 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49173 + rcu_read_lock();
49174 + {
49175 + const struct cred *tmpcred = current_cred();
49176 + const struct cred *cred = __task_cred(task);
49177 +
49178 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49179 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49180 + || in_group_p(grsec_proc_gid)
49181 +#endif
49182 + ) {
49183 + rcu_read_unlock();
49184 + return true;
49185 + }
49186 + }
49187 + rcu_read_unlock();
49188 +
49189 + if (!pid->hide_pid)
49190 + return false;
49191 +#endif
49192 +
49193 if (pid->hide_pid < hide_pid_min)
49194 return true;
49195 if (in_group_p(pid->pid_gid))
49196 return true;
49197 +
49198 return ptrace_may_access(task, PTRACE_MODE_READ);
49199 }
49200
49201 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49202 put_task_struct(task);
49203
49204 if (!has_perms) {
49205 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49206 + {
49207 +#else
49208 if (pid->hide_pid == 2) {
49209 +#endif
49210 /*
49211 * Let's make getdents(), stat(), and open()
49212 * consistent with each other. If a process
49213 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49214 if (!task)
49215 return -ESRCH;
49216
49217 + if (gr_acl_handle_procpidmem(task)) {
49218 + put_task_struct(task);
49219 + return -EPERM;
49220 + }
49221 +
49222 mm = mm_access(task, mode);
49223 put_task_struct(task);
49224
49225 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49226
49227 file->private_data = mm;
49228
49229 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49230 + file->f_version = current->exec_id;
49231 +#endif
49232 +
49233 return 0;
49234 }
49235
49236 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49237 ssize_t copied;
49238 char *page;
49239
49240 +#ifdef CONFIG_GRKERNSEC
49241 + if (write)
49242 + return -EPERM;
49243 +#endif
49244 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49245 + if (file->f_version != current->exec_id) {
49246 + gr_log_badprocpid("mem");
49247 + return 0;
49248 + }
49249 +#endif
49250 +
49251 if (!mm)
49252 return 0;
49253
49254 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49255 if (!mm)
49256 return 0;
49257
49258 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49259 + if (file->f_version != current->exec_id) {
49260 + gr_log_badprocpid("environ");
49261 + return 0;
49262 + }
49263 +#endif
49264 +
49265 page = (char *)__get_free_page(GFP_TEMPORARY);
49266 if (!page)
49267 return -ENOMEM;
49268 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49269 int error = -EACCES;
49270
49271 /* Are we allowed to snoop on the tasks file descriptors? */
49272 - if (!proc_fd_access_allowed(inode))
49273 + if (!proc_fd_access_allowed(inode, 0))
49274 goto out;
49275
49276 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49277 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49278 struct path path;
49279
49280 /* Are we allowed to snoop on the tasks file descriptors? */
49281 - if (!proc_fd_access_allowed(inode))
49282 - goto out;
49283 + /* logging this is needed for learning on chromium to work properly,
49284 + but we don't want to flood the logs from 'ps' which does a readlink
49285 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49286 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49287 + */
49288 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49289 + if (!proc_fd_access_allowed(inode,0))
49290 + goto out;
49291 + } else {
49292 + if (!proc_fd_access_allowed(inode,1))
49293 + goto out;
49294 + }
49295
49296 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49297 if (error)
49298 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49299 rcu_read_lock();
49300 cred = __task_cred(task);
49301 inode->i_uid = cred->euid;
49302 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49303 + inode->i_gid = grsec_proc_gid;
49304 +#else
49305 inode->i_gid = cred->egid;
49306 +#endif
49307 rcu_read_unlock();
49308 }
49309 security_task_to_inode(task, inode);
49310 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49311 return -ENOENT;
49312 }
49313 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49314 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49315 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49316 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49317 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49318 +#endif
49319 task_dumpable(task)) {
49320 cred = __task_cred(task);
49321 stat->uid = cred->euid;
49322 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49323 + stat->gid = grsec_proc_gid;
49324 +#else
49325 stat->gid = cred->egid;
49326 +#endif
49327 }
49328 }
49329 rcu_read_unlock();
49330 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49331
49332 if (task) {
49333 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49334 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49335 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49336 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49337 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49338 +#endif
49339 task_dumpable(task)) {
49340 rcu_read_lock();
49341 cred = __task_cred(task);
49342 inode->i_uid = cred->euid;
49343 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49344 + inode->i_gid = grsec_proc_gid;
49345 +#else
49346 inode->i_gid = cred->egid;
49347 +#endif
49348 rcu_read_unlock();
49349 } else {
49350 inode->i_uid = GLOBAL_ROOT_UID;
49351 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49352 if (!task)
49353 goto out_no_task;
49354
49355 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49356 + goto out;
49357 +
49358 /*
49359 * Yes, it does not scale. And it should not. Don't add
49360 * new entries into /proc/<tgid>/ without very good reasons.
49361 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
49362 if (!task)
49363 goto out_no_task;
49364
49365 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49366 + goto out;
49367 +
49368 ret = 0;
49369 i = filp->f_pos;
49370 switch (i) {
49371 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49372 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49373 void *cookie)
49374 {
49375 - char *s = nd_get_link(nd);
49376 + const char *s = nd_get_link(nd);
49377 if (!IS_ERR(s))
49378 kfree(s);
49379 }
49380 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49381 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49382 #endif
49383 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49384 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49385 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49386 INF("syscall", S_IRUGO, proc_pid_syscall),
49387 #endif
49388 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49389 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49390 #ifdef CONFIG_SECURITY
49391 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49392 #endif
49393 -#ifdef CONFIG_KALLSYMS
49394 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49395 INF("wchan", S_IRUGO, proc_pid_wchan),
49396 #endif
49397 -#ifdef CONFIG_STACKTRACE
49398 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49399 ONE("stack", S_IRUGO, proc_pid_stack),
49400 #endif
49401 #ifdef CONFIG_SCHEDSTATS
49402 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49403 #ifdef CONFIG_HARDWALL
49404 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49405 #endif
49406 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49407 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49408 +#endif
49409 #ifdef CONFIG_USER_NS
49410 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49411 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49412 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49413 if (!inode)
49414 goto out;
49415
49416 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49417 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49418 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49419 + inode->i_gid = grsec_proc_gid;
49420 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49421 +#else
49422 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49423 +#endif
49424 inode->i_op = &proc_tgid_base_inode_operations;
49425 inode->i_fop = &proc_tgid_base_operations;
49426 inode->i_flags|=S_IMMUTABLE;
49427 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49428 if (!task)
49429 goto out;
49430
49431 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49432 + goto out_put_task;
49433 +
49434 result = proc_pid_instantiate(dir, dentry, task, NULL);
49435 +out_put_task:
49436 put_task_struct(task);
49437 out:
49438 return result;
49439 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49440 static int fake_filldir(void *buf, const char *name, int namelen,
49441 loff_t offset, u64 ino, unsigned d_type)
49442 {
49443 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49444 + __buf->error = -EINVAL;
49445 return 0;
49446 }
49447
49448 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
49449 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49450 #endif
49451 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49452 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49453 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49454 INF("syscall", S_IRUGO, proc_pid_syscall),
49455 #endif
49456 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49457 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
49458 #ifdef CONFIG_SECURITY
49459 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49460 #endif
49461 -#ifdef CONFIG_KALLSYMS
49462 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49463 INF("wchan", S_IRUGO, proc_pid_wchan),
49464 #endif
49465 -#ifdef CONFIG_STACKTRACE
49466 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49467 ONE("stack", S_IRUGO, proc_pid_stack),
49468 #endif
49469 #ifdef CONFIG_SCHEDSTATS
49470 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49471 index 82676e3..5f8518a 100644
49472 --- a/fs/proc/cmdline.c
49473 +++ b/fs/proc/cmdline.c
49474 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49475
49476 static int __init proc_cmdline_init(void)
49477 {
49478 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49479 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49480 +#else
49481 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49482 +#endif
49483 return 0;
49484 }
49485 module_init(proc_cmdline_init);
49486 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49487 index b143471..bb105e5 100644
49488 --- a/fs/proc/devices.c
49489 +++ b/fs/proc/devices.c
49490 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49491
49492 static int __init proc_devices_init(void)
49493 {
49494 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49495 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49496 +#else
49497 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49498 +#endif
49499 return 0;
49500 }
49501 module_init(proc_devices_init);
49502 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
49503 index f28a875..c467953 100644
49504 --- a/fs/proc/fd.c
49505 +++ b/fs/proc/fd.c
49506 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
49507 if (!task)
49508 return -ENOENT;
49509
49510 - files = get_files_struct(task);
49511 + if (!gr_acl_handle_procpidmem(task))
49512 + files = get_files_struct(task);
49513 put_task_struct(task);
49514
49515 if (files) {
49516 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
49517 */
49518 int proc_fd_permission(struct inode *inode, int mask)
49519 {
49520 + struct task_struct *task;
49521 int rv = generic_permission(inode, mask);
49522 - if (rv == 0)
49523 - return 0;
49524 +
49525 if (task_pid(current) == proc_pid(inode))
49526 rv = 0;
49527 +
49528 + task = get_proc_task(inode);
49529 + if (task == NULL)
49530 + return rv;
49531 +
49532 + if (gr_acl_handle_procpidmem(task))
49533 + rv = -EACCES;
49534 +
49535 + put_task_struct(task);
49536 +
49537 return rv;
49538 }
49539
49540 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49541 index 3b22bbd..895b58c 100644
49542 --- a/fs/proc/inode.c
49543 +++ b/fs/proc/inode.c
49544 @@ -21,11 +21,17 @@
49545 #include <linux/seq_file.h>
49546 #include <linux/slab.h>
49547 #include <linux/mount.h>
49548 +#include <linux/grsecurity.h>
49549
49550 #include <asm/uaccess.h>
49551
49552 #include "internal.h"
49553
49554 +#ifdef CONFIG_PROC_SYSCTL
49555 +extern const struct inode_operations proc_sys_inode_operations;
49556 +extern const struct inode_operations proc_sys_dir_operations;
49557 +#endif
49558 +
49559 static void proc_evict_inode(struct inode *inode)
49560 {
49561 struct proc_dir_entry *de;
49562 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49563 ns_ops = PROC_I(inode)->ns_ops;
49564 if (ns_ops && ns_ops->put)
49565 ns_ops->put(PROC_I(inode)->ns);
49566 +
49567 +#ifdef CONFIG_PROC_SYSCTL
49568 + if (inode->i_op == &proc_sys_inode_operations ||
49569 + inode->i_op == &proc_sys_dir_operations)
49570 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49571 +#endif
49572 +
49573 }
49574
49575 static struct kmem_cache * proc_inode_cachep;
49576 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49577 if (de->mode) {
49578 inode->i_mode = de->mode;
49579 inode->i_uid = de->uid;
49580 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49581 + inode->i_gid = grsec_proc_gid;
49582 +#else
49583 inode->i_gid = de->gid;
49584 +#endif
49585 }
49586 if (de->size)
49587 inode->i_size = de->size;
49588 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49589 index 43973b0..a20e704 100644
49590 --- a/fs/proc/internal.h
49591 +++ b/fs/proc/internal.h
49592 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49593 struct pid *pid, struct task_struct *task);
49594 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49595 struct pid *pid, struct task_struct *task);
49596 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49597 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49598 +#endif
49599 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49600
49601 extern const struct file_operations proc_tid_children_operations;
49602 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49603 index 86c67ee..cdca321 100644
49604 --- a/fs/proc/kcore.c
49605 +++ b/fs/proc/kcore.c
49606 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49607 * the addresses in the elf_phdr on our list.
49608 */
49609 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49610 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49611 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49612 + if (tsz > buflen)
49613 tsz = buflen;
49614 -
49615 +
49616 while (buflen) {
49617 struct kcore_list *m;
49618
49619 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49620 kfree(elf_buf);
49621 } else {
49622 if (kern_addr_valid(start)) {
49623 - unsigned long n;
49624 + char *elf_buf;
49625 + mm_segment_t oldfs;
49626
49627 - n = copy_to_user(buffer, (char *)start, tsz);
49628 - /*
49629 - * We cannot distinguish between fault on source
49630 - * and fault on destination. When this happens
49631 - * we clear too and hope it will trigger the
49632 - * EFAULT again.
49633 - */
49634 - if (n) {
49635 - if (clear_user(buffer + tsz - n,
49636 - n))
49637 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49638 + if (!elf_buf)
49639 + return -ENOMEM;
49640 + oldfs = get_fs();
49641 + set_fs(KERNEL_DS);
49642 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49643 + set_fs(oldfs);
49644 + if (copy_to_user(buffer, elf_buf, tsz)) {
49645 + kfree(elf_buf);
49646 return -EFAULT;
49647 + }
49648 }
49649 + set_fs(oldfs);
49650 + kfree(elf_buf);
49651 } else {
49652 if (clear_user(buffer, tsz))
49653 return -EFAULT;
49654 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49655
49656 static int open_kcore(struct inode *inode, struct file *filp)
49657 {
49658 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49659 + return -EPERM;
49660 +#endif
49661 if (!capable(CAP_SYS_RAWIO))
49662 return -EPERM;
49663 if (kcore_need_update)
49664 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49665 index 80e4645..53e5fcf 100644
49666 --- a/fs/proc/meminfo.c
49667 +++ b/fs/proc/meminfo.c
49668 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49669 vmi.used >> 10,
49670 vmi.largest_chunk >> 10
49671 #ifdef CONFIG_MEMORY_FAILURE
49672 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49673 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49674 #endif
49675 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49676 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49677 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49678 index b1822dd..df622cb 100644
49679 --- a/fs/proc/nommu.c
49680 +++ b/fs/proc/nommu.c
49681 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49682 if (len < 1)
49683 len = 1;
49684 seq_printf(m, "%*c", len, ' ');
49685 - seq_path(m, &file->f_path, "");
49686 + seq_path(m, &file->f_path, "\n\\");
49687 }
49688
49689 seq_putc(m, '\n');
49690 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49691 index fe72cd0..cb9b67d 100644
49692 --- a/fs/proc/proc_net.c
49693 +++ b/fs/proc/proc_net.c
49694 @@ -23,6 +23,7 @@
49695 #include <linux/nsproxy.h>
49696 #include <net/net_namespace.h>
49697 #include <linux/seq_file.h>
49698 +#include <linux/grsecurity.h>
49699
49700 #include "internal.h"
49701
49702 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49703 struct task_struct *task;
49704 struct nsproxy *ns;
49705 struct net *net = NULL;
49706 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49707 + const struct cred *cred = current_cred();
49708 +#endif
49709 +
49710 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49711 + if (cred->fsuid)
49712 + return net;
49713 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49714 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49715 + return net;
49716 +#endif
49717
49718 rcu_read_lock();
49719 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49720 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49721 index a781bdf..6665284 100644
49722 --- a/fs/proc/proc_sysctl.c
49723 +++ b/fs/proc/proc_sysctl.c
49724 @@ -12,11 +12,15 @@
49725 #include <linux/module.h>
49726 #include "internal.h"
49727
49728 +extern int gr_handle_chroot_sysctl(const int op);
49729 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49730 + const int op);
49731 +
49732 static const struct dentry_operations proc_sys_dentry_operations;
49733 static const struct file_operations proc_sys_file_operations;
49734 -static const struct inode_operations proc_sys_inode_operations;
49735 +const struct inode_operations proc_sys_inode_operations;
49736 static const struct file_operations proc_sys_dir_file_operations;
49737 -static const struct inode_operations proc_sys_dir_operations;
49738 +const struct inode_operations proc_sys_dir_operations;
49739
49740 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49741 {
49742 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49743
49744 err = NULL;
49745 d_set_d_op(dentry, &proc_sys_dentry_operations);
49746 +
49747 + gr_handle_proc_create(dentry, inode);
49748 +
49749 d_add(dentry, inode);
49750
49751 out:
49752 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49753 struct inode *inode = filp->f_path.dentry->d_inode;
49754 struct ctl_table_header *head = grab_header(inode);
49755 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49756 + int op = write ? MAY_WRITE : MAY_READ;
49757 ssize_t error;
49758 size_t res;
49759
49760 if (IS_ERR(head))
49761 return PTR_ERR(head);
49762
49763 +
49764 /*
49765 * At this point we know that the sysctl was not unregistered
49766 * and won't be until we finish.
49767 */
49768 error = -EPERM;
49769 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49770 + if (sysctl_perm(head->root, table, op))
49771 goto out;
49772
49773 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49774 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49775 if (!table->proc_handler)
49776 goto out;
49777
49778 +#ifdef CONFIG_GRKERNSEC
49779 + error = -EPERM;
49780 + if (gr_handle_chroot_sysctl(op))
49781 + goto out;
49782 + dget(filp->f_path.dentry);
49783 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49784 + dput(filp->f_path.dentry);
49785 + goto out;
49786 + }
49787 + dput(filp->f_path.dentry);
49788 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49789 + goto out;
49790 + if (write && !capable(CAP_SYS_ADMIN))
49791 + goto out;
49792 +#endif
49793 +
49794 /* careful: calling conventions are nasty here */
49795 res = count;
49796 error = table->proc_handler(table, write, buf, &res, ppos);
49797 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49798 return -ENOMEM;
49799 } else {
49800 d_set_d_op(child, &proc_sys_dentry_operations);
49801 +
49802 + gr_handle_proc_create(child, inode);
49803 +
49804 d_add(child, inode);
49805 }
49806 } else {
49807 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49808 if ((*pos)++ < file->f_pos)
49809 return 0;
49810
49811 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49812 + return 0;
49813 +
49814 if (unlikely(S_ISLNK(table->mode)))
49815 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49816 else
49817 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49818 if (IS_ERR(head))
49819 return PTR_ERR(head);
49820
49821 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49822 + return -ENOENT;
49823 +
49824 generic_fillattr(inode, stat);
49825 if (table)
49826 stat->mode = (stat->mode & S_IFMT) | table->mode;
49827 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49828 .llseek = generic_file_llseek,
49829 };
49830
49831 -static const struct inode_operations proc_sys_inode_operations = {
49832 +const struct inode_operations proc_sys_inode_operations = {
49833 .permission = proc_sys_permission,
49834 .setattr = proc_sys_setattr,
49835 .getattr = proc_sys_getattr,
49836 };
49837
49838 -static const struct inode_operations proc_sys_dir_operations = {
49839 +const struct inode_operations proc_sys_dir_operations = {
49840 .lookup = proc_sys_lookup,
49841 .permission = proc_sys_permission,
49842 .setattr = proc_sys_setattr,
49843 diff --git a/fs/proc/root.c b/fs/proc/root.c
49844 index 9889a92..2613b48 100644
49845 --- a/fs/proc/root.c
49846 +++ b/fs/proc/root.c
49847 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49848 #ifdef CONFIG_PROC_DEVICETREE
49849 proc_device_tree_init();
49850 #endif
49851 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49852 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49853 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49854 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49855 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49856 +#endif
49857 +#else
49858 proc_mkdir("bus", NULL);
49859 +#endif
49860 proc_sys_init();
49861 }
49862
49863 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49864 index 90c63f9..e662cfc 100644
49865 --- a/fs/proc/task_mmu.c
49866 +++ b/fs/proc/task_mmu.c
49867 @@ -11,12 +11,19 @@
49868 #include <linux/rmap.h>
49869 #include <linux/swap.h>
49870 #include <linux/swapops.h>
49871 +#include <linux/grsecurity.h>
49872
49873 #include <asm/elf.h>
49874 #include <asm/uaccess.h>
49875 #include <asm/tlbflush.h>
49876 #include "internal.h"
49877
49878 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49879 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49880 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49881 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49882 +#endif
49883 +
49884 void task_mem(struct seq_file *m, struct mm_struct *mm)
49885 {
49886 unsigned long data, text, lib, swap;
49887 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49888 "VmExe:\t%8lu kB\n"
49889 "VmLib:\t%8lu kB\n"
49890 "VmPTE:\t%8lu kB\n"
49891 - "VmSwap:\t%8lu kB\n",
49892 - hiwater_vm << (PAGE_SHIFT-10),
49893 + "VmSwap:\t%8lu kB\n"
49894 +
49895 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49896 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49897 +#endif
49898 +
49899 + ,hiwater_vm << (PAGE_SHIFT-10),
49900 total_vm << (PAGE_SHIFT-10),
49901 mm->locked_vm << (PAGE_SHIFT-10),
49902 mm->pinned_vm << (PAGE_SHIFT-10),
49903 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49904 data << (PAGE_SHIFT-10),
49905 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49906 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49907 - swap << (PAGE_SHIFT-10));
49908 + swap << (PAGE_SHIFT-10)
49909 +
49910 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49911 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49912 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49913 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49914 +#else
49915 + , mm->context.user_cs_base
49916 + , mm->context.user_cs_limit
49917 +#endif
49918 +#endif
49919 +
49920 + );
49921 }
49922
49923 unsigned long task_vsize(struct mm_struct *mm)
49924 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49925 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49926 }
49927
49928 - /* We don't show the stack guard page in /proc/maps */
49929 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49930 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49931 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49932 +#else
49933 start = vma->vm_start;
49934 - if (stack_guard_page_start(vma, start))
49935 - start += PAGE_SIZE;
49936 end = vma->vm_end;
49937 - if (stack_guard_page_end(vma, end))
49938 - end -= PAGE_SIZE;
49939 +#endif
49940
49941 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49942 start,
49943 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49944 flags & VM_WRITE ? 'w' : '-',
49945 flags & VM_EXEC ? 'x' : '-',
49946 flags & VM_MAYSHARE ? 's' : 'p',
49947 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49948 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49949 +#else
49950 pgoff,
49951 +#endif
49952 MAJOR(dev), MINOR(dev), ino, &len);
49953
49954 /*
49955 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49956 */
49957 if (file) {
49958 pad_len_spaces(m, len);
49959 - seq_path(m, &file->f_path, "\n");
49960 + seq_path(m, &file->f_path, "\n\\");
49961 goto done;
49962 }
49963
49964 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49965 * Thread stack in /proc/PID/task/TID/maps or
49966 * the main process stack.
49967 */
49968 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49969 - vma->vm_end >= mm->start_stack)) {
49970 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49971 + (vma->vm_start <= mm->start_stack &&
49972 + vma->vm_end >= mm->start_stack)) {
49973 name = "[stack]";
49974 } else {
49975 /* Thread stack in /proc/PID/maps */
49976 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49977 struct proc_maps_private *priv = m->private;
49978 struct task_struct *task = priv->task;
49979
49980 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49981 + if (current->exec_id != m->exec_id) {
49982 + gr_log_badprocpid("maps");
49983 + return 0;
49984 + }
49985 +#endif
49986 +
49987 show_map_vma(m, vma, is_pid);
49988
49989 if (m->count < m->size) /* vma is copied successfully */
49990 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49991 .private = &mss,
49992 };
49993
49994 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49995 + if (current->exec_id != m->exec_id) {
49996 + gr_log_badprocpid("smaps");
49997 + return 0;
49998 + }
49999 +#endif
50000 memset(&mss, 0, sizeof mss);
50001 - mss.vma = vma;
50002 - /* mmap_sem is held in m_start */
50003 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50004 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50005 -
50006 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50007 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50008 +#endif
50009 + mss.vma = vma;
50010 + /* mmap_sem is held in m_start */
50011 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50012 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50013 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50014 + }
50015 +#endif
50016 show_map_vma(m, vma, is_pid);
50017
50018 seq_printf(m,
50019 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50020 "KernelPageSize: %8lu kB\n"
50021 "MMUPageSize: %8lu kB\n"
50022 "Locked: %8lu kB\n",
50023 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50024 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50025 +#else
50026 (vma->vm_end - vma->vm_start) >> 10,
50027 +#endif
50028 mss.resident >> 10,
50029 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50030 mss.shared_clean >> 10,
50031 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50032 int n;
50033 char buffer[50];
50034
50035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50036 + if (current->exec_id != m->exec_id) {
50037 + gr_log_badprocpid("numa_maps");
50038 + return 0;
50039 + }
50040 +#endif
50041 +
50042 if (!mm)
50043 return 0;
50044
50045 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50046 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50047 mpol_cond_put(pol);
50048
50049 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50050 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50051 +#else
50052 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50053 +#endif
50054
50055 if (file) {
50056 seq_printf(m, " file=");
50057 - seq_path(m, &file->f_path, "\n\t= ");
50058 + seq_path(m, &file->f_path, "\n\t\\= ");
50059 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50060 seq_printf(m, " heap");
50061 } else {
50062 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50063 index 1ccfa53..0848f95 100644
50064 --- a/fs/proc/task_nommu.c
50065 +++ b/fs/proc/task_nommu.c
50066 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50067 else
50068 bytes += kobjsize(mm);
50069
50070 - if (current->fs && current->fs->users > 1)
50071 + if (current->fs && atomic_read(&current->fs->users) > 1)
50072 sbytes += kobjsize(current->fs);
50073 else
50074 bytes += kobjsize(current->fs);
50075 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50076
50077 if (file) {
50078 pad_len_spaces(m, len);
50079 - seq_path(m, &file->f_path, "");
50080 + seq_path(m, &file->f_path, "\n\\");
50081 } else if (mm) {
50082 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50083
50084 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50085 index 16e8abb..2dcf914 100644
50086 --- a/fs/quota/netlink.c
50087 +++ b/fs/quota/netlink.c
50088 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50089 void quota_send_warning(struct kqid qid, dev_t dev,
50090 const char warntype)
50091 {
50092 - static atomic_t seq;
50093 + static atomic_unchecked_t seq;
50094 struct sk_buff *skb;
50095 void *msg_head;
50096 int ret;
50097 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
50098 "VFS: Not enough memory to send quota warning.\n");
50099 return;
50100 }
50101 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50102 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50103 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50104 if (!msg_head) {
50105 printk(KERN_ERR
50106 diff --git a/fs/read_write.c b/fs/read_write.c
50107 index d065348..8e2b43d 100644
50108 --- a/fs/read_write.c
50109 +++ b/fs/read_write.c
50110 @@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
50111 if (retval > 0) {
50112 add_rchar(current, retval);
50113 add_wchar(current, retval);
50114 + fsnotify_access(in.file);
50115 + fsnotify_modify(out.file);
50116 }
50117
50118 inc_syscr(current);
50119 diff --git a/fs/readdir.c b/fs/readdir.c
50120 index 5e69ef5..e5d9099 100644
50121 --- a/fs/readdir.c
50122 +++ b/fs/readdir.c
50123 @@ -17,6 +17,7 @@
50124 #include <linux/security.h>
50125 #include <linux/syscalls.h>
50126 #include <linux/unistd.h>
50127 +#include <linux/namei.h>
50128
50129 #include <asm/uaccess.h>
50130
50131 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50132
50133 struct readdir_callback {
50134 struct old_linux_dirent __user * dirent;
50135 + struct file * file;
50136 int result;
50137 };
50138
50139 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50140 buf->result = -EOVERFLOW;
50141 return -EOVERFLOW;
50142 }
50143 +
50144 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50145 + return 0;
50146 +
50147 buf->result++;
50148 dirent = buf->dirent;
50149 if (!access_ok(VERIFY_WRITE, dirent,
50150 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50151
50152 buf.result = 0;
50153 buf.dirent = dirent;
50154 + buf.file = f.file;
50155
50156 error = vfs_readdir(f.file, fillonedir, &buf);
50157 if (buf.result)
50158 @@ -139,6 +146,7 @@ struct linux_dirent {
50159 struct getdents_callback {
50160 struct linux_dirent __user * current_dir;
50161 struct linux_dirent __user * previous;
50162 + struct file * file;
50163 int count;
50164 int error;
50165 };
50166 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50167 buf->error = -EOVERFLOW;
50168 return -EOVERFLOW;
50169 }
50170 +
50171 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50172 + return 0;
50173 +
50174 dirent = buf->previous;
50175 if (dirent) {
50176 if (__put_user(offset, &dirent->d_off))
50177 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50178 buf.previous = NULL;
50179 buf.count = count;
50180 buf.error = 0;
50181 + buf.file = f.file;
50182
50183 error = vfs_readdir(f.file, filldir, &buf);
50184 if (error >= 0)
50185 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50186 struct getdents_callback64 {
50187 struct linux_dirent64 __user * current_dir;
50188 struct linux_dirent64 __user * previous;
50189 + struct file *file;
50190 int count;
50191 int error;
50192 };
50193 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50194 buf->error = -EINVAL; /* only used if we fail.. */
50195 if (reclen > buf->count)
50196 return -EINVAL;
50197 +
50198 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50199 + return 0;
50200 +
50201 dirent = buf->previous;
50202 if (dirent) {
50203 if (__put_user(offset, &dirent->d_off))
50204 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50205
50206 buf.current_dir = dirent;
50207 buf.previous = NULL;
50208 + buf.file = f.file;
50209 buf.count = count;
50210 buf.error = 0;
50211
50212 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50213 error = buf.error;
50214 lastdirent = buf.previous;
50215 if (lastdirent) {
50216 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
50217 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50218 if (__put_user(d_off, &lastdirent->d_off))
50219 error = -EFAULT;
50220 else
50221 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50222 index 2b7882b..1c5ef48 100644
50223 --- a/fs/reiserfs/do_balan.c
50224 +++ b/fs/reiserfs/do_balan.c
50225 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50226 return;
50227 }
50228
50229 - atomic_inc(&(fs_generation(tb->tb_sb)));
50230 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50231 do_balance_starts(tb);
50232
50233 /* balance leaf returns 0 except if combining L R and S into
50234 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50235 index e60e870..f40ac16 100644
50236 --- a/fs/reiserfs/procfs.c
50237 +++ b/fs/reiserfs/procfs.c
50238 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50239 "SMALL_TAILS " : "NO_TAILS ",
50240 replay_only(sb) ? "REPLAY_ONLY " : "",
50241 convert_reiserfs(sb) ? "CONV " : "",
50242 - atomic_read(&r->s_generation_counter),
50243 + atomic_read_unchecked(&r->s_generation_counter),
50244 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50245 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50246 SF(s_good_search_by_key_reada), SF(s_bmaps),
50247 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50248 index 33215f5..c5d427a 100644
50249 --- a/fs/reiserfs/reiserfs.h
50250 +++ b/fs/reiserfs/reiserfs.h
50251 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50252 /* Comment? -Hans */
50253 wait_queue_head_t s_wait;
50254 /* To be obsoleted soon by per buffer seals.. -Hans */
50255 - atomic_t s_generation_counter; // increased by one every time the
50256 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50257 // tree gets re-balanced
50258 unsigned long s_properties; /* File system properties. Currently holds
50259 on-disk FS format */
50260 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50261 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50262
50263 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50264 -#define get_generation(s) atomic_read (&fs_generation(s))
50265 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50266 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50267 #define __fs_changed(gen,s) (gen != get_generation (s))
50268 #define fs_changed(gen,s) \
50269 diff --git a/fs/select.c b/fs/select.c
50270 index 2ef72d9..f213b17 100644
50271 --- a/fs/select.c
50272 +++ b/fs/select.c
50273 @@ -20,6 +20,7 @@
50274 #include <linux/export.h>
50275 #include <linux/slab.h>
50276 #include <linux/poll.h>
50277 +#include <linux/security.h>
50278 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50279 #include <linux/file.h>
50280 #include <linux/fdtable.h>
50281 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50282 struct poll_list *walk = head;
50283 unsigned long todo = nfds;
50284
50285 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50286 if (nfds > rlimit(RLIMIT_NOFILE))
50287 return -EINVAL;
50288
50289 diff --git a/fs/seq_file.c b/fs/seq_file.c
50290 index 99dffab..884a1eb 100644
50291 --- a/fs/seq_file.c
50292 +++ b/fs/seq_file.c
50293 @@ -10,6 +10,7 @@
50294 #include <linux/seq_file.h>
50295 #include <linux/slab.h>
50296 #include <linux/cred.h>
50297 +#include <linux/sched.h>
50298
50299 #include <asm/uaccess.h>
50300 #include <asm/page.h>
50301 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50302 #ifdef CONFIG_USER_NS
50303 p->user_ns = file->f_cred->user_ns;
50304 #endif
50305 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50306 + p->exec_id = current->exec_id;
50307 +#endif
50308
50309 /*
50310 * Wrappers around seq_open(e.g. swaps_open) need to be
50311 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50312 return 0;
50313 }
50314 if (!m->buf) {
50315 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50316 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50317 if (!m->buf)
50318 return -ENOMEM;
50319 }
50320 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50321 Eoverflow:
50322 m->op->stop(m, p);
50323 kfree(m->buf);
50324 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50325 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50326 return !m->buf ? -ENOMEM : -EAGAIN;
50327 }
50328
50329 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50330
50331 /* grab buffer if we didn't have one */
50332 if (!m->buf) {
50333 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50334 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50335 if (!m->buf)
50336 goto Enomem;
50337 }
50338 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50339 goto Fill;
50340 m->op->stop(m, p);
50341 kfree(m->buf);
50342 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50343 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50344 if (!m->buf)
50345 goto Enomem;
50346 m->count = 0;
50347 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
50348 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50349 void *data)
50350 {
50351 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50352 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50353 int res = -ENOMEM;
50354
50355 if (op) {
50356 diff --git a/fs/splice.c b/fs/splice.c
50357 index 13e5b47..2262998 100644
50358 --- a/fs/splice.c
50359 +++ b/fs/splice.c
50360 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50361 pipe_lock(pipe);
50362
50363 for (;;) {
50364 - if (!pipe->readers) {
50365 + if (!atomic_read(&pipe->readers)) {
50366 send_sig(SIGPIPE, current, 0);
50367 if (!ret)
50368 ret = -EPIPE;
50369 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50370 do_wakeup = 0;
50371 }
50372
50373 - pipe->waiting_writers++;
50374 + atomic_inc(&pipe->waiting_writers);
50375 pipe_wait(pipe);
50376 - pipe->waiting_writers--;
50377 + atomic_dec(&pipe->waiting_writers);
50378 }
50379
50380 pipe_unlock(pipe);
50381 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50382 old_fs = get_fs();
50383 set_fs(get_ds());
50384 /* The cast to a user pointer is valid due to the set_fs() */
50385 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50386 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50387 set_fs(old_fs);
50388
50389 return res;
50390 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50391 old_fs = get_fs();
50392 set_fs(get_ds());
50393 /* The cast to a user pointer is valid due to the set_fs() */
50394 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50395 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50396 set_fs(old_fs);
50397
50398 return res;
50399 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50400 goto err;
50401
50402 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50403 - vec[i].iov_base = (void __user *) page_address(page);
50404 + vec[i].iov_base = (void __force_user *) page_address(page);
50405 vec[i].iov_len = this_len;
50406 spd.pages[i] = page;
50407 spd.nr_pages++;
50408 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50409 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50410 {
50411 while (!pipe->nrbufs) {
50412 - if (!pipe->writers)
50413 + if (!atomic_read(&pipe->writers))
50414 return 0;
50415
50416 - if (!pipe->waiting_writers && sd->num_spliced)
50417 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50418 return 0;
50419
50420 if (sd->flags & SPLICE_F_NONBLOCK)
50421 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50422 * out of the pipe right after the splice_to_pipe(). So set
50423 * PIPE_READERS appropriately.
50424 */
50425 - pipe->readers = 1;
50426 + atomic_set(&pipe->readers, 1);
50427
50428 current->splice_pipe = pipe;
50429 }
50430 @@ -1739,9 +1739,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50431 ret = -ERESTARTSYS;
50432 break;
50433 }
50434 - if (!pipe->writers)
50435 + if (!atomic_read(&pipe->writers))
50436 break;
50437 - if (!pipe->waiting_writers) {
50438 + if (!atomic_read(&pipe->waiting_writers)) {
50439 if (flags & SPLICE_F_NONBLOCK) {
50440 ret = -EAGAIN;
50441 break;
50442 @@ -1773,7 +1773,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50443 pipe_lock(pipe);
50444
50445 while (pipe->nrbufs >= pipe->buffers) {
50446 - if (!pipe->readers) {
50447 + if (!atomic_read(&pipe->readers)) {
50448 send_sig(SIGPIPE, current, 0);
50449 ret = -EPIPE;
50450 break;
50451 @@ -1786,9 +1786,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50452 ret = -ERESTARTSYS;
50453 break;
50454 }
50455 - pipe->waiting_writers++;
50456 + atomic_inc(&pipe->waiting_writers);
50457 pipe_wait(pipe);
50458 - pipe->waiting_writers--;
50459 + atomic_dec(&pipe->waiting_writers);
50460 }
50461
50462 pipe_unlock(pipe);
50463 @@ -1824,14 +1824,14 @@ retry:
50464 pipe_double_lock(ipipe, opipe);
50465
50466 do {
50467 - if (!opipe->readers) {
50468 + if (!atomic_read(&opipe->readers)) {
50469 send_sig(SIGPIPE, current, 0);
50470 if (!ret)
50471 ret = -EPIPE;
50472 break;
50473 }
50474
50475 - if (!ipipe->nrbufs && !ipipe->writers)
50476 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50477 break;
50478
50479 /*
50480 @@ -1928,7 +1928,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50481 pipe_double_lock(ipipe, opipe);
50482
50483 do {
50484 - if (!opipe->readers) {
50485 + if (!atomic_read(&opipe->readers)) {
50486 send_sig(SIGPIPE, current, 0);
50487 if (!ret)
50488 ret = -EPIPE;
50489 @@ -1973,7 +1973,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50490 * return EAGAIN if we have the potential of some data in the
50491 * future, otherwise just return 0
50492 */
50493 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50494 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50495 ret = -EAGAIN;
50496
50497 pipe_unlock(ipipe);
50498 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50499 index 2fbdff6..5530a61 100644
50500 --- a/fs/sysfs/dir.c
50501 +++ b/fs/sysfs/dir.c
50502 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50503 struct sysfs_dirent *sd;
50504 int rc;
50505
50506 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50507 + const char *parent_name = parent_sd->s_name;
50508 +
50509 + mode = S_IFDIR | S_IRWXU;
50510 +
50511 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50512 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50513 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50514 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50515 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50516 +#endif
50517 +
50518 /* allocate */
50519 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50520 if (!sd)
50521 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50522 index 00012e3..8392349 100644
50523 --- a/fs/sysfs/file.c
50524 +++ b/fs/sysfs/file.c
50525 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50526
50527 struct sysfs_open_dirent {
50528 atomic_t refcnt;
50529 - atomic_t event;
50530 + atomic_unchecked_t event;
50531 wait_queue_head_t poll;
50532 struct list_head buffers; /* goes through sysfs_buffer.list */
50533 };
50534 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50535 if (!sysfs_get_active(attr_sd))
50536 return -ENODEV;
50537
50538 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50539 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50540 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50541
50542 sysfs_put_active(attr_sd);
50543 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50544 return -ENOMEM;
50545
50546 atomic_set(&new_od->refcnt, 0);
50547 - atomic_set(&new_od->event, 1);
50548 + atomic_set_unchecked(&new_od->event, 1);
50549 init_waitqueue_head(&new_od->poll);
50550 INIT_LIST_HEAD(&new_od->buffers);
50551 goto retry;
50552 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50553
50554 sysfs_put_active(attr_sd);
50555
50556 - if (buffer->event != atomic_read(&od->event))
50557 + if (buffer->event != atomic_read_unchecked(&od->event))
50558 goto trigger;
50559
50560 return DEFAULT_POLLMASK;
50561 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50562
50563 od = sd->s_attr.open;
50564 if (od) {
50565 - atomic_inc(&od->event);
50566 + atomic_inc_unchecked(&od->event);
50567 wake_up_interruptible(&od->poll);
50568 }
50569
50570 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50571 index 3c9eb56..9dea5be 100644
50572 --- a/fs/sysfs/symlink.c
50573 +++ b/fs/sysfs/symlink.c
50574 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50575
50576 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50577 {
50578 - char *page = nd_get_link(nd);
50579 + const char *page = nd_get_link(nd);
50580 if (!IS_ERR(page))
50581 free_page((unsigned long)page);
50582 }
50583 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50584 index c175b4d..8f36a16 100644
50585 --- a/fs/udf/misc.c
50586 +++ b/fs/udf/misc.c
50587 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50588
50589 u8 udf_tag_checksum(const struct tag *t)
50590 {
50591 - u8 *data = (u8 *)t;
50592 + const u8 *data = (const u8 *)t;
50593 u8 checksum = 0;
50594 int i;
50595 for (i = 0; i < sizeof(struct tag); ++i)
50596 diff --git a/fs/utimes.c b/fs/utimes.c
50597 index bb0696a..552054b 100644
50598 --- a/fs/utimes.c
50599 +++ b/fs/utimes.c
50600 @@ -1,6 +1,7 @@
50601 #include <linux/compiler.h>
50602 #include <linux/file.h>
50603 #include <linux/fs.h>
50604 +#include <linux/security.h>
50605 #include <linux/linkage.h>
50606 #include <linux/mount.h>
50607 #include <linux/namei.h>
50608 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50609 goto mnt_drop_write_and_out;
50610 }
50611 }
50612 +
50613 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50614 + error = -EACCES;
50615 + goto mnt_drop_write_and_out;
50616 + }
50617 +
50618 mutex_lock(&inode->i_mutex);
50619 error = notify_change(path->dentry, &newattrs);
50620 mutex_unlock(&inode->i_mutex);
50621 diff --git a/fs/xattr.c b/fs/xattr.c
50622 index e21c119..21dfc7c 100644
50623 --- a/fs/xattr.c
50624 +++ b/fs/xattr.c
50625 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50626 * Extended attribute SET operations
50627 */
50628 static long
50629 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50630 +setxattr(struct path *path, const char __user *name, const void __user *value,
50631 size_t size, int flags)
50632 {
50633 int error;
50634 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50635 posix_acl_fix_xattr_from_user(kvalue, size);
50636 }
50637
50638 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50639 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50640 + error = -EACCES;
50641 + goto out;
50642 + }
50643 +
50644 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50645 out:
50646 if (vvalue)
50647 vfree(vvalue);
50648 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50649 return error;
50650 error = mnt_want_write(path.mnt);
50651 if (!error) {
50652 - error = setxattr(path.dentry, name, value, size, flags);
50653 + error = setxattr(&path, name, value, size, flags);
50654 mnt_drop_write(path.mnt);
50655 }
50656 path_put(&path);
50657 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50658 return error;
50659 error = mnt_want_write(path.mnt);
50660 if (!error) {
50661 - error = setxattr(path.dentry, name, value, size, flags);
50662 + error = setxattr(&path, name, value, size, flags);
50663 mnt_drop_write(path.mnt);
50664 }
50665 path_put(&path);
50666 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50667 const void __user *,value, size_t, size, int, flags)
50668 {
50669 struct fd f = fdget(fd);
50670 - struct dentry *dentry;
50671 int error = -EBADF;
50672
50673 if (!f.file)
50674 return error;
50675 - dentry = f.file->f_path.dentry;
50676 - audit_inode(NULL, dentry, 0);
50677 + audit_inode(NULL, f.file->f_path.dentry, 0);
50678 error = mnt_want_write_file(f.file);
50679 if (!error) {
50680 - error = setxattr(dentry, name, value, size, flags);
50681 + error = setxattr(&f.file->f_path, name, value, size, flags);
50682 mnt_drop_write_file(f.file);
50683 }
50684 fdput(f);
50685 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50686 index 9fbea87..6b19972 100644
50687 --- a/fs/xattr_acl.c
50688 +++ b/fs/xattr_acl.c
50689 @@ -76,8 +76,8 @@ struct posix_acl *
50690 posix_acl_from_xattr(struct user_namespace *user_ns,
50691 const void *value, size_t size)
50692 {
50693 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50694 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50695 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50696 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50697 int count;
50698 struct posix_acl *acl;
50699 struct posix_acl_entry *acl_e;
50700 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50701 index 83d0cf3..2ef526b 100644
50702 --- a/fs/xfs/xfs_bmap.c
50703 +++ b/fs/xfs/xfs_bmap.c
50704 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50705 int nmap,
50706 int ret_nmap);
50707 #else
50708 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50709 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50710 #endif /* DEBUG */
50711
50712 STATIC int
50713 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50714 index 1b9fc3e..e1bdde0 100644
50715 --- a/fs/xfs/xfs_dir2_sf.c
50716 +++ b/fs/xfs/xfs_dir2_sf.c
50717 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50718 }
50719
50720 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50721 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50722 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50723 + char name[sfep->namelen];
50724 + memcpy(name, sfep->name, sfep->namelen);
50725 + if (filldir(dirent, name, sfep->namelen,
50726 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50727 + *offset = off & 0x7fffffff;
50728 + return 0;
50729 + }
50730 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50731 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50732 *offset = off & 0x7fffffff;
50733 return 0;
50734 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50735 index c1df3c6..f987db6 100644
50736 --- a/fs/xfs/xfs_ioctl.c
50737 +++ b/fs/xfs/xfs_ioctl.c
50738 @@ -126,7 +126,7 @@ xfs_find_handle(
50739 }
50740
50741 error = -EFAULT;
50742 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50743 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50744 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50745 goto out_put;
50746
50747 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50748 index 4e00cf0..3374374 100644
50749 --- a/fs/xfs/xfs_iops.c
50750 +++ b/fs/xfs/xfs_iops.c
50751 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50752 struct nameidata *nd,
50753 void *p)
50754 {
50755 - char *s = nd_get_link(nd);
50756 + const char *s = nd_get_link(nd);
50757
50758 if (!IS_ERR(s))
50759 kfree(s);
50760 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50761 new file mode 100644
50762 index 0000000..3900064
50763 --- /dev/null
50764 +++ b/grsecurity/Kconfig
50765 @@ -0,0 +1,964 @@
50766 +#
50767 +# grecurity configuration
50768 +#
50769 +menu "Memory Protections"
50770 +depends on GRKERNSEC
50771 +
50772 +config GRKERNSEC_KMEM
50773 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50774 + default y if GRKERNSEC_CONFIG_AUTO
50775 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50776 + help
50777 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50778 + be written to or read from to modify or leak the contents of the running
50779 + kernel. /dev/port will also not be allowed to be opened. If you have module
50780 + support disabled, enabling this will close up four ways that are
50781 + currently used to insert malicious code into the running kernel.
50782 + Even with all these features enabled, we still highly recommend that
50783 + you use the RBAC system, as it is still possible for an attacker to
50784 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50785 + If you are not using XFree86, you may be able to stop this additional
50786 + case by enabling the 'Disable privileged I/O' option. Though nothing
50787 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50788 + but only to video memory, which is the only writing we allow in this
50789 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50790 + not be allowed to mprotect it with PROT_WRITE later.
50791 + It is highly recommended that you say Y here if you meet all the
50792 + conditions above.
50793 +
50794 +config GRKERNSEC_VM86
50795 + bool "Restrict VM86 mode"
50796 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50797 + depends on X86_32
50798 +
50799 + help
50800 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50801 + make use of a special execution mode on 32bit x86 processors called
50802 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50803 + video cards and will still work with this option enabled. The purpose
50804 + of the option is to prevent exploitation of emulation errors in
50805 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50806 + Nearly all users should be able to enable this option.
50807 +
50808 +config GRKERNSEC_IO
50809 + bool "Disable privileged I/O"
50810 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50811 + depends on X86
50812 + select RTC_CLASS
50813 + select RTC_INTF_DEV
50814 + select RTC_DRV_CMOS
50815 +
50816 + help
50817 + If you say Y here, all ioperm and iopl calls will return an error.
50818 + Ioperm and iopl can be used to modify the running kernel.
50819 + Unfortunately, some programs need this access to operate properly,
50820 + the most notable of which are XFree86 and hwclock. hwclock can be
50821 + remedied by having RTC support in the kernel, so real-time
50822 + clock support is enabled if this option is enabled, to ensure
50823 + that hwclock operates correctly. XFree86 still will not
50824 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50825 + IF YOU USE XFree86. If you use XFree86 and you still want to
50826 + protect your kernel against modification, use the RBAC system.
50827 +
50828 +config GRKERNSEC_JIT_HARDEN
50829 + bool "Harden BPF JIT against spray attacks"
50830 + default y if GRKERNSEC_CONFIG_AUTO
50831 + depends on BPF_JIT
50832 + help
50833 + If you say Y here, the native code generated by the kernel's Berkeley
50834 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
50835 + attacks that attempt to fit attacker-beneficial instructions in
50836 + 32bit immediate fields of JIT-generated native instructions. The
50837 + attacker will generally aim to cause an unintended instruction sequence
50838 + of JIT-generated native code to execute by jumping into the middle of
50839 + a generated instruction. This feature effectively randomizes the 32bit
50840 + immediate constants present in the generated code to thwart such attacks.
50841 +
50842 + If you're using KERNEXEC, it's recommended that you enable this option
50843 + to supplement the hardening of the kernel.
50844 +
50845 +config GRKERNSEC_PROC_MEMMAP
50846 + bool "Harden ASLR against information leaks and entropy reduction"
50847 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50848 + depends on PAX_NOEXEC || PAX_ASLR
50849 + help
50850 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50851 + give no information about the addresses of its mappings if
50852 + PaX features that rely on random addresses are enabled on the task.
50853 + In addition to sanitizing this information and disabling other
50854 + dangerous sources of information, this option causes reads of sensitive
50855 + /proc/<pid> entries where the file descriptor was opened in a different
50856 + task than the one performing the read. Such attempts are logged.
50857 + This option also limits argv/env strings for suid/sgid binaries
50858 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50859 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50860 + binaries to prevent alternative mmap layouts from being abused.
50861 +
50862 + If you use PaX it is essential that you say Y here as it closes up
50863 + several holes that make full ASLR useless locally.
50864 +
50865 +config GRKERNSEC_BRUTE
50866 + bool "Deter exploit bruteforcing"
50867 + default y if GRKERNSEC_CONFIG_AUTO
50868 + help
50869 + If you say Y here, attempts to bruteforce exploits against forking
50870 + daemons such as apache or sshd, as well as against suid/sgid binaries
50871 + will be deterred. When a child of a forking daemon is killed by PaX
50872 + or crashes due to an illegal instruction or other suspicious signal,
50873 + the parent process will be delayed 30 seconds upon every subsequent
50874 + fork until the administrator is able to assess the situation and
50875 + restart the daemon.
50876 + In the suid/sgid case, the attempt is logged, the user has all their
50877 + processes terminated, and they are prevented from executing any further
50878 + processes for 15 minutes.
50879 + It is recommended that you also enable signal logging in the auditing
50880 + section so that logs are generated when a process triggers a suspicious
50881 + signal.
50882 + If the sysctl option is enabled, a sysctl option with name
50883 + "deter_bruteforce" is created.
50884 +
50885 +
50886 +config GRKERNSEC_MODHARDEN
50887 + bool "Harden module auto-loading"
50888 + default y if GRKERNSEC_CONFIG_AUTO
50889 + depends on MODULES
50890 + help
50891 + If you say Y here, module auto-loading in response to use of some
50892 + feature implemented by an unloaded module will be restricted to
50893 + root users. Enabling this option helps defend against attacks
50894 + by unprivileged users who abuse the auto-loading behavior to
50895 + cause a vulnerable module to load that is then exploited.
50896 +
50897 + If this option prevents a legitimate use of auto-loading for a
50898 + non-root user, the administrator can execute modprobe manually
50899 + with the exact name of the module mentioned in the alert log.
50900 + Alternatively, the administrator can add the module to the list
50901 + of modules loaded at boot by modifying init scripts.
50902 +
50903 + Modification of init scripts will most likely be needed on
50904 + Ubuntu servers with encrypted home directory support enabled,
50905 + as the first non-root user logging in will cause the ecb(aes),
50906 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50907 +
50908 +config GRKERNSEC_HIDESYM
50909 + bool "Hide kernel symbols"
50910 + default y if GRKERNSEC_CONFIG_AUTO
50911 + select PAX_USERCOPY_SLABS
50912 + help
50913 + If you say Y here, getting information on loaded modules, and
50914 + displaying all kernel symbols through a syscall will be restricted
50915 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50916 + /proc/kallsyms will be restricted to the root user. The RBAC
50917 + system can hide that entry even from root.
50918 +
50919 + This option also prevents leaking of kernel addresses through
50920 + several /proc entries.
50921 +
50922 + Note that this option is only effective provided the following
50923 + conditions are met:
50924 + 1) The kernel using grsecurity is not precompiled by some distribution
50925 + 2) You have also enabled GRKERNSEC_DMESG
50926 + 3) You are using the RBAC system and hiding other files such as your
50927 + kernel image and System.map. Alternatively, enabling this option
50928 + causes the permissions on /boot, /lib/modules, and the kernel
50929 + source directory to change at compile time to prevent
50930 + reading by non-root users.
50931 + If the above conditions are met, this option will aid in providing a
50932 + useful protection against local kernel exploitation of overflows
50933 + and arbitrary read/write vulnerabilities.
50934 +
50935 +config GRKERNSEC_KERN_LOCKOUT
50936 + bool "Active kernel exploit response"
50937 + default y if GRKERNSEC_CONFIG_AUTO
50938 + depends on X86 || ARM || PPC || SPARC
50939 + help
50940 + If you say Y here, when a PaX alert is triggered due to suspicious
50941 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50942 + or an OOPS occurs due to bad memory accesses, instead of just
50943 + terminating the offending process (and potentially allowing
50944 + a subsequent exploit from the same user), we will take one of two
50945 + actions:
50946 + If the user was root, we will panic the system
50947 + If the user was non-root, we will log the attempt, terminate
50948 + all processes owned by the user, then prevent them from creating
50949 + any new processes until the system is restarted
50950 + This deters repeated kernel exploitation/bruteforcing attempts
50951 + and is useful for later forensics.
50952 +
50953 +endmenu
50954 +menu "Role Based Access Control Options"
50955 +depends on GRKERNSEC
50956 +
50957 +config GRKERNSEC_RBAC_DEBUG
50958 + bool
50959 +
50960 +config GRKERNSEC_NO_RBAC
50961 + bool "Disable RBAC system"
50962 + help
50963 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50964 + preventing the RBAC system from being enabled. You should only say Y
50965 + here if you have no intention of using the RBAC system, so as to prevent
50966 + an attacker with root access from misusing the RBAC system to hide files
50967 + and processes when loadable module support and /dev/[k]mem have been
50968 + locked down.
50969 +
50970 +config GRKERNSEC_ACL_HIDEKERN
50971 + bool "Hide kernel processes"
50972 + help
50973 + If you say Y here, all kernel threads will be hidden to all
50974 + processes but those whose subject has the "view hidden processes"
50975 + flag.
50976 +
50977 +config GRKERNSEC_ACL_MAXTRIES
50978 + int "Maximum tries before password lockout"
50979 + default 3
50980 + help
50981 + This option enforces the maximum number of times a user can attempt
50982 + to authorize themselves with the grsecurity RBAC system before being
50983 + denied the ability to attempt authorization again for a specified time.
50984 + The lower the number, the harder it will be to brute-force a password.
50985 +
50986 +config GRKERNSEC_ACL_TIMEOUT
50987 + int "Time to wait after max password tries, in seconds"
50988 + default 30
50989 + help
50990 + This option specifies the time the user must wait after attempting to
50991 + authorize to the RBAC system with the maximum number of invalid
50992 + passwords. The higher the number, the harder it will be to brute-force
50993 + a password.
50994 +
50995 +endmenu
50996 +menu "Filesystem Protections"
50997 +depends on GRKERNSEC
50998 +
50999 +config GRKERNSEC_PROC
51000 + bool "Proc restrictions"
51001 + default y if GRKERNSEC_CONFIG_AUTO
51002 + help
51003 + If you say Y here, the permissions of the /proc filesystem
51004 + will be altered to enhance system security and privacy. You MUST
51005 + choose either a user only restriction or a user and group restriction.
51006 + Depending upon the option you choose, you can either restrict users to
51007 + see only the processes they themselves run, or choose a group that can
51008 + view all processes and files normally restricted to root if you choose
51009 + the "restrict to user only" option. NOTE: If you're running identd or
51010 + ntpd as a non-root user, you will have to run it as the group you
51011 + specify here.
51012 +
51013 +config GRKERNSEC_PROC_USER
51014 + bool "Restrict /proc to user only"
51015 + depends on GRKERNSEC_PROC
51016 + help
51017 + If you say Y here, non-root users will only be able to view their own
51018 + processes, and restricts them from viewing network-related information,
51019 + and viewing kernel symbol and module information.
51020 +
51021 +config GRKERNSEC_PROC_USERGROUP
51022 + bool "Allow special group"
51023 + default y if GRKERNSEC_CONFIG_AUTO
51024 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
51025 + help
51026 + If you say Y here, you will be able to select a group that will be
51027 + able to view all processes and network-related information. If you've
51028 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
51029 + remain hidden. This option is useful if you want to run identd as
51030 + a non-root user. The group you select may also be chosen at boot time
51031 + via "grsec_proc_gid=" on the kernel commandline.
51032 +
51033 +config GRKERNSEC_PROC_GID
51034 + int "GID for special group"
51035 + depends on GRKERNSEC_PROC_USERGROUP
51036 + default 1001
51037 +
51038 +config GRKERNSEC_PROC_ADD
51039 + bool "Additional restrictions"
51040 + default y if GRKERNSEC_CONFIG_AUTO
51041 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51042 + help
51043 + If you say Y here, additional restrictions will be placed on
51044 + /proc that keep normal users from viewing device information and
51045 + slabinfo information that could be useful for exploits.
51046 +
51047 +config GRKERNSEC_LINK
51048 + bool "Linking restrictions"
51049 + default y if GRKERNSEC_CONFIG_AUTO
51050 + help
51051 + If you say Y here, /tmp race exploits will be prevented, since users
51052 + will no longer be able to follow symlinks owned by other users in
51053 + world-writable +t directories (e.g. /tmp), unless the owner of the
51054 + symlink is the owner of the directory. users will also not be
51055 + able to hardlink to files they do not own. If the sysctl option is
51056 + enabled, a sysctl option with name "linking_restrictions" is created.
51057 +
51058 +config GRKERNSEC_SYMLINKOWN
51059 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51060 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51061 + help
51062 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51063 + that prevents it from being used as a security feature. As Apache
51064 + verifies the symlink by performing a stat() against the target of
51065 + the symlink before it is followed, an attacker can setup a symlink
51066 + to point to a same-owned file, then replace the symlink with one
51067 + that targets another user's file just after Apache "validates" the
51068 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51069 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51070 + will be in place for the group you specify. If the sysctl option
51071 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51072 + created.
51073 +
51074 +config GRKERNSEC_SYMLINKOWN_GID
51075 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51076 + depends on GRKERNSEC_SYMLINKOWN
51077 + default 1006
51078 + help
51079 + Setting this GID determines what group kernel-enforced
51080 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51081 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51082 +
51083 +config GRKERNSEC_FIFO
51084 + bool "FIFO restrictions"
51085 + default y if GRKERNSEC_CONFIG_AUTO
51086 + help
51087 + If you say Y here, users will not be able to write to FIFOs they don't
51088 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51089 + the FIFO is the same owner of the directory it's held in. If the sysctl
51090 + option is enabled, a sysctl option with name "fifo_restrictions" is
51091 + created.
51092 +
51093 +config GRKERNSEC_SYSFS_RESTRICT
51094 + bool "Sysfs/debugfs restriction"
51095 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51096 + depends on SYSFS
51097 + help
51098 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51099 + any filesystem normally mounted under it (e.g. debugfs) will be
51100 + mostly accessible only by root. These filesystems generally provide access
51101 + to hardware and debug information that isn't appropriate for unprivileged
51102 + users of the system. Sysfs and debugfs have also become a large source
51103 + of new vulnerabilities, ranging from infoleaks to local compromise.
51104 + There has been very little oversight with an eye toward security involved
51105 + in adding new exporters of information to these filesystems, so their
51106 + use is discouraged.
51107 + For reasons of compatibility, a few directories have been whitelisted
51108 + for access by non-root users:
51109 + /sys/fs/selinux
51110 + /sys/fs/fuse
51111 + /sys/devices/system/cpu
51112 +
51113 +config GRKERNSEC_ROFS
51114 + bool "Runtime read-only mount protection"
51115 + help
51116 + If you say Y here, a sysctl option with name "romount_protect" will
51117 + be created. By setting this option to 1 at runtime, filesystems
51118 + will be protected in the following ways:
51119 + * No new writable mounts will be allowed
51120 + * Existing read-only mounts won't be able to be remounted read/write
51121 + * Write operations will be denied on all block devices
51122 + This option acts independently of grsec_lock: once it is set to 1,
51123 + it cannot be turned off. Therefore, please be mindful of the resulting
51124 + behavior if this option is enabled in an init script on a read-only
51125 + filesystem. This feature is mainly intended for secure embedded systems.
51126 +
51127 +config GRKERNSEC_CHROOT
51128 + bool "Chroot jail restrictions"
51129 + default y if GRKERNSEC_CONFIG_AUTO
51130 + help
51131 + If you say Y here, you will be able to choose several options that will
51132 + make breaking out of a chrooted jail much more difficult. If you
51133 + encounter no software incompatibilities with the following options, it
51134 + is recommended that you enable each one.
51135 +
51136 +config GRKERNSEC_CHROOT_MOUNT
51137 + bool "Deny mounts"
51138 + default y if GRKERNSEC_CONFIG_AUTO
51139 + depends on GRKERNSEC_CHROOT
51140 + help
51141 + If you say Y here, processes inside a chroot will not be able to
51142 + mount or remount filesystems. If the sysctl option is enabled, a
51143 + sysctl option with name "chroot_deny_mount" is created.
51144 +
51145 +config GRKERNSEC_CHROOT_DOUBLE
51146 + bool "Deny double-chroots"
51147 + default y if GRKERNSEC_CONFIG_AUTO
51148 + depends on GRKERNSEC_CHROOT
51149 + help
51150 + If you say Y here, processes inside a chroot will not be able to chroot
51151 + again outside the chroot. This is a widely used method of breaking
51152 + out of a chroot jail and should not be allowed. If the sysctl
51153 + option is enabled, a sysctl option with name
51154 + "chroot_deny_chroot" is created.
51155 +
51156 +config GRKERNSEC_CHROOT_PIVOT
51157 + bool "Deny pivot_root in chroot"
51158 + default y if GRKERNSEC_CONFIG_AUTO
51159 + depends on GRKERNSEC_CHROOT
51160 + help
51161 + If you say Y here, processes inside a chroot will not be able to use
51162 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51163 + works similar to chroot in that it changes the root filesystem. This
51164 + function could be misused in a chrooted process to attempt to break out
51165 + of the chroot, and therefore should not be allowed. If the sysctl
51166 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51167 + created.
51168 +
51169 +config GRKERNSEC_CHROOT_CHDIR
51170 + bool "Enforce chdir(\"/\") on all chroots"
51171 + default y if GRKERNSEC_CONFIG_AUTO
51172 + depends on GRKERNSEC_CHROOT
51173 + help
51174 + If you say Y here, the current working directory of all newly-chrooted
51175 + applications will be set to the the root directory of the chroot.
51176 + The man page on chroot(2) states:
51177 + Note that this call does not change the current working
51178 + directory, so that `.' can be outside the tree rooted at
51179 + `/'. In particular, the super-user can escape from a
51180 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51181 +
51182 + It is recommended that you say Y here, since it's not known to break
51183 + any software. If the sysctl option is enabled, a sysctl option with
51184 + name "chroot_enforce_chdir" is created.
51185 +
51186 +config GRKERNSEC_CHROOT_CHMOD
51187 + bool "Deny (f)chmod +s"
51188 + default y if GRKERNSEC_CONFIG_AUTO
51189 + depends on GRKERNSEC_CHROOT
51190 + help
51191 + If you say Y here, processes inside a chroot will not be able to chmod
51192 + or fchmod files to make them have suid or sgid bits. This protects
51193 + against another published method of breaking a chroot. If the sysctl
51194 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51195 + created.
51196 +
51197 +config GRKERNSEC_CHROOT_FCHDIR
51198 + bool "Deny fchdir out of chroot"
51199 + default y if GRKERNSEC_CONFIG_AUTO
51200 + depends on GRKERNSEC_CHROOT
51201 + help
51202 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51203 + to a file descriptor of the chrooting process that points to a directory
51204 + outside the filesystem will be stopped. If the sysctl option
51205 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51206 +
51207 +config GRKERNSEC_CHROOT_MKNOD
51208 + bool "Deny mknod"
51209 + default y if GRKERNSEC_CONFIG_AUTO
51210 + depends on GRKERNSEC_CHROOT
51211 + help
51212 + If you say Y here, processes inside a chroot will not be allowed to
51213 + mknod. The problem with using mknod inside a chroot is that it
51214 + would allow an attacker to create a device entry that is the same
51215 + as one on the physical root of your system, which could range from
51216 + anything from the console device to a device for your harddrive (which
51217 + they could then use to wipe the drive or steal data). It is recommended
51218 + that you say Y here, unless you run into software incompatibilities.
51219 + If the sysctl option is enabled, a sysctl option with name
51220 + "chroot_deny_mknod" is created.
51221 +
51222 +config GRKERNSEC_CHROOT_SHMAT
51223 + bool "Deny shmat() out of chroot"
51224 + default y if GRKERNSEC_CONFIG_AUTO
51225 + depends on GRKERNSEC_CHROOT
51226 + help
51227 + If you say Y here, processes inside a chroot will not be able to attach
51228 + to shared memory segments that were created outside of the chroot jail.
51229 + It is recommended that you say Y here. If the sysctl option is enabled,
51230 + a sysctl option with name "chroot_deny_shmat" is created.
51231 +
51232 +config GRKERNSEC_CHROOT_UNIX
51233 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51234 + default y if GRKERNSEC_CONFIG_AUTO
51235 + depends on GRKERNSEC_CHROOT
51236 + help
51237 + If you say Y here, processes inside a chroot will not be able to
51238 + connect to abstract (meaning not belonging to a filesystem) Unix
51239 + domain sockets that were bound outside of a chroot. It is recommended
51240 + that you say Y here. If the sysctl option is enabled, a sysctl option
51241 + with name "chroot_deny_unix" is created.
51242 +
51243 +config GRKERNSEC_CHROOT_FINDTASK
51244 + bool "Protect outside processes"
51245 + default y if GRKERNSEC_CONFIG_AUTO
51246 + depends on GRKERNSEC_CHROOT
51247 + help
51248 + If you say Y here, processes inside a chroot will not be able to
51249 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51250 + getsid, or view any process outside of the chroot. If the sysctl
51251 + option is enabled, a sysctl option with name "chroot_findtask" is
51252 + created.
51253 +
51254 +config GRKERNSEC_CHROOT_NICE
51255 + bool "Restrict priority changes"
51256 + default y if GRKERNSEC_CONFIG_AUTO
51257 + depends on GRKERNSEC_CHROOT
51258 + help
51259 + If you say Y here, processes inside a chroot will not be able to raise
51260 + the priority of processes in the chroot, or alter the priority of
51261 + processes outside the chroot. This provides more security than simply
51262 + removing CAP_SYS_NICE from the process' capability set. If the
51263 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51264 + is created.
51265 +
51266 +config GRKERNSEC_CHROOT_SYSCTL
51267 + bool "Deny sysctl writes"
51268 + default y if GRKERNSEC_CONFIG_AUTO
51269 + depends on GRKERNSEC_CHROOT
51270 + help
51271 + If you say Y here, an attacker in a chroot will not be able to
51272 + write to sysctl entries, either by sysctl(2) or through a /proc
51273 + interface. It is strongly recommended that you say Y here. If the
51274 + sysctl option is enabled, a sysctl option with name
51275 + "chroot_deny_sysctl" is created.
51276 +
51277 +config GRKERNSEC_CHROOT_CAPS
51278 + bool "Capability restrictions"
51279 + default y if GRKERNSEC_CONFIG_AUTO
51280 + depends on GRKERNSEC_CHROOT
51281 + help
51282 + If you say Y here, the capabilities on all processes within a
51283 + chroot jail will be lowered to stop module insertion, raw i/o,
51284 + system and net admin tasks, rebooting the system, modifying immutable
51285 + files, modifying IPC owned by another, and changing the system time.
51286 + This is left an option because it can break some apps. Disable this
51287 + if your chrooted apps are having problems performing those kinds of
51288 + tasks. If the sysctl option is enabled, a sysctl option with
51289 + name "chroot_caps" is created.
51290 +
51291 +endmenu
51292 +menu "Kernel Auditing"
51293 +depends on GRKERNSEC
51294 +
51295 +config GRKERNSEC_AUDIT_GROUP
51296 + bool "Single group for auditing"
51297 + help
51298 + If you say Y here, the exec, chdir, and (un)mount logging features
51299 + will only operate on a group you specify. This option is recommended
51300 + if you only want to watch certain users instead of having a large
51301 + amount of logs from the entire system. If the sysctl option is enabled,
51302 + a sysctl option with name "audit_group" is created.
51303 +
51304 +config GRKERNSEC_AUDIT_GID
51305 + int "GID for auditing"
51306 + depends on GRKERNSEC_AUDIT_GROUP
51307 + default 1007
51308 +
51309 +config GRKERNSEC_EXECLOG
51310 + bool "Exec logging"
51311 + help
51312 + If you say Y here, all execve() calls will be logged (since the
51313 + other exec*() calls are frontends to execve(), all execution
51314 + will be logged). Useful for shell-servers that like to keep track
51315 + of their users. If the sysctl option is enabled, a sysctl option with
51316 + name "exec_logging" is created.
51317 + WARNING: This option when enabled will produce a LOT of logs, especially
51318 + on an active system.
51319 +
51320 +config GRKERNSEC_RESLOG
51321 + bool "Resource logging"
51322 + default y if GRKERNSEC_CONFIG_AUTO
51323 + help
51324 + If you say Y here, all attempts to overstep resource limits will
51325 + be logged with the resource name, the requested size, and the current
51326 + limit. It is highly recommended that you say Y here. If the sysctl
51327 + option is enabled, a sysctl option with name "resource_logging" is
51328 + created. If the RBAC system is enabled, the sysctl value is ignored.
51329 +
51330 +config GRKERNSEC_CHROOT_EXECLOG
51331 + bool "Log execs within chroot"
51332 + help
51333 + If you say Y here, all executions inside a chroot jail will be logged
51334 + to syslog. This can cause a large amount of logs if certain
51335 + applications (eg. djb's daemontools) are installed on the system, and
51336 + is therefore left as an option. If the sysctl option is enabled, a
51337 + sysctl option with name "chroot_execlog" is created.
51338 +
51339 +config GRKERNSEC_AUDIT_PTRACE
51340 + bool "Ptrace logging"
51341 + help
51342 + If you say Y here, all attempts to attach to a process via ptrace
51343 + will be logged. If the sysctl option is enabled, a sysctl option
51344 + with name "audit_ptrace" is created.
51345 +
51346 +config GRKERNSEC_AUDIT_CHDIR
51347 + bool "Chdir logging"
51348 + help
51349 + If you say Y here, all chdir() calls will be logged. If the sysctl
51350 + option is enabled, a sysctl option with name "audit_chdir" is created.
51351 +
51352 +config GRKERNSEC_AUDIT_MOUNT
51353 + bool "(Un)Mount logging"
51354 + help
51355 + If you say Y here, all mounts and unmounts will be logged. If the
51356 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51357 + created.
51358 +
51359 +config GRKERNSEC_SIGNAL
51360 + bool "Signal logging"
51361 + default y if GRKERNSEC_CONFIG_AUTO
51362 + help
51363 + If you say Y here, certain important signals will be logged, such as
51364 + SIGSEGV, which will as a result inform you of when a error in a program
51365 + occurred, which in some cases could mean a possible exploit attempt.
51366 + If the sysctl option is enabled, a sysctl option with name
51367 + "signal_logging" is created.
51368 +
51369 +config GRKERNSEC_FORKFAIL
51370 + bool "Fork failure logging"
51371 + help
51372 + If you say Y here, all failed fork() attempts will be logged.
51373 + This could suggest a fork bomb, or someone attempting to overstep
51374 + their process limit. If the sysctl option is enabled, a sysctl option
51375 + with name "forkfail_logging" is created.
51376 +
51377 +config GRKERNSEC_TIME
51378 + bool "Time change logging"
51379 + default y if GRKERNSEC_CONFIG_AUTO
51380 + help
51381 + If you say Y here, any changes of the system clock will be logged.
51382 + If the sysctl option is enabled, a sysctl option with name
51383 + "timechange_logging" is created.
51384 +
51385 +config GRKERNSEC_PROC_IPADDR
51386 + bool "/proc/<pid>/ipaddr support"
51387 + default y if GRKERNSEC_CONFIG_AUTO
51388 + help
51389 + If you say Y here, a new entry will be added to each /proc/<pid>
51390 + directory that contains the IP address of the person using the task.
51391 + The IP is carried across local TCP and AF_UNIX stream sockets.
51392 + This information can be useful for IDS/IPSes to perform remote response
51393 + to a local attack. The entry is readable by only the owner of the
51394 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51395 + the RBAC system), and thus does not create privacy concerns.
51396 +
51397 +config GRKERNSEC_RWXMAP_LOG
51398 + bool 'Denied RWX mmap/mprotect logging'
51399 + default y if GRKERNSEC_CONFIG_AUTO
51400 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51401 + help
51402 + If you say Y here, calls to mmap() and mprotect() with explicit
51403 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51404 + denied by the PAX_MPROTECT feature. If the sysctl option is
51405 + enabled, a sysctl option with name "rwxmap_logging" is created.
51406 +
51407 +config GRKERNSEC_AUDIT_TEXTREL
51408 + bool 'ELF text relocations logging (READ HELP)'
51409 + depends on PAX_MPROTECT
51410 + help
51411 + If you say Y here, text relocations will be logged with the filename
51412 + of the offending library or binary. The purpose of the feature is
51413 + to help Linux distribution developers get rid of libraries and
51414 + binaries that need text relocations which hinder the future progress
51415 + of PaX. Only Linux distribution developers should say Y here, and
51416 + never on a production machine, as this option creates an information
51417 + leak that could aid an attacker in defeating the randomization of
51418 + a single memory region. If the sysctl option is enabled, a sysctl
51419 + option with name "audit_textrel" is created.
51420 +
51421 +endmenu
51422 +
51423 +menu "Executable Protections"
51424 +depends on GRKERNSEC
51425 +
51426 +config GRKERNSEC_DMESG
51427 + bool "Dmesg(8) restriction"
51428 + default y if GRKERNSEC_CONFIG_AUTO
51429 + help
51430 + If you say Y here, non-root users will not be able to use dmesg(8)
51431 + to view the contents of the kernel's circular log buffer.
51432 + The kernel's log buffer often contains kernel addresses and other
51433 + identifying information useful to an attacker in fingerprinting a
51434 + system for a targeted exploit.
51435 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51436 + created.
51437 +
51438 +config GRKERNSEC_HARDEN_PTRACE
51439 + bool "Deter ptrace-based process snooping"
51440 + default y if GRKERNSEC_CONFIG_AUTO
51441 + help
51442 + If you say Y here, TTY sniffers and other malicious monitoring
51443 + programs implemented through ptrace will be defeated. If you
51444 + have been using the RBAC system, this option has already been
51445 + enabled for several years for all users, with the ability to make
51446 + fine-grained exceptions.
51447 +
51448 + This option only affects the ability of non-root users to ptrace
51449 + processes that are not a descendent of the ptracing process.
51450 + This means that strace ./binary and gdb ./binary will still work,
51451 + but attaching to arbitrary processes will not. If the sysctl
51452 + option is enabled, a sysctl option with name "harden_ptrace" is
51453 + created.
51454 +
51455 +config GRKERNSEC_PTRACE_READEXEC
51456 + bool "Require read access to ptrace sensitive binaries"
51457 + default y if GRKERNSEC_CONFIG_AUTO
51458 + help
51459 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51460 + binaries. This option is useful in environments that
51461 + remove the read bits (e.g. file mode 4711) from suid binaries to
51462 + prevent infoleaking of their contents. This option adds
51463 + consistency to the use of that file mode, as the binary could normally
51464 + be read out when run without privileges while ptracing.
51465 +
51466 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51467 + is created.
51468 +
51469 +config GRKERNSEC_SETXID
51470 + bool "Enforce consistent multithreaded privileges"
51471 + default y if GRKERNSEC_CONFIG_AUTO
51472 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51473 + help
51474 + If you say Y here, a change from a root uid to a non-root uid
51475 + in a multithreaded application will cause the resulting uids,
51476 + gids, supplementary groups, and capabilities in that thread
51477 + to be propagated to the other threads of the process. In most
51478 + cases this is unnecessary, as glibc will emulate this behavior
51479 + on behalf of the application. Other libcs do not act in the
51480 + same way, allowing the other threads of the process to continue
51481 + running with root privileges. If the sysctl option is enabled,
51482 + a sysctl option with name "consistent_setxid" is created.
51483 +
51484 +config GRKERNSEC_TPE
51485 + bool "Trusted Path Execution (TPE)"
51486 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51487 + help
51488 + If you say Y here, you will be able to choose a gid to add to the
51489 + supplementary groups of users you want to mark as "untrusted."
51490 + These users will not be able to execute any files that are not in
51491 + root-owned directories writable only by root. If the sysctl option
51492 + is enabled, a sysctl option with name "tpe" is created.
51493 +
51494 +config GRKERNSEC_TPE_ALL
51495 + bool "Partially restrict all non-root users"
51496 + depends on GRKERNSEC_TPE
51497 + help
51498 + If you say Y here, all non-root users will be covered under
51499 + a weaker TPE restriction. This is separate from, and in addition to,
51500 + the main TPE options that you have selected elsewhere. Thus, if a
51501 + "trusted" GID is chosen, this restriction applies to even that GID.
51502 + Under this restriction, all non-root users will only be allowed to
51503 + execute files in directories they own that are not group or
51504 + world-writable, or in directories owned by root and writable only by
51505 + root. If the sysctl option is enabled, a sysctl option with name
51506 + "tpe_restrict_all" is created.
51507 +
51508 +config GRKERNSEC_TPE_INVERT
51509 + bool "Invert GID option"
51510 + depends on GRKERNSEC_TPE
51511 + help
51512 + If you say Y here, the group you specify in the TPE configuration will
51513 + decide what group TPE restrictions will be *disabled* for. This
51514 + option is useful if you want TPE restrictions to be applied to most
51515 + users on the system. If the sysctl option is enabled, a sysctl option
51516 + with name "tpe_invert" is created. Unlike other sysctl options, this
51517 + entry will default to on for backward-compatibility.
51518 +
51519 +config GRKERNSEC_TPE_GID
51520 + int
51521 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51522 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51523 +
51524 +config GRKERNSEC_TPE_UNTRUSTED_GID
51525 + int "GID for TPE-untrusted users"
51526 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51527 + default 1005
51528 + help
51529 + Setting this GID determines what group TPE restrictions will be
51530 + *enabled* for. If the sysctl option is enabled, a sysctl option
51531 + with name "tpe_gid" is created.
51532 +
51533 +config GRKERNSEC_TPE_TRUSTED_GID
51534 + int "GID for TPE-trusted users"
51535 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51536 + default 1005
51537 + help
51538 + Setting this GID determines what group TPE restrictions will be
51539 + *disabled* for. If the sysctl option is enabled, a sysctl option
51540 + with name "tpe_gid" is created.
51541 +
51542 +endmenu
51543 +menu "Network Protections"
51544 +depends on GRKERNSEC
51545 +
51546 +config GRKERNSEC_RANDNET
51547 + bool "Larger entropy pools"
51548 + default y if GRKERNSEC_CONFIG_AUTO
51549 + help
51550 + If you say Y here, the entropy pools used for many features of Linux
51551 + and grsecurity will be doubled in size. Since several grsecurity
51552 + features use additional randomness, it is recommended that you say Y
51553 + here. Saying Y here has a similar effect as modifying
51554 + /proc/sys/kernel/random/poolsize.
51555 +
51556 +config GRKERNSEC_BLACKHOLE
51557 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51558 + default y if GRKERNSEC_CONFIG_AUTO
51559 + depends on NET
51560 + help
51561 + If you say Y here, neither TCP resets nor ICMP
51562 + destination-unreachable packets will be sent in response to packets
51563 + sent to ports for which no associated listening process exists.
51564 + This feature supports both IPV4 and IPV6 and exempts the
51565 + loopback interface from blackholing. Enabling this feature
51566 + makes a host more resilient to DoS attacks and reduces network
51567 + visibility against scanners.
51568 +
51569 + The blackhole feature as-implemented is equivalent to the FreeBSD
51570 + blackhole feature, as it prevents RST responses to all packets, not
51571 + just SYNs. Under most application behavior this causes no
51572 + problems, but applications (like haproxy) may not close certain
51573 + connections in a way that cleanly terminates them on the remote
51574 + end, leaving the remote host in LAST_ACK state. Because of this
51575 + side-effect and to prevent intentional LAST_ACK DoSes, this
51576 + feature also adds automatic mitigation against such attacks.
51577 + The mitigation drastically reduces the amount of time a socket
51578 + can spend in LAST_ACK state. If you're using haproxy and not
51579 + all servers it connects to have this option enabled, consider
51580 + disabling this feature on the haproxy host.
51581 +
51582 + If the sysctl option is enabled, two sysctl options with names
51583 + "ip_blackhole" and "lastack_retries" will be created.
51584 + While "ip_blackhole" takes the standard zero/non-zero on/off
51585 + toggle, "lastack_retries" uses the same kinds of values as
51586 + "tcp_retries1" and "tcp_retries2". The default value of 4
51587 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51588 + state.
51589 +
51590 +config GRKERNSEC_SOCKET
51591 + bool "Socket restrictions"
51592 + depends on NET
51593 + help
51594 + If you say Y here, you will be able to choose from several options.
51595 + If you assign a GID on your system and add it to the supplementary
51596 + groups of users you want to restrict socket access to, this patch
51597 + will perform up to three things, based on the option(s) you choose.
51598 +
51599 +config GRKERNSEC_SOCKET_ALL
51600 + bool "Deny any sockets to group"
51601 + depends on GRKERNSEC_SOCKET
51602 + help
51603 + If you say Y here, you will be able to choose a GID of whose users will
51604 + be unable to connect to other hosts from your machine or run server
51605 + applications from your machine. If the sysctl option is enabled, a
51606 + sysctl option with name "socket_all" is created.
51607 +
51608 +config GRKERNSEC_SOCKET_ALL_GID
51609 + int "GID to deny all sockets for"
51610 + depends on GRKERNSEC_SOCKET_ALL
51611 + default 1004
51612 + help
51613 + Here you can choose the GID to disable socket access for. Remember to
51614 + add the users you want socket access disabled for to the GID
51615 + specified here. If the sysctl option is enabled, a sysctl option
51616 + with name "socket_all_gid" is created.
51617 +
51618 +config GRKERNSEC_SOCKET_CLIENT
51619 + bool "Deny client sockets to group"
51620 + depends on GRKERNSEC_SOCKET
51621 + help
51622 + If you say Y here, you will be able to choose a GID of whose users will
51623 + be unable to connect to other hosts from your machine, but will be
51624 + able to run servers. If this option is enabled, all users in the group
51625 + you specify will have to use passive mode when initiating ftp transfers
51626 + from the shell on your machine. If the sysctl option is enabled, a
51627 + sysctl option with name "socket_client" is created.
51628 +
51629 +config GRKERNSEC_SOCKET_CLIENT_GID
51630 + int "GID to deny client sockets for"
51631 + depends on GRKERNSEC_SOCKET_CLIENT
51632 + default 1003
51633 + help
51634 + Here you can choose the GID to disable client socket access for.
51635 + Remember to add the users you want client socket access disabled for to
51636 + the GID specified here. If the sysctl option is enabled, a sysctl
51637 + option with name "socket_client_gid" is created.
51638 +
51639 +config GRKERNSEC_SOCKET_SERVER
51640 + bool "Deny server sockets to group"
51641 + depends on GRKERNSEC_SOCKET
51642 + help
51643 + If you say Y here, you will be able to choose a GID of whose users will
51644 + be unable to run server applications from your machine. If the sysctl
51645 + option is enabled, a sysctl option with name "socket_server" is created.
51646 +
51647 +config GRKERNSEC_SOCKET_SERVER_GID
51648 + int "GID to deny server sockets for"
51649 + depends on GRKERNSEC_SOCKET_SERVER
51650 + default 1002
51651 + help
51652 + Here you can choose the GID to disable server socket access for.
51653 + Remember to add the users you want server socket access disabled for to
51654 + the GID specified here. If the sysctl option is enabled, a sysctl
51655 + option with name "socket_server_gid" is created.
51656 +
51657 +endmenu
51658 +menu "Sysctl Support"
51659 +depends on GRKERNSEC && SYSCTL
51660 +
51661 +config GRKERNSEC_SYSCTL
51662 + bool "Sysctl support"
51663 + default y if GRKERNSEC_CONFIG_AUTO
51664 + help
51665 + If you say Y here, you will be able to change the options that
51666 + grsecurity runs with at bootup, without having to recompile your
51667 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51668 + to enable (1) or disable (0) various features. All the sysctl entries
51669 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51670 + All features enabled in the kernel configuration are disabled at boot
51671 + if you do not say Y to the "Turn on features by default" option.
51672 + All options should be set at startup, and the grsec_lock entry should
51673 + be set to a non-zero value after all the options are set.
51674 + *THIS IS EXTREMELY IMPORTANT*
51675 +
51676 +config GRKERNSEC_SYSCTL_DISTRO
51677 + bool "Extra sysctl support for distro makers (READ HELP)"
51678 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51679 + help
51680 + If you say Y here, additional sysctl options will be created
51681 + for features that affect processes running as root. Therefore,
51682 + it is critical when using this option that the grsec_lock entry be
51683 + enabled after boot. Only distros with prebuilt kernel packages
51684 + with this option enabled that can ensure grsec_lock is enabled
51685 + after boot should use this option.
51686 + *Failure to set grsec_lock after boot makes all grsec features
51687 + this option covers useless*
51688 +
51689 + Currently this option creates the following sysctl entries:
51690 + "Disable Privileged I/O": "disable_priv_io"
51691 +
51692 +config GRKERNSEC_SYSCTL_ON
51693 + bool "Turn on features by default"
51694 + default y if GRKERNSEC_CONFIG_AUTO
51695 + depends on GRKERNSEC_SYSCTL
51696 + help
51697 + If you say Y here, instead of having all features enabled in the
51698 + kernel configuration disabled at boot time, the features will be
51699 + enabled at boot time. It is recommended you say Y here unless
51700 + there is some reason you would want all sysctl-tunable features to
51701 + be disabled by default. As mentioned elsewhere, it is important
51702 + to enable the grsec_lock entry once you have finished modifying
51703 + the sysctl entries.
51704 +
51705 +endmenu
51706 +menu "Logging Options"
51707 +depends on GRKERNSEC
51708 +
51709 +config GRKERNSEC_FLOODTIME
51710 + int "Seconds in between log messages (minimum)"
51711 + default 10
51712 + help
51713 + This option allows you to enforce the number of seconds between
51714 + grsecurity log messages. The default should be suitable for most
51715 + people, however, if you choose to change it, choose a value small enough
51716 + to allow informative logs to be produced, but large enough to
51717 + prevent flooding.
51718 +
51719 +config GRKERNSEC_FLOODBURST
51720 + int "Number of messages in a burst (maximum)"
51721 + default 6
51722 + help
51723 + This option allows you to choose the maximum number of messages allowed
51724 + within the flood time interval you chose in a separate option. The
51725 + default should be suitable for most people, however if you find that
51726 + many of your logs are being interpreted as flooding, you may want to
51727 + raise this value.
51728 +
51729 +endmenu
51730 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51731 new file mode 100644
51732 index 0000000..1b9afa9
51733 --- /dev/null
51734 +++ b/grsecurity/Makefile
51735 @@ -0,0 +1,38 @@
51736 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51737 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51738 +# into an RBAC system
51739 +#
51740 +# All code in this directory and various hooks inserted throughout the kernel
51741 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51742 +# under the GPL v2 or higher
51743 +
51744 +KBUILD_CFLAGS += -Werror
51745 +
51746 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51747 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51748 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51749 +
51750 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51751 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51752 + gracl_learn.o grsec_log.o
51753 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51754 +
51755 +ifdef CONFIG_NET
51756 +obj-y += grsec_sock.o
51757 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51758 +endif
51759 +
51760 +ifndef CONFIG_GRKERNSEC
51761 +obj-y += grsec_disabled.o
51762 +endif
51763 +
51764 +ifdef CONFIG_GRKERNSEC_HIDESYM
51765 +extra-y := grsec_hidesym.o
51766 +$(obj)/grsec_hidesym.o:
51767 + @-chmod -f 500 /boot
51768 + @-chmod -f 500 /lib/modules
51769 + @-chmod -f 500 /lib64/modules
51770 + @-chmod -f 500 /lib32/modules
51771 + @-chmod -f 700 .
51772 + @echo ' grsec: protected kernel image paths'
51773 +endif
51774 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51775 new file mode 100644
51776 index 0000000..b1810d9
51777 --- /dev/null
51778 +++ b/grsecurity/gracl.c
51779 @@ -0,0 +1,4056 @@
51780 +#include <linux/kernel.h>
51781 +#include <linux/module.h>
51782 +#include <linux/sched.h>
51783 +#include <linux/mm.h>
51784 +#include <linux/file.h>
51785 +#include <linux/fs.h>
51786 +#include <linux/namei.h>
51787 +#include <linux/mount.h>
51788 +#include <linux/tty.h>
51789 +#include <linux/proc_fs.h>
51790 +#include <linux/lglock.h>
51791 +#include <linux/slab.h>
51792 +#include <linux/vmalloc.h>
51793 +#include <linux/types.h>
51794 +#include <linux/sysctl.h>
51795 +#include <linux/netdevice.h>
51796 +#include <linux/ptrace.h>
51797 +#include <linux/gracl.h>
51798 +#include <linux/gralloc.h>
51799 +#include <linux/security.h>
51800 +#include <linux/grinternal.h>
51801 +#include <linux/pid_namespace.h>
51802 +#include <linux/stop_machine.h>
51803 +#include <linux/fdtable.h>
51804 +#include <linux/percpu.h>
51805 +#include <linux/lglock.h>
51806 +#include "../fs/mount.h"
51807 +
51808 +#include <asm/uaccess.h>
51809 +#include <asm/errno.h>
51810 +#include <asm/mman.h>
51811 +
51812 +extern struct lglock vfsmount_lock;
51813 +
51814 +static struct acl_role_db acl_role_set;
51815 +static struct name_db name_set;
51816 +static struct inodev_db inodev_set;
51817 +
51818 +/* for keeping track of userspace pointers used for subjects, so we
51819 + can share references in the kernel as well
51820 +*/
51821 +
51822 +static struct path real_root;
51823 +
51824 +static struct acl_subj_map_db subj_map_set;
51825 +
51826 +static struct acl_role_label *default_role;
51827 +
51828 +static struct acl_role_label *role_list;
51829 +
51830 +static u16 acl_sp_role_value;
51831 +
51832 +extern char *gr_shared_page[4];
51833 +static DEFINE_MUTEX(gr_dev_mutex);
51834 +DEFINE_RWLOCK(gr_inode_lock);
51835 +
51836 +struct gr_arg *gr_usermode;
51837 +
51838 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51839 +
51840 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51841 +extern void gr_clear_learn_entries(void);
51842 +
51843 +#ifdef CONFIG_GRKERNSEC_RESLOG
51844 +extern void gr_log_resource(const struct task_struct *task,
51845 + const int res, const unsigned long wanted, const int gt);
51846 +#endif
51847 +
51848 +unsigned char *gr_system_salt;
51849 +unsigned char *gr_system_sum;
51850 +
51851 +static struct sprole_pw **acl_special_roles = NULL;
51852 +static __u16 num_sprole_pws = 0;
51853 +
51854 +static struct acl_role_label *kernel_role = NULL;
51855 +
51856 +static unsigned int gr_auth_attempts = 0;
51857 +static unsigned long gr_auth_expires = 0UL;
51858 +
51859 +#ifdef CONFIG_NET
51860 +extern struct vfsmount *sock_mnt;
51861 +#endif
51862 +
51863 +extern struct vfsmount *pipe_mnt;
51864 +extern struct vfsmount *shm_mnt;
51865 +#ifdef CONFIG_HUGETLBFS
51866 +extern struct vfsmount *hugetlbfs_vfsmount;
51867 +#endif
51868 +
51869 +static struct acl_object_label *fakefs_obj_rw;
51870 +static struct acl_object_label *fakefs_obj_rwx;
51871 +
51872 +extern int gr_init_uidset(void);
51873 +extern void gr_free_uidset(void);
51874 +extern void gr_remove_uid(uid_t uid);
51875 +extern int gr_find_uid(uid_t uid);
51876 +
51877 +__inline__ int
51878 +gr_acl_is_enabled(void)
51879 +{
51880 + return (gr_status & GR_READY);
51881 +}
51882 +
51883 +#ifdef CONFIG_BTRFS_FS
51884 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51885 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51886 +#endif
51887 +
51888 +static inline dev_t __get_dev(const struct dentry *dentry)
51889 +{
51890 +#ifdef CONFIG_BTRFS_FS
51891 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51892 + return get_btrfs_dev_from_inode(dentry->d_inode);
51893 + else
51894 +#endif
51895 + return dentry->d_inode->i_sb->s_dev;
51896 +}
51897 +
51898 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51899 +{
51900 + return __get_dev(dentry);
51901 +}
51902 +
51903 +static char gr_task_roletype_to_char(struct task_struct *task)
51904 +{
51905 + switch (task->role->roletype &
51906 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51907 + GR_ROLE_SPECIAL)) {
51908 + case GR_ROLE_DEFAULT:
51909 + return 'D';
51910 + case GR_ROLE_USER:
51911 + return 'U';
51912 + case GR_ROLE_GROUP:
51913 + return 'G';
51914 + case GR_ROLE_SPECIAL:
51915 + return 'S';
51916 + }
51917 +
51918 + return 'X';
51919 +}
51920 +
51921 +char gr_roletype_to_char(void)
51922 +{
51923 + return gr_task_roletype_to_char(current);
51924 +}
51925 +
51926 +__inline__ int
51927 +gr_acl_tpe_check(void)
51928 +{
51929 + if (unlikely(!(gr_status & GR_READY)))
51930 + return 0;
51931 + if (current->role->roletype & GR_ROLE_TPE)
51932 + return 1;
51933 + else
51934 + return 0;
51935 +}
51936 +
51937 +int
51938 +gr_handle_rawio(const struct inode *inode)
51939 +{
51940 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51941 + if (inode && S_ISBLK(inode->i_mode) &&
51942 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51943 + !capable(CAP_SYS_RAWIO))
51944 + return 1;
51945 +#endif
51946 + return 0;
51947 +}
51948 +
51949 +static int
51950 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51951 +{
51952 + if (likely(lena != lenb))
51953 + return 0;
51954 +
51955 + return !memcmp(a, b, lena);
51956 +}
51957 +
51958 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51959 +{
51960 + *buflen -= namelen;
51961 + if (*buflen < 0)
51962 + return -ENAMETOOLONG;
51963 + *buffer -= namelen;
51964 + memcpy(*buffer, str, namelen);
51965 + return 0;
51966 +}
51967 +
51968 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51969 +{
51970 + return prepend(buffer, buflen, name->name, name->len);
51971 +}
51972 +
51973 +static int prepend_path(const struct path *path, struct path *root,
51974 + char **buffer, int *buflen)
51975 +{
51976 + struct dentry *dentry = path->dentry;
51977 + struct vfsmount *vfsmnt = path->mnt;
51978 + struct mount *mnt = real_mount(vfsmnt);
51979 + bool slash = false;
51980 + int error = 0;
51981 +
51982 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51983 + struct dentry * parent;
51984 +
51985 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51986 + /* Global root? */
51987 + if (!mnt_has_parent(mnt)) {
51988 + goto out;
51989 + }
51990 + dentry = mnt->mnt_mountpoint;
51991 + mnt = mnt->mnt_parent;
51992 + vfsmnt = &mnt->mnt;
51993 + continue;
51994 + }
51995 + parent = dentry->d_parent;
51996 + prefetch(parent);
51997 + spin_lock(&dentry->d_lock);
51998 + error = prepend_name(buffer, buflen, &dentry->d_name);
51999 + spin_unlock(&dentry->d_lock);
52000 + if (!error)
52001 + error = prepend(buffer, buflen, "/", 1);
52002 + if (error)
52003 + break;
52004 +
52005 + slash = true;
52006 + dentry = parent;
52007 + }
52008 +
52009 +out:
52010 + if (!error && !slash)
52011 + error = prepend(buffer, buflen, "/", 1);
52012 +
52013 + return error;
52014 +}
52015 +
52016 +/* this must be called with vfsmount_lock and rename_lock held */
52017 +
52018 +static char *__our_d_path(const struct path *path, struct path *root,
52019 + char *buf, int buflen)
52020 +{
52021 + char *res = buf + buflen;
52022 + int error;
52023 +
52024 + prepend(&res, &buflen, "\0", 1);
52025 + error = prepend_path(path, root, &res, &buflen);
52026 + if (error)
52027 + return ERR_PTR(error);
52028 +
52029 + return res;
52030 +}
52031 +
52032 +static char *
52033 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52034 +{
52035 + char *retval;
52036 +
52037 + retval = __our_d_path(path, root, buf, buflen);
52038 + if (unlikely(IS_ERR(retval)))
52039 + retval = strcpy(buf, "<path too long>");
52040 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52041 + retval[1] = '\0';
52042 +
52043 + return retval;
52044 +}
52045 +
52046 +static char *
52047 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52048 + char *buf, int buflen)
52049 +{
52050 + struct path path;
52051 + char *res;
52052 +
52053 + path.dentry = (struct dentry *)dentry;
52054 + path.mnt = (struct vfsmount *)vfsmnt;
52055 +
52056 + /* we can use real_root.dentry, real_root.mnt, because this is only called
52057 + by the RBAC system */
52058 + res = gen_full_path(&path, &real_root, buf, buflen);
52059 +
52060 + return res;
52061 +}
52062 +
52063 +static char *
52064 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52065 + char *buf, int buflen)
52066 +{
52067 + char *res;
52068 + struct path path;
52069 + struct path root;
52070 + struct task_struct *reaper = init_pid_ns.child_reaper;
52071 +
52072 + path.dentry = (struct dentry *)dentry;
52073 + path.mnt = (struct vfsmount *)vfsmnt;
52074 +
52075 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52076 + get_fs_root(reaper->fs, &root);
52077 +
52078 + write_seqlock(&rename_lock);
52079 + br_read_lock(&vfsmount_lock);
52080 + res = gen_full_path(&path, &root, buf, buflen);
52081 + br_read_unlock(&vfsmount_lock);
52082 + write_sequnlock(&rename_lock);
52083 +
52084 + path_put(&root);
52085 + return res;
52086 +}
52087 +
52088 +static char *
52089 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52090 +{
52091 + char *ret;
52092 + write_seqlock(&rename_lock);
52093 + br_read_lock(&vfsmount_lock);
52094 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52095 + PAGE_SIZE);
52096 + br_read_unlock(&vfsmount_lock);
52097 + write_sequnlock(&rename_lock);
52098 + return ret;
52099 +}
52100 +
52101 +static char *
52102 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52103 +{
52104 + char *ret;
52105 + char *buf;
52106 + int buflen;
52107 +
52108 + write_seqlock(&rename_lock);
52109 + br_read_lock(&vfsmount_lock);
52110 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52111 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52112 + buflen = (int)(ret - buf);
52113 + if (buflen >= 5)
52114 + prepend(&ret, &buflen, "/proc", 5);
52115 + else
52116 + ret = strcpy(buf, "<path too long>");
52117 + br_read_unlock(&vfsmount_lock);
52118 + write_sequnlock(&rename_lock);
52119 + return ret;
52120 +}
52121 +
52122 +char *
52123 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52124 +{
52125 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52126 + PAGE_SIZE);
52127 +}
52128 +
52129 +char *
52130 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52131 +{
52132 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52133 + PAGE_SIZE);
52134 +}
52135 +
52136 +char *
52137 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52138 +{
52139 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52140 + PAGE_SIZE);
52141 +}
52142 +
52143 +char *
52144 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52145 +{
52146 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52147 + PAGE_SIZE);
52148 +}
52149 +
52150 +char *
52151 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52152 +{
52153 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52154 + PAGE_SIZE);
52155 +}
52156 +
52157 +__inline__ __u32
52158 +to_gr_audit(const __u32 reqmode)
52159 +{
52160 + /* masks off auditable permission flags, then shifts them to create
52161 + auditing flags, and adds the special case of append auditing if
52162 + we're requesting write */
52163 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52164 +}
52165 +
52166 +struct acl_subject_label *
52167 +lookup_subject_map(const struct acl_subject_label *userp)
52168 +{
52169 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
52170 + struct subject_map *match;
52171 +
52172 + match = subj_map_set.s_hash[index];
52173 +
52174 + while (match && match->user != userp)
52175 + match = match->next;
52176 +
52177 + if (match != NULL)
52178 + return match->kernel;
52179 + else
52180 + return NULL;
52181 +}
52182 +
52183 +static void
52184 +insert_subj_map_entry(struct subject_map *subjmap)
52185 +{
52186 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
52187 + struct subject_map **curr;
52188 +
52189 + subjmap->prev = NULL;
52190 +
52191 + curr = &subj_map_set.s_hash[index];
52192 + if (*curr != NULL)
52193 + (*curr)->prev = subjmap;
52194 +
52195 + subjmap->next = *curr;
52196 + *curr = subjmap;
52197 +
52198 + return;
52199 +}
52200 +
52201 +static struct acl_role_label *
52202 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52203 + const gid_t gid)
52204 +{
52205 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52206 + struct acl_role_label *match;
52207 + struct role_allowed_ip *ipp;
52208 + unsigned int x;
52209 + u32 curr_ip = task->signal->curr_ip;
52210 +
52211 + task->signal->saved_ip = curr_ip;
52212 +
52213 + match = acl_role_set.r_hash[index];
52214 +
52215 + while (match) {
52216 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52217 + for (x = 0; x < match->domain_child_num; x++) {
52218 + if (match->domain_children[x] == uid)
52219 + goto found;
52220 + }
52221 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52222 + break;
52223 + match = match->next;
52224 + }
52225 +found:
52226 + if (match == NULL) {
52227 + try_group:
52228 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52229 + match = acl_role_set.r_hash[index];
52230 +
52231 + while (match) {
52232 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52233 + for (x = 0; x < match->domain_child_num; x++) {
52234 + if (match->domain_children[x] == gid)
52235 + goto found2;
52236 + }
52237 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52238 + break;
52239 + match = match->next;
52240 + }
52241 +found2:
52242 + if (match == NULL)
52243 + match = default_role;
52244 + if (match->allowed_ips == NULL)
52245 + return match;
52246 + else {
52247 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52248 + if (likely
52249 + ((ntohl(curr_ip) & ipp->netmask) ==
52250 + (ntohl(ipp->addr) & ipp->netmask)))
52251 + return match;
52252 + }
52253 + match = default_role;
52254 + }
52255 + } else if (match->allowed_ips == NULL) {
52256 + return match;
52257 + } else {
52258 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52259 + if (likely
52260 + ((ntohl(curr_ip) & ipp->netmask) ==
52261 + (ntohl(ipp->addr) & ipp->netmask)))
52262 + return match;
52263 + }
52264 + goto try_group;
52265 + }
52266 +
52267 + return match;
52268 +}
52269 +
52270 +struct acl_subject_label *
52271 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52272 + const struct acl_role_label *role)
52273 +{
52274 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
52275 + struct acl_subject_label *match;
52276 +
52277 + match = role->subj_hash[index];
52278 +
52279 + while (match && (match->inode != ino || match->device != dev ||
52280 + (match->mode & GR_DELETED))) {
52281 + match = match->next;
52282 + }
52283 +
52284 + if (match && !(match->mode & GR_DELETED))
52285 + return match;
52286 + else
52287 + return NULL;
52288 +}
52289 +
52290 +struct acl_subject_label *
52291 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52292 + const struct acl_role_label *role)
52293 +{
52294 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
52295 + struct acl_subject_label *match;
52296 +
52297 + match = role->subj_hash[index];
52298 +
52299 + while (match && (match->inode != ino || match->device != dev ||
52300 + !(match->mode & GR_DELETED))) {
52301 + match = match->next;
52302 + }
52303 +
52304 + if (match && (match->mode & GR_DELETED))
52305 + return match;
52306 + else
52307 + return NULL;
52308 +}
52309 +
52310 +static struct acl_object_label *
52311 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52312 + const struct acl_subject_label *subj)
52313 +{
52314 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
52315 + struct acl_object_label *match;
52316 +
52317 + match = subj->obj_hash[index];
52318 +
52319 + while (match && (match->inode != ino || match->device != dev ||
52320 + (match->mode & GR_DELETED))) {
52321 + match = match->next;
52322 + }
52323 +
52324 + if (match && !(match->mode & GR_DELETED))
52325 + return match;
52326 + else
52327 + return NULL;
52328 +}
52329 +
52330 +static struct acl_object_label *
52331 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52332 + const struct acl_subject_label *subj)
52333 +{
52334 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
52335 + struct acl_object_label *match;
52336 +
52337 + match = subj->obj_hash[index];
52338 +
52339 + while (match && (match->inode != ino || match->device != dev ||
52340 + !(match->mode & GR_DELETED))) {
52341 + match = match->next;
52342 + }
52343 +
52344 + if (match && (match->mode & GR_DELETED))
52345 + return match;
52346 +
52347 + match = subj->obj_hash[index];
52348 +
52349 + while (match && (match->inode != ino || match->device != dev ||
52350 + (match->mode & GR_DELETED))) {
52351 + match = match->next;
52352 + }
52353 +
52354 + if (match && !(match->mode & GR_DELETED))
52355 + return match;
52356 + else
52357 + return NULL;
52358 +}
52359 +
52360 +static struct name_entry *
52361 +lookup_name_entry(const char *name)
52362 +{
52363 + unsigned int len = strlen(name);
52364 + unsigned int key = full_name_hash(name, len);
52365 + unsigned int index = key % name_set.n_size;
52366 + struct name_entry *match;
52367 +
52368 + match = name_set.n_hash[index];
52369 +
52370 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52371 + match = match->next;
52372 +
52373 + return match;
52374 +}
52375 +
52376 +static struct name_entry *
52377 +lookup_name_entry_create(const char *name)
52378 +{
52379 + unsigned int len = strlen(name);
52380 + unsigned int key = full_name_hash(name, len);
52381 + unsigned int index = key % name_set.n_size;
52382 + struct name_entry *match;
52383 +
52384 + match = name_set.n_hash[index];
52385 +
52386 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52387 + !match->deleted))
52388 + match = match->next;
52389 +
52390 + if (match && match->deleted)
52391 + return match;
52392 +
52393 + match = name_set.n_hash[index];
52394 +
52395 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52396 + match->deleted))
52397 + match = match->next;
52398 +
52399 + if (match && !match->deleted)
52400 + return match;
52401 + else
52402 + return NULL;
52403 +}
52404 +
52405 +static struct inodev_entry *
52406 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52407 +{
52408 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
52409 + struct inodev_entry *match;
52410 +
52411 + match = inodev_set.i_hash[index];
52412 +
52413 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52414 + match = match->next;
52415 +
52416 + return match;
52417 +}
52418 +
52419 +static void
52420 +insert_inodev_entry(struct inodev_entry *entry)
52421 +{
52422 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
52423 + inodev_set.i_size);
52424 + struct inodev_entry **curr;
52425 +
52426 + entry->prev = NULL;
52427 +
52428 + curr = &inodev_set.i_hash[index];
52429 + if (*curr != NULL)
52430 + (*curr)->prev = entry;
52431 +
52432 + entry->next = *curr;
52433 + *curr = entry;
52434 +
52435 + return;
52436 +}
52437 +
52438 +static void
52439 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52440 +{
52441 + unsigned int index =
52442 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52443 + struct acl_role_label **curr;
52444 + struct acl_role_label *tmp, *tmp2;
52445 +
52446 + curr = &acl_role_set.r_hash[index];
52447 +
52448 + /* simple case, slot is empty, just set it to our role */
52449 + if (*curr == NULL) {
52450 + *curr = role;
52451 + } else {
52452 + /* example:
52453 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52454 + 2 -> 3
52455 + */
52456 + /* first check to see if we can already be reached via this slot */
52457 + tmp = *curr;
52458 + while (tmp && tmp != role)
52459 + tmp = tmp->next;
52460 + if (tmp == role) {
52461 + /* we don't need to add ourselves to this slot's chain */
52462 + return;
52463 + }
52464 + /* we need to add ourselves to this chain, two cases */
52465 + if (role->next == NULL) {
52466 + /* simple case, append the current chain to our role */
52467 + role->next = *curr;
52468 + *curr = role;
52469 + } else {
52470 + /* 1 -> 2 -> 3 -> 4
52471 + 2 -> 3 -> 4
52472 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52473 + */
52474 + /* trickier case: walk our role's chain until we find
52475 + the role for the start of the current slot's chain */
52476 + tmp = role;
52477 + tmp2 = *curr;
52478 + while (tmp->next && tmp->next != tmp2)
52479 + tmp = tmp->next;
52480 + if (tmp->next == tmp2) {
52481 + /* from example above, we found 3, so just
52482 + replace this slot's chain with ours */
52483 + *curr = role;
52484 + } else {
52485 + /* we didn't find a subset of our role's chain
52486 + in the current slot's chain, so append their
52487 + chain to ours, and set us as the first role in
52488 + the slot's chain
52489 +
52490 + we could fold this case with the case above,
52491 + but making it explicit for clarity
52492 + */
52493 + tmp->next = tmp2;
52494 + *curr = role;
52495 + }
52496 + }
52497 + }
52498 +
52499 + return;
52500 +}
52501 +
52502 +static void
52503 +insert_acl_role_label(struct acl_role_label *role)
52504 +{
52505 + int i;
52506 +
52507 + if (role_list == NULL) {
52508 + role_list = role;
52509 + role->prev = NULL;
52510 + } else {
52511 + role->prev = role_list;
52512 + role_list = role;
52513 + }
52514 +
52515 + /* used for hash chains */
52516 + role->next = NULL;
52517 +
52518 + if (role->roletype & GR_ROLE_DOMAIN) {
52519 + for (i = 0; i < role->domain_child_num; i++)
52520 + __insert_acl_role_label(role, role->domain_children[i]);
52521 + } else
52522 + __insert_acl_role_label(role, role->uidgid);
52523 +}
52524 +
52525 +static int
52526 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52527 +{
52528 + struct name_entry **curr, *nentry;
52529 + struct inodev_entry *ientry;
52530 + unsigned int len = strlen(name);
52531 + unsigned int key = full_name_hash(name, len);
52532 + unsigned int index = key % name_set.n_size;
52533 +
52534 + curr = &name_set.n_hash[index];
52535 +
52536 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52537 + curr = &((*curr)->next);
52538 +
52539 + if (*curr != NULL)
52540 + return 1;
52541 +
52542 + nentry = acl_alloc(sizeof (struct name_entry));
52543 + if (nentry == NULL)
52544 + return 0;
52545 + ientry = acl_alloc(sizeof (struct inodev_entry));
52546 + if (ientry == NULL)
52547 + return 0;
52548 + ientry->nentry = nentry;
52549 +
52550 + nentry->key = key;
52551 + nentry->name = name;
52552 + nentry->inode = inode;
52553 + nentry->device = device;
52554 + nentry->len = len;
52555 + nentry->deleted = deleted;
52556 +
52557 + nentry->prev = NULL;
52558 + curr = &name_set.n_hash[index];
52559 + if (*curr != NULL)
52560 + (*curr)->prev = nentry;
52561 + nentry->next = *curr;
52562 + *curr = nentry;
52563 +
52564 + /* insert us into the table searchable by inode/dev */
52565 + insert_inodev_entry(ientry);
52566 +
52567 + return 1;
52568 +}
52569 +
52570 +static void
52571 +insert_acl_obj_label(struct acl_object_label *obj,
52572 + struct acl_subject_label *subj)
52573 +{
52574 + unsigned int index =
52575 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
52576 + struct acl_object_label **curr;
52577 +
52578 +
52579 + obj->prev = NULL;
52580 +
52581 + curr = &subj->obj_hash[index];
52582 + if (*curr != NULL)
52583 + (*curr)->prev = obj;
52584 +
52585 + obj->next = *curr;
52586 + *curr = obj;
52587 +
52588 + return;
52589 +}
52590 +
52591 +static void
52592 +insert_acl_subj_label(struct acl_subject_label *obj,
52593 + struct acl_role_label *role)
52594 +{
52595 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
52596 + struct acl_subject_label **curr;
52597 +
52598 + obj->prev = NULL;
52599 +
52600 + curr = &role->subj_hash[index];
52601 + if (*curr != NULL)
52602 + (*curr)->prev = obj;
52603 +
52604 + obj->next = *curr;
52605 + *curr = obj;
52606 +
52607 + return;
52608 +}
52609 +
52610 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52611 +
52612 +static void *
52613 +create_table(__u32 * len, int elementsize)
52614 +{
52615 + unsigned int table_sizes[] = {
52616 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52617 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52618 + 4194301, 8388593, 16777213, 33554393, 67108859
52619 + };
52620 + void *newtable = NULL;
52621 + unsigned int pwr = 0;
52622 +
52623 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52624 + table_sizes[pwr] <= *len)
52625 + pwr++;
52626 +
52627 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52628 + return newtable;
52629 +
52630 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52631 + newtable =
52632 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52633 + else
52634 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52635 +
52636 + *len = table_sizes[pwr];
52637 +
52638 + return newtable;
52639 +}
52640 +
52641 +static int
52642 +init_variables(const struct gr_arg *arg)
52643 +{
52644 + struct task_struct *reaper = init_pid_ns.child_reaper;
52645 + unsigned int stacksize;
52646 +
52647 + subj_map_set.s_size = arg->role_db.num_subjects;
52648 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52649 + name_set.n_size = arg->role_db.num_objects;
52650 + inodev_set.i_size = arg->role_db.num_objects;
52651 +
52652 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52653 + !name_set.n_size || !inodev_set.i_size)
52654 + return 1;
52655 +
52656 + if (!gr_init_uidset())
52657 + return 1;
52658 +
52659 + /* set up the stack that holds allocation info */
52660 +
52661 + stacksize = arg->role_db.num_pointers + 5;
52662 +
52663 + if (!acl_alloc_stack_init(stacksize))
52664 + return 1;
52665 +
52666 + /* grab reference for the real root dentry and vfsmount */
52667 + get_fs_root(reaper->fs, &real_root);
52668 +
52669 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52670 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52671 +#endif
52672 +
52673 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52674 + if (fakefs_obj_rw == NULL)
52675 + return 1;
52676 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52677 +
52678 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52679 + if (fakefs_obj_rwx == NULL)
52680 + return 1;
52681 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52682 +
52683 + subj_map_set.s_hash =
52684 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52685 + acl_role_set.r_hash =
52686 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52687 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52688 + inodev_set.i_hash =
52689 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52690 +
52691 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52692 + !name_set.n_hash || !inodev_set.i_hash)
52693 + return 1;
52694 +
52695 + memset(subj_map_set.s_hash, 0,
52696 + sizeof(struct subject_map *) * subj_map_set.s_size);
52697 + memset(acl_role_set.r_hash, 0,
52698 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52699 + memset(name_set.n_hash, 0,
52700 + sizeof (struct name_entry *) * name_set.n_size);
52701 + memset(inodev_set.i_hash, 0,
52702 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52703 +
52704 + return 0;
52705 +}
52706 +
52707 +/* free information not needed after startup
52708 + currently contains user->kernel pointer mappings for subjects
52709 +*/
52710 +
52711 +static void
52712 +free_init_variables(void)
52713 +{
52714 + __u32 i;
52715 +
52716 + if (subj_map_set.s_hash) {
52717 + for (i = 0; i < subj_map_set.s_size; i++) {
52718 + if (subj_map_set.s_hash[i]) {
52719 + kfree(subj_map_set.s_hash[i]);
52720 + subj_map_set.s_hash[i] = NULL;
52721 + }
52722 + }
52723 +
52724 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52725 + PAGE_SIZE)
52726 + kfree(subj_map_set.s_hash);
52727 + else
52728 + vfree(subj_map_set.s_hash);
52729 + }
52730 +
52731 + return;
52732 +}
52733 +
52734 +static void
52735 +free_variables(void)
52736 +{
52737 + struct acl_subject_label *s;
52738 + struct acl_role_label *r;
52739 + struct task_struct *task, *task2;
52740 + unsigned int x;
52741 +
52742 + gr_clear_learn_entries();
52743 +
52744 + read_lock(&tasklist_lock);
52745 + do_each_thread(task2, task) {
52746 + task->acl_sp_role = 0;
52747 + task->acl_role_id = 0;
52748 + task->acl = NULL;
52749 + task->role = NULL;
52750 + } while_each_thread(task2, task);
52751 + read_unlock(&tasklist_lock);
52752 +
52753 + /* release the reference to the real root dentry and vfsmount */
52754 + path_put(&real_root);
52755 + memset(&real_root, 0, sizeof(real_root));
52756 +
52757 + /* free all object hash tables */
52758 +
52759 + FOR_EACH_ROLE_START(r)
52760 + if (r->subj_hash == NULL)
52761 + goto next_role;
52762 + FOR_EACH_SUBJECT_START(r, s, x)
52763 + if (s->obj_hash == NULL)
52764 + break;
52765 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52766 + kfree(s->obj_hash);
52767 + else
52768 + vfree(s->obj_hash);
52769 + FOR_EACH_SUBJECT_END(s, x)
52770 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52771 + if (s->obj_hash == NULL)
52772 + break;
52773 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52774 + kfree(s->obj_hash);
52775 + else
52776 + vfree(s->obj_hash);
52777 + FOR_EACH_NESTED_SUBJECT_END(s)
52778 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52779 + kfree(r->subj_hash);
52780 + else
52781 + vfree(r->subj_hash);
52782 + r->subj_hash = NULL;
52783 +next_role:
52784 + FOR_EACH_ROLE_END(r)
52785 +
52786 + acl_free_all();
52787 +
52788 + if (acl_role_set.r_hash) {
52789 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52790 + PAGE_SIZE)
52791 + kfree(acl_role_set.r_hash);
52792 + else
52793 + vfree(acl_role_set.r_hash);
52794 + }
52795 + if (name_set.n_hash) {
52796 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52797 + PAGE_SIZE)
52798 + kfree(name_set.n_hash);
52799 + else
52800 + vfree(name_set.n_hash);
52801 + }
52802 +
52803 + if (inodev_set.i_hash) {
52804 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52805 + PAGE_SIZE)
52806 + kfree(inodev_set.i_hash);
52807 + else
52808 + vfree(inodev_set.i_hash);
52809 + }
52810 +
52811 + gr_free_uidset();
52812 +
52813 + memset(&name_set, 0, sizeof (struct name_db));
52814 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52815 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52816 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52817 +
52818 + default_role = NULL;
52819 + kernel_role = NULL;
52820 + role_list = NULL;
52821 +
52822 + return;
52823 +}
52824 +
52825 +static __u32
52826 +count_user_objs(struct acl_object_label *userp)
52827 +{
52828 + struct acl_object_label o_tmp;
52829 + __u32 num = 0;
52830 +
52831 + while (userp) {
52832 + if (copy_from_user(&o_tmp, userp,
52833 + sizeof (struct acl_object_label)))
52834 + break;
52835 +
52836 + userp = o_tmp.prev;
52837 + num++;
52838 + }
52839 +
52840 + return num;
52841 +}
52842 +
52843 +static struct acl_subject_label *
52844 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
52845 +
52846 +static int
52847 +copy_user_glob(struct acl_object_label *obj)
52848 +{
52849 + struct acl_object_label *g_tmp, **guser;
52850 + unsigned int len;
52851 + char *tmp;
52852 +
52853 + if (obj->globbed == NULL)
52854 + return 0;
52855 +
52856 + guser = &obj->globbed;
52857 + while (*guser) {
52858 + g_tmp = (struct acl_object_label *)
52859 + acl_alloc(sizeof (struct acl_object_label));
52860 + if (g_tmp == NULL)
52861 + return -ENOMEM;
52862 +
52863 + if (copy_from_user(g_tmp, *guser,
52864 + sizeof (struct acl_object_label)))
52865 + return -EFAULT;
52866 +
52867 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52868 +
52869 + if (!len || len >= PATH_MAX)
52870 + return -EINVAL;
52871 +
52872 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52873 + return -ENOMEM;
52874 +
52875 + if (copy_from_user(tmp, g_tmp->filename, len))
52876 + return -EFAULT;
52877 + tmp[len-1] = '\0';
52878 + g_tmp->filename = tmp;
52879 +
52880 + *guser = g_tmp;
52881 + guser = &(g_tmp->next);
52882 + }
52883 +
52884 + return 0;
52885 +}
52886 +
52887 +static int
52888 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52889 + struct acl_role_label *role)
52890 +{
52891 + struct acl_object_label *o_tmp;
52892 + unsigned int len;
52893 + int ret;
52894 + char *tmp;
52895 +
52896 + while (userp) {
52897 + if ((o_tmp = (struct acl_object_label *)
52898 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52899 + return -ENOMEM;
52900 +
52901 + if (copy_from_user(o_tmp, userp,
52902 + sizeof (struct acl_object_label)))
52903 + return -EFAULT;
52904 +
52905 + userp = o_tmp->prev;
52906 +
52907 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52908 +
52909 + if (!len || len >= PATH_MAX)
52910 + return -EINVAL;
52911 +
52912 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52913 + return -ENOMEM;
52914 +
52915 + if (copy_from_user(tmp, o_tmp->filename, len))
52916 + return -EFAULT;
52917 + tmp[len-1] = '\0';
52918 + o_tmp->filename = tmp;
52919 +
52920 + insert_acl_obj_label(o_tmp, subj);
52921 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52922 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52923 + return -ENOMEM;
52924 +
52925 + ret = copy_user_glob(o_tmp);
52926 + if (ret)
52927 + return ret;
52928 +
52929 + if (o_tmp->nested) {
52930 + int already_copied;
52931 +
52932 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
52933 + if (IS_ERR(o_tmp->nested))
52934 + return PTR_ERR(o_tmp->nested);
52935 +
52936 + /* insert into nested subject list if we haven't copied this one yet
52937 + to prevent duplicate entries */
52938 + if (!already_copied) {
52939 + o_tmp->nested->next = role->hash->first;
52940 + role->hash->first = o_tmp->nested;
52941 + }
52942 + }
52943 + }
52944 +
52945 + return 0;
52946 +}
52947 +
52948 +static __u32
52949 +count_user_subjs(struct acl_subject_label *userp)
52950 +{
52951 + struct acl_subject_label s_tmp;
52952 + __u32 num = 0;
52953 +
52954 + while (userp) {
52955 + if (copy_from_user(&s_tmp, userp,
52956 + sizeof (struct acl_subject_label)))
52957 + break;
52958 +
52959 + userp = s_tmp.prev;
52960 + /* do not count nested subjects against this count, since
52961 + they are not included in the hash table, but are
52962 + attached to objects. We have already counted
52963 + the subjects in userspace for the allocation
52964 + stack
52965 + */
52966 + if (!(s_tmp.mode & GR_NESTED))
52967 + num++;
52968 + }
52969 +
52970 + return num;
52971 +}
52972 +
52973 +static int
52974 +copy_user_allowedips(struct acl_role_label *rolep)
52975 +{
52976 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52977 +
52978 + ruserip = rolep->allowed_ips;
52979 +
52980 + while (ruserip) {
52981 + rlast = rtmp;
52982 +
52983 + if ((rtmp = (struct role_allowed_ip *)
52984 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52985 + return -ENOMEM;
52986 +
52987 + if (copy_from_user(rtmp, ruserip,
52988 + sizeof (struct role_allowed_ip)))
52989 + return -EFAULT;
52990 +
52991 + ruserip = rtmp->prev;
52992 +
52993 + if (!rlast) {
52994 + rtmp->prev = NULL;
52995 + rolep->allowed_ips = rtmp;
52996 + } else {
52997 + rlast->next = rtmp;
52998 + rtmp->prev = rlast;
52999 + }
53000 +
53001 + if (!ruserip)
53002 + rtmp->next = NULL;
53003 + }
53004 +
53005 + return 0;
53006 +}
53007 +
53008 +static int
53009 +copy_user_transitions(struct acl_role_label *rolep)
53010 +{
53011 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
53012 +
53013 + unsigned int len;
53014 + char *tmp;
53015 +
53016 + rusertp = rolep->transitions;
53017 +
53018 + while (rusertp) {
53019 + rlast = rtmp;
53020 +
53021 + if ((rtmp = (struct role_transition *)
53022 + acl_alloc(sizeof (struct role_transition))) == NULL)
53023 + return -ENOMEM;
53024 +
53025 + if (copy_from_user(rtmp, rusertp,
53026 + sizeof (struct role_transition)))
53027 + return -EFAULT;
53028 +
53029 + rusertp = rtmp->prev;
53030 +
53031 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
53032 +
53033 + if (!len || len >= GR_SPROLE_LEN)
53034 + return -EINVAL;
53035 +
53036 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53037 + return -ENOMEM;
53038 +
53039 + if (copy_from_user(tmp, rtmp->rolename, len))
53040 + return -EFAULT;
53041 + tmp[len-1] = '\0';
53042 + rtmp->rolename = tmp;
53043 +
53044 + if (!rlast) {
53045 + rtmp->prev = NULL;
53046 + rolep->transitions = rtmp;
53047 + } else {
53048 + rlast->next = rtmp;
53049 + rtmp->prev = rlast;
53050 + }
53051 +
53052 + if (!rusertp)
53053 + rtmp->next = NULL;
53054 + }
53055 +
53056 + return 0;
53057 +}
53058 +
53059 +static struct acl_subject_label *
53060 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
53061 +{
53062 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53063 + unsigned int len;
53064 + char *tmp;
53065 + __u32 num_objs;
53066 + struct acl_ip_label **i_tmp, *i_utmp2;
53067 + struct gr_hash_struct ghash;
53068 + struct subject_map *subjmap;
53069 + unsigned int i_num;
53070 + int err;
53071 +
53072 + if (already_copied != NULL)
53073 + *already_copied = 0;
53074 +
53075 + s_tmp = lookup_subject_map(userp);
53076 +
53077 + /* we've already copied this subject into the kernel, just return
53078 + the reference to it, and don't copy it over again
53079 + */
53080 + if (s_tmp) {
53081 + if (already_copied != NULL)
53082 + *already_copied = 1;
53083 + return(s_tmp);
53084 + }
53085 +
53086 + if ((s_tmp = (struct acl_subject_label *)
53087 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53088 + return ERR_PTR(-ENOMEM);
53089 +
53090 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53091 + if (subjmap == NULL)
53092 + return ERR_PTR(-ENOMEM);
53093 +
53094 + subjmap->user = userp;
53095 + subjmap->kernel = s_tmp;
53096 + insert_subj_map_entry(subjmap);
53097 +
53098 + if (copy_from_user(s_tmp, userp,
53099 + sizeof (struct acl_subject_label)))
53100 + return ERR_PTR(-EFAULT);
53101 +
53102 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53103 +
53104 + if (!len || len >= PATH_MAX)
53105 + return ERR_PTR(-EINVAL);
53106 +
53107 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53108 + return ERR_PTR(-ENOMEM);
53109 +
53110 + if (copy_from_user(tmp, s_tmp->filename, len))
53111 + return ERR_PTR(-EFAULT);
53112 + tmp[len-1] = '\0';
53113 + s_tmp->filename = tmp;
53114 +
53115 + if (!strcmp(s_tmp->filename, "/"))
53116 + role->root_label = s_tmp;
53117 +
53118 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53119 + return ERR_PTR(-EFAULT);
53120 +
53121 + /* copy user and group transition tables */
53122 +
53123 + if (s_tmp->user_trans_num) {
53124 + uid_t *uidlist;
53125 +
53126 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53127 + if (uidlist == NULL)
53128 + return ERR_PTR(-ENOMEM);
53129 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53130 + return ERR_PTR(-EFAULT);
53131 +
53132 + s_tmp->user_transitions = uidlist;
53133 + }
53134 +
53135 + if (s_tmp->group_trans_num) {
53136 + gid_t *gidlist;
53137 +
53138 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53139 + if (gidlist == NULL)
53140 + return ERR_PTR(-ENOMEM);
53141 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53142 + return ERR_PTR(-EFAULT);
53143 +
53144 + s_tmp->group_transitions = gidlist;
53145 + }
53146 +
53147 + /* set up object hash table */
53148 + num_objs = count_user_objs(ghash.first);
53149 +
53150 + s_tmp->obj_hash_size = num_objs;
53151 + s_tmp->obj_hash =
53152 + (struct acl_object_label **)
53153 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53154 +
53155 + if (!s_tmp->obj_hash)
53156 + return ERR_PTR(-ENOMEM);
53157 +
53158 + memset(s_tmp->obj_hash, 0,
53159 + s_tmp->obj_hash_size *
53160 + sizeof (struct acl_object_label *));
53161 +
53162 + /* add in objects */
53163 + err = copy_user_objs(ghash.first, s_tmp, role);
53164 +
53165 + if (err)
53166 + return ERR_PTR(err);
53167 +
53168 + /* set pointer for parent subject */
53169 + if (s_tmp->parent_subject) {
53170 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
53171 +
53172 + if (IS_ERR(s_tmp2))
53173 + return s_tmp2;
53174 +
53175 + s_tmp->parent_subject = s_tmp2;
53176 + }
53177 +
53178 + /* add in ip acls */
53179 +
53180 + if (!s_tmp->ip_num) {
53181 + s_tmp->ips = NULL;
53182 + goto insert;
53183 + }
53184 +
53185 + i_tmp =
53186 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53187 + sizeof (struct acl_ip_label *));
53188 +
53189 + if (!i_tmp)
53190 + return ERR_PTR(-ENOMEM);
53191 +
53192 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53193 + *(i_tmp + i_num) =
53194 + (struct acl_ip_label *)
53195 + acl_alloc(sizeof (struct acl_ip_label));
53196 + if (!*(i_tmp + i_num))
53197 + return ERR_PTR(-ENOMEM);
53198 +
53199 + if (copy_from_user
53200 + (&i_utmp2, s_tmp->ips + i_num,
53201 + sizeof (struct acl_ip_label *)))
53202 + return ERR_PTR(-EFAULT);
53203 +
53204 + if (copy_from_user
53205 + (*(i_tmp + i_num), i_utmp2,
53206 + sizeof (struct acl_ip_label)))
53207 + return ERR_PTR(-EFAULT);
53208 +
53209 + if ((*(i_tmp + i_num))->iface == NULL)
53210 + continue;
53211 +
53212 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53213 + if (!len || len >= IFNAMSIZ)
53214 + return ERR_PTR(-EINVAL);
53215 + tmp = acl_alloc(len);
53216 + if (tmp == NULL)
53217 + return ERR_PTR(-ENOMEM);
53218 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53219 + return ERR_PTR(-EFAULT);
53220 + (*(i_tmp + i_num))->iface = tmp;
53221 + }
53222 +
53223 + s_tmp->ips = i_tmp;
53224 +
53225 +insert:
53226 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53227 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53228 + return ERR_PTR(-ENOMEM);
53229 +
53230 + return s_tmp;
53231 +}
53232 +
53233 +static int
53234 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53235 +{
53236 + struct acl_subject_label s_pre;
53237 + struct acl_subject_label * ret;
53238 + int err;
53239 +
53240 + while (userp) {
53241 + if (copy_from_user(&s_pre, userp,
53242 + sizeof (struct acl_subject_label)))
53243 + return -EFAULT;
53244 +
53245 + /* do not add nested subjects here, add
53246 + while parsing objects
53247 + */
53248 +
53249 + if (s_pre.mode & GR_NESTED) {
53250 + userp = s_pre.prev;
53251 + continue;
53252 + }
53253 +
53254 + ret = do_copy_user_subj(userp, role, NULL);
53255 +
53256 + err = PTR_ERR(ret);
53257 + if (IS_ERR(ret))
53258 + return err;
53259 +
53260 + insert_acl_subj_label(ret, role);
53261 +
53262 + userp = s_pre.prev;
53263 + }
53264 +
53265 + return 0;
53266 +}
53267 +
53268 +static int
53269 +copy_user_acl(struct gr_arg *arg)
53270 +{
53271 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53272 + struct acl_subject_label *subj_list;
53273 + struct sprole_pw *sptmp;
53274 + struct gr_hash_struct *ghash;
53275 + uid_t *domainlist;
53276 + unsigned int r_num;
53277 + unsigned int len;
53278 + char *tmp;
53279 + int err = 0;
53280 + __u16 i;
53281 + __u32 num_subjs;
53282 +
53283 + /* we need a default and kernel role */
53284 + if (arg->role_db.num_roles < 2)
53285 + return -EINVAL;
53286 +
53287 + /* copy special role authentication info from userspace */
53288 +
53289 + num_sprole_pws = arg->num_sprole_pws;
53290 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53291 +
53292 + if (!acl_special_roles && num_sprole_pws)
53293 + return -ENOMEM;
53294 +
53295 + for (i = 0; i < num_sprole_pws; i++) {
53296 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53297 + if (!sptmp)
53298 + return -ENOMEM;
53299 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53300 + sizeof (struct sprole_pw)))
53301 + return -EFAULT;
53302 +
53303 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53304 +
53305 + if (!len || len >= GR_SPROLE_LEN)
53306 + return -EINVAL;
53307 +
53308 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53309 + return -ENOMEM;
53310 +
53311 + if (copy_from_user(tmp, sptmp->rolename, len))
53312 + return -EFAULT;
53313 +
53314 + tmp[len-1] = '\0';
53315 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53316 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53317 +#endif
53318 + sptmp->rolename = tmp;
53319 + acl_special_roles[i] = sptmp;
53320 + }
53321 +
53322 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53323 +
53324 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53325 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53326 +
53327 + if (!r_tmp)
53328 + return -ENOMEM;
53329 +
53330 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53331 + sizeof (struct acl_role_label *)))
53332 + return -EFAULT;
53333 +
53334 + if (copy_from_user(r_tmp, r_utmp2,
53335 + sizeof (struct acl_role_label)))
53336 + return -EFAULT;
53337 +
53338 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53339 +
53340 + if (!len || len >= PATH_MAX)
53341 + return -EINVAL;
53342 +
53343 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53344 + return -ENOMEM;
53345 +
53346 + if (copy_from_user(tmp, r_tmp->rolename, len))
53347 + return -EFAULT;
53348 +
53349 + tmp[len-1] = '\0';
53350 + r_tmp->rolename = tmp;
53351 +
53352 + if (!strcmp(r_tmp->rolename, "default")
53353 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53354 + default_role = r_tmp;
53355 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53356 + kernel_role = r_tmp;
53357 + }
53358 +
53359 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53360 + return -ENOMEM;
53361 +
53362 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53363 + return -EFAULT;
53364 +
53365 + r_tmp->hash = ghash;
53366 +
53367 + num_subjs = count_user_subjs(r_tmp->hash->first);
53368 +
53369 + r_tmp->subj_hash_size = num_subjs;
53370 + r_tmp->subj_hash =
53371 + (struct acl_subject_label **)
53372 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53373 +
53374 + if (!r_tmp->subj_hash)
53375 + return -ENOMEM;
53376 +
53377 + err = copy_user_allowedips(r_tmp);
53378 + if (err)
53379 + return err;
53380 +
53381 + /* copy domain info */
53382 + if (r_tmp->domain_children != NULL) {
53383 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53384 + if (domainlist == NULL)
53385 + return -ENOMEM;
53386 +
53387 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53388 + return -EFAULT;
53389 +
53390 + r_tmp->domain_children = domainlist;
53391 + }
53392 +
53393 + err = copy_user_transitions(r_tmp);
53394 + if (err)
53395 + return err;
53396 +
53397 + memset(r_tmp->subj_hash, 0,
53398 + r_tmp->subj_hash_size *
53399 + sizeof (struct acl_subject_label *));
53400 +
53401 + /* acquire the list of subjects, then NULL out
53402 + the list prior to parsing the subjects for this role,
53403 + as during this parsing the list is replaced with a list
53404 + of *nested* subjects for the role
53405 + */
53406 + subj_list = r_tmp->hash->first;
53407 +
53408 + /* set nested subject list to null */
53409 + r_tmp->hash->first = NULL;
53410 +
53411 + err = copy_user_subjs(subj_list, r_tmp);
53412 +
53413 + if (err)
53414 + return err;
53415 +
53416 + insert_acl_role_label(r_tmp);
53417 + }
53418 +
53419 + if (default_role == NULL || kernel_role == NULL)
53420 + return -EINVAL;
53421 +
53422 + return err;
53423 +}
53424 +
53425 +static int
53426 +gracl_init(struct gr_arg *args)
53427 +{
53428 + int error = 0;
53429 +
53430 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53431 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53432 +
53433 + if (init_variables(args)) {
53434 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53435 + error = -ENOMEM;
53436 + free_variables();
53437 + goto out;
53438 + }
53439 +
53440 + error = copy_user_acl(args);
53441 + free_init_variables();
53442 + if (error) {
53443 + free_variables();
53444 + goto out;
53445 + }
53446 +
53447 + if ((error = gr_set_acls(0))) {
53448 + free_variables();
53449 + goto out;
53450 + }
53451 +
53452 + pax_open_kernel();
53453 + gr_status |= GR_READY;
53454 + pax_close_kernel();
53455 +
53456 + out:
53457 + return error;
53458 +}
53459 +
53460 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53461 +
53462 +static int
53463 +glob_match(const char *p, const char *n)
53464 +{
53465 + char c;
53466 +
53467 + while ((c = *p++) != '\0') {
53468 + switch (c) {
53469 + case '?':
53470 + if (*n == '\0')
53471 + return 1;
53472 + else if (*n == '/')
53473 + return 1;
53474 + break;
53475 + case '\\':
53476 + if (*n != c)
53477 + return 1;
53478 + break;
53479 + case '*':
53480 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53481 + if (*n == '/')
53482 + return 1;
53483 + else if (c == '?') {
53484 + if (*n == '\0')
53485 + return 1;
53486 + else
53487 + ++n;
53488 + }
53489 + }
53490 + if (c == '\0') {
53491 + return 0;
53492 + } else {
53493 + const char *endp;
53494 +
53495 + if ((endp = strchr(n, '/')) == NULL)
53496 + endp = n + strlen(n);
53497 +
53498 + if (c == '[') {
53499 + for (--p; n < endp; ++n)
53500 + if (!glob_match(p, n))
53501 + return 0;
53502 + } else if (c == '/') {
53503 + while (*n != '\0' && *n != '/')
53504 + ++n;
53505 + if (*n == '/' && !glob_match(p, n + 1))
53506 + return 0;
53507 + } else {
53508 + for (--p; n < endp; ++n)
53509 + if (*n == c && !glob_match(p, n))
53510 + return 0;
53511 + }
53512 +
53513 + return 1;
53514 + }
53515 + case '[':
53516 + {
53517 + int not;
53518 + char cold;
53519 +
53520 + if (*n == '\0' || *n == '/')
53521 + return 1;
53522 +
53523 + not = (*p == '!' || *p == '^');
53524 + if (not)
53525 + ++p;
53526 +
53527 + c = *p++;
53528 + for (;;) {
53529 + unsigned char fn = (unsigned char)*n;
53530 +
53531 + if (c == '\0')
53532 + return 1;
53533 + else {
53534 + if (c == fn)
53535 + goto matched;
53536 + cold = c;
53537 + c = *p++;
53538 +
53539 + if (c == '-' && *p != ']') {
53540 + unsigned char cend = *p++;
53541 +
53542 + if (cend == '\0')
53543 + return 1;
53544 +
53545 + if (cold <= fn && fn <= cend)
53546 + goto matched;
53547 +
53548 + c = *p++;
53549 + }
53550 + }
53551 +
53552 + if (c == ']')
53553 + break;
53554 + }
53555 + if (!not)
53556 + return 1;
53557 + break;
53558 + matched:
53559 + while (c != ']') {
53560 + if (c == '\0')
53561 + return 1;
53562 +
53563 + c = *p++;
53564 + }
53565 + if (not)
53566 + return 1;
53567 + }
53568 + break;
53569 + default:
53570 + if (c != *n)
53571 + return 1;
53572 + }
53573 +
53574 + ++n;
53575 + }
53576 +
53577 + if (*n == '\0')
53578 + return 0;
53579 +
53580 + if (*n == '/')
53581 + return 0;
53582 +
53583 + return 1;
53584 +}
53585 +
53586 +static struct acl_object_label *
53587 +chk_glob_label(struct acl_object_label *globbed,
53588 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53589 +{
53590 + struct acl_object_label *tmp;
53591 +
53592 + if (*path == NULL)
53593 + *path = gr_to_filename_nolock(dentry, mnt);
53594 +
53595 + tmp = globbed;
53596 +
53597 + while (tmp) {
53598 + if (!glob_match(tmp->filename, *path))
53599 + return tmp;
53600 + tmp = tmp->next;
53601 + }
53602 +
53603 + return NULL;
53604 +}
53605 +
53606 +static struct acl_object_label *
53607 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53608 + const ino_t curr_ino, const dev_t curr_dev,
53609 + const struct acl_subject_label *subj, char **path, const int checkglob)
53610 +{
53611 + struct acl_subject_label *tmpsubj;
53612 + struct acl_object_label *retval;
53613 + struct acl_object_label *retval2;
53614 +
53615 + tmpsubj = (struct acl_subject_label *) subj;
53616 + read_lock(&gr_inode_lock);
53617 + do {
53618 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53619 + if (retval) {
53620 + if (checkglob && retval->globbed) {
53621 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53622 + if (retval2)
53623 + retval = retval2;
53624 + }
53625 + break;
53626 + }
53627 + } while ((tmpsubj = tmpsubj->parent_subject));
53628 + read_unlock(&gr_inode_lock);
53629 +
53630 + return retval;
53631 +}
53632 +
53633 +static __inline__ struct acl_object_label *
53634 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53635 + struct dentry *curr_dentry,
53636 + const struct acl_subject_label *subj, char **path, const int checkglob)
53637 +{
53638 + int newglob = checkglob;
53639 + ino_t inode;
53640 + dev_t device;
53641 +
53642 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53643 + as we don't want a / * rule to match instead of the / object
53644 + don't do this for create lookups that call this function though, since they're looking up
53645 + on the parent and thus need globbing checks on all paths
53646 + */
53647 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53648 + newglob = GR_NO_GLOB;
53649 +
53650 + spin_lock(&curr_dentry->d_lock);
53651 + inode = curr_dentry->d_inode->i_ino;
53652 + device = __get_dev(curr_dentry);
53653 + spin_unlock(&curr_dentry->d_lock);
53654 +
53655 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53656 +}
53657 +
53658 +static struct acl_object_label *
53659 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53660 + const struct acl_subject_label *subj, char *path, const int checkglob)
53661 +{
53662 + struct dentry *dentry = (struct dentry *) l_dentry;
53663 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53664 + struct mount *real_mnt = real_mount(mnt);
53665 + struct acl_object_label *retval;
53666 + struct dentry *parent;
53667 +
53668 + write_seqlock(&rename_lock);
53669 + br_read_lock(&vfsmount_lock);
53670 +
53671 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53672 +#ifdef CONFIG_NET
53673 + mnt == sock_mnt ||
53674 +#endif
53675 +#ifdef CONFIG_HUGETLBFS
53676 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53677 +#endif
53678 + /* ignore Eric Biederman */
53679 + IS_PRIVATE(l_dentry->d_inode))) {
53680 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53681 + goto out;
53682 + }
53683 +
53684 + for (;;) {
53685 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53686 + break;
53687 +
53688 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53689 + if (!mnt_has_parent(real_mnt))
53690 + break;
53691 +
53692 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53693 + if (retval != NULL)
53694 + goto out;
53695 +
53696 + dentry = real_mnt->mnt_mountpoint;
53697 + real_mnt = real_mnt->mnt_parent;
53698 + mnt = &real_mnt->mnt;
53699 + continue;
53700 + }
53701 +
53702 + parent = dentry->d_parent;
53703 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53704 + if (retval != NULL)
53705 + goto out;
53706 +
53707 + dentry = parent;
53708 + }
53709 +
53710 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53711 +
53712 + /* real_root is pinned so we don't have to hold a reference */
53713 + if (retval == NULL)
53714 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53715 +out:
53716 + br_read_unlock(&vfsmount_lock);
53717 + write_sequnlock(&rename_lock);
53718 +
53719 + BUG_ON(retval == NULL);
53720 +
53721 + return retval;
53722 +}
53723 +
53724 +static __inline__ struct acl_object_label *
53725 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53726 + const struct acl_subject_label *subj)
53727 +{
53728 + char *path = NULL;
53729 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53730 +}
53731 +
53732 +static __inline__ struct acl_object_label *
53733 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53734 + const struct acl_subject_label *subj)
53735 +{
53736 + char *path = NULL;
53737 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53738 +}
53739 +
53740 +static __inline__ struct acl_object_label *
53741 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53742 + const struct acl_subject_label *subj, char *path)
53743 +{
53744 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53745 +}
53746 +
53747 +static struct acl_subject_label *
53748 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53749 + const struct acl_role_label *role)
53750 +{
53751 + struct dentry *dentry = (struct dentry *) l_dentry;
53752 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53753 + struct mount *real_mnt = real_mount(mnt);
53754 + struct acl_subject_label *retval;
53755 + struct dentry *parent;
53756 +
53757 + write_seqlock(&rename_lock);
53758 + br_read_lock(&vfsmount_lock);
53759 +
53760 + for (;;) {
53761 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53762 + break;
53763 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53764 + if (!mnt_has_parent(real_mnt))
53765 + break;
53766 +
53767 + spin_lock(&dentry->d_lock);
53768 + read_lock(&gr_inode_lock);
53769 + retval =
53770 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53771 + __get_dev(dentry), role);
53772 + read_unlock(&gr_inode_lock);
53773 + spin_unlock(&dentry->d_lock);
53774 + if (retval != NULL)
53775 + goto out;
53776 +
53777 + dentry = real_mnt->mnt_mountpoint;
53778 + real_mnt = real_mnt->mnt_parent;
53779 + mnt = &real_mnt->mnt;
53780 + continue;
53781 + }
53782 +
53783 + spin_lock(&dentry->d_lock);
53784 + read_lock(&gr_inode_lock);
53785 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53786 + __get_dev(dentry), role);
53787 + read_unlock(&gr_inode_lock);
53788 + parent = dentry->d_parent;
53789 + spin_unlock(&dentry->d_lock);
53790 +
53791 + if (retval != NULL)
53792 + goto out;
53793 +
53794 + dentry = parent;
53795 + }
53796 +
53797 + spin_lock(&dentry->d_lock);
53798 + read_lock(&gr_inode_lock);
53799 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53800 + __get_dev(dentry), role);
53801 + read_unlock(&gr_inode_lock);
53802 + spin_unlock(&dentry->d_lock);
53803 +
53804 + if (unlikely(retval == NULL)) {
53805 + /* real_root is pinned, we don't need to hold a reference */
53806 + read_lock(&gr_inode_lock);
53807 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53808 + __get_dev(real_root.dentry), role);
53809 + read_unlock(&gr_inode_lock);
53810 + }
53811 +out:
53812 + br_read_unlock(&vfsmount_lock);
53813 + write_sequnlock(&rename_lock);
53814 +
53815 + BUG_ON(retval == NULL);
53816 +
53817 + return retval;
53818 +}
53819 +
53820 +static void
53821 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53822 +{
53823 + struct task_struct *task = current;
53824 + const struct cred *cred = current_cred();
53825 +
53826 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53827 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53828 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53829 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53830 +
53831 + return;
53832 +}
53833 +
53834 +static void
53835 +gr_log_learn_id_change(const char type, const unsigned int real,
53836 + const unsigned int effective, const unsigned int fs)
53837 +{
53838 + struct task_struct *task = current;
53839 + const struct cred *cred = current_cred();
53840 +
53841 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53842 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53843 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53844 + type, real, effective, fs, &task->signal->saved_ip);
53845 +
53846 + return;
53847 +}
53848 +
53849 +__u32
53850 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53851 + const struct vfsmount * mnt)
53852 +{
53853 + __u32 retval = mode;
53854 + struct acl_subject_label *curracl;
53855 + struct acl_object_label *currobj;
53856 +
53857 + if (unlikely(!(gr_status & GR_READY)))
53858 + return (mode & ~GR_AUDITS);
53859 +
53860 + curracl = current->acl;
53861 +
53862 + currobj = chk_obj_label(dentry, mnt, curracl);
53863 + retval = currobj->mode & mode;
53864 +
53865 + /* if we're opening a specified transfer file for writing
53866 + (e.g. /dev/initctl), then transfer our role to init
53867 + */
53868 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53869 + current->role->roletype & GR_ROLE_PERSIST)) {
53870 + struct task_struct *task = init_pid_ns.child_reaper;
53871 +
53872 + if (task->role != current->role) {
53873 + task->acl_sp_role = 0;
53874 + task->acl_role_id = current->acl_role_id;
53875 + task->role = current->role;
53876 + rcu_read_lock();
53877 + read_lock(&grsec_exec_file_lock);
53878 + gr_apply_subject_to_task(task);
53879 + read_unlock(&grsec_exec_file_lock);
53880 + rcu_read_unlock();
53881 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53882 + }
53883 + }
53884 +
53885 + if (unlikely
53886 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53887 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53888 + __u32 new_mode = mode;
53889 +
53890 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53891 +
53892 + retval = new_mode;
53893 +
53894 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53895 + new_mode |= GR_INHERIT;
53896 +
53897 + if (!(mode & GR_NOLEARN))
53898 + gr_log_learn(dentry, mnt, new_mode);
53899 + }
53900 +
53901 + return retval;
53902 +}
53903 +
53904 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53905 + const struct dentry *parent,
53906 + const struct vfsmount *mnt)
53907 +{
53908 + struct name_entry *match;
53909 + struct acl_object_label *matchpo;
53910 + struct acl_subject_label *curracl;
53911 + char *path;
53912 +
53913 + if (unlikely(!(gr_status & GR_READY)))
53914 + return NULL;
53915 +
53916 + preempt_disable();
53917 + path = gr_to_filename_rbac(new_dentry, mnt);
53918 + match = lookup_name_entry_create(path);
53919 +
53920 + curracl = current->acl;
53921 +
53922 + if (match) {
53923 + read_lock(&gr_inode_lock);
53924 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53925 + read_unlock(&gr_inode_lock);
53926 +
53927 + if (matchpo) {
53928 + preempt_enable();
53929 + return matchpo;
53930 + }
53931 + }
53932 +
53933 + // lookup parent
53934 +
53935 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53936 +
53937 + preempt_enable();
53938 + return matchpo;
53939 +}
53940 +
53941 +__u32
53942 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53943 + const struct vfsmount * mnt, const __u32 mode)
53944 +{
53945 + struct acl_object_label *matchpo;
53946 + __u32 retval;
53947 +
53948 + if (unlikely(!(gr_status & GR_READY)))
53949 + return (mode & ~GR_AUDITS);
53950 +
53951 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53952 +
53953 + retval = matchpo->mode & mode;
53954 +
53955 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53956 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53957 + __u32 new_mode = mode;
53958 +
53959 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53960 +
53961 + gr_log_learn(new_dentry, mnt, new_mode);
53962 + return new_mode;
53963 + }
53964 +
53965 + return retval;
53966 +}
53967 +
53968 +__u32
53969 +gr_check_link(const struct dentry * new_dentry,
53970 + const struct dentry * parent_dentry,
53971 + const struct vfsmount * parent_mnt,
53972 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53973 +{
53974 + struct acl_object_label *obj;
53975 + __u32 oldmode, newmode;
53976 + __u32 needmode;
53977 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53978 + GR_DELETE | GR_INHERIT;
53979 +
53980 + if (unlikely(!(gr_status & GR_READY)))
53981 + return (GR_CREATE | GR_LINK);
53982 +
53983 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53984 + oldmode = obj->mode;
53985 +
53986 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53987 + newmode = obj->mode;
53988 +
53989 + needmode = newmode & checkmodes;
53990 +
53991 + // old name for hardlink must have at least the permissions of the new name
53992 + if ((oldmode & needmode) != needmode)
53993 + goto bad;
53994 +
53995 + // if old name had restrictions/auditing, make sure the new name does as well
53996 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53997 +
53998 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53999 + if (is_privileged_binary(old_dentry))
54000 + needmode |= GR_SETID;
54001 +
54002 + if ((newmode & needmode) != needmode)
54003 + goto bad;
54004 +
54005 + // enforce minimum permissions
54006 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
54007 + return newmode;
54008 +bad:
54009 + needmode = oldmode;
54010 + if (is_privileged_binary(old_dentry))
54011 + needmode |= GR_SETID;
54012 +
54013 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
54014 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
54015 + return (GR_CREATE | GR_LINK);
54016 + } else if (newmode & GR_SUPPRESS)
54017 + return GR_SUPPRESS;
54018 + else
54019 + return 0;
54020 +}
54021 +
54022 +int
54023 +gr_check_hidden_task(const struct task_struct *task)
54024 +{
54025 + if (unlikely(!(gr_status & GR_READY)))
54026 + return 0;
54027 +
54028 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
54029 + return 1;
54030 +
54031 + return 0;
54032 +}
54033 +
54034 +int
54035 +gr_check_protected_task(const struct task_struct *task)
54036 +{
54037 + if (unlikely(!(gr_status & GR_READY) || !task))
54038 + return 0;
54039 +
54040 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54041 + task->acl != current->acl)
54042 + return 1;
54043 +
54044 + return 0;
54045 +}
54046 +
54047 +int
54048 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54049 +{
54050 + struct task_struct *p;
54051 + int ret = 0;
54052 +
54053 + if (unlikely(!(gr_status & GR_READY) || !pid))
54054 + return ret;
54055 +
54056 + read_lock(&tasklist_lock);
54057 + do_each_pid_task(pid, type, p) {
54058 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54059 + p->acl != current->acl) {
54060 + ret = 1;
54061 + goto out;
54062 + }
54063 + } while_each_pid_task(pid, type, p);
54064 +out:
54065 + read_unlock(&tasklist_lock);
54066 +
54067 + return ret;
54068 +}
54069 +
54070 +void
54071 +gr_copy_label(struct task_struct *tsk)
54072 +{
54073 + tsk->signal->used_accept = 0;
54074 + tsk->acl_sp_role = 0;
54075 + tsk->acl_role_id = current->acl_role_id;
54076 + tsk->acl = current->acl;
54077 + tsk->role = current->role;
54078 + tsk->signal->curr_ip = current->signal->curr_ip;
54079 + tsk->signal->saved_ip = current->signal->saved_ip;
54080 + if (current->exec_file)
54081 + get_file(current->exec_file);
54082 + tsk->exec_file = current->exec_file;
54083 + tsk->is_writable = current->is_writable;
54084 + if (unlikely(current->signal->used_accept)) {
54085 + current->signal->curr_ip = 0;
54086 + current->signal->saved_ip = 0;
54087 + }
54088 +
54089 + return;
54090 +}
54091 +
54092 +static void
54093 +gr_set_proc_res(struct task_struct *task)
54094 +{
54095 + struct acl_subject_label *proc;
54096 + unsigned short i;
54097 +
54098 + proc = task->acl;
54099 +
54100 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54101 + return;
54102 +
54103 + for (i = 0; i < RLIM_NLIMITS; i++) {
54104 + if (!(proc->resmask & (1 << i)))
54105 + continue;
54106 +
54107 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54108 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54109 + }
54110 +
54111 + return;
54112 +}
54113 +
54114 +extern int __gr_process_user_ban(struct user_struct *user);
54115 +
54116 +int
54117 +gr_check_user_change(int real, int effective, int fs)
54118 +{
54119 + unsigned int i;
54120 + __u16 num;
54121 + uid_t *uidlist;
54122 + int curuid;
54123 + int realok = 0;
54124 + int effectiveok = 0;
54125 + int fsok = 0;
54126 +
54127 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54128 + struct user_struct *user;
54129 +
54130 + if (real == -1)
54131 + goto skipit;
54132 +
54133 + user = find_user(real);
54134 + if (user == NULL)
54135 + goto skipit;
54136 +
54137 + if (__gr_process_user_ban(user)) {
54138 + /* for find_user */
54139 + free_uid(user);
54140 + return 1;
54141 + }
54142 +
54143 + /* for find_user */
54144 + free_uid(user);
54145 +
54146 +skipit:
54147 +#endif
54148 +
54149 + if (unlikely(!(gr_status & GR_READY)))
54150 + return 0;
54151 +
54152 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54153 + gr_log_learn_id_change('u', real, effective, fs);
54154 +
54155 + num = current->acl->user_trans_num;
54156 + uidlist = current->acl->user_transitions;
54157 +
54158 + if (uidlist == NULL)
54159 + return 0;
54160 +
54161 + if (real == -1)
54162 + realok = 1;
54163 + if (effective == -1)
54164 + effectiveok = 1;
54165 + if (fs == -1)
54166 + fsok = 1;
54167 +
54168 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54169 + for (i = 0; i < num; i++) {
54170 + curuid = (int)uidlist[i];
54171 + if (real == curuid)
54172 + realok = 1;
54173 + if (effective == curuid)
54174 + effectiveok = 1;
54175 + if (fs == curuid)
54176 + fsok = 1;
54177 + }
54178 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54179 + for (i = 0; i < num; i++) {
54180 + curuid = (int)uidlist[i];
54181 + if (real == curuid)
54182 + break;
54183 + if (effective == curuid)
54184 + break;
54185 + if (fs == curuid)
54186 + break;
54187 + }
54188 + /* not in deny list */
54189 + if (i == num) {
54190 + realok = 1;
54191 + effectiveok = 1;
54192 + fsok = 1;
54193 + }
54194 + }
54195 +
54196 + if (realok && effectiveok && fsok)
54197 + return 0;
54198 + else {
54199 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54200 + return 1;
54201 + }
54202 +}
54203 +
54204 +int
54205 +gr_check_group_change(int real, int effective, int fs)
54206 +{
54207 + unsigned int i;
54208 + __u16 num;
54209 + gid_t *gidlist;
54210 + int curgid;
54211 + int realok = 0;
54212 + int effectiveok = 0;
54213 + int fsok = 0;
54214 +
54215 + if (unlikely(!(gr_status & GR_READY)))
54216 + return 0;
54217 +
54218 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54219 + gr_log_learn_id_change('g', real, effective, fs);
54220 +
54221 + num = current->acl->group_trans_num;
54222 + gidlist = current->acl->group_transitions;
54223 +
54224 + if (gidlist == NULL)
54225 + return 0;
54226 +
54227 + if (real == -1)
54228 + realok = 1;
54229 + if (effective == -1)
54230 + effectiveok = 1;
54231 + if (fs == -1)
54232 + fsok = 1;
54233 +
54234 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54235 + for (i = 0; i < num; i++) {
54236 + curgid = (int)gidlist[i];
54237 + if (real == curgid)
54238 + realok = 1;
54239 + if (effective == curgid)
54240 + effectiveok = 1;
54241 + if (fs == curgid)
54242 + fsok = 1;
54243 + }
54244 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54245 + for (i = 0; i < num; i++) {
54246 + curgid = (int)gidlist[i];
54247 + if (real == curgid)
54248 + break;
54249 + if (effective == curgid)
54250 + break;
54251 + if (fs == curgid)
54252 + break;
54253 + }
54254 + /* not in deny list */
54255 + if (i == num) {
54256 + realok = 1;
54257 + effectiveok = 1;
54258 + fsok = 1;
54259 + }
54260 + }
54261 +
54262 + if (realok && effectiveok && fsok)
54263 + return 0;
54264 + else {
54265 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54266 + return 1;
54267 + }
54268 +}
54269 +
54270 +extern int gr_acl_is_capable(const int cap);
54271 +
54272 +void
54273 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54274 +{
54275 + struct acl_role_label *role = task->role;
54276 + struct acl_subject_label *subj = NULL;
54277 + struct acl_object_label *obj;
54278 + struct file *filp;
54279 +
54280 + if (unlikely(!(gr_status & GR_READY)))
54281 + return;
54282 +
54283 + filp = task->exec_file;
54284 +
54285 + /* kernel process, we'll give them the kernel role */
54286 + if (unlikely(!filp)) {
54287 + task->role = kernel_role;
54288 + task->acl = kernel_role->root_label;
54289 + return;
54290 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54291 + role = lookup_acl_role_label(task, uid, gid);
54292 +
54293 + /* don't change the role if we're not a privileged process */
54294 + if (role && task->role != role &&
54295 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54296 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54297 + return;
54298 +
54299 + /* perform subject lookup in possibly new role
54300 + we can use this result below in the case where role == task->role
54301 + */
54302 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54303 +
54304 + /* if we changed uid/gid, but result in the same role
54305 + and are using inheritance, don't lose the inherited subject
54306 + if current subject is other than what normal lookup
54307 + would result in, we arrived via inheritance, don't
54308 + lose subject
54309 + */
54310 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54311 + (subj == task->acl)))
54312 + task->acl = subj;
54313 +
54314 + task->role = role;
54315 +
54316 + task->is_writable = 0;
54317 +
54318 + /* ignore additional mmap checks for processes that are writable
54319 + by the default ACL */
54320 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54321 + if (unlikely(obj->mode & GR_WRITE))
54322 + task->is_writable = 1;
54323 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54324 + if (unlikely(obj->mode & GR_WRITE))
54325 + task->is_writable = 1;
54326 +
54327 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54328 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54329 +#endif
54330 +
54331 + gr_set_proc_res(task);
54332 +
54333 + return;
54334 +}
54335 +
54336 +int
54337 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54338 + const int unsafe_flags)
54339 +{
54340 + struct task_struct *task = current;
54341 + struct acl_subject_label *newacl;
54342 + struct acl_object_label *obj;
54343 + __u32 retmode;
54344 +
54345 + if (unlikely(!(gr_status & GR_READY)))
54346 + return 0;
54347 +
54348 + newacl = chk_subj_label(dentry, mnt, task->role);
54349 +
54350 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54351 + did an exec
54352 + */
54353 + rcu_read_lock();
54354 + read_lock(&tasklist_lock);
54355 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54356 + (task->parent->acl->mode & GR_POVERRIDE))) {
54357 + read_unlock(&tasklist_lock);
54358 + rcu_read_unlock();
54359 + goto skip_check;
54360 + }
54361 + read_unlock(&tasklist_lock);
54362 + rcu_read_unlock();
54363 +
54364 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54365 + !(task->role->roletype & GR_ROLE_GOD) &&
54366 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54367 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54368 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54369 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54370 + else
54371 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54372 + return -EACCES;
54373 + }
54374 +
54375 +skip_check:
54376 +
54377 + obj = chk_obj_label(dentry, mnt, task->acl);
54378 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54379 +
54380 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54381 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54382 + if (obj->nested)
54383 + task->acl = obj->nested;
54384 + else
54385 + task->acl = newacl;
54386 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54387 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54388 +
54389 + task->is_writable = 0;
54390 +
54391 + /* ignore additional mmap checks for processes that are writable
54392 + by the default ACL */
54393 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54394 + if (unlikely(obj->mode & GR_WRITE))
54395 + task->is_writable = 1;
54396 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54397 + if (unlikely(obj->mode & GR_WRITE))
54398 + task->is_writable = 1;
54399 +
54400 + gr_set_proc_res(task);
54401 +
54402 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54403 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54404 +#endif
54405 + return 0;
54406 +}
54407 +
54408 +/* always called with valid inodev ptr */
54409 +static void
54410 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54411 +{
54412 + struct acl_object_label *matchpo;
54413 + struct acl_subject_label *matchps;
54414 + struct acl_subject_label *subj;
54415 + struct acl_role_label *role;
54416 + unsigned int x;
54417 +
54418 + FOR_EACH_ROLE_START(role)
54419 + FOR_EACH_SUBJECT_START(role, subj, x)
54420 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54421 + matchpo->mode |= GR_DELETED;
54422 + FOR_EACH_SUBJECT_END(subj,x)
54423 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54424 + /* nested subjects aren't in the role's subj_hash table */
54425 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54426 + matchpo->mode |= GR_DELETED;
54427 + FOR_EACH_NESTED_SUBJECT_END(subj)
54428 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54429 + matchps->mode |= GR_DELETED;
54430 + FOR_EACH_ROLE_END(role)
54431 +
54432 + inodev->nentry->deleted = 1;
54433 +
54434 + return;
54435 +}
54436 +
54437 +void
54438 +gr_handle_delete(const ino_t ino, const dev_t dev)
54439 +{
54440 + struct inodev_entry *inodev;
54441 +
54442 + if (unlikely(!(gr_status & GR_READY)))
54443 + return;
54444 +
54445 + write_lock(&gr_inode_lock);
54446 + inodev = lookup_inodev_entry(ino, dev);
54447 + if (inodev != NULL)
54448 + do_handle_delete(inodev, ino, dev);
54449 + write_unlock(&gr_inode_lock);
54450 +
54451 + return;
54452 +}
54453 +
54454 +static void
54455 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54456 + const ino_t newinode, const dev_t newdevice,
54457 + struct acl_subject_label *subj)
54458 +{
54459 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
54460 + struct acl_object_label *match;
54461 +
54462 + match = subj->obj_hash[index];
54463 +
54464 + while (match && (match->inode != oldinode ||
54465 + match->device != olddevice ||
54466 + !(match->mode & GR_DELETED)))
54467 + match = match->next;
54468 +
54469 + if (match && (match->inode == oldinode)
54470 + && (match->device == olddevice)
54471 + && (match->mode & GR_DELETED)) {
54472 + if (match->prev == NULL) {
54473 + subj->obj_hash[index] = match->next;
54474 + if (match->next != NULL)
54475 + match->next->prev = NULL;
54476 + } else {
54477 + match->prev->next = match->next;
54478 + if (match->next != NULL)
54479 + match->next->prev = match->prev;
54480 + }
54481 + match->prev = NULL;
54482 + match->next = NULL;
54483 + match->inode = newinode;
54484 + match->device = newdevice;
54485 + match->mode &= ~GR_DELETED;
54486 +
54487 + insert_acl_obj_label(match, subj);
54488 + }
54489 +
54490 + return;
54491 +}
54492 +
54493 +static void
54494 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54495 + const ino_t newinode, const dev_t newdevice,
54496 + struct acl_role_label *role)
54497 +{
54498 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
54499 + struct acl_subject_label *match;
54500 +
54501 + match = role->subj_hash[index];
54502 +
54503 + while (match && (match->inode != oldinode ||
54504 + match->device != olddevice ||
54505 + !(match->mode & GR_DELETED)))
54506 + match = match->next;
54507 +
54508 + if (match && (match->inode == oldinode)
54509 + && (match->device == olddevice)
54510 + && (match->mode & GR_DELETED)) {
54511 + if (match->prev == NULL) {
54512 + role->subj_hash[index] = match->next;
54513 + if (match->next != NULL)
54514 + match->next->prev = NULL;
54515 + } else {
54516 + match->prev->next = match->next;
54517 + if (match->next != NULL)
54518 + match->next->prev = match->prev;
54519 + }
54520 + match->prev = NULL;
54521 + match->next = NULL;
54522 + match->inode = newinode;
54523 + match->device = newdevice;
54524 + match->mode &= ~GR_DELETED;
54525 +
54526 + insert_acl_subj_label(match, role);
54527 + }
54528 +
54529 + return;
54530 +}
54531 +
54532 +static void
54533 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54534 + const ino_t newinode, const dev_t newdevice)
54535 +{
54536 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
54537 + struct inodev_entry *match;
54538 +
54539 + match = inodev_set.i_hash[index];
54540 +
54541 + while (match && (match->nentry->inode != oldinode ||
54542 + match->nentry->device != olddevice || !match->nentry->deleted))
54543 + match = match->next;
54544 +
54545 + if (match && (match->nentry->inode == oldinode)
54546 + && (match->nentry->device == olddevice) &&
54547 + match->nentry->deleted) {
54548 + if (match->prev == NULL) {
54549 + inodev_set.i_hash[index] = match->next;
54550 + if (match->next != NULL)
54551 + match->next->prev = NULL;
54552 + } else {
54553 + match->prev->next = match->next;
54554 + if (match->next != NULL)
54555 + match->next->prev = match->prev;
54556 + }
54557 + match->prev = NULL;
54558 + match->next = NULL;
54559 + match->nentry->inode = newinode;
54560 + match->nentry->device = newdevice;
54561 + match->nentry->deleted = 0;
54562 +
54563 + insert_inodev_entry(match);
54564 + }
54565 +
54566 + return;
54567 +}
54568 +
54569 +static void
54570 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54571 +{
54572 + struct acl_subject_label *subj;
54573 + struct acl_role_label *role;
54574 + unsigned int x;
54575 +
54576 + FOR_EACH_ROLE_START(role)
54577 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54578 +
54579 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54580 + if ((subj->inode == ino) && (subj->device == dev)) {
54581 + subj->inode = ino;
54582 + subj->device = dev;
54583 + }
54584 + /* nested subjects aren't in the role's subj_hash table */
54585 + update_acl_obj_label(matchn->inode, matchn->device,
54586 + ino, dev, subj);
54587 + FOR_EACH_NESTED_SUBJECT_END(subj)
54588 + FOR_EACH_SUBJECT_START(role, subj, x)
54589 + update_acl_obj_label(matchn->inode, matchn->device,
54590 + ino, dev, subj);
54591 + FOR_EACH_SUBJECT_END(subj,x)
54592 + FOR_EACH_ROLE_END(role)
54593 +
54594 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54595 +
54596 + return;
54597 +}
54598 +
54599 +static void
54600 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54601 + const struct vfsmount *mnt)
54602 +{
54603 + ino_t ino = dentry->d_inode->i_ino;
54604 + dev_t dev = __get_dev(dentry);
54605 +
54606 + __do_handle_create(matchn, ino, dev);
54607 +
54608 + return;
54609 +}
54610 +
54611 +void
54612 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54613 +{
54614 + struct name_entry *matchn;
54615 +
54616 + if (unlikely(!(gr_status & GR_READY)))
54617 + return;
54618 +
54619 + preempt_disable();
54620 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54621 +
54622 + if (unlikely((unsigned long)matchn)) {
54623 + write_lock(&gr_inode_lock);
54624 + do_handle_create(matchn, dentry, mnt);
54625 + write_unlock(&gr_inode_lock);
54626 + }
54627 + preempt_enable();
54628 +
54629 + return;
54630 +}
54631 +
54632 +void
54633 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54634 +{
54635 + struct name_entry *matchn;
54636 +
54637 + if (unlikely(!(gr_status & GR_READY)))
54638 + return;
54639 +
54640 + preempt_disable();
54641 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54642 +
54643 + if (unlikely((unsigned long)matchn)) {
54644 + write_lock(&gr_inode_lock);
54645 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54646 + write_unlock(&gr_inode_lock);
54647 + }
54648 + preempt_enable();
54649 +
54650 + return;
54651 +}
54652 +
54653 +void
54654 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54655 + struct dentry *old_dentry,
54656 + struct dentry *new_dentry,
54657 + struct vfsmount *mnt, const __u8 replace)
54658 +{
54659 + struct name_entry *matchn;
54660 + struct inodev_entry *inodev;
54661 + struct inode *inode = new_dentry->d_inode;
54662 + ino_t old_ino = old_dentry->d_inode->i_ino;
54663 + dev_t old_dev = __get_dev(old_dentry);
54664 +
54665 + /* vfs_rename swaps the name and parent link for old_dentry and
54666 + new_dentry
54667 + at this point, old_dentry has the new name, parent link, and inode
54668 + for the renamed file
54669 + if a file is being replaced by a rename, new_dentry has the inode
54670 + and name for the replaced file
54671 + */
54672 +
54673 + if (unlikely(!(gr_status & GR_READY)))
54674 + return;
54675 +
54676 + preempt_disable();
54677 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54678 +
54679 + /* we wouldn't have to check d_inode if it weren't for
54680 + NFS silly-renaming
54681 + */
54682 +
54683 + write_lock(&gr_inode_lock);
54684 + if (unlikely(replace && inode)) {
54685 + ino_t new_ino = inode->i_ino;
54686 + dev_t new_dev = __get_dev(new_dentry);
54687 +
54688 + inodev = lookup_inodev_entry(new_ino, new_dev);
54689 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54690 + do_handle_delete(inodev, new_ino, new_dev);
54691 + }
54692 +
54693 + inodev = lookup_inodev_entry(old_ino, old_dev);
54694 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54695 + do_handle_delete(inodev, old_ino, old_dev);
54696 +
54697 + if (unlikely((unsigned long)matchn))
54698 + do_handle_create(matchn, old_dentry, mnt);
54699 +
54700 + write_unlock(&gr_inode_lock);
54701 + preempt_enable();
54702 +
54703 + return;
54704 +}
54705 +
54706 +static int
54707 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54708 + unsigned char **sum)
54709 +{
54710 + struct acl_role_label *r;
54711 + struct role_allowed_ip *ipp;
54712 + struct role_transition *trans;
54713 + unsigned int i;
54714 + int found = 0;
54715 + u32 curr_ip = current->signal->curr_ip;
54716 +
54717 + current->signal->saved_ip = curr_ip;
54718 +
54719 + /* check transition table */
54720 +
54721 + for (trans = current->role->transitions; trans; trans = trans->next) {
54722 + if (!strcmp(rolename, trans->rolename)) {
54723 + found = 1;
54724 + break;
54725 + }
54726 + }
54727 +
54728 + if (!found)
54729 + return 0;
54730 +
54731 + /* handle special roles that do not require authentication
54732 + and check ip */
54733 +
54734 + FOR_EACH_ROLE_START(r)
54735 + if (!strcmp(rolename, r->rolename) &&
54736 + (r->roletype & GR_ROLE_SPECIAL)) {
54737 + found = 0;
54738 + if (r->allowed_ips != NULL) {
54739 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54740 + if ((ntohl(curr_ip) & ipp->netmask) ==
54741 + (ntohl(ipp->addr) & ipp->netmask))
54742 + found = 1;
54743 + }
54744 + } else
54745 + found = 2;
54746 + if (!found)
54747 + return 0;
54748 +
54749 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54750 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54751 + *salt = NULL;
54752 + *sum = NULL;
54753 + return 1;
54754 + }
54755 + }
54756 + FOR_EACH_ROLE_END(r)
54757 +
54758 + for (i = 0; i < num_sprole_pws; i++) {
54759 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54760 + *salt = acl_special_roles[i]->salt;
54761 + *sum = acl_special_roles[i]->sum;
54762 + return 1;
54763 + }
54764 + }
54765 +
54766 + return 0;
54767 +}
54768 +
54769 +static void
54770 +assign_special_role(char *rolename)
54771 +{
54772 + struct acl_object_label *obj;
54773 + struct acl_role_label *r;
54774 + struct acl_role_label *assigned = NULL;
54775 + struct task_struct *tsk;
54776 + struct file *filp;
54777 +
54778 + FOR_EACH_ROLE_START(r)
54779 + if (!strcmp(rolename, r->rolename) &&
54780 + (r->roletype & GR_ROLE_SPECIAL)) {
54781 + assigned = r;
54782 + break;
54783 + }
54784 + FOR_EACH_ROLE_END(r)
54785 +
54786 + if (!assigned)
54787 + return;
54788 +
54789 + read_lock(&tasklist_lock);
54790 + read_lock(&grsec_exec_file_lock);
54791 +
54792 + tsk = current->real_parent;
54793 + if (tsk == NULL)
54794 + goto out_unlock;
54795 +
54796 + filp = tsk->exec_file;
54797 + if (filp == NULL)
54798 + goto out_unlock;
54799 +
54800 + tsk->is_writable = 0;
54801 +
54802 + tsk->acl_sp_role = 1;
54803 + tsk->acl_role_id = ++acl_sp_role_value;
54804 + tsk->role = assigned;
54805 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54806 +
54807 + /* ignore additional mmap checks for processes that are writable
54808 + by the default ACL */
54809 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54810 + if (unlikely(obj->mode & GR_WRITE))
54811 + tsk->is_writable = 1;
54812 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54813 + if (unlikely(obj->mode & GR_WRITE))
54814 + tsk->is_writable = 1;
54815 +
54816 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54817 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54818 +#endif
54819 +
54820 +out_unlock:
54821 + read_unlock(&grsec_exec_file_lock);
54822 + read_unlock(&tasklist_lock);
54823 + return;
54824 +}
54825 +
54826 +int gr_check_secure_terminal(struct task_struct *task)
54827 +{
54828 + struct task_struct *p, *p2, *p3;
54829 + struct files_struct *files;
54830 + struct fdtable *fdt;
54831 + struct file *our_file = NULL, *file;
54832 + int i;
54833 +
54834 + if (task->signal->tty == NULL)
54835 + return 1;
54836 +
54837 + files = get_files_struct(task);
54838 + if (files != NULL) {
54839 + rcu_read_lock();
54840 + fdt = files_fdtable(files);
54841 + for (i=0; i < fdt->max_fds; i++) {
54842 + file = fcheck_files(files, i);
54843 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54844 + get_file(file);
54845 + our_file = file;
54846 + }
54847 + }
54848 + rcu_read_unlock();
54849 + put_files_struct(files);
54850 + }
54851 +
54852 + if (our_file == NULL)
54853 + return 1;
54854 +
54855 + read_lock(&tasklist_lock);
54856 + do_each_thread(p2, p) {
54857 + files = get_files_struct(p);
54858 + if (files == NULL ||
54859 + (p->signal && p->signal->tty == task->signal->tty)) {
54860 + if (files != NULL)
54861 + put_files_struct(files);
54862 + continue;
54863 + }
54864 + rcu_read_lock();
54865 + fdt = files_fdtable(files);
54866 + for (i=0; i < fdt->max_fds; i++) {
54867 + file = fcheck_files(files, i);
54868 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54869 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54870 + p3 = task;
54871 + while (p3->pid > 0) {
54872 + if (p3 == p)
54873 + break;
54874 + p3 = p3->real_parent;
54875 + }
54876 + if (p3 == p)
54877 + break;
54878 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54879 + gr_handle_alertkill(p);
54880 + rcu_read_unlock();
54881 + put_files_struct(files);
54882 + read_unlock(&tasklist_lock);
54883 + fput(our_file);
54884 + return 0;
54885 + }
54886 + }
54887 + rcu_read_unlock();
54888 + put_files_struct(files);
54889 + } while_each_thread(p2, p);
54890 + read_unlock(&tasklist_lock);
54891 +
54892 + fput(our_file);
54893 + return 1;
54894 +}
54895 +
54896 +static int gr_rbac_disable(void *unused)
54897 +{
54898 + pax_open_kernel();
54899 + gr_status &= ~GR_READY;
54900 + pax_close_kernel();
54901 +
54902 + return 0;
54903 +}
54904 +
54905 +ssize_t
54906 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54907 +{
54908 + struct gr_arg_wrapper uwrap;
54909 + unsigned char *sprole_salt = NULL;
54910 + unsigned char *sprole_sum = NULL;
54911 + int error = sizeof (struct gr_arg_wrapper);
54912 + int error2 = 0;
54913 +
54914 + mutex_lock(&gr_dev_mutex);
54915 +
54916 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54917 + error = -EPERM;
54918 + goto out;
54919 + }
54920 +
54921 + if (count != sizeof (struct gr_arg_wrapper)) {
54922 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54923 + error = -EINVAL;
54924 + goto out;
54925 + }
54926 +
54927 +
54928 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54929 + gr_auth_expires = 0;
54930 + gr_auth_attempts = 0;
54931 + }
54932 +
54933 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54934 + error = -EFAULT;
54935 + goto out;
54936 + }
54937 +
54938 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54939 + error = -EINVAL;
54940 + goto out;
54941 + }
54942 +
54943 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54944 + error = -EFAULT;
54945 + goto out;
54946 + }
54947 +
54948 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54949 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54950 + time_after(gr_auth_expires, get_seconds())) {
54951 + error = -EBUSY;
54952 + goto out;
54953 + }
54954 +
54955 + /* if non-root trying to do anything other than use a special role,
54956 + do not attempt authentication, do not count towards authentication
54957 + locking
54958 + */
54959 +
54960 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54961 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54962 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54963 + error = -EPERM;
54964 + goto out;
54965 + }
54966 +
54967 + /* ensure pw and special role name are null terminated */
54968 +
54969 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54970 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54971 +
54972 + /* Okay.
54973 + * We have our enough of the argument structure..(we have yet
54974 + * to copy_from_user the tables themselves) . Copy the tables
54975 + * only if we need them, i.e. for loading operations. */
54976 +
54977 + switch (gr_usermode->mode) {
54978 + case GR_STATUS:
54979 + if (gr_status & GR_READY) {
54980 + error = 1;
54981 + if (!gr_check_secure_terminal(current))
54982 + error = 3;
54983 + } else
54984 + error = 2;
54985 + goto out;
54986 + case GR_SHUTDOWN:
54987 + if ((gr_status & GR_READY)
54988 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54989 + stop_machine(gr_rbac_disable, NULL, NULL);
54990 + free_variables();
54991 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54992 + memset(gr_system_salt, 0, GR_SALT_LEN);
54993 + memset(gr_system_sum, 0, GR_SHA_LEN);
54994 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54995 + } else if (gr_status & GR_READY) {
54996 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54997 + error = -EPERM;
54998 + } else {
54999 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
55000 + error = -EAGAIN;
55001 + }
55002 + break;
55003 + case GR_ENABLE:
55004 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
55005 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
55006 + else {
55007 + if (gr_status & GR_READY)
55008 + error = -EAGAIN;
55009 + else
55010 + error = error2;
55011 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
55012 + }
55013 + break;
55014 + case GR_RELOAD:
55015 + if (!(gr_status & GR_READY)) {
55016 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
55017 + error = -EAGAIN;
55018 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55019 + stop_machine(gr_rbac_disable, NULL, NULL);
55020 + free_variables();
55021 + error2 = gracl_init(gr_usermode);
55022 + if (!error2)
55023 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
55024 + else {
55025 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55026 + error = error2;
55027 + }
55028 + } else {
55029 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
55030 + error = -EPERM;
55031 + }
55032 + break;
55033 + case GR_SEGVMOD:
55034 + if (unlikely(!(gr_status & GR_READY))) {
55035 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
55036 + error = -EAGAIN;
55037 + break;
55038 + }
55039 +
55040 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
55041 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
55042 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55043 + struct acl_subject_label *segvacl;
55044 + segvacl =
55045 + lookup_acl_subj_label(gr_usermode->segv_inode,
55046 + gr_usermode->segv_device,
55047 + current->role);
55048 + if (segvacl) {
55049 + segvacl->crashes = 0;
55050 + segvacl->expires = 0;
55051 + }
55052 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55053 + gr_remove_uid(gr_usermode->segv_uid);
55054 + }
55055 + } else {
55056 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55057 + error = -EPERM;
55058 + }
55059 + break;
55060 + case GR_SPROLE:
55061 + case GR_SPROLEPAM:
55062 + if (unlikely(!(gr_status & GR_READY))) {
55063 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55064 + error = -EAGAIN;
55065 + break;
55066 + }
55067 +
55068 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55069 + current->role->expires = 0;
55070 + current->role->auth_attempts = 0;
55071 + }
55072 +
55073 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55074 + time_after(current->role->expires, get_seconds())) {
55075 + error = -EBUSY;
55076 + goto out;
55077 + }
55078 +
55079 + if (lookup_special_role_auth
55080 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55081 + && ((!sprole_salt && !sprole_sum)
55082 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55083 + char *p = "";
55084 + assign_special_role(gr_usermode->sp_role);
55085 + read_lock(&tasklist_lock);
55086 + if (current->real_parent)
55087 + p = current->real_parent->role->rolename;
55088 + read_unlock(&tasklist_lock);
55089 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55090 + p, acl_sp_role_value);
55091 + } else {
55092 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55093 + error = -EPERM;
55094 + if(!(current->role->auth_attempts++))
55095 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55096 +
55097 + goto out;
55098 + }
55099 + break;
55100 + case GR_UNSPROLE:
55101 + if (unlikely(!(gr_status & GR_READY))) {
55102 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55103 + error = -EAGAIN;
55104 + break;
55105 + }
55106 +
55107 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55108 + char *p = "";
55109 + int i = 0;
55110 +
55111 + read_lock(&tasklist_lock);
55112 + if (current->real_parent) {
55113 + p = current->real_parent->role->rolename;
55114 + i = current->real_parent->acl_role_id;
55115 + }
55116 + read_unlock(&tasklist_lock);
55117 +
55118 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55119 + gr_set_acls(1);
55120 + } else {
55121 + error = -EPERM;
55122 + goto out;
55123 + }
55124 + break;
55125 + default:
55126 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55127 + error = -EINVAL;
55128 + break;
55129 + }
55130 +
55131 + if (error != -EPERM)
55132 + goto out;
55133 +
55134 + if(!(gr_auth_attempts++))
55135 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55136 +
55137 + out:
55138 + mutex_unlock(&gr_dev_mutex);
55139 + return error;
55140 +}
55141 +
55142 +/* must be called with
55143 + rcu_read_lock();
55144 + read_lock(&tasklist_lock);
55145 + read_lock(&grsec_exec_file_lock);
55146 +*/
55147 +int gr_apply_subject_to_task(struct task_struct *task)
55148 +{
55149 + struct acl_object_label *obj;
55150 + char *tmpname;
55151 + struct acl_subject_label *tmpsubj;
55152 + struct file *filp;
55153 + struct name_entry *nmatch;
55154 +
55155 + filp = task->exec_file;
55156 + if (filp == NULL)
55157 + return 0;
55158 +
55159 + /* the following is to apply the correct subject
55160 + on binaries running when the RBAC system
55161 + is enabled, when the binaries have been
55162 + replaced or deleted since their execution
55163 + -----
55164 + when the RBAC system starts, the inode/dev
55165 + from exec_file will be one the RBAC system
55166 + is unaware of. It only knows the inode/dev
55167 + of the present file on disk, or the absence
55168 + of it.
55169 + */
55170 + preempt_disable();
55171 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55172 +
55173 + nmatch = lookup_name_entry(tmpname);
55174 + preempt_enable();
55175 + tmpsubj = NULL;
55176 + if (nmatch) {
55177 + if (nmatch->deleted)
55178 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55179 + else
55180 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55181 + if (tmpsubj != NULL)
55182 + task->acl = tmpsubj;
55183 + }
55184 + if (tmpsubj == NULL)
55185 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55186 + task->role);
55187 + if (task->acl) {
55188 + task->is_writable = 0;
55189 + /* ignore additional mmap checks for processes that are writable
55190 + by the default ACL */
55191 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55192 + if (unlikely(obj->mode & GR_WRITE))
55193 + task->is_writable = 1;
55194 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55195 + if (unlikely(obj->mode & GR_WRITE))
55196 + task->is_writable = 1;
55197 +
55198 + gr_set_proc_res(task);
55199 +
55200 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55201 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55202 +#endif
55203 + } else {
55204 + return 1;
55205 + }
55206 +
55207 + return 0;
55208 +}
55209 +
55210 +int
55211 +gr_set_acls(const int type)
55212 +{
55213 + struct task_struct *task, *task2;
55214 + struct acl_role_label *role = current->role;
55215 + __u16 acl_role_id = current->acl_role_id;
55216 + const struct cred *cred;
55217 + int ret;
55218 +
55219 + rcu_read_lock();
55220 + read_lock(&tasklist_lock);
55221 + read_lock(&grsec_exec_file_lock);
55222 + do_each_thread(task2, task) {
55223 + /* check to see if we're called from the exit handler,
55224 + if so, only replace ACLs that have inherited the admin
55225 + ACL */
55226 +
55227 + if (type && (task->role != role ||
55228 + task->acl_role_id != acl_role_id))
55229 + continue;
55230 +
55231 + task->acl_role_id = 0;
55232 + task->acl_sp_role = 0;
55233 +
55234 + if (task->exec_file) {
55235 + cred = __task_cred(task);
55236 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55237 + ret = gr_apply_subject_to_task(task);
55238 + if (ret) {
55239 + read_unlock(&grsec_exec_file_lock);
55240 + read_unlock(&tasklist_lock);
55241 + rcu_read_unlock();
55242 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55243 + return ret;
55244 + }
55245 + } else {
55246 + // it's a kernel process
55247 + task->role = kernel_role;
55248 + task->acl = kernel_role->root_label;
55249 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55250 + task->acl->mode &= ~GR_PROCFIND;
55251 +#endif
55252 + }
55253 + } while_each_thread(task2, task);
55254 + read_unlock(&grsec_exec_file_lock);
55255 + read_unlock(&tasklist_lock);
55256 + rcu_read_unlock();
55257 +
55258 + return 0;
55259 +}
55260 +
55261 +void
55262 +gr_learn_resource(const struct task_struct *task,
55263 + const int res, const unsigned long wanted, const int gt)
55264 +{
55265 + struct acl_subject_label *acl;
55266 + const struct cred *cred;
55267 +
55268 + if (unlikely((gr_status & GR_READY) &&
55269 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55270 + goto skip_reslog;
55271 +
55272 +#ifdef CONFIG_GRKERNSEC_RESLOG
55273 + gr_log_resource(task, res, wanted, gt);
55274 +#endif
55275 + skip_reslog:
55276 +
55277 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55278 + return;
55279 +
55280 + acl = task->acl;
55281 +
55282 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55283 + !(acl->resmask & (1 << (unsigned short) res))))
55284 + return;
55285 +
55286 + if (wanted >= acl->res[res].rlim_cur) {
55287 + unsigned long res_add;
55288 +
55289 + res_add = wanted;
55290 + switch (res) {
55291 + case RLIMIT_CPU:
55292 + res_add += GR_RLIM_CPU_BUMP;
55293 + break;
55294 + case RLIMIT_FSIZE:
55295 + res_add += GR_RLIM_FSIZE_BUMP;
55296 + break;
55297 + case RLIMIT_DATA:
55298 + res_add += GR_RLIM_DATA_BUMP;
55299 + break;
55300 + case RLIMIT_STACK:
55301 + res_add += GR_RLIM_STACK_BUMP;
55302 + break;
55303 + case RLIMIT_CORE:
55304 + res_add += GR_RLIM_CORE_BUMP;
55305 + break;
55306 + case RLIMIT_RSS:
55307 + res_add += GR_RLIM_RSS_BUMP;
55308 + break;
55309 + case RLIMIT_NPROC:
55310 + res_add += GR_RLIM_NPROC_BUMP;
55311 + break;
55312 + case RLIMIT_NOFILE:
55313 + res_add += GR_RLIM_NOFILE_BUMP;
55314 + break;
55315 + case RLIMIT_MEMLOCK:
55316 + res_add += GR_RLIM_MEMLOCK_BUMP;
55317 + break;
55318 + case RLIMIT_AS:
55319 + res_add += GR_RLIM_AS_BUMP;
55320 + break;
55321 + case RLIMIT_LOCKS:
55322 + res_add += GR_RLIM_LOCKS_BUMP;
55323 + break;
55324 + case RLIMIT_SIGPENDING:
55325 + res_add += GR_RLIM_SIGPENDING_BUMP;
55326 + break;
55327 + case RLIMIT_MSGQUEUE:
55328 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55329 + break;
55330 + case RLIMIT_NICE:
55331 + res_add += GR_RLIM_NICE_BUMP;
55332 + break;
55333 + case RLIMIT_RTPRIO:
55334 + res_add += GR_RLIM_RTPRIO_BUMP;
55335 + break;
55336 + case RLIMIT_RTTIME:
55337 + res_add += GR_RLIM_RTTIME_BUMP;
55338 + break;
55339 + }
55340 +
55341 + acl->res[res].rlim_cur = res_add;
55342 +
55343 + if (wanted > acl->res[res].rlim_max)
55344 + acl->res[res].rlim_max = res_add;
55345 +
55346 + /* only log the subject filename, since resource logging is supported for
55347 + single-subject learning only */
55348 + rcu_read_lock();
55349 + cred = __task_cred(task);
55350 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55351 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55352 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55353 + "", (unsigned long) res, &task->signal->saved_ip);
55354 + rcu_read_unlock();
55355 + }
55356 +
55357 + return;
55358 +}
55359 +
55360 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55361 +void
55362 +pax_set_initial_flags(struct linux_binprm *bprm)
55363 +{
55364 + struct task_struct *task = current;
55365 + struct acl_subject_label *proc;
55366 + unsigned long flags;
55367 +
55368 + if (unlikely(!(gr_status & GR_READY)))
55369 + return;
55370 +
55371 + flags = pax_get_flags(task);
55372 +
55373 + proc = task->acl;
55374 +
55375 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55376 + flags &= ~MF_PAX_PAGEEXEC;
55377 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55378 + flags &= ~MF_PAX_SEGMEXEC;
55379 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55380 + flags &= ~MF_PAX_RANDMMAP;
55381 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55382 + flags &= ~MF_PAX_EMUTRAMP;
55383 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55384 + flags &= ~MF_PAX_MPROTECT;
55385 +
55386 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55387 + flags |= MF_PAX_PAGEEXEC;
55388 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55389 + flags |= MF_PAX_SEGMEXEC;
55390 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55391 + flags |= MF_PAX_RANDMMAP;
55392 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55393 + flags |= MF_PAX_EMUTRAMP;
55394 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55395 + flags |= MF_PAX_MPROTECT;
55396 +
55397 + pax_set_flags(task, flags);
55398 +
55399 + return;
55400 +}
55401 +#endif
55402 +
55403 +int
55404 +gr_handle_proc_ptrace(struct task_struct *task)
55405 +{
55406 + struct file *filp;
55407 + struct task_struct *tmp = task;
55408 + struct task_struct *curtemp = current;
55409 + __u32 retmode;
55410 +
55411 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55412 + if (unlikely(!(gr_status & GR_READY)))
55413 + return 0;
55414 +#endif
55415 +
55416 + read_lock(&tasklist_lock);
55417 + read_lock(&grsec_exec_file_lock);
55418 + filp = task->exec_file;
55419 +
55420 + while (tmp->pid > 0) {
55421 + if (tmp == curtemp)
55422 + break;
55423 + tmp = tmp->real_parent;
55424 + }
55425 +
55426 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55427 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55428 + read_unlock(&grsec_exec_file_lock);
55429 + read_unlock(&tasklist_lock);
55430 + return 1;
55431 + }
55432 +
55433 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55434 + if (!(gr_status & GR_READY)) {
55435 + read_unlock(&grsec_exec_file_lock);
55436 + read_unlock(&tasklist_lock);
55437 + return 0;
55438 + }
55439 +#endif
55440 +
55441 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55442 + read_unlock(&grsec_exec_file_lock);
55443 + read_unlock(&tasklist_lock);
55444 +
55445 + if (retmode & GR_NOPTRACE)
55446 + return 1;
55447 +
55448 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55449 + && (current->acl != task->acl || (current->acl != current->role->root_label
55450 + && current->pid != task->pid)))
55451 + return 1;
55452 +
55453 + return 0;
55454 +}
55455 +
55456 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55457 +{
55458 + if (unlikely(!(gr_status & GR_READY)))
55459 + return;
55460 +
55461 + if (!(current->role->roletype & GR_ROLE_GOD))
55462 + return;
55463 +
55464 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55465 + p->role->rolename, gr_task_roletype_to_char(p),
55466 + p->acl->filename);
55467 +}
55468 +
55469 +int
55470 +gr_handle_ptrace(struct task_struct *task, const long request)
55471 +{
55472 + struct task_struct *tmp = task;
55473 + struct task_struct *curtemp = current;
55474 + __u32 retmode;
55475 +
55476 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55477 + if (unlikely(!(gr_status & GR_READY)))
55478 + return 0;
55479 +#endif
55480 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55481 + read_lock(&tasklist_lock);
55482 + while (tmp->pid > 0) {
55483 + if (tmp == curtemp)
55484 + break;
55485 + tmp = tmp->real_parent;
55486 + }
55487 +
55488 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55489 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55490 + read_unlock(&tasklist_lock);
55491 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55492 + return 1;
55493 + }
55494 + read_unlock(&tasklist_lock);
55495 + }
55496 +
55497 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55498 + if (!(gr_status & GR_READY))
55499 + return 0;
55500 +#endif
55501 +
55502 + read_lock(&grsec_exec_file_lock);
55503 + if (unlikely(!task->exec_file)) {
55504 + read_unlock(&grsec_exec_file_lock);
55505 + return 0;
55506 + }
55507 +
55508 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55509 + read_unlock(&grsec_exec_file_lock);
55510 +
55511 + if (retmode & GR_NOPTRACE) {
55512 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55513 + return 1;
55514 + }
55515 +
55516 + if (retmode & GR_PTRACERD) {
55517 + switch (request) {
55518 + case PTRACE_SEIZE:
55519 + case PTRACE_POKETEXT:
55520 + case PTRACE_POKEDATA:
55521 + case PTRACE_POKEUSR:
55522 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55523 + case PTRACE_SETREGS:
55524 + case PTRACE_SETFPREGS:
55525 +#endif
55526 +#ifdef CONFIG_X86
55527 + case PTRACE_SETFPXREGS:
55528 +#endif
55529 +#ifdef CONFIG_ALTIVEC
55530 + case PTRACE_SETVRREGS:
55531 +#endif
55532 + return 1;
55533 + default:
55534 + return 0;
55535 + }
55536 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55537 + !(current->role->roletype & GR_ROLE_GOD) &&
55538 + (current->acl != task->acl)) {
55539 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55540 + return 1;
55541 + }
55542 +
55543 + return 0;
55544 +}
55545 +
55546 +static int is_writable_mmap(const struct file *filp)
55547 +{
55548 + struct task_struct *task = current;
55549 + struct acl_object_label *obj, *obj2;
55550 +
55551 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55552 + !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))) {
55553 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55554 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55555 + task->role->root_label);
55556 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55557 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55558 + return 1;
55559 + }
55560 + }
55561 + return 0;
55562 +}
55563 +
55564 +int
55565 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55566 +{
55567 + __u32 mode;
55568 +
55569 + if (unlikely(!file || !(prot & PROT_EXEC)))
55570 + return 1;
55571 +
55572 + if (is_writable_mmap(file))
55573 + return 0;
55574 +
55575 + mode =
55576 + gr_search_file(file->f_path.dentry,
55577 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55578 + file->f_path.mnt);
55579 +
55580 + if (!gr_tpe_allow(file))
55581 + return 0;
55582 +
55583 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55584 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55585 + return 0;
55586 + } else if (unlikely(!(mode & GR_EXEC))) {
55587 + return 0;
55588 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55589 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55590 + return 1;
55591 + }
55592 +
55593 + return 1;
55594 +}
55595 +
55596 +int
55597 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55598 +{
55599 + __u32 mode;
55600 +
55601 + if (unlikely(!file || !(prot & PROT_EXEC)))
55602 + return 1;
55603 +
55604 + if (is_writable_mmap(file))
55605 + return 0;
55606 +
55607 + mode =
55608 + gr_search_file(file->f_path.dentry,
55609 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55610 + file->f_path.mnt);
55611 +
55612 + if (!gr_tpe_allow(file))
55613 + return 0;
55614 +
55615 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55616 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55617 + return 0;
55618 + } else if (unlikely(!(mode & GR_EXEC))) {
55619 + return 0;
55620 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55621 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55622 + return 1;
55623 + }
55624 +
55625 + return 1;
55626 +}
55627 +
55628 +void
55629 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55630 +{
55631 + unsigned long runtime;
55632 + unsigned long cputime;
55633 + unsigned int wday, cday;
55634 + __u8 whr, chr;
55635 + __u8 wmin, cmin;
55636 + __u8 wsec, csec;
55637 + struct timespec timeval;
55638 +
55639 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55640 + !(task->acl->mode & GR_PROCACCT)))
55641 + return;
55642 +
55643 + do_posix_clock_monotonic_gettime(&timeval);
55644 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55645 + wday = runtime / (3600 * 24);
55646 + runtime -= wday * (3600 * 24);
55647 + whr = runtime / 3600;
55648 + runtime -= whr * 3600;
55649 + wmin = runtime / 60;
55650 + runtime -= wmin * 60;
55651 + wsec = runtime;
55652 +
55653 + cputime = (task->utime + task->stime) / HZ;
55654 + cday = cputime / (3600 * 24);
55655 + cputime -= cday * (3600 * 24);
55656 + chr = cputime / 3600;
55657 + cputime -= chr * 3600;
55658 + cmin = cputime / 60;
55659 + cputime -= cmin * 60;
55660 + csec = cputime;
55661 +
55662 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55663 +
55664 + return;
55665 +}
55666 +
55667 +void gr_set_kernel_label(struct task_struct *task)
55668 +{
55669 + if (gr_status & GR_READY) {
55670 + task->role = kernel_role;
55671 + task->acl = kernel_role->root_label;
55672 + }
55673 + return;
55674 +}
55675 +
55676 +#ifdef CONFIG_TASKSTATS
55677 +int gr_is_taskstats_denied(int pid)
55678 +{
55679 + struct task_struct *task;
55680 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55681 + const struct cred *cred;
55682 +#endif
55683 + int ret = 0;
55684 +
55685 + /* restrict taskstats viewing to un-chrooted root users
55686 + who have the 'view' subject flag if the RBAC system is enabled
55687 + */
55688 +
55689 + rcu_read_lock();
55690 + read_lock(&tasklist_lock);
55691 + task = find_task_by_vpid(pid);
55692 + if (task) {
55693 +#ifdef CONFIG_GRKERNSEC_CHROOT
55694 + if (proc_is_chrooted(task))
55695 + ret = -EACCES;
55696 +#endif
55697 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55698 + cred = __task_cred(task);
55699 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55700 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55701 + ret = -EACCES;
55702 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55703 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55704 + ret = -EACCES;
55705 +#endif
55706 +#endif
55707 + if (gr_status & GR_READY) {
55708 + if (!(task->acl->mode & GR_VIEW))
55709 + ret = -EACCES;
55710 + }
55711 + } else
55712 + ret = -ENOENT;
55713 +
55714 + read_unlock(&tasklist_lock);
55715 + rcu_read_unlock();
55716 +
55717 + return ret;
55718 +}
55719 +#endif
55720 +
55721 +/* AUXV entries are filled via a descendant of search_binary_handler
55722 + after we've already applied the subject for the target
55723 +*/
55724 +int gr_acl_enable_at_secure(void)
55725 +{
55726 + if (unlikely(!(gr_status & GR_READY)))
55727 + return 0;
55728 +
55729 + if (current->acl->mode & GR_ATSECURE)
55730 + return 1;
55731 +
55732 + return 0;
55733 +}
55734 +
55735 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55736 +{
55737 + struct task_struct *task = current;
55738 + struct dentry *dentry = file->f_path.dentry;
55739 + struct vfsmount *mnt = file->f_path.mnt;
55740 + struct acl_object_label *obj, *tmp;
55741 + struct acl_subject_label *subj;
55742 + unsigned int bufsize;
55743 + int is_not_root;
55744 + char *path;
55745 + dev_t dev = __get_dev(dentry);
55746 +
55747 + if (unlikely(!(gr_status & GR_READY)))
55748 + return 1;
55749 +
55750 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55751 + return 1;
55752 +
55753 + /* ignore Eric Biederman */
55754 + if (IS_PRIVATE(dentry->d_inode))
55755 + return 1;
55756 +
55757 + subj = task->acl;
55758 + read_lock(&gr_inode_lock);
55759 + do {
55760 + obj = lookup_acl_obj_label(ino, dev, subj);
55761 + if (obj != NULL) {
55762 + read_unlock(&gr_inode_lock);
55763 + return (obj->mode & GR_FIND) ? 1 : 0;
55764 + }
55765 + } while ((subj = subj->parent_subject));
55766 + read_unlock(&gr_inode_lock);
55767 +
55768 + /* this is purely an optimization since we're looking for an object
55769 + for the directory we're doing a readdir on
55770 + if it's possible for any globbed object to match the entry we're
55771 + filling into the directory, then the object we find here will be
55772 + an anchor point with attached globbed objects
55773 + */
55774 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55775 + if (obj->globbed == NULL)
55776 + return (obj->mode & GR_FIND) ? 1 : 0;
55777 +
55778 + is_not_root = ((obj->filename[0] == '/') &&
55779 + (obj->filename[1] == '\0')) ? 0 : 1;
55780 + bufsize = PAGE_SIZE - namelen - is_not_root;
55781 +
55782 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55783 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55784 + return 1;
55785 +
55786 + preempt_disable();
55787 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55788 + bufsize);
55789 +
55790 + bufsize = strlen(path);
55791 +
55792 + /* if base is "/", don't append an additional slash */
55793 + if (is_not_root)
55794 + *(path + bufsize) = '/';
55795 + memcpy(path + bufsize + is_not_root, name, namelen);
55796 + *(path + bufsize + namelen + is_not_root) = '\0';
55797 +
55798 + tmp = obj->globbed;
55799 + while (tmp) {
55800 + if (!glob_match(tmp->filename, path)) {
55801 + preempt_enable();
55802 + return (tmp->mode & GR_FIND) ? 1 : 0;
55803 + }
55804 + tmp = tmp->next;
55805 + }
55806 + preempt_enable();
55807 + return (obj->mode & GR_FIND) ? 1 : 0;
55808 +}
55809 +
55810 +void gr_put_exec_file(struct task_struct *task)
55811 +{
55812 + struct file *filp;
55813 +
55814 + write_lock(&grsec_exec_file_lock);
55815 + filp = task->exec_file;
55816 + task->exec_file = NULL;
55817 + write_unlock(&grsec_exec_file_lock);
55818 +
55819 + if (filp)
55820 + fput(filp);
55821 +
55822 + return;
55823 +}
55824 +
55825 +
55826 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55827 +EXPORT_SYMBOL(gr_acl_is_enabled);
55828 +#endif
55829 +EXPORT_SYMBOL(gr_learn_resource);
55830 +EXPORT_SYMBOL(gr_set_kernel_label);
55831 +#ifdef CONFIG_SECURITY
55832 +EXPORT_SYMBOL(gr_check_user_change);
55833 +EXPORT_SYMBOL(gr_check_group_change);
55834 +#endif
55835 +
55836 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55837 new file mode 100644
55838 index 0000000..34fefda
55839 --- /dev/null
55840 +++ b/grsecurity/gracl_alloc.c
55841 @@ -0,0 +1,105 @@
55842 +#include <linux/kernel.h>
55843 +#include <linux/mm.h>
55844 +#include <linux/slab.h>
55845 +#include <linux/vmalloc.h>
55846 +#include <linux/gracl.h>
55847 +#include <linux/grsecurity.h>
55848 +
55849 +static unsigned long alloc_stack_next = 1;
55850 +static unsigned long alloc_stack_size = 1;
55851 +static void **alloc_stack;
55852 +
55853 +static __inline__ int
55854 +alloc_pop(void)
55855 +{
55856 + if (alloc_stack_next == 1)
55857 + return 0;
55858 +
55859 + kfree(alloc_stack[alloc_stack_next - 2]);
55860 +
55861 + alloc_stack_next--;
55862 +
55863 + return 1;
55864 +}
55865 +
55866 +static __inline__ int
55867 +alloc_push(void *buf)
55868 +{
55869 + if (alloc_stack_next >= alloc_stack_size)
55870 + return 1;
55871 +
55872 + alloc_stack[alloc_stack_next - 1] = buf;
55873 +
55874 + alloc_stack_next++;
55875 +
55876 + return 0;
55877 +}
55878 +
55879 +void *
55880 +acl_alloc(unsigned long len)
55881 +{
55882 + void *ret = NULL;
55883 +
55884 + if (!len || len > PAGE_SIZE)
55885 + goto out;
55886 +
55887 + ret = kmalloc(len, GFP_KERNEL);
55888 +
55889 + if (ret) {
55890 + if (alloc_push(ret)) {
55891 + kfree(ret);
55892 + ret = NULL;
55893 + }
55894 + }
55895 +
55896 +out:
55897 + return ret;
55898 +}
55899 +
55900 +void *
55901 +acl_alloc_num(unsigned long num, unsigned long len)
55902 +{
55903 + if (!len || (num > (PAGE_SIZE / len)))
55904 + return NULL;
55905 +
55906 + return acl_alloc(num * len);
55907 +}
55908 +
55909 +void
55910 +acl_free_all(void)
55911 +{
55912 + if (gr_acl_is_enabled() || !alloc_stack)
55913 + return;
55914 +
55915 + while (alloc_pop()) ;
55916 +
55917 + if (alloc_stack) {
55918 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55919 + kfree(alloc_stack);
55920 + else
55921 + vfree(alloc_stack);
55922 + }
55923 +
55924 + alloc_stack = NULL;
55925 + alloc_stack_size = 1;
55926 + alloc_stack_next = 1;
55927 +
55928 + return;
55929 +}
55930 +
55931 +int
55932 +acl_alloc_stack_init(unsigned long size)
55933 +{
55934 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55935 + alloc_stack =
55936 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55937 + else
55938 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55939 +
55940 + alloc_stack_size = size;
55941 +
55942 + if (!alloc_stack)
55943 + return 0;
55944 + else
55945 + return 1;
55946 +}
55947 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55948 new file mode 100644
55949 index 0000000..6d21049
55950 --- /dev/null
55951 +++ b/grsecurity/gracl_cap.c
55952 @@ -0,0 +1,110 @@
55953 +#include <linux/kernel.h>
55954 +#include <linux/module.h>
55955 +#include <linux/sched.h>
55956 +#include <linux/gracl.h>
55957 +#include <linux/grsecurity.h>
55958 +#include <linux/grinternal.h>
55959 +
55960 +extern const char *captab_log[];
55961 +extern int captab_log_entries;
55962 +
55963 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55964 +{
55965 + struct acl_subject_label *curracl;
55966 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55967 + kernel_cap_t cap_audit = __cap_empty_set;
55968 +
55969 + if (!gr_acl_is_enabled())
55970 + return 1;
55971 +
55972 + curracl = task->acl;
55973 +
55974 + cap_drop = curracl->cap_lower;
55975 + cap_mask = curracl->cap_mask;
55976 + cap_audit = curracl->cap_invert_audit;
55977 +
55978 + while ((curracl = curracl->parent_subject)) {
55979 + /* if the cap isn't specified in the current computed mask but is specified in the
55980 + current level subject, and is lowered in the current level subject, then add
55981 + it to the set of dropped capabilities
55982 + otherwise, add the current level subject's mask to the current computed mask
55983 + */
55984 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55985 + cap_raise(cap_mask, cap);
55986 + if (cap_raised(curracl->cap_lower, cap))
55987 + cap_raise(cap_drop, cap);
55988 + if (cap_raised(curracl->cap_invert_audit, cap))
55989 + cap_raise(cap_audit, cap);
55990 + }
55991 + }
55992 +
55993 + if (!cap_raised(cap_drop, cap)) {
55994 + if (cap_raised(cap_audit, cap))
55995 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55996 + return 1;
55997 + }
55998 +
55999 + curracl = task->acl;
56000 +
56001 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
56002 + && cap_raised(cred->cap_effective, cap)) {
56003 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56004 + task->role->roletype, cred->uid,
56005 + cred->gid, task->exec_file ?
56006 + gr_to_filename(task->exec_file->f_path.dentry,
56007 + task->exec_file->f_path.mnt) : curracl->filename,
56008 + curracl->filename, 0UL,
56009 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56010 + return 1;
56011 + }
56012 +
56013 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56014 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56015 +
56016 + return 0;
56017 +}
56018 +
56019 +int
56020 +gr_acl_is_capable(const int cap)
56021 +{
56022 + return gr_task_acl_is_capable(current, current_cred(), cap);
56023 +}
56024 +
56025 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56026 +{
56027 + struct acl_subject_label *curracl;
56028 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56029 +
56030 + if (!gr_acl_is_enabled())
56031 + return 1;
56032 +
56033 + curracl = task->acl;
56034 +
56035 + cap_drop = curracl->cap_lower;
56036 + cap_mask = curracl->cap_mask;
56037 +
56038 + while ((curracl = curracl->parent_subject)) {
56039 + /* if the cap isn't specified in the current computed mask but is specified in the
56040 + current level subject, and is lowered in the current level subject, then add
56041 + it to the set of dropped capabilities
56042 + otherwise, add the current level subject's mask to the current computed mask
56043 + */
56044 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56045 + cap_raise(cap_mask, cap);
56046 + if (cap_raised(curracl->cap_lower, cap))
56047 + cap_raise(cap_drop, cap);
56048 + }
56049 + }
56050 +
56051 + if (!cap_raised(cap_drop, cap))
56052 + return 1;
56053 +
56054 + return 0;
56055 +}
56056 +
56057 +int
56058 +gr_acl_is_capable_nolog(const int cap)
56059 +{
56060 + return gr_task_acl_is_capable_nolog(current, cap);
56061 +}
56062 +
56063 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56064 new file mode 100644
56065 index 0000000..decb035
56066 --- /dev/null
56067 +++ b/grsecurity/gracl_fs.c
56068 @@ -0,0 +1,437 @@
56069 +#include <linux/kernel.h>
56070 +#include <linux/sched.h>
56071 +#include <linux/types.h>
56072 +#include <linux/fs.h>
56073 +#include <linux/file.h>
56074 +#include <linux/stat.h>
56075 +#include <linux/grsecurity.h>
56076 +#include <linux/grinternal.h>
56077 +#include <linux/gracl.h>
56078 +
56079 +umode_t
56080 +gr_acl_umask(void)
56081 +{
56082 + if (unlikely(!gr_acl_is_enabled()))
56083 + return 0;
56084 +
56085 + return current->role->umask;
56086 +}
56087 +
56088 +__u32
56089 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56090 + const struct vfsmount * mnt)
56091 +{
56092 + __u32 mode;
56093 +
56094 + if (unlikely(!dentry->d_inode))
56095 + return GR_FIND;
56096 +
56097 + mode =
56098 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56099 +
56100 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56101 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56102 + return mode;
56103 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56104 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56105 + return 0;
56106 + } else if (unlikely(!(mode & GR_FIND)))
56107 + return 0;
56108 +
56109 + return GR_FIND;
56110 +}
56111 +
56112 +__u32
56113 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56114 + int acc_mode)
56115 +{
56116 + __u32 reqmode = GR_FIND;
56117 + __u32 mode;
56118 +
56119 + if (unlikely(!dentry->d_inode))
56120 + return reqmode;
56121 +
56122 + if (acc_mode & MAY_APPEND)
56123 + reqmode |= GR_APPEND;
56124 + else if (acc_mode & MAY_WRITE)
56125 + reqmode |= GR_WRITE;
56126 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56127 + reqmode |= GR_READ;
56128 +
56129 + mode =
56130 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56131 + mnt);
56132 +
56133 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56134 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56135 + reqmode & GR_READ ? " reading" : "",
56136 + reqmode & GR_WRITE ? " writing" : reqmode &
56137 + GR_APPEND ? " appending" : "");
56138 + return reqmode;
56139 + } else
56140 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56141 + {
56142 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56143 + reqmode & GR_READ ? " reading" : "",
56144 + reqmode & GR_WRITE ? " writing" : reqmode &
56145 + GR_APPEND ? " appending" : "");
56146 + return 0;
56147 + } else if (unlikely((mode & reqmode) != reqmode))
56148 + return 0;
56149 +
56150 + return reqmode;
56151 +}
56152 +
56153 +__u32
56154 +gr_acl_handle_creat(const struct dentry * dentry,
56155 + const struct dentry * p_dentry,
56156 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56157 + const int imode)
56158 +{
56159 + __u32 reqmode = GR_WRITE | GR_CREATE;
56160 + __u32 mode;
56161 +
56162 + if (acc_mode & MAY_APPEND)
56163 + reqmode |= GR_APPEND;
56164 + // if a directory was required or the directory already exists, then
56165 + // don't count this open as a read
56166 + if ((acc_mode & MAY_READ) &&
56167 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56168 + reqmode |= GR_READ;
56169 + if ((open_flags & O_CREAT) &&
56170 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56171 + reqmode |= GR_SETID;
56172 +
56173 + mode =
56174 + gr_check_create(dentry, p_dentry, p_mnt,
56175 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56176 +
56177 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56178 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56179 + reqmode & GR_READ ? " reading" : "",
56180 + reqmode & GR_WRITE ? " writing" : reqmode &
56181 + GR_APPEND ? " appending" : "");
56182 + return reqmode;
56183 + } else
56184 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56185 + {
56186 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56187 + reqmode & GR_READ ? " reading" : "",
56188 + reqmode & GR_WRITE ? " writing" : reqmode &
56189 + GR_APPEND ? " appending" : "");
56190 + return 0;
56191 + } else if (unlikely((mode & reqmode) != reqmode))
56192 + return 0;
56193 +
56194 + return reqmode;
56195 +}
56196 +
56197 +__u32
56198 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56199 + const int fmode)
56200 +{
56201 + __u32 mode, reqmode = GR_FIND;
56202 +
56203 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56204 + reqmode |= GR_EXEC;
56205 + if (fmode & S_IWOTH)
56206 + reqmode |= GR_WRITE;
56207 + if (fmode & S_IROTH)
56208 + reqmode |= GR_READ;
56209 +
56210 + mode =
56211 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56212 + mnt);
56213 +
56214 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56215 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56216 + reqmode & GR_READ ? " reading" : "",
56217 + reqmode & GR_WRITE ? " writing" : "",
56218 + reqmode & GR_EXEC ? " executing" : "");
56219 + return reqmode;
56220 + } else
56221 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56222 + {
56223 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56224 + reqmode & GR_READ ? " reading" : "",
56225 + reqmode & GR_WRITE ? " writing" : "",
56226 + reqmode & GR_EXEC ? " executing" : "");
56227 + return 0;
56228 + } else if (unlikely((mode & reqmode) != reqmode))
56229 + return 0;
56230 +
56231 + return reqmode;
56232 +}
56233 +
56234 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56235 +{
56236 + __u32 mode;
56237 +
56238 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56239 +
56240 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56241 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56242 + return mode;
56243 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56244 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56245 + return 0;
56246 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56247 + return 0;
56248 +
56249 + return (reqmode);
56250 +}
56251 +
56252 +__u32
56253 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56254 +{
56255 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56256 +}
56257 +
56258 +__u32
56259 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56260 +{
56261 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56262 +}
56263 +
56264 +__u32
56265 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56266 +{
56267 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56268 +}
56269 +
56270 +__u32
56271 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56272 +{
56273 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56274 +}
56275 +
56276 +__u32
56277 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56278 + umode_t *modeptr)
56279 +{
56280 + umode_t mode;
56281 +
56282 + *modeptr &= ~gr_acl_umask();
56283 + mode = *modeptr;
56284 +
56285 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56286 + return 1;
56287 +
56288 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56289 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56290 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56291 + GR_CHMOD_ACL_MSG);
56292 + } else {
56293 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56294 + }
56295 +}
56296 +
56297 +__u32
56298 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56299 +{
56300 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56301 +}
56302 +
56303 +__u32
56304 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56305 +{
56306 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56307 +}
56308 +
56309 +__u32
56310 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56311 +{
56312 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56313 +}
56314 +
56315 +__u32
56316 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56317 +{
56318 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56319 + GR_UNIXCONNECT_ACL_MSG);
56320 +}
56321 +
56322 +/* hardlinks require at minimum create and link permission,
56323 + any additional privilege required is based on the
56324 + privilege of the file being linked to
56325 +*/
56326 +__u32
56327 +gr_acl_handle_link(const struct dentry * new_dentry,
56328 + const struct dentry * parent_dentry,
56329 + const struct vfsmount * parent_mnt,
56330 + const struct dentry * old_dentry,
56331 + const struct vfsmount * old_mnt, const struct filename *to)
56332 +{
56333 + __u32 mode;
56334 + __u32 needmode = GR_CREATE | GR_LINK;
56335 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56336 +
56337 + mode =
56338 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56339 + old_mnt);
56340 +
56341 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56342 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
56343 + return mode;
56344 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56345 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
56346 + return 0;
56347 + } else if (unlikely((mode & needmode) != needmode))
56348 + return 0;
56349 +
56350 + return 1;
56351 +}
56352 +
56353 +__u32
56354 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56355 + const struct dentry * parent_dentry,
56356 + const struct vfsmount * parent_mnt, const struct filename *from)
56357 +{
56358 + __u32 needmode = GR_WRITE | GR_CREATE;
56359 + __u32 mode;
56360 +
56361 + mode =
56362 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56363 + GR_CREATE | GR_AUDIT_CREATE |
56364 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56365 +
56366 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56367 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
56368 + return mode;
56369 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56370 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
56371 + return 0;
56372 + } else if (unlikely((mode & needmode) != needmode))
56373 + return 0;
56374 +
56375 + return (GR_WRITE | GR_CREATE);
56376 +}
56377 +
56378 +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)
56379 +{
56380 + __u32 mode;
56381 +
56382 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56383 +
56384 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56385 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56386 + return mode;
56387 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56388 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56389 + return 0;
56390 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56391 + return 0;
56392 +
56393 + return (reqmode);
56394 +}
56395 +
56396 +__u32
56397 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56398 + const struct dentry * parent_dentry,
56399 + const struct vfsmount * parent_mnt,
56400 + const int mode)
56401 +{
56402 + __u32 reqmode = GR_WRITE | GR_CREATE;
56403 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56404 + reqmode |= GR_SETID;
56405 +
56406 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56407 + reqmode, GR_MKNOD_ACL_MSG);
56408 +}
56409 +
56410 +__u32
56411 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56412 + const struct dentry *parent_dentry,
56413 + const struct vfsmount *parent_mnt)
56414 +{
56415 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56416 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56417 +}
56418 +
56419 +#define RENAME_CHECK_SUCCESS(old, new) \
56420 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56421 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56422 +
56423 +int
56424 +gr_acl_handle_rename(struct dentry *new_dentry,
56425 + struct dentry *parent_dentry,
56426 + const struct vfsmount *parent_mnt,
56427 + struct dentry *old_dentry,
56428 + struct inode *old_parent_inode,
56429 + struct vfsmount *old_mnt, const struct filename *newname)
56430 +{
56431 + __u32 comp1, comp2;
56432 + int error = 0;
56433 +
56434 + if (unlikely(!gr_acl_is_enabled()))
56435 + return 0;
56436 +
56437 + if (!new_dentry->d_inode) {
56438 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56439 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56440 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56441 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56442 + GR_DELETE | GR_AUDIT_DELETE |
56443 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56444 + GR_SUPPRESS, old_mnt);
56445 + } else {
56446 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56447 + GR_CREATE | GR_DELETE |
56448 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56449 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56450 + GR_SUPPRESS, parent_mnt);
56451 + comp2 =
56452 + gr_search_file(old_dentry,
56453 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56454 + GR_DELETE | GR_AUDIT_DELETE |
56455 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56456 + }
56457 +
56458 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56459 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56460 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
56461 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56462 + && !(comp2 & GR_SUPPRESS)) {
56463 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
56464 + error = -EACCES;
56465 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56466 + error = -EACCES;
56467 +
56468 + return error;
56469 +}
56470 +
56471 +void
56472 +gr_acl_handle_exit(void)
56473 +{
56474 + u16 id;
56475 + char *rolename;
56476 + struct file *exec_file;
56477 +
56478 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56479 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56480 + id = current->acl_role_id;
56481 + rolename = current->role->rolename;
56482 + gr_set_acls(1);
56483 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56484 + }
56485 +
56486 + write_lock(&grsec_exec_file_lock);
56487 + exec_file = current->exec_file;
56488 + current->exec_file = NULL;
56489 + write_unlock(&grsec_exec_file_lock);
56490 +
56491 + if (exec_file)
56492 + fput(exec_file);
56493 +}
56494 +
56495 +int
56496 +gr_acl_handle_procpidmem(const struct task_struct *task)
56497 +{
56498 + if (unlikely(!gr_acl_is_enabled()))
56499 + return 0;
56500 +
56501 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56502 + return -EACCES;
56503 +
56504 + return 0;
56505 +}
56506 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56507 new file mode 100644
56508 index 0000000..58800a7
56509 --- /dev/null
56510 +++ b/grsecurity/gracl_ip.c
56511 @@ -0,0 +1,384 @@
56512 +#include <linux/kernel.h>
56513 +#include <asm/uaccess.h>
56514 +#include <asm/errno.h>
56515 +#include <net/sock.h>
56516 +#include <linux/file.h>
56517 +#include <linux/fs.h>
56518 +#include <linux/net.h>
56519 +#include <linux/in.h>
56520 +#include <linux/skbuff.h>
56521 +#include <linux/ip.h>
56522 +#include <linux/udp.h>
56523 +#include <linux/types.h>
56524 +#include <linux/sched.h>
56525 +#include <linux/netdevice.h>
56526 +#include <linux/inetdevice.h>
56527 +#include <linux/gracl.h>
56528 +#include <linux/grsecurity.h>
56529 +#include <linux/grinternal.h>
56530 +
56531 +#define GR_BIND 0x01
56532 +#define GR_CONNECT 0x02
56533 +#define GR_INVERT 0x04
56534 +#define GR_BINDOVERRIDE 0x08
56535 +#define GR_CONNECTOVERRIDE 0x10
56536 +#define GR_SOCK_FAMILY 0x20
56537 +
56538 +static const char * gr_protocols[IPPROTO_MAX] = {
56539 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56540 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56541 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56542 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56543 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56544 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56545 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56546 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56547 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56548 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56549 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56550 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56551 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56552 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56553 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56554 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56555 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56556 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56557 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56558 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56559 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56560 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56561 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56562 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56563 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56564 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56565 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56566 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56567 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56568 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56569 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56570 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56571 + };
56572 +
56573 +static const char * gr_socktypes[SOCK_MAX] = {
56574 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56575 + "unknown:7", "unknown:8", "unknown:9", "packet"
56576 + };
56577 +
56578 +static const char * gr_sockfamilies[AF_MAX+1] = {
56579 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56580 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56581 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56582 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56583 + };
56584 +
56585 +const char *
56586 +gr_proto_to_name(unsigned char proto)
56587 +{
56588 + return gr_protocols[proto];
56589 +}
56590 +
56591 +const char *
56592 +gr_socktype_to_name(unsigned char type)
56593 +{
56594 + return gr_socktypes[type];
56595 +}
56596 +
56597 +const char *
56598 +gr_sockfamily_to_name(unsigned char family)
56599 +{
56600 + return gr_sockfamilies[family];
56601 +}
56602 +
56603 +int
56604 +gr_search_socket(const int domain, const int type, const int protocol)
56605 +{
56606 + struct acl_subject_label *curr;
56607 + const struct cred *cred = current_cred();
56608 +
56609 + if (unlikely(!gr_acl_is_enabled()))
56610 + goto exit;
56611 +
56612 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56613 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56614 + goto exit; // let the kernel handle it
56615 +
56616 + curr = current->acl;
56617 +
56618 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56619 + /* the family is allowed, if this is PF_INET allow it only if
56620 + the extra sock type/protocol checks pass */
56621 + if (domain == PF_INET)
56622 + goto inet_check;
56623 + goto exit;
56624 + } else {
56625 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56626 + __u32 fakeip = 0;
56627 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56628 + current->role->roletype, cred->uid,
56629 + cred->gid, current->exec_file ?
56630 + gr_to_filename(current->exec_file->f_path.dentry,
56631 + current->exec_file->f_path.mnt) :
56632 + curr->filename, curr->filename,
56633 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56634 + &current->signal->saved_ip);
56635 + goto exit;
56636 + }
56637 + goto exit_fail;
56638 + }
56639 +
56640 +inet_check:
56641 + /* the rest of this checking is for IPv4 only */
56642 + if (!curr->ips)
56643 + goto exit;
56644 +
56645 + if ((curr->ip_type & (1 << type)) &&
56646 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56647 + goto exit;
56648 +
56649 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56650 + /* we don't place acls on raw sockets , and sometimes
56651 + dgram/ip sockets are opened for ioctl and not
56652 + bind/connect, so we'll fake a bind learn log */
56653 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56654 + __u32 fakeip = 0;
56655 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56656 + current->role->roletype, cred->uid,
56657 + cred->gid, current->exec_file ?
56658 + gr_to_filename(current->exec_file->f_path.dentry,
56659 + current->exec_file->f_path.mnt) :
56660 + curr->filename, curr->filename,
56661 + &fakeip, 0, type,
56662 + protocol, GR_CONNECT, &current->signal->saved_ip);
56663 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56664 + __u32 fakeip = 0;
56665 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56666 + current->role->roletype, cred->uid,
56667 + cred->gid, current->exec_file ?
56668 + gr_to_filename(current->exec_file->f_path.dentry,
56669 + current->exec_file->f_path.mnt) :
56670 + curr->filename, curr->filename,
56671 + &fakeip, 0, type,
56672 + protocol, GR_BIND, &current->signal->saved_ip);
56673 + }
56674 + /* we'll log when they use connect or bind */
56675 + goto exit;
56676 + }
56677 +
56678 +exit_fail:
56679 + if (domain == PF_INET)
56680 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56681 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56682 + else
56683 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56684 + gr_socktype_to_name(type), protocol);
56685 +
56686 + return 0;
56687 +exit:
56688 + return 1;
56689 +}
56690 +
56691 +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)
56692 +{
56693 + if ((ip->mode & mode) &&
56694 + (ip_port >= ip->low) &&
56695 + (ip_port <= ip->high) &&
56696 + ((ntohl(ip_addr) & our_netmask) ==
56697 + (ntohl(our_addr) & our_netmask))
56698 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56699 + && (ip->type & (1 << type))) {
56700 + if (ip->mode & GR_INVERT)
56701 + return 2; // specifically denied
56702 + else
56703 + return 1; // allowed
56704 + }
56705 +
56706 + return 0; // not specifically allowed, may continue parsing
56707 +}
56708 +
56709 +static int
56710 +gr_search_connectbind(const int full_mode, struct sock *sk,
56711 + struct sockaddr_in *addr, const int type)
56712 +{
56713 + char iface[IFNAMSIZ] = {0};
56714 + struct acl_subject_label *curr;
56715 + struct acl_ip_label *ip;
56716 + struct inet_sock *isk;
56717 + struct net_device *dev;
56718 + struct in_device *idev;
56719 + unsigned long i;
56720 + int ret;
56721 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56722 + __u32 ip_addr = 0;
56723 + __u32 our_addr;
56724 + __u32 our_netmask;
56725 + char *p;
56726 + __u16 ip_port = 0;
56727 + const struct cred *cred = current_cred();
56728 +
56729 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56730 + return 0;
56731 +
56732 + curr = current->acl;
56733 + isk = inet_sk(sk);
56734 +
56735 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56736 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56737 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56738 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56739 + struct sockaddr_in saddr;
56740 + int err;
56741 +
56742 + saddr.sin_family = AF_INET;
56743 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56744 + saddr.sin_port = isk->inet_sport;
56745 +
56746 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56747 + if (err)
56748 + return err;
56749 +
56750 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56751 + if (err)
56752 + return err;
56753 + }
56754 +
56755 + if (!curr->ips)
56756 + return 0;
56757 +
56758 + ip_addr = addr->sin_addr.s_addr;
56759 + ip_port = ntohs(addr->sin_port);
56760 +
56761 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56762 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56763 + current->role->roletype, cred->uid,
56764 + cred->gid, current->exec_file ?
56765 + gr_to_filename(current->exec_file->f_path.dentry,
56766 + current->exec_file->f_path.mnt) :
56767 + curr->filename, curr->filename,
56768 + &ip_addr, ip_port, type,
56769 + sk->sk_protocol, mode, &current->signal->saved_ip);
56770 + return 0;
56771 + }
56772 +
56773 + for (i = 0; i < curr->ip_num; i++) {
56774 + ip = *(curr->ips + i);
56775 + if (ip->iface != NULL) {
56776 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56777 + p = strchr(iface, ':');
56778 + if (p != NULL)
56779 + *p = '\0';
56780 + dev = dev_get_by_name(sock_net(sk), iface);
56781 + if (dev == NULL)
56782 + continue;
56783 + idev = in_dev_get(dev);
56784 + if (idev == NULL) {
56785 + dev_put(dev);
56786 + continue;
56787 + }
56788 + rcu_read_lock();
56789 + for_ifa(idev) {
56790 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56791 + our_addr = ifa->ifa_address;
56792 + our_netmask = 0xffffffff;
56793 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56794 + if (ret == 1) {
56795 + rcu_read_unlock();
56796 + in_dev_put(idev);
56797 + dev_put(dev);
56798 + return 0;
56799 + } else if (ret == 2) {
56800 + rcu_read_unlock();
56801 + in_dev_put(idev);
56802 + dev_put(dev);
56803 + goto denied;
56804 + }
56805 + }
56806 + } endfor_ifa(idev);
56807 + rcu_read_unlock();
56808 + in_dev_put(idev);
56809 + dev_put(dev);
56810 + } else {
56811 + our_addr = ip->addr;
56812 + our_netmask = ip->netmask;
56813 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56814 + if (ret == 1)
56815 + return 0;
56816 + else if (ret == 2)
56817 + goto denied;
56818 + }
56819 + }
56820 +
56821 +denied:
56822 + if (mode == GR_BIND)
56823 + 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));
56824 + else if (mode == GR_CONNECT)
56825 + 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));
56826 +
56827 + return -EACCES;
56828 +}
56829 +
56830 +int
56831 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56832 +{
56833 + /* always allow disconnection of dgram sockets with connect */
56834 + if (addr->sin_family == AF_UNSPEC)
56835 + return 0;
56836 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56837 +}
56838 +
56839 +int
56840 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56841 +{
56842 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56843 +}
56844 +
56845 +int gr_search_listen(struct socket *sock)
56846 +{
56847 + struct sock *sk = sock->sk;
56848 + struct sockaddr_in addr;
56849 +
56850 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56851 + addr.sin_port = inet_sk(sk)->inet_sport;
56852 +
56853 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56854 +}
56855 +
56856 +int gr_search_accept(struct socket *sock)
56857 +{
56858 + struct sock *sk = sock->sk;
56859 + struct sockaddr_in addr;
56860 +
56861 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56862 + addr.sin_port = inet_sk(sk)->inet_sport;
56863 +
56864 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56865 +}
56866 +
56867 +int
56868 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56869 +{
56870 + if (addr)
56871 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56872 + else {
56873 + struct sockaddr_in sin;
56874 + const struct inet_sock *inet = inet_sk(sk);
56875 +
56876 + sin.sin_addr.s_addr = inet->inet_daddr;
56877 + sin.sin_port = inet->inet_dport;
56878 +
56879 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56880 + }
56881 +}
56882 +
56883 +int
56884 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56885 +{
56886 + struct sockaddr_in sin;
56887 +
56888 + if (unlikely(skb->len < sizeof (struct udphdr)))
56889 + return 0; // skip this packet
56890 +
56891 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56892 + sin.sin_port = udp_hdr(skb)->source;
56893 +
56894 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56895 +}
56896 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56897 new file mode 100644
56898 index 0000000..25f54ef
56899 --- /dev/null
56900 +++ b/grsecurity/gracl_learn.c
56901 @@ -0,0 +1,207 @@
56902 +#include <linux/kernel.h>
56903 +#include <linux/mm.h>
56904 +#include <linux/sched.h>
56905 +#include <linux/poll.h>
56906 +#include <linux/string.h>
56907 +#include <linux/file.h>
56908 +#include <linux/types.h>
56909 +#include <linux/vmalloc.h>
56910 +#include <linux/grinternal.h>
56911 +
56912 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56913 + size_t count, loff_t *ppos);
56914 +extern int gr_acl_is_enabled(void);
56915 +
56916 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56917 +static int gr_learn_attached;
56918 +
56919 +/* use a 512k buffer */
56920 +#define LEARN_BUFFER_SIZE (512 * 1024)
56921 +
56922 +static DEFINE_SPINLOCK(gr_learn_lock);
56923 +static DEFINE_MUTEX(gr_learn_user_mutex);
56924 +
56925 +/* we need to maintain two buffers, so that the kernel context of grlearn
56926 + uses a semaphore around the userspace copying, and the other kernel contexts
56927 + use a spinlock when copying into the buffer, since they cannot sleep
56928 +*/
56929 +static char *learn_buffer;
56930 +static char *learn_buffer_user;
56931 +static int learn_buffer_len;
56932 +static int learn_buffer_user_len;
56933 +
56934 +static ssize_t
56935 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56936 +{
56937 + DECLARE_WAITQUEUE(wait, current);
56938 + ssize_t retval = 0;
56939 +
56940 + add_wait_queue(&learn_wait, &wait);
56941 + set_current_state(TASK_INTERRUPTIBLE);
56942 + do {
56943 + mutex_lock(&gr_learn_user_mutex);
56944 + spin_lock(&gr_learn_lock);
56945 + if (learn_buffer_len)
56946 + break;
56947 + spin_unlock(&gr_learn_lock);
56948 + mutex_unlock(&gr_learn_user_mutex);
56949 + if (file->f_flags & O_NONBLOCK) {
56950 + retval = -EAGAIN;
56951 + goto out;
56952 + }
56953 + if (signal_pending(current)) {
56954 + retval = -ERESTARTSYS;
56955 + goto out;
56956 + }
56957 +
56958 + schedule();
56959 + } while (1);
56960 +
56961 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56962 + learn_buffer_user_len = learn_buffer_len;
56963 + retval = learn_buffer_len;
56964 + learn_buffer_len = 0;
56965 +
56966 + spin_unlock(&gr_learn_lock);
56967 +
56968 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56969 + retval = -EFAULT;
56970 +
56971 + mutex_unlock(&gr_learn_user_mutex);
56972 +out:
56973 + set_current_state(TASK_RUNNING);
56974 + remove_wait_queue(&learn_wait, &wait);
56975 + return retval;
56976 +}
56977 +
56978 +static unsigned int
56979 +poll_learn(struct file * file, poll_table * wait)
56980 +{
56981 + poll_wait(file, &learn_wait, wait);
56982 +
56983 + if (learn_buffer_len)
56984 + return (POLLIN | POLLRDNORM);
56985 +
56986 + return 0;
56987 +}
56988 +
56989 +void
56990 +gr_clear_learn_entries(void)
56991 +{
56992 + char *tmp;
56993 +
56994 + mutex_lock(&gr_learn_user_mutex);
56995 + spin_lock(&gr_learn_lock);
56996 + tmp = learn_buffer;
56997 + learn_buffer = NULL;
56998 + spin_unlock(&gr_learn_lock);
56999 + if (tmp)
57000 + vfree(tmp);
57001 + if (learn_buffer_user != NULL) {
57002 + vfree(learn_buffer_user);
57003 + learn_buffer_user = NULL;
57004 + }
57005 + learn_buffer_len = 0;
57006 + mutex_unlock(&gr_learn_user_mutex);
57007 +
57008 + return;
57009 +}
57010 +
57011 +void
57012 +gr_add_learn_entry(const char *fmt, ...)
57013 +{
57014 + va_list args;
57015 + unsigned int len;
57016 +
57017 + if (!gr_learn_attached)
57018 + return;
57019 +
57020 + spin_lock(&gr_learn_lock);
57021 +
57022 + /* leave a gap at the end so we know when it's "full" but don't have to
57023 + compute the exact length of the string we're trying to append
57024 + */
57025 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57026 + spin_unlock(&gr_learn_lock);
57027 + wake_up_interruptible(&learn_wait);
57028 + return;
57029 + }
57030 + if (learn_buffer == NULL) {
57031 + spin_unlock(&gr_learn_lock);
57032 + return;
57033 + }
57034 +
57035 + va_start(args, fmt);
57036 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57037 + va_end(args);
57038 +
57039 + learn_buffer_len += len + 1;
57040 +
57041 + spin_unlock(&gr_learn_lock);
57042 + wake_up_interruptible(&learn_wait);
57043 +
57044 + return;
57045 +}
57046 +
57047 +static int
57048 +open_learn(struct inode *inode, struct file *file)
57049 +{
57050 + if (file->f_mode & FMODE_READ && gr_learn_attached)
57051 + return -EBUSY;
57052 + if (file->f_mode & FMODE_READ) {
57053 + int retval = 0;
57054 + mutex_lock(&gr_learn_user_mutex);
57055 + if (learn_buffer == NULL)
57056 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57057 + if (learn_buffer_user == NULL)
57058 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57059 + if (learn_buffer == NULL) {
57060 + retval = -ENOMEM;
57061 + goto out_error;
57062 + }
57063 + if (learn_buffer_user == NULL) {
57064 + retval = -ENOMEM;
57065 + goto out_error;
57066 + }
57067 + learn_buffer_len = 0;
57068 + learn_buffer_user_len = 0;
57069 + gr_learn_attached = 1;
57070 +out_error:
57071 + mutex_unlock(&gr_learn_user_mutex);
57072 + return retval;
57073 + }
57074 + return 0;
57075 +}
57076 +
57077 +static int
57078 +close_learn(struct inode *inode, struct file *file)
57079 +{
57080 + if (file->f_mode & FMODE_READ) {
57081 + char *tmp = NULL;
57082 + mutex_lock(&gr_learn_user_mutex);
57083 + spin_lock(&gr_learn_lock);
57084 + tmp = learn_buffer;
57085 + learn_buffer = NULL;
57086 + spin_unlock(&gr_learn_lock);
57087 + if (tmp)
57088 + vfree(tmp);
57089 + if (learn_buffer_user != NULL) {
57090 + vfree(learn_buffer_user);
57091 + learn_buffer_user = NULL;
57092 + }
57093 + learn_buffer_len = 0;
57094 + learn_buffer_user_len = 0;
57095 + gr_learn_attached = 0;
57096 + mutex_unlock(&gr_learn_user_mutex);
57097 + }
57098 +
57099 + return 0;
57100 +}
57101 +
57102 +const struct file_operations grsec_fops = {
57103 + .read = read_learn,
57104 + .write = write_grsec_handler,
57105 + .open = open_learn,
57106 + .release = close_learn,
57107 + .poll = poll_learn,
57108 +};
57109 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57110 new file mode 100644
57111 index 0000000..39645c9
57112 --- /dev/null
57113 +++ b/grsecurity/gracl_res.c
57114 @@ -0,0 +1,68 @@
57115 +#include <linux/kernel.h>
57116 +#include <linux/sched.h>
57117 +#include <linux/gracl.h>
57118 +#include <linux/grinternal.h>
57119 +
57120 +static const char *restab_log[] = {
57121 + [RLIMIT_CPU] = "RLIMIT_CPU",
57122 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57123 + [RLIMIT_DATA] = "RLIMIT_DATA",
57124 + [RLIMIT_STACK] = "RLIMIT_STACK",
57125 + [RLIMIT_CORE] = "RLIMIT_CORE",
57126 + [RLIMIT_RSS] = "RLIMIT_RSS",
57127 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57128 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57129 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57130 + [RLIMIT_AS] = "RLIMIT_AS",
57131 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57132 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57133 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57134 + [RLIMIT_NICE] = "RLIMIT_NICE",
57135 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57136 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57137 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57138 +};
57139 +
57140 +void
57141 +gr_log_resource(const struct task_struct *task,
57142 + const int res, const unsigned long wanted, const int gt)
57143 +{
57144 + const struct cred *cred;
57145 + unsigned long rlim;
57146 +
57147 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57148 + return;
57149 +
57150 + // not yet supported resource
57151 + if (unlikely(!restab_log[res]))
57152 + return;
57153 +
57154 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57155 + rlim = task_rlimit_max(task, res);
57156 + else
57157 + rlim = task_rlimit(task, res);
57158 +
57159 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57160 + return;
57161 +
57162 + rcu_read_lock();
57163 + cred = __task_cred(task);
57164 +
57165 + if (res == RLIMIT_NPROC &&
57166 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57167 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57168 + goto out_rcu_unlock;
57169 + else if (res == RLIMIT_MEMLOCK &&
57170 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57171 + goto out_rcu_unlock;
57172 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57173 + goto out_rcu_unlock;
57174 + rcu_read_unlock();
57175 +
57176 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57177 +
57178 + return;
57179 +out_rcu_unlock:
57180 + rcu_read_unlock();
57181 + return;
57182 +}
57183 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57184 new file mode 100644
57185 index 0000000..25197e9
57186 --- /dev/null
57187 +++ b/grsecurity/gracl_segv.c
57188 @@ -0,0 +1,299 @@
57189 +#include <linux/kernel.h>
57190 +#include <linux/mm.h>
57191 +#include <asm/uaccess.h>
57192 +#include <asm/errno.h>
57193 +#include <asm/mman.h>
57194 +#include <net/sock.h>
57195 +#include <linux/file.h>
57196 +#include <linux/fs.h>
57197 +#include <linux/net.h>
57198 +#include <linux/in.h>
57199 +#include <linux/slab.h>
57200 +#include <linux/types.h>
57201 +#include <linux/sched.h>
57202 +#include <linux/timer.h>
57203 +#include <linux/gracl.h>
57204 +#include <linux/grsecurity.h>
57205 +#include <linux/grinternal.h>
57206 +
57207 +static struct crash_uid *uid_set;
57208 +static unsigned short uid_used;
57209 +static DEFINE_SPINLOCK(gr_uid_lock);
57210 +extern rwlock_t gr_inode_lock;
57211 +extern struct acl_subject_label *
57212 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57213 + struct acl_role_label *role);
57214 +
57215 +#ifdef CONFIG_BTRFS_FS
57216 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57217 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57218 +#endif
57219 +
57220 +static inline dev_t __get_dev(const struct dentry *dentry)
57221 +{
57222 +#ifdef CONFIG_BTRFS_FS
57223 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57224 + return get_btrfs_dev_from_inode(dentry->d_inode);
57225 + else
57226 +#endif
57227 + return dentry->d_inode->i_sb->s_dev;
57228 +}
57229 +
57230 +int
57231 +gr_init_uidset(void)
57232 +{
57233 + uid_set =
57234 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57235 + uid_used = 0;
57236 +
57237 + return uid_set ? 1 : 0;
57238 +}
57239 +
57240 +void
57241 +gr_free_uidset(void)
57242 +{
57243 + if (uid_set)
57244 + kfree(uid_set);
57245 +
57246 + return;
57247 +}
57248 +
57249 +int
57250 +gr_find_uid(const uid_t uid)
57251 +{
57252 + struct crash_uid *tmp = uid_set;
57253 + uid_t buid;
57254 + int low = 0, high = uid_used - 1, mid;
57255 +
57256 + while (high >= low) {
57257 + mid = (low + high) >> 1;
57258 + buid = tmp[mid].uid;
57259 + if (buid == uid)
57260 + return mid;
57261 + if (buid > uid)
57262 + high = mid - 1;
57263 + if (buid < uid)
57264 + low = mid + 1;
57265 + }
57266 +
57267 + return -1;
57268 +}
57269 +
57270 +static __inline__ void
57271 +gr_insertsort(void)
57272 +{
57273 + unsigned short i, j;
57274 + struct crash_uid index;
57275 +
57276 + for (i = 1; i < uid_used; i++) {
57277 + index = uid_set[i];
57278 + j = i;
57279 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57280 + uid_set[j] = uid_set[j - 1];
57281 + j--;
57282 + }
57283 + uid_set[j] = index;
57284 + }
57285 +
57286 + return;
57287 +}
57288 +
57289 +static __inline__ void
57290 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57291 +{
57292 + int loc;
57293 +
57294 + if (uid_used == GR_UIDTABLE_MAX)
57295 + return;
57296 +
57297 + loc = gr_find_uid(uid);
57298 +
57299 + if (loc >= 0) {
57300 + uid_set[loc].expires = expires;
57301 + return;
57302 + }
57303 +
57304 + uid_set[uid_used].uid = uid;
57305 + uid_set[uid_used].expires = expires;
57306 + uid_used++;
57307 +
57308 + gr_insertsort();
57309 +
57310 + return;
57311 +}
57312 +
57313 +void
57314 +gr_remove_uid(const unsigned short loc)
57315 +{
57316 + unsigned short i;
57317 +
57318 + for (i = loc + 1; i < uid_used; i++)
57319 + uid_set[i - 1] = uid_set[i];
57320 +
57321 + uid_used--;
57322 +
57323 + return;
57324 +}
57325 +
57326 +int
57327 +gr_check_crash_uid(const uid_t uid)
57328 +{
57329 + int loc;
57330 + int ret = 0;
57331 +
57332 + if (unlikely(!gr_acl_is_enabled()))
57333 + return 0;
57334 +
57335 + spin_lock(&gr_uid_lock);
57336 + loc = gr_find_uid(uid);
57337 +
57338 + if (loc < 0)
57339 + goto out_unlock;
57340 +
57341 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57342 + gr_remove_uid(loc);
57343 + else
57344 + ret = 1;
57345 +
57346 +out_unlock:
57347 + spin_unlock(&gr_uid_lock);
57348 + return ret;
57349 +}
57350 +
57351 +static __inline__ int
57352 +proc_is_setxid(const struct cred *cred)
57353 +{
57354 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57355 + !uid_eq(cred->uid, cred->fsuid))
57356 + return 1;
57357 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57358 + !uid_eq(cred->gid, cred->fsgid))
57359 + return 1;
57360 +
57361 + return 0;
57362 +}
57363 +
57364 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57365 +
57366 +void
57367 +gr_handle_crash(struct task_struct *task, const int sig)
57368 +{
57369 + struct acl_subject_label *curr;
57370 + struct task_struct *tsk, *tsk2;
57371 + const struct cred *cred;
57372 + const struct cred *cred2;
57373 +
57374 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57375 + return;
57376 +
57377 + if (unlikely(!gr_acl_is_enabled()))
57378 + return;
57379 +
57380 + curr = task->acl;
57381 +
57382 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57383 + return;
57384 +
57385 + if (time_before_eq(curr->expires, get_seconds())) {
57386 + curr->expires = 0;
57387 + curr->crashes = 0;
57388 + }
57389 +
57390 + curr->crashes++;
57391 +
57392 + if (!curr->expires)
57393 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57394 +
57395 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57396 + time_after(curr->expires, get_seconds())) {
57397 + rcu_read_lock();
57398 + cred = __task_cred(task);
57399 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57400 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57401 + spin_lock(&gr_uid_lock);
57402 + gr_insert_uid(cred->uid, curr->expires);
57403 + spin_unlock(&gr_uid_lock);
57404 + curr->expires = 0;
57405 + curr->crashes = 0;
57406 + read_lock(&tasklist_lock);
57407 + do_each_thread(tsk2, tsk) {
57408 + cred2 = __task_cred(tsk);
57409 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57410 + gr_fake_force_sig(SIGKILL, tsk);
57411 + } while_each_thread(tsk2, tsk);
57412 + read_unlock(&tasklist_lock);
57413 + } else {
57414 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57415 + read_lock(&tasklist_lock);
57416 + read_lock(&grsec_exec_file_lock);
57417 + do_each_thread(tsk2, tsk) {
57418 + if (likely(tsk != task)) {
57419 + // if this thread has the same subject as the one that triggered
57420 + // RES_CRASH and it's the same binary, kill it
57421 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57422 + gr_fake_force_sig(SIGKILL, tsk);
57423 + }
57424 + } while_each_thread(tsk2, tsk);
57425 + read_unlock(&grsec_exec_file_lock);
57426 + read_unlock(&tasklist_lock);
57427 + }
57428 + rcu_read_unlock();
57429 + }
57430 +
57431 + return;
57432 +}
57433 +
57434 +int
57435 +gr_check_crash_exec(const struct file *filp)
57436 +{
57437 + struct acl_subject_label *curr;
57438 +
57439 + if (unlikely(!gr_acl_is_enabled()))
57440 + return 0;
57441 +
57442 + read_lock(&gr_inode_lock);
57443 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57444 + __get_dev(filp->f_path.dentry),
57445 + current->role);
57446 + read_unlock(&gr_inode_lock);
57447 +
57448 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57449 + (!curr->crashes && !curr->expires))
57450 + return 0;
57451 +
57452 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57453 + time_after(curr->expires, get_seconds()))
57454 + return 1;
57455 + else if (time_before_eq(curr->expires, get_seconds())) {
57456 + curr->crashes = 0;
57457 + curr->expires = 0;
57458 + }
57459 +
57460 + return 0;
57461 +}
57462 +
57463 +void
57464 +gr_handle_alertkill(struct task_struct *task)
57465 +{
57466 + struct acl_subject_label *curracl;
57467 + __u32 curr_ip;
57468 + struct task_struct *p, *p2;
57469 +
57470 + if (unlikely(!gr_acl_is_enabled()))
57471 + return;
57472 +
57473 + curracl = task->acl;
57474 + curr_ip = task->signal->curr_ip;
57475 +
57476 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57477 + read_lock(&tasklist_lock);
57478 + do_each_thread(p2, p) {
57479 + if (p->signal->curr_ip == curr_ip)
57480 + gr_fake_force_sig(SIGKILL, p);
57481 + } while_each_thread(p2, p);
57482 + read_unlock(&tasklist_lock);
57483 + } else if (curracl->mode & GR_KILLPROC)
57484 + gr_fake_force_sig(SIGKILL, task);
57485 +
57486 + return;
57487 +}
57488 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57489 new file mode 100644
57490 index 0000000..9d83a69
57491 --- /dev/null
57492 +++ b/grsecurity/gracl_shm.c
57493 @@ -0,0 +1,40 @@
57494 +#include <linux/kernel.h>
57495 +#include <linux/mm.h>
57496 +#include <linux/sched.h>
57497 +#include <linux/file.h>
57498 +#include <linux/ipc.h>
57499 +#include <linux/gracl.h>
57500 +#include <linux/grsecurity.h>
57501 +#include <linux/grinternal.h>
57502 +
57503 +int
57504 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57505 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57506 +{
57507 + struct task_struct *task;
57508 +
57509 + if (!gr_acl_is_enabled())
57510 + return 1;
57511 +
57512 + rcu_read_lock();
57513 + read_lock(&tasklist_lock);
57514 +
57515 + task = find_task_by_vpid(shm_cprid);
57516 +
57517 + if (unlikely(!task))
57518 + task = find_task_by_vpid(shm_lapid);
57519 +
57520 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57521 + (task->pid == shm_lapid)) &&
57522 + (task->acl->mode & GR_PROTSHM) &&
57523 + (task->acl != current->acl))) {
57524 + read_unlock(&tasklist_lock);
57525 + rcu_read_unlock();
57526 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57527 + return 0;
57528 + }
57529 + read_unlock(&tasklist_lock);
57530 + rcu_read_unlock();
57531 +
57532 + return 1;
57533 +}
57534 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57535 new file mode 100644
57536 index 0000000..bc0be01
57537 --- /dev/null
57538 +++ b/grsecurity/grsec_chdir.c
57539 @@ -0,0 +1,19 @@
57540 +#include <linux/kernel.h>
57541 +#include <linux/sched.h>
57542 +#include <linux/fs.h>
57543 +#include <linux/file.h>
57544 +#include <linux/grsecurity.h>
57545 +#include <linux/grinternal.h>
57546 +
57547 +void
57548 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57549 +{
57550 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57551 + if ((grsec_enable_chdir && grsec_enable_group &&
57552 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57553 + !grsec_enable_group)) {
57554 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57555 + }
57556 +#endif
57557 + return;
57558 +}
57559 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57560 new file mode 100644
57561 index 0000000..9807ee2
57562 --- /dev/null
57563 +++ b/grsecurity/grsec_chroot.c
57564 @@ -0,0 +1,368 @@
57565 +#include <linux/kernel.h>
57566 +#include <linux/module.h>
57567 +#include <linux/sched.h>
57568 +#include <linux/file.h>
57569 +#include <linux/fs.h>
57570 +#include <linux/mount.h>
57571 +#include <linux/types.h>
57572 +#include "../fs/mount.h"
57573 +#include <linux/grsecurity.h>
57574 +#include <linux/grinternal.h>
57575 +
57576 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57577 +{
57578 +#ifdef CONFIG_GRKERNSEC
57579 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57580 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57581 + task->gr_is_chrooted = 1;
57582 + else
57583 + task->gr_is_chrooted = 0;
57584 +
57585 + task->gr_chroot_dentry = path->dentry;
57586 +#endif
57587 + return;
57588 +}
57589 +
57590 +void gr_clear_chroot_entries(struct task_struct *task)
57591 +{
57592 +#ifdef CONFIG_GRKERNSEC
57593 + task->gr_is_chrooted = 0;
57594 + task->gr_chroot_dentry = NULL;
57595 +#endif
57596 + return;
57597 +}
57598 +
57599 +int
57600 +gr_handle_chroot_unix(const pid_t pid)
57601 +{
57602 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57603 + struct task_struct *p;
57604 +
57605 + if (unlikely(!grsec_enable_chroot_unix))
57606 + return 1;
57607 +
57608 + if (likely(!proc_is_chrooted(current)))
57609 + return 1;
57610 +
57611 + rcu_read_lock();
57612 + read_lock(&tasklist_lock);
57613 + p = find_task_by_vpid_unrestricted(pid);
57614 + if (unlikely(p && !have_same_root(current, p))) {
57615 + read_unlock(&tasklist_lock);
57616 + rcu_read_unlock();
57617 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57618 + return 0;
57619 + }
57620 + read_unlock(&tasklist_lock);
57621 + rcu_read_unlock();
57622 +#endif
57623 + return 1;
57624 +}
57625 +
57626 +int
57627 +gr_handle_chroot_nice(void)
57628 +{
57629 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57630 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57631 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57632 + return -EPERM;
57633 + }
57634 +#endif
57635 + return 0;
57636 +}
57637 +
57638 +int
57639 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57640 +{
57641 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57642 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57643 + && proc_is_chrooted(current)) {
57644 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57645 + return -EACCES;
57646 + }
57647 +#endif
57648 + return 0;
57649 +}
57650 +
57651 +int
57652 +gr_handle_chroot_rawio(const struct inode *inode)
57653 +{
57654 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57655 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57656 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57657 + return 1;
57658 +#endif
57659 + return 0;
57660 +}
57661 +
57662 +int
57663 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57664 +{
57665 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57666 + struct task_struct *p;
57667 + int ret = 0;
57668 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57669 + return ret;
57670 +
57671 + read_lock(&tasklist_lock);
57672 + do_each_pid_task(pid, type, p) {
57673 + if (!have_same_root(current, p)) {
57674 + ret = 1;
57675 + goto out;
57676 + }
57677 + } while_each_pid_task(pid, type, p);
57678 +out:
57679 + read_unlock(&tasklist_lock);
57680 + return ret;
57681 +#endif
57682 + return 0;
57683 +}
57684 +
57685 +int
57686 +gr_pid_is_chrooted(struct task_struct *p)
57687 +{
57688 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57689 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57690 + return 0;
57691 +
57692 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57693 + !have_same_root(current, p)) {
57694 + return 1;
57695 + }
57696 +#endif
57697 + return 0;
57698 +}
57699 +
57700 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57701 +
57702 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57703 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57704 +{
57705 + struct path path, currentroot;
57706 + int ret = 0;
57707 +
57708 + path.dentry = (struct dentry *)u_dentry;
57709 + path.mnt = (struct vfsmount *)u_mnt;
57710 + get_fs_root(current->fs, &currentroot);
57711 + if (path_is_under(&path, &currentroot))
57712 + ret = 1;
57713 + path_put(&currentroot);
57714 +
57715 + return ret;
57716 +}
57717 +#endif
57718 +
57719 +int
57720 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57721 +{
57722 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57723 + if (!grsec_enable_chroot_fchdir)
57724 + return 1;
57725 +
57726 + if (!proc_is_chrooted(current))
57727 + return 1;
57728 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57729 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57730 + return 0;
57731 + }
57732 +#endif
57733 + return 1;
57734 +}
57735 +
57736 +int
57737 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57738 + const time_t shm_createtime)
57739 +{
57740 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57741 + struct task_struct *p;
57742 + time_t starttime;
57743 +
57744 + if (unlikely(!grsec_enable_chroot_shmat))
57745 + return 1;
57746 +
57747 + if (likely(!proc_is_chrooted(current)))
57748 + return 1;
57749 +
57750 + rcu_read_lock();
57751 + read_lock(&tasklist_lock);
57752 +
57753 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57754 + starttime = p->start_time.tv_sec;
57755 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57756 + if (have_same_root(current, p)) {
57757 + goto allow;
57758 + } else {
57759 + read_unlock(&tasklist_lock);
57760 + rcu_read_unlock();
57761 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57762 + return 0;
57763 + }
57764 + }
57765 + /* creator exited, pid reuse, fall through to next check */
57766 + }
57767 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57768 + if (unlikely(!have_same_root(current, p))) {
57769 + read_unlock(&tasklist_lock);
57770 + rcu_read_unlock();
57771 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57772 + return 0;
57773 + }
57774 + }
57775 +
57776 +allow:
57777 + read_unlock(&tasklist_lock);
57778 + rcu_read_unlock();
57779 +#endif
57780 + return 1;
57781 +}
57782 +
57783 +void
57784 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57785 +{
57786 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57787 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57788 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57789 +#endif
57790 + return;
57791 +}
57792 +
57793 +int
57794 +gr_handle_chroot_mknod(const struct dentry *dentry,
57795 + const struct vfsmount *mnt, const int mode)
57796 +{
57797 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57798 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57799 + proc_is_chrooted(current)) {
57800 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57801 + return -EPERM;
57802 + }
57803 +#endif
57804 + return 0;
57805 +}
57806 +
57807 +int
57808 +gr_handle_chroot_mount(const struct dentry *dentry,
57809 + const struct vfsmount *mnt, const char *dev_name)
57810 +{
57811 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57812 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57813 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57814 + return -EPERM;
57815 + }
57816 +#endif
57817 + return 0;
57818 +}
57819 +
57820 +int
57821 +gr_handle_chroot_pivot(void)
57822 +{
57823 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57824 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57825 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57826 + return -EPERM;
57827 + }
57828 +#endif
57829 + return 0;
57830 +}
57831 +
57832 +int
57833 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57834 +{
57835 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57836 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57837 + !gr_is_outside_chroot(dentry, mnt)) {
57838 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57839 + return -EPERM;
57840 + }
57841 +#endif
57842 + return 0;
57843 +}
57844 +
57845 +extern const char *captab_log[];
57846 +extern int captab_log_entries;
57847 +
57848 +int
57849 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57850 +{
57851 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57852 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57853 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57854 + if (cap_raised(chroot_caps, cap)) {
57855 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57856 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57857 + }
57858 + return 0;
57859 + }
57860 + }
57861 +#endif
57862 + return 1;
57863 +}
57864 +
57865 +int
57866 +gr_chroot_is_capable(const int cap)
57867 +{
57868 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57869 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57870 +#endif
57871 + return 1;
57872 +}
57873 +
57874 +int
57875 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57876 +{
57877 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57878 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57879 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57880 + if (cap_raised(chroot_caps, cap)) {
57881 + return 0;
57882 + }
57883 + }
57884 +#endif
57885 + return 1;
57886 +}
57887 +
57888 +int
57889 +gr_chroot_is_capable_nolog(const int cap)
57890 +{
57891 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57892 + return gr_task_chroot_is_capable_nolog(current, cap);
57893 +#endif
57894 + return 1;
57895 +}
57896 +
57897 +int
57898 +gr_handle_chroot_sysctl(const int op)
57899 +{
57900 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57901 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57902 + proc_is_chrooted(current))
57903 + return -EACCES;
57904 +#endif
57905 + return 0;
57906 +}
57907 +
57908 +void
57909 +gr_handle_chroot_chdir(struct path *path)
57910 +{
57911 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57912 + if (grsec_enable_chroot_chdir)
57913 + set_fs_pwd(current->fs, path);
57914 +#endif
57915 + return;
57916 +}
57917 +
57918 +int
57919 +gr_handle_chroot_chmod(const struct dentry *dentry,
57920 + const struct vfsmount *mnt, const int mode)
57921 +{
57922 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57923 + /* allow chmod +s on directories, but not files */
57924 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57925 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57926 + proc_is_chrooted(current)) {
57927 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57928 + return -EPERM;
57929 + }
57930 +#endif
57931 + return 0;
57932 +}
57933 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57934 new file mode 100644
57935 index 0000000..7de2055
57936 --- /dev/null
57937 +++ b/grsecurity/grsec_disabled.c
57938 @@ -0,0 +1,442 @@
57939 +#include <linux/kernel.h>
57940 +#include <linux/module.h>
57941 +#include <linux/sched.h>
57942 +#include <linux/file.h>
57943 +#include <linux/fs.h>
57944 +#include <linux/kdev_t.h>
57945 +#include <linux/net.h>
57946 +#include <linux/in.h>
57947 +#include <linux/ip.h>
57948 +#include <linux/skbuff.h>
57949 +#include <linux/sysctl.h>
57950 +
57951 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57952 +void
57953 +pax_set_initial_flags(struct linux_binprm *bprm)
57954 +{
57955 + return;
57956 +}
57957 +#endif
57958 +
57959 +#ifdef CONFIG_SYSCTL
57960 +__u32
57961 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57962 +{
57963 + return 0;
57964 +}
57965 +#endif
57966 +
57967 +#ifdef CONFIG_TASKSTATS
57968 +int gr_is_taskstats_denied(int pid)
57969 +{
57970 + return 0;
57971 +}
57972 +#endif
57973 +
57974 +int
57975 +gr_acl_is_enabled(void)
57976 +{
57977 + return 0;
57978 +}
57979 +
57980 +void
57981 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57982 +{
57983 + return;
57984 +}
57985 +
57986 +int
57987 +gr_handle_rawio(const struct inode *inode)
57988 +{
57989 + return 0;
57990 +}
57991 +
57992 +void
57993 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57994 +{
57995 + return;
57996 +}
57997 +
57998 +int
57999 +gr_handle_ptrace(struct task_struct *task, const long request)
58000 +{
58001 + return 0;
58002 +}
58003 +
58004 +int
58005 +gr_handle_proc_ptrace(struct task_struct *task)
58006 +{
58007 + return 0;
58008 +}
58009 +
58010 +void
58011 +gr_learn_resource(const struct task_struct *task,
58012 + const int res, const unsigned long wanted, const int gt)
58013 +{
58014 + return;
58015 +}
58016 +
58017 +int
58018 +gr_set_acls(const int type)
58019 +{
58020 + return 0;
58021 +}
58022 +
58023 +int
58024 +gr_check_hidden_task(const struct task_struct *tsk)
58025 +{
58026 + return 0;
58027 +}
58028 +
58029 +int
58030 +gr_check_protected_task(const struct task_struct *task)
58031 +{
58032 + return 0;
58033 +}
58034 +
58035 +int
58036 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58037 +{
58038 + return 0;
58039 +}
58040 +
58041 +void
58042 +gr_copy_label(struct task_struct *tsk)
58043 +{
58044 + return;
58045 +}
58046 +
58047 +void
58048 +gr_set_pax_flags(struct task_struct *task)
58049 +{
58050 + return;
58051 +}
58052 +
58053 +int
58054 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58055 + const int unsafe_share)
58056 +{
58057 + return 0;
58058 +}
58059 +
58060 +void
58061 +gr_handle_delete(const ino_t ino, const dev_t dev)
58062 +{
58063 + return;
58064 +}
58065 +
58066 +void
58067 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58068 +{
58069 + return;
58070 +}
58071 +
58072 +void
58073 +gr_handle_crash(struct task_struct *task, const int sig)
58074 +{
58075 + return;
58076 +}
58077 +
58078 +int
58079 +gr_check_crash_exec(const struct file *filp)
58080 +{
58081 + return 0;
58082 +}
58083 +
58084 +int
58085 +gr_check_crash_uid(const uid_t uid)
58086 +{
58087 + return 0;
58088 +}
58089 +
58090 +void
58091 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58092 + struct dentry *old_dentry,
58093 + struct dentry *new_dentry,
58094 + struct vfsmount *mnt, const __u8 replace)
58095 +{
58096 + return;
58097 +}
58098 +
58099 +int
58100 +gr_search_socket(const int family, const int type, const int protocol)
58101 +{
58102 + return 1;
58103 +}
58104 +
58105 +int
58106 +gr_search_connectbind(const int mode, const struct socket *sock,
58107 + const struct sockaddr_in *addr)
58108 +{
58109 + return 0;
58110 +}
58111 +
58112 +void
58113 +gr_handle_alertkill(struct task_struct *task)
58114 +{
58115 + return;
58116 +}
58117 +
58118 +__u32
58119 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58120 +{
58121 + return 1;
58122 +}
58123 +
58124 +__u32
58125 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58126 + const struct vfsmount * mnt)
58127 +{
58128 + return 1;
58129 +}
58130 +
58131 +__u32
58132 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58133 + int acc_mode)
58134 +{
58135 + return 1;
58136 +}
58137 +
58138 +__u32
58139 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58140 +{
58141 + return 1;
58142 +}
58143 +
58144 +__u32
58145 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58146 +{
58147 + return 1;
58148 +}
58149 +
58150 +int
58151 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58152 + unsigned int *vm_flags)
58153 +{
58154 + return 1;
58155 +}
58156 +
58157 +__u32
58158 +gr_acl_handle_truncate(const struct dentry * dentry,
58159 + const struct vfsmount * mnt)
58160 +{
58161 + return 1;
58162 +}
58163 +
58164 +__u32
58165 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58166 +{
58167 + return 1;
58168 +}
58169 +
58170 +__u32
58171 +gr_acl_handle_access(const struct dentry * dentry,
58172 + const struct vfsmount * mnt, const int fmode)
58173 +{
58174 + return 1;
58175 +}
58176 +
58177 +__u32
58178 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58179 + umode_t *mode)
58180 +{
58181 + return 1;
58182 +}
58183 +
58184 +__u32
58185 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58186 +{
58187 + return 1;
58188 +}
58189 +
58190 +__u32
58191 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58192 +{
58193 + return 1;
58194 +}
58195 +
58196 +void
58197 +grsecurity_init(void)
58198 +{
58199 + return;
58200 +}
58201 +
58202 +umode_t gr_acl_umask(void)
58203 +{
58204 + return 0;
58205 +}
58206 +
58207 +__u32
58208 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58209 + const struct dentry * parent_dentry,
58210 + const struct vfsmount * parent_mnt,
58211 + const int mode)
58212 +{
58213 + return 1;
58214 +}
58215 +
58216 +__u32
58217 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58218 + const struct dentry * parent_dentry,
58219 + const struct vfsmount * parent_mnt)
58220 +{
58221 + return 1;
58222 +}
58223 +
58224 +__u32
58225 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58226 + const struct dentry * parent_dentry,
58227 + const struct vfsmount * parent_mnt, const struct filename *from)
58228 +{
58229 + return 1;
58230 +}
58231 +
58232 +__u32
58233 +gr_acl_handle_link(const struct dentry * new_dentry,
58234 + const struct dentry * parent_dentry,
58235 + const struct vfsmount * parent_mnt,
58236 + const struct dentry * old_dentry,
58237 + const struct vfsmount * old_mnt, const struct filename *to)
58238 +{
58239 + return 1;
58240 +}
58241 +
58242 +int
58243 +gr_acl_handle_rename(const struct dentry *new_dentry,
58244 + const struct dentry *parent_dentry,
58245 + const struct vfsmount *parent_mnt,
58246 + const struct dentry *old_dentry,
58247 + const struct inode *old_parent_inode,
58248 + const struct vfsmount *old_mnt, const struct filename *newname)
58249 +{
58250 + return 0;
58251 +}
58252 +
58253 +int
58254 +gr_acl_handle_filldir(const struct file *file, const char *name,
58255 + const int namelen, const ino_t ino)
58256 +{
58257 + return 1;
58258 +}
58259 +
58260 +int
58261 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58262 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58263 +{
58264 + return 1;
58265 +}
58266 +
58267 +int
58268 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58269 +{
58270 + return 0;
58271 +}
58272 +
58273 +int
58274 +gr_search_accept(const struct socket *sock)
58275 +{
58276 + return 0;
58277 +}
58278 +
58279 +int
58280 +gr_search_listen(const struct socket *sock)
58281 +{
58282 + return 0;
58283 +}
58284 +
58285 +int
58286 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58287 +{
58288 + return 0;
58289 +}
58290 +
58291 +__u32
58292 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58293 +{
58294 + return 1;
58295 +}
58296 +
58297 +__u32
58298 +gr_acl_handle_creat(const struct dentry * dentry,
58299 + const struct dentry * p_dentry,
58300 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58301 + const int imode)
58302 +{
58303 + return 1;
58304 +}
58305 +
58306 +void
58307 +gr_acl_handle_exit(void)
58308 +{
58309 + return;
58310 +}
58311 +
58312 +int
58313 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58314 +{
58315 + return 1;
58316 +}
58317 +
58318 +void
58319 +gr_set_role_label(const uid_t uid, const gid_t gid)
58320 +{
58321 + return;
58322 +}
58323 +
58324 +int
58325 +gr_acl_handle_procpidmem(const struct task_struct *task)
58326 +{
58327 + return 0;
58328 +}
58329 +
58330 +int
58331 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58332 +{
58333 + return 0;
58334 +}
58335 +
58336 +int
58337 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58338 +{
58339 + return 0;
58340 +}
58341 +
58342 +void
58343 +gr_set_kernel_label(struct task_struct *task)
58344 +{
58345 + return;
58346 +}
58347 +
58348 +int
58349 +gr_check_user_change(int real, int effective, int fs)
58350 +{
58351 + return 0;
58352 +}
58353 +
58354 +int
58355 +gr_check_group_change(int real, int effective, int fs)
58356 +{
58357 + return 0;
58358 +}
58359 +
58360 +int gr_acl_enable_at_secure(void)
58361 +{
58362 + return 0;
58363 +}
58364 +
58365 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58366 +{
58367 + return dentry->d_inode->i_sb->s_dev;
58368 +}
58369 +
58370 +void gr_put_exec_file(struct task_struct *task)
58371 +{
58372 + return;
58373 +}
58374 +
58375 +EXPORT_SYMBOL(gr_learn_resource);
58376 +EXPORT_SYMBOL(gr_set_kernel_label);
58377 +#ifdef CONFIG_SECURITY
58378 +EXPORT_SYMBOL(gr_check_user_change);
58379 +EXPORT_SYMBOL(gr_check_group_change);
58380 +#endif
58381 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58382 new file mode 100644
58383 index 0000000..abfa971
58384 --- /dev/null
58385 +++ b/grsecurity/grsec_exec.c
58386 @@ -0,0 +1,174 @@
58387 +#include <linux/kernel.h>
58388 +#include <linux/sched.h>
58389 +#include <linux/file.h>
58390 +#include <linux/binfmts.h>
58391 +#include <linux/fs.h>
58392 +#include <linux/types.h>
58393 +#include <linux/grdefs.h>
58394 +#include <linux/grsecurity.h>
58395 +#include <linux/grinternal.h>
58396 +#include <linux/capability.h>
58397 +#include <linux/module.h>
58398 +
58399 +#include <asm/uaccess.h>
58400 +
58401 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58402 +static char gr_exec_arg_buf[132];
58403 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58404 +#endif
58405 +
58406 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58407 +
58408 +void
58409 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58410 +{
58411 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58412 + char *grarg = gr_exec_arg_buf;
58413 + unsigned int i, x, execlen = 0;
58414 + char c;
58415 +
58416 + if (!((grsec_enable_execlog && grsec_enable_group &&
58417 + in_group_p(grsec_audit_gid))
58418 + || (grsec_enable_execlog && !grsec_enable_group)))
58419 + return;
58420 +
58421 + mutex_lock(&gr_exec_arg_mutex);
58422 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58423 +
58424 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58425 + const char __user *p;
58426 + unsigned int len;
58427 +
58428 + p = get_user_arg_ptr(argv, i);
58429 + if (IS_ERR(p))
58430 + goto log;
58431 +
58432 + len = strnlen_user(p, 128 - execlen);
58433 + if (len > 128 - execlen)
58434 + len = 128 - execlen;
58435 + else if (len > 0)
58436 + len--;
58437 + if (copy_from_user(grarg + execlen, p, len))
58438 + goto log;
58439 +
58440 + /* rewrite unprintable characters */
58441 + for (x = 0; x < len; x++) {
58442 + c = *(grarg + execlen + x);
58443 + if (c < 32 || c > 126)
58444 + *(grarg + execlen + x) = ' ';
58445 + }
58446 +
58447 + execlen += len;
58448 + *(grarg + execlen) = ' ';
58449 + *(grarg + execlen + 1) = '\0';
58450 + execlen++;
58451 + }
58452 +
58453 + log:
58454 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58455 + bprm->file->f_path.mnt, grarg);
58456 + mutex_unlock(&gr_exec_arg_mutex);
58457 +#endif
58458 + return;
58459 +}
58460 +
58461 +#ifdef CONFIG_GRKERNSEC
58462 +extern int gr_acl_is_capable(const int cap);
58463 +extern int gr_acl_is_capable_nolog(const int cap);
58464 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58465 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58466 +extern int gr_chroot_is_capable(const int cap);
58467 +extern int gr_chroot_is_capable_nolog(const int cap);
58468 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58469 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58470 +#endif
58471 +
58472 +const char *captab_log[] = {
58473 + "CAP_CHOWN",
58474 + "CAP_DAC_OVERRIDE",
58475 + "CAP_DAC_READ_SEARCH",
58476 + "CAP_FOWNER",
58477 + "CAP_FSETID",
58478 + "CAP_KILL",
58479 + "CAP_SETGID",
58480 + "CAP_SETUID",
58481 + "CAP_SETPCAP",
58482 + "CAP_LINUX_IMMUTABLE",
58483 + "CAP_NET_BIND_SERVICE",
58484 + "CAP_NET_BROADCAST",
58485 + "CAP_NET_ADMIN",
58486 + "CAP_NET_RAW",
58487 + "CAP_IPC_LOCK",
58488 + "CAP_IPC_OWNER",
58489 + "CAP_SYS_MODULE",
58490 + "CAP_SYS_RAWIO",
58491 + "CAP_SYS_CHROOT",
58492 + "CAP_SYS_PTRACE",
58493 + "CAP_SYS_PACCT",
58494 + "CAP_SYS_ADMIN",
58495 + "CAP_SYS_BOOT",
58496 + "CAP_SYS_NICE",
58497 + "CAP_SYS_RESOURCE",
58498 + "CAP_SYS_TIME",
58499 + "CAP_SYS_TTY_CONFIG",
58500 + "CAP_MKNOD",
58501 + "CAP_LEASE",
58502 + "CAP_AUDIT_WRITE",
58503 + "CAP_AUDIT_CONTROL",
58504 + "CAP_SETFCAP",
58505 + "CAP_MAC_OVERRIDE",
58506 + "CAP_MAC_ADMIN",
58507 + "CAP_SYSLOG",
58508 + "CAP_WAKE_ALARM"
58509 +};
58510 +
58511 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58512 +
58513 +int gr_is_capable(const int cap)
58514 +{
58515 +#ifdef CONFIG_GRKERNSEC
58516 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58517 + return 1;
58518 + return 0;
58519 +#else
58520 + return 1;
58521 +#endif
58522 +}
58523 +
58524 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58525 +{
58526 +#ifdef CONFIG_GRKERNSEC
58527 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58528 + return 1;
58529 + return 0;
58530 +#else
58531 + return 1;
58532 +#endif
58533 +}
58534 +
58535 +int gr_is_capable_nolog(const int cap)
58536 +{
58537 +#ifdef CONFIG_GRKERNSEC
58538 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58539 + return 1;
58540 + return 0;
58541 +#else
58542 + return 1;
58543 +#endif
58544 +}
58545 +
58546 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58547 +{
58548 +#ifdef CONFIG_GRKERNSEC
58549 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58550 + return 1;
58551 + return 0;
58552 +#else
58553 + return 1;
58554 +#endif
58555 +}
58556 +
58557 +EXPORT_SYMBOL(gr_is_capable);
58558 +EXPORT_SYMBOL(gr_is_capable_nolog);
58559 +EXPORT_SYMBOL(gr_task_is_capable);
58560 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58561 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58562 new file mode 100644
58563 index 0000000..d3ee748
58564 --- /dev/null
58565 +++ b/grsecurity/grsec_fifo.c
58566 @@ -0,0 +1,24 @@
58567 +#include <linux/kernel.h>
58568 +#include <linux/sched.h>
58569 +#include <linux/fs.h>
58570 +#include <linux/file.h>
58571 +#include <linux/grinternal.h>
58572 +
58573 +int
58574 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58575 + const struct dentry *dir, const int flag, const int acc_mode)
58576 +{
58577 +#ifdef CONFIG_GRKERNSEC_FIFO
58578 + const struct cred *cred = current_cred();
58579 +
58580 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58581 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58582 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58583 + (cred->fsuid != dentry->d_inode->i_uid)) {
58584 + if (!inode_permission(dentry->d_inode, acc_mode))
58585 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58586 + return -EACCES;
58587 + }
58588 +#endif
58589 + return 0;
58590 +}
58591 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58592 new file mode 100644
58593 index 0000000..8ca18bf
58594 --- /dev/null
58595 +++ b/grsecurity/grsec_fork.c
58596 @@ -0,0 +1,23 @@
58597 +#include <linux/kernel.h>
58598 +#include <linux/sched.h>
58599 +#include <linux/grsecurity.h>
58600 +#include <linux/grinternal.h>
58601 +#include <linux/errno.h>
58602 +
58603 +void
58604 +gr_log_forkfail(const int retval)
58605 +{
58606 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58607 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58608 + switch (retval) {
58609 + case -EAGAIN:
58610 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58611 + break;
58612 + case -ENOMEM:
58613 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58614 + break;
58615 + }
58616 + }
58617 +#endif
58618 + return;
58619 +}
58620 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58621 new file mode 100644
58622 index 0000000..05a6015
58623 --- /dev/null
58624 +++ b/grsecurity/grsec_init.c
58625 @@ -0,0 +1,283 @@
58626 +#include <linux/kernel.h>
58627 +#include <linux/sched.h>
58628 +#include <linux/mm.h>
58629 +#include <linux/gracl.h>
58630 +#include <linux/slab.h>
58631 +#include <linux/vmalloc.h>
58632 +#include <linux/percpu.h>
58633 +#include <linux/module.h>
58634 +
58635 +int grsec_enable_ptrace_readexec;
58636 +int grsec_enable_setxid;
58637 +int grsec_enable_symlinkown;
58638 +int grsec_symlinkown_gid;
58639 +int grsec_enable_brute;
58640 +int grsec_enable_link;
58641 +int grsec_enable_dmesg;
58642 +int grsec_enable_harden_ptrace;
58643 +int grsec_enable_fifo;
58644 +int grsec_enable_execlog;
58645 +int grsec_enable_signal;
58646 +int grsec_enable_forkfail;
58647 +int grsec_enable_audit_ptrace;
58648 +int grsec_enable_time;
58649 +int grsec_enable_audit_textrel;
58650 +int grsec_enable_group;
58651 +int grsec_audit_gid;
58652 +int grsec_enable_chdir;
58653 +int grsec_enable_mount;
58654 +int grsec_enable_rofs;
58655 +int grsec_enable_chroot_findtask;
58656 +int grsec_enable_chroot_mount;
58657 +int grsec_enable_chroot_shmat;
58658 +int grsec_enable_chroot_fchdir;
58659 +int grsec_enable_chroot_double;
58660 +int grsec_enable_chroot_pivot;
58661 +int grsec_enable_chroot_chdir;
58662 +int grsec_enable_chroot_chmod;
58663 +int grsec_enable_chroot_mknod;
58664 +int grsec_enable_chroot_nice;
58665 +int grsec_enable_chroot_execlog;
58666 +int grsec_enable_chroot_caps;
58667 +int grsec_enable_chroot_sysctl;
58668 +int grsec_enable_chroot_unix;
58669 +int grsec_enable_tpe;
58670 +int grsec_tpe_gid;
58671 +int grsec_enable_blackhole;
58672 +#ifdef CONFIG_IPV6_MODULE
58673 +EXPORT_SYMBOL(grsec_enable_blackhole);
58674 +#endif
58675 +int grsec_lastack_retries;
58676 +int grsec_enable_tpe_all;
58677 +int grsec_enable_tpe_invert;
58678 +int grsec_enable_socket_all;
58679 +int grsec_socket_all_gid;
58680 +int grsec_enable_socket_client;
58681 +int grsec_socket_client_gid;
58682 +int grsec_enable_socket_server;
58683 +int grsec_socket_server_gid;
58684 +int grsec_resource_logging;
58685 +int grsec_disable_privio;
58686 +int grsec_enable_log_rwxmaps;
58687 +int grsec_lock;
58688 +
58689 +DEFINE_SPINLOCK(grsec_alert_lock);
58690 +unsigned long grsec_alert_wtime = 0;
58691 +unsigned long grsec_alert_fyet = 0;
58692 +
58693 +DEFINE_SPINLOCK(grsec_audit_lock);
58694 +
58695 +DEFINE_RWLOCK(grsec_exec_file_lock);
58696 +
58697 +char *gr_shared_page[4];
58698 +
58699 +char *gr_alert_log_fmt;
58700 +char *gr_audit_log_fmt;
58701 +char *gr_alert_log_buf;
58702 +char *gr_audit_log_buf;
58703 +
58704 +extern struct gr_arg *gr_usermode;
58705 +extern unsigned char *gr_system_salt;
58706 +extern unsigned char *gr_system_sum;
58707 +
58708 +void __init
58709 +grsecurity_init(void)
58710 +{
58711 + int j;
58712 + /* create the per-cpu shared pages */
58713 +
58714 +#ifdef CONFIG_X86
58715 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58716 +#endif
58717 +
58718 + for (j = 0; j < 4; j++) {
58719 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58720 + if (gr_shared_page[j] == NULL) {
58721 + panic("Unable to allocate grsecurity shared page");
58722 + return;
58723 + }
58724 + }
58725 +
58726 + /* allocate log buffers */
58727 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58728 + if (!gr_alert_log_fmt) {
58729 + panic("Unable to allocate grsecurity alert log format buffer");
58730 + return;
58731 + }
58732 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58733 + if (!gr_audit_log_fmt) {
58734 + panic("Unable to allocate grsecurity audit log format buffer");
58735 + return;
58736 + }
58737 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58738 + if (!gr_alert_log_buf) {
58739 + panic("Unable to allocate grsecurity alert log buffer");
58740 + return;
58741 + }
58742 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58743 + if (!gr_audit_log_buf) {
58744 + panic("Unable to allocate grsecurity audit log buffer");
58745 + return;
58746 + }
58747 +
58748 + /* allocate memory for authentication structure */
58749 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58750 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58751 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58752 +
58753 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58754 + panic("Unable to allocate grsecurity authentication structure");
58755 + return;
58756 + }
58757 +
58758 +
58759 +#ifdef CONFIG_GRKERNSEC_IO
58760 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58761 + grsec_disable_privio = 1;
58762 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58763 + grsec_disable_privio = 1;
58764 +#else
58765 + grsec_disable_privio = 0;
58766 +#endif
58767 +#endif
58768 +
58769 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58770 + /* for backward compatibility, tpe_invert always defaults to on if
58771 + enabled in the kernel
58772 + */
58773 + grsec_enable_tpe_invert = 1;
58774 +#endif
58775 +
58776 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58777 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58778 + grsec_lock = 1;
58779 +#endif
58780 +
58781 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58782 + grsec_enable_audit_textrel = 1;
58783 +#endif
58784 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58785 + grsec_enable_log_rwxmaps = 1;
58786 +#endif
58787 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58788 + grsec_enable_group = 1;
58789 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58790 +#endif
58791 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58792 + grsec_enable_ptrace_readexec = 1;
58793 +#endif
58794 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58795 + grsec_enable_chdir = 1;
58796 +#endif
58797 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58798 + grsec_enable_harden_ptrace = 1;
58799 +#endif
58800 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58801 + grsec_enable_mount = 1;
58802 +#endif
58803 +#ifdef CONFIG_GRKERNSEC_LINK
58804 + grsec_enable_link = 1;
58805 +#endif
58806 +#ifdef CONFIG_GRKERNSEC_BRUTE
58807 + grsec_enable_brute = 1;
58808 +#endif
58809 +#ifdef CONFIG_GRKERNSEC_DMESG
58810 + grsec_enable_dmesg = 1;
58811 +#endif
58812 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58813 + grsec_enable_blackhole = 1;
58814 + grsec_lastack_retries = 4;
58815 +#endif
58816 +#ifdef CONFIG_GRKERNSEC_FIFO
58817 + grsec_enable_fifo = 1;
58818 +#endif
58819 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58820 + grsec_enable_execlog = 1;
58821 +#endif
58822 +#ifdef CONFIG_GRKERNSEC_SETXID
58823 + grsec_enable_setxid = 1;
58824 +#endif
58825 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58826 + grsec_enable_signal = 1;
58827 +#endif
58828 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58829 + grsec_enable_forkfail = 1;
58830 +#endif
58831 +#ifdef CONFIG_GRKERNSEC_TIME
58832 + grsec_enable_time = 1;
58833 +#endif
58834 +#ifdef CONFIG_GRKERNSEC_RESLOG
58835 + grsec_resource_logging = 1;
58836 +#endif
58837 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58838 + grsec_enable_chroot_findtask = 1;
58839 +#endif
58840 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58841 + grsec_enable_chroot_unix = 1;
58842 +#endif
58843 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58844 + grsec_enable_chroot_mount = 1;
58845 +#endif
58846 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58847 + grsec_enable_chroot_fchdir = 1;
58848 +#endif
58849 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58850 + grsec_enable_chroot_shmat = 1;
58851 +#endif
58852 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58853 + grsec_enable_audit_ptrace = 1;
58854 +#endif
58855 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58856 + grsec_enable_chroot_double = 1;
58857 +#endif
58858 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58859 + grsec_enable_chroot_pivot = 1;
58860 +#endif
58861 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58862 + grsec_enable_chroot_chdir = 1;
58863 +#endif
58864 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58865 + grsec_enable_chroot_chmod = 1;
58866 +#endif
58867 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58868 + grsec_enable_chroot_mknod = 1;
58869 +#endif
58870 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58871 + grsec_enable_chroot_nice = 1;
58872 +#endif
58873 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58874 + grsec_enable_chroot_execlog = 1;
58875 +#endif
58876 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58877 + grsec_enable_chroot_caps = 1;
58878 +#endif
58879 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58880 + grsec_enable_chroot_sysctl = 1;
58881 +#endif
58882 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58883 + grsec_enable_symlinkown = 1;
58884 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58885 +#endif
58886 +#ifdef CONFIG_GRKERNSEC_TPE
58887 + grsec_enable_tpe = 1;
58888 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58889 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58890 + grsec_enable_tpe_all = 1;
58891 +#endif
58892 +#endif
58893 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58894 + grsec_enable_socket_all = 1;
58895 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58896 +#endif
58897 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58898 + grsec_enable_socket_client = 1;
58899 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58900 +#endif
58901 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58902 + grsec_enable_socket_server = 1;
58903 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58904 +#endif
58905 +#endif
58906 +
58907 + return;
58908 +}
58909 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58910 new file mode 100644
58911 index 0000000..6095407
58912 --- /dev/null
58913 +++ b/grsecurity/grsec_link.c
58914 @@ -0,0 +1,58 @@
58915 +#include <linux/kernel.h>
58916 +#include <linux/sched.h>
58917 +#include <linux/fs.h>
58918 +#include <linux/file.h>
58919 +#include <linux/grinternal.h>
58920 +
58921 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58922 +{
58923 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58924 + const struct inode *link_inode = link->dentry->d_inode;
58925 +
58926 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58927 + /* ignore root-owned links, e.g. /proc/self */
58928 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58929 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58930 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58931 + return 1;
58932 + }
58933 +#endif
58934 + return 0;
58935 +}
58936 +
58937 +int
58938 +gr_handle_follow_link(const struct inode *parent,
58939 + const struct inode *inode,
58940 + const struct dentry *dentry, const struct vfsmount *mnt)
58941 +{
58942 +#ifdef CONFIG_GRKERNSEC_LINK
58943 + const struct cred *cred = current_cred();
58944 +
58945 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58946 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58947 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58948 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58949 + return -EACCES;
58950 + }
58951 +#endif
58952 + return 0;
58953 +}
58954 +
58955 +int
58956 +gr_handle_hardlink(const struct dentry *dentry,
58957 + const struct vfsmount *mnt,
58958 + struct inode *inode, const int mode, const struct filename *to)
58959 +{
58960 +#ifdef CONFIG_GRKERNSEC_LINK
58961 + const struct cred *cred = current_cred();
58962 +
58963 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58964 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58965 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58966 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58967 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
58968 + return -EPERM;
58969 + }
58970 +#endif
58971 + return 0;
58972 +}
58973 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58974 new file mode 100644
58975 index 0000000..a45d2e9
58976 --- /dev/null
58977 +++ b/grsecurity/grsec_log.c
58978 @@ -0,0 +1,322 @@
58979 +#include <linux/kernel.h>
58980 +#include <linux/sched.h>
58981 +#include <linux/file.h>
58982 +#include <linux/tty.h>
58983 +#include <linux/fs.h>
58984 +#include <linux/grinternal.h>
58985 +
58986 +#ifdef CONFIG_TREE_PREEMPT_RCU
58987 +#define DISABLE_PREEMPT() preempt_disable()
58988 +#define ENABLE_PREEMPT() preempt_enable()
58989 +#else
58990 +#define DISABLE_PREEMPT()
58991 +#define ENABLE_PREEMPT()
58992 +#endif
58993 +
58994 +#define BEGIN_LOCKS(x) \
58995 + DISABLE_PREEMPT(); \
58996 + rcu_read_lock(); \
58997 + read_lock(&tasklist_lock); \
58998 + read_lock(&grsec_exec_file_lock); \
58999 + if (x != GR_DO_AUDIT) \
59000 + spin_lock(&grsec_alert_lock); \
59001 + else \
59002 + spin_lock(&grsec_audit_lock)
59003 +
59004 +#define END_LOCKS(x) \
59005 + if (x != GR_DO_AUDIT) \
59006 + spin_unlock(&grsec_alert_lock); \
59007 + else \
59008 + spin_unlock(&grsec_audit_lock); \
59009 + read_unlock(&grsec_exec_file_lock); \
59010 + read_unlock(&tasklist_lock); \
59011 + rcu_read_unlock(); \
59012 + ENABLE_PREEMPT(); \
59013 + if (x == GR_DONT_AUDIT) \
59014 + gr_handle_alertkill(current)
59015 +
59016 +enum {
59017 + FLOODING,
59018 + NO_FLOODING
59019 +};
59020 +
59021 +extern char *gr_alert_log_fmt;
59022 +extern char *gr_audit_log_fmt;
59023 +extern char *gr_alert_log_buf;
59024 +extern char *gr_audit_log_buf;
59025 +
59026 +static int gr_log_start(int audit)
59027 +{
59028 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
59029 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
59030 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59031 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
59032 + unsigned long curr_secs = get_seconds();
59033 +
59034 + if (audit == GR_DO_AUDIT)
59035 + goto set_fmt;
59036 +
59037 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59038 + grsec_alert_wtime = curr_secs;
59039 + grsec_alert_fyet = 0;
59040 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59041 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59042 + grsec_alert_fyet++;
59043 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59044 + grsec_alert_wtime = curr_secs;
59045 + grsec_alert_fyet++;
59046 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59047 + return FLOODING;
59048 + }
59049 + else return FLOODING;
59050 +
59051 +set_fmt:
59052 +#endif
59053 + memset(buf, 0, PAGE_SIZE);
59054 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
59055 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59056 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59057 + } else if (current->signal->curr_ip) {
59058 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59059 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59060 + } else if (gr_acl_is_enabled()) {
59061 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59062 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59063 + } else {
59064 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59065 + strcpy(buf, fmt);
59066 + }
59067 +
59068 + return NO_FLOODING;
59069 +}
59070 +
59071 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59072 + __attribute__ ((format (printf, 2, 0)));
59073 +
59074 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59075 +{
59076 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59077 + unsigned int len = strlen(buf);
59078 +
59079 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59080 +
59081 + return;
59082 +}
59083 +
59084 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59085 + __attribute__ ((format (printf, 2, 3)));
59086 +
59087 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59088 +{
59089 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59090 + unsigned int len = strlen(buf);
59091 + va_list ap;
59092 +
59093 + va_start(ap, msg);
59094 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59095 + va_end(ap);
59096 +
59097 + return;
59098 +}
59099 +
59100 +static void gr_log_end(int audit, int append_default)
59101 +{
59102 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59103 +
59104 + if (append_default) {
59105 + unsigned int len = strlen(buf);
59106 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59107 + }
59108 +
59109 + printk("%s\n", buf);
59110 +
59111 + return;
59112 +}
59113 +
59114 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59115 +{
59116 + int logtype;
59117 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59118 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59119 + void *voidptr = NULL;
59120 + int num1 = 0, num2 = 0;
59121 + unsigned long ulong1 = 0, ulong2 = 0;
59122 + struct dentry *dentry = NULL;
59123 + struct vfsmount *mnt = NULL;
59124 + struct file *file = NULL;
59125 + struct task_struct *task = NULL;
59126 + const struct cred *cred, *pcred;
59127 + va_list ap;
59128 +
59129 + BEGIN_LOCKS(audit);
59130 + logtype = gr_log_start(audit);
59131 + if (logtype == FLOODING) {
59132 + END_LOCKS(audit);
59133 + return;
59134 + }
59135 + va_start(ap, argtypes);
59136 + switch (argtypes) {
59137 + case GR_TTYSNIFF:
59138 + task = va_arg(ap, struct task_struct *);
59139 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
59140 + break;
59141 + case GR_SYSCTL_HIDDEN:
59142 + str1 = va_arg(ap, char *);
59143 + gr_log_middle_varargs(audit, msg, result, str1);
59144 + break;
59145 + case GR_RBAC:
59146 + dentry = va_arg(ap, struct dentry *);
59147 + mnt = va_arg(ap, struct vfsmount *);
59148 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59149 + break;
59150 + case GR_RBAC_STR:
59151 + dentry = va_arg(ap, struct dentry *);
59152 + mnt = va_arg(ap, struct vfsmount *);
59153 + str1 = va_arg(ap, char *);
59154 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59155 + break;
59156 + case GR_STR_RBAC:
59157 + str1 = va_arg(ap, char *);
59158 + dentry = va_arg(ap, struct dentry *);
59159 + mnt = va_arg(ap, struct vfsmount *);
59160 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59161 + break;
59162 + case GR_RBAC_MODE2:
59163 + dentry = va_arg(ap, struct dentry *);
59164 + mnt = va_arg(ap, struct vfsmount *);
59165 + str1 = va_arg(ap, char *);
59166 + str2 = va_arg(ap, char *);
59167 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59168 + break;
59169 + case GR_RBAC_MODE3:
59170 + dentry = va_arg(ap, struct dentry *);
59171 + mnt = va_arg(ap, struct vfsmount *);
59172 + str1 = va_arg(ap, char *);
59173 + str2 = va_arg(ap, char *);
59174 + str3 = va_arg(ap, char *);
59175 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59176 + break;
59177 + case GR_FILENAME:
59178 + dentry = va_arg(ap, struct dentry *);
59179 + mnt = va_arg(ap, struct vfsmount *);
59180 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59181 + break;
59182 + case GR_STR_FILENAME:
59183 + str1 = va_arg(ap, char *);
59184 + dentry = va_arg(ap, struct dentry *);
59185 + mnt = va_arg(ap, struct vfsmount *);
59186 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59187 + break;
59188 + case GR_FILENAME_STR:
59189 + dentry = va_arg(ap, struct dentry *);
59190 + mnt = va_arg(ap, struct vfsmount *);
59191 + str1 = va_arg(ap, char *);
59192 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59193 + break;
59194 + case GR_FILENAME_TWO_INT:
59195 + dentry = va_arg(ap, struct dentry *);
59196 + mnt = va_arg(ap, struct vfsmount *);
59197 + num1 = va_arg(ap, int);
59198 + num2 = va_arg(ap, int);
59199 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59200 + break;
59201 + case GR_FILENAME_TWO_INT_STR:
59202 + dentry = va_arg(ap, struct dentry *);
59203 + mnt = va_arg(ap, struct vfsmount *);
59204 + num1 = va_arg(ap, int);
59205 + num2 = va_arg(ap, int);
59206 + str1 = va_arg(ap, char *);
59207 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59208 + break;
59209 + case GR_TEXTREL:
59210 + file = va_arg(ap, struct file *);
59211 + ulong1 = va_arg(ap, unsigned long);
59212 + ulong2 = va_arg(ap, unsigned long);
59213 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59214 + break;
59215 + case GR_PTRACE:
59216 + task = va_arg(ap, struct task_struct *);
59217 + 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);
59218 + break;
59219 + case GR_RESOURCE:
59220 + task = va_arg(ap, struct task_struct *);
59221 + cred = __task_cred(task);
59222 + pcred = __task_cred(task->real_parent);
59223 + ulong1 = va_arg(ap, unsigned long);
59224 + str1 = va_arg(ap, char *);
59225 + ulong2 = va_arg(ap, unsigned long);
59226 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
59227 + break;
59228 + case GR_CAP:
59229 + task = va_arg(ap, struct task_struct *);
59230 + cred = __task_cred(task);
59231 + pcred = __task_cred(task->real_parent);
59232 + str1 = va_arg(ap, char *);
59233 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
59234 + break;
59235 + case GR_SIG:
59236 + str1 = va_arg(ap, char *);
59237 + voidptr = va_arg(ap, void *);
59238 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59239 + break;
59240 + case GR_SIG2:
59241 + task = va_arg(ap, struct task_struct *);
59242 + cred = __task_cred(task);
59243 + pcred = __task_cred(task->real_parent);
59244 + num1 = va_arg(ap, int);
59245 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
59246 + break;
59247 + case GR_CRASH1:
59248 + task = va_arg(ap, struct task_struct *);
59249 + cred = __task_cred(task);
59250 + pcred = __task_cred(task->real_parent);
59251 + ulong1 = va_arg(ap, unsigned long);
59252 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
59253 + break;
59254 + case GR_CRASH2:
59255 + task = va_arg(ap, struct task_struct *);
59256 + cred = __task_cred(task);
59257 + pcred = __task_cred(task->real_parent);
59258 + ulong1 = va_arg(ap, unsigned long);
59259 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
59260 + break;
59261 + case GR_RWXMAP:
59262 + file = va_arg(ap, struct file *);
59263 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59264 + break;
59265 + case GR_PSACCT:
59266 + {
59267 + unsigned int wday, cday;
59268 + __u8 whr, chr;
59269 + __u8 wmin, cmin;
59270 + __u8 wsec, csec;
59271 + char cur_tty[64] = { 0 };
59272 + char parent_tty[64] = { 0 };
59273 +
59274 + task = va_arg(ap, struct task_struct *);
59275 + wday = va_arg(ap, unsigned int);
59276 + cday = va_arg(ap, unsigned int);
59277 + whr = va_arg(ap, int);
59278 + chr = va_arg(ap, int);
59279 + wmin = va_arg(ap, int);
59280 + cmin = va_arg(ap, int);
59281 + wsec = va_arg(ap, int);
59282 + csec = va_arg(ap, int);
59283 + ulong1 = va_arg(ap, unsigned long);
59284 + cred = __task_cred(task);
59285 + pcred = __task_cred(task->real_parent);
59286 +
59287 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->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->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
59288 + }
59289 + break;
59290 + default:
59291 + gr_log_middle(audit, msg, ap);
59292 + }
59293 + va_end(ap);
59294 + // these don't need DEFAULTSECARGS printed on the end
59295 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59296 + gr_log_end(audit, 0);
59297 + else
59298 + gr_log_end(audit, 1);
59299 + END_LOCKS(audit);
59300 +}
59301 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59302 new file mode 100644
59303 index 0000000..f536303
59304 --- /dev/null
59305 +++ b/grsecurity/grsec_mem.c
59306 @@ -0,0 +1,40 @@
59307 +#include <linux/kernel.h>
59308 +#include <linux/sched.h>
59309 +#include <linux/mm.h>
59310 +#include <linux/mman.h>
59311 +#include <linux/grinternal.h>
59312 +
59313 +void
59314 +gr_handle_ioperm(void)
59315 +{
59316 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59317 + return;
59318 +}
59319 +
59320 +void
59321 +gr_handle_iopl(void)
59322 +{
59323 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59324 + return;
59325 +}
59326 +
59327 +void
59328 +gr_handle_mem_readwrite(u64 from, u64 to)
59329 +{
59330 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59331 + return;
59332 +}
59333 +
59334 +void
59335 +gr_handle_vm86(void)
59336 +{
59337 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59338 + return;
59339 +}
59340 +
59341 +void
59342 +gr_log_badprocpid(const char *entry)
59343 +{
59344 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59345 + return;
59346 +}
59347 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59348 new file mode 100644
59349 index 0000000..2131422
59350 --- /dev/null
59351 +++ b/grsecurity/grsec_mount.c
59352 @@ -0,0 +1,62 @@
59353 +#include <linux/kernel.h>
59354 +#include <linux/sched.h>
59355 +#include <linux/mount.h>
59356 +#include <linux/grsecurity.h>
59357 +#include <linux/grinternal.h>
59358 +
59359 +void
59360 +gr_log_remount(const char *devname, const int retval)
59361 +{
59362 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59363 + if (grsec_enable_mount && (retval >= 0))
59364 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59365 +#endif
59366 + return;
59367 +}
59368 +
59369 +void
59370 +gr_log_unmount(const char *devname, const int retval)
59371 +{
59372 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59373 + if (grsec_enable_mount && (retval >= 0))
59374 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59375 +#endif
59376 + return;
59377 +}
59378 +
59379 +void
59380 +gr_log_mount(const char *from, const char *to, const int retval)
59381 +{
59382 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59383 + if (grsec_enable_mount && (retval >= 0))
59384 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59385 +#endif
59386 + return;
59387 +}
59388 +
59389 +int
59390 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59391 +{
59392 +#ifdef CONFIG_GRKERNSEC_ROFS
59393 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59394 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59395 + return -EPERM;
59396 + } else
59397 + return 0;
59398 +#endif
59399 + return 0;
59400 +}
59401 +
59402 +int
59403 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59404 +{
59405 +#ifdef CONFIG_GRKERNSEC_ROFS
59406 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59407 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59408 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59409 + return -EPERM;
59410 + } else
59411 + return 0;
59412 +#endif
59413 + return 0;
59414 +}
59415 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59416 new file mode 100644
59417 index 0000000..a3b12a0
59418 --- /dev/null
59419 +++ b/grsecurity/grsec_pax.c
59420 @@ -0,0 +1,36 @@
59421 +#include <linux/kernel.h>
59422 +#include <linux/sched.h>
59423 +#include <linux/mm.h>
59424 +#include <linux/file.h>
59425 +#include <linux/grinternal.h>
59426 +#include <linux/grsecurity.h>
59427 +
59428 +void
59429 +gr_log_textrel(struct vm_area_struct * vma)
59430 +{
59431 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59432 + if (grsec_enable_audit_textrel)
59433 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59434 +#endif
59435 + return;
59436 +}
59437 +
59438 +void
59439 +gr_log_rwxmmap(struct file *file)
59440 +{
59441 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59442 + if (grsec_enable_log_rwxmaps)
59443 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59444 +#endif
59445 + return;
59446 +}
59447 +
59448 +void
59449 +gr_log_rwxmprotect(struct file *file)
59450 +{
59451 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59452 + if (grsec_enable_log_rwxmaps)
59453 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59454 +#endif
59455 + return;
59456 +}
59457 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59458 new file mode 100644
59459 index 0000000..f7f29aa
59460 --- /dev/null
59461 +++ b/grsecurity/grsec_ptrace.c
59462 @@ -0,0 +1,30 @@
59463 +#include <linux/kernel.h>
59464 +#include <linux/sched.h>
59465 +#include <linux/grinternal.h>
59466 +#include <linux/security.h>
59467 +
59468 +void
59469 +gr_audit_ptrace(struct task_struct *task)
59470 +{
59471 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59472 + if (grsec_enable_audit_ptrace)
59473 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59474 +#endif
59475 + return;
59476 +}
59477 +
59478 +int
59479 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59480 +{
59481 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59482 + const struct dentry *dentry = file->f_path.dentry;
59483 + const struct vfsmount *mnt = file->f_path.mnt;
59484 +
59485 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59486 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59487 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59488 + return -EACCES;
59489 + }
59490 +#endif
59491 + return 0;
59492 +}
59493 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59494 new file mode 100644
59495 index 0000000..5c00416
59496 --- /dev/null
59497 +++ b/grsecurity/grsec_sig.c
59498 @@ -0,0 +1,222 @@
59499 +#include <linux/kernel.h>
59500 +#include <linux/sched.h>
59501 +#include <linux/delay.h>
59502 +#include <linux/grsecurity.h>
59503 +#include <linux/grinternal.h>
59504 +#include <linux/hardirq.h>
59505 +
59506 +char *signames[] = {
59507 + [SIGSEGV] = "Segmentation fault",
59508 + [SIGILL] = "Illegal instruction",
59509 + [SIGABRT] = "Abort",
59510 + [SIGBUS] = "Invalid alignment/Bus error"
59511 +};
59512 +
59513 +void
59514 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59515 +{
59516 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59517 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59518 + (sig == SIGABRT) || (sig == SIGBUS))) {
59519 + if (t->pid == current->pid) {
59520 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59521 + } else {
59522 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59523 + }
59524 + }
59525 +#endif
59526 + return;
59527 +}
59528 +
59529 +int
59530 +gr_handle_signal(const struct task_struct *p, const int sig)
59531 +{
59532 +#ifdef CONFIG_GRKERNSEC
59533 + /* ignore the 0 signal for protected task checks */
59534 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59535 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59536 + return -EPERM;
59537 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59538 + return -EPERM;
59539 + }
59540 +#endif
59541 + return 0;
59542 +}
59543 +
59544 +#ifdef CONFIG_GRKERNSEC
59545 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59546 +
59547 +int gr_fake_force_sig(int sig, struct task_struct *t)
59548 +{
59549 + unsigned long int flags;
59550 + int ret, blocked, ignored;
59551 + struct k_sigaction *action;
59552 +
59553 + spin_lock_irqsave(&t->sighand->siglock, flags);
59554 + action = &t->sighand->action[sig-1];
59555 + ignored = action->sa.sa_handler == SIG_IGN;
59556 + blocked = sigismember(&t->blocked, sig);
59557 + if (blocked || ignored) {
59558 + action->sa.sa_handler = SIG_DFL;
59559 + if (blocked) {
59560 + sigdelset(&t->blocked, sig);
59561 + recalc_sigpending_and_wake(t);
59562 + }
59563 + }
59564 + if (action->sa.sa_handler == SIG_DFL)
59565 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59566 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59567 +
59568 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59569 +
59570 + return ret;
59571 +}
59572 +#endif
59573 +
59574 +#ifdef CONFIG_GRKERNSEC_BRUTE
59575 +#define GR_USER_BAN_TIME (15 * 60)
59576 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
59577 +
59578 +static int __get_dumpable(unsigned long mm_flags)
59579 +{
59580 + int ret;
59581 +
59582 + ret = mm_flags & MMF_DUMPABLE_MASK;
59583 + return (ret >= 2) ? 2 : ret;
59584 +}
59585 +#endif
59586 +
59587 +void gr_handle_brute_attach(unsigned long mm_flags)
59588 +{
59589 +#ifdef CONFIG_GRKERNSEC_BRUTE
59590 + struct task_struct *p = current;
59591 + kuid_t uid = GLOBAL_ROOT_UID;
59592 + int daemon = 0;
59593 +
59594 + if (!grsec_enable_brute)
59595 + return;
59596 +
59597 + rcu_read_lock();
59598 + read_lock(&tasklist_lock);
59599 + read_lock(&grsec_exec_file_lock);
59600 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
59601 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
59602 + p->real_parent->brute = 1;
59603 + daemon = 1;
59604 + } else {
59605 + const struct cred *cred = __task_cred(p), *cred2;
59606 + struct task_struct *tsk, *tsk2;
59607 +
59608 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59609 + struct user_struct *user;
59610 +
59611 + uid = cred->uid;
59612 +
59613 + /* this is put upon execution past expiration */
59614 + user = find_user(uid);
59615 + if (user == NULL)
59616 + goto unlock;
59617 + user->banned = 1;
59618 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59619 + if (user->ban_expires == ~0UL)
59620 + user->ban_expires--;
59621 +
59622 + do_each_thread(tsk2, tsk) {
59623 + cred2 = __task_cred(tsk);
59624 + if (tsk != p && uid_eq(cred2->uid, uid))
59625 + gr_fake_force_sig(SIGKILL, tsk);
59626 + } while_each_thread(tsk2, tsk);
59627 + }
59628 + }
59629 +unlock:
59630 + read_unlock(&grsec_exec_file_lock);
59631 + read_unlock(&tasklist_lock);
59632 + rcu_read_unlock();
59633 +
59634 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59635 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59636 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59637 + else if (daemon)
59638 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
59639 +
59640 +#endif
59641 + return;
59642 +}
59643 +
59644 +void gr_handle_brute_check(void)
59645 +{
59646 +#ifdef CONFIG_GRKERNSEC_BRUTE
59647 + struct task_struct *p = current;
59648 +
59649 + if (unlikely(p->brute)) {
59650 + if (!grsec_enable_brute)
59651 + p->brute = 0;
59652 + else if (time_before(get_seconds(), p->brute_expires))
59653 + msleep(30 * 1000);
59654 + }
59655 +#endif
59656 + return;
59657 +}
59658 +
59659 +void gr_handle_kernel_exploit(void)
59660 +{
59661 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59662 + const struct cred *cred;
59663 + struct task_struct *tsk, *tsk2;
59664 + struct user_struct *user;
59665 + kuid_t uid;
59666 +
59667 + if (in_irq() || in_serving_softirq() || in_nmi())
59668 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59669 +
59670 + uid = current_uid();
59671 +
59672 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59673 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59674 + else {
59675 + /* kill all the processes of this user, hold a reference
59676 + to their creds struct, and prevent them from creating
59677 + another process until system reset
59678 + */
59679 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59680 + from_kuid_munged(&init_user_ns, uid));
59681 + /* we intentionally leak this ref */
59682 + user = get_uid(current->cred->user);
59683 + if (user) {
59684 + user->banned = 1;
59685 + user->ban_expires = ~0UL;
59686 + }
59687 +
59688 + read_lock(&tasklist_lock);
59689 + do_each_thread(tsk2, tsk) {
59690 + cred = __task_cred(tsk);
59691 + if (uid_eq(cred->uid, uid))
59692 + gr_fake_force_sig(SIGKILL, tsk);
59693 + } while_each_thread(tsk2, tsk);
59694 + read_unlock(&tasklist_lock);
59695 + }
59696 +#endif
59697 +}
59698 +
59699 +int __gr_process_user_ban(struct user_struct *user)
59700 +{
59701 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59702 + if (unlikely(user->banned)) {
59703 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59704 + user->banned = 0;
59705 + user->ban_expires = 0;
59706 + free_uid(user);
59707 + } else
59708 + return -EPERM;
59709 + }
59710 +#endif
59711 + return 0;
59712 +}
59713 +
59714 +int gr_process_user_ban(void)
59715 +{
59716 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59717 + return __gr_process_user_ban(current->cred->user);
59718 +#endif
59719 + return 0;
59720 +}
59721 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59722 new file mode 100644
59723 index 0000000..4030d57
59724 --- /dev/null
59725 +++ b/grsecurity/grsec_sock.c
59726 @@ -0,0 +1,244 @@
59727 +#include <linux/kernel.h>
59728 +#include <linux/module.h>
59729 +#include <linux/sched.h>
59730 +#include <linux/file.h>
59731 +#include <linux/net.h>
59732 +#include <linux/in.h>
59733 +#include <linux/ip.h>
59734 +#include <net/sock.h>
59735 +#include <net/inet_sock.h>
59736 +#include <linux/grsecurity.h>
59737 +#include <linux/grinternal.h>
59738 +#include <linux/gracl.h>
59739 +
59740 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59741 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59742 +
59743 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59744 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59745 +
59746 +#ifdef CONFIG_UNIX_MODULE
59747 +EXPORT_SYMBOL(gr_acl_handle_unix);
59748 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59749 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59750 +EXPORT_SYMBOL(gr_handle_create);
59751 +#endif
59752 +
59753 +#ifdef CONFIG_GRKERNSEC
59754 +#define gr_conn_table_size 32749
59755 +struct conn_table_entry {
59756 + struct conn_table_entry *next;
59757 + struct signal_struct *sig;
59758 +};
59759 +
59760 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59761 +DEFINE_SPINLOCK(gr_conn_table_lock);
59762 +
59763 +extern const char * gr_socktype_to_name(unsigned char type);
59764 +extern const char * gr_proto_to_name(unsigned char proto);
59765 +extern const char * gr_sockfamily_to_name(unsigned char family);
59766 +
59767 +static __inline__ int
59768 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59769 +{
59770 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59771 +}
59772 +
59773 +static __inline__ int
59774 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59775 + __u16 sport, __u16 dport)
59776 +{
59777 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59778 + sig->gr_sport == sport && sig->gr_dport == dport))
59779 + return 1;
59780 + else
59781 + return 0;
59782 +}
59783 +
59784 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59785 +{
59786 + struct conn_table_entry **match;
59787 + unsigned int index;
59788 +
59789 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59790 + sig->gr_sport, sig->gr_dport,
59791 + gr_conn_table_size);
59792 +
59793 + newent->sig = sig;
59794 +
59795 + match = &gr_conn_table[index];
59796 + newent->next = *match;
59797 + *match = newent;
59798 +
59799 + return;
59800 +}
59801 +
59802 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59803 +{
59804 + struct conn_table_entry *match, *last = NULL;
59805 + unsigned int index;
59806 +
59807 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59808 + sig->gr_sport, sig->gr_dport,
59809 + gr_conn_table_size);
59810 +
59811 + match = gr_conn_table[index];
59812 + while (match && !conn_match(match->sig,
59813 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59814 + sig->gr_dport)) {
59815 + last = match;
59816 + match = match->next;
59817 + }
59818 +
59819 + if (match) {
59820 + if (last)
59821 + last->next = match->next;
59822 + else
59823 + gr_conn_table[index] = NULL;
59824 + kfree(match);
59825 + }
59826 +
59827 + return;
59828 +}
59829 +
59830 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59831 + __u16 sport, __u16 dport)
59832 +{
59833 + struct conn_table_entry *match;
59834 + unsigned int index;
59835 +
59836 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59837 +
59838 + match = gr_conn_table[index];
59839 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59840 + match = match->next;
59841 +
59842 + if (match)
59843 + return match->sig;
59844 + else
59845 + return NULL;
59846 +}
59847 +
59848 +#endif
59849 +
59850 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59851 +{
59852 +#ifdef CONFIG_GRKERNSEC
59853 + struct signal_struct *sig = task->signal;
59854 + struct conn_table_entry *newent;
59855 +
59856 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59857 + if (newent == NULL)
59858 + return;
59859 + /* no bh lock needed since we are called with bh disabled */
59860 + spin_lock(&gr_conn_table_lock);
59861 + gr_del_task_from_ip_table_nolock(sig);
59862 + sig->gr_saddr = inet->inet_rcv_saddr;
59863 + sig->gr_daddr = inet->inet_daddr;
59864 + sig->gr_sport = inet->inet_sport;
59865 + sig->gr_dport = inet->inet_dport;
59866 + gr_add_to_task_ip_table_nolock(sig, newent);
59867 + spin_unlock(&gr_conn_table_lock);
59868 +#endif
59869 + return;
59870 +}
59871 +
59872 +void gr_del_task_from_ip_table(struct task_struct *task)
59873 +{
59874 +#ifdef CONFIG_GRKERNSEC
59875 + spin_lock_bh(&gr_conn_table_lock);
59876 + gr_del_task_from_ip_table_nolock(task->signal);
59877 + spin_unlock_bh(&gr_conn_table_lock);
59878 +#endif
59879 + return;
59880 +}
59881 +
59882 +void
59883 +gr_attach_curr_ip(const struct sock *sk)
59884 +{
59885 +#ifdef CONFIG_GRKERNSEC
59886 + struct signal_struct *p, *set;
59887 + const struct inet_sock *inet = inet_sk(sk);
59888 +
59889 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59890 + return;
59891 +
59892 + set = current->signal;
59893 +
59894 + spin_lock_bh(&gr_conn_table_lock);
59895 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59896 + inet->inet_dport, inet->inet_sport);
59897 + if (unlikely(p != NULL)) {
59898 + set->curr_ip = p->curr_ip;
59899 + set->used_accept = 1;
59900 + gr_del_task_from_ip_table_nolock(p);
59901 + spin_unlock_bh(&gr_conn_table_lock);
59902 + return;
59903 + }
59904 + spin_unlock_bh(&gr_conn_table_lock);
59905 +
59906 + set->curr_ip = inet->inet_daddr;
59907 + set->used_accept = 1;
59908 +#endif
59909 + return;
59910 +}
59911 +
59912 +int
59913 +gr_handle_sock_all(const int family, const int type, const int protocol)
59914 +{
59915 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59916 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59917 + (family != AF_UNIX)) {
59918 + if (family == AF_INET)
59919 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59920 + else
59921 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59922 + return -EACCES;
59923 + }
59924 +#endif
59925 + return 0;
59926 +}
59927 +
59928 +int
59929 +gr_handle_sock_server(const struct sockaddr *sck)
59930 +{
59931 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59932 + if (grsec_enable_socket_server &&
59933 + in_group_p(grsec_socket_server_gid) &&
59934 + sck && (sck->sa_family != AF_UNIX) &&
59935 + (sck->sa_family != AF_LOCAL)) {
59936 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59937 + return -EACCES;
59938 + }
59939 +#endif
59940 + return 0;
59941 +}
59942 +
59943 +int
59944 +gr_handle_sock_server_other(const struct sock *sck)
59945 +{
59946 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59947 + if (grsec_enable_socket_server &&
59948 + in_group_p(grsec_socket_server_gid) &&
59949 + sck && (sck->sk_family != AF_UNIX) &&
59950 + (sck->sk_family != AF_LOCAL)) {
59951 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59952 + return -EACCES;
59953 + }
59954 +#endif
59955 + return 0;
59956 +}
59957 +
59958 +int
59959 +gr_handle_sock_client(const struct sockaddr *sck)
59960 +{
59961 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59962 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59963 + sck && (sck->sa_family != AF_UNIX) &&
59964 + (sck->sa_family != AF_LOCAL)) {
59965 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59966 + return -EACCES;
59967 + }
59968 +#endif
59969 + return 0;
59970 +}
59971 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59972 new file mode 100644
59973 index 0000000..f55ef0f
59974 --- /dev/null
59975 +++ b/grsecurity/grsec_sysctl.c
59976 @@ -0,0 +1,469 @@
59977 +#include <linux/kernel.h>
59978 +#include <linux/sched.h>
59979 +#include <linux/sysctl.h>
59980 +#include <linux/grsecurity.h>
59981 +#include <linux/grinternal.h>
59982 +
59983 +int
59984 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59985 +{
59986 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59987 + if (dirname == NULL || name == NULL)
59988 + return 0;
59989 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59990 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59991 + return -EACCES;
59992 + }
59993 +#endif
59994 + return 0;
59995 +}
59996 +
59997 +#ifdef CONFIG_GRKERNSEC_ROFS
59998 +static int __maybe_unused one = 1;
59999 +#endif
60000 +
60001 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
60002 +struct ctl_table grsecurity_table[] = {
60003 +#ifdef CONFIG_GRKERNSEC_SYSCTL
60004 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
60005 +#ifdef CONFIG_GRKERNSEC_IO
60006 + {
60007 + .procname = "disable_priv_io",
60008 + .data = &grsec_disable_privio,
60009 + .maxlen = sizeof(int),
60010 + .mode = 0600,
60011 + .proc_handler = &proc_dointvec,
60012 + },
60013 +#endif
60014 +#endif
60015 +#ifdef CONFIG_GRKERNSEC_LINK
60016 + {
60017 + .procname = "linking_restrictions",
60018 + .data = &grsec_enable_link,
60019 + .maxlen = sizeof(int),
60020 + .mode = 0600,
60021 + .proc_handler = &proc_dointvec,
60022 + },
60023 +#endif
60024 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60025 + {
60026 + .procname = "enforce_symlinksifowner",
60027 + .data = &grsec_enable_symlinkown,
60028 + .maxlen = sizeof(int),
60029 + .mode = 0600,
60030 + .proc_handler = &proc_dointvec,
60031 + },
60032 + {
60033 + .procname = "symlinkown_gid",
60034 + .data = &grsec_symlinkown_gid,
60035 + .maxlen = sizeof(int),
60036 + .mode = 0600,
60037 + .proc_handler = &proc_dointvec,
60038 + },
60039 +#endif
60040 +#ifdef CONFIG_GRKERNSEC_BRUTE
60041 + {
60042 + .procname = "deter_bruteforce",
60043 + .data = &grsec_enable_brute,
60044 + .maxlen = sizeof(int),
60045 + .mode = 0600,
60046 + .proc_handler = &proc_dointvec,
60047 + },
60048 +#endif
60049 +#ifdef CONFIG_GRKERNSEC_FIFO
60050 + {
60051 + .procname = "fifo_restrictions",
60052 + .data = &grsec_enable_fifo,
60053 + .maxlen = sizeof(int),
60054 + .mode = 0600,
60055 + .proc_handler = &proc_dointvec,
60056 + },
60057 +#endif
60058 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60059 + {
60060 + .procname = "ptrace_readexec",
60061 + .data = &grsec_enable_ptrace_readexec,
60062 + .maxlen = sizeof(int),
60063 + .mode = 0600,
60064 + .proc_handler = &proc_dointvec,
60065 + },
60066 +#endif
60067 +#ifdef CONFIG_GRKERNSEC_SETXID
60068 + {
60069 + .procname = "consistent_setxid",
60070 + .data = &grsec_enable_setxid,
60071 + .maxlen = sizeof(int),
60072 + .mode = 0600,
60073 + .proc_handler = &proc_dointvec,
60074 + },
60075 +#endif
60076 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60077 + {
60078 + .procname = "ip_blackhole",
60079 + .data = &grsec_enable_blackhole,
60080 + .maxlen = sizeof(int),
60081 + .mode = 0600,
60082 + .proc_handler = &proc_dointvec,
60083 + },
60084 + {
60085 + .procname = "lastack_retries",
60086 + .data = &grsec_lastack_retries,
60087 + .maxlen = sizeof(int),
60088 + .mode = 0600,
60089 + .proc_handler = &proc_dointvec,
60090 + },
60091 +#endif
60092 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60093 + {
60094 + .procname = "exec_logging",
60095 + .data = &grsec_enable_execlog,
60096 + .maxlen = sizeof(int),
60097 + .mode = 0600,
60098 + .proc_handler = &proc_dointvec,
60099 + },
60100 +#endif
60101 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60102 + {
60103 + .procname = "rwxmap_logging",
60104 + .data = &grsec_enable_log_rwxmaps,
60105 + .maxlen = sizeof(int),
60106 + .mode = 0600,
60107 + .proc_handler = &proc_dointvec,
60108 + },
60109 +#endif
60110 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60111 + {
60112 + .procname = "signal_logging",
60113 + .data = &grsec_enable_signal,
60114 + .maxlen = sizeof(int),
60115 + .mode = 0600,
60116 + .proc_handler = &proc_dointvec,
60117 + },
60118 +#endif
60119 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60120 + {
60121 + .procname = "forkfail_logging",
60122 + .data = &grsec_enable_forkfail,
60123 + .maxlen = sizeof(int),
60124 + .mode = 0600,
60125 + .proc_handler = &proc_dointvec,
60126 + },
60127 +#endif
60128 +#ifdef CONFIG_GRKERNSEC_TIME
60129 + {
60130 + .procname = "timechange_logging",
60131 + .data = &grsec_enable_time,
60132 + .maxlen = sizeof(int),
60133 + .mode = 0600,
60134 + .proc_handler = &proc_dointvec,
60135 + },
60136 +#endif
60137 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60138 + {
60139 + .procname = "chroot_deny_shmat",
60140 + .data = &grsec_enable_chroot_shmat,
60141 + .maxlen = sizeof(int),
60142 + .mode = 0600,
60143 + .proc_handler = &proc_dointvec,
60144 + },
60145 +#endif
60146 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60147 + {
60148 + .procname = "chroot_deny_unix",
60149 + .data = &grsec_enable_chroot_unix,
60150 + .maxlen = sizeof(int),
60151 + .mode = 0600,
60152 + .proc_handler = &proc_dointvec,
60153 + },
60154 +#endif
60155 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60156 + {
60157 + .procname = "chroot_deny_mount",
60158 + .data = &grsec_enable_chroot_mount,
60159 + .maxlen = sizeof(int),
60160 + .mode = 0600,
60161 + .proc_handler = &proc_dointvec,
60162 + },
60163 +#endif
60164 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60165 + {
60166 + .procname = "chroot_deny_fchdir",
60167 + .data = &grsec_enable_chroot_fchdir,
60168 + .maxlen = sizeof(int),
60169 + .mode = 0600,
60170 + .proc_handler = &proc_dointvec,
60171 + },
60172 +#endif
60173 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60174 + {
60175 + .procname = "chroot_deny_chroot",
60176 + .data = &grsec_enable_chroot_double,
60177 + .maxlen = sizeof(int),
60178 + .mode = 0600,
60179 + .proc_handler = &proc_dointvec,
60180 + },
60181 +#endif
60182 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60183 + {
60184 + .procname = "chroot_deny_pivot",
60185 + .data = &grsec_enable_chroot_pivot,
60186 + .maxlen = sizeof(int),
60187 + .mode = 0600,
60188 + .proc_handler = &proc_dointvec,
60189 + },
60190 +#endif
60191 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60192 + {
60193 + .procname = "chroot_enforce_chdir",
60194 + .data = &grsec_enable_chroot_chdir,
60195 + .maxlen = sizeof(int),
60196 + .mode = 0600,
60197 + .proc_handler = &proc_dointvec,
60198 + },
60199 +#endif
60200 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60201 + {
60202 + .procname = "chroot_deny_chmod",
60203 + .data = &grsec_enable_chroot_chmod,
60204 + .maxlen = sizeof(int),
60205 + .mode = 0600,
60206 + .proc_handler = &proc_dointvec,
60207 + },
60208 +#endif
60209 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60210 + {
60211 + .procname = "chroot_deny_mknod",
60212 + .data = &grsec_enable_chroot_mknod,
60213 + .maxlen = sizeof(int),
60214 + .mode = 0600,
60215 + .proc_handler = &proc_dointvec,
60216 + },
60217 +#endif
60218 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60219 + {
60220 + .procname = "chroot_restrict_nice",
60221 + .data = &grsec_enable_chroot_nice,
60222 + .maxlen = sizeof(int),
60223 + .mode = 0600,
60224 + .proc_handler = &proc_dointvec,
60225 + },
60226 +#endif
60227 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60228 + {
60229 + .procname = "chroot_execlog",
60230 + .data = &grsec_enable_chroot_execlog,
60231 + .maxlen = sizeof(int),
60232 + .mode = 0600,
60233 + .proc_handler = &proc_dointvec,
60234 + },
60235 +#endif
60236 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60237 + {
60238 + .procname = "chroot_caps",
60239 + .data = &grsec_enable_chroot_caps,
60240 + .maxlen = sizeof(int),
60241 + .mode = 0600,
60242 + .proc_handler = &proc_dointvec,
60243 + },
60244 +#endif
60245 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60246 + {
60247 + .procname = "chroot_deny_sysctl",
60248 + .data = &grsec_enable_chroot_sysctl,
60249 + .maxlen = sizeof(int),
60250 + .mode = 0600,
60251 + .proc_handler = &proc_dointvec,
60252 + },
60253 +#endif
60254 +#ifdef CONFIG_GRKERNSEC_TPE
60255 + {
60256 + .procname = "tpe",
60257 + .data = &grsec_enable_tpe,
60258 + .maxlen = sizeof(int),
60259 + .mode = 0600,
60260 + .proc_handler = &proc_dointvec,
60261 + },
60262 + {
60263 + .procname = "tpe_gid",
60264 + .data = &grsec_tpe_gid,
60265 + .maxlen = sizeof(int),
60266 + .mode = 0600,
60267 + .proc_handler = &proc_dointvec,
60268 + },
60269 +#endif
60270 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60271 + {
60272 + .procname = "tpe_invert",
60273 + .data = &grsec_enable_tpe_invert,
60274 + .maxlen = sizeof(int),
60275 + .mode = 0600,
60276 + .proc_handler = &proc_dointvec,
60277 + },
60278 +#endif
60279 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60280 + {
60281 + .procname = "tpe_restrict_all",
60282 + .data = &grsec_enable_tpe_all,
60283 + .maxlen = sizeof(int),
60284 + .mode = 0600,
60285 + .proc_handler = &proc_dointvec,
60286 + },
60287 +#endif
60288 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60289 + {
60290 + .procname = "socket_all",
60291 + .data = &grsec_enable_socket_all,
60292 + .maxlen = sizeof(int),
60293 + .mode = 0600,
60294 + .proc_handler = &proc_dointvec,
60295 + },
60296 + {
60297 + .procname = "socket_all_gid",
60298 + .data = &grsec_socket_all_gid,
60299 + .maxlen = sizeof(int),
60300 + .mode = 0600,
60301 + .proc_handler = &proc_dointvec,
60302 + },
60303 +#endif
60304 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60305 + {
60306 + .procname = "socket_client",
60307 + .data = &grsec_enable_socket_client,
60308 + .maxlen = sizeof(int),
60309 + .mode = 0600,
60310 + .proc_handler = &proc_dointvec,
60311 + },
60312 + {
60313 + .procname = "socket_client_gid",
60314 + .data = &grsec_socket_client_gid,
60315 + .maxlen = sizeof(int),
60316 + .mode = 0600,
60317 + .proc_handler = &proc_dointvec,
60318 + },
60319 +#endif
60320 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60321 + {
60322 + .procname = "socket_server",
60323 + .data = &grsec_enable_socket_server,
60324 + .maxlen = sizeof(int),
60325 + .mode = 0600,
60326 + .proc_handler = &proc_dointvec,
60327 + },
60328 + {
60329 + .procname = "socket_server_gid",
60330 + .data = &grsec_socket_server_gid,
60331 + .maxlen = sizeof(int),
60332 + .mode = 0600,
60333 + .proc_handler = &proc_dointvec,
60334 + },
60335 +#endif
60336 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60337 + {
60338 + .procname = "audit_group",
60339 + .data = &grsec_enable_group,
60340 + .maxlen = sizeof(int),
60341 + .mode = 0600,
60342 + .proc_handler = &proc_dointvec,
60343 + },
60344 + {
60345 + .procname = "audit_gid",
60346 + .data = &grsec_audit_gid,
60347 + .maxlen = sizeof(int),
60348 + .mode = 0600,
60349 + .proc_handler = &proc_dointvec,
60350 + },
60351 +#endif
60352 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60353 + {
60354 + .procname = "audit_chdir",
60355 + .data = &grsec_enable_chdir,
60356 + .maxlen = sizeof(int),
60357 + .mode = 0600,
60358 + .proc_handler = &proc_dointvec,
60359 + },
60360 +#endif
60361 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60362 + {
60363 + .procname = "audit_mount",
60364 + .data = &grsec_enable_mount,
60365 + .maxlen = sizeof(int),
60366 + .mode = 0600,
60367 + .proc_handler = &proc_dointvec,
60368 + },
60369 +#endif
60370 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60371 + {
60372 + .procname = "audit_textrel",
60373 + .data = &grsec_enable_audit_textrel,
60374 + .maxlen = sizeof(int),
60375 + .mode = 0600,
60376 + .proc_handler = &proc_dointvec,
60377 + },
60378 +#endif
60379 +#ifdef CONFIG_GRKERNSEC_DMESG
60380 + {
60381 + .procname = "dmesg",
60382 + .data = &grsec_enable_dmesg,
60383 + .maxlen = sizeof(int),
60384 + .mode = 0600,
60385 + .proc_handler = &proc_dointvec,
60386 + },
60387 +#endif
60388 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60389 + {
60390 + .procname = "chroot_findtask",
60391 + .data = &grsec_enable_chroot_findtask,
60392 + .maxlen = sizeof(int),
60393 + .mode = 0600,
60394 + .proc_handler = &proc_dointvec,
60395 + },
60396 +#endif
60397 +#ifdef CONFIG_GRKERNSEC_RESLOG
60398 + {
60399 + .procname = "resource_logging",
60400 + .data = &grsec_resource_logging,
60401 + .maxlen = sizeof(int),
60402 + .mode = 0600,
60403 + .proc_handler = &proc_dointvec,
60404 + },
60405 +#endif
60406 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60407 + {
60408 + .procname = "audit_ptrace",
60409 + .data = &grsec_enable_audit_ptrace,
60410 + .maxlen = sizeof(int),
60411 + .mode = 0600,
60412 + .proc_handler = &proc_dointvec,
60413 + },
60414 +#endif
60415 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60416 + {
60417 + .procname = "harden_ptrace",
60418 + .data = &grsec_enable_harden_ptrace,
60419 + .maxlen = sizeof(int),
60420 + .mode = 0600,
60421 + .proc_handler = &proc_dointvec,
60422 + },
60423 +#endif
60424 + {
60425 + .procname = "grsec_lock",
60426 + .data = &grsec_lock,
60427 + .maxlen = sizeof(int),
60428 + .mode = 0600,
60429 + .proc_handler = &proc_dointvec,
60430 + },
60431 +#endif
60432 +#ifdef CONFIG_GRKERNSEC_ROFS
60433 + {
60434 + .procname = "romount_protect",
60435 + .data = &grsec_enable_rofs,
60436 + .maxlen = sizeof(int),
60437 + .mode = 0600,
60438 + .proc_handler = &proc_dointvec_minmax,
60439 + .extra1 = &one,
60440 + .extra2 = &one,
60441 + },
60442 +#endif
60443 + { }
60444 +};
60445 +#endif
60446 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60447 new file mode 100644
60448 index 0000000..0dc13c3
60449 --- /dev/null
60450 +++ b/grsecurity/grsec_time.c
60451 @@ -0,0 +1,16 @@
60452 +#include <linux/kernel.h>
60453 +#include <linux/sched.h>
60454 +#include <linux/grinternal.h>
60455 +#include <linux/module.h>
60456 +
60457 +void
60458 +gr_log_timechange(void)
60459 +{
60460 +#ifdef CONFIG_GRKERNSEC_TIME
60461 + if (grsec_enable_time)
60462 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60463 +#endif
60464 + return;
60465 +}
60466 +
60467 +EXPORT_SYMBOL(gr_log_timechange);
60468 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60469 new file mode 100644
60470 index 0000000..07e0dc0
60471 --- /dev/null
60472 +++ b/grsecurity/grsec_tpe.c
60473 @@ -0,0 +1,73 @@
60474 +#include <linux/kernel.h>
60475 +#include <linux/sched.h>
60476 +#include <linux/file.h>
60477 +#include <linux/fs.h>
60478 +#include <linux/grinternal.h>
60479 +
60480 +extern int gr_acl_tpe_check(void);
60481 +
60482 +int
60483 +gr_tpe_allow(const struct file *file)
60484 +{
60485 +#ifdef CONFIG_GRKERNSEC
60486 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60487 + const struct cred *cred = current_cred();
60488 + char *msg = NULL;
60489 + char *msg2 = NULL;
60490 +
60491 + // never restrict root
60492 + if (!cred->uid)
60493 + return 1;
60494 +
60495 + if (grsec_enable_tpe) {
60496 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60497 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60498 + msg = "not being in trusted group";
60499 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60500 + msg = "being in untrusted group";
60501 +#else
60502 + if (in_group_p(grsec_tpe_gid))
60503 + msg = "being in untrusted group";
60504 +#endif
60505 + }
60506 + if (!msg && gr_acl_tpe_check())
60507 + msg = "being in untrusted role";
60508 +
60509 + // not in any affected group/role
60510 + if (!msg)
60511 + goto next_check;
60512 +
60513 + if (inode->i_uid)
60514 + msg2 = "file in non-root-owned directory";
60515 + else if (inode->i_mode & S_IWOTH)
60516 + msg2 = "file in world-writable directory";
60517 + else if (inode->i_mode & S_IWGRP)
60518 + msg2 = "file in group-writable directory";
60519 +
60520 + if (msg && msg2) {
60521 + char fullmsg[70] = {0};
60522 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60523 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60524 + return 0;
60525 + }
60526 + msg = NULL;
60527 +next_check:
60528 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60529 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60530 + return 1;
60531 +
60532 + if (inode->i_uid && (inode->i_uid != cred->uid))
60533 + msg = "directory not owned by user";
60534 + else if (inode->i_mode & S_IWOTH)
60535 + msg = "file in world-writable directory";
60536 + else if (inode->i_mode & S_IWGRP)
60537 + msg = "file in group-writable directory";
60538 +
60539 + if (msg) {
60540 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60541 + return 0;
60542 + }
60543 +#endif
60544 +#endif
60545 + return 1;
60546 +}
60547 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60548 new file mode 100644
60549 index 0000000..9f7b1ac
60550 --- /dev/null
60551 +++ b/grsecurity/grsum.c
60552 @@ -0,0 +1,61 @@
60553 +#include <linux/err.h>
60554 +#include <linux/kernel.h>
60555 +#include <linux/sched.h>
60556 +#include <linux/mm.h>
60557 +#include <linux/scatterlist.h>
60558 +#include <linux/crypto.h>
60559 +#include <linux/gracl.h>
60560 +
60561 +
60562 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60563 +#error "crypto and sha256 must be built into the kernel"
60564 +#endif
60565 +
60566 +int
60567 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60568 +{
60569 + char *p;
60570 + struct crypto_hash *tfm;
60571 + struct hash_desc desc;
60572 + struct scatterlist sg;
60573 + unsigned char temp_sum[GR_SHA_LEN];
60574 + volatile int retval = 0;
60575 + volatile int dummy = 0;
60576 + unsigned int i;
60577 +
60578 + sg_init_table(&sg, 1);
60579 +
60580 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60581 + if (IS_ERR(tfm)) {
60582 + /* should never happen, since sha256 should be built in */
60583 + return 1;
60584 + }
60585 +
60586 + desc.tfm = tfm;
60587 + desc.flags = 0;
60588 +
60589 + crypto_hash_init(&desc);
60590 +
60591 + p = salt;
60592 + sg_set_buf(&sg, p, GR_SALT_LEN);
60593 + crypto_hash_update(&desc, &sg, sg.length);
60594 +
60595 + p = entry->pw;
60596 + sg_set_buf(&sg, p, strlen(p));
60597 +
60598 + crypto_hash_update(&desc, &sg, sg.length);
60599 +
60600 + crypto_hash_final(&desc, temp_sum);
60601 +
60602 + memset(entry->pw, 0, GR_PW_LEN);
60603 +
60604 + for (i = 0; i < GR_SHA_LEN; i++)
60605 + if (sum[i] != temp_sum[i])
60606 + retval = 1;
60607 + else
60608 + dummy = 1; // waste a cycle
60609 +
60610 + crypto_free_hash(tfm);
60611 +
60612 + return retval;
60613 +}
60614 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60615 index 0daa0fb..f548aa4 100644
60616 --- a/include/acpi/acpi_bus.h
60617 +++ b/include/acpi/acpi_bus.h
60618 @@ -107,7 +107,7 @@ struct acpi_device_ops {
60619 acpi_op_bind bind;
60620 acpi_op_unbind unbind;
60621 acpi_op_notify notify;
60622 -};
60623 +} __no_const;
60624
60625 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60626
60627 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60628 index 77ff547..181834f 100644
60629 --- a/include/asm-generic/4level-fixup.h
60630 +++ b/include/asm-generic/4level-fixup.h
60631 @@ -13,8 +13,10 @@
60632 #define pmd_alloc(mm, pud, address) \
60633 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60634 NULL: pmd_offset(pud, address))
60635 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60636
60637 #define pud_alloc(mm, pgd, address) (pgd)
60638 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60639 #define pud_offset(pgd, start) (pgd)
60640 #define pud_none(pud) 0
60641 #define pud_bad(pud) 0
60642 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60643 index b7babf0..04ad282 100644
60644 --- a/include/asm-generic/atomic-long.h
60645 +++ b/include/asm-generic/atomic-long.h
60646 @@ -22,6 +22,12 @@
60647
60648 typedef atomic64_t atomic_long_t;
60649
60650 +#ifdef CONFIG_PAX_REFCOUNT
60651 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60652 +#else
60653 +typedef atomic64_t atomic_long_unchecked_t;
60654 +#endif
60655 +
60656 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60657
60658 static inline long atomic_long_read(atomic_long_t *l)
60659 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60660 return (long)atomic64_read(v);
60661 }
60662
60663 +#ifdef CONFIG_PAX_REFCOUNT
60664 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60665 +{
60666 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60667 +
60668 + return (long)atomic64_read_unchecked(v);
60669 +}
60670 +#endif
60671 +
60672 static inline void atomic_long_set(atomic_long_t *l, long i)
60673 {
60674 atomic64_t *v = (atomic64_t *)l;
60675 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60676 atomic64_set(v, i);
60677 }
60678
60679 +#ifdef CONFIG_PAX_REFCOUNT
60680 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60681 +{
60682 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60683 +
60684 + atomic64_set_unchecked(v, i);
60685 +}
60686 +#endif
60687 +
60688 static inline void atomic_long_inc(atomic_long_t *l)
60689 {
60690 atomic64_t *v = (atomic64_t *)l;
60691 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60692 atomic64_inc(v);
60693 }
60694
60695 +#ifdef CONFIG_PAX_REFCOUNT
60696 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60697 +{
60698 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60699 +
60700 + atomic64_inc_unchecked(v);
60701 +}
60702 +#endif
60703 +
60704 static inline void atomic_long_dec(atomic_long_t *l)
60705 {
60706 atomic64_t *v = (atomic64_t *)l;
60707 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60708 atomic64_dec(v);
60709 }
60710
60711 +#ifdef CONFIG_PAX_REFCOUNT
60712 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60713 +{
60714 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60715 +
60716 + atomic64_dec_unchecked(v);
60717 +}
60718 +#endif
60719 +
60720 static inline void atomic_long_add(long i, atomic_long_t *l)
60721 {
60722 atomic64_t *v = (atomic64_t *)l;
60723 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60724 atomic64_add(i, v);
60725 }
60726
60727 +#ifdef CONFIG_PAX_REFCOUNT
60728 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60729 +{
60730 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60731 +
60732 + atomic64_add_unchecked(i, v);
60733 +}
60734 +#endif
60735 +
60736 static inline void atomic_long_sub(long i, atomic_long_t *l)
60737 {
60738 atomic64_t *v = (atomic64_t *)l;
60739 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60740 atomic64_sub(i, v);
60741 }
60742
60743 +#ifdef CONFIG_PAX_REFCOUNT
60744 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60745 +{
60746 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60747 +
60748 + atomic64_sub_unchecked(i, v);
60749 +}
60750 +#endif
60751 +
60752 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60753 {
60754 atomic64_t *v = (atomic64_t *)l;
60755 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
60756 return (long)atomic64_add_return(i, v);
60757 }
60758
60759 +#ifdef CONFIG_PAX_REFCOUNT
60760 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
60761 +{
60762 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60763 +
60764 + return (long)atomic64_add_return_unchecked(i, v);
60765 +}
60766 +#endif
60767 +
60768 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
60769 {
60770 atomic64_t *v = (atomic64_t *)l;
60771 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60772 return (long)atomic64_inc_return(v);
60773 }
60774
60775 +#ifdef CONFIG_PAX_REFCOUNT
60776 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60777 +{
60778 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60779 +
60780 + return (long)atomic64_inc_return_unchecked(v);
60781 +}
60782 +#endif
60783 +
60784 static inline long atomic_long_dec_return(atomic_long_t *l)
60785 {
60786 atomic64_t *v = (atomic64_t *)l;
60787 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60788
60789 typedef atomic_t atomic_long_t;
60790
60791 +#ifdef CONFIG_PAX_REFCOUNT
60792 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60793 +#else
60794 +typedef atomic_t atomic_long_unchecked_t;
60795 +#endif
60796 +
60797 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60798 static inline long atomic_long_read(atomic_long_t *l)
60799 {
60800 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60801 return (long)atomic_read(v);
60802 }
60803
60804 +#ifdef CONFIG_PAX_REFCOUNT
60805 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60806 +{
60807 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60808 +
60809 + return (long)atomic_read_unchecked(v);
60810 +}
60811 +#endif
60812 +
60813 static inline void atomic_long_set(atomic_long_t *l, long i)
60814 {
60815 atomic_t *v = (atomic_t *)l;
60816 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60817 atomic_set(v, i);
60818 }
60819
60820 +#ifdef CONFIG_PAX_REFCOUNT
60821 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60822 +{
60823 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60824 +
60825 + atomic_set_unchecked(v, i);
60826 +}
60827 +#endif
60828 +
60829 static inline void atomic_long_inc(atomic_long_t *l)
60830 {
60831 atomic_t *v = (atomic_t *)l;
60832 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60833 atomic_inc(v);
60834 }
60835
60836 +#ifdef CONFIG_PAX_REFCOUNT
60837 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60838 +{
60839 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60840 +
60841 + atomic_inc_unchecked(v);
60842 +}
60843 +#endif
60844 +
60845 static inline void atomic_long_dec(atomic_long_t *l)
60846 {
60847 atomic_t *v = (atomic_t *)l;
60848 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60849 atomic_dec(v);
60850 }
60851
60852 +#ifdef CONFIG_PAX_REFCOUNT
60853 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60854 +{
60855 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60856 +
60857 + atomic_dec_unchecked(v);
60858 +}
60859 +#endif
60860 +
60861 static inline void atomic_long_add(long i, atomic_long_t *l)
60862 {
60863 atomic_t *v = (atomic_t *)l;
60864 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60865 atomic_add(i, v);
60866 }
60867
60868 +#ifdef CONFIG_PAX_REFCOUNT
60869 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60870 +{
60871 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60872 +
60873 + atomic_add_unchecked(i, v);
60874 +}
60875 +#endif
60876 +
60877 static inline void atomic_long_sub(long i, atomic_long_t *l)
60878 {
60879 atomic_t *v = (atomic_t *)l;
60880 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60881 atomic_sub(i, v);
60882 }
60883
60884 +#ifdef CONFIG_PAX_REFCOUNT
60885 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60886 +{
60887 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60888 +
60889 + atomic_sub_unchecked(i, v);
60890 +}
60891 +#endif
60892 +
60893 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60894 {
60895 atomic_t *v = (atomic_t *)l;
60896 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
60897 return (long)atomic_add_return(i, v);
60898 }
60899
60900 +#ifdef CONFIG_PAX_REFCOUNT
60901 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
60902 +{
60903 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60904 +
60905 + return (long)atomic_add_return_unchecked(i, v);
60906 +}
60907 +
60908 +#endif
60909 +
60910 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
60911 {
60912 atomic_t *v = (atomic_t *)l;
60913 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60914 return (long)atomic_inc_return(v);
60915 }
60916
60917 +#ifdef CONFIG_PAX_REFCOUNT
60918 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60919 +{
60920 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60921 +
60922 + return (long)atomic_inc_return_unchecked(v);
60923 +}
60924 +#endif
60925 +
60926 static inline long atomic_long_dec_return(atomic_long_t *l)
60927 {
60928 atomic_t *v = (atomic_t *)l;
60929 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60930
60931 #endif /* BITS_PER_LONG == 64 */
60932
60933 +#ifdef CONFIG_PAX_REFCOUNT
60934 +static inline void pax_refcount_needs_these_functions(void)
60935 +{
60936 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60937 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60938 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60939 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60940 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60941 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60942 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60943 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60944 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60945 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60946 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60947 +#ifdef CONFIG_X86
60948 + atomic_clear_mask_unchecked(0, NULL);
60949 + atomic_set_mask_unchecked(0, NULL);
60950 +#endif
60951 +
60952 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60953 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60954 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60955 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60956 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60957 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
60958 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60959 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60960 +}
60961 +#else
60962 +#define atomic_read_unchecked(v) atomic_read(v)
60963 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60964 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60965 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60966 +#define atomic_inc_unchecked(v) atomic_inc(v)
60967 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60968 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60969 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60970 +#define atomic_dec_unchecked(v) atomic_dec(v)
60971 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60972 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60973 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60974 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60975 +
60976 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60977 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60978 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60979 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60980 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60981 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
60982 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60983 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60984 +#endif
60985 +
60986 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60987 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60988 index 1ced641..c896ee8 100644
60989 --- a/include/asm-generic/atomic.h
60990 +++ b/include/asm-generic/atomic.h
60991 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60992 * Atomically clears the bits set in @mask from @v
60993 */
60994 #ifndef atomic_clear_mask
60995 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60996 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60997 {
60998 unsigned long flags;
60999
61000 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
61001 index b18ce4f..2ee2843 100644
61002 --- a/include/asm-generic/atomic64.h
61003 +++ b/include/asm-generic/atomic64.h
61004 @@ -16,6 +16,8 @@ typedef struct {
61005 long long counter;
61006 } atomic64_t;
61007
61008 +typedef atomic64_t atomic64_unchecked_t;
61009 +
61010 #define ATOMIC64_INIT(i) { (i) }
61011
61012 extern long long atomic64_read(const atomic64_t *v);
61013 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
61014 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
61015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
61016
61017 +#define atomic64_read_unchecked(v) atomic64_read(v)
61018 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
61019 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
61020 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
61021 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
61022 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
61023 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
61024 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
61025 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
61026 +
61027 #endif /* _ASM_GENERIC_ATOMIC64_H */
61028 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
61029 index 1bfcfe5..e04c5c9 100644
61030 --- a/include/asm-generic/cache.h
61031 +++ b/include/asm-generic/cache.h
61032 @@ -6,7 +6,7 @@
61033 * cache lines need to provide their own cache.h.
61034 */
61035
61036 -#define L1_CACHE_SHIFT 5
61037 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
61038 +#define L1_CACHE_SHIFT 5UL
61039 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
61040
61041 #endif /* __ASM_GENERIC_CACHE_H */
61042 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
61043 index 0d68a1e..b74a761 100644
61044 --- a/include/asm-generic/emergency-restart.h
61045 +++ b/include/asm-generic/emergency-restart.h
61046 @@ -1,7 +1,7 @@
61047 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
61048 #define _ASM_GENERIC_EMERGENCY_RESTART_H
61049
61050 -static inline void machine_emergency_restart(void)
61051 +static inline __noreturn void machine_emergency_restart(void)
61052 {
61053 machine_restart(NULL);
61054 }
61055 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
61056 index 90f99c7..00ce236 100644
61057 --- a/include/asm-generic/kmap_types.h
61058 +++ b/include/asm-generic/kmap_types.h
61059 @@ -2,9 +2,9 @@
61060 #define _ASM_GENERIC_KMAP_TYPES_H
61061
61062 #ifdef __WITH_KM_FENCE
61063 -# define KM_TYPE_NR 41
61064 +# define KM_TYPE_NR 42
61065 #else
61066 -# define KM_TYPE_NR 20
61067 +# define KM_TYPE_NR 21
61068 #endif
61069
61070 #endif
61071 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
61072 index 9ceb03b..62b0b8f 100644
61073 --- a/include/asm-generic/local.h
61074 +++ b/include/asm-generic/local.h
61075 @@ -23,24 +23,37 @@ typedef struct
61076 atomic_long_t a;
61077 } local_t;
61078
61079 +typedef struct {
61080 + atomic_long_unchecked_t a;
61081 +} local_unchecked_t;
61082 +
61083 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
61084
61085 #define local_read(l) atomic_long_read(&(l)->a)
61086 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
61087 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
61088 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
61089 #define local_inc(l) atomic_long_inc(&(l)->a)
61090 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
61091 #define local_dec(l) atomic_long_dec(&(l)->a)
61092 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
61093 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
61094 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
61095 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
61096 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
61097
61098 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
61099 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
61100 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
61101 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
61102 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
61103 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
61104 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
61105 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
61106 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
61107
61108 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61109 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
61110 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
61111 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
61112 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
61113 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
61114 index 725612b..9cc513a 100644
61115 --- a/include/asm-generic/pgtable-nopmd.h
61116 +++ b/include/asm-generic/pgtable-nopmd.h
61117 @@ -1,14 +1,19 @@
61118 #ifndef _PGTABLE_NOPMD_H
61119 #define _PGTABLE_NOPMD_H
61120
61121 -#ifndef __ASSEMBLY__
61122 -
61123 #include <asm-generic/pgtable-nopud.h>
61124
61125 -struct mm_struct;
61126 -
61127 #define __PAGETABLE_PMD_FOLDED
61128
61129 +#define PMD_SHIFT PUD_SHIFT
61130 +#define PTRS_PER_PMD 1
61131 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
61132 +#define PMD_MASK (~(PMD_SIZE-1))
61133 +
61134 +#ifndef __ASSEMBLY__
61135 +
61136 +struct mm_struct;
61137 +
61138 /*
61139 * Having the pmd type consist of a pud gets the size right, and allows
61140 * us to conceptually access the pud entry that this pmd is folded into
61141 @@ -16,11 +21,6 @@ struct mm_struct;
61142 */
61143 typedef struct { pud_t pud; } pmd_t;
61144
61145 -#define PMD_SHIFT PUD_SHIFT
61146 -#define PTRS_PER_PMD 1
61147 -#define PMD_SIZE (1UL << PMD_SHIFT)
61148 -#define PMD_MASK (~(PMD_SIZE-1))
61149 -
61150 /*
61151 * The "pud_xxx()" functions here are trivial for a folded two-level
61152 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61153 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61154 index 810431d..0ec4804f 100644
61155 --- a/include/asm-generic/pgtable-nopud.h
61156 +++ b/include/asm-generic/pgtable-nopud.h
61157 @@ -1,10 +1,15 @@
61158 #ifndef _PGTABLE_NOPUD_H
61159 #define _PGTABLE_NOPUD_H
61160
61161 -#ifndef __ASSEMBLY__
61162 -
61163 #define __PAGETABLE_PUD_FOLDED
61164
61165 +#define PUD_SHIFT PGDIR_SHIFT
61166 +#define PTRS_PER_PUD 1
61167 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61168 +#define PUD_MASK (~(PUD_SIZE-1))
61169 +
61170 +#ifndef __ASSEMBLY__
61171 +
61172 /*
61173 * Having the pud type consist of a pgd gets the size right, and allows
61174 * us to conceptually access the pgd entry that this pud is folded into
61175 @@ -12,11 +17,6 @@
61176 */
61177 typedef struct { pgd_t pgd; } pud_t;
61178
61179 -#define PUD_SHIFT PGDIR_SHIFT
61180 -#define PTRS_PER_PUD 1
61181 -#define PUD_SIZE (1UL << PUD_SHIFT)
61182 -#define PUD_MASK (~(PUD_SIZE-1))
61183 -
61184 /*
61185 * The "pgd_xxx()" functions here are trivial for a folded two-level
61186 * setup: the pud is never bad, and a pud always exists (as it's folded
61187 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61188 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61189
61190 #define pgd_populate(mm, pgd, pud) do { } while (0)
61191 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61192 /*
61193 * (puds are folded into pgds so this doesn't get actually called,
61194 * but the define is needed for a generic inline function.)
61195 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61196 index b36ce40..019426d 100644
61197 --- a/include/asm-generic/pgtable.h
61198 +++ b/include/asm-generic/pgtable.h
61199 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61200 #endif
61201 }
61202
61203 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61204 +static inline unsigned long pax_open_kernel(void) { return 0; }
61205 +#endif
61206 +
61207 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61208 +static inline unsigned long pax_close_kernel(void) { return 0; }
61209 +#endif
61210 +
61211 #endif /* CONFIG_MMU */
61212
61213 #endif /* !__ASSEMBLY__ */
61214 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61215 index d1ea7ce..b1ebf2a 100644
61216 --- a/include/asm-generic/vmlinux.lds.h
61217 +++ b/include/asm-generic/vmlinux.lds.h
61218 @@ -218,6 +218,7 @@
61219 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61220 VMLINUX_SYMBOL(__start_rodata) = .; \
61221 *(.rodata) *(.rodata.*) \
61222 + *(.data..read_only) \
61223 *(__vermagic) /* Kernel version magic */ \
61224 . = ALIGN(8); \
61225 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61226 @@ -725,17 +726,18 @@
61227 * section in the linker script will go there too. @phdr should have
61228 * a leading colon.
61229 *
61230 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61231 + * Note that this macros defines per_cpu_load as an absolute symbol.
61232 * If there is no need to put the percpu section at a predetermined
61233 * address, use PERCPU_SECTION.
61234 */
61235 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61236 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61237 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61238 + per_cpu_load = .; \
61239 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61240 - LOAD_OFFSET) { \
61241 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61242 PERCPU_INPUT(cacheline) \
61243 } phdr \
61244 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61245 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61246
61247 /**
61248 * PERCPU_SECTION - define output section for percpu area, simple version
61249 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61250 index 3fd8280..2b3c415 100644
61251 --- a/include/drm/drmP.h
61252 +++ b/include/drm/drmP.h
61253 @@ -72,6 +72,7 @@
61254 #include <linux/workqueue.h>
61255 #include <linux/poll.h>
61256 #include <asm/pgalloc.h>
61257 +#include <asm/local.h>
61258 #include <drm/drm.h>
61259 #include <drm/drm_sarea.h>
61260
61261 @@ -1068,7 +1069,7 @@ struct drm_device {
61262
61263 /** \name Usage Counters */
61264 /*@{ */
61265 - int open_count; /**< Outstanding files open */
61266 + local_t open_count; /**< Outstanding files open */
61267 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61268 atomic_t vma_count; /**< Outstanding vma areas open */
61269 int buf_use; /**< Buffers in use -- cannot alloc */
61270 @@ -1079,7 +1080,7 @@ struct drm_device {
61271 /*@{ */
61272 unsigned long counters;
61273 enum drm_stat_type types[15];
61274 - atomic_t counts[15];
61275 + atomic_unchecked_t counts[15];
61276 /*@} */
61277
61278 struct list_head filelist;
61279 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61280 index e01cc80..319855d 100644
61281 --- a/include/drm/drm_crtc_helper.h
61282 +++ b/include/drm/drm_crtc_helper.h
61283 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61284
61285 /* disable crtc when not in use - more explicit than dpms off */
61286 void (*disable)(struct drm_crtc *crtc);
61287 -};
61288 +} __no_const;
61289
61290 /**
61291 * drm_encoder_helper_funcs - helper operations for encoders
61292 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61293 struct drm_connector *connector);
61294 /* disable encoder when not in use - more explicit than dpms off */
61295 void (*disable)(struct drm_encoder *encoder);
61296 -};
61297 +} __no_const;
61298
61299 /**
61300 * drm_connector_helper_funcs - helper operations for connectors
61301 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61302 index d6d1da4..fdd1ac5 100644
61303 --- a/include/drm/ttm/ttm_memory.h
61304 +++ b/include/drm/ttm/ttm_memory.h
61305 @@ -48,7 +48,7 @@
61306
61307 struct ttm_mem_shrink {
61308 int (*do_shrink) (struct ttm_mem_shrink *);
61309 -};
61310 +} __no_const;
61311
61312 /**
61313 * struct ttm_mem_global - Global memory accounting structure.
61314 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61315 index 22ef21c..75904ba 100644
61316 --- a/include/linux/atmdev.h
61317 +++ b/include/linux/atmdev.h
61318 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
61319 #endif
61320
61321 struct k_atm_aal_stats {
61322 -#define __HANDLE_ITEM(i) atomic_t i
61323 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61324 __AAL_STAT_ITEMS
61325 #undef __HANDLE_ITEM
61326 };
61327 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61328 index cfcc6bf..9a7c73e 100644
61329 --- a/include/linux/binfmts.h
61330 +++ b/include/linux/binfmts.h
61331 @@ -75,6 +75,7 @@ struct linux_binfmt {
61332 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61333 int (*load_shlib)(struct file *);
61334 int (*core_dump)(struct coredump_params *cprm);
61335 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61336 unsigned long min_coredump; /* minimal dump size */
61337 };
61338
61339 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61340 index 1756001..ab117ec 100644
61341 --- a/include/linux/blkdev.h
61342 +++ b/include/linux/blkdev.h
61343 @@ -1478,7 +1478,7 @@ struct block_device_operations {
61344 /* this callback is with swap_lock and sometimes page table lock held */
61345 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61346 struct module *owner;
61347 -};
61348 +} __do_const;
61349
61350 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61351 unsigned long);
61352 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61353 index 7c2e030..b72475d 100644
61354 --- a/include/linux/blktrace_api.h
61355 +++ b/include/linux/blktrace_api.h
61356 @@ -23,7 +23,7 @@ struct blk_trace {
61357 struct dentry *dir;
61358 struct dentry *dropped_file;
61359 struct dentry *msg_file;
61360 - atomic_t dropped;
61361 + atomic_unchecked_t dropped;
61362 };
61363
61364 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61365 diff --git a/include/linux/cache.h b/include/linux/cache.h
61366 index 4c57065..4307975 100644
61367 --- a/include/linux/cache.h
61368 +++ b/include/linux/cache.h
61369 @@ -16,6 +16,10 @@
61370 #define __read_mostly
61371 #endif
61372
61373 +#ifndef __read_only
61374 +#define __read_only __read_mostly
61375 +#endif
61376 +
61377 #ifndef ____cacheline_aligned
61378 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61379 #endif
61380 diff --git a/include/linux/capability.h b/include/linux/capability.h
61381 index 98503b7..cc36d18 100644
61382 --- a/include/linux/capability.h
61383 +++ b/include/linux/capability.h
61384 @@ -211,8 +211,13 @@ extern bool capable(int cap);
61385 extern bool ns_capable(struct user_namespace *ns, int cap);
61386 extern bool nsown_capable(int cap);
61387 extern bool inode_capable(const struct inode *inode, int cap);
61388 +extern bool capable_nolog(int cap);
61389 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61390 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61391
61392 /* audit system wants to get cap info from files as well */
61393 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61394
61395 +extern int is_privileged_binary(const struct dentry *dentry);
61396 +
61397 #endif /* !_LINUX_CAPABILITY_H */
61398 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61399 index 42e55de..1cd0e66 100644
61400 --- a/include/linux/cleancache.h
61401 +++ b/include/linux/cleancache.h
61402 @@ -31,7 +31,7 @@ struct cleancache_ops {
61403 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61404 void (*invalidate_inode)(int, struct cleancache_filekey);
61405 void (*invalidate_fs)(int);
61406 -};
61407 +} __no_const;
61408
61409 extern struct cleancache_ops
61410 cleancache_register_ops(struct cleancache_ops *ops);
61411 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61412 index f9f5e9e..9fb4d36 100644
61413 --- a/include/linux/clk-provider.h
61414 +++ b/include/linux/clk-provider.h
61415 @@ -112,6 +112,7 @@ struct clk_ops {
61416 unsigned long);
61417 void (*init)(struct clk_hw *hw);
61418 };
61419 +typedef struct clk_ops __no_const clk_ops_no_const;
61420
61421 /**
61422 * struct clk_init_data - holds init data that's common to all clocks and is
61423 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61424 index 412bc6c..c31666e 100644
61425 --- a/include/linux/compiler-gcc4.h
61426 +++ b/include/linux/compiler-gcc4.h
61427 @@ -32,6 +32,21 @@
61428 #define __linktime_error(message) __attribute__((__error__(message)))
61429
61430 #if __GNUC_MINOR__ >= 5
61431 +
61432 +#ifdef CONSTIFY_PLUGIN
61433 +#define __no_const __attribute__((no_const))
61434 +#define __do_const __attribute__((do_const))
61435 +#endif
61436 +
61437 +#ifdef SIZE_OVERFLOW_PLUGIN
61438 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61439 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61440 +#endif
61441 +
61442 +#ifdef LATENT_ENTROPY_PLUGIN
61443 +#define __latent_entropy __attribute__((latent_entropy))
61444 +#endif
61445 +
61446 /*
61447 * Mark a position in code as unreachable. This can be used to
61448 * suppress control flow warnings after asm blocks that transfer
61449 @@ -47,6 +62,11 @@
61450 #define __noclone __attribute__((__noclone__))
61451
61452 #endif
61453 +
61454 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61455 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61456 +#define __bos0(ptr) __bos((ptr), 0)
61457 +#define __bos1(ptr) __bos((ptr), 1)
61458 #endif
61459
61460 #if __GNUC_MINOR__ >= 6
61461 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61462 index f430e41..38be90f 100644
61463 --- a/include/linux/compiler.h
61464 +++ b/include/linux/compiler.h
61465 @@ -5,31 +5,62 @@
61466
61467 #ifdef __CHECKER__
61468 # define __user __attribute__((noderef, address_space(1)))
61469 +# define __force_user __force __user
61470 # define __kernel __attribute__((address_space(0)))
61471 +# define __force_kernel __force __kernel
61472 # define __safe __attribute__((safe))
61473 # define __force __attribute__((force))
61474 # define __nocast __attribute__((nocast))
61475 # define __iomem __attribute__((noderef, address_space(2)))
61476 +# define __force_iomem __force __iomem
61477 # define __acquires(x) __attribute__((context(x,0,1)))
61478 # define __releases(x) __attribute__((context(x,1,0)))
61479 # define __acquire(x) __context__(x,1)
61480 # define __release(x) __context__(x,-1)
61481 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61482 # define __percpu __attribute__((noderef, address_space(3)))
61483 +# define __force_percpu __force __percpu
61484 #ifdef CONFIG_SPARSE_RCU_POINTER
61485 # define __rcu __attribute__((noderef, address_space(4)))
61486 +# define __force_rcu __force __rcu
61487 #else
61488 # define __rcu
61489 +# define __force_rcu
61490 #endif
61491 extern void __chk_user_ptr(const volatile void __user *);
61492 extern void __chk_io_ptr(const volatile void __iomem *);
61493 +#elif defined(CHECKER_PLUGIN)
61494 +//# define __user
61495 +//# define __force_user
61496 +//# define __kernel
61497 +//# define __force_kernel
61498 +# define __safe
61499 +# define __force
61500 +# define __nocast
61501 +# define __iomem
61502 +# define __force_iomem
61503 +# define __chk_user_ptr(x) (void)0
61504 +# define __chk_io_ptr(x) (void)0
61505 +# define __builtin_warning(x, y...) (1)
61506 +# define __acquires(x)
61507 +# define __releases(x)
61508 +# define __acquire(x) (void)0
61509 +# define __release(x) (void)0
61510 +# define __cond_lock(x,c) (c)
61511 +# define __percpu
61512 +# define __force_percpu
61513 +# define __rcu
61514 +# define __force_rcu
61515 #else
61516 # define __user
61517 +# define __force_user
61518 # define __kernel
61519 +# define __force_kernel
61520 # define __safe
61521 # define __force
61522 # define __nocast
61523 # define __iomem
61524 +# define __force_iomem
61525 # define __chk_user_ptr(x) (void)0
61526 # define __chk_io_ptr(x) (void)0
61527 # define __builtin_warning(x, y...) (1)
61528 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61529 # define __release(x) (void)0
61530 # define __cond_lock(x,c) (c)
61531 # define __percpu
61532 +# define __force_percpu
61533 # define __rcu
61534 +# define __force_rcu
61535 #endif
61536
61537 #ifdef __KERNEL__
61538 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61539 # define __attribute_const__ /* unimplemented */
61540 #endif
61541
61542 +#ifndef __no_const
61543 +# define __no_const
61544 +#endif
61545 +
61546 +#ifndef __do_const
61547 +# define __do_const
61548 +#endif
61549 +
61550 +#ifndef __size_overflow
61551 +# define __size_overflow(...)
61552 +#endif
61553 +
61554 +#ifndef __intentional_overflow
61555 +# define __intentional_overflow(...)
61556 +#endif
61557 +
61558 +#ifndef __latent_entropy
61559 +# define __latent_entropy
61560 +#endif
61561 +
61562 /*
61563 * Tell gcc if a function is cold. The compiler will assume any path
61564 * directly leading to the call is unlikely.
61565 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61566 #define __cold
61567 #endif
61568
61569 +#ifndef __alloc_size
61570 +#define __alloc_size(...)
61571 +#endif
61572 +
61573 +#ifndef __bos
61574 +#define __bos(ptr, arg)
61575 +#endif
61576 +
61577 +#ifndef __bos0
61578 +#define __bos0(ptr)
61579 +#endif
61580 +
61581 +#ifndef __bos1
61582 +#define __bos1(ptr)
61583 +#endif
61584 +
61585 /* Simple shorthand for a section definition */
61586 #ifndef __section
61587 # define __section(S) __attribute__ ((__section__(#S)))
61588 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61589 * use is to mediate communication between process-level code and irq/NMI
61590 * handlers, all running on the same CPU.
61591 */
61592 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61593 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61594 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61595
61596 #endif /* __LINUX_COMPILER_H */
61597 diff --git a/include/linux/cred.h b/include/linux/cred.h
61598 index ebbed2c..908cc2c 100644
61599 --- a/include/linux/cred.h
61600 +++ b/include/linux/cred.h
61601 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61602 static inline void validate_process_creds(void)
61603 {
61604 }
61605 +static inline void validate_task_creds(struct task_struct *task)
61606 +{
61607 +}
61608 #endif
61609
61610 /**
61611 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61612 index b92eadf..b4ecdc1 100644
61613 --- a/include/linux/crypto.h
61614 +++ b/include/linux/crypto.h
61615 @@ -373,7 +373,7 @@ struct cipher_tfm {
61616 const u8 *key, unsigned int keylen);
61617 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61618 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61619 -};
61620 +} __no_const;
61621
61622 struct hash_tfm {
61623 int (*init)(struct hash_desc *desc);
61624 @@ -394,13 +394,13 @@ struct compress_tfm {
61625 int (*cot_decompress)(struct crypto_tfm *tfm,
61626 const u8 *src, unsigned int slen,
61627 u8 *dst, unsigned int *dlen);
61628 -};
61629 +} __no_const;
61630
61631 struct rng_tfm {
61632 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61633 unsigned int dlen);
61634 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61635 -};
61636 +} __no_const;
61637
61638 #define crt_ablkcipher crt_u.ablkcipher
61639 #define crt_aead crt_u.aead
61640 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61641 index 7925bf0..d5143d2 100644
61642 --- a/include/linux/decompress/mm.h
61643 +++ b/include/linux/decompress/mm.h
61644 @@ -77,7 +77,7 @@ static void free(void *where)
61645 * warnings when not needed (indeed large_malloc / large_free are not
61646 * needed by inflate */
61647
61648 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61649 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61650 #define free(a) kfree(a)
61651
61652 #define large_malloc(a) vmalloc(a)
61653 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61654 index 94af418..b1ca7a2 100644
61655 --- a/include/linux/dma-mapping.h
61656 +++ b/include/linux/dma-mapping.h
61657 @@ -54,7 +54,7 @@ struct dma_map_ops {
61658 u64 (*get_required_mask)(struct device *dev);
61659 #endif
61660 int is_phys;
61661 -};
61662 +} __do_const;
61663
61664 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61665
61666 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61667 index d3201e4..8281e63 100644
61668 --- a/include/linux/dmaengine.h
61669 +++ b/include/linux/dmaengine.h
61670 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
61671 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61672 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61673
61674 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61675 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61676 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61677 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61678 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61679 struct dma_pinned_list *pinned_list, struct page *page,
61680 unsigned int offset, size_t len);
61681
61682 diff --git a/include/linux/efi.h b/include/linux/efi.h
61683 index 8670eb1..7eb3ade 100644
61684 --- a/include/linux/efi.h
61685 +++ b/include/linux/efi.h
61686 @@ -643,7 +643,7 @@ struct efivar_operations {
61687 efi_get_variable_t *get_variable;
61688 efi_get_next_variable_t *get_next_variable;
61689 efi_set_variable_t *set_variable;
61690 -};
61691 +} __no_const;
61692
61693 struct efivars {
61694 /*
61695 diff --git a/include/linux/elf.h b/include/linux/elf.h
61696 index 8c9048e..16a4665 100644
61697 --- a/include/linux/elf.h
61698 +++ b/include/linux/elf.h
61699 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
61700 #define elf_note elf32_note
61701 #define elf_addr_t Elf32_Off
61702 #define Elf_Half Elf32_Half
61703 +#define elf_dyn Elf32_Dyn
61704
61705 #else
61706
61707 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
61708 #define elf_note elf64_note
61709 #define elf_addr_t Elf64_Off
61710 #define Elf_Half Elf64_Half
61711 +#define elf_dyn Elf64_Dyn
61712
61713 #endif
61714
61715 diff --git a/include/linux/filter.h b/include/linux/filter.h
61716 index 24d251f..7afb83d 100644
61717 --- a/include/linux/filter.h
61718 +++ b/include/linux/filter.h
61719 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
61720
61721 struct sk_buff;
61722 struct sock;
61723 +struct bpf_jit_work;
61724
61725 struct sk_filter
61726 {
61727 @@ -27,6 +28,9 @@ struct sk_filter
61728 unsigned int len; /* Number of filter blocks */
61729 unsigned int (*bpf_func)(const struct sk_buff *skb,
61730 const struct sock_filter *filter);
61731 +#ifdef CONFIG_BPF_JIT
61732 + struct bpf_jit_work *work;
61733 +#endif
61734 struct rcu_head rcu;
61735 struct sock_filter insns[0];
61736 };
61737 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61738 index 191501a..3952e37 100644
61739 --- a/include/linux/firewire.h
61740 +++ b/include/linux/firewire.h
61741 @@ -438,7 +438,7 @@ struct fw_iso_context {
61742 union {
61743 fw_iso_callback_t sc;
61744 fw_iso_mc_callback_t mc;
61745 - } callback;
61746 + } __no_const callback;
61747 void *callback_data;
61748 };
61749
61750 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61751 index 3044254..9767f41 100644
61752 --- a/include/linux/frontswap.h
61753 +++ b/include/linux/frontswap.h
61754 @@ -11,7 +11,7 @@ struct frontswap_ops {
61755 int (*load)(unsigned, pgoff_t, struct page *);
61756 void (*invalidate_page)(unsigned, pgoff_t);
61757 void (*invalidate_area)(unsigned);
61758 -};
61759 +} __no_const;
61760
61761 extern bool frontswap_enabled;
61762 extern struct frontswap_ops
61763 diff --git a/include/linux/fs.h b/include/linux/fs.h
61764 index 75fe9a1..72a4a6b 100644
61765 --- a/include/linux/fs.h
61766 +++ b/include/linux/fs.h
61767 @@ -1543,7 +1543,8 @@ struct file_operations {
61768 int (*setlease)(struct file *, long, struct file_lock **);
61769 long (*fallocate)(struct file *file, int mode, loff_t offset,
61770 loff_t len);
61771 -};
61772 +} __do_const;
61773 +typedef struct file_operations __no_const file_operations_no_const;
61774
61775 struct inode_operations {
61776 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61777 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61778 index 003dc0f..3c4ea97 100644
61779 --- a/include/linux/fs_struct.h
61780 +++ b/include/linux/fs_struct.h
61781 @@ -6,7 +6,7 @@
61782 #include <linux/seqlock.h>
61783
61784 struct fs_struct {
61785 - int users;
61786 + atomic_t users;
61787 spinlock_t lock;
61788 seqcount_t seq;
61789 int umask;
61790 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61791 index ce31408..b1ad003 100644
61792 --- a/include/linux/fscache-cache.h
61793 +++ b/include/linux/fscache-cache.h
61794 @@ -102,7 +102,7 @@ struct fscache_operation {
61795 fscache_operation_release_t release;
61796 };
61797
61798 -extern atomic_t fscache_op_debug_id;
61799 +extern atomic_unchecked_t fscache_op_debug_id;
61800 extern void fscache_op_work_func(struct work_struct *work);
61801
61802 extern void fscache_enqueue_operation(struct fscache_operation *);
61803 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61804 {
61805 INIT_WORK(&op->work, fscache_op_work_func);
61806 atomic_set(&op->usage, 1);
61807 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61808 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61809 op->processor = processor;
61810 op->release = release;
61811 INIT_LIST_HEAD(&op->pend_link);
61812 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61813 index 0fbfb46..52a6556 100644
61814 --- a/include/linux/fsnotify.h
61815 +++ b/include/linux/fsnotify.h
61816 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61817 */
61818 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61819 {
61820 - return kstrdup(name, GFP_KERNEL);
61821 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61822 }
61823
61824 /*
61825 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61826 index 63d966d..cdcb717 100644
61827 --- a/include/linux/fsnotify_backend.h
61828 +++ b/include/linux/fsnotify_backend.h
61829 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61830 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61831 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61832 };
61833 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61834
61835 /*
61836 * A group is a "thing" that wants to receive notification about filesystem
61837 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61838 index 642928c..e6c83a7 100644
61839 --- a/include/linux/ftrace_event.h
61840 +++ b/include/linux/ftrace_event.h
61841 @@ -97,7 +97,7 @@ struct trace_event_functions {
61842 trace_print_func raw;
61843 trace_print_func hex;
61844 trace_print_func binary;
61845 -};
61846 +} __no_const;
61847
61848 struct trace_event {
61849 struct hlist_node node;
61850 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61851 extern int trace_add_event_call(struct ftrace_event_call *call);
61852 extern void trace_remove_event_call(struct ftrace_event_call *call);
61853
61854 -#define is_signed_type(type) (((type)(-1)) < 0)
61855 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61856
61857 int trace_set_clr_event(const char *system, const char *event, int set);
61858
61859 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61860 index 4f440b3..342233a 100644
61861 --- a/include/linux/genhd.h
61862 +++ b/include/linux/genhd.h
61863 @@ -190,7 +190,7 @@ struct gendisk {
61864 struct kobject *slave_dir;
61865
61866 struct timer_rand_state *random;
61867 - atomic_t sync_io; /* RAID */
61868 + atomic_unchecked_t sync_io; /* RAID */
61869 struct disk_events *ev;
61870 #ifdef CONFIG_BLK_DEV_INTEGRITY
61871 struct blk_integrity *integrity;
61872 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61873 index d0a7967..63c4c47 100644
61874 --- a/include/linux/gfp.h
61875 +++ b/include/linux/gfp.h
61876 @@ -35,6 +35,12 @@ struct vm_area_struct;
61877 #define ___GFP_OTHER_NODE 0x800000u
61878 #define ___GFP_WRITE 0x1000000u
61879
61880 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61881 +#define ___GFP_USERCOPY 0x2000000u
61882 +#else
61883 +#define ___GFP_USERCOPY 0
61884 +#endif
61885 +
61886 /*
61887 * GFP bitmasks..
61888 *
61889 @@ -89,6 +95,7 @@ struct vm_area_struct;
61890 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61891 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61892 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61893 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61894
61895 /*
61896 * This may seem redundant, but it's a way of annotating false positives vs.
61897 @@ -96,7 +103,7 @@ struct vm_area_struct;
61898 */
61899 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61900
61901 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61902 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61903 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61904
61905 /* This equals 0, but use constants in case they ever change */
61906 @@ -150,6 +157,8 @@ struct vm_area_struct;
61907 /* 4GB DMA on some platforms */
61908 #define GFP_DMA32 __GFP_DMA32
61909
61910 +#define GFP_USERCOPY __GFP_USERCOPY
61911 +
61912 /* Convert GFP flags to their corresponding migrate type */
61913 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61914 {
61915 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61916 new file mode 100644
61917 index 0000000..ebe6d72
61918 --- /dev/null
61919 +++ b/include/linux/gracl.h
61920 @@ -0,0 +1,319 @@
61921 +#ifndef GR_ACL_H
61922 +#define GR_ACL_H
61923 +
61924 +#include <linux/grdefs.h>
61925 +#include <linux/resource.h>
61926 +#include <linux/capability.h>
61927 +#include <linux/dcache.h>
61928 +#include <asm/resource.h>
61929 +
61930 +/* Major status information */
61931 +
61932 +#define GR_VERSION "grsecurity 2.9.1"
61933 +#define GRSECURITY_VERSION 0x2901
61934 +
61935 +enum {
61936 + GR_SHUTDOWN = 0,
61937 + GR_ENABLE = 1,
61938 + GR_SPROLE = 2,
61939 + GR_RELOAD = 3,
61940 + GR_SEGVMOD = 4,
61941 + GR_STATUS = 5,
61942 + GR_UNSPROLE = 6,
61943 + GR_PASSSET = 7,
61944 + GR_SPROLEPAM = 8,
61945 +};
61946 +
61947 +/* Password setup definitions
61948 + * kernel/grhash.c */
61949 +enum {
61950 + GR_PW_LEN = 128,
61951 + GR_SALT_LEN = 16,
61952 + GR_SHA_LEN = 32,
61953 +};
61954 +
61955 +enum {
61956 + GR_SPROLE_LEN = 64,
61957 +};
61958 +
61959 +enum {
61960 + GR_NO_GLOB = 0,
61961 + GR_REG_GLOB,
61962 + GR_CREATE_GLOB
61963 +};
61964 +
61965 +#define GR_NLIMITS 32
61966 +
61967 +/* Begin Data Structures */
61968 +
61969 +struct sprole_pw {
61970 + unsigned char *rolename;
61971 + unsigned char salt[GR_SALT_LEN];
61972 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61973 +};
61974 +
61975 +struct name_entry {
61976 + __u32 key;
61977 + ino_t inode;
61978 + dev_t device;
61979 + char *name;
61980 + __u16 len;
61981 + __u8 deleted;
61982 + struct name_entry *prev;
61983 + struct name_entry *next;
61984 +};
61985 +
61986 +struct inodev_entry {
61987 + struct name_entry *nentry;
61988 + struct inodev_entry *prev;
61989 + struct inodev_entry *next;
61990 +};
61991 +
61992 +struct acl_role_db {
61993 + struct acl_role_label **r_hash;
61994 + __u32 r_size;
61995 +};
61996 +
61997 +struct inodev_db {
61998 + struct inodev_entry **i_hash;
61999 + __u32 i_size;
62000 +};
62001 +
62002 +struct name_db {
62003 + struct name_entry **n_hash;
62004 + __u32 n_size;
62005 +};
62006 +
62007 +struct crash_uid {
62008 + uid_t uid;
62009 + unsigned long expires;
62010 +};
62011 +
62012 +struct gr_hash_struct {
62013 + void **table;
62014 + void **nametable;
62015 + void *first;
62016 + __u32 table_size;
62017 + __u32 used_size;
62018 + int type;
62019 +};
62020 +
62021 +/* Userspace Grsecurity ACL data structures */
62022 +
62023 +struct acl_subject_label {
62024 + char *filename;
62025 + ino_t inode;
62026 + dev_t device;
62027 + __u32 mode;
62028 + kernel_cap_t cap_mask;
62029 + kernel_cap_t cap_lower;
62030 + kernel_cap_t cap_invert_audit;
62031 +
62032 + struct rlimit res[GR_NLIMITS];
62033 + __u32 resmask;
62034 +
62035 + __u8 user_trans_type;
62036 + __u8 group_trans_type;
62037 + uid_t *user_transitions;
62038 + gid_t *group_transitions;
62039 + __u16 user_trans_num;
62040 + __u16 group_trans_num;
62041 +
62042 + __u32 sock_families[2];
62043 + __u32 ip_proto[8];
62044 + __u32 ip_type;
62045 + struct acl_ip_label **ips;
62046 + __u32 ip_num;
62047 + __u32 inaddr_any_override;
62048 +
62049 + __u32 crashes;
62050 + unsigned long expires;
62051 +
62052 + struct acl_subject_label *parent_subject;
62053 + struct gr_hash_struct *hash;
62054 + struct acl_subject_label *prev;
62055 + struct acl_subject_label *next;
62056 +
62057 + struct acl_object_label **obj_hash;
62058 + __u32 obj_hash_size;
62059 + __u16 pax_flags;
62060 +};
62061 +
62062 +struct role_allowed_ip {
62063 + __u32 addr;
62064 + __u32 netmask;
62065 +
62066 + struct role_allowed_ip *prev;
62067 + struct role_allowed_ip *next;
62068 +};
62069 +
62070 +struct role_transition {
62071 + char *rolename;
62072 +
62073 + struct role_transition *prev;
62074 + struct role_transition *next;
62075 +};
62076 +
62077 +struct acl_role_label {
62078 + char *rolename;
62079 + uid_t uidgid;
62080 + __u16 roletype;
62081 +
62082 + __u16 auth_attempts;
62083 + unsigned long expires;
62084 +
62085 + struct acl_subject_label *root_label;
62086 + struct gr_hash_struct *hash;
62087 +
62088 + struct acl_role_label *prev;
62089 + struct acl_role_label *next;
62090 +
62091 + struct role_transition *transitions;
62092 + struct role_allowed_ip *allowed_ips;
62093 + uid_t *domain_children;
62094 + __u16 domain_child_num;
62095 +
62096 + umode_t umask;
62097 +
62098 + struct acl_subject_label **subj_hash;
62099 + __u32 subj_hash_size;
62100 +};
62101 +
62102 +struct user_acl_role_db {
62103 + struct acl_role_label **r_table;
62104 + __u32 num_pointers; /* Number of allocations to track */
62105 + __u32 num_roles; /* Number of roles */
62106 + __u32 num_domain_children; /* Number of domain children */
62107 + __u32 num_subjects; /* Number of subjects */
62108 + __u32 num_objects; /* Number of objects */
62109 +};
62110 +
62111 +struct acl_object_label {
62112 + char *filename;
62113 + ino_t inode;
62114 + dev_t device;
62115 + __u32 mode;
62116 +
62117 + struct acl_subject_label *nested;
62118 + struct acl_object_label *globbed;
62119 +
62120 + /* next two structures not used */
62121 +
62122 + struct acl_object_label *prev;
62123 + struct acl_object_label *next;
62124 +};
62125 +
62126 +struct acl_ip_label {
62127 + char *iface;
62128 + __u32 addr;
62129 + __u32 netmask;
62130 + __u16 low, high;
62131 + __u8 mode;
62132 + __u32 type;
62133 + __u32 proto[8];
62134 +
62135 + /* next two structures not used */
62136 +
62137 + struct acl_ip_label *prev;
62138 + struct acl_ip_label *next;
62139 +};
62140 +
62141 +struct gr_arg {
62142 + struct user_acl_role_db role_db;
62143 + unsigned char pw[GR_PW_LEN];
62144 + unsigned char salt[GR_SALT_LEN];
62145 + unsigned char sum[GR_SHA_LEN];
62146 + unsigned char sp_role[GR_SPROLE_LEN];
62147 + struct sprole_pw *sprole_pws;
62148 + dev_t segv_device;
62149 + ino_t segv_inode;
62150 + uid_t segv_uid;
62151 + __u16 num_sprole_pws;
62152 + __u16 mode;
62153 +};
62154 +
62155 +struct gr_arg_wrapper {
62156 + struct gr_arg *arg;
62157 + __u32 version;
62158 + __u32 size;
62159 +};
62160 +
62161 +struct subject_map {
62162 + struct acl_subject_label *user;
62163 + struct acl_subject_label *kernel;
62164 + struct subject_map *prev;
62165 + struct subject_map *next;
62166 +};
62167 +
62168 +struct acl_subj_map_db {
62169 + struct subject_map **s_hash;
62170 + __u32 s_size;
62171 +};
62172 +
62173 +/* End Data Structures Section */
62174 +
62175 +/* Hash functions generated by empirical testing by Brad Spengler
62176 + Makes good use of the low bits of the inode. Generally 0-1 times
62177 + in loop for successful match. 0-3 for unsuccessful match.
62178 + Shift/add algorithm with modulus of table size and an XOR*/
62179 +
62180 +static __inline__ unsigned int
62181 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62182 +{
62183 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62184 +}
62185 +
62186 + static __inline__ unsigned int
62187 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
62188 +{
62189 + return ((const unsigned long)userp % sz);
62190 +}
62191 +
62192 +static __inline__ unsigned int
62193 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62194 +{
62195 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62196 +}
62197 +
62198 +static __inline__ unsigned int
62199 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
62200 +{
62201 + return full_name_hash((const unsigned char *)name, len) % sz;
62202 +}
62203 +
62204 +#define FOR_EACH_ROLE_START(role) \
62205 + role = role_list; \
62206 + while (role) {
62207 +
62208 +#define FOR_EACH_ROLE_END(role) \
62209 + role = role->prev; \
62210 + }
62211 +
62212 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62213 + subj = NULL; \
62214 + iter = 0; \
62215 + while (iter < role->subj_hash_size) { \
62216 + if (subj == NULL) \
62217 + subj = role->subj_hash[iter]; \
62218 + if (subj == NULL) { \
62219 + iter++; \
62220 + continue; \
62221 + }
62222 +
62223 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62224 + subj = subj->next; \
62225 + if (subj == NULL) \
62226 + iter++; \
62227 + }
62228 +
62229 +
62230 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62231 + subj = role->hash->first; \
62232 + while (subj != NULL) {
62233 +
62234 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62235 + subj = subj->next; \
62236 + }
62237 +
62238 +#endif
62239 +
62240 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62241 new file mode 100644
62242 index 0000000..323ecf2
62243 --- /dev/null
62244 +++ b/include/linux/gralloc.h
62245 @@ -0,0 +1,9 @@
62246 +#ifndef __GRALLOC_H
62247 +#define __GRALLOC_H
62248 +
62249 +void acl_free_all(void);
62250 +int acl_alloc_stack_init(unsigned long size);
62251 +void *acl_alloc(unsigned long len);
62252 +void *acl_alloc_num(unsigned long num, unsigned long len);
62253 +
62254 +#endif
62255 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62256 new file mode 100644
62257 index 0000000..b30e9bc
62258 --- /dev/null
62259 +++ b/include/linux/grdefs.h
62260 @@ -0,0 +1,140 @@
62261 +#ifndef GRDEFS_H
62262 +#define GRDEFS_H
62263 +
62264 +/* Begin grsecurity status declarations */
62265 +
62266 +enum {
62267 + GR_READY = 0x01,
62268 + GR_STATUS_INIT = 0x00 // disabled state
62269 +};
62270 +
62271 +/* Begin ACL declarations */
62272 +
62273 +/* Role flags */
62274 +
62275 +enum {
62276 + GR_ROLE_USER = 0x0001,
62277 + GR_ROLE_GROUP = 0x0002,
62278 + GR_ROLE_DEFAULT = 0x0004,
62279 + GR_ROLE_SPECIAL = 0x0008,
62280 + GR_ROLE_AUTH = 0x0010,
62281 + GR_ROLE_NOPW = 0x0020,
62282 + GR_ROLE_GOD = 0x0040,
62283 + GR_ROLE_LEARN = 0x0080,
62284 + GR_ROLE_TPE = 0x0100,
62285 + GR_ROLE_DOMAIN = 0x0200,
62286 + GR_ROLE_PAM = 0x0400,
62287 + GR_ROLE_PERSIST = 0x0800
62288 +};
62289 +
62290 +/* ACL Subject and Object mode flags */
62291 +enum {
62292 + GR_DELETED = 0x80000000
62293 +};
62294 +
62295 +/* ACL Object-only mode flags */
62296 +enum {
62297 + GR_READ = 0x00000001,
62298 + GR_APPEND = 0x00000002,
62299 + GR_WRITE = 0x00000004,
62300 + GR_EXEC = 0x00000008,
62301 + GR_FIND = 0x00000010,
62302 + GR_INHERIT = 0x00000020,
62303 + GR_SETID = 0x00000040,
62304 + GR_CREATE = 0x00000080,
62305 + GR_DELETE = 0x00000100,
62306 + GR_LINK = 0x00000200,
62307 + GR_AUDIT_READ = 0x00000400,
62308 + GR_AUDIT_APPEND = 0x00000800,
62309 + GR_AUDIT_WRITE = 0x00001000,
62310 + GR_AUDIT_EXEC = 0x00002000,
62311 + GR_AUDIT_FIND = 0x00004000,
62312 + GR_AUDIT_INHERIT= 0x00008000,
62313 + GR_AUDIT_SETID = 0x00010000,
62314 + GR_AUDIT_CREATE = 0x00020000,
62315 + GR_AUDIT_DELETE = 0x00040000,
62316 + GR_AUDIT_LINK = 0x00080000,
62317 + GR_PTRACERD = 0x00100000,
62318 + GR_NOPTRACE = 0x00200000,
62319 + GR_SUPPRESS = 0x00400000,
62320 + GR_NOLEARN = 0x00800000,
62321 + GR_INIT_TRANSFER= 0x01000000
62322 +};
62323 +
62324 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62325 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62326 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62327 +
62328 +/* ACL subject-only mode flags */
62329 +enum {
62330 + GR_KILL = 0x00000001,
62331 + GR_VIEW = 0x00000002,
62332 + GR_PROTECTED = 0x00000004,
62333 + GR_LEARN = 0x00000008,
62334 + GR_OVERRIDE = 0x00000010,
62335 + /* just a placeholder, this mode is only used in userspace */
62336 + GR_DUMMY = 0x00000020,
62337 + GR_PROTSHM = 0x00000040,
62338 + GR_KILLPROC = 0x00000080,
62339 + GR_KILLIPPROC = 0x00000100,
62340 + /* just a placeholder, this mode is only used in userspace */
62341 + GR_NOTROJAN = 0x00000200,
62342 + GR_PROTPROCFD = 0x00000400,
62343 + GR_PROCACCT = 0x00000800,
62344 + GR_RELAXPTRACE = 0x00001000,
62345 + GR_NESTED = 0x00002000,
62346 + GR_INHERITLEARN = 0x00004000,
62347 + GR_PROCFIND = 0x00008000,
62348 + GR_POVERRIDE = 0x00010000,
62349 + GR_KERNELAUTH = 0x00020000,
62350 + GR_ATSECURE = 0x00040000,
62351 + GR_SHMEXEC = 0x00080000
62352 +};
62353 +
62354 +enum {
62355 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62356 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62357 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62358 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62359 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62360 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62361 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62362 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62363 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62364 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62365 +};
62366 +
62367 +enum {
62368 + GR_ID_USER = 0x01,
62369 + GR_ID_GROUP = 0x02,
62370 +};
62371 +
62372 +enum {
62373 + GR_ID_ALLOW = 0x01,
62374 + GR_ID_DENY = 0x02,
62375 +};
62376 +
62377 +#define GR_CRASH_RES 31
62378 +#define GR_UIDTABLE_MAX 500
62379 +
62380 +/* begin resource learning section */
62381 +enum {
62382 + GR_RLIM_CPU_BUMP = 60,
62383 + GR_RLIM_FSIZE_BUMP = 50000,
62384 + GR_RLIM_DATA_BUMP = 10000,
62385 + GR_RLIM_STACK_BUMP = 1000,
62386 + GR_RLIM_CORE_BUMP = 10000,
62387 + GR_RLIM_RSS_BUMP = 500000,
62388 + GR_RLIM_NPROC_BUMP = 1,
62389 + GR_RLIM_NOFILE_BUMP = 5,
62390 + GR_RLIM_MEMLOCK_BUMP = 50000,
62391 + GR_RLIM_AS_BUMP = 500000,
62392 + GR_RLIM_LOCKS_BUMP = 2,
62393 + GR_RLIM_SIGPENDING_BUMP = 5,
62394 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62395 + GR_RLIM_NICE_BUMP = 1,
62396 + GR_RLIM_RTPRIO_BUMP = 1,
62397 + GR_RLIM_RTTIME_BUMP = 1000000
62398 +};
62399 +
62400 +#endif
62401 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62402 new file mode 100644
62403 index 0000000..c9292f7
62404 --- /dev/null
62405 +++ b/include/linux/grinternal.h
62406 @@ -0,0 +1,223 @@
62407 +#ifndef __GRINTERNAL_H
62408 +#define __GRINTERNAL_H
62409 +
62410 +#ifdef CONFIG_GRKERNSEC
62411 +
62412 +#include <linux/fs.h>
62413 +#include <linux/mnt_namespace.h>
62414 +#include <linux/nsproxy.h>
62415 +#include <linux/gracl.h>
62416 +#include <linux/grdefs.h>
62417 +#include <linux/grmsg.h>
62418 +
62419 +void gr_add_learn_entry(const char *fmt, ...)
62420 + __attribute__ ((format (printf, 1, 2)));
62421 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62422 + const struct vfsmount *mnt);
62423 +__u32 gr_check_create(const struct dentry *new_dentry,
62424 + const struct dentry *parent,
62425 + const struct vfsmount *mnt, const __u32 mode);
62426 +int gr_check_protected_task(const struct task_struct *task);
62427 +__u32 to_gr_audit(const __u32 reqmode);
62428 +int gr_set_acls(const int type);
62429 +int gr_apply_subject_to_task(struct task_struct *task);
62430 +int gr_acl_is_enabled(void);
62431 +char gr_roletype_to_char(void);
62432 +
62433 +void gr_handle_alertkill(struct task_struct *task);
62434 +char *gr_to_filename(const struct dentry *dentry,
62435 + const struct vfsmount *mnt);
62436 +char *gr_to_filename1(const struct dentry *dentry,
62437 + const struct vfsmount *mnt);
62438 +char *gr_to_filename2(const struct dentry *dentry,
62439 + const struct vfsmount *mnt);
62440 +char *gr_to_filename3(const struct dentry *dentry,
62441 + const struct vfsmount *mnt);
62442 +
62443 +extern int grsec_enable_ptrace_readexec;
62444 +extern int grsec_enable_harden_ptrace;
62445 +extern int grsec_enable_link;
62446 +extern int grsec_enable_fifo;
62447 +extern int grsec_enable_execve;
62448 +extern int grsec_enable_shm;
62449 +extern int grsec_enable_execlog;
62450 +extern int grsec_enable_signal;
62451 +extern int grsec_enable_audit_ptrace;
62452 +extern int grsec_enable_forkfail;
62453 +extern int grsec_enable_time;
62454 +extern int grsec_enable_rofs;
62455 +extern int grsec_enable_chroot_shmat;
62456 +extern int grsec_enable_chroot_mount;
62457 +extern int grsec_enable_chroot_double;
62458 +extern int grsec_enable_chroot_pivot;
62459 +extern int grsec_enable_chroot_chdir;
62460 +extern int grsec_enable_chroot_chmod;
62461 +extern int grsec_enable_chroot_mknod;
62462 +extern int grsec_enable_chroot_fchdir;
62463 +extern int grsec_enable_chroot_nice;
62464 +extern int grsec_enable_chroot_execlog;
62465 +extern int grsec_enable_chroot_caps;
62466 +extern int grsec_enable_chroot_sysctl;
62467 +extern int grsec_enable_chroot_unix;
62468 +extern int grsec_enable_symlinkown;
62469 +extern int grsec_symlinkown_gid;
62470 +extern int grsec_enable_tpe;
62471 +extern int grsec_tpe_gid;
62472 +extern int grsec_enable_tpe_all;
62473 +extern int grsec_enable_tpe_invert;
62474 +extern int grsec_enable_socket_all;
62475 +extern int grsec_socket_all_gid;
62476 +extern int grsec_enable_socket_client;
62477 +extern int grsec_socket_client_gid;
62478 +extern int grsec_enable_socket_server;
62479 +extern int grsec_socket_server_gid;
62480 +extern int grsec_audit_gid;
62481 +extern int grsec_enable_group;
62482 +extern int grsec_enable_audit_textrel;
62483 +extern int grsec_enable_log_rwxmaps;
62484 +extern int grsec_enable_mount;
62485 +extern int grsec_enable_chdir;
62486 +extern int grsec_resource_logging;
62487 +extern int grsec_enable_blackhole;
62488 +extern int grsec_lastack_retries;
62489 +extern int grsec_enable_brute;
62490 +extern int grsec_lock;
62491 +
62492 +extern spinlock_t grsec_alert_lock;
62493 +extern unsigned long grsec_alert_wtime;
62494 +extern unsigned long grsec_alert_fyet;
62495 +
62496 +extern spinlock_t grsec_audit_lock;
62497 +
62498 +extern rwlock_t grsec_exec_file_lock;
62499 +
62500 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62501 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62502 + (tsk)->exec_file->f_vfsmnt) : "/")
62503 +
62504 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62505 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62506 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62507 +
62508 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62509 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62510 + (tsk)->exec_file->f_vfsmnt) : "/")
62511 +
62512 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62513 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62514 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62515 +
62516 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62517 +
62518 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62519 +
62520 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62521 + (task)->pid, (cred)->uid, \
62522 + (cred)->euid, (cred)->gid, (cred)->egid, \
62523 + gr_parent_task_fullpath(task), \
62524 + (task)->real_parent->comm, (task)->real_parent->pid, \
62525 + (pcred)->uid, (pcred)->euid, \
62526 + (pcred)->gid, (pcred)->egid
62527 +
62528 +#define GR_CHROOT_CAPS {{ \
62529 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62530 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62531 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62532 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62533 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62534 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62535 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62536 +
62537 +#define security_learn(normal_msg,args...) \
62538 +({ \
62539 + read_lock(&grsec_exec_file_lock); \
62540 + gr_add_learn_entry(normal_msg "\n", ## args); \
62541 + read_unlock(&grsec_exec_file_lock); \
62542 +})
62543 +
62544 +enum {
62545 + GR_DO_AUDIT,
62546 + GR_DONT_AUDIT,
62547 + /* used for non-audit messages that we shouldn't kill the task on */
62548 + GR_DONT_AUDIT_GOOD
62549 +};
62550 +
62551 +enum {
62552 + GR_TTYSNIFF,
62553 + GR_RBAC,
62554 + GR_RBAC_STR,
62555 + GR_STR_RBAC,
62556 + GR_RBAC_MODE2,
62557 + GR_RBAC_MODE3,
62558 + GR_FILENAME,
62559 + GR_SYSCTL_HIDDEN,
62560 + GR_NOARGS,
62561 + GR_ONE_INT,
62562 + GR_ONE_INT_TWO_STR,
62563 + GR_ONE_STR,
62564 + GR_STR_INT,
62565 + GR_TWO_STR_INT,
62566 + GR_TWO_INT,
62567 + GR_TWO_U64,
62568 + GR_THREE_INT,
62569 + GR_FIVE_INT_TWO_STR,
62570 + GR_TWO_STR,
62571 + GR_THREE_STR,
62572 + GR_FOUR_STR,
62573 + GR_STR_FILENAME,
62574 + GR_FILENAME_STR,
62575 + GR_FILENAME_TWO_INT,
62576 + GR_FILENAME_TWO_INT_STR,
62577 + GR_TEXTREL,
62578 + GR_PTRACE,
62579 + GR_RESOURCE,
62580 + GR_CAP,
62581 + GR_SIG,
62582 + GR_SIG2,
62583 + GR_CRASH1,
62584 + GR_CRASH2,
62585 + GR_PSACCT,
62586 + GR_RWXMAP
62587 +};
62588 +
62589 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62590 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62591 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62592 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62593 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62594 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62595 +#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)
62596 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62597 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62598 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62599 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62600 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62601 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62602 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62603 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62604 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62605 +#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)
62606 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62607 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62608 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62609 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62610 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62611 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62612 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62613 +#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)
62614 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62615 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62616 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62617 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62618 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62619 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62620 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62621 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62622 +#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)
62623 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62624 +
62625 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62626 +
62627 +#endif
62628 +
62629 +#endif
62630 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62631 new file mode 100644
62632 index 0000000..2bd4c8d
62633 --- /dev/null
62634 +++ b/include/linux/grmsg.h
62635 @@ -0,0 +1,111 @@
62636 +#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"
62637 +#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"
62638 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62639 +#define GR_STOPMOD_MSG "denied modification of module state by "
62640 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62641 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62642 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62643 +#define GR_IOPL_MSG "denied use of iopl() by "
62644 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62645 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62646 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62647 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62648 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62649 +#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"
62650 +#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"
62651 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62652 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62653 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62654 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62655 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62656 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62657 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62658 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62659 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62660 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62661 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62662 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62663 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62664 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62665 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62666 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62667 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62668 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62669 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62670 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62671 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62672 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62673 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62674 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62675 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62676 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62677 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62678 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62679 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62680 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62681 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62682 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62683 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62684 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62685 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62686 +#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"
62687 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62688 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62689 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62690 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62691 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62692 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62693 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62694 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62695 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62696 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62697 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62698 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62699 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62700 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62701 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62702 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62703 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62704 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62705 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62706 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62707 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62708 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62709 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62710 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62711 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62712 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62713 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62714 +#define GR_TIME_MSG "time set by "
62715 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62716 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62717 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62718 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62719 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62720 +#define GR_BIND_MSG "denied bind() by "
62721 +#define GR_CONNECT_MSG "denied connect() by "
62722 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62723 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62724 +#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"
62725 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62726 +#define GR_CAP_ACL_MSG "use of %s denied for "
62727 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62728 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62729 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62730 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62731 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62732 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62733 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62734 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62735 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62736 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62737 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62738 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62739 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62740 +#define GR_VM86_MSG "denied use of vm86 by "
62741 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62742 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62743 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62744 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62745 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62746 +#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 "
62747 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62748 new file mode 100644
62749 index 0000000..f2f5d5b
62750 --- /dev/null
62751 +++ b/include/linux/grsecurity.h
62752 @@ -0,0 +1,239 @@
62753 +#ifndef GR_SECURITY_H
62754 +#define GR_SECURITY_H
62755 +#include <linux/fs.h>
62756 +#include <linux/fs_struct.h>
62757 +#include <linux/binfmts.h>
62758 +#include <linux/gracl.h>
62759 +
62760 +/* notify of brain-dead configs */
62761 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62762 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62763 +#endif
62764 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62765 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62766 +#endif
62767 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62768 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62769 +#endif
62770 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62771 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62772 +#endif
62773 +
62774 +#include <linux/compat.h>
62775 +
62776 +struct user_arg_ptr {
62777 +#ifdef CONFIG_COMPAT
62778 + bool is_compat;
62779 +#endif
62780 + union {
62781 + const char __user *const __user *native;
62782 +#ifdef CONFIG_COMPAT
62783 + const compat_uptr_t __user *compat;
62784 +#endif
62785 + } ptr;
62786 +};
62787 +
62788 +void gr_handle_brute_attach(unsigned long mm_flags);
62789 +void gr_handle_brute_check(void);
62790 +void gr_handle_kernel_exploit(void);
62791 +int gr_process_user_ban(void);
62792 +
62793 +char gr_roletype_to_char(void);
62794 +
62795 +int gr_acl_enable_at_secure(void);
62796 +
62797 +int gr_check_user_change(int real, int effective, int fs);
62798 +int gr_check_group_change(int real, int effective, int fs);
62799 +
62800 +void gr_del_task_from_ip_table(struct task_struct *p);
62801 +
62802 +int gr_pid_is_chrooted(struct task_struct *p);
62803 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62804 +int gr_handle_chroot_nice(void);
62805 +int gr_handle_chroot_sysctl(const int op);
62806 +int gr_handle_chroot_setpriority(struct task_struct *p,
62807 + const int niceval);
62808 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62809 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62810 + const struct vfsmount *mnt);
62811 +void gr_handle_chroot_chdir(struct path *path);
62812 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62813 + const struct vfsmount *mnt, const int mode);
62814 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62815 + const struct vfsmount *mnt, const int mode);
62816 +int gr_handle_chroot_mount(const struct dentry *dentry,
62817 + const struct vfsmount *mnt,
62818 + const char *dev_name);
62819 +int gr_handle_chroot_pivot(void);
62820 +int gr_handle_chroot_unix(const pid_t pid);
62821 +
62822 +int gr_handle_rawio(const struct inode *inode);
62823 +
62824 +void gr_handle_ioperm(void);
62825 +void gr_handle_iopl(void);
62826 +
62827 +umode_t gr_acl_umask(void);
62828 +
62829 +int gr_tpe_allow(const struct file *file);
62830 +
62831 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62832 +void gr_clear_chroot_entries(struct task_struct *task);
62833 +
62834 +void gr_log_forkfail(const int retval);
62835 +void gr_log_timechange(void);
62836 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62837 +void gr_log_chdir(const struct dentry *dentry,
62838 + const struct vfsmount *mnt);
62839 +void gr_log_chroot_exec(const struct dentry *dentry,
62840 + const struct vfsmount *mnt);
62841 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62842 +void gr_log_remount(const char *devname, const int retval);
62843 +void gr_log_unmount(const char *devname, const int retval);
62844 +void gr_log_mount(const char *from, const char *to, const int retval);
62845 +void gr_log_textrel(struct vm_area_struct *vma);
62846 +void gr_log_rwxmmap(struct file *file);
62847 +void gr_log_rwxmprotect(struct file *file);
62848 +
62849 +int gr_handle_follow_link(const struct inode *parent,
62850 + const struct inode *inode,
62851 + const struct dentry *dentry,
62852 + const struct vfsmount *mnt);
62853 +int gr_handle_fifo(const struct dentry *dentry,
62854 + const struct vfsmount *mnt,
62855 + const struct dentry *dir, const int flag,
62856 + const int acc_mode);
62857 +int gr_handle_hardlink(const struct dentry *dentry,
62858 + const struct vfsmount *mnt,
62859 + struct inode *inode,
62860 + const int mode, const struct filename *to);
62861 +
62862 +int gr_is_capable(const int cap);
62863 +int gr_is_capable_nolog(const int cap);
62864 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62865 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62866 +
62867 +void gr_learn_resource(const struct task_struct *task, const int limit,
62868 + const unsigned long wanted, const int gt);
62869 +void gr_copy_label(struct task_struct *tsk);
62870 +void gr_handle_crash(struct task_struct *task, const int sig);
62871 +int gr_handle_signal(const struct task_struct *p, const int sig);
62872 +int gr_check_crash_uid(const uid_t uid);
62873 +int gr_check_protected_task(const struct task_struct *task);
62874 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62875 +int gr_acl_handle_mmap(const struct file *file,
62876 + const unsigned long prot);
62877 +int gr_acl_handle_mprotect(const struct file *file,
62878 + const unsigned long prot);
62879 +int gr_check_hidden_task(const struct task_struct *tsk);
62880 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62881 + const struct vfsmount *mnt);
62882 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62883 + const struct vfsmount *mnt);
62884 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62885 + const struct vfsmount *mnt, const int fmode);
62886 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62887 + const struct vfsmount *mnt, umode_t *mode);
62888 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62889 + const struct vfsmount *mnt);
62890 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62891 + const struct vfsmount *mnt);
62892 +int gr_handle_ptrace(struct task_struct *task, const long request);
62893 +int gr_handle_proc_ptrace(struct task_struct *task);
62894 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62895 + const struct vfsmount *mnt);
62896 +int gr_check_crash_exec(const struct file *filp);
62897 +int gr_acl_is_enabled(void);
62898 +void gr_set_kernel_label(struct task_struct *task);
62899 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62900 + const gid_t gid);
62901 +int gr_set_proc_label(const struct dentry *dentry,
62902 + const struct vfsmount *mnt,
62903 + const int unsafe_flags);
62904 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62905 + const struct vfsmount *mnt);
62906 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62907 + const struct vfsmount *mnt, int acc_mode);
62908 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62909 + const struct dentry *p_dentry,
62910 + const struct vfsmount *p_mnt,
62911 + int open_flags, int acc_mode, const int imode);
62912 +void gr_handle_create(const struct dentry *dentry,
62913 + const struct vfsmount *mnt);
62914 +void gr_handle_proc_create(const struct dentry *dentry,
62915 + const struct inode *inode);
62916 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62917 + const struct dentry *parent_dentry,
62918 + const struct vfsmount *parent_mnt,
62919 + const int mode);
62920 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62921 + const struct dentry *parent_dentry,
62922 + const struct vfsmount *parent_mnt);
62923 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62924 + const struct vfsmount *mnt);
62925 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62926 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62927 + const struct vfsmount *mnt);
62928 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62929 + const struct dentry *parent_dentry,
62930 + const struct vfsmount *parent_mnt,
62931 + const struct filename *from);
62932 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62933 + const struct dentry *parent_dentry,
62934 + const struct vfsmount *parent_mnt,
62935 + const struct dentry *old_dentry,
62936 + const struct vfsmount *old_mnt, const struct filename *to);
62937 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62938 +int gr_acl_handle_rename(struct dentry *new_dentry,
62939 + struct dentry *parent_dentry,
62940 + const struct vfsmount *parent_mnt,
62941 + struct dentry *old_dentry,
62942 + struct inode *old_parent_inode,
62943 + struct vfsmount *old_mnt, const struct filename *newname);
62944 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62945 + struct dentry *old_dentry,
62946 + struct dentry *new_dentry,
62947 + struct vfsmount *mnt, const __u8 replace);
62948 +__u32 gr_check_link(const struct dentry *new_dentry,
62949 + const struct dentry *parent_dentry,
62950 + const struct vfsmount *parent_mnt,
62951 + const struct dentry *old_dentry,
62952 + const struct vfsmount *old_mnt);
62953 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62954 + const unsigned int namelen, const ino_t ino);
62955 +
62956 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62957 + const struct vfsmount *mnt);
62958 +void gr_acl_handle_exit(void);
62959 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62960 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62961 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62962 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62963 +void gr_audit_ptrace(struct task_struct *task);
62964 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62965 +void gr_put_exec_file(struct task_struct *task);
62966 +
62967 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62968 +
62969 +#ifdef CONFIG_GRKERNSEC
62970 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62971 +void gr_handle_vm86(void);
62972 +void gr_handle_mem_readwrite(u64 from, u64 to);
62973 +
62974 +void gr_log_badprocpid(const char *entry);
62975 +
62976 +extern int grsec_enable_dmesg;
62977 +extern int grsec_disable_privio;
62978 +
62979 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62980 +extern int grsec_proc_gid;
62981 +#endif
62982 +
62983 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62984 +extern int grsec_enable_chroot_findtask;
62985 +#endif
62986 +#ifdef CONFIG_GRKERNSEC_SETXID
62987 +extern int grsec_enable_setxid;
62988 +#endif
62989 +#endif
62990 +
62991 +#endif
62992 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62993 new file mode 100644
62994 index 0000000..e7ffaaf
62995 --- /dev/null
62996 +++ b/include/linux/grsock.h
62997 @@ -0,0 +1,19 @@
62998 +#ifndef __GRSOCK_H
62999 +#define __GRSOCK_H
63000 +
63001 +extern void gr_attach_curr_ip(const struct sock *sk);
63002 +extern int gr_handle_sock_all(const int family, const int type,
63003 + const int protocol);
63004 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63005 +extern int gr_handle_sock_server_other(const struct sock *sck);
63006 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63007 +extern int gr_search_connect(struct socket * sock,
63008 + struct sockaddr_in * addr);
63009 +extern int gr_search_bind(struct socket * sock,
63010 + struct sockaddr_in * addr);
63011 +extern int gr_search_listen(struct socket * sock);
63012 +extern int gr_search_accept(struct socket * sock);
63013 +extern int gr_search_socket(const int domain, const int type,
63014 + const int protocol);
63015 +
63016 +#endif
63017 diff --git a/include/linux/hid.h b/include/linux/hid.h
63018 index c076041..6f54d73 100644
63019 --- a/include/linux/hid.h
63020 +++ b/include/linux/hid.h
63021 @@ -671,7 +671,7 @@ struct hid_ll_driver {
63022 unsigned int code, int value);
63023
63024 int (*parse)(struct hid_device *hdev);
63025 -};
63026 +} __no_const;
63027
63028 #define PM_HINT_FULLON 1<<5
63029 #define PM_HINT_NORMAL 1<<1
63030 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63031 index ef788b5..ac41b7b 100644
63032 --- a/include/linux/highmem.h
63033 +++ b/include/linux/highmem.h
63034 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63035 kunmap_atomic(kaddr);
63036 }
63037
63038 +static inline void sanitize_highpage(struct page *page)
63039 +{
63040 + void *kaddr;
63041 + unsigned long flags;
63042 +
63043 + local_irq_save(flags);
63044 + kaddr = kmap_atomic(page);
63045 + clear_page(kaddr);
63046 + kunmap_atomic(kaddr);
63047 + local_irq_restore(flags);
63048 +}
63049 +
63050 static inline void zero_user_segments(struct page *page,
63051 unsigned start1, unsigned end1,
63052 unsigned start2, unsigned end2)
63053 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63054 index 800de22..7a2fa46 100644
63055 --- a/include/linux/i2c.h
63056 +++ b/include/linux/i2c.h
63057 @@ -367,6 +367,7 @@ struct i2c_algorithm {
63058 /* To determine what the adapter supports */
63059 u32 (*functionality) (struct i2c_adapter *);
63060 };
63061 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63062
63063 /*
63064 * i2c_adapter is the structure used to identify a physical i2c bus along
63065 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63066 index d23c3c2..eb63c81 100644
63067 --- a/include/linux/i2o.h
63068 +++ b/include/linux/i2o.h
63069 @@ -565,7 +565,7 @@ struct i2o_controller {
63070 struct i2o_device *exec; /* Executive */
63071 #if BITS_PER_LONG == 64
63072 spinlock_t context_list_lock; /* lock for context_list */
63073 - atomic_t context_list_counter; /* needed for unique contexts */
63074 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63075 struct list_head context_list; /* list of context id's
63076 and pointers */
63077 #endif
63078 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63079 index 0245def..1199c5a 100644
63080 --- a/include/linux/if_team.h
63081 +++ b/include/linux/if_team.h
63082 @@ -111,6 +111,7 @@ struct team_mode_ops {
63083 void (*port_enabled)(struct team *team, struct team_port *port);
63084 void (*port_disabled)(struct team *team, struct team_port *port);
63085 };
63086 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63087
63088 enum team_option_type {
63089 TEAM_OPTION_TYPE_U32,
63090 @@ -185,7 +186,7 @@ struct team {
63091 struct list_head option_inst_list; /* list of option instances */
63092
63093 const struct team_mode *mode;
63094 - struct team_mode_ops ops;
63095 + team_mode_ops_no_const ops;
63096 bool queue_override_enabled;
63097 struct list_head *qom_lists; /* array of queue override mapping lists */
63098 long mode_priv[TEAM_MODE_PRIV_LONGS];
63099 diff --git a/include/linux/init.h b/include/linux/init.h
63100 index e59041e..df0a975 100644
63101 --- a/include/linux/init.h
63102 +++ b/include/linux/init.h
63103 @@ -39,9 +39,36 @@
63104 * Also note, that this data cannot be "const".
63105 */
63106
63107 +#ifdef MODULE
63108 +#define add_init_latent_entropy
63109 +#define add_devinit_latent_entropy
63110 +#define add_cpuinit_latent_entropy
63111 +#define add_meminit_latent_entropy
63112 +#else
63113 +#define add_init_latent_entropy __latent_entropy
63114 +
63115 +#ifdef CONFIG_HOTPLUG
63116 +#define add_devinit_latent_entropy
63117 +#else
63118 +#define add_devinit_latent_entropy __latent_entropy
63119 +#endif
63120 +
63121 +#ifdef CONFIG_HOTPLUG_CPU
63122 +#define add_cpuinit_latent_entropy
63123 +#else
63124 +#define add_cpuinit_latent_entropy __latent_entropy
63125 +#endif
63126 +
63127 +#ifdef CONFIG_MEMORY_HOTPLUG
63128 +#define add_meminit_latent_entropy
63129 +#else
63130 +#define add_meminit_latent_entropy __latent_entropy
63131 +#endif
63132 +#endif
63133 +
63134 /* These are for everybody (although not all archs will actually
63135 discard it in modules) */
63136 -#define __init __section(.init.text) __cold notrace
63137 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
63138 #define __initdata __section(.init.data)
63139 #define __initconst __constsection(.init.rodata)
63140 #define __exitdata __section(.exit.data)
63141 @@ -94,7 +121,7 @@
63142 #define __exit __section(.exit.text) __exitused __cold notrace
63143
63144 /* Used for HOTPLUG */
63145 -#define __devinit __section(.devinit.text) __cold notrace
63146 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
63147 #define __devinitdata __section(.devinit.data)
63148 #define __devinitconst __constsection(.devinit.rodata)
63149 #define __devexit __section(.devexit.text) __exitused __cold notrace
63150 @@ -102,7 +129,7 @@
63151 #define __devexitconst __constsection(.devexit.rodata)
63152
63153 /* Used for HOTPLUG_CPU */
63154 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63155 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
63156 #define __cpuinitdata __section(.cpuinit.data)
63157 #define __cpuinitconst __constsection(.cpuinit.rodata)
63158 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63159 @@ -110,7 +137,7 @@
63160 #define __cpuexitconst __constsection(.cpuexit.rodata)
63161
63162 /* Used for MEMORY_HOTPLUG */
63163 -#define __meminit __section(.meminit.text) __cold notrace
63164 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
63165 #define __meminitdata __section(.meminit.data)
63166 #define __meminitconst __constsection(.meminit.rodata)
63167 #define __memexit __section(.memexit.text) __exitused __cold notrace
63168 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63169 index 6d087c5..401cab8 100644
63170 --- a/include/linux/init_task.h
63171 +++ b/include/linux/init_task.h
63172 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63173
63174 #define INIT_TASK_COMM "swapper"
63175
63176 +#ifdef CONFIG_X86
63177 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63178 +#else
63179 +#define INIT_TASK_THREAD_INFO
63180 +#endif
63181 +
63182 /*
63183 * INIT_TASK is used to set up the first task table, touch at
63184 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63185 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63186 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63187 .comm = INIT_TASK_COMM, \
63188 .thread = INIT_THREAD, \
63189 + INIT_TASK_THREAD_INFO \
63190 .fs = &init_fs, \
63191 .files = &init_files, \
63192 .signal = &init_signals, \
63193 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63194 index 78e2ada..745564d 100644
63195 --- a/include/linux/intel-iommu.h
63196 +++ b/include/linux/intel-iommu.h
63197 @@ -296,7 +296,7 @@ struct iommu_flush {
63198 u8 fm, u64 type);
63199 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63200 unsigned int size_order, u64 type);
63201 -};
63202 +} __no_const;
63203
63204 enum {
63205 SR_DMAR_FECTL_REG,
63206 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63207 index 5e4e617..eee383d 100644
63208 --- a/include/linux/interrupt.h
63209 +++ b/include/linux/interrupt.h
63210 @@ -435,7 +435,7 @@ enum
63211 /* map softirq index to softirq name. update 'softirq_to_name' in
63212 * kernel/softirq.c when adding a new softirq.
63213 */
63214 -extern char *softirq_to_name[NR_SOFTIRQS];
63215 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63216
63217 /* softirq mask and active fields moved to irq_cpustat_t in
63218 * asm/hardirq.h to get better cache usage. KAO
63219 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63220
63221 struct softirq_action
63222 {
63223 - void (*action)(struct softirq_action *);
63224 + void (*action)(void);
63225 };
63226
63227 asmlinkage void do_softirq(void);
63228 asmlinkage void __do_softirq(void);
63229 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63230 +extern void open_softirq(int nr, void (*action)(void));
63231 extern void softirq_init(void);
63232 extern void __raise_softirq_irqoff(unsigned int nr);
63233
63234 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63235 index 6883e19..06992b1 100644
63236 --- a/include/linux/kallsyms.h
63237 +++ b/include/linux/kallsyms.h
63238 @@ -15,7 +15,8 @@
63239
63240 struct module;
63241
63242 -#ifdef CONFIG_KALLSYMS
63243 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63244 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63245 /* Lookup the address for a symbol. Returns 0 if not found. */
63246 unsigned long kallsyms_lookup_name(const char *name);
63247
63248 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63249 /* Stupid that this does nothing, but I didn't create this mess. */
63250 #define __print_symbol(fmt, addr)
63251 #endif /*CONFIG_KALLSYMS*/
63252 +#else /* when included by kallsyms.c, vsnprintf.c, or
63253 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63254 +extern void __print_symbol(const char *fmt, unsigned long address);
63255 +extern int sprint_backtrace(char *buffer, unsigned long address);
63256 +extern int sprint_symbol(char *buffer, unsigned long address);
63257 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63258 +const char *kallsyms_lookup(unsigned long addr,
63259 + unsigned long *symbolsize,
63260 + unsigned long *offset,
63261 + char **modname, char *namebuf);
63262 +#endif
63263
63264 /* This macro allows us to keep printk typechecking */
63265 static __printf(1, 2)
63266 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63267 index 4dff0c6..1ca9b72 100644
63268 --- a/include/linux/kgdb.h
63269 +++ b/include/linux/kgdb.h
63270 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63271 extern int kgdb_io_module_registered;
63272
63273 extern atomic_t kgdb_setting_breakpoint;
63274 -extern atomic_t kgdb_cpu_doing_single_step;
63275 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63276
63277 extern struct task_struct *kgdb_usethread;
63278 extern struct task_struct *kgdb_contthread;
63279 @@ -255,7 +255,7 @@ struct kgdb_arch {
63280 void (*correct_hw_break)(void);
63281
63282 void (*enable_nmi)(bool on);
63283 -};
63284 +} __do_const;
63285
63286 /**
63287 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63288 @@ -280,7 +280,7 @@ struct kgdb_io {
63289 void (*pre_exception) (void);
63290 void (*post_exception) (void);
63291 int is_console;
63292 -};
63293 +} __do_const;
63294
63295 extern struct kgdb_arch arch_kgdb_ops;
63296
63297 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63298 index 5398d58..5883a34 100644
63299 --- a/include/linux/kmod.h
63300 +++ b/include/linux/kmod.h
63301 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63302 * usually useless though. */
63303 extern __printf(2, 3)
63304 int __request_module(bool wait, const char *name, ...);
63305 +extern __printf(3, 4)
63306 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63307 #define request_module(mod...) __request_module(true, mod)
63308 #define request_module_nowait(mod...) __request_module(false, mod)
63309 #define try_then_request_module(x, mod...) \
63310 diff --git a/include/linux/kref.h b/include/linux/kref.h
63311 index 65af688..0592677 100644
63312 --- a/include/linux/kref.h
63313 +++ b/include/linux/kref.h
63314 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63315 static inline int kref_sub(struct kref *kref, unsigned int count,
63316 void (*release)(struct kref *kref))
63317 {
63318 - WARN_ON(release == NULL);
63319 + BUG_ON(release == NULL);
63320
63321 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63322 release(kref);
63323 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63324 index ecc5543..0e96bcc 100644
63325 --- a/include/linux/kvm_host.h
63326 +++ b/include/linux/kvm_host.h
63327 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63328 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
63329 void vcpu_put(struct kvm_vcpu *vcpu);
63330
63331 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63332 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63333 struct module *module);
63334 void kvm_exit(void);
63335
63336 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63337 struct kvm_guest_debug *dbg);
63338 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63339
63340 -int kvm_arch_init(void *opaque);
63341 +int kvm_arch_init(const void *opaque);
63342 void kvm_arch_exit(void);
63343
63344 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63345 diff --git a/include/linux/libata.h b/include/linux/libata.h
63346 index 77eeeda..062ed69c 100644
63347 --- a/include/linux/libata.h
63348 +++ b/include/linux/libata.h
63349 @@ -914,7 +914,7 @@ struct ata_port_operations {
63350 * fields must be pointers.
63351 */
63352 const struct ata_port_operations *inherits;
63353 -};
63354 +} __do_const;
63355
63356 struct ata_port_info {
63357 unsigned long flags;
63358 diff --git a/include/linux/memory.h b/include/linux/memory.h
63359 index ff9a9f8..c715deb 100644
63360 --- a/include/linux/memory.h
63361 +++ b/include/linux/memory.h
63362 @@ -143,7 +143,7 @@ struct memory_accessor {
63363 size_t count);
63364 ssize_t (*write)(struct memory_accessor *, const char *buf,
63365 off_t offset, size_t count);
63366 -};
63367 +} __no_const;
63368
63369 /*
63370 * Kernel text modification mutex, used for code patching. Users of this lock
63371 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63372 index 5d5298d..e3e5a2e 100644
63373 --- a/include/linux/mfd/abx500.h
63374 +++ b/include/linux/mfd/abx500.h
63375 @@ -337,6 +337,7 @@ struct abx500_ops {
63376 int (*event_registers_startup_state_get) (struct device *, u8 *);
63377 int (*startup_irq_enabled) (struct device *, unsigned int);
63378 };
63379 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63380
63381 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63382 void abx500_remove_ops(struct device *dev);
63383 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63384 index 9b07725..3d55001 100644
63385 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63386 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63387 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63388 int (*enable) (struct ux500_charger *, int, int, int);
63389 int (*kick_wd) (struct ux500_charger *);
63390 int (*update_curr) (struct ux500_charger *, int);
63391 -};
63392 +} __no_const;
63393
63394 /**
63395 * struct ux500_charger - power supply ux500 charger sub class
63396 diff --git a/include/linux/mm.h b/include/linux/mm.h
63397 index bcaab4e..f842186 100644
63398 --- a/include/linux/mm.h
63399 +++ b/include/linux/mm.h
63400 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
63401 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
63402 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
63403 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
63404 +
63405 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63406 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
63407 +#endif
63408 +
63409 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
63410
63411 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63412 @@ -1040,34 +1045,6 @@ int set_page_dirty(struct page *page);
63413 int set_page_dirty_lock(struct page *page);
63414 int clear_page_dirty_for_io(struct page *page);
63415
63416 -/* Is the vma a continuation of the stack vma above it? */
63417 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63418 -{
63419 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63420 -}
63421 -
63422 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63423 - unsigned long addr)
63424 -{
63425 - return (vma->vm_flags & VM_GROWSDOWN) &&
63426 - (vma->vm_start == addr) &&
63427 - !vma_growsdown(vma->vm_prev, addr);
63428 -}
63429 -
63430 -/* Is the vma a continuation of the stack vma below it? */
63431 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63432 -{
63433 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63434 -}
63435 -
63436 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63437 - unsigned long addr)
63438 -{
63439 - return (vma->vm_flags & VM_GROWSUP) &&
63440 - (vma->vm_end == addr) &&
63441 - !vma_growsup(vma->vm_next, addr);
63442 -}
63443 -
63444 extern pid_t
63445 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63446
63447 @@ -1167,6 +1144,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63448 }
63449 #endif
63450
63451 +#ifdef CONFIG_MMU
63452 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63453 +#else
63454 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63455 +{
63456 + return __pgprot(0);
63457 +}
63458 +#endif
63459 +
63460 int vma_wants_writenotify(struct vm_area_struct *vma);
63461
63462 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63463 @@ -1185,8 +1171,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63464 {
63465 return 0;
63466 }
63467 +
63468 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63469 + unsigned long address)
63470 +{
63471 + return 0;
63472 +}
63473 #else
63474 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63475 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63476 #endif
63477
63478 #ifdef __PAGETABLE_PMD_FOLDED
63479 @@ -1195,8 +1188,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63480 {
63481 return 0;
63482 }
63483 +
63484 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63485 + unsigned long address)
63486 +{
63487 + return 0;
63488 +}
63489 #else
63490 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63491 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63492 #endif
63493
63494 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63495 @@ -1214,11 +1214,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63496 NULL: pud_offset(pgd, address);
63497 }
63498
63499 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63500 +{
63501 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63502 + NULL: pud_offset(pgd, address);
63503 +}
63504 +
63505 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63506 {
63507 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63508 NULL: pmd_offset(pud, address);
63509 }
63510 +
63511 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63512 +{
63513 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63514 + NULL: pmd_offset(pud, address);
63515 +}
63516 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63517
63518 #if USE_SPLIT_PTLOCKS
63519 @@ -1448,6 +1460,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63520 unsigned long, unsigned long,
63521 unsigned long, unsigned long);
63522 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63523 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63524
63525 /* These take the mm semaphore themselves */
63526 extern unsigned long vm_brk(unsigned long, unsigned long);
63527 @@ -1511,6 +1524,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63528 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63529 struct vm_area_struct **pprev);
63530
63531 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63532 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63533 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63534 +
63535 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63536 NULL if none. Assume start_addr < end_addr. */
63537 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63538 @@ -1539,15 +1556,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63539 return vma;
63540 }
63541
63542 -#ifdef CONFIG_MMU
63543 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63544 -#else
63545 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63546 -{
63547 - return __pgprot(0);
63548 -}
63549 -#endif
63550 -
63551 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63552 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63553 unsigned long pfn, unsigned long size, pgprot_t);
63554 @@ -1653,7 +1661,7 @@ extern int unpoison_memory(unsigned long pfn);
63555 extern int sysctl_memory_failure_early_kill;
63556 extern int sysctl_memory_failure_recovery;
63557 extern void shake_page(struct page *p, int access);
63558 -extern atomic_long_t mce_bad_pages;
63559 +extern atomic_long_unchecked_t mce_bad_pages;
63560 extern int soft_offline_page(struct page *page, int flags);
63561
63562 extern void dump_page(struct page *page);
63563 @@ -1684,5 +1692,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63564 static inline bool page_is_guard(struct page *page) { return false; }
63565 #endif /* CONFIG_DEBUG_PAGEALLOC */
63566
63567 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63568 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63569 +#else
63570 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63571 +#endif
63572 +
63573 #endif /* __KERNEL__ */
63574 #endif /* _LINUX_MM_H */
63575 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63576 index 31f8a3a..499f1db 100644
63577 --- a/include/linux/mm_types.h
63578 +++ b/include/linux/mm_types.h
63579 @@ -275,6 +275,8 @@ struct vm_area_struct {
63580 #ifdef CONFIG_NUMA
63581 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63582 #endif
63583 +
63584 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63585 };
63586
63587 struct core_thread {
63588 @@ -348,7 +350,7 @@ struct mm_struct {
63589 unsigned long def_flags;
63590 unsigned long nr_ptes; /* Page table pages */
63591 unsigned long start_code, end_code, start_data, end_data;
63592 - unsigned long start_brk, brk, start_stack;
63593 + unsigned long brk_gap, start_brk, brk, start_stack;
63594 unsigned long arg_start, arg_end, env_start, env_end;
63595
63596 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63597 @@ -399,6 +401,24 @@ struct mm_struct {
63598 struct cpumask cpumask_allocation;
63599 #endif
63600 struct uprobes_state uprobes_state;
63601 +
63602 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63603 + unsigned long pax_flags;
63604 +#endif
63605 +
63606 +#ifdef CONFIG_PAX_DLRESOLVE
63607 + unsigned long call_dl_resolve;
63608 +#endif
63609 +
63610 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63611 + unsigned long call_syscall;
63612 +#endif
63613 +
63614 +#ifdef CONFIG_PAX_ASLR
63615 + unsigned long delta_mmap; /* randomized offset */
63616 + unsigned long delta_stack; /* randomized offset */
63617 +#endif
63618 +
63619 };
63620
63621 static inline void mm_init_cpumask(struct mm_struct *mm)
63622 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63623 index a23923b..073fee4 100644
63624 --- a/include/linux/mmzone.h
63625 +++ b/include/linux/mmzone.h
63626 @@ -421,7 +421,7 @@ struct zone {
63627 unsigned long flags; /* zone flags, see below */
63628
63629 /* Zone statistics */
63630 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63631 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63632
63633 /*
63634 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63635 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63636 index fed3def..7cc3f93 100644
63637 --- a/include/linux/mod_devicetable.h
63638 +++ b/include/linux/mod_devicetable.h
63639 @@ -12,7 +12,7 @@
63640 typedef unsigned long kernel_ulong_t;
63641 #endif
63642
63643 -#define PCI_ANY_ID (~0)
63644 +#define PCI_ANY_ID ((__u16)~0)
63645
63646 struct pci_device_id {
63647 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63648 @@ -139,7 +139,7 @@ struct usb_device_id {
63649 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63650 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63651
63652 -#define HID_ANY_ID (~0)
63653 +#define HID_ANY_ID (~0U)
63654 #define HID_BUS_ANY 0xffff
63655 #define HID_GROUP_ANY 0x0000
63656
63657 diff --git a/include/linux/module.h b/include/linux/module.h
63658 index 7760c6d..07a2d3d 100644
63659 --- a/include/linux/module.h
63660 +++ b/include/linux/module.h
63661 @@ -17,6 +17,7 @@
63662 #include <linux/moduleparam.h>
63663 #include <linux/tracepoint.h>
63664 #include <linux/export.h>
63665 +#include <linux/fs.h>
63666
63667 #include <linux/percpu.h>
63668 #include <asm/module.h>
63669 @@ -281,19 +282,16 @@ struct module
63670 int (*init)(void);
63671
63672 /* If this is non-NULL, vfree after init() returns */
63673 - void *module_init;
63674 + void *module_init_rx, *module_init_rw;
63675
63676 /* Here is the actual code + data, vfree'd on unload. */
63677 - void *module_core;
63678 + void *module_core_rx, *module_core_rw;
63679
63680 /* Here are the sizes of the init and core sections */
63681 - unsigned int init_size, core_size;
63682 + unsigned int init_size_rw, core_size_rw;
63683
63684 /* The size of the executable code in each section. */
63685 - unsigned int init_text_size, core_text_size;
63686 -
63687 - /* Size of RO sections of the module (text+rodata) */
63688 - unsigned int init_ro_size, core_ro_size;
63689 + unsigned int init_size_rx, core_size_rx;
63690
63691 /* Arch-specific module values */
63692 struct mod_arch_specific arch;
63693 @@ -349,6 +347,10 @@ struct module
63694 #ifdef CONFIG_EVENT_TRACING
63695 struct ftrace_event_call **trace_events;
63696 unsigned int num_trace_events;
63697 + struct file_operations trace_id;
63698 + struct file_operations trace_enable;
63699 + struct file_operations trace_format;
63700 + struct file_operations trace_filter;
63701 #endif
63702 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63703 unsigned int num_ftrace_callsites;
63704 @@ -396,16 +398,46 @@ bool is_module_address(unsigned long addr);
63705 bool is_module_percpu_address(unsigned long addr);
63706 bool is_module_text_address(unsigned long addr);
63707
63708 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63709 +{
63710 +
63711 +#ifdef CONFIG_PAX_KERNEXEC
63712 + if (ktla_ktva(addr) >= (unsigned long)start &&
63713 + ktla_ktva(addr) < (unsigned long)start + size)
63714 + return 1;
63715 +#endif
63716 +
63717 + return ((void *)addr >= start && (void *)addr < start + size);
63718 +}
63719 +
63720 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63721 +{
63722 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63723 +}
63724 +
63725 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63726 +{
63727 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63728 +}
63729 +
63730 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63731 +{
63732 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63733 +}
63734 +
63735 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63736 +{
63737 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63738 +}
63739 +
63740 static inline int within_module_core(unsigned long addr, struct module *mod)
63741 {
63742 - return (unsigned long)mod->module_core <= addr &&
63743 - addr < (unsigned long)mod->module_core + mod->core_size;
63744 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63745 }
63746
63747 static inline int within_module_init(unsigned long addr, struct module *mod)
63748 {
63749 - return (unsigned long)mod->module_init <= addr &&
63750 - addr < (unsigned long)mod->module_init + mod->init_size;
63751 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63752 }
63753
63754 /* Search for module by name: must hold module_mutex. */
63755 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63756 index 560ca53..16968cc 100644
63757 --- a/include/linux/moduleloader.h
63758 +++ b/include/linux/moduleloader.h
63759 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63760
63761 /* Allocator used for allocating struct module, core sections and init
63762 sections. Returns NULL on failure. */
63763 -void *module_alloc(unsigned long size);
63764 +void *module_alloc(unsigned long size) __size_overflow(1);
63765 +
63766 +#ifdef CONFIG_PAX_KERNEXEC
63767 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63768 +#else
63769 +#define module_alloc_exec(x) module_alloc(x)
63770 +#endif
63771
63772 /* Free memory returned from module_alloc. */
63773 void module_free(struct module *mod, void *module_region);
63774
63775 +#ifdef CONFIG_PAX_KERNEXEC
63776 +void module_free_exec(struct module *mod, void *module_region);
63777 +#else
63778 +#define module_free_exec(x, y) module_free((x), (y))
63779 +#endif
63780 +
63781 /*
63782 * Apply the given relocation to the (simplified) ELF. Return -error
63783 * or 0.
63784 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63785 index d6a5806..7c13347 100644
63786 --- a/include/linux/moduleparam.h
63787 +++ b/include/linux/moduleparam.h
63788 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63789 * @len is usually just sizeof(string).
63790 */
63791 #define module_param_string(name, string, len, perm) \
63792 - static const struct kparam_string __param_string_##name \
63793 + static const struct kparam_string __param_string_##name __used \
63794 = { len, string }; \
63795 __module_param_call(MODULE_PARAM_PREFIX, name, \
63796 &param_ops_string, \
63797 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63798 */
63799 #define module_param_array_named(name, array, type, nump, perm) \
63800 param_check_##type(name, &(array)[0]); \
63801 - static const struct kparam_array __param_arr_##name \
63802 + static const struct kparam_array __param_arr_##name __used \
63803 = { .max = ARRAY_SIZE(array), .num = nump, \
63804 .ops = &param_ops_##type, \
63805 .elemsize = sizeof(array[0]), .elem = array }; \
63806 diff --git a/include/linux/namei.h b/include/linux/namei.h
63807 index 4bf19d8..5268cea 100644
63808 --- a/include/linux/namei.h
63809 +++ b/include/linux/namei.h
63810 @@ -18,7 +18,7 @@ struct nameidata {
63811 unsigned seq;
63812 int last_type;
63813 unsigned depth;
63814 - char *saved_names[MAX_NESTED_LINKS + 1];
63815 + const char *saved_names[MAX_NESTED_LINKS + 1];
63816 };
63817
63818 /*
63819 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63820
63821 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63822
63823 -static inline void nd_set_link(struct nameidata *nd, char *path)
63824 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63825 {
63826 nd->saved_names[nd->depth] = path;
63827 }
63828
63829 -static inline char *nd_get_link(struct nameidata *nd)
63830 +static inline const char *nd_get_link(const struct nameidata *nd)
63831 {
63832 return nd->saved_names[nd->depth];
63833 }
63834 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63835 index a848ffc..3bbbaee 100644
63836 --- a/include/linux/netdevice.h
63837 +++ b/include/linux/netdevice.h
63838 @@ -999,6 +999,7 @@ struct net_device_ops {
63839 struct net_device *dev,
63840 int idx);
63841 };
63842 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63843
63844 /*
63845 * The DEVICE structure.
63846 @@ -1059,7 +1060,7 @@ struct net_device {
63847 int iflink;
63848
63849 struct net_device_stats stats;
63850 - atomic_long_t rx_dropped; /* dropped packets by core network
63851 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63852 * Do not use this in drivers.
63853 */
63854
63855 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63856 new file mode 100644
63857 index 0000000..33f4af8
63858 --- /dev/null
63859 +++ b/include/linux/netfilter/xt_gradm.h
63860 @@ -0,0 +1,9 @@
63861 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63862 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63863 +
63864 +struct xt_gradm_mtinfo {
63865 + __u16 flags;
63866 + __u16 invflags;
63867 +};
63868 +
63869 +#endif
63870 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63871 index c65a18a..0c05f3a 100644
63872 --- a/include/linux/of_pdt.h
63873 +++ b/include/linux/of_pdt.h
63874 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63875
63876 /* return 0 on success; fill in 'len' with number of bytes in path */
63877 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63878 -};
63879 +} __no_const;
63880
63881 extern void *prom_early_alloc(unsigned long size);
63882
63883 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63884 index a4c5624..79d6d88 100644
63885 --- a/include/linux/oprofile.h
63886 +++ b/include/linux/oprofile.h
63887 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63888 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63889 char const * name, ulong * val);
63890
63891 -/** Create a file for read-only access to an atomic_t. */
63892 +/** Create a file for read-only access to an atomic_unchecked_t. */
63893 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63894 - char const * name, atomic_t * val);
63895 + char const * name, atomic_unchecked_t * val);
63896
63897 /** create a directory */
63898 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63899 diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
63900 index b5d1384..70473da 100644
63901 --- a/include/linux/page-flags.h
63902 +++ b/include/linux/page-flags.h
63903 @@ -362,7 +362,7 @@ static inline void ClearPageCompound(struct page *page)
63904 * pages on the LRU and/or pagecache.
63905 */
63906 TESTPAGEFLAG(Compound, compound)
63907 -__PAGEFLAG(Head, compound)
63908 +__SETPAGEFLAG(Head, compound) __CLEARPAGEFLAG(Head, compound)
63909
63910 /*
63911 * PG_reclaim is used in combination with PG_compound to mark the
63912 @@ -374,8 +374,14 @@ __PAGEFLAG(Head, compound)
63913 * PG_compound & PG_reclaim => Tail page
63914 * PG_compound & ~PG_reclaim => Head page
63915 */
63916 +#define PG_head_mask ((1L << PG_compound))
63917 #define PG_head_tail_mask ((1L << PG_compound) | (1L << PG_reclaim))
63918
63919 +static inline int PageHead(struct page *page)
63920 +{
63921 + return ((page->flags & PG_head_tail_mask) == PG_head_mask);
63922 +}
63923 +
63924 static inline int PageTail(struct page *page)
63925 {
63926 return ((page->flags & PG_head_tail_mask) == PG_head_tail_mask);
63927 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63928 index 6bfb2faa..1204767 100644
63929 --- a/include/linux/perf_event.h
63930 +++ b/include/linux/perf_event.h
63931 @@ -328,8 +328,8 @@ struct perf_event {
63932
63933 enum perf_event_active_state state;
63934 unsigned int attach_state;
63935 - local64_t count;
63936 - atomic64_t child_count;
63937 + local64_t count; /* PaX: fix it one day */
63938 + atomic64_unchecked_t child_count;
63939
63940 /*
63941 * These are the total time in nanoseconds that the event
63942 @@ -380,8 +380,8 @@ struct perf_event {
63943 * These accumulate total time (in nanoseconds) that children
63944 * events have been enabled and running, respectively.
63945 */
63946 - atomic64_t child_total_time_enabled;
63947 - atomic64_t child_total_time_running;
63948 + atomic64_unchecked_t child_total_time_enabled;
63949 + atomic64_unchecked_t child_total_time_running;
63950
63951 /*
63952 * Protect attach/detach and child_list:
63953 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63954 index ad1a427..6419649 100644
63955 --- a/include/linux/pipe_fs_i.h
63956 +++ b/include/linux/pipe_fs_i.h
63957 @@ -45,9 +45,9 @@ struct pipe_buffer {
63958 struct pipe_inode_info {
63959 wait_queue_head_t wait;
63960 unsigned int nrbufs, curbuf, buffers;
63961 - unsigned int readers;
63962 - unsigned int writers;
63963 - unsigned int waiting_writers;
63964 + atomic_t readers;
63965 + atomic_t writers;
63966 + atomic_t waiting_writers;
63967 unsigned int r_counter;
63968 unsigned int w_counter;
63969 struct page *tmp_page;
63970 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
63971 index 5f28cae..3d23723 100644
63972 --- a/include/linux/platform_data/usb-ehci-s5p.h
63973 +++ b/include/linux/platform_data/usb-ehci-s5p.h
63974 @@ -14,7 +14,7 @@
63975 struct s5p_ehci_platdata {
63976 int (*phy_init)(struct platform_device *pdev, int type);
63977 int (*phy_exit)(struct platform_device *pdev, int type);
63978 -};
63979 +} __no_const;
63980
63981 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
63982
63983 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63984 index f271860..6b3bec5 100644
63985 --- a/include/linux/pm_runtime.h
63986 +++ b/include/linux/pm_runtime.h
63987 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63988
63989 static inline void pm_runtime_mark_last_busy(struct device *dev)
63990 {
63991 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63992 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63993 }
63994
63995 #else /* !CONFIG_PM_RUNTIME */
63996 diff --git a/include/linux/poison.h b/include/linux/poison.h
63997 index 2110a81..13a11bb 100644
63998 --- a/include/linux/poison.h
63999 +++ b/include/linux/poison.h
64000 @@ -19,8 +19,8 @@
64001 * under normal circumstances, used to verify that nobody uses
64002 * non-initialized list entries.
64003 */
64004 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
64005 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
64006 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
64007 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
64008
64009 /********** include/linux/timer.h **********/
64010 /*
64011 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
64012 index 5a710b9..0b0dab9 100644
64013 --- a/include/linux/preempt.h
64014 +++ b/include/linux/preempt.h
64015 @@ -126,7 +126,7 @@ struct preempt_ops {
64016 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64017 void (*sched_out)(struct preempt_notifier *notifier,
64018 struct task_struct *next);
64019 -};
64020 +} __no_const;
64021
64022 /**
64023 * preempt_notifier - key for installing preemption notifiers
64024 diff --git a/include/linux/printk.h b/include/linux/printk.h
64025 index 9afc01e..92c32e8 100644
64026 --- a/include/linux/printk.h
64027 +++ b/include/linux/printk.h
64028 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64029 extern int printk_needs_cpu(int cpu);
64030 extern void printk_tick(void);
64031
64032 +extern int kptr_restrict;
64033 +
64034 #ifdef CONFIG_PRINTK
64035 asmlinkage __printf(5, 0)
64036 int vprintk_emit(int facility, int level,
64037 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64038
64039 extern int printk_delay_msec;
64040 extern int dmesg_restrict;
64041 -extern int kptr_restrict;
64042
64043 void log_buf_kexec_setup(void);
64044 void __init setup_log_buf(int early);
64045 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64046 index 3fd2e87..d93a721 100644
64047 --- a/include/linux/proc_fs.h
64048 +++ b/include/linux/proc_fs.h
64049 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64050 return proc_create_data(name, mode, parent, proc_fops, NULL);
64051 }
64052
64053 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64054 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64055 +{
64056 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64057 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64058 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64059 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64060 +#else
64061 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64062 +#endif
64063 +}
64064 +
64065 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64066 umode_t mode, struct proc_dir_entry *base,
64067 read_proc_t *read_proc, void * data)
64068 @@ -258,7 +270,7 @@ union proc_op {
64069 int (*proc_show)(struct seq_file *m,
64070 struct pid_namespace *ns, struct pid *pid,
64071 struct task_struct *task);
64072 -};
64073 +} __no_const;
64074
64075 struct ctl_table_header;
64076 struct ctl_table;
64077 diff --git a/include/linux/random.h b/include/linux/random.h
64078 index 6330ed4..6faf63b 100644
64079 --- a/include/linux/random.h
64080 +++ b/include/linux/random.h
64081 @@ -14,6 +14,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64082 unsigned int value);
64083 extern void add_interrupt_randomness(int irq, int irq_flags);
64084
64085 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64086 +extern void transfer_latent_entropy(void);
64087 +#endif
64088 +
64089 extern void get_random_bytes(void *buf, int nbytes);
64090 extern void get_random_bytes_arch(void *buf, int nbytes);
64091 void generate_random_uuid(unsigned char uuid_out[16]);
64092 @@ -30,12 +34,17 @@ void srandom32(u32 seed);
64093
64094 u32 prandom32(struct rnd_state *);
64095
64096 +static inline unsigned long pax_get_random_long(void)
64097 +{
64098 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64099 +}
64100 +
64101 /*
64102 * Handle minimum values for seeds
64103 */
64104 static inline u32 __seed(u32 x, u32 m)
64105 {
64106 - return (x < m) ? x + m : x;
64107 + return (x <= m) ? x + m + 1 : x;
64108 }
64109
64110 /**
64111 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64112 index 23b3630..e1bc12b 100644
64113 --- a/include/linux/reboot.h
64114 +++ b/include/linux/reboot.h
64115 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64116 * Architecture-specific implementations of sys_reboot commands.
64117 */
64118
64119 -extern void machine_restart(char *cmd);
64120 -extern void machine_halt(void);
64121 -extern void machine_power_off(void);
64122 +extern void machine_restart(char *cmd) __noreturn;
64123 +extern void machine_halt(void) __noreturn;
64124 +extern void machine_power_off(void) __noreturn;
64125
64126 extern void machine_shutdown(void);
64127 struct pt_regs;
64128 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64129 */
64130
64131 extern void kernel_restart_prepare(char *cmd);
64132 -extern void kernel_restart(char *cmd);
64133 -extern void kernel_halt(void);
64134 -extern void kernel_power_off(void);
64135 +extern void kernel_restart(char *cmd) __noreturn;
64136 +extern void kernel_halt(void) __noreturn;
64137 +extern void kernel_power_off(void) __noreturn;
64138
64139 extern int C_A_D; /* for sysctl */
64140 void ctrl_alt_del(void);
64141 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
64142 * Emergency restart, callable from an interrupt handler.
64143 */
64144
64145 -extern void emergency_restart(void);
64146 +extern void emergency_restart(void) __noreturn;
64147 #include <asm/emergency-restart.h>
64148
64149 #endif /* _LINUX_REBOOT_H */
64150 diff --git a/include/linux/relay.h b/include/linux/relay.h
64151 index 91cacc3..b55ff74 100644
64152 --- a/include/linux/relay.h
64153 +++ b/include/linux/relay.h
64154 @@ -160,7 +160,7 @@ struct rchan_callbacks
64155 * The callback should return 0 if successful, negative if not.
64156 */
64157 int (*remove_buf_file)(struct dentry *dentry);
64158 -};
64159 +} __no_const;
64160
64161 /*
64162 * CONFIG_RELAY kernel API, kernel/relay.c
64163 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64164 index d901078..0b7d00e 100644
64165 --- a/include/linux/rfkill.h
64166 +++ b/include/linux/rfkill.h
64167 @@ -63,6 +63,7 @@ struct rfkill_ops {
64168 void (*query)(struct rfkill *rfkill, void *data);
64169 int (*set_block)(void *data, bool blocked);
64170 };
64171 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64172
64173 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64174 /**
64175 diff --git a/include/linux/rio.h b/include/linux/rio.h
64176 index a3e7842..d973ca6 100644
64177 --- a/include/linux/rio.h
64178 +++ b/include/linux/rio.h
64179 @@ -339,7 +339,7 @@ struct rio_ops {
64180 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
64181 u64 rstart, u32 size, u32 flags);
64182 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
64183 -};
64184 +} __no_const;
64185
64186 #define RIO_RESOURCE_MEM 0x00000100
64187 #define RIO_RESOURCE_DOORBELL 0x00000200
64188 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64189 index bfe1f47..6a33ee3 100644
64190 --- a/include/linux/rmap.h
64191 +++ b/include/linux/rmap.h
64192 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64193 void anon_vma_init(void); /* create anon_vma_cachep */
64194 int anon_vma_prepare(struct vm_area_struct *);
64195 void unlink_anon_vmas(struct vm_area_struct *);
64196 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64197 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64198 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64199 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64200
64201 static inline void anon_vma_merge(struct vm_area_struct *vma,
64202 struct vm_area_struct *next)
64203 diff --git a/include/linux/sched.h b/include/linux/sched.h
64204 index 0dd42a0..cc9bffb 100644
64205 --- a/include/linux/sched.h
64206 +++ b/include/linux/sched.h
64207 @@ -61,6 +61,7 @@ struct bio_list;
64208 struct fs_struct;
64209 struct perf_event_context;
64210 struct blk_plug;
64211 +struct linux_binprm;
64212
64213 /*
64214 * List of flags we want to share for kernel threads,
64215 @@ -344,10 +345,13 @@ struct user_namespace;
64216 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64217
64218 extern int sysctl_max_map_count;
64219 +extern unsigned long sysctl_heap_stack_gap;
64220
64221 #include <linux/aio.h>
64222
64223 #ifdef CONFIG_MMU
64224 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64225 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64226 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64227 extern unsigned long
64228 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64229 @@ -614,6 +618,17 @@ struct signal_struct {
64230 #ifdef CONFIG_TASKSTATS
64231 struct taskstats *stats;
64232 #endif
64233 +
64234 +#ifdef CONFIG_GRKERNSEC
64235 + u32 curr_ip;
64236 + u32 saved_ip;
64237 + u32 gr_saddr;
64238 + u32 gr_daddr;
64239 + u16 gr_sport;
64240 + u16 gr_dport;
64241 + u8 used_accept:1;
64242 +#endif
64243 +
64244 #ifdef CONFIG_AUDIT
64245 unsigned audit_tty;
64246 struct tty_audit_buf *tty_audit_buf;
64247 @@ -691,6 +706,11 @@ struct user_struct {
64248 struct key *session_keyring; /* UID's default session keyring */
64249 #endif
64250
64251 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64252 + unsigned int banned;
64253 + unsigned long ban_expires;
64254 +#endif
64255 +
64256 /* Hash table maintenance information */
64257 struct hlist_node uidhash_node;
64258 kuid_t uid;
64259 @@ -1312,8 +1332,8 @@ struct task_struct {
64260 struct list_head thread_group;
64261
64262 struct completion *vfork_done; /* for vfork() */
64263 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64264 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64265 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64266 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64267
64268 cputime_t utime, stime, utimescaled, stimescaled;
64269 cputime_t gtime;
64270 @@ -1329,11 +1349,6 @@ struct task_struct {
64271 struct task_cputime cputime_expires;
64272 struct list_head cpu_timers[3];
64273
64274 -/* process credentials */
64275 - const struct cred __rcu *real_cred; /* objective and real subjective task
64276 - * credentials (COW) */
64277 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64278 - * credentials (COW) */
64279 char comm[TASK_COMM_LEN]; /* executable name excluding path
64280 - access with [gs]et_task_comm (which lock
64281 it with task_lock())
64282 @@ -1350,6 +1365,10 @@ struct task_struct {
64283 #endif
64284 /* CPU-specific state of this task */
64285 struct thread_struct thread;
64286 +/* thread_info moved to task_struct */
64287 +#ifdef CONFIG_X86
64288 + struct thread_info tinfo;
64289 +#endif
64290 /* filesystem information */
64291 struct fs_struct *fs;
64292 /* open file information */
64293 @@ -1423,6 +1442,10 @@ struct task_struct {
64294 gfp_t lockdep_reclaim_gfp;
64295 #endif
64296
64297 +/* process credentials */
64298 + const struct cred __rcu *real_cred; /* objective and real subjective task
64299 + * credentials (COW) */
64300 +
64301 /* journalling filesystem info */
64302 void *journal_info;
64303
64304 @@ -1461,6 +1484,10 @@ struct task_struct {
64305 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64306 struct list_head cg_list;
64307 #endif
64308 +
64309 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64310 + * credentials (COW) */
64311 +
64312 #ifdef CONFIG_FUTEX
64313 struct robust_list_head __user *robust_list;
64314 #ifdef CONFIG_COMPAT
64315 @@ -1548,8 +1575,75 @@ struct task_struct {
64316 #ifdef CONFIG_UPROBES
64317 struct uprobe_task *utask;
64318 #endif
64319 +
64320 +#ifdef CONFIG_GRKERNSEC
64321 + /* grsecurity */
64322 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64323 + u64 exec_id;
64324 +#endif
64325 +#ifdef CONFIG_GRKERNSEC_SETXID
64326 + const struct cred *delayed_cred;
64327 +#endif
64328 + struct dentry *gr_chroot_dentry;
64329 + struct acl_subject_label *acl;
64330 + struct acl_role_label *role;
64331 + struct file *exec_file;
64332 + unsigned long brute_expires;
64333 + u16 acl_role_id;
64334 + /* is this the task that authenticated to the special role */
64335 + u8 acl_sp_role;
64336 + u8 is_writable;
64337 + u8 brute;
64338 + u8 gr_is_chrooted;
64339 +#endif
64340 +
64341 };
64342
64343 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64344 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64345 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64346 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64347 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64348 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64349 +
64350 +#ifdef CONFIG_PAX_SOFTMODE
64351 +extern int pax_softmode;
64352 +#endif
64353 +
64354 +extern int pax_check_flags(unsigned long *);
64355 +
64356 +/* if tsk != current then task_lock must be held on it */
64357 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64358 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64359 +{
64360 + if (likely(tsk->mm))
64361 + return tsk->mm->pax_flags;
64362 + else
64363 + return 0UL;
64364 +}
64365 +
64366 +/* if tsk != current then task_lock must be held on it */
64367 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64368 +{
64369 + if (likely(tsk->mm)) {
64370 + tsk->mm->pax_flags = flags;
64371 + return 0;
64372 + }
64373 + return -EINVAL;
64374 +}
64375 +#endif
64376 +
64377 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64378 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64379 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64380 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64381 +#endif
64382 +
64383 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64384 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64385 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64386 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64387 +
64388 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64389 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64390
64391 @@ -2092,7 +2186,9 @@ void yield(void);
64392 extern struct exec_domain default_exec_domain;
64393
64394 union thread_union {
64395 +#ifndef CONFIG_X86
64396 struct thread_info thread_info;
64397 +#endif
64398 unsigned long stack[THREAD_SIZE/sizeof(long)];
64399 };
64400
64401 @@ -2125,6 +2221,7 @@ extern struct pid_namespace init_pid_ns;
64402 */
64403
64404 extern struct task_struct *find_task_by_vpid(pid_t nr);
64405 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64406 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64407 struct pid_namespace *ns);
64408
64409 @@ -2281,7 +2378,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64410 extern void exit_itimers(struct signal_struct *);
64411 extern void flush_itimer_signals(void);
64412
64413 -extern void do_group_exit(int);
64414 +extern __noreturn void do_group_exit(int);
64415
64416 extern void daemonize(const char *, ...);
64417 extern int allow_signal(int);
64418 @@ -2485,9 +2582,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64419
64420 #endif
64421
64422 -static inline int object_is_on_stack(void *obj)
64423 +static inline int object_starts_on_stack(void *obj)
64424 {
64425 - void *stack = task_stack_page(current);
64426 + const void *stack = task_stack_page(current);
64427
64428 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64429 }
64430 diff --git a/include/linux/security.h b/include/linux/security.h
64431 index 05e88bd..5cda002 100644
64432 --- a/include/linux/security.h
64433 +++ b/include/linux/security.h
64434 @@ -26,6 +26,7 @@
64435 #include <linux/capability.h>
64436 #include <linux/slab.h>
64437 #include <linux/err.h>
64438 +#include <linux/grsecurity.h>
64439
64440 struct linux_binprm;
64441 struct cred;
64442 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64443 index 68a04a3..866e6a1 100644
64444 --- a/include/linux/seq_file.h
64445 +++ b/include/linux/seq_file.h
64446 @@ -26,6 +26,9 @@ struct seq_file {
64447 struct mutex lock;
64448 const struct seq_operations *op;
64449 int poll_event;
64450 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64451 + u64 exec_id;
64452 +#endif
64453 #ifdef CONFIG_USER_NS
64454 struct user_namespace *user_ns;
64455 #endif
64456 @@ -38,6 +41,7 @@ struct seq_operations {
64457 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64458 int (*show) (struct seq_file *m, void *v);
64459 };
64460 +typedef struct seq_operations __no_const seq_operations_no_const;
64461
64462 #define SEQ_SKIP 1
64463
64464 diff --git a/include/linux/shm.h b/include/linux/shm.h
64465 index bcf8a6a..4d0af77 100644
64466 --- a/include/linux/shm.h
64467 +++ b/include/linux/shm.h
64468 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
64469
64470 /* The task created the shm object. NULL if the task is dead. */
64471 struct task_struct *shm_creator;
64472 +#ifdef CONFIG_GRKERNSEC
64473 + time_t shm_createtime;
64474 + pid_t shm_lapid;
64475 +#endif
64476 };
64477
64478 /* shm_mode upper byte flags */
64479 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64480 index 6a2c34e..a1f320f 100644
64481 --- a/include/linux/skbuff.h
64482 +++ b/include/linux/skbuff.h
64483 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64484 extern struct sk_buff *__alloc_skb(unsigned int size,
64485 gfp_t priority, int flags, int node);
64486 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64487 -static inline struct sk_buff *alloc_skb(unsigned int size,
64488 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64489 gfp_t priority)
64490 {
64491 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64492 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64493 */
64494 static inline int skb_queue_empty(const struct sk_buff_head *list)
64495 {
64496 - return list->next == (struct sk_buff *)list;
64497 + return list->next == (const struct sk_buff *)list;
64498 }
64499
64500 /**
64501 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64502 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64503 const struct sk_buff *skb)
64504 {
64505 - return skb->next == (struct sk_buff *)list;
64506 + return skb->next == (const struct sk_buff *)list;
64507 }
64508
64509 /**
64510 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64511 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64512 const struct sk_buff *skb)
64513 {
64514 - return skb->prev == (struct sk_buff *)list;
64515 + return skb->prev == (const struct sk_buff *)list;
64516 }
64517
64518 /**
64519 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64520 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64521 */
64522 #ifndef NET_SKB_PAD
64523 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64524 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64525 #endif
64526
64527 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64528 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64529 int noblock, int *err);
64530 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64531 struct poll_table_struct *wait);
64532 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64533 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64534 int offset, struct iovec *to,
64535 int size);
64536 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64537 diff --git a/include/linux/slab.h b/include/linux/slab.h
64538 index 83d1a14..cbce507 100644
64539 --- a/include/linux/slab.h
64540 +++ b/include/linux/slab.h
64541 @@ -11,12 +11,20 @@
64542
64543 #include <linux/gfp.h>
64544 #include <linux/types.h>
64545 +#include <linux/err.h>
64546
64547 /*
64548 * Flags to pass to kmem_cache_create().
64549 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64550 */
64551 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64552 +
64553 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64554 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64555 +#else
64556 +#define SLAB_USERCOPY 0x00000000UL
64557 +#endif
64558 +
64559 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64560 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64561 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64562 @@ -87,10 +95,13 @@
64563 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64564 * Both make kfree a no-op.
64565 */
64566 -#define ZERO_SIZE_PTR ((void *)16)
64567 +#define ZERO_SIZE_PTR \
64568 +({ \
64569 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64570 + (void *)(-MAX_ERRNO-1L); \
64571 +})
64572
64573 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64574 - (unsigned long)ZERO_SIZE_PTR)
64575 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64576
64577 /*
64578 * Common fields provided in kmem_cache by all slab allocators
64579 @@ -110,7 +121,7 @@ struct kmem_cache {
64580 unsigned int align; /* Alignment as calculated */
64581 unsigned long flags; /* Active flags on the slab */
64582 const char *name; /* Slab name for sysfs */
64583 - int refcount; /* Use counter */
64584 + atomic_t refcount; /* Use counter */
64585 void (*ctor)(void *); /* Called on object slot creation */
64586 struct list_head list; /* List of all slab caches on the system */
64587 };
64588 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64589 void kfree(const void *);
64590 void kzfree(const void *);
64591 size_t ksize(const void *);
64592 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64593 +bool is_usercopy_object(const void *ptr);
64594
64595 /*
64596 * Allocator specific definitions. These are mainly used to establish optimized
64597 @@ -323,7 +336,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64598 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64599 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
64600 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
64601 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64602 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64603 #define kmalloc_track_caller(size, flags) \
64604 __kmalloc_track_caller(size, flags, _RET_IP_)
64605 #else
64606 @@ -343,7 +356,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64607 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64608 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
64609 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
64610 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64611 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64612 #define kmalloc_node_track_caller(size, flags, node) \
64613 __kmalloc_node_track_caller(size, flags, node, \
64614 _RET_IP_)
64615 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64616 index cc290f0..0ba60931 100644
64617 --- a/include/linux/slab_def.h
64618 +++ b/include/linux/slab_def.h
64619 @@ -52,7 +52,7 @@ struct kmem_cache {
64620 /* 4) cache creation/removal */
64621 const char *name;
64622 struct list_head list;
64623 - int refcount;
64624 + atomic_t refcount;
64625 int object_size;
64626 int align;
64627
64628 @@ -68,10 +68,10 @@ struct kmem_cache {
64629 unsigned long node_allocs;
64630 unsigned long node_frees;
64631 unsigned long node_overflow;
64632 - atomic_t allochit;
64633 - atomic_t allocmiss;
64634 - atomic_t freehit;
64635 - atomic_t freemiss;
64636 + atomic_unchecked_t allochit;
64637 + atomic_unchecked_t allocmiss;
64638 + atomic_unchecked_t freehit;
64639 + atomic_unchecked_t freemiss;
64640
64641 /*
64642 * If debugging is enabled, then the allocator can add additional
64643 @@ -104,11 +104,16 @@ struct cache_sizes {
64644 #ifdef CONFIG_ZONE_DMA
64645 struct kmem_cache *cs_dmacachep;
64646 #endif
64647 +
64648 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64649 + struct kmem_cache *cs_usercopycachep;
64650 +#endif
64651 +
64652 };
64653 extern struct cache_sizes malloc_sizes[];
64654
64655 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64656 -void *__kmalloc(size_t size, gfp_t flags);
64657 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64658
64659 #ifdef CONFIG_TRACING
64660 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
64661 @@ -145,6 +150,13 @@ found:
64662 cachep = malloc_sizes[i].cs_dmacachep;
64663 else
64664 #endif
64665 +
64666 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64667 + if (flags & GFP_USERCOPY)
64668 + cachep = malloc_sizes[i].cs_usercopycachep;
64669 + else
64670 +#endif
64671 +
64672 cachep = malloc_sizes[i].cs_cachep;
64673
64674 ret = kmem_cache_alloc_trace(cachep, flags, size);
64675 @@ -155,7 +167,7 @@ found:
64676 }
64677
64678 #ifdef CONFIG_NUMA
64679 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64680 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64681 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64682
64683 #ifdef CONFIG_TRACING
64684 @@ -198,6 +210,13 @@ found:
64685 cachep = malloc_sizes[i].cs_dmacachep;
64686 else
64687 #endif
64688 +
64689 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64690 + if (flags & GFP_USERCOPY)
64691 + cachep = malloc_sizes[i].cs_usercopycachep;
64692 + else
64693 +#endif
64694 +
64695 cachep = malloc_sizes[i].cs_cachep;
64696
64697 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
64698 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64699 index f28e14a..7831211 100644
64700 --- a/include/linux/slob_def.h
64701 +++ b/include/linux/slob_def.h
64702 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64703 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
64704 }
64705
64706 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64707 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64708
64709 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64710 {
64711 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64712 return __kmalloc_node(size, flags, NUMA_NO_NODE);
64713 }
64714
64715 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64716 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64717 {
64718 return kmalloc(size, flags);
64719 }
64720 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64721 index df448ad..b99e7f6 100644
64722 --- a/include/linux/slub_def.h
64723 +++ b/include/linux/slub_def.h
64724 @@ -91,7 +91,7 @@ struct kmem_cache {
64725 struct kmem_cache_order_objects max;
64726 struct kmem_cache_order_objects min;
64727 gfp_t allocflags; /* gfp flags to use on each alloc */
64728 - int refcount; /* Refcount for slab cache destroy */
64729 + atomic_t refcount; /* Refcount for slab cache destroy */
64730 void (*ctor)(void *);
64731 int inuse; /* Offset to metadata */
64732 int align; /* Alignment */
64733 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64734 * Sorry that the following has to be that ugly but some versions of GCC
64735 * have trouble with constant propagation and loops.
64736 */
64737 -static __always_inline int kmalloc_index(size_t size)
64738 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64739 {
64740 if (!size)
64741 return 0;
64742 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64743 }
64744
64745 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64746 -void *__kmalloc(size_t size, gfp_t flags);
64747 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64748
64749 static __always_inline void *
64750 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64751 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64752 }
64753 #endif
64754
64755 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64756 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64757 {
64758 unsigned int order = get_order(size);
64759 return kmalloc_order_trace(size, flags, order);
64760 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64761 }
64762
64763 #ifdef CONFIG_NUMA
64764 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64765 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64766 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64767
64768 #ifdef CONFIG_TRACING
64769 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64770 index 680f9a3..f13aeb0 100644
64771 --- a/include/linux/sonet.h
64772 +++ b/include/linux/sonet.h
64773 @@ -7,7 +7,7 @@
64774 #include <uapi/linux/sonet.h>
64775
64776 struct k_sonet_stats {
64777 -#define __HANDLE_ITEM(i) atomic_t i
64778 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64779 __SONET_ITEMS
64780 #undef __HANDLE_ITEM
64781 };
64782 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64783 index 34206b8..f019e06 100644
64784 --- a/include/linux/sunrpc/clnt.h
64785 +++ b/include/linux/sunrpc/clnt.h
64786 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64787 {
64788 switch (sap->sa_family) {
64789 case AF_INET:
64790 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64791 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64792 case AF_INET6:
64793 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64794 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64795 }
64796 return 0;
64797 }
64798 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64799 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64800 const struct sockaddr *src)
64801 {
64802 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64803 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64804 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64805
64806 dsin->sin_family = ssin->sin_family;
64807 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64808 if (sa->sa_family != AF_INET6)
64809 return 0;
64810
64811 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64812 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64813 }
64814
64815 #endif /* __KERNEL__ */
64816 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64817 index dc0c3cc..8503fb6 100644
64818 --- a/include/linux/sunrpc/sched.h
64819 +++ b/include/linux/sunrpc/sched.h
64820 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64821 void (*rpc_count_stats)(struct rpc_task *, void *);
64822 void (*rpc_release)(void *);
64823 };
64824 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64825
64826 struct rpc_task_setup {
64827 struct rpc_task *task;
64828 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64829 index 0b8e3e6..33e0a01 100644
64830 --- a/include/linux/sunrpc/svc_rdma.h
64831 +++ b/include/linux/sunrpc/svc_rdma.h
64832 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64833 extern unsigned int svcrdma_max_requests;
64834 extern unsigned int svcrdma_max_req_size;
64835
64836 -extern atomic_t rdma_stat_recv;
64837 -extern atomic_t rdma_stat_read;
64838 -extern atomic_t rdma_stat_write;
64839 -extern atomic_t rdma_stat_sq_starve;
64840 -extern atomic_t rdma_stat_rq_starve;
64841 -extern atomic_t rdma_stat_rq_poll;
64842 -extern atomic_t rdma_stat_rq_prod;
64843 -extern atomic_t rdma_stat_sq_poll;
64844 -extern atomic_t rdma_stat_sq_prod;
64845 +extern atomic_unchecked_t rdma_stat_recv;
64846 +extern atomic_unchecked_t rdma_stat_read;
64847 +extern atomic_unchecked_t rdma_stat_write;
64848 +extern atomic_unchecked_t rdma_stat_sq_starve;
64849 +extern atomic_unchecked_t rdma_stat_rq_starve;
64850 +extern atomic_unchecked_t rdma_stat_rq_poll;
64851 +extern atomic_unchecked_t rdma_stat_rq_prod;
64852 +extern atomic_unchecked_t rdma_stat_sq_poll;
64853 +extern atomic_unchecked_t rdma_stat_sq_prod;
64854
64855 #define RPCRDMA_VERSION 1
64856
64857 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64858 index cd844a6..3ca3592 100644
64859 --- a/include/linux/sysctl.h
64860 +++ b/include/linux/sysctl.h
64861 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64862
64863 extern int proc_dostring(struct ctl_table *, int,
64864 void __user *, size_t *, loff_t *);
64865 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64866 + void __user *, size_t *, loff_t *);
64867 extern int proc_dointvec(struct ctl_table *, int,
64868 void __user *, size_t *, loff_t *);
64869 extern int proc_dointvec_minmax(struct ctl_table *, int,
64870 diff --git a/include/linux/tty.h b/include/linux/tty.h
64871 index f0b4eb4..1c4854e 100644
64872 --- a/include/linux/tty.h
64873 +++ b/include/linux/tty.h
64874 @@ -192,7 +192,7 @@ struct tty_port {
64875 const struct tty_port_operations *ops; /* Port operations */
64876 spinlock_t lock; /* Lock protecting tty field */
64877 int blocked_open; /* Waiting to open */
64878 - int count; /* Usage count */
64879 + atomic_t count; /* Usage count */
64880 wait_queue_head_t open_wait; /* Open waiters */
64881 wait_queue_head_t close_wait; /* Close waiters */
64882 wait_queue_head_t delta_msr_wait; /* Modem status change */
64883 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
64884 struct tty_struct *tty, struct file *filp);
64885 static inline int tty_port_users(struct tty_port *port)
64886 {
64887 - return port->count + port->blocked_open;
64888 + return atomic_read(&port->count) + port->blocked_open;
64889 }
64890
64891 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64892 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64893 index fb79dd8d..07d4773 100644
64894 --- a/include/linux/tty_ldisc.h
64895 +++ b/include/linux/tty_ldisc.h
64896 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64897
64898 struct module *owner;
64899
64900 - int refcount;
64901 + atomic_t refcount;
64902 };
64903
64904 struct tty_ldisc {
64905 diff --git a/include/linux/types.h b/include/linux/types.h
64906 index 1cc0e4b..0d50edf 100644
64907 --- a/include/linux/types.h
64908 +++ b/include/linux/types.h
64909 @@ -175,10 +175,26 @@ typedef struct {
64910 int counter;
64911 } atomic_t;
64912
64913 +#ifdef CONFIG_PAX_REFCOUNT
64914 +typedef struct {
64915 + int counter;
64916 +} atomic_unchecked_t;
64917 +#else
64918 +typedef atomic_t atomic_unchecked_t;
64919 +#endif
64920 +
64921 #ifdef CONFIG_64BIT
64922 typedef struct {
64923 long counter;
64924 } atomic64_t;
64925 +
64926 +#ifdef CONFIG_PAX_REFCOUNT
64927 +typedef struct {
64928 + long counter;
64929 +} atomic64_unchecked_t;
64930 +#else
64931 +typedef atomic64_t atomic64_unchecked_t;
64932 +#endif
64933 #endif
64934
64935 struct list_head {
64936 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64937 index 5ca0951..ab496a5 100644
64938 --- a/include/linux/uaccess.h
64939 +++ b/include/linux/uaccess.h
64940 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64941 long ret; \
64942 mm_segment_t old_fs = get_fs(); \
64943 \
64944 - set_fs(KERNEL_DS); \
64945 pagefault_disable(); \
64946 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64947 - pagefault_enable(); \
64948 + set_fs(KERNEL_DS); \
64949 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64950 set_fs(old_fs); \
64951 + pagefault_enable(); \
64952 ret; \
64953 })
64954
64955 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64956 index 99c1b4d..bb94261 100644
64957 --- a/include/linux/unaligned/access_ok.h
64958 +++ b/include/linux/unaligned/access_ok.h
64959 @@ -6,32 +6,32 @@
64960
64961 static inline u16 get_unaligned_le16(const void *p)
64962 {
64963 - return le16_to_cpup((__le16 *)p);
64964 + return le16_to_cpup((const __le16 *)p);
64965 }
64966
64967 static inline u32 get_unaligned_le32(const void *p)
64968 {
64969 - return le32_to_cpup((__le32 *)p);
64970 + return le32_to_cpup((const __le32 *)p);
64971 }
64972
64973 static inline u64 get_unaligned_le64(const void *p)
64974 {
64975 - return le64_to_cpup((__le64 *)p);
64976 + return le64_to_cpup((const __le64 *)p);
64977 }
64978
64979 static inline u16 get_unaligned_be16(const void *p)
64980 {
64981 - return be16_to_cpup((__be16 *)p);
64982 + return be16_to_cpup((const __be16 *)p);
64983 }
64984
64985 static inline u32 get_unaligned_be32(const void *p)
64986 {
64987 - return be32_to_cpup((__be32 *)p);
64988 + return be32_to_cpup((const __be32 *)p);
64989 }
64990
64991 static inline u64 get_unaligned_be64(const void *p)
64992 {
64993 - return be64_to_cpup((__be64 *)p);
64994 + return be64_to_cpup((const __be64 *)p);
64995 }
64996
64997 static inline void put_unaligned_le16(u16 val, void *p)
64998 diff --git a/include/linux/usb.h b/include/linux/usb.h
64999 index 10278d1..e21ec3c 100644
65000 --- a/include/linux/usb.h
65001 +++ b/include/linux/usb.h
65002 @@ -551,7 +551,7 @@ struct usb_device {
65003 int maxchild;
65004
65005 u32 quirks;
65006 - atomic_t urbnum;
65007 + atomic_unchecked_t urbnum;
65008
65009 unsigned long active_duration;
65010
65011 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65012 index c5d36c6..8478c90 100644
65013 --- a/include/linux/usb/renesas_usbhs.h
65014 +++ b/include/linux/usb/renesas_usbhs.h
65015 @@ -39,7 +39,7 @@ enum {
65016 */
65017 struct renesas_usbhs_driver_callback {
65018 int (*notify_hotplug)(struct platform_device *pdev);
65019 -};
65020 +} __no_const;
65021
65022 /*
65023 * callback functions for platform
65024 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65025 * VBUS control is needed for Host
65026 */
65027 int (*set_vbus)(struct platform_device *pdev, int enable);
65028 -};
65029 +} __no_const;
65030
65031 /*
65032 * parameters for renesas usbhs
65033 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65034 index 6f8fbcf..8259001 100644
65035 --- a/include/linux/vermagic.h
65036 +++ b/include/linux/vermagic.h
65037 @@ -25,9 +25,35 @@
65038 #define MODULE_ARCH_VERMAGIC ""
65039 #endif
65040
65041 +#ifdef CONFIG_PAX_REFCOUNT
65042 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65043 +#else
65044 +#define MODULE_PAX_REFCOUNT ""
65045 +#endif
65046 +
65047 +#ifdef CONSTIFY_PLUGIN
65048 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65049 +#else
65050 +#define MODULE_CONSTIFY_PLUGIN ""
65051 +#endif
65052 +
65053 +#ifdef STACKLEAK_PLUGIN
65054 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65055 +#else
65056 +#define MODULE_STACKLEAK_PLUGIN ""
65057 +#endif
65058 +
65059 +#ifdef CONFIG_GRKERNSEC
65060 +#define MODULE_GRSEC "GRSEC "
65061 +#else
65062 +#define MODULE_GRSEC ""
65063 +#endif
65064 +
65065 #define VERMAGIC_STRING \
65066 UTS_RELEASE " " \
65067 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65068 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65069 - MODULE_ARCH_VERMAGIC
65070 + MODULE_ARCH_VERMAGIC \
65071 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65072 + MODULE_GRSEC
65073
65074 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65075 index 6071e91..ca6a489 100644
65076 --- a/include/linux/vmalloc.h
65077 +++ b/include/linux/vmalloc.h
65078 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65079 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65080 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65081 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65082 +
65083 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65084 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65085 +#endif
65086 +
65087 /* bits [20..32] reserved for arch specific ioremap internals */
65088
65089 /*
65090 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65091 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65092 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65093 unsigned long start, unsigned long end, gfp_t gfp_mask,
65094 - pgprot_t prot, int node, const void *caller);
65095 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65096 extern void vfree(const void *addr);
65097
65098 extern void *vmap(struct page **pages, unsigned int count,
65099 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65100 extern void free_vm_area(struct vm_struct *area);
65101
65102 /* for /dev/kmem */
65103 -extern long vread(char *buf, char *addr, unsigned long count);
65104 -extern long vwrite(char *buf, char *addr, unsigned long count);
65105 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65106 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65107
65108 /*
65109 * Internals. Dont't use..
65110 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65111 index 92a86b2..1d9eb3c 100644
65112 --- a/include/linux/vmstat.h
65113 +++ b/include/linux/vmstat.h
65114 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65115 /*
65116 * Zone based page accounting with per cpu differentials.
65117 */
65118 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65119 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65120
65121 static inline void zone_page_state_add(long x, struct zone *zone,
65122 enum zone_stat_item item)
65123 {
65124 - atomic_long_add(x, &zone->vm_stat[item]);
65125 - atomic_long_add(x, &vm_stat[item]);
65126 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65127 + atomic_long_add_unchecked(x, &vm_stat[item]);
65128 }
65129
65130 static inline unsigned long global_page_state(enum zone_stat_item item)
65131 {
65132 - long x = atomic_long_read(&vm_stat[item]);
65133 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65134 #ifdef CONFIG_SMP
65135 if (x < 0)
65136 x = 0;
65137 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65138 static inline unsigned long zone_page_state(struct zone *zone,
65139 enum zone_stat_item item)
65140 {
65141 - long x = atomic_long_read(&zone->vm_stat[item]);
65142 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65143 #ifdef CONFIG_SMP
65144 if (x < 0)
65145 x = 0;
65146 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65147 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65148 enum zone_stat_item item)
65149 {
65150 - long x = atomic_long_read(&zone->vm_stat[item]);
65151 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65152
65153 #ifdef CONFIG_SMP
65154 int cpu;
65155 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65156
65157 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65158 {
65159 - atomic_long_inc(&zone->vm_stat[item]);
65160 - atomic_long_inc(&vm_stat[item]);
65161 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65162 + atomic_long_inc_unchecked(&vm_stat[item]);
65163 }
65164
65165 static inline void __inc_zone_page_state(struct page *page,
65166 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
65167
65168 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65169 {
65170 - atomic_long_dec(&zone->vm_stat[item]);
65171 - atomic_long_dec(&vm_stat[item]);
65172 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65173 + atomic_long_dec_unchecked(&vm_stat[item]);
65174 }
65175
65176 static inline void __dec_zone_page_state(struct page *page,
65177 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65178 index 944ecdf..a3994fc 100644
65179 --- a/include/media/saa7146_vv.h
65180 +++ b/include/media/saa7146_vv.h
65181 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65182 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65183
65184 /* the extension can override this */
65185 - struct v4l2_ioctl_ops vid_ops;
65186 - struct v4l2_ioctl_ops vbi_ops;
65187 + v4l2_ioctl_ops_no_const vid_ops;
65188 + v4l2_ioctl_ops_no_const vbi_ops;
65189 /* pointer to the saa7146 core ops */
65190 const struct v4l2_ioctl_ops *core_ops;
65191
65192 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65193 index 95d1c91..19a5d94 100644
65194 --- a/include/media/v4l2-dev.h
65195 +++ b/include/media/v4l2-dev.h
65196 @@ -76,7 +76,8 @@ struct v4l2_file_operations {
65197 int (*mmap) (struct file *, struct vm_area_struct *);
65198 int (*open) (struct file *);
65199 int (*release) (struct file *);
65200 -};
65201 +} __do_const;
65202 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65203
65204 /*
65205 * Newer version of video_device, handled by videodev2.c
65206 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65207 index e48b571..cec1748 100644
65208 --- a/include/media/v4l2-ioctl.h
65209 +++ b/include/media/v4l2-ioctl.h
65210 @@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
65211 long (*vidioc_default) (struct file *file, void *fh,
65212 bool valid_prio, int cmd, void *arg);
65213 };
65214 -
65215 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65216
65217 /* v4l debugging and diagnostics */
65218
65219 diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
65220 index ede0369..067cf12 100644
65221 --- a/include/net/bluetooth/bluetooth.h
65222 +++ b/include/net/bluetooth/bluetooth.h
65223 @@ -204,7 +204,7 @@ struct bt_sock_list {
65224 struct hlist_head head;
65225 rwlock_t lock;
65226 #ifdef CONFIG_PROC_FS
65227 - struct file_operations fops;
65228 + file_operations_no_const fops;
65229 int (* custom_seq_show)(struct seq_file *, void *);
65230 #endif
65231 };
65232 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65233 index bcb9cc3..f4ec722e 100644
65234 --- a/include/net/caif/caif_hsi.h
65235 +++ b/include/net/caif/caif_hsi.h
65236 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65237 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65238 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65239 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65240 -};
65241 +} __no_const;
65242
65243 /* Structure implemented by HSI device. */
65244 struct cfhsi_ops {
65245 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65246 index 9e5425b..8136ffc 100644
65247 --- a/include/net/caif/cfctrl.h
65248 +++ b/include/net/caif/cfctrl.h
65249 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65250 void (*radioset_rsp)(void);
65251 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65252 struct cflayer *client_layer);
65253 -};
65254 +} __no_const;
65255
65256 /* Link Setup Parameters for CAIF-Links. */
65257 struct cfctrl_link_param {
65258 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65259 struct cfctrl {
65260 struct cfsrvl serv;
65261 struct cfctrl_rsp res;
65262 - atomic_t req_seq_no;
65263 - atomic_t rsp_seq_no;
65264 + atomic_unchecked_t req_seq_no;
65265 + atomic_unchecked_t rsp_seq_no;
65266 struct list_head list;
65267 /* Protects from simultaneous access to first_req list */
65268 spinlock_t info_list_lock;
65269 diff --git a/include/net/flow.h b/include/net/flow.h
65270 index 628e11b..4c475df 100644
65271 --- a/include/net/flow.h
65272 +++ b/include/net/flow.h
65273 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65274
65275 extern void flow_cache_flush(void);
65276 extern void flow_cache_flush_deferred(void);
65277 -extern atomic_t flow_cache_genid;
65278 +extern atomic_unchecked_t flow_cache_genid;
65279
65280 #endif
65281 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
65282 index 4fd8a4b..123e31a 100644
65283 --- a/include/net/gro_cells.h
65284 +++ b/include/net/gro_cells.h
65285 @@ -30,7 +30,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
65286 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
65287
65288 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
65289 - atomic_long_inc(&dev->rx_dropped);
65290 + atomic_long_inc_unchecked(&dev->rx_dropped);
65291 kfree_skb(skb);
65292 return;
65293 }
65294 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65295 index 53f464d..ba76aaa 100644
65296 --- a/include/net/inetpeer.h
65297 +++ b/include/net/inetpeer.h
65298 @@ -47,8 +47,8 @@ struct inet_peer {
65299 */
65300 union {
65301 struct {
65302 - atomic_t rid; /* Frag reception counter */
65303 - atomic_t ip_id_count; /* IP ID for the next packet */
65304 + atomic_unchecked_t rid; /* Frag reception counter */
65305 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65306 };
65307 struct rcu_head rcu;
65308 struct inet_peer *gc_next;
65309 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65310 more++;
65311 inet_peer_refcheck(p);
65312 do {
65313 - old = atomic_read(&p->ip_id_count);
65314 + old = atomic_read_unchecked(&p->ip_id_count);
65315 new = old + more;
65316 if (!new)
65317 new = 1;
65318 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65319 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65320 return new;
65321 }
65322
65323 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65324 index 9497be1..5a4fafe 100644
65325 --- a/include/net/ip_fib.h
65326 +++ b/include/net/ip_fib.h
65327 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65328
65329 #define FIB_RES_SADDR(net, res) \
65330 ((FIB_RES_NH(res).nh_saddr_genid == \
65331 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65332 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65333 FIB_RES_NH(res).nh_saddr : \
65334 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65335 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65336 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65337 index ee75ccd..2cc2b95 100644
65338 --- a/include/net/ip_vs.h
65339 +++ b/include/net/ip_vs.h
65340 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65341 struct ip_vs_conn *control; /* Master control connection */
65342 atomic_t n_control; /* Number of controlled ones */
65343 struct ip_vs_dest *dest; /* real server */
65344 - atomic_t in_pkts; /* incoming packet counter */
65345 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65346
65347 /* packet transmitter for different forwarding methods. If it
65348 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65349 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65350 __be16 port; /* port number of the server */
65351 union nf_inet_addr addr; /* IP address of the server */
65352 volatile unsigned int flags; /* dest status flags */
65353 - atomic_t conn_flags; /* flags to copy to conn */
65354 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65355 atomic_t weight; /* server weight */
65356
65357 atomic_t refcnt; /* reference counter */
65358 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65359 index 69b610a..fe3962c 100644
65360 --- a/include/net/irda/ircomm_core.h
65361 +++ b/include/net/irda/ircomm_core.h
65362 @@ -51,7 +51,7 @@ typedef struct {
65363 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65364 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65365 struct ircomm_info *);
65366 -} call_t;
65367 +} __no_const call_t;
65368
65369 struct ircomm_cb {
65370 irda_queue_t queue;
65371 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65372 index 80ffde3..968b0f4 100644
65373 --- a/include/net/irda/ircomm_tty.h
65374 +++ b/include/net/irda/ircomm_tty.h
65375 @@ -35,6 +35,7 @@
65376 #include <linux/termios.h>
65377 #include <linux/timer.h>
65378 #include <linux/tty.h> /* struct tty_struct */
65379 +#include <asm/local.h>
65380
65381 #include <net/irda/irias_object.h>
65382 #include <net/irda/ircomm_core.h>
65383 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65384 index cc7c197..9f2da2a 100644
65385 --- a/include/net/iucv/af_iucv.h
65386 +++ b/include/net/iucv/af_iucv.h
65387 @@ -141,7 +141,7 @@ struct iucv_sock {
65388 struct iucv_sock_list {
65389 struct hlist_head head;
65390 rwlock_t lock;
65391 - atomic_t autobind_name;
65392 + atomic_unchecked_t autobind_name;
65393 };
65394
65395 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65396 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65397 index 0dab173..1b76af0 100644
65398 --- a/include/net/neighbour.h
65399 +++ b/include/net/neighbour.h
65400 @@ -123,7 +123,7 @@ struct neigh_ops {
65401 void (*error_report)(struct neighbour *, struct sk_buff *);
65402 int (*output)(struct neighbour *, struct sk_buff *);
65403 int (*connected_output)(struct neighbour *, struct sk_buff *);
65404 -};
65405 +} __do_const;
65406
65407 struct pneigh_entry {
65408 struct pneigh_entry *next;
65409 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65410 index 95e6466..251016d 100644
65411 --- a/include/net/net_namespace.h
65412 +++ b/include/net/net_namespace.h
65413 @@ -110,7 +110,7 @@ struct net {
65414 #endif
65415 struct netns_ipvs *ipvs;
65416 struct sock *diag_nlsk;
65417 - atomic_t rt_genid;
65418 + atomic_unchecked_t rt_genid;
65419 };
65420
65421 /*
65422 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65423
65424 static inline int rt_genid(struct net *net)
65425 {
65426 - return atomic_read(&net->rt_genid);
65427 + return atomic_read_unchecked(&net->rt_genid);
65428 }
65429
65430 static inline void rt_genid_bump(struct net *net)
65431 {
65432 - atomic_inc(&net->rt_genid);
65433 + atomic_inc_unchecked(&net->rt_genid);
65434 }
65435
65436 #endif /* __NET_NET_NAMESPACE_H */
65437 diff --git a/include/net/netdma.h b/include/net/netdma.h
65438 index 8ba8ce2..99b7fff 100644
65439 --- a/include/net/netdma.h
65440 +++ b/include/net/netdma.h
65441 @@ -24,7 +24,7 @@
65442 #include <linux/dmaengine.h>
65443 #include <linux/skbuff.h>
65444
65445 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65446 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65447 struct sk_buff *skb, int offset, struct iovec *to,
65448 size_t len, struct dma_pinned_list *pinned_list);
65449
65450 diff --git a/include/net/netlink.h b/include/net/netlink.h
65451 index 9690b0f..87aded7 100644
65452 --- a/include/net/netlink.h
65453 +++ b/include/net/netlink.h
65454 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65455 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65456 {
65457 if (mark)
65458 - skb_trim(skb, (unsigned char *) mark - skb->data);
65459 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65460 }
65461
65462 /**
65463 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65464 index 2ae2b83..dbdc85e 100644
65465 --- a/include/net/netns/ipv4.h
65466 +++ b/include/net/netns/ipv4.h
65467 @@ -64,7 +64,7 @@ struct netns_ipv4 {
65468 kgid_t sysctl_ping_group_range[2];
65469 long sysctl_tcp_mem[3];
65470
65471 - atomic_t dev_addr_genid;
65472 + atomic_unchecked_t dev_addr_genid;
65473
65474 #ifdef CONFIG_IP_MROUTE
65475 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65476 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65477 index 9c6414f..fbd0524 100644
65478 --- a/include/net/sctp/sctp.h
65479 +++ b/include/net/sctp/sctp.h
65480 @@ -318,9 +318,9 @@ do { \
65481
65482 #else /* SCTP_DEBUG */
65483
65484 -#define SCTP_DEBUG_PRINTK(whatever...)
65485 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65486 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65487 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65488 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65489 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65490 #define SCTP_ENABLE_DEBUG
65491 #define SCTP_DISABLE_DEBUG
65492 #define SCTP_ASSERT(expr, str, func)
65493 diff --git a/include/net/sock.h b/include/net/sock.h
65494 index c945fba..e162e56 100644
65495 --- a/include/net/sock.h
65496 +++ b/include/net/sock.h
65497 @@ -304,7 +304,7 @@ struct sock {
65498 #ifdef CONFIG_RPS
65499 __u32 sk_rxhash;
65500 #endif
65501 - atomic_t sk_drops;
65502 + atomic_unchecked_t sk_drops;
65503 int sk_rcvbuf;
65504
65505 struct sk_filter __rcu *sk_filter;
65506 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65507 }
65508
65509 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65510 - char __user *from, char *to,
65511 + char __user *from, unsigned char *to,
65512 int copy, int offset)
65513 {
65514 if (skb->ip_summed == CHECKSUM_NONE) {
65515 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65516 }
65517 }
65518
65519 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65520 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65521
65522 /**
65523 * sk_page_frag - return an appropriate page_frag
65524 diff --git a/include/net/tcp.h b/include/net/tcp.h
65525 index 4af45e3..32163a9 100644
65526 --- a/include/net/tcp.h
65527 +++ b/include/net/tcp.h
65528 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65529 extern void tcp_xmit_retransmit_queue(struct sock *);
65530 extern void tcp_simple_retransmit(struct sock *);
65531 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65532 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65533 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65534
65535 extern void tcp_send_probe0(struct sock *);
65536 extern void tcp_send_partial(struct sock *);
65537 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
65538 struct inet6_skb_parm h6;
65539 #endif
65540 } header; /* For incoming frames */
65541 - __u32 seq; /* Starting sequence number */
65542 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65543 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65544 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65545 __u32 when; /* used to compute rtt's */
65546 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65547
65548 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
65549
65550 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65551 /* 1 byte hole */
65552 - __u32 ack_seq; /* Sequence number ACK'd */
65553 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65554 };
65555
65556 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65557 @@ -1563,7 +1563,7 @@ struct tcp_seq_afinfo {
65558 char *name;
65559 sa_family_t family;
65560 const struct file_operations *seq_fops;
65561 - struct seq_operations seq_ops;
65562 + seq_operations_no_const seq_ops;
65563 };
65564
65565 struct tcp_iter_state {
65566 diff --git a/include/net/udp.h b/include/net/udp.h
65567 index 065f379..b661b40 100644
65568 --- a/include/net/udp.h
65569 +++ b/include/net/udp.h
65570 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65571 sa_family_t family;
65572 struct udp_table *udp_table;
65573 const struct file_operations *seq_fops;
65574 - struct seq_operations seq_ops;
65575 + seq_operations_no_const seq_ops;
65576 };
65577
65578 struct udp_iter_state {
65579 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65580 index 63445ed..01ddc62 100644
65581 --- a/include/net/xfrm.h
65582 +++ b/include/net/xfrm.h
65583 @@ -514,7 +514,7 @@ struct xfrm_policy {
65584 struct timer_list timer;
65585
65586 struct flow_cache_object flo;
65587 - atomic_t genid;
65588 + atomic_unchecked_t genid;
65589 u32 priority;
65590 u32 index;
65591 struct xfrm_mark mark;
65592 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65593 index 1a046b1..ee0bef0 100644
65594 --- a/include/rdma/iw_cm.h
65595 +++ b/include/rdma/iw_cm.h
65596 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65597 int backlog);
65598
65599 int (*destroy_listen)(struct iw_cm_id *cm_id);
65600 -};
65601 +} __no_const;
65602
65603 /**
65604 * iw_create_cm_id - Create an IW CM identifier.
65605 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65606 index 399162b..b337f1a 100644
65607 --- a/include/scsi/libfc.h
65608 +++ b/include/scsi/libfc.h
65609 @@ -762,6 +762,7 @@ struct libfc_function_template {
65610 */
65611 void (*disc_stop_final) (struct fc_lport *);
65612 };
65613 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65614
65615 /**
65616 * struct fc_disc - Discovery context
65617 @@ -866,7 +867,7 @@ struct fc_lport {
65618 struct fc_vport *vport;
65619
65620 /* Operational Information */
65621 - struct libfc_function_template tt;
65622 + libfc_function_template_no_const tt;
65623 u8 link_up;
65624 u8 qfull;
65625 enum fc_lport_state state;
65626 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65627 index 55367b0..d97bd2a 100644
65628 --- a/include/scsi/scsi_device.h
65629 +++ b/include/scsi/scsi_device.h
65630 @@ -169,9 +169,9 @@ struct scsi_device {
65631 unsigned int max_device_blocked; /* what device_blocked counts down from */
65632 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65633
65634 - atomic_t iorequest_cnt;
65635 - atomic_t iodone_cnt;
65636 - atomic_t ioerr_cnt;
65637 + atomic_unchecked_t iorequest_cnt;
65638 + atomic_unchecked_t iodone_cnt;
65639 + atomic_unchecked_t ioerr_cnt;
65640
65641 struct device sdev_gendev,
65642 sdev_dev;
65643 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65644 index b797e8f..8e2c3aa 100644
65645 --- a/include/scsi/scsi_transport_fc.h
65646 +++ b/include/scsi/scsi_transport_fc.h
65647 @@ -751,7 +751,8 @@ struct fc_function_template {
65648 unsigned long show_host_system_hostname:1;
65649
65650 unsigned long disable_target_scan:1;
65651 -};
65652 +} __do_const;
65653 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65654
65655
65656 /**
65657 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65658 index 030b87c..98a6954 100644
65659 --- a/include/sound/ak4xxx-adda.h
65660 +++ b/include/sound/ak4xxx-adda.h
65661 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65662 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65663 unsigned char val);
65664 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65665 -};
65666 +} __no_const;
65667
65668 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65669
65670 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65671 index 8c05e47..2b5df97 100644
65672 --- a/include/sound/hwdep.h
65673 +++ b/include/sound/hwdep.h
65674 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65675 struct snd_hwdep_dsp_status *status);
65676 int (*dsp_load)(struct snd_hwdep *hw,
65677 struct snd_hwdep_dsp_image *image);
65678 -};
65679 +} __no_const;
65680
65681 struct snd_hwdep {
65682 struct snd_card *card;
65683 diff --git a/include/sound/info.h b/include/sound/info.h
65684 index 9ca1a49..aba1728 100644
65685 --- a/include/sound/info.h
65686 +++ b/include/sound/info.h
65687 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65688 struct snd_info_buffer *buffer);
65689 void (*write)(struct snd_info_entry *entry,
65690 struct snd_info_buffer *buffer);
65691 -};
65692 +} __no_const;
65693
65694 struct snd_info_entry_ops {
65695 int (*open)(struct snd_info_entry *entry,
65696 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65697 index 6268a41..de9b9d1 100644
65698 --- a/include/sound/pcm.h
65699 +++ b/include/sound/pcm.h
65700 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65701 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65702 int (*ack)(struct snd_pcm_substream *substream);
65703 };
65704 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65705
65706 /*
65707 *
65708 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65709 index 7e95056..52df55a 100644
65710 --- a/include/sound/sb16_csp.h
65711 +++ b/include/sound/sb16_csp.h
65712 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65713 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65714 int (*csp_stop) (struct snd_sb_csp * p);
65715 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65716 -};
65717 +} __no_const;
65718
65719 /*
65720 * CSP private data
65721 diff --git a/include/sound/soc.h b/include/sound/soc.h
65722 index 91244a0..4534aae 100644
65723 --- a/include/sound/soc.h
65724 +++ b/include/sound/soc.h
65725 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
65726 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65727 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65728 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65729 -};
65730 +} __do_const;
65731
65732 struct snd_soc_platform {
65733 const char *name;
65734 @@ -1031,7 +1031,7 @@ struct snd_soc_pcm_runtime {
65735 struct snd_soc_dai_link *dai_link;
65736 struct mutex pcm_mutex;
65737 enum snd_soc_pcm_subclass pcm_subclass;
65738 - struct snd_pcm_ops ops;
65739 + snd_pcm_ops_no_const ops;
65740
65741 unsigned int dev_registered:1;
65742
65743 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65744 index 098c4de..171054b 100644
65745 --- a/include/sound/tea575x-tuner.h
65746 +++ b/include/sound/tea575x-tuner.h
65747 @@ -49,7 +49,7 @@ struct snd_tea575x_ops {
65748
65749 struct snd_tea575x {
65750 struct v4l2_device *v4l2_dev;
65751 - struct v4l2_file_operations fops;
65752 + v4l2_file_operations_no_const fops;
65753 struct video_device vd; /* video device */
65754 int radio_nr; /* radio_nr */
65755 bool tea5759; /* 5759 chip is present */
65756 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65757 index 5be8937..a8e46e9 100644
65758 --- a/include/target/target_core_base.h
65759 +++ b/include/target/target_core_base.h
65760 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65761 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65762 int (*t10_pr_register)(struct se_cmd *);
65763 int (*t10_pr_clear)(struct se_cmd *);
65764 -};
65765 +} __no_const;
65766
65767 struct t10_reservation {
65768 /* Reservation effects all target ports */
65769 @@ -758,7 +758,7 @@ struct se_device {
65770 spinlock_t stats_lock;
65771 /* Active commands on this virtual SE device */
65772 atomic_t simple_cmds;
65773 - atomic_t dev_ordered_id;
65774 + atomic_unchecked_t dev_ordered_id;
65775 atomic_t dev_ordered_sync;
65776 atomic_t dev_qf_count;
65777 struct se_obj dev_obj;
65778 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65779 new file mode 100644
65780 index 0000000..fb634b7
65781 --- /dev/null
65782 +++ b/include/trace/events/fs.h
65783 @@ -0,0 +1,53 @@
65784 +#undef TRACE_SYSTEM
65785 +#define TRACE_SYSTEM fs
65786 +
65787 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65788 +#define _TRACE_FS_H
65789 +
65790 +#include <linux/fs.h>
65791 +#include <linux/tracepoint.h>
65792 +
65793 +TRACE_EVENT(do_sys_open,
65794 +
65795 + TP_PROTO(const char *filename, int flags, int mode),
65796 +
65797 + TP_ARGS(filename, flags, mode),
65798 +
65799 + TP_STRUCT__entry(
65800 + __string( filename, filename )
65801 + __field( int, flags )
65802 + __field( int, mode )
65803 + ),
65804 +
65805 + TP_fast_assign(
65806 + __assign_str(filename, filename);
65807 + __entry->flags = flags;
65808 + __entry->mode = mode;
65809 + ),
65810 +
65811 + TP_printk("\"%s\" %x %o",
65812 + __get_str(filename), __entry->flags, __entry->mode)
65813 +);
65814 +
65815 +TRACE_EVENT(open_exec,
65816 +
65817 + TP_PROTO(const char *filename),
65818 +
65819 + TP_ARGS(filename),
65820 +
65821 + TP_STRUCT__entry(
65822 + __string( filename, filename )
65823 + ),
65824 +
65825 + TP_fast_assign(
65826 + __assign_str(filename, filename);
65827 + ),
65828 +
65829 + TP_printk("\"%s\"",
65830 + __get_str(filename))
65831 +);
65832 +
65833 +#endif /* _TRACE_FS_H */
65834 +
65835 +/* This part must be outside protection */
65836 +#include <trace/define_trace.h>
65837 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65838 index 1c09820..7f5ec79 100644
65839 --- a/include/trace/events/irq.h
65840 +++ b/include/trace/events/irq.h
65841 @@ -36,7 +36,7 @@ struct softirq_action;
65842 */
65843 TRACE_EVENT(irq_handler_entry,
65844
65845 - TP_PROTO(int irq, struct irqaction *action),
65846 + TP_PROTO(int irq, const struct irqaction *action),
65847
65848 TP_ARGS(irq, action),
65849
65850 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65851 */
65852 TRACE_EVENT(irq_handler_exit,
65853
65854 - TP_PROTO(int irq, struct irqaction *action, int ret),
65855 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65856
65857 TP_ARGS(irq, action, ret),
65858
65859 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
65860 index 7caf44c..23c6f27 100644
65861 --- a/include/uapi/linux/a.out.h
65862 +++ b/include/uapi/linux/a.out.h
65863 @@ -39,6 +39,14 @@ enum machine_type {
65864 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
65865 };
65866
65867 +/* Constants for the N_FLAGS field */
65868 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65869 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
65870 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
65871 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
65872 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65873 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65874 +
65875 #if !defined (N_MAGIC)
65876 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
65877 #endif
65878 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
65879 index d876736..b36014e 100644
65880 --- a/include/uapi/linux/byteorder/little_endian.h
65881 +++ b/include/uapi/linux/byteorder/little_endian.h
65882 @@ -42,51 +42,51 @@
65883
65884 static inline __le64 __cpu_to_le64p(const __u64 *p)
65885 {
65886 - return (__force __le64)*p;
65887 + return (__force const __le64)*p;
65888 }
65889 static inline __u64 __le64_to_cpup(const __le64 *p)
65890 {
65891 - return (__force __u64)*p;
65892 + return (__force const __u64)*p;
65893 }
65894 static inline __le32 __cpu_to_le32p(const __u32 *p)
65895 {
65896 - return (__force __le32)*p;
65897 + return (__force const __le32)*p;
65898 }
65899 static inline __u32 __le32_to_cpup(const __le32 *p)
65900 {
65901 - return (__force __u32)*p;
65902 + return (__force const __u32)*p;
65903 }
65904 static inline __le16 __cpu_to_le16p(const __u16 *p)
65905 {
65906 - return (__force __le16)*p;
65907 + return (__force const __le16)*p;
65908 }
65909 static inline __u16 __le16_to_cpup(const __le16 *p)
65910 {
65911 - return (__force __u16)*p;
65912 + return (__force const __u16)*p;
65913 }
65914 static inline __be64 __cpu_to_be64p(const __u64 *p)
65915 {
65916 - return (__force __be64)__swab64p(p);
65917 + return (__force const __be64)__swab64p(p);
65918 }
65919 static inline __u64 __be64_to_cpup(const __be64 *p)
65920 {
65921 - return __swab64p((__u64 *)p);
65922 + return __swab64p((const __u64 *)p);
65923 }
65924 static inline __be32 __cpu_to_be32p(const __u32 *p)
65925 {
65926 - return (__force __be32)__swab32p(p);
65927 + return (__force const __be32)__swab32p(p);
65928 }
65929 static inline __u32 __be32_to_cpup(const __be32 *p)
65930 {
65931 - return __swab32p((__u32 *)p);
65932 + return __swab32p((const __u32 *)p);
65933 }
65934 static inline __be16 __cpu_to_be16p(const __u16 *p)
65935 {
65936 - return (__force __be16)__swab16p(p);
65937 + return (__force const __be16)__swab16p(p);
65938 }
65939 static inline __u16 __be16_to_cpup(const __be16 *p)
65940 {
65941 - return __swab16p((__u16 *)p);
65942 + return __swab16p((const __u16 *)p);
65943 }
65944 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
65945 #define __le64_to_cpus(x) do { (void)(x); } while (0)
65946 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
65947 index 126a817..d522bd1 100644
65948 --- a/include/uapi/linux/elf.h
65949 +++ b/include/uapi/linux/elf.h
65950 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
65951 #define PT_GNU_EH_FRAME 0x6474e550
65952
65953 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
65954 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
65955 +
65956 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
65957 +
65958 +/* Constants for the e_flags field */
65959 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65960 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
65961 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
65962 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
65963 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65964 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65965
65966 /*
65967 * Extended Numbering
65968 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
65969 #define DT_DEBUG 21
65970 #define DT_TEXTREL 22
65971 #define DT_JMPREL 23
65972 +#define DT_FLAGS 30
65973 + #define DF_TEXTREL 0x00000004
65974 #define DT_ENCODING 32
65975 #define OLD_DT_LOOS 0x60000000
65976 #define DT_LOOS 0x6000000d
65977 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
65978 #define PF_W 0x2
65979 #define PF_X 0x1
65980
65981 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
65982 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
65983 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
65984 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
65985 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
65986 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
65987 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
65988 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
65989 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
65990 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
65991 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
65992 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
65993 +
65994 typedef struct elf32_phdr{
65995 Elf32_Word p_type;
65996 Elf32_Off p_offset;
65997 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
65998 #define EI_OSABI 7
65999 #define EI_PAD 8
66000
66001 +#define EI_PAX 14
66002 +
66003 #define ELFMAG0 0x7f /* EI_MAG */
66004 #define ELFMAG1 'E'
66005 #define ELFMAG2 'L'
66006 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
66007 index aa169c4..6a2771d 100644
66008 --- a/include/uapi/linux/personality.h
66009 +++ b/include/uapi/linux/personality.h
66010 @@ -30,6 +30,7 @@ enum {
66011 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
66012 ADDR_NO_RANDOMIZE | \
66013 ADDR_COMPAT_LAYOUT | \
66014 + ADDR_LIMIT_3GB | \
66015 MMAP_PAGE_ZERO)
66016
66017 /*
66018 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
66019 index 7530e74..e714828 100644
66020 --- a/include/uapi/linux/screen_info.h
66021 +++ b/include/uapi/linux/screen_info.h
66022 @@ -43,7 +43,8 @@ struct screen_info {
66023 __u16 pages; /* 0x32 */
66024 __u16 vesa_attributes; /* 0x34 */
66025 __u32 capabilities; /* 0x36 */
66026 - __u8 _reserved[6]; /* 0x3a */
66027 + __u16 vesapm_size; /* 0x3a */
66028 + __u8 _reserved[4]; /* 0x3c */
66029 } __attribute__((packed));
66030
66031 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
66032 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
66033 index 6d67213..8dab561 100644
66034 --- a/include/uapi/linux/sysctl.h
66035 +++ b/include/uapi/linux/sysctl.h
66036 @@ -155,7 +155,11 @@ enum
66037 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
66038 };
66039
66040 -
66041 +#ifdef CONFIG_PAX_SOFTMODE
66042 +enum {
66043 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
66044 +};
66045 +#endif
66046
66047 /* CTL_VM names: */
66048 enum
66049 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
66050 index 26607bd..588b65f 100644
66051 --- a/include/uapi/linux/xattr.h
66052 +++ b/include/uapi/linux/xattr.h
66053 @@ -60,5 +60,9 @@
66054 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
66055 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
66056
66057 +/* User namespace */
66058 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
66059 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
66060 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
66061
66062 #endif /* _UAPI_LINUX_XATTR_H */
66063 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
66064 index f9466fa..f4e2b81 100644
66065 --- a/include/video/udlfb.h
66066 +++ b/include/video/udlfb.h
66067 @@ -53,10 +53,10 @@ struct dlfb_data {
66068 u32 pseudo_palette[256];
66069 int blank_mode; /*one of FB_BLANK_ */
66070 /* blit-only rendering path metrics, exposed through sysfs */
66071 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66072 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
66073 - atomic_t bytes_sent; /* to usb, after compression including overhead */
66074 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
66075 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
66076 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
66077 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
66078 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
66079 };
66080
66081 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
66082 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
66083 index 0993a22..32ba2fe 100644
66084 --- a/include/video/uvesafb.h
66085 +++ b/include/video/uvesafb.h
66086 @@ -177,6 +177,7 @@ struct uvesafb_par {
66087 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
66088 u8 pmi_setpal; /* PMI for palette changes */
66089 u16 *pmi_base; /* protected mode interface location */
66090 + u8 *pmi_code; /* protected mode code location */
66091 void *pmi_start;
66092 void *pmi_pal;
66093 u8 *vbe_state_orig; /*
66094 diff --git a/init/Kconfig b/init/Kconfig
66095 index 6fdd6e3..5b01610 100644
66096 --- a/init/Kconfig
66097 +++ b/init/Kconfig
66098 @@ -925,6 +925,7 @@ endif # CGROUPS
66099
66100 config CHECKPOINT_RESTORE
66101 bool "Checkpoint/restore support" if EXPERT
66102 + depends on !GRKERNSEC
66103 default n
66104 help
66105 Enables additional kernel features in a sake of checkpoint/restore.
66106 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
66107 depends on OCFS2_FS = n
66108 depends on XFS_FS = n
66109
66110 + depends on GRKERNSEC = n
66111 +
66112 config UIDGID_STRICT_TYPE_CHECKS
66113 bool "Require conversions between uid/gids and their internal representation"
66114 depends on UIDGID_CONVERTED
66115 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
66116
66117 config COMPAT_BRK
66118 bool "Disable heap randomization"
66119 - default y
66120 + default n
66121 help
66122 Randomizing heap placement makes heap exploits harder, but it
66123 also breaks ancient binaries (including anything libc5 based).
66124 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
66125 config STOP_MACHINE
66126 bool
66127 default y
66128 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
66129 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
66130 help
66131 Need stop_machine() primitive.
66132
66133 diff --git a/init/Makefile b/init/Makefile
66134 index 7bc47ee..6da2dc7 100644
66135 --- a/init/Makefile
66136 +++ b/init/Makefile
66137 @@ -2,6 +2,9 @@
66138 # Makefile for the linux kernel.
66139 #
66140
66141 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
66142 +asflags-y := $(GCC_PLUGINS_AFLAGS)
66143 +
66144 obj-y := main.o version.o mounts.o
66145 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
66146 obj-y += noinitramfs.o
66147 diff --git a/init/do_mounts.c b/init/do_mounts.c
66148 index f8a6642..4e5ee1b 100644
66149 --- a/init/do_mounts.c
66150 +++ b/init/do_mounts.c
66151 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
66152 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
66153 {
66154 struct super_block *s;
66155 - int err = sys_mount(name, "/root", fs, flags, data);
66156 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
66157 if (err)
66158 return err;
66159
66160 - sys_chdir("/root");
66161 + sys_chdir((const char __force_user *)"/root");
66162 s = current->fs->pwd.dentry->d_sb;
66163 ROOT_DEV = s->s_dev;
66164 printk(KERN_INFO
66165 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
66166 va_start(args, fmt);
66167 vsprintf(buf, fmt, args);
66168 va_end(args);
66169 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
66170 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
66171 if (fd >= 0) {
66172 sys_ioctl(fd, FDEJECT, 0);
66173 sys_close(fd);
66174 }
66175 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
66176 - fd = sys_open("/dev/console", O_RDWR, 0);
66177 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
66178 if (fd >= 0) {
66179 sys_ioctl(fd, TCGETS, (long)&termios);
66180 termios.c_lflag &= ~ICANON;
66181 sys_ioctl(fd, TCSETSF, (long)&termios);
66182 - sys_read(fd, &c, 1);
66183 + sys_read(fd, (char __user *)&c, 1);
66184 termios.c_lflag |= ICANON;
66185 sys_ioctl(fd, TCSETSF, (long)&termios);
66186 sys_close(fd);
66187 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
66188 mount_root();
66189 out:
66190 devtmpfs_mount("dev");
66191 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66192 - sys_chroot(".");
66193 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66194 + sys_chroot((const char __force_user *)".");
66195 }
66196 diff --git a/init/do_mounts.h b/init/do_mounts.h
66197 index f5b978a..69dbfe8 100644
66198 --- a/init/do_mounts.h
66199 +++ b/init/do_mounts.h
66200 @@ -15,15 +15,15 @@ extern int root_mountflags;
66201
66202 static inline int create_dev(char *name, dev_t dev)
66203 {
66204 - sys_unlink(name);
66205 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
66206 + sys_unlink((char __force_user *)name);
66207 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
66208 }
66209
66210 #if BITS_PER_LONG == 32
66211 static inline u32 bstat(char *name)
66212 {
66213 struct stat64 stat;
66214 - if (sys_stat64(name, &stat) != 0)
66215 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66216 return 0;
66217 if (!S_ISBLK(stat.st_mode))
66218 return 0;
66219 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66220 static inline u32 bstat(char *name)
66221 {
66222 struct stat stat;
66223 - if (sys_newstat(name, &stat) != 0)
66224 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66225 return 0;
66226 if (!S_ISBLK(stat.st_mode))
66227 return 0;
66228 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66229 index 5e4ded5..aa3cd7e 100644
66230 --- a/init/do_mounts_initrd.c
66231 +++ b/init/do_mounts_initrd.c
66232 @@ -54,8 +54,8 @@ static void __init handle_initrd(void)
66233 create_dev("/dev/root.old", Root_RAM0);
66234 /* mount initrd on rootfs' /root */
66235 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66236 - sys_mkdir("/old", 0700);
66237 - sys_chdir("/old");
66238 + sys_mkdir((const char __force_user *)"/old", 0700);
66239 + sys_chdir((const char __force_user *)"/old");
66240
66241 /*
66242 * In case that a resume from disk is carried out by linuxrc or one of
66243 @@ -69,31 +69,31 @@ static void __init handle_initrd(void)
66244 current->flags &= ~PF_FREEZER_SKIP;
66245
66246 /* move initrd to rootfs' /old */
66247 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
66248 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
66249 /* switch root and cwd back to / of rootfs */
66250 - sys_chroot("..");
66251 + sys_chroot((const char __force_user *)"..");
66252
66253 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66254 - sys_chdir("/old");
66255 + sys_chdir((const char __force_user *)"/old");
66256 return;
66257 }
66258
66259 - sys_chdir("/");
66260 + sys_chdir((const char __force_user *)"/");
66261 ROOT_DEV = new_decode_dev(real_root_dev);
66262 mount_root();
66263
66264 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66265 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66266 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66267 if (!error)
66268 printk("okay\n");
66269 else {
66270 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66271 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66272 if (error == -ENOENT)
66273 printk("/initrd does not exist. Ignored.\n");
66274 else
66275 printk("failed\n");
66276 printk(KERN_NOTICE "Unmounting old root\n");
66277 - sys_umount("/old", MNT_DETACH);
66278 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66279 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66280 if (fd < 0) {
66281 error = fd;
66282 @@ -116,11 +116,11 @@ int __init initrd_load(void)
66283 * mounted in the normal path.
66284 */
66285 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66286 - sys_unlink("/initrd.image");
66287 + sys_unlink((const char __force_user *)"/initrd.image");
66288 handle_initrd();
66289 return 1;
66290 }
66291 }
66292 - sys_unlink("/initrd.image");
66293 + sys_unlink((const char __force_user *)"/initrd.image");
66294 return 0;
66295 }
66296 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66297 index 8cb6db5..d729f50 100644
66298 --- a/init/do_mounts_md.c
66299 +++ b/init/do_mounts_md.c
66300 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66301 partitioned ? "_d" : "", minor,
66302 md_setup_args[ent].device_names);
66303
66304 - fd = sys_open(name, 0, 0);
66305 + fd = sys_open((char __force_user *)name, 0, 0);
66306 if (fd < 0) {
66307 printk(KERN_ERR "md: open failed - cannot start "
66308 "array %s\n", name);
66309 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66310 * array without it
66311 */
66312 sys_close(fd);
66313 - fd = sys_open(name, 0, 0);
66314 + fd = sys_open((char __force_user *)name, 0, 0);
66315 sys_ioctl(fd, BLKRRPART, 0);
66316 }
66317 sys_close(fd);
66318 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66319
66320 wait_for_device_probe();
66321
66322 - fd = sys_open("/dev/md0", 0, 0);
66323 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66324 if (fd >= 0) {
66325 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66326 sys_close(fd);
66327 diff --git a/init/init_task.c b/init/init_task.c
66328 index 8b2f399..f0797c9 100644
66329 --- a/init/init_task.c
66330 +++ b/init/init_task.c
66331 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66332 * Initial thread structure. Alignment of this is handled by a special
66333 * linker map entry.
66334 */
66335 +#ifdef CONFIG_X86
66336 +union thread_union init_thread_union __init_task_data;
66337 +#else
66338 union thread_union init_thread_union __init_task_data =
66339 { INIT_THREAD_INFO(init_task) };
66340 +#endif
66341 diff --git a/init/initramfs.c b/init/initramfs.c
66342 index 84c6bf1..8899338 100644
66343 --- a/init/initramfs.c
66344 +++ b/init/initramfs.c
66345 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66346 }
66347 }
66348
66349 -static long __init do_utime(char *filename, time_t mtime)
66350 +static long __init do_utime(char __force_user *filename, time_t mtime)
66351 {
66352 struct timespec t[2];
66353
66354 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66355 struct dir_entry *de, *tmp;
66356 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66357 list_del(&de->list);
66358 - do_utime(de->name, de->mtime);
66359 + do_utime((char __force_user *)de->name, de->mtime);
66360 kfree(de->name);
66361 kfree(de);
66362 }
66363 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66364 if (nlink >= 2) {
66365 char *old = find_link(major, minor, ino, mode, collected);
66366 if (old)
66367 - return (sys_link(old, collected) < 0) ? -1 : 1;
66368 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66369 }
66370 return 0;
66371 }
66372 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66373 {
66374 struct stat st;
66375
66376 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66377 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66378 if (S_ISDIR(st.st_mode))
66379 - sys_rmdir(path);
66380 + sys_rmdir((char __force_user *)path);
66381 else
66382 - sys_unlink(path);
66383 + sys_unlink((char __force_user *)path);
66384 }
66385 }
66386
66387 @@ -315,7 +315,7 @@ static int __init do_name(void)
66388 int openflags = O_WRONLY|O_CREAT;
66389 if (ml != 1)
66390 openflags |= O_TRUNC;
66391 - wfd = sys_open(collected, openflags, mode);
66392 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66393
66394 if (wfd >= 0) {
66395 sys_fchown(wfd, uid, gid);
66396 @@ -327,17 +327,17 @@ static int __init do_name(void)
66397 }
66398 }
66399 } else if (S_ISDIR(mode)) {
66400 - sys_mkdir(collected, mode);
66401 - sys_chown(collected, uid, gid);
66402 - sys_chmod(collected, mode);
66403 + sys_mkdir((char __force_user *)collected, mode);
66404 + sys_chown((char __force_user *)collected, uid, gid);
66405 + sys_chmod((char __force_user *)collected, mode);
66406 dir_add(collected, mtime);
66407 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66408 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66409 if (maybe_link() == 0) {
66410 - sys_mknod(collected, mode, rdev);
66411 - sys_chown(collected, uid, gid);
66412 - sys_chmod(collected, mode);
66413 - do_utime(collected, mtime);
66414 + sys_mknod((char __force_user *)collected, mode, rdev);
66415 + sys_chown((char __force_user *)collected, uid, gid);
66416 + sys_chmod((char __force_user *)collected, mode);
66417 + do_utime((char __force_user *)collected, mtime);
66418 }
66419 }
66420 return 0;
66421 @@ -346,15 +346,15 @@ static int __init do_name(void)
66422 static int __init do_copy(void)
66423 {
66424 if (count >= body_len) {
66425 - sys_write(wfd, victim, body_len);
66426 + sys_write(wfd, (char __force_user *)victim, body_len);
66427 sys_close(wfd);
66428 - do_utime(vcollected, mtime);
66429 + do_utime((char __force_user *)vcollected, mtime);
66430 kfree(vcollected);
66431 eat(body_len);
66432 state = SkipIt;
66433 return 0;
66434 } else {
66435 - sys_write(wfd, victim, count);
66436 + sys_write(wfd, (char __force_user *)victim, count);
66437 body_len -= count;
66438 eat(count);
66439 return 1;
66440 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66441 {
66442 collected[N_ALIGN(name_len) + body_len] = '\0';
66443 clean_path(collected, 0);
66444 - sys_symlink(collected + N_ALIGN(name_len), collected);
66445 - sys_lchown(collected, uid, gid);
66446 - do_utime(collected, mtime);
66447 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66448 + sys_lchown((char __force_user *)collected, uid, gid);
66449 + do_utime((char __force_user *)collected, mtime);
66450 state = SkipIt;
66451 next_state = Reset;
66452 return 0;
66453 diff --git a/init/main.c b/init/main.c
66454 index e33e09d..8544e50 100644
66455 --- a/init/main.c
66456 +++ b/init/main.c
66457 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66458 extern void tc_init(void);
66459 #endif
66460
66461 +extern void grsecurity_init(void);
66462 +
66463 /*
66464 * Debug helper: via this flag we know that we are in 'early bootup code'
66465 * where only the boot processor is running with IRQ disabled. This means
66466 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66467
66468 __setup("reset_devices", set_reset_devices);
66469
66470 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66471 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66472 +static int __init setup_grsec_proc_gid(char *str)
66473 +{
66474 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66475 + return 1;
66476 +}
66477 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66478 +#endif
66479 +
66480 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66481 +extern char pax_enter_kernel_user[];
66482 +extern char pax_exit_kernel_user[];
66483 +extern pgdval_t clone_pgd_mask;
66484 +#endif
66485 +
66486 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66487 +static int __init setup_pax_nouderef(char *str)
66488 +{
66489 +#ifdef CONFIG_X86_32
66490 + unsigned int cpu;
66491 + struct desc_struct *gdt;
66492 +
66493 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66494 + gdt = get_cpu_gdt_table(cpu);
66495 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66496 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66497 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66498 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66499 + }
66500 + loadsegment(ds, __KERNEL_DS);
66501 + loadsegment(es, __KERNEL_DS);
66502 + loadsegment(ss, __KERNEL_DS);
66503 +#else
66504 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66505 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66506 + clone_pgd_mask = ~(pgdval_t)0UL;
66507 +#endif
66508 +
66509 + return 0;
66510 +}
66511 +early_param("pax_nouderef", setup_pax_nouderef);
66512 +#endif
66513 +
66514 +#ifdef CONFIG_PAX_SOFTMODE
66515 +int pax_softmode;
66516 +
66517 +static int __init setup_pax_softmode(char *str)
66518 +{
66519 + get_option(&str, &pax_softmode);
66520 + return 1;
66521 +}
66522 +__setup("pax_softmode=", setup_pax_softmode);
66523 +#endif
66524 +
66525 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66526 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66527 static const char *panic_later, *panic_param;
66528 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66529 {
66530 int count = preempt_count();
66531 int ret;
66532 + const char *msg1 = "", *msg2 = "";
66533
66534 if (initcall_debug)
66535 ret = do_one_initcall_debug(fn);
66536 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66537 sprintf(msgbuf, "error code %d ", ret);
66538
66539 if (preempt_count() != count) {
66540 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66541 + msg1 = " preemption imbalance";
66542 preempt_count() = count;
66543 }
66544 if (irqs_disabled()) {
66545 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66546 + msg2 = " disabled interrupts";
66547 local_irq_enable();
66548 }
66549 - if (msgbuf[0]) {
66550 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66551 + if (msgbuf[0] || *msg1 || *msg2) {
66552 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66553 }
66554
66555 return ret;
66556 @@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
66557 level, level,
66558 &repair_env_string);
66559
66560 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66561 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66562 do_one_initcall(*fn);
66563 +
66564 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66565 + transfer_latent_entropy();
66566 +#endif
66567 +
66568 + }
66569 }
66570
66571 static void __init do_initcalls(void)
66572 @@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
66573 {
66574 initcall_t *fn;
66575
66576 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66577 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66578 do_one_initcall(*fn);
66579 +
66580 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66581 + transfer_latent_entropy();
66582 +#endif
66583 +
66584 + }
66585 }
66586
66587 static int run_init_process(const char *init_filename)
66588 @@ -876,7 +946,7 @@ static void __init kernel_init_freeable(void)
66589 do_basic_setup();
66590
66591 /* Open the /dev/console on the rootfs, this should never fail */
66592 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66593 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66594 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66595
66596 (void) sys_dup(0);
66597 @@ -889,11 +959,13 @@ static void __init kernel_init_freeable(void)
66598 if (!ramdisk_execute_command)
66599 ramdisk_execute_command = "/init";
66600
66601 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66602 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66603 ramdisk_execute_command = NULL;
66604 prepare_namespace();
66605 }
66606
66607 + grsecurity_init();
66608 +
66609 /*
66610 * Ok, we have completed the initial bootup, and
66611 * we're essentially up and running. Get rid of the
66612 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66613 index 71a3ca1..cc330ee 100644
66614 --- a/ipc/mqueue.c
66615 +++ b/ipc/mqueue.c
66616 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66617 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66618 info->attr.mq_msgsize);
66619
66620 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66621 spin_lock(&mq_lock);
66622 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66623 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66624 diff --git a/ipc/msg.c b/ipc/msg.c
66625 index a71af5a..a90a110 100644
66626 --- a/ipc/msg.c
66627 +++ b/ipc/msg.c
66628 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66629 return security_msg_queue_associate(msq, msgflg);
66630 }
66631
66632 +static struct ipc_ops msg_ops = {
66633 + .getnew = newque,
66634 + .associate = msg_security,
66635 + .more_checks = NULL
66636 +};
66637 +
66638 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66639 {
66640 struct ipc_namespace *ns;
66641 - struct ipc_ops msg_ops;
66642 struct ipc_params msg_params;
66643
66644 ns = current->nsproxy->ipc_ns;
66645
66646 - msg_ops.getnew = newque;
66647 - msg_ops.associate = msg_security;
66648 - msg_ops.more_checks = NULL;
66649 -
66650 msg_params.key = key;
66651 msg_params.flg = msgflg;
66652
66653 diff --git a/ipc/sem.c b/ipc/sem.c
66654 index 58d31f1..cce7a55 100644
66655 --- a/ipc/sem.c
66656 +++ b/ipc/sem.c
66657 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66658 return 0;
66659 }
66660
66661 +static struct ipc_ops sem_ops = {
66662 + .getnew = newary,
66663 + .associate = sem_security,
66664 + .more_checks = sem_more_checks
66665 +};
66666 +
66667 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66668 {
66669 struct ipc_namespace *ns;
66670 - struct ipc_ops sem_ops;
66671 struct ipc_params sem_params;
66672
66673 ns = current->nsproxy->ipc_ns;
66674 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66675 if (nsems < 0 || nsems > ns->sc_semmsl)
66676 return -EINVAL;
66677
66678 - sem_ops.getnew = newary;
66679 - sem_ops.associate = sem_security;
66680 - sem_ops.more_checks = sem_more_checks;
66681 -
66682 sem_params.key = key;
66683 sem_params.flg = semflg;
66684 sem_params.u.nsems = nsems;
66685 diff --git a/ipc/shm.c b/ipc/shm.c
66686 index dff40c9..9450e27 100644
66687 --- a/ipc/shm.c
66688 +++ b/ipc/shm.c
66689 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66690 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66691 #endif
66692
66693 +#ifdef CONFIG_GRKERNSEC
66694 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66695 + const time_t shm_createtime, const uid_t cuid,
66696 + const int shmid);
66697 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66698 + const time_t shm_createtime);
66699 +#endif
66700 +
66701 void shm_init_ns(struct ipc_namespace *ns)
66702 {
66703 ns->shm_ctlmax = SHMMAX;
66704 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66705 shp->shm_lprid = 0;
66706 shp->shm_atim = shp->shm_dtim = 0;
66707 shp->shm_ctim = get_seconds();
66708 +#ifdef CONFIG_GRKERNSEC
66709 + {
66710 + struct timespec timeval;
66711 + do_posix_clock_monotonic_gettime(&timeval);
66712 +
66713 + shp->shm_createtime = timeval.tv_sec;
66714 + }
66715 +#endif
66716 shp->shm_segsz = size;
66717 shp->shm_nattch = 0;
66718 shp->shm_file = file;
66719 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66720 return 0;
66721 }
66722
66723 +static struct ipc_ops shm_ops = {
66724 + .getnew = newseg,
66725 + .associate = shm_security,
66726 + .more_checks = shm_more_checks
66727 +};
66728 +
66729 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66730 {
66731 struct ipc_namespace *ns;
66732 - struct ipc_ops shm_ops;
66733 struct ipc_params shm_params;
66734
66735 ns = current->nsproxy->ipc_ns;
66736
66737 - shm_ops.getnew = newseg;
66738 - shm_ops.associate = shm_security;
66739 - shm_ops.more_checks = shm_more_checks;
66740 -
66741 shm_params.key = key;
66742 shm_params.flg = shmflg;
66743 shm_params.u.size = size;
66744 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66745 f_mode = FMODE_READ | FMODE_WRITE;
66746 }
66747 if (shmflg & SHM_EXEC) {
66748 +
66749 +#ifdef CONFIG_PAX_MPROTECT
66750 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66751 + goto out;
66752 +#endif
66753 +
66754 prot |= PROT_EXEC;
66755 acc_mode |= S_IXUGO;
66756 }
66757 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66758 if (err)
66759 goto out_unlock;
66760
66761 +#ifdef CONFIG_GRKERNSEC
66762 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66763 + shp->shm_perm.cuid, shmid) ||
66764 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66765 + err = -EACCES;
66766 + goto out_unlock;
66767 + }
66768 +#endif
66769 +
66770 path = shp->shm_file->f_path;
66771 path_get(&path);
66772 shp->shm_nattch++;
66773 +#ifdef CONFIG_GRKERNSEC
66774 + shp->shm_lapid = current->pid;
66775 +#endif
66776 size = i_size_read(path.dentry->d_inode);
66777 shm_unlock(shp);
66778
66779 diff --git a/kernel/acct.c b/kernel/acct.c
66780 index 051e071..15e0920 100644
66781 --- a/kernel/acct.c
66782 +++ b/kernel/acct.c
66783 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66784 */
66785 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66786 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66787 - file->f_op->write(file, (char *)&ac,
66788 + file->f_op->write(file, (char __force_user *)&ac,
66789 sizeof(acct_t), &file->f_pos);
66790 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66791 set_fs(fs);
66792 diff --git a/kernel/audit.c b/kernel/audit.c
66793 index 40414e9..c920b72 100644
66794 --- a/kernel/audit.c
66795 +++ b/kernel/audit.c
66796 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
66797 3) suppressed due to audit_rate_limit
66798 4) suppressed due to audit_backlog_limit
66799 */
66800 -static atomic_t audit_lost = ATOMIC_INIT(0);
66801 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66802
66803 /* The netlink socket. */
66804 static struct sock *audit_sock;
66805 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
66806 unsigned long now;
66807 int print;
66808
66809 - atomic_inc(&audit_lost);
66810 + atomic_inc_unchecked(&audit_lost);
66811
66812 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66813
66814 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
66815 printk(KERN_WARNING
66816 "audit: audit_lost=%d audit_rate_limit=%d "
66817 "audit_backlog_limit=%d\n",
66818 - atomic_read(&audit_lost),
66819 + atomic_read_unchecked(&audit_lost),
66820 audit_rate_limit,
66821 audit_backlog_limit);
66822 audit_panic(message);
66823 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66824 status_set.pid = audit_pid;
66825 status_set.rate_limit = audit_rate_limit;
66826 status_set.backlog_limit = audit_backlog_limit;
66827 - status_set.lost = atomic_read(&audit_lost);
66828 + status_set.lost = atomic_read_unchecked(&audit_lost);
66829 status_set.backlog = skb_queue_len(&audit_skb_queue);
66830 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
66831 &status_set, sizeof(status_set));
66832 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66833 index 2f186ed..afb42c2 100644
66834 --- a/kernel/auditsc.c
66835 +++ b/kernel/auditsc.c
66836 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66837 }
66838
66839 /* global counter which is incremented every time something logs in */
66840 -static atomic_t session_id = ATOMIC_INIT(0);
66841 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66842
66843 /**
66844 * audit_set_loginuid - set current task's audit_context loginuid
66845 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
66846 return -EPERM;
66847 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66848
66849 - sessionid = atomic_inc_return(&session_id);
66850 + sessionid = atomic_inc_return_unchecked(&session_id);
66851 if (context && context->in_syscall) {
66852 struct audit_buffer *ab;
66853
66854 diff --git a/kernel/capability.c b/kernel/capability.c
66855 index 493d972..ea17248 100644
66856 --- a/kernel/capability.c
66857 +++ b/kernel/capability.c
66858 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66859 * before modification is attempted and the application
66860 * fails.
66861 */
66862 + if (tocopy > ARRAY_SIZE(kdata))
66863 + return -EFAULT;
66864 +
66865 if (copy_to_user(dataptr, kdata, tocopy
66866 * sizeof(struct __user_cap_data_struct))) {
66867 return -EFAULT;
66868 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66869 int ret;
66870
66871 rcu_read_lock();
66872 - ret = security_capable(__task_cred(t), ns, cap);
66873 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66874 + gr_task_is_capable(t, __task_cred(t), cap);
66875 rcu_read_unlock();
66876
66877 - return (ret == 0);
66878 + return ret;
66879 }
66880
66881 /**
66882 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66883 int ret;
66884
66885 rcu_read_lock();
66886 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66887 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66888 rcu_read_unlock();
66889
66890 - return (ret == 0);
66891 + return ret;
66892 }
66893
66894 /**
66895 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66896 BUG();
66897 }
66898
66899 - if (security_capable(current_cred(), ns, cap) == 0) {
66900 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66901 current->flags |= PF_SUPERPRIV;
66902 return true;
66903 }
66904 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66905 }
66906 EXPORT_SYMBOL(ns_capable);
66907
66908 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66909 +{
66910 + if (unlikely(!cap_valid(cap))) {
66911 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66912 + BUG();
66913 + }
66914 +
66915 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66916 + current->flags |= PF_SUPERPRIV;
66917 + return true;
66918 + }
66919 + return false;
66920 +}
66921 +EXPORT_SYMBOL(ns_capable_nolog);
66922 +
66923 /**
66924 * capable - Determine if the current task has a superior capability in effect
66925 * @cap: The capability to be tested for
66926 @@ -408,6 +427,12 @@ bool capable(int cap)
66927 }
66928 EXPORT_SYMBOL(capable);
66929
66930 +bool capable_nolog(int cap)
66931 +{
66932 + return ns_capable_nolog(&init_user_ns, cap);
66933 +}
66934 +EXPORT_SYMBOL(capable_nolog);
66935 +
66936 /**
66937 * nsown_capable - Check superior capability to one's own user_ns
66938 * @cap: The capability in question
66939 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66940
66941 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66942 }
66943 +
66944 +bool inode_capable_nolog(const struct inode *inode, int cap)
66945 +{
66946 + struct user_namespace *ns = current_user_ns();
66947 +
66948 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66949 +}
66950 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66951 index f24f724..0612ec45 100644
66952 --- a/kernel/cgroup.c
66953 +++ b/kernel/cgroup.c
66954 @@ -5518,7 +5518,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66955 struct css_set *cg = link->cg;
66956 struct task_struct *task;
66957 int count = 0;
66958 - seq_printf(seq, "css_set %p\n", cg);
66959 + seq_printf(seq, "css_set %pK\n", cg);
66960 list_for_each_entry(task, &cg->tasks, cg_list) {
66961 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66962 seq_puts(seq, " ...\n");
66963 diff --git a/kernel/compat.c b/kernel/compat.c
66964 index c28a306..b4d0cf3 100644
66965 --- a/kernel/compat.c
66966 +++ b/kernel/compat.c
66967 @@ -13,6 +13,7 @@
66968
66969 #include <linux/linkage.h>
66970 #include <linux/compat.h>
66971 +#include <linux/module.h>
66972 #include <linux/errno.h>
66973 #include <linux/time.h>
66974 #include <linux/signal.h>
66975 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66976 mm_segment_t oldfs;
66977 long ret;
66978
66979 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66980 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66981 oldfs = get_fs();
66982 set_fs(KERNEL_DS);
66983 ret = hrtimer_nanosleep_restart(restart);
66984 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66985 oldfs = get_fs();
66986 set_fs(KERNEL_DS);
66987 ret = hrtimer_nanosleep(&tu,
66988 - rmtp ? (struct timespec __user *)&rmt : NULL,
66989 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66990 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66991 set_fs(oldfs);
66992
66993 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66994 mm_segment_t old_fs = get_fs();
66995
66996 set_fs(KERNEL_DS);
66997 - ret = sys_sigpending((old_sigset_t __user *) &s);
66998 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66999 set_fs(old_fs);
67000 if (ret == 0)
67001 ret = put_user(s, set);
67002 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
67003 mm_segment_t old_fs = get_fs();
67004
67005 set_fs(KERNEL_DS);
67006 - ret = sys_old_getrlimit(resource, &r);
67007 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
67008 set_fs(old_fs);
67009
67010 if (!ret) {
67011 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
67012 mm_segment_t old_fs = get_fs();
67013
67014 set_fs(KERNEL_DS);
67015 - ret = sys_getrusage(who, (struct rusage __user *) &r);
67016 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
67017 set_fs(old_fs);
67018
67019 if (ret)
67020 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
67021 set_fs (KERNEL_DS);
67022 ret = sys_wait4(pid,
67023 (stat_addr ?
67024 - (unsigned int __user *) &status : NULL),
67025 - options, (struct rusage __user *) &r);
67026 + (unsigned int __force_user *) &status : NULL),
67027 + options, (struct rusage __force_user *) &r);
67028 set_fs (old_fs);
67029
67030 if (ret > 0) {
67031 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
67032 memset(&info, 0, sizeof(info));
67033
67034 set_fs(KERNEL_DS);
67035 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
67036 - uru ? (struct rusage __user *)&ru : NULL);
67037 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
67038 + uru ? (struct rusage __force_user *)&ru : NULL);
67039 set_fs(old_fs);
67040
67041 if ((ret < 0) || (info.si_signo == 0))
67042 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
67043 oldfs = get_fs();
67044 set_fs(KERNEL_DS);
67045 err = sys_timer_settime(timer_id, flags,
67046 - (struct itimerspec __user *) &newts,
67047 - (struct itimerspec __user *) &oldts);
67048 + (struct itimerspec __force_user *) &newts,
67049 + (struct itimerspec __force_user *) &oldts);
67050 set_fs(oldfs);
67051 if (!err && old && put_compat_itimerspec(old, &oldts))
67052 return -EFAULT;
67053 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
67054 oldfs = get_fs();
67055 set_fs(KERNEL_DS);
67056 err = sys_timer_gettime(timer_id,
67057 - (struct itimerspec __user *) &ts);
67058 + (struct itimerspec __force_user *) &ts);
67059 set_fs(oldfs);
67060 if (!err && put_compat_itimerspec(setting, &ts))
67061 return -EFAULT;
67062 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
67063 oldfs = get_fs();
67064 set_fs(KERNEL_DS);
67065 err = sys_clock_settime(which_clock,
67066 - (struct timespec __user *) &ts);
67067 + (struct timespec __force_user *) &ts);
67068 set_fs(oldfs);
67069 return err;
67070 }
67071 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
67072 oldfs = get_fs();
67073 set_fs(KERNEL_DS);
67074 err = sys_clock_gettime(which_clock,
67075 - (struct timespec __user *) &ts);
67076 + (struct timespec __force_user *) &ts);
67077 set_fs(oldfs);
67078 if (!err && put_compat_timespec(&ts, tp))
67079 return -EFAULT;
67080 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
67081
67082 oldfs = get_fs();
67083 set_fs(KERNEL_DS);
67084 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
67085 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
67086 set_fs(oldfs);
67087
67088 err = compat_put_timex(utp, &txc);
67089 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
67090 oldfs = get_fs();
67091 set_fs(KERNEL_DS);
67092 err = sys_clock_getres(which_clock,
67093 - (struct timespec __user *) &ts);
67094 + (struct timespec __force_user *) &ts);
67095 set_fs(oldfs);
67096 if (!err && tp && put_compat_timespec(&ts, tp))
67097 return -EFAULT;
67098 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
67099 long err;
67100 mm_segment_t oldfs;
67101 struct timespec tu;
67102 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
67103 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
67104
67105 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
67106 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
67107 oldfs = get_fs();
67108 set_fs(KERNEL_DS);
67109 err = clock_nanosleep_restart(restart);
67110 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
67111 oldfs = get_fs();
67112 set_fs(KERNEL_DS);
67113 err = sys_clock_nanosleep(which_clock, flags,
67114 - (struct timespec __user *) &in,
67115 - (struct timespec __user *) &out);
67116 + (struct timespec __force_user *) &in,
67117 + (struct timespec __force_user *) &out);
67118 set_fs(oldfs);
67119
67120 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
67121 diff --git a/kernel/configs.c b/kernel/configs.c
67122 index 42e8fa0..9e7406b 100644
67123 --- a/kernel/configs.c
67124 +++ b/kernel/configs.c
67125 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
67126 struct proc_dir_entry *entry;
67127
67128 /* create the current config file */
67129 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67130 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
67131 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
67132 + &ikconfig_file_ops);
67133 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67134 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
67135 + &ikconfig_file_ops);
67136 +#endif
67137 +#else
67138 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
67139 &ikconfig_file_ops);
67140 +#endif
67141 +
67142 if (!entry)
67143 return -ENOMEM;
67144
67145 diff --git a/kernel/cred.c b/kernel/cred.c
67146 index 48cea3d..3476734 100644
67147 --- a/kernel/cred.c
67148 +++ b/kernel/cred.c
67149 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
67150 validate_creds(cred);
67151 alter_cred_subscribers(cred, -1);
67152 put_cred(cred);
67153 +
67154 +#ifdef CONFIG_GRKERNSEC_SETXID
67155 + cred = (struct cred *) tsk->delayed_cred;
67156 + if (cred != NULL) {
67157 + tsk->delayed_cred = NULL;
67158 + validate_creds(cred);
67159 + alter_cred_subscribers(cred, -1);
67160 + put_cred(cred);
67161 + }
67162 +#endif
67163 }
67164
67165 /**
67166 @@ -469,7 +479,7 @@ error_put:
67167 * Always returns 0 thus allowing this function to be tail-called at the end
67168 * of, say, sys_setgid().
67169 */
67170 -int commit_creds(struct cred *new)
67171 +static int __commit_creds(struct cred *new)
67172 {
67173 struct task_struct *task = current;
67174 const struct cred *old = task->real_cred;
67175 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
67176
67177 get_cred(new); /* we will require a ref for the subj creds too */
67178
67179 + gr_set_role_label(task, new->uid, new->gid);
67180 +
67181 /* dumpability changes */
67182 if (!uid_eq(old->euid, new->euid) ||
67183 !gid_eq(old->egid, new->egid) ||
67184 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
67185 put_cred(old);
67186 return 0;
67187 }
67188 +#ifdef CONFIG_GRKERNSEC_SETXID
67189 +extern int set_user(struct cred *new);
67190 +
67191 +void gr_delayed_cred_worker(void)
67192 +{
67193 + const struct cred *new = current->delayed_cred;
67194 + struct cred *ncred;
67195 +
67196 + current->delayed_cred = NULL;
67197 +
67198 + if (current_uid() && new != NULL) {
67199 + // from doing get_cred on it when queueing this
67200 + put_cred(new);
67201 + return;
67202 + } else if (new == NULL)
67203 + return;
67204 +
67205 + ncred = prepare_creds();
67206 + if (!ncred)
67207 + goto die;
67208 + // uids
67209 + ncred->uid = new->uid;
67210 + ncred->euid = new->euid;
67211 + ncred->suid = new->suid;
67212 + ncred->fsuid = new->fsuid;
67213 + // gids
67214 + ncred->gid = new->gid;
67215 + ncred->egid = new->egid;
67216 + ncred->sgid = new->sgid;
67217 + ncred->fsgid = new->fsgid;
67218 + // groups
67219 + if (set_groups(ncred, new->group_info) < 0) {
67220 + abort_creds(ncred);
67221 + goto die;
67222 + }
67223 + // caps
67224 + ncred->securebits = new->securebits;
67225 + ncred->cap_inheritable = new->cap_inheritable;
67226 + ncred->cap_permitted = new->cap_permitted;
67227 + ncred->cap_effective = new->cap_effective;
67228 + ncred->cap_bset = new->cap_bset;
67229 +
67230 + if (set_user(ncred)) {
67231 + abort_creds(ncred);
67232 + goto die;
67233 + }
67234 +
67235 + // from doing get_cred on it when queueing this
67236 + put_cred(new);
67237 +
67238 + __commit_creds(ncred);
67239 + return;
67240 +die:
67241 + // from doing get_cred on it when queueing this
67242 + put_cred(new);
67243 + do_group_exit(SIGKILL);
67244 +}
67245 +#endif
67246 +
67247 +int commit_creds(struct cred *new)
67248 +{
67249 +#ifdef CONFIG_GRKERNSEC_SETXID
67250 + int ret;
67251 + int schedule_it = 0;
67252 + struct task_struct *t;
67253 +
67254 + /* we won't get called with tasklist_lock held for writing
67255 + and interrupts disabled as the cred struct in that case is
67256 + init_cred
67257 + */
67258 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67259 + !current_uid() && new->uid) {
67260 + schedule_it = 1;
67261 + }
67262 + ret = __commit_creds(new);
67263 + if (schedule_it) {
67264 + rcu_read_lock();
67265 + read_lock(&tasklist_lock);
67266 + for (t = next_thread(current); t != current;
67267 + t = next_thread(t)) {
67268 + if (t->delayed_cred == NULL) {
67269 + t->delayed_cred = get_cred(new);
67270 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67271 + set_tsk_need_resched(t);
67272 + }
67273 + }
67274 + read_unlock(&tasklist_lock);
67275 + rcu_read_unlock();
67276 + }
67277 + return ret;
67278 +#else
67279 + return __commit_creds(new);
67280 +#endif
67281 +}
67282 +
67283 EXPORT_SYMBOL(commit_creds);
67284
67285 /**
67286 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67287 index 9a61738..c5c8f3a 100644
67288 --- a/kernel/debug/debug_core.c
67289 +++ b/kernel/debug/debug_core.c
67290 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67291 */
67292 static atomic_t masters_in_kgdb;
67293 static atomic_t slaves_in_kgdb;
67294 -static atomic_t kgdb_break_tasklet_var;
67295 +static atomic_unchecked_t kgdb_break_tasklet_var;
67296 atomic_t kgdb_setting_breakpoint;
67297
67298 struct task_struct *kgdb_usethread;
67299 @@ -132,7 +132,7 @@ int kgdb_single_step;
67300 static pid_t kgdb_sstep_pid;
67301
67302 /* to keep track of the CPU which is doing the single stepping*/
67303 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67304 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67305
67306 /*
67307 * If you are debugging a problem where roundup (the collection of
67308 @@ -540,7 +540,7 @@ return_normal:
67309 * kernel will only try for the value of sstep_tries before
67310 * giving up and continuing on.
67311 */
67312 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67313 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67314 (kgdb_info[cpu].task &&
67315 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67316 atomic_set(&kgdb_active, -1);
67317 @@ -634,8 +634,8 @@ cpu_master_loop:
67318 }
67319
67320 kgdb_restore:
67321 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67322 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67323 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67324 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67325 if (kgdb_info[sstep_cpu].task)
67326 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67327 else
67328 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
67329 static void kgdb_tasklet_bpt(unsigned long ing)
67330 {
67331 kgdb_breakpoint();
67332 - atomic_set(&kgdb_break_tasklet_var, 0);
67333 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67334 }
67335
67336 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67337
67338 void kgdb_schedule_breakpoint(void)
67339 {
67340 - if (atomic_read(&kgdb_break_tasklet_var) ||
67341 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67342 atomic_read(&kgdb_active) != -1 ||
67343 atomic_read(&kgdb_setting_breakpoint))
67344 return;
67345 - atomic_inc(&kgdb_break_tasklet_var);
67346 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67347 tasklet_schedule(&kgdb_tasklet_breakpoint);
67348 }
67349 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67350 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67351 index 4d5f8d5..4743f33 100644
67352 --- a/kernel/debug/kdb/kdb_main.c
67353 +++ b/kernel/debug/kdb/kdb_main.c
67354 @@ -1972,7 +1972,7 @@ static int kdb_lsmod(int argc, const char **argv)
67355 list_for_each_entry(mod, kdb_modules, list) {
67356
67357 kdb_printf("%-20s%8u 0x%p ", mod->name,
67358 - mod->core_size, (void *)mod);
67359 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67360 #ifdef CONFIG_MODULE_UNLOAD
67361 kdb_printf("%4ld ", module_refcount(mod));
67362 #endif
67363 @@ -1982,7 +1982,7 @@ static int kdb_lsmod(int argc, const char **argv)
67364 kdb_printf(" (Loading)");
67365 else
67366 kdb_printf(" (Live)");
67367 - kdb_printf(" 0x%p", mod->module_core);
67368 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67369
67370 #ifdef CONFIG_MODULE_UNLOAD
67371 {
67372 diff --git a/kernel/events/core.c b/kernel/events/core.c
67373 index dbccf83..8c66482 100644
67374 --- a/kernel/events/core.c
67375 +++ b/kernel/events/core.c
67376 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67377 return 0;
67378 }
67379
67380 -static atomic64_t perf_event_id;
67381 +static atomic64_unchecked_t perf_event_id;
67382
67383 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67384 enum event_type_t event_type);
67385 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
67386
67387 static inline u64 perf_event_count(struct perf_event *event)
67388 {
67389 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67390 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67391 }
67392
67393 static u64 perf_event_read(struct perf_event *event)
67394 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67395 mutex_lock(&event->child_mutex);
67396 total += perf_event_read(event);
67397 *enabled += event->total_time_enabled +
67398 - atomic64_read(&event->child_total_time_enabled);
67399 + atomic64_read_unchecked(&event->child_total_time_enabled);
67400 *running += event->total_time_running +
67401 - atomic64_read(&event->child_total_time_running);
67402 + atomic64_read_unchecked(&event->child_total_time_running);
67403
67404 list_for_each_entry(child, &event->child_list, child_list) {
67405 total += perf_event_read(child);
67406 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
67407 userpg->offset -= local64_read(&event->hw.prev_count);
67408
67409 userpg->time_enabled = enabled +
67410 - atomic64_read(&event->child_total_time_enabled);
67411 + atomic64_read_unchecked(&event->child_total_time_enabled);
67412
67413 userpg->time_running = running +
67414 - atomic64_read(&event->child_total_time_running);
67415 + atomic64_read_unchecked(&event->child_total_time_running);
67416
67417 arch_perf_update_userpage(userpg, now);
67418
67419 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67420 values[n++] = perf_event_count(event);
67421 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67422 values[n++] = enabled +
67423 - atomic64_read(&event->child_total_time_enabled);
67424 + atomic64_read_unchecked(&event->child_total_time_enabled);
67425 }
67426 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67427 values[n++] = running +
67428 - atomic64_read(&event->child_total_time_running);
67429 + atomic64_read_unchecked(&event->child_total_time_running);
67430 }
67431 if (read_format & PERF_FORMAT_ID)
67432 values[n++] = primary_event_id(event);
67433 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67434 * need to add enough zero bytes after the string to handle
67435 * the 64bit alignment we do later.
67436 */
67437 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67438 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67439 if (!buf) {
67440 name = strncpy(tmp, "//enomem", sizeof(tmp));
67441 goto got_name;
67442 }
67443 - name = d_path(&file->f_path, buf, PATH_MAX);
67444 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67445 if (IS_ERR(name)) {
67446 name = strncpy(tmp, "//toolong", sizeof(tmp));
67447 goto got_name;
67448 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67449 event->parent = parent_event;
67450
67451 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67452 - event->id = atomic64_inc_return(&perf_event_id);
67453 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67454
67455 event->state = PERF_EVENT_STATE_INACTIVE;
67456
67457 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
67458 /*
67459 * Add back the child's count to the parent's count:
67460 */
67461 - atomic64_add(child_val, &parent_event->child_count);
67462 - atomic64_add(child_event->total_time_enabled,
67463 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67464 + atomic64_add_unchecked(child_event->total_time_enabled,
67465 &parent_event->child_total_time_enabled);
67466 - atomic64_add(child_event->total_time_running,
67467 + atomic64_add_unchecked(child_event->total_time_running,
67468 &parent_event->child_total_time_running);
67469
67470 /*
67471 diff --git a/kernel/exit.c b/kernel/exit.c
67472 index 346616c..a86ec83 100644
67473 --- a/kernel/exit.c
67474 +++ b/kernel/exit.c
67475 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
67476 struct task_struct *leader;
67477 int zap_leader;
67478 repeat:
67479 +#ifdef CONFIG_NET
67480 + gr_del_task_from_ip_table(p);
67481 +#endif
67482 +
67483 /* don't need to get the RCU readlock here - the process is dead and
67484 * can't be modifying its own credentials. But shut RCU-lockdep up */
67485 rcu_read_lock();
67486 @@ -394,7 +398,7 @@ int allow_signal(int sig)
67487 * know it'll be handled, so that they don't get converted to
67488 * SIGKILL or just silently dropped.
67489 */
67490 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67491 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67492 recalc_sigpending();
67493 spin_unlock_irq(&current->sighand->siglock);
67494 return 0;
67495 @@ -430,6 +434,8 @@ void daemonize(const char *name, ...)
67496 vsnprintf(current->comm, sizeof(current->comm), name, args);
67497 va_end(args);
67498
67499 + gr_set_kernel_label(current);
67500 +
67501 /*
67502 * If we were started as result of loading a module, close all of the
67503 * user space pages. We don't need them, and if we didn't close them
67504 @@ -812,6 +818,8 @@ void do_exit(long code)
67505 struct task_struct *tsk = current;
67506 int group_dead;
67507
67508 + set_fs(USER_DS);
67509 +
67510 profile_task_exit(tsk);
67511
67512 WARN_ON(blk_needs_flush_plug(tsk));
67513 @@ -828,7 +836,6 @@ void do_exit(long code)
67514 * mm_release()->clear_child_tid() from writing to a user-controlled
67515 * kernel address.
67516 */
67517 - set_fs(USER_DS);
67518
67519 ptrace_event(PTRACE_EVENT_EXIT, code);
67520
67521 @@ -887,6 +894,9 @@ void do_exit(long code)
67522 tsk->exit_code = code;
67523 taskstats_exit(tsk, group_dead);
67524
67525 + gr_acl_handle_psacct(tsk, code);
67526 + gr_acl_handle_exit();
67527 +
67528 exit_mm(tsk);
67529
67530 if (group_dead)
67531 @@ -1007,7 +1017,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67532 * Take down every thread in the group. This is called by fatal signals
67533 * as well as by sys_exit_group (below).
67534 */
67535 -void
67536 +__noreturn void
67537 do_group_exit(int exit_code)
67538 {
67539 struct signal_struct *sig = current->signal;
67540 diff --git a/kernel/fork.c b/kernel/fork.c
67541 index 8b20ab7..58f2e45 100644
67542 --- a/kernel/fork.c
67543 +++ b/kernel/fork.c
67544 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67545 *stackend = STACK_END_MAGIC; /* for overflow detection */
67546
67547 #ifdef CONFIG_CC_STACKPROTECTOR
67548 - tsk->stack_canary = get_random_int();
67549 + tsk->stack_canary = pax_get_random_long();
67550 #endif
67551
67552 /*
67553 @@ -344,13 +344,81 @@ free_tsk:
67554 }
67555
67556 #ifdef CONFIG_MMU
67557 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67558 +{
67559 + struct vm_area_struct *tmp;
67560 + unsigned long charge;
67561 + struct mempolicy *pol;
67562 + struct file *file;
67563 +
67564 + charge = 0;
67565 + if (mpnt->vm_flags & VM_ACCOUNT) {
67566 + unsigned long len = vma_pages(mpnt);
67567 +
67568 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67569 + goto fail_nomem;
67570 + charge = len;
67571 + }
67572 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67573 + if (!tmp)
67574 + goto fail_nomem;
67575 + *tmp = *mpnt;
67576 + tmp->vm_mm = mm;
67577 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67578 + pol = mpol_dup(vma_policy(mpnt));
67579 + if (IS_ERR(pol))
67580 + goto fail_nomem_policy;
67581 + vma_set_policy(tmp, pol);
67582 + if (anon_vma_fork(tmp, mpnt))
67583 + goto fail_nomem_anon_vma_fork;
67584 + tmp->vm_flags &= ~VM_LOCKED;
67585 + tmp->vm_next = tmp->vm_prev = NULL;
67586 + tmp->vm_mirror = NULL;
67587 + file = tmp->vm_file;
67588 + if (file) {
67589 + struct inode *inode = file->f_path.dentry->d_inode;
67590 + struct address_space *mapping = file->f_mapping;
67591 +
67592 + get_file(file);
67593 + if (tmp->vm_flags & VM_DENYWRITE)
67594 + atomic_dec(&inode->i_writecount);
67595 + mutex_lock(&mapping->i_mmap_mutex);
67596 + if (tmp->vm_flags & VM_SHARED)
67597 + mapping->i_mmap_writable++;
67598 + flush_dcache_mmap_lock(mapping);
67599 + /* insert tmp into the share list, just after mpnt */
67600 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
67601 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
67602 + else
67603 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
67604 + flush_dcache_mmap_unlock(mapping);
67605 + mutex_unlock(&mapping->i_mmap_mutex);
67606 + }
67607 +
67608 + /*
67609 + * Clear hugetlb-related page reserves for children. This only
67610 + * affects MAP_PRIVATE mappings. Faults generated by the child
67611 + * are not guaranteed to succeed, even if read-only
67612 + */
67613 + if (is_vm_hugetlb_page(tmp))
67614 + reset_vma_resv_huge_pages(tmp);
67615 +
67616 + return tmp;
67617 +
67618 +fail_nomem_anon_vma_fork:
67619 + mpol_put(pol);
67620 +fail_nomem_policy:
67621 + kmem_cache_free(vm_area_cachep, tmp);
67622 +fail_nomem:
67623 + vm_unacct_memory(charge);
67624 + return NULL;
67625 +}
67626 +
67627 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67628 {
67629 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67630 struct rb_node **rb_link, *rb_parent;
67631 int retval;
67632 - unsigned long charge;
67633 - struct mempolicy *pol;
67634
67635 down_write(&oldmm->mmap_sem);
67636 flush_cache_dup_mm(oldmm);
67637 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67638 mm->locked_vm = 0;
67639 mm->mmap = NULL;
67640 mm->mmap_cache = NULL;
67641 - mm->free_area_cache = oldmm->mmap_base;
67642 - mm->cached_hole_size = ~0UL;
67643 + mm->free_area_cache = oldmm->free_area_cache;
67644 + mm->cached_hole_size = oldmm->cached_hole_size;
67645 mm->map_count = 0;
67646 cpumask_clear(mm_cpumask(mm));
67647 mm->mm_rb = RB_ROOT;
67648 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67649
67650 prev = NULL;
67651 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67652 - struct file *file;
67653 -
67654 if (mpnt->vm_flags & VM_DONTCOPY) {
67655 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67656 -vma_pages(mpnt));
67657 continue;
67658 }
67659 - charge = 0;
67660 - if (mpnt->vm_flags & VM_ACCOUNT) {
67661 - unsigned long len = vma_pages(mpnt);
67662 -
67663 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67664 - goto fail_nomem;
67665 - charge = len;
67666 - }
67667 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67668 - if (!tmp)
67669 - goto fail_nomem;
67670 - *tmp = *mpnt;
67671 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67672 - pol = mpol_dup(vma_policy(mpnt));
67673 - retval = PTR_ERR(pol);
67674 - if (IS_ERR(pol))
67675 - goto fail_nomem_policy;
67676 - vma_set_policy(tmp, pol);
67677 - tmp->vm_mm = mm;
67678 - if (anon_vma_fork(tmp, mpnt))
67679 - goto fail_nomem_anon_vma_fork;
67680 - tmp->vm_flags &= ~VM_LOCKED;
67681 - tmp->vm_next = tmp->vm_prev = NULL;
67682 - file = tmp->vm_file;
67683 - if (file) {
67684 - struct inode *inode = file->f_path.dentry->d_inode;
67685 - struct address_space *mapping = file->f_mapping;
67686 -
67687 - get_file(file);
67688 - if (tmp->vm_flags & VM_DENYWRITE)
67689 - atomic_dec(&inode->i_writecount);
67690 - mutex_lock(&mapping->i_mmap_mutex);
67691 - if (tmp->vm_flags & VM_SHARED)
67692 - mapping->i_mmap_writable++;
67693 - flush_dcache_mmap_lock(mapping);
67694 - /* insert tmp into the share list, just after mpnt */
67695 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
67696 - vma_nonlinear_insert(tmp,
67697 - &mapping->i_mmap_nonlinear);
67698 - else
67699 - vma_interval_tree_insert_after(tmp, mpnt,
67700 - &mapping->i_mmap);
67701 - flush_dcache_mmap_unlock(mapping);
67702 - mutex_unlock(&mapping->i_mmap_mutex);
67703 + tmp = dup_vma(mm, oldmm, mpnt);
67704 + if (!tmp) {
67705 + retval = -ENOMEM;
67706 + goto out;
67707 }
67708
67709 /*
67710 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67711 if (retval)
67712 goto out;
67713 }
67714 +
67715 +#ifdef CONFIG_PAX_SEGMEXEC
67716 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67717 + struct vm_area_struct *mpnt_m;
67718 +
67719 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67720 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67721 +
67722 + if (!mpnt->vm_mirror)
67723 + continue;
67724 +
67725 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67726 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67727 + mpnt->vm_mirror = mpnt_m;
67728 + } else {
67729 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67730 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67731 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67732 + mpnt->vm_mirror->vm_mirror = mpnt;
67733 + }
67734 + }
67735 + BUG_ON(mpnt_m);
67736 + }
67737 +#endif
67738 +
67739 /* a new mm has just been created */
67740 arch_dup_mmap(oldmm, mm);
67741 retval = 0;
67742 @@ -470,14 +521,6 @@ out:
67743 flush_tlb_mm(oldmm);
67744 up_write(&oldmm->mmap_sem);
67745 return retval;
67746 -fail_nomem_anon_vma_fork:
67747 - mpol_put(pol);
67748 -fail_nomem_policy:
67749 - kmem_cache_free(vm_area_cachep, tmp);
67750 -fail_nomem:
67751 - retval = -ENOMEM;
67752 - vm_unacct_memory(charge);
67753 - goto out;
67754 }
67755
67756 static inline int mm_alloc_pgd(struct mm_struct *mm)
67757 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67758 return ERR_PTR(err);
67759
67760 mm = get_task_mm(task);
67761 - if (mm && mm != current->mm &&
67762 - !ptrace_may_access(task, mode)) {
67763 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67764 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67765 mmput(mm);
67766 mm = ERR_PTR(-EACCES);
67767 }
67768 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67769 spin_unlock(&fs->lock);
67770 return -EAGAIN;
67771 }
67772 - fs->users++;
67773 + atomic_inc(&fs->users);
67774 spin_unlock(&fs->lock);
67775 return 0;
67776 }
67777 tsk->fs = copy_fs_struct(fs);
67778 if (!tsk->fs)
67779 return -ENOMEM;
67780 + /* Carry through gr_chroot_dentry and is_chrooted instead
67781 + of recomputing it here. Already copied when the task struct
67782 + is duplicated. This allows pivot_root to not be treated as
67783 + a chroot
67784 + */
67785 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67786 +
67787 return 0;
67788 }
67789
67790 @@ -1184,6 +1234,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67791 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67792 #endif
67793 retval = -EAGAIN;
67794 +
67795 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67796 +
67797 if (atomic_read(&p->real_cred->user->processes) >=
67798 task_rlimit(p, RLIMIT_NPROC)) {
67799 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67800 @@ -1402,6 +1455,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67801 /* Need tasklist lock for parent etc handling! */
67802 write_lock_irq(&tasklist_lock);
67803
67804 + /* synchronizes with gr_set_acls() */
67805 + gr_copy_label(p);
67806 +
67807 /* CLONE_PARENT re-uses the old parent */
67808 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67809 p->real_parent = current->real_parent;
67810 @@ -1512,6 +1568,8 @@ bad_fork_cleanup_count:
67811 bad_fork_free:
67812 free_task(p);
67813 fork_out:
67814 + gr_log_forkfail(retval);
67815 +
67816 return ERR_PTR(retval);
67817 }
67818
67819 @@ -1612,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
67820 if (clone_flags & CLONE_PARENT_SETTID)
67821 put_user(nr, parent_tidptr);
67822
67823 + gr_handle_brute_check();
67824 +
67825 if (clone_flags & CLONE_VFORK) {
67826 p->vfork_done = &vfork;
67827 init_completion(&vfork);
67828 @@ -1721,7 +1781,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67829 return 0;
67830
67831 /* don't need lock here; in the worst case we'll do useless copy */
67832 - if (fs->users == 1)
67833 + if (atomic_read(&fs->users) == 1)
67834 return 0;
67835
67836 *new_fsp = copy_fs_struct(fs);
67837 @@ -1810,7 +1870,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67838 fs = current->fs;
67839 spin_lock(&fs->lock);
67840 current->fs = new_fs;
67841 - if (--fs->users)
67842 + gr_set_chroot_entries(current, &current->fs->root);
67843 + if (atomic_dec_return(&fs->users))
67844 new_fs = NULL;
67845 else
67846 new_fs = fs;
67847 diff --git a/kernel/futex.c b/kernel/futex.c
67848 index 19eb089..b8c65ea 100644
67849 --- a/kernel/futex.c
67850 +++ b/kernel/futex.c
67851 @@ -54,6 +54,7 @@
67852 #include <linux/mount.h>
67853 #include <linux/pagemap.h>
67854 #include <linux/syscalls.h>
67855 +#include <linux/ptrace.h>
67856 #include <linux/signal.h>
67857 #include <linux/export.h>
67858 #include <linux/magic.h>
67859 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67860 struct page *page, *page_head;
67861 int err, ro = 0;
67862
67863 +#ifdef CONFIG_PAX_SEGMEXEC
67864 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67865 + return -EFAULT;
67866 +#endif
67867 +
67868 /*
67869 * The futex address must be "naturally" aligned.
67870 */
67871 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
67872 {
67873 u32 curval;
67874 int i;
67875 + mm_segment_t oldfs;
67876
67877 /*
67878 * This will fail and we want it. Some arch implementations do
67879 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
67880 * implementation, the non-functional ones will return
67881 * -ENOSYS.
67882 */
67883 + oldfs = get_fs();
67884 + set_fs(USER_DS);
67885 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67886 futex_cmpxchg_enabled = 1;
67887 + set_fs(oldfs);
67888
67889 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67890 plist_head_init(&futex_queues[i].chain);
67891 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67892 index 9b22d03..6295b62 100644
67893 --- a/kernel/gcov/base.c
67894 +++ b/kernel/gcov/base.c
67895 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67896 }
67897
67898 #ifdef CONFIG_MODULES
67899 -static inline int within(void *addr, void *start, unsigned long size)
67900 -{
67901 - return ((addr >= start) && (addr < start + size));
67902 -}
67903 -
67904 /* Update list and generate events when modules are unloaded. */
67905 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67906 void *data)
67907 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67908 prev = NULL;
67909 /* Remove entries located in module from linked list. */
67910 for (info = gcov_info_head; info; info = info->next) {
67911 - if (within(info, mod->module_core, mod->core_size)) {
67912 + if (within_module_core_rw((unsigned long)info, mod)) {
67913 if (prev)
67914 prev->next = info->next;
67915 else
67916 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67917 index 6db7a5e..25b6648 100644
67918 --- a/kernel/hrtimer.c
67919 +++ b/kernel/hrtimer.c
67920 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67921 local_irq_restore(flags);
67922 }
67923
67924 -static void run_hrtimer_softirq(struct softirq_action *h)
67925 +static void run_hrtimer_softirq(void)
67926 {
67927 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67928
67929 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67930 index 60f48fa..7f3a770 100644
67931 --- a/kernel/jump_label.c
67932 +++ b/kernel/jump_label.c
67933 @@ -13,6 +13,7 @@
67934 #include <linux/sort.h>
67935 #include <linux/err.h>
67936 #include <linux/static_key.h>
67937 +#include <linux/mm.h>
67938
67939 #ifdef HAVE_JUMP_LABEL
67940
67941 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67942
67943 size = (((unsigned long)stop - (unsigned long)start)
67944 / sizeof(struct jump_entry));
67945 + pax_open_kernel();
67946 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67947 + pax_close_kernel();
67948 }
67949
67950 static void jump_label_update(struct static_key *key, int enable);
67951 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67952 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67953 struct jump_entry *iter;
67954
67955 + pax_open_kernel();
67956 for (iter = iter_start; iter < iter_stop; iter++) {
67957 if (within_module_init(iter->code, mod))
67958 iter->code = 0;
67959 }
67960 + pax_close_kernel();
67961 }
67962
67963 static int
67964 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67965 index 2169fee..45c017a 100644
67966 --- a/kernel/kallsyms.c
67967 +++ b/kernel/kallsyms.c
67968 @@ -11,6 +11,9 @@
67969 * Changed the compression method from stem compression to "table lookup"
67970 * compression (see scripts/kallsyms.c for a more complete description)
67971 */
67972 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67973 +#define __INCLUDED_BY_HIDESYM 1
67974 +#endif
67975 #include <linux/kallsyms.h>
67976 #include <linux/module.h>
67977 #include <linux/init.h>
67978 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67979
67980 static inline int is_kernel_inittext(unsigned long addr)
67981 {
67982 + if (system_state != SYSTEM_BOOTING)
67983 + return 0;
67984 +
67985 if (addr >= (unsigned long)_sinittext
67986 && addr <= (unsigned long)_einittext)
67987 return 1;
67988 return 0;
67989 }
67990
67991 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67992 +#ifdef CONFIG_MODULES
67993 +static inline int is_module_text(unsigned long addr)
67994 +{
67995 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67996 + return 1;
67997 +
67998 + addr = ktla_ktva(addr);
67999 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
68000 +}
68001 +#else
68002 +static inline int is_module_text(unsigned long addr)
68003 +{
68004 + return 0;
68005 +}
68006 +#endif
68007 +#endif
68008 +
68009 static inline int is_kernel_text(unsigned long addr)
68010 {
68011 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
68012 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
68013
68014 static inline int is_kernel(unsigned long addr)
68015 {
68016 +
68017 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68018 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
68019 + return 1;
68020 +
68021 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
68022 +#else
68023 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
68024 +#endif
68025 +
68026 return 1;
68027 return in_gate_area_no_mm(addr);
68028 }
68029
68030 static int is_ksym_addr(unsigned long addr)
68031 {
68032 +
68033 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
68034 + if (is_module_text(addr))
68035 + return 0;
68036 +#endif
68037 +
68038 if (all_var)
68039 return is_kernel(addr);
68040
68041 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
68042
68043 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
68044 {
68045 - iter->name[0] = '\0';
68046 iter->nameoff = get_symbol_offset(new_pos);
68047 iter->pos = new_pos;
68048 }
68049 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
68050 {
68051 struct kallsym_iter *iter = m->private;
68052
68053 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68054 + if (current_uid())
68055 + return 0;
68056 +#endif
68057 +
68058 /* Some debugging symbols have no name. Ignore them. */
68059 if (!iter->name[0])
68060 return 0;
68061 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
68062 */
68063 type = iter->exported ? toupper(iter->type) :
68064 tolower(iter->type);
68065 +
68066 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
68067 type, iter->name, iter->module_name);
68068 } else
68069 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
68070 struct kallsym_iter *iter;
68071 int ret;
68072
68073 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
68074 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
68075 if (!iter)
68076 return -ENOMEM;
68077 reset_iter(iter, 0);
68078 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
68079 index 30b7b22..c726387 100644
68080 --- a/kernel/kcmp.c
68081 +++ b/kernel/kcmp.c
68082 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
68083 struct task_struct *task1, *task2;
68084 int ret;
68085
68086 +#ifdef CONFIG_GRKERNSEC
68087 + return -ENOSYS;
68088 +#endif
68089 +
68090 rcu_read_lock();
68091
68092 /*
68093 diff --git a/kernel/kexec.c b/kernel/kexec.c
68094 index 5e4bd78..00c5b91 100644
68095 --- a/kernel/kexec.c
68096 +++ b/kernel/kexec.c
68097 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
68098 unsigned long flags)
68099 {
68100 struct compat_kexec_segment in;
68101 - struct kexec_segment out, __user *ksegments;
68102 + struct kexec_segment out;
68103 + struct kexec_segment __user *ksegments;
68104 unsigned long i, result;
68105
68106 /* Don't allow clients that don't understand the native
68107 diff --git a/kernel/kmod.c b/kernel/kmod.c
68108 index 1c317e3..4a92a55 100644
68109 --- a/kernel/kmod.c
68110 +++ b/kernel/kmod.c
68111 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
68112 kfree(info->argv);
68113 }
68114
68115 -static int call_modprobe(char *module_name, int wait)
68116 +static int call_modprobe(char *module_name, char *module_param, int wait)
68117 {
68118 static char *envp[] = {
68119 "HOME=/",
68120 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
68121 NULL
68122 };
68123
68124 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
68125 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
68126 if (!argv)
68127 goto out;
68128
68129 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
68130 argv[1] = "-q";
68131 argv[2] = "--";
68132 argv[3] = module_name; /* check free_modprobe_argv() */
68133 - argv[4] = NULL;
68134 + argv[4] = module_param;
68135 + argv[5] = NULL;
68136
68137 return call_usermodehelper_fns(modprobe_path, argv, envp,
68138 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
68139 @@ -120,9 +121,8 @@ out:
68140 * If module auto-loading support is disabled then this function
68141 * becomes a no-operation.
68142 */
68143 -int __request_module(bool wait, const char *fmt, ...)
68144 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
68145 {
68146 - va_list args;
68147 char module_name[MODULE_NAME_LEN];
68148 unsigned int max_modprobes;
68149 int ret;
68150 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
68151 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
68152 static int kmod_loop_msg;
68153
68154 - va_start(args, fmt);
68155 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
68156 - va_end(args);
68157 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
68158 if (ret >= MODULE_NAME_LEN)
68159 return -ENAMETOOLONG;
68160
68161 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
68162 if (ret)
68163 return ret;
68164
68165 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68166 + if (!current_uid()) {
68167 + /* hack to workaround consolekit/udisks stupidity */
68168 + read_lock(&tasklist_lock);
68169 + if (!strcmp(current->comm, "mount") &&
68170 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
68171 + read_unlock(&tasklist_lock);
68172 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
68173 + return -EPERM;
68174 + }
68175 + read_unlock(&tasklist_lock);
68176 + }
68177 +#endif
68178 +
68179 /* If modprobe needs a service that is in a module, we get a recursive
68180 * loop. Limit the number of running kmod threads to max_threads/2 or
68181 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
68182 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
68183
68184 trace_module_request(module_name, wait, _RET_IP_);
68185
68186 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68187 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68188
68189 atomic_dec(&kmod_concurrent);
68190 return ret;
68191 }
68192 +
68193 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68194 +{
68195 + va_list args;
68196 + int ret;
68197 +
68198 + va_start(args, fmt);
68199 + ret = ____request_module(wait, module_param, fmt, args);
68200 + va_end(args);
68201 +
68202 + return ret;
68203 +}
68204 +
68205 +int __request_module(bool wait, const char *fmt, ...)
68206 +{
68207 + va_list args;
68208 + int ret;
68209 +
68210 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68211 + if (current_uid()) {
68212 + char module_param[MODULE_NAME_LEN];
68213 +
68214 + memset(module_param, 0, sizeof(module_param));
68215 +
68216 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68217 +
68218 + va_start(args, fmt);
68219 + ret = ____request_module(wait, module_param, fmt, args);
68220 + va_end(args);
68221 +
68222 + return ret;
68223 + }
68224 +#endif
68225 +
68226 + va_start(args, fmt);
68227 + ret = ____request_module(wait, NULL, fmt, args);
68228 + va_end(args);
68229 +
68230 + return ret;
68231 +}
68232 +
68233 EXPORT_SYMBOL(__request_module);
68234 #endif /* CONFIG_MODULES */
68235
68236 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
68237 *
68238 * Thus the __user pointer cast is valid here.
68239 */
68240 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68241 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68242
68243 /*
68244 * If ret is 0, either ____call_usermodehelper failed and the
68245 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68246 index 098f396..fe85ff1 100644
68247 --- a/kernel/kprobes.c
68248 +++ b/kernel/kprobes.c
68249 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68250 * kernel image and loaded module images reside. This is required
68251 * so x86_64 can correctly handle the %rip-relative fixups.
68252 */
68253 - kip->insns = module_alloc(PAGE_SIZE);
68254 + kip->insns = module_alloc_exec(PAGE_SIZE);
68255 if (!kip->insns) {
68256 kfree(kip);
68257 return NULL;
68258 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68259 */
68260 if (!list_is_singular(&kip->list)) {
68261 list_del(&kip->list);
68262 - module_free(NULL, kip->insns);
68263 + module_free_exec(NULL, kip->insns);
68264 kfree(kip);
68265 }
68266 return 1;
68267 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
68268 {
68269 int i, err = 0;
68270 unsigned long offset = 0, size = 0;
68271 - char *modname, namebuf[128];
68272 + char *modname, namebuf[KSYM_NAME_LEN];
68273 const char *symbol_name;
68274 void *addr;
68275 struct kprobe_blackpoint *kb;
68276 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68277 kprobe_type = "k";
68278
68279 if (sym)
68280 - seq_printf(pi, "%p %s %s+0x%x %s ",
68281 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68282 p->addr, kprobe_type, sym, offset,
68283 (modname ? modname : " "));
68284 else
68285 - seq_printf(pi, "%p %s %p ",
68286 + seq_printf(pi, "%pK %s %pK ",
68287 p->addr, kprobe_type, p->addr);
68288
68289 if (!pp)
68290 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68291 const char *sym = NULL;
68292 unsigned int i = *(loff_t *) v;
68293 unsigned long offset = 0;
68294 - char *modname, namebuf[128];
68295 + char *modname, namebuf[KSYM_NAME_LEN];
68296
68297 head = &kprobe_table[i];
68298 preempt_disable();
68299 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68300 index 4e316e1..5501eef 100644
68301 --- a/kernel/ksysfs.c
68302 +++ b/kernel/ksysfs.c
68303 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68304 {
68305 if (count+1 > UEVENT_HELPER_PATH_LEN)
68306 return -ENOENT;
68307 + if (!capable(CAP_SYS_ADMIN))
68308 + return -EPERM;
68309 memcpy(uevent_helper, buf, count);
68310 uevent_helper[count] = '\0';
68311 if (count && uevent_helper[count-1] == '\n')
68312 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68313 index 7981e5b..7f2105c 100644
68314 --- a/kernel/lockdep.c
68315 +++ b/kernel/lockdep.c
68316 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68317 end = (unsigned long) &_end,
68318 addr = (unsigned long) obj;
68319
68320 +#ifdef CONFIG_PAX_KERNEXEC
68321 + start = ktla_ktva(start);
68322 +#endif
68323 +
68324 /*
68325 * static variable?
68326 */
68327 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68328 if (!static_obj(lock->key)) {
68329 debug_locks_off();
68330 printk("INFO: trying to register non-static key.\n");
68331 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68332 printk("the code is fine but needs lockdep annotation.\n");
68333 printk("turning off the locking correctness validator.\n");
68334 dump_stack();
68335 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68336 if (!class)
68337 return 0;
68338 }
68339 - atomic_inc((atomic_t *)&class->ops);
68340 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68341 if (very_verbose(class)) {
68342 printk("\nacquire class [%p] %s", class->key, class->name);
68343 if (class->name_version > 1)
68344 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68345 index 91c32a0..7b88d63 100644
68346 --- a/kernel/lockdep_proc.c
68347 +++ b/kernel/lockdep_proc.c
68348 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68349
68350 static void print_name(struct seq_file *m, struct lock_class *class)
68351 {
68352 - char str[128];
68353 + char str[KSYM_NAME_LEN];
68354 const char *name = class->name;
68355
68356 if (!name) {
68357 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68358 return 0;
68359 }
68360
68361 - seq_printf(m, "%p", class->key);
68362 + seq_printf(m, "%pK", class->key);
68363 #ifdef CONFIG_DEBUG_LOCKDEP
68364 seq_printf(m, " OPS:%8ld", class->ops);
68365 #endif
68366 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68367
68368 list_for_each_entry(entry, &class->locks_after, entry) {
68369 if (entry->distance == 1) {
68370 - seq_printf(m, " -> [%p] ", entry->class->key);
68371 + seq_printf(m, " -> [%pK] ", entry->class->key);
68372 print_name(m, entry->class);
68373 seq_puts(m, "\n");
68374 }
68375 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68376 if (!class->key)
68377 continue;
68378
68379 - seq_printf(m, "[%p] ", class->key);
68380 + seq_printf(m, "[%pK] ", class->key);
68381 print_name(m, class);
68382 seq_puts(m, "\n");
68383 }
68384 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68385 if (!i)
68386 seq_line(m, '-', 40-namelen, namelen);
68387
68388 - snprintf(ip, sizeof(ip), "[<%p>]",
68389 + snprintf(ip, sizeof(ip), "[<%pK>]",
68390 (void *)class->contention_point[i]);
68391 seq_printf(m, "%40s %14lu %29s %pS\n",
68392 name, stats->contention_point[i],
68393 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68394 if (!i)
68395 seq_line(m, '-', 40-namelen, namelen);
68396
68397 - snprintf(ip, sizeof(ip), "[<%p>]",
68398 + snprintf(ip, sizeof(ip), "[<%pK>]",
68399 (void *)class->contending_point[i]);
68400 seq_printf(m, "%40s %14lu %29s %pS\n",
68401 name, stats->contending_point[i],
68402 diff --git a/kernel/module.c b/kernel/module.c
68403 index 6e48c3a..ac2ef5b 100644
68404 --- a/kernel/module.c
68405 +++ b/kernel/module.c
68406 @@ -59,6 +59,7 @@
68407 #include <linux/pfn.h>
68408 #include <linux/bsearch.h>
68409 #include <linux/fips.h>
68410 +#include <linux/grsecurity.h>
68411 #include "module-internal.h"
68412
68413 #define CREATE_TRACE_POINTS
68414 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68415
68416 /* Bounds of module allocation, for speeding __module_address.
68417 * Protected by module_mutex. */
68418 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68419 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68420 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68421
68422 int register_module_notifier(struct notifier_block * nb)
68423 {
68424 @@ -318,7 +320,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68425 return true;
68426
68427 list_for_each_entry_rcu(mod, &modules, list) {
68428 - struct symsearch arr[] = {
68429 + struct symsearch modarr[] = {
68430 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68431 NOT_GPL_ONLY, false },
68432 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68433 @@ -340,7 +342,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68434 #endif
68435 };
68436
68437 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68438 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68439 return true;
68440 }
68441 return false;
68442 @@ -472,7 +474,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68443 static int percpu_modalloc(struct module *mod,
68444 unsigned long size, unsigned long align)
68445 {
68446 - if (align > PAGE_SIZE) {
68447 + if (align-1 >= PAGE_SIZE) {
68448 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68449 mod->name, align, PAGE_SIZE);
68450 align = PAGE_SIZE;
68451 @@ -1072,7 +1074,7 @@ struct module_attribute module_uevent =
68452 static ssize_t show_coresize(struct module_attribute *mattr,
68453 struct module_kobject *mk, char *buffer)
68454 {
68455 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68456 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68457 }
68458
68459 static struct module_attribute modinfo_coresize =
68460 @@ -1081,7 +1083,7 @@ static struct module_attribute modinfo_coresize =
68461 static ssize_t show_initsize(struct module_attribute *mattr,
68462 struct module_kobject *mk, char *buffer)
68463 {
68464 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68465 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68466 }
68467
68468 static struct module_attribute modinfo_initsize =
68469 @@ -1295,7 +1297,7 @@ resolve_symbol_wait(struct module *mod,
68470 */
68471 #ifdef CONFIG_SYSFS
68472
68473 -#ifdef CONFIG_KALLSYMS
68474 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68475 static inline bool sect_empty(const Elf_Shdr *sect)
68476 {
68477 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68478 @@ -1761,21 +1763,21 @@ static void set_section_ro_nx(void *base,
68479
68480 static void unset_module_core_ro_nx(struct module *mod)
68481 {
68482 - set_page_attributes(mod->module_core + mod->core_text_size,
68483 - mod->module_core + mod->core_size,
68484 + set_page_attributes(mod->module_core_rw,
68485 + mod->module_core_rw + mod->core_size_rw,
68486 set_memory_x);
68487 - set_page_attributes(mod->module_core,
68488 - mod->module_core + mod->core_ro_size,
68489 + set_page_attributes(mod->module_core_rx,
68490 + mod->module_core_rx + mod->core_size_rx,
68491 set_memory_rw);
68492 }
68493
68494 static void unset_module_init_ro_nx(struct module *mod)
68495 {
68496 - set_page_attributes(mod->module_init + mod->init_text_size,
68497 - mod->module_init + mod->init_size,
68498 + set_page_attributes(mod->module_init_rw,
68499 + mod->module_init_rw + mod->init_size_rw,
68500 set_memory_x);
68501 - set_page_attributes(mod->module_init,
68502 - mod->module_init + mod->init_ro_size,
68503 + set_page_attributes(mod->module_init_rx,
68504 + mod->module_init_rx + mod->init_size_rx,
68505 set_memory_rw);
68506 }
68507
68508 @@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
68509
68510 mutex_lock(&module_mutex);
68511 list_for_each_entry_rcu(mod, &modules, list) {
68512 - if ((mod->module_core) && (mod->core_text_size)) {
68513 - set_page_attributes(mod->module_core,
68514 - mod->module_core + mod->core_text_size,
68515 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68516 + set_page_attributes(mod->module_core_rx,
68517 + mod->module_core_rx + mod->core_size_rx,
68518 set_memory_rw);
68519 }
68520 - if ((mod->module_init) && (mod->init_text_size)) {
68521 - set_page_attributes(mod->module_init,
68522 - mod->module_init + mod->init_text_size,
68523 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68524 + set_page_attributes(mod->module_init_rx,
68525 + mod->module_init_rx + mod->init_size_rx,
68526 set_memory_rw);
68527 }
68528 }
68529 @@ -1807,14 +1809,14 @@ void set_all_modules_text_ro(void)
68530
68531 mutex_lock(&module_mutex);
68532 list_for_each_entry_rcu(mod, &modules, list) {
68533 - if ((mod->module_core) && (mod->core_text_size)) {
68534 - set_page_attributes(mod->module_core,
68535 - mod->module_core + mod->core_text_size,
68536 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68537 + set_page_attributes(mod->module_core_rx,
68538 + mod->module_core_rx + mod->core_size_rx,
68539 set_memory_ro);
68540 }
68541 - if ((mod->module_init) && (mod->init_text_size)) {
68542 - set_page_attributes(mod->module_init,
68543 - mod->module_init + mod->init_text_size,
68544 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68545 + set_page_attributes(mod->module_init_rx,
68546 + mod->module_init_rx + mod->init_size_rx,
68547 set_memory_ro);
68548 }
68549 }
68550 @@ -1860,16 +1862,19 @@ static void free_module(struct module *mod)
68551
68552 /* This may be NULL, but that's OK */
68553 unset_module_init_ro_nx(mod);
68554 - module_free(mod, mod->module_init);
68555 + module_free(mod, mod->module_init_rw);
68556 + module_free_exec(mod, mod->module_init_rx);
68557 kfree(mod->args);
68558 percpu_modfree(mod);
68559
68560 /* Free lock-classes: */
68561 - lockdep_free_key_range(mod->module_core, mod->core_size);
68562 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68563 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68564
68565 /* Finally, free the core (containing the module structure) */
68566 unset_module_core_ro_nx(mod);
68567 - module_free(mod, mod->module_core);
68568 + module_free_exec(mod, mod->module_core_rx);
68569 + module_free(mod, mod->module_core_rw);
68570
68571 #ifdef CONFIG_MPU
68572 update_protections(current->mm);
68573 @@ -1939,9 +1944,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68574 int ret = 0;
68575 const struct kernel_symbol *ksym;
68576
68577 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68578 + int is_fs_load = 0;
68579 + int register_filesystem_found = 0;
68580 + char *p;
68581 +
68582 + p = strstr(mod->args, "grsec_modharden_fs");
68583 + if (p) {
68584 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
68585 + /* copy \0 as well */
68586 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68587 + is_fs_load = 1;
68588 + }
68589 +#endif
68590 +
68591 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68592 const char *name = info->strtab + sym[i].st_name;
68593
68594 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68595 + /* it's a real shame this will never get ripped and copied
68596 + upstream! ;(
68597 + */
68598 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68599 + register_filesystem_found = 1;
68600 +#endif
68601 +
68602 switch (sym[i].st_shndx) {
68603 case SHN_COMMON:
68604 /* We compiled with -fno-common. These are not
68605 @@ -1962,7 +1989,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68606 ksym = resolve_symbol_wait(mod, info, name);
68607 /* Ok if resolved. */
68608 if (ksym && !IS_ERR(ksym)) {
68609 + pax_open_kernel();
68610 sym[i].st_value = ksym->value;
68611 + pax_close_kernel();
68612 break;
68613 }
68614
68615 @@ -1981,11 +2010,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68616 secbase = (unsigned long)mod_percpu(mod);
68617 else
68618 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68619 + pax_open_kernel();
68620 sym[i].st_value += secbase;
68621 + pax_close_kernel();
68622 break;
68623 }
68624 }
68625
68626 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68627 + if (is_fs_load && !register_filesystem_found) {
68628 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68629 + ret = -EPERM;
68630 + }
68631 +#endif
68632 +
68633 return ret;
68634 }
68635
68636 @@ -2069,22 +2107,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68637 || s->sh_entsize != ~0UL
68638 || strstarts(sname, ".init"))
68639 continue;
68640 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68641 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68642 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68643 + else
68644 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68645 pr_debug("\t%s\n", sname);
68646 }
68647 - switch (m) {
68648 - case 0: /* executable */
68649 - mod->core_size = debug_align(mod->core_size);
68650 - mod->core_text_size = mod->core_size;
68651 - break;
68652 - case 1: /* RO: text and ro-data */
68653 - mod->core_size = debug_align(mod->core_size);
68654 - mod->core_ro_size = mod->core_size;
68655 - break;
68656 - case 3: /* whole core */
68657 - mod->core_size = debug_align(mod->core_size);
68658 - break;
68659 - }
68660 }
68661
68662 pr_debug("Init section allocation order:\n");
68663 @@ -2098,23 +2126,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68664 || s->sh_entsize != ~0UL
68665 || !strstarts(sname, ".init"))
68666 continue;
68667 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68668 - | INIT_OFFSET_MASK);
68669 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68670 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68671 + else
68672 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68673 + s->sh_entsize |= INIT_OFFSET_MASK;
68674 pr_debug("\t%s\n", sname);
68675 }
68676 - switch (m) {
68677 - case 0: /* executable */
68678 - mod->init_size = debug_align(mod->init_size);
68679 - mod->init_text_size = mod->init_size;
68680 - break;
68681 - case 1: /* RO: text and ro-data */
68682 - mod->init_size = debug_align(mod->init_size);
68683 - mod->init_ro_size = mod->init_size;
68684 - break;
68685 - case 3: /* whole init */
68686 - mod->init_size = debug_align(mod->init_size);
68687 - break;
68688 - }
68689 }
68690 }
68691
68692 @@ -2286,7 +2304,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68693
68694 /* Put symbol section at end of init part of module. */
68695 symsect->sh_flags |= SHF_ALLOC;
68696 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68697 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68698 info->index.sym) | INIT_OFFSET_MASK;
68699 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68700
68701 @@ -2306,13 +2324,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68702 }
68703
68704 /* Append room for core symbols at end of core part. */
68705 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68706 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68707 - mod->core_size += strtab_size;
68708 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68709 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68710 + mod->core_size_rx += strtab_size;
68711
68712 /* Put string table section at end of init part of module. */
68713 strsect->sh_flags |= SHF_ALLOC;
68714 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68715 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68716 info->index.str) | INIT_OFFSET_MASK;
68717 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68718 }
68719 @@ -2330,12 +2348,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68720 /* Make sure we get permanent strtab: don't use info->strtab. */
68721 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68722
68723 + pax_open_kernel();
68724 +
68725 /* Set types up while we still have access to sections. */
68726 for (i = 0; i < mod->num_symtab; i++)
68727 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68728
68729 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68730 - mod->core_strtab = s = mod->module_core + info->stroffs;
68731 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68732 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68733 src = mod->symtab;
68734 *s++ = 0;
68735 for (ndst = i = 0; i < mod->num_symtab; i++) {
68736 @@ -2348,6 +2368,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68737 }
68738 }
68739 mod->core_num_syms = ndst;
68740 +
68741 + pax_close_kernel();
68742 }
68743 #else
68744 static inline void layout_symtab(struct module *mod, struct load_info *info)
68745 @@ -2381,17 +2403,33 @@ void * __weak module_alloc(unsigned long size)
68746 return size == 0 ? NULL : vmalloc_exec(size);
68747 }
68748
68749 -static void *module_alloc_update_bounds(unsigned long size)
68750 +static void *module_alloc_update_bounds_rw(unsigned long size)
68751 {
68752 void *ret = module_alloc(size);
68753
68754 if (ret) {
68755 mutex_lock(&module_mutex);
68756 /* Update module bounds. */
68757 - if ((unsigned long)ret < module_addr_min)
68758 - module_addr_min = (unsigned long)ret;
68759 - if ((unsigned long)ret + size > module_addr_max)
68760 - module_addr_max = (unsigned long)ret + size;
68761 + if ((unsigned long)ret < module_addr_min_rw)
68762 + module_addr_min_rw = (unsigned long)ret;
68763 + if ((unsigned long)ret + size > module_addr_max_rw)
68764 + module_addr_max_rw = (unsigned long)ret + size;
68765 + mutex_unlock(&module_mutex);
68766 + }
68767 + return ret;
68768 +}
68769 +
68770 +static void *module_alloc_update_bounds_rx(unsigned long size)
68771 +{
68772 + void *ret = module_alloc_exec(size);
68773 +
68774 + if (ret) {
68775 + mutex_lock(&module_mutex);
68776 + /* Update module bounds. */
68777 + if ((unsigned long)ret < module_addr_min_rx)
68778 + module_addr_min_rx = (unsigned long)ret;
68779 + if ((unsigned long)ret + size > module_addr_max_rx)
68780 + module_addr_max_rx = (unsigned long)ret + size;
68781 mutex_unlock(&module_mutex);
68782 }
68783 return ret;
68784 @@ -2610,8 +2648,14 @@ static struct module *setup_load_info(struct load_info *info)
68785 static int check_modinfo(struct module *mod, struct load_info *info)
68786 {
68787 const char *modmagic = get_modinfo(info, "vermagic");
68788 + const char *license = get_modinfo(info, "license");
68789 int err;
68790
68791 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68792 + if (!license || !license_is_gpl_compatible(license))
68793 + return -ENOEXEC;
68794 +#endif
68795 +
68796 /* This is allowed: modprobe --force will invalidate it. */
68797 if (!modmagic) {
68798 err = try_to_force_load(mod, "bad vermagic");
68799 @@ -2634,7 +2678,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68800 }
68801
68802 /* Set up license info based on the info section */
68803 - set_license(mod, get_modinfo(info, "license"));
68804 + set_license(mod, license);
68805
68806 return 0;
68807 }
68808 @@ -2728,7 +2772,7 @@ static int move_module(struct module *mod, struct load_info *info)
68809 void *ptr;
68810
68811 /* Do the allocs. */
68812 - ptr = module_alloc_update_bounds(mod->core_size);
68813 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68814 /*
68815 * The pointer to this block is stored in the module structure
68816 * which is inside the block. Just mark it as not being a
68817 @@ -2738,23 +2782,50 @@ static int move_module(struct module *mod, struct load_info *info)
68818 if (!ptr)
68819 return -ENOMEM;
68820
68821 - memset(ptr, 0, mod->core_size);
68822 - mod->module_core = ptr;
68823 + memset(ptr, 0, mod->core_size_rw);
68824 + mod->module_core_rw = ptr;
68825
68826 - ptr = module_alloc_update_bounds(mod->init_size);
68827 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68828 /*
68829 * The pointer to this block is stored in the module structure
68830 * which is inside the block. This block doesn't need to be
68831 * scanned as it contains data and code that will be freed
68832 * after the module is initialized.
68833 */
68834 - kmemleak_ignore(ptr);
68835 - if (!ptr && mod->init_size) {
68836 - module_free(mod, mod->module_core);
68837 + kmemleak_not_leak(ptr);
68838 + if (!ptr && mod->init_size_rw) {
68839 + module_free(mod, mod->module_core_rw);
68840 return -ENOMEM;
68841 }
68842 - memset(ptr, 0, mod->init_size);
68843 - mod->module_init = ptr;
68844 + memset(ptr, 0, mod->init_size_rw);
68845 + mod->module_init_rw = ptr;
68846 +
68847 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68848 + kmemleak_not_leak(ptr);
68849 + if (!ptr) {
68850 + module_free(mod, mod->module_init_rw);
68851 + module_free(mod, mod->module_core_rw);
68852 + return -ENOMEM;
68853 + }
68854 +
68855 + pax_open_kernel();
68856 + memset(ptr, 0, mod->core_size_rx);
68857 + pax_close_kernel();
68858 + mod->module_core_rx = ptr;
68859 +
68860 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68861 + kmemleak_not_leak(ptr);
68862 + if (!ptr && mod->init_size_rx) {
68863 + module_free_exec(mod, mod->module_core_rx);
68864 + module_free(mod, mod->module_init_rw);
68865 + module_free(mod, mod->module_core_rw);
68866 + return -ENOMEM;
68867 + }
68868 +
68869 + pax_open_kernel();
68870 + memset(ptr, 0, mod->init_size_rx);
68871 + pax_close_kernel();
68872 + mod->module_init_rx = ptr;
68873
68874 /* Transfer each section which specifies SHF_ALLOC */
68875 pr_debug("final section addresses:\n");
68876 @@ -2765,16 +2836,45 @@ static int move_module(struct module *mod, struct load_info *info)
68877 if (!(shdr->sh_flags & SHF_ALLOC))
68878 continue;
68879
68880 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68881 - dest = mod->module_init
68882 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68883 - else
68884 - dest = mod->module_core + shdr->sh_entsize;
68885 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68886 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68887 + dest = mod->module_init_rw
68888 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68889 + else
68890 + dest = mod->module_init_rx
68891 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68892 + } else {
68893 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68894 + dest = mod->module_core_rw + shdr->sh_entsize;
68895 + else
68896 + dest = mod->module_core_rx + shdr->sh_entsize;
68897 + }
68898 +
68899 + if (shdr->sh_type != SHT_NOBITS) {
68900 +
68901 +#ifdef CONFIG_PAX_KERNEXEC
68902 +#ifdef CONFIG_X86_64
68903 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68904 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68905 +#endif
68906 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68907 + pax_open_kernel();
68908 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68909 + pax_close_kernel();
68910 + } else
68911 +#endif
68912
68913 - if (shdr->sh_type != SHT_NOBITS)
68914 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68915 + }
68916 /* Update sh_addr to point to copy in image. */
68917 - shdr->sh_addr = (unsigned long)dest;
68918 +
68919 +#ifdef CONFIG_PAX_KERNEXEC
68920 + if (shdr->sh_flags & SHF_EXECINSTR)
68921 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68922 + else
68923 +#endif
68924 +
68925 + shdr->sh_addr = (unsigned long)dest;
68926 pr_debug("\t0x%lx %s\n",
68927 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68928 }
68929 @@ -2829,12 +2929,12 @@ static void flush_module_icache(const struct module *mod)
68930 * Do it before processing of module parameters, so the module
68931 * can provide parameter accessor functions of its own.
68932 */
68933 - if (mod->module_init)
68934 - flush_icache_range((unsigned long)mod->module_init,
68935 - (unsigned long)mod->module_init
68936 - + mod->init_size);
68937 - flush_icache_range((unsigned long)mod->module_core,
68938 - (unsigned long)mod->module_core + mod->core_size);
68939 + if (mod->module_init_rx)
68940 + flush_icache_range((unsigned long)mod->module_init_rx,
68941 + (unsigned long)mod->module_init_rx
68942 + + mod->init_size_rx);
68943 + flush_icache_range((unsigned long)mod->module_core_rx,
68944 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68945
68946 set_fs(old_fs);
68947 }
68948 @@ -2904,8 +3004,10 @@ out:
68949 static void module_deallocate(struct module *mod, struct load_info *info)
68950 {
68951 percpu_modfree(mod);
68952 - module_free(mod, mod->module_init);
68953 - module_free(mod, mod->module_core);
68954 + module_free_exec(mod, mod->module_init_rx);
68955 + module_free_exec(mod, mod->module_core_rx);
68956 + module_free(mod, mod->module_init_rw);
68957 + module_free(mod, mod->module_core_rw);
68958 }
68959
68960 int __weak module_finalize(const Elf_Ehdr *hdr,
68961 @@ -2918,7 +3020,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68962 static int post_relocation(struct module *mod, const struct load_info *info)
68963 {
68964 /* Sort exception table now relocations are done. */
68965 + pax_open_kernel();
68966 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68967 + pax_close_kernel();
68968
68969 /* Copy relocated percpu area over. */
68970 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68971 @@ -2989,9 +3093,38 @@ static struct module *load_module(void __user *umod,
68972 if (err)
68973 goto free_unload;
68974
68975 + /* Now copy in args */
68976 + mod->args = strndup_user(uargs, ~0UL >> 1);
68977 + if (IS_ERR(mod->args)) {
68978 + err = PTR_ERR(mod->args);
68979 + goto free_unload;
68980 + }
68981 +
68982 /* Set up MODINFO_ATTR fields */
68983 setup_modinfo(mod, &info);
68984
68985 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68986 + {
68987 + char *p, *p2;
68988 +
68989 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68990 + 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);
68991 + err = -EPERM;
68992 + goto free_modinfo;
68993 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68994 + p += sizeof("grsec_modharden_normal") - 1;
68995 + p2 = strstr(p, "_");
68996 + if (p2) {
68997 + *p2 = '\0';
68998 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68999 + *p2 = '_';
69000 + }
69001 + err = -EPERM;
69002 + goto free_modinfo;
69003 + }
69004 + }
69005 +#endif
69006 +
69007 /* Fix up syms, so that st_value is a pointer to location. */
69008 err = simplify_symbols(mod, &info);
69009 if (err < 0)
69010 @@ -3007,13 +3140,6 @@ static struct module *load_module(void __user *umod,
69011
69012 flush_module_icache(mod);
69013
69014 - /* Now copy in args */
69015 - mod->args = strndup_user(uargs, ~0UL >> 1);
69016 - if (IS_ERR(mod->args)) {
69017 - err = PTR_ERR(mod->args);
69018 - goto free_arch_cleanup;
69019 - }
69020 -
69021 /* Mark state as coming so strong_try_module_get() ignores us. */
69022 mod->state = MODULE_STATE_COMING;
69023
69024 @@ -3081,11 +3207,11 @@ again:
69025 unlock:
69026 mutex_unlock(&module_mutex);
69027 synchronize_sched();
69028 - kfree(mod->args);
69029 free_arch_cleanup:
69030 module_arch_cleanup(mod);
69031 free_modinfo:
69032 free_modinfo(mod);
69033 + kfree(mod->args);
69034 free_unload:
69035 module_unload_free(mod);
69036 free_module:
69037 @@ -3126,16 +3252,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69038 MODULE_STATE_COMING, mod);
69039
69040 /* Set RO and NX regions for core */
69041 - set_section_ro_nx(mod->module_core,
69042 - mod->core_text_size,
69043 - mod->core_ro_size,
69044 - mod->core_size);
69045 + set_section_ro_nx(mod->module_core_rx,
69046 + mod->core_size_rx,
69047 + mod->core_size_rx,
69048 + mod->core_size_rx);
69049
69050 /* Set RO and NX regions for init */
69051 - set_section_ro_nx(mod->module_init,
69052 - mod->init_text_size,
69053 - mod->init_ro_size,
69054 - mod->init_size);
69055 + set_section_ro_nx(mod->module_init_rx,
69056 + mod->init_size_rx,
69057 + mod->init_size_rx,
69058 + mod->init_size_rx);
69059
69060 do_mod_ctors(mod);
69061 /* Start the module */
69062 @@ -3180,11 +3306,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
69063 mod->strtab = mod->core_strtab;
69064 #endif
69065 unset_module_init_ro_nx(mod);
69066 - module_free(mod, mod->module_init);
69067 - mod->module_init = NULL;
69068 - mod->init_size = 0;
69069 - mod->init_ro_size = 0;
69070 - mod->init_text_size = 0;
69071 + module_free(mod, mod->module_init_rw);
69072 + module_free_exec(mod, mod->module_init_rx);
69073 + mod->module_init_rw = NULL;
69074 + mod->module_init_rx = NULL;
69075 + mod->init_size_rw = 0;
69076 + mod->init_size_rx = 0;
69077 mutex_unlock(&module_mutex);
69078 wake_up_all(&module_wq);
69079
69080 @@ -3216,10 +3343,16 @@ static const char *get_ksymbol(struct module *mod,
69081 unsigned long nextval;
69082
69083 /* At worse, next value is at end of module */
69084 - if (within_module_init(addr, mod))
69085 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
69086 + if (within_module_init_rx(addr, mod))
69087 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
69088 + else if (within_module_init_rw(addr, mod))
69089 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
69090 + else if (within_module_core_rx(addr, mod))
69091 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
69092 + else if (within_module_core_rw(addr, mod))
69093 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
69094 else
69095 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
69096 + return NULL;
69097
69098 /* Scan for closest preceding symbol, and next symbol. (ELF
69099 starts real symbols at 1). */
69100 @@ -3454,7 +3587,7 @@ static int m_show(struct seq_file *m, void *p)
69101 char buf[8];
69102
69103 seq_printf(m, "%s %u",
69104 - mod->name, mod->init_size + mod->core_size);
69105 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
69106 print_unload_info(m, mod);
69107
69108 /* Informative for users. */
69109 @@ -3463,7 +3596,7 @@ static int m_show(struct seq_file *m, void *p)
69110 mod->state == MODULE_STATE_COMING ? "Loading":
69111 "Live");
69112 /* Used by oprofile and other similar tools. */
69113 - seq_printf(m, " 0x%pK", mod->module_core);
69114 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
69115
69116 /* Taints info */
69117 if (mod->taints)
69118 @@ -3499,7 +3632,17 @@ static const struct file_operations proc_modules_operations = {
69119
69120 static int __init proc_modules_init(void)
69121 {
69122 +#ifndef CONFIG_GRKERNSEC_HIDESYM
69123 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69124 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69125 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69126 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
69127 +#else
69128 proc_create("modules", 0, NULL, &proc_modules_operations);
69129 +#endif
69130 +#else
69131 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
69132 +#endif
69133 return 0;
69134 }
69135 module_init(proc_modules_init);
69136 @@ -3558,12 +3701,12 @@ struct module *__module_address(unsigned long addr)
69137 {
69138 struct module *mod;
69139
69140 - if (addr < module_addr_min || addr > module_addr_max)
69141 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
69142 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
69143 return NULL;
69144
69145 list_for_each_entry_rcu(mod, &modules, list)
69146 - if (within_module_core(addr, mod)
69147 - || within_module_init(addr, mod))
69148 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
69149 return mod;
69150 return NULL;
69151 }
69152 @@ -3597,11 +3740,20 @@ bool is_module_text_address(unsigned long addr)
69153 */
69154 struct module *__module_text_address(unsigned long addr)
69155 {
69156 - struct module *mod = __module_address(addr);
69157 + struct module *mod;
69158 +
69159 +#ifdef CONFIG_X86_32
69160 + addr = ktla_ktva(addr);
69161 +#endif
69162 +
69163 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
69164 + return NULL;
69165 +
69166 + mod = __module_address(addr);
69167 +
69168 if (mod) {
69169 /* Make sure it's within the text section. */
69170 - if (!within(addr, mod->module_init, mod->init_text_size)
69171 - && !within(addr, mod->module_core, mod->core_text_size))
69172 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
69173 mod = NULL;
69174 }
69175 return mod;
69176 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
69177 index 7e3443f..b2a1e6b 100644
69178 --- a/kernel/mutex-debug.c
69179 +++ b/kernel/mutex-debug.c
69180 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
69181 }
69182
69183 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69184 - struct thread_info *ti)
69185 + struct task_struct *task)
69186 {
69187 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69188
69189 /* Mark the current thread as blocked on the lock: */
69190 - ti->task->blocked_on = waiter;
69191 + task->blocked_on = waiter;
69192 }
69193
69194 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69195 - struct thread_info *ti)
69196 + struct task_struct *task)
69197 {
69198 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69199 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69200 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69201 - ti->task->blocked_on = NULL;
69202 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69203 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69204 + task->blocked_on = NULL;
69205
69206 list_del_init(&waiter->list);
69207 waiter->task = NULL;
69208 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69209 index 0799fd3..d06ae3b 100644
69210 --- a/kernel/mutex-debug.h
69211 +++ b/kernel/mutex-debug.h
69212 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69213 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69214 extern void debug_mutex_add_waiter(struct mutex *lock,
69215 struct mutex_waiter *waiter,
69216 - struct thread_info *ti);
69217 + struct task_struct *task);
69218 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69219 - struct thread_info *ti);
69220 + struct task_struct *task);
69221 extern void debug_mutex_unlock(struct mutex *lock);
69222 extern void debug_mutex_init(struct mutex *lock, const char *name,
69223 struct lock_class_key *key);
69224 diff --git a/kernel/mutex.c b/kernel/mutex.c
69225 index a307cc9..27fd2e9 100644
69226 --- a/kernel/mutex.c
69227 +++ b/kernel/mutex.c
69228 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69229 spin_lock_mutex(&lock->wait_lock, flags);
69230
69231 debug_mutex_lock_common(lock, &waiter);
69232 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69233 + debug_mutex_add_waiter(lock, &waiter, task);
69234
69235 /* add waiting tasks to the end of the waitqueue (FIFO): */
69236 list_add_tail(&waiter.list, &lock->wait_list);
69237 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69238 * TASK_UNINTERRUPTIBLE case.)
69239 */
69240 if (unlikely(signal_pending_state(state, task))) {
69241 - mutex_remove_waiter(lock, &waiter,
69242 - task_thread_info(task));
69243 + mutex_remove_waiter(lock, &waiter, task);
69244 mutex_release(&lock->dep_map, 1, ip);
69245 spin_unlock_mutex(&lock->wait_lock, flags);
69246
69247 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69248 done:
69249 lock_acquired(&lock->dep_map, ip);
69250 /* got the lock - rejoice! */
69251 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69252 + mutex_remove_waiter(lock, &waiter, task);
69253 mutex_set_owner(lock);
69254
69255 /* set it to 0 if there are no waiters left: */
69256 diff --git a/kernel/panic.c b/kernel/panic.c
69257 index e1b2822..5edc1d9 100644
69258 --- a/kernel/panic.c
69259 +++ b/kernel/panic.c
69260 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69261 const char *board;
69262
69263 printk(KERN_WARNING "------------[ cut here ]------------\n");
69264 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69265 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69266 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69267 if (board)
69268 printk(KERN_WARNING "Hardware name: %s\n", board);
69269 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69270 */
69271 void __stack_chk_fail(void)
69272 {
69273 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69274 + dump_stack();
69275 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69276 __builtin_return_address(0));
69277 }
69278 EXPORT_SYMBOL(__stack_chk_fail);
69279 diff --git a/kernel/pid.c b/kernel/pid.c
69280 index aebd4f5..1693c13 100644
69281 --- a/kernel/pid.c
69282 +++ b/kernel/pid.c
69283 @@ -33,6 +33,7 @@
69284 #include <linux/rculist.h>
69285 #include <linux/bootmem.h>
69286 #include <linux/hash.h>
69287 +#include <linux/security.h>
69288 #include <linux/pid_namespace.h>
69289 #include <linux/init_task.h>
69290 #include <linux/syscalls.h>
69291 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69292
69293 int pid_max = PID_MAX_DEFAULT;
69294
69295 -#define RESERVED_PIDS 300
69296 +#define RESERVED_PIDS 500
69297
69298 int pid_max_min = RESERVED_PIDS + 1;
69299 int pid_max_max = PID_MAX_LIMIT;
69300 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69301 */
69302 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69303 {
69304 + struct task_struct *task;
69305 +
69306 rcu_lockdep_assert(rcu_read_lock_held(),
69307 "find_task_by_pid_ns() needs rcu_read_lock()"
69308 " protection");
69309 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69310 +
69311 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69312 +
69313 + if (gr_pid_is_chrooted(task))
69314 + return NULL;
69315 +
69316 + return task;
69317 }
69318
69319 struct task_struct *find_task_by_vpid(pid_t vnr)
69320 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69321 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69322 }
69323
69324 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69325 +{
69326 + rcu_lockdep_assert(rcu_read_lock_held(),
69327 + "find_task_by_pid_ns() needs rcu_read_lock()"
69328 + " protection");
69329 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69330 +}
69331 +
69332 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69333 {
69334 struct pid *pid;
69335 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69336 index 125cb67..2e5c8ad 100644
69337 --- a/kernel/posix-cpu-timers.c
69338 +++ b/kernel/posix-cpu-timers.c
69339 @@ -6,9 +6,11 @@
69340 #include <linux/posix-timers.h>
69341 #include <linux/errno.h>
69342 #include <linux/math64.h>
69343 +#include <linux/security.h>
69344 #include <asm/uaccess.h>
69345 #include <linux/kernel_stat.h>
69346 #include <trace/events/timer.h>
69347 +#include <linux/random.h>
69348
69349 /*
69350 * Called after updating RLIMIT_CPU to run cpu timer and update
69351 @@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
69352 */
69353 void posix_cpu_timers_exit(struct task_struct *tsk)
69354 {
69355 + add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
69356 + sizeof(unsigned long long));
69357 cleanup_timers(tsk->cpu_timers,
69358 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
69359
69360 @@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
69361
69362 static __init int init_posix_cpu_timers(void)
69363 {
69364 - struct k_clock process = {
69365 + static struct k_clock process = {
69366 .clock_getres = process_cpu_clock_getres,
69367 .clock_get = process_cpu_clock_get,
69368 .timer_create = process_cpu_timer_create,
69369 .nsleep = process_cpu_nsleep,
69370 .nsleep_restart = process_cpu_nsleep_restart,
69371 };
69372 - struct k_clock thread = {
69373 + static struct k_clock thread = {
69374 .clock_getres = thread_cpu_clock_getres,
69375 .clock_get = thread_cpu_clock_get,
69376 .timer_create = thread_cpu_timer_create,
69377 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69378 index 69185ae..cc2847a 100644
69379 --- a/kernel/posix-timers.c
69380 +++ b/kernel/posix-timers.c
69381 @@ -43,6 +43,7 @@
69382 #include <linux/idr.h>
69383 #include <linux/posix-clock.h>
69384 #include <linux/posix-timers.h>
69385 +#include <linux/grsecurity.h>
69386 #include <linux/syscalls.h>
69387 #include <linux/wait.h>
69388 #include <linux/workqueue.h>
69389 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69390 * which we beg off on and pass to do_sys_settimeofday().
69391 */
69392
69393 -static struct k_clock posix_clocks[MAX_CLOCKS];
69394 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69395
69396 /*
69397 * These ones are defined below.
69398 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69399 */
69400 static __init int init_posix_timers(void)
69401 {
69402 - struct k_clock clock_realtime = {
69403 + static struct k_clock clock_realtime = {
69404 .clock_getres = hrtimer_get_res,
69405 .clock_get = posix_clock_realtime_get,
69406 .clock_set = posix_clock_realtime_set,
69407 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69408 .timer_get = common_timer_get,
69409 .timer_del = common_timer_del,
69410 };
69411 - struct k_clock clock_monotonic = {
69412 + static struct k_clock clock_monotonic = {
69413 .clock_getres = hrtimer_get_res,
69414 .clock_get = posix_ktime_get_ts,
69415 .nsleep = common_nsleep,
69416 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69417 .timer_get = common_timer_get,
69418 .timer_del = common_timer_del,
69419 };
69420 - struct k_clock clock_monotonic_raw = {
69421 + static struct k_clock clock_monotonic_raw = {
69422 .clock_getres = hrtimer_get_res,
69423 .clock_get = posix_get_monotonic_raw,
69424 };
69425 - struct k_clock clock_realtime_coarse = {
69426 + static struct k_clock clock_realtime_coarse = {
69427 .clock_getres = posix_get_coarse_res,
69428 .clock_get = posix_get_realtime_coarse,
69429 };
69430 - struct k_clock clock_monotonic_coarse = {
69431 + static struct k_clock clock_monotonic_coarse = {
69432 .clock_getres = posix_get_coarse_res,
69433 .clock_get = posix_get_monotonic_coarse,
69434 };
69435 - struct k_clock clock_boottime = {
69436 + static struct k_clock clock_boottime = {
69437 .clock_getres = hrtimer_get_res,
69438 .clock_get = posix_get_boottime,
69439 .nsleep = common_nsleep,
69440 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69441 return;
69442 }
69443
69444 - posix_clocks[clock_id] = *new_clock;
69445 + posix_clocks[clock_id] = new_clock;
69446 }
69447 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69448
69449 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69450 return (id & CLOCKFD_MASK) == CLOCKFD ?
69451 &clock_posix_dynamic : &clock_posix_cpu;
69452
69453 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69454 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69455 return NULL;
69456 - return &posix_clocks[id];
69457 + return posix_clocks[id];
69458 }
69459
69460 static int common_timer_create(struct k_itimer *new_timer)
69461 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69462 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69463 return -EFAULT;
69464
69465 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69466 + have their clock_set fptr set to a nosettime dummy function
69467 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69468 + call common_clock_set, which calls do_sys_settimeofday, which
69469 + we hook
69470 + */
69471 +
69472 return kc->clock_set(which_clock, &new_tp);
69473 }
69474
69475 diff --git a/kernel/power/process.c b/kernel/power/process.c
69476 index 87da817..30ddd13 100644
69477 --- a/kernel/power/process.c
69478 +++ b/kernel/power/process.c
69479 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69480 u64 elapsed_csecs64;
69481 unsigned int elapsed_csecs;
69482 bool wakeup = false;
69483 + bool timedout = false;
69484
69485 do_gettimeofday(&start);
69486
69487 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69488
69489 while (true) {
69490 todo = 0;
69491 + if (time_after(jiffies, end_time))
69492 + timedout = true;
69493 read_lock(&tasklist_lock);
69494 do_each_thread(g, p) {
69495 if (p == current || !freeze_task(p))
69496 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69497 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69498 * transition can't race with task state testing here.
69499 */
69500 - if (!task_is_stopped_or_traced(p) &&
69501 - !freezer_should_skip(p))
69502 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69503 todo++;
69504 + if (timedout) {
69505 + printk(KERN_ERR "Task refusing to freeze:\n");
69506 + sched_show_task(p);
69507 + }
69508 + }
69509 } while_each_thread(g, p);
69510 read_unlock(&tasklist_lock);
69511
69512 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69513 todo += wq_busy;
69514 }
69515
69516 - if (!todo || time_after(jiffies, end_time))
69517 + if (!todo || timedout)
69518 break;
69519
69520 if (pm_wakeup_pending()) {
69521 diff --git a/kernel/printk.c b/kernel/printk.c
69522 index 2d607f4..7413773 100644
69523 --- a/kernel/printk.c
69524 +++ b/kernel/printk.c
69525 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69526 if (from_file && type != SYSLOG_ACTION_OPEN)
69527 return 0;
69528
69529 +#ifdef CONFIG_GRKERNSEC_DMESG
69530 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69531 + return -EPERM;
69532 +#endif
69533 +
69534 if (syslog_action_restricted(type)) {
69535 if (capable(CAP_SYSLOG))
69536 return 0;
69537 diff --git a/kernel/profile.c b/kernel/profile.c
69538 index 76b8e77..a2930e8 100644
69539 --- a/kernel/profile.c
69540 +++ b/kernel/profile.c
69541 @@ -39,7 +39,7 @@ struct profile_hit {
69542 /* Oprofile timer tick hook */
69543 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69544
69545 -static atomic_t *prof_buffer;
69546 +static atomic_unchecked_t *prof_buffer;
69547 static unsigned long prof_len, prof_shift;
69548
69549 int prof_on __read_mostly;
69550 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69551 hits[i].pc = 0;
69552 continue;
69553 }
69554 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69555 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69556 hits[i].hits = hits[i].pc = 0;
69557 }
69558 }
69559 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69560 * Add the current hit(s) and flush the write-queue out
69561 * to the global buffer:
69562 */
69563 - atomic_add(nr_hits, &prof_buffer[pc]);
69564 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69565 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69566 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69567 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69568 hits[i].pc = hits[i].hits = 0;
69569 }
69570 out:
69571 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69572 {
69573 unsigned long pc;
69574 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69575 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69576 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69577 }
69578 #endif /* !CONFIG_SMP */
69579
69580 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69581 return -EFAULT;
69582 buf++; p++; count--; read++;
69583 }
69584 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69585 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69586 if (copy_to_user(buf, (void *)pnt, count))
69587 return -EFAULT;
69588 read += count;
69589 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69590 }
69591 #endif
69592 profile_discard_flip_buffers();
69593 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69594 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69595 return count;
69596 }
69597
69598 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69599 index 1f5e55d..8b8f969 100644
69600 --- a/kernel/ptrace.c
69601 +++ b/kernel/ptrace.c
69602 @@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69603
69604 if (seize)
69605 flags |= PT_SEIZED;
69606 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69607 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69608 flags |= PT_PTRACE_CAP;
69609 task->ptrace = flags;
69610
69611 @@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69612 break;
69613 return -EIO;
69614 }
69615 - if (copy_to_user(dst, buf, retval))
69616 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69617 return -EFAULT;
69618 copied += retval;
69619 src += retval;
69620 @@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
69621 bool seized = child->ptrace & PT_SEIZED;
69622 int ret = -EIO;
69623 siginfo_t siginfo, *si;
69624 - void __user *datavp = (void __user *) data;
69625 + void __user *datavp = (__force void __user *) data;
69626 unsigned long __user *datalp = datavp;
69627 unsigned long flags;
69628
69629 @@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69630 goto out;
69631 }
69632
69633 + if (gr_handle_ptrace(child, request)) {
69634 + ret = -EPERM;
69635 + goto out_put_task_struct;
69636 + }
69637 +
69638 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69639 ret = ptrace_attach(child, request, addr, data);
69640 /*
69641 * Some architectures need to do book-keeping after
69642 * a ptrace attach.
69643 */
69644 - if (!ret)
69645 + if (!ret) {
69646 arch_ptrace_attach(child);
69647 + gr_audit_ptrace(child);
69648 + }
69649 goto out_put_task_struct;
69650 }
69651
69652 @@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69653 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69654 if (copied != sizeof(tmp))
69655 return -EIO;
69656 - return put_user(tmp, (unsigned long __user *)data);
69657 + return put_user(tmp, (__force unsigned long __user *)data);
69658 }
69659
69660 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69661 @@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69662 goto out;
69663 }
69664
69665 + if (gr_handle_ptrace(child, request)) {
69666 + ret = -EPERM;
69667 + goto out_put_task_struct;
69668 + }
69669 +
69670 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69671 ret = ptrace_attach(child, request, addr, data);
69672 /*
69673 * Some architectures need to do book-keeping after
69674 * a ptrace attach.
69675 */
69676 - if (!ret)
69677 + if (!ret) {
69678 arch_ptrace_attach(child);
69679 + gr_audit_ptrace(child);
69680 + }
69681 goto out_put_task_struct;
69682 }
69683
69684 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69685 index e4c6a59..c86621a 100644
69686 --- a/kernel/rcutiny.c
69687 +++ b/kernel/rcutiny.c
69688 @@ -46,7 +46,7 @@
69689 struct rcu_ctrlblk;
69690 static void invoke_rcu_callbacks(void);
69691 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69692 -static void rcu_process_callbacks(struct softirq_action *unused);
69693 +static void rcu_process_callbacks(void);
69694 static void __call_rcu(struct rcu_head *head,
69695 void (*func)(struct rcu_head *rcu),
69696 struct rcu_ctrlblk *rcp);
69697 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69698 rcu_is_callbacks_kthread()));
69699 }
69700
69701 -static void rcu_process_callbacks(struct softirq_action *unused)
69702 +static void rcu_process_callbacks(void)
69703 {
69704 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69705 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69706 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69707 index 3d01902..afbf46e 100644
69708 --- a/kernel/rcutiny_plugin.h
69709 +++ b/kernel/rcutiny_plugin.h
69710 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69711 have_rcu_kthread_work = morework;
69712 local_irq_restore(flags);
69713 if (work)
69714 - rcu_process_callbacks(NULL);
69715 + rcu_process_callbacks();
69716 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69717 }
69718
69719 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69720 index aaa7b9f..055ff1e 100644
69721 --- a/kernel/rcutorture.c
69722 +++ b/kernel/rcutorture.c
69723 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69724 { 0 };
69725 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69726 { 0 };
69727 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69728 -static atomic_t n_rcu_torture_alloc;
69729 -static atomic_t n_rcu_torture_alloc_fail;
69730 -static atomic_t n_rcu_torture_free;
69731 -static atomic_t n_rcu_torture_mberror;
69732 -static atomic_t n_rcu_torture_error;
69733 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69734 +static atomic_unchecked_t n_rcu_torture_alloc;
69735 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69736 +static atomic_unchecked_t n_rcu_torture_free;
69737 +static atomic_unchecked_t n_rcu_torture_mberror;
69738 +static atomic_unchecked_t n_rcu_torture_error;
69739 static long n_rcu_torture_barrier_error;
69740 static long n_rcu_torture_boost_ktrerror;
69741 static long n_rcu_torture_boost_rterror;
69742 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
69743
69744 spin_lock_bh(&rcu_torture_lock);
69745 if (list_empty(&rcu_torture_freelist)) {
69746 - atomic_inc(&n_rcu_torture_alloc_fail);
69747 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69748 spin_unlock_bh(&rcu_torture_lock);
69749 return NULL;
69750 }
69751 - atomic_inc(&n_rcu_torture_alloc);
69752 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69753 p = rcu_torture_freelist.next;
69754 list_del_init(p);
69755 spin_unlock_bh(&rcu_torture_lock);
69756 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
69757 static void
69758 rcu_torture_free(struct rcu_torture *p)
69759 {
69760 - atomic_inc(&n_rcu_torture_free);
69761 + atomic_inc_unchecked(&n_rcu_torture_free);
69762 spin_lock_bh(&rcu_torture_lock);
69763 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69764 spin_unlock_bh(&rcu_torture_lock);
69765 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
69766 i = rp->rtort_pipe_count;
69767 if (i > RCU_TORTURE_PIPE_LEN)
69768 i = RCU_TORTURE_PIPE_LEN;
69769 - atomic_inc(&rcu_torture_wcount[i]);
69770 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69771 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69772 rp->rtort_mbtest = 0;
69773 rcu_torture_free(rp);
69774 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69775 i = rp->rtort_pipe_count;
69776 if (i > RCU_TORTURE_PIPE_LEN)
69777 i = RCU_TORTURE_PIPE_LEN;
69778 - atomic_inc(&rcu_torture_wcount[i]);
69779 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69780 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69781 rp->rtort_mbtest = 0;
69782 list_del(&rp->rtort_free);
69783 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
69784 i = old_rp->rtort_pipe_count;
69785 if (i > RCU_TORTURE_PIPE_LEN)
69786 i = RCU_TORTURE_PIPE_LEN;
69787 - atomic_inc(&rcu_torture_wcount[i]);
69788 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69789 old_rp->rtort_pipe_count++;
69790 cur_ops->deferred_free(old_rp);
69791 }
69792 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
69793 }
69794 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69795 if (p->rtort_mbtest == 0)
69796 - atomic_inc(&n_rcu_torture_mberror);
69797 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69798 spin_lock(&rand_lock);
69799 cur_ops->read_delay(&rand);
69800 n_rcu_torture_timers++;
69801 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
69802 }
69803 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69804 if (p->rtort_mbtest == 0)
69805 - atomic_inc(&n_rcu_torture_mberror);
69806 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69807 cur_ops->read_delay(&rand);
69808 preempt_disable();
69809 pipe_count = p->rtort_pipe_count;
69810 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
69811 rcu_torture_current,
69812 rcu_torture_current_version,
69813 list_empty(&rcu_torture_freelist),
69814 - atomic_read(&n_rcu_torture_alloc),
69815 - atomic_read(&n_rcu_torture_alloc_fail),
69816 - atomic_read(&n_rcu_torture_free));
69817 + atomic_read_unchecked(&n_rcu_torture_alloc),
69818 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69819 + atomic_read_unchecked(&n_rcu_torture_free));
69820 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69821 - atomic_read(&n_rcu_torture_mberror),
69822 + atomic_read_unchecked(&n_rcu_torture_mberror),
69823 n_rcu_torture_boost_ktrerror,
69824 n_rcu_torture_boost_rterror);
69825 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69826 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
69827 n_barrier_attempts,
69828 n_rcu_torture_barrier_error);
69829 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69830 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69831 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69832 n_rcu_torture_barrier_error != 0 ||
69833 n_rcu_torture_boost_ktrerror != 0 ||
69834 n_rcu_torture_boost_rterror != 0 ||
69835 n_rcu_torture_boost_failure != 0 ||
69836 i > 1) {
69837 cnt += sprintf(&page[cnt], "!!! ");
69838 - atomic_inc(&n_rcu_torture_error);
69839 + atomic_inc_unchecked(&n_rcu_torture_error);
69840 WARN_ON_ONCE(1);
69841 }
69842 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69843 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
69844 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69845 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69846 cnt += sprintf(&page[cnt], " %d",
69847 - atomic_read(&rcu_torture_wcount[i]));
69848 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69849 }
69850 cnt += sprintf(&page[cnt], "\n");
69851 if (cur_ops->stats)
69852 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
69853
69854 if (cur_ops->cleanup)
69855 cur_ops->cleanup();
69856 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69857 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69858 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69859 else if (n_online_successes != n_online_attempts ||
69860 n_offline_successes != n_offline_attempts)
69861 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
69862
69863 rcu_torture_current = NULL;
69864 rcu_torture_current_version = 0;
69865 - atomic_set(&n_rcu_torture_alloc, 0);
69866 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69867 - atomic_set(&n_rcu_torture_free, 0);
69868 - atomic_set(&n_rcu_torture_mberror, 0);
69869 - atomic_set(&n_rcu_torture_error, 0);
69870 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69871 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69872 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69873 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69874 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69875 n_rcu_torture_barrier_error = 0;
69876 n_rcu_torture_boost_ktrerror = 0;
69877 n_rcu_torture_boost_rterror = 0;
69878 n_rcu_torture_boost_failure = 0;
69879 n_rcu_torture_boosts = 0;
69880 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69881 - atomic_set(&rcu_torture_wcount[i], 0);
69882 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69883 for_each_possible_cpu(cpu) {
69884 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69885 per_cpu(rcu_torture_count, cpu)[i] = 0;
69886 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69887 index 2682295..0f2297e 100644
69888 --- a/kernel/rcutree.c
69889 +++ b/kernel/rcutree.c
69890 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
69891 rcu_prepare_for_idle(smp_processor_id());
69892 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69893 smp_mb__before_atomic_inc(); /* See above. */
69894 - atomic_inc(&rdtp->dynticks);
69895 + atomic_inc_unchecked(&rdtp->dynticks);
69896 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69897 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69898 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69899
69900 /*
69901 * It is illegal to enter an extended quiescent state while
69902 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
69903 int user)
69904 {
69905 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69906 - atomic_inc(&rdtp->dynticks);
69907 + atomic_inc_unchecked(&rdtp->dynticks);
69908 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69909 smp_mb__after_atomic_inc(); /* See above. */
69910 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69911 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69912 rcu_cleanup_after_idle(smp_processor_id());
69913 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69914 if (!user && !is_idle_task(current)) {
69915 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
69916 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69917
69918 if (rdtp->dynticks_nmi_nesting == 0 &&
69919 - (atomic_read(&rdtp->dynticks) & 0x1))
69920 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69921 return;
69922 rdtp->dynticks_nmi_nesting++;
69923 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69924 - atomic_inc(&rdtp->dynticks);
69925 + atomic_inc_unchecked(&rdtp->dynticks);
69926 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69927 smp_mb__after_atomic_inc(); /* See above. */
69928 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69929 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69930 }
69931
69932 /**
69933 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
69934 return;
69935 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69936 smp_mb__before_atomic_inc(); /* See above. */
69937 - atomic_inc(&rdtp->dynticks);
69938 + atomic_inc_unchecked(&rdtp->dynticks);
69939 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69940 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69941 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69942 }
69943
69944 /**
69945 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
69946 int ret;
69947
69948 preempt_disable();
69949 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69950 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69951 preempt_enable();
69952 return ret;
69953 }
69954 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69955 */
69956 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69957 {
69958 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69959 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69960 return (rdp->dynticks_snap & 0x1) == 0;
69961 }
69962
69963 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69964 unsigned int curr;
69965 unsigned int snap;
69966
69967 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69968 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69969 snap = (unsigned int)rdp->dynticks_snap;
69970
69971 /*
69972 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
69973 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69974 */
69975 if (till_stall_check < 3) {
69976 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69977 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69978 till_stall_check = 3;
69979 } else if (till_stall_check > 300) {
69980 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69981 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69982 till_stall_check = 300;
69983 }
69984 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69985 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69986 rsp->qlen += rdp->qlen;
69987 rdp->n_cbs_orphaned += rdp->qlen;
69988 rdp->qlen_lazy = 0;
69989 - ACCESS_ONCE(rdp->qlen) = 0;
69990 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69991 }
69992
69993 /*
69994 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69995 }
69996 smp_mb(); /* List handling before counting for rcu_barrier(). */
69997 rdp->qlen_lazy -= count_lazy;
69998 - ACCESS_ONCE(rdp->qlen) -= count;
69999 + ACCESS_ONCE_RW(rdp->qlen) -= count;
70000 rdp->n_cbs_invoked += count;
70001
70002 /* Reinstate batch limit if we have worked down the excess. */
70003 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
70004 /*
70005 * Do RCU core processing for the current CPU.
70006 */
70007 -static void rcu_process_callbacks(struct softirq_action *unused)
70008 +static void rcu_process_callbacks(void)
70009 {
70010 struct rcu_state *rsp;
70011
70012 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
70013 local_irq_restore(flags);
70014 return;
70015 }
70016 - ACCESS_ONCE(rdp->qlen)++;
70017 + ACCESS_ONCE_RW(rdp->qlen)++;
70018 if (lazy)
70019 rdp->qlen_lazy++;
70020 else
70021 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
70022 }
70023 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
70024
70025 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
70026 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
70027 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
70028 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
70029
70030 static int synchronize_sched_expedited_cpu_stop(void *data)
70031 {
70032 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
70033 int firstsnap, s, snap, trycount = 0;
70034
70035 /* Note that atomic_inc_return() implies full memory barrier. */
70036 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
70037 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
70038 get_online_cpus();
70039 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
70040
70041 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
70042 }
70043
70044 /* Check to see if someone else did our work for us. */
70045 - s = atomic_read(&sync_sched_expedited_done);
70046 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70047 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
70048 smp_mb(); /* ensure test happens before caller kfree */
70049 return;
70050 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
70051 * grace period works for us.
70052 */
70053 get_online_cpus();
70054 - snap = atomic_read(&sync_sched_expedited_started);
70055 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
70056 smp_mb(); /* ensure read is before try_stop_cpus(). */
70057 }
70058
70059 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
70060 * than we did beat us to the punch.
70061 */
70062 do {
70063 - s = atomic_read(&sync_sched_expedited_done);
70064 + s = atomic_read_unchecked(&sync_sched_expedited_done);
70065 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
70066 smp_mb(); /* ensure test happens before caller kfree */
70067 break;
70068 }
70069 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
70070 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
70071
70072 put_online_cpus();
70073 }
70074 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70075 * ACCESS_ONCE() to prevent the compiler from speculating
70076 * the increment to precede the early-exit check.
70077 */
70078 - ACCESS_ONCE(rsp->n_barrier_done)++;
70079 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70080 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
70081 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
70082 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
70083 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
70084
70085 /* Increment ->n_barrier_done to prevent duplicate work. */
70086 smp_mb(); /* Keep increment after above mechanism. */
70087 - ACCESS_ONCE(rsp->n_barrier_done)++;
70088 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
70089 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
70090 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
70091 smp_mb(); /* Keep increment before caller's subsequent code. */
70092 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
70093 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
70094 init_callback_list(rdp);
70095 rdp->qlen_lazy = 0;
70096 - ACCESS_ONCE(rdp->qlen) = 0;
70097 + ACCESS_ONCE_RW(rdp->qlen) = 0;
70098 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
70099 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
70100 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
70101 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
70102 #ifdef CONFIG_RCU_USER_QS
70103 WARN_ON_ONCE(rdp->dynticks->in_user);
70104 #endif
70105 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
70106 rdp->blimit = blimit;
70107 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
70108 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
70109 - atomic_set(&rdp->dynticks->dynticks,
70110 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
70111 + atomic_set_unchecked(&rdp->dynticks->dynticks,
70112 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
70113 rcu_prepare_for_idle_init(cpu);
70114 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
70115
70116 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
70117 index a240f03..d469618 100644
70118 --- a/kernel/rcutree.h
70119 +++ b/kernel/rcutree.h
70120 @@ -86,7 +86,7 @@ struct rcu_dynticks {
70121 long long dynticks_nesting; /* Track irq/process nesting level. */
70122 /* Process level is worth LLONG_MAX/2. */
70123 int dynticks_nmi_nesting; /* Track NMI nesting level. */
70124 - atomic_t dynticks; /* Even value for idle, else odd. */
70125 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
70126 #ifdef CONFIG_RCU_FAST_NO_HZ
70127 int dyntick_drain; /* Prepare-for-idle state variable. */
70128 unsigned long dyntick_holdoff;
70129 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
70130 index f921154..34c4873 100644
70131 --- a/kernel/rcutree_plugin.h
70132 +++ b/kernel/rcutree_plugin.h
70133 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
70134
70135 /* Clean up and exit. */
70136 smp_mb(); /* ensure expedited GP seen before counter increment. */
70137 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
70138 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
70139 unlock_mb_ret:
70140 mutex_unlock(&sync_rcu_preempt_exp_mutex);
70141 mb_ret:
70142 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
70143 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
70144 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
70145 cpu, ticks_value, ticks_title,
70146 - atomic_read(&rdtp->dynticks) & 0xfff,
70147 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
70148 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
70149 fast_no_hz);
70150 }
70151 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
70152 index 693513b..b9f1d63 100644
70153 --- a/kernel/rcutree_trace.c
70154 +++ b/kernel/rcutree_trace.c
70155 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
70156 rdp->completed, rdp->gpnum,
70157 rdp->passed_quiesce, rdp->qs_pending);
70158 seq_printf(m, " dt=%d/%llx/%d df=%lu",
70159 - atomic_read(&rdp->dynticks->dynticks),
70160 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70161 rdp->dynticks->dynticks_nesting,
70162 rdp->dynticks->dynticks_nmi_nesting,
70163 rdp->dynticks_fqs);
70164 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
70165 rdp->completed, rdp->gpnum,
70166 rdp->passed_quiesce, rdp->qs_pending);
70167 seq_printf(m, ",%d,%llx,%d,%lu",
70168 - atomic_read(&rdp->dynticks->dynticks),
70169 + atomic_read_unchecked(&rdp->dynticks->dynticks),
70170 rdp->dynticks->dynticks_nesting,
70171 rdp->dynticks->dynticks_nmi_nesting,
70172 rdp->dynticks_fqs);
70173 diff --git a/kernel/resource.c b/kernel/resource.c
70174 index 73f35d4..4684fc4 100644
70175 --- a/kernel/resource.c
70176 +++ b/kernel/resource.c
70177 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
70178
70179 static int __init ioresources_init(void)
70180 {
70181 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70182 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70183 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
70184 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
70185 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70186 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
70187 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
70188 +#endif
70189 +#else
70190 proc_create("ioports", 0, NULL, &proc_ioports_operations);
70191 proc_create("iomem", 0, NULL, &proc_iomem_operations);
70192 +#endif
70193 return 0;
70194 }
70195 __initcall(ioresources_init);
70196 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70197 index 98ec494..4241d6d 100644
70198 --- a/kernel/rtmutex-tester.c
70199 +++ b/kernel/rtmutex-tester.c
70200 @@ -20,7 +20,7 @@
70201 #define MAX_RT_TEST_MUTEXES 8
70202
70203 static spinlock_t rttest_lock;
70204 -static atomic_t rttest_event;
70205 +static atomic_unchecked_t rttest_event;
70206
70207 struct test_thread_data {
70208 int opcode;
70209 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70210
70211 case RTTEST_LOCKCONT:
70212 td->mutexes[td->opdata] = 1;
70213 - td->event = atomic_add_return(1, &rttest_event);
70214 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70215 return 0;
70216
70217 case RTTEST_RESET:
70218 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70219 return 0;
70220
70221 case RTTEST_RESETEVENT:
70222 - atomic_set(&rttest_event, 0);
70223 + atomic_set_unchecked(&rttest_event, 0);
70224 return 0;
70225
70226 default:
70227 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70228 return ret;
70229
70230 td->mutexes[id] = 1;
70231 - td->event = atomic_add_return(1, &rttest_event);
70232 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70233 rt_mutex_lock(&mutexes[id]);
70234 - td->event = atomic_add_return(1, &rttest_event);
70235 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70236 td->mutexes[id] = 4;
70237 return 0;
70238
70239 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70240 return ret;
70241
70242 td->mutexes[id] = 1;
70243 - td->event = atomic_add_return(1, &rttest_event);
70244 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70245 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70246 - td->event = atomic_add_return(1, &rttest_event);
70247 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70248 td->mutexes[id] = ret ? 0 : 4;
70249 return ret ? -EINTR : 0;
70250
70251 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70252 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70253 return ret;
70254
70255 - td->event = atomic_add_return(1, &rttest_event);
70256 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70257 rt_mutex_unlock(&mutexes[id]);
70258 - td->event = atomic_add_return(1, &rttest_event);
70259 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70260 td->mutexes[id] = 0;
70261 return 0;
70262
70263 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70264 break;
70265
70266 td->mutexes[dat] = 2;
70267 - td->event = atomic_add_return(1, &rttest_event);
70268 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70269 break;
70270
70271 default:
70272 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70273 return;
70274
70275 td->mutexes[dat] = 3;
70276 - td->event = atomic_add_return(1, &rttest_event);
70277 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70278 break;
70279
70280 case RTTEST_LOCKNOWAIT:
70281 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70282 return;
70283
70284 td->mutexes[dat] = 1;
70285 - td->event = atomic_add_return(1, &rttest_event);
70286 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70287 return;
70288
70289 default:
70290 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70291 index 15f60d0..7e50319 100644
70292 --- a/kernel/sched/auto_group.c
70293 +++ b/kernel/sched/auto_group.c
70294 @@ -11,7 +11,7 @@
70295
70296 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70297 static struct autogroup autogroup_default;
70298 -static atomic_t autogroup_seq_nr;
70299 +static atomic_unchecked_t autogroup_seq_nr;
70300
70301 void __init autogroup_init(struct task_struct *init_task)
70302 {
70303 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70304
70305 kref_init(&ag->kref);
70306 init_rwsem(&ag->lock);
70307 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70308 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70309 ag->tg = tg;
70310 #ifdef CONFIG_RT_GROUP_SCHED
70311 /*
70312 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70313 index 2d8927f..f617765 100644
70314 --- a/kernel/sched/core.c
70315 +++ b/kernel/sched/core.c
70316 @@ -3562,6 +3562,8 @@ int can_nice(const struct task_struct *p, const int nice)
70317 /* convert nice value [19,-20] to rlimit style value [1,40] */
70318 int nice_rlim = 20 - nice;
70319
70320 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70321 +
70322 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70323 capable(CAP_SYS_NICE));
70324 }
70325 @@ -3595,7 +3597,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70326 if (nice > 19)
70327 nice = 19;
70328
70329 - if (increment < 0 && !can_nice(current, nice))
70330 + if (increment < 0 && (!can_nice(current, nice) ||
70331 + gr_handle_chroot_nice()))
70332 return -EPERM;
70333
70334 retval = security_task_setnice(current, nice);
70335 @@ -3749,6 +3752,7 @@ recheck:
70336 unsigned long rlim_rtprio =
70337 task_rlimit(p, RLIMIT_RTPRIO);
70338
70339 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70340 /* can't set/change the rt policy */
70341 if (policy != p->policy && !rlim_rtprio)
70342 return -EPERM;
70343 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70344 index 6b800a1..0c36227 100644
70345 --- a/kernel/sched/fair.c
70346 +++ b/kernel/sched/fair.c
70347 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70348 * run_rebalance_domains is triggered when needed from the scheduler tick.
70349 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70350 */
70351 -static void run_rebalance_domains(struct softirq_action *h)
70352 +static void run_rebalance_domains(void)
70353 {
70354 int this_cpu = smp_processor_id();
70355 struct rq *this_rq = cpu_rq(this_cpu);
70356 diff --git a/kernel/signal.c b/kernel/signal.c
70357 index 0af8868..a00119d 100644
70358 --- a/kernel/signal.c
70359 +++ b/kernel/signal.c
70360 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
70361
70362 int print_fatal_signals __read_mostly;
70363
70364 -static void __user *sig_handler(struct task_struct *t, int sig)
70365 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70366 {
70367 return t->sighand->action[sig - 1].sa.sa_handler;
70368 }
70369
70370 -static int sig_handler_ignored(void __user *handler, int sig)
70371 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70372 {
70373 /* Is it explicitly or implicitly ignored? */
70374 return handler == SIG_IGN ||
70375 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70376
70377 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70378 {
70379 - void __user *handler;
70380 + __sighandler_t handler;
70381
70382 handler = sig_handler(t, sig);
70383
70384 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70385 atomic_inc(&user->sigpending);
70386 rcu_read_unlock();
70387
70388 + if (!override_rlimit)
70389 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70390 +
70391 if (override_rlimit ||
70392 atomic_read(&user->sigpending) <=
70393 task_rlimit(t, RLIMIT_SIGPENDING)) {
70394 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70395
70396 int unhandled_signal(struct task_struct *tsk, int sig)
70397 {
70398 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70399 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70400 if (is_global_init(tsk))
70401 return 1;
70402 if (handler != SIG_IGN && handler != SIG_DFL)
70403 @@ -817,6 +820,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70404 }
70405 }
70406
70407 + /* allow glibc communication via tgkill to other threads in our
70408 + thread group */
70409 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70410 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70411 + && gr_handle_signal(t, sig))
70412 + return -EPERM;
70413 +
70414 return security_task_kill(t, info, sig, 0);
70415 }
70416
70417 @@ -1198,7 +1208,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70418 return send_signal(sig, info, p, 1);
70419 }
70420
70421 -static int
70422 +int
70423 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70424 {
70425 return send_signal(sig, info, t, 0);
70426 @@ -1235,6 +1245,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70427 unsigned long int flags;
70428 int ret, blocked, ignored;
70429 struct k_sigaction *action;
70430 + int is_unhandled = 0;
70431
70432 spin_lock_irqsave(&t->sighand->siglock, flags);
70433 action = &t->sighand->action[sig-1];
70434 @@ -1249,9 +1260,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70435 }
70436 if (action->sa.sa_handler == SIG_DFL)
70437 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70438 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70439 + is_unhandled = 1;
70440 ret = specific_send_sig_info(sig, info, t);
70441 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70442
70443 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70444 + normal operation */
70445 + if (is_unhandled) {
70446 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70447 + gr_handle_crash(t, sig);
70448 + }
70449 +
70450 return ret;
70451 }
70452
70453 @@ -1318,8 +1338,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70454 ret = check_kill_permission(sig, info, p);
70455 rcu_read_unlock();
70456
70457 - if (!ret && sig)
70458 + if (!ret && sig) {
70459 ret = do_send_sig_info(sig, info, p, true);
70460 + if (!ret)
70461 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70462 + }
70463
70464 return ret;
70465 }
70466 @@ -2864,7 +2887,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70467 int error = -ESRCH;
70468
70469 rcu_read_lock();
70470 - p = find_task_by_vpid(pid);
70471 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70472 + /* allow glibc communication via tgkill to other threads in our
70473 + thread group */
70474 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70475 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70476 + p = find_task_by_vpid_unrestricted(pid);
70477 + else
70478 +#endif
70479 + p = find_task_by_vpid(pid);
70480 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70481 error = check_kill_permission(sig, info, p);
70482 /*
70483 diff --git a/kernel/softirq.c b/kernel/softirq.c
70484 index cc96bdc..8bb9750 100644
70485 --- a/kernel/softirq.c
70486 +++ b/kernel/softirq.c
70487 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70488
70489 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70490
70491 -char *softirq_to_name[NR_SOFTIRQS] = {
70492 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70493 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70494 "TASKLET", "SCHED", "HRTIMER", "RCU"
70495 };
70496 @@ -244,7 +244,7 @@ restart:
70497 kstat_incr_softirqs_this_cpu(vec_nr);
70498
70499 trace_softirq_entry(vec_nr);
70500 - h->action(h);
70501 + h->action();
70502 trace_softirq_exit(vec_nr);
70503 if (unlikely(prev_count != preempt_count())) {
70504 printk(KERN_ERR "huh, entered softirq %u %s %p"
70505 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70506 or_softirq_pending(1UL << nr);
70507 }
70508
70509 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70510 +void open_softirq(int nr, void (*action)(void))
70511 {
70512 - softirq_vec[nr].action = action;
70513 + pax_open_kernel();
70514 + *(void **)&softirq_vec[nr].action = action;
70515 + pax_close_kernel();
70516 }
70517
70518 /*
70519 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70520
70521 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70522
70523 -static void tasklet_action(struct softirq_action *a)
70524 +static void tasklet_action(void)
70525 {
70526 struct tasklet_struct *list;
70527
70528 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
70529 }
70530 }
70531
70532 -static void tasklet_hi_action(struct softirq_action *a)
70533 +static void tasklet_hi_action(void)
70534 {
70535 struct tasklet_struct *list;
70536
70537 diff --git a/kernel/srcu.c b/kernel/srcu.c
70538 index 97c465e..d83f3bb 100644
70539 --- a/kernel/srcu.c
70540 +++ b/kernel/srcu.c
70541 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70542 preempt_disable();
70543 idx = rcu_dereference_index_check(sp->completed,
70544 rcu_read_lock_sched_held()) & 0x1;
70545 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70546 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70547 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70548 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70549 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70550 preempt_enable();
70551 return idx;
70552 }
70553 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70554 {
70555 preempt_disable();
70556 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70557 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70558 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70559 preempt_enable();
70560 }
70561 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70562 diff --git a/kernel/sys.c b/kernel/sys.c
70563 index e6e0ece..1f2e413 100644
70564 --- a/kernel/sys.c
70565 +++ b/kernel/sys.c
70566 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70567 error = -EACCES;
70568 goto out;
70569 }
70570 +
70571 + if (gr_handle_chroot_setpriority(p, niceval)) {
70572 + error = -EACCES;
70573 + goto out;
70574 + }
70575 +
70576 no_nice = security_task_setnice(p, niceval);
70577 if (no_nice) {
70578 error = no_nice;
70579 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70580 goto error;
70581 }
70582
70583 + if (gr_check_group_change(new->gid, new->egid, -1))
70584 + goto error;
70585 +
70586 if (rgid != (gid_t) -1 ||
70587 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70588 new->sgid = new->egid;
70589 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70590 old = current_cred();
70591
70592 retval = -EPERM;
70593 +
70594 + if (gr_check_group_change(kgid, kgid, kgid))
70595 + goto error;
70596 +
70597 if (nsown_capable(CAP_SETGID))
70598 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70599 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70600 @@ -647,7 +660,7 @@ error:
70601 /*
70602 * change the user struct in a credentials set to match the new UID
70603 */
70604 -static int set_user(struct cred *new)
70605 +int set_user(struct cred *new)
70606 {
70607 struct user_struct *new_user;
70608
70609 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70610 goto error;
70611 }
70612
70613 + if (gr_check_user_change(new->uid, new->euid, -1))
70614 + goto error;
70615 +
70616 if (!uid_eq(new->uid, old->uid)) {
70617 retval = set_user(new);
70618 if (retval < 0)
70619 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70620 old = current_cred();
70621
70622 retval = -EPERM;
70623 +
70624 + if (gr_check_crash_uid(kuid))
70625 + goto error;
70626 + if (gr_check_user_change(kuid, kuid, kuid))
70627 + goto error;
70628 +
70629 if (nsown_capable(CAP_SETUID)) {
70630 new->suid = new->uid = kuid;
70631 if (!uid_eq(kuid, old->uid)) {
70632 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70633 goto error;
70634 }
70635
70636 + if (gr_check_user_change(kruid, keuid, -1))
70637 + goto error;
70638 +
70639 if (ruid != (uid_t) -1) {
70640 new->uid = kruid;
70641 if (!uid_eq(kruid, old->uid)) {
70642 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70643 goto error;
70644 }
70645
70646 + if (gr_check_group_change(krgid, kegid, -1))
70647 + goto error;
70648 +
70649 if (rgid != (gid_t) -1)
70650 new->gid = krgid;
70651 if (egid != (gid_t) -1)
70652 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70653 if (!uid_valid(kuid))
70654 return old_fsuid;
70655
70656 + if (gr_check_user_change(-1, -1, kuid))
70657 + goto error;
70658 +
70659 new = prepare_creds();
70660 if (!new)
70661 return old_fsuid;
70662 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70663 }
70664 }
70665
70666 +error:
70667 abort_creds(new);
70668 return old_fsuid;
70669
70670 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70671 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70672 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70673 nsown_capable(CAP_SETGID)) {
70674 + if (gr_check_group_change(-1, -1, kgid))
70675 + goto error;
70676 +
70677 if (!gid_eq(kgid, old->fsgid)) {
70678 new->fsgid = kgid;
70679 goto change_okay;
70680 }
70681 }
70682
70683 +error:
70684 abort_creds(new);
70685 return old_fsgid;
70686
70687 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70688 return -EFAULT;
70689
70690 down_read(&uts_sem);
70691 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70692 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70693 __OLD_UTS_LEN);
70694 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70695 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70696 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70697 __OLD_UTS_LEN);
70698 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70699 - error |= __copy_to_user(&name->release, &utsname()->release,
70700 + error |= __copy_to_user(name->release, &utsname()->release,
70701 __OLD_UTS_LEN);
70702 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70703 - error |= __copy_to_user(&name->version, &utsname()->version,
70704 + error |= __copy_to_user(name->version, &utsname()->version,
70705 __OLD_UTS_LEN);
70706 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70707 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70708 + error |= __copy_to_user(name->machine, &utsname()->machine,
70709 __OLD_UTS_LEN);
70710 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70711 up_read(&uts_sem);
70712 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70713 error = get_dumpable(me->mm);
70714 break;
70715 case PR_SET_DUMPABLE:
70716 - if (arg2 < 0 || arg2 > 1) {
70717 + if (arg2 > 1) {
70718 error = -EINVAL;
70719 break;
70720 }
70721 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70722 index 26f65ea..df8e5ad 100644
70723 --- a/kernel/sysctl.c
70724 +++ b/kernel/sysctl.c
70725 @@ -92,7 +92,6 @@
70726
70727
70728 #if defined(CONFIG_SYSCTL)
70729 -
70730 /* External variables not in a header file. */
70731 extern int sysctl_overcommit_memory;
70732 extern int sysctl_overcommit_ratio;
70733 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
70734 void __user *buffer, size_t *lenp, loff_t *ppos);
70735 #endif
70736
70737 -#ifdef CONFIG_PRINTK
70738 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70739 void __user *buffer, size_t *lenp, loff_t *ppos);
70740 -#endif
70741
70742 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70743 void __user *buffer, size_t *lenp, loff_t *ppos);
70744 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70745
70746 #endif
70747
70748 +extern struct ctl_table grsecurity_table[];
70749 +
70750 static struct ctl_table kern_table[];
70751 static struct ctl_table vm_table[];
70752 static struct ctl_table fs_table[];
70753 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
70754 int sysctl_legacy_va_layout;
70755 #endif
70756
70757 +#ifdef CONFIG_PAX_SOFTMODE
70758 +static ctl_table pax_table[] = {
70759 + {
70760 + .procname = "softmode",
70761 + .data = &pax_softmode,
70762 + .maxlen = sizeof(unsigned int),
70763 + .mode = 0600,
70764 + .proc_handler = &proc_dointvec,
70765 + },
70766 +
70767 + { }
70768 +};
70769 +#endif
70770 +
70771 /* The default sysctl tables: */
70772
70773 static struct ctl_table sysctl_base_table[] = {
70774 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
70775 #endif
70776
70777 static struct ctl_table kern_table[] = {
70778 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70779 + {
70780 + .procname = "grsecurity",
70781 + .mode = 0500,
70782 + .child = grsecurity_table,
70783 + },
70784 +#endif
70785 +
70786 +#ifdef CONFIG_PAX_SOFTMODE
70787 + {
70788 + .procname = "pax",
70789 + .mode = 0500,
70790 + .child = pax_table,
70791 + },
70792 +#endif
70793 +
70794 {
70795 .procname = "sched_child_runs_first",
70796 .data = &sysctl_sched_child_runs_first,
70797 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
70798 .data = &modprobe_path,
70799 .maxlen = KMOD_PATH_LEN,
70800 .mode = 0644,
70801 - .proc_handler = proc_dostring,
70802 + .proc_handler = proc_dostring_modpriv,
70803 },
70804 {
70805 .procname = "modules_disabled",
70806 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
70807 .extra1 = &zero,
70808 .extra2 = &one,
70809 },
70810 +#endif
70811 {
70812 .procname = "kptr_restrict",
70813 .data = &kptr_restrict,
70814 .maxlen = sizeof(int),
70815 .mode = 0644,
70816 .proc_handler = proc_dointvec_minmax_sysadmin,
70817 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70818 + .extra1 = &two,
70819 +#else
70820 .extra1 = &zero,
70821 +#endif
70822 .extra2 = &two,
70823 },
70824 -#endif
70825 {
70826 .procname = "ngroups_max",
70827 .data = &ngroups_max,
70828 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
70829 .proc_handler = proc_dointvec_minmax,
70830 .extra1 = &zero,
70831 },
70832 + {
70833 + .procname = "heap_stack_gap",
70834 + .data = &sysctl_heap_stack_gap,
70835 + .maxlen = sizeof(sysctl_heap_stack_gap),
70836 + .mode = 0644,
70837 + .proc_handler = proc_doulongvec_minmax,
70838 + },
70839 #else
70840 {
70841 .procname = "nr_trim_pages",
70842 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
70843 buffer, lenp, ppos);
70844 }
70845
70846 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70847 + void __user *buffer, size_t *lenp, loff_t *ppos)
70848 +{
70849 + if (write && !capable(CAP_SYS_MODULE))
70850 + return -EPERM;
70851 +
70852 + return _proc_do_string(table->data, table->maxlen, write,
70853 + buffer, lenp, ppos);
70854 +}
70855 +
70856 static size_t proc_skip_spaces(char **buf)
70857 {
70858 size_t ret;
70859 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70860 len = strlen(tmp);
70861 if (len > *size)
70862 len = *size;
70863 + if (len > sizeof(tmp))
70864 + len = sizeof(tmp);
70865 if (copy_to_user(*buf, tmp, len))
70866 return -EFAULT;
70867 *size -= len;
70868 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
70869 return err;
70870 }
70871
70872 -#ifdef CONFIG_PRINTK
70873 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70874 void __user *buffer, size_t *lenp, loff_t *ppos)
70875 {
70876 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70877
70878 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70879 }
70880 -#endif
70881
70882 struct do_proc_dointvec_minmax_conv_param {
70883 int *min;
70884 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70885 *i = val;
70886 } else {
70887 val = convdiv * (*i) / convmul;
70888 - if (!first)
70889 + if (!first) {
70890 err = proc_put_char(&buffer, &left, '\t');
70891 + if (err)
70892 + break;
70893 + }
70894 err = proc_put_long(&buffer, &left, val, false);
70895 if (err)
70896 break;
70897 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
70898 return -ENOSYS;
70899 }
70900
70901 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70902 + void __user *buffer, size_t *lenp, loff_t *ppos)
70903 +{
70904 + return -ENOSYS;
70905 +}
70906 +
70907 int proc_dointvec(struct ctl_table *table, int write,
70908 void __user *buffer, size_t *lenp, loff_t *ppos)
70909 {
70910 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70911 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70912 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70913 EXPORT_SYMBOL(proc_dostring);
70914 +EXPORT_SYMBOL(proc_dostring_modpriv);
70915 EXPORT_SYMBOL(proc_doulongvec_minmax);
70916 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70917 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70918 index 65bdcf1..21eb831 100644
70919 --- a/kernel/sysctl_binary.c
70920 +++ b/kernel/sysctl_binary.c
70921 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70922 int i;
70923
70924 set_fs(KERNEL_DS);
70925 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70926 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70927 set_fs(old_fs);
70928 if (result < 0)
70929 goto out_kfree;
70930 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70931 }
70932
70933 set_fs(KERNEL_DS);
70934 - result = vfs_write(file, buffer, str - buffer, &pos);
70935 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70936 set_fs(old_fs);
70937 if (result < 0)
70938 goto out_kfree;
70939 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70940 int i;
70941
70942 set_fs(KERNEL_DS);
70943 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70944 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70945 set_fs(old_fs);
70946 if (result < 0)
70947 goto out_kfree;
70948 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70949 }
70950
70951 set_fs(KERNEL_DS);
70952 - result = vfs_write(file, buffer, str - buffer, &pos);
70953 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70954 set_fs(old_fs);
70955 if (result < 0)
70956 goto out_kfree;
70957 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70958 int i;
70959
70960 set_fs(KERNEL_DS);
70961 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70962 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70963 set_fs(old_fs);
70964 if (result < 0)
70965 goto out;
70966 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70967 __le16 dnaddr;
70968
70969 set_fs(KERNEL_DS);
70970 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70971 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70972 set_fs(old_fs);
70973 if (result < 0)
70974 goto out;
70975 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70976 le16_to_cpu(dnaddr) & 0x3ff);
70977
70978 set_fs(KERNEL_DS);
70979 - result = vfs_write(file, buf, len, &pos);
70980 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70981 set_fs(old_fs);
70982 if (result < 0)
70983 goto out;
70984 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70985 index 145bb4d..b2aa969 100644
70986 --- a/kernel/taskstats.c
70987 +++ b/kernel/taskstats.c
70988 @@ -28,9 +28,12 @@
70989 #include <linux/fs.h>
70990 #include <linux/file.h>
70991 #include <linux/pid_namespace.h>
70992 +#include <linux/grsecurity.h>
70993 #include <net/genetlink.h>
70994 #include <linux/atomic.h>
70995
70996 +extern int gr_is_taskstats_denied(int pid);
70997 +
70998 /*
70999 * Maximum length of a cpumask that can be specified in
71000 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
71001 @@ -570,6 +573,9 @@ err:
71002
71003 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
71004 {
71005 + if (gr_is_taskstats_denied(current->pid))
71006 + return -EACCES;
71007 +
71008 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
71009 return cmd_attr_register_cpumask(info);
71010 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
71011 diff --git a/kernel/time.c b/kernel/time.c
71012 index d226c6a..c7c0960 100644
71013 --- a/kernel/time.c
71014 +++ b/kernel/time.c
71015 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
71016 return error;
71017
71018 if (tz) {
71019 + /* we log in do_settimeofday called below, so don't log twice
71020 + */
71021 + if (!tv)
71022 + gr_log_timechange();
71023 +
71024 sys_tz = *tz;
71025 update_vsyscall_tz();
71026 if (firsttime) {
71027 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
71028 index f11d83b..d016d91 100644
71029 --- a/kernel/time/alarmtimer.c
71030 +++ b/kernel/time/alarmtimer.c
71031 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
71032 struct platform_device *pdev;
71033 int error = 0;
71034 int i;
71035 - struct k_clock alarm_clock = {
71036 + static struct k_clock alarm_clock = {
71037 .clock_getres = alarm_clock_getres,
71038 .clock_get = alarm_clock_get,
71039 .timer_create = alarm_timer_create,
71040 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
71041 index f113755..ec24223 100644
71042 --- a/kernel/time/tick-broadcast.c
71043 +++ b/kernel/time/tick-broadcast.c
71044 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
71045 * then clear the broadcast bit.
71046 */
71047 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
71048 - int cpu = smp_processor_id();
71049 + cpu = smp_processor_id();
71050
71051 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
71052 tick_broadcast_clear_oneshot(cpu);
71053 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
71054 index e424970..4c7962b 100644
71055 --- a/kernel/time/timekeeping.c
71056 +++ b/kernel/time/timekeeping.c
71057 @@ -15,6 +15,7 @@
71058 #include <linux/init.h>
71059 #include <linux/mm.h>
71060 #include <linux/sched.h>
71061 +#include <linux/grsecurity.h>
71062 #include <linux/syscore_ops.h>
71063 #include <linux/clocksource.h>
71064 #include <linux/jiffies.h>
71065 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
71066 if (!timespec_valid_strict(tv))
71067 return -EINVAL;
71068
71069 + gr_log_timechange();
71070 +
71071 write_seqlock_irqsave(&tk->lock, flags);
71072
71073 timekeeping_forward_now(tk);
71074 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
71075 index af5a7e9..715611a 100644
71076 --- a/kernel/time/timer_list.c
71077 +++ b/kernel/time/timer_list.c
71078 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
71079
71080 static void print_name_offset(struct seq_file *m, void *sym)
71081 {
71082 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71083 + SEQ_printf(m, "<%p>", NULL);
71084 +#else
71085 char symname[KSYM_NAME_LEN];
71086
71087 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
71088 SEQ_printf(m, "<%pK>", sym);
71089 else
71090 SEQ_printf(m, "%s", symname);
71091 +#endif
71092 }
71093
71094 static void
71095 @@ -112,7 +116,11 @@ next_one:
71096 static void
71097 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
71098 {
71099 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71100 + SEQ_printf(m, " .base: %p\n", NULL);
71101 +#else
71102 SEQ_printf(m, " .base: %pK\n", base);
71103 +#endif
71104 SEQ_printf(m, " .index: %d\n",
71105 base->index);
71106 SEQ_printf(m, " .resolution: %Lu nsecs\n",
71107 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
71108 {
71109 struct proc_dir_entry *pe;
71110
71111 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71112 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
71113 +#else
71114 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
71115 +#endif
71116 if (!pe)
71117 return -ENOMEM;
71118 return 0;
71119 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
71120 index 0b537f2..40d6c20 100644
71121 --- a/kernel/time/timer_stats.c
71122 +++ b/kernel/time/timer_stats.c
71123 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
71124 static unsigned long nr_entries;
71125 static struct entry entries[MAX_ENTRIES];
71126
71127 -static atomic_t overflow_count;
71128 +static atomic_unchecked_t overflow_count;
71129
71130 /*
71131 * The entries are in a hash-table, for fast lookup:
71132 @@ -140,7 +140,7 @@ static void reset_entries(void)
71133 nr_entries = 0;
71134 memset(entries, 0, sizeof(entries));
71135 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
71136 - atomic_set(&overflow_count, 0);
71137 + atomic_set_unchecked(&overflow_count, 0);
71138 }
71139
71140 static struct entry *alloc_entry(void)
71141 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71142 if (likely(entry))
71143 entry->count++;
71144 else
71145 - atomic_inc(&overflow_count);
71146 + atomic_inc_unchecked(&overflow_count);
71147
71148 out_unlock:
71149 raw_spin_unlock_irqrestore(lock, flags);
71150 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
71151
71152 static void print_name_offset(struct seq_file *m, unsigned long addr)
71153 {
71154 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71155 + seq_printf(m, "<%p>", NULL);
71156 +#else
71157 char symname[KSYM_NAME_LEN];
71158
71159 if (lookup_symbol_name(addr, symname) < 0)
71160 - seq_printf(m, "<%p>", (void *)addr);
71161 + seq_printf(m, "<%pK>", (void *)addr);
71162 else
71163 seq_printf(m, "%s", symname);
71164 +#endif
71165 }
71166
71167 static int tstats_show(struct seq_file *m, void *v)
71168 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
71169
71170 seq_puts(m, "Timer Stats Version: v0.2\n");
71171 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
71172 - if (atomic_read(&overflow_count))
71173 + if (atomic_read_unchecked(&overflow_count))
71174 seq_printf(m, "Overflow: %d entries\n",
71175 - atomic_read(&overflow_count));
71176 + atomic_read_unchecked(&overflow_count));
71177
71178 for (i = 0; i < nr_entries; i++) {
71179 entry = entries + i;
71180 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
71181 {
71182 struct proc_dir_entry *pe;
71183
71184 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71185 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
71186 +#else
71187 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
71188 +#endif
71189 if (!pe)
71190 return -ENOMEM;
71191 return 0;
71192 diff --git a/kernel/timer.c b/kernel/timer.c
71193 index 367d008..6e2ac71 100644
71194 --- a/kernel/timer.c
71195 +++ b/kernel/timer.c
71196 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
71197 /*
71198 * This function runs timers and the timer-tq in bottom half context.
71199 */
71200 -static void run_timer_softirq(struct softirq_action *h)
71201 +static void run_timer_softirq(void)
71202 {
71203 struct tvec_base *base = __this_cpu_read(tvec_bases);
71204
71205 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71206 index c0bd030..62a1927 100644
71207 --- a/kernel/trace/blktrace.c
71208 +++ b/kernel/trace/blktrace.c
71209 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71210 struct blk_trace *bt = filp->private_data;
71211 char buf[16];
71212
71213 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71214 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71215
71216 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71217 }
71218 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71219 return 1;
71220
71221 bt = buf->chan->private_data;
71222 - atomic_inc(&bt->dropped);
71223 + atomic_inc_unchecked(&bt->dropped);
71224 return 0;
71225 }
71226
71227 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71228
71229 bt->dir = dir;
71230 bt->dev = dev;
71231 - atomic_set(&bt->dropped, 0);
71232 + atomic_set_unchecked(&bt->dropped, 0);
71233
71234 ret = -EIO;
71235 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71236 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71237 index 51b7159..7f83cf8 100644
71238 --- a/kernel/trace/ftrace.c
71239 +++ b/kernel/trace/ftrace.c
71240 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71241 if (unlikely(ftrace_disabled))
71242 return 0;
71243
71244 + ret = ftrace_arch_code_modify_prepare();
71245 + FTRACE_WARN_ON(ret);
71246 + if (ret)
71247 + return 0;
71248 +
71249 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71250 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71251 if (ret) {
71252 ftrace_bug(ret, ip);
71253 - return 0;
71254 }
71255 - return 1;
71256 + return ret ? 0 : 1;
71257 }
71258
71259 /*
71260 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71261
71262 int
71263 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71264 - void *data)
71265 + void *data)
71266 {
71267 struct ftrace_func_probe *entry;
71268 struct ftrace_page *pg;
71269 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
71270 if (!count)
71271 return 0;
71272
71273 + pax_open_kernel();
71274 sort(start, count, sizeof(*start),
71275 ftrace_cmp_ips, ftrace_swap_ips);
71276 + pax_close_kernel();
71277
71278 start_pg = ftrace_allocate_pages(count);
71279 if (!start_pg)
71280 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
71281 index 4cb5e51..e7e05d9 100644
71282 --- a/kernel/trace/ring_buffer.c
71283 +++ b/kernel/trace/ring_buffer.c
71284 @@ -346,9 +346,9 @@ struct buffer_data_page {
71285 */
71286 struct buffer_page {
71287 struct list_head list; /* list of buffer pages */
71288 - local_t write; /* index for next write */
71289 + local_unchecked_t write; /* index for next write */
71290 unsigned read; /* index for next read */
71291 - local_t entries; /* entries on this page */
71292 + local_unchecked_t entries; /* entries on this page */
71293 unsigned long real_end; /* real end of data */
71294 struct buffer_data_page *page; /* Actual data page */
71295 };
71296 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
71297 unsigned long lost_events;
71298 unsigned long last_overrun;
71299 local_t entries_bytes;
71300 - local_t commit_overrun;
71301 - local_t overrun;
71302 + local_unchecked_t commit_overrun;
71303 + local_unchecked_t overrun;
71304 local_t entries;
71305 local_t committing;
71306 local_t commits;
71307 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
71308 *
71309 * We add a counter to the write field to denote this.
71310 */
71311 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
71312 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
71313 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
71314 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
71315
71316 /*
71317 * Just make sure we have seen our old_write and synchronize
71318 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
71319 * cmpxchg to only update if an interrupt did not already
71320 * do it for us. If the cmpxchg fails, we don't care.
71321 */
71322 - (void)local_cmpxchg(&next_page->write, old_write, val);
71323 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
71324 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
71325 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
71326
71327 /*
71328 * No need to worry about races with clearing out the commit.
71329 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
71330
71331 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
71332 {
71333 - return local_read(&bpage->entries) & RB_WRITE_MASK;
71334 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
71335 }
71336
71337 static inline unsigned long rb_page_write(struct buffer_page *bpage)
71338 {
71339 - return local_read(&bpage->write) & RB_WRITE_MASK;
71340 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
71341 }
71342
71343 static int
71344 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
71345 * bytes consumed in ring buffer from here.
71346 * Increment overrun to account for the lost events.
71347 */
71348 - local_add(page_entries, &cpu_buffer->overrun);
71349 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
71350 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
71351 }
71352
71353 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
71354 * it is our responsibility to update
71355 * the counters.
71356 */
71357 - local_add(entries, &cpu_buffer->overrun);
71358 + local_add_unchecked(entries, &cpu_buffer->overrun);
71359 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
71360
71361 /*
71362 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71363 if (tail == BUF_PAGE_SIZE)
71364 tail_page->real_end = 0;
71365
71366 - local_sub(length, &tail_page->write);
71367 + local_sub_unchecked(length, &tail_page->write);
71368 return;
71369 }
71370
71371 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71372 rb_event_set_padding(event);
71373
71374 /* Set the write back to the previous setting */
71375 - local_sub(length, &tail_page->write);
71376 + local_sub_unchecked(length, &tail_page->write);
71377 return;
71378 }
71379
71380 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
71381
71382 /* Set write to end of buffer */
71383 length = (tail + length) - BUF_PAGE_SIZE;
71384 - local_sub(length, &tail_page->write);
71385 + local_sub_unchecked(length, &tail_page->write);
71386 }
71387
71388 /*
71389 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
71390 * about it.
71391 */
71392 if (unlikely(next_page == commit_page)) {
71393 - local_inc(&cpu_buffer->commit_overrun);
71394 + local_inc_unchecked(&cpu_buffer->commit_overrun);
71395 goto out_reset;
71396 }
71397
71398 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
71399 cpu_buffer->tail_page) &&
71400 (cpu_buffer->commit_page ==
71401 cpu_buffer->reader_page))) {
71402 - local_inc(&cpu_buffer->commit_overrun);
71403 + local_inc_unchecked(&cpu_buffer->commit_overrun);
71404 goto out_reset;
71405 }
71406 }
71407 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
71408 length += RB_LEN_TIME_EXTEND;
71409
71410 tail_page = cpu_buffer->tail_page;
71411 - write = local_add_return(length, &tail_page->write);
71412 + write = local_add_return_unchecked(length, &tail_page->write);
71413
71414 /* set write to only the index of the write */
71415 write &= RB_WRITE_MASK;
71416 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
71417 kmemcheck_annotate_bitfield(event, bitfield);
71418 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
71419
71420 - local_inc(&tail_page->entries);
71421 + local_inc_unchecked(&tail_page->entries);
71422
71423 /*
71424 * If this is the first commit on the page, then update
71425 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
71426
71427 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
71428 unsigned long write_mask =
71429 - local_read(&bpage->write) & ~RB_WRITE_MASK;
71430 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
71431 unsigned long event_length = rb_event_length(event);
71432 /*
71433 * This is on the tail page. It is possible that
71434 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
71435 */
71436 old_index += write_mask;
71437 new_index += write_mask;
71438 - index = local_cmpxchg(&bpage->write, old_index, new_index);
71439 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
71440 if (index == old_index) {
71441 /* update counters */
71442 local_sub(event_length, &cpu_buffer->entries_bytes);
71443 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
71444
71445 /* Do the likely case first */
71446 if (likely(bpage->page == (void *)addr)) {
71447 - local_dec(&bpage->entries);
71448 + local_dec_unchecked(&bpage->entries);
71449 return;
71450 }
71451
71452 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
71453 start = bpage;
71454 do {
71455 if (bpage->page == (void *)addr) {
71456 - local_dec(&bpage->entries);
71457 + local_dec_unchecked(&bpage->entries);
71458 return;
71459 }
71460 rb_inc_page(cpu_buffer, &bpage);
71461 @@ -2923,7 +2923,7 @@ static inline unsigned long
71462 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
71463 {
71464 return local_read(&cpu_buffer->entries) -
71465 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
71466 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
71467 }
71468
71469 /**
71470 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
71471 return 0;
71472
71473 cpu_buffer = buffer->buffers[cpu];
71474 - ret = local_read(&cpu_buffer->overrun);
71475 + ret = local_read_unchecked(&cpu_buffer->overrun);
71476
71477 return ret;
71478 }
71479 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
71480 return 0;
71481
71482 cpu_buffer = buffer->buffers[cpu];
71483 - ret = local_read(&cpu_buffer->commit_overrun);
71484 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
71485
71486 return ret;
71487 }
71488 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
71489 /* if you care about this being correct, lock the buffer */
71490 for_each_buffer_cpu(buffer, cpu) {
71491 cpu_buffer = buffer->buffers[cpu];
71492 - overruns += local_read(&cpu_buffer->overrun);
71493 + overruns += local_read_unchecked(&cpu_buffer->overrun);
71494 }
71495
71496 return overruns;
71497 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
71498 /*
71499 * Reset the reader page to size zero.
71500 */
71501 - local_set(&cpu_buffer->reader_page->write, 0);
71502 - local_set(&cpu_buffer->reader_page->entries, 0);
71503 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
71504 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
71505 local_set(&cpu_buffer->reader_page->page->commit, 0);
71506 cpu_buffer->reader_page->real_end = 0;
71507
71508 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
71509 * want to compare with the last_overrun.
71510 */
71511 smp_mb();
71512 - overwrite = local_read(&(cpu_buffer->overrun));
71513 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
71514
71515 /*
71516 * Here's the tricky part.
71517 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
71518
71519 cpu_buffer->head_page
71520 = list_entry(cpu_buffer->pages, struct buffer_page, list);
71521 - local_set(&cpu_buffer->head_page->write, 0);
71522 - local_set(&cpu_buffer->head_page->entries, 0);
71523 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
71524 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
71525 local_set(&cpu_buffer->head_page->page->commit, 0);
71526
71527 cpu_buffer->head_page->read = 0;
71528 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
71529
71530 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
71531 INIT_LIST_HEAD(&cpu_buffer->new_pages);
71532 - local_set(&cpu_buffer->reader_page->write, 0);
71533 - local_set(&cpu_buffer->reader_page->entries, 0);
71534 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
71535 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
71536 local_set(&cpu_buffer->reader_page->page->commit, 0);
71537 cpu_buffer->reader_page->read = 0;
71538
71539 - local_set(&cpu_buffer->commit_overrun, 0);
71540 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
71541 local_set(&cpu_buffer->entries_bytes, 0);
71542 - local_set(&cpu_buffer->overrun, 0);
71543 + local_set_unchecked(&cpu_buffer->overrun, 0);
71544 local_set(&cpu_buffer->entries, 0);
71545 local_set(&cpu_buffer->committing, 0);
71546 local_set(&cpu_buffer->commits, 0);
71547 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
71548 rb_init_page(bpage);
71549 bpage = reader->page;
71550 reader->page = *data_page;
71551 - local_set(&reader->write, 0);
71552 - local_set(&reader->entries, 0);
71553 + local_set_unchecked(&reader->write, 0);
71554 + local_set_unchecked(&reader->entries, 0);
71555 reader->read = 0;
71556 *data_page = bpage;
71557
71558 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71559 index 31e4f55..62da00f 100644
71560 --- a/kernel/trace/trace.c
71561 +++ b/kernel/trace/trace.c
71562 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71563 };
71564 #endif
71565
71566 -static struct dentry *d_tracer;
71567 -
71568 struct dentry *tracing_init_dentry(void)
71569 {
71570 + static struct dentry *d_tracer;
71571 static int once;
71572
71573 if (d_tracer)
71574 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
71575 return d_tracer;
71576 }
71577
71578 -static struct dentry *d_percpu;
71579 -
71580 struct dentry *tracing_dentry_percpu(void)
71581 {
71582 + static struct dentry *d_percpu;
71583 static int once;
71584 struct dentry *d_tracer;
71585
71586 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71587 index d608d09..7eddcb1 100644
71588 --- a/kernel/trace/trace_events.c
71589 +++ b/kernel/trace/trace_events.c
71590 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
71591 struct ftrace_module_file_ops {
71592 struct list_head list;
71593 struct module *mod;
71594 - struct file_operations id;
71595 - struct file_operations enable;
71596 - struct file_operations format;
71597 - struct file_operations filter;
71598 };
71599
71600 static struct ftrace_module_file_ops *
71601 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
71602
71603 file_ops->mod = mod;
71604
71605 - file_ops->id = ftrace_event_id_fops;
71606 - file_ops->id.owner = mod;
71607 -
71608 - file_ops->enable = ftrace_enable_fops;
71609 - file_ops->enable.owner = mod;
71610 -
71611 - file_ops->filter = ftrace_event_filter_fops;
71612 - file_ops->filter.owner = mod;
71613 -
71614 - file_ops->format = ftrace_event_format_fops;
71615 - file_ops->format.owner = mod;
71616 + pax_open_kernel();
71617 + *(void **)&mod->trace_id.owner = mod;
71618 + *(void **)&mod->trace_enable.owner = mod;
71619 + *(void **)&mod->trace_filter.owner = mod;
71620 + *(void **)&mod->trace_format.owner = mod;
71621 + pax_close_kernel();
71622
71623 list_add(&file_ops->list, &ftrace_module_file_list);
71624
71625 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
71626
71627 for_each_event(call, start, end) {
71628 __trace_add_event_call(*call, mod,
71629 - &file_ops->id, &file_ops->enable,
71630 - &file_ops->filter, &file_ops->format);
71631 + &mod->trace_id, &mod->trace_enable,
71632 + &mod->trace_filter, &mod->trace_format);
71633 }
71634 }
71635
71636 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71637 index fd3c8aa..5f324a6 100644
71638 --- a/kernel/trace/trace_mmiotrace.c
71639 +++ b/kernel/trace/trace_mmiotrace.c
71640 @@ -24,7 +24,7 @@ struct header_iter {
71641 static struct trace_array *mmio_trace_array;
71642 static bool overrun_detected;
71643 static unsigned long prev_overruns;
71644 -static atomic_t dropped_count;
71645 +static atomic_unchecked_t dropped_count;
71646
71647 static void mmio_reset_data(struct trace_array *tr)
71648 {
71649 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71650
71651 static unsigned long count_overruns(struct trace_iterator *iter)
71652 {
71653 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71654 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71655 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71656
71657 if (over > prev_overruns)
71658 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71659 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71660 sizeof(*entry), 0, pc);
71661 if (!event) {
71662 - atomic_inc(&dropped_count);
71663 + atomic_inc_unchecked(&dropped_count);
71664 return;
71665 }
71666 entry = ring_buffer_event_data(event);
71667 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71668 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71669 sizeof(*entry), 0, pc);
71670 if (!event) {
71671 - atomic_inc(&dropped_count);
71672 + atomic_inc_unchecked(&dropped_count);
71673 return;
71674 }
71675 entry = ring_buffer_event_data(event);
71676 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71677 index 123b189..97b81f5 100644
71678 --- a/kernel/trace/trace_output.c
71679 +++ b/kernel/trace/trace_output.c
71680 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71681
71682 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71683 if (!IS_ERR(p)) {
71684 - p = mangle_path(s->buffer + s->len, p, "\n");
71685 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71686 if (p) {
71687 s->len = p - s->buffer;
71688 return 1;
71689 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71690 index 0c1b1657..95337e9 100644
71691 --- a/kernel/trace/trace_stack.c
71692 +++ b/kernel/trace/trace_stack.c
71693 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71694 return;
71695
71696 /* we do not handle interrupt stacks yet */
71697 - if (!object_is_on_stack(&this_size))
71698 + if (!object_starts_on_stack(&this_size))
71699 return;
71700
71701 local_irq_save(flags);
71702 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71703 index 28e9d6c9..50381bd 100644
71704 --- a/lib/Kconfig.debug
71705 +++ b/lib/Kconfig.debug
71706 @@ -1278,6 +1278,7 @@ config LATENCYTOP
71707 depends on DEBUG_KERNEL
71708 depends on STACKTRACE_SUPPORT
71709 depends on PROC_FS
71710 + depends on !GRKERNSEC_HIDESYM
71711 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71712 select KALLSYMS
71713 select KALLSYMS_ALL
71714 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
71715
71716 config PROVIDE_OHCI1394_DMA_INIT
71717 bool "Remote debugging over FireWire early on boot"
71718 - depends on PCI && X86
71719 + depends on PCI && X86 && !GRKERNSEC
71720 help
71721 If you want to debug problems which hang or crash the kernel early
71722 on boot and the crashing machine has a FireWire port, you can use
71723 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71724
71725 config FIREWIRE_OHCI_REMOTE_DMA
71726 bool "Remote debugging over FireWire with firewire-ohci"
71727 - depends on FIREWIRE_OHCI
71728 + depends on FIREWIRE_OHCI && !GRKERNSEC
71729 help
71730 This option lets you use the FireWire bus for remote debugging
71731 with help of the firewire-ohci driver. It enables unfiltered
71732 diff --git a/lib/bitmap.c b/lib/bitmap.c
71733 index 06fdfa1..97c5c7d 100644
71734 --- a/lib/bitmap.c
71735 +++ b/lib/bitmap.c
71736 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71737 {
71738 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71739 u32 chunk;
71740 - const char __user __force *ubuf = (const char __user __force *)buf;
71741 + const char __user *ubuf = (const char __force_user *)buf;
71742
71743 bitmap_zero(maskp, nmaskbits);
71744
71745 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71746 {
71747 if (!access_ok(VERIFY_READ, ubuf, ulen))
71748 return -EFAULT;
71749 - return __bitmap_parse((const char __force *)ubuf,
71750 + return __bitmap_parse((const char __force_kernel *)ubuf,
71751 ulen, 1, maskp, nmaskbits);
71752
71753 }
71754 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71755 {
71756 unsigned a, b;
71757 int c, old_c, totaldigits;
71758 - const char __user __force *ubuf = (const char __user __force *)buf;
71759 + const char __user *ubuf = (const char __force_user *)buf;
71760 int exp_digit, in_range;
71761
71762 totaldigits = c = 0;
71763 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71764 {
71765 if (!access_ok(VERIFY_READ, ubuf, ulen))
71766 return -EFAULT;
71767 - return __bitmap_parselist((const char __force *)ubuf,
71768 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71769 ulen, 1, maskp, nmaskbits);
71770 }
71771 EXPORT_SYMBOL(bitmap_parselist_user);
71772 diff --git a/lib/bug.c b/lib/bug.c
71773 index a28c141..2bd3d95 100644
71774 --- a/lib/bug.c
71775 +++ b/lib/bug.c
71776 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71777 return BUG_TRAP_TYPE_NONE;
71778
71779 bug = find_bug(bugaddr);
71780 + if (!bug)
71781 + return BUG_TRAP_TYPE_NONE;
71782
71783 file = NULL;
71784 line = 0;
71785 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71786 index d11808c..dc2d6f8 100644
71787 --- a/lib/debugobjects.c
71788 +++ b/lib/debugobjects.c
71789 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71790 if (limit > 4)
71791 return;
71792
71793 - is_on_stack = object_is_on_stack(addr);
71794 + is_on_stack = object_starts_on_stack(addr);
71795 if (is_on_stack == onstack)
71796 return;
71797
71798 diff --git a/lib/devres.c b/lib/devres.c
71799 index 80b9c76..9e32279 100644
71800 --- a/lib/devres.c
71801 +++ b/lib/devres.c
71802 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71803 void devm_iounmap(struct device *dev, void __iomem *addr)
71804 {
71805 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71806 - (void *)addr));
71807 + (void __force *)addr));
71808 iounmap(addr);
71809 }
71810 EXPORT_SYMBOL(devm_iounmap);
71811 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71812 {
71813 ioport_unmap(addr);
71814 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71815 - devm_ioport_map_match, (void *)addr));
71816 + devm_ioport_map_match, (void __force *)addr));
71817 }
71818 EXPORT_SYMBOL(devm_ioport_unmap);
71819
71820 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71821 index d84beb9..10a4749 100644
71822 --- a/lib/dma-debug.c
71823 +++ b/lib/dma-debug.c
71824 @@ -919,7 +919,7 @@ out:
71825
71826 static void check_for_stack(struct device *dev, void *addr)
71827 {
71828 - if (object_is_on_stack(addr))
71829 + if (object_starts_on_stack(addr))
71830 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71831 "stack [addr=%p]\n", addr);
71832 }
71833 diff --git a/lib/inflate.c b/lib/inflate.c
71834 index 013a761..c28f3fc 100644
71835 --- a/lib/inflate.c
71836 +++ b/lib/inflate.c
71837 @@ -269,7 +269,7 @@ static void free(void *where)
71838 malloc_ptr = free_mem_ptr;
71839 }
71840 #else
71841 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71842 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71843 #define free(a) kfree(a)
71844 #endif
71845
71846 diff --git a/lib/ioremap.c b/lib/ioremap.c
71847 index 0c9216c..863bd89 100644
71848 --- a/lib/ioremap.c
71849 +++ b/lib/ioremap.c
71850 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71851 unsigned long next;
71852
71853 phys_addr -= addr;
71854 - pmd = pmd_alloc(&init_mm, pud, addr);
71855 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71856 if (!pmd)
71857 return -ENOMEM;
71858 do {
71859 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71860 unsigned long next;
71861
71862 phys_addr -= addr;
71863 - pud = pud_alloc(&init_mm, pgd, addr);
71864 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71865 if (!pud)
71866 return -ENOMEM;
71867 do {
71868 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71869 index bd2bea9..6b3c95e 100644
71870 --- a/lib/is_single_threaded.c
71871 +++ b/lib/is_single_threaded.c
71872 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71873 struct task_struct *p, *t;
71874 bool ret;
71875
71876 + if (!mm)
71877 + return true;
71878 +
71879 if (atomic_read(&task->signal->live) != 1)
71880 return false;
71881
71882 diff --git a/lib/list_debug.c b/lib/list_debug.c
71883 index c24c2f7..bef49ee 100644
71884 --- a/lib/list_debug.c
71885 +++ b/lib/list_debug.c
71886 @@ -23,17 +23,19 @@ void __list_add(struct list_head *new,
71887 struct list_head *prev,
71888 struct list_head *next)
71889 {
71890 - WARN(next->prev != prev,
71891 + if (WARN(next->prev != prev,
71892 "list_add corruption. next->prev should be "
71893 "prev (%p), but was %p. (next=%p).\n",
71894 - prev, next->prev, next);
71895 - WARN(prev->next != next,
71896 + prev, next->prev, next) ||
71897 + WARN(prev->next != next,
71898 "list_add corruption. prev->next should be "
71899 "next (%p), but was %p. (prev=%p).\n",
71900 - next, prev->next, prev);
71901 - WARN(new == prev || new == next,
71902 + next, prev->next, prev) ||
71903 + WARN(new == prev || new == next,
71904 "list_add double add: new=%p, prev=%p, next=%p.\n",
71905 - new, prev, next);
71906 + new, prev, next))
71907 + return;
71908 +
71909 next->prev = new;
71910 new->next = next;
71911 new->prev = prev;
71912 @@ -86,12 +88,14 @@ EXPORT_SYMBOL(list_del);
71913 void __list_add_rcu(struct list_head *new,
71914 struct list_head *prev, struct list_head *next)
71915 {
71916 - WARN(next->prev != prev,
71917 + if (WARN(next->prev != prev,
71918 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
71919 - prev, next->prev, next);
71920 - WARN(prev->next != next,
71921 + prev, next->prev, next) ||
71922 + WARN(prev->next != next,
71923 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
71924 - next, prev->next, prev);
71925 + next, prev->next, prev))
71926 + return;
71927 +
71928 new->next = next;
71929 new->prev = prev;
71930 rcu_assign_pointer(list_next_rcu(prev), new);
71931 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71932 index e796429..6e38f9f 100644
71933 --- a/lib/radix-tree.c
71934 +++ b/lib/radix-tree.c
71935 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71936 int nr;
71937 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71938 };
71939 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71940 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71941
71942 static inline void *ptr_to_indirect(void *ptr)
71943 {
71944 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71945 index bb2b201..46abaf9 100644
71946 --- a/lib/strncpy_from_user.c
71947 +++ b/lib/strncpy_from_user.c
71948 @@ -21,7 +21,7 @@
71949 */
71950 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71951 {
71952 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71953 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71954 long res = 0;
71955
71956 /*
71957 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71958 index a28df52..3d55877 100644
71959 --- a/lib/strnlen_user.c
71960 +++ b/lib/strnlen_user.c
71961 @@ -26,7 +26,7 @@
71962 */
71963 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71964 {
71965 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71966 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71967 long align, res = 0;
71968 unsigned long c;
71969
71970 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71971 index 39c99fe..ba3f00d 100644
71972 --- a/lib/vsprintf.c
71973 +++ b/lib/vsprintf.c
71974 @@ -16,6 +16,9 @@
71975 * - scnprintf and vscnprintf
71976 */
71977
71978 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71979 +#define __INCLUDED_BY_HIDESYM 1
71980 +#endif
71981 #include <stdarg.h>
71982 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71983 #include <linux/types.h>
71984 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71985 char sym[KSYM_SYMBOL_LEN];
71986 if (ext == 'B')
71987 sprint_backtrace(sym, value);
71988 - else if (ext != 'f' && ext != 's')
71989 + else if (ext != 'f' && ext != 's' && ext != 'a')
71990 sprint_symbol(sym, value);
71991 else
71992 sprint_symbol_no_offset(sym, value);
71993 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71994 return number(buf, end, *(const netdev_features_t *)addr, spec);
71995 }
71996
71997 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71998 +int kptr_restrict __read_mostly = 2;
71999 +#else
72000 int kptr_restrict __read_mostly;
72001 +#endif
72002
72003 /*
72004 * Show a '%p' thing. A kernel extension is that the '%p' is followed
72005 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
72006 * - 'S' For symbolic direct pointers with offset
72007 * - 's' For symbolic direct pointers without offset
72008 * - 'B' For backtraced symbolic direct pointers with offset
72009 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
72010 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
72011 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
72012 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
72013 * - 'M' For a 6-byte MAC address, it prints the address in the
72014 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72015
72016 if (!ptr && *fmt != 'K') {
72017 /*
72018 - * Print (null) with the same width as a pointer so it makes
72019 + * Print (nil) with the same width as a pointer so it makes
72020 * tabular output look nice.
72021 */
72022 if (spec.field_width == -1)
72023 spec.field_width = default_width;
72024 - return string(buf, end, "(null)", spec);
72025 + return string(buf, end, "(nil)", spec);
72026 }
72027
72028 switch (*fmt) {
72029 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72030 /* Fallthrough */
72031 case 'S':
72032 case 's':
72033 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72034 + break;
72035 +#else
72036 + return symbol_string(buf, end, ptr, spec, *fmt);
72037 +#endif
72038 + case 'A':
72039 + case 'a':
72040 case 'B':
72041 return symbol_string(buf, end, ptr, spec, *fmt);
72042 case 'R':
72043 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72044 va_end(va);
72045 return buf;
72046 }
72047 + case 'P':
72048 + break;
72049 case 'K':
72050 /*
72051 * %pK cannot be used in IRQ context because its test
72052 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
72053 }
72054 break;
72055 }
72056 +
72057 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72058 + /* 'P' = approved pointers to copy to userland,
72059 + as in the /proc/kallsyms case, as we make it display nothing
72060 + for non-root users, and the real contents for root users
72061 + Also ignore 'K' pointers, since we force their NULLing for non-root users
72062 + above
72063 + */
72064 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
72065 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
72066 + dump_stack();
72067 + ptr = NULL;
72068 + }
72069 +#endif
72070 +
72071 spec.flags |= SMALL;
72072 if (spec.field_width == -1) {
72073 spec.field_width = default_width;
72074 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72075 typeof(type) value; \
72076 if (sizeof(type) == 8) { \
72077 args = PTR_ALIGN(args, sizeof(u32)); \
72078 - *(u32 *)&value = *(u32 *)args; \
72079 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
72080 + *(u32 *)&value = *(const u32 *)args; \
72081 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
72082 } else { \
72083 args = PTR_ALIGN(args, sizeof(type)); \
72084 - value = *(typeof(type) *)args; \
72085 + value = *(const typeof(type) *)args; \
72086 } \
72087 args += sizeof(type); \
72088 value; \
72089 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
72090 case FORMAT_TYPE_STR: {
72091 const char *str_arg = args;
72092 args += strlen(str_arg) + 1;
72093 - str = string(str, end, (char *)str_arg, spec);
72094 + str = string(str, end, str_arg, spec);
72095 break;
72096 }
72097
72098 diff --git a/localversion-grsec b/localversion-grsec
72099 new file mode 100644
72100 index 0000000..7cd6065
72101 --- /dev/null
72102 +++ b/localversion-grsec
72103 @@ -0,0 +1 @@
72104 +-grsec
72105 diff --git a/mm/Kconfig b/mm/Kconfig
72106 index a3f8ddd..f31e92e 100644
72107 --- a/mm/Kconfig
72108 +++ b/mm/Kconfig
72109 @@ -252,10 +252,10 @@ config KSM
72110 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
72111
72112 config DEFAULT_MMAP_MIN_ADDR
72113 - int "Low address space to protect from user allocation"
72114 + int "Low address space to protect from user allocation"
72115 depends on MMU
72116 - default 4096
72117 - help
72118 + default 65536
72119 + help
72120 This is the portion of low virtual memory which should be protected
72121 from userspace allocation. Keeping a user from writing to low pages
72122 can help reduce the impact of kernel NULL pointer bugs.
72123 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
72124
72125 config HWPOISON_INJECT
72126 tristate "HWPoison pages injector"
72127 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
72128 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
72129 select PROC_PAGE_MONITOR
72130
72131 config NOMMU_INITIAL_TRIM_EXCESS
72132 diff --git a/mm/filemap.c b/mm/filemap.c
72133 index 83efee7..3f99381 100644
72134 --- a/mm/filemap.c
72135 +++ b/mm/filemap.c
72136 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
72137 struct address_space *mapping = file->f_mapping;
72138
72139 if (!mapping->a_ops->readpage)
72140 - return -ENOEXEC;
72141 + return -ENODEV;
72142 file_accessed(file);
72143 vma->vm_ops = &generic_file_vm_ops;
72144 return 0;
72145 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
72146 *pos = i_size_read(inode);
72147
72148 if (limit != RLIM_INFINITY) {
72149 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
72150 if (*pos >= limit) {
72151 send_sig(SIGXFSZ, current, 0);
72152 return -EFBIG;
72153 diff --git a/mm/fremap.c b/mm/fremap.c
72154 index a0aaf0e..20325c3 100644
72155 --- a/mm/fremap.c
72156 +++ b/mm/fremap.c
72157 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
72158 retry:
72159 vma = find_vma(mm, start);
72160
72161 +#ifdef CONFIG_PAX_SEGMEXEC
72162 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
72163 + goto out;
72164 +#endif
72165 +
72166 /*
72167 * Make sure the vma is shared, that it supports prefaulting,
72168 * and that the remapped range is valid and fully within
72169 diff --git a/mm/highmem.c b/mm/highmem.c
72170 index 2da13a5..9568fec 100644
72171 --- a/mm/highmem.c
72172 +++ b/mm/highmem.c
72173 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
72174 * So no dangers, even with speculative execution.
72175 */
72176 page = pte_page(pkmap_page_table[i]);
72177 + pax_open_kernel();
72178 pte_clear(&init_mm, (unsigned long)page_address(page),
72179 &pkmap_page_table[i]);
72180 -
72181 + pax_close_kernel();
72182 set_page_address(page, NULL);
72183 need_flush = 1;
72184 }
72185 @@ -198,9 +199,11 @@ start:
72186 }
72187 }
72188 vaddr = PKMAP_ADDR(last_pkmap_nr);
72189 +
72190 + pax_open_kernel();
72191 set_pte_at(&init_mm, vaddr,
72192 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
72193 -
72194 + pax_close_kernel();
72195 pkmap_count[last_pkmap_nr] = 1;
72196 set_page_address(page, (void *)vaddr);
72197
72198 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
72199 index 40f17c3..c1cc011 100644
72200 --- a/mm/huge_memory.c
72201 +++ b/mm/huge_memory.c
72202 @@ -710,7 +710,7 @@ out:
72203 * run pte_offset_map on the pmd, if an huge pmd could
72204 * materialize from under us from a different thread.
72205 */
72206 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
72207 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72208 return VM_FAULT_OOM;
72209 /* if an huge pmd materialized from under us just retry later */
72210 if (unlikely(pmd_trans_huge(*pmd)))
72211 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
72212 index 59a0059..b3f3d86 100644
72213 --- a/mm/hugetlb.c
72214 +++ b/mm/hugetlb.c
72215 @@ -2518,6 +2518,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
72216 return 1;
72217 }
72218
72219 +#ifdef CONFIG_PAX_SEGMEXEC
72220 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
72221 +{
72222 + struct mm_struct *mm = vma->vm_mm;
72223 + struct vm_area_struct *vma_m;
72224 + unsigned long address_m;
72225 + pte_t *ptep_m;
72226 +
72227 + vma_m = pax_find_mirror_vma(vma);
72228 + if (!vma_m)
72229 + return;
72230 +
72231 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72232 + address_m = address + SEGMEXEC_TASK_SIZE;
72233 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
72234 + get_page(page_m);
72235 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
72236 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
72237 +}
72238 +#endif
72239 +
72240 /*
72241 * Hugetlb_cow() should be called with page lock of the original hugepage held.
72242 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
72243 @@ -2636,6 +2657,11 @@ retry_avoidcopy:
72244 make_huge_pte(vma, new_page, 1));
72245 page_remove_rmap(old_page);
72246 hugepage_add_new_anon_rmap(new_page, vma, address);
72247 +
72248 +#ifdef CONFIG_PAX_SEGMEXEC
72249 + pax_mirror_huge_pte(vma, address, new_page);
72250 +#endif
72251 +
72252 /* Make the old page be freed below */
72253 new_page = old_page;
72254 }
72255 @@ -2795,6 +2821,10 @@ retry:
72256 && (vma->vm_flags & VM_SHARED)));
72257 set_huge_pte_at(mm, address, ptep, new_pte);
72258
72259 +#ifdef CONFIG_PAX_SEGMEXEC
72260 + pax_mirror_huge_pte(vma, address, page);
72261 +#endif
72262 +
72263 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
72264 /* Optimization, do the COW without a second fault */
72265 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
72266 @@ -2824,6 +2854,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72267 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
72268 struct hstate *h = hstate_vma(vma);
72269
72270 +#ifdef CONFIG_PAX_SEGMEXEC
72271 + struct vm_area_struct *vma_m;
72272 +#endif
72273 +
72274 address &= huge_page_mask(h);
72275
72276 ptep = huge_pte_offset(mm, address);
72277 @@ -2837,6 +2871,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72278 VM_FAULT_SET_HINDEX(hstate_index(h));
72279 }
72280
72281 +#ifdef CONFIG_PAX_SEGMEXEC
72282 + vma_m = pax_find_mirror_vma(vma);
72283 + if (vma_m) {
72284 + unsigned long address_m;
72285 +
72286 + if (vma->vm_start > vma_m->vm_start) {
72287 + address_m = address;
72288 + address -= SEGMEXEC_TASK_SIZE;
72289 + vma = vma_m;
72290 + h = hstate_vma(vma);
72291 + } else
72292 + address_m = address + SEGMEXEC_TASK_SIZE;
72293 +
72294 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
72295 + return VM_FAULT_OOM;
72296 + address_m &= HPAGE_MASK;
72297 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
72298 + }
72299 +#endif
72300 +
72301 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
72302 if (!ptep)
72303 return VM_FAULT_OOM;
72304 diff --git a/mm/internal.h b/mm/internal.h
72305 index a4fa284..9a02499 100644
72306 --- a/mm/internal.h
72307 +++ b/mm/internal.h
72308 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
72309 * in mm/page_alloc.c
72310 */
72311 extern void __free_pages_bootmem(struct page *page, unsigned int order);
72312 +extern void free_compound_page(struct page *page);
72313 extern void prep_compound_page(struct page *page, unsigned long order);
72314 #ifdef CONFIG_MEMORY_FAILURE
72315 extern bool is_free_buddy_page(struct page *page);
72316 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
72317 index a217cc5..74c9ec0 100644
72318 --- a/mm/kmemleak.c
72319 +++ b/mm/kmemleak.c
72320 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
72321
72322 for (i = 0; i < object->trace_len; i++) {
72323 void *ptr = (void *)object->trace[i];
72324 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
72325 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
72326 }
72327 }
72328
72329 diff --git a/mm/maccess.c b/mm/maccess.c
72330 index d53adf9..03a24bf 100644
72331 --- a/mm/maccess.c
72332 +++ b/mm/maccess.c
72333 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
72334 set_fs(KERNEL_DS);
72335 pagefault_disable();
72336 ret = __copy_from_user_inatomic(dst,
72337 - (__force const void __user *)src, size);
72338 + (const void __force_user *)src, size);
72339 pagefault_enable();
72340 set_fs(old_fs);
72341
72342 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
72343
72344 set_fs(KERNEL_DS);
72345 pagefault_disable();
72346 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
72347 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
72348 pagefault_enable();
72349 set_fs(old_fs);
72350
72351 diff --git a/mm/madvise.c b/mm/madvise.c
72352 index 03dfa5c..b032917 100644
72353 --- a/mm/madvise.c
72354 +++ b/mm/madvise.c
72355 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
72356 pgoff_t pgoff;
72357 unsigned long new_flags = vma->vm_flags;
72358
72359 +#ifdef CONFIG_PAX_SEGMEXEC
72360 + struct vm_area_struct *vma_m;
72361 +#endif
72362 +
72363 switch (behavior) {
72364 case MADV_NORMAL:
72365 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
72366 @@ -123,6 +127,13 @@ success:
72367 /*
72368 * vm_flags is protected by the mmap_sem held in write mode.
72369 */
72370 +
72371 +#ifdef CONFIG_PAX_SEGMEXEC
72372 + vma_m = pax_find_mirror_vma(vma);
72373 + if (vma_m)
72374 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
72375 +#endif
72376 +
72377 vma->vm_flags = new_flags;
72378
72379 out:
72380 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72381 struct vm_area_struct ** prev,
72382 unsigned long start, unsigned long end)
72383 {
72384 +
72385 +#ifdef CONFIG_PAX_SEGMEXEC
72386 + struct vm_area_struct *vma_m;
72387 +#endif
72388 +
72389 *prev = vma;
72390 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
72391 return -EINVAL;
72392 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
72393 zap_page_range(vma, start, end - start, &details);
72394 } else
72395 zap_page_range(vma, start, end - start, NULL);
72396 +
72397 +#ifdef CONFIG_PAX_SEGMEXEC
72398 + vma_m = pax_find_mirror_vma(vma);
72399 + if (vma_m) {
72400 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
72401 + struct zap_details details = {
72402 + .nonlinear_vma = vma_m,
72403 + .last_index = ULONG_MAX,
72404 + };
72405 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
72406 + } else
72407 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
72408 + }
72409 +#endif
72410 +
72411 return 0;
72412 }
72413
72414 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
72415 if (end < start)
72416 goto out;
72417
72418 +#ifdef CONFIG_PAX_SEGMEXEC
72419 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72420 + if (end > SEGMEXEC_TASK_SIZE)
72421 + goto out;
72422 + } else
72423 +#endif
72424 +
72425 + if (end > TASK_SIZE)
72426 + goto out;
72427 +
72428 error = 0;
72429 if (end == start)
72430 goto out;
72431 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
72432 index 8b20278..05dac18 100644
72433 --- a/mm/memory-failure.c
72434 +++ b/mm/memory-failure.c
72435 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
72436
72437 int sysctl_memory_failure_recovery __read_mostly = 1;
72438
72439 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72440 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
72441
72442 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
72443
72444 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
72445 pfn, t->comm, t->pid);
72446 si.si_signo = SIGBUS;
72447 si.si_errno = 0;
72448 - si.si_addr = (void *)addr;
72449 + si.si_addr = (void __user *)addr;
72450 #ifdef __ARCH_SI_TRAPNO
72451 si.si_trapno = trapno;
72452 #endif
72453 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72454 }
72455
72456 nr_pages = 1 << compound_trans_order(hpage);
72457 - atomic_long_add(nr_pages, &mce_bad_pages);
72458 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
72459
72460 /*
72461 * We need/can do nothing about count=0 pages.
72462 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72463 if (!PageHWPoison(hpage)
72464 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
72465 || (p != hpage && TestSetPageHWPoison(hpage))) {
72466 - atomic_long_sub(nr_pages, &mce_bad_pages);
72467 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72468 return 0;
72469 }
72470 set_page_hwpoison_huge_page(hpage);
72471 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
72472 }
72473 if (hwpoison_filter(p)) {
72474 if (TestClearPageHWPoison(p))
72475 - atomic_long_sub(nr_pages, &mce_bad_pages);
72476 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72477 unlock_page(hpage);
72478 put_page(hpage);
72479 return 0;
72480 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
72481 return 0;
72482 }
72483 if (TestClearPageHWPoison(p))
72484 - atomic_long_sub(nr_pages, &mce_bad_pages);
72485 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72486 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
72487 return 0;
72488 }
72489 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
72490 */
72491 if (TestClearPageHWPoison(page)) {
72492 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
72493 - atomic_long_sub(nr_pages, &mce_bad_pages);
72494 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
72495 freeit = 1;
72496 if (PageHuge(page))
72497 clear_page_hwpoison_huge_page(page);
72498 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
72499 }
72500 done:
72501 if (!PageHWPoison(hpage))
72502 - atomic_long_add(1 << compound_trans_order(hpage),
72503 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72504 &mce_bad_pages);
72505 set_page_hwpoison_huge_page(hpage);
72506 dequeue_hwpoisoned_huge_page(hpage);
72507 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
72508 return ret;
72509
72510 done:
72511 - atomic_long_add(1, &mce_bad_pages);
72512 + atomic_long_add_unchecked(1, &mce_bad_pages);
72513 SetPageHWPoison(page);
72514 /* keep elevated page count for bad page */
72515 return ret;
72516 diff --git a/mm/memory.c b/mm/memory.c
72517 index 221fc9f..d1d4db1 100644
72518 --- a/mm/memory.c
72519 +++ b/mm/memory.c
72520 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72521 free_pte_range(tlb, pmd, addr);
72522 } while (pmd++, addr = next, addr != end);
72523
72524 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72525 start &= PUD_MASK;
72526 if (start < floor)
72527 return;
72528 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72529 pmd = pmd_offset(pud, start);
72530 pud_clear(pud);
72531 pmd_free_tlb(tlb, pmd, start);
72532 +#endif
72533 +
72534 }
72535
72536 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72537 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72538 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72539 } while (pud++, addr = next, addr != end);
72540
72541 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72542 start &= PGDIR_MASK;
72543 if (start < floor)
72544 return;
72545 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72546 pud = pud_offset(pgd, start);
72547 pgd_clear(pgd);
72548 pud_free_tlb(tlb, pud, start);
72549 +#endif
72550 +
72551 }
72552
72553 /*
72554 @@ -1621,12 +1627,6 @@ no_page_table:
72555 return page;
72556 }
72557
72558 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72559 -{
72560 - return stack_guard_page_start(vma, addr) ||
72561 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72562 -}
72563 -
72564 /**
72565 * __get_user_pages() - pin user pages in memory
72566 * @tsk: task_struct of target task
72567 @@ -1699,10 +1699,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72568 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72569 i = 0;
72570
72571 - do {
72572 + while (nr_pages) {
72573 struct vm_area_struct *vma;
72574
72575 - vma = find_extend_vma(mm, start);
72576 + vma = find_vma(mm, start);
72577 if (!vma && in_gate_area(mm, start)) {
72578 unsigned long pg = start & PAGE_MASK;
72579 pgd_t *pgd;
72580 @@ -1750,7 +1750,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72581 goto next_page;
72582 }
72583
72584 - if (!vma ||
72585 + if (!vma || start < vma->vm_start ||
72586 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72587 !(vm_flags & vma->vm_flags))
72588 return i ? : -EFAULT;
72589 @@ -1777,11 +1777,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72590 int ret;
72591 unsigned int fault_flags = 0;
72592
72593 - /* For mlock, just skip the stack guard page. */
72594 - if (foll_flags & FOLL_MLOCK) {
72595 - if (stack_guard_page(vma, start))
72596 - goto next_page;
72597 - }
72598 if (foll_flags & FOLL_WRITE)
72599 fault_flags |= FAULT_FLAG_WRITE;
72600 if (nonblocking)
72601 @@ -1855,7 +1850,7 @@ next_page:
72602 start += PAGE_SIZE;
72603 nr_pages--;
72604 } while (nr_pages && start < vma->vm_end);
72605 - } while (nr_pages);
72606 + }
72607 return i;
72608 }
72609 EXPORT_SYMBOL(__get_user_pages);
72610 @@ -2062,6 +2057,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72611 page_add_file_rmap(page);
72612 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72613
72614 +#ifdef CONFIG_PAX_SEGMEXEC
72615 + pax_mirror_file_pte(vma, addr, page, ptl);
72616 +#endif
72617 +
72618 retval = 0;
72619 pte_unmap_unlock(pte, ptl);
72620 return retval;
72621 @@ -2106,9 +2105,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72622 if (!page_count(page))
72623 return -EINVAL;
72624 if (!(vma->vm_flags & VM_MIXEDMAP)) {
72625 +
72626 +#ifdef CONFIG_PAX_SEGMEXEC
72627 + struct vm_area_struct *vma_m;
72628 +#endif
72629 +
72630 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
72631 BUG_ON(vma->vm_flags & VM_PFNMAP);
72632 vma->vm_flags |= VM_MIXEDMAP;
72633 +
72634 +#ifdef CONFIG_PAX_SEGMEXEC
72635 + vma_m = pax_find_mirror_vma(vma);
72636 + if (vma_m)
72637 + vma_m->vm_flags |= VM_MIXEDMAP;
72638 +#endif
72639 +
72640 }
72641 return insert_page(vma, addr, page, vma->vm_page_prot);
72642 }
72643 @@ -2191,6 +2202,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72644 unsigned long pfn)
72645 {
72646 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72647 + BUG_ON(vma->vm_mirror);
72648
72649 if (addr < vma->vm_start || addr >= vma->vm_end)
72650 return -EFAULT;
72651 @@ -2391,7 +2403,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72652
72653 BUG_ON(pud_huge(*pud));
72654
72655 - pmd = pmd_alloc(mm, pud, addr);
72656 + pmd = (mm == &init_mm) ?
72657 + pmd_alloc_kernel(mm, pud, addr) :
72658 + pmd_alloc(mm, pud, addr);
72659 if (!pmd)
72660 return -ENOMEM;
72661 do {
72662 @@ -2411,7 +2425,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72663 unsigned long next;
72664 int err;
72665
72666 - pud = pud_alloc(mm, pgd, addr);
72667 + pud = (mm == &init_mm) ?
72668 + pud_alloc_kernel(mm, pgd, addr) :
72669 + pud_alloc(mm, pgd, addr);
72670 if (!pud)
72671 return -ENOMEM;
72672 do {
72673 @@ -2499,6 +2515,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72674 copy_user_highpage(dst, src, va, vma);
72675 }
72676
72677 +#ifdef CONFIG_PAX_SEGMEXEC
72678 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72679 +{
72680 + struct mm_struct *mm = vma->vm_mm;
72681 + spinlock_t *ptl;
72682 + pte_t *pte, entry;
72683 +
72684 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72685 + entry = *pte;
72686 + if (!pte_present(entry)) {
72687 + if (!pte_none(entry)) {
72688 + BUG_ON(pte_file(entry));
72689 + free_swap_and_cache(pte_to_swp_entry(entry));
72690 + pte_clear_not_present_full(mm, address, pte, 0);
72691 + }
72692 + } else {
72693 + struct page *page;
72694 +
72695 + flush_cache_page(vma, address, pte_pfn(entry));
72696 + entry = ptep_clear_flush(vma, address, pte);
72697 + BUG_ON(pte_dirty(entry));
72698 + page = vm_normal_page(vma, address, entry);
72699 + if (page) {
72700 + update_hiwater_rss(mm);
72701 + if (PageAnon(page))
72702 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72703 + else
72704 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72705 + page_remove_rmap(page);
72706 + page_cache_release(page);
72707 + }
72708 + }
72709 + pte_unmap_unlock(pte, ptl);
72710 +}
72711 +
72712 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72713 + *
72714 + * the ptl of the lower mapped page is held on entry and is not released on exit
72715 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72716 + */
72717 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72718 +{
72719 + struct mm_struct *mm = vma->vm_mm;
72720 + unsigned long address_m;
72721 + spinlock_t *ptl_m;
72722 + struct vm_area_struct *vma_m;
72723 + pmd_t *pmd_m;
72724 + pte_t *pte_m, entry_m;
72725 +
72726 + BUG_ON(!page_m || !PageAnon(page_m));
72727 +
72728 + vma_m = pax_find_mirror_vma(vma);
72729 + if (!vma_m)
72730 + return;
72731 +
72732 + BUG_ON(!PageLocked(page_m));
72733 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72734 + address_m = address + SEGMEXEC_TASK_SIZE;
72735 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72736 + pte_m = pte_offset_map(pmd_m, address_m);
72737 + ptl_m = pte_lockptr(mm, pmd_m);
72738 + if (ptl != ptl_m) {
72739 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72740 + if (!pte_none(*pte_m))
72741 + goto out;
72742 + }
72743 +
72744 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72745 + page_cache_get(page_m);
72746 + page_add_anon_rmap(page_m, vma_m, address_m);
72747 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72748 + set_pte_at(mm, address_m, pte_m, entry_m);
72749 + update_mmu_cache(vma_m, address_m, entry_m);
72750 +out:
72751 + if (ptl != ptl_m)
72752 + spin_unlock(ptl_m);
72753 + pte_unmap(pte_m);
72754 + unlock_page(page_m);
72755 +}
72756 +
72757 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72758 +{
72759 + struct mm_struct *mm = vma->vm_mm;
72760 + unsigned long address_m;
72761 + spinlock_t *ptl_m;
72762 + struct vm_area_struct *vma_m;
72763 + pmd_t *pmd_m;
72764 + pte_t *pte_m, entry_m;
72765 +
72766 + BUG_ON(!page_m || PageAnon(page_m));
72767 +
72768 + vma_m = pax_find_mirror_vma(vma);
72769 + if (!vma_m)
72770 + return;
72771 +
72772 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72773 + address_m = address + SEGMEXEC_TASK_SIZE;
72774 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72775 + pte_m = pte_offset_map(pmd_m, address_m);
72776 + ptl_m = pte_lockptr(mm, pmd_m);
72777 + if (ptl != ptl_m) {
72778 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72779 + if (!pte_none(*pte_m))
72780 + goto out;
72781 + }
72782 +
72783 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72784 + page_cache_get(page_m);
72785 + page_add_file_rmap(page_m);
72786 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72787 + set_pte_at(mm, address_m, pte_m, entry_m);
72788 + update_mmu_cache(vma_m, address_m, entry_m);
72789 +out:
72790 + if (ptl != ptl_m)
72791 + spin_unlock(ptl_m);
72792 + pte_unmap(pte_m);
72793 +}
72794 +
72795 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72796 +{
72797 + struct mm_struct *mm = vma->vm_mm;
72798 + unsigned long address_m;
72799 + spinlock_t *ptl_m;
72800 + struct vm_area_struct *vma_m;
72801 + pmd_t *pmd_m;
72802 + pte_t *pte_m, entry_m;
72803 +
72804 + vma_m = pax_find_mirror_vma(vma);
72805 + if (!vma_m)
72806 + return;
72807 +
72808 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72809 + address_m = address + SEGMEXEC_TASK_SIZE;
72810 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72811 + pte_m = pte_offset_map(pmd_m, address_m);
72812 + ptl_m = pte_lockptr(mm, pmd_m);
72813 + if (ptl != ptl_m) {
72814 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72815 + if (!pte_none(*pte_m))
72816 + goto out;
72817 + }
72818 +
72819 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72820 + set_pte_at(mm, address_m, pte_m, entry_m);
72821 +out:
72822 + if (ptl != ptl_m)
72823 + spin_unlock(ptl_m);
72824 + pte_unmap(pte_m);
72825 +}
72826 +
72827 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72828 +{
72829 + struct page *page_m;
72830 + pte_t entry;
72831 +
72832 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72833 + goto out;
72834 +
72835 + entry = *pte;
72836 + page_m = vm_normal_page(vma, address, entry);
72837 + if (!page_m)
72838 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72839 + else if (PageAnon(page_m)) {
72840 + if (pax_find_mirror_vma(vma)) {
72841 + pte_unmap_unlock(pte, ptl);
72842 + lock_page(page_m);
72843 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72844 + if (pte_same(entry, *pte))
72845 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72846 + else
72847 + unlock_page(page_m);
72848 + }
72849 + } else
72850 + pax_mirror_file_pte(vma, address, page_m, ptl);
72851 +
72852 +out:
72853 + pte_unmap_unlock(pte, ptl);
72854 +}
72855 +#endif
72856 +
72857 /*
72858 * This routine handles present pages, when users try to write
72859 * to a shared page. It is done by copying the page to a new address
72860 @@ -2715,6 +2911,12 @@ gotten:
72861 */
72862 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72863 if (likely(pte_same(*page_table, orig_pte))) {
72864 +
72865 +#ifdef CONFIG_PAX_SEGMEXEC
72866 + if (pax_find_mirror_vma(vma))
72867 + BUG_ON(!trylock_page(new_page));
72868 +#endif
72869 +
72870 if (old_page) {
72871 if (!PageAnon(old_page)) {
72872 dec_mm_counter_fast(mm, MM_FILEPAGES);
72873 @@ -2766,6 +2968,10 @@ gotten:
72874 page_remove_rmap(old_page);
72875 }
72876
72877 +#ifdef CONFIG_PAX_SEGMEXEC
72878 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72879 +#endif
72880 +
72881 /* Free the old page.. */
72882 new_page = old_page;
72883 ret |= VM_FAULT_WRITE;
72884 @@ -3046,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72885 swap_free(entry);
72886 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72887 try_to_free_swap(page);
72888 +
72889 +#ifdef CONFIG_PAX_SEGMEXEC
72890 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72891 +#endif
72892 +
72893 unlock_page(page);
72894 if (swapcache) {
72895 /*
72896 @@ -3069,6 +3280,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72897
72898 /* No need to invalidate - it was non-present before */
72899 update_mmu_cache(vma, address, page_table);
72900 +
72901 +#ifdef CONFIG_PAX_SEGMEXEC
72902 + pax_mirror_anon_pte(vma, address, page, ptl);
72903 +#endif
72904 +
72905 unlock:
72906 pte_unmap_unlock(page_table, ptl);
72907 out:
72908 @@ -3088,40 +3304,6 @@ out_release:
72909 }
72910
72911 /*
72912 - * This is like a special single-page "expand_{down|up}wards()",
72913 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72914 - * doesn't hit another vma.
72915 - */
72916 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72917 -{
72918 - address &= PAGE_MASK;
72919 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72920 - struct vm_area_struct *prev = vma->vm_prev;
72921 -
72922 - /*
72923 - * Is there a mapping abutting this one below?
72924 - *
72925 - * That's only ok if it's the same stack mapping
72926 - * that has gotten split..
72927 - */
72928 - if (prev && prev->vm_end == address)
72929 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72930 -
72931 - expand_downwards(vma, address - PAGE_SIZE);
72932 - }
72933 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72934 - struct vm_area_struct *next = vma->vm_next;
72935 -
72936 - /* As VM_GROWSDOWN but s/below/above/ */
72937 - if (next && next->vm_start == address + PAGE_SIZE)
72938 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72939 -
72940 - expand_upwards(vma, address + PAGE_SIZE);
72941 - }
72942 - return 0;
72943 -}
72944 -
72945 -/*
72946 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72947 * but allow concurrent faults), and pte mapped but not yet locked.
72948 * We return with mmap_sem still held, but pte unmapped and unlocked.
72949 @@ -3130,27 +3312,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72950 unsigned long address, pte_t *page_table, pmd_t *pmd,
72951 unsigned int flags)
72952 {
72953 - struct page *page;
72954 + struct page *page = NULL;
72955 spinlock_t *ptl;
72956 pte_t entry;
72957
72958 - pte_unmap(page_table);
72959 -
72960 - /* Check if we need to add a guard page to the stack */
72961 - if (check_stack_guard_page(vma, address) < 0)
72962 - return VM_FAULT_SIGBUS;
72963 -
72964 - /* Use the zero-page for reads */
72965 if (!(flags & FAULT_FLAG_WRITE)) {
72966 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72967 vma->vm_page_prot));
72968 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72969 + ptl = pte_lockptr(mm, pmd);
72970 + spin_lock(ptl);
72971 if (!pte_none(*page_table))
72972 goto unlock;
72973 goto setpte;
72974 }
72975
72976 /* Allocate our own private page. */
72977 + pte_unmap(page_table);
72978 +
72979 if (unlikely(anon_vma_prepare(vma)))
72980 goto oom;
72981 page = alloc_zeroed_user_highpage_movable(vma, address);
72982 @@ -3169,6 +3347,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72983 if (!pte_none(*page_table))
72984 goto release;
72985
72986 +#ifdef CONFIG_PAX_SEGMEXEC
72987 + if (pax_find_mirror_vma(vma))
72988 + BUG_ON(!trylock_page(page));
72989 +#endif
72990 +
72991 inc_mm_counter_fast(mm, MM_ANONPAGES);
72992 page_add_new_anon_rmap(page, vma, address);
72993 setpte:
72994 @@ -3176,6 +3359,12 @@ setpte:
72995
72996 /* No need to invalidate - it was non-present before */
72997 update_mmu_cache(vma, address, page_table);
72998 +
72999 +#ifdef CONFIG_PAX_SEGMEXEC
73000 + if (page)
73001 + pax_mirror_anon_pte(vma, address, page, ptl);
73002 +#endif
73003 +
73004 unlock:
73005 pte_unmap_unlock(page_table, ptl);
73006 return 0;
73007 @@ -3319,6 +3508,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73008 */
73009 /* Only go through if we didn't race with anybody else... */
73010 if (likely(pte_same(*page_table, orig_pte))) {
73011 +
73012 +#ifdef CONFIG_PAX_SEGMEXEC
73013 + if (anon && pax_find_mirror_vma(vma))
73014 + BUG_ON(!trylock_page(page));
73015 +#endif
73016 +
73017 flush_icache_page(vma, page);
73018 entry = mk_pte(page, vma->vm_page_prot);
73019 if (flags & FAULT_FLAG_WRITE)
73020 @@ -3338,6 +3533,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73021
73022 /* no need to invalidate: a not-present page won't be cached */
73023 update_mmu_cache(vma, address, page_table);
73024 +
73025 +#ifdef CONFIG_PAX_SEGMEXEC
73026 + if (anon)
73027 + pax_mirror_anon_pte(vma, address, page, ptl);
73028 + else
73029 + pax_mirror_file_pte(vma, address, page, ptl);
73030 +#endif
73031 +
73032 } else {
73033 if (cow_page)
73034 mem_cgroup_uncharge_page(cow_page);
73035 @@ -3492,6 +3695,12 @@ int handle_pte_fault(struct mm_struct *mm,
73036 if (flags & FAULT_FLAG_WRITE)
73037 flush_tlb_fix_spurious_fault(vma, address);
73038 }
73039 +
73040 +#ifdef CONFIG_PAX_SEGMEXEC
73041 + pax_mirror_pte(vma, address, pte, pmd, ptl);
73042 + return 0;
73043 +#endif
73044 +
73045 unlock:
73046 pte_unmap_unlock(pte, ptl);
73047 return 0;
73048 @@ -3508,6 +3717,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73049 pmd_t *pmd;
73050 pte_t *pte;
73051
73052 +#ifdef CONFIG_PAX_SEGMEXEC
73053 + struct vm_area_struct *vma_m;
73054 +#endif
73055 +
73056 __set_current_state(TASK_RUNNING);
73057
73058 count_vm_event(PGFAULT);
73059 @@ -3519,6 +3732,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73060 if (unlikely(is_vm_hugetlb_page(vma)))
73061 return hugetlb_fault(mm, vma, address, flags);
73062
73063 +#ifdef CONFIG_PAX_SEGMEXEC
73064 + vma_m = pax_find_mirror_vma(vma);
73065 + if (vma_m) {
73066 + unsigned long address_m;
73067 + pgd_t *pgd_m;
73068 + pud_t *pud_m;
73069 + pmd_t *pmd_m;
73070 +
73071 + if (vma->vm_start > vma_m->vm_start) {
73072 + address_m = address;
73073 + address -= SEGMEXEC_TASK_SIZE;
73074 + vma = vma_m;
73075 + } else
73076 + address_m = address + SEGMEXEC_TASK_SIZE;
73077 +
73078 + pgd_m = pgd_offset(mm, address_m);
73079 + pud_m = pud_alloc(mm, pgd_m, address_m);
73080 + if (!pud_m)
73081 + return VM_FAULT_OOM;
73082 + pmd_m = pmd_alloc(mm, pud_m, address_m);
73083 + if (!pmd_m)
73084 + return VM_FAULT_OOM;
73085 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
73086 + return VM_FAULT_OOM;
73087 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
73088 + }
73089 +#endif
73090 +
73091 retry:
73092 pgd = pgd_offset(mm, address);
73093 pud = pud_alloc(mm, pgd, address);
73094 @@ -3560,7 +3801,7 @@ retry:
73095 * run pte_offset_map on the pmd, if an huge pmd could
73096 * materialize from under us from a different thread.
73097 */
73098 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
73099 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73100 return VM_FAULT_OOM;
73101 /* if an huge pmd materialized from under us just retry later */
73102 if (unlikely(pmd_trans_huge(*pmd)))
73103 @@ -3597,6 +3838,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73104 spin_unlock(&mm->page_table_lock);
73105 return 0;
73106 }
73107 +
73108 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
73109 +{
73110 + pud_t *new = pud_alloc_one(mm, address);
73111 + if (!new)
73112 + return -ENOMEM;
73113 +
73114 + smp_wmb(); /* See comment in __pte_alloc */
73115 +
73116 + spin_lock(&mm->page_table_lock);
73117 + if (pgd_present(*pgd)) /* Another has populated it */
73118 + pud_free(mm, new);
73119 + else
73120 + pgd_populate_kernel(mm, pgd, new);
73121 + spin_unlock(&mm->page_table_lock);
73122 + return 0;
73123 +}
73124 #endif /* __PAGETABLE_PUD_FOLDED */
73125
73126 #ifndef __PAGETABLE_PMD_FOLDED
73127 @@ -3627,6 +3885,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
73128 spin_unlock(&mm->page_table_lock);
73129 return 0;
73130 }
73131 +
73132 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
73133 +{
73134 + pmd_t *new = pmd_alloc_one(mm, address);
73135 + if (!new)
73136 + return -ENOMEM;
73137 +
73138 + smp_wmb(); /* See comment in __pte_alloc */
73139 +
73140 + spin_lock(&mm->page_table_lock);
73141 +#ifndef __ARCH_HAS_4LEVEL_HACK
73142 + if (pud_present(*pud)) /* Another has populated it */
73143 + pmd_free(mm, new);
73144 + else
73145 + pud_populate_kernel(mm, pud, new);
73146 +#else
73147 + if (pgd_present(*pud)) /* Another has populated it */
73148 + pmd_free(mm, new);
73149 + else
73150 + pgd_populate_kernel(mm, pud, new);
73151 +#endif /* __ARCH_HAS_4LEVEL_HACK */
73152 + spin_unlock(&mm->page_table_lock);
73153 + return 0;
73154 +}
73155 #endif /* __PAGETABLE_PMD_FOLDED */
73156
73157 int make_pages_present(unsigned long addr, unsigned long end)
73158 @@ -3664,7 +3946,7 @@ static int __init gate_vma_init(void)
73159 gate_vma.vm_start = FIXADDR_USER_START;
73160 gate_vma.vm_end = FIXADDR_USER_END;
73161 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
73162 - gate_vma.vm_page_prot = __P101;
73163 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
73164
73165 return 0;
73166 }
73167 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
73168 index 4ea600d..1cd61c2 100644
73169 --- a/mm/mempolicy.c
73170 +++ b/mm/mempolicy.c
73171 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73172 unsigned long vmstart;
73173 unsigned long vmend;
73174
73175 +#ifdef CONFIG_PAX_SEGMEXEC
73176 + struct vm_area_struct *vma_m;
73177 +#endif
73178 +
73179 vma = find_vma(mm, start);
73180 if (!vma || vma->vm_start > start)
73181 return -EFAULT;
73182 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
73183 if (err)
73184 goto out;
73185 }
73186 +
73187 err = vma_replace_policy(vma, new_pol);
73188 if (err)
73189 goto out;
73190 +
73191 +#ifdef CONFIG_PAX_SEGMEXEC
73192 + vma_m = pax_find_mirror_vma(vma);
73193 + if (vma_m) {
73194 + err = vma_replace_policy(vma_m, new_pol);
73195 + if (err)
73196 + goto out;
73197 + }
73198 +#endif
73199 +
73200 }
73201
73202 out:
73203 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
73204
73205 if (end < start)
73206 return -EINVAL;
73207 +
73208 +#ifdef CONFIG_PAX_SEGMEXEC
73209 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73210 + if (end > SEGMEXEC_TASK_SIZE)
73211 + return -EINVAL;
73212 + } else
73213 +#endif
73214 +
73215 + if (end > TASK_SIZE)
73216 + return -EINVAL;
73217 +
73218 if (end == start)
73219 return 0;
73220
73221 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73222 */
73223 tcred = __task_cred(task);
73224 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73225 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73226 - !capable(CAP_SYS_NICE)) {
73227 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73228 rcu_read_unlock();
73229 err = -EPERM;
73230 goto out_put;
73231 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
73232 goto out;
73233 }
73234
73235 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
73236 + if (mm != current->mm &&
73237 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
73238 + mmput(mm);
73239 + err = -EPERM;
73240 + goto out;
73241 + }
73242 +#endif
73243 +
73244 err = do_migrate_pages(mm, old, new,
73245 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
73246
73247 diff --git a/mm/migrate.c b/mm/migrate.c
73248 index 77ed2d7..317d528 100644
73249 --- a/mm/migrate.c
73250 +++ b/mm/migrate.c
73251 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
73252 */
73253 tcred = __task_cred(task);
73254 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
73255 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
73256 - !capable(CAP_SYS_NICE)) {
73257 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
73258 rcu_read_unlock();
73259 err = -EPERM;
73260 goto out;
73261 diff --git a/mm/mlock.c b/mm/mlock.c
73262 index f0b9ce5..da8d069 100644
73263 --- a/mm/mlock.c
73264 +++ b/mm/mlock.c
73265 @@ -13,6 +13,7 @@
73266 #include <linux/pagemap.h>
73267 #include <linux/mempolicy.h>
73268 #include <linux/syscalls.h>
73269 +#include <linux/security.h>
73270 #include <linux/sched.h>
73271 #include <linux/export.h>
73272 #include <linux/rmap.h>
73273 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
73274 {
73275 unsigned long nstart, end, tmp;
73276 struct vm_area_struct * vma, * prev;
73277 - int error;
73278 + int error = 0;
73279
73280 VM_BUG_ON(start & ~PAGE_MASK);
73281 VM_BUG_ON(len != PAGE_ALIGN(len));
73282 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
73283 return -EINVAL;
73284 if (end == start)
73285 return 0;
73286 + if (end > TASK_SIZE)
73287 + return -EINVAL;
73288 +
73289 vma = find_vma(current->mm, start);
73290 if (!vma || vma->vm_start > start)
73291 return -ENOMEM;
73292 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
73293 for (nstart = start ; ; ) {
73294 vm_flags_t newflags;
73295
73296 +#ifdef CONFIG_PAX_SEGMEXEC
73297 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73298 + break;
73299 +#endif
73300 +
73301 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
73302
73303 newflags = vma->vm_flags | VM_LOCKED;
73304 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
73305 lock_limit >>= PAGE_SHIFT;
73306
73307 /* check against resource limits */
73308 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
73309 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
73310 error = do_mlock(start, len, 1);
73311 up_write(&current->mm->mmap_sem);
73312 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
73313 static int do_mlockall(int flags)
73314 {
73315 struct vm_area_struct * vma, * prev = NULL;
73316 - unsigned int def_flags = 0;
73317
73318 if (flags & MCL_FUTURE)
73319 - def_flags = VM_LOCKED;
73320 - current->mm->def_flags = def_flags;
73321 + current->mm->def_flags |= VM_LOCKED;
73322 + else
73323 + current->mm->def_flags &= ~VM_LOCKED;
73324 if (flags == MCL_FUTURE)
73325 goto out;
73326
73327 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
73328 vm_flags_t newflags;
73329
73330 +#ifdef CONFIG_PAX_SEGMEXEC
73331 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
73332 + break;
73333 +#endif
73334 +
73335 + BUG_ON(vma->vm_end > TASK_SIZE);
73336 newflags = vma->vm_flags | VM_LOCKED;
73337 if (!(flags & MCL_CURRENT))
73338 newflags &= ~VM_LOCKED;
73339 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
73340 lock_limit >>= PAGE_SHIFT;
73341
73342 ret = -ENOMEM;
73343 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
73344 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
73345 capable(CAP_IPC_LOCK))
73346 ret = do_mlockall(flags);
73347 diff --git a/mm/mmap.c b/mm/mmap.c
73348 index 9a796c4..4fba820 100644
73349 --- a/mm/mmap.c
73350 +++ b/mm/mmap.c
73351 @@ -47,6 +47,16 @@
73352 #define arch_rebalance_pgtables(addr, len) (addr)
73353 #endif
73354
73355 +static inline void verify_mm_writelocked(struct mm_struct *mm)
73356 +{
73357 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
73358 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73359 + up_read(&mm->mmap_sem);
73360 + BUG();
73361 + }
73362 +#endif
73363 +}
73364 +
73365 static void unmap_region(struct mm_struct *mm,
73366 struct vm_area_struct *vma, struct vm_area_struct *prev,
73367 unsigned long start, unsigned long end);
73368 @@ -66,22 +76,32 @@ static void unmap_region(struct mm_struct *mm,
73369 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
73370 *
73371 */
73372 -pgprot_t protection_map[16] = {
73373 +pgprot_t protection_map[16] __read_only = {
73374 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
73375 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
73376 };
73377
73378 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
73379 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
73380 {
73381 - return __pgprot(pgprot_val(protection_map[vm_flags &
73382 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
73383 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
73384 pgprot_val(arch_vm_get_page_prot(vm_flags)));
73385 +
73386 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73387 + if (!(__supported_pte_mask & _PAGE_NX) &&
73388 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
73389 + (vm_flags & (VM_READ | VM_WRITE)))
73390 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
73391 +#endif
73392 +
73393 + return prot;
73394 }
73395 EXPORT_SYMBOL(vm_get_page_prot);
73396
73397 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
73398 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
73399 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
73400 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
73401 /*
73402 * Make sure vm_committed_as in one cacheline and not cacheline shared with
73403 * other variables. It can be updated by several CPUs frequently.
73404 @@ -223,6 +243,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
73405 struct vm_area_struct *next = vma->vm_next;
73406
73407 might_sleep();
73408 + BUG_ON(vma->vm_mirror);
73409 if (vma->vm_ops && vma->vm_ops->close)
73410 vma->vm_ops->close(vma);
73411 if (vma->vm_file)
73412 @@ -266,6 +287,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
73413 * not page aligned -Ram Gupta
73414 */
73415 rlim = rlimit(RLIMIT_DATA);
73416 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
73417 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
73418 (mm->end_data - mm->start_data) > rlim)
73419 goto out;
73420 @@ -736,6 +758,12 @@ static int
73421 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
73422 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73423 {
73424 +
73425 +#ifdef CONFIG_PAX_SEGMEXEC
73426 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
73427 + return 0;
73428 +#endif
73429 +
73430 if (is_mergeable_vma(vma, file, vm_flags) &&
73431 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73432 if (vma->vm_pgoff == vm_pgoff)
73433 @@ -755,6 +783,12 @@ static int
73434 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73435 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
73436 {
73437 +
73438 +#ifdef CONFIG_PAX_SEGMEXEC
73439 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
73440 + return 0;
73441 +#endif
73442 +
73443 if (is_mergeable_vma(vma, file, vm_flags) &&
73444 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
73445 pgoff_t vm_pglen;
73446 @@ -797,13 +831,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
73447 struct vm_area_struct *vma_merge(struct mm_struct *mm,
73448 struct vm_area_struct *prev, unsigned long addr,
73449 unsigned long end, unsigned long vm_flags,
73450 - struct anon_vma *anon_vma, struct file *file,
73451 + struct anon_vma *anon_vma, struct file *file,
73452 pgoff_t pgoff, struct mempolicy *policy)
73453 {
73454 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
73455 struct vm_area_struct *area, *next;
73456 int err;
73457
73458 +#ifdef CONFIG_PAX_SEGMEXEC
73459 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
73460 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
73461 +
73462 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
73463 +#endif
73464 +
73465 /*
73466 * We later require that vma->vm_flags == vm_flags,
73467 * so this tests vma->vm_flags & VM_SPECIAL, too.
73468 @@ -819,6 +860,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73469 if (next && next->vm_end == end) /* cases 6, 7, 8 */
73470 next = next->vm_next;
73471
73472 +#ifdef CONFIG_PAX_SEGMEXEC
73473 + if (prev)
73474 + prev_m = pax_find_mirror_vma(prev);
73475 + if (area)
73476 + area_m = pax_find_mirror_vma(area);
73477 + if (next)
73478 + next_m = pax_find_mirror_vma(next);
73479 +#endif
73480 +
73481 /*
73482 * Can it merge with the predecessor?
73483 */
73484 @@ -838,9 +888,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73485 /* cases 1, 6 */
73486 err = vma_adjust(prev, prev->vm_start,
73487 next->vm_end, prev->vm_pgoff, NULL);
73488 - } else /* cases 2, 5, 7 */
73489 +
73490 +#ifdef CONFIG_PAX_SEGMEXEC
73491 + if (!err && prev_m)
73492 + err = vma_adjust(prev_m, prev_m->vm_start,
73493 + next_m->vm_end, prev_m->vm_pgoff, NULL);
73494 +#endif
73495 +
73496 + } else { /* cases 2, 5, 7 */
73497 err = vma_adjust(prev, prev->vm_start,
73498 end, prev->vm_pgoff, NULL);
73499 +
73500 +#ifdef CONFIG_PAX_SEGMEXEC
73501 + if (!err && prev_m)
73502 + err = vma_adjust(prev_m, prev_m->vm_start,
73503 + end_m, prev_m->vm_pgoff, NULL);
73504 +#endif
73505 +
73506 + }
73507 if (err)
73508 return NULL;
73509 khugepaged_enter_vma_merge(prev);
73510 @@ -854,12 +919,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73511 mpol_equal(policy, vma_policy(next)) &&
73512 can_vma_merge_before(next, vm_flags,
73513 anon_vma, file, pgoff+pglen)) {
73514 - if (prev && addr < prev->vm_end) /* case 4 */
73515 + if (prev && addr < prev->vm_end) { /* case 4 */
73516 err = vma_adjust(prev, prev->vm_start,
73517 addr, prev->vm_pgoff, NULL);
73518 - else /* cases 3, 8 */
73519 +
73520 +#ifdef CONFIG_PAX_SEGMEXEC
73521 + if (!err && prev_m)
73522 + err = vma_adjust(prev_m, prev_m->vm_start,
73523 + addr_m, prev_m->vm_pgoff, NULL);
73524 +#endif
73525 +
73526 + } else { /* cases 3, 8 */
73527 err = vma_adjust(area, addr, next->vm_end,
73528 next->vm_pgoff - pglen, NULL);
73529 +
73530 +#ifdef CONFIG_PAX_SEGMEXEC
73531 + if (!err && area_m)
73532 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73533 + next_m->vm_pgoff - pglen, NULL);
73534 +#endif
73535 +
73536 + }
73537 if (err)
73538 return NULL;
73539 khugepaged_enter_vma_merge(area);
73540 @@ -968,16 +1048,13 @@ none:
73541 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73542 struct file *file, long pages)
73543 {
73544 - const unsigned long stack_flags
73545 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73546 -
73547 mm->total_vm += pages;
73548
73549 if (file) {
73550 mm->shared_vm += pages;
73551 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73552 mm->exec_vm += pages;
73553 - } else if (flags & stack_flags)
73554 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73555 mm->stack_vm += pages;
73556 }
73557 #endif /* CONFIG_PROC_FS */
73558 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73559 * (the exception is when the underlying filesystem is noexec
73560 * mounted, in which case we dont add PROT_EXEC.)
73561 */
73562 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73563 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73564 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73565 prot |= PROT_EXEC;
73566
73567 @@ -1039,7 +1116,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73568 /* Obtain the address to map to. we verify (or select) it and ensure
73569 * that it represents a valid section of the address space.
73570 */
73571 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73572 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73573 if (addr & ~PAGE_MASK)
73574 return addr;
73575
73576 @@ -1050,6 +1127,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73577 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73578 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73579
73580 +#ifdef CONFIG_PAX_MPROTECT
73581 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73582 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73583 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73584 + gr_log_rwxmmap(file);
73585 +
73586 +#ifdef CONFIG_PAX_EMUPLT
73587 + vm_flags &= ~VM_EXEC;
73588 +#else
73589 + return -EPERM;
73590 +#endif
73591 +
73592 + }
73593 +
73594 + if (!(vm_flags & VM_EXEC))
73595 + vm_flags &= ~VM_MAYEXEC;
73596 +#else
73597 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73598 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73599 +#endif
73600 + else
73601 + vm_flags &= ~VM_MAYWRITE;
73602 + }
73603 +#endif
73604 +
73605 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73606 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73607 + vm_flags &= ~VM_PAGEEXEC;
73608 +#endif
73609 +
73610 if (flags & MAP_LOCKED)
73611 if (!can_do_mlock())
73612 return -EPERM;
73613 @@ -1061,6 +1168,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73614 locked += mm->locked_vm;
73615 lock_limit = rlimit(RLIMIT_MEMLOCK);
73616 lock_limit >>= PAGE_SHIFT;
73617 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73618 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73619 return -EAGAIN;
73620 }
73621 @@ -1127,6 +1235,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73622 }
73623 }
73624
73625 + if (!gr_acl_handle_mmap(file, prot))
73626 + return -EACCES;
73627 +
73628 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73629 }
73630
73631 @@ -1203,7 +1314,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73632 vm_flags_t vm_flags = vma->vm_flags;
73633
73634 /* If it was private or non-writable, the write bit is already clear */
73635 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73636 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73637 return 0;
73638
73639 /* The backer wishes to know when pages are first written to? */
73640 @@ -1252,13 +1363,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73641 unsigned long charged = 0;
73642 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73643
73644 +#ifdef CONFIG_PAX_SEGMEXEC
73645 + struct vm_area_struct *vma_m = NULL;
73646 +#endif
73647 +
73648 + /*
73649 + * mm->mmap_sem is required to protect against another thread
73650 + * changing the mappings in case we sleep.
73651 + */
73652 + verify_mm_writelocked(mm);
73653 +
73654 /* Clear old maps */
73655 error = -ENOMEM;
73656 -munmap_back:
73657 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
73658 if (do_munmap(mm, addr, len))
73659 return -ENOMEM;
73660 - goto munmap_back;
73661 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
73662 }
73663
73664 /* Check against address space limit. */
73665 @@ -1307,6 +1427,16 @@ munmap_back:
73666 goto unacct_error;
73667 }
73668
73669 +#ifdef CONFIG_PAX_SEGMEXEC
73670 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73671 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73672 + if (!vma_m) {
73673 + error = -ENOMEM;
73674 + goto free_vma;
73675 + }
73676 + }
73677 +#endif
73678 +
73679 vma->vm_mm = mm;
73680 vma->vm_start = addr;
73681 vma->vm_end = addr + len;
73682 @@ -1331,6 +1461,13 @@ munmap_back:
73683 if (error)
73684 goto unmap_and_free_vma;
73685
73686 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73687 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73688 + vma->vm_flags |= VM_PAGEEXEC;
73689 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73690 + }
73691 +#endif
73692 +
73693 /* Can addr have changed??
73694 *
73695 * Answer: Yes, several device drivers can do it in their
73696 @@ -1365,6 +1502,11 @@ munmap_back:
73697 vma_link(mm, vma, prev, rb_link, rb_parent);
73698 file = vma->vm_file;
73699
73700 +#ifdef CONFIG_PAX_SEGMEXEC
73701 + if (vma_m)
73702 + BUG_ON(pax_mirror_vma(vma_m, vma));
73703 +#endif
73704 +
73705 /* Once vma denies write, undo our temporary denial count */
73706 if (correct_wcount)
73707 atomic_inc(&inode->i_writecount);
73708 @@ -1372,6 +1514,7 @@ out:
73709 perf_event_mmap(vma);
73710
73711 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73712 + track_exec_limit(mm, addr, addr + len, vm_flags);
73713 if (vm_flags & VM_LOCKED) {
73714 if (!mlock_vma_pages_range(vma, addr, addr + len))
73715 mm->locked_vm += (len >> PAGE_SHIFT);
73716 @@ -1393,6 +1536,12 @@ unmap_and_free_vma:
73717 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73718 charged = 0;
73719 free_vma:
73720 +
73721 +#ifdef CONFIG_PAX_SEGMEXEC
73722 + if (vma_m)
73723 + kmem_cache_free(vm_area_cachep, vma_m);
73724 +#endif
73725 +
73726 kmem_cache_free(vm_area_cachep, vma);
73727 unacct_error:
73728 if (charged)
73729 @@ -1400,6 +1549,44 @@ unacct_error:
73730 return error;
73731 }
73732
73733 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73734 +{
73735 + if (!vma) {
73736 +#ifdef CONFIG_STACK_GROWSUP
73737 + if (addr > sysctl_heap_stack_gap)
73738 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73739 + else
73740 + vma = find_vma(current->mm, 0);
73741 + if (vma && (vma->vm_flags & VM_GROWSUP))
73742 + return false;
73743 +#endif
73744 + return true;
73745 + }
73746 +
73747 + if (addr + len > vma->vm_start)
73748 + return false;
73749 +
73750 + if (vma->vm_flags & VM_GROWSDOWN)
73751 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73752 +#ifdef CONFIG_STACK_GROWSUP
73753 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73754 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73755 +#endif
73756 +
73757 + return true;
73758 +}
73759 +
73760 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73761 +{
73762 + if (vma->vm_start < len)
73763 + return -ENOMEM;
73764 + if (!(vma->vm_flags & VM_GROWSDOWN))
73765 + return vma->vm_start - len;
73766 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73767 + return vma->vm_start - len - sysctl_heap_stack_gap;
73768 + return -ENOMEM;
73769 +}
73770 +
73771 /* Get an address range which is currently unmapped.
73772 * For shmat() with addr=0.
73773 *
73774 @@ -1426,18 +1613,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73775 if (flags & MAP_FIXED)
73776 return addr;
73777
73778 +#ifdef CONFIG_PAX_RANDMMAP
73779 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73780 +#endif
73781 +
73782 if (addr) {
73783 addr = PAGE_ALIGN(addr);
73784 - vma = find_vma(mm, addr);
73785 - if (TASK_SIZE - len >= addr &&
73786 - (!vma || addr + len <= vma->vm_start))
73787 - return addr;
73788 + if (TASK_SIZE - len >= addr) {
73789 + vma = find_vma(mm, addr);
73790 + if (check_heap_stack_gap(vma, addr, len))
73791 + return addr;
73792 + }
73793 }
73794 if (len > mm->cached_hole_size) {
73795 - start_addr = addr = mm->free_area_cache;
73796 + start_addr = addr = mm->free_area_cache;
73797 } else {
73798 - start_addr = addr = TASK_UNMAPPED_BASE;
73799 - mm->cached_hole_size = 0;
73800 + start_addr = addr = mm->mmap_base;
73801 + mm->cached_hole_size = 0;
73802 }
73803
73804 full_search:
73805 @@ -1448,34 +1640,40 @@ full_search:
73806 * Start a new search - just in case we missed
73807 * some holes.
73808 */
73809 - if (start_addr != TASK_UNMAPPED_BASE) {
73810 - addr = TASK_UNMAPPED_BASE;
73811 - start_addr = addr;
73812 + if (start_addr != mm->mmap_base) {
73813 + start_addr = addr = mm->mmap_base;
73814 mm->cached_hole_size = 0;
73815 goto full_search;
73816 }
73817 return -ENOMEM;
73818 }
73819 - if (!vma || addr + len <= vma->vm_start) {
73820 - /*
73821 - * Remember the place where we stopped the search:
73822 - */
73823 - mm->free_area_cache = addr + len;
73824 - return addr;
73825 - }
73826 + if (check_heap_stack_gap(vma, addr, len))
73827 + break;
73828 if (addr + mm->cached_hole_size < vma->vm_start)
73829 mm->cached_hole_size = vma->vm_start - addr;
73830 addr = vma->vm_end;
73831 }
73832 +
73833 + /*
73834 + * Remember the place where we stopped the search:
73835 + */
73836 + mm->free_area_cache = addr + len;
73837 + return addr;
73838 }
73839 #endif
73840
73841 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73842 {
73843 +
73844 +#ifdef CONFIG_PAX_SEGMEXEC
73845 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73846 + return;
73847 +#endif
73848 +
73849 /*
73850 * Is this a new hole at the lowest possible address?
73851 */
73852 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73853 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73854 mm->free_area_cache = addr;
73855 }
73856
73857 @@ -1491,7 +1689,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73858 {
73859 struct vm_area_struct *vma;
73860 struct mm_struct *mm = current->mm;
73861 - unsigned long addr = addr0, start_addr;
73862 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73863
73864 /* requested length too big for entire address space */
73865 if (len > TASK_SIZE)
73866 @@ -1500,13 +1698,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73867 if (flags & MAP_FIXED)
73868 return addr;
73869
73870 +#ifdef CONFIG_PAX_RANDMMAP
73871 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73872 +#endif
73873 +
73874 /* requesting a specific address */
73875 if (addr) {
73876 addr = PAGE_ALIGN(addr);
73877 - vma = find_vma(mm, addr);
73878 - if (TASK_SIZE - len >= addr &&
73879 - (!vma || addr + len <= vma->vm_start))
73880 - return addr;
73881 + if (TASK_SIZE - len >= addr) {
73882 + vma = find_vma(mm, addr);
73883 + if (check_heap_stack_gap(vma, addr, len))
73884 + return addr;
73885 + }
73886 }
73887
73888 /* check if free_area_cache is useful for us */
73889 @@ -1530,7 +1733,7 @@ try_again:
73890 * return with success:
73891 */
73892 vma = find_vma(mm, addr);
73893 - if (!vma || addr+len <= vma->vm_start)
73894 + if (check_heap_stack_gap(vma, addr, len))
73895 /* remember the address as a hint for next time */
73896 return (mm->free_area_cache = addr);
73897
73898 @@ -1539,8 +1742,8 @@ try_again:
73899 mm->cached_hole_size = vma->vm_start - addr;
73900
73901 /* try just below the current vma->vm_start */
73902 - addr = vma->vm_start-len;
73903 - } while (len < vma->vm_start);
73904 + addr = skip_heap_stack_gap(vma, len);
73905 + } while (!IS_ERR_VALUE(addr));
73906
73907 fail:
73908 /*
73909 @@ -1563,13 +1766,21 @@ fail:
73910 * can happen with large stack limits and large mmap()
73911 * allocations.
73912 */
73913 + mm->mmap_base = TASK_UNMAPPED_BASE;
73914 +
73915 +#ifdef CONFIG_PAX_RANDMMAP
73916 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73917 + mm->mmap_base += mm->delta_mmap;
73918 +#endif
73919 +
73920 + mm->free_area_cache = mm->mmap_base;
73921 mm->cached_hole_size = ~0UL;
73922 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73923 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73924 /*
73925 * Restore the topdown base:
73926 */
73927 - mm->free_area_cache = mm->mmap_base;
73928 + mm->mmap_base = base;
73929 + mm->free_area_cache = base;
73930 mm->cached_hole_size = ~0UL;
73931
73932 return addr;
73933 @@ -1578,6 +1789,12 @@ fail:
73934
73935 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73936 {
73937 +
73938 +#ifdef CONFIG_PAX_SEGMEXEC
73939 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73940 + return;
73941 +#endif
73942 +
73943 /*
73944 * Is this a new hole at the highest possible address?
73945 */
73946 @@ -1585,8 +1802,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73947 mm->free_area_cache = addr;
73948
73949 /* dont allow allocations above current base */
73950 - if (mm->free_area_cache > mm->mmap_base)
73951 + if (mm->free_area_cache > mm->mmap_base) {
73952 mm->free_area_cache = mm->mmap_base;
73953 + mm->cached_hole_size = ~0UL;
73954 + }
73955 }
73956
73957 unsigned long
73958 @@ -1685,6 +1904,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73959 return vma;
73960 }
73961
73962 +#ifdef CONFIG_PAX_SEGMEXEC
73963 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73964 +{
73965 + struct vm_area_struct *vma_m;
73966 +
73967 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73968 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73969 + BUG_ON(vma->vm_mirror);
73970 + return NULL;
73971 + }
73972 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73973 + vma_m = vma->vm_mirror;
73974 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73975 + BUG_ON(vma->vm_file != vma_m->vm_file);
73976 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73977 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73978 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73979 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
73980 + return vma_m;
73981 +}
73982 +#endif
73983 +
73984 /*
73985 * Verify that the stack growth is acceptable and
73986 * update accounting. This is shared with both the
73987 @@ -1701,6 +1942,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73988 return -ENOMEM;
73989
73990 /* Stack limit test */
73991 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73992 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73993 return -ENOMEM;
73994
73995 @@ -1711,6 +1953,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73996 locked = mm->locked_vm + grow;
73997 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73998 limit >>= PAGE_SHIFT;
73999 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
74000 if (locked > limit && !capable(CAP_IPC_LOCK))
74001 return -ENOMEM;
74002 }
74003 @@ -1740,37 +1983,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
74004 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
74005 * vma is the last one with address > vma->vm_end. Have to extend vma.
74006 */
74007 +#ifndef CONFIG_IA64
74008 +static
74009 +#endif
74010 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
74011 {
74012 int error;
74013 + bool locknext;
74014
74015 if (!(vma->vm_flags & VM_GROWSUP))
74016 return -EFAULT;
74017
74018 + /* Also guard against wrapping around to address 0. */
74019 + if (address < PAGE_ALIGN(address+1))
74020 + address = PAGE_ALIGN(address+1);
74021 + else
74022 + return -ENOMEM;
74023 +
74024 /*
74025 * We must make sure the anon_vma is allocated
74026 * so that the anon_vma locking is not a noop.
74027 */
74028 if (unlikely(anon_vma_prepare(vma)))
74029 return -ENOMEM;
74030 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
74031 + if (locknext && anon_vma_prepare(vma->vm_next))
74032 + return -ENOMEM;
74033 vma_lock_anon_vma(vma);
74034 + if (locknext)
74035 + vma_lock_anon_vma(vma->vm_next);
74036
74037 /*
74038 * vma->vm_start/vm_end cannot change under us because the caller
74039 * is required to hold the mmap_sem in read mode. We need the
74040 - * anon_vma lock to serialize against concurrent expand_stacks.
74041 - * Also guard against wrapping around to address 0.
74042 + * anon_vma locks to serialize against concurrent expand_stacks
74043 + * and expand_upwards.
74044 */
74045 - if (address < PAGE_ALIGN(address+4))
74046 - address = PAGE_ALIGN(address+4);
74047 - else {
74048 - vma_unlock_anon_vma(vma);
74049 - return -ENOMEM;
74050 - }
74051 error = 0;
74052
74053 /* Somebody else might have raced and expanded it already */
74054 - if (address > vma->vm_end) {
74055 + 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)
74056 + error = -ENOMEM;
74057 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
74058 unsigned long size, grow;
74059
74060 size = address - vma->vm_start;
74061 @@ -1787,6 +2041,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
74062 }
74063 }
74064 }
74065 + if (locknext)
74066 + vma_unlock_anon_vma(vma->vm_next);
74067 vma_unlock_anon_vma(vma);
74068 khugepaged_enter_vma_merge(vma);
74069 validate_mm(vma->vm_mm);
74070 @@ -1801,6 +2057,8 @@ int expand_downwards(struct vm_area_struct *vma,
74071 unsigned long address)
74072 {
74073 int error;
74074 + bool lockprev = false;
74075 + struct vm_area_struct *prev;
74076
74077 /*
74078 * We must make sure the anon_vma is allocated
74079 @@ -1814,6 +2072,15 @@ int expand_downwards(struct vm_area_struct *vma,
74080 if (error)
74081 return error;
74082
74083 + prev = vma->vm_prev;
74084 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
74085 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
74086 +#endif
74087 + if (lockprev && anon_vma_prepare(prev))
74088 + return -ENOMEM;
74089 + if (lockprev)
74090 + vma_lock_anon_vma(prev);
74091 +
74092 vma_lock_anon_vma(vma);
74093
74094 /*
74095 @@ -1823,9 +2090,17 @@ int expand_downwards(struct vm_area_struct *vma,
74096 */
74097
74098 /* Somebody else might have raced and expanded it already */
74099 - if (address < vma->vm_start) {
74100 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
74101 + error = -ENOMEM;
74102 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
74103 unsigned long size, grow;
74104
74105 +#ifdef CONFIG_PAX_SEGMEXEC
74106 + struct vm_area_struct *vma_m;
74107 +
74108 + vma_m = pax_find_mirror_vma(vma);
74109 +#endif
74110 +
74111 size = vma->vm_end - address;
74112 grow = (vma->vm_start - address) >> PAGE_SHIFT;
74113
74114 @@ -1837,6 +2112,17 @@ int expand_downwards(struct vm_area_struct *vma,
74115 vma->vm_start = address;
74116 vma->vm_pgoff -= grow;
74117 anon_vma_interval_tree_post_update_vma(vma);
74118 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
74119 +
74120 +#ifdef CONFIG_PAX_SEGMEXEC
74121 + if (vma_m) {
74122 + anon_vma_interval_tree_pre_update_vma(vma_m);
74123 + vma_m->vm_start -= grow << PAGE_SHIFT;
74124 + vma_m->vm_pgoff -= grow;
74125 + anon_vma_interval_tree_post_update_vma(vma_m);
74126 + }
74127 +#endif
74128 +
74129 perf_event_mmap(vma);
74130 }
74131 }
74132 @@ -1914,6 +2200,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
74133 do {
74134 long nrpages = vma_pages(vma);
74135
74136 +#ifdef CONFIG_PAX_SEGMEXEC
74137 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
74138 + vma = remove_vma(vma);
74139 + continue;
74140 + }
74141 +#endif
74142 +
74143 if (vma->vm_flags & VM_ACCOUNT)
74144 nr_accounted += nrpages;
74145 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
74146 @@ -1959,6 +2252,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
74147 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
74148 vma->vm_prev = NULL;
74149 do {
74150 +
74151 +#ifdef CONFIG_PAX_SEGMEXEC
74152 + if (vma->vm_mirror) {
74153 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
74154 + vma->vm_mirror->vm_mirror = NULL;
74155 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
74156 + vma->vm_mirror = NULL;
74157 + }
74158 +#endif
74159 +
74160 rb_erase(&vma->vm_rb, &mm->mm_rb);
74161 mm->map_count--;
74162 tail_vma = vma;
74163 @@ -1987,14 +2290,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74164 struct vm_area_struct *new;
74165 int err = -ENOMEM;
74166
74167 +#ifdef CONFIG_PAX_SEGMEXEC
74168 + struct vm_area_struct *vma_m, *new_m = NULL;
74169 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
74170 +#endif
74171 +
74172 if (is_vm_hugetlb_page(vma) && (addr &
74173 ~(huge_page_mask(hstate_vma(vma)))))
74174 return -EINVAL;
74175
74176 +#ifdef CONFIG_PAX_SEGMEXEC
74177 + vma_m = pax_find_mirror_vma(vma);
74178 +#endif
74179 +
74180 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74181 if (!new)
74182 goto out_err;
74183
74184 +#ifdef CONFIG_PAX_SEGMEXEC
74185 + if (vma_m) {
74186 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
74187 + if (!new_m) {
74188 + kmem_cache_free(vm_area_cachep, new);
74189 + goto out_err;
74190 + }
74191 + }
74192 +#endif
74193 +
74194 /* most fields are the same, copy all, and then fixup */
74195 *new = *vma;
74196
74197 @@ -2007,6 +2329,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74198 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
74199 }
74200
74201 +#ifdef CONFIG_PAX_SEGMEXEC
74202 + if (vma_m) {
74203 + *new_m = *vma_m;
74204 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
74205 + new_m->vm_mirror = new;
74206 + new->vm_mirror = new_m;
74207 +
74208 + if (new_below)
74209 + new_m->vm_end = addr_m;
74210 + else {
74211 + new_m->vm_start = addr_m;
74212 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
74213 + }
74214 + }
74215 +#endif
74216 +
74217 pol = mpol_dup(vma_policy(vma));
74218 if (IS_ERR(pol)) {
74219 err = PTR_ERR(pol);
74220 @@ -2029,6 +2367,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74221 else
74222 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
74223
74224 +#ifdef CONFIG_PAX_SEGMEXEC
74225 + if (!err && vma_m) {
74226 + if (anon_vma_clone(new_m, vma_m))
74227 + goto out_free_mpol;
74228 +
74229 + mpol_get(pol);
74230 + vma_set_policy(new_m, pol);
74231 +
74232 + if (new_m->vm_file)
74233 + get_file(new_m->vm_file);
74234 +
74235 + if (new_m->vm_ops && new_m->vm_ops->open)
74236 + new_m->vm_ops->open(new_m);
74237 +
74238 + if (new_below)
74239 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
74240 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
74241 + else
74242 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
74243 +
74244 + if (err) {
74245 + if (new_m->vm_ops && new_m->vm_ops->close)
74246 + new_m->vm_ops->close(new_m);
74247 + if (new_m->vm_file)
74248 + fput(new_m->vm_file);
74249 + mpol_put(pol);
74250 + }
74251 + }
74252 +#endif
74253 +
74254 /* Success. */
74255 if (!err)
74256 return 0;
74257 @@ -2038,10 +2406,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74258 new->vm_ops->close(new);
74259 if (new->vm_file)
74260 fput(new->vm_file);
74261 - unlink_anon_vmas(new);
74262 out_free_mpol:
74263 mpol_put(pol);
74264 out_free_vma:
74265 +
74266 +#ifdef CONFIG_PAX_SEGMEXEC
74267 + if (new_m) {
74268 + unlink_anon_vmas(new_m);
74269 + kmem_cache_free(vm_area_cachep, new_m);
74270 + }
74271 +#endif
74272 +
74273 + unlink_anon_vmas(new);
74274 kmem_cache_free(vm_area_cachep, new);
74275 out_err:
74276 return err;
74277 @@ -2054,6 +2430,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
74278 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74279 unsigned long addr, int new_below)
74280 {
74281 +
74282 +#ifdef CONFIG_PAX_SEGMEXEC
74283 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74284 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
74285 + if (mm->map_count >= sysctl_max_map_count-1)
74286 + return -ENOMEM;
74287 + } else
74288 +#endif
74289 +
74290 if (mm->map_count >= sysctl_max_map_count)
74291 return -ENOMEM;
74292
74293 @@ -2065,11 +2450,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74294 * work. This now handles partial unmappings.
74295 * Jeremy Fitzhardinge <jeremy@goop.org>
74296 */
74297 +#ifdef CONFIG_PAX_SEGMEXEC
74298 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74299 {
74300 + int ret = __do_munmap(mm, start, len);
74301 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
74302 + return ret;
74303 +
74304 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
74305 +}
74306 +
74307 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74308 +#else
74309 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74310 +#endif
74311 +{
74312 unsigned long end;
74313 struct vm_area_struct *vma, *prev, *last;
74314
74315 + /*
74316 + * mm->mmap_sem is required to protect against another thread
74317 + * changing the mappings in case we sleep.
74318 + */
74319 + verify_mm_writelocked(mm);
74320 +
74321 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
74322 return -EINVAL;
74323
74324 @@ -2144,6 +2548,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
74325 /* Fix up all other VM information */
74326 remove_vma_list(mm, vma);
74327
74328 + track_exec_limit(mm, start, end, 0UL);
74329 +
74330 return 0;
74331 }
74332
74333 @@ -2152,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
74334 int ret;
74335 struct mm_struct *mm = current->mm;
74336
74337 +
74338 +#ifdef CONFIG_PAX_SEGMEXEC
74339 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
74340 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
74341 + return -EINVAL;
74342 +#endif
74343 +
74344 down_write(&mm->mmap_sem);
74345 ret = do_munmap(mm, start, len);
74346 up_write(&mm->mmap_sem);
74347 @@ -2165,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
74348 return vm_munmap(addr, len);
74349 }
74350
74351 -static inline void verify_mm_writelocked(struct mm_struct *mm)
74352 -{
74353 -#ifdef CONFIG_DEBUG_VM
74354 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74355 - WARN_ON(1);
74356 - up_read(&mm->mmap_sem);
74357 - }
74358 -#endif
74359 -}
74360 -
74361 /*
74362 * this is really a simplified "do_mmap". it only handles
74363 * anonymous maps. eventually we may be able to do some
74364 @@ -2188,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74365 struct rb_node ** rb_link, * rb_parent;
74366 pgoff_t pgoff = addr >> PAGE_SHIFT;
74367 int error;
74368 + unsigned long charged;
74369
74370 len = PAGE_ALIGN(len);
74371 if (!len)
74372 @@ -2195,16 +2599,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74373
74374 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
74375
74376 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
74377 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
74378 + flags &= ~VM_EXEC;
74379 +
74380 +#ifdef CONFIG_PAX_MPROTECT
74381 + if (mm->pax_flags & MF_PAX_MPROTECT)
74382 + flags &= ~VM_MAYEXEC;
74383 +#endif
74384 +
74385 + }
74386 +#endif
74387 +
74388 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
74389 if (error & ~PAGE_MASK)
74390 return error;
74391
74392 + charged = len >> PAGE_SHIFT;
74393 +
74394 /*
74395 * mlock MCL_FUTURE?
74396 */
74397 if (mm->def_flags & VM_LOCKED) {
74398 unsigned long locked, lock_limit;
74399 - locked = len >> PAGE_SHIFT;
74400 + locked = charged;
74401 locked += mm->locked_vm;
74402 lock_limit = rlimit(RLIMIT_MEMLOCK);
74403 lock_limit >>= PAGE_SHIFT;
74404 @@ -2221,21 +2639,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74405 /*
74406 * Clear old maps. this also does some error checking for us
74407 */
74408 - munmap_back:
74409 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
74410 if (do_munmap(mm, addr, len))
74411 return -ENOMEM;
74412 - goto munmap_back;
74413 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
74414 }
74415
74416 /* Check against address space limits *after* clearing old maps... */
74417 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
74418 + if (!may_expand_vm(mm, charged))
74419 return -ENOMEM;
74420
74421 if (mm->map_count > sysctl_max_map_count)
74422 return -ENOMEM;
74423
74424 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
74425 + if (security_vm_enough_memory_mm(mm, charged))
74426 return -ENOMEM;
74427
74428 /* Can we just expand an old private anonymous mapping? */
74429 @@ -2249,7 +2666,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74430 */
74431 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74432 if (!vma) {
74433 - vm_unacct_memory(len >> PAGE_SHIFT);
74434 + vm_unacct_memory(charged);
74435 return -ENOMEM;
74436 }
74437
74438 @@ -2263,11 +2680,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
74439 vma_link(mm, vma, prev, rb_link, rb_parent);
74440 out:
74441 perf_event_mmap(vma);
74442 - mm->total_vm += len >> PAGE_SHIFT;
74443 + mm->total_vm += charged;
74444 if (flags & VM_LOCKED) {
74445 if (!mlock_vma_pages_range(vma, addr, addr + len))
74446 - mm->locked_vm += (len >> PAGE_SHIFT);
74447 + mm->locked_vm += charged;
74448 }
74449 + track_exec_limit(mm, addr, addr + len, flags);
74450 return addr;
74451 }
74452
74453 @@ -2325,6 +2743,7 @@ void exit_mmap(struct mm_struct *mm)
74454 while (vma) {
74455 if (vma->vm_flags & VM_ACCOUNT)
74456 nr_accounted += vma_pages(vma);
74457 + vma->vm_mirror = NULL;
74458 vma = remove_vma(vma);
74459 }
74460 vm_unacct_memory(nr_accounted);
74461 @@ -2341,6 +2760,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
74462 struct vm_area_struct *prev;
74463 struct rb_node **rb_link, *rb_parent;
74464
74465 +#ifdef CONFIG_PAX_SEGMEXEC
74466 + struct vm_area_struct *vma_m = NULL;
74467 +#endif
74468 +
74469 + if (security_mmap_addr(vma->vm_start))
74470 + return -EPERM;
74471 +
74472 /*
74473 * The vm_pgoff of a purely anonymous vma should be irrelevant
74474 * until its first write fault, when page's anon_vma and index
74475 @@ -2364,7 +2790,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
74476 security_vm_enough_memory_mm(mm, vma_pages(vma)))
74477 return -ENOMEM;
74478
74479 +#ifdef CONFIG_PAX_SEGMEXEC
74480 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74481 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74482 + if (!vma_m)
74483 + return -ENOMEM;
74484 + }
74485 +#endif
74486 +
74487 vma_link(mm, vma, prev, rb_link, rb_parent);
74488 +
74489 +#ifdef CONFIG_PAX_SEGMEXEC
74490 + if (vma_m)
74491 + BUG_ON(pax_mirror_vma(vma_m, vma));
74492 +#endif
74493 +
74494 return 0;
74495 }
74496
74497 @@ -2384,6 +2824,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74498 struct mempolicy *pol;
74499 bool faulted_in_anon_vma = true;
74500
74501 + BUG_ON(vma->vm_mirror);
74502 +
74503 /*
74504 * If anonymous vma has not yet been faulted, update new pgoff
74505 * to match new location, to increase its chance of merging.
74506 @@ -2450,6 +2892,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74507 return NULL;
74508 }
74509
74510 +#ifdef CONFIG_PAX_SEGMEXEC
74511 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74512 +{
74513 + struct vm_area_struct *prev_m;
74514 + struct rb_node **rb_link_m, *rb_parent_m;
74515 + struct mempolicy *pol_m;
74516 +
74517 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74518 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74519 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74520 + *vma_m = *vma;
74521 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74522 + if (anon_vma_clone(vma_m, vma))
74523 + return -ENOMEM;
74524 + pol_m = vma_policy(vma_m);
74525 + mpol_get(pol_m);
74526 + vma_set_policy(vma_m, pol_m);
74527 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74528 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74529 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74530 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74531 + if (vma_m->vm_file)
74532 + get_file(vma_m->vm_file);
74533 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74534 + vma_m->vm_ops->open(vma_m);
74535 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
74536 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74537 + vma_m->vm_mirror = vma;
74538 + vma->vm_mirror = vma_m;
74539 + return 0;
74540 +}
74541 +#endif
74542 +
74543 /*
74544 * Return true if the calling process may expand its vm space by the passed
74545 * number of pages
74546 @@ -2461,6 +2936,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74547
74548 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74549
74550 +#ifdef CONFIG_PAX_RANDMMAP
74551 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74552 + cur -= mm->brk_gap;
74553 +#endif
74554 +
74555 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74556 if (cur + npages > lim)
74557 return 0;
74558 return 1;
74559 @@ -2531,6 +3012,22 @@ int install_special_mapping(struct mm_struct *mm,
74560 vma->vm_start = addr;
74561 vma->vm_end = addr + len;
74562
74563 +#ifdef CONFIG_PAX_MPROTECT
74564 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74565 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74566 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74567 + return -EPERM;
74568 + if (!(vm_flags & VM_EXEC))
74569 + vm_flags &= ~VM_MAYEXEC;
74570 +#else
74571 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74572 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74573 +#endif
74574 + else
74575 + vm_flags &= ~VM_MAYWRITE;
74576 + }
74577 +#endif
74578 +
74579 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74580 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74581
74582 diff --git a/mm/mprotect.c b/mm/mprotect.c
74583 index a409926..8b32e6d 100644
74584 --- a/mm/mprotect.c
74585 +++ b/mm/mprotect.c
74586 @@ -23,10 +23,17 @@
74587 #include <linux/mmu_notifier.h>
74588 #include <linux/migrate.h>
74589 #include <linux/perf_event.h>
74590 +
74591 +#ifdef CONFIG_PAX_MPROTECT
74592 +#include <linux/elf.h>
74593 +#include <linux/binfmts.h>
74594 +#endif
74595 +
74596 #include <asm/uaccess.h>
74597 #include <asm/pgtable.h>
74598 #include <asm/cacheflush.h>
74599 #include <asm/tlbflush.h>
74600 +#include <asm/mmu_context.h>
74601
74602 #ifndef pgprot_modify
74603 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74604 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74605 flush_tlb_range(vma, start, end);
74606 }
74607
74608 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74609 +/* called while holding the mmap semaphor for writing except stack expansion */
74610 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74611 +{
74612 + unsigned long oldlimit, newlimit = 0UL;
74613 +
74614 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74615 + return;
74616 +
74617 + spin_lock(&mm->page_table_lock);
74618 + oldlimit = mm->context.user_cs_limit;
74619 + if ((prot & VM_EXEC) && oldlimit < end)
74620 + /* USER_CS limit moved up */
74621 + newlimit = end;
74622 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74623 + /* USER_CS limit moved down */
74624 + newlimit = start;
74625 +
74626 + if (newlimit) {
74627 + mm->context.user_cs_limit = newlimit;
74628 +
74629 +#ifdef CONFIG_SMP
74630 + wmb();
74631 + cpus_clear(mm->context.cpu_user_cs_mask);
74632 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74633 +#endif
74634 +
74635 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74636 + }
74637 + spin_unlock(&mm->page_table_lock);
74638 + if (newlimit == end) {
74639 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74640 +
74641 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74642 + if (is_vm_hugetlb_page(vma))
74643 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74644 + else
74645 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74646 + }
74647 +}
74648 +#endif
74649 +
74650 int
74651 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74652 unsigned long start, unsigned long end, unsigned long newflags)
74653 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74654 int error;
74655 int dirty_accountable = 0;
74656
74657 +#ifdef CONFIG_PAX_SEGMEXEC
74658 + struct vm_area_struct *vma_m = NULL;
74659 + unsigned long start_m, end_m;
74660 +
74661 + start_m = start + SEGMEXEC_TASK_SIZE;
74662 + end_m = end + SEGMEXEC_TASK_SIZE;
74663 +#endif
74664 +
74665 if (newflags == oldflags) {
74666 *pprev = vma;
74667 return 0;
74668 }
74669
74670 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74671 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74672 +
74673 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74674 + return -ENOMEM;
74675 +
74676 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74677 + return -ENOMEM;
74678 + }
74679 +
74680 /*
74681 * If we make a private mapping writable we increase our commit;
74682 * but (without finer accounting) cannot reduce our commit if we
74683 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74684 }
74685 }
74686
74687 +#ifdef CONFIG_PAX_SEGMEXEC
74688 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74689 + if (start != vma->vm_start) {
74690 + error = split_vma(mm, vma, start, 1);
74691 + if (error)
74692 + goto fail;
74693 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74694 + *pprev = (*pprev)->vm_next;
74695 + }
74696 +
74697 + if (end != vma->vm_end) {
74698 + error = split_vma(mm, vma, end, 0);
74699 + if (error)
74700 + goto fail;
74701 + }
74702 +
74703 + if (pax_find_mirror_vma(vma)) {
74704 + error = __do_munmap(mm, start_m, end_m - start_m);
74705 + if (error)
74706 + goto fail;
74707 + } else {
74708 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74709 + if (!vma_m) {
74710 + error = -ENOMEM;
74711 + goto fail;
74712 + }
74713 + vma->vm_flags = newflags;
74714 + error = pax_mirror_vma(vma_m, vma);
74715 + if (error) {
74716 + vma->vm_flags = oldflags;
74717 + goto fail;
74718 + }
74719 + }
74720 + }
74721 +#endif
74722 +
74723 /*
74724 * First try to merge with previous and/or next vma.
74725 */
74726 @@ -204,9 +307,21 @@ success:
74727 * vm_flags and vm_page_prot are protected by the mmap_sem
74728 * held in write mode.
74729 */
74730 +
74731 +#ifdef CONFIG_PAX_SEGMEXEC
74732 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74733 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74734 +#endif
74735 +
74736 vma->vm_flags = newflags;
74737 +
74738 +#ifdef CONFIG_PAX_MPROTECT
74739 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74740 + mm->binfmt->handle_mprotect(vma, newflags);
74741 +#endif
74742 +
74743 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74744 - vm_get_page_prot(newflags));
74745 + vm_get_page_prot(vma->vm_flags));
74746
74747 if (vma_wants_writenotify(vma)) {
74748 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74749 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74750 end = start + len;
74751 if (end <= start)
74752 return -ENOMEM;
74753 +
74754 +#ifdef CONFIG_PAX_SEGMEXEC
74755 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74756 + if (end > SEGMEXEC_TASK_SIZE)
74757 + return -EINVAL;
74758 + } else
74759 +#endif
74760 +
74761 + if (end > TASK_SIZE)
74762 + return -EINVAL;
74763 +
74764 if (!arch_validate_prot(prot))
74765 return -EINVAL;
74766
74767 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74768 /*
74769 * Does the application expect PROT_READ to imply PROT_EXEC:
74770 */
74771 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74772 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74773 prot |= PROT_EXEC;
74774
74775 vm_flags = calc_vm_prot_bits(prot);
74776 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74777 if (start > vma->vm_start)
74778 prev = vma;
74779
74780 +#ifdef CONFIG_PAX_MPROTECT
74781 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74782 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74783 +#endif
74784 +
74785 for (nstart = start ; ; ) {
74786 unsigned long newflags;
74787
74788 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74789
74790 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74791 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74792 + if (prot & (PROT_WRITE | PROT_EXEC))
74793 + gr_log_rwxmprotect(vma->vm_file);
74794 +
74795 + error = -EACCES;
74796 + goto out;
74797 + }
74798 +
74799 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74800 error = -EACCES;
74801 goto out;
74802 }
74803 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74804 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74805 if (error)
74806 goto out;
74807 +
74808 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74809 +
74810 nstart = tmp;
74811
74812 if (nstart < prev->vm_end)
74813 diff --git a/mm/mremap.c b/mm/mremap.c
74814 index 1b61c2d..1cc0e3c 100644
74815 --- a/mm/mremap.c
74816 +++ b/mm/mremap.c
74817 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74818 continue;
74819 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74820 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74821 +
74822 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74823 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74824 + pte = pte_exprotect(pte);
74825 +#endif
74826 +
74827 set_pte_at(mm, new_addr, new_pte, pte);
74828 }
74829
74830 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74831 if (is_vm_hugetlb_page(vma))
74832 goto Einval;
74833
74834 +#ifdef CONFIG_PAX_SEGMEXEC
74835 + if (pax_find_mirror_vma(vma))
74836 + goto Einval;
74837 +#endif
74838 +
74839 /* We can't remap across vm area boundaries */
74840 if (old_len > vma->vm_end - addr)
74841 goto Efault;
74842 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
74843 unsigned long ret = -EINVAL;
74844 unsigned long charged = 0;
74845 unsigned long map_flags;
74846 + unsigned long pax_task_size = TASK_SIZE;
74847
74848 if (new_addr & ~PAGE_MASK)
74849 goto out;
74850
74851 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74852 +#ifdef CONFIG_PAX_SEGMEXEC
74853 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74854 + pax_task_size = SEGMEXEC_TASK_SIZE;
74855 +#endif
74856 +
74857 + pax_task_size -= PAGE_SIZE;
74858 +
74859 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74860 goto out;
74861
74862 /* Check if the location we're moving into overlaps the
74863 * old location at all, and fail if it does.
74864 */
74865 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74866 - goto out;
74867 -
74868 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74869 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74870 goto out;
74871
74872 ret = do_munmap(mm, new_addr, new_len);
74873 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74874 struct vm_area_struct *vma;
74875 unsigned long ret = -EINVAL;
74876 unsigned long charged = 0;
74877 + unsigned long pax_task_size = TASK_SIZE;
74878
74879 down_write(&current->mm->mmap_sem);
74880
74881 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74882 if (!new_len)
74883 goto out;
74884
74885 +#ifdef CONFIG_PAX_SEGMEXEC
74886 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74887 + pax_task_size = SEGMEXEC_TASK_SIZE;
74888 +#endif
74889 +
74890 + pax_task_size -= PAGE_SIZE;
74891 +
74892 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74893 + old_len > pax_task_size || addr > pax_task_size-old_len)
74894 + goto out;
74895 +
74896 if (flags & MREMAP_FIXED) {
74897 if (flags & MREMAP_MAYMOVE)
74898 ret = mremap_to(addr, old_len, new_addr, new_len);
74899 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74900 addr + new_len);
74901 }
74902 ret = addr;
74903 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74904 goto out;
74905 }
74906 }
74907 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74908 goto out;
74909 }
74910
74911 + map_flags = vma->vm_flags;
74912 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74913 + if (!(ret & ~PAGE_MASK)) {
74914 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74915 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74916 + }
74917 }
74918 out:
74919 if (ret & ~PAGE_MASK)
74920 diff --git a/mm/nommu.c b/mm/nommu.c
74921 index 45131b4..c521665 100644
74922 --- a/mm/nommu.c
74923 +++ b/mm/nommu.c
74924 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74925 int sysctl_overcommit_ratio = 50; /* default is 50% */
74926 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74927 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74928 -int heap_stack_gap = 0;
74929
74930 atomic_long_t mmap_pages_allocated;
74931
74932 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74933 EXPORT_SYMBOL(find_vma);
74934
74935 /*
74936 - * find a VMA
74937 - * - we don't extend stack VMAs under NOMMU conditions
74938 - */
74939 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74940 -{
74941 - return find_vma(mm, addr);
74942 -}
74943 -
74944 -/*
74945 * expand a stack to a given address
74946 * - not supported under NOMMU conditions
74947 */
74948 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74949
74950 /* most fields are the same, copy all, and then fixup */
74951 *new = *vma;
74952 + INIT_LIST_HEAD(&new->anon_vma_chain);
74953 *region = *vma->vm_region;
74954 new->vm_region = region;
74955
74956 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74957 index 7e208f0..d96f232 100644
74958 --- a/mm/page_alloc.c
74959 +++ b/mm/page_alloc.c
74960 @@ -340,7 +340,7 @@ out:
74961 * This usage means that zero-order pages may not be compound.
74962 */
74963
74964 -static void free_compound_page(struct page *page)
74965 +void free_compound_page(struct page *page)
74966 {
74967 __free_pages_ok(page, compound_order(page));
74968 }
74969 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74970 int i;
74971 int bad = 0;
74972
74973 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74974 + unsigned long index = 1UL << order;
74975 +#endif
74976 +
74977 trace_mm_page_free(page, order);
74978 kmemcheck_free_shadow(page, order);
74979
74980 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74981 debug_check_no_obj_freed(page_address(page),
74982 PAGE_SIZE << order);
74983 }
74984 +
74985 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74986 + for (; index; --index)
74987 + sanitize_highpage(page + index - 1);
74988 +#endif
74989 +
74990 arch_free_page(page, order);
74991 kernel_map_pages(page, 1 << order, 0);
74992
74993 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74994 arch_alloc_page(page, order);
74995 kernel_map_pages(page, 1 << order, 1);
74996
74997 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74998 if (gfp_flags & __GFP_ZERO)
74999 prep_zero_page(page, order, gfp_flags);
75000 +#endif
75001
75002 if (order && (gfp_flags & __GFP_COMP))
75003 prep_compound_page(page, order);
75004 @@ -3703,7 +3715,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
75005 unsigned long pfn;
75006
75007 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
75008 +#ifdef CONFIG_X86_32
75009 + /* boot failures in VMware 8 on 32bit vanilla since
75010 + this change */
75011 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
75012 +#else
75013 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
75014 +#endif
75015 return 1;
75016 }
75017 return 0;
75018 diff --git a/mm/percpu.c b/mm/percpu.c
75019 index ddc5efb..f632d2c 100644
75020 --- a/mm/percpu.c
75021 +++ b/mm/percpu.c
75022 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
75023 static unsigned int pcpu_high_unit_cpu __read_mostly;
75024
75025 /* the address of the first chunk which starts with the kernel static area */
75026 -void *pcpu_base_addr __read_mostly;
75027 +void *pcpu_base_addr __read_only;
75028 EXPORT_SYMBOL_GPL(pcpu_base_addr);
75029
75030 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
75031 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
75032 index 926b466..b23df53 100644
75033 --- a/mm/process_vm_access.c
75034 +++ b/mm/process_vm_access.c
75035 @@ -13,6 +13,7 @@
75036 #include <linux/uio.h>
75037 #include <linux/sched.h>
75038 #include <linux/highmem.h>
75039 +#include <linux/security.h>
75040 #include <linux/ptrace.h>
75041 #include <linux/slab.h>
75042 #include <linux/syscalls.h>
75043 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75044 size_t iov_l_curr_offset = 0;
75045 ssize_t iov_len;
75046
75047 + return -ENOSYS; // PaX: until properly audited
75048 +
75049 /*
75050 * Work out how many pages of struct pages we're going to need
75051 * when eventually calling get_user_pages
75052 */
75053 for (i = 0; i < riovcnt; i++) {
75054 iov_len = rvec[i].iov_len;
75055 - if (iov_len > 0) {
75056 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
75057 - + iov_len)
75058 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
75059 - / PAGE_SIZE + 1;
75060 - nr_pages = max(nr_pages, nr_pages_iov);
75061 - }
75062 + if (iov_len <= 0)
75063 + continue;
75064 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
75065 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
75066 + nr_pages = max(nr_pages, nr_pages_iov);
75067 }
75068
75069 if (nr_pages == 0)
75070 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
75071 goto free_proc_pages;
75072 }
75073
75074 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
75075 + rc = -EPERM;
75076 + goto put_task_struct;
75077 + }
75078 +
75079 mm = mm_access(task, PTRACE_MODE_ATTACH);
75080 if (!mm || IS_ERR(mm)) {
75081 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
75082 diff --git a/mm/rmap.c b/mm/rmap.c
75083 index 2ee1ef0..2e175ba 100644
75084 --- a/mm/rmap.c
75085 +++ b/mm/rmap.c
75086 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75087 struct anon_vma *anon_vma = vma->anon_vma;
75088 struct anon_vma_chain *avc;
75089
75090 +#ifdef CONFIG_PAX_SEGMEXEC
75091 + struct anon_vma_chain *avc_m = NULL;
75092 +#endif
75093 +
75094 might_sleep();
75095 if (unlikely(!anon_vma)) {
75096 struct mm_struct *mm = vma->vm_mm;
75097 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75098 if (!avc)
75099 goto out_enomem;
75100
75101 +#ifdef CONFIG_PAX_SEGMEXEC
75102 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
75103 + if (!avc_m)
75104 + goto out_enomem_free_avc;
75105 +#endif
75106 +
75107 anon_vma = find_mergeable_anon_vma(vma);
75108 allocated = NULL;
75109 if (!anon_vma) {
75110 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75111 /* page_table_lock to protect against threads */
75112 spin_lock(&mm->page_table_lock);
75113 if (likely(!vma->anon_vma)) {
75114 +
75115 +#ifdef CONFIG_PAX_SEGMEXEC
75116 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
75117 +
75118 + if (vma_m) {
75119 + BUG_ON(vma_m->anon_vma);
75120 + vma_m->anon_vma = anon_vma;
75121 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
75122 + avc_m = NULL;
75123 + }
75124 +#endif
75125 +
75126 vma->anon_vma = anon_vma;
75127 anon_vma_chain_link(vma, avc, anon_vma);
75128 allocated = NULL;
75129 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
75130
75131 if (unlikely(allocated))
75132 put_anon_vma(allocated);
75133 +
75134 +#ifdef CONFIG_PAX_SEGMEXEC
75135 + if (unlikely(avc_m))
75136 + anon_vma_chain_free(avc_m);
75137 +#endif
75138 +
75139 if (unlikely(avc))
75140 anon_vma_chain_free(avc);
75141 }
75142 return 0;
75143
75144 out_enomem_free_avc:
75145 +
75146 +#ifdef CONFIG_PAX_SEGMEXEC
75147 + if (avc_m)
75148 + anon_vma_chain_free(avc_m);
75149 +#endif
75150 +
75151 anon_vma_chain_free(avc);
75152 out_enomem:
75153 return -ENOMEM;
75154 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
75155 * Attach the anon_vmas from src to dst.
75156 * Returns 0 on success, -ENOMEM on failure.
75157 */
75158 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
75159 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
75160 {
75161 struct anon_vma_chain *avc, *pavc;
75162 struct anon_vma *root = NULL;
75163 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
75164 * the corresponding VMA in the parent process is attached to.
75165 * Returns 0 on success, non-zero on failure.
75166 */
75167 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
75168 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
75169 {
75170 struct anon_vma_chain *avc;
75171 struct anon_vma *anon_vma;
75172 diff --git a/mm/shmem.c b/mm/shmem.c
75173 index 50c5b8f..0bc87f7 100644
75174 --- a/mm/shmem.c
75175 +++ b/mm/shmem.c
75176 @@ -31,7 +31,7 @@
75177 #include <linux/export.h>
75178 #include <linux/swap.h>
75179
75180 -static struct vfsmount *shm_mnt;
75181 +struct vfsmount *shm_mnt;
75182
75183 #ifdef CONFIG_SHMEM
75184 /*
75185 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
75186 #define BOGO_DIRENT_SIZE 20
75187
75188 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
75189 -#define SHORT_SYMLINK_LEN 128
75190 +#define SHORT_SYMLINK_LEN 64
75191
75192 /*
75193 * shmem_fallocate and shmem_writepage communicate via inode->i_private
75194 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
75195 static int shmem_xattr_validate(const char *name)
75196 {
75197 struct { const char *prefix; size_t len; } arr[] = {
75198 +
75199 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75200 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
75201 +#endif
75202 +
75203 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
75204 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
75205 };
75206 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
75207 if (err)
75208 return err;
75209
75210 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
75211 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
75212 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
75213 + return -EOPNOTSUPP;
75214 + if (size > 8)
75215 + return -EINVAL;
75216 + }
75217 +#endif
75218 +
75219 return simple_xattr_set(&info->xattrs, name, value, size, flags);
75220 }
75221
75222 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
75223 int err = -ENOMEM;
75224
75225 /* Round up to L1_CACHE_BYTES to resist false sharing */
75226 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
75227 - L1_CACHE_BYTES), GFP_KERNEL);
75228 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
75229 if (!sbinfo)
75230 return -ENOMEM;
75231
75232 diff --git a/mm/slab.c b/mm/slab.c
75233 index 33d3363..69ffb8a 100644
75234 --- a/mm/slab.c
75235 +++ b/mm/slab.c
75236 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
75237
75238 /* Legal flag mask for kmem_cache_create(). */
75239 #if DEBUG
75240 -# define CREATE_MASK (SLAB_RED_ZONE | \
75241 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
75242 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
75243 SLAB_CACHE_DMA | \
75244 SLAB_STORE_USER | \
75245 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
75246 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75247 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
75248 #else
75249 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
75250 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
75251 SLAB_CACHE_DMA | \
75252 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
75253 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
75254 @@ -322,7 +322,7 @@ struct kmem_list3 {
75255 * Need this for bootstrapping a per node allocator.
75256 */
75257 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
75258 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
75259 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
75260 #define CACHE_CACHE 0
75261 #define SIZE_AC MAX_NUMNODES
75262 #define SIZE_L3 (2 * MAX_NUMNODES)
75263 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
75264 if ((x)->max_freeable < i) \
75265 (x)->max_freeable = i; \
75266 } while (0)
75267 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
75268 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
75269 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
75270 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
75271 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
75272 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
75273 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
75274 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
75275 #else
75276 #define STATS_INC_ACTIVE(x) do { } while (0)
75277 #define STATS_DEC_ACTIVE(x) do { } while (0)
75278 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
75279 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
75280 */
75281 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
75282 - const struct slab *slab, void *obj)
75283 + const struct slab *slab, const void *obj)
75284 {
75285 u32 offset = (obj - slab->s_mem);
75286 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
75287 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
75288 struct cache_names {
75289 char *name;
75290 char *name_dma;
75291 + char *name_usercopy;
75292 };
75293
75294 static struct cache_names __initdata cache_names[] = {
75295 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
75296 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
75297 #include <linux/kmalloc_sizes.h>
75298 - {NULL,}
75299 + {NULL}
75300 #undef CACHE
75301 };
75302
75303 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
75304 if (unlikely(gfpflags & GFP_DMA))
75305 return csizep->cs_dmacachep;
75306 #endif
75307 +
75308 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75309 + if (unlikely(gfpflags & GFP_USERCOPY))
75310 + return csizep->cs_usercopycachep;
75311 +#endif
75312 +
75313 return csizep->cs_cachep;
75314 }
75315
75316 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
75317 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
75318 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
75319 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75320 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75321 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75322 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
75323
75324 if (INDEX_AC != INDEX_L3) {
75325 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
75326 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
75327 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
75328 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75329 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75330 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75331 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
75332 }
75333
75334 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
75335 sizes->cs_cachep->size = sizes->cs_size;
75336 sizes->cs_cachep->object_size = sizes->cs_size;
75337 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
75338 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
75339 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
75340 list_add(&sizes->cs_cachep->list, &slab_caches);
75341 }
75342 #ifdef CONFIG_ZONE_DMA
75343 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
75344 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
75345 list_add(&sizes->cs_dmacachep->list, &slab_caches);
75346 #endif
75347 +
75348 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75349 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
75350 + sizes->cs_usercopycachep->name = names->name_dma;
75351 + sizes->cs_usercopycachep->size = sizes->cs_size;
75352 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
75353 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
75354 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
75355 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
75356 +#endif
75357 +
75358 sizes++;
75359 names++;
75360 }
75361 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
75362 }
75363 /* cpu stats */
75364 {
75365 - unsigned long allochit = atomic_read(&cachep->allochit);
75366 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
75367 - unsigned long freehit = atomic_read(&cachep->freehit);
75368 - unsigned long freemiss = atomic_read(&cachep->freemiss);
75369 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
75370 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
75371 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
75372 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
75373
75374 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
75375 allochit, allocmiss, freehit, freemiss);
75376 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
75377 {
75378 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
75379 #ifdef CONFIG_DEBUG_SLAB_LEAK
75380 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
75381 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
75382 #endif
75383 return 0;
75384 }
75385 module_init(slab_proc_init);
75386 #endif
75387
75388 +bool is_usercopy_object(const void *ptr)
75389 +{
75390 + struct page *page;
75391 + struct kmem_cache *cachep;
75392 +
75393 + if (ZERO_OR_NULL_PTR(ptr))
75394 + return false;
75395 +
75396 + if (!slab_is_available())
75397 + return false;
75398 +
75399 + if (!virt_addr_valid(ptr))
75400 + return false;
75401 +
75402 + page = virt_to_head_page(ptr);
75403 +
75404 + if (!PageSlab(page))
75405 + return false;
75406 +
75407 + cachep = page->slab_cache;
75408 + return cachep->flags & SLAB_USERCOPY;
75409 +}
75410 +
75411 +#ifdef CONFIG_PAX_USERCOPY
75412 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75413 +{
75414 + struct page *page;
75415 + struct kmem_cache *cachep;
75416 + struct slab *slabp;
75417 + unsigned int objnr;
75418 + unsigned long offset;
75419 +
75420 + if (ZERO_OR_NULL_PTR(ptr))
75421 + return "<null>";
75422 +
75423 + if (!virt_addr_valid(ptr))
75424 + return NULL;
75425 +
75426 + page = virt_to_head_page(ptr);
75427 +
75428 + if (!PageSlab(page))
75429 + return NULL;
75430 +
75431 + cachep = page->slab_cache;
75432 + if (!(cachep->flags & SLAB_USERCOPY))
75433 + return cachep->name;
75434 +
75435 + slabp = page->slab_page;
75436 + objnr = obj_to_index(cachep, slabp, ptr);
75437 + BUG_ON(objnr >= cachep->num);
75438 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
75439 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
75440 + return NULL;
75441 +
75442 + return cachep->name;
75443 +}
75444 +#endif
75445 +
75446 /**
75447 * ksize - get the actual amount of memory allocated for a given object
75448 * @objp: Pointer to the object
75449 diff --git a/mm/slab_common.c b/mm/slab_common.c
75450 index 069a24e6..226a310 100644
75451 --- a/mm/slab_common.c
75452 +++ b/mm/slab_common.c
75453 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
75454 err = __kmem_cache_create(s, flags);
75455 if (!err) {
75456
75457 - s->refcount = 1;
75458 + atomic_set(&s->refcount, 1);
75459 list_add(&s->list, &slab_caches);
75460
75461 } else {
75462 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
75463 {
75464 get_online_cpus();
75465 mutex_lock(&slab_mutex);
75466 - s->refcount--;
75467 - if (!s->refcount) {
75468 + if (atomic_dec_and_test(&s->refcount)) {
75469 list_del(&s->list);
75470
75471 if (!__kmem_cache_shutdown(s)) {
75472 diff --git a/mm/slob.c b/mm/slob.c
75473 index 1e921c5..7042228 100644
75474 --- a/mm/slob.c
75475 +++ b/mm/slob.c
75476 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
75477 /*
75478 * Return the size of a slob block.
75479 */
75480 -static slobidx_t slob_units(slob_t *s)
75481 +static slobidx_t slob_units(const slob_t *s)
75482 {
75483 if (s->units > 0)
75484 return s->units;
75485 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
75486 /*
75487 * Return the next free slob block pointer after this one.
75488 */
75489 -static slob_t *slob_next(slob_t *s)
75490 +static slob_t *slob_next(const slob_t *s)
75491 {
75492 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
75493 slobidx_t next;
75494 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
75495 /*
75496 * Returns true if s is the last free block in its page.
75497 */
75498 -static int slob_last(slob_t *s)
75499 +static int slob_last(const slob_t *s)
75500 {
75501 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
75502 }
75503
75504 -static void *slob_new_pages(gfp_t gfp, int order, int node)
75505 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
75506 {
75507 - void *page;
75508 + struct page *page;
75509
75510 #ifdef CONFIG_NUMA
75511 if (node != NUMA_NO_NODE)
75512 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
75513 if (!page)
75514 return NULL;
75515
75516 - return page_address(page);
75517 + __SetPageSlab(page);
75518 + return page;
75519 }
75520
75521 -static void slob_free_pages(void *b, int order)
75522 +static void slob_free_pages(struct page *sp, int order)
75523 {
75524 if (current->reclaim_state)
75525 current->reclaim_state->reclaimed_slab += 1 << order;
75526 - free_pages((unsigned long)b, order);
75527 + __ClearPageSlab(sp);
75528 + reset_page_mapcount(sp);
75529 + sp->private = 0;
75530 + __free_pages(sp, order);
75531 }
75532
75533 /*
75534 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75535
75536 /* Not enough space: must allocate a new page */
75537 if (!b) {
75538 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75539 - if (!b)
75540 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75541 + if (!sp)
75542 return NULL;
75543 - sp = virt_to_page(b);
75544 - __SetPageSlab(sp);
75545 + b = page_address(sp);
75546
75547 spin_lock_irqsave(&slob_lock, flags);
75548 sp->units = SLOB_UNITS(PAGE_SIZE);
75549 sp->freelist = b;
75550 + sp->private = 0;
75551 INIT_LIST_HEAD(&sp->list);
75552 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75553 set_slob_page_free(sp, slob_list);
75554 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75555 if (slob_page_free(sp))
75556 clear_slob_page_free(sp);
75557 spin_unlock_irqrestore(&slob_lock, flags);
75558 - __ClearPageSlab(sp);
75559 - reset_page_mapcount(sp);
75560 - slob_free_pages(b, 0);
75561 + slob_free_pages(sp, 0);
75562 return;
75563 }
75564
75565 @@ -426,11 +428,10 @@ out:
75566 */
75567
75568 static __always_inline void *
75569 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75570 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
75571 {
75572 - unsigned int *m;
75573 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75574 - void *ret;
75575 + slob_t *m;
75576 + void *ret = NULL;
75577
75578 gfp &= gfp_allowed_mask;
75579
75580 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75581
75582 if (!m)
75583 return NULL;
75584 - *m = size;
75585 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75586 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75587 + m[0].units = size;
75588 + m[1].units = align;
75589 ret = (void *)m + align;
75590
75591 trace_kmalloc_node(caller, ret,
75592 size, size + align, gfp, node);
75593 } else {
75594 unsigned int order = get_order(size);
75595 + struct page *page;
75596
75597 if (likely(order))
75598 gfp |= __GFP_COMP;
75599 - ret = slob_new_pages(gfp, order, node);
75600 - if (ret) {
75601 - struct page *page;
75602 - page = virt_to_page(ret);
75603 + page = slob_new_pages(gfp, order, node);
75604 + if (page) {
75605 + ret = page_address(page);
75606 page->private = size;
75607 }
75608
75609 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75610 size, PAGE_SIZE << order, gfp, node);
75611 }
75612
75613 - kmemleak_alloc(ret, size, 1, gfp);
75614 + return ret;
75615 +}
75616 +
75617 +static __always_inline void *
75618 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
75619 +{
75620 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75621 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
75622 +
75623 + if (!ZERO_OR_NULL_PTR(ret))
75624 + kmemleak_alloc(ret, size, 1, gfp);
75625 return ret;
75626 }
75627
75628 @@ -501,15 +515,91 @@ void kfree(const void *block)
75629 kmemleak_free(block);
75630
75631 sp = virt_to_page(block);
75632 - if (PageSlab(sp)) {
75633 + VM_BUG_ON(!PageSlab(sp));
75634 + if (!sp->private) {
75635 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75636 - unsigned int *m = (unsigned int *)(block - align);
75637 - slob_free(m, *m + align);
75638 - } else
75639 + slob_t *m = (slob_t *)(block - align);
75640 + slob_free(m, m[0].units + align);
75641 + } else {
75642 + __ClearPageSlab(sp);
75643 + reset_page_mapcount(sp);
75644 + sp->private = 0;
75645 put_page(sp);
75646 + }
75647 }
75648 EXPORT_SYMBOL(kfree);
75649
75650 +bool is_usercopy_object(const void *ptr)
75651 +{
75652 + if (!slab_is_available())
75653 + return false;
75654 +
75655 + // PAX: TODO
75656 +
75657 + return false;
75658 +}
75659 +
75660 +#ifdef CONFIG_PAX_USERCOPY
75661 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75662 +{
75663 + struct page *page;
75664 + const slob_t *free;
75665 + const void *base;
75666 + unsigned long flags;
75667 +
75668 + if (ZERO_OR_NULL_PTR(ptr))
75669 + return "<null>";
75670 +
75671 + if (!virt_addr_valid(ptr))
75672 + return NULL;
75673 +
75674 + page = virt_to_head_page(ptr);
75675 + if (!PageSlab(page))
75676 + return NULL;
75677 +
75678 + if (page->private) {
75679 + base = page;
75680 + if (base <= ptr && n <= page->private - (ptr - base))
75681 + return NULL;
75682 + return "<slob>";
75683 + }
75684 +
75685 + /* some tricky double walking to find the chunk */
75686 + spin_lock_irqsave(&slob_lock, flags);
75687 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75688 + free = page->freelist;
75689 +
75690 + while (!slob_last(free) && (void *)free <= ptr) {
75691 + base = free + slob_units(free);
75692 + free = slob_next(free);
75693 + }
75694 +
75695 + while (base < (void *)free) {
75696 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75697 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75698 + int offset;
75699 +
75700 + if (ptr < base + align)
75701 + break;
75702 +
75703 + offset = ptr - base - align;
75704 + if (offset >= m) {
75705 + base += size;
75706 + continue;
75707 + }
75708 +
75709 + if (n > m - offset)
75710 + break;
75711 +
75712 + spin_unlock_irqrestore(&slob_lock, flags);
75713 + return NULL;
75714 + }
75715 +
75716 + spin_unlock_irqrestore(&slob_lock, flags);
75717 + return "<slob>";
75718 +}
75719 +#endif
75720 +
75721 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75722 size_t ksize(const void *block)
75723 {
75724 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
75725 return 0;
75726
75727 sp = virt_to_page(block);
75728 - if (PageSlab(sp)) {
75729 + VM_BUG_ON(!PageSlab(sp));
75730 + if (!sp->private) {
75731 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75732 - unsigned int *m = (unsigned int *)(block - align);
75733 - return SLOB_UNITS(*m) * SLOB_UNIT;
75734 + slob_t *m = (slob_t *)(block - align);
75735 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75736 } else
75737 return sp->private;
75738 }
75739 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
75740
75741 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75742 {
75743 - void *b;
75744 + void *b = NULL;
75745
75746 flags &= gfp_allowed_mask;
75747
75748 lockdep_trace_alloc(flags);
75749
75750 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75751 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
75752 +#else
75753 if (c->size < PAGE_SIZE) {
75754 b = slob_alloc(c->size, flags, c->align, node);
75755 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75756 SLOB_UNITS(c->size) * SLOB_UNIT,
75757 flags, node);
75758 } else {
75759 - b = slob_new_pages(flags, get_order(c->size), node);
75760 + struct page *sp;
75761 +
75762 + sp = slob_new_pages(flags, get_order(c->size), node);
75763 + if (sp) {
75764 + b = page_address(sp);
75765 + sp->private = c->size;
75766 + }
75767 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75768 PAGE_SIZE << get_order(c->size),
75769 flags, node);
75770 }
75771 +#endif
75772
75773 if (c->ctor)
75774 c->ctor(b);
75775 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75776
75777 static void __kmem_cache_free(void *b, int size)
75778 {
75779 - if (size < PAGE_SIZE)
75780 + struct page *sp;
75781 +
75782 + sp = virt_to_page(b);
75783 + BUG_ON(!PageSlab(sp));
75784 + if (!sp->private)
75785 slob_free(b, size);
75786 else
75787 - slob_free_pages(b, get_order(size));
75788 + slob_free_pages(sp, get_order(size));
75789 }
75790
75791 static void kmem_rcu_free(struct rcu_head *head)
75792 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75793
75794 void kmem_cache_free(struct kmem_cache *c, void *b)
75795 {
75796 + int size = c->size;
75797 +
75798 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75799 + if (size + c->align < PAGE_SIZE) {
75800 + size += c->align;
75801 + b -= c->align;
75802 + }
75803 +#endif
75804 +
75805 kmemleak_free_recursive(b, c->flags);
75806 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75807 struct slob_rcu *slob_rcu;
75808 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75809 - slob_rcu->size = c->size;
75810 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75811 + slob_rcu->size = size;
75812 call_rcu(&slob_rcu->head, kmem_rcu_free);
75813 } else {
75814 - __kmem_cache_free(b, c->size);
75815 + __kmem_cache_free(b, size);
75816 }
75817
75818 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75819 + trace_kfree(_RET_IP_, b);
75820 +#else
75821 trace_kmem_cache_free(_RET_IP_, b);
75822 +#endif
75823 +
75824 }
75825 EXPORT_SYMBOL(kmem_cache_free);
75826
75827 diff --git a/mm/slub.c b/mm/slub.c
75828 index a0d6984..b77d8c9 100644
75829 --- a/mm/slub.c
75830 +++ b/mm/slub.c
75831 @@ -201,7 +201,7 @@ struct track {
75832
75833 enum track_item { TRACK_ALLOC, TRACK_FREE };
75834
75835 -#ifdef CONFIG_SYSFS
75836 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75837 static int sysfs_slab_add(struct kmem_cache *);
75838 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75839 static void sysfs_slab_remove(struct kmem_cache *);
75840 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
75841 if (!t->addr)
75842 return;
75843
75844 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75845 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75846 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75847 #ifdef CONFIG_STACKTRACE
75848 {
75849 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75850
75851 page = virt_to_head_page(x);
75852
75853 + BUG_ON(!PageSlab(page));
75854 +
75855 if (kmem_cache_debug(s) && page->slab != s) {
75856 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
75857 " is from %s\n", page->slab->name, s->name);
75858 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
75859 * Merge control. If this is set then no merging of slab caches will occur.
75860 * (Could be removed. This was introduced to pacify the merge skeptics.)
75861 */
75862 -static int slub_nomerge;
75863 +static int slub_nomerge = 1;
75864
75865 /*
75866 * Calculate the order of allocation given an slab object size.
75867 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
75868 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75869 #endif
75870
75871 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75872 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75873 +#endif
75874 +
75875 static int __init setup_slub_min_order(char *str)
75876 {
75877 get_option(&str, &slub_min_order);
75878 @@ -3342,6 +3348,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75879 return kmalloc_dma_caches[index];
75880
75881 #endif
75882 +
75883 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75884 + if (flags & SLAB_USERCOPY)
75885 + return kmalloc_usercopy_caches[index];
75886 +
75887 +#endif
75888 +
75889 return kmalloc_caches[index];
75890 }
75891
75892 @@ -3410,6 +3423,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75893 EXPORT_SYMBOL(__kmalloc_node);
75894 #endif
75895
75896 +bool is_usercopy_object(const void *ptr)
75897 +{
75898 + struct page *page;
75899 + struct kmem_cache *s;
75900 +
75901 + if (ZERO_OR_NULL_PTR(ptr))
75902 + return false;
75903 +
75904 + if (!slab_is_available())
75905 + return false;
75906 +
75907 + if (!virt_addr_valid(ptr))
75908 + return false;
75909 +
75910 + page = virt_to_head_page(ptr);
75911 +
75912 + if (!PageSlab(page))
75913 + return false;
75914 +
75915 + s = page->slab;
75916 + return s->flags & SLAB_USERCOPY;
75917 +}
75918 +
75919 +#ifdef CONFIG_PAX_USERCOPY
75920 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75921 +{
75922 + struct page *page;
75923 + struct kmem_cache *s;
75924 + unsigned long offset;
75925 +
75926 + if (ZERO_OR_NULL_PTR(ptr))
75927 + return "<null>";
75928 +
75929 + if (!virt_addr_valid(ptr))
75930 + return NULL;
75931 +
75932 + page = virt_to_head_page(ptr);
75933 +
75934 + if (!PageSlab(page))
75935 + return NULL;
75936 +
75937 + s = page->slab;
75938 + if (!(s->flags & SLAB_USERCOPY))
75939 + return s->name;
75940 +
75941 + offset = (ptr - page_address(page)) % s->size;
75942 + if (offset <= s->object_size && n <= s->object_size - offset)
75943 + return NULL;
75944 +
75945 + return s->name;
75946 +}
75947 +#endif
75948 +
75949 size_t ksize(const void *object)
75950 {
75951 struct page *page;
75952 @@ -3684,7 +3750,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75953 int node;
75954
75955 list_add(&s->list, &slab_caches);
75956 - s->refcount = -1;
75957 + atomic_set(&s->refcount, -1);
75958
75959 for_each_node_state(node, N_NORMAL_MEMORY) {
75960 struct kmem_cache_node *n = get_node(s, node);
75961 @@ -3807,17 +3873,17 @@ void __init kmem_cache_init(void)
75962
75963 /* Caches that are not of the two-to-the-power-of size */
75964 if (KMALLOC_MIN_SIZE <= 32) {
75965 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75966 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75967 caches++;
75968 }
75969
75970 if (KMALLOC_MIN_SIZE <= 64) {
75971 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75972 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75973 caches++;
75974 }
75975
75976 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75977 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75978 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75979 caches++;
75980 }
75981
75982 @@ -3859,6 +3925,22 @@ void __init kmem_cache_init(void)
75983 }
75984 }
75985 #endif
75986 +
75987 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75988 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75989 + struct kmem_cache *s = kmalloc_caches[i];
75990 +
75991 + if (s && s->size) {
75992 + char *name = kasprintf(GFP_NOWAIT,
75993 + "usercopy-kmalloc-%d", s->object_size);
75994 +
75995 + BUG_ON(!name);
75996 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75997 + s->object_size, SLAB_USERCOPY);
75998 + }
75999 + }
76000 +#endif
76001 +
76002 printk(KERN_INFO
76003 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
76004 " CPUs=%d, Nodes=%d\n",
76005 @@ -3885,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
76006 /*
76007 * We may have set a slab to be unmergeable during bootstrap.
76008 */
76009 - if (s->refcount < 0)
76010 + if (atomic_read(&s->refcount) < 0)
76011 return 1;
76012
76013 return 0;
76014 @@ -3939,7 +4021,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
76015
76016 s = find_mergeable(size, align, flags, name, ctor);
76017 if (s) {
76018 - s->refcount++;
76019 + atomic_inc(&s->refcount);
76020 /*
76021 * Adjust the object sizes so that we clear
76022 * the complete object on kzalloc.
76023 @@ -3948,7 +4030,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
76024 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
76025
76026 if (sysfs_slab_alias(s, name)) {
76027 - s->refcount--;
76028 + atomic_dec(&s->refcount);
76029 s = NULL;
76030 }
76031 }
76032 @@ -4063,7 +4145,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
76033 }
76034 #endif
76035
76036 -#ifdef CONFIG_SYSFS
76037 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76038 static int count_inuse(struct page *page)
76039 {
76040 return page->inuse;
76041 @@ -4450,12 +4532,12 @@ static void resiliency_test(void)
76042 validate_slab_cache(kmalloc_caches[9]);
76043 }
76044 #else
76045 -#ifdef CONFIG_SYSFS
76046 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76047 static void resiliency_test(void) {};
76048 #endif
76049 #endif
76050
76051 -#ifdef CONFIG_SYSFS
76052 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76053 enum slab_stat_type {
76054 SL_ALL, /* All slabs */
76055 SL_PARTIAL, /* Only partially allocated slabs */
76056 @@ -4699,7 +4781,7 @@ SLAB_ATTR_RO(ctor);
76057
76058 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
76059 {
76060 - return sprintf(buf, "%d\n", s->refcount - 1);
76061 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
76062 }
76063 SLAB_ATTR_RO(aliases);
76064
76065 @@ -5261,6 +5343,7 @@ static char *create_unique_id(struct kmem_cache *s)
76066 return name;
76067 }
76068
76069 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76070 static int sysfs_slab_add(struct kmem_cache *s)
76071 {
76072 int err;
76073 @@ -5323,6 +5406,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
76074 kobject_del(&s->kobj);
76075 kobject_put(&s->kobj);
76076 }
76077 +#endif
76078
76079 /*
76080 * Need to buffer aliases during bootup until sysfs becomes
76081 @@ -5336,6 +5420,7 @@ struct saved_alias {
76082
76083 static struct saved_alias *alias_list;
76084
76085 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
76086 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76087 {
76088 struct saved_alias *al;
76089 @@ -5358,6 +5443,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
76090 alias_list = al;
76091 return 0;
76092 }
76093 +#endif
76094
76095 static int __init slab_sysfs_init(void)
76096 {
76097 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
76098 index 1b7e22a..3fcd4f3 100644
76099 --- a/mm/sparse-vmemmap.c
76100 +++ b/mm/sparse-vmemmap.c
76101 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
76102 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76103 if (!p)
76104 return NULL;
76105 - pud_populate(&init_mm, pud, p);
76106 + pud_populate_kernel(&init_mm, pud, p);
76107 }
76108 return pud;
76109 }
76110 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
76111 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
76112 if (!p)
76113 return NULL;
76114 - pgd_populate(&init_mm, pgd, p);
76115 + pgd_populate_kernel(&init_mm, pgd, p);
76116 }
76117 return pgd;
76118 }
76119 diff --git a/mm/swap.c b/mm/swap.c
76120 index 6310dc2..3662b3f 100644
76121 --- a/mm/swap.c
76122 +++ b/mm/swap.c
76123 @@ -30,6 +30,7 @@
76124 #include <linux/backing-dev.h>
76125 #include <linux/memcontrol.h>
76126 #include <linux/gfp.h>
76127 +#include <linux/hugetlb.h>
76128
76129 #include "internal.h"
76130
76131 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
76132
76133 __page_cache_release(page);
76134 dtor = get_compound_page_dtor(page);
76135 + if (!PageHuge(page))
76136 + BUG_ON(dtor != free_compound_page);
76137 (*dtor)(page);
76138 }
76139
76140 diff --git a/mm/swapfile.c b/mm/swapfile.c
76141 index f91a255..9dcac21 100644
76142 --- a/mm/swapfile.c
76143 +++ b/mm/swapfile.c
76144 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
76145
76146 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
76147 /* Activity counter to indicate that a swapon or swapoff has occurred */
76148 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
76149 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
76150
76151 static inline unsigned char swap_count(unsigned char ent)
76152 {
76153 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
76154 }
76155 filp_close(swap_file, NULL);
76156 err = 0;
76157 - atomic_inc(&proc_poll_event);
76158 + atomic_inc_unchecked(&proc_poll_event);
76159 wake_up_interruptible(&proc_poll_wait);
76160
76161 out_dput:
76162 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
76163
76164 poll_wait(file, &proc_poll_wait, wait);
76165
76166 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
76167 - seq->poll_event = atomic_read(&proc_poll_event);
76168 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
76169 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76170 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
76171 }
76172
76173 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
76174 return ret;
76175
76176 seq = file->private_data;
76177 - seq->poll_event = atomic_read(&proc_poll_event);
76178 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
76179 return 0;
76180 }
76181
76182 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
76183 (frontswap_map) ? "FS" : "");
76184
76185 mutex_unlock(&swapon_mutex);
76186 - atomic_inc(&proc_poll_event);
76187 + atomic_inc_unchecked(&proc_poll_event);
76188 wake_up_interruptible(&proc_poll_wait);
76189
76190 if (S_ISREG(inode->i_mode))
76191 diff --git a/mm/util.c b/mm/util.c
76192 index dc3036c..b6c7c9d 100644
76193 --- a/mm/util.c
76194 +++ b/mm/util.c
76195 @@ -292,6 +292,12 @@ done:
76196 void arch_pick_mmap_layout(struct mm_struct *mm)
76197 {
76198 mm->mmap_base = TASK_UNMAPPED_BASE;
76199 +
76200 +#ifdef CONFIG_PAX_RANDMMAP
76201 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76202 + mm->mmap_base += mm->delta_mmap;
76203 +#endif
76204 +
76205 mm->get_unmapped_area = arch_get_unmapped_area;
76206 mm->unmap_area = arch_unmap_area;
76207 }
76208 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
76209 index 78e0830..8bfb8bd 100644
76210 --- a/mm/vmalloc.c
76211 +++ b/mm/vmalloc.c
76212 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
76213
76214 pte = pte_offset_kernel(pmd, addr);
76215 do {
76216 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76217 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76218 +
76219 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76220 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
76221 + BUG_ON(!pte_exec(*pte));
76222 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
76223 + continue;
76224 + }
76225 +#endif
76226 +
76227 + {
76228 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
76229 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
76230 + }
76231 } while (pte++, addr += PAGE_SIZE, addr != end);
76232 }
76233
76234 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
76235 pte = pte_alloc_kernel(pmd, addr);
76236 if (!pte)
76237 return -ENOMEM;
76238 +
76239 + pax_open_kernel();
76240 do {
76241 struct page *page = pages[*nr];
76242
76243 - if (WARN_ON(!pte_none(*pte)))
76244 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76245 + if (pgprot_val(prot) & _PAGE_NX)
76246 +#endif
76247 +
76248 + if (!pte_none(*pte)) {
76249 + pax_close_kernel();
76250 + WARN_ON(1);
76251 return -EBUSY;
76252 - if (WARN_ON(!page))
76253 + }
76254 + if (!page) {
76255 + pax_close_kernel();
76256 + WARN_ON(1);
76257 return -ENOMEM;
76258 + }
76259 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
76260 (*nr)++;
76261 } while (pte++, addr += PAGE_SIZE, addr != end);
76262 + pax_close_kernel();
76263 return 0;
76264 }
76265
76266 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
76267 pmd_t *pmd;
76268 unsigned long next;
76269
76270 - pmd = pmd_alloc(&init_mm, pud, addr);
76271 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
76272 if (!pmd)
76273 return -ENOMEM;
76274 do {
76275 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
76276 pud_t *pud;
76277 unsigned long next;
76278
76279 - pud = pud_alloc(&init_mm, pgd, addr);
76280 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
76281 if (!pud)
76282 return -ENOMEM;
76283 do {
76284 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
76285 * and fall back on vmalloc() if that fails. Others
76286 * just put it in the vmalloc space.
76287 */
76288 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
76289 +#ifdef CONFIG_MODULES
76290 +#ifdef MODULES_VADDR
76291 unsigned long addr = (unsigned long)x;
76292 if (addr >= MODULES_VADDR && addr < MODULES_END)
76293 return 1;
76294 #endif
76295 +
76296 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76297 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
76298 + return 1;
76299 +#endif
76300 +
76301 +#endif
76302 +
76303 return is_vmalloc_addr(x);
76304 }
76305
76306 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
76307
76308 if (!pgd_none(*pgd)) {
76309 pud_t *pud = pud_offset(pgd, addr);
76310 +#ifdef CONFIG_X86
76311 + if (!pud_large(*pud))
76312 +#endif
76313 if (!pud_none(*pud)) {
76314 pmd_t *pmd = pmd_offset(pud, addr);
76315 +#ifdef CONFIG_X86
76316 + if (!pmd_large(*pmd))
76317 +#endif
76318 if (!pmd_none(*pmd)) {
76319 pte_t *ptep, pte;
76320
76321 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
76322 * Allocate a region of KVA of the specified size and alignment, within the
76323 * vstart and vend.
76324 */
76325 -static struct vmap_area *alloc_vmap_area(unsigned long size,
76326 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
76327 unsigned long align,
76328 unsigned long vstart, unsigned long vend,
76329 int node, gfp_t gfp_mask)
76330 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
76331 struct vm_struct *area;
76332
76333 BUG_ON(in_interrupt());
76334 +
76335 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76336 + if (flags & VM_KERNEXEC) {
76337 + if (start != VMALLOC_START || end != VMALLOC_END)
76338 + return NULL;
76339 + start = (unsigned long)MODULES_EXEC_VADDR;
76340 + end = (unsigned long)MODULES_EXEC_END;
76341 + }
76342 +#endif
76343 +
76344 if (flags & VM_IOREMAP) {
76345 int bit = fls(size);
76346
76347 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
76348 if (count > totalram_pages)
76349 return NULL;
76350
76351 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76352 + if (!(pgprot_val(prot) & _PAGE_NX))
76353 + flags |= VM_KERNEXEC;
76354 +#endif
76355 +
76356 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
76357 __builtin_return_address(0));
76358 if (!area)
76359 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
76360 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
76361 goto fail;
76362
76363 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
76364 + if (!(pgprot_val(prot) & _PAGE_NX))
76365 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
76366 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
76367 + else
76368 +#endif
76369 +
76370 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
76371 start, end, node, gfp_mask, caller);
76372 if (!area)
76373 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
76374 * For tight control over page level allocator and protection flags
76375 * use __vmalloc() instead.
76376 */
76377 -
76378 void *vmalloc_exec(unsigned long size)
76379 {
76380 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
76381 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
76382 -1, __builtin_return_address(0));
76383 }
76384
76385 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
76386 unsigned long uaddr = vma->vm_start;
76387 unsigned long usize = vma->vm_end - vma->vm_start;
76388
76389 + BUG_ON(vma->vm_mirror);
76390 +
76391 if ((PAGE_SIZE-1) & (unsigned long)addr)
76392 return -EINVAL;
76393
76394 diff --git a/mm/vmstat.c b/mm/vmstat.c
76395 index c737057..a49753a 100644
76396 --- a/mm/vmstat.c
76397 +++ b/mm/vmstat.c
76398 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
76399 *
76400 * vm_stat contains the global counters
76401 */
76402 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76403 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
76404 EXPORT_SYMBOL(vm_stat);
76405
76406 #ifdef CONFIG_SMP
76407 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
76408 v = p->vm_stat_diff[i];
76409 p->vm_stat_diff[i] = 0;
76410 local_irq_restore(flags);
76411 - atomic_long_add(v, &zone->vm_stat[i]);
76412 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76413 global_diff[i] += v;
76414 #ifdef CONFIG_NUMA
76415 /* 3 seconds idle till flush */
76416 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
76417
76418 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
76419 if (global_diff[i])
76420 - atomic_long_add(global_diff[i], &vm_stat[i]);
76421 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
76422 }
76423
76424 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
76425 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
76426 if (pset->vm_stat_diff[i]) {
76427 int v = pset->vm_stat_diff[i];
76428 pset->vm_stat_diff[i] = 0;
76429 - atomic_long_add(v, &zone->vm_stat[i]);
76430 - atomic_long_add(v, &vm_stat[i]);
76431 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
76432 + atomic_long_add_unchecked(v, &vm_stat[i]);
76433 }
76434 }
76435 #endif
76436 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
76437 start_cpu_timer(cpu);
76438 #endif
76439 #ifdef CONFIG_PROC_FS
76440 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
76441 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
76442 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
76443 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
76444 + {
76445 + mode_t gr_mode = S_IRUGO;
76446 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76447 + gr_mode = S_IRUSR;
76448 +#endif
76449 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
76450 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
76451 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
76452 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
76453 +#else
76454 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
76455 +#endif
76456 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
76457 + }
76458 #endif
76459 return 0;
76460 }
76461 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
76462 index ee07072..e280bfa 100644
76463 --- a/net/8021q/vlan.c
76464 +++ b/net/8021q/vlan.c
76465 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
76466 err = -EPERM;
76467 if (!capable(CAP_NET_ADMIN))
76468 break;
76469 - if ((args.u.name_type >= 0) &&
76470 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
76471 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
76472 struct vlan_net *vn;
76473
76474 vn = net_generic(net, vlan_net_id);
76475 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
76476 index 02efb25..41541a9 100644
76477 --- a/net/9p/trans_fd.c
76478 +++ b/net/9p/trans_fd.c
76479 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
76480 oldfs = get_fs();
76481 set_fs(get_ds());
76482 /* The cast to a user pointer is valid due to the set_fs() */
76483 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
76484 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
76485 set_fs(oldfs);
76486
76487 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
76488 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76489 index 876fbe8..8bbea9f 100644
76490 --- a/net/atm/atm_misc.c
76491 +++ b/net/atm/atm_misc.c
76492 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76493 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76494 return 1;
76495 atm_return(vcc, truesize);
76496 - atomic_inc(&vcc->stats->rx_drop);
76497 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76498 return 0;
76499 }
76500 EXPORT_SYMBOL(atm_charge);
76501 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76502 }
76503 }
76504 atm_return(vcc, guess);
76505 - atomic_inc(&vcc->stats->rx_drop);
76506 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76507 return NULL;
76508 }
76509 EXPORT_SYMBOL(atm_alloc_charge);
76510 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76511
76512 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76513 {
76514 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76515 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76516 __SONET_ITEMS
76517 #undef __HANDLE_ITEM
76518 }
76519 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76520
76521 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76522 {
76523 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76524 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76525 __SONET_ITEMS
76526 #undef __HANDLE_ITEM
76527 }
76528 diff --git a/net/atm/lec.h b/net/atm/lec.h
76529 index a86aff9..3a0d6f6 100644
76530 --- a/net/atm/lec.h
76531 +++ b/net/atm/lec.h
76532 @@ -48,7 +48,7 @@ struct lane2_ops {
76533 const u8 *tlvs, u32 sizeoftlvs);
76534 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76535 const u8 *tlvs, u32 sizeoftlvs);
76536 -};
76537 +} __no_const;
76538
76539 /*
76540 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76541 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76542 index 0919a88..a23d54e 100644
76543 --- a/net/atm/mpc.h
76544 +++ b/net/atm/mpc.h
76545 @@ -33,7 +33,7 @@ struct mpoa_client {
76546 struct mpc_parameters parameters; /* parameters for this client */
76547
76548 const struct net_device_ops *old_ops;
76549 - struct net_device_ops new_ops;
76550 + net_device_ops_no_const new_ops;
76551 };
76552
76553
76554 diff --git a/net/atm/proc.c b/net/atm/proc.c
76555 index 0d020de..011c7bb 100644
76556 --- a/net/atm/proc.c
76557 +++ b/net/atm/proc.c
76558 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76559 const struct k_atm_aal_stats *stats)
76560 {
76561 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76562 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76563 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76564 - atomic_read(&stats->rx_drop));
76565 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76566 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76567 + atomic_read_unchecked(&stats->rx_drop));
76568 }
76569
76570 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76571 diff --git a/net/atm/resources.c b/net/atm/resources.c
76572 index 0447d5d..3cf4728 100644
76573 --- a/net/atm/resources.c
76574 +++ b/net/atm/resources.c
76575 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76576 static void copy_aal_stats(struct k_atm_aal_stats *from,
76577 struct atm_aal_stats *to)
76578 {
76579 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76580 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76581 __AAL_STAT_ITEMS
76582 #undef __HANDLE_ITEM
76583 }
76584 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76585 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76586 struct atm_aal_stats *to)
76587 {
76588 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76589 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76590 __AAL_STAT_ITEMS
76591 #undef __HANDLE_ITEM
76592 }
76593 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76594 index b02b75d..0a9636e 100644
76595 --- a/net/batman-adv/bat_iv_ogm.c
76596 +++ b/net/batman-adv/bat_iv_ogm.c
76597 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76598
76599 /* randomize initial seqno to avoid collision */
76600 get_random_bytes(&random_seqno, sizeof(random_seqno));
76601 - atomic_set(&hard_iface->seqno, random_seqno);
76602 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76603
76604 hard_iface->packet_len = BATADV_OGM_HLEN;
76605 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76606 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76607 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
76608
76609 /* change sequence number to network order */
76610 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
76611 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
76612 batadv_ogm_packet->seqno = htonl(seqno);
76613 - atomic_inc(&hard_iface->seqno);
76614 + atomic_inc_unchecked(&hard_iface->seqno);
76615
76616 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
76617 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
76618 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76619 return;
76620
76621 /* could be changed by schedule_own_packet() */
76622 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76623 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76624
76625 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76626 has_directlink_flag = 1;
76627 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76628 index d112fd6..686a447 100644
76629 --- a/net/batman-adv/hard-interface.c
76630 +++ b/net/batman-adv/hard-interface.c
76631 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76632 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76633 dev_add_pack(&hard_iface->batman_adv_ptype);
76634
76635 - atomic_set(&hard_iface->frag_seqno, 1);
76636 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76637 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76638 hard_iface->net_dev->name);
76639
76640 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76641 /* This can't be called via a bat_priv callback because
76642 * we have no bat_priv yet.
76643 */
76644 - atomic_set(&hard_iface->seqno, 1);
76645 + atomic_set_unchecked(&hard_iface->seqno, 1);
76646 hard_iface->packet_buff = NULL;
76647
76648 return hard_iface;
76649 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76650 index ce0684a..4a0cbf1 100644
76651 --- a/net/batman-adv/soft-interface.c
76652 +++ b/net/batman-adv/soft-interface.c
76653 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76654 primary_if->net_dev->dev_addr, ETH_ALEN);
76655
76656 /* set broadcast sequence number */
76657 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
76658 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
76659 bcast_packet->seqno = htonl(seqno);
76660
76661 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76662 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
76663 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76664
76665 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76666 - atomic_set(&bat_priv->bcast_seqno, 1);
76667 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76668 atomic_set(&bat_priv->tt.vn, 0);
76669 atomic_set(&bat_priv->tt.local_changes, 0);
76670 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
76671 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76672 index ac1e07a..4c846e2 100644
76673 --- a/net/batman-adv/types.h
76674 +++ b/net/batman-adv/types.h
76675 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76676 int16_t if_num;
76677 char if_status;
76678 struct net_device *net_dev;
76679 - atomic_t seqno;
76680 - atomic_t frag_seqno;
76681 + atomic_unchecked_t seqno;
76682 + atomic_unchecked_t frag_seqno;
76683 unsigned char *packet_buff;
76684 int packet_len;
76685 struct kobject *hardif_obj;
76686 @@ -244,7 +244,7 @@ struct batadv_priv {
76687 atomic_t orig_interval; /* uint */
76688 atomic_t hop_penalty; /* uint */
76689 atomic_t log_level; /* uint */
76690 - atomic_t bcast_seqno;
76691 + atomic_unchecked_t bcast_seqno;
76692 atomic_t bcast_queue_left;
76693 atomic_t batman_queue_left;
76694 char num_ifaces;
76695 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76696 index f397232..3206a33 100644
76697 --- a/net/batman-adv/unicast.c
76698 +++ b/net/batman-adv/unicast.c
76699 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76700 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76701 frag2->flags = large_tail;
76702
76703 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76704 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76705 frag1->seqno = htons(seqno - 1);
76706 frag2->seqno = htons(seqno);
76707
76708 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76709 index 07f0739..3c42e34 100644
76710 --- a/net/bluetooth/hci_sock.c
76711 +++ b/net/bluetooth/hci_sock.c
76712 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76713 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76714 }
76715
76716 - len = min_t(unsigned int, len, sizeof(uf));
76717 + len = min((size_t)len, sizeof(uf));
76718 if (copy_from_user(&uf, optval, len)) {
76719 err = -EFAULT;
76720 break;
76721 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76722 index a91239d..d7ed533 100644
76723 --- a/net/bluetooth/l2cap_core.c
76724 +++ b/net/bluetooth/l2cap_core.c
76725 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76726 break;
76727
76728 case L2CAP_CONF_RFC:
76729 - if (olen == sizeof(rfc))
76730 - memcpy(&rfc, (void *)val, olen);
76731 + if (olen != sizeof(rfc))
76732 + break;
76733 +
76734 + memcpy(&rfc, (void *)val, olen);
76735
76736 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76737 rfc.mode != chan->mode)
76738 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76739 index 083f2bf..799f9448 100644
76740 --- a/net/bluetooth/l2cap_sock.c
76741 +++ b/net/bluetooth/l2cap_sock.c
76742 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76743 struct sock *sk = sock->sk;
76744 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76745 struct l2cap_options opts;
76746 - int len, err = 0;
76747 + int err = 0;
76748 + size_t len = optlen;
76749 u32 opt;
76750
76751 BT_DBG("sk %p", sk);
76752 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76753 opts.max_tx = chan->max_tx;
76754 opts.txwin_size = chan->tx_win;
76755
76756 - len = min_t(unsigned int, sizeof(opts), optlen);
76757 + len = min(sizeof(opts), len);
76758 if (copy_from_user((char *) &opts, optval, len)) {
76759 err = -EFAULT;
76760 break;
76761 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76762 struct bt_security sec;
76763 struct bt_power pwr;
76764 struct l2cap_conn *conn;
76765 - int len, err = 0;
76766 + int err = 0;
76767 + size_t len = optlen;
76768 u32 opt;
76769
76770 BT_DBG("sk %p", sk);
76771 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76772
76773 sec.level = BT_SECURITY_LOW;
76774
76775 - len = min_t(unsigned int, sizeof(sec), optlen);
76776 + len = min(sizeof(sec), len);
76777 if (copy_from_user((char *) &sec, optval, len)) {
76778 err = -EFAULT;
76779 break;
76780 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76781
76782 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76783
76784 - len = min_t(unsigned int, sizeof(pwr), optlen);
76785 + len = min(sizeof(pwr), len);
76786 if (copy_from_user((char *) &pwr, optval, len)) {
76787 err = -EFAULT;
76788 break;
76789 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76790 index b3226f3..8916f43 100644
76791 --- a/net/bluetooth/rfcomm/sock.c
76792 +++ b/net/bluetooth/rfcomm/sock.c
76793 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76794 struct sock *sk = sock->sk;
76795 struct bt_security sec;
76796 int err = 0;
76797 - size_t len;
76798 + size_t len = optlen;
76799 u32 opt;
76800
76801 BT_DBG("sk %p", sk);
76802 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76803
76804 sec.level = BT_SECURITY_LOW;
76805
76806 - len = min_t(unsigned int, sizeof(sec), optlen);
76807 + len = min(sizeof(sec), len);
76808 if (copy_from_user((char *) &sec, optval, len)) {
76809 err = -EFAULT;
76810 break;
76811 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76812 index ccc2487..921073d 100644
76813 --- a/net/bluetooth/rfcomm/tty.c
76814 +++ b/net/bluetooth/rfcomm/tty.c
76815 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76816 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76817
76818 spin_lock_irqsave(&dev->port.lock, flags);
76819 - if (dev->port.count > 0) {
76820 + if (atomic_read(&dev->port.count) > 0) {
76821 spin_unlock_irqrestore(&dev->port.lock, flags);
76822 return;
76823 }
76824 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76825 return -ENODEV;
76826
76827 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76828 - dev->channel, dev->port.count);
76829 + dev->channel, atomic_read(&dev->port.count));
76830
76831 spin_lock_irqsave(&dev->port.lock, flags);
76832 - if (++dev->port.count > 1) {
76833 + if (atomic_inc_return(&dev->port.count) > 1) {
76834 spin_unlock_irqrestore(&dev->port.lock, flags);
76835 return 0;
76836 }
76837 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76838 return;
76839
76840 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76841 - dev->port.count);
76842 + atomic_read(&dev->port.count));
76843
76844 spin_lock_irqsave(&dev->port.lock, flags);
76845 - if (!--dev->port.count) {
76846 + if (!atomic_dec_return(&dev->port.count)) {
76847 spin_unlock_irqrestore(&dev->port.lock, flags);
76848 if (dev->tty_dev->parent)
76849 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76850 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76851 index 5fe2ff3..121d696 100644
76852 --- a/net/bridge/netfilter/ebtables.c
76853 +++ b/net/bridge/netfilter/ebtables.c
76854 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76855 tmp.valid_hooks = t->table->valid_hooks;
76856 }
76857 mutex_unlock(&ebt_mutex);
76858 - if (copy_to_user(user, &tmp, *len) != 0){
76859 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76860 BUGPRINT("c2u Didn't work\n");
76861 ret = -EFAULT;
76862 break;
76863 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76864 goto out;
76865 tmp.valid_hooks = t->valid_hooks;
76866
76867 - if (copy_to_user(user, &tmp, *len) != 0) {
76868 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76869 ret = -EFAULT;
76870 break;
76871 }
76872 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76873 tmp.entries_size = t->table->entries_size;
76874 tmp.valid_hooks = t->table->valid_hooks;
76875
76876 - if (copy_to_user(user, &tmp, *len) != 0) {
76877 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76878 ret = -EFAULT;
76879 break;
76880 }
76881 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76882 index 44f270f..1f5602d 100644
76883 --- a/net/caif/cfctrl.c
76884 +++ b/net/caif/cfctrl.c
76885 @@ -10,6 +10,7 @@
76886 #include <linux/spinlock.h>
76887 #include <linux/slab.h>
76888 #include <linux/pkt_sched.h>
76889 +#include <linux/sched.h>
76890 #include <net/caif/caif_layer.h>
76891 #include <net/caif/cfpkt.h>
76892 #include <net/caif/cfctrl.h>
76893 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76894 memset(&dev_info, 0, sizeof(dev_info));
76895 dev_info.id = 0xff;
76896 cfsrvl_init(&this->serv, 0, &dev_info, false);
76897 - atomic_set(&this->req_seq_no, 1);
76898 - atomic_set(&this->rsp_seq_no, 1);
76899 + atomic_set_unchecked(&this->req_seq_no, 1);
76900 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76901 this->serv.layer.receive = cfctrl_recv;
76902 sprintf(this->serv.layer.name, "ctrl");
76903 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76904 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76905 struct cfctrl_request_info *req)
76906 {
76907 spin_lock_bh(&ctrl->info_list_lock);
76908 - atomic_inc(&ctrl->req_seq_no);
76909 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76910 + atomic_inc_unchecked(&ctrl->req_seq_no);
76911 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76912 list_add_tail(&req->list, &ctrl->list);
76913 spin_unlock_bh(&ctrl->info_list_lock);
76914 }
76915 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76916 if (p != first)
76917 pr_warn("Requests are not received in order\n");
76918
76919 - atomic_set(&ctrl->rsp_seq_no,
76920 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76921 p->sequence_no);
76922 list_del(&p->list);
76923 goto out;
76924 diff --git a/net/can/gw.c b/net/can/gw.c
76925 index 1f5c978..522e050 100644
76926 --- a/net/can/gw.c
76927 +++ b/net/can/gw.c
76928 @@ -96,7 +96,7 @@ struct cf_mod {
76929 struct {
76930 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76931 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76932 - } csumfunc;
76933 + } __no_const csumfunc;
76934 };
76935
76936
76937 diff --git a/net/compat.c b/net/compat.c
76938 index 79ae884..17c5c09 100644
76939 --- a/net/compat.c
76940 +++ b/net/compat.c
76941 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76942 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76943 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76944 return -EFAULT;
76945 - kmsg->msg_name = compat_ptr(tmp1);
76946 - kmsg->msg_iov = compat_ptr(tmp2);
76947 - kmsg->msg_control = compat_ptr(tmp3);
76948 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76949 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76950 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76951 return 0;
76952 }
76953
76954 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76955
76956 if (kern_msg->msg_namelen) {
76957 if (mode == VERIFY_READ) {
76958 - int err = move_addr_to_kernel(kern_msg->msg_name,
76959 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76960 kern_msg->msg_namelen,
76961 kern_address);
76962 if (err < 0)
76963 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76964 kern_msg->msg_name = NULL;
76965
76966 tot_len = iov_from_user_compat_to_kern(kern_iov,
76967 - (struct compat_iovec __user *)kern_msg->msg_iov,
76968 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76969 kern_msg->msg_iovlen);
76970 if (tot_len >= 0)
76971 kern_msg->msg_iov = kern_iov;
76972 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76973
76974 #define CMSG_COMPAT_FIRSTHDR(msg) \
76975 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76976 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76977 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76978 (struct compat_cmsghdr __user *)NULL)
76979
76980 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76981 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76982 (ucmlen) <= (unsigned long) \
76983 ((mhdr)->msg_controllen - \
76984 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76985 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76986
76987 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76988 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76989 {
76990 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76991 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76992 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76993 msg->msg_controllen)
76994 return NULL;
76995 return (struct compat_cmsghdr __user *)ptr;
76996 @@ -219,7 +219,7 @@ Efault:
76997
76998 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76999 {
77000 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
77001 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
77002 struct compat_cmsghdr cmhdr;
77003 struct compat_timeval ctv;
77004 struct compat_timespec cts[3];
77005 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
77006
77007 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
77008 {
77009 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
77010 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
77011 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
77012 int fdnum = scm->fp->count;
77013 struct file **fp = scm->fp->fp;
77014 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
77015 return -EFAULT;
77016 old_fs = get_fs();
77017 set_fs(KERNEL_DS);
77018 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
77019 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
77020 set_fs(old_fs);
77021
77022 return err;
77023 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
77024 len = sizeof(ktime);
77025 old_fs = get_fs();
77026 set_fs(KERNEL_DS);
77027 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
77028 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
77029 set_fs(old_fs);
77030
77031 if (!err) {
77032 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77033 case MCAST_JOIN_GROUP:
77034 case MCAST_LEAVE_GROUP:
77035 {
77036 - struct compat_group_req __user *gr32 = (void *)optval;
77037 + struct compat_group_req __user *gr32 = (void __user *)optval;
77038 struct group_req __user *kgr =
77039 compat_alloc_user_space(sizeof(struct group_req));
77040 u32 interface;
77041 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77042 case MCAST_BLOCK_SOURCE:
77043 case MCAST_UNBLOCK_SOURCE:
77044 {
77045 - struct compat_group_source_req __user *gsr32 = (void *)optval;
77046 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
77047 struct group_source_req __user *kgsr = compat_alloc_user_space(
77048 sizeof(struct group_source_req));
77049 u32 interface;
77050 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
77051 }
77052 case MCAST_MSFILTER:
77053 {
77054 - struct compat_group_filter __user *gf32 = (void *)optval;
77055 + struct compat_group_filter __user *gf32 = (void __user *)optval;
77056 struct group_filter __user *kgf;
77057 u32 interface, fmode, numsrc;
77058
77059 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
77060 char __user *optval, int __user *optlen,
77061 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
77062 {
77063 - struct compat_group_filter __user *gf32 = (void *)optval;
77064 + struct compat_group_filter __user *gf32 = (void __user *)optval;
77065 struct group_filter __user *kgf;
77066 int __user *koptlen;
77067 u32 interface, fmode, numsrc;
77068 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
77069
77070 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
77071 return -EINVAL;
77072 - if (copy_from_user(a, args, nas[call]))
77073 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
77074 return -EFAULT;
77075 a0 = a[0];
77076 a1 = a[1];
77077 diff --git a/net/core/datagram.c b/net/core/datagram.c
77078 index 0337e2b..47914a0 100644
77079 --- a/net/core/datagram.c
77080 +++ b/net/core/datagram.c
77081 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
77082 }
77083
77084 kfree_skb(skb);
77085 - atomic_inc(&sk->sk_drops);
77086 + atomic_inc_unchecked(&sk->sk_drops);
77087 sk_mem_reclaim_partial(sk);
77088
77089 return err;
77090 diff --git a/net/core/dev.c b/net/core/dev.c
77091 index e5942bf..25998c3 100644
77092 --- a/net/core/dev.c
77093 +++ b/net/core/dev.c
77094 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
77095 if (no_module && capable(CAP_NET_ADMIN))
77096 no_module = request_module("netdev-%s", name);
77097 if (no_module && capable(CAP_SYS_MODULE)) {
77098 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
77099 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
77100 +#else
77101 if (!request_module("%s", name))
77102 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
77103 name);
77104 +#endif
77105 }
77106 }
77107 EXPORT_SYMBOL(dev_load);
77108 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77109 {
77110 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
77111 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
77112 - atomic_long_inc(&dev->rx_dropped);
77113 + atomic_long_inc_unchecked(&dev->rx_dropped);
77114 kfree_skb(skb);
77115 return NET_RX_DROP;
77116 }
77117 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
77118 nf_reset(skb);
77119
77120 if (unlikely(!is_skb_forwardable(dev, skb))) {
77121 - atomic_long_inc(&dev->rx_dropped);
77122 + atomic_long_inc_unchecked(&dev->rx_dropped);
77123 kfree_skb(skb);
77124 return NET_RX_DROP;
77125 }
77126 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
77127
77128 struct dev_gso_cb {
77129 void (*destructor)(struct sk_buff *skb);
77130 -};
77131 +} __no_const;
77132
77133 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
77134
77135 @@ -2955,7 +2959,7 @@ enqueue:
77136
77137 local_irq_restore(flags);
77138
77139 - atomic_long_inc(&skb->dev->rx_dropped);
77140 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77141 kfree_skb(skb);
77142 return NET_RX_DROP;
77143 }
77144 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
77145 }
77146 EXPORT_SYMBOL(netif_rx_ni);
77147
77148 -static void net_tx_action(struct softirq_action *h)
77149 +static void net_tx_action(void)
77150 {
77151 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77152
77153 @@ -3358,7 +3362,7 @@ ncls:
77154 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
77155 } else {
77156 drop:
77157 - atomic_long_inc(&skb->dev->rx_dropped);
77158 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
77159 kfree_skb(skb);
77160 /* Jamal, now you will not able to escape explaining
77161 * me how you were going to use this. :-)
77162 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
77163 }
77164 EXPORT_SYMBOL(netif_napi_del);
77165
77166 -static void net_rx_action(struct softirq_action *h)
77167 +static void net_rx_action(void)
77168 {
77169 struct softnet_data *sd = &__get_cpu_var(softnet_data);
77170 unsigned long time_limit = jiffies + 2;
77171 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
77172 else
77173 seq_printf(seq, "%04x", ntohs(pt->type));
77174
77175 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77176 + seq_printf(seq, " %-8s %p\n",
77177 + pt->dev ? pt->dev->name : "", NULL);
77178 +#else
77179 seq_printf(seq, " %-8s %pF\n",
77180 pt->dev ? pt->dev->name : "", pt->func);
77181 +#endif
77182 }
77183
77184 return 0;
77185 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
77186 } else {
77187 netdev_stats_to_stats64(storage, &dev->stats);
77188 }
77189 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
77190 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
77191 return storage;
77192 }
77193 EXPORT_SYMBOL(dev_get_stats);
77194 diff --git a/net/core/flow.c b/net/core/flow.c
77195 index e318c7e..168b1d0 100644
77196 --- a/net/core/flow.c
77197 +++ b/net/core/flow.c
77198 @@ -61,7 +61,7 @@ struct flow_cache {
77199 struct timer_list rnd_timer;
77200 };
77201
77202 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
77203 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
77204 EXPORT_SYMBOL(flow_cache_genid);
77205 static struct flow_cache flow_cache_global;
77206 static struct kmem_cache *flow_cachep __read_mostly;
77207 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
77208
77209 static int flow_entry_valid(struct flow_cache_entry *fle)
77210 {
77211 - if (atomic_read(&flow_cache_genid) != fle->genid)
77212 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
77213 return 0;
77214 if (fle->object && !fle->object->ops->check(fle->object))
77215 return 0;
77216 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
77217 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
77218 fcp->hash_count++;
77219 }
77220 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
77221 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
77222 flo = fle->object;
77223 if (!flo)
77224 goto ret_object;
77225 @@ -280,7 +280,7 @@ nocache:
77226 }
77227 flo = resolver(net, key, family, dir, flo, ctx);
77228 if (fle) {
77229 - fle->genid = atomic_read(&flow_cache_genid);
77230 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
77231 if (!IS_ERR(flo))
77232 fle->object = flo;
77233 else
77234 diff --git a/net/core/iovec.c b/net/core/iovec.c
77235 index 7e7aeb0..2a998cb 100644
77236 --- a/net/core/iovec.c
77237 +++ b/net/core/iovec.c
77238 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77239 if (m->msg_namelen) {
77240 if (mode == VERIFY_READ) {
77241 void __user *namep;
77242 - namep = (void __user __force *) m->msg_name;
77243 + namep = (void __force_user *) m->msg_name;
77244 err = move_addr_to_kernel(namep, m->msg_namelen,
77245 address);
77246 if (err < 0)
77247 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
77248 }
77249
77250 size = m->msg_iovlen * sizeof(struct iovec);
77251 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
77252 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
77253 return -EFAULT;
77254
77255 m->msg_iov = iov;
77256 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
77257 index fad649a..df5891e 100644
77258 --- a/net/core/rtnetlink.c
77259 +++ b/net/core/rtnetlink.c
77260 @@ -58,7 +58,7 @@ struct rtnl_link {
77261 rtnl_doit_func doit;
77262 rtnl_dumpit_func dumpit;
77263 rtnl_calcit_func calcit;
77264 -};
77265 +} __no_const;
77266
77267 static DEFINE_MUTEX(rtnl_mutex);
77268
77269 diff --git a/net/core/scm.c b/net/core/scm.c
77270 index ab57084..0190c8f 100644
77271 --- a/net/core/scm.c
77272 +++ b/net/core/scm.c
77273 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
77274 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77275 {
77276 struct cmsghdr __user *cm
77277 - = (__force struct cmsghdr __user *)msg->msg_control;
77278 + = (struct cmsghdr __force_user *)msg->msg_control;
77279 struct cmsghdr cmhdr;
77280 int cmlen = CMSG_LEN(len);
77281 int err;
77282 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
77283 err = -EFAULT;
77284 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
77285 goto out;
77286 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
77287 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
77288 goto out;
77289 cmlen = CMSG_SPACE(len);
77290 if (msg->msg_controllen < cmlen)
77291 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
77292 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77293 {
77294 struct cmsghdr __user *cm
77295 - = (__force struct cmsghdr __user*)msg->msg_control;
77296 + = (struct cmsghdr __force_user *)msg->msg_control;
77297
77298 int fdmax = 0;
77299 int fdnum = scm->fp->count;
77300 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
77301 if (fdnum < fdmax)
77302 fdmax = fdnum;
77303
77304 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
77305 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
77306 i++, cmfptr++)
77307 {
77308 struct socket *sock;
77309 diff --git a/net/core/sock.c b/net/core/sock.c
77310 index 8a146cf..ee08914d 100644
77311 --- a/net/core/sock.c
77312 +++ b/net/core/sock.c
77313 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77314 struct sk_buff_head *list = &sk->sk_receive_queue;
77315
77316 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
77317 - atomic_inc(&sk->sk_drops);
77318 + atomic_inc_unchecked(&sk->sk_drops);
77319 trace_sock_rcvqueue_full(sk, skb);
77320 return -ENOMEM;
77321 }
77322 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77323 return err;
77324
77325 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
77326 - atomic_inc(&sk->sk_drops);
77327 + atomic_inc_unchecked(&sk->sk_drops);
77328 return -ENOBUFS;
77329 }
77330
77331 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77332 skb_dst_force(skb);
77333
77334 spin_lock_irqsave(&list->lock, flags);
77335 - skb->dropcount = atomic_read(&sk->sk_drops);
77336 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
77337 __skb_queue_tail(list, skb);
77338 spin_unlock_irqrestore(&list->lock, flags);
77339
77340 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77341 skb->dev = NULL;
77342
77343 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
77344 - atomic_inc(&sk->sk_drops);
77345 + atomic_inc_unchecked(&sk->sk_drops);
77346 goto discard_and_relse;
77347 }
77348 if (nested)
77349 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
77350 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
77351 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
77352 bh_unlock_sock(sk);
77353 - atomic_inc(&sk->sk_drops);
77354 + atomic_inc_unchecked(&sk->sk_drops);
77355 goto discard_and_relse;
77356 }
77357
77358 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77359 struct timeval tm;
77360 } v;
77361
77362 - int lv = sizeof(int);
77363 - int len;
77364 + unsigned int lv = sizeof(int);
77365 + unsigned int len;
77366
77367 if (get_user(len, optlen))
77368 return -EFAULT;
77369 - if (len < 0)
77370 + if (len > INT_MAX)
77371 return -EINVAL;
77372
77373 memset(&v, 0, sizeof(v));
77374 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77375
77376 case SO_PEERNAME:
77377 {
77378 - char address[128];
77379 + char address[_K_SS_MAXSIZE];
77380
77381 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
77382 return -ENOTCONN;
77383 - if (lv < len)
77384 + if (lv < len || sizeof address < len)
77385 return -EINVAL;
77386 if (copy_to_user(optval, address, len))
77387 return -EFAULT;
77388 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
77389
77390 if (len > lv)
77391 len = lv;
77392 - if (copy_to_user(optval, &v, len))
77393 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
77394 return -EFAULT;
77395 lenout:
77396 if (put_user(len, optlen))
77397 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
77398 */
77399 smp_wmb();
77400 atomic_set(&sk->sk_refcnt, 1);
77401 - atomic_set(&sk->sk_drops, 0);
77402 + atomic_set_unchecked(&sk->sk_drops, 0);
77403 }
77404 EXPORT_SYMBOL(sock_init_data);
77405
77406 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
77407 index 602cd63..05c6c60 100644
77408 --- a/net/core/sock_diag.c
77409 +++ b/net/core/sock_diag.c
77410 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
77411
77412 int sock_diag_check_cookie(void *sk, __u32 *cookie)
77413 {
77414 +#ifndef CONFIG_GRKERNSEC_HIDESYM
77415 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
77416 cookie[1] != INET_DIAG_NOCOOKIE) &&
77417 ((u32)(unsigned long)sk != cookie[0] ||
77418 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
77419 return -ESTALE;
77420 else
77421 +#endif
77422 return 0;
77423 }
77424 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
77425
77426 void sock_diag_save_cookie(void *sk, __u32 *cookie)
77427 {
77428 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77429 + cookie[0] = 0;
77430 + cookie[1] = 0;
77431 +#else
77432 cookie[0] = (u32)(unsigned long)sk;
77433 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
77434 +#endif
77435 }
77436 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
77437
77438 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
77439 index a55eecc..dd8428c 100644
77440 --- a/net/decnet/sysctl_net_decnet.c
77441 +++ b/net/decnet/sysctl_net_decnet.c
77442 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
77443
77444 if (len > *lenp) len = *lenp;
77445
77446 - if (copy_to_user(buffer, addr, len))
77447 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
77448 return -EFAULT;
77449
77450 *lenp = len;
77451 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
77452
77453 if (len > *lenp) len = *lenp;
77454
77455 - if (copy_to_user(buffer, devname, len))
77456 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
77457 return -EFAULT;
77458
77459 *lenp = len;
77460 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
77461 index 825c608..750ff29 100644
77462 --- a/net/ipv4/fib_frontend.c
77463 +++ b/net/ipv4/fib_frontend.c
77464 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
77465 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77466 fib_sync_up(dev);
77467 #endif
77468 - atomic_inc(&net->ipv4.dev_addr_genid);
77469 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77470 rt_cache_flush(dev_net(dev));
77471 break;
77472 case NETDEV_DOWN:
77473 fib_del_ifaddr(ifa, NULL);
77474 - atomic_inc(&net->ipv4.dev_addr_genid);
77475 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77476 if (ifa->ifa_dev->ifa_list == NULL) {
77477 /* Last address was deleted from this interface.
77478 * Disable IP.
77479 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
77480 #ifdef CONFIG_IP_ROUTE_MULTIPATH
77481 fib_sync_up(dev);
77482 #endif
77483 - atomic_inc(&net->ipv4.dev_addr_genid);
77484 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
77485 rt_cache_flush(net);
77486 break;
77487 case NETDEV_DOWN:
77488 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
77489 index 71b125c..f4c70b0 100644
77490 --- a/net/ipv4/fib_semantics.c
77491 +++ b/net/ipv4/fib_semantics.c
77492 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77493 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77494 nh->nh_gw,
77495 nh->nh_parent->fib_scope);
77496 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77497 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77498
77499 return nh->nh_saddr;
77500 }
77501 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77502 index 7880af9..70f92a3 100644
77503 --- a/net/ipv4/inet_hashtables.c
77504 +++ b/net/ipv4/inet_hashtables.c
77505 @@ -18,12 +18,15 @@
77506 #include <linux/sched.h>
77507 #include <linux/slab.h>
77508 #include <linux/wait.h>
77509 +#include <linux/security.h>
77510
77511 #include <net/inet_connection_sock.h>
77512 #include <net/inet_hashtables.h>
77513 #include <net/secure_seq.h>
77514 #include <net/ip.h>
77515
77516 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77517 +
77518 /*
77519 * Allocate and initialize a new local port bind bucket.
77520 * The bindhash mutex for snum's hash chain must be held here.
77521 @@ -530,6 +533,8 @@ ok:
77522 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77523 spin_unlock(&head->lock);
77524
77525 + gr_update_task_in_ip_table(current, inet_sk(sk));
77526 +
77527 if (tw) {
77528 inet_twsk_deschedule(tw, death_row);
77529 while (twrefcnt) {
77530 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77531 index 000e3d2..5472da3 100644
77532 --- a/net/ipv4/inetpeer.c
77533 +++ b/net/ipv4/inetpeer.c
77534 @@ -503,8 +503,8 @@ relookup:
77535 if (p) {
77536 p->daddr = *daddr;
77537 atomic_set(&p->refcnt, 1);
77538 - atomic_set(&p->rid, 0);
77539 - atomic_set(&p->ip_id_count,
77540 + atomic_set_unchecked(&p->rid, 0);
77541 + atomic_set_unchecked(&p->ip_id_count,
77542 (daddr->family == AF_INET) ?
77543 secure_ip_id(daddr->addr.a4) :
77544 secure_ipv6_id(daddr->addr.a6));
77545 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77546 index 8d5cc75..821fd11 100644
77547 --- a/net/ipv4/ip_fragment.c
77548 +++ b/net/ipv4/ip_fragment.c
77549 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77550 return 0;
77551
77552 start = qp->rid;
77553 - end = atomic_inc_return(&peer->rid);
77554 + end = atomic_inc_return_unchecked(&peer->rid);
77555 qp->rid = end;
77556
77557 rc = qp->q.fragments && (end - start) > max;
77558 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77559 index 14bbfcf..644f472 100644
77560 --- a/net/ipv4/ip_sockglue.c
77561 +++ b/net/ipv4/ip_sockglue.c
77562 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77563 len = min_t(unsigned int, len, opt->optlen);
77564 if (put_user(len, optlen))
77565 return -EFAULT;
77566 - if (copy_to_user(optval, opt->__data, len))
77567 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77568 + copy_to_user(optval, opt->__data, len))
77569 return -EFAULT;
77570 return 0;
77571 }
77572 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77573 if (sk->sk_type != SOCK_STREAM)
77574 return -ENOPROTOOPT;
77575
77576 - msg.msg_control = optval;
77577 + msg.msg_control = (void __force_kernel *)optval;
77578 msg.msg_controllen = len;
77579 msg.msg_flags = flags;
77580
77581 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77582 index 798358b..73570b7 100644
77583 --- a/net/ipv4/ipconfig.c
77584 +++ b/net/ipv4/ipconfig.c
77585 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77586
77587 mm_segment_t oldfs = get_fs();
77588 set_fs(get_ds());
77589 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77590 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77591 set_fs(oldfs);
77592 return res;
77593 }
77594 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77595
77596 mm_segment_t oldfs = get_fs();
77597 set_fs(get_ds());
77598 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77599 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77600 set_fs(oldfs);
77601 return res;
77602 }
77603 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77604
77605 mm_segment_t oldfs = get_fs();
77606 set_fs(get_ds());
77607 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77608 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77609 set_fs(oldfs);
77610 return res;
77611 }
77612 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77613 index 97e61ea..cac1bbb 100644
77614 --- a/net/ipv4/netfilter/arp_tables.c
77615 +++ b/net/ipv4/netfilter/arp_tables.c
77616 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77617 #endif
77618
77619 static int get_info(struct net *net, void __user *user,
77620 - const int *len, int compat)
77621 + int len, int compat)
77622 {
77623 char name[XT_TABLE_MAXNAMELEN];
77624 struct xt_table *t;
77625 int ret;
77626
77627 - if (*len != sizeof(struct arpt_getinfo)) {
77628 - duprintf("length %u != %Zu\n", *len,
77629 + if (len != sizeof(struct arpt_getinfo)) {
77630 + duprintf("length %u != %Zu\n", len,
77631 sizeof(struct arpt_getinfo));
77632 return -EINVAL;
77633 }
77634 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77635 info.size = private->size;
77636 strcpy(info.name, name);
77637
77638 - if (copy_to_user(user, &info, *len) != 0)
77639 + if (copy_to_user(user, &info, len) != 0)
77640 ret = -EFAULT;
77641 else
77642 ret = 0;
77643 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77644
77645 switch (cmd) {
77646 case ARPT_SO_GET_INFO:
77647 - ret = get_info(sock_net(sk), user, len, 1);
77648 + ret = get_info(sock_net(sk), user, *len, 1);
77649 break;
77650 case ARPT_SO_GET_ENTRIES:
77651 ret = compat_get_entries(sock_net(sk), user, len);
77652 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77653
77654 switch (cmd) {
77655 case ARPT_SO_GET_INFO:
77656 - ret = get_info(sock_net(sk), user, len, 0);
77657 + ret = get_info(sock_net(sk), user, *len, 0);
77658 break;
77659
77660 case ARPT_SO_GET_ENTRIES:
77661 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77662 index 170b1fd..6105b91 100644
77663 --- a/net/ipv4/netfilter/ip_tables.c
77664 +++ b/net/ipv4/netfilter/ip_tables.c
77665 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77666 #endif
77667
77668 static int get_info(struct net *net, void __user *user,
77669 - const int *len, int compat)
77670 + int len, int compat)
77671 {
77672 char name[XT_TABLE_MAXNAMELEN];
77673 struct xt_table *t;
77674 int ret;
77675
77676 - if (*len != sizeof(struct ipt_getinfo)) {
77677 - duprintf("length %u != %zu\n", *len,
77678 + if (len != sizeof(struct ipt_getinfo)) {
77679 + duprintf("length %u != %zu\n", len,
77680 sizeof(struct ipt_getinfo));
77681 return -EINVAL;
77682 }
77683 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77684 info.size = private->size;
77685 strcpy(info.name, name);
77686
77687 - if (copy_to_user(user, &info, *len) != 0)
77688 + if (copy_to_user(user, &info, len) != 0)
77689 ret = -EFAULT;
77690 else
77691 ret = 0;
77692 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77693
77694 switch (cmd) {
77695 case IPT_SO_GET_INFO:
77696 - ret = get_info(sock_net(sk), user, len, 1);
77697 + ret = get_info(sock_net(sk), user, *len, 1);
77698 break;
77699 case IPT_SO_GET_ENTRIES:
77700 ret = compat_get_entries(sock_net(sk), user, len);
77701 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77702
77703 switch (cmd) {
77704 case IPT_SO_GET_INFO:
77705 - ret = get_info(sock_net(sk), user, len, 0);
77706 + ret = get_info(sock_net(sk), user, *len, 0);
77707 break;
77708
77709 case IPT_SO_GET_ENTRIES:
77710 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77711 index 8f3d054..c58d05d 100644
77712 --- a/net/ipv4/ping.c
77713 +++ b/net/ipv4/ping.c
77714 @@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77715 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
77716 0, sock_i_ino(sp),
77717 atomic_read(&sp->sk_refcnt), sp,
77718 - atomic_read(&sp->sk_drops), len);
77719 + atomic_read_unchecked(&sp->sk_drops), len);
77720 }
77721
77722 static int ping_seq_show(struct seq_file *seq, void *v)
77723 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77724 index 73d1e4d..3af0e8f 100644
77725 --- a/net/ipv4/raw.c
77726 +++ b/net/ipv4/raw.c
77727 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77728 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77729 {
77730 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77731 - atomic_inc(&sk->sk_drops);
77732 + atomic_inc_unchecked(&sk->sk_drops);
77733 kfree_skb(skb);
77734 return NET_RX_DROP;
77735 }
77736 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77737
77738 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77739 {
77740 + struct icmp_filter filter;
77741 +
77742 if (optlen > sizeof(struct icmp_filter))
77743 optlen = sizeof(struct icmp_filter);
77744 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77745 + if (copy_from_user(&filter, optval, optlen))
77746 return -EFAULT;
77747 + raw_sk(sk)->filter = filter;
77748 return 0;
77749 }
77750
77751 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77752 {
77753 int len, ret = -EFAULT;
77754 + struct icmp_filter filter;
77755
77756 if (get_user(len, optlen))
77757 goto out;
77758 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77759 if (len > sizeof(struct icmp_filter))
77760 len = sizeof(struct icmp_filter);
77761 ret = -EFAULT;
77762 - if (put_user(len, optlen) ||
77763 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77764 + filter = raw_sk(sk)->filter;
77765 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77766 goto out;
77767 ret = 0;
77768 out: return ret;
77769 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77770 0, 0L, 0,
77771 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
77772 0, sock_i_ino(sp),
77773 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77774 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
77775 }
77776
77777 static int raw_seq_show(struct seq_file *seq, void *v)
77778 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77779 index df25142..e92a82a 100644
77780 --- a/net/ipv4/route.c
77781 +++ b/net/ipv4/route.c
77782 @@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77783
77784 static __net_init int rt_genid_init(struct net *net)
77785 {
77786 - atomic_set(&net->rt_genid, 0);
77787 + atomic_set_unchecked(&net->rt_genid, 0);
77788 get_random_bytes(&net->ipv4.dev_addr_genid,
77789 sizeof(net->ipv4.dev_addr_genid));
77790 return 0;
77791 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77792 index 181fc82..f211869 100644
77793 --- a/net/ipv4/tcp_input.c
77794 +++ b/net/ipv4/tcp_input.c
77795 @@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77796 * simplifies code)
77797 */
77798 static void
77799 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77800 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77801 struct sk_buff *head, struct sk_buff *tail,
77802 u32 start, u32 end)
77803 {
77804 @@ -5536,6 +5536,9 @@ slow_path:
77805 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
77806 goto csum_error;
77807
77808 + if (!th->ack)
77809 + goto discard;
77810 +
77811 /*
77812 * Standard slow path.
77813 */
77814 @@ -5544,7 +5547,7 @@ slow_path:
77815 return 0;
77816
77817 step5:
77818 - if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
77819 + if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
77820 goto discard;
77821
77822 /* ts_recent update must be made after we are sure that the packet
77823 @@ -5930,7 +5933,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
77824 goto discard;
77825
77826 if (th->syn) {
77827 - if (th->fin)
77828 + if (th->fin || th->urg || th->psh)
77829 goto discard;
77830 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
77831 return 1;
77832 @@ -5977,11 +5980,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
77833 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
77834 goto discard;
77835 }
77836 +
77837 + if (!th->ack)
77838 + goto discard;
77839 +
77840 if (!tcp_validate_incoming(sk, skb, th, 0))
77841 return 0;
77842
77843 /* step 5: check the ACK field */
77844 - if (th->ack) {
77845 + if (true) {
77846 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
77847
77848 switch (sk->sk_state) {
77849 @@ -6131,8 +6138,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
77850 }
77851 break;
77852 }
77853 - } else
77854 - goto discard;
77855 + }
77856
77857 /* ts_recent update must be made after we are sure that the packet
77858 * is in window.
77859 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77860 index 0c4a643..e584990 100644
77861 --- a/net/ipv4/tcp_ipv4.c
77862 +++ b/net/ipv4/tcp_ipv4.c
77863 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77864 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77865
77866
77867 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77868 +extern int grsec_enable_blackhole;
77869 +#endif
77870 +
77871 #ifdef CONFIG_TCP_MD5SIG
77872 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77873 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77874 @@ -1901,6 +1905,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77875 return 0;
77876
77877 reset:
77878 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77879 + if (!grsec_enable_blackhole)
77880 +#endif
77881 tcp_v4_send_reset(rsk, skb);
77882 discard:
77883 kfree_skb(skb);
77884 @@ -2001,12 +2008,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77885 TCP_SKB_CB(skb)->sacked = 0;
77886
77887 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77888 - if (!sk)
77889 + if (!sk) {
77890 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77891 + ret = 1;
77892 +#endif
77893 goto no_tcp_socket;
77894 -
77895 + }
77896 process:
77897 - if (sk->sk_state == TCP_TIME_WAIT)
77898 + if (sk->sk_state == TCP_TIME_WAIT) {
77899 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77900 + ret = 2;
77901 +#endif
77902 goto do_time_wait;
77903 + }
77904
77905 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77906 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77907 @@ -2057,6 +2071,10 @@ no_tcp_socket:
77908 bad_packet:
77909 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77910 } else {
77911 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77912 + if (!grsec_enable_blackhole || (ret == 1 &&
77913 + (skb->dev->flags & IFF_LOOPBACK)))
77914 +#endif
77915 tcp_v4_send_reset(NULL, skb);
77916 }
77917
77918 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77919 index a7302d9..e3ec754 100644
77920 --- a/net/ipv4/tcp_minisocks.c
77921 +++ b/net/ipv4/tcp_minisocks.c
77922 @@ -27,6 +27,10 @@
77923 #include <net/inet_common.h>
77924 #include <net/xfrm.h>
77925
77926 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77927 +extern int grsec_enable_blackhole;
77928 +#endif
77929 +
77930 int sysctl_tcp_syncookies __read_mostly = 1;
77931 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77932
77933 @@ -742,7 +746,10 @@ embryonic_reset:
77934 * avoid becoming vulnerable to outside attack aiming at
77935 * resetting legit local connections.
77936 */
77937 - req->rsk_ops->send_reset(sk, skb);
77938 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77939 + if (!grsec_enable_blackhole)
77940 +#endif
77941 + req->rsk_ops->send_reset(sk, skb);
77942 } else if (fastopen) { /* received a valid RST pkt */
77943 reqsk_fastopen_remove(sk, req, true);
77944 tcp_reset(sk);
77945 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77946 index 4526fe6..1a34e43 100644
77947 --- a/net/ipv4/tcp_probe.c
77948 +++ b/net/ipv4/tcp_probe.c
77949 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77950 if (cnt + width >= len)
77951 break;
77952
77953 - if (copy_to_user(buf + cnt, tbuf, width))
77954 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77955 return -EFAULT;
77956 cnt += width;
77957 }
77958 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77959 index d47c1b4..b0584de 100644
77960 --- a/net/ipv4/tcp_timer.c
77961 +++ b/net/ipv4/tcp_timer.c
77962 @@ -22,6 +22,10 @@
77963 #include <linux/gfp.h>
77964 #include <net/tcp.h>
77965
77966 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77967 +extern int grsec_lastack_retries;
77968 +#endif
77969 +
77970 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77971 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77972 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77973 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77974 }
77975 }
77976
77977 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77978 + if ((sk->sk_state == TCP_LAST_ACK) &&
77979 + (grsec_lastack_retries > 0) &&
77980 + (grsec_lastack_retries < retry_until))
77981 + retry_until = grsec_lastack_retries;
77982 +#endif
77983 +
77984 if (retransmits_timed_out(sk, retry_until,
77985 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77986 /* Has it gone just too far? */
77987 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77988 index 79c8dbe..aceb1b6 100644
77989 --- a/net/ipv4/udp.c
77990 +++ b/net/ipv4/udp.c
77991 @@ -87,6 +87,7 @@
77992 #include <linux/types.h>
77993 #include <linux/fcntl.h>
77994 #include <linux/module.h>
77995 +#include <linux/security.h>
77996 #include <linux/socket.h>
77997 #include <linux/sockios.h>
77998 #include <linux/igmp.h>
77999 @@ -111,6 +112,10 @@
78000 #include <trace/events/skb.h>
78001 #include "udp_impl.h"
78002
78003 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78004 +extern int grsec_enable_blackhole;
78005 +#endif
78006 +
78007 struct udp_table udp_table __read_mostly;
78008 EXPORT_SYMBOL(udp_table);
78009
78010 @@ -569,6 +574,9 @@ found:
78011 return s;
78012 }
78013
78014 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
78015 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
78016 +
78017 /*
78018 * This routine is called by the ICMP module when it gets some
78019 * sort of error condition. If err < 0 then the socket should
78020 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
78021 dport = usin->sin_port;
78022 if (dport == 0)
78023 return -EINVAL;
78024 +
78025 + err = gr_search_udp_sendmsg(sk, usin);
78026 + if (err)
78027 + return err;
78028 } else {
78029 if (sk->sk_state != TCP_ESTABLISHED)
78030 return -EDESTADDRREQ;
78031 +
78032 + err = gr_search_udp_sendmsg(sk, NULL);
78033 + if (err)
78034 + return err;
78035 +
78036 daddr = inet->inet_daddr;
78037 dport = inet->inet_dport;
78038 /* Open fast path for connected socket.
78039 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
78040 udp_lib_checksum_complete(skb)) {
78041 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78042 IS_UDPLITE(sk));
78043 - atomic_inc(&sk->sk_drops);
78044 + atomic_inc_unchecked(&sk->sk_drops);
78045 __skb_unlink(skb, rcvq);
78046 __skb_queue_tail(&list_kill, skb);
78047 }
78048 @@ -1194,6 +1211,10 @@ try_again:
78049 if (!skb)
78050 goto out;
78051
78052 + err = gr_search_udp_recvmsg(sk, skb);
78053 + if (err)
78054 + goto out_free;
78055 +
78056 ulen = skb->len - sizeof(struct udphdr);
78057 copied = len;
78058 if (copied > ulen)
78059 @@ -1227,7 +1248,7 @@ try_again:
78060 if (unlikely(err)) {
78061 trace_kfree_skb(skb, udp_recvmsg);
78062 if (!peeked) {
78063 - atomic_inc(&sk->sk_drops);
78064 + atomic_inc_unchecked(&sk->sk_drops);
78065 UDP_INC_STATS_USER(sock_net(sk),
78066 UDP_MIB_INERRORS, is_udplite);
78067 }
78068 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78069
78070 drop:
78071 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78072 - atomic_inc(&sk->sk_drops);
78073 + atomic_inc_unchecked(&sk->sk_drops);
78074 kfree_skb(skb);
78075 return -1;
78076 }
78077 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78078 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78079
78080 if (!skb1) {
78081 - atomic_inc(&sk->sk_drops);
78082 + atomic_inc_unchecked(&sk->sk_drops);
78083 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78084 IS_UDPLITE(sk));
78085 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78086 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78087 goto csum_error;
78088
78089 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78090 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78091 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78092 +#endif
78093 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
78094
78095 /*
78096 @@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
78097 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
78098 0, sock_i_ino(sp),
78099 atomic_read(&sp->sk_refcnt), sp,
78100 - atomic_read(&sp->sk_drops), len);
78101 + atomic_read_unchecked(&sp->sk_drops), len);
78102 }
78103
78104 int udp4_seq_show(struct seq_file *seq, void *v)
78105 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
78106 index 0424e4e..308dd43 100644
78107 --- a/net/ipv6/addrconf.c
78108 +++ b/net/ipv6/addrconf.c
78109 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
78110 p.iph.ihl = 5;
78111 p.iph.protocol = IPPROTO_IPV6;
78112 p.iph.ttl = 64;
78113 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
78114 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
78115
78116 if (ops->ndo_do_ioctl) {
78117 mm_segment_t oldfs = get_fs();
78118 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
78119 index e02faed..9780f28 100644
78120 --- a/net/ipv6/ipv6_sockglue.c
78121 +++ b/net/ipv6/ipv6_sockglue.c
78122 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
78123 if (sk->sk_type != SOCK_STREAM)
78124 return -ENOPROTOOPT;
78125
78126 - msg.msg_control = optval;
78127 + msg.msg_control = (void __force_kernel *)optval;
78128 msg.msg_controllen = len;
78129 msg.msg_flags = flags;
78130
78131 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
78132 index d7cb045..8c0ded6 100644
78133 --- a/net/ipv6/netfilter/ip6_tables.c
78134 +++ b/net/ipv6/netfilter/ip6_tables.c
78135 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
78136 #endif
78137
78138 static int get_info(struct net *net, void __user *user,
78139 - const int *len, int compat)
78140 + int len, int compat)
78141 {
78142 char name[XT_TABLE_MAXNAMELEN];
78143 struct xt_table *t;
78144 int ret;
78145
78146 - if (*len != sizeof(struct ip6t_getinfo)) {
78147 - duprintf("length %u != %zu\n", *len,
78148 + if (len != sizeof(struct ip6t_getinfo)) {
78149 + duprintf("length %u != %zu\n", len,
78150 sizeof(struct ip6t_getinfo));
78151 return -EINVAL;
78152 }
78153 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
78154 info.size = private->size;
78155 strcpy(info.name, name);
78156
78157 - if (copy_to_user(user, &info, *len) != 0)
78158 + if (copy_to_user(user, &info, len) != 0)
78159 ret = -EFAULT;
78160 else
78161 ret = 0;
78162 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78163
78164 switch (cmd) {
78165 case IP6T_SO_GET_INFO:
78166 - ret = get_info(sock_net(sk), user, len, 1);
78167 + ret = get_info(sock_net(sk), user, *len, 1);
78168 break;
78169 case IP6T_SO_GET_ENTRIES:
78170 ret = compat_get_entries(sock_net(sk), user, len);
78171 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78172
78173 switch (cmd) {
78174 case IP6T_SO_GET_INFO:
78175 - ret = get_info(sock_net(sk), user, len, 0);
78176 + ret = get_info(sock_net(sk), user, *len, 0);
78177 break;
78178
78179 case IP6T_SO_GET_ENTRIES:
78180 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
78181 index d8e95c7..81422bc 100644
78182 --- a/net/ipv6/raw.c
78183 +++ b/net/ipv6/raw.c
78184 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
78185 {
78186 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
78187 skb_checksum_complete(skb)) {
78188 - atomic_inc(&sk->sk_drops);
78189 + atomic_inc_unchecked(&sk->sk_drops);
78190 kfree_skb(skb);
78191 return NET_RX_DROP;
78192 }
78193 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78194 struct raw6_sock *rp = raw6_sk(sk);
78195
78196 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
78197 - atomic_inc(&sk->sk_drops);
78198 + atomic_inc_unchecked(&sk->sk_drops);
78199 kfree_skb(skb);
78200 return NET_RX_DROP;
78201 }
78202 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
78203
78204 if (inet->hdrincl) {
78205 if (skb_checksum_complete(skb)) {
78206 - atomic_inc(&sk->sk_drops);
78207 + atomic_inc_unchecked(&sk->sk_drops);
78208 kfree_skb(skb);
78209 return NET_RX_DROP;
78210 }
78211 @@ -604,7 +604,7 @@ out:
78212 return err;
78213 }
78214
78215 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
78216 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
78217 struct flowi6 *fl6, struct dst_entry **dstp,
78218 unsigned int flags)
78219 {
78220 @@ -916,12 +916,15 @@ do_confirm:
78221 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
78222 char __user *optval, int optlen)
78223 {
78224 + struct icmp6_filter filter;
78225 +
78226 switch (optname) {
78227 case ICMPV6_FILTER:
78228 if (optlen > sizeof(struct icmp6_filter))
78229 optlen = sizeof(struct icmp6_filter);
78230 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
78231 + if (copy_from_user(&filter, optval, optlen))
78232 return -EFAULT;
78233 + raw6_sk(sk)->filter = filter;
78234 return 0;
78235 default:
78236 return -ENOPROTOOPT;
78237 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78238 char __user *optval, int __user *optlen)
78239 {
78240 int len;
78241 + struct icmp6_filter filter;
78242
78243 switch (optname) {
78244 case ICMPV6_FILTER:
78245 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
78246 len = sizeof(struct icmp6_filter);
78247 if (put_user(len, optlen))
78248 return -EFAULT;
78249 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
78250 + filter = raw6_sk(sk)->filter;
78251 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
78252 return -EFAULT;
78253 return 0;
78254 default:
78255 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
78256 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
78257 0,
78258 sock_i_ino(sp),
78259 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
78260 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
78261 }
78262
78263 static int raw6_seq_show(struct seq_file *seq, void *v)
78264 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
78265 index 26175bf..fc3e4fb 100644
78266 --- a/net/ipv6/tcp_ipv6.c
78267 +++ b/net/ipv6/tcp_ipv6.c
78268 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
78269 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
78270 }
78271
78272 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78273 +extern int grsec_enable_blackhole;
78274 +#endif
78275 +
78276 static void tcp_v6_hash(struct sock *sk)
78277 {
78278 if (sk->sk_state != TCP_CLOSE) {
78279 @@ -1524,6 +1528,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
78280 return 0;
78281
78282 reset:
78283 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78284 + if (!grsec_enable_blackhole)
78285 +#endif
78286 tcp_v6_send_reset(sk, skb);
78287 discard:
78288 if (opt_skb)
78289 @@ -1605,12 +1612,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
78290 TCP_SKB_CB(skb)->sacked = 0;
78291
78292 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
78293 - if (!sk)
78294 + if (!sk) {
78295 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78296 + ret = 1;
78297 +#endif
78298 goto no_tcp_socket;
78299 + }
78300
78301 process:
78302 - if (sk->sk_state == TCP_TIME_WAIT)
78303 + if (sk->sk_state == TCP_TIME_WAIT) {
78304 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78305 + ret = 2;
78306 +#endif
78307 goto do_time_wait;
78308 + }
78309
78310 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
78311 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
78312 @@ -1659,6 +1674,10 @@ no_tcp_socket:
78313 bad_packet:
78314 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
78315 } else {
78316 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78317 + if (!grsec_enable_blackhole || (ret == 1 &&
78318 + (skb->dev->flags & IFF_LOOPBACK)))
78319 +#endif
78320 tcp_v6_send_reset(NULL, skb);
78321 }
78322
78323 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
78324 index fc99972..69397e8 100644
78325 --- a/net/ipv6/udp.c
78326 +++ b/net/ipv6/udp.c
78327 @@ -51,6 +51,10 @@
78328 #include <trace/events/skb.h>
78329 #include "udp_impl.h"
78330
78331 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78332 +extern int grsec_enable_blackhole;
78333 +#endif
78334 +
78335 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
78336 {
78337 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
78338 @@ -395,7 +399,7 @@ try_again:
78339 if (unlikely(err)) {
78340 trace_kfree_skb(skb, udpv6_recvmsg);
78341 if (!peeked) {
78342 - atomic_inc(&sk->sk_drops);
78343 + atomic_inc_unchecked(&sk->sk_drops);
78344 if (is_udp4)
78345 UDP_INC_STATS_USER(sock_net(sk),
78346 UDP_MIB_INERRORS,
78347 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
78348 return rc;
78349 drop:
78350 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
78351 - atomic_inc(&sk->sk_drops);
78352 + atomic_inc_unchecked(&sk->sk_drops);
78353 kfree_skb(skb);
78354 return -1;
78355 }
78356 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
78357 if (likely(skb1 == NULL))
78358 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
78359 if (!skb1) {
78360 - atomic_inc(&sk->sk_drops);
78361 + atomic_inc_unchecked(&sk->sk_drops);
78362 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
78363 IS_UDPLITE(sk));
78364 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
78365 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
78366 goto discard;
78367
78368 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
78369 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78370 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
78371 +#endif
78372 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
78373
78374 kfree_skb(skb);
78375 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
78376 0,
78377 sock_i_ino(sp),
78378 atomic_read(&sp->sk_refcnt), sp,
78379 - atomic_read(&sp->sk_drops));
78380 + atomic_read_unchecked(&sp->sk_drops));
78381 }
78382
78383 int udp6_seq_show(struct seq_file *seq, void *v)
78384 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
78385 index 496ce2c..f79fac8 100644
78386 --- a/net/irda/ircomm/ircomm_tty.c
78387 +++ b/net/irda/ircomm/ircomm_tty.c
78388 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78389 add_wait_queue(&port->open_wait, &wait);
78390
78391 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
78392 - __FILE__, __LINE__, tty->driver->name, port->count);
78393 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78394
78395 spin_lock_irqsave(&port->lock, flags);
78396 if (!tty_hung_up_p(filp)) {
78397 extra_count = 1;
78398 - port->count--;
78399 + atomic_dec(&port->count);
78400 }
78401 spin_unlock_irqrestore(&port->lock, flags);
78402 port->blocked_open++;
78403 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78404 }
78405
78406 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78407 - __FILE__, __LINE__, tty->driver->name, port->count);
78408 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78409
78410 schedule();
78411 }
78412 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78413 if (extra_count) {
78414 /* ++ is not atomic, so this should be protected - Jean II */
78415 spin_lock_irqsave(&port->lock, flags);
78416 - port->count++;
78417 + atomic_inc(&port->count);
78418 spin_unlock_irqrestore(&port->lock, flags);
78419 }
78420 port->blocked_open--;
78421
78422 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78423 - __FILE__, __LINE__, tty->driver->name, port->count);
78424 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
78425
78426 if (!retval)
78427 port->flags |= ASYNC_NORMAL_ACTIVE;
78428 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78429
78430 /* ++ is not atomic, so this should be protected - Jean II */
78431 spin_lock_irqsave(&self->port.lock, flags);
78432 - self->port.count++;
78433 + atomic_inc(&self->port.count);
78434 spin_unlock_irqrestore(&self->port.lock, flags);
78435 tty_port_tty_set(&self->port, tty);
78436
78437 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78438 - self->line, self->port.count);
78439 + self->line, atomic_read(&self->port.count));
78440
78441 /* Not really used by us, but lets do it anyway */
78442 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78443 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78444 tty_kref_put(port->tty);
78445 }
78446 port->tty = NULL;
78447 - port->count = 0;
78448 + atomic_set(&port->count, 0);
78449 spin_unlock_irqrestore(&port->lock, flags);
78450
78451 wake_up_interruptible(&port->open_wait);
78452 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78453 seq_putc(m, '\n');
78454
78455 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78456 - seq_printf(m, "Open count: %d\n", self->port.count);
78457 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
78458 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78459 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78460
78461 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78462 index cd6f7a9..e63fe89 100644
78463 --- a/net/iucv/af_iucv.c
78464 +++ b/net/iucv/af_iucv.c
78465 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78466
78467 write_lock_bh(&iucv_sk_list.lock);
78468
78469 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78470 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78471 while (__iucv_get_sock_by_name(name)) {
78472 sprintf(name, "%08x",
78473 - atomic_inc_return(&iucv_sk_list.autobind_name));
78474 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78475 }
78476
78477 write_unlock_bh(&iucv_sk_list.lock);
78478 diff --git a/net/key/af_key.c b/net/key/af_key.c
78479 index 08897a3..0b812ab 100644
78480 --- a/net/key/af_key.c
78481 +++ b/net/key/af_key.c
78482 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78483 static u32 get_acqseq(void)
78484 {
78485 u32 res;
78486 - static atomic_t acqseq;
78487 + static atomic_unchecked_t acqseq;
78488
78489 do {
78490 - res = atomic_inc_return(&acqseq);
78491 + res = atomic_inc_return_unchecked(&acqseq);
78492 } while (!res);
78493 return res;
78494 }
78495 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
78496 index 7371f67..9897314 100644
78497 --- a/net/mac80211/cfg.c
78498 +++ b/net/mac80211/cfg.c
78499 @@ -2594,7 +2594,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
78500 else
78501 local->probe_req_reg--;
78502
78503 - if (!local->open_count)
78504 + if (!local_read(&local->open_count))
78505 break;
78506
78507 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
78508 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78509 index 156e583..900a7c7 100644
78510 --- a/net/mac80211/ieee80211_i.h
78511 +++ b/net/mac80211/ieee80211_i.h
78512 @@ -28,6 +28,7 @@
78513 #include <net/ieee80211_radiotap.h>
78514 #include <net/cfg80211.h>
78515 #include <net/mac80211.h>
78516 +#include <asm/local.h>
78517 #include "key.h"
78518 #include "sta_info.h"
78519 #include "debug.h"
78520 @@ -848,7 +849,7 @@ struct ieee80211_local {
78521 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78522 spinlock_t queue_stop_reason_lock;
78523
78524 - int open_count;
78525 + local_t open_count;
78526 int monitors, cooked_mntrs;
78527 /* number of interfaces with corresponding FIF_ flags */
78528 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78529 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78530 index 7de7717..3de8e97 100644
78531 --- a/net/mac80211/iface.c
78532 +++ b/net/mac80211/iface.c
78533 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78534 break;
78535 }
78536
78537 - if (local->open_count == 0) {
78538 + if (local_read(&local->open_count) == 0) {
78539 res = drv_start(local);
78540 if (res)
78541 goto err_del_bss;
78542 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78543 break;
78544 }
78545
78546 - if (local->monitors == 0 && local->open_count == 0) {
78547 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78548 res = ieee80211_add_virtual_monitor(local);
78549 if (res)
78550 goto err_stop;
78551 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78552 mutex_unlock(&local->mtx);
78553
78554 if (coming_up)
78555 - local->open_count++;
78556 + local_inc(&local->open_count);
78557
78558 if (hw_reconf_flags)
78559 ieee80211_hw_config(local, hw_reconf_flags);
78560 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
78561 err_del_interface:
78562 drv_remove_interface(local, sdata);
78563 err_stop:
78564 - if (!local->open_count)
78565 + if (!local_read(&local->open_count))
78566 drv_stop(local);
78567 err_del_bss:
78568 sdata->bss = NULL;
78569 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78570 }
78571
78572 if (going_down)
78573 - local->open_count--;
78574 + local_dec(&local->open_count);
78575
78576 switch (sdata->vif.type) {
78577 case NL80211_IFTYPE_AP_VLAN:
78578 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78579
78580 ieee80211_recalc_ps(local, -1);
78581
78582 - if (local->open_count == 0) {
78583 + if (local_read(&local->open_count) == 0) {
78584 if (local->ops->napi_poll)
78585 napi_disable(&local->napi);
78586 ieee80211_clear_tx_pending(local);
78587 @@ -859,7 +859,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78588 }
78589 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78590
78591 - if (local->monitors == local->open_count && local->monitors > 0)
78592 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78593 ieee80211_add_virtual_monitor(local);
78594 }
78595
78596 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78597 index f57f597..e0a7c03 100644
78598 --- a/net/mac80211/main.c
78599 +++ b/net/mac80211/main.c
78600 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78601 local->hw.conf.power_level = power;
78602 }
78603
78604 - if (changed && local->open_count) {
78605 + if (changed && local_read(&local->open_count)) {
78606 ret = drv_config(local, changed);
78607 /*
78608 * Goal:
78609 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78610 index 5c572e7..ecf75ce 100644
78611 --- a/net/mac80211/pm.c
78612 +++ b/net/mac80211/pm.c
78613 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78614 struct ieee80211_sub_if_data *sdata;
78615 struct sta_info *sta;
78616
78617 - if (!local->open_count)
78618 + if (!local_read(&local->open_count))
78619 goto suspend;
78620
78621 ieee80211_scan_cancel(local);
78622 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78623 cancel_work_sync(&local->dynamic_ps_enable_work);
78624 del_timer_sync(&local->dynamic_ps_timer);
78625
78626 - local->wowlan = wowlan && local->open_count;
78627 + local->wowlan = wowlan && local_read(&local->open_count);
78628 if (local->wowlan) {
78629 int err = drv_suspend(local, wowlan);
78630 if (err < 0) {
78631 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78632 drv_remove_interface(local, sdata);
78633
78634 /* stop hardware - this must stop RX */
78635 - if (local->open_count)
78636 + if (local_read(&local->open_count))
78637 ieee80211_stop_device(local);
78638
78639 suspend:
78640 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78641 index 3313c11..bec9f17 100644
78642 --- a/net/mac80211/rate.c
78643 +++ b/net/mac80211/rate.c
78644 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78645
78646 ASSERT_RTNL();
78647
78648 - if (local->open_count)
78649 + if (local_read(&local->open_count))
78650 return -EBUSY;
78651
78652 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78653 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78654 index c97a065..ff61928 100644
78655 --- a/net/mac80211/rc80211_pid_debugfs.c
78656 +++ b/net/mac80211/rc80211_pid_debugfs.c
78657 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78658
78659 spin_unlock_irqrestore(&events->lock, status);
78660
78661 - if (copy_to_user(buf, pb, p))
78662 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78663 return -EFAULT;
78664
78665 return p;
78666 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78667 index 0151ae3..26709d3 100644
78668 --- a/net/mac80211/util.c
78669 +++ b/net/mac80211/util.c
78670 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78671 }
78672 #endif
78673 /* everything else happens only if HW was up & running */
78674 - if (!local->open_count)
78675 + if (!local_read(&local->open_count))
78676 goto wake_up;
78677
78678 /*
78679 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78680 index fefa514..0755f23 100644
78681 --- a/net/netfilter/Kconfig
78682 +++ b/net/netfilter/Kconfig
78683 @@ -929,6 +929,16 @@ config NETFILTER_XT_MATCH_ESP
78684
78685 To compile it as a module, choose M here. If unsure, say N.
78686
78687 +config NETFILTER_XT_MATCH_GRADM
78688 + tristate '"gradm" match support'
78689 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78690 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78691 + ---help---
78692 + The gradm match allows to match on grsecurity RBAC being enabled.
78693 + It is useful when iptables rules are applied early on bootup to
78694 + prevent connections to the machine (except from a trusted host)
78695 + while the RBAC system is disabled.
78696 +
78697 config NETFILTER_XT_MATCH_HASHLIMIT
78698 tristate '"hashlimit" match support'
78699 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78700 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78701 index 3259697..54d5393 100644
78702 --- a/net/netfilter/Makefile
78703 +++ b/net/netfilter/Makefile
78704 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78705 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78706 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78707 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78708 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78709 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78710 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78711 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78712 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78713 index 1548df9..98ad9b4 100644
78714 --- a/net/netfilter/ipvs/ip_vs_conn.c
78715 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78716 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78717 /* Increase the refcnt counter of the dest */
78718 atomic_inc(&dest->refcnt);
78719
78720 - conn_flags = atomic_read(&dest->conn_flags);
78721 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78722 if (cp->protocol != IPPROTO_UDP)
78723 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78724 flags = cp->flags;
78725 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78726 atomic_set(&cp->refcnt, 1);
78727
78728 atomic_set(&cp->n_control, 0);
78729 - atomic_set(&cp->in_pkts, 0);
78730 + atomic_set_unchecked(&cp->in_pkts, 0);
78731
78732 atomic_inc(&ipvs->conn_count);
78733 if (flags & IP_VS_CONN_F_NO_CPORT)
78734 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78735
78736 /* Don't drop the entry if its number of incoming packets is not
78737 located in [0, 8] */
78738 - i = atomic_read(&cp->in_pkts);
78739 + i = atomic_read_unchecked(&cp->in_pkts);
78740 if (i > 8 || i < 0) return 0;
78741
78742 if (!todrop_rate[i]) return 0;
78743 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78744 index 58918e2..4d177a9 100644
78745 --- a/net/netfilter/ipvs/ip_vs_core.c
78746 +++ b/net/netfilter/ipvs/ip_vs_core.c
78747 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78748 ret = cp->packet_xmit(skb, cp, pd->pp);
78749 /* do not touch skb anymore */
78750
78751 - atomic_inc(&cp->in_pkts);
78752 + atomic_inc_unchecked(&cp->in_pkts);
78753 ip_vs_conn_put(cp);
78754 return ret;
78755 }
78756 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78757 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78758 pkts = sysctl_sync_threshold(ipvs);
78759 else
78760 - pkts = atomic_add_return(1, &cp->in_pkts);
78761 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78762
78763 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78764 ip_vs_sync_conn(net, cp, pkts);
78765 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78766 index c4ee437..a774a74 100644
78767 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78768 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78769 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78770 ip_vs_rs_hash(ipvs, dest);
78771 write_unlock_bh(&ipvs->rs_lock);
78772 }
78773 - atomic_set(&dest->conn_flags, conn_flags);
78774 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78775
78776 /* bind the service */
78777 if (!dest->svc) {
78778 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78779 " %-7s %-6d %-10d %-10d\n",
78780 &dest->addr.in6,
78781 ntohs(dest->port),
78782 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78783 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78784 atomic_read(&dest->weight),
78785 atomic_read(&dest->activeconns),
78786 atomic_read(&dest->inactconns));
78787 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78788 "%-7s %-6d %-10d %-10d\n",
78789 ntohl(dest->addr.ip),
78790 ntohs(dest->port),
78791 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78792 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78793 atomic_read(&dest->weight),
78794 atomic_read(&dest->activeconns),
78795 atomic_read(&dest->inactconns));
78796 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78797
78798 entry.addr = dest->addr.ip;
78799 entry.port = dest->port;
78800 - entry.conn_flags = atomic_read(&dest->conn_flags);
78801 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78802 entry.weight = atomic_read(&dest->weight);
78803 entry.u_threshold = dest->u_threshold;
78804 entry.l_threshold = dest->l_threshold;
78805 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78806 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78807 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78808 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78809 - (atomic_read(&dest->conn_flags) &
78810 + (atomic_read_unchecked(&dest->conn_flags) &
78811 IP_VS_CONN_F_FWD_MASK)) ||
78812 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78813 atomic_read(&dest->weight)) ||
78814 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78815 index effa10c..9058928 100644
78816 --- a/net/netfilter/ipvs/ip_vs_sync.c
78817 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78818 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78819 cp = cp->control;
78820 if (cp) {
78821 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78822 - pkts = atomic_add_return(1, &cp->in_pkts);
78823 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78824 else
78825 pkts = sysctl_sync_threshold(ipvs);
78826 ip_vs_sync_conn(net, cp->control, pkts);
78827 @@ -758,7 +758,7 @@ control:
78828 if (!cp)
78829 return;
78830 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78831 - pkts = atomic_add_return(1, &cp->in_pkts);
78832 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78833 else
78834 pkts = sysctl_sync_threshold(ipvs);
78835 goto sloop;
78836 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78837
78838 if (opt)
78839 memcpy(&cp->in_seq, opt, sizeof(*opt));
78840 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78841 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78842 cp->state = state;
78843 cp->old_state = cp->state;
78844 /*
78845 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78846 index cc4c809..50f8fe5 100644
78847 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78848 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78849 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78850 else
78851 rc = NF_ACCEPT;
78852 /* do not touch skb anymore */
78853 - atomic_inc(&cp->in_pkts);
78854 + atomic_inc_unchecked(&cp->in_pkts);
78855 goto out;
78856 }
78857
78858 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78859 else
78860 rc = NF_ACCEPT;
78861 /* do not touch skb anymore */
78862 - atomic_inc(&cp->in_pkts);
78863 + atomic_inc_unchecked(&cp->in_pkts);
78864 goto out;
78865 }
78866
78867 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78868 index 0f241be..2c9be6d 100644
78869 --- a/net/netfilter/nf_conntrack_core.c
78870 +++ b/net/netfilter/nf_conntrack_core.c
78871 @@ -1532,6 +1532,10 @@ err_extend:
78872 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78873 #define DYING_NULLS_VAL ((1<<30)+1)
78874
78875 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78876 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78877 +#endif
78878 +
78879 static int nf_conntrack_init_net(struct net *net)
78880 {
78881 int ret;
78882 @@ -1545,7 +1549,11 @@ static int nf_conntrack_init_net(struct net *net)
78883 goto err_stat;
78884 }
78885
78886 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78887 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78888 +#else
78889 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78890 +#endif
78891 if (!net->ct.slabname) {
78892 ret = -ENOMEM;
78893 goto err_slabname;
78894 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78895 index 9f199f2..719ad23 100644
78896 --- a/net/netfilter/nfnetlink_log.c
78897 +++ b/net/netfilter/nfnetlink_log.c
78898 @@ -71,7 +71,7 @@ struct nfulnl_instance {
78899 };
78900
78901 static DEFINE_SPINLOCK(instances_lock);
78902 -static atomic_t global_seq;
78903 +static atomic_unchecked_t global_seq;
78904
78905 #define INSTANCE_BUCKETS 16
78906 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78907 @@ -527,7 +527,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78908 /* global sequence number */
78909 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78910 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78911 - htonl(atomic_inc_return(&global_seq))))
78912 + htonl(atomic_inc_return_unchecked(&global_seq))))
78913 goto nla_put_failure;
78914
78915 if (data_len) {
78916 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78917 new file mode 100644
78918 index 0000000..c566332
78919 --- /dev/null
78920 +++ b/net/netfilter/xt_gradm.c
78921 @@ -0,0 +1,51 @@
78922 +/*
78923 + * gradm match for netfilter
78924 + * Copyright © Zbigniew Krzystolik, 2010
78925 + *
78926 + * This program is free software; you can redistribute it and/or modify
78927 + * it under the terms of the GNU General Public License; either version
78928 + * 2 or 3 as published by the Free Software Foundation.
78929 + */
78930 +#include <linux/module.h>
78931 +#include <linux/moduleparam.h>
78932 +#include <linux/skbuff.h>
78933 +#include <linux/netfilter/x_tables.h>
78934 +#include <linux/grsecurity.h>
78935 +#include <linux/netfilter/xt_gradm.h>
78936 +
78937 +static bool
78938 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78939 +{
78940 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78941 + bool retval = false;
78942 + if (gr_acl_is_enabled())
78943 + retval = true;
78944 + return retval ^ info->invflags;
78945 +}
78946 +
78947 +static struct xt_match gradm_mt_reg __read_mostly = {
78948 + .name = "gradm",
78949 + .revision = 0,
78950 + .family = NFPROTO_UNSPEC,
78951 + .match = gradm_mt,
78952 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78953 + .me = THIS_MODULE,
78954 +};
78955 +
78956 +static int __init gradm_mt_init(void)
78957 +{
78958 + return xt_register_match(&gradm_mt_reg);
78959 +}
78960 +
78961 +static void __exit gradm_mt_exit(void)
78962 +{
78963 + xt_unregister_match(&gradm_mt_reg);
78964 +}
78965 +
78966 +module_init(gradm_mt_init);
78967 +module_exit(gradm_mt_exit);
78968 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78969 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78970 +MODULE_LICENSE("GPL");
78971 +MODULE_ALIAS("ipt_gradm");
78972 +MODULE_ALIAS("ip6t_gradm");
78973 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78974 index 4fe4fb4..87a89e5 100644
78975 --- a/net/netfilter/xt_statistic.c
78976 +++ b/net/netfilter/xt_statistic.c
78977 @@ -19,7 +19,7 @@
78978 #include <linux/module.h>
78979
78980 struct xt_statistic_priv {
78981 - atomic_t count;
78982 + atomic_unchecked_t count;
78983 } ____cacheline_aligned_in_smp;
78984
78985 MODULE_LICENSE("GPL");
78986 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78987 break;
78988 case XT_STATISTIC_MODE_NTH:
78989 do {
78990 - oval = atomic_read(&info->master->count);
78991 + oval = atomic_read_unchecked(&info->master->count);
78992 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78993 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78994 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78995 if (nval == 0)
78996 ret = !ret;
78997 break;
78998 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78999 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
79000 if (info->master == NULL)
79001 return -ENOMEM;
79002 - atomic_set(&info->master->count, info->u.nth.count);
79003 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
79004
79005 return 0;
79006 }
79007 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
79008 index 4da797f..eb1df70 100644
79009 --- a/net/netlink/af_netlink.c
79010 +++ b/net/netlink/af_netlink.c
79011 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
79012 sk->sk_error_report(sk);
79013 }
79014 }
79015 - atomic_inc(&sk->sk_drops);
79016 + atomic_inc_unchecked(&sk->sk_drops);
79017 }
79018
79019 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
79020 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
79021 sk_wmem_alloc_get(s),
79022 nlk->cb,
79023 atomic_read(&s->sk_refcnt),
79024 - atomic_read(&s->sk_drops),
79025 + atomic_read_unchecked(&s->sk_drops),
79026 sock_i_ino(s)
79027 );
79028
79029 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
79030 index 7261eb8..44e8ac6 100644
79031 --- a/net/netrom/af_netrom.c
79032 +++ b/net/netrom/af_netrom.c
79033 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
79034 struct sock *sk = sock->sk;
79035 struct nr_sock *nr = nr_sk(sk);
79036
79037 + memset(sax, 0, sizeof(*sax));
79038 lock_sock(sk);
79039 if (peer != 0) {
79040 if (sk->sk_state != TCP_ESTABLISHED) {
79041 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
79042 *uaddr_len = sizeof(struct full_sockaddr_ax25);
79043 } else {
79044 sax->fsa_ax25.sax25_family = AF_NETROM;
79045 - sax->fsa_ax25.sax25_ndigis = 0;
79046 sax->fsa_ax25.sax25_call = nr->source_addr;
79047 *uaddr_len = sizeof(struct sockaddr_ax25);
79048 }
79049 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
79050 index 94060ed..9c066f3 100644
79051 --- a/net/packet/af_packet.c
79052 +++ b/net/packet/af_packet.c
79053 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
79054
79055 spin_lock(&sk->sk_receive_queue.lock);
79056 po->stats.tp_packets++;
79057 - skb->dropcount = atomic_read(&sk->sk_drops);
79058 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79059 __skb_queue_tail(&sk->sk_receive_queue, skb);
79060 spin_unlock(&sk->sk_receive_queue.lock);
79061 sk->sk_data_ready(sk, skb->len);
79062 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
79063 drop_n_acct:
79064 spin_lock(&sk->sk_receive_queue.lock);
79065 po->stats.tp_drops++;
79066 - atomic_inc(&sk->sk_drops);
79067 + atomic_inc_unchecked(&sk->sk_drops);
79068 spin_unlock(&sk->sk_receive_queue.lock);
79069
79070 drop_n_restore:
79071 @@ -2537,6 +2537,7 @@ out:
79072
79073 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
79074 {
79075 + struct sock_extended_err ee;
79076 struct sock_exterr_skb *serr;
79077 struct sk_buff *skb, *skb2;
79078 int copied, err;
79079 @@ -2558,8 +2559,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
79080 sock_recv_timestamp(msg, sk, skb);
79081
79082 serr = SKB_EXT_ERR(skb);
79083 + ee = serr->ee;
79084 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
79085 - sizeof(serr->ee), &serr->ee);
79086 + sizeof ee, &ee);
79087
79088 msg->msg_flags |= MSG_ERRQUEUE;
79089 err = copied;
79090 @@ -3171,7 +3173,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
79091 case PACKET_HDRLEN:
79092 if (len > sizeof(int))
79093 len = sizeof(int);
79094 - if (copy_from_user(&val, optval, len))
79095 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
79096 return -EFAULT;
79097 switch (val) {
79098 case TPACKET_V1:
79099 @@ -3210,7 +3212,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
79100 len = lv;
79101 if (put_user(len, optlen))
79102 return -EFAULT;
79103 - if (copy_to_user(optval, data, len))
79104 + if (len > sizeof(st) || copy_to_user(optval, data, len))
79105 return -EFAULT;
79106 return 0;
79107 }
79108 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
79109 index 5a940db..f0b9c12 100644
79110 --- a/net/phonet/af_phonet.c
79111 +++ b/net/phonet/af_phonet.c
79112 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
79113 {
79114 struct phonet_protocol *pp;
79115
79116 - if (protocol >= PHONET_NPROTO)
79117 + if (protocol < 0 || protocol >= PHONET_NPROTO)
79118 return NULL;
79119
79120 rcu_read_lock();
79121 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
79122 {
79123 int err = 0;
79124
79125 - if (protocol >= PHONET_NPROTO)
79126 + if (protocol < 0 || protocol >= PHONET_NPROTO)
79127 return -EINVAL;
79128
79129 err = proto_register(pp->prot, 1);
79130 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
79131 index 576f22c..bc7a71b 100644
79132 --- a/net/phonet/pep.c
79133 +++ b/net/phonet/pep.c
79134 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
79135
79136 case PNS_PEP_CTRL_REQ:
79137 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
79138 - atomic_inc(&sk->sk_drops);
79139 + atomic_inc_unchecked(&sk->sk_drops);
79140 break;
79141 }
79142 __skb_pull(skb, 4);
79143 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
79144 }
79145
79146 if (pn->rx_credits == 0) {
79147 - atomic_inc(&sk->sk_drops);
79148 + atomic_inc_unchecked(&sk->sk_drops);
79149 err = -ENOBUFS;
79150 break;
79151 }
79152 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
79153 }
79154
79155 if (pn->rx_credits == 0) {
79156 - atomic_inc(&sk->sk_drops);
79157 + atomic_inc_unchecked(&sk->sk_drops);
79158 err = NET_RX_DROP;
79159 break;
79160 }
79161 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
79162 index b7e9827..c264c85 100644
79163 --- a/net/phonet/socket.c
79164 +++ b/net/phonet/socket.c
79165 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
79166 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
79167 sock_i_ino(sk),
79168 atomic_read(&sk->sk_refcnt), sk,
79169 - atomic_read(&sk->sk_drops), &len);
79170 + atomic_read_unchecked(&sk->sk_drops), &len);
79171 }
79172 seq_printf(seq, "%*s\n", 127 - len, "");
79173 return 0;
79174 diff --git a/net/rds/cong.c b/net/rds/cong.c
79175 index e5b65ac..f3b6fb7 100644
79176 --- a/net/rds/cong.c
79177 +++ b/net/rds/cong.c
79178 @@ -78,7 +78,7 @@
79179 * finds that the saved generation number is smaller than the global generation
79180 * number, it wakes up the process.
79181 */
79182 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
79183 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
79184
79185 /*
79186 * Congestion monitoring
79187 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
79188 rdsdebug("waking map %p for %pI4\n",
79189 map, &map->m_addr);
79190 rds_stats_inc(s_cong_update_received);
79191 - atomic_inc(&rds_cong_generation);
79192 + atomic_inc_unchecked(&rds_cong_generation);
79193 if (waitqueue_active(&map->m_waitq))
79194 wake_up(&map->m_waitq);
79195 if (waitqueue_active(&rds_poll_waitq))
79196 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
79197
79198 int rds_cong_updated_since(unsigned long *recent)
79199 {
79200 - unsigned long gen = atomic_read(&rds_cong_generation);
79201 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
79202
79203 if (likely(*recent == gen))
79204 return 0;
79205 diff --git a/net/rds/ib.h b/net/rds/ib.h
79206 index 8d2b3d5..227ec5b 100644
79207 --- a/net/rds/ib.h
79208 +++ b/net/rds/ib.h
79209 @@ -128,7 +128,7 @@ struct rds_ib_connection {
79210 /* sending acks */
79211 unsigned long i_ack_flags;
79212 #ifdef KERNEL_HAS_ATOMIC64
79213 - atomic64_t i_ack_next; /* next ACK to send */
79214 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79215 #else
79216 spinlock_t i_ack_lock; /* protect i_ack_next */
79217 u64 i_ack_next; /* next ACK to send */
79218 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
79219 index a1e1162..265e129 100644
79220 --- a/net/rds/ib_cm.c
79221 +++ b/net/rds/ib_cm.c
79222 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
79223 /* Clear the ACK state */
79224 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79225 #ifdef KERNEL_HAS_ATOMIC64
79226 - atomic64_set(&ic->i_ack_next, 0);
79227 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79228 #else
79229 ic->i_ack_next = 0;
79230 #endif
79231 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
79232 index 8d19491..05a3e65 100644
79233 --- a/net/rds/ib_recv.c
79234 +++ b/net/rds/ib_recv.c
79235 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79236 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
79237 int ack_required)
79238 {
79239 - atomic64_set(&ic->i_ack_next, seq);
79240 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79241 if (ack_required) {
79242 smp_mb__before_clear_bit();
79243 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79244 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79245 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79246 smp_mb__after_clear_bit();
79247
79248 - return atomic64_read(&ic->i_ack_next);
79249 + return atomic64_read_unchecked(&ic->i_ack_next);
79250 }
79251 #endif
79252
79253 diff --git a/net/rds/iw.h b/net/rds/iw.h
79254 index 04ce3b1..48119a6 100644
79255 --- a/net/rds/iw.h
79256 +++ b/net/rds/iw.h
79257 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79258 /* sending acks */
79259 unsigned long i_ack_flags;
79260 #ifdef KERNEL_HAS_ATOMIC64
79261 - atomic64_t i_ack_next; /* next ACK to send */
79262 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79263 #else
79264 spinlock_t i_ack_lock; /* protect i_ack_next */
79265 u64 i_ack_next; /* next ACK to send */
79266 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79267 index a91e1db..cf3053f 100644
79268 --- a/net/rds/iw_cm.c
79269 +++ b/net/rds/iw_cm.c
79270 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79271 /* Clear the ACK state */
79272 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79273 #ifdef KERNEL_HAS_ATOMIC64
79274 - atomic64_set(&ic->i_ack_next, 0);
79275 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79276 #else
79277 ic->i_ack_next = 0;
79278 #endif
79279 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79280 index 4503335..db566b4 100644
79281 --- a/net/rds/iw_recv.c
79282 +++ b/net/rds/iw_recv.c
79283 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79284 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79285 int ack_required)
79286 {
79287 - atomic64_set(&ic->i_ack_next, seq);
79288 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79289 if (ack_required) {
79290 smp_mb__before_clear_bit();
79291 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79292 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79293 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79294 smp_mb__after_clear_bit();
79295
79296 - return atomic64_read(&ic->i_ack_next);
79297 + return atomic64_read_unchecked(&ic->i_ack_next);
79298 }
79299 #endif
79300
79301 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79302 index edac9ef..16bcb98 100644
79303 --- a/net/rds/tcp.c
79304 +++ b/net/rds/tcp.c
79305 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79306 int val = 1;
79307
79308 set_fs(KERNEL_DS);
79309 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79310 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79311 sizeof(val));
79312 set_fs(oldfs);
79313 }
79314 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79315 index 81cf5a4..b5826ff 100644
79316 --- a/net/rds/tcp_send.c
79317 +++ b/net/rds/tcp_send.c
79318 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79319
79320 oldfs = get_fs();
79321 set_fs(KERNEL_DS);
79322 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79323 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79324 sizeof(val));
79325 set_fs(oldfs);
79326 }
79327 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79328 index 05996d0..5a1dfe0 100644
79329 --- a/net/rxrpc/af_rxrpc.c
79330 +++ b/net/rxrpc/af_rxrpc.c
79331 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79332 __be32 rxrpc_epoch;
79333
79334 /* current debugging ID */
79335 -atomic_t rxrpc_debug_id;
79336 +atomic_unchecked_t rxrpc_debug_id;
79337
79338 /* count of skbs currently in use */
79339 atomic_t rxrpc_n_skbs;
79340 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79341 index e4d9cbc..b229649 100644
79342 --- a/net/rxrpc/ar-ack.c
79343 +++ b/net/rxrpc/ar-ack.c
79344 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79345
79346 _enter("{%d,%d,%d,%d},",
79347 call->acks_hard, call->acks_unacked,
79348 - atomic_read(&call->sequence),
79349 + atomic_read_unchecked(&call->sequence),
79350 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79351
79352 stop = 0;
79353 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79354
79355 /* each Tx packet has a new serial number */
79356 sp->hdr.serial =
79357 - htonl(atomic_inc_return(&call->conn->serial));
79358 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79359
79360 hdr = (struct rxrpc_header *) txb->head;
79361 hdr->serial = sp->hdr.serial;
79362 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79363 */
79364 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79365 {
79366 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79367 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79368 }
79369
79370 /*
79371 @@ -629,7 +629,7 @@ process_further:
79372
79373 latest = ntohl(sp->hdr.serial);
79374 hard = ntohl(ack.firstPacket);
79375 - tx = atomic_read(&call->sequence);
79376 + tx = atomic_read_unchecked(&call->sequence);
79377
79378 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79379 latest,
79380 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79381 goto maybe_reschedule;
79382
79383 send_ACK_with_skew:
79384 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79385 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79386 ntohl(ack.serial));
79387 send_ACK:
79388 mtu = call->conn->trans->peer->if_mtu;
79389 @@ -1173,7 +1173,7 @@ send_ACK:
79390 ackinfo.rxMTU = htonl(5692);
79391 ackinfo.jumbo_max = htonl(4);
79392
79393 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79394 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79395 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79396 ntohl(hdr.serial),
79397 ntohs(ack.maxSkew),
79398 @@ -1191,7 +1191,7 @@ send_ACK:
79399 send_message:
79400 _debug("send message");
79401
79402 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79403 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79404 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79405 send_message_2:
79406
79407 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79408 index a3bbb36..3341fb9 100644
79409 --- a/net/rxrpc/ar-call.c
79410 +++ b/net/rxrpc/ar-call.c
79411 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79412 spin_lock_init(&call->lock);
79413 rwlock_init(&call->state_lock);
79414 atomic_set(&call->usage, 1);
79415 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79416 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79417 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79418
79419 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79420 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79421 index 4106ca9..a338d7a 100644
79422 --- a/net/rxrpc/ar-connection.c
79423 +++ b/net/rxrpc/ar-connection.c
79424 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79425 rwlock_init(&conn->lock);
79426 spin_lock_init(&conn->state_lock);
79427 atomic_set(&conn->usage, 1);
79428 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79429 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79430 conn->avail_calls = RXRPC_MAXCALLS;
79431 conn->size_align = 4;
79432 conn->header_size = sizeof(struct rxrpc_header);
79433 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79434 index e7ed43a..6afa140 100644
79435 --- a/net/rxrpc/ar-connevent.c
79436 +++ b/net/rxrpc/ar-connevent.c
79437 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79438
79439 len = iov[0].iov_len + iov[1].iov_len;
79440
79441 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79442 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79443 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79444
79445 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79446 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79447 index 529572f..c758ca7 100644
79448 --- a/net/rxrpc/ar-input.c
79449 +++ b/net/rxrpc/ar-input.c
79450 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79451 /* track the latest serial number on this connection for ACK packet
79452 * information */
79453 serial = ntohl(sp->hdr.serial);
79454 - hi_serial = atomic_read(&call->conn->hi_serial);
79455 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79456 while (serial > hi_serial)
79457 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79458 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79459 serial);
79460
79461 /* request ACK generation for any ACK or DATA packet that requests
79462 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79463 index a693aca..81e7293 100644
79464 --- a/net/rxrpc/ar-internal.h
79465 +++ b/net/rxrpc/ar-internal.h
79466 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79467 int error; /* error code for local abort */
79468 int debug_id; /* debug ID for printks */
79469 unsigned int call_counter; /* call ID counter */
79470 - atomic_t serial; /* packet serial number counter */
79471 - atomic_t hi_serial; /* highest serial number received */
79472 + atomic_unchecked_t serial; /* packet serial number counter */
79473 + atomic_unchecked_t hi_serial; /* highest serial number received */
79474 u8 avail_calls; /* number of calls available */
79475 u8 size_align; /* data size alignment (for security) */
79476 u8 header_size; /* rxrpc + security header size */
79477 @@ -346,7 +346,7 @@ struct rxrpc_call {
79478 spinlock_t lock;
79479 rwlock_t state_lock; /* lock for state transition */
79480 atomic_t usage;
79481 - atomic_t sequence; /* Tx data packet sequence counter */
79482 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79483 u32 abort_code; /* local/remote abort code */
79484 enum { /* current state of call */
79485 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79486 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79487 */
79488 extern atomic_t rxrpc_n_skbs;
79489 extern __be32 rxrpc_epoch;
79490 -extern atomic_t rxrpc_debug_id;
79491 +extern atomic_unchecked_t rxrpc_debug_id;
79492 extern struct workqueue_struct *rxrpc_workqueue;
79493
79494 /*
79495 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79496 index 87f7135..74d3703 100644
79497 --- a/net/rxrpc/ar-local.c
79498 +++ b/net/rxrpc/ar-local.c
79499 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79500 spin_lock_init(&local->lock);
79501 rwlock_init(&local->services_lock);
79502 atomic_set(&local->usage, 1);
79503 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79504 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79505 memcpy(&local->srx, srx, sizeof(*srx));
79506 }
79507
79508 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79509 index e1ac183..b43e10e 100644
79510 --- a/net/rxrpc/ar-output.c
79511 +++ b/net/rxrpc/ar-output.c
79512 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79513 sp->hdr.cid = call->cid;
79514 sp->hdr.callNumber = call->call_id;
79515 sp->hdr.seq =
79516 - htonl(atomic_inc_return(&call->sequence));
79517 + htonl(atomic_inc_return_unchecked(&call->sequence));
79518 sp->hdr.serial =
79519 - htonl(atomic_inc_return(&conn->serial));
79520 + htonl(atomic_inc_return_unchecked(&conn->serial));
79521 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79522 sp->hdr.userStatus = 0;
79523 sp->hdr.securityIndex = conn->security_ix;
79524 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79525 index bebaa43..2644591 100644
79526 --- a/net/rxrpc/ar-peer.c
79527 +++ b/net/rxrpc/ar-peer.c
79528 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79529 INIT_LIST_HEAD(&peer->error_targets);
79530 spin_lock_init(&peer->lock);
79531 atomic_set(&peer->usage, 1);
79532 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79533 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79534 memcpy(&peer->srx, srx, sizeof(*srx));
79535
79536 rxrpc_assess_MTU_size(peer);
79537 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79538 index 38047f7..9f48511 100644
79539 --- a/net/rxrpc/ar-proc.c
79540 +++ b/net/rxrpc/ar-proc.c
79541 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79542 atomic_read(&conn->usage),
79543 rxrpc_conn_states[conn->state],
79544 key_serial(conn->key),
79545 - atomic_read(&conn->serial),
79546 - atomic_read(&conn->hi_serial));
79547 + atomic_read_unchecked(&conn->serial),
79548 + atomic_read_unchecked(&conn->hi_serial));
79549
79550 return 0;
79551 }
79552 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79553 index 92df566..87ec1bf 100644
79554 --- a/net/rxrpc/ar-transport.c
79555 +++ b/net/rxrpc/ar-transport.c
79556 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79557 spin_lock_init(&trans->client_lock);
79558 rwlock_init(&trans->conn_lock);
79559 atomic_set(&trans->usage, 1);
79560 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79561 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79562
79563 if (peer->srx.transport.family == AF_INET) {
79564 switch (peer->srx.transport_type) {
79565 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79566 index f226709..0e735a8 100644
79567 --- a/net/rxrpc/rxkad.c
79568 +++ b/net/rxrpc/rxkad.c
79569 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79570
79571 len = iov[0].iov_len + iov[1].iov_len;
79572
79573 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79574 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79575 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79576
79577 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79578 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79579
79580 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79581
79582 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79583 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79584 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79585
79586 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79587 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79588 index 9966e7b..540c575 100644
79589 --- a/net/sctp/proc.c
79590 +++ b/net/sctp/proc.c
79591 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79592 seq_printf(seq,
79593 "%8pK %8pK %-3d %-3d %-2d %-4d "
79594 "%4d %8d %8d %7d %5lu %-5d %5d ",
79595 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79596 + assoc, sk,
79597 + sctp_sk(sk)->type, sk->sk_state,
79598 assoc->state, hash,
79599 assoc->assoc_id,
79600 assoc->sndbuf_used,
79601 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79602 index 406d957..543c737 100644
79603 --- a/net/sctp/socket.c
79604 +++ b/net/sctp/socket.c
79605 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79606 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79607 if (space_left < addrlen)
79608 return -ENOMEM;
79609 + if (addrlen > sizeof(temp) || addrlen < 0)
79610 + return -EFAULT;
79611 if (copy_to_user(to, &temp, addrlen))
79612 return -EFAULT;
79613 to += addrlen;
79614 diff --git a/net/socket.c b/net/socket.c
79615 index d92c490..b4bc863 100644
79616 --- a/net/socket.c
79617 +++ b/net/socket.c
79618 @@ -89,6 +89,7 @@
79619 #include <linux/magic.h>
79620 #include <linux/slab.h>
79621 #include <linux/xattr.h>
79622 +#include <linux/in.h>
79623
79624 #include <asm/uaccess.h>
79625 #include <asm/unistd.h>
79626 @@ -106,6 +107,8 @@
79627 #include <linux/sockios.h>
79628 #include <linux/atalk.h>
79629
79630 +#include <linux/grsock.h>
79631 +
79632 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79633 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79634 unsigned long nr_segs, loff_t pos);
79635 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79636 &sockfs_dentry_operations, SOCKFS_MAGIC);
79637 }
79638
79639 -static struct vfsmount *sock_mnt __read_mostly;
79640 +struct vfsmount *sock_mnt __read_mostly;
79641
79642 static struct file_system_type sock_fs_type = {
79643 .name = "sockfs",
79644 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79645 return -EAFNOSUPPORT;
79646 if (type < 0 || type >= SOCK_MAX)
79647 return -EINVAL;
79648 + if (protocol < 0)
79649 + return -EINVAL;
79650
79651 /* Compatibility.
79652
79653 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79654 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79655 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79656
79657 + if(!gr_search_socket(family, type, protocol)) {
79658 + retval = -EACCES;
79659 + goto out;
79660 + }
79661 +
79662 + if (gr_handle_sock_all(family, type, protocol)) {
79663 + retval = -EACCES;
79664 + goto out;
79665 + }
79666 +
79667 retval = sock_create(family, type, protocol, &sock);
79668 if (retval < 0)
79669 goto out;
79670 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79671 if (sock) {
79672 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79673 if (err >= 0) {
79674 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79675 + err = -EACCES;
79676 + goto error;
79677 + }
79678 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79679 + if (err)
79680 + goto error;
79681 +
79682 err = security_socket_bind(sock,
79683 (struct sockaddr *)&address,
79684 addrlen);
79685 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79686 (struct sockaddr *)
79687 &address, addrlen);
79688 }
79689 +error:
79690 fput_light(sock->file, fput_needed);
79691 }
79692 return err;
79693 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79694 if ((unsigned int)backlog > somaxconn)
79695 backlog = somaxconn;
79696
79697 + if (gr_handle_sock_server_other(sock->sk)) {
79698 + err = -EPERM;
79699 + goto error;
79700 + }
79701 +
79702 + err = gr_search_listen(sock);
79703 + if (err)
79704 + goto error;
79705 +
79706 err = security_socket_listen(sock, backlog);
79707 if (!err)
79708 err = sock->ops->listen(sock, backlog);
79709
79710 +error:
79711 fput_light(sock->file, fput_needed);
79712 }
79713 return err;
79714 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79715 newsock->type = sock->type;
79716 newsock->ops = sock->ops;
79717
79718 + if (gr_handle_sock_server_other(sock->sk)) {
79719 + err = -EPERM;
79720 + sock_release(newsock);
79721 + goto out_put;
79722 + }
79723 +
79724 + err = gr_search_accept(sock);
79725 + if (err) {
79726 + sock_release(newsock);
79727 + goto out_put;
79728 + }
79729 +
79730 /*
79731 * We don't need try_module_get here, as the listening socket (sock)
79732 * has the protocol module (sock->ops->owner) held.
79733 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79734 fd_install(newfd, newfile);
79735 err = newfd;
79736
79737 + gr_attach_curr_ip(newsock->sk);
79738 +
79739 out_put:
79740 fput_light(sock->file, fput_needed);
79741 out:
79742 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79743 int, addrlen)
79744 {
79745 struct socket *sock;
79746 + struct sockaddr *sck;
79747 struct sockaddr_storage address;
79748 int err, fput_needed;
79749
79750 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79751 if (err < 0)
79752 goto out_put;
79753
79754 + sck = (struct sockaddr *)&address;
79755 +
79756 + if (gr_handle_sock_client(sck)) {
79757 + err = -EACCES;
79758 + goto out_put;
79759 + }
79760 +
79761 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79762 + if (err)
79763 + goto out_put;
79764 +
79765 err =
79766 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79767 if (err)
79768 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79769 * checking falls down on this.
79770 */
79771 if (copy_from_user(ctl_buf,
79772 - (void __user __force *)msg_sys->msg_control,
79773 + (void __force_user *)msg_sys->msg_control,
79774 ctl_len))
79775 goto out_freectl;
79776 msg_sys->msg_control = ctl_buf;
79777 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79778 * kernel msghdr to use the kernel address space)
79779 */
79780
79781 - uaddr = (__force void __user *)msg_sys->msg_name;
79782 + uaddr = (void __force_user *)msg_sys->msg_name;
79783 uaddr_len = COMPAT_NAMELEN(msg);
79784 if (MSG_CMSG_COMPAT & flags) {
79785 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79786 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79787 }
79788
79789 ifr = compat_alloc_user_space(buf_size);
79790 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79791 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79792
79793 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79794 return -EFAULT;
79795 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79796 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79797
79798 if (copy_in_user(rxnfc, compat_rxnfc,
79799 - (void *)(&rxnfc->fs.m_ext + 1) -
79800 - (void *)rxnfc) ||
79801 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79802 + (void __user *)rxnfc) ||
79803 copy_in_user(&rxnfc->fs.ring_cookie,
79804 &compat_rxnfc->fs.ring_cookie,
79805 - (void *)(&rxnfc->fs.location + 1) -
79806 - (void *)&rxnfc->fs.ring_cookie) ||
79807 + (void __user *)(&rxnfc->fs.location + 1) -
79808 + (void __user *)&rxnfc->fs.ring_cookie) ||
79809 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79810 sizeof(rxnfc->rule_cnt)))
79811 return -EFAULT;
79812 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79813
79814 if (convert_out) {
79815 if (copy_in_user(compat_rxnfc, rxnfc,
79816 - (const void *)(&rxnfc->fs.m_ext + 1) -
79817 - (const void *)rxnfc) ||
79818 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79819 + (const void __user *)rxnfc) ||
79820 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79821 &rxnfc->fs.ring_cookie,
79822 - (const void *)(&rxnfc->fs.location + 1) -
79823 - (const void *)&rxnfc->fs.ring_cookie) ||
79824 + (const void __user *)(&rxnfc->fs.location + 1) -
79825 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79826 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79827 sizeof(rxnfc->rule_cnt)))
79828 return -EFAULT;
79829 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79830 old_fs = get_fs();
79831 set_fs(KERNEL_DS);
79832 err = dev_ioctl(net, cmd,
79833 - (struct ifreq __user __force *) &kifr);
79834 + (struct ifreq __force_user *) &kifr);
79835 set_fs(old_fs);
79836
79837 return err;
79838 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79839
79840 old_fs = get_fs();
79841 set_fs(KERNEL_DS);
79842 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79843 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79844 set_fs(old_fs);
79845
79846 if (cmd == SIOCGIFMAP && !err) {
79847 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79848 ret |= __get_user(rtdev, &(ur4->rt_dev));
79849 if (rtdev) {
79850 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79851 - r4.rt_dev = (char __user __force *)devname;
79852 + r4.rt_dev = (char __force_user *)devname;
79853 devname[15] = 0;
79854 } else
79855 r4.rt_dev = NULL;
79856 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79857 int __user *uoptlen;
79858 int err;
79859
79860 - uoptval = (char __user __force *) optval;
79861 - uoptlen = (int __user __force *) optlen;
79862 + uoptval = (char __force_user *) optval;
79863 + uoptlen = (int __force_user *) optlen;
79864
79865 set_fs(KERNEL_DS);
79866 if (level == SOL_SOCKET)
79867 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79868 char __user *uoptval;
79869 int err;
79870
79871 - uoptval = (char __user __force *) optval;
79872 + uoptval = (char __force_user *) optval;
79873
79874 set_fs(KERNEL_DS);
79875 if (level == SOL_SOCKET)
79876 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79877 index 6357fcb..244c7db 100644
79878 --- a/net/sunrpc/sched.c
79879 +++ b/net/sunrpc/sched.c
79880 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79881 #ifdef RPC_DEBUG
79882 static void rpc_task_set_debuginfo(struct rpc_task *task)
79883 {
79884 - static atomic_t rpc_pid;
79885 + static atomic_unchecked_t rpc_pid;
79886
79887 - task->tk_pid = atomic_inc_return(&rpc_pid);
79888 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79889 }
79890 #else
79891 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79892 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79893 index 8343737..677025e 100644
79894 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79895 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79896 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79897 static unsigned int min_max_inline = 4096;
79898 static unsigned int max_max_inline = 65536;
79899
79900 -atomic_t rdma_stat_recv;
79901 -atomic_t rdma_stat_read;
79902 -atomic_t rdma_stat_write;
79903 -atomic_t rdma_stat_sq_starve;
79904 -atomic_t rdma_stat_rq_starve;
79905 -atomic_t rdma_stat_rq_poll;
79906 -atomic_t rdma_stat_rq_prod;
79907 -atomic_t rdma_stat_sq_poll;
79908 -atomic_t rdma_stat_sq_prod;
79909 +atomic_unchecked_t rdma_stat_recv;
79910 +atomic_unchecked_t rdma_stat_read;
79911 +atomic_unchecked_t rdma_stat_write;
79912 +atomic_unchecked_t rdma_stat_sq_starve;
79913 +atomic_unchecked_t rdma_stat_rq_starve;
79914 +atomic_unchecked_t rdma_stat_rq_poll;
79915 +atomic_unchecked_t rdma_stat_rq_prod;
79916 +atomic_unchecked_t rdma_stat_sq_poll;
79917 +atomic_unchecked_t rdma_stat_sq_prod;
79918
79919 /* Temporary NFS request map and context caches */
79920 struct kmem_cache *svc_rdma_map_cachep;
79921 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79922 len -= *ppos;
79923 if (len > *lenp)
79924 len = *lenp;
79925 - if (len && copy_to_user(buffer, str_buf, len))
79926 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79927 return -EFAULT;
79928 *lenp = len;
79929 *ppos += len;
79930 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79931 {
79932 .procname = "rdma_stat_read",
79933 .data = &rdma_stat_read,
79934 - .maxlen = sizeof(atomic_t),
79935 + .maxlen = sizeof(atomic_unchecked_t),
79936 .mode = 0644,
79937 .proc_handler = read_reset_stat,
79938 },
79939 {
79940 .procname = "rdma_stat_recv",
79941 .data = &rdma_stat_recv,
79942 - .maxlen = sizeof(atomic_t),
79943 + .maxlen = sizeof(atomic_unchecked_t),
79944 .mode = 0644,
79945 .proc_handler = read_reset_stat,
79946 },
79947 {
79948 .procname = "rdma_stat_write",
79949 .data = &rdma_stat_write,
79950 - .maxlen = sizeof(atomic_t),
79951 + .maxlen = sizeof(atomic_unchecked_t),
79952 .mode = 0644,
79953 .proc_handler = read_reset_stat,
79954 },
79955 {
79956 .procname = "rdma_stat_sq_starve",
79957 .data = &rdma_stat_sq_starve,
79958 - .maxlen = sizeof(atomic_t),
79959 + .maxlen = sizeof(atomic_unchecked_t),
79960 .mode = 0644,
79961 .proc_handler = read_reset_stat,
79962 },
79963 {
79964 .procname = "rdma_stat_rq_starve",
79965 .data = &rdma_stat_rq_starve,
79966 - .maxlen = sizeof(atomic_t),
79967 + .maxlen = sizeof(atomic_unchecked_t),
79968 .mode = 0644,
79969 .proc_handler = read_reset_stat,
79970 },
79971 {
79972 .procname = "rdma_stat_rq_poll",
79973 .data = &rdma_stat_rq_poll,
79974 - .maxlen = sizeof(atomic_t),
79975 + .maxlen = sizeof(atomic_unchecked_t),
79976 .mode = 0644,
79977 .proc_handler = read_reset_stat,
79978 },
79979 {
79980 .procname = "rdma_stat_rq_prod",
79981 .data = &rdma_stat_rq_prod,
79982 - .maxlen = sizeof(atomic_t),
79983 + .maxlen = sizeof(atomic_unchecked_t),
79984 .mode = 0644,
79985 .proc_handler = read_reset_stat,
79986 },
79987 {
79988 .procname = "rdma_stat_sq_poll",
79989 .data = &rdma_stat_sq_poll,
79990 - .maxlen = sizeof(atomic_t),
79991 + .maxlen = sizeof(atomic_unchecked_t),
79992 .mode = 0644,
79993 .proc_handler = read_reset_stat,
79994 },
79995 {
79996 .procname = "rdma_stat_sq_prod",
79997 .data = &rdma_stat_sq_prod,
79998 - .maxlen = sizeof(atomic_t),
79999 + .maxlen = sizeof(atomic_unchecked_t),
80000 .mode = 0644,
80001 .proc_handler = read_reset_stat,
80002 },
80003 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80004 index 41cb63b..c4a1489 100644
80005 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80006 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
80007 @@ -501,7 +501,7 @@ next_sge:
80008 svc_rdma_put_context(ctxt, 0);
80009 goto out;
80010 }
80011 - atomic_inc(&rdma_stat_read);
80012 + atomic_inc_unchecked(&rdma_stat_read);
80013
80014 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
80015 chl_map->ch[ch_no].count -= read_wr.num_sge;
80016 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
80017 dto_q);
80018 list_del_init(&ctxt->dto_q);
80019 } else {
80020 - atomic_inc(&rdma_stat_rq_starve);
80021 + atomic_inc_unchecked(&rdma_stat_rq_starve);
80022 clear_bit(XPT_DATA, &xprt->xpt_flags);
80023 ctxt = NULL;
80024 }
80025 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
80026 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
80027 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
80028 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
80029 - atomic_inc(&rdma_stat_recv);
80030 + atomic_inc_unchecked(&rdma_stat_recv);
80031
80032 /* Build up the XDR from the receive buffers. */
80033 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
80034 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80035 index 42eb7ba..c887c45 100644
80036 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80037 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
80038 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
80039 write_wr.wr.rdma.remote_addr = to;
80040
80041 /* Post It */
80042 - atomic_inc(&rdma_stat_write);
80043 + atomic_inc_unchecked(&rdma_stat_write);
80044 if (svc_rdma_send(xprt, &write_wr))
80045 goto err;
80046 return 0;
80047 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
80048 index 62e4f9b..dd3f2d7 100644
80049 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
80050 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
80051 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
80052 return;
80053
80054 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
80055 - atomic_inc(&rdma_stat_rq_poll);
80056 + atomic_inc_unchecked(&rdma_stat_rq_poll);
80057
80058 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
80059 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
80060 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
80061 }
80062
80063 if (ctxt)
80064 - atomic_inc(&rdma_stat_rq_prod);
80065 + atomic_inc_unchecked(&rdma_stat_rq_prod);
80066
80067 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
80068 /*
80069 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
80070 return;
80071
80072 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
80073 - atomic_inc(&rdma_stat_sq_poll);
80074 + atomic_inc_unchecked(&rdma_stat_sq_poll);
80075 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
80076 if (wc.status != IB_WC_SUCCESS)
80077 /* Close the transport */
80078 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
80079 }
80080
80081 if (ctxt)
80082 - atomic_inc(&rdma_stat_sq_prod);
80083 + atomic_inc_unchecked(&rdma_stat_sq_prod);
80084 }
80085
80086 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
80087 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
80088 spin_lock_bh(&xprt->sc_lock);
80089 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
80090 spin_unlock_bh(&xprt->sc_lock);
80091 - atomic_inc(&rdma_stat_sq_starve);
80092 + atomic_inc_unchecked(&rdma_stat_sq_starve);
80093
80094 /* See if we can opportunistically reap SQ WR to make room */
80095 sq_cq_reap(xprt);
80096 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
80097 index e3a6e37..be2ea77 100644
80098 --- a/net/sysctl_net.c
80099 +++ b/net/sysctl_net.c
80100 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
80101 struct ctl_table *table)
80102 {
80103 /* Allow network administrator to have same access as root. */
80104 - if (capable(CAP_NET_ADMIN)) {
80105 + if (capable_nolog(CAP_NET_ADMIN)) {
80106 int mode = (table->mode >> 6) & 7;
80107 return (mode << 6) | (mode << 3) | mode;
80108 }
80109 diff --git a/net/tipc/link.c b/net/tipc/link.c
80110 index a79c755..eca357d 100644
80111 --- a/net/tipc/link.c
80112 +++ b/net/tipc/link.c
80113 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
80114 struct tipc_msg fragm_hdr;
80115 struct sk_buff *buf, *buf_chain, *prev;
80116 u32 fragm_crs, fragm_rest, hsz, sect_rest;
80117 - const unchar *sect_crs;
80118 + const unchar __user *sect_crs;
80119 int curr_sect;
80120 u32 fragm_no;
80121
80122 @@ -1210,7 +1210,7 @@ again:
80123
80124 if (!sect_rest) {
80125 sect_rest = msg_sect[++curr_sect].iov_len;
80126 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
80127 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
80128 }
80129
80130 if (sect_rest < fragm_rest)
80131 @@ -1229,7 +1229,7 @@ error:
80132 }
80133 } else
80134 skb_copy_to_linear_data_offset(buf, fragm_crs,
80135 - sect_crs, sz);
80136 + (const void __force_kernel *)sect_crs, sz);
80137 sect_crs += sz;
80138 sect_rest -= sz;
80139 fragm_crs += sz;
80140 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
80141 index f2db8a8..9245aa4 100644
80142 --- a/net/tipc/msg.c
80143 +++ b/net/tipc/msg.c
80144 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
80145 msg_sect[cnt].iov_len);
80146 else
80147 skb_copy_to_linear_data_offset(*buf, pos,
80148 - msg_sect[cnt].iov_base,
80149 + (const void __force_kernel *)msg_sect[cnt].iov_base,
80150 msg_sect[cnt].iov_len);
80151 pos += msg_sect[cnt].iov_len;
80152 }
80153 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
80154 index 0f7d0d0..00f89bf 100644
80155 --- a/net/tipc/subscr.c
80156 +++ b/net/tipc/subscr.c
80157 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
80158 {
80159 struct iovec msg_sect;
80160
80161 - msg_sect.iov_base = (void *)&sub->evt;
80162 + msg_sect.iov_base = (void __force_user *)&sub->evt;
80163 msg_sect.iov_len = sizeof(struct tipc_event);
80164
80165 sub->evt.event = htohl(event, sub->swap);
80166 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
80167 index 5b5c876..3127bf7 100644
80168 --- a/net/unix/af_unix.c
80169 +++ b/net/unix/af_unix.c
80170 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
80171 err = -ECONNREFUSED;
80172 if (!S_ISSOCK(inode->i_mode))
80173 goto put_fail;
80174 +
80175 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
80176 + err = -EACCES;
80177 + goto put_fail;
80178 + }
80179 +
80180 u = unix_find_socket_byinode(inode);
80181 if (!u)
80182 goto put_fail;
80183 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
80184 if (u) {
80185 struct dentry *dentry;
80186 dentry = unix_sk(u)->path.dentry;
80187 +
80188 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
80189 + err = -EPERM;
80190 + sock_put(u);
80191 + goto fail;
80192 + }
80193 +
80194 if (dentry)
80195 touch_atime(&unix_sk(u)->path);
80196 } else
80197 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
80198 */
80199 err = security_path_mknod(&path, dentry, mode, 0);
80200 if (!err) {
80201 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
80202 + err = -EACCES;
80203 + goto out;
80204 + }
80205 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
80206 if (!err) {
80207 res->mnt = mntget(path.mnt);
80208 res->dentry = dget(dentry);
80209 + gr_handle_create(dentry, path.mnt);
80210 }
80211 }
80212 +out:
80213 done_path_create(&path, dentry);
80214 return err;
80215 }
80216 diff --git a/net/wireless/core.h b/net/wireless/core.h
80217 index a343be4..0c6e081 100644
80218 --- a/net/wireless/core.h
80219 +++ b/net/wireless/core.h
80220 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
80221 struct mutex mtx;
80222
80223 /* rfkill support */
80224 - struct rfkill_ops rfkill_ops;
80225 + rfkill_ops_no_const rfkill_ops;
80226 struct rfkill *rfkill;
80227 struct work_struct rfkill_sync;
80228
80229 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80230 index c8717c1..08539f5 100644
80231 --- a/net/wireless/wext-core.c
80232 +++ b/net/wireless/wext-core.c
80233 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80234 */
80235
80236 /* Support for very large requests */
80237 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80238 - (user_length > descr->max_tokens)) {
80239 + if (user_length > descr->max_tokens) {
80240 /* Allow userspace to GET more than max so
80241 * we can support any size GET requests.
80242 * There is still a limit : -ENOMEM.
80243 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80244 }
80245 }
80246
80247 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80248 - /*
80249 - * If this is a GET, but not NOMAX, it means that the extra
80250 - * data is not bounded by userspace, but by max_tokens. Thus
80251 - * set the length to max_tokens. This matches the extra data
80252 - * allocation.
80253 - * The driver should fill it with the number of tokens it
80254 - * provided, and it may check iwp->length rather than having
80255 - * knowledge of max_tokens. If the driver doesn't change the
80256 - * iwp->length, this ioctl just copies back max_token tokens
80257 - * filled with zeroes. Hopefully the driver isn't claiming
80258 - * them to be valid data.
80259 - */
80260 - iwp->length = descr->max_tokens;
80261 - }
80262 -
80263 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80264
80265 iwp->length += essid_compat;
80266 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80267 index 41eabc4..8d4e6d6 100644
80268 --- a/net/xfrm/xfrm_policy.c
80269 +++ b/net/xfrm/xfrm_policy.c
80270 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80271 {
80272 policy->walk.dead = 1;
80273
80274 - atomic_inc(&policy->genid);
80275 + atomic_inc_unchecked(&policy->genid);
80276
80277 if (del_timer(&policy->timer))
80278 xfrm_pol_put(policy);
80279 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80280 hlist_add_head(&policy->bydst, chain);
80281 xfrm_pol_hold(policy);
80282 net->xfrm.policy_count[dir]++;
80283 - atomic_inc(&flow_cache_genid);
80284 + atomic_inc_unchecked(&flow_cache_genid);
80285 rt_genid_bump(net);
80286 if (delpol)
80287 __xfrm_policy_unlink(delpol, dir);
80288 @@ -1550,7 +1550,7 @@ free_dst:
80289 goto out;
80290 }
80291
80292 -static int inline
80293 +static inline int
80294 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80295 {
80296 if (!*target) {
80297 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80298 return 0;
80299 }
80300
80301 -static int inline
80302 +static inline int
80303 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80304 {
80305 #ifdef CONFIG_XFRM_SUB_POLICY
80306 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80307 #endif
80308 }
80309
80310 -static int inline
80311 +static inline int
80312 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80313 {
80314 #ifdef CONFIG_XFRM_SUB_POLICY
80315 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80316
80317 xdst->num_pols = num_pols;
80318 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80319 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80320 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80321
80322 return xdst;
80323 }
80324 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80325 if (xdst->xfrm_genid != dst->xfrm->genid)
80326 return 0;
80327 if (xdst->num_pols > 0 &&
80328 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80329 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80330 return 0;
80331
80332 mtu = dst_mtu(dst->child);
80333 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80334 sizeof(pol->xfrm_vec[i].saddr));
80335 pol->xfrm_vec[i].encap_family = mp->new_family;
80336 /* flush bundles */
80337 - atomic_inc(&pol->genid);
80338 + atomic_inc_unchecked(&pol->genid);
80339 }
80340 }
80341
80342 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80343 index 0e801c3..5c8ad3b 100644
80344 --- a/scripts/Makefile.build
80345 +++ b/scripts/Makefile.build
80346 @@ -111,7 +111,7 @@ endif
80347 endif
80348
80349 # Do not include host rules unless needed
80350 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80351 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80352 include scripts/Makefile.host
80353 endif
80354
80355 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80356 index 686cb0d..9d653bf 100644
80357 --- a/scripts/Makefile.clean
80358 +++ b/scripts/Makefile.clean
80359 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80360 __clean-files := $(extra-y) $(always) \
80361 $(targets) $(clean-files) \
80362 $(host-progs) \
80363 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80364 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80365 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80366
80367 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80368
80369 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80370 index 1ac414f..38575f7 100644
80371 --- a/scripts/Makefile.host
80372 +++ b/scripts/Makefile.host
80373 @@ -31,6 +31,8 @@
80374 # Note: Shared libraries consisting of C++ files are not supported
80375
80376 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80377 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80378 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80379
80380 # C code
80381 # Executables compiled from a single .c file
80382 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80383 # Shared libaries (only .c supported)
80384 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80385 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80386 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80387 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80388 # Remove .so files from "xxx-objs"
80389 host-cobjs := $(filter-out %.so,$(host-cobjs))
80390 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80391
80392 -#Object (.o) files used by the shared libaries
80393 +# Object (.o) files used by the shared libaries
80394 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80395 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80396
80397 # output directory for programs/.o files
80398 # hostprogs-y := tools/build may have been specified. Retrieve directory
80399 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80400 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80401 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80402 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80403 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80404 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80405 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80406 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80407
80408 obj-dirs += $(host-objdirs)
80409 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80410 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80411 $(call if_changed_dep,host-cshobjs)
80412
80413 +# Compile .c file, create position independent .o file
80414 +# host-cxxshobjs -> .o
80415 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80416 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80417 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80418 + $(call if_changed_dep,host-cxxshobjs)
80419 +
80420 # Link a shared library, based on position independent .o files
80421 # *.o -> .so shared library (host-cshlib)
80422 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80423 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80424 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80425 $(call if_changed,host-cshlib)
80426
80427 +# Link a shared library, based on position independent .o files
80428 +# *.o -> .so shared library (host-cxxshlib)
80429 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80430 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80431 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80432 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80433 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80434 + $(call if_changed,host-cxxshlib)
80435 +
80436 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80437 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80438 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80439
80440 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80441 index cb1f50c..cef2a7c 100644
80442 --- a/scripts/basic/fixdep.c
80443 +++ b/scripts/basic/fixdep.c
80444 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80445 /*
80446 * Lookup a value in the configuration string.
80447 */
80448 -static int is_defined_config(const char *name, int len, unsigned int hash)
80449 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80450 {
80451 struct item *aux;
80452
80453 @@ -211,10 +211,10 @@ static void clear_config(void)
80454 /*
80455 * Record the use of a CONFIG_* word.
80456 */
80457 -static void use_config(const char *m, int slen)
80458 +static void use_config(const char *m, unsigned int slen)
80459 {
80460 unsigned int hash = strhash(m, slen);
80461 - int c, i;
80462 + unsigned int c, i;
80463
80464 if (is_defined_config(m, slen, hash))
80465 return;
80466 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80467
80468 static void parse_config_file(const char *map, size_t len)
80469 {
80470 - const int *end = (const int *) (map + len);
80471 + const unsigned int *end = (const unsigned int *) (map + len);
80472 /* start at +1, so that p can never be < map */
80473 - const int *m = (const int *) map + 1;
80474 + const unsigned int *m = (const unsigned int *) map + 1;
80475 const char *p, *q;
80476
80477 for (; m < end; m++) {
80478 @@ -406,7 +406,7 @@ static void print_deps(void)
80479 static void traps(void)
80480 {
80481 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80482 - int *p = (int *)test;
80483 + unsigned int *p = (unsigned int *)test;
80484
80485 if (*p != INT_CONF) {
80486 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80487 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80488 new file mode 100644
80489 index 0000000..008ac1a
80490 --- /dev/null
80491 +++ b/scripts/gcc-plugin.sh
80492 @@ -0,0 +1,17 @@
80493 +#!/bin/bash
80494 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80495 +#include "gcc-plugin.h"
80496 +#include "tree.h"
80497 +#include "tm.h"
80498 +#include "rtl.h"
80499 +#ifdef ENABLE_BUILD_WITH_CXX
80500 +#warning $2
80501 +#else
80502 +#warning $1
80503 +#endif
80504 +EOF`
80505 +if [ $? -eq 0 ]
80506 +then
80507 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80508 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80509 +fi
80510 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80511 index b3d907e..a4782ab 100644
80512 --- a/scripts/link-vmlinux.sh
80513 +++ b/scripts/link-vmlinux.sh
80514 @@ -152,7 +152,7 @@ else
80515 fi;
80516
80517 # final build of init/
80518 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80519 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80520
80521 kallsymso=""
80522 kallsyms_vmlinux=""
80523 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80524 index df4fc23..0ea719d 100644
80525 --- a/scripts/mod/file2alias.c
80526 +++ b/scripts/mod/file2alias.c
80527 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80528 unsigned long size, unsigned long id_size,
80529 void *symval)
80530 {
80531 - int i;
80532 + unsigned int i;
80533
80534 if (size % id_size || size < id_size) {
80535 if (cross_build != 0)
80536 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80537 /* USB is special because the bcdDevice can be matched against a numeric range */
80538 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80539 static void do_usb_entry(struct usb_device_id *id,
80540 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80541 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80542 unsigned char range_lo, unsigned char range_hi,
80543 unsigned char max, struct module *mod)
80544 {
80545 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80546 {
80547 unsigned int devlo, devhi;
80548 unsigned char chi, clo, max;
80549 - int ndigits;
80550 + unsigned int ndigits;
80551
80552 id->match_flags = TO_NATIVE(id->match_flags);
80553 id->idVendor = TO_NATIVE(id->idVendor);
80554 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80555 for (i = 0; i < count; i++) {
80556 const char *id = (char *)devs[i].id;
80557 char acpi_id[sizeof(devs[0].id)];
80558 - int j;
80559 + unsigned int j;
80560
80561 buf_printf(&mod->dev_table_buf,
80562 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80563 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80564
80565 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80566 const char *id = (char *)card->devs[j].id;
80567 - int i2, j2;
80568 + unsigned int i2, j2;
80569 int dup = 0;
80570
80571 if (!id[0])
80572 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80573 /* add an individual alias for every device entry */
80574 if (!dup) {
80575 char acpi_id[sizeof(card->devs[0].id)];
80576 - int k;
80577 + unsigned int k;
80578
80579 buf_printf(&mod->dev_table_buf,
80580 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80581 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80582 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80583 char *alias)
80584 {
80585 - int i, j;
80586 + unsigned int i, j;
80587
80588 sprintf(alias, "dmi*");
80589
80590 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80591 index 0d93856..e828363 100644
80592 --- a/scripts/mod/modpost.c
80593 +++ b/scripts/mod/modpost.c
80594 @@ -933,6 +933,7 @@ enum mismatch {
80595 ANY_INIT_TO_ANY_EXIT,
80596 ANY_EXIT_TO_ANY_INIT,
80597 EXPORT_TO_INIT_EXIT,
80598 + DATA_TO_TEXT
80599 };
80600
80601 struct sectioncheck {
80602 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
80603 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80604 .mismatch = EXPORT_TO_INIT_EXIT,
80605 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80606 +},
80607 +/* Do not reference code from writable data */
80608 +{
80609 + .fromsec = { DATA_SECTIONS, NULL },
80610 + .tosec = { TEXT_SECTIONS, NULL },
80611 + .mismatch = DATA_TO_TEXT
80612 }
80613 };
80614
80615 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80616 continue;
80617 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80618 continue;
80619 - if (sym->st_value == addr)
80620 - return sym;
80621 /* Find a symbol nearby - addr are maybe negative */
80622 d = sym->st_value - addr;
80623 + if (d == 0)
80624 + return sym;
80625 if (d < 0)
80626 d = addr - sym->st_value;
80627 if (d < distance) {
80628 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
80629 tosym, prl_to, prl_to, tosym);
80630 free(prl_to);
80631 break;
80632 + case DATA_TO_TEXT:
80633 +#if 0
80634 + fprintf(stderr,
80635 + "The %s %s:%s references\n"
80636 + "the %s %s:%s%s\n",
80637 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80638 +#endif
80639 + break;
80640 }
80641 fprintf(stderr, "\n");
80642 }
80643 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80644 static void check_sec_ref(struct module *mod, const char *modname,
80645 struct elf_info *elf)
80646 {
80647 - int i;
80648 + unsigned int i;
80649 Elf_Shdr *sechdrs = elf->sechdrs;
80650
80651 /* Walk through all sections */
80652 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80653 va_end(ap);
80654 }
80655
80656 -void buf_write(struct buffer *buf, const char *s, int len)
80657 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80658 {
80659 if (buf->size - buf->pos < len) {
80660 buf->size += len + SZ;
80661 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80662 if (fstat(fileno(file), &st) < 0)
80663 goto close_write;
80664
80665 - if (st.st_size != b->pos)
80666 + if (st.st_size != (off_t)b->pos)
80667 goto close_write;
80668
80669 tmp = NOFAIL(malloc(b->pos));
80670 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80671 index 51207e4..f7d603d 100644
80672 --- a/scripts/mod/modpost.h
80673 +++ b/scripts/mod/modpost.h
80674 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80675
80676 struct buffer {
80677 char *p;
80678 - int pos;
80679 - int size;
80680 + unsigned int pos;
80681 + unsigned int size;
80682 };
80683
80684 void __attribute__((format(printf, 2, 3)))
80685 buf_printf(struct buffer *buf, const char *fmt, ...);
80686
80687 void
80688 -buf_write(struct buffer *buf, const char *s, int len);
80689 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80690
80691 struct module {
80692 struct module *next;
80693 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80694 index 9dfcd6d..099068e 100644
80695 --- a/scripts/mod/sumversion.c
80696 +++ b/scripts/mod/sumversion.c
80697 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80698 goto out;
80699 }
80700
80701 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80702 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80703 warn("writing sum in %s failed: %s\n",
80704 filename, strerror(errno));
80705 goto out;
80706 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80707 index 5c11312..72742b5 100644
80708 --- a/scripts/pnmtologo.c
80709 +++ b/scripts/pnmtologo.c
80710 @@ -237,14 +237,14 @@ static void write_header(void)
80711 fprintf(out, " * Linux logo %s\n", logoname);
80712 fputs(" */\n\n", out);
80713 fputs("#include <linux/linux_logo.h>\n\n", out);
80714 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80715 + fprintf(out, "static unsigned char %s_data[] = {\n",
80716 logoname);
80717 }
80718
80719 static void write_footer(void)
80720 {
80721 fputs("\n};\n\n", out);
80722 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80723 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80724 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80725 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80726 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80727 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80728 fputs("\n};\n\n", out);
80729
80730 /* write logo clut */
80731 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80732 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80733 logoname);
80734 write_hex_cnt = 0;
80735 for (i = 0; i < logo_clutsize; i++) {
80736 diff --git a/security/Kconfig b/security/Kconfig
80737 index e9c6ac7..152c2e3 100644
80738 --- a/security/Kconfig
80739 +++ b/security/Kconfig
80740 @@ -4,6 +4,896 @@
80741
80742 menu "Security options"
80743
80744 +menu "Grsecurity"
80745 +
80746 + config ARCH_TRACK_EXEC_LIMIT
80747 + bool
80748 +
80749 + config PAX_KERNEXEC_PLUGIN
80750 + bool
80751 +
80752 + config PAX_PER_CPU_PGD
80753 + bool
80754 +
80755 + config TASK_SIZE_MAX_SHIFT
80756 + int
80757 + depends on X86_64
80758 + default 47 if !PAX_PER_CPU_PGD
80759 + default 42 if PAX_PER_CPU_PGD
80760 +
80761 + config PAX_ENABLE_PAE
80762 + bool
80763 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80764 +
80765 + config PAX_USERCOPY_SLABS
80766 + bool
80767 +
80768 +config GRKERNSEC
80769 + bool "Grsecurity"
80770 + select CRYPTO
80771 + select CRYPTO_SHA256
80772 + select PROC_FS
80773 + select STOP_MACHINE
80774 + help
80775 + If you say Y here, you will be able to configure many features
80776 + that will enhance the security of your system. It is highly
80777 + recommended that you say Y here and read through the help
80778 + for each option so that you fully understand the features and
80779 + can evaluate their usefulness for your machine.
80780 +
80781 +choice
80782 + prompt "Configuration Method"
80783 + depends on GRKERNSEC
80784 + default GRKERNSEC_CONFIG_CUSTOM
80785 + help
80786 +
80787 +config GRKERNSEC_CONFIG_AUTO
80788 + bool "Automatic"
80789 + help
80790 + If you choose this configuration method, you'll be able to answer a small
80791 + number of simple questions about how you plan to use this kernel.
80792 + The settings of grsecurity and PaX will be automatically configured for
80793 + the highest commonly-used settings within the provided constraints.
80794 +
80795 + If you require additional configuration, custom changes can still be made
80796 + from the "custom configuration" menu.
80797 +
80798 +config GRKERNSEC_CONFIG_CUSTOM
80799 + bool "Custom"
80800 + help
80801 + If you choose this configuration method, you'll be able to configure all
80802 + grsecurity and PaX settings manually. Via this method, no options are
80803 + automatically enabled.
80804 +
80805 +endchoice
80806 +
80807 +choice
80808 + prompt "Usage Type"
80809 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80810 + default GRKERNSEC_CONFIG_SERVER
80811 + help
80812 +
80813 +config GRKERNSEC_CONFIG_SERVER
80814 + bool "Server"
80815 + help
80816 + Choose this option if you plan to use this kernel on a server.
80817 +
80818 +config GRKERNSEC_CONFIG_DESKTOP
80819 + bool "Desktop"
80820 + help
80821 + Choose this option if you plan to use this kernel on a desktop.
80822 +
80823 +endchoice
80824 +
80825 +choice
80826 + prompt "Virtualization Type"
80827 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80828 + default GRKERNSEC_CONFIG_VIRT_NONE
80829 + help
80830 +
80831 +config GRKERNSEC_CONFIG_VIRT_NONE
80832 + bool "None"
80833 + help
80834 + Choose this option if this kernel will be run on bare metal.
80835 +
80836 +config GRKERNSEC_CONFIG_VIRT_GUEST
80837 + bool "Guest"
80838 + help
80839 + Choose this option if this kernel will be run as a VM guest.
80840 +
80841 +config GRKERNSEC_CONFIG_VIRT_HOST
80842 + bool "Host"
80843 + help
80844 + Choose this option if this kernel will be run as a VM host.
80845 +
80846 +endchoice
80847 +
80848 +choice
80849 + prompt "Virtualization Hardware"
80850 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80851 + help
80852 +
80853 +config GRKERNSEC_CONFIG_VIRT_EPT
80854 + bool "EPT/RVI Processor Support"
80855 + depends on X86
80856 + help
80857 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80858 + hardware virtualization. This allows for additional kernel hardening protections
80859 + to operate without additional performance impact.
80860 +
80861 + To see if your Intel processor supports EPT, see:
80862 + http://ark.intel.com/Products/VirtualizationTechnology
80863 + (Most Core i3/5/7 support EPT)
80864 +
80865 + To see if your AMD processor supports RVI, see:
80866 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80867 +
80868 +config GRKERNSEC_CONFIG_VIRT_SOFT
80869 + bool "First-gen/No Hardware Virtualization"
80870 + help
80871 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80872 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80873 +
80874 +endchoice
80875 +
80876 +choice
80877 + prompt "Virtualization Software"
80878 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80879 + help
80880 +
80881 +config GRKERNSEC_CONFIG_VIRT_XEN
80882 + bool "Xen"
80883 + help
80884 + Choose this option if this kernel is running as a Xen guest or host.
80885 +
80886 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80887 + bool "VMWare"
80888 + help
80889 + Choose this option if this kernel is running as a VMWare guest or host.
80890 +
80891 +config GRKERNSEC_CONFIG_VIRT_KVM
80892 + bool "KVM"
80893 + help
80894 + Choose this option if this kernel is running as a KVM guest or host.
80895 +
80896 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80897 + bool "VirtualBox"
80898 + help
80899 + Choose this option if this kernel is running as a VirtualBox guest or host.
80900 +
80901 +endchoice
80902 +
80903 +choice
80904 + prompt "Required Priorities"
80905 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80906 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80907 + help
80908 +
80909 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80910 + bool "Performance"
80911 + help
80912 + Choose this option if performance is of highest priority for this deployment
80913 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80914 + and freed memory sanitizing will be disabled.
80915 +
80916 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80917 + bool "Security"
80918 + help
80919 + Choose this option if security is of highest priority for this deployment of
80920 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80921 + be enabled for this kernel. In a worst-case scenario, these features can
80922 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80923 +
80924 +endchoice
80925 +
80926 +menu "Default Special Groups"
80927 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80928 +
80929 +config GRKERNSEC_PROC_GID
80930 + int "GID exempted from /proc restrictions"
80931 + default 1001
80932 + help
80933 + Setting this GID determines which group will be exempted from
80934 + grsecurity's /proc restrictions, allowing users of the specified
80935 + group to view network statistics and the existence of other users'
80936 + processes on the system. This GID may also be chosen at boot time
80937 + via "grsec_proc_gid=" on the kernel commandline.
80938 +
80939 +config GRKERNSEC_TPE_UNTRUSTED_GID
80940 + int "GID for TPE-untrusted users"
80941 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80942 + default 1005
80943 + help
80944 + Setting this GID determines which group untrusted users should
80945 + be added to. These users will be placed under grsecurity's Trusted Path
80946 + Execution mechanism, preventing them from executing their own binaries.
80947 + The users will only be able to execute binaries in directories owned and
80948 + writable only by the root user. If the sysctl option is enabled, a sysctl
80949 + option with name "tpe_gid" is created.
80950 +
80951 +config GRKERNSEC_TPE_TRUSTED_GID
80952 + int "GID for TPE-trusted users"
80953 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80954 + default 1005
80955 + help
80956 + Setting this GID determines what group TPE restrictions will be
80957 + *disabled* for. If the sysctl option is enabled, a sysctl option
80958 + with name "tpe_gid" is created.
80959 +
80960 +config GRKERNSEC_SYMLINKOWN_GID
80961 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80962 + depends on GRKERNSEC_CONFIG_SERVER
80963 + default 1006
80964 + help
80965 + Setting this GID determines what group kernel-enforced
80966 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80967 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80968 +
80969 +
80970 +endmenu
80971 +
80972 +menu "Customize Configuration"
80973 +depends on GRKERNSEC
80974 +
80975 +menu "PaX"
80976 +
80977 +config PAX
80978 + bool "Enable various PaX features"
80979 + default y if GRKERNSEC_CONFIG_AUTO
80980 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80981 + help
80982 + This allows you to enable various PaX features. PaX adds
80983 + intrusion prevention mechanisms to the kernel that reduce
80984 + the risks posed by exploitable memory corruption bugs.
80985 +
80986 +menu "PaX Control"
80987 + depends on PAX
80988 +
80989 +config PAX_SOFTMODE
80990 + bool 'Support soft mode'
80991 + help
80992 + Enabling this option will allow you to run PaX in soft mode, that
80993 + is, PaX features will not be enforced by default, only on executables
80994 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80995 + support as they are the only way to mark executables for soft mode use.
80996 +
80997 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80998 + line option on boot. Furthermore you can control various PaX features
80999 + at runtime via the entries in /proc/sys/kernel/pax.
81000 +
81001 +config PAX_EI_PAX
81002 + bool 'Use legacy ELF header marking'
81003 + default y if GRKERNSEC_CONFIG_AUTO
81004 + help
81005 + Enabling this option will allow you to control PaX features on
81006 + a per executable basis via the 'chpax' utility available at
81007 + http://pax.grsecurity.net/. The control flags will be read from
81008 + an otherwise reserved part of the ELF header. This marking has
81009 + numerous drawbacks (no support for soft-mode, toolchain does not
81010 + know about the non-standard use of the ELF header) therefore it
81011 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
81012 + support.
81013 +
81014 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
81015 + support as well, they will override the legacy EI_PAX marks.
81016 +
81017 + If you enable none of the marking options then all applications
81018 + will run with PaX enabled on them by default.
81019 +
81020 +config PAX_PT_PAX_FLAGS
81021 + bool 'Use ELF program header marking'
81022 + default y if GRKERNSEC_CONFIG_AUTO
81023 + help
81024 + Enabling this option will allow you to control PaX features on
81025 + a per executable basis via the 'paxctl' utility available at
81026 + http://pax.grsecurity.net/. The control flags will be read from
81027 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
81028 + has the benefits of supporting both soft mode and being fully
81029 + integrated into the toolchain (the binutils patch is available
81030 + from http://pax.grsecurity.net).
81031 +
81032 + Note that if you enable the legacy EI_PAX marking support as well,
81033 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
81034 +
81035 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
81036 + must make sure that the marks are the same if a binary has both marks.
81037 +
81038 + If you enable none of the marking options then all applications
81039 + will run with PaX enabled on them by default.
81040 +
81041 +config PAX_XATTR_PAX_FLAGS
81042 + bool 'Use filesystem extended attributes marking'
81043 + default y if GRKERNSEC_CONFIG_AUTO
81044 + select CIFS_XATTR if CIFS
81045 + select EXT2_FS_XATTR if EXT2_FS
81046 + select EXT3_FS_XATTR if EXT3_FS
81047 + select EXT4_FS_XATTR if EXT4_FS
81048 + select JFFS2_FS_XATTR if JFFS2_FS
81049 + select REISERFS_FS_XATTR if REISERFS_FS
81050 + select SQUASHFS_XATTR if SQUASHFS
81051 + select TMPFS_XATTR if TMPFS
81052 + select UBIFS_FS_XATTR if UBIFS_FS
81053 + help
81054 + Enabling this option will allow you to control PaX features on
81055 + a per executable basis via the 'setfattr' utility. The control
81056 + flags will be read from the user.pax.flags extended attribute of
81057 + the file. This marking has the benefit of supporting binary-only
81058 + applications that self-check themselves (e.g., skype) and would
81059 + not tolerate chpax/paxctl changes. The main drawback is that
81060 + extended attributes are not supported by some filesystems (e.g.,
81061 + isofs, udf, vfat) so copying files through such filesystems will
81062 + lose the extended attributes and these PaX markings.
81063 +
81064 + Note that if you enable the legacy EI_PAX marking support as well,
81065 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
81066 +
81067 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
81068 + must make sure that the marks are the same if a binary has both marks.
81069 +
81070 + If you enable none of the marking options then all applications
81071 + will run with PaX enabled on them by default.
81072 +
81073 +choice
81074 + prompt 'MAC system integration'
81075 + default PAX_HAVE_ACL_FLAGS
81076 + help
81077 + Mandatory Access Control systems have the option of controlling
81078 + PaX flags on a per executable basis, choose the method supported
81079 + by your particular system.
81080 +
81081 + - "none": if your MAC system does not interact with PaX,
81082 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
81083 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
81084 +
81085 + NOTE: this option is for developers/integrators only.
81086 +
81087 + config PAX_NO_ACL_FLAGS
81088 + bool 'none'
81089 +
81090 + config PAX_HAVE_ACL_FLAGS
81091 + bool 'direct'
81092 +
81093 + config PAX_HOOK_ACL_FLAGS
81094 + bool 'hook'
81095 +endchoice
81096 +
81097 +endmenu
81098 +
81099 +menu "Non-executable pages"
81100 + depends on PAX
81101 +
81102 +config PAX_NOEXEC
81103 + bool "Enforce non-executable pages"
81104 + default y if GRKERNSEC_CONFIG_AUTO
81105 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
81106 + help
81107 + By design some architectures do not allow for protecting memory
81108 + pages against execution or even if they do, Linux does not make
81109 + use of this feature. In practice this means that if a page is
81110 + readable (such as the stack or heap) it is also executable.
81111 +
81112 + There is a well known exploit technique that makes use of this
81113 + fact and a common programming mistake where an attacker can
81114 + introduce code of his choice somewhere in the attacked program's
81115 + memory (typically the stack or the heap) and then execute it.
81116 +
81117 + If the attacked program was running with different (typically
81118 + higher) privileges than that of the attacker, then he can elevate
81119 + his own privilege level (e.g. get a root shell, write to files for
81120 + which he does not have write access to, etc).
81121 +
81122 + Enabling this option will let you choose from various features
81123 + that prevent the injection and execution of 'foreign' code in
81124 + a program.
81125 +
81126 + This will also break programs that rely on the old behaviour and
81127 + expect that dynamically allocated memory via the malloc() family
81128 + of functions is executable (which it is not). Notable examples
81129 + are the XFree86 4.x server, the java runtime and wine.
81130 +
81131 +config PAX_PAGEEXEC
81132 + bool "Paging based non-executable pages"
81133 + default y if GRKERNSEC_CONFIG_AUTO
81134 + 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)
81135 + select S390_SWITCH_AMODE if S390
81136 + select S390_EXEC_PROTECT if S390
81137 + select ARCH_TRACK_EXEC_LIMIT if X86_32
81138 + help
81139 + This implementation is based on the paging feature of the CPU.
81140 + On i386 without hardware non-executable bit support there is a
81141 + variable but usually low performance impact, however on Intel's
81142 + P4 core based CPUs it is very high so you should not enable this
81143 + for kernels meant to be used on such CPUs.
81144 +
81145 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
81146 + with hardware non-executable bit support there is no performance
81147 + impact, on ppc the impact is negligible.
81148 +
81149 + Note that several architectures require various emulations due to
81150 + badly designed userland ABIs, this will cause a performance impact
81151 + but will disappear as soon as userland is fixed. For example, ppc
81152 + userland MUST have been built with secure-plt by a recent toolchain.
81153 +
81154 +config PAX_SEGMEXEC
81155 + bool "Segmentation based non-executable pages"
81156 + default y if GRKERNSEC_CONFIG_AUTO
81157 + depends on PAX_NOEXEC && X86_32
81158 + help
81159 + This implementation is based on the segmentation feature of the
81160 + CPU and has a very small performance impact, however applications
81161 + will be limited to a 1.5 GB address space instead of the normal
81162 + 3 GB.
81163 +
81164 +config PAX_EMUTRAMP
81165 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
81166 + default y if PARISC
81167 + help
81168 + There are some programs and libraries that for one reason or
81169 + another attempt to execute special small code snippets from
81170 + non-executable memory pages. Most notable examples are the
81171 + signal handler return code generated by the kernel itself and
81172 + the GCC trampolines.
81173 +
81174 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
81175 + such programs will no longer work under your kernel.
81176 +
81177 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
81178 + utilities to enable trampoline emulation for the affected programs
81179 + yet still have the protection provided by the non-executable pages.
81180 +
81181 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
81182 + your system will not even boot.
81183 +
81184 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
81185 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
81186 + for the affected files.
81187 +
81188 + NOTE: enabling this feature *may* open up a loophole in the
81189 + protection provided by non-executable pages that an attacker
81190 + could abuse. Therefore the best solution is to not have any
81191 + files on your system that would require this option. This can
81192 + be achieved by not using libc5 (which relies on the kernel
81193 + signal handler return code) and not using or rewriting programs
81194 + that make use of the nested function implementation of GCC.
81195 + Skilled users can just fix GCC itself so that it implements
81196 + nested function calls in a way that does not interfere with PaX.
81197 +
81198 +config PAX_EMUSIGRT
81199 + bool "Automatically emulate sigreturn trampolines"
81200 + depends on PAX_EMUTRAMP && PARISC
81201 + default y
81202 + help
81203 + Enabling this option will have the kernel automatically detect
81204 + and emulate signal return trampolines executing on the stack
81205 + that would otherwise lead to task termination.
81206 +
81207 + This solution is intended as a temporary one for users with
81208 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
81209 + Modula-3 runtime, etc) or executables linked to such, basically
81210 + everything that does not specify its own SA_RESTORER function in
81211 + normal executable memory like glibc 2.1+ does.
81212 +
81213 + On parisc you MUST enable this option, otherwise your system will
81214 + not even boot.
81215 +
81216 + NOTE: this feature cannot be disabled on a per executable basis
81217 + and since it *does* open up a loophole in the protection provided
81218 + by non-executable pages, the best solution is to not have any
81219 + files on your system that would require this option.
81220 +
81221 +config PAX_MPROTECT
81222 + bool "Restrict mprotect()"
81223 + default y if GRKERNSEC_CONFIG_AUTO
81224 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81225 + help
81226 + Enabling this option will prevent programs from
81227 + - changing the executable status of memory pages that were
81228 + not originally created as executable,
81229 + - making read-only executable pages writable again,
81230 + - creating executable pages from anonymous memory,
81231 + - making read-only-after-relocations (RELRO) data pages writable again.
81232 +
81233 + You should say Y here to complete the protection provided by
81234 + the enforcement of non-executable pages.
81235 +
81236 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81237 + this feature on a per file basis.
81238 +
81239 +config PAX_MPROTECT_COMPAT
81240 + bool "Use legacy/compat protection demoting (read help)"
81241 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81242 + depends on PAX_MPROTECT
81243 + help
81244 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81245 + by sending the proper error code to the application. For some broken
81246 + userland, this can cause problems with Python or other applications. The
81247 + current implementation however allows for applications like clamav to
81248 + detect if JIT compilation/execution is allowed and to fall back gracefully
81249 + to an interpreter-based mode if it does not. While we encourage everyone
81250 + to use the current implementation as-is and push upstream to fix broken
81251 + userland (note that the RWX logging option can assist with this), in some
81252 + environments this may not be possible. Having to disable MPROTECT
81253 + completely on certain binaries reduces the security benefit of PaX,
81254 + so this option is provided for those environments to revert to the old
81255 + behavior.
81256 +
81257 +config PAX_ELFRELOCS
81258 + bool "Allow ELF text relocations (read help)"
81259 + depends on PAX_MPROTECT
81260 + default n
81261 + help
81262 + Non-executable pages and mprotect() restrictions are effective
81263 + in preventing the introduction of new executable code into an
81264 + attacked task's address space. There remain only two venues
81265 + for this kind of attack: if the attacker can execute already
81266 + existing code in the attacked task then he can either have it
81267 + create and mmap() a file containing his code or have it mmap()
81268 + an already existing ELF library that does not have position
81269 + independent code in it and use mprotect() on it to make it
81270 + writable and copy his code there. While protecting against
81271 + the former approach is beyond PaX, the latter can be prevented
81272 + by having only PIC ELF libraries on one's system (which do not
81273 + need to relocate their code). If you are sure this is your case,
81274 + as is the case with all modern Linux distributions, then leave
81275 + this option disabled. You should say 'n' here.
81276 +
81277 +config PAX_ETEXECRELOCS
81278 + bool "Allow ELF ET_EXEC text relocations"
81279 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81280 + select PAX_ELFRELOCS
81281 + default y
81282 + help
81283 + On some architectures there are incorrectly created applications
81284 + that require text relocations and would not work without enabling
81285 + this option. If you are an alpha, ia64 or parisc user, you should
81286 + enable this option and disable it once you have made sure that
81287 + none of your applications need it.
81288 +
81289 +config PAX_EMUPLT
81290 + bool "Automatically emulate ELF PLT"
81291 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81292 + default y
81293 + help
81294 + Enabling this option will have the kernel automatically detect
81295 + and emulate the Procedure Linkage Table entries in ELF files.
81296 + On some architectures such entries are in writable memory, and
81297 + become non-executable leading to task termination. Therefore
81298 + it is mandatory that you enable this option on alpha, parisc,
81299 + sparc and sparc64, otherwise your system would not even boot.
81300 +
81301 + NOTE: this feature *does* open up a loophole in the protection
81302 + provided by the non-executable pages, therefore the proper
81303 + solution is to modify the toolchain to produce a PLT that does
81304 + not need to be writable.
81305 +
81306 +config PAX_DLRESOLVE
81307 + bool 'Emulate old glibc resolver stub'
81308 + depends on PAX_EMUPLT && SPARC
81309 + default n
81310 + help
81311 + This option is needed if userland has an old glibc (before 2.4)
81312 + that puts a 'save' instruction into the runtime generated resolver
81313 + stub that needs special emulation.
81314 +
81315 +config PAX_KERNEXEC
81316 + bool "Enforce non-executable kernel pages"
81317 + 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))
81318 + depends on X86 && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81319 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81320 + select PAX_KERNEXEC_PLUGIN if X86_64
81321 + help
81322 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81323 + that is, enabling this option will make it harder to inject
81324 + and execute 'foreign' code in kernel memory itself.
81325 +
81326 +choice
81327 + prompt "Return Address Instrumentation Method"
81328 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81329 + depends on PAX_KERNEXEC_PLUGIN
81330 + help
81331 + Select the method used to instrument function pointer dereferences.
81332 + Note that binary modules cannot be instrumented by this approach.
81333 +
81334 + Note that the implementation requires a gcc with plugin support,
81335 + i.e., gcc 4.5 or newer. You may need to install the supporting
81336 + headers explicitly in addition to the normal gcc package.
81337 +
81338 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81339 + bool "bts"
81340 + help
81341 + This method is compatible with binary only modules but has
81342 + a higher runtime overhead.
81343 +
81344 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81345 + bool "or"
81346 + depends on !PARAVIRT
81347 + help
81348 + This method is incompatible with binary only modules but has
81349 + a lower runtime overhead.
81350 +endchoice
81351 +
81352 +config PAX_KERNEXEC_PLUGIN_METHOD
81353 + string
81354 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81355 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81356 + default ""
81357 +
81358 +config PAX_KERNEXEC_MODULE_TEXT
81359 + int "Minimum amount of memory reserved for module code"
81360 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81361 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81362 + depends on PAX_KERNEXEC && X86_32 && MODULES
81363 + help
81364 + Due to implementation details the kernel must reserve a fixed
81365 + amount of memory for module code at compile time that cannot be
81366 + changed at runtime. Here you can specify the minimum amount
81367 + in MB that will be reserved. Due to the same implementation
81368 + details this size will always be rounded up to the next 2/4 MB
81369 + boundary (depends on PAE) so the actually available memory for
81370 + module code will usually be more than this minimum.
81371 +
81372 + The default 4 MB should be enough for most users but if you have
81373 + an excessive number of modules (e.g., most distribution configs
81374 + compile many drivers as modules) or use huge modules such as
81375 + nvidia's kernel driver, you will need to adjust this amount.
81376 + A good rule of thumb is to look at your currently loaded kernel
81377 + modules and add up their sizes.
81378 +
81379 +endmenu
81380 +
81381 +menu "Address Space Layout Randomization"
81382 + depends on PAX
81383 +
81384 +config PAX_ASLR
81385 + bool "Address Space Layout Randomization"
81386 + default y if GRKERNSEC_CONFIG_AUTO
81387 + help
81388 + Many if not most exploit techniques rely on the knowledge of
81389 + certain addresses in the attacked program. The following options
81390 + will allow the kernel to apply a certain amount of randomization
81391 + to specific parts of the program thereby forcing an attacker to
81392 + guess them in most cases. Any failed guess will most likely crash
81393 + the attacked program which allows the kernel to detect such attempts
81394 + and react on them. PaX itself provides no reaction mechanisms,
81395 + instead it is strongly encouraged that you make use of Nergal's
81396 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81397 + (http://www.grsecurity.net/) built-in crash detection features or
81398 + develop one yourself.
81399 +
81400 + By saying Y here you can choose to randomize the following areas:
81401 + - top of the task's kernel stack
81402 + - top of the task's userland stack
81403 + - base address for mmap() requests that do not specify one
81404 + (this includes all libraries)
81405 + - base address of the main executable
81406 +
81407 + It is strongly recommended to say Y here as address space layout
81408 + randomization has negligible impact on performance yet it provides
81409 + a very effective protection.
81410 +
81411 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81412 + this feature on a per file basis.
81413 +
81414 +config PAX_RANDKSTACK
81415 + bool "Randomize kernel stack base"
81416 + default y if GRKERNSEC_CONFIG_AUTO
81417 + depends on X86_TSC && X86
81418 + help
81419 + By saying Y here the kernel will randomize every task's kernel
81420 + stack on every system call. This will not only force an attacker
81421 + to guess it but also prevent him from making use of possible
81422 + leaked information about it.
81423 +
81424 + Since the kernel stack is a rather scarce resource, randomization
81425 + may cause unexpected stack overflows, therefore you should very
81426 + carefully test your system. Note that once enabled in the kernel
81427 + configuration, this feature cannot be disabled on a per file basis.
81428 +
81429 +config PAX_RANDUSTACK
81430 + bool "Randomize user stack base"
81431 + default y if GRKERNSEC_CONFIG_AUTO
81432 + depends on PAX_ASLR
81433 + help
81434 + By saying Y here the kernel will randomize every task's userland
81435 + stack. The randomization is done in two steps where the second
81436 + one may apply a big amount of shift to the top of the stack and
81437 + cause problems for programs that want to use lots of memory (more
81438 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81439 + For this reason the second step can be controlled by 'chpax' or
81440 + 'paxctl' on a per file basis.
81441 +
81442 +config PAX_RANDMMAP
81443 + bool "Randomize mmap() base"
81444 + default y if GRKERNSEC_CONFIG_AUTO
81445 + depends on PAX_ASLR
81446 + help
81447 + By saying Y here the kernel will use a randomized base address for
81448 + mmap() requests that do not specify one themselves. As a result
81449 + all dynamically loaded libraries will appear at random addresses
81450 + and therefore be harder to exploit by a technique where an attacker
81451 + attempts to execute library code for his purposes (e.g. spawn a
81452 + shell from an exploited program that is running at an elevated
81453 + privilege level).
81454 +
81455 + Furthermore, if a program is relinked as a dynamic ELF file, its
81456 + base address will be randomized as well, completing the full
81457 + randomization of the address space layout. Attacking such programs
81458 + becomes a guess game. You can find an example of doing this at
81459 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81460 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81461 +
81462 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81463 + feature on a per file basis.
81464 +
81465 +endmenu
81466 +
81467 +menu "Miscellaneous hardening features"
81468 +
81469 +config PAX_MEMORY_SANITIZE
81470 + bool "Sanitize all freed memory"
81471 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81472 + depends on !HIBERNATION
81473 + help
81474 + By saying Y here the kernel will erase memory pages as soon as they
81475 + are freed. This in turn reduces the lifetime of data stored in the
81476 + pages, making it less likely that sensitive information such as
81477 + passwords, cryptographic secrets, etc stay in memory for too long.
81478 +
81479 + This is especially useful for programs whose runtime is short, long
81480 + lived processes and the kernel itself benefit from this as long as
81481 + they operate on whole memory pages and ensure timely freeing of pages
81482 + that may hold sensitive information.
81483 +
81484 + The tradeoff is performance impact, on a single CPU system kernel
81485 + compilation sees a 3% slowdown, other systems and workloads may vary
81486 + and you are advised to test this feature on your expected workload
81487 + before deploying it.
81488 +
81489 + Note that this feature does not protect data stored in live pages,
81490 + e.g., process memory swapped to disk may stay there for a long time.
81491 +
81492 +config PAX_MEMORY_STACKLEAK
81493 + bool "Sanitize kernel stack"
81494 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81495 + depends on X86
81496 + help
81497 + By saying Y here the kernel will erase the kernel stack before it
81498 + returns from a system call. This in turn reduces the information
81499 + that a kernel stack leak bug can reveal.
81500 +
81501 + Note that such a bug can still leak information that was put on
81502 + the stack by the current system call (the one eventually triggering
81503 + the bug) but traces of earlier system calls on the kernel stack
81504 + cannot leak anymore.
81505 +
81506 + The tradeoff is performance impact: on a single CPU system kernel
81507 + compilation sees a 1% slowdown, other systems and workloads may vary
81508 + and you are advised to test this feature on your expected workload
81509 + before deploying it.
81510 +
81511 + Note that the full feature requires a gcc with plugin support,
81512 + i.e., gcc 4.5 or newer. You may need to install the supporting
81513 + headers explicitly in addition to the normal gcc package. Using
81514 + older gcc versions means that functions with large enough stack
81515 + frames may leave uninitialized memory behind that may be exposed
81516 + to a later syscall leaking the stack.
81517 +
81518 +config PAX_MEMORY_UDEREF
81519 + bool "Prevent invalid userland pointer dereference"
81520 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81521 + depends on X86 && !UML_X86 && !XEN
81522 + select PAX_PER_CPU_PGD if X86_64
81523 + help
81524 + By saying Y here the kernel will be prevented from dereferencing
81525 + userland pointers in contexts where the kernel expects only kernel
81526 + pointers. This is both a useful runtime debugging feature and a
81527 + security measure that prevents exploiting a class of kernel bugs.
81528 +
81529 + The tradeoff is that some virtualization solutions may experience
81530 + a huge slowdown and therefore you should not enable this feature
81531 + for kernels meant to run in such environments. Whether a given VM
81532 + solution is affected or not is best determined by simply trying it
81533 + out, the performance impact will be obvious right on boot as this
81534 + mechanism engages from very early on. A good rule of thumb is that
81535 + VMs running on CPUs without hardware virtualization support (i.e.,
81536 + the majority of IA-32 CPUs) will likely experience the slowdown.
81537 +
81538 +config PAX_REFCOUNT
81539 + bool "Prevent various kernel object reference counter overflows"
81540 + default y if GRKERNSEC_CONFIG_AUTO
81541 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81542 + help
81543 + By saying Y here the kernel will detect and prevent overflowing
81544 + various (but not all) kinds of object reference counters. Such
81545 + overflows can normally occur due to bugs only and are often, if
81546 + not always, exploitable.
81547 +
81548 + The tradeoff is that data structures protected by an overflowed
81549 + refcount will never be freed and therefore will leak memory. Note
81550 + that this leak also happens even without this protection but in
81551 + that case the overflow can eventually trigger the freeing of the
81552 + data structure while it is still being used elsewhere, resulting
81553 + in the exploitable situation that this feature prevents.
81554 +
81555 + Since this has a negligible performance impact, you should enable
81556 + this feature.
81557 +
81558 +config PAX_USERCOPY
81559 + bool "Harden heap object copies between kernel and userland"
81560 + default y if GRKERNSEC_CONFIG_AUTO
81561 + depends on X86 || PPC || SPARC || ARM
81562 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81563 + select PAX_USERCOPY_SLABS
81564 + help
81565 + By saying Y here the kernel will enforce the size of heap objects
81566 + when they are copied in either direction between the kernel and
81567 + userland, even if only a part of the heap object is copied.
81568 +
81569 + Specifically, this checking prevents information leaking from the
81570 + kernel heap during kernel to userland copies (if the kernel heap
81571 + object is otherwise fully initialized) and prevents kernel heap
81572 + overflows during userland to kernel copies.
81573 +
81574 + Note that the current implementation provides the strictest bounds
81575 + checks for the SLUB allocator.
81576 +
81577 + Enabling this option also enables per-slab cache protection against
81578 + data in a given cache being copied into/out of via userland
81579 + accessors. Though the whitelist of regions will be reduced over
81580 + time, it notably protects important data structures like task structs.
81581 +
81582 + If frame pointers are enabled on x86, this option will also restrict
81583 + copies into and out of the kernel stack to local variables within a
81584 + single frame.
81585 +
81586 + Since this has a negligible performance impact, you should enable
81587 + this feature.
81588 +
81589 +config PAX_SIZE_OVERFLOW
81590 + bool "Prevent various integer overflows in function size parameters"
81591 + default y if GRKERNSEC_CONFIG_AUTO
81592 + depends on X86
81593 + help
81594 + By saying Y here the kernel recomputes expressions of function
81595 + arguments marked by a size_overflow attribute with double integer
81596 + precision (DImode/TImode for 32/64 bit integer types).
81597 +
81598 + The recomputed argument is checked against TYPE_MAX and an event
81599 + is logged on overflow and the triggering process is killed.
81600 +
81601 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81602 +
81603 + Note that the implementation requires a gcc with plugin support,
81604 + i.e., gcc 4.5 or newer. You may need to install the supporting
81605 + headers explicitly in addition to the normal gcc package.
81606 +
81607 +config PAX_LATENT_ENTROPY
81608 + bool "Generate some entropy during boot"
81609 + default y if GRKERNSEC_CONFIG_AUTO
81610 + help
81611 + By saying Y here the kernel will instrument early boot code to
81612 + extract some entropy from both original and artificially created
81613 + program state. This will help especially embedded systems where
81614 + there is little 'natural' source of entropy normally. The cost
81615 + is some slowdown of the boot process.
81616 +
81617 + Note that the implementation requires a gcc with plugin support,
81618 + i.e., gcc 4.5 or newer. You may need to install the supporting
81619 + headers explicitly in addition to the normal gcc package.
81620 +
81621 + Note that entropy extracted this way is not cryptographically
81622 + secure!
81623 +
81624 +endmenu
81625 +
81626 +endmenu
81627 +
81628 +source grsecurity/Kconfig
81629 +
81630 +endmenu
81631 +
81632 +endmenu
81633 +
81634 source security/keys/Kconfig
81635
81636 config SECURITY_DMESG_RESTRICT
81637 @@ -103,7 +993,7 @@ config INTEL_TXT
81638 config LSM_MMAP_MIN_ADDR
81639 int "Low address space for LSM to protect from user allocation"
81640 depends on SECURITY && SECURITY_SELINUX
81641 - default 32768 if ARM
81642 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81643 default 65536
81644 help
81645 This is the portion of low virtual memory which should be protected
81646 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81647 index 8c2a7f6..b133ac9 100644
81648 --- a/security/apparmor/lsm.c
81649 +++ b/security/apparmor/lsm.c
81650 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81651 return error;
81652 }
81653
81654 -static struct security_operations apparmor_ops = {
81655 +static struct security_operations apparmor_ops __read_only = {
81656 .name = "apparmor",
81657
81658 .ptrace_access_check = apparmor_ptrace_access_check,
81659 diff --git a/security/commoncap.c b/security/commoncap.c
81660 index 6dbae46..d5611fd 100644
81661 --- a/security/commoncap.c
81662 +++ b/security/commoncap.c
81663 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81664 return 0;
81665 }
81666
81667 +/* returns:
81668 + 1 for suid privilege
81669 + 2 for sgid privilege
81670 + 3 for fscap privilege
81671 +*/
81672 +int is_privileged_binary(const struct dentry *dentry)
81673 +{
81674 + struct cpu_vfs_cap_data capdata;
81675 + struct inode *inode = dentry->d_inode;
81676 +
81677 + if (!inode || S_ISDIR(inode->i_mode))
81678 + return 0;
81679 +
81680 + if (inode->i_mode & S_ISUID)
81681 + return 1;
81682 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81683 + return 2;
81684 +
81685 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81686 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81687 + return 3;
81688 + }
81689 +
81690 + return 0;
81691 +}
81692 +
81693 /*
81694 * Attempt to get the on-exec apply capability sets for an executable file from
81695 * its xattrs and, if present, apply them to the proposed credentials being
81696 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81697 const struct cred *cred = current_cred();
81698 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81699
81700 + if (gr_acl_enable_at_secure())
81701 + return 1;
81702 +
81703 if (!uid_eq(cred->uid, root_uid)) {
81704 if (bprm->cap_effective)
81705 return 1;
81706 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81707 index 6ee8826..6350060 100644
81708 --- a/security/integrity/ima/ima.h
81709 +++ b/security/integrity/ima/ima.h
81710 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81711 extern spinlock_t ima_queue_lock;
81712
81713 struct ima_h_table {
81714 - atomic_long_t len; /* number of stored measurements in the list */
81715 - atomic_long_t violations;
81716 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81717 + atomic_long_unchecked_t violations;
81718 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81719 };
81720 extern struct ima_h_table ima_htable;
81721 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81722 index b356884..fd9676e 100644
81723 --- a/security/integrity/ima/ima_api.c
81724 +++ b/security/integrity/ima/ima_api.c
81725 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81726 int result;
81727
81728 /* can overflow, only indicator */
81729 - atomic_long_inc(&ima_htable.violations);
81730 + atomic_long_inc_unchecked(&ima_htable.violations);
81731
81732 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81733 if (!entry) {
81734 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81735 index 38477c9..87a60c7 100644
81736 --- a/security/integrity/ima/ima_fs.c
81737 +++ b/security/integrity/ima/ima_fs.c
81738 @@ -28,12 +28,12 @@
81739 static int valid_policy = 1;
81740 #define TMPBUFLEN 12
81741 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81742 - loff_t *ppos, atomic_long_t *val)
81743 + loff_t *ppos, atomic_long_unchecked_t *val)
81744 {
81745 char tmpbuf[TMPBUFLEN];
81746 ssize_t len;
81747
81748 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81749 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81750 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81751 }
81752
81753 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81754 index 55a6271..ad829c3 100644
81755 --- a/security/integrity/ima/ima_queue.c
81756 +++ b/security/integrity/ima/ima_queue.c
81757 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81758 INIT_LIST_HEAD(&qe->later);
81759 list_add_tail_rcu(&qe->later, &ima_measurements);
81760
81761 - atomic_long_inc(&ima_htable.len);
81762 + atomic_long_inc_unchecked(&ima_htable.len);
81763 key = ima_hash_key(entry->digest);
81764 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81765 return 0;
81766 diff --git a/security/keys/compat.c b/security/keys/compat.c
81767 index 1c26176..64a1ba2 100644
81768 --- a/security/keys/compat.c
81769 +++ b/security/keys/compat.c
81770 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81771 if (ret == 0)
81772 goto no_payload_free;
81773
81774 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81775 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81776
81777 if (iov != iovstack)
81778 kfree(iov);
81779 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81780 index 5d34b4e..2456674 100644
81781 --- a/security/keys/keyctl.c
81782 +++ b/security/keys/keyctl.c
81783 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81784 /*
81785 * Copy the iovec data from userspace
81786 */
81787 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81788 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81789 unsigned ioc)
81790 {
81791 for (; ioc > 0; ioc--) {
81792 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81793 * If successful, 0 will be returned.
81794 */
81795 long keyctl_instantiate_key_common(key_serial_t id,
81796 - const struct iovec *payload_iov,
81797 + const struct iovec __user *payload_iov,
81798 unsigned ioc,
81799 size_t plen,
81800 key_serial_t ringid)
81801 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
81802 [0].iov_len = plen
81803 };
81804
81805 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81806 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81807 }
81808
81809 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81810 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81811 if (ret == 0)
81812 goto no_payload_free;
81813
81814 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81815 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81816
81817 if (iov != iovstack)
81818 kfree(iov);
81819 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81820 index 6e42df1..aba52bd 100644
81821 --- a/security/keys/keyring.c
81822 +++ b/security/keys/keyring.c
81823 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81824 ret = -EFAULT;
81825
81826 for (loop = 0; loop < klist->nkeys; loop++) {
81827 + key_serial_t serial;
81828 key = rcu_deref_link_locked(klist, loop,
81829 keyring);
81830 + serial = key->serial;
81831
81832 tmp = sizeof(key_serial_t);
81833 if (tmp > buflen)
81834 tmp = buflen;
81835
81836 - if (copy_to_user(buffer,
81837 - &key->serial,
81838 - tmp) != 0)
81839 + if (copy_to_user(buffer, &serial, tmp))
81840 goto error;
81841
81842 buflen -= tmp;
81843 diff --git a/security/min_addr.c b/security/min_addr.c
81844 index f728728..6457a0c 100644
81845 --- a/security/min_addr.c
81846 +++ b/security/min_addr.c
81847 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81848 */
81849 static void update_mmap_min_addr(void)
81850 {
81851 +#ifndef SPARC
81852 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81853 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81854 mmap_min_addr = dac_mmap_min_addr;
81855 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81856 #else
81857 mmap_min_addr = dac_mmap_min_addr;
81858 #endif
81859 +#endif
81860 }
81861
81862 /*
81863 diff --git a/security/security.c b/security/security.c
81864 index 8dcd4ae..1124de7 100644
81865 --- a/security/security.c
81866 +++ b/security/security.c
81867 @@ -20,6 +20,7 @@
81868 #include <linux/ima.h>
81869 #include <linux/evm.h>
81870 #include <linux/fsnotify.h>
81871 +#include <linux/mm.h>
81872 #include <linux/mman.h>
81873 #include <linux/mount.h>
81874 #include <linux/personality.h>
81875 @@ -32,8 +33,8 @@
81876 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81877 CONFIG_DEFAULT_SECURITY;
81878
81879 -static struct security_operations *security_ops;
81880 -static struct security_operations default_security_ops = {
81881 +static struct security_operations *security_ops __read_only;
81882 +static struct security_operations default_security_ops __read_only = {
81883 .name = "default",
81884 };
81885
81886 @@ -74,7 +75,9 @@ int __init security_init(void)
81887
81888 void reset_security_ops(void)
81889 {
81890 + pax_open_kernel();
81891 security_ops = &default_security_ops;
81892 + pax_close_kernel();
81893 }
81894
81895 /* Save user chosen LSM */
81896 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81897 index 61a5336..27215d8 100644
81898 --- a/security/selinux/hooks.c
81899 +++ b/security/selinux/hooks.c
81900 @@ -95,8 +95,6 @@
81901
81902 #define NUM_SEL_MNT_OPTS 5
81903
81904 -extern struct security_operations *security_ops;
81905 -
81906 /* SECMARK reference count */
81907 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81908
81909 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81910
81911 #endif
81912
81913 -static struct security_operations selinux_ops = {
81914 +static struct security_operations selinux_ops __read_only = {
81915 .name = "selinux",
81916
81917 .ptrace_access_check = selinux_ptrace_access_check,
81918 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81919 index 65f67cb..3f141ef 100644
81920 --- a/security/selinux/include/xfrm.h
81921 +++ b/security/selinux/include/xfrm.h
81922 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81923
81924 static inline void selinux_xfrm_notify_policyload(void)
81925 {
81926 - atomic_inc(&flow_cache_genid);
81927 + atomic_inc_unchecked(&flow_cache_genid);
81928 rt_genid_bump(&init_net);
81929 }
81930 #else
81931 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81932 index 38be92c..21f49ee 100644
81933 --- a/security/smack/smack_lsm.c
81934 +++ b/security/smack/smack_lsm.c
81935 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81936 return 0;
81937 }
81938
81939 -struct security_operations smack_ops = {
81940 +struct security_operations smack_ops __read_only = {
81941 .name = "smack",
81942
81943 .ptrace_access_check = smack_ptrace_access_check,
81944 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81945 index a2ee362..5754f34 100644
81946 --- a/security/tomoyo/tomoyo.c
81947 +++ b/security/tomoyo/tomoyo.c
81948 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81949 * tomoyo_security_ops is a "struct security_operations" which is used for
81950 * registering TOMOYO.
81951 */
81952 -static struct security_operations tomoyo_security_ops = {
81953 +static struct security_operations tomoyo_security_ops __read_only = {
81954 .name = "tomoyo",
81955 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81956 .cred_prepare = tomoyo_cred_prepare,
81957 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81958 index 20ef514..4182bed 100644
81959 --- a/security/yama/Kconfig
81960 +++ b/security/yama/Kconfig
81961 @@ -1,6 +1,6 @@
81962 config SECURITY_YAMA
81963 bool "Yama support"
81964 - depends on SECURITY
81965 + depends on SECURITY && !GRKERNSEC
81966 select SECURITYFS
81967 select SECURITY_PATH
81968 default n
81969 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81970 index 4cedc69..e59d8a3 100644
81971 --- a/sound/aoa/codecs/onyx.c
81972 +++ b/sound/aoa/codecs/onyx.c
81973 @@ -54,7 +54,7 @@ struct onyx {
81974 spdif_locked:1,
81975 analog_locked:1,
81976 original_mute:2;
81977 - int open_count;
81978 + local_t open_count;
81979 struct codec_info *codec_info;
81980
81981 /* mutex serializes concurrent access to the device
81982 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81983 struct onyx *onyx = cii->codec_data;
81984
81985 mutex_lock(&onyx->mutex);
81986 - onyx->open_count++;
81987 + local_inc(&onyx->open_count);
81988 mutex_unlock(&onyx->mutex);
81989
81990 return 0;
81991 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81992 struct onyx *onyx = cii->codec_data;
81993
81994 mutex_lock(&onyx->mutex);
81995 - onyx->open_count--;
81996 - if (!onyx->open_count)
81997 + if (local_dec_and_test(&onyx->open_count))
81998 onyx->spdif_locked = onyx->analog_locked = 0;
81999 mutex_unlock(&onyx->mutex);
82000
82001 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
82002 index ffd2025..df062c9 100644
82003 --- a/sound/aoa/codecs/onyx.h
82004 +++ b/sound/aoa/codecs/onyx.h
82005 @@ -11,6 +11,7 @@
82006 #include <linux/i2c.h>
82007 #include <asm/pmac_low_i2c.h>
82008 #include <asm/prom.h>
82009 +#include <asm/local.h>
82010
82011 /* PCM3052 register definitions */
82012
82013 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
82014 index 4c1cc51..16040040 100644
82015 --- a/sound/core/oss/pcm_oss.c
82016 +++ b/sound/core/oss/pcm_oss.c
82017 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
82018 if (in_kernel) {
82019 mm_segment_t fs;
82020 fs = snd_enter_user();
82021 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
82022 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
82023 snd_leave_user(fs);
82024 } else {
82025 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
82026 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
82027 }
82028 if (ret != -EPIPE && ret != -ESTRPIPE)
82029 break;
82030 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
82031 if (in_kernel) {
82032 mm_segment_t fs;
82033 fs = snd_enter_user();
82034 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
82035 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
82036 snd_leave_user(fs);
82037 } else {
82038 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
82039 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
82040 }
82041 if (ret == -EPIPE) {
82042 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
82043 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
82044 struct snd_pcm_plugin_channel *channels;
82045 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
82046 if (!in_kernel) {
82047 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
82048 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
82049 return -EFAULT;
82050 buf = runtime->oss.buffer;
82051 }
82052 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
82053 }
82054 } else {
82055 tmp = snd_pcm_oss_write2(substream,
82056 - (const char __force *)buf,
82057 + (const char __force_kernel *)buf,
82058 runtime->oss.period_bytes, 0);
82059 if (tmp <= 0)
82060 goto err;
82061 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
82062 struct snd_pcm_runtime *runtime = substream->runtime;
82063 snd_pcm_sframes_t frames, frames1;
82064 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
82065 - char __user *final_dst = (char __force __user *)buf;
82066 + char __user *final_dst = (char __force_user *)buf;
82067 if (runtime->oss.plugin_first) {
82068 struct snd_pcm_plugin_channel *channels;
82069 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
82070 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
82071 xfer += tmp;
82072 runtime->oss.buffer_used -= tmp;
82073 } else {
82074 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
82075 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
82076 runtime->oss.period_bytes, 0);
82077 if (tmp <= 0)
82078 goto err;
82079 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
82080 size1);
82081 size1 /= runtime->channels; /* frames */
82082 fs = snd_enter_user();
82083 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
82084 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
82085 snd_leave_user(fs);
82086 }
82087 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
82088 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
82089 index 91cdf943..4085161 100644
82090 --- a/sound/core/pcm_compat.c
82091 +++ b/sound/core/pcm_compat.c
82092 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
82093 int err;
82094
82095 fs = snd_enter_user();
82096 - err = snd_pcm_delay(substream, &delay);
82097 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
82098 snd_leave_user(fs);
82099 if (err < 0)
82100 return err;
82101 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
82102 index f9ddecf..e27404d 100644
82103 --- a/sound/core/pcm_native.c
82104 +++ b/sound/core/pcm_native.c
82105 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
82106 switch (substream->stream) {
82107 case SNDRV_PCM_STREAM_PLAYBACK:
82108 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
82109 - (void __user *)arg);
82110 + (void __force_user *)arg);
82111 break;
82112 case SNDRV_PCM_STREAM_CAPTURE:
82113 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
82114 - (void __user *)arg);
82115 + (void __force_user *)arg);
82116 break;
82117 default:
82118 result = -EINVAL;
82119 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
82120 index 60e8fc1..786abcb 100644
82121 --- a/sound/core/seq/seq_device.c
82122 +++ b/sound/core/seq/seq_device.c
82123 @@ -64,7 +64,7 @@ struct ops_list {
82124 int argsize; /* argument size */
82125
82126 /* operators */
82127 - struct snd_seq_dev_ops ops;
82128 + struct snd_seq_dev_ops *ops;
82129
82130 /* registred devices */
82131 struct list_head dev_list; /* list of devices */
82132 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
82133
82134 mutex_lock(&ops->reg_mutex);
82135 /* copy driver operators */
82136 - ops->ops = *entry;
82137 + ops->ops = entry;
82138 ops->driver |= DRIVER_LOADED;
82139 ops->argsize = argsize;
82140
82141 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
82142 dev->name, ops->id, ops->argsize, dev->argsize);
82143 return -EINVAL;
82144 }
82145 - if (ops->ops.init_device(dev) >= 0) {
82146 + if (ops->ops->init_device(dev) >= 0) {
82147 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
82148 ops->num_init_devices++;
82149 } else {
82150 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
82151 dev->name, ops->id, ops->argsize, dev->argsize);
82152 return -EINVAL;
82153 }
82154 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
82155 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
82156 dev->status = SNDRV_SEQ_DEVICE_FREE;
82157 dev->driver_data = NULL;
82158 ops->num_init_devices--;
82159 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
82160 index 2d5514b..3afae9c 100644
82161 --- a/sound/drivers/mts64.c
82162 +++ b/sound/drivers/mts64.c
82163 @@ -29,6 +29,7 @@
82164 #include <sound/initval.h>
82165 #include <sound/rawmidi.h>
82166 #include <sound/control.h>
82167 +#include <asm/local.h>
82168
82169 #define CARD_NAME "Miditerminal 4140"
82170 #define DRIVER_NAME "MTS64"
82171 @@ -67,7 +68,7 @@ struct mts64 {
82172 struct pardevice *pardev;
82173 int pardev_claimed;
82174
82175 - int open_count;
82176 + local_t open_count;
82177 int current_midi_output_port;
82178 int current_midi_input_port;
82179 u8 mode[MTS64_NUM_INPUT_PORTS];
82180 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82181 {
82182 struct mts64 *mts = substream->rmidi->private_data;
82183
82184 - if (mts->open_count == 0) {
82185 + if (local_read(&mts->open_count) == 0) {
82186 /* We don't need a spinlock here, because this is just called
82187 if the device has not been opened before.
82188 So there aren't any IRQs from the device */
82189 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
82190
82191 msleep(50);
82192 }
82193 - ++(mts->open_count);
82194 + local_inc(&mts->open_count);
82195
82196 return 0;
82197 }
82198 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82199 struct mts64 *mts = substream->rmidi->private_data;
82200 unsigned long flags;
82201
82202 - --(mts->open_count);
82203 - if (mts->open_count == 0) {
82204 + if (local_dec_return(&mts->open_count) == 0) {
82205 /* We need the spinlock_irqsave here because we can still
82206 have IRQs at this point */
82207 spin_lock_irqsave(&mts->lock, flags);
82208 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82209
82210 msleep(500);
82211
82212 - } else if (mts->open_count < 0)
82213 - mts->open_count = 0;
82214 + } else if (local_read(&mts->open_count) < 0)
82215 + local_set(&mts->open_count, 0);
82216
82217 return 0;
82218 }
82219 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82220 index b953fb4..1999c01 100644
82221 --- a/sound/drivers/opl4/opl4_lib.c
82222 +++ b/sound/drivers/opl4/opl4_lib.c
82223 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82224 MODULE_DESCRIPTION("OPL4 driver");
82225 MODULE_LICENSE("GPL");
82226
82227 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82228 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82229 {
82230 int timeout = 10;
82231 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82232 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82233 index 8364855..59f2e2b 100644
82234 --- a/sound/drivers/portman2x4.c
82235 +++ b/sound/drivers/portman2x4.c
82236 @@ -48,6 +48,7 @@
82237 #include <sound/initval.h>
82238 #include <sound/rawmidi.h>
82239 #include <sound/control.h>
82240 +#include <asm/local.h>
82241
82242 #define CARD_NAME "Portman 2x4"
82243 #define DRIVER_NAME "portman"
82244 @@ -85,7 +86,7 @@ struct portman {
82245 struct pardevice *pardev;
82246 int pardev_claimed;
82247
82248 - int open_count;
82249 + local_t open_count;
82250 int mode[PORTMAN_NUM_INPUT_PORTS];
82251 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82252 };
82253 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82254 index ea995af..f1bfa37 100644
82255 --- a/sound/firewire/amdtp.c
82256 +++ b/sound/firewire/amdtp.c
82257 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82258 ptr = s->pcm_buffer_pointer + data_blocks;
82259 if (ptr >= pcm->runtime->buffer_size)
82260 ptr -= pcm->runtime->buffer_size;
82261 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82262 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82263
82264 s->pcm_period_pointer += data_blocks;
82265 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82266 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82267 */
82268 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82269 {
82270 - ACCESS_ONCE(s->source_node_id_field) =
82271 + ACCESS_ONCE_RW(s->source_node_id_field) =
82272 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82273 }
82274 EXPORT_SYMBOL(amdtp_out_stream_update);
82275 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82276 index b680c5e..061b7a0 100644
82277 --- a/sound/firewire/amdtp.h
82278 +++ b/sound/firewire/amdtp.h
82279 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82280 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82281 struct snd_pcm_substream *pcm)
82282 {
82283 - ACCESS_ONCE(s->pcm) = pcm;
82284 + ACCESS_ONCE_RW(s->pcm) = pcm;
82285 }
82286
82287 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82288 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82289 index d428ffe..751ef78 100644
82290 --- a/sound/firewire/isight.c
82291 +++ b/sound/firewire/isight.c
82292 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82293 ptr += count;
82294 if (ptr >= runtime->buffer_size)
82295 ptr -= runtime->buffer_size;
82296 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82297 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82298
82299 isight->period_counter += count;
82300 if (isight->period_counter >= runtime->period_size) {
82301 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82302 if (err < 0)
82303 return err;
82304
82305 - ACCESS_ONCE(isight->pcm_active) = true;
82306 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82307
82308 return 0;
82309 }
82310 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82311 {
82312 struct isight *isight = substream->private_data;
82313
82314 - ACCESS_ONCE(isight->pcm_active) = false;
82315 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82316
82317 mutex_lock(&isight->mutex);
82318 isight_stop_streaming(isight);
82319 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82320
82321 switch (cmd) {
82322 case SNDRV_PCM_TRIGGER_START:
82323 - ACCESS_ONCE(isight->pcm_running) = true;
82324 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82325 break;
82326 case SNDRV_PCM_TRIGGER_STOP:
82327 - ACCESS_ONCE(isight->pcm_running) = false;
82328 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82329 break;
82330 default:
82331 return -EINVAL;
82332 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82333 index 7bd5e33..1fcab12 100644
82334 --- a/sound/isa/cmi8330.c
82335 +++ b/sound/isa/cmi8330.c
82336 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82337
82338 struct snd_pcm *pcm;
82339 struct snd_cmi8330_stream {
82340 - struct snd_pcm_ops ops;
82341 + snd_pcm_ops_no_const ops;
82342 snd_pcm_open_callback_t open;
82343 void *private_data; /* sb or wss */
82344 } streams[2];
82345 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82346 index b2b3c01..e1c1e1f 100644
82347 --- a/sound/oss/sb_audio.c
82348 +++ b/sound/oss/sb_audio.c
82349 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82350 buf16 = (signed short *)(localbuf + localoffs);
82351 while (c)
82352 {
82353 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82354 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82355 if (copy_from_user(lbuf8,
82356 userbuf+useroffs + p,
82357 locallen))
82358 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82359 index 7d8803a..559f8d0 100644
82360 --- a/sound/oss/swarm_cs4297a.c
82361 +++ b/sound/oss/swarm_cs4297a.c
82362 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82363 {
82364 struct cs4297a_state *s;
82365 u32 pwr, id;
82366 - mm_segment_t fs;
82367 int rval;
82368 #ifndef CONFIG_BCM_CS4297A_CSWARM
82369 u64 cfg;
82370 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82371 if (!rval) {
82372 char *sb1250_duart_present;
82373
82374 +#if 0
82375 + mm_segment_t fs;
82376 fs = get_fs();
82377 set_fs(KERNEL_DS);
82378 -#if 0
82379 val = SOUND_MASK_LINE;
82380 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82381 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82382 val = initvol[i].vol;
82383 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82384 }
82385 + set_fs(fs);
82386 // cs4297a_write_ac97(s, 0x18, 0x0808);
82387 #else
82388 // cs4297a_write_ac97(s, 0x5e, 0x180);
82389 cs4297a_write_ac97(s, 0x02, 0x0808);
82390 cs4297a_write_ac97(s, 0x18, 0x0808);
82391 #endif
82392 - set_fs(fs);
82393
82394 list_add(&s->list, &cs4297a_devs);
82395
82396 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82397 index 4f4e545..9b75d10 100644
82398 --- a/sound/pci/hda/hda_codec.h
82399 +++ b/sound/pci/hda/hda_codec.h
82400 @@ -618,7 +618,7 @@ struct hda_bus_ops {
82401 /* notify power-up/down from codec to controller */
82402 void (*pm_notify)(struct hda_bus *bus, bool power_up);
82403 #endif
82404 -};
82405 +} __no_const;
82406
82407 /* template to pass to the bus constructor */
82408 struct hda_bus_template {
82409 @@ -716,6 +716,7 @@ struct hda_codec_ops {
82410 #endif
82411 void (*reboot_notify)(struct hda_codec *codec);
82412 };
82413 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82414
82415 /* record for amp information cache */
82416 struct hda_cache_head {
82417 @@ -746,7 +747,7 @@ struct hda_pcm_ops {
82418 struct snd_pcm_substream *substream);
82419 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82420 struct snd_pcm_substream *substream);
82421 -};
82422 +} __no_const;
82423
82424 /* PCM information for each substream */
82425 struct hda_pcm_stream {
82426 @@ -805,7 +806,7 @@ struct hda_codec {
82427 const char *modelname; /* model name for preset */
82428
82429 /* set by patch */
82430 - struct hda_codec_ops patch_ops;
82431 + hda_codec_ops_no_const patch_ops;
82432
82433 /* PCM to create, set by patch_ops.build_pcms callback */
82434 unsigned int num_pcms;
82435 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82436 index d0e7d87..49ec1bb 100644
82437 --- a/sound/pci/ice1712/ice1712.h
82438 +++ b/sound/pci/ice1712/ice1712.h
82439 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82440 unsigned int mask_flags; /* total mask bits */
82441 struct snd_akm4xxx_ops {
82442 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82443 - } ops;
82444 + } __no_const ops;
82445 };
82446
82447 struct snd_ice1712_spdif {
82448 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82449 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82450 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82451 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82452 - } ops;
82453 + } __no_const ops;
82454 };
82455
82456
82457 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82458 index 4631a23..001ae57 100644
82459 --- a/sound/pci/ymfpci/ymfpci.h
82460 +++ b/sound/pci/ymfpci/ymfpci.h
82461 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82462 spinlock_t reg_lock;
82463 spinlock_t voice_lock;
82464 wait_queue_head_t interrupt_sleep;
82465 - atomic_t interrupt_sleep_count;
82466 + atomic_unchecked_t interrupt_sleep_count;
82467 struct snd_info_entry *proc_entry;
82468 const struct firmware *dsp_microcode;
82469 const struct firmware *controller_microcode;
82470 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82471 index 3a6f03f..bc5c86c 100644
82472 --- a/sound/pci/ymfpci/ymfpci_main.c
82473 +++ b/sound/pci/ymfpci/ymfpci_main.c
82474 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82475 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82476 break;
82477 }
82478 - if (atomic_read(&chip->interrupt_sleep_count)) {
82479 - atomic_set(&chip->interrupt_sleep_count, 0);
82480 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82481 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82482 wake_up(&chip->interrupt_sleep);
82483 }
82484 __end:
82485 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82486 continue;
82487 init_waitqueue_entry(&wait, current);
82488 add_wait_queue(&chip->interrupt_sleep, &wait);
82489 - atomic_inc(&chip->interrupt_sleep_count);
82490 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82491 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82492 remove_wait_queue(&chip->interrupt_sleep, &wait);
82493 }
82494 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82495 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82496 spin_unlock(&chip->reg_lock);
82497
82498 - if (atomic_read(&chip->interrupt_sleep_count)) {
82499 - atomic_set(&chip->interrupt_sleep_count, 0);
82500 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82501 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82502 wake_up(&chip->interrupt_sleep);
82503 }
82504 }
82505 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82506 spin_lock_init(&chip->reg_lock);
82507 spin_lock_init(&chip->voice_lock);
82508 init_waitqueue_head(&chip->interrupt_sleep);
82509 - atomic_set(&chip->interrupt_sleep_count, 0);
82510 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82511 chip->card = card;
82512 chip->pci = pci;
82513 chip->irq = -1;
82514 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82515 new file mode 100644
82516 index 0000000..50f2f2f
82517 --- /dev/null
82518 +++ b/tools/gcc/.gitignore
82519 @@ -0,0 +1 @@
82520 +size_overflow_hash.h
82521 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82522 new file mode 100644
82523 index 0000000..1d09b7e
82524 --- /dev/null
82525 +++ b/tools/gcc/Makefile
82526 @@ -0,0 +1,43 @@
82527 +#CC := gcc
82528 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82529 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82530 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82531 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82532 +
82533 +ifeq ($(PLUGINCC),$(HOSTCC))
82534 +HOSTLIBS := hostlibs
82535 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82536 +else
82537 +HOSTLIBS := hostcxxlibs
82538 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82539 +endif
82540 +
82541 +$(HOSTLIBS)-y := constify_plugin.so
82542 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82543 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82544 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82545 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82546 +$(HOSTLIBS)-y += colorize_plugin.so
82547 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82548 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82549 +
82550 +always := $($(HOSTLIBS)-y)
82551 +
82552 +constify_plugin-objs := constify_plugin.o
82553 +stackleak_plugin-objs := stackleak_plugin.o
82554 +kallocstat_plugin-objs := kallocstat_plugin.o
82555 +kernexec_plugin-objs := kernexec_plugin.o
82556 +checker_plugin-objs := checker_plugin.o
82557 +colorize_plugin-objs := colorize_plugin.o
82558 +size_overflow_plugin-objs := size_overflow_plugin.o
82559 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82560 +
82561 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82562 +
82563 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82564 + cmd_build_size_overflow_hash = \
82565 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82566 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82567 + $(call if_changed,build_size_overflow_hash)
82568 +
82569 +targets += size_overflow_hash.h
82570 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82571 new file mode 100644
82572 index 0000000..d41b5af
82573 --- /dev/null
82574 +++ b/tools/gcc/checker_plugin.c
82575 @@ -0,0 +1,171 @@
82576 +/*
82577 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82578 + * Licensed under the GPL v2
82579 + *
82580 + * Note: the choice of the license means that the compilation process is
82581 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82582 + * but for the kernel it doesn't matter since it doesn't link against
82583 + * any of the gcc libraries
82584 + *
82585 + * gcc plugin to implement various sparse (source code checker) features
82586 + *
82587 + * TODO:
82588 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82589 + *
82590 + * BUGS:
82591 + * - none known
82592 + */
82593 +#include "gcc-plugin.h"
82594 +#include "config.h"
82595 +#include "system.h"
82596 +#include "coretypes.h"
82597 +#include "tree.h"
82598 +#include "tree-pass.h"
82599 +#include "flags.h"
82600 +#include "intl.h"
82601 +#include "toplev.h"
82602 +#include "plugin.h"
82603 +//#include "expr.h" where are you...
82604 +#include "diagnostic.h"
82605 +#include "plugin-version.h"
82606 +#include "tm.h"
82607 +#include "function.h"
82608 +#include "basic-block.h"
82609 +#include "gimple.h"
82610 +#include "rtl.h"
82611 +#include "emit-rtl.h"
82612 +#include "tree-flow.h"
82613 +#include "target.h"
82614 +
82615 +extern void c_register_addr_space (const char *str, addr_space_t as);
82616 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82617 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82618 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82619 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82620 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82621 +
82622 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82623 +extern rtx emit_move_insn(rtx x, rtx y);
82624 +
82625 +int plugin_is_GPL_compatible;
82626 +
82627 +static struct plugin_info checker_plugin_info = {
82628 + .version = "201111150100",
82629 +};
82630 +
82631 +#define ADDR_SPACE_KERNEL 0
82632 +#define ADDR_SPACE_FORCE_KERNEL 1
82633 +#define ADDR_SPACE_USER 2
82634 +#define ADDR_SPACE_FORCE_USER 3
82635 +#define ADDR_SPACE_IOMEM 0
82636 +#define ADDR_SPACE_FORCE_IOMEM 0
82637 +#define ADDR_SPACE_PERCPU 0
82638 +#define ADDR_SPACE_FORCE_PERCPU 0
82639 +#define ADDR_SPACE_RCU 0
82640 +#define ADDR_SPACE_FORCE_RCU 0
82641 +
82642 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82643 +{
82644 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82645 +}
82646 +
82647 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82648 +{
82649 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82650 +}
82651 +
82652 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82653 +{
82654 + return default_addr_space_valid_pointer_mode(mode, as);
82655 +}
82656 +
82657 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82658 +{
82659 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82660 +}
82661 +
82662 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82663 +{
82664 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82665 +}
82666 +
82667 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82668 +{
82669 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82670 + return true;
82671 +
82672 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82673 + return true;
82674 +
82675 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82676 + return true;
82677 +
82678 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82679 + return true;
82680 +
82681 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82682 + return true;
82683 +
82684 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82685 + return true;
82686 +
82687 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82688 + return true;
82689 +
82690 + return subset == superset;
82691 +}
82692 +
82693 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82694 +{
82695 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82696 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82697 +
82698 + return op;
82699 +}
82700 +
82701 +static void register_checker_address_spaces(void *event_data, void *data)
82702 +{
82703 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82704 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82705 + c_register_addr_space("__user", ADDR_SPACE_USER);
82706 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82707 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82708 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82709 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82710 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82711 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82712 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82713 +
82714 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82715 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82716 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82717 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82718 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82719 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82720 + targetm.addr_space.convert = checker_addr_space_convert;
82721 +}
82722 +
82723 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82724 +{
82725 + const char * const plugin_name = plugin_info->base_name;
82726 + const int argc = plugin_info->argc;
82727 + const struct plugin_argument * const argv = plugin_info->argv;
82728 + int i;
82729 +
82730 + if (!plugin_default_version_check(version, &gcc_version)) {
82731 + error(G_("incompatible gcc/plugin versions"));
82732 + return 1;
82733 + }
82734 +
82735 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82736 +
82737 + for (i = 0; i < argc; ++i)
82738 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82739 +
82740 + if (TARGET_64BIT == 0)
82741 + return 0;
82742 +
82743 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82744 +
82745 + return 0;
82746 +}
82747 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82748 new file mode 100644
82749 index 0000000..846aeb0
82750 --- /dev/null
82751 +++ b/tools/gcc/colorize_plugin.c
82752 @@ -0,0 +1,148 @@
82753 +/*
82754 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82755 + * Licensed under the GPL v2
82756 + *
82757 + * Note: the choice of the license means that the compilation process is
82758 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82759 + * but for the kernel it doesn't matter since it doesn't link against
82760 + * any of the gcc libraries
82761 + *
82762 + * gcc plugin to colorize diagnostic output
82763 + *
82764 + */
82765 +
82766 +#include "gcc-plugin.h"
82767 +#include "config.h"
82768 +#include "system.h"
82769 +#include "coretypes.h"
82770 +#include "tree.h"
82771 +#include "tree-pass.h"
82772 +#include "flags.h"
82773 +#include "intl.h"
82774 +#include "toplev.h"
82775 +#include "plugin.h"
82776 +#include "diagnostic.h"
82777 +#include "plugin-version.h"
82778 +#include "tm.h"
82779 +
82780 +int plugin_is_GPL_compatible;
82781 +
82782 +static struct plugin_info colorize_plugin_info = {
82783 + .version = "201203092200",
82784 + .help = NULL,
82785 +};
82786 +
82787 +#define GREEN "\033[32m\033[2m"
82788 +#define LIGHTGREEN "\033[32m\033[1m"
82789 +#define YELLOW "\033[33m\033[2m"
82790 +#define LIGHTYELLOW "\033[33m\033[1m"
82791 +#define RED "\033[31m\033[2m"
82792 +#define LIGHTRED "\033[31m\033[1m"
82793 +#define BLUE "\033[34m\033[2m"
82794 +#define LIGHTBLUE "\033[34m\033[1m"
82795 +#define BRIGHT "\033[m\033[1m"
82796 +#define NORMAL "\033[m"
82797 +
82798 +static diagnostic_starter_fn old_starter;
82799 +static diagnostic_finalizer_fn old_finalizer;
82800 +
82801 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82802 +{
82803 + const char *color;
82804 + char *newprefix;
82805 +
82806 + switch (diagnostic->kind) {
82807 + case DK_NOTE:
82808 + color = LIGHTBLUE;
82809 + break;
82810 +
82811 + case DK_PEDWARN:
82812 + case DK_WARNING:
82813 + color = LIGHTYELLOW;
82814 + break;
82815 +
82816 + case DK_ERROR:
82817 + case DK_FATAL:
82818 + case DK_ICE:
82819 + case DK_PERMERROR:
82820 + case DK_SORRY:
82821 + color = LIGHTRED;
82822 + break;
82823 +
82824 + default:
82825 + color = NORMAL;
82826 + }
82827 +
82828 + old_starter(context, diagnostic);
82829 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82830 + return;
82831 + pp_destroy_prefix(context->printer);
82832 + pp_set_prefix(context->printer, newprefix);
82833 +}
82834 +
82835 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82836 +{
82837 + old_finalizer(context, diagnostic);
82838 +}
82839 +
82840 +static void colorize_arm(void)
82841 +{
82842 + old_starter = diagnostic_starter(global_dc);
82843 + old_finalizer = diagnostic_finalizer(global_dc);
82844 +
82845 + diagnostic_starter(global_dc) = start_colorize;
82846 + diagnostic_finalizer(global_dc) = finalize_colorize;
82847 +}
82848 +
82849 +static unsigned int execute_colorize_rearm(void)
82850 +{
82851 + if (diagnostic_starter(global_dc) == start_colorize)
82852 + return 0;
82853 +
82854 + colorize_arm();
82855 + return 0;
82856 +}
82857 +
82858 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82859 + .pass = {
82860 + .type = SIMPLE_IPA_PASS,
82861 + .name = "colorize_rearm",
82862 + .gate = NULL,
82863 + .execute = execute_colorize_rearm,
82864 + .sub = NULL,
82865 + .next = NULL,
82866 + .static_pass_number = 0,
82867 + .tv_id = TV_NONE,
82868 + .properties_required = 0,
82869 + .properties_provided = 0,
82870 + .properties_destroyed = 0,
82871 + .todo_flags_start = 0,
82872 + .todo_flags_finish = 0
82873 + }
82874 +};
82875 +
82876 +static void colorize_start_unit(void *gcc_data, void *user_data)
82877 +{
82878 + colorize_arm();
82879 +}
82880 +
82881 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82882 +{
82883 + const char * const plugin_name = plugin_info->base_name;
82884 + struct register_pass_info colorize_rearm_pass_info = {
82885 + .pass = &pass_ipa_colorize_rearm.pass,
82886 + .reference_pass_name = "*free_lang_data",
82887 + .ref_pass_instance_number = 1,
82888 + .pos_op = PASS_POS_INSERT_AFTER
82889 + };
82890 +
82891 + if (!plugin_default_version_check(version, &gcc_version)) {
82892 + error(G_("incompatible gcc/plugin versions"));
82893 + return 1;
82894 + }
82895 +
82896 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82897 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82898 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82899 + return 0;
82900 +}
82901 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82902 new file mode 100644
82903 index 0000000..92ed719
82904 --- /dev/null
82905 +++ b/tools/gcc/constify_plugin.c
82906 @@ -0,0 +1,331 @@
82907 +/*
82908 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82909 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82910 + * Licensed under the GPL v2, or (at your option) v3
82911 + *
82912 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82913 + *
82914 + * Homepage:
82915 + * http://www.grsecurity.net/~ephox/const_plugin/
82916 + *
82917 + * Usage:
82918 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82919 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82920 + */
82921 +
82922 +#include "gcc-plugin.h"
82923 +#include "config.h"
82924 +#include "system.h"
82925 +#include "coretypes.h"
82926 +#include "tree.h"
82927 +#include "tree-pass.h"
82928 +#include "flags.h"
82929 +#include "intl.h"
82930 +#include "toplev.h"
82931 +#include "plugin.h"
82932 +#include "diagnostic.h"
82933 +#include "plugin-version.h"
82934 +#include "tm.h"
82935 +#include "function.h"
82936 +#include "basic-block.h"
82937 +#include "gimple.h"
82938 +#include "rtl.h"
82939 +#include "emit-rtl.h"
82940 +#include "tree-flow.h"
82941 +
82942 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82943 +
82944 +int plugin_is_GPL_compatible;
82945 +
82946 +static struct plugin_info const_plugin_info = {
82947 + .version = "201205300030",
82948 + .help = "no-constify\tturn off constification\n",
82949 +};
82950 +
82951 +static void deconstify_tree(tree node);
82952 +
82953 +static void deconstify_type(tree type)
82954 +{
82955 + tree field;
82956 +
82957 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82958 + tree type = TREE_TYPE(field);
82959 +
82960 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82961 + continue;
82962 + if (!TYPE_READONLY(type))
82963 + continue;
82964 +
82965 + deconstify_tree(field);
82966 + }
82967 + TYPE_READONLY(type) = 0;
82968 + C_TYPE_FIELDS_READONLY(type) = 0;
82969 +}
82970 +
82971 +static void deconstify_tree(tree node)
82972 +{
82973 + tree old_type, new_type, field;
82974 +
82975 + old_type = TREE_TYPE(node);
82976 +
82977 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82978 +
82979 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82980 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82981 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82982 + DECL_FIELD_CONTEXT(field) = new_type;
82983 +
82984 + deconstify_type(new_type);
82985 +
82986 + TREE_READONLY(node) = 0;
82987 + TREE_TYPE(node) = new_type;
82988 +}
82989 +
82990 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82991 +{
82992 + tree type;
82993 +
82994 + *no_add_attrs = true;
82995 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82996 + error("%qE attribute does not apply to functions", name);
82997 + return NULL_TREE;
82998 + }
82999 +
83000 + if (TREE_CODE(*node) == VAR_DECL) {
83001 + error("%qE attribute does not apply to variables", name);
83002 + return NULL_TREE;
83003 + }
83004 +
83005 + if (TYPE_P(*node)) {
83006 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
83007 + *no_add_attrs = false;
83008 + else
83009 + error("%qE attribute applies to struct and union types only", name);
83010 + return NULL_TREE;
83011 + }
83012 +
83013 + type = TREE_TYPE(*node);
83014 +
83015 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
83016 + error("%qE attribute applies to struct and union types only", name);
83017 + return NULL_TREE;
83018 + }
83019 +
83020 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
83021 + error("%qE attribute is already applied to the type", name);
83022 + return NULL_TREE;
83023 + }
83024 +
83025 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
83026 + error("%qE attribute used on type that is not constified", name);
83027 + return NULL_TREE;
83028 + }
83029 +
83030 + if (TREE_CODE(*node) == TYPE_DECL) {
83031 + deconstify_tree(*node);
83032 + return NULL_TREE;
83033 + }
83034 +
83035 + return NULL_TREE;
83036 +}
83037 +
83038 +static void constify_type(tree type)
83039 +{
83040 + TYPE_READONLY(type) = 1;
83041 + C_TYPE_FIELDS_READONLY(type) = 1;
83042 +}
83043 +
83044 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83045 +{
83046 + *no_add_attrs = true;
83047 + if (!TYPE_P(*node)) {
83048 + error("%qE attribute applies to types only", name);
83049 + return NULL_TREE;
83050 + }
83051 +
83052 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
83053 + error("%qE attribute applies to struct and union types only", name);
83054 + return NULL_TREE;
83055 + }
83056 +
83057 + *no_add_attrs = false;
83058 + constify_type(*node);
83059 + return NULL_TREE;
83060 +}
83061 +
83062 +static struct attribute_spec no_const_attr = {
83063 + .name = "no_const",
83064 + .min_length = 0,
83065 + .max_length = 0,
83066 + .decl_required = false,
83067 + .type_required = false,
83068 + .function_type_required = false,
83069 + .handler = handle_no_const_attribute,
83070 +#if BUILDING_GCC_VERSION >= 4007
83071 + .affects_type_identity = true
83072 +#endif
83073 +};
83074 +
83075 +static struct attribute_spec do_const_attr = {
83076 + .name = "do_const",
83077 + .min_length = 0,
83078 + .max_length = 0,
83079 + .decl_required = false,
83080 + .type_required = false,
83081 + .function_type_required = false,
83082 + .handler = handle_do_const_attribute,
83083 +#if BUILDING_GCC_VERSION >= 4007
83084 + .affects_type_identity = true
83085 +#endif
83086 +};
83087 +
83088 +static void register_attributes(void *event_data, void *data)
83089 +{
83090 + register_attribute(&no_const_attr);
83091 + register_attribute(&do_const_attr);
83092 +}
83093 +
83094 +static bool is_fptr(tree field)
83095 +{
83096 + tree ptr = TREE_TYPE(field);
83097 +
83098 + if (TREE_CODE(ptr) != POINTER_TYPE)
83099 + return false;
83100 +
83101 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
83102 +}
83103 +
83104 +static bool walk_struct(tree node)
83105 +{
83106 + tree field;
83107 +
83108 + if (TYPE_FIELDS(node) == NULL_TREE)
83109 + return false;
83110 +
83111 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
83112 + gcc_assert(!TYPE_READONLY(node));
83113 + deconstify_type(node);
83114 + return false;
83115 + }
83116 +
83117 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
83118 + tree type = TREE_TYPE(field);
83119 + enum tree_code code = TREE_CODE(type);
83120 +
83121 + if (node == type)
83122 + return false;
83123 + if (code == RECORD_TYPE || code == UNION_TYPE) {
83124 + if (!(walk_struct(type)))
83125 + return false;
83126 + } else if (!is_fptr(field) && !TREE_READONLY(field))
83127 + return false;
83128 + }
83129 + return true;
83130 +}
83131 +
83132 +static void finish_type(void *event_data, void *data)
83133 +{
83134 + tree type = (tree)event_data;
83135 +
83136 + if (type == NULL_TREE || type == error_mark_node)
83137 + return;
83138 +
83139 + if (TYPE_READONLY(type))
83140 + return;
83141 +
83142 + if (walk_struct(type))
83143 + constify_type(type);
83144 +}
83145 +
83146 +static unsigned int check_local_variables(void);
83147 +
83148 +struct gimple_opt_pass pass_local_variable = {
83149 + {
83150 + .type = GIMPLE_PASS,
83151 + .name = "check_local_variables",
83152 + .gate = NULL,
83153 + .execute = check_local_variables,
83154 + .sub = NULL,
83155 + .next = NULL,
83156 + .static_pass_number = 0,
83157 + .tv_id = TV_NONE,
83158 + .properties_required = 0,
83159 + .properties_provided = 0,
83160 + .properties_destroyed = 0,
83161 + .todo_flags_start = 0,
83162 + .todo_flags_finish = 0
83163 + }
83164 +};
83165 +
83166 +static unsigned int check_local_variables(void)
83167 +{
83168 + tree var;
83169 + referenced_var_iterator rvi;
83170 +
83171 +#if BUILDING_GCC_VERSION == 4005
83172 + FOR_EACH_REFERENCED_VAR(var, rvi) {
83173 +#else
83174 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
83175 +#endif
83176 + tree type = TREE_TYPE(var);
83177 +
83178 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
83179 + continue;
83180 +
83181 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
83182 + continue;
83183 +
83184 + if (!TYPE_READONLY(type))
83185 + continue;
83186 +
83187 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
83188 +// continue;
83189 +
83190 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
83191 +// continue;
83192 +
83193 + if (walk_struct(type)) {
83194 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
83195 + return 1;
83196 + }
83197 + }
83198 + return 0;
83199 +}
83200 +
83201 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83202 +{
83203 + const char * const plugin_name = plugin_info->base_name;
83204 + const int argc = plugin_info->argc;
83205 + const struct plugin_argument * const argv = plugin_info->argv;
83206 + int i;
83207 + bool constify = true;
83208 +
83209 + struct register_pass_info local_variable_pass_info = {
83210 + .pass = &pass_local_variable.pass,
83211 + .reference_pass_name = "*referenced_vars",
83212 + .ref_pass_instance_number = 1,
83213 + .pos_op = PASS_POS_INSERT_AFTER
83214 + };
83215 +
83216 + if (!plugin_default_version_check(version, &gcc_version)) {
83217 + error(G_("incompatible gcc/plugin versions"));
83218 + return 1;
83219 + }
83220 +
83221 + for (i = 0; i < argc; ++i) {
83222 + if (!(strcmp(argv[i].key, "no-constify"))) {
83223 + constify = false;
83224 + continue;
83225 + }
83226 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83227 + }
83228 +
83229 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83230 + if (constify) {
83231 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83232 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83233 + }
83234 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83235 +
83236 + return 0;
83237 +}
83238 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83239 new file mode 100644
83240 index 0000000..e518932
83241 --- /dev/null
83242 +++ b/tools/gcc/generate_size_overflow_hash.sh
83243 @@ -0,0 +1,94 @@
83244 +#!/bin/bash
83245 +
83246 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83247 +
83248 +header1="size_overflow_hash.h"
83249 +database="size_overflow_hash.data"
83250 +n=65536
83251 +
83252 +usage() {
83253 +cat <<EOF
83254 +usage: $0 options
83255 +OPTIONS:
83256 + -h|--help help
83257 + -o header file
83258 + -d database file
83259 + -n hash array size
83260 +EOF
83261 + return 0
83262 +}
83263 +
83264 +while true
83265 +do
83266 + case "$1" in
83267 + -h|--help) usage && exit 0;;
83268 + -n) n=$2; shift 2;;
83269 + -o) header1="$2"; shift 2;;
83270 + -d) database="$2"; shift 2;;
83271 + --) shift 1; break ;;
83272 + *) break ;;
83273 + esac
83274 +done
83275 +
83276 +create_defines() {
83277 + for i in `seq 0 31`
83278 + do
83279 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83280 + done
83281 + echo >> "$header1"
83282 +}
83283 +
83284 +create_structs() {
83285 + rm -f "$header1"
83286 +
83287 + create_defines
83288 +
83289 + cat "$database" | while read data
83290 + do
83291 + data_array=($data)
83292 + struct_hash_name="${data_array[0]}"
83293 + funcn="${data_array[1]}"
83294 + params="${data_array[2]}"
83295 + next="${data_array[4]}"
83296 +
83297 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83298 +
83299 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83300 + echo -en "\t.param\t= " >> "$header1"
83301 + line=
83302 + for param_num in ${params//-/ };
83303 + do
83304 + line="${line}PARAM"$param_num"|"
83305 + done
83306 +
83307 + echo -e "${line%?},\n};\n" >> "$header1"
83308 + done
83309 +}
83310 +
83311 +create_headers() {
83312 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83313 +}
83314 +
83315 +create_array_elements() {
83316 + index=0
83317 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83318 + do
83319 + data_array=($data)
83320 + i="${data_array[3]}"
83321 + hash="${data_array[0]}"
83322 + while [[ $index -lt $i ]]
83323 + do
83324 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83325 + index=$(($index + 1))
83326 + done
83327 + index=$(($index + 1))
83328 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83329 + done
83330 + echo '};' >> $header1
83331 +}
83332 +
83333 +create_structs
83334 +create_headers
83335 +create_array_elements
83336 +
83337 +exit 0
83338 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83339 new file mode 100644
83340 index 0000000..a86e422
83341 --- /dev/null
83342 +++ b/tools/gcc/kallocstat_plugin.c
83343 @@ -0,0 +1,167 @@
83344 +/*
83345 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83346 + * Licensed under the GPL v2
83347 + *
83348 + * Note: the choice of the license means that the compilation process is
83349 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83350 + * but for the kernel it doesn't matter since it doesn't link against
83351 + * any of the gcc libraries
83352 + *
83353 + * gcc plugin to find the distribution of k*alloc sizes
83354 + *
83355 + * TODO:
83356 + *
83357 + * BUGS:
83358 + * - none known
83359 + */
83360 +#include "gcc-plugin.h"
83361 +#include "config.h"
83362 +#include "system.h"
83363 +#include "coretypes.h"
83364 +#include "tree.h"
83365 +#include "tree-pass.h"
83366 +#include "flags.h"
83367 +#include "intl.h"
83368 +#include "toplev.h"
83369 +#include "plugin.h"
83370 +//#include "expr.h" where are you...
83371 +#include "diagnostic.h"
83372 +#include "plugin-version.h"
83373 +#include "tm.h"
83374 +#include "function.h"
83375 +#include "basic-block.h"
83376 +#include "gimple.h"
83377 +#include "rtl.h"
83378 +#include "emit-rtl.h"
83379 +
83380 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83381 +
83382 +int plugin_is_GPL_compatible;
83383 +
83384 +static const char * const kalloc_functions[] = {
83385 + "__kmalloc",
83386 + "kmalloc",
83387 + "kmalloc_large",
83388 + "kmalloc_node",
83389 + "kmalloc_order",
83390 + "kmalloc_order_trace",
83391 + "kmalloc_slab",
83392 + "kzalloc",
83393 + "kzalloc_node",
83394 +};
83395 +
83396 +static struct plugin_info kallocstat_plugin_info = {
83397 + .version = "201111150100",
83398 +};
83399 +
83400 +static unsigned int execute_kallocstat(void);
83401 +
83402 +static struct gimple_opt_pass kallocstat_pass = {
83403 + .pass = {
83404 + .type = GIMPLE_PASS,
83405 + .name = "kallocstat",
83406 + .gate = NULL,
83407 + .execute = execute_kallocstat,
83408 + .sub = NULL,
83409 + .next = NULL,
83410 + .static_pass_number = 0,
83411 + .tv_id = TV_NONE,
83412 + .properties_required = 0,
83413 + .properties_provided = 0,
83414 + .properties_destroyed = 0,
83415 + .todo_flags_start = 0,
83416 + .todo_flags_finish = 0
83417 + }
83418 +};
83419 +
83420 +static bool is_kalloc(const char *fnname)
83421 +{
83422 + size_t i;
83423 +
83424 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83425 + if (!strcmp(fnname, kalloc_functions[i]))
83426 + return true;
83427 + return false;
83428 +}
83429 +
83430 +static unsigned int execute_kallocstat(void)
83431 +{
83432 + basic_block bb;
83433 +
83434 + // 1. loop through BBs and GIMPLE statements
83435 + FOR_EACH_BB(bb) {
83436 + gimple_stmt_iterator gsi;
83437 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83438 + // gimple match:
83439 + tree fndecl, size;
83440 + gimple call_stmt;
83441 + const char *fnname;
83442 +
83443 + // is it a call
83444 + call_stmt = gsi_stmt(gsi);
83445 + if (!is_gimple_call(call_stmt))
83446 + continue;
83447 + fndecl = gimple_call_fndecl(call_stmt);
83448 + if (fndecl == NULL_TREE)
83449 + continue;
83450 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83451 + continue;
83452 +
83453 + // is it a call to k*alloc
83454 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83455 + if (!is_kalloc(fnname))
83456 + continue;
83457 +
83458 + // is the size arg the result of a simple const assignment
83459 + size = gimple_call_arg(call_stmt, 0);
83460 + while (true) {
83461 + gimple def_stmt;
83462 + expanded_location xloc;
83463 + size_t size_val;
83464 +
83465 + if (TREE_CODE(size) != SSA_NAME)
83466 + break;
83467 + def_stmt = SSA_NAME_DEF_STMT(size);
83468 + if (!def_stmt || !is_gimple_assign(def_stmt))
83469 + break;
83470 + if (gimple_num_ops(def_stmt) != 2)
83471 + break;
83472 + size = gimple_assign_rhs1(def_stmt);
83473 + if (!TREE_CONSTANT(size))
83474 + continue;
83475 + xloc = expand_location(gimple_location(def_stmt));
83476 + if (!xloc.file)
83477 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83478 + size_val = TREE_INT_CST_LOW(size);
83479 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83480 + break;
83481 + }
83482 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83483 +//debug_tree(gimple_call_fn(call_stmt));
83484 +//print_node(stderr, "pax", fndecl, 4);
83485 + }
83486 + }
83487 +
83488 + return 0;
83489 +}
83490 +
83491 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83492 +{
83493 + const char * const plugin_name = plugin_info->base_name;
83494 + struct register_pass_info kallocstat_pass_info = {
83495 + .pass = &kallocstat_pass.pass,
83496 + .reference_pass_name = "ssa",
83497 + .ref_pass_instance_number = 1,
83498 + .pos_op = PASS_POS_INSERT_AFTER
83499 + };
83500 +
83501 + if (!plugin_default_version_check(version, &gcc_version)) {
83502 + error(G_("incompatible gcc/plugin versions"));
83503 + return 1;
83504 + }
83505 +
83506 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83507 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83508 +
83509 + return 0;
83510 +}
83511 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83512 new file mode 100644
83513 index 0000000..8856202
83514 --- /dev/null
83515 +++ b/tools/gcc/kernexec_plugin.c
83516 @@ -0,0 +1,432 @@
83517 +/*
83518 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83519 + * Licensed under the GPL v2
83520 + *
83521 + * Note: the choice of the license means that the compilation process is
83522 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83523 + * but for the kernel it doesn't matter since it doesn't link against
83524 + * any of the gcc libraries
83525 + *
83526 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83527 + *
83528 + * TODO:
83529 + *
83530 + * BUGS:
83531 + * - none known
83532 + */
83533 +#include "gcc-plugin.h"
83534 +#include "config.h"
83535 +#include "system.h"
83536 +#include "coretypes.h"
83537 +#include "tree.h"
83538 +#include "tree-pass.h"
83539 +#include "flags.h"
83540 +#include "intl.h"
83541 +#include "toplev.h"
83542 +#include "plugin.h"
83543 +//#include "expr.h" where are you...
83544 +#include "diagnostic.h"
83545 +#include "plugin-version.h"
83546 +#include "tm.h"
83547 +#include "function.h"
83548 +#include "basic-block.h"
83549 +#include "gimple.h"
83550 +#include "rtl.h"
83551 +#include "emit-rtl.h"
83552 +#include "tree-flow.h"
83553 +
83554 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83555 +extern rtx emit_move_insn(rtx x, rtx y);
83556 +
83557 +#if BUILDING_GCC_VERSION <= 4006
83558 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
83559 +#endif
83560 +
83561 +int plugin_is_GPL_compatible;
83562 +
83563 +static struct plugin_info kernexec_plugin_info = {
83564 + .version = "201111291120",
83565 + .help = "method=[bts|or]\tinstrumentation method\n"
83566 +};
83567 +
83568 +static unsigned int execute_kernexec_reload(void);
83569 +static unsigned int execute_kernexec_fptr(void);
83570 +static unsigned int execute_kernexec_retaddr(void);
83571 +static bool kernexec_cmodel_check(void);
83572 +
83573 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83574 +static void (*kernexec_instrument_retaddr)(rtx);
83575 +
83576 +static struct gimple_opt_pass kernexec_reload_pass = {
83577 + .pass = {
83578 + .type = GIMPLE_PASS,
83579 + .name = "kernexec_reload",
83580 + .gate = kernexec_cmodel_check,
83581 + .execute = execute_kernexec_reload,
83582 + .sub = NULL,
83583 + .next = NULL,
83584 + .static_pass_number = 0,
83585 + .tv_id = TV_NONE,
83586 + .properties_required = 0,
83587 + .properties_provided = 0,
83588 + .properties_destroyed = 0,
83589 + .todo_flags_start = 0,
83590 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83591 + }
83592 +};
83593 +
83594 +static struct gimple_opt_pass kernexec_fptr_pass = {
83595 + .pass = {
83596 + .type = GIMPLE_PASS,
83597 + .name = "kernexec_fptr",
83598 + .gate = kernexec_cmodel_check,
83599 + .execute = execute_kernexec_fptr,
83600 + .sub = NULL,
83601 + .next = NULL,
83602 + .static_pass_number = 0,
83603 + .tv_id = TV_NONE,
83604 + .properties_required = 0,
83605 + .properties_provided = 0,
83606 + .properties_destroyed = 0,
83607 + .todo_flags_start = 0,
83608 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83609 + }
83610 +};
83611 +
83612 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83613 + .pass = {
83614 + .type = RTL_PASS,
83615 + .name = "kernexec_retaddr",
83616 + .gate = kernexec_cmodel_check,
83617 + .execute = execute_kernexec_retaddr,
83618 + .sub = NULL,
83619 + .next = NULL,
83620 + .static_pass_number = 0,
83621 + .tv_id = TV_NONE,
83622 + .properties_required = 0,
83623 + .properties_provided = 0,
83624 + .properties_destroyed = 0,
83625 + .todo_flags_start = 0,
83626 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83627 + }
83628 +};
83629 +
83630 +static bool kernexec_cmodel_check(void)
83631 +{
83632 + tree section;
83633 +
83634 + if (ix86_cmodel != CM_KERNEL)
83635 + return false;
83636 +
83637 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83638 + if (!section || !TREE_VALUE(section))
83639 + return true;
83640 +
83641 + section = TREE_VALUE(TREE_VALUE(section));
83642 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83643 + return true;
83644 +
83645 + return false;
83646 +}
83647 +
83648 +/*
83649 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83650 + */
83651 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83652 +{
83653 + gimple asm_movabs_stmt;
83654 +
83655 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83656 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83657 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83658 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83659 + update_stmt(asm_movabs_stmt);
83660 +}
83661 +
83662 +/*
83663 + * find all asm() stmts that clobber r10 and add a reload of r10
83664 + */
83665 +static unsigned int execute_kernexec_reload(void)
83666 +{
83667 + basic_block bb;
83668 +
83669 + // 1. loop through BBs and GIMPLE statements
83670 + FOR_EACH_BB(bb) {
83671 + gimple_stmt_iterator gsi;
83672 +
83673 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83674 + // gimple match: __asm__ ("" : : : "r10");
83675 + gimple asm_stmt;
83676 + size_t nclobbers;
83677 +
83678 + // is it an asm ...
83679 + asm_stmt = gsi_stmt(gsi);
83680 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83681 + continue;
83682 +
83683 + // ... clobbering r10
83684 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83685 + while (nclobbers--) {
83686 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83687 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83688 + continue;
83689 + kernexec_reload_fptr_mask(&gsi);
83690 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83691 + break;
83692 + }
83693 + }
83694 + }
83695 +
83696 + return 0;
83697 +}
83698 +
83699 +/*
83700 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83701 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83702 + */
83703 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83704 +{
83705 + gimple assign_intptr, assign_new_fptr, call_stmt;
83706 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83707 +
83708 + call_stmt = gsi_stmt(*gsi);
83709 + old_fptr = gimple_call_fn(call_stmt);
83710 +
83711 + // create temporary unsigned long variable used for bitops and cast fptr to it
83712 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83713 + add_referenced_var(intptr);
83714 + mark_sym_for_renaming(intptr);
83715 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83716 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83717 + update_stmt(assign_intptr);
83718 +
83719 + // apply logical or to temporary unsigned long and bitmask
83720 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83721 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83722 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83723 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83724 + update_stmt(assign_intptr);
83725 +
83726 + // cast temporary unsigned long back to a temporary fptr variable
83727 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83728 + add_referenced_var(new_fptr);
83729 + mark_sym_for_renaming(new_fptr);
83730 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83731 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83732 + update_stmt(assign_new_fptr);
83733 +
83734 + // replace call stmt fn with the new fptr
83735 + gimple_call_set_fn(call_stmt, new_fptr);
83736 + update_stmt(call_stmt);
83737 +}
83738 +
83739 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83740 +{
83741 + gimple asm_or_stmt, call_stmt;
83742 + tree old_fptr, new_fptr, input, output;
83743 + VEC(tree, gc) *inputs = NULL;
83744 + VEC(tree, gc) *outputs = NULL;
83745 +
83746 + call_stmt = gsi_stmt(*gsi);
83747 + old_fptr = gimple_call_fn(call_stmt);
83748 +
83749 + // create temporary fptr variable
83750 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83751 + add_referenced_var(new_fptr);
83752 + mark_sym_for_renaming(new_fptr);
83753 +
83754 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83755 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83756 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83757 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83758 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83759 + VEC_safe_push(tree, gc, inputs, input);
83760 + VEC_safe_push(tree, gc, outputs, output);
83761 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83762 + gimple_asm_set_volatile(asm_or_stmt, true);
83763 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83764 + update_stmt(asm_or_stmt);
83765 +
83766 + // replace call stmt fn with the new fptr
83767 + gimple_call_set_fn(call_stmt, new_fptr);
83768 + update_stmt(call_stmt);
83769 +}
83770 +
83771 +/*
83772 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83773 + */
83774 +static unsigned int execute_kernexec_fptr(void)
83775 +{
83776 + basic_block bb;
83777 +
83778 + // 1. loop through BBs and GIMPLE statements
83779 + FOR_EACH_BB(bb) {
83780 + gimple_stmt_iterator gsi;
83781 +
83782 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83783 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83784 + tree fn;
83785 + gimple call_stmt;
83786 +
83787 + // is it a call ...
83788 + call_stmt = gsi_stmt(gsi);
83789 + if (!is_gimple_call(call_stmt))
83790 + continue;
83791 + fn = gimple_call_fn(call_stmt);
83792 + if (TREE_CODE(fn) == ADDR_EXPR)
83793 + continue;
83794 + if (TREE_CODE(fn) != SSA_NAME)
83795 + gcc_unreachable();
83796 +
83797 + // ... through a function pointer
83798 + fn = SSA_NAME_VAR(fn);
83799 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83800 + continue;
83801 + fn = TREE_TYPE(fn);
83802 + if (TREE_CODE(fn) != POINTER_TYPE)
83803 + continue;
83804 + fn = TREE_TYPE(fn);
83805 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83806 + continue;
83807 +
83808 + kernexec_instrument_fptr(&gsi);
83809 +
83810 +//debug_tree(gimple_call_fn(call_stmt));
83811 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83812 + }
83813 + }
83814 +
83815 + return 0;
83816 +}
83817 +
83818 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83819 +static void kernexec_instrument_retaddr_bts(rtx insn)
83820 +{
83821 + rtx btsq;
83822 + rtvec argvec, constraintvec, labelvec;
83823 + int line;
83824 +
83825 + // create asm volatile("btsq $63,(%%rsp)":::)
83826 + argvec = rtvec_alloc(0);
83827 + constraintvec = rtvec_alloc(0);
83828 + labelvec = rtvec_alloc(0);
83829 + line = expand_location(RTL_LOCATION(insn)).line;
83830 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83831 + MEM_VOLATILE_P(btsq) = 1;
83832 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83833 + emit_insn_before(btsq, insn);
83834 +}
83835 +
83836 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83837 +static void kernexec_instrument_retaddr_or(rtx insn)
83838 +{
83839 + rtx orq;
83840 + rtvec argvec, constraintvec, labelvec;
83841 + int line;
83842 +
83843 + // create asm volatile("orq %%r10,(%%rsp)":::)
83844 + argvec = rtvec_alloc(0);
83845 + constraintvec = rtvec_alloc(0);
83846 + labelvec = rtvec_alloc(0);
83847 + line = expand_location(RTL_LOCATION(insn)).line;
83848 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83849 + MEM_VOLATILE_P(orq) = 1;
83850 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83851 + emit_insn_before(orq, insn);
83852 +}
83853 +
83854 +/*
83855 + * find all asm level function returns and forcibly set the highest bit of the return address
83856 + */
83857 +static unsigned int execute_kernexec_retaddr(void)
83858 +{
83859 + rtx insn;
83860 +
83861 + // 1. find function returns
83862 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83863 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83864 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83865 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
83866 + rtx body;
83867 +
83868 + // is it a retn
83869 + if (!JUMP_P(insn))
83870 + continue;
83871 + body = PATTERN(insn);
83872 + if (GET_CODE(body) == PARALLEL)
83873 + body = XVECEXP(body, 0, 0);
83874 + if (!ANY_RETURN_P(body))
83875 + continue;
83876 + kernexec_instrument_retaddr(insn);
83877 + }
83878 +
83879 +// print_simple_rtl(stderr, get_insns());
83880 +// print_rtl(stderr, get_insns());
83881 +
83882 + return 0;
83883 +}
83884 +
83885 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83886 +{
83887 + const char * const plugin_name = plugin_info->base_name;
83888 + const int argc = plugin_info->argc;
83889 + const struct plugin_argument * const argv = plugin_info->argv;
83890 + int i;
83891 + struct register_pass_info kernexec_reload_pass_info = {
83892 + .pass = &kernexec_reload_pass.pass,
83893 + .reference_pass_name = "ssa",
83894 + .ref_pass_instance_number = 1,
83895 + .pos_op = PASS_POS_INSERT_AFTER
83896 + };
83897 + struct register_pass_info kernexec_fptr_pass_info = {
83898 + .pass = &kernexec_fptr_pass.pass,
83899 + .reference_pass_name = "ssa",
83900 + .ref_pass_instance_number = 1,
83901 + .pos_op = PASS_POS_INSERT_AFTER
83902 + };
83903 + struct register_pass_info kernexec_retaddr_pass_info = {
83904 + .pass = &kernexec_retaddr_pass.pass,
83905 + .reference_pass_name = "pro_and_epilogue",
83906 + .ref_pass_instance_number = 1,
83907 + .pos_op = PASS_POS_INSERT_AFTER
83908 + };
83909 +
83910 + if (!plugin_default_version_check(version, &gcc_version)) {
83911 + error(G_("incompatible gcc/plugin versions"));
83912 + return 1;
83913 + }
83914 +
83915 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83916 +
83917 + if (TARGET_64BIT == 0)
83918 + return 0;
83919 +
83920 + for (i = 0; i < argc; ++i) {
83921 + if (!strcmp(argv[i].key, "method")) {
83922 + if (!argv[i].value) {
83923 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83924 + continue;
83925 + }
83926 + if (!strcmp(argv[i].value, "bts")) {
83927 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83928 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83929 + } else if (!strcmp(argv[i].value, "or")) {
83930 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83931 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83932 + fix_register("r10", 1, 1);
83933 + } else
83934 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83935 + continue;
83936 + }
83937 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83938 + }
83939 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83940 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83941 +
83942 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83943 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83944 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83945 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83946 +
83947 + return 0;
83948 +}
83949 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83950 new file mode 100644
83951 index 0000000..b8008f7
83952 --- /dev/null
83953 +++ b/tools/gcc/latent_entropy_plugin.c
83954 @@ -0,0 +1,295 @@
83955 +/*
83956 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83957 + * Licensed under the GPL v2
83958 + *
83959 + * Note: the choice of the license means that the compilation process is
83960 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83961 + * but for the kernel it doesn't matter since it doesn't link against
83962 + * any of the gcc libraries
83963 + *
83964 + * gcc plugin to help generate a little bit of entropy from program state,
83965 + * used during boot in the kernel
83966 + *
83967 + * TODO:
83968 + * - add ipa pass to identify not explicitly marked candidate functions
83969 + * - mix in more program state (function arguments/return values, loop variables, etc)
83970 + * - more instrumentation control via attribute parameters
83971 + *
83972 + * BUGS:
83973 + * - LTO needs -flto-partition=none for now
83974 + */
83975 +#include "gcc-plugin.h"
83976 +#include "config.h"
83977 +#include "system.h"
83978 +#include "coretypes.h"
83979 +#include "tree.h"
83980 +#include "tree-pass.h"
83981 +#include "flags.h"
83982 +#include "intl.h"
83983 +#include "toplev.h"
83984 +#include "plugin.h"
83985 +//#include "expr.h" where are you...
83986 +#include "diagnostic.h"
83987 +#include "plugin-version.h"
83988 +#include "tm.h"
83989 +#include "function.h"
83990 +#include "basic-block.h"
83991 +#include "gimple.h"
83992 +#include "rtl.h"
83993 +#include "emit-rtl.h"
83994 +#include "tree-flow.h"
83995 +
83996 +int plugin_is_GPL_compatible;
83997 +
83998 +static tree latent_entropy_decl;
83999 +
84000 +static struct plugin_info latent_entropy_plugin_info = {
84001 + .version = "201207271820",
84002 + .help = NULL
84003 +};
84004 +
84005 +static unsigned int execute_latent_entropy(void);
84006 +static bool gate_latent_entropy(void);
84007 +
84008 +static struct gimple_opt_pass latent_entropy_pass = {
84009 + .pass = {
84010 + .type = GIMPLE_PASS,
84011 + .name = "latent_entropy",
84012 + .gate = gate_latent_entropy,
84013 + .execute = execute_latent_entropy,
84014 + .sub = NULL,
84015 + .next = NULL,
84016 + .static_pass_number = 0,
84017 + .tv_id = TV_NONE,
84018 + .properties_required = PROP_gimple_leh | PROP_cfg,
84019 + .properties_provided = 0,
84020 + .properties_destroyed = 0,
84021 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84022 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
84023 + }
84024 +};
84025 +
84026 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
84027 +{
84028 + if (TREE_CODE(*node) != FUNCTION_DECL) {
84029 + *no_add_attrs = true;
84030 + error("%qE attribute only applies to functions", name);
84031 + }
84032 + return NULL_TREE;
84033 +}
84034 +
84035 +static struct attribute_spec latent_entropy_attr = {
84036 + .name = "latent_entropy",
84037 + .min_length = 0,
84038 + .max_length = 0,
84039 + .decl_required = true,
84040 + .type_required = false,
84041 + .function_type_required = false,
84042 + .handler = handle_latent_entropy_attribute,
84043 +#if BUILDING_GCC_VERSION >= 4007
84044 + .affects_type_identity = false
84045 +#endif
84046 +};
84047 +
84048 +static void register_attributes(void *event_data, void *data)
84049 +{
84050 + register_attribute(&latent_entropy_attr);
84051 +}
84052 +
84053 +static bool gate_latent_entropy(void)
84054 +{
84055 + tree latent_entropy_attr;
84056 +
84057 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
84058 + return latent_entropy_attr != NULL_TREE;
84059 +}
84060 +
84061 +static unsigned HOST_WIDE_INT seed;
84062 +static unsigned HOST_WIDE_INT get_random_const(void)
84063 +{
84064 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
84065 + return seed;
84066 +}
84067 +
84068 +static enum tree_code get_op(tree *rhs)
84069 +{
84070 + static enum tree_code op;
84071 + unsigned HOST_WIDE_INT random_const;
84072 +
84073 + random_const = get_random_const();
84074 +
84075 + switch (op) {
84076 + case BIT_XOR_EXPR:
84077 + op = PLUS_EXPR;
84078 + break;
84079 +
84080 + case PLUS_EXPR:
84081 + if (rhs) {
84082 + op = LROTATE_EXPR;
84083 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
84084 + break;
84085 + }
84086 +
84087 + case LROTATE_EXPR:
84088 + default:
84089 + op = BIT_XOR_EXPR;
84090 + break;
84091 + }
84092 + if (rhs)
84093 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
84094 + return op;
84095 +}
84096 +
84097 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
84098 +{
84099 + gimple_stmt_iterator gsi;
84100 + gimple assign;
84101 + tree addxorrol, rhs;
84102 + enum tree_code op;
84103 +
84104 + op = get_op(&rhs);
84105 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
84106 + assign = gimple_build_assign(local_entropy, addxorrol);
84107 + find_referenced_vars_in(assign);
84108 +//debug_bb(bb);
84109 + gsi = gsi_after_labels(bb);
84110 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
84111 + update_stmt(assign);
84112 +}
84113 +
84114 +static void perturb_latent_entropy(basic_block bb, tree rhs)
84115 +{
84116 + gimple_stmt_iterator gsi;
84117 + gimple assign;
84118 + tree addxorrol, temp;
84119 +
84120 + // 1. create temporary copy of latent_entropy
84121 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
84122 + add_referenced_var(temp);
84123 + mark_sym_for_renaming(temp);
84124 +
84125 + // 2. read...
84126 + assign = gimple_build_assign(temp, latent_entropy_decl);
84127 + find_referenced_vars_in(assign);
84128 + gsi = gsi_after_labels(bb);
84129 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84130 + update_stmt(assign);
84131 +
84132 + // 3. ...modify...
84133 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
84134 + assign = gimple_build_assign(temp, addxorrol);
84135 + find_referenced_vars_in(assign);
84136 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84137 + update_stmt(assign);
84138 +
84139 + // 4. ...write latent_entropy
84140 + assign = gimple_build_assign(latent_entropy_decl, temp);
84141 + find_referenced_vars_in(assign);
84142 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84143 + update_stmt(assign);
84144 +}
84145 +
84146 +static unsigned int execute_latent_entropy(void)
84147 +{
84148 + basic_block bb;
84149 + gimple assign;
84150 + gimple_stmt_iterator gsi;
84151 + tree local_entropy;
84152 +
84153 + if (!latent_entropy_decl) {
84154 + struct varpool_node *node;
84155 +
84156 + for (node = varpool_nodes; node; node = node->next) {
84157 + tree var = node->decl;
84158 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
84159 + continue;
84160 + latent_entropy_decl = var;
84161 +// debug_tree(var);
84162 + break;
84163 + }
84164 + if (!latent_entropy_decl) {
84165 +// debug_tree(current_function_decl);
84166 + return 0;
84167 + }
84168 + }
84169 +
84170 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
84171 +
84172 + // 1. create local entropy variable
84173 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
84174 + add_referenced_var(local_entropy);
84175 + mark_sym_for_renaming(local_entropy);
84176 +
84177 + // 2. initialize local entropy variable
84178 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
84179 + if (dom_info_available_p(CDI_DOMINATORS))
84180 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
84181 + gsi = gsi_start_bb(bb);
84182 +
84183 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
84184 +// gimple_set_location(assign, loc);
84185 + find_referenced_vars_in(assign);
84186 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
84187 + update_stmt(assign);
84188 + bb = bb->next_bb;
84189 +
84190 + // 3. instrument each BB with an operation on the local entropy variable
84191 + while (bb != EXIT_BLOCK_PTR) {
84192 + perturb_local_entropy(bb, local_entropy);
84193 + bb = bb->next_bb;
84194 + };
84195 +
84196 + // 4. mix local entropy into the global entropy variable
84197 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
84198 + return 0;
84199 +}
84200 +
84201 +static void start_unit_callback(void *gcc_data, void *user_data)
84202 +{
84203 +#if BUILDING_GCC_VERSION >= 4007
84204 + seed = get_random_seed(false);
84205 +#else
84206 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
84207 + seed *= seed;
84208 +#endif
84209 +
84210 + if (in_lto_p)
84211 + return;
84212 +
84213 + // extern u64 latent_entropy
84214 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
84215 +
84216 + TREE_STATIC(latent_entropy_decl) = 1;
84217 + TREE_PUBLIC(latent_entropy_decl) = 1;
84218 + TREE_USED(latent_entropy_decl) = 1;
84219 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84220 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84221 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84222 + DECL_INITIAL(latent_entropy_decl) = NULL;
84223 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84224 +// varpool_finalize_decl(latent_entropy_decl);
84225 +// varpool_mark_needed_node(latent_entropy_decl);
84226 +}
84227 +
84228 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84229 +{
84230 + const char * const plugin_name = plugin_info->base_name;
84231 + struct register_pass_info latent_entropy_pass_info = {
84232 + .pass = &latent_entropy_pass.pass,
84233 + .reference_pass_name = "optimized",
84234 + .ref_pass_instance_number = 1,
84235 + .pos_op = PASS_POS_INSERT_BEFORE
84236 + };
84237 +
84238 + if (!plugin_default_version_check(version, &gcc_version)) {
84239 + error(G_("incompatible gcc/plugin versions"));
84240 + return 1;
84241 + }
84242 +
84243 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84244 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84245 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84246 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84247 +
84248 + return 0;
84249 +}
84250 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84251 new file mode 100644
84252 index 0000000..afebc99
84253 --- /dev/null
84254 +++ b/tools/gcc/size_overflow_hash.data
84255 @@ -0,0 +1,3709 @@
84256 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
84257 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
84258 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
84259 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
84260 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
84261 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
84262 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
84263 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
84264 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
84265 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
84266 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
84267 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
84268 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
84269 +create_log_8225 create_log 2 8225 NULL
84270 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
84271 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
84272 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
84273 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
84274 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
84275 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
84276 +padzero_55 padzero 1 55 &sel_read_policyvers_55
84277 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
84278 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
84279 +read_file_blob_57406 read_file_blob 3 57406 NULL
84280 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
84281 +enclosure_register_57412 enclosure_register 3 57412 NULL
84282 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
84283 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
84284 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
84285 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
84286 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
84287 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
84288 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
84289 +init_cdev_8274 init_cdev 1 8274 NULL
84290 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
84291 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
84292 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
84293 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
84294 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
84295 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
84296 +load_msg_95 load_msg 2 95 NULL
84297 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
84298 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
84299 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
84300 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
84301 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
84302 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
84303 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
84304 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
84305 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
84306 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
84307 +send_midi_async_57463 send_midi_async 3 57463 NULL
84308 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
84309 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
84310 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
84311 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
84312 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
84313 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
84314 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
84315 +init_q_132 init_q 4 132 NULL
84316 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
84317 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
84318 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
84319 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
84320 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
84321 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
84322 +uio_read_49300 uio_read 3 49300 NULL
84323 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
84324 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
84325 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
84326 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
84327 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
84328 +play_iframe_8219 play_iframe 3 8219 NULL
84329 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
84330 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
84331 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
84332 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
84333 +init_tag_map_57515 init_tag_map 3 57515 NULL
84334 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
84335 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
84336 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
84337 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
84338 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
84339 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
84340 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
84341 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
84342 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
84343 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
84344 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
84345 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
84346 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
84347 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
84348 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
84349 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
84350 +cache_read_24790 cache_read 3 24790 NULL
84351 +px_raw_event_49371 px_raw_event 4 49371 NULL
84352 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
84353 +compat_filldir_32999 compat_filldir 3 32999 NULL
84354 +hci_si_event_1404 hci_si_event 3 1404 NULL
84355 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
84356 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
84357 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
84358 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
84359 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
84360 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
84361 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
84362 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
84363 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
84364 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
84365 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
84366 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
84367 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
84368 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
84369 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
84370 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
84371 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
84372 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
84373 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
84374 +mem_read_57631 mem_read 3 57631 NULL
84375 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
84376 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
84377 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
84378 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
84379 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
84380 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
84381 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
84382 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
84383 +queues_read_24877 queues_read 3 24877 NULL
84384 +__fprog_create_41263 __fprog_create 2 41263 NULL
84385 +syslog_print_307 syslog_print 2 307 NULL
84386 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
84387 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
84388 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
84389 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
84390 +r3964_write_57662 r3964_write 4 57662 NULL
84391 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
84392 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
84393 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
84394 +alloc_context_41283 alloc_context 1 41283 NULL
84395 +__lgwrite_57669 __lgwrite 4 57669 NULL
84396 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
84397 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
84398 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
84399 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
84400 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
84401 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
84402 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
84403 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
84404 +write_node_33121 write_node 4 33121 NULL
84405 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
84406 +profile_remove_8556 profile_remove 3 8556 NULL
84407 +evm_read_key_54674 evm_read_key 3 54674 NULL
84408 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
84409 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
84410 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
84411 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
84412 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
84413 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
84414 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
84415 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
84416 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
84417 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
84418 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
84419 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
84420 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
84421 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
84422 +smk_write_access_49561 smk_write_access 3 49561 NULL
84423 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
84424 +kmp_init_41373 kmp_init 2 41373 NULL
84425 +context_alloc_24645 context_alloc 3 24645 NULL
84426 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
84427 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
84428 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
84429 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
84430 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
84431 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
84432 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
84433 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
84434 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
84435 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
84436 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
84437 +pp_read_33210 pp_read 3 33210 NULL
84438 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
84439 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
84440 +ivtv_read_57796 ivtv_read 3 57796 NULL
84441 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
84442 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
84443 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
84444 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
84445 +heap_init_49617 heap_init 2 49617 NULL
84446 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
84447 +aoechr_write_62883 aoechr_write 3 62883 NULL nohasharray
84448 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 &aoechr_write_62883
84449 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
84450 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
84451 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
84452 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
84453 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
84454 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
84455 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
84456 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
84457 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
84458 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
84459 +st_write_16874 st_write 3 16874 NULL
84460 +copy_to_user_57835 copy_to_user 3 57835 NULL
84461 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
84462 +pidlist_resize_496 pidlist_resize 2 496 NULL
84463 +flash_read_57843 flash_read 3 57843 NULL
84464 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
84465 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
84466 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
84467 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
84468 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
84469 +arcfb_write_8702 arcfb_write 3 8702 NULL
84470 +send_to_tty_45141 send_to_tty 3 45141 NULL
84471 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
84472 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
84473 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
84474 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
84475 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
84476 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
84477 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
84478 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
84479 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
84480 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
84481 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
84482 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
84483 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
84484 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
84485 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
84486 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
84487 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
84488 +vhci_read_47878 vhci_read 3 47878 NULL
84489 +devres_alloc_551 devres_alloc 2 551 NULL
84490 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
84491 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
84492 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
84493 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
84494 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
84495 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
84496 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
84497 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
84498 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
84499 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
84500 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
84501 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
84502 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
84503 +sys_prctl_8766 sys_prctl 4 8766 NULL
84504 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
84505 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
84506 +insert_one_name_61668 insert_one_name 7 61668 NULL
84507 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
84508 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
84509 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
84510 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
84511 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
84512 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
84513 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
84514 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
84515 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
84516 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
84517 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
84518 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
84519 +gserial_setup_41558 gserial_setup 2 41558 NULL
84520 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
84521 +rx_57944 rx 4 57944 NULL
84522 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
84523 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
84524 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
84525 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
84526 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
84527 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
84528 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
84529 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
84530 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
84531 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
84532 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
84533 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
84534 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
84535 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
84536 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
84537 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
84538 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
84539 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
84540 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
84541 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
84542 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
84543 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
84544 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
84545 +a2mp_send_41615 a2mp_send 4 41615 NULL
84546 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
84547 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
84548 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
84549 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
84550 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
84551 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
84552 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
84553 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
84554 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
84555 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
84556 +add_uuid_49831 add_uuid 4 49831 NULL
84557 +send_pages_8872 send_pages 3 8872 NULL
84558 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
84559 +read_file_recv_48232 read_file_recv 3 48232 NULL
84560 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
84561 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
84562 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
84563 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
84564 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
84565 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
84566 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
84567 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
84568 +vfs_writev_25278 vfs_writev 3 25278 NULL
84569 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
84570 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
84571 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
84572 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
84573 +create_entry_33479 create_entry 2 33479 NULL
84574 +mce_async_out_58056 mce_async_out 3 58056 NULL
84575 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
84576 +sys_preadv_17100 sys_preadv 3 17100 NULL
84577 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
84578 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
84579 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
84580 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
84581 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
84582 +res_counter_read_33499 res_counter_read 4 33499 NULL
84583 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
84584 +cm4040_write_58079 cm4040_write 3 58079 NULL
84585 +fb_read_33506 fb_read 3 33506 NULL
84586 +help_25316 help 5 25316 NULL nohasharray
84587 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
84588 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
84589 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
84590 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
84591 +ddp_set_map_751 ddp_set_map 4 751 NULL
84592 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
84593 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
84594 +dvb_video_write_754 dvb_video_write 3 754 NULL
84595 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
84596 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
84597 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
84598 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
84599 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
84600 +udi_log_event_58105 udi_log_event 3 58105 NULL
84601 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
84602 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
84603 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
84604 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
84605 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
84606 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
84607 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
84608 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
84609 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
84610 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
84611 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
84612 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
84613 +sep_read_17161 sep_read 3 17161 NULL
84614 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
84615 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
84616 +dup_array_33551 dup_array 3 33551 NULL
84617 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
84618 +fillonedir_41746 fillonedir 3 41746 NULL
84619 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
84620 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
84621 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
84622 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
84623 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
84624 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
84625 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
84626 +if_writecmd_815 if_writecmd 2 815 NULL
84627 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
84628 +read_fifo_826 read_fifo 3 826 NULL
84629 +scsi_execute_33596 scsi_execute 5 33596 NULL
84630 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
84631 +ms_rw_17220 ms_rw 3-4 17220 NULL
84632 +read_tree_block_841 read_tree_block 3 841 NULL
84633 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
84634 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
84635 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
84636 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
84637 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
84638 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
84639 +um_idi_read_850 um_idi_read 3 850 NULL
84640 +__module_alloc_50004 __module_alloc 1 50004 NULL
84641 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
84642 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
84643 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
84644 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
84645 +provide_user_output_41105 provide_user_output 3 41105 NULL
84646 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
84647 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
84648 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
84649 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
84650 +alloc_ep_17269 alloc_ep 1 17269 NULL
84651 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
84652 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
84653 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
84654 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
84655 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
84656 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
84657 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
84658 +create_queues_9088 create_queues 2-3 9088 NULL
84659 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
84660 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
84661 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
84662 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
84663 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
84664 +read_file_debug_58256 read_file_debug 3 58256 NULL
84665 +skb_pad_17302 skb_pad 2 17302 NULL
84666 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
84667 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
84668 +profile_load_58267 profile_load 3 58267 NULL
84669 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
84670 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
84671 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
84672 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
84673 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
84674 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
84675 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
84676 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
84677 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
84678 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
84679 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
84680 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
84681 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
84682 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
84683 +get_packet_41914 get_packet 3 41914 NULL
84684 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
84685 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
84686 +read_file_slot_50111 read_file_slot 3 50111 NULL
84687 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
84688 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
84689 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
84690 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
84691 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
84692 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
84693 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
84694 +copy_items_50140 copy_items 6 50140 NULL
84695 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
84696 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
84697 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
84698 +ts_write_64336 ts_write 3 64336 NULL
84699 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
84700 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
84701 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
84702 +portnames_read_41958 portnames_read 3 41958 NULL
84703 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
84704 +hashtab_create_33769 hashtab_create 3 33769 NULL
84705 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
84706 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
84707 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
84708 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
84709 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
84710 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
84711 +odev_update_50169 odev_update 2 50169 NULL
84712 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
84713 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
84714 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
84715 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
84716 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
84717 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
84718 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
84719 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
84720 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
84721 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
84722 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
84723 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
84724 +lguest_map_42008 lguest_map 1-2 42008 NULL
84725 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
84726 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
84727 +pool_allocate_42012 pool_allocate 3 42012 NULL
84728 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
84729 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
84730 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
84731 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
84732 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
84733 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
84734 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
84735 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
84736 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
84737 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
84738 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
84739 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
84740 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
84741 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
84742 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
84743 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
84744 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
84745 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
84746 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
84747 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
84748 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
84749 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
84750 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
84751 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
84752 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
84753 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
84754 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
84755 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
84756 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
84757 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
84758 +config_proc_write_33878 config_proc_write 3 33878 NULL
84759 +capabilities_read_58457 capabilities_read 3 58457 NULL
84760 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
84761 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
84762 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
84763 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
84764 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
84765 +dm_table_create_35687 dm_table_create 3 35687 NULL
84766 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
84767 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
84768 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
84769 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
84770 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
84771 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
84772 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
84773 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
84774 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
84775 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
84776 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
84777 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
84778 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
84779 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
84780 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
84781 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
84782 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
84783 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
84784 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
84785 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
84786 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
84787 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
84788 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
84789 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
84790 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
84791 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
84792 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
84793 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
84794 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
84795 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
84796 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
84797 +read_9397 read 3 9397 NULL
84798 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
84799 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
84800 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
84801 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
84802 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
84803 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
84804 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
84805 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
84806 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
84807 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
84808 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
84809 +osst_execute_17607 osst_execute 7-6 17607 NULL
84810 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
84811 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
84812 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
84813 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
84814 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
84815 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
84816 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
84817 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
84818 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
84819 +xip_file_read_58592 xip_file_read 3 58592 NULL
84820 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
84821 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
84822 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
84823 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
84824 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
84825 +ppp_write_34034 ppp_write 3 34034 NULL
84826 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
84827 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
84828 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
84829 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
84830 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
84831 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
84832 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
84833 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
84834 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
84835 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
84836 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
84837 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
84838 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
84839 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
84840 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
84841 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
84842 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
84843 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
84844 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
84845 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
84846 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
84847 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
84848 +lp_write_9511 lp_write 3 9511 NULL
84849 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
84850 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
84851 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
84852 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
84853 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
84854 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
84855 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
84856 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
84857 +read_file_dma_9530 read_file_dma 3 9530 NULL
84858 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
84859 +rcname_read_25919 rcname_read 3 25919 NULL
84860 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
84861 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
84862 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
84863 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
84864 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
84865 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
84866 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
84867 +key_flags_read_25931 key_flags_read 3 25931 NULL
84868 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
84869 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
84870 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
84871 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
84872 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
84873 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
84874 +fw_node_create_9559 fw_node_create 2 9559 NULL
84875 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
84876 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
84877 +kobj_map_9566 kobj_map 2-3 9566 NULL
84878 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
84879 +acpi_map_58725 acpi_map 1-2 58725 NULL
84880 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
84881 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
84882 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
84883 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
84884 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
84885 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
84886 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
84887 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
84888 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
84889 +file_read_actor_1401 file_read_actor 4 1401 NULL
84890 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
84891 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
84892 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
84893 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
84894 +do_sync_9604 do_sync 1 9604 NULL
84895 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
84896 +compat_readv_30273 compat_readv 3 30273 NULL
84897 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
84898 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
84899 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
84900 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
84901 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
84902 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
84903 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
84904 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
84905 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
84906 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
84907 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
84908 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
84909 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
84910 +sge_rx_50594 sge_rx 3 50594 NULL
84911 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
84912 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
84913 +skb_padto_50759 skb_padto 2 50759 NULL
84914 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
84915 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
84916 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
84917 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
84918 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
84919 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
84920 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
84921 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
84922 +ep_read_58813 ep_read 3 58813 NULL
84923 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
84924 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
84925 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
84926 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
84927 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
84928 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
84929 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
84930 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
84931 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
84932 +dns_query_9676 dns_query 3 9676 NULL
84933 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
84934 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
84935 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
84936 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
84937 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
84938 +command_write_58841 command_write 3 58841 NULL
84939 +dev_config_8506 dev_config 3 8506 NULL
84940 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
84941 +sys_readv_50664 sys_readv 3 50664 NULL
84942 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
84943 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
84944 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
84945 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
84946 +recover_head_17904 recover_head 3 17904 NULL
84947 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
84948 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
84949 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
84950 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
84951 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
84952 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
84953 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
84954 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
84955 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
84956 +skb_cow_26138 skb_cow 2 26138 NULL
84957 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
84958 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
84959 +do_sigpending_9766 do_sigpending 2 9766 NULL
84960 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
84961 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
84962 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
84963 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
84964 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
84965 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
84966 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
84967 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
84968 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
84969 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
84970 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
84971 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
84972 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
84973 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
84974 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
84975 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
84976 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
84977 +get_registers_26187 get_registers 3 26187 NULL
84978 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
84979 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
84980 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
84981 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
84982 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
84983 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
84984 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
84985 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
84986 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
84987 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
84988 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
84989 +mce_write_26201 mce_write 3 26201 NULL
84990 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
84991 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
84992 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
84993 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
84994 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
84995 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
84996 +tpm_write_50798 tpm_write 3 50798 NULL
84997 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
84998 +tun_do_read_50800 tun_do_read 4 50800 NULL
84999 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
85000 +write_flush_50803 write_flush 3 50803 NULL
85001 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
85002 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
85003 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
85004 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
85005 +dvb_play_50814 dvb_play 3 50814 NULL
85006 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
85007 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
85008 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
85009 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
85010 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
85011 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
85012 +dma_attach_50831 dma_attach 6-7 50831 NULL
85013 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
85014 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
85015 +packet_came_18072 packet_came 3 18072 NULL
85016 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
85017 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
85018 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
85019 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
85020 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
85021 +get_vm_area_18080 get_vm_area 1 18080 NULL
85022 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
85023 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
85024 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
85025 +self_check_write_50856 self_check_write 5 50856 NULL
85026 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
85027 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
85028 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
85029 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
85030 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
85031 +get_packet_5747 get_packet 3 5747 NULL
85032 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
85033 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
85034 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
85035 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
85036 +vb2_read_42703 vb2_read 3 42703 NULL
85037 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
85038 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
85039 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
85040 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
85041 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
85042 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
85043 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
85044 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
85045 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
85046 +alloc_buf_34532 alloc_buf 1 34532 NULL
85047 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
85048 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
85049 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
85050 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
85051 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
85052 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
85053 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
85054 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
85055 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
85056 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
85057 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
85058 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
85059 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
85060 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
85061 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
85062 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
85063 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
85064 +mld_newpack_50950 mld_newpack 2 50950 NULL
85065 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
85066 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
85067 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
85068 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
85069 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
85070 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
85071 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
85072 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
85073 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
85074 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
85075 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
85076 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
85077 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
85078 +timeout_write_50991 timeout_write 3 50991 NULL
85079 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
85080 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
85081 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
85082 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
85083 +proc_write_51003 proc_write 3 51003 NULL
85084 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
85085 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
85086 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
85087 +set_arg_42824 set_arg 3 42824 NULL
85088 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
85089 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
85090 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
85091 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
85092 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
85093 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
85094 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
85095 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
85096 +dt3155_read_59226 dt3155_read 3 59226 NULL
85097 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
85098 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
85099 +dump_midi_51040 dump_midi 3 51040 NULL
85100 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
85101 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
85102 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
85103 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
85104 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
85105 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
85106 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
85107 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
85108 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
85109 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
85110 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
85111 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
85112 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
85113 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
85114 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
85115 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
85116 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
85117 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
85118 +read_vmcore_26501 read_vmcore 3 26501 NULL
85119 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
85120 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
85121 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
85122 +alloc_skb_55439 alloc_skb 1 55439 NULL
85123 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
85124 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
85125 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
85126 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
85127 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
85128 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
85129 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
85130 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
85131 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
85132 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
85133 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
85134 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
85135 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
85136 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
85137 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
85138 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
85139 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
85140 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
85141 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
85142 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
85143 +fd_copyout_59323 fd_copyout 3 59323 NULL
85144 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
85145 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
85146 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
85147 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
85148 +solos_param_store_34755 solos_param_store 4 34755 NULL
85149 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
85150 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
85151 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
85152 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
85153 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
85154 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
85155 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
85156 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
85157 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
85158 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
85159 +set_registers_53582 set_registers 3 53582 NULL
85160 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
85161 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
85162 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
85163 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
85164 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
85165 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
85166 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
85167 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
85168 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
85169 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
85170 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
85171 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
85172 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
85173 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
85174 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
85175 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
85176 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
85177 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
85178 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
85179 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
85180 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
85181 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
85182 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
85183 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
85184 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
85185 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
85186 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
85187 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
85188 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
85189 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
85190 +tipc_send_51238 tipc_send 4 51238 NULL
85191 +drm_property_create_51239 drm_property_create 4 51239 NULL
85192 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
85193 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
85194 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
85195 +audit_expand_2098 audit_expand 2 2098 NULL
85196 +st_read_51251 st_read 3 51251 NULL
85197 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
85198 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
85199 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
85200 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
85201 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
85202 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
85203 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
85204 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
85205 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
85206 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
85207 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
85208 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
85209 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
85210 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
85211 +pkt_add_39897 pkt_add 3 39897 NULL
85212 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
85213 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
85214 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
85215 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
85216 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
85217 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
85218 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
85219 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
85220 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
85221 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
85222 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
85223 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
85224 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
85225 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
85226 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
85227 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
85228 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
85229 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
85230 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
85231 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
85232 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
85233 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
85234 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
85235 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
85236 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
85237 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
85238 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
85239 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
85240 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
85241 +debug_output_18575 debug_output 3 18575 NULL
85242 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
85243 +Realloc_34961 Realloc 2 34961 NULL
85244 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
85245 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
85246 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
85247 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
85248 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
85249 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
85250 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
85251 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
85252 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
85253 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
85254 +vhci_write_2224 vhci_write 3 2224 NULL
85255 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
85256 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
85257 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
85258 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
85259 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
85260 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
85261 +write_pbl_59583 write_pbl 4 59583 NULL
85262 +from_buffer_18625 from_buffer 3 18625 NULL
85263 +uio_write_43202 uio_write 3 43202 NULL
85264 +memdup_user_59590 memdup_user 2 59590 NULL
85265 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
85266 +iso_callback_43208 iso_callback 3 43208 NULL
85267 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
85268 +smk_write_load_26829 smk_write_load 3 26829 NULL
85269 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
85270 +do_update_counters_2259 do_update_counters 4 2259 NULL
85271 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
85272 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
85273 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
85274 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
85275 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
85276 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
85277 +mtrr_write_59622 mtrr_write 3 59622 NULL
85278 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
85279 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
85280 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
85281 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
85282 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
85283 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
85284 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
85285 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
85286 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
85287 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
85288 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
85289 +fixup_leb_43256 fixup_leb 3 43256 NULL
85290 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
85291 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
85292 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
85293 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
85294 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
85295 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
85296 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
85297 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
85298 +evtchn_write_43278 evtchn_write 3 43278 NULL
85299 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
85300 +store_ifalias_35088 store_ifalias 4 35088 NULL
85301 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
85302 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
85303 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
85304 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
85305 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
85306 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
85307 +tower_write_8580 tower_write 3 8580 NULL
85308 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
85309 +capi_write_35104 capi_write 3 35104 NULL nohasharray
85310 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
85311 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
85312 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
85313 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
85314 +dev_read_56369 dev_read 3 56369 NULL
85315 +read_file_misc_9948 read_file_misc 3 9948 NULL
85316 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
85317 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
85318 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
85319 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
85320 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
85321 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
85322 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
85323 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
85324 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
85325 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
85326 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
85327 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
85328 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
85329 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
85330 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
85331 +do_trimming_26952 do_trimming 3 26952 NULL
85332 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
85333 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
85334 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
85335 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
85336 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
85337 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
85338 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
85339 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
85340 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
85341 +otp_read_10594 otp_read 2-4-5 10594 NULL
85342 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
85343 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
85344 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
85345 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
85346 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
85347 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
85348 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
85349 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
85350 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
85351 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
85352 +venus_remove_59781 venus_remove 4 59781 NULL
85353 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
85354 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
85355 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
85356 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
85357 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
85358 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
85359 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
85360 +xenfb_write_43412 xenfb_write 3 43412 NULL
85361 +cosa_write_1774 cosa_write 3 1774 NULL
85362 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
85363 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
85364 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
85365 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
85366 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 NULL nohasharray
85367 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 &gdm_wimax_netif_rx_43423
85368 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
85369 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
85370 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
85371 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
85372 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
85373 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
85374 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
85375 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
85376 +cmd_complete_51629 cmd_complete 6 51629 NULL
85377 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
85378 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
85379 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
85380 +set_fd_set_35249 set_fd_set 1 35249 NULL
85381 +wiphy_new_2482 wiphy_new 2 2482 NULL
85382 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
85383 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
85384 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
85385 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
85386 +tcp_push_10680 tcp_push 3 10680 NULL
85387 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
85388 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
85389 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
85390 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
85391 +tun_put_user_59849 tun_put_user 4 59849 NULL
85392 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
85393 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
85394 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
85395 +dm_write_2513 dm_write 3 2513 NULL
85396 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
85397 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
85398 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
85399 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
85400 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
85401 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
85402 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
85403 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
85404 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
85405 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
85406 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
85407 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
85408 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
85409 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
85410 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
85411 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
85412 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
85413 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
85414 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
85415 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
85416 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
85417 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
85418 +sel_write_access_51704 sel_write_access 3 51704 NULL
85419 +sys_syslog_10746 sys_syslog 3 10746 NULL
85420 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
85421 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
85422 +do_readlink_43518 do_readlink 2 43518 NULL
85423 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
85424 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
85425 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
85426 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
85427 +pms_capture_27142 pms_capture 4 27142 NULL
85428 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
85429 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
85430 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
85431 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
85432 +msg_set_51725 msg_set 3 51725 NULL
85433 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
85434 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
85435 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
85436 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
85437 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
85438 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
85439 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
85440 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
85441 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
85442 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
85443 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
85444 +sys_bind_10799 sys_bind 3 10799 NULL
85445 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
85446 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
85447 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
85448 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
85449 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
85450 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
85451 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
85452 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
85453 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
85454 +send_command_10832 send_command 4 10832 NULL
85455 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
85456 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
85457 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
85458 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
85459 +proc_read_43614 proc_read 3 43614 NULL
85460 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
85461 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
85462 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
85463 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
85464 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
85465 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
85466 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
85467 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
85468 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
85469 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
85470 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
85471 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
85472 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
85473 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
85474 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
85475 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
85476 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
85477 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
85478 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
85479 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
85480 +unifi_write_65012 unifi_write 3 65012 NULL
85481 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
85482 +get_scq_10897 get_scq 2 10897 NULL
85483 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
85484 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
85485 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
85486 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
85487 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
85488 +load_module_60056 load_module 2 60056 NULL nohasharray
85489 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
85490 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
85491 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
85492 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
85493 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
85494 +nfsd_read_19568 nfsd_read 5 19568 NULL
85495 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
85496 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
85497 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
85498 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
85499 +user_read_51881 user_read 3 51881 NULL
85500 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
85501 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
85502 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
85503 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
85504 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
85505 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
85506 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
85507 +async_setkey_35521 async_setkey 3 35521 NULL
85508 +send_msg_37323 send_msg 4 37323 NULL
85509 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
85510 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
85511 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
85512 +gnttab_map_56439 gnttab_map 2 56439 NULL
85513 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
85514 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
85515 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
85516 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
85517 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
85518 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
85519 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
85520 +kcalloc_27770 kcalloc 1-2 27770 NULL
85521 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
85522 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
85523 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
85524 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
85525 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
85526 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
85527 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
85528 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
85529 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
85530 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
85531 +handle_request_10024 handle_request 9 10024 NULL
85532 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
85533 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
85534 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
85535 +init_state_60165 init_state 2 60165 NULL
85536 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
85537 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
85538 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
85539 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
85540 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
85541 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
85542 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
85543 +read_dma_55086 read_dma 3 55086 NULL
85544 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
85545 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
85546 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
85547 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
85548 +kernel_readv_35617 kernel_readv 3 35617 NULL
85549 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
85550 +reshape_ring_29147 reshape_ring 2 29147 NULL
85551 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
85552 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
85553 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
85554 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
85555 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
85556 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
85557 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
85558 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
85559 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
85560 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
85561 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
85562 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
85563 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
85564 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
85565 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
85566 +store_debug_level_35652 store_debug_level 3 35652 NULL
85567 +read_flush_43851 read_flush 3 43851 NULL
85568 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
85569 +cmm_write_2896 cmm_write 3 2896 NULL
85570 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
85571 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
85572 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
85573 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
85574 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
85575 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
85576 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
85577 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
85578 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
85579 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
85580 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
85581 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
85582 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
85583 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
85584 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
85585 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
85586 +printer_write_60276 printer_write 3 60276 NULL
85587 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
85588 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
85589 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
85590 +debug_read_19322 debug_read 3 19322 NULL
85591 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
85592 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
85593 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
85594 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
85595 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
85596 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
85597 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
85598 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
85599 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
85600 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
85601 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
85602 +SendString_43928 SendString 3 43928 NULL
85603 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
85604 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
85605 +retry_count_read_52129 retry_count_read 3 52129 NULL
85606 +trace_options_read_11419 trace_options_read 3 11419 NULL
85607 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
85608 +read_zero_19366 read_zero 3 19366 NULL
85609 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
85610 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
85611 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
85612 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
85613 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
85614 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
85615 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
85616 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
85617 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
85618 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
85619 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
85620 +depth_write_3021 depth_write 3 3021 NULL
85621 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
85622 +read_file_stations_35795 read_file_stations 3 35795 NULL
85623 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
85624 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
85625 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
85626 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
85627 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
85628 +copy_from_user_17559 copy_from_user 3 17559 NULL
85629 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
85630 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
85631 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
85632 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
85633 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
85634 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
85635 +driver_names_read_60399 driver_names_read 3 60399 NULL
85636 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
85637 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
85638 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
85639 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
85640 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
85641 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
85642 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
85643 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
85644 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
85645 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
85646 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
85647 +rx_data_60442 rx_data 4 60442 NULL
85648 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
85649 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
85650 +rb_alloc_3102 rb_alloc 1 3102 NULL
85651 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
85652 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
85653 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
85654 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
85655 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
85656 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
85657 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
85658 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
85659 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
85660 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
85661 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
85662 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
85663 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
85664 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
85665 +construct_key_11329 construct_key 3 11329 NULL
85666 +evm_write_key_27715 evm_write_key 3 27715 NULL
85667 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
85668 +xsd_read_15653 xsd_read 3 15653 NULL
85669 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
85670 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
85671 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
85672 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
85673 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
85674 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
85675 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
85676 +read_file_reset_52310 read_file_reset 3 52310 NULL
85677 +sel_write_create_11353 sel_write_create 3 11353 NULL
85678 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
85679 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
85680 +hwflags_read_52318 hwflags_read 3 52318 NULL
85681 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
85682 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
85683 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
85684 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
85685 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
85686 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
85687 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
85688 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
85689 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
85690 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
85691 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
85692 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
85693 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
85694 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
85695 +alloc_context_3194 alloc_context 1 3194 NULL
85696 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
85697 +bm_status_read_19583 bm_status_read 3 19583 NULL
85698 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
85699 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
85700 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
85701 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
85702 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
85703 +str_to_user_11411 str_to_user 2 11411 NULL
85704 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
85705 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
85706 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
85707 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
85708 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
85709 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
85710 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
85711 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
85712 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
85713 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
85714 +console_store_36007 console_store 4 36007 NULL
85715 +bttv_read_11432 bttv_read 3 11432 NULL
85716 +key_key_read_3241 key_key_read 3 3241 NULL
85717 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
85718 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
85719 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
85720 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
85721 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
85722 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
85723 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
85724 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
85725 +um_idi_write_18293 um_idi_write 3 18293 NULL
85726 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
85727 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
85728 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
85729 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
85730 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
85731 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
85732 +sys_init_module_36047 sys_init_module 2 36047 NULL
85733 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
85734 +read_profile_27859 read_profile 3 27859 NULL
85735 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
85736 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
85737 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
85738 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
85739 +refill_pool_19477 refill_pool 2 19477 NULL
85740 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
85741 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
85742 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
85743 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
85744 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
85745 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
85746 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
85747 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
85748 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
85749 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
85750 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
85751 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
85752 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
85753 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
85754 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
85755 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
85756 +alloc_async_14208 alloc_async 1 14208 NULL
85757 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
85758 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
85759 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
85760 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
85761 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
85762 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
85763 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
85764 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
85765 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
85766 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
85767 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
85768 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
85769 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
85770 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
85771 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
85772 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
85773 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
85774 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
85775 +init_data_container_60709 init_data_container 1 60709 NULL
85776 +p9_client_read_19750 p9_client_read 5 19750 NULL
85777 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
85778 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
85779 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
85780 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
85781 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
85782 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
85783 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
85784 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
85785 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
85786 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
85787 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
85788 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
85789 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
85790 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
85791 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
85792 +send_stream_3397 send_stream 4 3397 NULL
85793 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
85794 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
85795 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
85796 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
85797 +msix_map_region_3411 msix_map_region 3 3411 NULL
85798 +idmouse_read_63374 idmouse_read 3 63374 NULL
85799 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
85800 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
85801 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
85802 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
85803 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
85804 +opticon_write_60775 opticon_write 4 60775 NULL
85805 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
85806 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
85807 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
85808 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
85809 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
85810 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
85811 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
85812 +vip_read_19832 vip_read 3 19832 NULL
85813 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
85814 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
85815 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
85816 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
85817 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
85818 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
85819 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
85820 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
85821 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
85822 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
85823 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
85824 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
85825 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
85826 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
85827 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
85828 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
85829 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
85830 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
85831 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
85832 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
85833 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
85834 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
85835 +split_11691 split 2 11691 NULL
85836 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
85837 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
85838 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
85839 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
85840 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
85841 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
85842 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
85843 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
85844 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
85845 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
85846 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
85847 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
85848 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
85849 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
85850 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
85851 +dsp_write_46218 dsp_write 2 46218 NULL
85852 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
85853 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
85854 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
85855 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
85856 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
85857 +spidev_write_44510 spidev_write 3 44510 NULL
85858 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
85859 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
85860 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
85861 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
85862 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
85863 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
85864 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
85865 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
85866 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
85867 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
85868 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
85869 +evtchn_read_3569 evtchn_read 3 3569 NULL
85870 +video_read_28148 video_read 3 28148 NULL
85871 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
85872 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
85873 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
85874 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
85875 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
85876 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
85877 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
85878 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
85879 +vc_resize_3585 vc_resize 2-3 3585 NULL
85880 +sys_select_38827 sys_select 1 38827 NULL
85881 +gluebi_write_27905 gluebi_write 3 27905 NULL
85882 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
85883 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
85884 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
85885 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
85886 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
85887 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
85888 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
85889 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
85890 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
85891 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
85892 +pti_char_write_60960 pti_char_write 3 60960 NULL
85893 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
85894 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
85895 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
85896 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
85897 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
85898 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
85899 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
85900 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
85901 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
85902 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
85903 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
85904 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
85905 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
85906 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
85907 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
85908 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
85909 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
85910 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
85911 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
85912 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
85913 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
85914 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
85915 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
85916 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
85917 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
85918 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
85919 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
85920 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
85921 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
85922 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
85923 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
85924 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
85925 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
85926 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
85927 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
85928 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
85929 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
85930 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
85931 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
85932 +symtab_init_61050 symtab_init 2 61050 NULL
85933 +team_options_register_20091 team_options_register 3 20091 NULL
85934 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
85935 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
85936 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
85937 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
85938 +mpi_resize_44674 mpi_resize 2 44674 NULL
85939 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
85940 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
85941 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
85942 +interfaces_38859 interfaces 2 38859 NULL
85943 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
85944 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
85945 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
85946 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
85947 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
85948 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
85949 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
85950 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
85951 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
85952 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
85953 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
85954 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
85955 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
85956 +get_derived_key_61100 get_derived_key 4 61100 NULL
85957 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
85958 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
85959 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
85960 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
85961 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
85962 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
85963 +fs_path_add_15648 fs_path_add 3 15648 NULL
85964 +kone_send_63435 kone_send 4 63435 NULL
85965 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
85966 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
85967 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
85968 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
85969 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
85970 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
85971 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
85972 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
85973 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
85974 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
85975 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
85976 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
85977 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
85978 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
85979 +send_packet_52960 send_packet 4 52960 NULL
85980 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
85981 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
85982 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
85983 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
85984 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
85985 +put_cmsg_36589 put_cmsg 4 36589 NULL
85986 +__vmalloc_61168 __vmalloc 1 61168 NULL
85987 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
85988 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
85989 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
85990 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
85991 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
85992 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
85993 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
85994 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
85995 +p54_init_common_23850 p54_init_common 1 23850 NULL
85996 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
85997 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
85998 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
85999 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
86000 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
86001 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
86002 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
86003 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
86004 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
86005 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
86006 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
86007 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
86008 +garp_request_join_7471 garp_request_join 4 7471 NULL
86009 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
86010 +unlink_queued_645 unlink_queued 3-4 645 NULL
86011 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
86012 +sisusb_write_44834 sisusb_write 3 44834 NULL
86013 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
86014 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
86015 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
86016 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
86017 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
86018 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
86019 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
86020 +nvram_write_3894 nvram_write 3 3894 NULL
86021 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
86022 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
86023 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
86024 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
86025 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
86026 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
86027 +vcs_write_3910 vcs_write 3 3910 NULL
86028 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
86029 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
86030 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
86031 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
86032 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
86033 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
86034 +do_tty_write_44896 do_tty_write 5 44896 NULL
86035 +set_powered_12129 set_powered 4 12129 NULL
86036 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
86037 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
86038 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
86039 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
86040 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
86041 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
86042 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
86043 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
86044 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
86045 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
86046 +udf_readpages_38761 udf_readpages 4 38761 NULL
86047 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
86048 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
86049 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
86050 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
86051 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
86052 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
86053 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
86054 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
86055 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
86056 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
86057 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
86058 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
86059 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
86060 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
86061 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
86062 +do_add_counters_3992 do_add_counters 3 3992 NULL
86063 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
86064 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
86065 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
86066 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
86067 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
86068 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
86069 +mei_write_4005 mei_write 3 4005 NULL
86070 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
86071 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
86072 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
86073 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
86074 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
86075 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
86076 +receive_copy_12216 receive_copy 3 12216 NULL
86077 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
86078 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
86079 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
86080 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
86081 +change_xattr_61390 change_xattr 5 61390 NULL
86082 +find_skb_20431 find_skb 2 20431 NULL
86083 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
86084 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
86085 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
86086 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
86087 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
86088 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
86089 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
86090 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
86091 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
86092 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
86093 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
86094 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
86095 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
86096 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
86097 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
86098 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
86099 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
86100 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
86101 +cm_write_36858 cm_write 3 36858 NULL
86102 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
86103 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
86104 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
86105 +sel_write_user_45060 sel_write_user 3 45060 NULL
86106 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
86107 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
86108 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
86109 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
86110 +fast_user_write_20494 fast_user_write 5 20494 NULL
86111 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
86112 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
86113 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
86114 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
86115 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
86116 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
86117 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
86118 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
86119 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
86120 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
86121 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
86122 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
86123 +tm6000_read_4151 tm6000_read 3 4151 NULL
86124 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
86125 +usbdev_read_45114 usbdev_read 3 45114 NULL
86126 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
86127 +spi_execute_28736 spi_execute 5 28736 NULL
86128 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
86129 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
86130 +get_alua_req_4166 get_alua_req 3 4166 NULL
86131 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
86132 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
86133 +venus_create_20555 venus_create 4 20555 NULL
86134 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
86135 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
86136 +receive_packet_12367 receive_packet 2 12367 NULL
86137 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
86138 +mem_write_22232 mem_write 3 22232 NULL
86139 +read_file_bool_4180 read_file_bool 3 4180 NULL
86140 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
86141 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
86142 +write_leb_36957 write_leb 5 36957 NULL
86143 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
86144 +device_write_45156 device_write 3 45156 NULL
86145 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
86146 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
86147 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
86148 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
86149 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
86150 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
86151 +isp1760_register_628 isp1760_register 1-2 628 NULL
86152 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
86153 +lirc_write_20604 lirc_write 3 20604 NULL
86154 +sel_write_member_28800 sel_write_member 3 28800 NULL
86155 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
86156 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
86157 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
86158 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
86159 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
86160 +setxattr_37006 setxattr 4 37006 NULL
86161 +add_child_45201 add_child 4 45201 NULL
86162 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
86163 +seq_open_private_61589 seq_open_private 3 61589 NULL
86164 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
86165 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
86166 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
86167 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
86168 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
86169 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
86170 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
86171 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
86172 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
86173 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
86174 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
86175 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
86176 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
86177 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
86178 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
86179 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
86180 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
86181 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
86182 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
86183 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
86184 +resize_stripes_61650 resize_stripes 2 61650 NULL
86185 +n2_run_53459 n2_run 3 53459 NULL
86186 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
86187 +parse_command_37079 parse_command 2 37079 NULL
86188 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
86189 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
86190 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
86191 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
86192 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
86193 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
86194 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
86195 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
86196 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
86197 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
86198 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
86199 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
86200 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
86201 +lock_loop_61681 lock_loop 1 61681 NULL
86202 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
86203 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
86204 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
86205 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
86206 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
86207 +push_rx_28939 push_rx 3 28939 NULL
86208 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
86209 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
86210 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
86211 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
86212 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
86213 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
86214 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
86215 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
86216 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
86217 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
86218 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
86219 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
86220 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
86221 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
86222 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
86223 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
86224 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
86225 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
86226 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
86227 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
86228 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
86229 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
86230 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
86231 +bin_uuid_28999 bin_uuid 3 28999 NULL
86232 +sys_sendto_20809 sys_sendto 6 20809 NULL
86233 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
86234 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
86235 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
86236 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
86237 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
86238 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
86239 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
86240 +keymap_store_45406 keymap_store 4 45406 NULL
86241 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
86242 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
86243 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
86244 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
86245 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
86246 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
86247 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
86248 +__do_replace_37227 __do_replace 5 37227 NULL
86249 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
86250 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
86251 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
86252 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
86253 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
86254 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
86255 +tso_fragment_29050 tso_fragment 3 29050 NULL
86256 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
86257 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
86258 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
86259 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
86260 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
86261 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
86262 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
86263 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
86264 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
86265 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
86266 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
86267 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
86268 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
86269 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
86270 +set_link_security_4502 set_link_security 4 4502 NULL
86271 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
86272 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
86273 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
86274 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
86275 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
86276 +c101_run_37279 c101_run 2 37279 NULL
86277 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
86278 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
86279 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
86280 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
86281 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
86282 +ivtv_write_12721 ivtv_write 3 12721 NULL
86283 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
86284 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
86285 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
86286 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
86287 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
86288 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
86289 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
86290 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
86291 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
86292 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
86293 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
86294 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
86295 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
86296 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
86297 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
86298 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
86299 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
86300 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
86301 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
86302 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
86303 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
86304 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
86305 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
86306 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
86307 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
86308 +copy_macs_45534 copy_macs 4 45534 NULL
86309 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
86310 +listxattr_12769 listxattr 3 12769 NULL
86311 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
86312 +wdm_write_53735 wdm_write 3 53735 NULL
86313 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
86314 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
86315 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
86316 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
86317 +bch_alloc_4593 bch_alloc 1 4593 NULL
86318 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
86319 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
86320 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
86321 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
86322 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
86323 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
86324 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
86325 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
86326 +mgmt_event_12810 mgmt_event 4 12810 NULL
86327 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
86328 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
86329 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
86330 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
86331 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
86332 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
86333 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
86334 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
86335 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
86336 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
86337 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
86338 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
86339 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
86340 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
86341 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
86342 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
86343 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
86344 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
86345 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
86346 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
86347 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
86348 +recover_peb_29238 recover_peb 6-7 29238 NULL
86349 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
86350 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
86351 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
86352 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
86353 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
86354 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
86355 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
86356 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
86357 +kone_receive_4690 kone_receive 4 4690 NULL
86358 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
86359 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
86360 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
86361 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
86362 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
86363 +savemem_58129 savemem 3 58129 NULL
86364 +do_pselect_62061 do_pselect 1 62061 NULL
86365 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
86366 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
86367 +pms_read_53873 pms_read 3 53873 NULL
86368 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
86369 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
86370 +groups_alloc_7614 groups_alloc 1 7614 NULL
86371 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
86372 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
86373 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
86374 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
86375 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
86376 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
86377 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
86378 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
86379 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
86380 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
86381 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
86382 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
86383 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
86384 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
86385 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
86386 +new_skb_21148 new_skb 1 21148 NULL
86387 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
86388 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
86389 +bm_status_write_12964 bm_status_write 3 12964 NULL
86390 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
86391 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
86392 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
86393 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
86394 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
86395 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
86396 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
86397 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
86398 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
86399 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
86400 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
86401 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
86402 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
86403 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
86404 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
86405 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
86406 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
86407 +video_usercopy_62151 video_usercopy 2 62151 NULL
86408 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
86409 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
86410 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
86411 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
86412 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
86413 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
86414 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
86415 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
86416 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
86417 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
86418 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
86419 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
86420 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
86421 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
86422 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
86423 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
86424 +input_ff_create_21240 input_ff_create 2 21240 NULL
86425 +mempool_create_29437 mempool_create 1 29437 NULL
86426 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
86427 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
86428 +amthi_read_45831 amthi_read 4 45831 NULL
86429 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
86430 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
86431 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
86432 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
86433 +sys_ipc_4889 sys_ipc 3 4889 NULL
86434 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
86435 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86436 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86437 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
86438 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
86439 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
86440 +do_register_entry_29478 do_register_entry 4 29478 NULL
86441 +isdn_write_45863 isdn_write 3 45863 NULL
86442 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
86443 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
86444 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
86445 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
86446 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
86447 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
86448 +_malloc_54077 _malloc 1 54077 NULL
86449 +add_res_range_21310 add_res_range 4 21310 NULL
86450 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
86451 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
86452 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
86453 +vb2_write_31948 vb2_write 3 31948 NULL
86454 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
86455 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
86456 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
86457 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
86458 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
86459 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
86460 +create_xattr_54106 create_xattr 5 54106 NULL
86461 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
86462 +ep_write_59008 ep_write 3 59008 NULL
86463 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
86464 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
86465 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
86466 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
86467 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
86468 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
86469 +alloc_mr_45935 alloc_mr 1 45935 NULL
86470 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
86471 +isku_receive_54130 isku_receive 4 54130 NULL
86472 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
86473 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
86474 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
86475 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
86476 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
86477 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
86478 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
86479 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
86480 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
86481 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
86482 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
86483 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
86484 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
86485 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
86486 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
86487 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
86488 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
86489 +comedi_read_13199 comedi_read 3 13199 NULL
86490 +flash_write_62354 flash_write 3 62354 NULL
86491 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
86492 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
86493 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
86494 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
86495 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
86496 +proc_file_read_53905 proc_file_read 3 53905 NULL
86497 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
86498 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
86499 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
86500 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
86501 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
86502 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
86503 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
86504 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
86505 +cru_detect_11272 cru_detect 1 11272 NULL
86506 +altera_irscan_62396 altera_irscan 2 62396 NULL
86507 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
86508 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
86509 +fw_download_code_13249 fw_download_code 3 13249 NULL
86510 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
86511 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
86512 +set_ssp_62411 set_ssp 4 62411 NULL
86513 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
86514 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
86515 +get_free_entries_46030 get_free_entries 1 46030 NULL
86516 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
86517 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
86518 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
86519 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
86520 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
86521 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
86522 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
86523 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
86524 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
86525 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
86526 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
86527 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
86528 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
86529 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
86530 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
86531 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
86532 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
86533 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
86534 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
86535 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
86536 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
86537 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
86538 +tunables_write_59563 tunables_write 3 59563 NULL
86539 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
86540 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
86541 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
86542 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
86543 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
86544 +probes_write_29711 probes_write 3 29711 NULL
86545 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
86546 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
86547 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
86548 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86549 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
86550 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
86551 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
86552 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
86553 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
86554 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
86555 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
86556 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
86557 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
86558 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
86559 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
86560 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
86561 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
86562 +event_filter_write_56609 event_filter_write 3 56609 NULL
86563 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
86564 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
86565 +insert_dent_65034 insert_dent 7 65034 NULL
86566 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
86567 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
86568 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
86569 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
86570 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
86571 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
86572 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
86573 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
86574 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
86575 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
86576 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
86577 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
86578 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
86579 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
86580 +isdn_read_50021 isdn_read 3 50021 NULL
86581 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
86582 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
86583 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
86584 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
86585 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
86586 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
86587 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
86588 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
86589 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
86590 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
86591 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
86592 +get_subdir_62581 get_subdir 3 62581 NULL
86593 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
86594 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
86595 +vfs_readv_38011 vfs_readv 3 38011 NULL
86596 +keyring_read_13438 keyring_read 3 13438 NULL
86597 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
86598 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
86599 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
86600 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
86601 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
86602 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
86603 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
86604 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
86605 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
86606 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
86607 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
86608 +ftrace_write_29551 ftrace_write 3 29551 NULL
86609 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
86610 +port_show_regs_5904 port_show_regs 3 5904 NULL
86611 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
86612 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
86613 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
86614 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
86615 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
86616 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
86617 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
86618 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
86619 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
86620 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
86621 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
86622 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
86623 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
86624 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
86625 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
86626 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
86627 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
86628 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
86629 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
86630 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
86631 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
86632 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
86633 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
86634 +bm_init_13529 bm_init 2 13529 NULL
86635 +check586_29914 check586 2 29914 NULL
86636 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
86637 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
86638 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
86639 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
86640 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
86641 +pg_read_17276 pg_read 3 17276 NULL
86642 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
86643 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
86644 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
86645 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
86646 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
86647 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
86648 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
86649 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
86650 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
86651 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
86652 +l2down_create_21755 l2down_create 4 21755 NULL
86653 +alloc_tio_13564 alloc_tio 3 13564 NULL
86654 +viacam_read_54526 viacam_read 3 54526 NULL
86655 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
86656 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
86657 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
86658 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
86659 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
86660 +setsockopt_54539 setsockopt 5 54539 NULL
86661 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
86662 +bio_alloc_32095 bio_alloc 2 32095 NULL
86663 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
86664 +tty_register_device_4544 tty_register_device 2 4544 NULL
86665 +cache_write_13589 cache_write 3 13589 NULL
86666 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
86667 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
86668 +key_replays_read_62746 key_replays_read 3 62746 NULL
86669 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
86670 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
86671 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
86672 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
86673 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
86674 +cdev_add_38176 cdev_add 2-3 38176 NULL
86675 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
86676 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
86677 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
86678 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
86679 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
86680 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
86681 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
86682 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
86683 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
86684 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
86685 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
86686 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
86687 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
86688 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
86689 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
86690 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
86691 +packet_snd_13634 packet_snd 3 13634 NULL
86692 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
86693 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
86694 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
86695 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
86696 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
86697 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
86698 +drp_wmove_30043 drp_wmove 4 30043 NULL
86699 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
86700 +cache_downcall_13666 cache_downcall 3 13666 NULL
86701 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
86702 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86703 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
86704 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
86705 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
86706 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
86707 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
86708 +tty_write_5494 tty_write 3 5494 NULL
86709 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
86710 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
86711 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
86712 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
86713 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
86714 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
86715 +filldir64_46469 filldir64 3 46469 NULL
86716 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
86717 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
86718 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
86719 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
86720 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
86721 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
86722 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
86723 +spidev_message_5518 spidev_message 3 5518 NULL
86724 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
86725 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
86726 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86727 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86728 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
86729 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
86730 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
86731 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86732 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
86733 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
86734 +u32_array_read_2219 u32_array_read 3 2219 NULL
86735 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
86736 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
86737 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
86738 +kmsg_read_46514 kmsg_read 3 46514 NULL
86739 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86740 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
86741 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
86742 +recv_stream_30138 recv_stream 4 30138 NULL
86743 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86744 +getdqbuf_62908 getdqbuf 1 62908 NULL
86745 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
86746 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
86747 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
86748 +fir16_create_5574 fir16_create 3 5574 NULL
86749 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
86750 +pt_write_40159 pt_write 3 40159 NULL
86751 +bioset_create_5580 bioset_create 1 5580 NULL
86752 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
86753 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
86754 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
86755 +kzalloc_54740 kzalloc 1 54740 NULL
86756 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
86757 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
86758 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
86759 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
86760 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
86761 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
86762 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
86763 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
86764 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
86765 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
86766 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
86767 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
86768 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
86769 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
86770 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
86771 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
86772 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
86773 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
86774 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
86775 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
86776 +ti_recv_22027 ti_recv 4 22027 NULL
86777 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
86778 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
86779 +nfsd_write_54809 nfsd_write 6 54809 NULL
86780 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
86781 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
86782 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
86783 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
86784 +get_skb_63008 get_skb 2 63008 NULL
86785 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
86786 +netlink_send_38434 netlink_send 5 38434 NULL
86787 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
86788 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
86789 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
86790 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
86791 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
86792 +write_rio_54837 write_rio 3 54837 NULL
86793 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
86794 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
86795 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
86796 +get_arg_5694 get_arg 3 5694 NULL
86797 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
86798 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
86799 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
86800 +printer_read_54851 printer_read 3 54851 NULL
86801 +mem_rw_22085 mem_rw 3 22085 NULL
86802 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
86803 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
86804 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
86805 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
86806 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
86807 +unlink1_63059 unlink1 3 63059 NULL
86808 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
86809 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
86810 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
86811 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
86812 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
86813 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
86814 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
86815 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
86816 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
86817 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
86818 +dev_names_read_38509 dev_names_read 3 38509 NULL
86819 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
86820 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
86821 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
86822 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
86823 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
86824 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
86825 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
86826 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
86827 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
86828 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
86829 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
86830 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
86831 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
86832 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
86833 +resource_from_user_30341 resource_from_user 3 30341 NULL
86834 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
86835 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
86836 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
86837 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
86838 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
86839 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
86840 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
86841 +com90xx_found_13974 com90xx_found 3 13974 NULL
86842 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
86843 +qcam_read_13977 qcam_read 3 13977 NULL
86844 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
86845 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
86846 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
86847 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
86848 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
86849 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
86850 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
86851 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
86852 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
86853 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
86854 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
86855 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
86856 +l2up_create_6430 l2up_create 3 6430 NULL
86857 +c4_add_card_54968 c4_add_card 3 54968 NULL
86858 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
86859 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
86860 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
86861 +concat_writev_21451 concat_writev 3 21451 NULL
86862 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
86863 +_queue_data_54983 _queue_data 4 54983 NULL
86864 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
86865 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
86866 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
86867 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
86868 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
86869 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
86870 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
86871 +setup_req_5848 setup_req 3 5848 NULL
86872 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
86873 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
86874 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
86875 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
86876 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
86877 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
86878 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
86879 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
86880 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
86881 +cma_create_area_38642 cma_create_area 2 38642 NULL
86882 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
86883 +sriov_enable_59689 sriov_enable 2 59689 NULL
86884 +enable_write_30456 enable_write 3 30456 NULL
86885 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
86886 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
86887 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
86888 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
86889 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
86890 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
86891 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
86892 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
86893 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
86894 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
86895 +ptp_read_63251 ptp_read 4 63251 NULL
86896 +adu_write_30487 adu_write 3 30487 NULL
86897 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
86898 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
86899 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
86900 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
86901 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
86902 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
86903 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
86904 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
86905 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
86906 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
86907 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
86908 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
86909 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
86910 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
86911 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
86912 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
86913 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
86914 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
86915 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
86916 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
86917 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
86918 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
86919 +em_canid_change_14150 em_canid_change 3 14150 NULL
86920 +raid5_resize_63306 raid5_resize 2 63306 NULL
86921 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
86922 +fb_write_46924 fb_write 3 46924 NULL
86923 +ts_read_44687 ts_read 3 44687 NULL
86924 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
86925 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
86926 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
86927 +filldir_55137 filldir 3 55137 NULL
86928 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
86929 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
86930 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
86931 +reada_add_block_54247 reada_add_block 2 54247 NULL
86932 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
86933 +proc_info_read_63344 proc_info_read 3 63344 NULL
86934 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
86935 +pep_indicate_38611 pep_indicate 5 38611 NULL
86936 +set_le_30581 set_le 4 30581 NULL
86937 +write_62671 write 3 62671 NULL
86938 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
86939 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
86940 +alloc_private_22399 alloc_private 2 22399 NULL
86941 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
86942 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
86943 +zoran_write_22404 zoran_write 3 22404 NULL
86944 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
86945 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
86946 +queue_reply_22416 queue_reply 3 22416 NULL
86947 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
86948 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
86949 +sound_write_5102 sound_write 3 5102 NULL
86950 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
86951 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
86952 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
86953 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
86954 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
86955 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
86956 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
86957 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
86958 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
86959 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
86960 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
86961 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
86962 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
86963 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
86964 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
86965 +direct_entry_38836 direct_entry 3 38836 NULL
86966 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
86967 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
86968 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
86969 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
86970 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
86971 +write_head_30481 write_head 4 30481 NULL
86972 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
86973 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
86974 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
86975 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
86976 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
86977 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
86978 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
86979 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
86980 +agp_remap_30665 agp_remap 2 30665 NULL
86981 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
86982 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
86983 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
86984 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
86985 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
86986 +qc_capture_19298 qc_capture 3 19298 NULL
86987 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
86988 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
86989 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
86990 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
86991 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
86992 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
86993 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
86994 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
86995 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
86996 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
86997 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
86998 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
86999 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
87000 +read_kcore_63488 read_kcore 3 63488 NULL
87001 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
87002 +sel_write_load_63830 sel_write_load 3 63830 NULL
87003 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
87004 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
87005 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
87006 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
87007 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
87008 +mousedev_read_47123 mousedev_read 3 47123 NULL
87009 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
87010 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
87011 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
87012 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
87013 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
87014 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
87015 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
87016 +vme_user_read_55338 vme_user_read 3 55338 NULL
87017 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
87018 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
87019 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
87020 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
87021 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
87022 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
87023 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
87024 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
87025 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
87026 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
87027 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
87028 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
87029 +snapshot_read_22601 snapshot_read 3 22601 NULL
87030 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
87031 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
87032 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
87033 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
87034 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
87035 +__send_to_port_55383 __send_to_port 3 55383 NULL
87036 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
87037 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
87038 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
87039 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
87040 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
87041 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
87042 +get_nodes_39012 get_nodes 3 39012 NULL
87043 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
87044 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
87045 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
87046 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
87047 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
87048 +create_subvol_30836 create_subvol 4 30836 NULL
87049 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
87050 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
87051 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
87052 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
87053 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
87054 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
87055 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
87056 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
87057 +options_write_47243 options_write 3 47243 NULL
87058 +module_alloc_63630 module_alloc 1 63630 NULL
87059 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
87060 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
87061 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
87062 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
87063 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
87064 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
87065 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
87066 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
87067 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
87068 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
87069 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
87070 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
87071 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
87072 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
87073 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
87074 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
87075 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
87076 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
87077 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
87078 +vbi_read_63673 vbi_read 3 63673 NULL
87079 +tun_get_user_39099 tun_get_user 4 39099 NULL
87080 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
87081 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
87082 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
87083 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
87084 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
87085 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
87086 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
87087 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 NULL nohasharray
87088 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
87089 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
87090 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
87091 +ax25_output_22736 ax25_output 2 22736 NULL
87092 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
87093 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
87094 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
87095 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
87096 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
87097 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
87098 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
87099 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
87100 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
87101 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
87102 +hid_input_report_32458 hid_input_report 4 32458 NULL
87103 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
87104 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
87105 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
87106 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
87107 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
87108 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
87109 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
87110 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
87111 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
87112 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
87113 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
87114 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
87115 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
87116 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
87117 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
87118 +setkey_14987 setkey 3 14987 NULL
87119 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
87120 +init_list_set_39188 init_list_set 2-3 39188 NULL
87121 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
87122 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
87123 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
87124 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
87125 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
87126 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
87127 +add_partition_55588 add_partition 2 55588 NULL
87128 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
87129 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
87130 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
87131 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
87132 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
87133 +profile_replace_14652 profile_replace 3 14652 NULL
87134 +vzalloc_47421 vzalloc 1 47421 NULL
87135 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
87136 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
87137 +sys_writev_28384 sys_writev 3 28384 NULL
87138 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
87139 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
87140 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
87141 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
87142 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
87143 +create_attr_set_22861 create_attr_set 1 22861 NULL
87144 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
87145 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
87146 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
87147 +__skb_cow_39254 __skb_cow 2 39254 NULL
87148 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
87149 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
87150 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
87151 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
87152 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
87153 +probe_bios_17467 probe_bios 1 17467 NULL
87154 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
87155 +read_oldmem_55658 read_oldmem 3 55658 NULL
87156 +mei_read_6507 mei_read 3 6507 NULL
87157 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
87158 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
87159 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
87160 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
87161 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
87162 +SetArea_50835 SetArea 4 50835 NULL
87163 +tpm_read_50344 tpm_read 3 50344 NULL
87164 +newpart_47485 newpart 6 47485 NULL
87165 +get_info_55681 get_info 3 55681 NULL
87166 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
87167 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
87168 +core_sys_select_47494 core_sys_select 1 47494 NULL
87169 +depth_read_31112 depth_read 3 31112 NULL
87170 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
87171 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
87172 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
87173 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
87174 +unlink_simple_47506 unlink_simple 3 47506 NULL
87175 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
87176 +wdm_read_6549 wdm_read 3 6549 NULL
87177 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
87178 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
87179 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
87180 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
87181 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
87182 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
87183 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
87184 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
87185 +filter_read_61692 filter_read 3 61692 NULL
87186 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
87187 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
87188 +debugfs_read_62535 debugfs_read 3 62535 NULL
87189 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
87190 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
87191 +divas_write_63901 divas_write 3 63901 NULL
87192 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
87193 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
87194 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
87195 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
87196 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
87197 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
87198 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
87199 +ipw_write_59807 ipw_write 3 59807 NULL
87200 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
87201 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
87202 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
87203 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
87204 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
87205 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
87206 +cycx_setup_47562 cycx_setup 4 47562 NULL
87207 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
87208 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
87209 +set_local_name_55757 set_local_name 4 55757 NULL
87210 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
87211 +read_ldt_47570 read_ldt 2 47570 NULL
87212 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
87213 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
87214 +pci_iomap_47575 pci_iomap 3 47575 NULL
87215 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
87216 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
87217 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
87218 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
87219 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
87220 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
87221 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
87222 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
87223 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
87224 +conf_read_55786 conf_read 3 55786 NULL
87225 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
87226 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
87227 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
87228 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
87229 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
87230 +user_power_read_39414 user_power_read 3 39414 NULL
87231 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
87232 +uea_request_47613 uea_request 4 47613 NULL
87233 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
87234 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
87235 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
87236 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
87237 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
87238 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
87239 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
87240 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
87241 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
87242 +kmemdup_64015 kmemdup 2 64015 NULL
87243 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
87244 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
87245 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
87246 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
87247 +oz_events_read_47535 oz_events_read 3 47535 NULL
87248 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
87249 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
87250 +sys_semop_39457 sys_semop 3 39457 NULL
87251 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
87252 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
87253 +update_pmkid_2481 update_pmkid 4 2481 NULL
87254 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
87255 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
87256 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
87257 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
87258 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
87259 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
87260 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
87261 +mpeg_read_6708 mpeg_read 3 6708 NULL
87262 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
87263 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
87264 +sky2_receive_13407 sky2_receive 2 13407 NULL
87265 +krealloc_14908 krealloc 2 14908 NULL
87266 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
87267 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
87268 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
87269 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
87270 +video_proc_write_6724 video_proc_write 3 6724 NULL
87271 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
87272 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
87273 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
87274 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
87275 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
87276 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
87277 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
87278 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
87279 +command_file_write_31318 command_file_write 3 31318 NULL
87280 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
87281 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
87282 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
87283 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
87284 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
87285 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
87286 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
87287 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
87288 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
87289 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87290 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
87291 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
87292 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
87293 +int_proc_write_39542 int_proc_write 3 39542 NULL
87294 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
87295 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
87296 +read_file_ani_23161 read_file_ani 3 23161 NULL
87297 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
87298 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
87299 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
87300 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
87301 +init_bch_64130 init_bch 1-2 64130 NULL
87302 +ioremap_23172 ioremap 1-2 23172 NULL
87303 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
87304 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
87305 +usblp_write_23178 usblp_write 3 23178 NULL
87306 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
87307 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
87308 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
87309 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
87310 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
87311 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
87312 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
87313 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
87314 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
87315 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
87316 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
87317 +get_fd_set_3866 get_fd_set 1 3866 NULL
87318 +__team_options_register_63941 __team_options_register 3 63941 NULL
87319 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
87320 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
87321 +rvmalloc_46873 rvmalloc 1 46873 NULL
87322 +vmap_15025 vmap 2 15025 NULL
87323 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
87324 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
87325 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
87326 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
87327 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
87328 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
87329 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
87330 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
87331 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
87332 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
87333 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
87334 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
87335 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
87336 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
87337 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
87338 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
87339 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
87340 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
87341 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 NULL nohasharray
87342 +set_dev_class_39645 set_dev_class 4 39645 &dm_exception_table_init_39645
87343 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
87344 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
87345 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87346 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
87347 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
87348 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
87349 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
87350 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
87351 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
87352 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
87353 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
87354 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
87355 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
87356 +doc_probe_23285 doc_probe 1 23285 NULL
87357 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
87358 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
87359 +alg_setkey_31485 alg_setkey 3 31485 NULL
87360 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
87361 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
87362 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
87363 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
87364 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
87365 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
87366 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
87367 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
87368 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
87369 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
87370 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
87371 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
87372 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
87373 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
87374 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
87375 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
87376 +timeout_read_47915 timeout_read 3 47915 NULL
87377 +hidraw_write_31536 hidraw_write 3 31536 NULL
87378 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
87379 +page_readlink_23346 page_readlink 3 23346 NULL
87380 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
87381 +comedi_write_47926 comedi_write 3 47926 NULL
87382 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
87383 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
87384 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
87385 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
87386 +usbvision_read_31555 usbvision_read 3 31555 NULL
87387 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
87388 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
87389 +request_key_async_6990 request_key_async 4 6990 NULL
87390 +map_addr_56144 map_addr 7 56144 NULL
87391 +handle_response_55951 handle_response 5 55951 NULL
87392 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
87393 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
87394 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
87395 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
87396 +osst_write_31581 osst_write 3 31581 NULL
87397 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
87398 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
87399 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
87400 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
87401 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
87402 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
87403 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
87404 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
87405 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
87406 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
87407 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
87408 +ilo_write_64378 ilo_write 3 64378 NULL
87409 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
87410 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
87411 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
87412 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
87413 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
87414 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
87415 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
87416 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
87417 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
87418 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
87419 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
87420 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
87421 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
87422 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
87423 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
87424 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
87425 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
87426 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
87427 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
87428 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
87429 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
87430 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
87431 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
87432 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
87433 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
87434 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
87435 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
87436 +__lgread_31668 __lgread 4 31668 NULL
87437 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
87438 +fd_copyin_56247 fd_copyin 3 56247 NULL
87439 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
87440 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
87441 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
87442 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
87443 +teiup_create_43201 teiup_create 3 43201 NULL
87444 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
87445 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
87446 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
87447 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
87448 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
87449 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
87450 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
87451 +event_filter_read_23494 event_filter_read 3 23494 NULL
87452 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
87453 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
87454 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
87455 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
87456 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
87457 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
87458 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
87459 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
87460 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
87461 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
87462 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
87463 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
87464 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
87465 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
87466 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
87467 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
87468 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
87469 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
87470 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
87471 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
87472 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
87473 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
87474 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
87475 +remove_uuid_64505 remove_uuid 4 64505 NULL
87476 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
87477 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
87478 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
87479 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
87480 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
87481 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
87482 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
87483 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
87484 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
87485 +set_discoverable_48141 set_discoverable 4 48141 NULL
87486 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
87487 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
87488 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
87489 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
87490 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
87491 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
87492 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
87493 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
87494 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
87495 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
87496 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
87497 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
87498 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
87499 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
87500 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
87501 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
87502 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
87503 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
87504 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
87505 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
87506 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
87507 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
87508 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
87509 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
87510 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
87511 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
87512 +init_ipath_48187 init_ipath 1 48187 NULL
87513 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
87514 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
87515 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
87516 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
87517 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
87518 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
87519 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
87520 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
87521 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
87522 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
87523 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
87524 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
87525 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
87526 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
87527 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
87528 +use_pool_64607 use_pool 2 64607 NULL
87529 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
87530 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
87531 +store_msg_56417 store_msg 3 56417 NULL
87532 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87533 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
87534 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
87535 +vmalloc_15464 vmalloc 1 15464 NULL
87536 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
87537 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
87538 +fanotify_write_64623 fanotify_write 3 64623 NULL
87539 +sys_add_key_61288 sys_add_key 4 61288 NULL
87540 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
87541 +fl_create_56435 fl_create 5 56435 NULL
87542 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87543 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87544 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
87545 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
87546 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
87547 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
87548 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
87549 +set_connectable_56458 set_connectable 4 56458 NULL
87550 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
87551 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
87552 +add_port_54941 add_port 2 54941 NULL
87553 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
87554 +cx18_read_23699 cx18_read 3 23699 NULL
87555 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
87556 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
87557 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
87558 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
87559 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
87560 +send_set_info_48288 send_set_info 7 48288 NULL
87561 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
87562 +sg_read_25799 sg_read 3 25799 NULL
87563 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
87564 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
87565 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
87566 +new_dir_31919 new_dir 3 31919 NULL
87567 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
87568 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
87569 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
87570 +mgmt_control_7349 mgmt_control 3 7349 NULL
87571 +hash_setkey_48310 hash_setkey 3 48310 NULL
87572 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
87573 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
87574 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
87575 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
87576 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
87577 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
87578 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
87579 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
87580 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
87581 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
87582 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
87583 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
87584 +smk_user_access_24440 smk_user_access 3 24440 NULL
87585 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
87586 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
87587 +ip_options_get_56538 ip_options_get 4 56538 NULL
87588 +ep0_read_38095 ep0_read 3 38095 NULL
87589 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
87590 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
87591 +vme_user_write_15587 vme_user_write 3 15587 NULL
87592 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
87593 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
87594 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
87595 +skb_add_data_48363 skb_add_data 3 48363 NULL
87596 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
87597 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
87598 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
87599 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
87600 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
87601 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
87602 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
87603 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
87604 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
87605 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
87606 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
87607 +calc_hmac_32010 calc_hmac 3 32010 NULL
87608 +system_enable_read_25815 system_enable_read 3 25815 NULL
87609 +allocate_probes_40204 allocate_probes 1 40204 NULL
87610 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
87611 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
87612 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
87613 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
87614 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
87615 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
87616 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
87617 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
87618 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
87619 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
87620 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
87621 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
87622 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
87623 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
87624 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
87625 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
87626 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
87627 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87628 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
87629 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
87630 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
87631 +osst_read_40237 osst_read 3 40237 NULL
87632 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
87633 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
87634 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
87635 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
87636 +unifi_read_14899 unifi_read 3 14899 NULL
87637 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
87638 +dm_read_15674 dm_read 3 15674 NULL
87639 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
87640 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
87641 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
87642 +gather_array_56641 gather_array 3 56641 NULL
87643 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
87644 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
87645 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
87646 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
87647 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
87648 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
87649 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
87650 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
87651 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
87652 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
87653 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
87654 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
87655 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
87656 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
87657 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
87658 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
87659 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
87660 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
87661 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
87662 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
87663 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
87664 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
87665 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
87666 +send_control_msg_48498 send_control_msg 6 48498 NULL
87667 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
87668 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
87669 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
87670 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
87671 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
87672 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
87673 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
87674 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
87675 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
87676 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
87677 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
87678 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
87679 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
87680 +alloc_tx_32143 alloc_tx 2 32143 NULL
87681 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
87682 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
87683 +hsc_write_55875 hsc_write 3 55875 NULL
87684 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
87685 +do_test_15766 do_test 1 15766 NULL
87686 +mmio_read_40348 mmio_read 4 40348 NULL
87687 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
87688 +named_distribute_48544 named_distribute 4 48544 NULL
87689 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
87690 +venus_link_32165 venus_link 5 32165 NULL
87691 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
87692 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
87693 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
87694 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
87695 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
87696 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
87697 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
87698 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
87699 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
87700 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
87701 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
87702 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
87703 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
87704 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
87705 +tunables_read_36385 tunables_read 3 36385 NULL
87706 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
87707 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
87708 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
87709 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
87710 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
87711 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
87712 +snapshot_write_28351 snapshot_write 3 28351 NULL
87713 +event_enable_read_7074 event_enable_read 3 7074 NULL
87714 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
87715 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
87716 +do_syslog_56807 do_syslog 3 56807 NULL
87717 +pskb_pull_65005 pskb_pull 2 65005 NULL
87718 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
87719 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
87720 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
87721 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
87722 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
87723 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
87724 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
87725 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
87726 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
87727 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
87728 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
87729 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
87730 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
87731 +if_write_51756 if_write 3 51756 NULL
87732 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
87733 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
87734 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
87735 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
87736 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
87737 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
87738 +lc_create_48662 lc_create 3 48662 NULL
87739 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
87740 +dev_write_7708 dev_write 3 7708 NULL
87741 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
87742 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87743 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
87744 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
87745 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
87746 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
87747 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
87748 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
87749 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
87750 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
87751 +altera_drscan_48698 altera_drscan 2 48698 NULL
87752 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
87753 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
87754 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
87755 +power_read_15939 power_read 3 15939 NULL
87756 +recv_msg_48709 recv_msg 4 48709 NULL
87757 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
87758 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
87759 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
87760 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
87761 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
87762 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87763 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
87764 +revalidate_19043 revalidate 2 19043 NULL
87765 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
87766 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
87767 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
87768 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
87769 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
87770 +check_header_56930 check_header 2 56930 NULL
87771 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
87772 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
87773 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
87774 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
87775 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
87776 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
87777 +frame_alloc_15981 frame_alloc 4 15981 NULL
87778 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
87779 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
87780 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
87781 +adu_read_24177 adu_read 3 24177 NULL
87782 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
87783 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
87784 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
87785 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
87786 +vfd_write_14717 vfd_write 3 14717 NULL
87787 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
87788 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
87789 +read_file_queue_40895 read_file_queue 3 40895 NULL
87790 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
87791 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
87792 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
87793 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
87794 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
87795 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
87796 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
87797 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
87798 +register_device_60015 register_device 2-3 60015 NULL
87799 +got_frame_16028 got_frame 2 16028 NULL
87800 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
87801 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
87802 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
87803 +waiters_read_40902 waiters_read 3 40902 NULL
87804 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
87805 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
87806 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
87807 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
87808 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
87809 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
87810 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
87811 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
87812 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
87813 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
87814 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
87815 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
87816 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
87817 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
87818 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
87819 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
87820 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
87821 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
87822 +fops_read_40672 fops_read 3 40672 NULL
87823 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
87824 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
87825 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
87826 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
87827 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
87828 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
87829 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
87830 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
87831 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
87832 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
87833 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
87834 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
87835 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
87836 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
87837 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
87838 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
87839 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
87840 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
87841 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
87842 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
87843 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
87844 +fsm_init_16134 fsm_init 2 16134 NULL
87845 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
87846 +disconnect_32521 disconnect 4 32521 NULL
87847 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
87848 +pp_write_39554 pp_write 3 39554 NULL
87849 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
87850 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
87851 +ilo_read_32531 ilo_read 3 32531 NULL
87852 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
87853 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
87854 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
87855 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
87856 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
87857 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
87858 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
87859 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
87860 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
87861 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
87862 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
87863 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
87864 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
87865 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
87866 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
87867 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
87868 +card_send_command_40757 card_send_command 3 40757 NULL
87869 +sys_mbind_7990 sys_mbind 5 7990 NULL
87870 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
87871 +pg_write_40766 pg_write 3 40766 NULL
87872 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
87873 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
87874 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
87875 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
87876 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
87877 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
87878 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
87879 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
87880 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
87881 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
87882 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
87883 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
87884 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
87885 +vcs_read_8017 vcs_read 3 8017 NULL
87886 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
87887 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
87888 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
87889 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
87890 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
87891 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
87892 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
87893 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
87894 +copy_and_check_19089 copy_and_check 3 19089 NULL
87895 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
87896 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
87897 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
87898 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
87899 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
87900 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
87901 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
87902 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
87903 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
87904 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
87905 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
87906 +xd_rw_49020 xd_rw 3-4 49020 NULL
87907 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
87908 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
87909 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
87910 +kvmalloc_32646 kvmalloc 1 32646 NULL
87911 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
87912 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
87913 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
87914 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
87915 +generic_readlink_32654 generic_readlink 3 32654 NULL
87916 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
87917 +rbd_add_16366 rbd_add 3 16366 NULL
87918 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
87919 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
87920 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
87921 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
87922 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
87923 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
87924 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
87925 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
87926 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
87927 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
87928 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
87929 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
87930 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
87931 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
87932 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
87933 +venus_lookup_8121 venus_lookup 4 8121 NULL
87934 +compat_writev_60063 compat_writev 3 60063 NULL
87935 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
87936 +pd_video_read_24510 pd_video_read 3 24510 NULL
87937 +read_buf_20469 read_buf 2 20469 NULL
87938 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
87939 +scsi_register_49094 scsi_register 2 49094 NULL
87940 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
87941 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
87942 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
87943 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
87944 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
87945 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
87946 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
87947 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
87948 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
87949 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
87950 +alloc_dr_65495 alloc_dr 2 65495 NULL
87951 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
87952 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
87953 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
87954 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
87955 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
87956 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
87957 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
87958 +pt_read_49136 pt_read 3 49136 NULL
87959 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
87960 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
87961 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
87962 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
87963 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
87964 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
87965 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87966 new file mode 100644
87967 index 0000000..6387ddc
87968 --- /dev/null
87969 +++ b/tools/gcc/size_overflow_plugin.c
87970 @@ -0,0 +1,1918 @@
87971 +/*
87972 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87973 + * Licensed under the GPL v2, or (at your option) v3
87974 + *
87975 + * Homepage:
87976 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87977 + *
87978 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87979 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87980 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87981 + *
87982 + * Usage:
87983 + * $ gcc -I`gcc -print-file-name=plugin`/include/c-family -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -ggdb -Wall -W -Wno-missing-field-initializers -o size_overflow_plugin.so size_overflow_plugin.c
87984 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87985 + */
87986 +
87987 +#include "gcc-plugin.h"
87988 +#include "config.h"
87989 +#include "system.h"
87990 +#include "coretypes.h"
87991 +#include "tree.h"
87992 +#include "tree-pass.h"
87993 +#include "intl.h"
87994 +#include "plugin-version.h"
87995 +#include "tm.h"
87996 +#include "toplev.h"
87997 +#include "function.h"
87998 +#include "tree-flow.h"
87999 +#include "plugin.h"
88000 +#include "gimple.h"
88001 +#include "c-common.h"
88002 +#include "diagnostic.h"
88003 +#include "cfgloop.h"
88004 +
88005 +#if BUILDING_GCC_VERSION >= 4007
88006 +#include "c-tree.h"
88007 +#else
88008 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
88009 +#endif
88010 +
88011 +struct size_overflow_hash {
88012 + const struct size_overflow_hash * const next;
88013 + const char * const name;
88014 + const unsigned int param;
88015 +};
88016 +
88017 +#include "size_overflow_hash.h"
88018 +
88019 +enum marked {
88020 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
88021 +};
88022 +
88023 +#define __unused __attribute__((__unused__))
88024 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
88025 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
88026 +#define BEFORE_STMT true
88027 +#define AFTER_STMT false
88028 +#define CREATE_NEW_VAR NULL_TREE
88029 +#define CODES_LIMIT 32
88030 +#define MAX_PARAM 32
88031 +#define MY_STMT GF_PLF_1
88032 +#define NO_CAST_CHECK GF_PLF_2
88033 +
88034 +#if BUILDING_GCC_VERSION == 4005
88035 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
88036 +#endif
88037 +
88038 +int plugin_is_GPL_compatible;
88039 +void debug_gimple_stmt(gimple gs);
88040 +
88041 +static tree expand(struct pointer_set_t *visited, tree lhs);
88042 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
88043 +static tree report_size_overflow_decl;
88044 +static const_tree const_char_ptr_type_node;
88045 +static unsigned int handle_function(void);
88046 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
88047 +static tree get_size_overflow_type(gimple stmt, const_tree node);
88048 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
88049 +
88050 +static unsigned int call_count=0;
88051 +
88052 +static struct plugin_info size_overflow_plugin_info = {
88053 + .version = "20121212beta",
88054 + .help = "no-size-overflow\tturn off size overflow checking\n",
88055 +};
88056 +
88057 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
88058 +{
88059 + unsigned int arg_count;
88060 + enum tree_code code = TREE_CODE(*node);
88061 +
88062 + switch (code) {
88063 + case FUNCTION_DECL:
88064 + arg_count = type_num_arguments(TREE_TYPE(*node));
88065 + break;
88066 + case FUNCTION_TYPE:
88067 + case METHOD_TYPE:
88068 + arg_count = type_num_arguments(*node);
88069 + break;
88070 + default:
88071 + *no_add_attrs = true;
88072 + error("%s: %qE attribute only applies to functions", __func__, name);
88073 + return NULL_TREE;
88074 + }
88075 +
88076 + for (; args; args = TREE_CHAIN(args)) {
88077 + tree position = TREE_VALUE(args);
88078 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
88079 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
88080 + *no_add_attrs = true;
88081 + }
88082 + }
88083 + return NULL_TREE;
88084 +}
88085 +
88086 +static const char* get_asm_name(tree node)
88087 +{
88088 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
88089 +}
88090 +
88091 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
88092 +{
88093 + unsigned int arg_count, arg_num;
88094 + enum tree_code code = TREE_CODE(*node);
88095 +
88096 + switch (code) {
88097 + case FUNCTION_DECL:
88098 + arg_count = type_num_arguments(TREE_TYPE(*node));
88099 + break;
88100 + case FUNCTION_TYPE:
88101 + case METHOD_TYPE:
88102 + arg_count = type_num_arguments(*node);
88103 + break;
88104 + case FIELD_DECL:
88105 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
88106 + if (arg_num != 0) {
88107 + *no_add_attrs = true;
88108 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
88109 + }
88110 + return NULL_TREE;
88111 + default:
88112 + *no_add_attrs = true;
88113 + error("%qE attribute only applies to functions", name);
88114 + return NULL_TREE;
88115 + }
88116 +
88117 + for (; args; args = TREE_CHAIN(args)) {
88118 + tree position = TREE_VALUE(args);
88119 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
88120 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
88121 + *no_add_attrs = true;
88122 + }
88123 + }
88124 + return NULL_TREE;
88125 +}
88126 +
88127 +static struct attribute_spec size_overflow_attr = {
88128 + .name = "size_overflow",
88129 + .min_length = 1,
88130 + .max_length = -1,
88131 + .decl_required = true,
88132 + .type_required = false,
88133 + .function_type_required = false,
88134 + .handler = handle_size_overflow_attribute,
88135 +#if BUILDING_GCC_VERSION >= 4007
88136 + .affects_type_identity = false
88137 +#endif
88138 +};
88139 +
88140 +static struct attribute_spec intentional_overflow_attr = {
88141 + .name = "intentional_overflow",
88142 + .min_length = 1,
88143 + .max_length = -1,
88144 + .decl_required = true,
88145 + .type_required = false,
88146 + .function_type_required = false,
88147 + .handler = handle_intentional_overflow_attribute,
88148 +#if BUILDING_GCC_VERSION >= 4007
88149 + .affects_type_identity = false
88150 +#endif
88151 +};
88152 +
88153 +static void register_attributes(void __unused *event_data, void __unused *data)
88154 +{
88155 + register_attribute(&size_overflow_attr);
88156 + register_attribute(&intentional_overflow_attr);
88157 +}
88158 +
88159 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
88160 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
88161 +{
88162 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
88163 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
88164 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
88165 +
88166 + unsigned int m = 0x57559429;
88167 + unsigned int n = 0x5052acdb;
88168 + const unsigned int *key4 = (const unsigned int *)key;
88169 + unsigned int h = len;
88170 + unsigned int k = len + seed + n;
88171 + unsigned long long p;
88172 +
88173 + while (len >= 8) {
88174 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
88175 + len -= 8;
88176 + }
88177 + if (len >= 4) {
88178 + cwmixb(key4[0]) key4 += 1;
88179 + len -= 4;
88180 + }
88181 + if (len)
88182 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
88183 + cwmixb(h ^ (k + n));
88184 + return k ^ h;
88185 +
88186 +#undef cwfold
88187 +#undef cwmixa
88188 +#undef cwmixb
88189 +}
88190 +
88191 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
88192 +{
88193 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
88194 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
88195 + return fn ^ codes;
88196 +}
88197 +
88198 +static inline tree get_original_function_decl(tree fndecl)
88199 +{
88200 + if (DECL_ABSTRACT_ORIGIN(fndecl))
88201 + return DECL_ABSTRACT_ORIGIN(fndecl);
88202 + return fndecl;
88203 +}
88204 +
88205 +static inline gimple get_def_stmt(const_tree node)
88206 +{
88207 + gcc_assert(node != NULL_TREE);
88208 + gcc_assert(TREE_CODE(node) == SSA_NAME);
88209 + return SSA_NAME_DEF_STMT(node);
88210 +}
88211 +
88212 +static unsigned char get_tree_code(const_tree type)
88213 +{
88214 + switch (TREE_CODE(type)) {
88215 + case ARRAY_TYPE:
88216 + return 0;
88217 + case BOOLEAN_TYPE:
88218 + return 1;
88219 + case ENUMERAL_TYPE:
88220 + return 2;
88221 + case FUNCTION_TYPE:
88222 + return 3;
88223 + case INTEGER_TYPE:
88224 + return 4;
88225 + case POINTER_TYPE:
88226 + return 5;
88227 + case RECORD_TYPE:
88228 + return 6;
88229 + case UNION_TYPE:
88230 + return 7;
88231 + case VOID_TYPE:
88232 + return 8;
88233 + case REAL_TYPE:
88234 + return 9;
88235 + case VECTOR_TYPE:
88236 + return 10;
88237 + case REFERENCE_TYPE:
88238 + return 11;
88239 + case OFFSET_TYPE:
88240 + return 12;
88241 + case COMPLEX_TYPE:
88242 + return 13;
88243 + default:
88244 + debug_tree((tree)type);
88245 + gcc_unreachable();
88246 + }
88247 +}
88248 +
88249 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
88250 +{
88251 + gcc_assert(type != NULL_TREE);
88252 +
88253 + while (type && len < CODES_LIMIT) {
88254 + tree_codes[len] = get_tree_code(type);
88255 + len++;
88256 + type = TREE_TYPE(type);
88257 + }
88258 + return len;
88259 +}
88260 +
88261 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
88262 +{
88263 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
88264 + enum tree_code code = TREE_CODE(type);
88265 + size_t len = 0;
88266 +
88267 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
88268 +
88269 + arg = TYPE_ARG_TYPES(type);
88270 + // skip builtins __builtin_constant_p
88271 + if (!arg && DECL_BUILT_IN(fndecl))
88272 + return 0;
88273 +
88274 + if (TREE_CODE_CLASS(code) == tcc_type)
88275 + result = type;
88276 + else
88277 + result = DECL_RESULT(fndecl);
88278 +
88279 + gcc_assert(result != NULL_TREE);
88280 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
88281 +
88282 + if (arg == NULL_TREE) {
88283 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
88284 + arg_field = DECL_ARGUMENT_FLD(fndecl);
88285 + if (arg_field == NULL_TREE)
88286 + return 0;
88287 + arg = TREE_TYPE(arg_field);
88288 + len = add_type_codes(arg, tree_codes, len);
88289 + gcc_assert(len != 0);
88290 + return len;
88291 + }
88292 +
88293 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
88294 + while (arg && len < CODES_LIMIT) {
88295 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
88296 + arg = TREE_CHAIN(arg);
88297 + }
88298 +
88299 + gcc_assert(len != 0);
88300 + return len;
88301 +}
88302 +
88303 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
88304 +{
88305 + unsigned int hash;
88306 + const struct size_overflow_hash *entry;
88307 + unsigned char tree_codes[CODES_LIMIT];
88308 + size_t len;
88309 + const char *func_name = get_asm_name(fndecl);
88310 +
88311 + len = get_function_decl(fndecl, tree_codes);
88312 + if (len == 0)
88313 + return NULL;
88314 +
88315 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88316 +
88317 + entry = size_overflow_hash[hash];
88318 + while (entry) {
88319 + if (!strcmp(entry->name, func_name))
88320 + return entry;
88321 + entry = entry->next;
88322 + }
88323 +
88324 + return NULL;
88325 +}
88326 +
88327 +static void check_arg_type(const_tree arg)
88328 +{
88329 + const_tree type = TREE_TYPE(arg);
88330 + enum tree_code code = TREE_CODE(type);
88331 +
88332 + if (code == BOOLEAN_TYPE)
88333 + return;
88334 +
88335 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88336 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88337 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88338 +}
88339 +
88340 +static int find_arg_number(const_tree arg, tree func)
88341 +{
88342 + tree var;
88343 + unsigned int argnum = 1;
88344 +
88345 + if (TREE_CODE(arg) == SSA_NAME)
88346 + arg = SSA_NAME_VAR(arg);
88347 +
88348 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88349 + if (strcmp(NAME(arg), NAME(var))) {
88350 + argnum++;
88351 + continue;
88352 + }
88353 + check_arg_type(var);
88354 + return argnum;
88355 + }
88356 + gcc_unreachable();
88357 +}
88358 +
88359 +static tree create_new_var(tree type)
88360 +{
88361 + tree new_var = create_tmp_var(type, "cicus");
88362 +
88363 + add_referenced_var(new_var);
88364 + mark_sym_for_renaming(new_var);
88365 + return new_var;
88366 +}
88367 +
88368 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88369 +{
88370 + gimple assign;
88371 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88372 + tree type = TREE_TYPE(rhs1);
88373 + tree lhs = create_new_var(type);
88374 +
88375 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
88376 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88377 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88378 +
88379 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88380 + update_stmt(assign);
88381 + gimple_set_plf(assign, MY_STMT, true);
88382 + return assign;
88383 +}
88384 +
88385 +static bool is_bool(const_tree node)
88386 +{
88387 + const_tree type;
88388 +
88389 + if (node == NULL_TREE)
88390 + return false;
88391 +
88392 + type = TREE_TYPE(node);
88393 + if (!INTEGRAL_TYPE_P(type))
88394 + return false;
88395 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88396 + return true;
88397 + if (TYPE_PRECISION(type) == 1)
88398 + return true;
88399 + return false;
88400 +}
88401 +
88402 +static tree cast_a_tree(tree type, tree var)
88403 +{
88404 + gcc_assert(type != NULL_TREE);
88405 + gcc_assert(var != NULL_TREE);
88406 + gcc_assert(fold_convertible_p(type, var));
88407 +
88408 + return fold_convert(type, var);
88409 +}
88410 +
88411 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88412 +{
88413 + gimple assign;
88414 +
88415 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88416 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88417 + gcc_unreachable();
88418 +
88419 + if (lhs == CREATE_NEW_VAR)
88420 + lhs = create_new_var(dst_type);
88421 +
88422 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88423 +
88424 + if (!gsi_end_p(*gsi)) {
88425 + location_t loc = gimple_location(gsi_stmt(*gsi));
88426 + gimple_set_location(assign, loc);
88427 + }
88428 +
88429 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88430 +
88431 + if (before)
88432 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88433 + else
88434 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88435 + update_stmt(assign);
88436 + gimple_set_plf(assign, MY_STMT, true);
88437 +
88438 + return assign;
88439 +}
88440 +
88441 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
88442 +{
88443 + gimple assign;
88444 + gimple_stmt_iterator gsi;
88445 +
88446 + if (rhs == NULL_TREE)
88447 + return NULL_TREE;
88448 +
88449 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
88450 + return rhs;
88451 +
88452 + gsi = gsi_for_stmt(stmt);
88453 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
88454 + gimple_set_plf(assign, MY_STMT, true);
88455 + return gimple_get_lhs(assign);
88456 +}
88457 +
88458 +static tree cast_to_TI_type(gimple stmt, tree node)
88459 +{
88460 + gimple_stmt_iterator gsi;
88461 + gimple cast_stmt;
88462 + tree type = TREE_TYPE(node);
88463 +
88464 + if (types_compatible_p(type, intTI_type_node))
88465 + return node;
88466 +
88467 + gsi = gsi_for_stmt(stmt);
88468 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88469 + gimple_set_plf(cast_stmt, MY_STMT, true);
88470 + return gimple_get_lhs(cast_stmt);
88471 +}
88472 +
88473 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88474 +{
88475 + tree lhs;
88476 + gimple_stmt_iterator gsi;
88477 +
88478 + if (rhs1 == NULL_TREE) {
88479 + debug_gimple_stmt(oldstmt);
88480 + error("%s: rhs1 is NULL_TREE", __func__);
88481 + gcc_unreachable();
88482 + }
88483 +
88484 + switch (gimple_code(oldstmt)) {
88485 + case GIMPLE_ASM:
88486 + lhs = rhs1;
88487 + break;
88488 + case GIMPLE_CALL:
88489 + lhs = gimple_call_lhs(oldstmt);
88490 + break;
88491 + case GIMPLE_ASSIGN:
88492 + lhs = gimple_get_lhs(oldstmt);
88493 + break;
88494 + default:
88495 + debug_gimple_stmt(oldstmt);
88496 + gcc_unreachable();
88497 + }
88498 +
88499 + gsi = gsi_for_stmt(oldstmt);
88500 + pointer_set_insert(visited, oldstmt);
88501 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88502 + basic_block next_bb, cur_bb;
88503 + const_edge e;
88504 +
88505 + gcc_assert(before == false);
88506 + gcc_assert(stmt_can_throw_internal(oldstmt));
88507 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88508 + gcc_assert(!gsi_end_p(gsi));
88509 +
88510 + cur_bb = gimple_bb(oldstmt);
88511 + next_bb = cur_bb->next_bb;
88512 + e = find_edge(cur_bb, next_bb);
88513 + gcc_assert(e != NULL);
88514 + gcc_assert(e->flags & EDGE_FALLTHRU);
88515 +
88516 + gsi = gsi_after_labels(next_bb);
88517 + gcc_assert(!gsi_end_p(gsi));
88518 +
88519 + before = true;
88520 + oldstmt = gsi_stmt(gsi);
88521 + }
88522 +
88523 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
88524 +}
88525 +
88526 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
88527 +{
88528 + gimple stmt;
88529 + gimple_stmt_iterator gsi;
88530 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
88531 +
88532 + if (gimple_plf(oldstmt, MY_STMT))
88533 + return lhs;
88534 +
88535 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88536 + rhs1 = gimple_assign_rhs1(oldstmt);
88537 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88538 + }
88539 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88540 + rhs2 = gimple_assign_rhs2(oldstmt);
88541 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88542 + }
88543 +
88544 + stmt = gimple_copy(oldstmt);
88545 + gimple_set_location(stmt, gimple_location(oldstmt));
88546 + gimple_set_plf(stmt, MY_STMT, true);
88547 +
88548 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88549 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88550 +
88551 + size_overflow_type = get_size_overflow_type(oldstmt, node);
88552 +
88553 + if (is_bool(lhs))
88554 + new_var = SSA_NAME_VAR(lhs);
88555 + else
88556 + new_var = create_new_var(size_overflow_type);
88557 + new_var = make_ssa_name(new_var, stmt);
88558 + gimple_set_lhs(stmt, new_var);
88559 +
88560 + if (rhs1 != NULL_TREE)
88561 + gimple_assign_set_rhs1(stmt, rhs1);
88562 +
88563 + if (rhs2 != NULL_TREE)
88564 + gimple_assign_set_rhs2(stmt, rhs2);
88565 +#if BUILDING_GCC_VERSION >= 4007
88566 + if (rhs3 != NULL_TREE)
88567 + gimple_assign_set_rhs3(stmt, rhs3);
88568 +#endif
88569 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88570 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88571 +
88572 + gsi = gsi_for_stmt(oldstmt);
88573 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88574 + update_stmt(stmt);
88575 + pointer_set_insert(visited, oldstmt);
88576 + return gimple_get_lhs(stmt);
88577 +}
88578 +
88579 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88580 +{
88581 + basic_block bb;
88582 + gimple phi;
88583 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88584 +
88585 + bb = gsi_bb(gsi);
88586 +
88587 + phi = create_phi_node(result, bb);
88588 + gsi = gsi_last(phi_nodes(bb));
88589 + gsi_remove(&gsi, false);
88590 +
88591 + gsi = gsi_for_stmt(oldstmt);
88592 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88593 + gimple_set_bb(phi, bb);
88594 + gimple_set_plf(phi, MY_STMT, true);
88595 + return phi;
88596 +}
88597 +
88598 +static basic_block create_a_first_bb(void)
88599 +{
88600 + basic_block first_bb;
88601 +
88602 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88603 + if (dom_info_available_p(CDI_DOMINATORS))
88604 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88605 + return first_bb;
88606 +}
88607 +
88608 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88609 +{
88610 + basic_block bb;
88611 + const_gimple newstmt;
88612 + gimple_stmt_iterator gsi;
88613 + bool before = BEFORE_STMT;
88614 +
88615 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88616 + gsi = gsi_for_stmt(get_def_stmt(arg));
88617 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88618 + return gimple_get_lhs(newstmt);
88619 + }
88620 +
88621 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88622 + gsi = gsi_after_labels(bb);
88623 + if (bb->index == 0) {
88624 + bb = create_a_first_bb();
88625 + gsi = gsi_start_bb(bb);
88626 + }
88627 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88628 + return gimple_get_lhs(newstmt);
88629 +}
88630 +
88631 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88632 +{
88633 + gimple newstmt;
88634 + gimple_stmt_iterator gsi;
88635 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88636 + gimple def_newstmt = get_def_stmt(new_rhs);
88637 +
88638 + gsi_insert = gsi_insert_after;
88639 + gsi = gsi_for_stmt(def_newstmt);
88640 +
88641 + switch (gimple_code(get_def_stmt(arg))) {
88642 + case GIMPLE_PHI:
88643 + newstmt = gimple_build_assign(new_var, new_rhs);
88644 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88645 + gsi_insert = gsi_insert_before;
88646 + break;
88647 + case GIMPLE_ASM:
88648 + case GIMPLE_CALL:
88649 + newstmt = gimple_build_assign(new_var, new_rhs);
88650 + break;
88651 + case GIMPLE_ASSIGN:
88652 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88653 + break;
88654 + default:
88655 + /* unknown gimple_code (handle_build_new_phi_arg) */
88656 + gcc_unreachable();
88657 + }
88658 +
88659 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88660 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88661 + gimple_set_plf(newstmt, MY_STMT, true);
88662 + update_stmt(newstmt);
88663 + return newstmt;
88664 +}
88665 +
88666 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88667 +{
88668 + const_gimple newstmt;
88669 + gimple def_stmt;
88670 + tree new_rhs;
88671 +
88672 + new_rhs = expand(visited, arg);
88673 + if (new_rhs == NULL_TREE)
88674 + return NULL_TREE;
88675 +
88676 + def_stmt = get_def_stmt(new_rhs);
88677 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88678 + return NULL_TREE;
88679 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88680 +
88681 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88682 + return gimple_get_lhs(newstmt);
88683 +}
88684 +
88685 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88686 +{
88687 + gimple phi, oldstmt = get_def_stmt(orig_result);
88688 + tree new_result, size_overflow_type;
88689 + unsigned int i;
88690 + unsigned int n = gimple_phi_num_args(oldstmt);
88691 +
88692 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88693 +
88694 + new_result = create_new_var(size_overflow_type);
88695 +
88696 + pointer_set_insert(visited, oldstmt);
88697 + phi = overflow_create_phi_node(oldstmt, new_result);
88698 + for (i = 0; i < n; i++) {
88699 + tree arg, lhs;
88700 +
88701 + arg = gimple_phi_arg_def(oldstmt, i);
88702 + if (is_gimple_constant(arg))
88703 + arg = cast_a_tree(size_overflow_type, arg);
88704 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88705 + if (lhs == NULL_TREE)
88706 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88707 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88708 + }
88709 +
88710 + update_stmt(phi);
88711 + return gimple_phi_result(phi);
88712 +}
88713 +
88714 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88715 +{
88716 + const_gimple assign;
88717 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88718 + tree origtype = TREE_TYPE(orig_rhs);
88719 +
88720 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88721 +
88722 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88723 + return gimple_get_lhs(assign);
88724 +}
88725 +
88726 +static void change_rhs1(gimple stmt, tree new_rhs1)
88727 +{
88728 + tree assign_rhs;
88729 + const_tree rhs = gimple_assign_rhs1(stmt);
88730 +
88731 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88732 + gimple_assign_set_rhs1(stmt, assign_rhs);
88733 + update_stmt(stmt);
88734 +}
88735 +
88736 +static bool check_mode_type(const_gimple stmt)
88737 +{
88738 + const_tree lhs = gimple_get_lhs(stmt);
88739 + const_tree lhs_type = TREE_TYPE(lhs);
88740 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88741 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88742 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88743 +
88744 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88745 + return false;
88746 +
88747 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88748 + return false;
88749 +
88750 + return true;
88751 +}
88752 +
88753 +static bool check_undefined_integer_operation(const_gimple stmt)
88754 +{
88755 + const_gimple def_stmt;
88756 + const_tree lhs = gimple_get_lhs(stmt);
88757 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88758 + const_tree rhs1_type = TREE_TYPE(rhs1);
88759 + const_tree lhs_type = TREE_TYPE(lhs);
88760 +
88761 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88762 + return false;
88763 +
88764 + def_stmt = get_def_stmt(rhs1);
88765 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88766 + return false;
88767 +
88768 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88769 + return false;
88770 + return true;
88771 +}
88772 +
88773 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88774 +{
88775 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88776 + enum machine_mode lhs_mode, rhs_mode;
88777 + gimple def_stmt = get_def_stmt(no_const_rhs);
88778 +
88779 + if (!gimple_assign_cast_p(def_stmt))
88780 + return false;
88781 +
88782 + rhs1 = gimple_assign_rhs1(def_stmt);
88783 + lhs = gimple_get_lhs(def_stmt);
88784 + rhs1_type = TREE_TYPE(rhs1);
88785 + lhs_type = TREE_TYPE(lhs);
88786 + rhs_mode = TYPE_MODE(rhs1_type);
88787 + lhs_mode = TYPE_MODE(lhs_type);
88788 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88789 + return false;
88790 +
88791 + return true;
88792 +}
88793 +
88794 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88795 +{
88796 + gimple def_stmt;
88797 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88798 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88799 + const_tree rhs1_type = TREE_TYPE(rhs1);
88800 + const_tree lhs_type = TREE_TYPE(lhs);
88801 +
88802 + new_rhs1 = expand(visited, rhs1);
88803 +
88804 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88805 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88806 +
88807 + if (gimple_plf(stmt, MY_STMT))
88808 + return lhs;
88809 +
88810 + if (gimple_plf(stmt, NO_CAST_CHECK))
88811 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88812 +
88813 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88814 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88815 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88816 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88817 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88818 + }
88819 +
88820 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88821 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88822 +
88823 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88824 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88825 +
88826 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88827 +
88828 + rhs1 = gimple_assign_rhs1(stmt);
88829 + rhs1_type = TREE_TYPE(rhs1);
88830 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type)) {
88831 + def_stmt = get_def_stmt(new_rhs1);
88832 + rhs1 = gimple_assign_rhs1(def_stmt);
88833 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88834 + }
88835 + change_rhs1(stmt, new_rhs1);
88836 +
88837 + if (!check_mode_type(stmt))
88838 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88839 +
88840 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88841 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88842 +
88843 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88844 +
88845 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88846 +}
88847 +
88848 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
88849 +{
88850 + tree rhs1, lhs = gimple_get_lhs(stmt);
88851 + gimple def_stmt = get_def_stmt(lhs);
88852 +
88853 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
88854 + rhs1 = gimple_assign_rhs1(def_stmt);
88855 +
88856 + if (is_gimple_constant(rhs1))
88857 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88858 +
88859 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88860 + switch (TREE_CODE(rhs1)) {
88861 + case SSA_NAME:
88862 + return handle_unary_rhs(visited, def_stmt);
88863 + case ARRAY_REF:
88864 + case BIT_FIELD_REF:
88865 + case ADDR_EXPR:
88866 + case COMPONENT_REF:
88867 + case INDIRECT_REF:
88868 +#if BUILDING_GCC_VERSION >= 4006
88869 + case MEM_REF:
88870 +#endif
88871 + case TARGET_MEM_REF:
88872 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88873 + case PARM_DECL:
88874 + case VAR_DECL:
88875 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88876 +
88877 + default:
88878 + debug_gimple_stmt(def_stmt);
88879 + debug_tree(rhs1);
88880 + gcc_unreachable();
88881 + }
88882 +}
88883 +
88884 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88885 +{
88886 + gimple cond_stmt;
88887 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88888 +
88889 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88890 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88891 + update_stmt(cond_stmt);
88892 +}
88893 +
88894 +static tree create_string_param(tree string)
88895 +{
88896 + tree i_type, a_type;
88897 + const int length = TREE_STRING_LENGTH(string);
88898 +
88899 + gcc_assert(length > 0);
88900 +
88901 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88902 + a_type = build_array_type(char_type_node, i_type);
88903 +
88904 + TREE_TYPE(string) = a_type;
88905 + TREE_CONSTANT(string) = 1;
88906 + TREE_READONLY(string) = 1;
88907 +
88908 + return build1(ADDR_EXPR, ptr_type_node, string);
88909 +}
88910 +
88911 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88912 +{
88913 + gimple func_stmt;
88914 + const_gimple def_stmt;
88915 + const_tree loc_line;
88916 + tree loc_file, ssa_name, current_func;
88917 + expanded_location xloc;
88918 + char *ssa_name_buf;
88919 + int len;
88920 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88921 +
88922 + def_stmt = get_def_stmt(arg);
88923 + xloc = expand_location(gimple_location(def_stmt));
88924 +
88925 + if (!gimple_has_location(def_stmt)) {
88926 + xloc = expand_location(gimple_location(stmt));
88927 + if (!gimple_has_location(stmt))
88928 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88929 + }
88930 +
88931 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88932 +
88933 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88934 + loc_file = create_string_param(loc_file);
88935 +
88936 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88937 + current_func = create_string_param(current_func);
88938 +
88939 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
88940 + call_count++;
88941 + len = asprintf(&ssa_name_buf, "%s_%u %s, count: %u\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max", call_count);
88942 + gcc_assert(len > 0);
88943 + ssa_name = build_string(len + 1, ssa_name_buf);
88944 + free(ssa_name_buf);
88945 + ssa_name = create_string_param(ssa_name);
88946 +
88947 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88948 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88949 +
88950 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88951 +}
88952 +
88953 +static void __unused print_the_code_insertions(const_gimple stmt)
88954 +{
88955 + location_t loc = gimple_location(stmt);
88956 +
88957 + inform(loc, "Integer size_overflow check applied here.");
88958 +}
88959 +
88960 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88961 +{
88962 + basic_block cond_bb, join_bb, bb_true;
88963 + edge e;
88964 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88965 +
88966 + cond_bb = gimple_bb(stmt);
88967 + if (before)
88968 + gsi_prev(&gsi);
88969 + if (gsi_end_p(gsi))
88970 + e = split_block_after_labels(cond_bb);
88971 + else
88972 + e = split_block(cond_bb, gsi_stmt(gsi));
88973 + cond_bb = e->src;
88974 + join_bb = e->dest;
88975 + e->flags = EDGE_FALSE_VALUE;
88976 + e->probability = REG_BR_PROB_BASE;
88977 +
88978 + bb_true = create_empty_bb(cond_bb);
88979 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88980 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88981 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88982 +
88983 + if (dom_info_available_p(CDI_DOMINATORS)) {
88984 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88985 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88986 + }
88987 +
88988 + if (current_loops != NULL) {
88989 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88990 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88991 + }
88992 +
88993 + insert_cond(cond_bb, arg, cond_code, type_value);
88994 + insert_cond_result(bb_true, stmt, arg, min);
88995 +
88996 +// print_the_code_insertions(stmt);
88997 +}
88998 +
88999 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
89000 +{
89001 + const_tree rhs_type = TREE_TYPE(rhs);
89002 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
89003 +
89004 + gcc_assert(rhs_type != NULL_TREE);
89005 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
89006 + return;
89007 +
89008 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
89009 +
89010 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
89011 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
89012 +
89013 + gcc_assert(!TREE_OVERFLOW(type_max));
89014 +
89015 + cast_rhs_type = TREE_TYPE(cast_rhs);
89016 + type_max_type = TREE_TYPE(type_max);
89017 + type_min_type = TREE_TYPE(type_min);
89018 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
89019 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
89020 +
89021 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
89022 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
89023 +}
89024 +
89025 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
89026 +{
89027 + gimple change_rhs_def_stmt;
89028 + tree lhs = gimple_get_lhs(def_stmt);
89029 + tree lhs_type = TREE_TYPE(lhs);
89030 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
89031 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
89032 +
89033 + if (change_rhs == NULL_TREE)
89034 + return get_size_overflow_type(def_stmt, lhs);
89035 +
89036 + change_rhs_def_stmt = get_def_stmt(change_rhs);
89037 +
89038 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
89039 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89040 +
89041 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
89042 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89043 +
89044 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
89045 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
89046 +
89047 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
89048 + debug_gimple_stmt(def_stmt);
89049 + gcc_unreachable();
89050 + }
89051 +
89052 + return get_size_overflow_type(def_stmt, lhs);
89053 +}
89054 +
89055 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
89056 +{
89057 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
89058 + return false;
89059 + if (!is_gimple_constant(rhs))
89060 + return false;
89061 + return true;
89062 +}
89063 +
89064 +static bool is_subtraction_special(const_gimple stmt)
89065 +{
89066 + gimple rhs1_def_stmt, rhs2_def_stmt;
89067 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
89068 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
89069 + const_tree rhs1 = gimple_assign_rhs1(stmt);
89070 + const_tree rhs2 = gimple_assign_rhs2(stmt);
89071 +
89072 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
89073 + return false;
89074 +
89075 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
89076 +
89077 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
89078 + return false;
89079 +
89080 + rhs1_def_stmt = get_def_stmt(rhs1);
89081 + rhs2_def_stmt = get_def_stmt(rhs2);
89082 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
89083 + return false;
89084 +
89085 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
89086 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
89087 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
89088 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
89089 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
89090 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
89091 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
89092 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
89093 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
89094 + return false;
89095 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
89096 + return false;
89097 +
89098 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
89099 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
89100 + return true;
89101 +}
89102 +
89103 +static tree get_def_stmt_rhs(const_tree var)
89104 +{
89105 + tree rhs1, def_stmt_rhs1;
89106 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
89107 +
89108 + def_stmt = get_def_stmt(var);
89109 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
89110 +
89111 + rhs1 = gimple_assign_rhs1(def_stmt);
89112 + rhs1_def_stmt = get_def_stmt(rhs1);
89113 + gcc_assert(gimple_code(rhs1_def_stmt) != GIMPLE_NOP);
89114 + if (!gimple_assign_cast_p(rhs1_def_stmt))
89115 + return rhs1;
89116 +
89117 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
89118 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
89119 +
89120 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
89121 + case GIMPLE_CALL:
89122 + case GIMPLE_NOP:
89123 + case GIMPLE_ASM:
89124 + return def_stmt_rhs1;
89125 + case GIMPLE_ASSIGN:
89126 + return rhs1;
89127 + default:
89128 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
89129 + gcc_unreachable();
89130 + }
89131 +}
89132 +
89133 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
89134 +{
89135 + tree new_rhs1, new_rhs2;
89136 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
89137 + gimple assign, stmt = get_def_stmt(lhs);
89138 + tree rhs1 = gimple_assign_rhs1(stmt);
89139 + tree rhs2 = gimple_assign_rhs2(stmt);
89140 +
89141 + if (!is_subtraction_special(stmt))
89142 + return NULL_TREE;
89143 +
89144 + new_rhs1 = expand(visited, rhs1);
89145 + new_rhs2 = expand(visited, rhs2);
89146 +
89147 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
89148 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
89149 +
89150 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
89151 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
89152 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
89153 + }
89154 +
89155 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
89156 + new_lhs = gimple_get_lhs(assign);
89157 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
89158 +
89159 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89160 +}
89161 +
89162 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
89163 +{
89164 + const_gimple def_stmt;
89165 +
89166 + if (TREE_CODE(rhs) != SSA_NAME)
89167 + return false;
89168 +
89169 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
89170 + return false;
89171 +
89172 + def_stmt = get_def_stmt(rhs);
89173 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
89174 + return false;
89175 +
89176 + return true;
89177 +}
89178 +
89179 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
89180 +{
89181 + tree new_rhs, size_overflow_type, orig_rhs;
89182 + void (*gimple_assign_set_rhs)(gimple, tree);
89183 + tree rhs1 = gimple_assign_rhs1(stmt);
89184 + tree rhs2 = gimple_assign_rhs2(stmt);
89185 + tree lhs = gimple_get_lhs(stmt);
89186 +
89187 + if (change_rhs == NULL_TREE)
89188 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89189 +
89190 + if (new_rhs2 == NULL_TREE) {
89191 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
89192 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
89193 + orig_rhs = rhs1;
89194 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
89195 + } else {
89196 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
89197 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
89198 + orig_rhs = rhs2;
89199 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
89200 + }
89201 +
89202 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
89203 +
89204 + if (check_overflow)
89205 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
89206 +
89207 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
89208 + gimple_assign_set_rhs(stmt, new_rhs);
89209 + update_stmt(stmt);
89210 +
89211 + return create_assign(visited, stmt, lhs, AFTER_STMT);
89212 +}
89213 +
89214 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
89215 +{
89216 + tree rhs1, rhs2, new_lhs;
89217 + gimple def_stmt = get_def_stmt(lhs);
89218 + tree new_rhs1 = NULL_TREE;
89219 + tree new_rhs2 = NULL_TREE;
89220 +
89221 + rhs1 = gimple_assign_rhs1(def_stmt);
89222 + rhs2 = gimple_assign_rhs2(def_stmt);
89223 +
89224 + /* no DImode/TImode division in the 32/64 bit kernel */
89225 + switch (gimple_assign_rhs_code(def_stmt)) {
89226 + case RDIV_EXPR:
89227 + case TRUNC_DIV_EXPR:
89228 + case CEIL_DIV_EXPR:
89229 + case FLOOR_DIV_EXPR:
89230 + case ROUND_DIV_EXPR:
89231 + case TRUNC_MOD_EXPR:
89232 + case CEIL_MOD_EXPR:
89233 + case FLOOR_MOD_EXPR:
89234 + case ROUND_MOD_EXPR:
89235 + case EXACT_DIV_EXPR:
89236 + case POINTER_PLUS_EXPR:
89237 + case BIT_AND_EXPR:
89238 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89239 + default:
89240 + break;
89241 + }
89242 +
89243 + new_lhs = handle_integer_truncation(visited, lhs);
89244 + if (new_lhs != NULL_TREE)
89245 + return new_lhs;
89246 +
89247 + if (TREE_CODE(rhs1) == SSA_NAME)
89248 + new_rhs1 = expand(visited, rhs1);
89249 + if (TREE_CODE(rhs2) == SSA_NAME)
89250 + new_rhs2 = expand(visited, rhs2);
89251 +
89252 + if (is_a_neg_overflow(def_stmt, rhs2))
89253 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89254 + if (is_a_neg_overflow(def_stmt, rhs1))
89255 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89256 +
89257 + if (is_a_constant_overflow(def_stmt, rhs2))
89258 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
89259 + if (is_a_constant_overflow(def_stmt, rhs1))
89260 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
89261 +
89262 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
89263 +}
89264 +
89265 +#if BUILDING_GCC_VERSION >= 4007
89266 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
89267 +{
89268 + if (is_gimple_constant(rhs))
89269 + return cast_a_tree(size_overflow_type, rhs);
89270 + if (TREE_CODE(rhs) != SSA_NAME)
89271 + return NULL_TREE;
89272 + return expand(visited, rhs);
89273 +}
89274 +
89275 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
89276 +{
89277 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
89278 + gimple def_stmt = get_def_stmt(lhs);
89279 +
89280 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
89281 +
89282 + rhs1 = gimple_assign_rhs1(def_stmt);
89283 + rhs2 = gimple_assign_rhs2(def_stmt);
89284 + rhs3 = gimple_assign_rhs3(def_stmt);
89285 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
89286 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
89287 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
89288 +
89289 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
89290 +}
89291 +#endif
89292 +
89293 +static tree get_size_overflow_type(gimple stmt, const_tree node)
89294 +{
89295 + const_tree type;
89296 + tree new_type;
89297 +
89298 + gcc_assert(node != NULL_TREE);
89299 +
89300 + type = TREE_TYPE(node);
89301 +
89302 + if (gimple_plf(stmt, MY_STMT))
89303 + return TREE_TYPE(node);
89304 +
89305 + switch (TYPE_MODE(type)) {
89306 + case QImode:
89307 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
89308 + break;
89309 + case HImode:
89310 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
89311 + break;
89312 + case SImode:
89313 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89314 + break;
89315 + case DImode:
89316 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
89317 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89318 + else
89319 + new_type = (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
89320 + break;
89321 + default:
89322 + debug_tree((tree)node);
89323 + error("%s: unsupported gcc configuration.", __func__);
89324 + gcc_unreachable();
89325 + }
89326 +
89327 + if (TYPE_QUALS(type) != 0)
89328 + return build_qualified_type(new_type, TYPE_QUALS(type));
89329 + return new_type;
89330 +}
89331 +
89332 +static tree expand_visited(gimple def_stmt)
89333 +{
89334 + const_gimple next_stmt;
89335 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89336 +
89337 + gsi_next(&gsi);
89338 + next_stmt = gsi_stmt(gsi);
89339 +
89340 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89341 +
89342 + switch (gimple_code(next_stmt)) {
89343 + case GIMPLE_ASSIGN:
89344 + return gimple_get_lhs(next_stmt);
89345 + case GIMPLE_PHI:
89346 + return gimple_phi_result(next_stmt);
89347 + case GIMPLE_CALL:
89348 + return gimple_call_lhs(next_stmt);
89349 + default:
89350 + return NULL_TREE;
89351 + }
89352 +}
89353 +
89354 +static tree expand(struct pointer_set_t *visited, tree lhs)
89355 +{
89356 + gimple def_stmt;
89357 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89358 +
89359 + if (is_gimple_constant(lhs))
89360 + return NULL_TREE;
89361 +
89362 + if (TREE_CODE(lhs) == ADDR_EXPR)
89363 + return NULL_TREE;
89364 +
89365 + if (code == REAL_TYPE)
89366 + return NULL_TREE;
89367 +
89368 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89369 +
89370 + def_stmt = get_def_stmt(lhs);
89371 +
89372 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
89373 + return NULL_TREE;
89374 +
89375 + if (gimple_plf(def_stmt, MY_STMT))
89376 + return lhs;
89377 +
89378 + // skip char type, except PHI (FIXME: only kernel)
89379 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode && gimple_code(def_stmt) != GIMPLE_PHI)
89380 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89381 +
89382 + if (pointer_set_contains(visited, def_stmt))
89383 + return expand_visited(def_stmt);
89384 +
89385 + switch (gimple_code(def_stmt)) {
89386 + case GIMPLE_PHI:
89387 + return build_new_phi(visited, lhs);
89388 + case GIMPLE_CALL:
89389 + case GIMPLE_ASM:
89390 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89391 + case GIMPLE_ASSIGN:
89392 + switch (gimple_num_ops(def_stmt)) {
89393 + case 2:
89394 + return handle_unary_ops(visited, def_stmt);
89395 + case 3:
89396 + return handle_binary_ops(visited, lhs);
89397 +#if BUILDING_GCC_VERSION >= 4007
89398 + case 4:
89399 + return handle_ternary_ops(visited, lhs);
89400 +#endif
89401 + }
89402 + default:
89403 + debug_gimple_stmt(def_stmt);
89404 + error("%s: unknown gimple code", __func__);
89405 + gcc_unreachable();
89406 + }
89407 +}
89408 +
89409 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89410 +{
89411 + const_gimple assign;
89412 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89413 + tree origtype = TREE_TYPE(origarg);
89414 +
89415 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89416 +
89417 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89418 +
89419 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89420 + update_stmt(stmt);
89421 +}
89422 +
89423 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89424 +{
89425 + const char *origid;
89426 + tree arg;
89427 + const_tree origarg;
89428 +
89429 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89430 + return true;
89431 +
89432 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89433 + while (origarg && *argnum) {
89434 + (*argnum)--;
89435 + origarg = TREE_CHAIN(origarg);
89436 + }
89437 +
89438 + gcc_assert(*argnum == 0);
89439 +
89440 + gcc_assert(origarg != NULL_TREE);
89441 + origid = NAME(origarg);
89442 + *argnum = 0;
89443 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89444 + if (!strcmp(origid, NAME(arg)))
89445 + return true;
89446 + (*argnum)++;
89447 + }
89448 + return false;
89449 +}
89450 +
89451 +static bool skip_types(const_tree var)
89452 +{
89453 + const_tree type;
89454 +
89455 + switch (TREE_CODE(var)) {
89456 + case ADDR_EXPR:
89457 +#if BUILDING_GCC_VERSION >= 4006
89458 + case MEM_REF:
89459 +#endif
89460 + case ARRAY_REF:
89461 + case BIT_FIELD_REF:
89462 + case INDIRECT_REF:
89463 + case TARGET_MEM_REF:
89464 + case VAR_DECL:
89465 + return true;
89466 + default:
89467 + break;
89468 + }
89469 +
89470 + type = TREE_TYPE(TREE_TYPE(var));
89471 + if (!type)
89472 + return false;
89473 + switch (TREE_CODE(type)) {
89474 + case RECORD_TYPE:
89475 + return true;
89476 + default:
89477 + break;
89478 + }
89479 +
89480 + return false;
89481 +}
89482 +
89483 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89484 +{
89485 + gimple phi = get_def_stmt(result);
89486 + unsigned int i, n = gimple_phi_num_args(phi);
89487 +
89488 + if (!phi)
89489 + return false;
89490 +
89491 + pointer_set_insert(visited, phi);
89492 + for (i = 0; i < n; i++) {
89493 + const_tree arg = gimple_phi_arg_def(phi, i);
89494 + if (pre_expand(visited, arg))
89495 + return true;
89496 + }
89497 + return false;
89498 +}
89499 +
89500 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89501 +{
89502 + gimple def_stmt = get_def_stmt(lhs);
89503 + const_tree rhs;
89504 +
89505 + if (!def_stmt)
89506 + return false;
89507 +
89508 + rhs = gimple_assign_rhs1(def_stmt);
89509 + if (pre_expand(visited, rhs))
89510 + return true;
89511 + return false;
89512 +}
89513 +
89514 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89515 +{
89516 + bool rhs1_found, rhs2_found;
89517 + gimple def_stmt = get_def_stmt(lhs);
89518 + const_tree rhs1, rhs2;
89519 +
89520 + if (!def_stmt)
89521 + return false;
89522 +
89523 + rhs1 = gimple_assign_rhs1(def_stmt);
89524 + rhs2 = gimple_assign_rhs2(def_stmt);
89525 + rhs1_found = pre_expand(visited, rhs1);
89526 + rhs2_found = pre_expand(visited, rhs2);
89527 +
89528 + return rhs1_found || rhs2_found;
89529 +}
89530 +
89531 +static const_tree search_field_decl(const_tree comp_ref)
89532 +{
89533 + const_tree field = NULL_TREE;
89534 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89535 +
89536 + for (i = 0; i < len; i++) {
89537 + field = TREE_OPERAND(comp_ref, i);
89538 + if (TREE_CODE(field) == FIELD_DECL)
89539 + break;
89540 + }
89541 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89542 + return field;
89543 +}
89544 +
89545 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89546 +{
89547 + const_tree attr, p;
89548 +
89549 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89550 + if (!attr || !TREE_VALUE(attr))
89551 + return MARKED_NO;
89552 +
89553 + p = TREE_VALUE(attr);
89554 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89555 + return MARKED_NOT_INTENTIONAL;
89556 +
89557 + do {
89558 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89559 + return MARKED_YES;
89560 + p = TREE_CHAIN(p);
89561 + } while (p);
89562 +
89563 + return MARKED_NO;
89564 +}
89565 +
89566 +static void print_missing_msg(tree func, unsigned int argnum)
89567 +{
89568 + unsigned int new_hash;
89569 + size_t len;
89570 + unsigned char tree_codes[CODES_LIMIT];
89571 + location_t loc = DECL_SOURCE_LOCATION(func);
89572 + const char *curfunc = get_asm_name(func);
89573 +
89574 + len = get_function_decl(func, tree_codes);
89575 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89576 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89577 +}
89578 +
89579 +static unsigned int search_missing_attribute(const_tree arg)
89580 +{
89581 + const_tree type = TREE_TYPE(arg);
89582 + tree func = get_original_function_decl(current_function_decl);
89583 + unsigned int argnum;
89584 + const struct size_overflow_hash *hash;
89585 +
89586 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89587 +
89588 + if (TREE_CODE(type) == POINTER_TYPE)
89589 + return 0;
89590 +
89591 + argnum = find_arg_number(arg, func);
89592 + if (argnum == 0)
89593 + return 0;
89594 +
89595 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89596 + return argnum;
89597 +
89598 + hash = get_function_hash(func);
89599 + if (!hash || !(hash->param & (1U << argnum))) {
89600 + print_missing_msg(func, argnum);
89601 + return 0;
89602 + }
89603 + return argnum;
89604 +}
89605 +
89606 +static bool is_already_marked(const_tree lhs)
89607 +{
89608 + unsigned int argnum;
89609 + const_tree fndecl;
89610 +
89611 + argnum = search_missing_attribute(lhs);
89612 + fndecl = get_original_function_decl(current_function_decl);
89613 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89614 + return true;
89615 + return false;
89616 +}
89617 +
89618 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89619 +{
89620 + const_gimple def_stmt;
89621 +
89622 + if (is_gimple_constant(lhs))
89623 + return false;
89624 +
89625 + if (skip_types(lhs))
89626 + return false;
89627 +
89628 + // skip char type (FIXME: only kernel)
89629 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
89630 + return false;
89631 +
89632 + if (TREE_CODE(lhs) == PARM_DECL)
89633 + return is_already_marked(lhs);
89634 +
89635 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89636 + const_tree field, attr;
89637 +
89638 + field = search_field_decl(lhs);
89639 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89640 + if (!attr || !TREE_VALUE(attr))
89641 + return false;
89642 + return true;
89643 + }
89644 +
89645 + def_stmt = get_def_stmt(lhs);
89646 +
89647 + if (!def_stmt)
89648 + return false;
89649 +
89650 + if (pointer_set_contains(visited, def_stmt))
89651 + return false;
89652 +
89653 + switch (gimple_code(def_stmt)) {
89654 + case GIMPLE_NOP:
89655 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89656 + return is_already_marked(lhs);
89657 + return false;
89658 + case GIMPLE_PHI:
89659 + return walk_phi(visited, lhs);
89660 + case GIMPLE_CALL:
89661 + case GIMPLE_ASM:
89662 + return false;
89663 + case GIMPLE_ASSIGN:
89664 + switch (gimple_num_ops(def_stmt)) {
89665 + case 2:
89666 + return walk_unary_ops(visited, lhs);
89667 + case 3:
89668 + return walk_binary_ops(visited, lhs);
89669 + }
89670 + default:
89671 + debug_gimple_stmt((gimple)def_stmt);
89672 + error("%s: unknown gimple code", __func__);
89673 + gcc_unreachable();
89674 + }
89675 +}
89676 +
89677 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89678 +{
89679 + struct pointer_set_t *visited;
89680 + bool is_found;
89681 + enum marked is_marked;
89682 + location_t loc;
89683 +
89684 + visited = pointer_set_create();
89685 + is_found = pre_expand(visited, arg);
89686 + pointer_set_destroy(visited);
89687 +
89688 + is_marked = mark_status(fndecl, argnum + 1);
89689 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89690 + return true;
89691 +
89692 + if (is_found) {
89693 + loc = DECL_SOURCE_LOCATION(fndecl);
89694 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89695 + return true;
89696 + }
89697 + return false;
89698 +}
89699 +
89700 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89701 +{
89702 + struct pointer_set_t *visited;
89703 + tree arg, newarg;
89704 + bool match;
89705 +
89706 + match = get_function_arg(&argnum, fndecl);
89707 + if (!match)
89708 + return;
89709 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89710 + arg = gimple_call_arg(stmt, argnum);
89711 + if (arg == NULL_TREE)
89712 + return;
89713 +
89714 + if (is_gimple_constant(arg))
89715 + return;
89716 +
89717 + if (search_attributes(fndecl, arg, argnum))
89718 + return;
89719 +
89720 + if (TREE_CODE(arg) != SSA_NAME)
89721 + return;
89722 +
89723 + check_arg_type(arg);
89724 +
89725 + visited = pointer_set_create();
89726 + newarg = expand(visited, arg);
89727 + pointer_set_destroy(visited);
89728 +
89729 + if (newarg == NULL_TREE)
89730 + return;
89731 +
89732 + change_function_arg(stmt, arg, argnum, newarg);
89733 +
89734 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89735 +}
89736 +
89737 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89738 +{
89739 + tree p = TREE_VALUE(attr);
89740 + do {
89741 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89742 + p = TREE_CHAIN(p);
89743 + } while (p);
89744 +}
89745 +
89746 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89747 +{
89748 + tree orig_fndecl;
89749 + unsigned int num;
89750 + const struct size_overflow_hash *hash;
89751 +
89752 + orig_fndecl = get_original_function_decl(fndecl);
89753 + if (C_DECL_IMPLICIT(orig_fndecl))
89754 + return;
89755 + hash = get_function_hash(orig_fndecl);
89756 + if (!hash)
89757 + return;
89758 +
89759 + for (num = 1; num <= MAX_PARAM; num++)
89760 + if (hash->param & (1U << num))
89761 + handle_function_arg(stmt, fndecl, num - 1);
89762 +}
89763 +
89764 +static void set_plf_false(void)
89765 +{
89766 + basic_block bb;
89767 +
89768 + FOR_ALL_BB(bb) {
89769 + gimple_stmt_iterator si;
89770 +
89771 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89772 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89773 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89774 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89775 + }
89776 +}
89777 +
89778 +static unsigned int handle_function(void)
89779 +{
89780 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89781 +
89782 + set_plf_false();
89783 +
89784 + do {
89785 + gimple_stmt_iterator gsi;
89786 + next = bb->next_bb;
89787 +
89788 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89789 + tree fndecl, attr;
89790 + gimple stmt = gsi_stmt(gsi);
89791 +
89792 + if (!(is_gimple_call(stmt)))
89793 + continue;
89794 + fndecl = gimple_call_fndecl(stmt);
89795 + if (fndecl == NULL_TREE)
89796 + continue;
89797 + if (gimple_call_num_args(stmt) == 0)
89798 + continue;
89799 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89800 + if (!attr || !TREE_VALUE(attr))
89801 + handle_function_by_hash(stmt, fndecl);
89802 + else
89803 + handle_function_by_attribute(stmt, attr, fndecl);
89804 + gsi = gsi_for_stmt(stmt);
89805 + next = gimple_bb(stmt)->next_bb;
89806 + }
89807 + bb = next;
89808 + } while (bb);
89809 + return 0;
89810 +}
89811 +
89812 +static struct gimple_opt_pass size_overflow_pass = {
89813 + .pass = {
89814 + .type = GIMPLE_PASS,
89815 + .name = "size_overflow",
89816 + .gate = NULL,
89817 + .execute = handle_function,
89818 + .sub = NULL,
89819 + .next = NULL,
89820 + .static_pass_number = 0,
89821 + .tv_id = TV_NONE,
89822 + .properties_required = PROP_cfg | PROP_referenced_vars,
89823 + .properties_provided = 0,
89824 + .properties_destroyed = 0,
89825 + .todo_flags_start = 0,
89826 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
89827 + }
89828 +};
89829 +
89830 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89831 +{
89832 + tree fntype;
89833 +
89834 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89835 +
89836 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89837 + fntype = build_function_type_list(void_type_node,
89838 + const_char_ptr_type_node,
89839 + unsigned_type_node,
89840 + const_char_ptr_type_node,
89841 + const_char_ptr_type_node,
89842 + NULL_TREE);
89843 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89844 +
89845 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89846 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89847 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89848 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89849 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89850 +}
89851 +
89852 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89853 +{
89854 + int i;
89855 + const char * const plugin_name = plugin_info->base_name;
89856 + const int argc = plugin_info->argc;
89857 + const struct plugin_argument * const argv = plugin_info->argv;
89858 + bool enable = true;
89859 +
89860 + struct register_pass_info size_overflow_pass_info = {
89861 + .pass = &size_overflow_pass.pass,
89862 + .reference_pass_name = "ssa",
89863 + .ref_pass_instance_number = 1,
89864 + .pos_op = PASS_POS_INSERT_AFTER
89865 + };
89866 +
89867 + if (!plugin_default_version_check(version, &gcc_version)) {
89868 + error(G_("incompatible gcc/plugin versions"));
89869 + return 1;
89870 + }
89871 +
89872 + for (i = 0; i < argc; ++i) {
89873 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89874 + enable = false;
89875 + continue;
89876 + }
89877 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89878 + }
89879 +
89880 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89881 + if (enable) {
89882 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89883 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89884 + }
89885 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89886 +
89887 + return 0;
89888 +}
89889 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89890 new file mode 100644
89891 index 0000000..38d2014
89892 --- /dev/null
89893 +++ b/tools/gcc/stackleak_plugin.c
89894 @@ -0,0 +1,313 @@
89895 +/*
89896 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89897 + * Licensed under the GPL v2
89898 + *
89899 + * Note: the choice of the license means that the compilation process is
89900 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89901 + * but for the kernel it doesn't matter since it doesn't link against
89902 + * any of the gcc libraries
89903 + *
89904 + * gcc plugin to help implement various PaX features
89905 + *
89906 + * - track lowest stack pointer
89907 + *
89908 + * TODO:
89909 + * - initialize all local variables
89910 + *
89911 + * BUGS:
89912 + * - none known
89913 + */
89914 +#include "gcc-plugin.h"
89915 +#include "config.h"
89916 +#include "system.h"
89917 +#include "coretypes.h"
89918 +#include "tree.h"
89919 +#include "tree-pass.h"
89920 +#include "flags.h"
89921 +#include "intl.h"
89922 +#include "toplev.h"
89923 +#include "plugin.h"
89924 +//#include "expr.h" where are you...
89925 +#include "diagnostic.h"
89926 +#include "plugin-version.h"
89927 +#include "tm.h"
89928 +#include "function.h"
89929 +#include "basic-block.h"
89930 +#include "gimple.h"
89931 +#include "rtl.h"
89932 +#include "emit-rtl.h"
89933 +
89934 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89935 +
89936 +int plugin_is_GPL_compatible;
89937 +
89938 +static int track_frame_size = -1;
89939 +static const char track_function[] = "pax_track_stack";
89940 +static const char check_function[] = "pax_check_alloca";
89941 +static bool init_locals;
89942 +
89943 +static struct plugin_info stackleak_plugin_info = {
89944 + .version = "201203140940",
89945 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89946 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89947 +};
89948 +
89949 +static bool gate_stackleak_track_stack(void);
89950 +static unsigned int execute_stackleak_tree_instrument(void);
89951 +static unsigned int execute_stackleak_final(void);
89952 +
89953 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89954 + .pass = {
89955 + .type = GIMPLE_PASS,
89956 + .name = "stackleak_tree_instrument",
89957 + .gate = gate_stackleak_track_stack,
89958 + .execute = execute_stackleak_tree_instrument,
89959 + .sub = NULL,
89960 + .next = NULL,
89961 + .static_pass_number = 0,
89962 + .tv_id = TV_NONE,
89963 + .properties_required = PROP_gimple_leh | PROP_cfg,
89964 + .properties_provided = 0,
89965 + .properties_destroyed = 0,
89966 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89967 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89968 + }
89969 +};
89970 +
89971 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89972 + .pass = {
89973 + .type = RTL_PASS,
89974 + .name = "stackleak_final",
89975 + .gate = gate_stackleak_track_stack,
89976 + .execute = execute_stackleak_final,
89977 + .sub = NULL,
89978 + .next = NULL,
89979 + .static_pass_number = 0,
89980 + .tv_id = TV_NONE,
89981 + .properties_required = 0,
89982 + .properties_provided = 0,
89983 + .properties_destroyed = 0,
89984 + .todo_flags_start = 0,
89985 + .todo_flags_finish = TODO_dump_func
89986 + }
89987 +};
89988 +
89989 +static bool gate_stackleak_track_stack(void)
89990 +{
89991 + return track_frame_size >= 0;
89992 +}
89993 +
89994 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89995 +{
89996 + gimple check_alloca;
89997 + tree fntype, fndecl, alloca_size;
89998 +
89999 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
90000 + fndecl = build_fn_decl(check_function, fntype);
90001 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
90002 +
90003 + // insert call to void pax_check_alloca(unsigned long size)
90004 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
90005 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
90006 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
90007 +}
90008 +
90009 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
90010 +{
90011 + gimple track_stack;
90012 + tree fntype, fndecl;
90013 +
90014 + fntype = build_function_type_list(void_type_node, NULL_TREE);
90015 + fndecl = build_fn_decl(track_function, fntype);
90016 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
90017 +
90018 + // insert call to void pax_track_stack(void)
90019 + track_stack = gimple_build_call(fndecl, 0);
90020 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
90021 +}
90022 +
90023 +#if BUILDING_GCC_VERSION == 4005
90024 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
90025 +{
90026 + tree fndecl;
90027 +
90028 + if (!is_gimple_call(stmt))
90029 + return false;
90030 + fndecl = gimple_call_fndecl(stmt);
90031 + if (!fndecl)
90032 + return false;
90033 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
90034 + return false;
90035 +// print_node(stderr, "pax", fndecl, 4);
90036 + return DECL_FUNCTION_CODE(fndecl) == code;
90037 +}
90038 +#endif
90039 +
90040 +static bool is_alloca(gimple stmt)
90041 +{
90042 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
90043 + return true;
90044 +
90045 +#if BUILDING_GCC_VERSION >= 4007
90046 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
90047 + return true;
90048 +#endif
90049 +
90050 + return false;
90051 +}
90052 +
90053 +static unsigned int execute_stackleak_tree_instrument(void)
90054 +{
90055 + basic_block bb, entry_bb;
90056 + bool prologue_instrumented = false, is_leaf = true;
90057 +
90058 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
90059 +
90060 + // 1. loop through BBs and GIMPLE statements
90061 + FOR_EACH_BB(bb) {
90062 + gimple_stmt_iterator gsi;
90063 +
90064 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
90065 + gimple stmt;
90066 +
90067 + stmt = gsi_stmt(gsi);
90068 +
90069 + if (is_gimple_call(stmt))
90070 + is_leaf = false;
90071 +
90072 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
90073 + if (!is_alloca(stmt))
90074 + continue;
90075 +
90076 + // 2. insert stack overflow check before each __builtin_alloca call
90077 + stackleak_check_alloca(&gsi);
90078 +
90079 + // 3. insert track call after each __builtin_alloca call
90080 + stackleak_add_instrumentation(&gsi);
90081 + if (bb == entry_bb)
90082 + prologue_instrumented = true;
90083 + }
90084 + }
90085 +
90086 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
90087 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
90088 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
90089 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
90090 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
90091 + return 0;
90092 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
90093 + return 0;
90094 +
90095 + // 4. insert track call at the beginning
90096 + if (!prologue_instrumented) {
90097 + gimple_stmt_iterator gsi;
90098 +
90099 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90100 + if (dom_info_available_p(CDI_DOMINATORS))
90101 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
90102 + gsi = gsi_start_bb(bb);
90103 + stackleak_add_instrumentation(&gsi);
90104 + }
90105 +
90106 + return 0;
90107 +}
90108 +
90109 +static unsigned int execute_stackleak_final(void)
90110 +{
90111 + rtx insn;
90112 +
90113 + if (cfun->calls_alloca)
90114 + return 0;
90115 +
90116 + // keep calls only if function frame is big enough
90117 + if (get_frame_size() >= track_frame_size)
90118 + return 0;
90119 +
90120 + // 1. find pax_track_stack calls
90121 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
90122 + // 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))
90123 + rtx body;
90124 +
90125 + if (!CALL_P(insn))
90126 + continue;
90127 + body = PATTERN(insn);
90128 + if (GET_CODE(body) != CALL)
90129 + continue;
90130 + body = XEXP(body, 0);
90131 + if (GET_CODE(body) != MEM)
90132 + continue;
90133 + body = XEXP(body, 0);
90134 + if (GET_CODE(body) != SYMBOL_REF)
90135 + continue;
90136 + if (strcmp(XSTR(body, 0), track_function))
90137 + continue;
90138 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
90139 + // 2. delete call
90140 + insn = delete_insn_and_edges(insn);
90141 +#if BUILDING_GCC_VERSION >= 4007
90142 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
90143 + insn = delete_insn_and_edges(insn);
90144 +#endif
90145 + }
90146 +
90147 +// print_simple_rtl(stderr, get_insns());
90148 +// print_rtl(stderr, get_insns());
90149 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
90150 +
90151 + return 0;
90152 +}
90153 +
90154 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
90155 +{
90156 + const char * const plugin_name = plugin_info->base_name;
90157 + const int argc = plugin_info->argc;
90158 + const struct plugin_argument * const argv = plugin_info->argv;
90159 + int i;
90160 + struct register_pass_info stackleak_tree_instrument_pass_info = {
90161 + .pass = &stackleak_tree_instrument_pass.pass,
90162 +// .reference_pass_name = "tree_profile",
90163 + .reference_pass_name = "optimized",
90164 + .ref_pass_instance_number = 1,
90165 + .pos_op = PASS_POS_INSERT_BEFORE
90166 + };
90167 + struct register_pass_info stackleak_final_pass_info = {
90168 + .pass = &stackleak_final_rtl_opt_pass.pass,
90169 + .reference_pass_name = "final",
90170 + .ref_pass_instance_number = 1,
90171 + .pos_op = PASS_POS_INSERT_BEFORE
90172 + };
90173 +
90174 + if (!plugin_default_version_check(version, &gcc_version)) {
90175 + error(G_("incompatible gcc/plugin versions"));
90176 + return 1;
90177 + }
90178 +
90179 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
90180 +
90181 + for (i = 0; i < argc; ++i) {
90182 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
90183 + if (!argv[i].value) {
90184 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90185 + continue;
90186 + }
90187 + track_frame_size = atoi(argv[i].value);
90188 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
90189 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
90190 + continue;
90191 + }
90192 + if (!strcmp(argv[i].key, "initialize-locals")) {
90193 + if (argv[i].value) {
90194 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
90195 + continue;
90196 + }
90197 + init_locals = true;
90198 + continue;
90199 + }
90200 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
90201 + }
90202 +
90203 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
90204 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
90205 +
90206 + return 0;
90207 +}
90208 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
90209 index 6789d78..4afd019e 100644
90210 --- a/tools/perf/util/include/asm/alternative-asm.h
90211 +++ b/tools/perf/util/include/asm/alternative-asm.h
90212 @@ -5,4 +5,7 @@
90213
90214 #define altinstruction_entry #
90215
90216 + .macro pax_force_retaddr rip=0, reload=0
90217 + .endm
90218 +
90219 #endif
90220 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
90221 index be70035..739990f 100644
90222 --- a/virt/kvm/kvm_main.c
90223 +++ b/virt/kvm/kvm_main.c
90224 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
90225
90226 static cpumask_var_t cpus_hardware_enabled;
90227 static int kvm_usage_count = 0;
90228 -static atomic_t hardware_enable_failed;
90229 +static atomic_unchecked_t hardware_enable_failed;
90230
90231 struct kmem_cache *kvm_vcpu_cache;
90232 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
90233 @@ -727,7 +727,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
90234 /* We can read the guest memory with __xxx_user() later on. */
90235 if (user_alloc &&
90236 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
90237 - !access_ok(VERIFY_WRITE,
90238 + !__access_ok(VERIFY_WRITE,
90239 (void __user *)(unsigned long)mem->userspace_addr,
90240 mem->memory_size)))
90241 goto out;
90242 @@ -2453,7 +2453,7 @@ static void hardware_enable_nolock(void *junk)
90243
90244 if (r) {
90245 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
90246 - atomic_inc(&hardware_enable_failed);
90247 + atomic_inc_unchecked(&hardware_enable_failed);
90248 printk(KERN_INFO "kvm: enabling virtualization on "
90249 "CPU%d failed\n", cpu);
90250 }
90251 @@ -2507,10 +2507,10 @@ static int hardware_enable_all(void)
90252
90253 kvm_usage_count++;
90254 if (kvm_usage_count == 1) {
90255 - atomic_set(&hardware_enable_failed, 0);
90256 + atomic_set_unchecked(&hardware_enable_failed, 0);
90257 on_each_cpu(hardware_enable_nolock, NULL, 1);
90258
90259 - if (atomic_read(&hardware_enable_failed)) {
90260 + if (atomic_read_unchecked(&hardware_enable_failed)) {
90261 hardware_disable_all_nolock();
90262 r = -EBUSY;
90263 }
90264 @@ -2868,7 +2868,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
90265 kvm_arch_vcpu_put(vcpu);
90266 }
90267
90268 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90269 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90270 struct module *module)
90271 {
90272 int r;
90273 @@ -2904,7 +2904,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90274 if (!vcpu_align)
90275 vcpu_align = __alignof__(struct kvm_vcpu);
90276 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
90277 - 0, NULL);
90278 + SLAB_USERCOPY, NULL);
90279 if (!kvm_vcpu_cache) {
90280 r = -ENOMEM;
90281 goto out_free_3;
90282 @@ -2914,9 +2914,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
90283 if (r)
90284 goto out_free;
90285
90286 - kvm_chardev_ops.owner = module;
90287 - kvm_vm_fops.owner = module;
90288 - kvm_vcpu_fops.owner = module;
90289 + pax_open_kernel();
90290 + *(void **)&kvm_chardev_ops.owner = module;
90291 + *(void **)&kvm_vm_fops.owner = module;
90292 + *(void **)&kvm_vcpu_fops.owner = module;
90293 + pax_close_kernel();
90294
90295 r = misc_register(&kvm_dev);
90296 if (r) {